zz-chart
Version:
Alauda Chart components by Alauda Frontend Team
76 lines • 2.5 kB
JavaScript
import { get, isFunction } from 'lodash-es';
import { AXES_X_VALUES } from '../strategy/config.js';
import { template } from '../utils/index.js';
import { BaseComponent } from './base.js';
import { axisAutoSize } from './uplot-lib/index.js';
export class Axis extends BaseComponent {
constructor() {
super(...arguments);
this.name = 'axis';
}
render() {
// ..
const opt = this.ctrl.getOption();
this.option = get(opt, this.name, { x: {}, y: {} });
}
update() {
// ..
}
getOptions() {
return {
axes: [this.getXOptions(), this.getYOptions()],
};
}
getXOptions() {
const { formatter: xFormatter, show } = this.option.x || {};
const xValues = xFormatter
? (_u, splits) => splits.map(d => {
return isFunction(xFormatter)
? xFormatter(String(d))
: template(xFormatter, { value: d });
})
: AXES_X_VALUES;
return {
show: show !== false,
values: xValues,
};
}
getYOptions() {
const { autoSize, formatter: yFormatter, show } = this.option.y || {};
const yValues = yFormatter
? (u, splits, axisIdx, tickSpace, tickIncr) => {
const params = { u, splits, axisIdx, tickSpace, tickIncr };
return splits.map(d => {
return isFunction(yFormatter)
? yFormatter(String(d), params)
: template(yFormatter, { value: d });
});
}
: null;
const ySize = autoSize === false ? {} : { size: axisAutoSize };
return {
show: show !== false,
values: yValues,
...ySize,
// space: function (self: uPlot, axisIdx: number): number {
// const axis = self.axes[axisIdx];
// const scale = self.scales[axis.scale!];
// // for axis left & right
// if (axis.side !== 2 || !scale) {
// return 30;
// }
// const defaultSpacing = 40;
// return defaultSpacing;
// },
// gap: 5,
// side: 3,
// show: true,
// ticks: {
// show: true,
// size: 3,
// width: 0.5,
// },
};
}
}
//# sourceMappingURL=axis.js.map