Skip to content

Commit 7561513

Browse files
zBritvaignatvilesov
authored andcommitted
Fix restoring settings when data set was filtered (#25)
Fix links labels for graph with cycles Fix saving settings for graph with cycles
1 parent c6188f6 commit 7561513

4 files changed

Lines changed: 50 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 1.4.1
2+
3+
* Fix restoring settings when data set was filtered
4+
* Fix links labels for graph with cycles
5+
* Fix saving settings for graph with cycles
6+
17
## 1.4.0
28

39
* Feature to move nodes to any place in the viewport

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "powerbi-visuals-sankey",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"description": "Sankey is a type of flow diagram in which the width of the series is in proportion to the quantity of the flow. Use it to find major contributions to an overall flow.",
55
"repository": {
66
"type": "git",

pbiviz.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"visual": {
33
"name": "SankeyDiagram",
4-
"displayName": "Sankey 1.4.0",
4+
"displayName": "Sankey 1.4.1",
55
"guid": "SankeyDiagram1446463184954",
66
"visualClassName": "SankeyDiagram",
7-
"version": "1.4.0",
7+
"version": "1.4.1",
88
"description": "Sankey is a type of flow diagram in which the width of the series is in proportion to the quantity of the flow. Use it to find major contributions to an overall flow.",
99
"supportUrl": "http://community.powerbi.com",
1010
"gitHubUrl": "https://github.com/Microsoft/powerbi-visuals-sankey"

src/visual.ts

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,10 @@ module powerbi.extensibility.visual {
364364

365365
let cycles: SankeyDiagramCycleDictionary = this.checkCycles(nodes);
366366

367-
links = this.processCycles(cycles, nodes, links);
367+
links = this.processCycles(cycles, nodes, links, settings);
368+
369+
this.checkNodePositionSettings(nodes, settings);
370+
this.restoreNodePositions(nodes, settings);
368371

369372
return {
370373
nodes,
@@ -375,7 +378,7 @@ module powerbi.extensibility.visual {
375378
}
376379

377380
// in this method we breaking simple cycles for typical displaying with twice rendering onr node in cycle
378-
private processCycles(cycles: SankeyDiagramCycleDictionary, nodes: SankeyDiagramNode[], links: SankeyDiagramLink[]): SankeyDiagramLink[] {
381+
private processCycles(cycles: SankeyDiagramCycleDictionary, nodes: SankeyDiagramNode[], links: SankeyDiagramLink[], settings: SankeyDiagramSettings): SankeyDiagramLink[] {
379382
let createdNodes: SankeyDiagramNode[] = [];
380383
for (let nodeName in cycles) {
381384
let firstCyclesNode: SankeyDiagramNode = (cycles[nodeName].filter((node: SankeyDiagramNode): boolean => {
@@ -426,6 +429,33 @@ module powerbi.extensibility.visual {
426429
return links;
427430
}
428431

432+
private checkNodePositionSettings(nodes: SankeyDiagramNode[], settings: SankeyDiagramSettings) {
433+
let nodePositions: SankeyDiagramNodePositionSetting[] = settings._nodePositions;
434+
435+
nodePositions.forEach((position: SankeyDiagramNodePositionSetting) => {
436+
let check: boolean = nodes.some((node: SankeyDiagramNode) => {
437+
if (node.label.name === position.name) {
438+
return true;
439+
}
440+
441+
return false;
442+
});
443+
444+
// if check failed then reset positions
445+
if (!check) {
446+
settings.nodeComplexSettings.nodePositions = "{}";
447+
settings._nodePositions = [];
448+
}
449+
});
450+
}
451+
452+
private restoreNodePositions(nodes: SankeyDiagramNode[], settings: SankeyDiagramSettings) {
453+
nodes.forEach( (node: SankeyDiagramNode) => {
454+
let nodeSettings: SankeyDiagramNodePositionSetting = this.getNodeSettings(node.label.name, settings);
455+
node.settings = nodeSettings;
456+
});
457+
}
458+
429459
// remove dublicated links
430460
private static fixLinksCount(node: SankeyDiagramNode) {
431461
node.links = _.uniq(node.links);
@@ -549,8 +579,6 @@ module powerbi.extensibility.visual {
549579
color: settings.labels.fill
550580
};
551581

552-
let nodeSettings: SankeyDiagramNodePositionSetting = this.getNodeSettings(item, settings);
553-
554582
nodes.push({
555583
label: label,
556584
links: [],
@@ -561,7 +589,7 @@ module powerbi.extensibility.visual {
561589
colour: this.colorPalette.getColor(index.toString()).value,
562590
tooltipInfo: [],
563591
selectableDataPoints: [],
564-
settings: nodeSettings
592+
settings: null
565593
});
566594
});
567595

@@ -700,12 +728,12 @@ module powerbi.extensibility.visual {
700728
}
701729

702730
private getNodeSettings(
703-
internalName: string,
731+
name: string,
704732
settings: SankeyDiagramSettings): SankeyDiagramNodePositionSetting {
705733

706734
let setting: SankeyDiagramNodePositionSetting = null;
707735
settings._nodePositions.some( (nodePositions: SankeyDiagramNodePositionSetting) => {
708-
if (nodePositions.name === internalName) {
736+
if (nodePositions.name === name) {
709737
setting = nodePositions;
710738
return true;
711739
}
@@ -1341,13 +1369,13 @@ module powerbi.extensibility.visual {
13411369
node.settings = {
13421370
x: node.x.toFixed(2),
13431371
y: node.y.toFixed(2),
1344-
name: node.label.internalName
1372+
name: node.label.name
13451373
};
13461374

13471375
// Update each link related with this node
13481376
node.links.forEach( (link: SankeyDiagramLink) => {
13491377
// select link svg element by ID generated in link creation as Source-Destination
1350-
d3.select(`#${(link.source.label.internalName || "").replace(/\W*/g,"")}-${(link.destination.label.internalName || "").replace(/\W*/g,"")}`).attr({
1378+
d3.select(`#${(link.source.label.name || "").replace(/\W*/g,"")}-${(link.destination.label.name || "").replace(/\W*/g,"")}`).attr({
13511379
// get updated path params based on actual positions of node
13521380
d: sankeyVisual.getSvgPath(link)
13531381
});
@@ -1400,7 +1428,7 @@ module powerbi.extensibility.visual {
14001428
return;
14011429
}
14021430
let settings: SankeyDiagramNodePositionSetting = <SankeyDiagramNodePositionSetting>{
1403-
name: node.label.internalName,
1431+
name: node.label.name,
14041432
x: node.x.toFixed(0),
14051433
y: node.y.toFixed(0)
14061434
};
@@ -1468,7 +1496,7 @@ module powerbi.extensibility.visual {
14681496
d: (link: SankeyDiagramLink) => {
14691497
return this.getSvgPath(link);
14701498
},
1471-
id: (link: SankeyDiagramLink) => `${(link.source.label.internalName || "").replace(/\W*/g,"")}-${(link.destination.label.internalName || "").replace(/\W*/g,"")}`
1499+
id: (link: SankeyDiagramLink) => `${(link.source.label.name || "").replace(/\W*/g,"")}-${(link.destination.label.name || "").replace(/\W*/g,"")}`
14721500
})
14731501
.style({
14741502
"stroke-width": (link: SankeyDiagramLink) => link.height < SankeyDiagram.MinWidthOfLink ? SankeyDiagram.MinWidthOfLink : link.height,
@@ -1518,7 +1546,7 @@ module powerbi.extensibility.visual {
15181546
d: (link: SankeyDiagramLink) => {
15191547
return this.getSvgPath(link);
15201548
},
1521-
id: (link: SankeyDiagramLink) => `${(link.source.label.internalName || "").replace(/\W*/g,"")}-${(link.destination.label.internalName || "").replace(/\W*/g,"")}`
1549+
id: (link: SankeyDiagramLink) => `${(link.source.label.name || "").replace(/\W*/g,"")}-${(link.destination.label.name || "").replace(/\W*/g,"")}`
15221550
});
15231551

15241552
linkLabelPathsSelection
@@ -1549,7 +1577,7 @@ module powerbi.extensibility.visual {
15491577
textPathSelection
15501578
.attr({
15511579
startOffset: "50%",
1552-
href: (link: SankeyDiagramLink) => `#${(link.source.label.internalName || "").replace(/\W*/g,"")}-${(link.destination.label.internalName || "").replace(/\W*/g,"")}`
1580+
href: (link: SankeyDiagramLink) => `#${(link.source.label.name || "").replace(/\W*/g,"")}-${(link.destination.label.name || "").replace(/\W*/g,"")}`
15531581
})
15541582
.style({
15551583
"font-size": this.dataView.settings.linkLabels.fontSize,

0 commit comments

Comments
 (0)