Skip to content

fix 20813 for custom charts added an option to use legend by category… #20827

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
19 changes: 19 additions & 0 deletions src/chart/custom/CustomSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ import {
import { TransformProp } from 'zrender/src/core/Transformable';
import { ElementKeyframeAnimationOption } from '../../animation/customGraphicKeyframeAnimation';

import * as zrUtil from 'zrender/src/core/util';
import LegendVisualProvider from '../../visual/LegendVisualProvider';

export type CustomExtraElementInfo = Dictionary<unknown>;

// Also compat with ec4, where
Expand Down Expand Up @@ -329,6 +332,7 @@ export interface CustomSeriesOption extends
SeriesOnCalendarOptionMixin {

type?: 'custom'
useLegendByCategory?: boolean;

// If set as 'none', do not depends on coord sys.
coordinateSystem?: string | 'none';
Expand Down Expand Up @@ -375,6 +379,21 @@ export const customInnerStore = makeInner<{
export default class CustomSeriesModel extends SeriesModel<CustomSeriesOption> {

static type = 'series.custom';
/**
* @overwrite
*/
init(option: CustomSeriesOption): void {
super.init.apply(this, arguments as any);

if (option.useLegendByCategory) {
// Enable legend selection for each data item
// Use a function instead of direct access because data reference may changed
this.legendVisualProvider = new LegendVisualProvider(
zrUtil.bind(this.getData, this), zrUtil.bind(this.getRawData, this)
);
}
}

readonly type = CustomSeriesModel.type;

static dependencies = ['grid', 'polar', 'geo', 'singleAxis', 'calendar'];
Expand Down