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

fix(sankey): fix sankey line color 'target'/'source'/'gradient' doesn't work in non-normal state #18834

Merged
merged 2 commits into from
Jul 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 44 additions & 26 deletions src/chart/sankey/SankeyView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import * as graphic from '../../util/graphic';
import { enterEmphasis, leaveEmphasis, toggleHoverEmphasis, setStatesStylesFromModel } from '../../util/states';
import { LayoutOrient, ECElement } from '../../util/types';
import { PathProps } from 'zrender/src/graphic/Path';
import type { PathProps, PathStyleProps } from 'zrender/src/graphic/Path';
import SankeySeriesModel, { SankeyEdgeItemOption, SankeyNodeItemOption } from './SankeySeries';
import ChartView from '../../view/Chart';
import GlobalModel from '../../model/Global';
Expand All @@ -30,6 +30,7 @@ import { RectLike } from 'zrender/src/core/BoundingRect';
import { setLabelStyle, getLabelStatesModels } from '../../label/labelStyle';
import { getECData } from '../../util/innerStore';
import { isString, retrieve3 } from 'zrender/src/core/util';
import type { GraphEdge } from '../../data/Graph';

class SankeyPathShape {
x1 = 0;
Expand Down Expand Up @@ -195,30 +196,8 @@ class SankeyView extends ChartView {

curve.useStyle(lineStyleModel.getItemStyle());
// Special color, use source node color or target node color
switch (curve.style.fill) {
case 'source':
curve.style.fill = edge.node1.getVisual('color');
curve.style.decal = edge.node1.getVisual('style').decal;
break;
case 'target':
curve.style.fill = edge.node2.getVisual('color');
curve.style.decal = edge.node2.getVisual('style').decal;
break;
case 'gradient':
const sourceColor = edge.node1.getVisual('color');
const targetColor = edge.node2.getVisual('color');
if (isString(sourceColor) && isString(targetColor)) {
curve.style.fill = new graphic.LinearGradient(
0, 0, +(orient === 'horizontal'), +(orient === 'vertical'), [{
color: sourceColor,
offset: 0
}, {
color: targetColor,
offset: 1
}]
);
}
}
applyCurveStyle(curve.style, orient, edge);


const defaultEdgeLabelText = `${edgeModel.get('value')}`;
const edgeLabelStateModels = getLabelStatesModels(edgeModel, 'edgeLabel');
Expand Down Expand Up @@ -250,7 +229,13 @@ class SankeyView extends ChartView {

const emphasisModel = edgeModel.getModel('emphasis');

setStatesStylesFromModel(curve, edgeModel, 'lineStyle', (model) => model.getItemStyle());
setStatesStylesFromModel(curve, edgeModel, 'lineStyle', (model) => {
const style = model.getItemStyle();

applyCurveStyle(style, orient, edge);

return style;
});

group.add(curve);

Expand Down Expand Up @@ -362,6 +347,39 @@ class SankeyView extends ChartView {
}
}

/**
* Special color, use source node color or target node color
* @param curveProps curve's style to parse
* @param orient direction
* @param edge current curve data
*/
function applyCurveStyle(curveProps: PathStyleProps, orient: 'horizontal' | 'vertical', edge: GraphEdge) {
switch (curveProps.fill) {
case 'source':
curveProps.fill = edge.node1.getVisual('color');
curveProps.decal = edge.node1.getVisual('style').decal;
break;
case 'target':
curveProps.fill = edge.node2.getVisual('color');
curveProps.decal = edge.node2.getVisual('style').decal;
break;
case 'gradient':
const sourceColor = edge.node1.getVisual('color');
const targetColor = edge.node2.getVisual('color');
if (isString(sourceColor) && isString(targetColor)) {
curveProps.fill = new graphic.LinearGradient(
0, 0, +(orient === 'horizontal'), +(orient === 'vertical'), [{
color: sourceColor,
offset: 0
}, {
color: targetColor,
offset: 1
}]
);
}
}
}

// Add animation to the view
function createGridClipShape(rect: RectLike, seriesModel: SankeySeriesModel, cb: () => void) {
const rectEl = new graphic.Rect({
Expand Down
1 change: 1 addition & 0 deletions test/runTest/actions/__meta__.json

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

1 change: 1 addition & 0 deletions test/runTest/actions/sankey-emphasis-lineStyle.json

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

98 changes: 98 additions & 0 deletions test/sankey-emphasis-lineStyle.html

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