Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sankey): support trajectory for emphasis state #17451

Merged
merged 7 commits into from
Mar 9, 2023
2 changes: 1 addition & 1 deletion src/chart/sankey/SankeySeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ interface SankeyEdgeStyleOption extends LineStyleOption {

interface ExtraStateOption {
emphasis?: {
focus?: DefaultEmphasisFocus | 'adjacency'
focus?: DefaultEmphasisFocus | 'adjacency' | 'trajectory'
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/chart/sankey/SankeyView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ class SankeyView extends ChartView {
const focus = emphasisModel.get('focus');
toggleHoverEmphasis(
curve,
focus === 'adjacency' ? edge.getAdjacentDataIndices() : focus,
focus === 'adjacency' ? edge.getAdjacentDataIndices()
: focus === 'trajectory' ? edge.getTrajectoryDataIndices()
: focus,
ElayGelbart marked this conversation as resolved.
Show resolved Hide resolved
emphasisModel.get('blurScope'),
emphasisModel.get('disabled')
);
Expand Down Expand Up @@ -293,7 +295,11 @@ class SankeyView extends ChartView {
const focus = emphasisModel.get('focus');
toggleHoverEmphasis(
rect,
focus === 'adjacency' ? node.getAdjacentDataIndices() : focus,
focus === 'adjacency'
? node.getAdjacentDataIndices()
: focus === 'trajectory'
? node.getTrajectoryDataIndices()
: focus,
emphasisModel.get('blurScope'),
emphasisModel.get('disabled')
);
Expand Down
86 changes: 86 additions & 0 deletions src/data/Graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,51 @@ class GraphNode {
}
return dataIndices;
}

getTrajectoryDataIndices(): {node: number[], edge: number[]} {
const connectedEdgesMap = zrUtil.createHashMap<boolean, number>();
const connectedNodesMap = zrUtil.createHashMap<boolean, number>();

for (let i = 0; i < this.edges.length; i++) {
const adjacentEdge = this.edges[i];
if (adjacentEdge.dataIndex < 0) {
continue;
}

connectedEdgesMap.set(adjacentEdge.dataIndex, true);

const sourceNodesQueue = [adjacentEdge.node1];
const targetNodesQueue = [adjacentEdge.node2];

let nodeIteratorIndex = 0;
while (nodeIteratorIndex < sourceNodesQueue.length) {
const sourceNode = sourceNodesQueue[nodeIteratorIndex];
nodeIteratorIndex++;
connectedNodesMap.set(sourceNode.dataIndex, true);

for (let j = 0; j < sourceNode.inEdges.length; j++) {
connectedEdgesMap.set(sourceNode.inEdges[j].dataIndex, true);
sourceNodesQueue.push(sourceNode.inEdges[j].node1);
}
}

nodeIteratorIndex = 0;
while (nodeIteratorIndex < targetNodesQueue.length) {
const targetNode = targetNodesQueue[nodeIteratorIndex];
nodeIteratorIndex++;
connectedNodesMap.set(targetNode.dataIndex, true);
for (let j = 0; j < targetNode.outEdges.length; j++) {
connectedEdgesMap.set(targetNode.outEdges[j].dataIndex, true);
targetNodesQueue.push(targetNode.outEdges[j].node2);
}
}
}

return {
edge: connectedEdgesMap.keys(),
node: connectedNodesMap.keys()
};
}
}


Expand Down Expand Up @@ -429,6 +474,47 @@ class GraphEdge {
node: [this.node1.dataIndex, this.node2.dataIndex]
};
}

getTrajectoryDataIndices(): {node: number[], edge: number[]} {
const connectedEdgesMap = zrUtil.createHashMap<boolean, number>();
const connectedNodesMap = zrUtil.createHashMap<boolean, number>();

connectedEdgesMap.set(this.dataIndex, true);

const sourceNodes = [this.node1];
const targetNodes = [this.node2];

let nodeIteratorIndex = 0;
while (nodeIteratorIndex < sourceNodes.length) {
const sourceNode = sourceNodes[nodeIteratorIndex];
nodeIteratorIndex++;

connectedNodesMap.set(sourceNode.dataIndex, true);

for (let j = 0; j < sourceNode.inEdges.length; j++) {
connectedEdgesMap.set(sourceNode.inEdges[j].dataIndex, true);
sourceNodes.push(sourceNode.inEdges[j].node1);
}
}

nodeIteratorIndex = 0;
while (nodeIteratorIndex < targetNodes.length) {
const targetNode = targetNodes[nodeIteratorIndex];
nodeIteratorIndex++;

connectedNodesMap.set(targetNode.dataIndex, true);

for (let j = 0; j < targetNode.outEdges.length; j++) {
connectedEdgesMap.set(targetNode.outEdges[j].dataIndex, true);
targetNodes.push(targetNode.outEdges[j].node2);
}
}

return {
edge: connectedEdgesMap.keys(),
node: connectedNodesMap.keys()
};
}
}

type GetDataName<Host> = Host extends GraphEdge ? 'edgeData' : 'data';
Expand Down
62 changes: 62 additions & 0 deletions test/sankey-emphasis.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions test/sankey.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.