Skip to content

Commit

Permalink
feat(custom): support compoundPath in custom series
Browse files Browse the repository at this point in the history
  • Loading branch information
Ovilia committed Oct 8, 2024
1 parent 6639b23 commit 7714361
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
15 changes: 15 additions & 0 deletions src/chart/custom/CustomSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,24 @@ export interface CustomTextOption extends CustomDisplayableOption, TransitionOpt
keyframeAnimation?: ElementKeyframeAnimationOption<TextProps> | ElementKeyframeAnimationOption<TextProps>[]
}

export interface CustomompoundPathOptionOnState extends CustomDisplayableOptionOnState {
style?: PathStyleProps;
}
export interface CustomCompoundPathOption extends CustomDisplayableOption, TransitionOptionMixin<PathProps> {
type: 'compoundPath';
shape?: PathProps['shape'];
style?: PathStyleProps & TransitionOptionMixin<PathStyleProps>;
emphasis?: CustomompoundPathOptionOnState;
blur?: CustomompoundPathOptionOnState;
select?: CustomompoundPathOptionOnState;

keyframeAnimation?: ElementKeyframeAnimationOption<PathProps> | ElementKeyframeAnimationOption<PathProps>[]
}

export type CustomElementOption = CustomPathOption
| CustomImageOption
| CustomTextOption
| CustomCompoundPathOption
| CustomGroupOption;

// Can only set focus, blur on the root element.
Expand Down
34 changes: 30 additions & 4 deletions src/chart/custom/CustomView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*/

import {
hasOwn, assert, isString, retrieve2, retrieve3, defaults, each, indexOf
hasOwn, assert, isString, retrieve2, retrieve3, defaults, each, indexOf,
map
} from 'zrender/src/core/util';
import * as graphicUtil from '../../util/graphic';
import { setDefaultStateProxy, toggleHoverEmphasis } from '../../util/states';
Expand Down Expand Up @@ -54,6 +55,7 @@ import SeriesData, { DefaultDataVisual } from '../../data/SeriesData';
import GlobalModel from '../../model/Global';
import ExtensionAPI from '../../core/ExtensionAPI';
import Displayable from 'zrender/src/graphic/Displayable';
import Path from 'zrender/src/graphic/Path';
import Axis2D from '../../coord/cartesian/Axis2D';
import { RectLike } from 'zrender/src/core/BoundingRect';
import { PathStyleProps } from 'zrender/src/graphic/Path';
Expand Down Expand Up @@ -87,7 +89,8 @@ import CustomSeriesModel, {
PrepareCustomInfo,
CustomPathOption,
CustomRootElementOption,
CustomSeriesOption
CustomSeriesOption,
CustomCompoundPathOption
} from './CustomSeries';
import { PatternObject } from 'zrender/src/graphic/Pattern';
import {
Expand Down Expand Up @@ -352,7 +355,30 @@ function createEl(elOption: CustomElementOption): Element {
el = new graphicUtil.Group();
}
else if (graphicType === 'compoundPath') {
throw new Error('"compoundPath" is not supported yet.');
const shape = (elOption as CustomCompoundPathOption).shape;
if (!shape || !shape.paths) {
let errMsg = '';
if (__DEV__) {
errMsg = 'shape.paths must be specified in compoundPath';
}
throwError(errMsg);
}
const paths = map(shape.paths as Path[], function (path) {
const Clz = graphicUtil.getShapeClass(path.type);
if (!Clz) {
let errMsg = '';
if (__DEV__) {
errMsg = 'graphic type "' + graphicType + '" can not be found.';
}
throwError(errMsg);
}
return new Clz();
});
el = new graphicUtil.CompoundPath({
shape: {
paths
}
});
}
else {
const Clz = graphicUtil.getShapeClass(graphicType);
Expand Down Expand Up @@ -1148,7 +1174,7 @@ function doCreateOrUpdateAttachedTx(
attachedTxInfo: AttachedTxInfo
): void {
// Group does not support textContent temporarily until necessary.
if (el.isGroup) {
if (el.isGroup || el.type === 'compoundPath') {
return;
}

Expand Down

0 comments on commit 7714361

Please sign in to comment.