Skip to content

Commit 817ef5c

Browse files
authored
Merge pull request #20402 from apache/feat-compoundPath
feat(custom): support compoundPath in custom series renderItem
2 parents 6639b23 + 9fb4073 commit 817ef5c

File tree

3 files changed

+69
-7
lines changed

3 files changed

+69
-7
lines changed

src/animation/customGraphicTransition.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,24 @@ export function applyUpdateTransition(
149149
const propsToSet = {} as ElementProps;
150150

151151
prepareTransformAllPropsFinal(el, elOption, propsToSet);
152-
prepareShapeOrExtraAllPropsFinal('shape', elOption, propsToSet);
153-
prepareShapeOrExtraAllPropsFinal('extra', elOption, propsToSet);
152+
153+
if (el.type === 'compound') {
154+
/**
155+
* We cannot directly clone shape for compoundPath,
156+
* because it makes the path to be an object instead of a Path instance,
157+
* and thus missing `buildPath` method.
158+
*/
159+
const paths: Path[] = (el as Path).shape.paths;
160+
const optionPaths = elOption.shape.paths as TransitionElementOption['shape']['paths'];
161+
for (let i = 0; i < optionPaths.length; i++) {
162+
const path = optionPaths[i];
163+
prepareShapeOrExtraAllPropsFinal('shape', path, paths[i]);
164+
}
165+
}
166+
else {
167+
prepareShapeOrExtraAllPropsFinal('shape', elOption, propsToSet);
168+
prepareShapeOrExtraAllPropsFinal('extra', elOption, propsToSet);
169+
}
154170

155171
if (!isInit && hasAnimation) {
156172
prepareTransformTransitionFrom(el, elOption, transFromProps);

src/chart/custom/CustomSeries.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,24 @@ export interface CustomTextOption extends CustomDisplayableOption, TransitionOpt
234234
keyframeAnimation?: ElementKeyframeAnimationOption<TextProps> | ElementKeyframeAnimationOption<TextProps>[]
235235
}
236236

237+
export interface CustomompoundPathOptionOnState extends CustomDisplayableOptionOnState {
238+
style?: PathStyleProps;
239+
}
240+
export interface CustomCompoundPathOption extends CustomDisplayableOption, TransitionOptionMixin<PathProps> {
241+
type: 'compoundPath';
242+
shape?: PathProps['shape'];
243+
style?: PathStyleProps & TransitionOptionMixin<PathStyleProps>;
244+
emphasis?: CustomompoundPathOptionOnState;
245+
blur?: CustomompoundPathOptionOnState;
246+
select?: CustomompoundPathOptionOnState;
247+
248+
keyframeAnimation?: ElementKeyframeAnimationOption<PathProps> | ElementKeyframeAnimationOption<PathProps>[]
249+
}
250+
237251
export type CustomElementOption = CustomPathOption
238252
| CustomImageOption
239253
| CustomTextOption
254+
| CustomCompoundPathOption
240255
| CustomGroupOption;
241256

242257
// Can only set focus, blur on the root element.

src/chart/custom/CustomView.ts

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
*/
1919

2020
import {
21-
hasOwn, assert, isString, retrieve2, retrieve3, defaults, each, indexOf
21+
hasOwn, assert, isString, retrieve2, retrieve3, defaults, each, indexOf,
22+
map
2223
} from 'zrender/src/core/util';
2324
import * as graphicUtil from '../../util/graphic';
2425
import { setDefaultStateProxy, toggleHoverEmphasis } from '../../util/states';
@@ -56,7 +57,7 @@ import ExtensionAPI from '../../core/ExtensionAPI';
5657
import Displayable from 'zrender/src/graphic/Displayable';
5758
import Axis2D from '../../coord/cartesian/Axis2D';
5859
import { RectLike } from 'zrender/src/core/BoundingRect';
59-
import { PathStyleProps } from 'zrender/src/graphic/Path';
60+
import Path, { PathStyleProps } from 'zrender/src/graphic/Path';
6061
import { TextStyleProps } from 'zrender/src/graphic/Text';
6162
import {
6263
convertToEC4StyleForCustomSerise,
@@ -87,7 +88,8 @@ import CustomSeriesModel, {
8788
PrepareCustomInfo,
8889
CustomPathOption,
8990
CustomRootElementOption,
90-
CustomSeriesOption
91+
CustomSeriesOption,
92+
CustomCompoundPathOption
9193
} from './CustomSeries';
9294
import { PatternObject } from 'zrender/src/graphic/Pattern';
9395
import {
@@ -352,7 +354,36 @@ function createEl(elOption: CustomElementOption): Element {
352354
el = new graphicUtil.Group();
353355
}
354356
else if (graphicType === 'compoundPath') {
355-
throw new Error('"compoundPath" is not supported yet.');
357+
const shape = (elOption as CustomCompoundPathOption).shape;
358+
if (!shape || !shape.paths) {
359+
let errMsg = '';
360+
if (__DEV__) {
361+
errMsg = 'shape.paths must be specified in compoundPath';
362+
}
363+
throwError(errMsg);
364+
}
365+
const paths = map(shape.paths as Path[], function (path) {
366+
if (path.type === 'path') {
367+
return graphicUtil.makePath(path.shape.pathData, path, null);
368+
}
369+
const Clz = graphicUtil.getShapeClass(path.type);
370+
if (!Clz) {
371+
if (typeof path.buildPath === 'function') {
372+
return path;
373+
}
374+
let errMsg = '';
375+
if (__DEV__) {
376+
errMsg = 'graphic type "' + graphicType + '" can not be found.';
377+
}
378+
throwError(errMsg);
379+
}
380+
return new Clz();
381+
});
382+
el = new graphicUtil.CompoundPath({
383+
shape: {
384+
paths
385+
}
386+
});
356387
}
357388
else {
358389
const Clz = graphicUtil.getShapeClass(graphicType);
@@ -1148,7 +1179,7 @@ function doCreateOrUpdateAttachedTx(
11481179
attachedTxInfo: AttachedTxInfo
11491180
): void {
11501181
// Group does not support textContent temporarily until necessary.
1151-
if (el.isGroup) {
1182+
if (el.isGroup || el.type === 'compoundPath') {
11521183
return;
11531184
}
11541185

0 commit comments

Comments
 (0)