@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
62 lines (58 loc) • 2.81 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.ExtremeValue = void 0;
const vutils_1 = require("@visactor/vutils"), type_1 = require("../../type"), utils_1 = require("../../utils"), getExtremeValue = (dataset, measureId, seriesName, propsLowerThreshold, propsUpperThreshold) => {
if (!dataset || 0 === dataset.length) return [];
const lowerThreshold = null != propsLowerThreshold ? propsLowerThreshold : .2, upperThreshold = null != propsUpperThreshold ? propsUpperThreshold : 5, result = [], avg = dataset.map((d => d.dataItem)).reduce(((prev, cur) => {
const numValue = parseFloat(cur[measureId]);
return prev + ((0, vutils_1.isNumber)(numValue) ? Math.abs(numValue) : 0);
}), 0) / dataset.length;
return avg - 0 <= Number.EPSILON ? [] : (dataset.forEach((d => {
const numValue = parseFloat(d.dataItem[measureId]), percent = ((0, vutils_1.isNumber)(numValue) ? Math.abs(numValue) : 0) / avg;
percent > upperThreshold && result.push({
type: type_1.InsightType.ExtremeValue,
data: [ d ],
value: d.dataItem[measureId],
significant: percent / upperThreshold,
fieldId: measureId,
seriesName: seriesName,
info: {
type: "extreme_high",
averageValue: avg,
percent: percent
}
}), percent - 0 > Number.EPSILON && percent < lowerThreshold && result.push({
type: type_1.InsightType.ExtremeValue,
data: [ d ],
value: d.dataItem[measureId],
significant: lowerThreshold / percent,
fieldId: measureId,
seriesName: seriesName,
info: {
type: "extreme_low",
averageValue: avg,
percent: percent
}
});
})), result);
}, calcExtremeValue = (context, options) => {
const {seriesDataMap: seriesDataMap, cell: cell, spec: spec} = context, {y: celly} = cell, {upperThreshold: upperThreshold, lowerThreshold: lowerThreshold} = options || {}, yField = (0,
vutils_1.isArray)(celly) ? celly.flat() : [ celly ], result = [];
return Object.keys(seriesDataMap).forEach((series => {
const dataset = seriesDataMap[series];
yField.forEach((measure => {
if ((0, utils_1.isPercenSeries)(spec, measure)) return;
const insights = getExtremeValue(dataset, measure, series, lowerThreshold, upperThreshold);
result.push(...insights);
}));
})), [];
};
exports.ExtremeValue = {
name: "extremeValue",
insightType: type_1.InsightType.ExtremeValue,
algorithmFunction: calcExtremeValue,
supportStack: !0,
supportPercent: !1
};
//# sourceMappingURL=index.js.map