Skip to content

Commit

Permalink
fix(custom): use renderItem as registered custom name
Browse files Browse the repository at this point in the history
  • Loading branch information
Ovilia committed Aug 8, 2024
1 parent 197bacd commit 25132fd
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 36 deletions.
17 changes: 0 additions & 17 deletions src/chart/custom/CustomSeriesManager.ts

This file was deleted.

17 changes: 12 additions & 5 deletions src/chart/custom/CustomView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,11 +591,18 @@ function makeRenderItem(
ecModel: GlobalModel,
api: ExtensionAPI
) {
const type = customSeries.get('type').split('.');
const customRenderer = type.length > 1
? ecModel.getCustomRenderer(type[1])
: null;
const renderItem = customRenderer || customSeries.get('renderItem');
let renderItem = customSeries.get('renderItem');
if (typeof renderItem === 'string') {
// Find renderItem in registered custom series
const registeredRenderItem = ecModel.getCustomRenderer(renderItem);
if (registeredRenderItem) {
renderItem = registeredRenderItem;
}
else if (__DEV__) {
console.warn(`Custom series renderItem '${renderItem}' not found.
Call 'echarts.registerCustomSeries' to register it.`);
}
}
const coordSys = customSeries.coordinateSystem;
let prepareResult = {} as ReturnType<PrepareCustomInfo>;

Expand Down
4 changes: 2 additions & 2 deletions src/core/echarts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ import lifecycle, {
import { platformApi, setPlatformAPI } from 'zrender/src/core/platform';
import { getImpl } from './impl';
import type geoSourceManager from '../coord/geo/geoSourceManager';
import CustomSeriesManager from '../chart/custom/CustomSeriesManager';
import {registerCustomSeries as registerCustom} from '../chart/custom/customSeriesRegister';

declare let global: any;

Expand Down Expand Up @@ -2896,7 +2896,7 @@ export function getCoordinateSystemDimensions(type: string): DimensionDefinition
}

export function registerCustomSeries(seriesType: string, renderItem: CustomSeriesRenderItem) {
CustomSeriesManager.register(seriesType, renderItem);
registerCustom(seriesType, renderItem);
}

export {registerLocale} from './locale';
Expand Down
15 changes: 4 additions & 11 deletions src/model/Global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import { concatInternalOptions } from './internalComponentCreator';
import { LocaleOption } from '../core/locale';
import {PaletteMixin} from './mixin/palette';
import { error, warn } from '../util/log';
import CustomSeriesManager from '../chart/custom/CustomSeriesManager';
import { getCustomSeries } from '../chart/custom/customSeriesRegister';

export interface GlobalModelSetOptionOpts {
replaceMerge: ComponentMainType | ComponentMainType[];
Expand Down Expand Up @@ -162,8 +162,6 @@ class GlobalModel extends Model<ECUnitOption> {

private _optionManager: OptionManager;

private _customSeriesManager: CustomSeriesManager;

private _componentsMap: HashMap<ComponentModel[], ComponentMainType>;

/**
Expand Down Expand Up @@ -413,20 +411,15 @@ class GlobalModel extends Model<ECUnitOption> {
}
else {
const isSeriesType = mainType === 'series';

let subType = resultItem.keyInfo.subType;
if (subType && subType.startsWith('custom.')) {
subType = 'custom';
}

const ComponentModelClass = (ComponentModel as ComponentModelConstructor).getClass(
mainType,
subType,
resultItem.keyInfo.subType,
!isSeriesType // Give a more detailed warn later if series don't exists
);

if (!ComponentModelClass) {
if (__DEV__) {
const subType = resultItem.keyInfo.subType;
const seriesImportName = BUILTIN_CHARTS_MAP[subType as keyof typeof BUILTIN_CHARTS_MAP];
if (!componetsMissingLogPrinted[subType]) {
componetsMissingLogPrinted[subType] = true;
Expand Down Expand Up @@ -588,7 +581,7 @@ echarts.use([${seriesImportName}]);`);
}

getCustomRenderer(type: string) {
return CustomSeriesManager.get(type);
return getCustomSeries(type);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion test/custom-register.html

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

0 comments on commit 25132fd

Please sign in to comment.