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

74 lines (68 loc) 2.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.axis = exports.seriesField = void 0; const vutils_1 = require("@visactor/vutils"), base_1 = require("../../../../types/base"), seriesField = context => { const {spec: spec, fieldInfo: fieldInfo, dataTable: dataTable, cell: cell} = context, cellNew = Object.assign({}, cell), {seriesField: seriesField, xField: propsXField} = spec, colorField = (0, vutils_1.isArray)(seriesField) ? seriesField[0] : seriesField, colorFieldInfo = fieldInfo.find((v => v.fieldName === colorField)), xField = (0, vutils_1.isArray)(propsXField) ? propsXField : [ propsXField ]; if (colorField && (null == colorFieldInfo ? void 0 : colorFieldInfo.role) === base_1.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 = (0, vutils_1.uniqArray)(xMap.get(xValue)); if ((0, vutils_1.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 }; }; exports.seriesField = seriesField; const axis = context => { var _a, _b; const {spec: spec, cell: cell, fieldInfo: fieldInfo} = context, {y: celly} = cell, yFieldsInfo = ((0, vutils_1.isArray)(celly) ? celly : [ celly ]).map((field => fieldInfo.find((v => v.fieldName === field)))), isAllRatio = yFieldsInfo.every((v => !!(null == v ? void 0 : v.ratioGranularity))), isSameUnit = 1 === (0, vutils_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 }; }; exports.axis = axis; //# sourceMappingURL=cartesian.js.map