Skip to content

Commit 2118be8

Browse files
savvinsergeyignatvilesov
authored andcommitted
Adding various color settings (#26)
* Added colour settings for: Today Bar Color, Axis Color, Axis Text Color * Added ability to set colour of Tasks if there is no legend specified. * Increased version and added changelog for version 1.3.0 * Fixed a few lint errors * Added localization for new settings
1 parent 1ef43b1 commit 2118be8

File tree

7 files changed

+120
-24
lines changed

7 files changed

+120
-24
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 1.3.0
2+
* Added colour settings for: Today Bar Color, Axis Color, Axis Text Color
3+
* Added ability to set colour of Tasks if there is no legend specified.
14
## 1.2.0
25
* Added ability to set minimum of task duration
36
## 1.1.0

capabilities.json

+58
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,31 @@
397397
}
398398
}
399399
},
400+
"taskConfig": {
401+
"displayName": "Task Settings",
402+
"displayNameKey": "Visual_TaskSettings",
403+
"properties": {
404+
"fill": {
405+
"displayName": "Task color",
406+
"displayNameKey": "Visual_TaskSettings_Color",
407+
"description": "This ONLY takes effect when you have no legend specified",
408+
"type": {
409+
"fill": {
410+
"solid": {
411+
"color": true
412+
}
413+
}
414+
}
415+
},
416+
"height": {
417+
"displayName": "Height",
418+
"displayNameKey": "Visual_TaskSettings_Height",
419+
"type": {
420+
"numeric": true
421+
}
422+
}
423+
}
424+
},
400425
"taskResource": {
401426
"displayName": "Data Labels",
402427
"displayNameKey": "Visual_DataLabels",
@@ -461,6 +486,39 @@
461486
}
462487
]
463488
}
489+
},
490+
"todayColor": {
491+
"displayName": "Today Color",
492+
"displayNameKey": "Visual_GanttDateType_TodayColor",
493+
"type": {
494+
"fill": {
495+
"solid": {
496+
"color": true
497+
}
498+
}
499+
}
500+
},
501+
"axisColor": {
502+
"displayName": "Axis Color",
503+
"displayNameKey": "Visual_GanttDateType_AxisColor",
504+
"type": {
505+
"fill": {
506+
"solid": {
507+
"color": true
508+
}
509+
}
510+
}
511+
},
512+
"axisTextColor": {
513+
"displayName": "Axis Text Color",
514+
"displayNameKey": "Visual_GanttDateType_AxisTextColor",
515+
"type": {
516+
"fill": {
517+
"solid": {
518+
"color": true
519+
}
520+
}
521+
}
464522
}
465523
}
466524
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "powerbi-visuals-gantt",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"description": "A Gantt chart is a type of bar chart which illustrates a project timeline or schedule. The Gantt Chart visual shows the Tasks, Start Dates, Durations, % Complete, and Resources for a project. The Gantt Chart visual can be used to show current schedule status using percent-complete shadings and a vertical \"TODAY\" line. The Legend may be used to group or filter tasks based upon data values.",
55
"repository": {
66
"type": "git",

pbiviz.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"displayName": "Gantt",
55
"guid": "Gantt1448688115699",
66
"visualClassName": "Gantt",
7-
"version": "1.2.0",
7+
"version": "1.3.0",
88
"description": "A Gantt chart is a type of bar chart which illustrates a project timeline or schedule. The Gantt Chart visual shows the Tasks, Start Dates, Durations, % Complete, and Resources for a project. The Gantt Chart visual can be used to show current schedule status using percent-complete shadings and a vertical \"TODAY\" line. The Legend may be used to group or filter tasks based upon data values.",
99
"supportUrl": "http://community.powerbi.com",
1010
"gitHubUrl": "https://github.com/Microsoft/powerbi-visuals-gantt"

src/gantt.ts

+41-22
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,12 @@ module powerbi.extensibility.visual {
104104
const MillisecondsInWeek: number = 4 * MillisecondsInADay;
105105
const MillisecondsInAMonth: number = 30 * MillisecondsInADay;
106106
const MillisecondsInAYear: number = 365 * MillisecondsInADay;
107-
const ChartLineHeight: number = 40;
107+
function chartLineHeight(lineHeight: number): number {
108+
if (!lineHeight) {
109+
lineHeight = 40;
110+
}
111+
return lineHeight;
112+
};
108113
const PaddingTasks: number = 5;
109114

110115
const GanttDurationUnitType = [
@@ -501,7 +506,7 @@ module powerbi.extensibility.visual {
501506
};
502507
}
503508

504-
private static createLegend(dataView: DataView, host: IVisualHost, colorPalette: IColorPalette, settings: GanttSettings, taskTypes: TaskTypes): LegendData {
509+
private static createLegend(host: IVisualHost, colorPalette: IColorPalette, settings: GanttSettings, taskTypes: TaskTypes): LegendData {
505510
const colorHelper = new ColorHelper(colorPalette, Gantt.LegendPropertyIdentifier);
506511
const legendData: LegendData = {
507512
fontSize: settings.legend.fontSize,
@@ -529,14 +534,14 @@ module powerbi.extensibility.visual {
529534
* @param dataView The data Model.
530535
* @param formatters task attributes represented format.
531536
*/
532-
533537
private static createTasks(
534538
dataView: DataView,
535539
taskTypes: TaskTypes,
536540
host: IVisualHost,
537541
formatters: GanttChartFormatters,
538542
colors: IColorPalette,
539-
settings: GanttSettings
543+
settings: GanttSettings,
544+
taskColor: string
540545
): Task[] {
541546
const tasks: Task[] = [];
542547
const colorHelper: ColorHelper = new ColorHelper(
@@ -553,7 +558,7 @@ module powerbi.extensibility.visual {
553558
const selectoinBuider: ISelectionIdBuilder = host
554559
.createSelectionIdBuilder()
555560
.withCategory(dataView.categorical.categories[0], index);
556-
let color = Gantt.DefaultValues.TaskColor;
561+
let color = taskColor || Gantt.DefaultValues.TaskColor;
557562
const taskType = _.find(taskTypes.types, (typeMeta: TaskTypeMetadata) => typeMeta.name === group.Duration.source.groupName);
558563
if (taskType) {
559564
selectoinBuider
@@ -662,18 +667,22 @@ module powerbi.extensibility.visual {
662667
return null;
663668
}
664669

665-
const settings: GanttSettings = GanttSettings.parse<GanttSettings>(dataView);
666-
667-
const taskTypes: TaskTypes = Gantt.getAllTasksTypes(dataView)
670+
const settings: GanttSettings = GanttSettings.parse<GanttSettings>(dataView)
671+
, taskTypes: TaskTypes = Gantt.getAllTasksTypes(dataView)
668672
, formatters: GanttChartFormatters = this.getFormatters(dataView, host.locale || null)
669-
, tasks: Task[] = Gantt.createTasks(dataView, taskTypes, host, formatters, colors, settings);
673+
, legendData = Gantt.createLegend(host, colors, settings, taskTypes);
674+
675+
let taskColor: string = (legendData.dataPoints.length <= 1)
676+
? settings.taskConfig.fill
677+
: null;
670678

679+
const tasks: Task[] = Gantt.createTasks(dataView, taskTypes, host, formatters, colors, settings, taskColor);
671680
return {
672681
dataView,
673682
settings,
674683
taskTypes,
675684
tasks,
676-
legendData: Gantt.createLegend(dataView, host, colors, settings, taskTypes),
685+
legendData
677686
};
678687
}
679688

@@ -806,7 +815,7 @@ module powerbi.extensibility.visual {
806815
let axisLength: number = ticks * Gantt.DefaultTicksLength;
807816
this.ganttSvg
808817
.attr({
809-
height: PixelConverter.toString(groupedTasks.length * ChartLineHeight + this.margin.top),
818+
height: PixelConverter.toString(groupedTasks.length * chartLineHeight(this.viewModel.settings.taskConfig.height) + this.margin.top),
810819
width: PixelConverter.toString(this.margin.left + this.viewModel.settings.taskLabels.width + axisLength + Gantt.DefaultValues.ResourceWidth)
811820
});
812821
let viewportIn: IViewport = {
@@ -954,10 +963,17 @@ module powerbi.extensibility.visual {
954963
let xAxis: d3.svg.Axis = xAxisProperties.axis;
955964
xAxis.orient("bottom");
956965

966+
957967
this.axisGroup
958968
.transition()
959969
.duration(duration)
960970
.call(xAxis);
971+
972+
let axisColor: string = this.viewModel.settings.dateType.axisColor;
973+
let axisTextColor: string = this.viewModel.settings.dateType.axisTextColor;
974+
this.axisGroup.selectAll("path").style("stroke", axisColor); // Line
975+
this.axisGroup.selectAll(".tick line").style("stroke", axisColor); // ticks
976+
this.axisGroup.selectAll(".tick text").style("stroke", axisTextColor); // text
961977
}
962978

963979
/**
@@ -1032,9 +1048,9 @@ module powerbi.extensibility.visual {
10321048
.classed(Selectors.TaskRect.class, true)
10331049
.attr({
10341050
x: (task: Task) => this.timeScale(task.start),
1035-
y: (task: Task) => Gantt.getBarYCoordinate(task.id),
1051+
y: (task: Task) => Gantt.getBarYCoordinate(task.id, this.viewModel.settings.taskConfig.height),
10361052
width: (task: Task) => this.taskDurationToWidth(task),
1037-
height: () => Gantt.getBarHeight()
1053+
height: () => Gantt.getBarHeight(this.viewModel.settings.taskConfig.height)
10381054
})
10391055
.style("fill", (task: Task) => task.color);
10401056

@@ -1051,7 +1067,7 @@ module powerbi.extensibility.visual {
10511067
taskProgress
10521068
.attr({
10531069
x: (task: Task) => this.timeScale(task.start),
1054-
y: (task: Task) => Gantt.getBarYCoordinate(task.id) + Gantt.getBarHeight() / 2 - Gantt.DefaultValues.ProgressBarHeight / 2,
1070+
y: (task: Task) => Gantt.getBarYCoordinate(task.id, this.viewModel.settings.taskConfig.height) + Gantt.getBarHeight(this.viewModel.settings.taskConfig.height) / 2 - Gantt.DefaultValues.ProgressBarHeight / 2,
10551071
width: (task: Task) => this.setTaskProgress(task),
10561072
height: Gantt.DefaultValues.ProgressBarHeight
10571073
})
@@ -1074,7 +1090,7 @@ module powerbi.extensibility.visual {
10741090
taskResource
10751091
.attr({
10761092
x: (task: Task) => this.timeScale(task.end) + Gantt.TaskResourcePadding,
1077-
y: (task: Task) => (Gantt.getBarYCoordinate(task.id) + (Gantt.getBarHeight() / 2) + Gantt.TaskResourcePadding)
1093+
y: (task: Task) => (Gantt.getBarYCoordinate(task.id, this.viewModel.settings.taskConfig.height) + (Gantt.getBarHeight(this.viewModel.settings.taskConfig.height) / 2) + Gantt.TaskResourcePadding)
10781094
})
10791095
.text((task: Task) => task.resource)
10801096
.style({
@@ -1101,7 +1117,7 @@ module powerbi.extensibility.visual {
11011117
*/
11021118
private getTaskLabelCoordinateY(taskIndex: number): number {
11031119
const fontSize: number = + this.viewModel.settings.taskLabels.fontSize;
1104-
return (ChartLineHeight * taskIndex) + (Gantt.getBarHeight() + Gantt.BarHeightMargin - (ChartLineHeight - fontSize) / Gantt.ChartLineHeightDivider);
1120+
return (chartLineHeight(this.viewModel.settings.taskConfig.height) * taskIndex) + (Gantt.getBarHeight(this.viewModel.settings.taskConfig.height) + Gantt.BarHeightMargin - (chartLineHeight(this.viewModel.settings.taskConfig.height) - fontSize) / Gantt.ChartLineHeightDivider);
11051121
}
11061122

11071123
/**
@@ -1119,12 +1135,12 @@ module powerbi.extensibility.visual {
11191135
* Set the task progress bar in the gantt
11201136
* @param lineNumber Line number that represents the task number
11211137
*/
1122-
private static getBarYCoordinate(lineNumber: number): number {
1123-
return (ChartLineHeight * lineNumber) + (PaddingTasks);
1138+
private static getBarYCoordinate(lineNumber: number, lineHeight: number): number {
1139+
return (lineHeight * lineNumber) + (PaddingTasks);
11241140
}
11251141

1126-
private static getBarHeight(): number {
1127-
return ChartLineHeight / Gantt.ChartLineProportion;
1142+
private static getBarHeight(lineHeight: number): number {
1143+
return lineHeight / Gantt.ChartLineProportion;
11281144
}
11291145

11301146
/**
@@ -1147,6 +1163,7 @@ module powerbi.extensibility.visual {
11471163
* @param timestamp the milestone to be shown in the time axis (default Date.now())
11481164
*/
11491165
private createMilestoneLine(tasks: GroupedTask[], milestoneTitle: string = "Today", timestamp: number = Date.now()): void {
1166+
let todayColor: string = this.viewModel.settings.dateType.todayColor;
11501167
let line: Line[] = [{
11511168
x1: this.timeScale(new Date(timestamp)),
11521169
y1: Gantt.MilestoneTop,
@@ -1166,7 +1183,8 @@ module powerbi.extensibility.visual {
11661183
y1: (line: Line) => line.y1,
11671184
x2: (line: Line) => line.x2,
11681185
y2: (line: Line) => line.y2
1169-
});
1186+
})
1187+
.style("stroke", todayColor);
11701188

11711189
this.renderTooltip(chartLineSelection);
11721190
chartLineSelection.exit().remove();
@@ -1188,7 +1206,7 @@ module powerbi.extensibility.visual {
11881206
}
11891207

11901208
private getMilestoneLineLength(numOfTasks: number): number {
1191-
return numOfTasks * ChartLineHeight;
1209+
return numOfTasks * chartLineHeight(this.viewModel.settings.taskConfig.height);
11921210
}
11931211

11941212
public enumerateObjectInstances(options: EnumerateVisualObjectInstancesOptions): VisualObjectInstanceEnumeration {
@@ -1222,6 +1240,7 @@ module powerbi.extensibility.visual {
12221240
});
12231241
});
12241242
}
1243+
12251244
private addAnInstanceToEnumeration(
12261245
instanceEnumeration: VisualObjectInstanceEnumeration,
12271246
instance: VisualObjectInstance): void {

src/settings.ts

+10
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module powerbi.extensibility.visual {
3333
general: GeneralSettings = new GeneralSettings();
3434
legend: LegendSettings = new LegendSettings();
3535
taskLabels: TaskLabelsSettings = new TaskLabelsSettings();
36+
taskConfig: TaskConfigSettings = new TaskConfigSettings();
3637
taskCompletion: TaskCompletionSettings = new TaskCompletionSettings();
3738
taskResource: TaskResourceSettings = new TaskResourceSettings();
3839
dateType: DateTypeSettings = new DateTypeSettings();
@@ -60,6 +61,11 @@ module powerbi.extensibility.visual {
6061
width: number = 110;
6162
}
6263

64+
export class TaskConfigSettings {
65+
fill: string = "#00B099";
66+
height: number = 40;
67+
}
68+
6369
export class TaskCompletionSettings {
6470
show: boolean = true;
6571
fill: string = "#000000";
@@ -70,8 +76,12 @@ module powerbi.extensibility.visual {
7076
fill: string = "#000000";
7177
fontSize: number = 9;
7278
}
79+
7380
export class DateTypeSettings {
7481
// tslint:disable-next-line:no-reserved-keywords
7582
type: GanttDateType = "Week";
83+
todayColor: string = "#000000";
84+
axisColor: string = "#000000";
85+
axisTextColor: string = "#000000";
7686
}
7787
}

stringResources/en-US/resources.resjson

+6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
"Visual_Width": "Width",
2929
"Visual_TaskCompletion": "Task Completion",
3030
"Visual_CompletionColor": "Completion color",
31+
"Visual_TaskSettings": "Task settings",
32+
"Visual_TaskSettings_Color": "Color",
33+
"Visual_TaskSettings_Height": "Height",
3134
"Visual_DataLabels": "Data Labels",
3235
"Visual_CategoryLabels": "Category Labels",
3336
"Visual_Type": "Type",
@@ -36,4 +39,7 @@
3639
"Visual_GanttDateType_Week": "Week",
3740
"Visual_GanttDateType_Month": "Month",
3841
"Visual_GanttDateType_Year": "Year",
42+
"Visual_GanttDateType_TodayColor": "Today color",
43+
"Visual_GanttDateType_AxisColor": "Axis color",
44+
"Visual_GanttDateType_AxisTextColor": "Axis text color",
3945
}

0 commit comments

Comments
 (0)