@zhsz/cool-design-dv
Version:
36 lines (35 loc) • 1.28 kB
JavaScript
import { SERIES_LABEL_POSITION } from "./constant.mjs";
import { isObject } from "lodash-es";
import { getLabelFormatter } from "./util.mjs";
function createAxis({ direction, valueAxis }, { dimensions }) {
const categoryAxis = dimensions[0] ? [{ type: "category" }] : void 0;
const defaultValueAxis = dimensions[1] || {};
const configValueAxis = valueAxis ? [].concat(valueAxis) : [];
let mergeValueAxis = [
{ type: "value", axisLabel: getLabelFormatter(defaultValueAxis) }
];
if (configValueAxis.length) {
mergeValueAxis = configValueAxis.map((item, index) => {
const axisOptions = isObject(item) ? item : { name: item };
const dimension = dimensions.find(
(n) => [n.name, n.displayName].includes(axisOptions.name)
) || {};
return {
type: "value",
position: SERIES_LABEL_POSITION[direction][index],
axisLabel: getLabelFormatter(dimension),
...axisOptions,
// 兼容 name 和 displayName的设置
name: dimension.displayName || dimension.name || axisOptions.name
};
});
}
const isXCategory = direction === "x";
return {
xAxis: isXCategory ? categoryAxis : mergeValueAxis,
yAxis: !isXCategory ? categoryAxis : mergeValueAxis
};
}
export {
createAxis
};