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

103 lines (95 loc) 6.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.filterInsightByType = exports.filterCorrelationInsight = exports.mergePointInsight = void 0; const vutils_1 = require("@visactor/vutils"), type_1 = require("../type"), types_1 = require("../../../types"), filterInsight = (insights, type) => insights.filter((insight => insight.type === type)), getBandInsightByOutliear = (context, outliearFieldMapping) => { const bandInsightKeys = [], abnormalBand = [], {dimensionValues: dimensionValues, cell: cell, chartType: chartType} = context; if (![ types_1.ChartType.DualAxisChart, types_1.ChartType.LineChart, types_1.ChartType.BarChart, types_1.ChartType.AreaChart, types_1.ChartType.WaterFallChart ].includes(chartType)) return { bandInsightKeys: bandInsightKeys, abnormalBand: abnormalBand }; const {x: cellx} = cell, xField = (0, vutils_1.isArray)(cellx) ? cellx[0] : cellx; return Object.keys(outliearFieldMapping).forEach((fieldId => { var _a; const indexOfInsights = outliearFieldMapping[fieldId].map((content => { const xValue = content.insight.data[0].dataItem[xField]; return { xIndex: dimensionValues.indexOf(xValue), content: content }; })).sort(((a, b) => a.xIndex - b.xIndex)); let band = [ indexOfInsights[0] ]; for (let i = 1; i <= indexOfInsights.length; i++) { const curIndex = null === (_a = indexOfInsights[i]) || void 0 === _a ? void 0 : _a.xIndex, prevIndex = band[band.length - 1].xIndex; i < indexOfInsights.length && curIndex - prevIndex == 1 ? band.push(indexOfInsights[i]) : (band.length > 1 && (abnormalBand.push({ type: type_1.InsightType.AbnormalBand, name: type_1.InsightType.AbnormalBand, data: band.map((v => v.content.insight.data[0])), seriesName: fieldId, value: null, significant: band.length, info: { startValue: band[0].content.insight.data[0].dataItem[xField], endValue: band[band.length - 1].content.insight.data[0].dataItem[xField], xField: xField } }), bandInsightKeys.push(...band.map((v => v.content.key)))), band = [ indexOfInsights[i] ]); } })), { abnormalBand: abnormalBand, bandInsightKeys: bandInsightKeys }; }, mergePointInsight = (insightCtx, type, context) => { const outliear = {}, {insights: insights} = insightCtx, outliearFieldMapping = {}, filterOutliearInsight = filterInsight(insights, type_1.InsightType.Outlier); filterOutliearInsight.forEach((insight => { const {data: data} = insight, seriesName = null == insight ? void 0 : insight.seriesName, key = `${data[0].index}-&&&-${seriesName}`; outliear[key] || (outliear[key] = [], outliearFieldMapping[seriesName] || (outliearFieldMapping[seriesName] = []), outliearFieldMapping[seriesName].push({ insight: insight, key: key })), outliear[key].push(insight); })); const majorityValueInsight = filterInsight(insights, type_1.InsightType.MajorityValue).filter((insight => { const {data: data} = insight, seriesName = null == insight ? void 0 : insight.seriesName, key = `${data[0].index}-&&&-${seriesName}`; return !outliear[key]; })), pairOutlier = filterPairInsight(insights, filterOutliearInsight), turnPointInsight = filterInsight(insights, type_1.InsightType.TurningPoint), {abnormalBand: abnormalBand, bandInsightKeys: bandInsightKeys} = getBandInsightByOutliear(context, outliearFieldMapping); bandInsightKeys.forEach((key => { delete outliear[key]; })), turnPointInsight.forEach((insight => { const {data: data} = insight, seriesName = null == insight ? void 0 : insight.seriesName, key = `${data[0].index}-&&&-${seriesName}`; outliear[key] && delete outliear[key]; })); const outliearInsight = Object.keys(outliear).map((key => Object.assign(Object.assign({}, outliear[key][0]), { significant: outliear[key].reduce(((prev, cur) => prev + cur.significant), 0) }))); return Object.assign(Object.assign({}, insightCtx), { [type_1.InsightType.Outlier]: outliearInsight, [type_1.InsightType.PairOutlier]: pairOutlier, [type_1.InsightType.TurningPoint]: turnPointInsight, [type_1.InsightType.AbnormalBand]: abnormalBand, [type_1.InsightType.MajorityValue]: majorityValueInsight }); }; exports.mergePointInsight = mergePointInsight; const filterPairInsight = (insights, outliers) => { const pairs = filterInsight(insights, type_1.InsightType.PairOutlier), outlierKeys = new Set; return outliers.forEach((insight => { const {data: data, seriesName: seriesName} = insight, key = `${data[0].index}-&&&-${seriesName}`; outlierKeys.add(key); })), pairs.filter((v => { const {data: data, seriesName: seriesName} = v, keyList = data.map((v => `${v.index}-&&&-${seriesName}`)); return !keyList.find((key => outlierKeys.has(key))); })); }, filterCorrelationInsight = insightCtx => { const {insights: insights} = insightCtx, abnormalTrend = filterInsight(insights, type_1.InsightType.AbnormalTrend), trendFields = new Set(abnormalTrend.map((insight => insight.seriesName))), correlation = filterInsight(insights, type_1.InsightType.Correlation).filter((insight => "pearson-coefficient" === insight.name || (0, vutils_1.isArray)(insight.seriesName) && !insight.seriesName.find((seriesName => trendFields.has(seriesName))))); return Object.assign(Object.assign({}, insightCtx), { [type_1.InsightType.Correlation]: correlation }); }; exports.filterCorrelationInsight = filterCorrelationInsight; const filterInsightByType = (insightCtx, type) => Object.assign(Object.assign({}, insightCtx), { [type]: (null == insightCtx ? void 0 : insightCtx[type]) ? null == insightCtx ? void 0 : insightCtx[type] : filterInsight(insightCtx.insights, type) }); exports.filterInsightByType = filterInsightByType; //# sourceMappingURL=revised.js.map