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/graph/GraphSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export interface GraphNodeStateOption<TCbParams = never> {


interface ExtraEmphasisState {
focus?: DefaultEmphasisFocus | 'adjacency'
focus?: DefaultEmphasisFocus | 'adjacency' | 'trajectory'
ElayGelbart marked this conversation as resolved.
Show resolved Hide resolved
}
interface GraphNodeStatesMixin {
emphasis?: ExtraEmphasisState
Expand Down
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
8 changes: 6 additions & 2 deletions src/chart/sankey/SankeyView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ class SankeyView extends ChartView {
const focus = emphasisModel.get('focus');
toggleHoverEmphasis(
curve,
focus === 'adjacency' ? edge.getAdjacentDataIndices() : focus,
focus === 'adjacency' ? edge.getAdjacentDataIndices()
: focus === 'trajectory' ? edge.getFullPathDataIndices()
: focus,
ElayGelbart marked this conversation as resolved.
Show resolved Hide resolved
ElayGelbart marked this conversation as resolved.
Show resolved Hide resolved
emphasisModel.get('blurScope'),
emphasisModel.get('disabled')
);
Expand Down Expand Up @@ -283,7 +285,9 @@ class SankeyView extends ChartView {
const focus = emphasisModel.get('focus');
toggleHoverEmphasis(
rect,
focus === 'adjacency' ? node.getAdjacentDataIndices() : focus,
focus === 'adjacency' ? node.getAdjacentDataIndices()
: focus === 'trajectory' ? node.getFullPathDataIndices()
: focus,
ElayGelbart marked this conversation as resolved.
Show resolved Hide resolved
emphasisModel.get('blurScope'),
emphasisModel.get('disabled')
);
Expand Down
77 changes: 77 additions & 0 deletions src/data/Graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,49 @@ class GraphNode {
}
return dataIndices;
}

getFullPathDataIndices(): {node: number[], edge: number[]} {
ElayGelbart marked this conversation as resolved.
Show resolved Hide resolved
const dataIndices = {
edge: [] as number[],
node: [] as number[]
};

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

zrUtil.indexOf(dataIndices.edge, adjacentEdge.dataIndex) < 0
? dataIndices.edge.push(adjacentEdge.dataIndex) : null;
ElayGelbart marked this conversation as resolved.
Show resolved Hide resolved
ElayGelbart marked this conversation as resolved.
Show resolved Hide resolved
const sourceNodesQueue = [adjacentEdge.node1];
const targetNodesQueue = [adjacentEdge.node2];

while (sourceNodesQueue.length > 0) {
const sourceNode = sourceNodesQueue.shift();
dataIndices.node.indexOf(sourceNode.dataIndex) === -1
? dataIndices.node.push(sourceNode.dataIndex) : null;
for (let j = 0; j < sourceNode.inEdges.length; j++) {
dataIndices.edge.indexOf(sourceNode.inEdges[j].dataIndex) === -1
? dataIndices.edge.push(sourceNode.inEdges[j].dataIndex) : null;
sourceNodesQueue.push(sourceNode.inEdges[j].node1);
}
}

while (targetNodesQueue.length > 0) {
const targetNode = targetNodesQueue.shift();
dataIndices.node.indexOf(targetNode.dataIndex) === -1
? dataIndices.node.push(targetNode.dataIndex) : null;
for (let j = 0; j < targetNode.outEdges.length; j++) {
dataIndices.edge.indexOf(targetNode.outEdges[j].dataIndex) === -1
? dataIndices.edge.push(targetNode.outEdges[j].dataIndex) : null;
targetNodesQueue.push(targetNode.outEdges[j].node2);
}
}
}

return dataIndices;
}
}


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

getFullPathDataIndices(): {node: number[], edge: number[]} {
ElayGelbart marked this conversation as resolved.
Show resolved Hide resolved
const dataIndices = {
ElayGelbart marked this conversation as resolved.
Show resolved Hide resolved
edge: [] as number[],
node: [] as number[]
};

dataIndices.edge.push(this.dataIndex);
const sourceNodes = [this.node1];
const targetNodes = [this.node2];

while (sourceNodes.length > 0) {
const sourceNode = sourceNodes.shift();
dataIndices.node.indexOf(sourceNode.dataIndex) === -1 ? dataIndices.node.push(sourceNode.dataIndex) : null;
for (let j = 0; j < sourceNode.inEdges.length; j++) {
dataIndices.edge.indexOf(sourceNode.inEdges[j].dataIndex) === -1
? dataIndices.edge.push(sourceNode.inEdges[j].dataIndex) : null;
sourceNodes.push(sourceNode.inEdges[j].node1);
}
}

while (targetNodes.length > 0) {
const targetNode = targetNodes.shift();
dataIndices.node.indexOf(targetNode.dataIndex) === -1
? dataIndices.node.push(targetNode.dataIndex) : null;
for (let j = 0; j < targetNode.outEdges.length; j++) {
dataIndices.edge.indexOf(targetNode.outEdges[j].dataIndex) === -1
? dataIndices.edge.push(targetNode.outEdges[j].dataIndex) : null;
targetNodes.push(targetNode.outEdges[j].node2);
}
}

return dataIndices;
}
}

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

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