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): sankey support edgeLabel #16767

Merged
merged 4 commits into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions src/chart/sankey/SankeySeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export interface SankeyEdgeItemOption extends
StatesOptionMixin<SankeyEdgeStateOption, ExtraStateOption>,
GraphEdgeItemObject<OptionDataValueNumeric> {
focusNodeAdjacency?: FocusNodeAdjacency
edgeLabel?: SeriesLabelOption
}

export interface SankeyLevelOption extends SankeyNodeStateOption, SankeyEdgeStateOption {
Expand Down Expand Up @@ -137,6 +138,8 @@ export interface SankeySeriesOption
links?: SankeyEdgeItemOption[]

levels?: SankeyLevelOption[]

edgeLabel?: SeriesLabelOption
}

class SankeySeriesModel extends SeriesModel<SankeySeriesOption> {
Expand Down Expand Up @@ -298,6 +301,12 @@ class SankeySeriesModel extends SeriesModel<SankeySeriesOption> {
fontSize: 12
},

edgeLabel: {
show: false,
position: 'inside',
susiwen8 marked this conversation as resolved.
Show resolved Hide resolved
fontSize: 12
},

levels: [],

nodeAlign: 'justify',
Expand Down
15 changes: 13 additions & 2 deletions src/chart/sankey/SankeyView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class SankeyView extends ChartView {
group.y = layoutInfo.y;

// generate a bezire Curve for each edge
graph.eachEdge(function (edge) {
graph.eachEdge(function (edge, idx) {
const curve = new SankeyPath();
const ecData = getECData(curve);
ecData.dataIndex = edge.dataIndex;
Expand Down Expand Up @@ -193,7 +193,9 @@ class SankeyView extends ChartView {
cpy2: cpy2
});

curve.useStyle(lineStyleModel.getItemStyle());
const style = lineStyleModel.getItemStyle();
curve.useStyle(style);
edgeData.setItemVisual(idx, 'style', style);
susiwen8 marked this conversation as resolved.
Show resolved Hide resolved
// Special color, use source node color or target node color
switch (curve.style.fill) {
case 'source':
Expand All @@ -220,6 +222,15 @@ class SankeyView extends ChartView {
}
}

setLabelStyle(
susiwen8 marked this conversation as resolved.
Show resolved Hide resolved
curve, getLabelStatesModels(edgeModel, 'edgeLabel'),
{
labelFetcher: seriesModel,
labelDataIndex: edge.dataIndex,
defaultText: `${edgeModel.get('value')}`
susiwen8 marked this conversation as resolved.
Show resolved Hide resolved
}
);

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

setStatesStylesFromModel(curve, edgeModel, 'lineStyle', (model) => model.getItemStyle());
Expand Down
6 changes: 6 additions & 0 deletions test/sankey-depth.html

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