@visactor/vchart
Version:
charts lib based @visactor/VGrammar
44 lines (41 loc) • 1.59 kB
JavaScript
import { isArray } from "../util";
import { mergeSpec } from "@visactor/vutils-extension";
export class BaseModelSpecTransformer {
constructor(option) {
this._option = option, this.type = option.type;
}
_initTheme(spec, chartSpec) {
return this._theme = this.getTheme(spec, chartSpec), this._mergeThemeToSpec(spec, chartSpec);
}
getTheme(spec, chartSpec) {}
transformSpec(spec, chartSpec, chartSpecInfo) {
this._transformSpecBeforeMergingTheme(spec, chartSpec, chartSpecInfo);
const result = this._initTheme(spec, chartSpec);
return this._transformSpecAfterMergingTheme(result.spec, chartSpec, chartSpecInfo),
result;
}
_transformSpecBeforeMergingTheme(spec, chartSpec, chartSpecInfo) {}
_transformSpecAfterMergingTheme(spec, chartSpec, chartSpecInfo) {}
_mergeThemeToSpec(spec, chartSpec) {
const theme = this._theme;
if (this._shouldMergeThemeToSpec()) {
const specFromChart = this._getDefaultSpecFromChart(chartSpec), merge = originalSpec => mergeSpec({}, theme, specFromChart, originalSpec);
return isArray(spec) ? {
spec: spec.map((specItem => merge(specItem))),
theme: theme
} : {
spec: merge(spec),
theme: theme
};
}
return {
spec: spec,
theme: theme
};
}
_shouldMergeThemeToSpec() {
return !0;
}
_getDefaultSpecFromChart(chartSpec) {}
}
//# sourceMappingURL=base-model-transformer.js.map