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

102 lines (89 loc) 4.9 kB
import { isArray } from "@visactor/vutils"; import { ChartType } from "@visactor/chart-advisor"; import { ChartType as VMindChartType } from "../../types"; import { DEFAULT_VIDEO_LENGTH, VIDEO_LENGTH_BY_CHART_TYPE } from "./spec/constants"; export { getVChartTypeByVmind } from "./spec/chartTypeUtils"; export const getVizSchema = context => { const {fieldInfo: fieldInfo} = context; return { fields: fieldInfo && fieldInfo.map((d => ({ id: d.fieldName, alias: d.fieldName, description: d.description, visible: !0, type: d.type, role: d.role, location: d.role }))) }; }; export const typeMap = type => [ "string" ].includes(type) ? "string" : [ "date", "datetime", "time" ].includes(type) ? "date" : [ "int", "float" ].includes(type) ? "number" : "string"; export const VMindChartTypeMap = { [VMindChartType.BarChart]: [ ChartType.COLUMN, ChartType.COLUMN_PERCENT, ChartType.COLUMN_PARALLEL, ChartType.BAR, ChartType.BAR_PERCENT, ChartType.BAR_PARALLEL ], [VMindChartType.LineChart]: [ ChartType.LINE, ChartType.AREA, ChartType.AREA_PERCENT ], [VMindChartType.AreaChart]: [ ChartType.AREA, ChartType.AREA_PERCENT ], [VMindChartType.PieChart]: [ ChartType.PIE, ChartType.ANNULAR ], [VMindChartType.RoseChart]: [ ChartType.ROSE ], [VMindChartType.ScatterPlot]: [ ChartType.SCATTER ], [VMindChartType.DualAxisChart]: [ ChartType.DUAL_AXIS ], [VMindChartType.WordCloud]: [ ChartType.WORD_CLOUD ], [VMindChartType.FunnelChart]: [ ChartType.FUNNEL ], [VMindChartType.SankeyChart]: [ ChartType.SANKEY ], [VMindChartType.RadarChart]: [ ChartType.RADAR ] }; export const chartTypeMap = advisorChartType => { if ([ ChartType.COLUMN, ChartType.COLUMN_PERCENT, ChartType.COLUMN_PARALLEL, ChartType.BAR, ChartType.BAR_PERCENT, ChartType.BAR_PARALLEL ].includes(advisorChartType)) return "Bar Chart"; if ([ ChartType.LINE, ChartType.AREA, ChartType.AREA_PERCENT ].includes(advisorChartType)) return "Line Chart"; if ([ ChartType.PIE, ChartType.ANNULAR ].includes(advisorChartType)) return "Pie Chart"; if (ChartType.ROSE === advisorChartType) return "Rose Chart"; if (ChartType.SCATTER === advisorChartType) return "Scatter Plot"; if (ChartType.DUAL_AXIS === advisorChartType) return "Dual Axis Chart"; if (ChartType.WORD_CLOUD === advisorChartType) return "Word Cloud"; if (ChartType.FUNNEL === advisorChartType) return "Funnel Chart"; if (ChartType.SANKEY === advisorChartType) return "Sankey Chart"; if (ChartType.RADAR === advisorChartType) return "Radar Chart"; throw "no matched chart type " + advisorChartType; }; export const getCell = cell => { const keys = Object.keys(cell), result = {}; return keys.forEach((key => { const channel = cell[key]; Array.isArray(channel) && 1 === channel.length ? result[key] = String(channel[0]) : result[key] = Array.isArray(channel) ? channel.map((c => String(c))) : channel; })), result; }; const checkChannel = (cell, channel, count = 1) => 1 === count && "string" == typeof cell[channel] || (!!(Array.isArray(cell[channel]) && cell[channel].length >= count) || (console.error(`cell mismatch channel '${channel}'`), !1)); export const checkChartTypeAndCell = (chartType, cell, fieldInfo) => { const fieldList = fieldInfo.map((f => f.fieldName)); Object.values(cell).forEach((cellField => { cellField && (isArray(cellField) ? cellField.every((f => f && fieldList.includes(f))) || console.warn(`missing field ${cellField}`) : cellField && !fieldList.includes(cellField) && console.warn(`missing field ${cellField}`)); })); let checkChannelResult = !0; switch (chartType) { case "BAR CHART": case "LINE CHART": checkChannelResult = checkChannel(cell, "x") && checkChannel(cell, "y"); break; case "DUAL AXIS CHART": checkChannelResult = checkChannel(cell, "x") && checkChannel(cell, "y", 2); } return checkChannelResult; }; export const estimateVideoTime = (chartType, spec, parsedTime) => { var _a; if ("DYNAMIC BAR CHART" === chartType) { const frameNumber = spec.player.specs.length, duration = spec.player.interval; return { totalTime: null != parsedTime ? parsedTime : frameNumber * duration, frameArr: parsedTime ? Array.from(new Array(frameNumber).keys()).map((n => Number(parsedTime / frameNumber))) : Array.from(new Array(frameNumber).keys()).map((n => duration)) }; } return { totalTime: null !== (_a = null != parsedTime ? parsedTime : VIDEO_LENGTH_BY_CHART_TYPE[{ "PIE CHART": "pie", "WORD CLOUD": "wordCloud" }[chartType]]) && void 0 !== _a ? _a : DEFAULT_VIDEO_LENGTH, frameArr: [] }; }; //# sourceMappingURL=utils.js.map