UNPKG

@visactor/vmind

Version:

<div align="center"> <a href="https://github.com/VisActor#gh-light-mode-only" target="_blank"> <img alt="VisActor Logo" width="200" src="https://github.com/VisActor/.github/blob/main/profile/logo_500_200_light.svg"/> </a> <a href="https://githu

64 lines (60 loc) 2.71 kB
import { isArray, uniqArray } from "@visactor/vutils"; import { ROLE } from "../../../../types/base"; export const seriesField = context => { const {spec: spec, fieldInfo: fieldInfo, dataTable: dataTable, cell: cell} = context, cellNew = Object.assign({}, cell), {seriesField: seriesField, xField: propsXField} = spec, colorField = isArray(seriesField) ? seriesField[0] : seriesField, colorFieldInfo = fieldInfo.find((v => v.fieldName === colorField)), xField = isArray(propsXField) ? propsXField : [ propsXField ]; if (colorField && (null == colorFieldInfo ? void 0 : colorFieldInfo.role) === ROLE.DIMENSION && xField) { const xMap = new Map; dataTable.forEach((row => { const xValue = row[xField[0]]; xMap.has(xValue) ? xMap.get(xValue).push(row[colorField]) : xMap.set(xValue, [ row[colorField] ]); })); const xValues = Array.from(xMap.keys()); let isValidColor = !1; for (let i = 0; i < xValues.length; i++) { const xValue = xValues[i], colorValues = uniqArray(xMap.get(xValue)); if (isArray(colorValues) && colorValues.length > 1) { isValidColor = !0; break; } } isValidColor || xField.includes(colorField) && xField.length > 1 && (spec.seriesField = void 0, cellNew.color = void 0, spec.xField = xField.filter((field => field !== colorField))); } return { spec: spec, cell: cellNew }; }; export const axis = context => { var _a, _b; const {spec: spec, cell: cell, fieldInfo: fieldInfo} = context, {y: celly} = cell, yFieldsInfo = (isArray(celly) ? celly : [ celly ]).map((field => fieldInfo.find((v => v.fieldName === field)))), isAllRatio = yFieldsInfo.every((v => !!(null == v ? void 0 : v.ratioGranularity))), isSameUnit = 1 === uniqArray(yFieldsInfo.map((v => null == v ? void 0 : v.unit)).filter((v => !!v))).length; return spec.axes = [ { orient: "bottom", type: "band", label: { style: {} }, title: { visible: !1, style: {} } }, { orient: "left", type: "linear", label: { style: {}, formatter: isAllRatio ? "{label:~%}" : void 0 }, unit: isSameUnit && ![ "%", "‰" ].includes(null === (_a = yFieldsInfo[0]) || void 0 === _a ? void 0 : _a.unit) ? { visible: !0, text: null === (_b = yFieldsInfo[0]) || void 0 === _b ? void 0 : _b.unit } : void 0, title: { visible: !1, style: {} } } ], { spec: spec }; }; //# sourceMappingURL=cartesian.js.map