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

47 lines (40 loc) 1.88 kB
import { isArray } from "@visactor/vutils"; import BayesianChangePoint from "bayesian-changepoint"; import { InsightType } from "../../type"; import { ChartType } from "../../../../types"; import { isPercenSeries } from "../../utils"; const breakpointVerifier = (next, prev) => Math.abs(next.data - prev.data) >= 1, bayesianDetection = (dataset, measureId) => { const measureSet = dataset.map((d => Number(d[measureId]))), detection = new BayesianChangePoint({ breakpointVerifier: breakpointVerifier, chunkSize: measureSet.length, iteratee: d => d }); detection.exec(measureSet); return detection.breakPoints(); }, turningPointAlgo = context => { const result = [], {seriesDataMap: seriesDataMap, cell: cell, spec: spec} = context, {y: celly} = cell, yField = isArray(celly) ? celly.flat() : [ celly ]; return Object.keys(seriesDataMap).forEach((series => { const seriesDataset = seriesDataMap[series]; yField.forEach((measureId => { if (isPercenSeries(spec, measureId)) return; bayesianDetection(seriesDataset.map((d => d.dataItem)), measureId).forEach((res => { const {index: index} = res, d = seriesDataset[index]; result.push({ type: InsightType.TurningPoint, data: [ d ], fieldId: measureId, seriesName: series, value: d.dataItem[measureId] }); })); })); })), result; }; export const TurningPoint = { name: "turningPoint", forceChartType: [ ChartType.DualAxisChart, ChartType.LineChart, ChartType.BarChart, ChartType.AreaChart, ChartType.WaterFallChart ], insightType: InsightType.TurningPoint, algorithmFunction: turningPointAlgo, supportPercent: !1 }; //# sourceMappingURL=index.js.map