Skip to content

Commit c2ed900

Browse files
savvinsergeyignatvilesov
authored andcommitted
Added option to data labels which cut them up to the width of the task (#90)
1 parent 16f6b4f commit c2ed900

File tree

8 files changed

+47
-5
lines changed

8 files changed

+47
-5
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
## 1.8.6
2+
* Added option to data labels which cut them up to the width of the task
13
## 1.8.5
24
* Fixed issue with wrong displaying resources labels
35
## 1.8.4

capabilities.json

+7
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,13 @@
587587
"type": {
588588
"bool": true
589589
}
590+
},
591+
"widthByTask": {
592+
"displayName": "Width by task",
593+
"displayNameKey": "Visual_WidthByTask",
594+
"type": {
595+
"bool": true
596+
}
590597
}
591598
}
592599
},

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.8.5",
3+
"version": "1.8.6",
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.8.5",
7+
"version": "1.8.6",
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

+9-3
Original file line numberDiff line numberDiff line change
@@ -1697,6 +1697,7 @@ module powerbi.extensibility.visual {
16971697
let taskResourceFontSize: number = this.viewModel.settings.taskResource.fontSize;
16981698
let taskResourcePosition: ResourceLabelPositions = this.viewModel.settings.taskResource.position;
16991699
let taskResourceFullText: boolean = this.viewModel.settings.taskResource.fullText;
1700+
let taskResourceWidthByTask: boolean = this.viewModel.settings.taskResource.widthByTask;
17001701

17011702
if (taskResourceShow) {
17021703
let taskResource: UpdateSelection<Task> = taskSelection
@@ -1720,11 +1721,16 @@ module powerbi.extensibility.visual {
17201721
"font-size": PixelConverter.fromPoint(taskResourceFontSize)
17211722
});
17221723

1724+
let self: Gantt = this;
17231725
if (!taskResourceFullText) {
17241726
taskResource
1725-
.call(AxisHelper.LabelLayoutStrategy.clip,
1726-
Gantt.DefaultValues.ResourceWidth - Gantt.ResourceWidthPadding,
1727-
textMeasurementService.svgEllipsis);
1727+
.each(function(task: Task){
1728+
const width: number = taskResourceWidthByTask
1729+
? self.taskDurationToWidth(task.start, task.end)
1730+
: Gantt.DefaultValues.ResourceWidth - Gantt.ResourceWidthPadding;
1731+
1732+
AxisHelper.LabelLayoutStrategy.clip(d3.select(this), width, textMeasurementService.svgEllipsis);
1733+
});
17281734
}
17291735

17301736
taskResource

src/settings.ts

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ module powerbi.extensibility.visual {
8585
fontSize: number = 9;
8686
position: ResourceLabelPositions = ResourceLabelPositions.Right;
8787
fullText: boolean = false;
88+
widthByTask: boolean = false;
8889
}
8990

9091
export class DateTypeSettings {

stringResources/en-US/resources.resjson

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"Visual_LegendColor": "Legend color",
2525
"Visual_Show": "Show",
2626
"Visual_FullText": "Full text",
27+
"Visual_WidthByTask": "Width by task",
2728
"Visual_Position": "Position",
2829
"Visual_Position_Top": "Top",
2930
"Visual_Position_Bottom": "Bottom",

test/visualTest.ts

+25
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,31 @@ module powerbi.extensibility.visual.test {
802802
done();
803803
});
804804
});
805+
806+
it("widthByTask", (done) => {
807+
dataView.metadata.objects = {
808+
taskResource: {
809+
position: "Top",
810+
fullText: false,
811+
widthByTask: true
812+
}
813+
};
814+
815+
visualBuilder.updateRenderTimeout(dataView, () => {
816+
let taskRects: any[] = visualBuilder.taskRect.toArray().map($);
817+
visualBuilder.taskResources.toArray().map($).forEach((e, i) => {
818+
let labelElRawWidth: string = e.css("width");
819+
let labelElWidth: number = +labelElRawWidth.substr(0, labelElRawWidth.length - 2);
820+
821+
let taskElRawWidth: string = taskRects[i].css("width");
822+
let taskElWidth: number = +taskElRawWidth.substr(0, taskElRawWidth.length - 2);
823+
824+
expect(labelElWidth <= taskElWidth).toBeTruthy();
825+
});
826+
827+
done();
828+
});
829+
});
805830
});
806831

807832
describe("Task Completion", () => {

0 commit comments

Comments
 (0)