Skip to content

Commit 701e963

Browse files
mvgalievuve
authored andcommitted
fixed tooltip issue (#97)
1 parent a5cb1bd commit 701e963

File tree

7 files changed

+103
-6
lines changed

7 files changed

+103
-6
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ typings
66
.api
77
*.log
88
/coverage
9+
package-lock.json

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 1.9.3
2+
* Fixed issue with tooltip duration
3+
* Fixed issue with line length with float value and 'second' duration
14
## 1.9.2
25
* Fixed issue with wrong selection of children tasks from legend
36
## 1.9.1

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.9.2",
3+
"version": "1.9.3",
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.9.2",
7+
"version": "1.9.3",
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

+33-4
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ module powerbi.extensibility.visual {
174174
extraInformation: ExtraInformation[];
175175
daysOffList: DayOffData[];
176176
wasDowngradeDurationUnit: boolean;
177+
stepDurationTransformation?: number;
177178
}
178179

179180
export type DayOffData = [Date, number];
@@ -735,6 +736,7 @@ module powerbi.extensibility.visual {
735736
let completion: number = 0;
736737
let taskType: TaskTypeMetadata = null;
737738
let wasDowngradeDurationUnit: boolean = false;
739+
let stepDurationTransformation: number = 0;
738740

739741
const selectionBuider: ISelectionIdBuilder = host
740742
.createSelectionIdBuilder()
@@ -756,7 +758,7 @@ module powerbi.extensibility.visual {
756758

757759
if (duration && duration % 1 !== 0) {
758760
durationUnit = Gantt.downgradeDurationUnit(durationUnit);
759-
let stepDurationTransformation: number =
761+
stepDurationTransformation =
760762
GanttDurationUnitType.indexOf(settings.general.durationUnit) - GanttDurationUnitType.indexOf(durationUnit);
761763

762764
duration = Gantt.transformDuration(duration, durationUnit, stepDurationTransformation);
@@ -820,9 +822,15 @@ module powerbi.extensibility.visual {
820822
identity: selectionId,
821823
extraInformation,
822824
daysOffList: [],
823-
wasDowngradeDurationUnit
825+
wasDowngradeDurationUnit,
826+
stepDurationTransformation
824827
};
828+
tasks.push(task);
829+
});
825830

831+
Gantt.downgradeDurationUnitIfNeed(tasks, durationUnit);
832+
833+
tasks.forEach(task => {
826834
task.end = d3.time[durationUnit].offset(task.start, task.duration);
827835
if (settings.daysOff.show && duration) {
828836
let datesDiff: number = 0;
@@ -851,8 +859,6 @@ module powerbi.extensibility.visual {
851859
if (task.parent !== task.name) {
852860
task.visibility = collapsedTasks.indexOf(task.parent) === -1;
853861
}
854-
855-
tasks.push(task);
856862
});
857863

858864
if (values.Parent) {
@@ -879,6 +885,21 @@ module powerbi.extensibility.visual {
879885
return tasks;
880886
}
881887

888+
public static downgradeDurationUnitIfNeed(tasks: Task[], durationUnit: string) {
889+
const downgradedDurationUnitTasks = tasks.filter(t => t.wasDowngradeDurationUnit);
890+
891+
if (downgradedDurationUnitTasks.length) {
892+
let maxStepDurationTransformation: number = 0;
893+
downgradedDurationUnitTasks.forEach(x => maxStepDurationTransformation = x.stepDurationTransformation > maxStepDurationTransformation ? x.stepDurationTransformation : maxStepDurationTransformation);
894+
895+
tasks.filter(x => x.stepDurationTransformation !== maxStepDurationTransformation).forEach(task => {
896+
task.duration = Gantt.transformDuration(task.duration, durationUnit, maxStepDurationTransformation);
897+
task.stepDurationTransformation = maxStepDurationTransformation;
898+
task.wasDowngradeDurationUnit = true;
899+
});
900+
}
901+
}
902+
882903
private static childrenOfTaskProcessing(tasks: Task[],
883904
task: Task,
884905
settings: GanttSettings,
@@ -990,6 +1011,11 @@ module powerbi.extensibility.visual {
9901011
duration: number,
9911012
newDurationUnit: string | DurationUnits,
9921013
stepDurationTransformation: number): number {
1014+
1015+
if (!stepDurationTransformation) {
1016+
return Math.floor(duration);
1017+
}
1018+
9931019
let transformedDuration: number = duration;
9941020
switch (newDurationUnit) {
9951021
case DurationUnits.Hour:
@@ -1074,6 +1100,9 @@ module powerbi.extensibility.visual {
10741100
let oneHourDuration: number = MinutesInAHour;
10751101
let oneMinuteDuration: number = 1;
10761102
switch (durationUnit) {
1103+
case DurationUnits.Hour:
1104+
oneHourDuration = 1;
1105+
break;
10771106
case DurationUnits.Minute:
10781107
oneDayDuration = MinutesInADay;
10791108
break;

test/visualBuilder.ts

+4
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ module powerbi.extensibility.visual.test {
141141
.children("g#legendGroup");
142142
}
143143

144+
public downgradeDurationUnit(tasks: any, durationUnit: string) {
145+
VisualClass.downgradeDurationUnitIfNeed(tasks, durationUnit);
146+
}
147+
144148
public static getSolidColorStructuralObject(color: string): any {
145149
return { solid: { color: color } };
146150
}

test/visualTest.ts

+60
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,32 @@ module powerbi.extensibility.visual.test {
167167
});
168168
});
169169

170+
it("When task duration is float and duration unit 'second', it should be round", (done) => {
171+
defaultDataViewBuilder.valuesDuration = GanttData.getRandomUniqueNumbers(100, 1, 2, false);
172+
dataView = defaultDataViewBuilder.getDataView([
173+
GanttData.ColumnType,
174+
GanttData.ColumnTask,
175+
GanttData.ColumnStartDate,
176+
GanttData.ColumnResource,
177+
GanttData.ColumnCompletePrecntege]);
178+
179+
dataView.metadata.objects = {
180+
general: {
181+
durationUnit: "second"
182+
}
183+
};
184+
185+
visualBuilder.updateRenderTimeout(dataView, () => {
186+
let tasks: Task[] = d3.select(visualBuilder.element.get(0)).selectAll(".task").data();
187+
188+
for (let task of tasks) {
189+
expect(task.duration).toEqual(defaultTaskDuration);
190+
}
191+
192+
done();
193+
});
194+
});
195+
170196
it("When task start time is missing, it should be set to today date", (done) => {
171197
dataView = defaultDataViewBuilder.getDataView([
172198
GanttData.ColumnType,
@@ -687,6 +713,40 @@ module powerbi.extensibility.visual.test {
687713
});
688714

689715
});
716+
717+
describe("Duration units downgrade", () => {
718+
const firstTaskDuration = 4404;
719+
const secondTaskDuration = 1;
720+
const thirdTaskDuration = 1.12;
721+
const secondInHour = 3600;
722+
723+
it("hour to second", done => {
724+
const tasks = [
725+
{
726+
wasDowngradeDurationUnit: true,
727+
stepDurationTransformation: 2,
728+
duration: firstTaskDuration
729+
},
730+
{
731+
wasDowngradeDurationUnit: false,
732+
stepDurationTransformation: 0,
733+
duration: secondTaskDuration
734+
},
735+
{
736+
wasDowngradeDurationUnit: false,
737+
stepDurationTransformation: 0,
738+
duration: thirdTaskDuration
739+
}
740+
];
741+
742+
visualBuilder.downgradeDurationUnit(tasks, "second");
743+
expect(tasks[0].duration).toEqual(firstTaskDuration);
744+
expect(tasks[1].duration).toEqual(Math.floor(secondTaskDuration * secondInHour));
745+
expect(tasks[2].duration).toEqual(Math.floor(thirdTaskDuration * secondInHour));
746+
747+
done();
748+
});
749+
});
690750
});
691751

692752
describe("Days off", () => {

0 commit comments

Comments
 (0)