@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
39 lines (33 loc) • 1.74 kB
JavaScript
import { isArray } from "@visactor/vutils";
import { spearmanCoefficient } from "../statistics";
import { InsightType } from "../../type";
import { ChartType } from "../../../../types";
const spearmanAlgo = (context, options) => {
const {seriesDataMap: seriesDataMap, cell: cell} = context, {threshold: threshold = .95} = options || {}, {y: celly} = cell, yField = isArray(celly) ? celly.flat() : [ celly ], result = [], seriesNames = Object.keys(seriesDataMap);
return yField.forEach((measureId => {
for (let i = 0; i < seriesNames.length; i++) {
const iMeasureset = seriesDataMap[seriesNames[i]].map((d => d.dataItem)).map((d => d[measureId]));
for (let j = i + 1; j < seriesNames.length; j++) {
const jMeasureset = seriesDataMap[seriesNames[j]].map((d => d.dataItem)).map((d => d[measureId]));
if (iMeasureset.length !== jMeasureset.length) continue;
const spearmanCoff = spearmanCoefficient(iMeasureset, jMeasureset);
Math.abs(spearmanCoff) > threshold && result.push({
type: InsightType.Correlation,
fieldId: measureId,
seriesName: [ seriesNames[i], seriesNames[j] ],
significant: Math.abs(spearmanCoff),
info: {
correlationType: spearmanCoff > 0 ? "positive" : "negative"
}
});
}
}
})), result;
};
export const LineChartCorrelation = {
name: "spearman",
chartType: [ ChartType.LineChart, ChartType.DualAxisChart ],
insightType: InsightType.Correlation,
algorithmFunction: spearmanAlgo
};
//# sourceMappingURL=spearman.js.map