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 roaming #20321

Open
wants to merge 3 commits into
base: v6
Choose a base branch
from
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
14 changes: 12 additions & 2 deletions src/chart/sankey/SankeySeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ import {
GraphEdgeItemObject,
OptionDataValueNumeric,
DefaultEmphasisFocus,
CallbackDataParams
CallbackDataParams,
RoamOptionMixin
} from '../../util/types';
import GlobalModel from '../../model/Global';
import SeriesData from '../../data/SeriesData';
import { LayoutRect } from '../../util/layout';
import { createTooltipMarkup } from '../../component/tooltip/tooltipMarkup';
import View from '../../coord/View';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seem View only used as type



type FocusNodeAdjacency = boolean | 'inEdges' | 'outEdges' | 'allEdges';
Expand Down Expand Up @@ -95,7 +97,8 @@ export interface SankeyLevelOption extends SankeyNodeStateOption, SankeyEdgeStat
export interface SankeySeriesOption
extends SeriesOption<SankeyBothStateOption<CallbackDataParams>, ExtraStateOption>,
SankeyBothStateOption<CallbackDataParams>,
BoxLayoutOptionMixin {
BoxLayoutOptionMixin,
RoamOptionMixin {
type?: 'sankey'

/**
Expand Down Expand Up @@ -148,6 +151,8 @@ class SankeySeriesModel extends SeriesModel<SankeySeriesOption> {
static readonly type = 'series.sankey';
readonly type = SankeySeriesModel.type;

coordinateSystem: View;

levelModels: Model<SankeyLevelOption>[];

layoutInfo: LayoutRect;
Expand Down Expand Up @@ -297,6 +302,11 @@ class SankeySeriesModel extends SeriesModel<SankeySeriesOption> {

layoutIterations: 32,

// true | false | 'move' | 'scale', see module:component/helper/RoamController.
roam: false,
center: null,
zoom: 1,

label: {
show: true,
position: 'right',
Expand Down
71 changes: 71 additions & 0 deletions src/chart/sankey/SankeyView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ 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';
import RoamController from '../../component/helper/RoamController';
// eslint-disable-next-line no-duplicate-imports
import { onIrrelevantElement } from '../../component/helper/cursorHelper';
import * as roamHelper from '../../component/helper/roamHelper';
import View from '../../coord/View';

class SankeyPathShape {
x1 = 0;
Expand Down Expand Up @@ -111,6 +116,17 @@ class SankeyView extends ChartView {

private _data: SeriesData;

private _controller: RoamController;
private _controllerHost: roamHelper.RoamControllerHost;

init(ecModel: GlobalModel, api: ExtensionAPI): void {
this._controller = new RoamController(api.getZr());

this._controllerHost = {
target: this.group
} as roamHelper.RoamControllerHost;
}

render(seriesModel: SankeySeriesModel, ecModel: GlobalModel, api: ExtensionAPI) {
const sankeyView = this;
const graph = seriesModel.getGraph();
Expand All @@ -131,6 +147,14 @@ class SankeyView extends ChartView {
group.x = layoutInfo.x;
group.y = layoutInfo.y;

const viewCoordSys = seriesModel.coordinateSystem = new View();
viewCoordSys.zoomLimit = seriesModel.get('scaleLimit');
viewCoordSys.setBoundingRect(layoutInfo.x, layoutInfo.y, width, height);
viewCoordSys.setCenter(seriesModel.get('center'), api);
viewCoordSys.setZoom(seriesModel.get('zoom'));

this._updateController(seriesModel, ecModel, api);

// generate a bezire Curve for each edge
graph.eachEdge(function (edge) {
const curve = new SankeyPath();
Expand Down Expand Up @@ -346,6 +370,53 @@ class SankeyView extends ChartView {
}

dispose() {
this._controller && this._controller.dispose();
this._controllerHost = null;
}

private _updateController(
seriesModel: SankeySeriesModel,
ecModel: GlobalModel,
api: ExtensionAPI
) {
const controller = this._controller;
const controllerHost = this._controllerHost;
const group = this.group;
controller.setPointerChecker(function (e, x, y) {
const rect = group.getBoundingRect();
rect.applyTransform(group.transform);
return rect.contain(x, y)
&& !onIrrelevantElement(e, api, seriesModel);
});

controller.enable(seriesModel.get('roam'));
controllerHost.zoomLimit = seriesModel.get('scaleLimit');
controllerHost.zoom = seriesModel.coordinateSystem.getZoom();

controller
.off('pan')
.off('zoom')
.on('pan', (e) => {
roamHelper.updateViewOnPan(controllerHost, e.dx, e.dy);
api.dispatchAction({
seriesId: seriesModel.id,
type: 'sankeyRoam',
dx: e.dx,
dy: e.dy
});
})
.on('zoom', (e) => {
roamHelper.updateViewOnZoom(controllerHost, e.scale, e.originX, e.originY);
api.dispatchAction({
seriesId: seriesModel.id,
type: 'sankeyRoam',
zoom: e.scale,
originX: e.originX,
originY: e.originY
});
// Only update label layout on zoom
api.updateLabelLayout();
});
}
}

Expand Down
135 changes: 135 additions & 0 deletions test/sankey-roam.html

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