private void GenerateGanttChart() { GanttChartAreaCtrl.ClearGantt(); GanttChartDto ganttChartDto = ViewModel.GanttChartDto; if (ganttChartDto != null) { IList <IDependentActivity <int> > dependentActivities = ganttChartDto.DependentActivities; IList <ResourceSeriesDto> resourceSeriesSet = ganttChartDto.ResourceSeriesSet; IList <IResourceSchedule <int> > resourceSchedules = ganttChartDto.ResourceSchedules; m_DateTimeCalculator.UseBusinessDays(ViewModel.UseBusinessDays); DateTime projectStart = ViewModel.ProjectStart; DateTime minDate = DatePicker.SelectedDate ?? projectStart; DateTime maxDate = minDate.AddDays(DaysSelect.Value.GetValueOrDefault()); GanttChartAreaCtrl.Initialize(minDate, maxDate); // Create timelines and define how they should be presented. GanttChartAreaCtrl.CreateTimeLine(new PeriodYearSplitter(minDate, maxDate), FormatYear); GanttChartAreaCtrl.CreateTimeLine(new PeriodMonthSplitter(minDate, maxDate), FormatMonth); TimeLine gridLineTimeLine = GanttChartAreaCtrl.CreateTimeLine(new PeriodDaySplitter(minDate, maxDate), FormatDay); //GanttChartAreaCtrl.CreateTimeLine(new PeriodDaySplitter(minDate, maxDate), FormatDayName); // Attach gridlines. GanttChartAreaCtrl.SetGridLinesTimeline(gridLineTimeLine, DetermineBackground); // Prep formatting helpers. SlackColorFormatLookup colorFormatLookup = null; ArrowGraphSettingsDto arrowGraphSettingsDto = ViewModel.ArrowGraphSettingsDto; if (arrowGraphSettingsDto?.ActivitySeverities != null) { colorFormatLookup = new SlackColorFormatLookup(arrowGraphSettingsDto.ActivitySeverities); } if (GroupByResource.IsChecked.GetValueOrDefault()) { BuildGanttChart(dependentActivities, resourceSeriesSet, resourceSchedules, projectStart, colorFormatLookup); } else { BuildGanttChart(dependentActivities, projectStart, colorFormatLookup); } } }
private GanttTask CreateGanttTask( DateTime projectStart, IDependentActivity <int> activity, SlackColorFormatLookup colorFormatLookup) { Color background = colorFormatLookup?.FindSlackColor(activity.TotalSlack) ?? Colors.DodgerBlue; return(new GanttTask { Start = m_DateTimeCalculator.AddDays(projectStart, activity.EarliestStartTime.Value), End = m_DateTimeCalculator.AddDays(projectStart, activity.EarliestFinishTime.Value), Name = activity.Name, BackgroundColor = new SolidColorBrush(background), ForegroundColor = new SolidColorBrush(ContrastConvert(background)), Radius = activity.Duration < 3 ? 0 : 5, TaskProgressVisibility = Visibility.Collapsed, }); }
private void BuildGanttChart( IList <IDependentActivity <int> > dependentActivities, DateTime projectStart, SlackColorFormatLookup colorFormatLookup) { if (dependentActivities == null) { return; } foreach (IDependentActivity <int> activity in dependentActivities) { GanttRowGroup rowGroup = GanttChartAreaCtrl.CreateGanttRowGroup(); GanttRow row = GanttChartAreaCtrl.CreateGanttRow(rowGroup, activity.Name); if (activity.EarliestStartTime.HasValue && activity.EarliestFinishTime.HasValue) { GanttChartAreaCtrl.AddGanttTask( row, CreateGanttTask(projectStart, activity, colorFormatLookup)); } } }
private void BuildGanttChart( IList <IDependentActivity <int> > dependentActivities, IList <ResourceSeriesDto> resourceSeriesSet, IList <IResourceSchedule <int> > resourceSchedules, DateTime projectStart, SlackColorFormatLookup colorFormatLookup) { if (dependentActivities == null || resourceSeriesSet == null || resourceSchedules == null) { return; } IDictionary <int, IDependentActivity <int> > activityLookup = dependentActivities.ToDictionary(x => x.Id); int spareResourceCount = 1; for (int resourceIndex = 0; resourceIndex < resourceSchedules.Count; resourceIndex++) { IResourceSchedule <int> resourceSchedule = resourceSchedules[resourceIndex]; IList <IScheduledActivity <int> > scheduledActivities = resourceSchedule?.ScheduledActivities; if (scheduledActivities == null) { continue; } var stringBuilder = new StringBuilder(); if (resourceSchedule.Resource != null) { if (string.IsNullOrWhiteSpace(resourceSchedule.Resource.Name)) { stringBuilder.Append($@"Resource {resourceSchedule.Resource.Id}"); } else { stringBuilder.Append(resourceSchedule.Resource.Name); } } else { stringBuilder.Append($@"Resource {spareResourceCount}"); spareResourceCount++; } string resourceName = stringBuilder.ToString(); GanttRowGroup rowGroup = GanttChartAreaCtrl.CreateGanttRowGroup(resourceName); foreach (IScheduledActivity <int> scheduledctivity in resourceSchedule.ScheduledActivities) { if (activityLookup.TryGetValue(scheduledctivity.Id, out IDependentActivity <int> activity)) { GanttRow row = GanttChartAreaCtrl.CreateGanttRow(rowGroup, activity.Name); if (activity.EarliestStartTime.HasValue && activity.EarliestFinishTime.HasValue) { GanttChartAreaCtrl.AddGanttTask( row, CreateGanttTask(projectStart, activity, colorFormatLookup)); } } } } }