@visactor/vchart
Version:
charts lib based @visactor/VGrammar
193 lines (190 loc) • 8.1 kB
JavaScript
import { factoryRegistry } from "./factory-registry";
export class Factory {
static registerChart(key, chart) {
Factory._charts[key] = chart;
}
static registerSeries(key, series) {
Factory._series[key] = series;
}
static registerComponent(key, cmp, alwaysCheck, createOrder) {
Factory._components[key] = {
cmp: cmp,
alwaysCheck: alwaysCheck,
createOrder: null != createOrder ? createOrder : 0
};
}
static registerGraphicComponent(key, creator) {
Factory._graphicComponents[key] = creator;
}
static createGraphicComponent(componentType, attrs, options) {
const compCreator = Factory._graphicComponents[componentType];
return compCreator ? compCreator(attrs, options) : null;
}
static registerMark(key, mark) {
Factory._marks[key] = mark;
}
static registerRegion(key, region) {
Factory._regions[key] = region;
}
static registerTransform(key, transform) {
Factory.transforms[key] = transform;
}
static registerGrammarTransform(type, transform) {
Factory._grammarTransforms[type] = transform;
}
static getGrammarTransform(type) {
return Factory._grammarTransforms[type];
}
static registerLayout(key, layout) {
Factory._layout[key] = layout;
}
static registerAnimation(key, animation) {
Factory._animations[key] = animation;
}
static registerImplement(key, implement) {
Factory._implements[key] = implement;
}
static registerChartPlugin(key, plugin) {
Factory._chartPlugin[key] = plugin;
}
static registerVChartPlugin(key, plugin) {
Factory._vChartPlugin[key] = plugin;
}
static registerComponentPlugin(key, plugin) {
Factory._componentPlugin[key] = plugin;
}
static createChart(chartType, spec, options) {
if (!Factory._charts[chartType]) return null;
return new (0, Factory._charts[chartType])(spec, options);
}
static getChart(chartType) {
return Factory._charts[chartType];
}
static createChartSpecTransformer(chartType, option) {
if (!Factory._charts[chartType]) return null;
const ChartConstructor = Factory._charts[chartType];
return new (0, ChartConstructor.transformerConstructor)(Object.assign({
seriesType: ChartConstructor.seriesType
}, option));
}
static createRegion(regionType, spec, options) {
if (!Factory._regions[regionType]) return null;
return new (0, Factory._regions[regionType])(spec, options);
}
static createRegionSpecTransformer(regionType, options) {
if (!Factory._regions[regionType]) return null;
return new (0, Factory._regions[regionType].transformerConstructor)(options);
}
static createSeries(seriesType, spec, options) {
if (!Factory._series[seriesType]) return null;
return new (0, Factory._series[seriesType])(spec, options);
}
static createSeriesSpecTransformer(seriesType, options) {
if (!Factory._series[seriesType]) return null;
return new (0, Factory._series[seriesType].transformerConstructor)(options);
}
static createMark(markType, name, options) {
if (!Factory._marks[markType]) return null;
const markInstance = new (0, Factory._marks[markType])(name, options);
return "group" === markInstance.type && markInstance.setMarkConfig({
interactive: !1
}), markInstance;
}
static getComponents() {
return Object.values(Factory._components);
}
static getComponentInKey(name) {
return Factory._components[name].cmp;
}
static getLayout() {
return Object.values(Factory._layout);
}
static getLayoutInKey(name) {
return Factory._layout[name];
}
static getSeries() {
return Object.values(Factory._series);
}
static getSeriesInType(type) {
return Factory._series[type];
}
static getRegionInType(type) {
return Factory._regions[type];
}
static getAnimationInKey(key) {
return Factory._animations[key];
}
static getImplementInKey(key) {
return Factory._implements[key];
}
static getSeriesMarkMap(seriesType) {
return Factory._series[seriesType] ? Factory._series[seriesType].mark : {};
}
static getSeriesBuiltInTheme(themeKey) {
for (const key in Factory._series) {
const item = Factory._series[key];
if (item && item.builtInTheme && item.builtInTheme[themeKey]) return item.builtInTheme[themeKey];
}
return null;
}
static getComponentBuiltInTheme(themeKey) {
for (const key in Factory._components) {
const item = Factory._components[key];
if (item && item.cmp && item.cmp.builtInTheme && item.cmp.builtInTheme[themeKey]) return item.cmp.builtInTheme[themeKey];
}
return null;
}
static getChartPlugins() {
return Object.values(Factory._chartPlugin);
}
static getVChartPlugins() {
return Object.values(Factory._vChartPlugin);
}
static getComponentPlugins() {
return Object.values(Factory._componentPlugin);
}
static getComponentPluginInType(type) {
return Factory._componentPlugin[type];
}
static registerFormatter(func) {
this._formatter = func, factoryRegistry.formatter = func;
}
static getFormatter() {
var _a;
return null !== (_a = factoryRegistry.formatter) && void 0 !== _a ? _a : this._formatter;
}
static createInteractionTrigger(interactionType, options) {
const Ctor = Factory._interactionTriggers[interactionType];
return Ctor ? new Ctor(options) : null;
}
static hasInteractionTrigger(interactionType) {
return !!Factory._interactionTriggers[interactionType];
}
static getComposedEvent(eType) {
return Factory._composedEventMap[eType];
}
}
Factory._charts = factoryRegistry.charts, Factory._series = factoryRegistry.series,
Factory._components = factoryRegistry.components, Factory._graphicComponents = factoryRegistry.graphicComponents,
Factory._marks = factoryRegistry.marks, Factory._regions = factoryRegistry.regions,
Factory._animations = factoryRegistry.animations, Factory._implements = factoryRegistry.implements,
Factory._chartPlugin = factoryRegistry.chartPlugin, Factory._vChartPlugin = factoryRegistry.vChartPlugin,
Factory._componentPlugin = factoryRegistry.componentPlugin, Factory.transforms = factoryRegistry.transforms,
Factory.dataParser = factoryRegistry.dataParser, Factory._layout = factoryRegistry.layout,
Factory._grammarTransforms = factoryRegistry.grammarTransforms, Factory._stageEventPlugins = factoryRegistry.stageEventPlugins,
Factory.registerStageEventPlugin = (type, Plugin) => {
Factory._stageEventPlugins[type] = Plugin;
}, Factory.getStageEventPlugin = type => Factory._stageEventPlugins[type], Factory._interactionTriggers = factoryRegistry.interactionTriggers,
Factory.registerInteractionTrigger = (interactionType, interaction) => {
Factory._interactionTriggers[interactionType] = interaction;
}, Factory._composedEventMap = factoryRegistry.composedEventMap, Factory.registerComposedEvent = (eType, composedEvent) => {
Factory._composedEventMap[eType] = composedEvent;
}, Factory._tooltipProcessors = factoryRegistry.tooltipProcessors, Factory.registerTooltipProcessor = (type, processor) => {
Factory._tooltipProcessors[type] = processor;
}, Factory.createTooltipProcessor = (type, tooltip) => {
const Cror = Factory._tooltipProcessors[type];
return Cror ? new Cror(tooltip) : null;
}, Factory._runtimePluginInstallers = factoryRegistry.runtimePluginInstallers, Factory.registerRuntimePluginInstaller = (type, installer) => {
Factory._runtimePluginInstallers[type] = installer;
}, Factory.getRuntimePluginInstaller = type => Factory._runtimePluginInstallers[type];
//# sourceMappingURL=factory.js.map