UNPKG

zz-chart

Version:

Alauda Chart components by Alauda Frontend Team

75 lines 2.28 kB
import { get } from 'lodash-es'; import { getSeriesPathType } from '../../strategy/utils.js'; import { ShapeType } from '../../utils/index.js'; import { seriesBarsPlugin, stack } from '../uplot-lib/index.js'; import { Shape } from './index.js'; /** * Bar 柱状图 */ export default class Bar extends Shape { constructor(ctrl, opt = {}) { super(ctrl, opt); this.type = ShapeType.Bar; this.adjustOption = { type: 'group', marginRatio: 0.2, }; this.ctrl.setShape(this.type, this); const option = get(this.ctrl.getOption(), this.type); if (typeof option === 'object') { this.option = option; this.adjustOption = { ...this.adjustOption, ...option.adjust, }; } } get transposed() { return this.ctrl.getCoordinate().isTransposed; } get strategy() { return this.ctrl.strategyManage.getStrategy('uPlot'); } map(name) { this.mapName = name; return this; } adjust(adjustOpt) { if (typeof adjustOpt === 'string') { this.adjustOption.type = adjustOpt; } if (typeof adjustOpt === 'object') { this.adjustOption = adjustOpt; } } getSeries() { return this.getData().map(({ color, name }) => { return { stroke: color, label: name, points: { show: false, }, ...getSeriesPathType(this.type, color, this.option), }; }); } getOptions() { const data = this.strategy.getData(); const isStack = this.adjustOption.type === 'stack'; const stackOpt = isStack ? stack(data) : {}; return { ...stackOpt, plugins: [ seriesBarsPlugin({ time: !!get(this.ctrl.getOption()?.scale?.x, 'time'), ori: this.transposed ? 1 : 0, dir: this.transposed ? -1 : 1, stacked: isStack, marginRatio: this.adjustOption.marginRatio / 10, }), ], }; } } //# sourceMappingURL=bar.js.map