RadiantQ WPF Gantt
Critical Paths
Previous Topic  Next Topic 

A project's Critical Path is defined by a list of tasks whose delay will directly or indirectly affect the project's finish date. An activity could indirectly affect the project finish date because of the presence of dependencies that would in turn affect other activities move past the current project end time.


It's often required to highlight such critical activities for proper project planning.



Sample Gantt with critical path highlighted


The GanttControl provides built-in functionality to determine and visualize the critical path of the project.


Determining Critical Paths in code


The GanttControl.GetCriticalPathActivities method returns the list of activities that fall under the critical path. For example:


public List<IActivity> GetCriticalPathActivities(TimeSpan timeBuffer);


The 1st argument above is a time-buffer which specifies how further away an activity should be from potentially affecting the project dead line. If an activity is within this time-buffer then it will also be classified as "critical".


Highlighting Critical Paths


(A complete sample illustrating this can be found in the Samples/Appearance/GanttControlCriticalPath).


To highlight critical path activities, first cache the critical path activities in a static array as follows:


public static List<IActivity> CriticalPathActivities = new List<IActivity>();


// In Button_Click for example:

// The first argument to GetCriticalPathActivities is a time-buffer which specifies the "safe distance"

// that an activity's end time should be away from affecting the project deadline.

CriticalPathActivities = this.ganttControl.GetCriticalPathActivities(TimeSpan.FromHours(this.slider1.Value));


Then setup a binding that will provide custom color information for activities as follows:


this.ganttControl.TaskColorsBinding = new Binding() { Converter = new CustomColorProvider() };


public class CustomColorProvider : IValueConverter

{

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

    {

        IActivity activity = value as IActivity;

        if (IsCritical(activity))

        { // Use a reddish brush

            LinearGradientBrush brush = new LinearGradientBrush() { StartPoint = new Point(0, 0), EndPoint = new Point(0, 1) };

            brush.GradientStops.Add(new GradientStop() { Color = Colors.Transparent, Offset = 0 });

            brush.GradientStops.Add(new GradientStop() { Color = Color.FromArgb(255, 0xFF, 0xA0, 0x7A), Offset = 0.25 });

            brush.GradientStops.Add(new GradientStop() { Color = Color.FromArgb(255, 0xFF, 0x63, 0x47), Offset = 1 });

            return new TaskSpecificColors() { TaskItemBarFill = brush, TaskItemBarStroke = new SolidColorBrush(Color.FromArgb(255, 0xFF, 0x63, 0x47)), TaskItemProgressFill = new SolidColorBrush(Colors.Black) };

        }

        else

            return null;


    }


    private bool IsCritical(IActivity activity)

    {

        return MainPage.CriticalPathActivities.Contains(activity);

    }


}


The resultant Gantt screenshot is shown above.




� RadiantQ 2009 - 2019. All Rights Reserved.