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

84 lines (73 loc) 3.45 kB
import { DataType } from "../../../../types/base"; import { getFieldByDataType } from "../../../../utils/field"; import { COLOR_THEMES, DEFAULT_VIDEO_LENGTH } from "../constants"; import { axis, seriesField } from "./cartesian"; import { data, discreteLegend, onlyUnique } from "./common"; export const colorBar = context => { const {colors: colors, spec: spec, chartTheme: chartTheme} = context, colorThemes = COLOR_THEMES.default; return chartTheme || (colors && colors.length > 0 ? spec.color = colors : spec.color = colorThemes.map((c => ({ gradient: "linear", x0: .01, y0: 0, x1: .01, y1: 1, stops: [ { offset: 0, color: `#${c.split("#")[1]}FF` }, { offset: 1, color: `#${c.split("#")[1]}00` } ] })))), { spec: spec }; }; export const cartesianBar = context => { const {cell: cell, fieldInfo: fieldInfo = [], spec: spec, stackOrPercent: stackOrPercent} = context, cellNew = Object.assign({}, cell), flattenedXField = Array.isArray(cell.x) ? cell.x : [ cell.x ]; if (cell.color && cell.color.length > 0 && cell.color !== cell.x && flattenedXField.push(cell.color), spec.xField = flattenedXField, spec.yField = cell.y, cell.color) spec.seriesField = cell.color; else { const remainedFields = fieldInfo.filter((({fieldName: fieldName}) => !spec.xField.includes(fieldName) && spec.yField !== fieldName)), colorField = getFieldByDataType(remainedFields, [ DataType.STRING, DataType.DATE ]); colorField && (spec.seriesField = colorField.fieldName, spec.xField.push(colorField.fieldName), cellNew.color = colorField.fieldName); } return spec.xField.length > 1 && stackOrPercent && (spec.xField = [ spec.xField[0] ], spec.stack = !!stackOrPercent, spec.percent = "percent" === stackOrPercent), { spec: spec, cell: cellNew }; }; export const displayConfBar = context => { const {spec: spec, chartTheme: chartTheme} = context; return chartTheme || (spec.bar = { style: {} }), { spec: spec }; }; export const transposeField = context => { const {spec: spec, transpose: transpose} = context; if (transpose) { const newSpec = Object.assign(Object.assign({}, spec), { xField: spec.yField, yField: spec.xField, direction: "horizontal" }), bottomAxis = (newSpec.axes || []).find((axis => "bottom" === axis.orient)), leftAxis = (newSpec.axes || []).find((axis => "left" === axis.orient)); return bottomAxis && (bottomAxis.orient = "left"), leftAxis && (leftAxis.orient = "bottom"), Object.assign(Object.assign({}, context), { spec: newSpec }); } return context; }; export const animationCartesianBar = context => { var _a; const {spec: spec} = context, totalTime = null !== (_a = context.totalTime) && void 0 !== _a ? _a : DEFAULT_VIDEO_LENGTH, groupKey = Array.isArray(spec.xField) ? spec.xField[0] : spec.xField, groupNum = spec.data.values.map((d => d[groupKey])).filter(onlyUnique).length; return spec.animationAppear = { oneByOne: Number.MIN_VALUE, duration: totalTime / groupNum }, { spec: spec }; }; export const pipelineBar = [ data, colorBar, cartesianBar, seriesField, axis, discreteLegend, displayConfBar, transposeField ]; //# sourceMappingURL=bar.js.map