@@ -13,8 +13,6 @@ import { MarkTypeEnum } from '../mark/interface/type';
1313import type { IRegion , IRegionConstructor } from '../region/interface' ;
1414import type { IBaseModelSpecTransformer , IBaseModelSpecTransformerOption , IModelOption } from '../model/interface' ;
1515import type { Transform , Parser } from '@visactor/vdataset' ;
16- // eslint-disable-next-line no-duplicate-imports
17- import { fields , filter , fold , csvParser , dsvParser , tsvParser } from '@visactor/vdataset' ;
1816import type { ILayoutConstructor } from '../layout/interface' ;
1917import type { IChartPluginConstructor } from '../plugin/chart/interface' ;
2018import type { IComponentPluginConstructor } from '../plugin/components/interface' ;
@@ -26,44 +24,37 @@ import type { IComposedEventConstructor } from '../index-harmony-simple';
2624import type { ITooltipProcessorConstructor } from '../component/tooltip/processor/interface' ;
2725import type { ITooltip } from '../component' ;
2826import type { IVChartPluginConstructor } from '../plugin/vchart' ;
27+ import { factoryRegistry } from './factory-registry' ;
2928
3029export class Factory {
31- private static _charts : { [ key : string ] : IChartConstructor } = { } ;
32- private static _series : { [ key : string ] : ISeriesConstructor } = { } ;
30+ private static _charts : { [ key : string ] : IChartConstructor } = factoryRegistry . charts ;
31+ private static _series : { [ key : string ] : ISeriesConstructor } = factoryRegistry . series ;
3332 private static _components : {
3433 [ key : string ] : {
3534 cmp : IComponentConstructor ;
3635 alwaysCheck ?: boolean ;
3736 createOrder : number ;
3837 } ;
39- } = { } ;
40- private static _graphicComponents : Record < string , ( attrs : any , options ?: VRenderComponentOptions ) => IGraphic > = { } ;
41- private static _marks : { [ key : string ] : MarkConstructor } = { } ;
42- private static _regions : { [ key : string ] : IRegionConstructor } = { } ;
43- private static _animations : { [ key : string ] : ( params ?: any , preset ?: any ) => MarkAnimationSpec } = { } ;
44- private static _implements : { [ key : string ] : ( ...args : any ) => void } = { } ;
45- private static _chartPlugin : { [ key : string ] : IChartPluginConstructor } = { } ;
46- private static _vChartPlugin : { [ key : string ] : IVChartPluginConstructor } = { } ;
47- private static _componentPlugin : { [ key : string ] : IComponentPluginConstructor } = { } ;
38+ } = factoryRegistry . components ;
39+ private static _graphicComponents : Record < string , ( attrs : any , options ?: VRenderComponentOptions ) => IGraphic > =
40+ factoryRegistry . graphicComponents ;
41+ private static _marks : { [ key : string ] : MarkConstructor } = factoryRegistry . marks ;
42+ private static _regions : { [ key : string ] : IRegionConstructor } = factoryRegistry . regions ;
43+ private static _animations : { [ key : string ] : ( params ?: any , preset ?: any ) => MarkAnimationSpec } =
44+ factoryRegistry . animations ;
45+ private static _implements : { [ key : string ] : ( ...args : any ) => void } = factoryRegistry . implements ;
46+ private static _chartPlugin : { [ key : string ] : IChartPluginConstructor } = factoryRegistry . chartPlugin ;
47+ private static _vChartPlugin : { [ key : string ] : IVChartPluginConstructor } = factoryRegistry . vChartPlugin ;
48+ private static _componentPlugin : { [ key : string ] : IComponentPluginConstructor } = factoryRegistry . componentPlugin ;
4849 private static _formatter : (
4950 text : string | number | string [ ] | number [ ] ,
5051 datum : any ,
5152 formatter : string | string [ ]
5253 ) => any ;
5354
54- static transforms : { [ key : string ] : Transform } = {
55- // buildIn transforms
56- fields : fields ,
57- filter : filter ,
58- fold : fold
59- } ;
60- static dataParser : { [ key : string ] : Parser } = {
61- // buildIn parser
62- csv : csvParser ,
63- dsv : dsvParser ,
64- tsv : tsvParser
65- } ;
66- static _layout : { [ key : string ] : ILayoutConstructor } = { } ;
55+ static transforms : { [ key : string ] : Transform } = factoryRegistry . transforms ;
56+ static dataParser : { [ key : string ] : Parser } = factoryRegistry . dataParser ;
57+ static _layout : { [ key : string ] : ILayoutConstructor } = factoryRegistry . layout ;
6758
6859 static registerChart ( key : string , chart : IChartConstructor ) {
6960 Factory . _charts [ key ] = chart ;
@@ -98,7 +89,7 @@ export class Factory {
9889 Factory . transforms [ key ] = transform ;
9990 }
10091
101- private static _grammarTransforms : Record < string , GrammarTransformOption > = { } ;
92+ private static _grammarTransforms : Record < string , GrammarTransformOption > = factoryRegistry . grammarTransforms ;
10293
10394 static registerGrammarTransform ( type : string , transform : GrammarTransformOption ) {
10495 Factory . _grammarTransforms [ type ] = transform ;
@@ -288,13 +279,14 @@ export class Factory {
288279
289280 static registerFormatter ( func : typeof Factory [ '_formatter' ] ) {
290281 this . _formatter = func ;
282+ factoryRegistry . formatter = func ;
291283 }
292284
293285 static getFormatter ( ) {
294- return this . _formatter ;
286+ return factoryRegistry . formatter ?? this . _formatter ;
295287 }
296288
297- private static _stageEventPlugins : Record < string , IStageEventPlugin < any > > = { } ;
289+ private static _stageEventPlugins : Record < string , IStageEventPlugin < any > > = factoryRegistry . stageEventPlugins ;
298290
299291 static registerStageEventPlugin = ( type : string , Plugin : IStageEventPlugin < any > ) => {
300292 Factory . _stageEventPlugins [ type ] = Plugin ;
@@ -304,7 +296,7 @@ export class Factory {
304296 return Factory . _stageEventPlugins [ type ] ;
305297 } ;
306298
307- private static _interactionTriggers : Record < string , ITriggerConstructor > = { } ;
299+ private static _interactionTriggers : Record < string , ITriggerConstructor > = factoryRegistry . interactionTriggers ;
308300
309301 static registerInteractionTrigger = ( interactionType : string , interaction : ITriggerConstructor ) => {
310302 Factory . _interactionTriggers [ interactionType ] = interaction ;
@@ -323,7 +315,7 @@ export class Factory {
323315 return ! ! Factory . _interactionTriggers [ interactionType ] ;
324316 }
325317
326- private static _composedEventMap : Record < string , IComposedEventConstructor > = { } ;
318+ private static _composedEventMap : Record < string , IComposedEventConstructor > = factoryRegistry . composedEventMap ;
327319
328320 static registerComposedEvent = ( eType : string , composedEvent : IComposedEventConstructor ) => {
329321 Factory . _composedEventMap [ eType ] = composedEvent ;
@@ -333,7 +325,7 @@ export class Factory {
333325 return Factory . _composedEventMap [ eType ] ;
334326 }
335327
336- private static _tooltipProcessors : Record < string , ITooltipProcessorConstructor > = { } ;
328+ private static _tooltipProcessors : Record < string , ITooltipProcessorConstructor > = factoryRegistry . tooltipProcessors ;
337329 static registerTooltipProcessor = ( type : string , processor : ITooltipProcessorConstructor ) => {
338330 Factory . _tooltipProcessors [ type ] = processor ;
339331 } ;
0 commit comments