Skip to content

Commit 237badb

Browse files
committed
feat: (1) Support preserveAspect preserveAspectAlign preserveAspectVerticalAlign for series.map/geo/series.graph in box layout (lay out by left/right/top/bottom/width/height).
(2) Support `clip` on geo/series.map (3) Support `roamTigger: 'global' | 'selfRect'` to switch roam area to global on only self bounding rect. (4) Support cursor style change when hovering the roaming enabled area to hint users. (5) Fix that center and zoom option does not work in series.sankey, and no relevant test case. (the roam is introduced in impl in #20321, due v6). (6) Fix the percent base of `center` (such as `center: ['40%', '50%']`) for all View coord sys based components/series (geo/series.map/series.graph/series.tree/series.sankey). #16904 introcuded percentage string here, such as '33%'. But it was based on canvas width/height, which is not reasonable - the unit may incorrect, and it is unpredictable if the `View['_rect']` is not calculated based on the current canvas rect. Therefore the percentage value is changed to based on `View['_rect'].width/height` since v6. Under this definition, users can use '0%' to map the top-left of `View['_rect']` to the center of `View['_viewRect']`. (7) Enhance the behavior for roaming area overlapping - the upper one has higher precedence. (8) Fix some `scaleLimit` missing. (9) Some refactor and clarification of `RoamController` and `roamHelper`.
1 parent 0661c79 commit 237badb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2289
-531
lines changed

src/action/roamHelper.ts

Lines changed: 0 additions & 92 deletions
This file was deleted.

src/chart/graph/GraphSeries.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ import {
4343
GraphEdgeItemObject,
4444
OptionDataValueNumeric,
4545
CallbackDataParams,
46-
DefaultEmphasisFocus
46+
DefaultEmphasisFocus,
47+
PreserveAspectMixin
4748
} from '../../util/types';
4849
import SeriesModel from '../../model/Series';
4950
import Graph from '../../data/Graph';
@@ -144,7 +145,8 @@ export interface GraphSeriesOption
144145
SeriesOnGeoOptionMixin, SeriesOnSingleOptionMixin,
145146
SymbolOptionMixin<CallbackDataParams>,
146147
RoamOptionMixin,
147-
BoxLayoutOptionMixin {
148+
BoxLayoutOptionMixin,
149+
PreserveAspectMixin {
148150

149151
type?: 'graph'
150152

src/chart/graph/GraphView.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
updateViewOnPan,
2626
RoamControllerHost
2727
} from '../../component/helper/roamHelper';
28-
import {onIrrelevantElement} from '../../component/helper/cursorHelper';
2928
import * as graphic from '../../util/graphic';
3029
import adjustEdge from './adjustEdge';
3130
import {getNodeGlobalScale} from './graphHelper';
@@ -45,6 +44,7 @@ import { simpleLayoutEdge } from './simpleLayoutHelper';
4544
import { circularLayout, rotateNodeLabel } from './circularLayoutHelper';
4645
import { clone, extend } from 'zrender/src/core/util';
4746
import ECLinePath from '../helper/LinePath';
47+
import { NullUndefined } from '../../util/types';
4848

4949
function isViewCoordSys(coordSys: CoordinateSystem): coordSys is View {
5050
return coordSys.type === 'view';
@@ -127,7 +127,7 @@ class GraphView extends ChartView {
127127

128128
this._updateNodeAndLinkScale();
129129

130-
this._updateController(seriesModel, ecModel, api);
130+
this._updateController(null, seriesModel, api);
131131

132132
clearTimeout(this._layoutTimeout);
133133
const forceLayout = seriesModel.forceLayout;
@@ -251,29 +251,29 @@ class GraphView extends ChartView {
251251
}
252252

253253
private _updateController(
254+
clipRect: graphic.BoundingRect | NullUndefined,
254255
seriesModel: GraphSeriesModel,
255-
ecModel: GlobalModel,
256256
api: ExtensionAPI
257257
) {
258258
const controller = this._controller;
259259
const controllerHost = this._controllerHost;
260-
const group = this.group;
261-
262-
controller.setPointerChecker((e, x, y) => {
263-
const rect = group.getBoundingRect();
264-
rect.applyTransform(group.transform);
265-
return rect.contain(x, y)
266-
&& !this._thumbnail.contain(x, y)
267-
&& !onIrrelevantElement(e, api, seriesModel);
268-
});
260+
const coordSys = seriesModel.coordinateSystem;
269261

270-
if (!isViewCoordSys(seriesModel.coordinateSystem)) {
262+
if (!isViewCoordSys(coordSys)) {
271263
controller.disable();
272264
return;
273265
}
274-
controller.enable(seriesModel.get('roam'));
266+
controller.enable(seriesModel.get('roam'), {
267+
api,
268+
zInfo: {component: seriesModel},
269+
triggerInfo: {
270+
roamTrigger: seriesModel.get('roamTrigger'),
271+
isInSelf: (e, x, y) => coordSys.containPoint([x, y]),
272+
isInClip: (e, x, y) => !clipRect || clipRect.contain(x, y),
273+
},
274+
});
275275
controllerHost.zoomLimit = seriesModel.get('scaleLimit');
276-
controllerHost.zoom = seriesModel.coordinateSystem.getZoom();
276+
controllerHost.zoom = coordSys.getZoom();
277277

278278
controller
279279
.off('pan')
@@ -292,6 +292,9 @@ class GraphView extends ChartView {
292292
dx: number,
293293
dy: number
294294
): void {
295+
// FIXME: should do nothing except `api.dispatchAction` here, the other logic
296+
// should be performed in the action handler; otherwise, it causes inconsistency
297+
// if user triggers this action explicitly.
295298
updateViewOnPan(this._controllerHost, dx, dy);
296299
api.dispatchAction({
297300
seriesId: seriesModel.id,
@@ -309,6 +312,9 @@ class GraphView extends ChartView {
309312
originX: number,
310313
originY: number
311314
) {
315+
// FIXME: should do nothing except `api.dispatchAction` here, the other logic
316+
// should be performed in the action handler; otherwise, it causes inconsistency
317+
// if user triggers this action explicitly.
312318
updateViewOnZoom(this._controllerHost, scale, originX, originY);
313319
api.dispatchAction({
314320
seriesId: seriesModel.id,

src/chart/graph/Thumbnail.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import BoundingRect from 'zrender/src/core/BoundingRect';
88
import * as matrix from 'zrender/src/core/matrix';
99
import * as vector from 'zrender/src/core/vector';
1010
import SeriesModel from '../../model/Series';
11-
import { BoxLayoutOptionMixin, ItemStyleOption } from '../../util/types';
12-
import RoamController, { RoamEventDefinition, RoamType } from '../../component/helper/RoamController';
11+
import { BoxLayoutOptionMixin, ItemStyleOption, RoamOptionMixin } from '../../util/types';
12+
import RoamController, { RoamEventDefinition } from '../../component/helper/RoamController';
1313
import Eventful from 'zrender/src/core/Eventful';
1414
import tokens from '../../visual/tokens';
1515

@@ -60,7 +60,7 @@ class Thumbnail extends Eventful<Pick<RoamEventDefinition, 'zoom' | 'pan'>> {
6060
render(opt: {
6161
seriesModel: GraphSeriesModel;
6262
api: ExtensionAPI;
63-
roamType: RoamType;
63+
roamType: RoamOptionMixin['roam'];
6464
z2Setting: ThumbnailZ2Setting;
6565
seriesBoundingRect: BoundingRect,
6666
renderThumbnailContent: (viewGroup: graphic.Group) => void
@@ -85,22 +85,13 @@ class Thumbnail extends Eventful<Pick<RoamEventDefinition, 'zoom' | 'pan'>> {
8585
const itemStyle = itemStyleModel.getItemStyle();
8686
itemStyle.fill = seriesModel.ecModel.get('backgroundColor') || tokens.color.neutral00;
8787

88-
// Try to use border-box in thumbnail, see https://github.com/apache/echarts/issues/18022
89-
const boxBorderWidth = itemStyle.lineWidth || 0;
88+
const refContainer = layout.createBoxLayoutReference(seriesModel, api).refContainer;
9089
const boxContainBorder = layout.getLayoutRect(
91-
{
92-
left: thumbnailModel.get('left', true),
93-
top: thumbnailModel.get('top', true),
94-
right: thumbnailModel.get('right', true),
95-
bottom: thumbnailModel.get('bottom', true),
96-
width: thumbnailModel.get('width', true),
97-
height: thumbnailModel.get('height', true)
98-
},
99-
{
100-
width: api.getWidth(),
101-
height: api.getHeight()
102-
}
90+
layout.getBoxLayoutParams(thumbnailModel, true),
91+
refContainer
10392
);
93+
// Try to use border-box in thumbnail, see https://github.com/apache/echarts/issues/18022
94+
const boxBorderWidth = itemStyle.lineWidth || 0;
10495
const borderBoundingRect = graphic.expandOrShrinkRect(
10596
boxContainBorder.clone(), boxBorderWidth / 2, true, true
10697
);
@@ -155,7 +146,7 @@ class Thumbnail extends Eventful<Pick<RoamEventDefinition, 'zoom' | 'pan'>> {
155146
windowRect.__r = windowStyleModel.get('borderRadius', true);
156147
clipGroup.add(windowRect);
157148

158-
this._resetRoamController(opt.roamType);
149+
this._resetRoamController(opt.roamType, z2Setting.background);
159150

160151
this.updateWindow();
161152
}
@@ -188,14 +179,23 @@ class Thumbnail extends Eventful<Pick<RoamEventDefinition, 'zoom' | 'pan'>> {
188179
this._mtThumbnailToSerise = matrix.invert([], this._mtSeriesToThumbnail);
189180
}
190181

191-
private _resetRoamController(roamType: RoamType): void {
182+
private _resetRoamController(
183+
roamType: RoamOptionMixin['roam'],
184+
z2: number
185+
): void {
192186
let thumbnailController = this._thumbnailController;
193187
if (!thumbnailController) {
194188
thumbnailController = this._thumbnailController = new RoamController(this._api.getZr());
195-
thumbnailController.setPointerChecker((e, x, y) => this.contain(x, y));
196189
}
197190

198-
thumbnailController.enable(roamType);
191+
thumbnailController.enable(roamType, {
192+
api: this._api,
193+
zInfo: {component: this._seriesModel, z2},
194+
triggerInfo: {
195+
roamTrigger: null,
196+
isInSelf: (e, x, y) => this.contain(x, y)
197+
}
198+
});
199199
thumbnailController
200200
.off('pan')
201201
.off('zoom')

src/chart/graph/createView.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
// FIXME Where to create the simple view coordinate system
2121
import View from '../../coord/View';
22-
import {createBoxLayoutReference, getLayoutRect} from '../../util/layout';
22+
import {createBoxLayoutReference, getLayoutRect, applyPreserveAspect} from '../../util/layout';
2323
import * as bbox from 'zrender/src/core/bbox';
2424
import GraphSeriesModel, { GraphNodeItemOption } from './GraphSeries';
2525
import ExtensionAPI from '../../core/ExtensionAPI';
@@ -32,7 +32,8 @@ function getViewRect(seriesModel: GraphSeriesModel, api: ExtensionAPI, aspect: n
3232
const option = extend(seriesModel.getBoxLayoutParams(), {
3333
aspect: aspect
3434
});
35-
return getLayoutRect(option, layoutRef.refContainer);
35+
const viewRect = getLayoutRect(option, layoutRef.refContainer);
36+
return applyPreserveAspect(seriesModel, viewRect, aspect);
3637
}
3738

3839
export default function createViewCoordSys(ecModel: GlobalModel, api: ExtensionAPI) {
@@ -79,7 +80,7 @@ export default function createViewCoordSys(ecModel: GlobalModel, api: ExtensionA
7980
const bbWidth = max[0] - min[0];
8081
const bbHeight = max[1] - min[1];
8182

82-
const viewCoordSys = new View();
83+
const viewCoordSys = new View(null, {api, ecModel});
8384
viewCoordSys.zoomLimit = seriesModel.get('scaleLimit');
8485

8586
viewCoordSys.setBoundingRect(
@@ -90,7 +91,7 @@ export default function createViewCoordSys(ecModel: GlobalModel, api: ExtensionA
9091
);
9192

9293
// Update roam info
93-
viewCoordSys.setCenter(seriesModel.get('center'), {api, ecModel});
94+
viewCoordSys.setCenter(seriesModel.get('center'));
9495
viewCoordSys.setZoom(seriesModel.get('zoom'));
9596

9697
viewList.push(viewCoordSys);

src/chart/graph/install.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import createView from './createView';
2929
import View from '../../coord/View';
3030
import GraphView from './GraphView';
3131
import GraphSeriesModel from './GraphSeries';
32-
import { RoamPayload, updateCenterAndZoom } from '../../action/roamHelper';
32+
import { RoamPayload, updateCenterAndZoomInAction } from '../../component/helper/roamHelper';
3333
import GlobalModel from '../../model/Global';
3434
import { noop } from 'zrender/src/core/util';
3535
import type ExtensionAPI from '../../core/ExtensionAPI';
@@ -79,7 +79,7 @@ export function install(registers: EChartsExtensionInstallRegisters) {
7979
}, function (seriesModel: GraphSeriesModel) {
8080
const coordSys = seriesModel.coordinateSystem as View;
8181

82-
const res = updateCenterAndZoom(coordSys, payload, undefined, api);
82+
const res = updateCenterAndZoomInAction(coordSys, payload, seriesModel.get('scaleLimit'));
8383

8484
seriesModel.setCenter
8585
&& seriesModel.setCenter(res.center);

src/chart/sankey/SankeySeries.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ class SankeySeriesModel extends SeriesModel<SankeySeriesOption> {
317317

318318
// true | false | 'move' | 'scale', see module:component/helper/RoamController.
319319
roam: false,
320+
roamTrigger: 'global',
320321
center: null,
321322
zoom: 1,
322323

0 commit comments

Comments
 (0)