@visactor/vchart
Version:
charts lib based @visactor/VGrammar
132 lines (130 loc) • 4.55 kB
JavaScript
import { fields, filter, fold, csvParser, dsvParser, tsvParser } from "@visactor/vdataset";
export class Factory {
static registerChart(key, chart) {
Factory._charts[key] = chart;
}
static registerSeries(key, series) {
Factory._series[key] = series;
}
static registerComponent(key, cmp, alwaysCheck) {
Factory._components[key] = {
cmp: cmp,
alwaysCheck: alwaysCheck
};
}
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 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 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 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 getChartPlugins() {
return Object.values(Factory._chartPlugin);
}
static getComponentPlugins() {
return Object.values(Factory._componentPlugin);
}
static getComponentPluginInType(type) {
return Factory._componentPlugin[type];
}
static registerFormatter(func) {
this._formatter = func;
}
static getFormatter() {
return this._formatter;
}
}
Factory._charts = {}, Factory._series = {}, Factory._components = {}, Factory._marks = {},
Factory._regions = {}, Factory._animations = {}, Factory._implements = {}, Factory._chartPlugin = {},
Factory._componentPlugin = {}, Factory.transforms = {
fields: fields,
filter: filter,
fold: fold
}, Factory.dataParser = {
csv: csvParser,
dsv: dsvParser,
tsv: tsvParser
}, Factory._layout = {};
//# sourceMappingURL=factory.js.map