Skip to content
Open
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
35 changes: 35 additions & 0 deletions src/chart/sankey/SankeySeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
* under the License.
*/

import { extend, isString } from 'zrender/src/core/util';
import SeriesModel from '../../model/Series';
import { getDecalFromPalette } from '../../model/mixin/palette';
import createGraphFromNodeEdge from '../helper/createGraphFromNodeEdge';
import Model from '../../model/Model';
import {
Expand All @@ -29,6 +31,8 @@ import {
LineStyleOption,
LayoutOrient,
ColorString,
InnerDecalObject,
ZRColor,
StatesOptionMixin,
OptionDataItemObject,
GraphEdgeItemObject,
Expand Down Expand Up @@ -251,6 +255,37 @@ class SankeySeriesModel extends SeriesModel<SankeySeriesOption> implements RoamH
return this.getGraph().edgeData;
}

enableAriaDecal() {
const graph = this.getGraph();
const scope = {};
const decalForColor = (color: ZRColor, fallback: string) => {
const decal: InnerDecalObject = getDecalFromPalette(
this.ecModel, isString(color) ? 'color:' + color : fallback, scope
);
if (decal) {
decal.dirty = true;
}
return decal;
};

graph.eachNode(node => {
// Sankey colors come from flow values, levels or individual node options.
const paletteDecal = decalForColor(node.getVisual('color'), 'node:' + node.id);
const specifiedDecal = node.getModel<SankeyNodeItemOption>().get(['itemStyle', 'decal']);
node.setVisual('decal', specifiedDecal && specifiedDecal !== 'none'
? extend(extend({}, paletteDecal), specifiedDecal) : specifiedDecal || paletteDecal);
});

graph.eachEdge(edge => {
const color = edge.getModel<SankeyEdgeItemOption>().get(['lineStyle', 'color']);
// Source and target links already inherit the node's rendered pattern.
// A gradient interpolates between two colors and has no single color key.
if (color && color !== 'source' && color !== 'target' && color !== 'gradient') {
edge.setVisual('decal', decalForColor(color, 'edge:' + edge.dataIndex));
}
});
}

formatTooltip(
dataIndex: number,
multipleSeries: boolean,
Expand Down
5 changes: 5 additions & 0 deletions src/chart/sankey/SankeyView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import * as graphic from '../../util/graphic';
import { createOrUpdatePatternFromDecal } from '../../util/decal';
import { enterEmphasis, leaveEmphasis, toggleHoverEmphasis, setStatesStylesFromModel } from '../../util/states';
import { LayoutOrient, ECElement, RoamHostView, RoamPayload } from '../../util/types';
import type { PathProps, PathStyleProps } from 'zrender/src/graphic/Path';
Expand Down Expand Up @@ -216,6 +217,10 @@ class SankeyView extends ChartView implements RoamHostView {
});

curve.useStyle(lineStyleModel.getItemStyle());
const decal = edge.getVisual('decal');
if (decal) {
curve.style.decal = createOrUpdatePatternFromDecal(decal, api);
}
// Special color, use source node color or target node color
applyCurveStyle(curve.style, orient, edge);

Expand Down
82 changes: 82 additions & 0 deletions test/ut/spec/series/sankey-decal.test.ts

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