@milaboratories/miplots4 1.0.146 → 1.0.148
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/Legend.js +3 -3
- package/dist/common/Legend.js.map +1 -1
- package/dist/heatmap/ChartRenderer.js +1 -1
- package/dist/heatmap/ChartRenderer.js.map +1 -1
- package/dist/heatmap/HeatmapSettingsImpl.d.ts +6 -1
- package/dist/heatmap/HeatmapSettingsImpl.d.ts.map +1 -1
- package/dist/heatmap/HeatmapSettingsImpl.js +9 -3
- package/dist/heatmap/HeatmapSettingsImpl.js.map +1 -1
- package/dist/heatmap/components/Annotations/index.js +58 -58
- package/dist/heatmap/components/Annotations/index.js.map +1 -1
- package/dist/heatmap/components/Dendrograms.d.ts.map +1 -1
- package/dist/heatmap/components/Dendrograms.js +51 -51
- package/dist/heatmap/components/Dendrograms.js.map +1 -1
- package/dist/heatmap/components/types.d.ts +0 -1
- package/dist/heatmap/components/types.d.ts.map +1 -1
- package/dist/heatmap/getCells.d.ts +1 -1
- package/dist/heatmap/getCells.d.ts.map +1 -1
- package/dist/heatmap/getCells.js +204 -110
- package/dist/heatmap/getCells.js.map +1 -1
- package/dist/heatmap/getClusters.d.ts +81 -4
- package/dist/heatmap/getClusters.d.ts.map +1 -1
- package/dist/heatmap/getClusters.js +137 -48
- package/dist/heatmap/getClusters.js.map +1 -1
- package/dist/heatmap/getDendrograms.d.ts.map +1 -1
- package/dist/heatmap/getDendrograms.js +33 -35
- package/dist/heatmap/getDendrograms.js.map +1 -1
- package/dist/heatmap/index.d.ts.map +1 -1
- package/dist/heatmap/index.js +88 -85
- package/dist/heatmap/index.js.map +1 -1
- package/dist/types/heatmap.d.ts +24 -0
- package/dist/types/heatmap.d.ts.map +1 -1
- package/dist/types/heatmap.js +7 -2
- package/dist/types/heatmap.js.map +1 -1
- package/package.json +1 -1
package/dist/heatmap/getCells.js
CHANGED
|
@@ -1,38 +1,68 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import K from "../node_modules/lodash/lodash.js";
|
|
2
|
+
import { exhaustive as ee } from "../utils/index.js";
|
|
3
|
+
import X from "../node_modules/d3-array/src/mean.js";
|
|
4
|
+
import { quantileSorted as te } from "../node_modules/d3-array/src/quantile.js";
|
|
5
|
+
import ae from "../node_modules/d3-array/src/deviation.js";
|
|
6
|
+
import se from "../node_modules/d3-array/src/extent.js";
|
|
7
|
+
function ne(t) {
|
|
8
|
+
const s = ae(t), n = X(t);
|
|
9
|
+
return s === void 0 || n === void 0 || s === 0 ? (u) => u : (u) => (u - n) / s;
|
|
8
10
|
}
|
|
9
|
-
function
|
|
10
|
-
const
|
|
11
|
-
return
|
|
11
|
+
function oe(t) {
|
|
12
|
+
const s = X(t), [n, u] = se(t);
|
|
13
|
+
return s === void 0 || n === void 0 || u === void 0 || u === n ? (r) => r : (r) => (r - s) / (u - n);
|
|
12
14
|
}
|
|
13
|
-
function
|
|
14
|
-
return
|
|
15
|
+
function le(t, s) {
|
|
16
|
+
return t === "standardScaling" ? ne(s) : t === "meanNormalization" ? oe(s) : (n) => n;
|
|
15
17
|
}
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
+
function N(t, s) {
|
|
19
|
+
switch (t) {
|
|
20
|
+
case "max": {
|
|
21
|
+
let n = s[0];
|
|
22
|
+
for (const u of s)
|
|
23
|
+
n = Math.max(n, u);
|
|
24
|
+
return n;
|
|
25
|
+
}
|
|
26
|
+
case "min": {
|
|
27
|
+
let n = s[0];
|
|
28
|
+
for (const u of s)
|
|
29
|
+
n = Math.min(n, u);
|
|
30
|
+
return n;
|
|
31
|
+
}
|
|
32
|
+
case "median": {
|
|
33
|
+
const n = s.sort((u, r) => u - r);
|
|
34
|
+
return te(n, 0.5);
|
|
35
|
+
}
|
|
36
|
+
case "mean":
|
|
37
|
+
return X(s) ?? s[0];
|
|
38
|
+
default:
|
|
39
|
+
ee(t, `Unknown aggregation function ${t}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function P(t) {
|
|
43
|
+
const s = [...new Set(t)].sort();
|
|
44
|
+
return s.length > 3 ? [...s.slice(0, 3), "..."].join(", ") : s.join(", ");
|
|
45
|
+
}
|
|
46
|
+
function A(t) {
|
|
47
|
+
if (!t.length)
|
|
18
48
|
return [];
|
|
19
|
-
let
|
|
20
|
-
return
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}),
|
|
25
|
-
}),
|
|
49
|
+
let s = [[]];
|
|
50
|
+
return t.forEach((n) => {
|
|
51
|
+
const u = [];
|
|
52
|
+
n.forEach((r) => {
|
|
53
|
+
u.push(...s.map((p) => [...p, r]));
|
|
54
|
+
}), s = u;
|
|
55
|
+
}), s;
|
|
26
56
|
}
|
|
27
|
-
const
|
|
28
|
-
(
|
|
57
|
+
const Q = (t, s, n = {}) => t.sort(
|
|
58
|
+
(u, r) => s === "asc" ? (n[u] ?? u).localeCompare(n[r] ?? r, "en", { numeric: !0 }) : (n[r] ?? r).localeCompare(n[u] ?? u, "en", { numeric: !0 })
|
|
29
59
|
);
|
|
30
|
-
function
|
|
31
|
-
|
|
60
|
+
function ue() {
|
|
61
|
+
return {
|
|
32
62
|
meta: {
|
|
33
|
-
facetKeys:
|
|
34
|
-
xGroupKeys:
|
|
35
|
-
yGroupKeys:
|
|
63
|
+
facetKeys: [],
|
|
64
|
+
xGroupKeys: [],
|
|
65
|
+
yGroupKeys: [],
|
|
36
66
|
xKeysByGroups: {},
|
|
37
67
|
yKeysByGroups: {},
|
|
38
68
|
xLabels: {},
|
|
@@ -41,104 +71,168 @@ function le(n, o, l, c, f, d, b, D, z, X, C, Y, x, A, N) {
|
|
|
41
71
|
yGroupLabels: {},
|
|
42
72
|
xDataByKeys: {},
|
|
43
73
|
yDataByKeys: {},
|
|
44
|
-
facetKeyValues:
|
|
45
|
-
xGroupKeyValues:
|
|
46
|
-
yGroupKeyValues:
|
|
74
|
+
facetKeyValues: {},
|
|
75
|
+
xGroupKeyValues: {},
|
|
76
|
+
yGroupKeyValues: {},
|
|
47
77
|
valueExtent: [1 / 0, -1 / 0]
|
|
48
78
|
},
|
|
49
79
|
facets: {}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function ie(t, s, n, u, r) {
|
|
83
|
+
if (s.x || s.y) {
|
|
84
|
+
const p = [1 / 0, -1 / 0];
|
|
85
|
+
t.meta.facetKeys.forEach((y) => {
|
|
86
|
+
const { xKeys: B, yKeys: w, cells: g, xKeysByGroups: G, yKeysByGroups: E } = t.facets[y], c = s.x ? G : B.reduce((e, i) => (e[i] = [i], e), {}), V = s.y ? E : w.reduce((e, i) => (e[i] = [i], e), {}), d = Object.keys(c), D = Object.keys(V);
|
|
87
|
+
for (const e of d)
|
|
88
|
+
for (const i of D) {
|
|
89
|
+
const b = [];
|
|
90
|
+
if (c[e].forEach((v) => {
|
|
91
|
+
V[i].forEach((C) => {
|
|
92
|
+
var $, q, S;
|
|
93
|
+
const x = (q = ($ = g[v]) == null ? void 0 : $[C]) == null ? void 0 : q.value;
|
|
94
|
+
x !== void 0 && (b.push(x), (S = g[v]) == null || delete S[C]);
|
|
95
|
+
});
|
|
96
|
+
}), b.length > 0) {
|
|
97
|
+
const v = N(s.method, b);
|
|
98
|
+
t.facets[y].cells[e] || (t.facets[y].cells[e] = {}), t.facets[y].cells[e][i] = {
|
|
99
|
+
isCell: !0,
|
|
100
|
+
idx: 0,
|
|
101
|
+
id: `${e}_${i}`,
|
|
102
|
+
x: e,
|
|
103
|
+
y: i,
|
|
104
|
+
value: v,
|
|
105
|
+
normalizedValue: v
|
|
106
|
+
}, p[0] = Math.min(v, p[0]), p[1] = Math.max(v, p[1]);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
s.x && d.forEach((e) => {
|
|
110
|
+
n.forEach((i) => {
|
|
111
|
+
const b = r.find((x) => x.valueColumn.value === i || x.valueColumn.valueLabels === i);
|
|
112
|
+
if (!b)
|
|
113
|
+
return;
|
|
114
|
+
const v = [];
|
|
115
|
+
c[e].forEach((x) => {
|
|
116
|
+
v.push(t.meta.xDataByKeys[i][x]), delete t.meta.xDataByKeys[i][x];
|
|
117
|
+
});
|
|
118
|
+
const C = b.type === "continuous" ? N(s.method, v) : P(v);
|
|
119
|
+
t.meta.xDataByKeys[i][e] = C;
|
|
120
|
+
});
|
|
121
|
+
}), s.y && (u.forEach((e) => {
|
|
122
|
+
t.meta.yDataByKeys[e] = {};
|
|
123
|
+
}), D.forEach((e) => {
|
|
124
|
+
u.forEach((i) => {
|
|
125
|
+
const b = r.find((x) => x.valueColumn.value === i || x.valueColumn.valueLabels === i);
|
|
126
|
+
if (!b)
|
|
127
|
+
return;
|
|
128
|
+
const v = [];
|
|
129
|
+
V[e].forEach((x) => {
|
|
130
|
+
v.push(t.meta.yDataByKeys[i][x]), delete t.meta.yDataByKeys[i][x];
|
|
131
|
+
});
|
|
132
|
+
const C = b.type === "continuous" ? N(s.method, v) : P(v);
|
|
133
|
+
t.meta.yDataByKeys[i][e] = C;
|
|
134
|
+
});
|
|
135
|
+
})), s.x && (t.facets[y].xKeys = Object.keys(G), t.facets[y].xKeysByGroups = { null: t.facets[y].xKeys }, t.meta.xLabels = t.meta.xGroupLabels, t.meta.xGroupKeys = ["null"], t.meta.xGroupKeyValues = { null: ["null"] }), s.y && (t.facets[y].yKeys = Object.keys(E), t.facets[y].yKeysByGroups = { null: t.facets[y].yKeys }, t.meta.yLabels = t.meta.yGroupLabels, t.meta.yGroupKeys = ["null"], t.meta.yGroupKeyValues = { null: ["null"] });
|
|
136
|
+
}), t.meta.valueExtent = p;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function re(t, s) {
|
|
140
|
+
if (s) {
|
|
141
|
+
const n = [1 / 0, -1 / 0];
|
|
142
|
+
t.meta.facetKeys.forEach((u) => {
|
|
143
|
+
const { xKeys: r, yKeys: p, cells: y } = t.facets[u], B = s.direction === "row" ? r : p, w = s.direction === "row" ? p : r, g = s.direction === "row" ? (G, E) => {
|
|
144
|
+
var c;
|
|
145
|
+
return (c = y[G]) == null ? void 0 : c[E];
|
|
146
|
+
} : (G, E) => {
|
|
147
|
+
var c;
|
|
148
|
+
return (c = y[E]) == null ? void 0 : c[G];
|
|
149
|
+
};
|
|
150
|
+
w.forEach((G) => {
|
|
151
|
+
const E = [];
|
|
152
|
+
B.forEach((V) => {
|
|
153
|
+
var D;
|
|
154
|
+
const d = (D = g(V, G)) == null ? void 0 : D.value;
|
|
155
|
+
d !== void 0 && E.push(d);
|
|
156
|
+
});
|
|
157
|
+
const c = le(s.method, E);
|
|
158
|
+
B.forEach((V) => {
|
|
159
|
+
const d = g(V, G);
|
|
160
|
+
d !== void 0 && (d.normalizedValue = c(d.value), n[0] = Math.min(d.normalizedValue, n[0]), n[1] = Math.max(d.normalizedValue, n[1]));
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
}), t.meta.valueExtent = n;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function xe(t, s, n, u, r, p, y, B, w, g, G, E, c, V, d, D) {
|
|
167
|
+
const e = ue(), i = r.length ? r.map((a) => c[a.value] ?? t.getColumnCategories(a.value)) : [["null"]], b = p.length ? p.map((a) => c[a.value] ?? t.getColumnCategories(a.value)) : [["null"]], v = y.length ? y.map((a) => c[a.value] ?? t.getColumnCategories(a.value)) : [["null"]], C = A(i), x = A(b), $ = A(v), q = C.map((a) => a.join("_")), S = x.map((a) => a.join("_")), z = $.map((a) => a.join("_"));
|
|
168
|
+
e.meta.facetKeys = q, e.meta.xGroupKeys = S, e.meta.yGroupKeys = z, e.meta.facetKeyValues = q.reduce((a, o, f) => (a[o] = C[f], a), {}), e.meta.xGroupKeyValues = S.reduce((a, o, f) => (a[o] = x[f], a), {}), e.meta.yGroupKeyValues = z.reduce((a, o, f) => (a[o] = $[f], a), {});
|
|
169
|
+
const Y = s.valueLabels ?? s.value, F = n.valueLabels ?? n.value, T = B.filter((a) => a.axis === "x").map((a) => a.valueColumn.valueLabels ?? a.valueColumn.value), W = B.filter((a) => a.axis === "y").map((a) => a.valueColumn.valueLabels ?? a.valueColumn.value), Z = Object.values(w ?? {}).map((a) => a.value), O = Object.values(g ?? {}).map((a) => a.value), R = K.uniq([...T, ...Z, Y]), U = K.uniq([...W, ...O, F]);
|
|
170
|
+
for (let a = 0; a < t.rowsCount; a++) {
|
|
171
|
+
const o = r.length ? r.map((l) => t.getColumnValue(l.value, a)).join("_") : "null", f = p.length ? p.map((l) => t.getColumnValue(l.value, a)).join("_") : "null", L = y.length ? y.map((l) => t.getColumnValue(l.value, a)).join("_") : "null", j = p.length ? p.map((l) => t.getColumnValue(l.valueLabels ?? l.value, a)).join(", ") : "", k = y.length ? y.map((l) => t.getColumnValue(l.valueLabels ?? l.value, a)).join(", ") : "";
|
|
172
|
+
e.meta.xGroupLabels[f] = j, e.meta.yGroupLabels[L] = k;
|
|
173
|
+
const m = String(t.getColumnValue(s.value, a)), h = String(t.getColumnValue(n.value, a)), M = t.getColumnValue(u.value, a) ?? E;
|
|
174
|
+
if (m === "null" || h === "null" || M === null)
|
|
56
175
|
continue;
|
|
57
|
-
if (
|
|
176
|
+
if (e.facets[o] || (e.facets[o] = {
|
|
58
177
|
xKeys: [],
|
|
59
178
|
yKeys: [],
|
|
60
179
|
xKeysByGroups: {},
|
|
61
180
|
yKeysByGroups: {},
|
|
62
181
|
cells: {}
|
|
63
|
-
}),
|
|
64
|
-
throw Error(`More than 1 value for x=${
|
|
65
|
-
const
|
|
66
|
-
if (
|
|
67
|
-
throw Error(`More than 1 x-label value for x=${
|
|
68
|
-
const
|
|
69
|
-
if (
|
|
70
|
-
throw Error(`More than 1 y-label value for y=${
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
if (
|
|
74
|
-
throw Error(`More than 1 value for x = ${
|
|
75
|
-
|
|
76
|
-
}),
|
|
77
|
-
const
|
|
78
|
-
if (
|
|
79
|
-
throw Error(`More than 1 value for y = ${
|
|
80
|
-
|
|
81
|
-
}),
|
|
182
|
+
}), e.facets[o].xKeysByGroups[f] || (e.facets[o].xKeysByGroups[f] = []), e.facets[o].yKeysByGroups[L] || (e.facets[o].yKeysByGroups[L] = []), e.facets[o].xKeys.push(m), e.facets[o].yKeys.push(h), e.facets[o].xKeysByGroups[f].push(m), e.facets[o].yKeysByGroups[L].push(h), e.facets[o].cells[m] || (e.facets[o].cells[m] = {}), e.meta.valueExtent[0] = Math.min(M, e.meta.valueExtent[0]), e.meta.valueExtent[1] = Math.max(M, e.meta.valueExtent[1]), e.facets[o].cells[m][h] && e.facets[o].cells[m][h].value !== M)
|
|
183
|
+
throw Error(`More than 1 value for x=${m}, y=${h}`);
|
|
184
|
+
const H = t.getColumnValue(Y, a);
|
|
185
|
+
if (e.meta.xLabels[m] && String(H) !== e.meta.xLabels[m])
|
|
186
|
+
throw Error(`More than 1 x-label value for x=${m}`);
|
|
187
|
+
const J = t.getColumnValue(F, a);
|
|
188
|
+
if (e.meta.yLabels[h] && String(J) !== e.meta.yLabels[h])
|
|
189
|
+
throw Error(`More than 1 y-label value for y=${h}`);
|
|
190
|
+
e.meta.xLabels[m] = String(H), e.meta.yLabels[h] = String(J), R.forEach((l) => {
|
|
191
|
+
const I = typeof e.meta.xDataByKeys[l] < "u", _ = I && typeof e.meta.xDataByKeys[l][m] < "u";
|
|
192
|
+
if (I || (e.meta.xDataByKeys[l] = {}), _ && e.meta.xDataByKeys[l][m] !== t.getColumnValue(l, a))
|
|
193
|
+
throw Error(`More than 1 value for x = ${m} and column = ${l}`);
|
|
194
|
+
_ || (e.meta.xDataByKeys[l][m] = t.getColumnValue(l, a));
|
|
195
|
+
}), U.forEach((l) => {
|
|
196
|
+
const I = typeof e.meta.yDataByKeys[l] < "u", _ = I && typeof e.meta.yDataByKeys[l][h] < "u";
|
|
197
|
+
if (I || (e.meta.yDataByKeys[l] = {}), _ && e.meta.yDataByKeys[l][h] !== t.getColumnValue(l, a))
|
|
198
|
+
throw Error(`More than 1 value for y = ${h} and column = ${l}`);
|
|
199
|
+
_ || (e.meta.yDataByKeys[l][h] = t.getColumnValue(l, a));
|
|
200
|
+
}), e.facets[o].cells[m][h] = {
|
|
82
201
|
isCell: !0,
|
|
83
|
-
idx:
|
|
84
|
-
id: `${
|
|
85
|
-
x:
|
|
86
|
-
y:
|
|
87
|
-
value:
|
|
88
|
-
normalizedValue:
|
|
202
|
+
idx: a,
|
|
203
|
+
id: `${m}_${h}`,
|
|
204
|
+
x: m,
|
|
205
|
+
y: h,
|
|
206
|
+
value: M,
|
|
207
|
+
normalizedValue: M
|
|
89
208
|
};
|
|
90
209
|
}
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
210
|
+
return e.meta.facetKeys = e.meta.facetKeys.filter((a) => e.facets[a]), e.meta.facetKeys.forEach((a) => {
|
|
211
|
+
const o = e.facets[a], f = K.uniq(o.xKeys), L = K.uniq(o.yKeys);
|
|
212
|
+
o.xKeys = c[s.value] ? K.intersection(c[s.value], f) : f, o.yKeys = c[n.value] ? K.intersection(c[n.value], L) : L, S.forEach((j) => {
|
|
213
|
+
e.facets[a].xKeysByGroups[j] = K.intersection(
|
|
214
|
+
o.xKeys,
|
|
215
|
+
e.facets[a].xKeysByGroups[j]
|
|
97
216
|
);
|
|
98
|
-
}),
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
217
|
+
}), z.forEach((j) => {
|
|
218
|
+
e.facets[a].yKeysByGroups[j] = K.intersection(
|
|
219
|
+
o.yKeys,
|
|
220
|
+
e.facets[a].yKeysByGroups[j]
|
|
102
221
|
);
|
|
103
222
|
});
|
|
104
|
-
}),
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const h = [];
|
|
116
|
-
G.forEach((s) => {
|
|
117
|
-
var V;
|
|
118
|
-
const m = (V = r(s, p)) == null ? void 0 : V.value;
|
|
119
|
-
m !== void 0 && h.push(m);
|
|
120
|
-
});
|
|
121
|
-
const g = te(C.method, h);
|
|
122
|
-
G.forEach((s) => {
|
|
123
|
-
const m = r(s, p);
|
|
124
|
-
m !== void 0 && (m.normalizedValue = g(m.value), e[0] = Math.min(m.normalizedValue, e[0]), e[1] = Math.max(m.normalizedValue, e[1]));
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
}), t.meta.valueExtent = e;
|
|
128
|
-
}
|
|
129
|
-
return t.meta.xKeysByGroups = E.reduce((e, a) => {
|
|
130
|
-
const u = _(v.uniq(
|
|
131
|
-
v.flatten(t.meta.facetKeys.map((y) => t.facets[y].xKeysByGroups[a]))
|
|
132
|
-
), A.sorting, t.meta.xLabels);
|
|
133
|
-
return e[a] = x[o.value] ? v.intersection(x[o.value], u) : u, e;
|
|
134
|
-
}, {}), t.meta.yKeysByGroups = L.reduce((e, a) => {
|
|
135
|
-
const u = _(v.uniq(
|
|
136
|
-
v.flatten(t.meta.facetKeys.map((y) => t.facets[y].yKeysByGroups[a]))
|
|
137
|
-
), N.sorting, t.meta.yLabels);
|
|
138
|
-
return e[a] = x[l.value] ? v.intersection(x[l.value], u) : u, e;
|
|
139
|
-
}, {}), t.meta.valueExtent[0] === 1 / 0 && (t.meta.valueExtent[0] = 0), t.meta.valueExtent[1] === -1 / 0 && (t.meta.valueExtent[1] = 0), t;
|
|
223
|
+
}), ie(e, D, R, U, B), re(e, G), e.meta.xKeysByGroups = e.meta.xGroupKeys.reduce((a, o) => {
|
|
224
|
+
const f = Q(K.uniq(
|
|
225
|
+
K.flatten(e.meta.facetKeys.map((L) => e.facets[L].xKeysByGroups[o]))
|
|
226
|
+
), V.sorting, e.meta.xLabels);
|
|
227
|
+
return a[o] = c[s.value] ? K.intersection(c[s.value], f) : f, a;
|
|
228
|
+
}, {}), e.meta.yKeysByGroups = e.meta.yGroupKeys.reduce((a, o) => {
|
|
229
|
+
const f = Q(K.uniq(
|
|
230
|
+
K.flatten(e.meta.facetKeys.map((L) => e.facets[L].yKeysByGroups[o]))
|
|
231
|
+
), d.sorting, e.meta.yLabels);
|
|
232
|
+
return a[o] = c[n.value] ? K.intersection(c[n.value], f) : f, a;
|
|
233
|
+
}, {}), e.meta.valueExtent[0] === 1 / 0 && (e.meta.valueExtent[0] = 0), e.meta.valueExtent[1] === -1 / 0 && (e.meta.valueExtent[1] = 0), e;
|
|
140
234
|
}
|
|
141
235
|
export {
|
|
142
|
-
|
|
236
|
+
xe as getCells
|
|
143
237
|
};
|
|
144
238
|
//# sourceMappingURL=getCells.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCells.js","sources":["../../src/heatmap/getCells.ts"],"sourcesContent":["import { deviation, extent, mean } from 'd3-array';\nimport lodash from 'lodash';\nimport type { DataFrame } from '../DataFrame';\nimport type { ColumnName, DataValue, NormalizationMethod } from '../types';\nimport type { HeatmapSettingsImpl } from './HeatmapSettingsImpl';\n\nfunction normalizeByStd(values:number[]) {\n const stdValue = deviation(values);\n const meanValue = mean(values);\n\n if (stdValue === undefined || meanValue === undefined || stdValue === 0) {\n return (v:number) => v;\n }\n return (v:number) => (v - meanValue) / stdValue;\n}\nfunction normalizeByMinMax(values:number[]) {\n const meanValue = mean(values);\n const [min, max] = extent(values);\n if (meanValue === undefined || min === undefined || max === undefined || max === min) {\n return (v:number) => v;\n }\n return (v:number) => (v - meanValue) / (max - min);\n}\n\nfunction getNormalizationFn(method:NormalizationMethod, values:number[]) {\n if (method === 'standardScaling') {\n return normalizeByStd(values);\n }\n if (method === 'meanNormalization') {\n return normalizeByMinMax(values);\n }\n return (v:number) => v;\n}\n\nexport type Cell = {\n isCell: true;\n idx: number;\n id: string;\n value: DataValue;\n normalizedValue: DataValue;\n x: DataValue;\n y: DataValue;\n};\n\nexport type GroupedCellsData = {\n meta: {\n facetKeys: string[];\n xGroupKeys: string[];\n yGroupKeys: string[];\n xKeysByGroups: Record<string, string[]>;\n yKeysByGroups: Record<string, string[]>;\n // for titles, if facet by more 1 columns title has several values separated by commas\n facetKeyValues: Record<string, string[]>;\n xGroupKeyValues: Record<string, string[]>;\n yGroupKeyValues: Record<string, string[]>;\n xLabels: Record<string, string>;\n yLabels: Record<string, string>;\n xGroupLabels: Record<string, string>;\n yGroupLabels: Record<string, string>;\n valueExtent: [number, number]; // for color scales\n // data for labels, annotations and dendrograms\n xDataByKeys: Record<string, Record<string, DataValue>>;\n yDataByKeys: Record<string, Record<string, DataValue>>;\n };\n //facet groups\n facets: Record<\n string,\n {\n // axis keys\n xKeys: string[];\n yKeys: string[];\n // axis keys grouped by group keys from meta\n xKeysByGroups: Record<string, string[]>;\n yKeysByGroups: Record<string, string[]>;\n // cells grouped by X, then by Y\n cells: Record<string, Record<string, Cell>>;\n }\n >;\n};\n\n// all combinations with 1 key from each list\nfunction getKeysCombinations(keysLists: string[][]) {\n if (!keysLists.length) {\n return [];\n }\n let result: string[][] = [[]];\n keysLists.forEach(keys => {\n const nextResult: string[][] = [];\n keys.forEach(key => {\n nextResult.push(...result.map(resultItem => [...resultItem, key]));\n });\n result = nextResult;\n });\n return result;\n}\nconst sortByLabels = (arr: string[], direction: 'asc' | 'desc', labels: Record<string, string> = {}) => {\n return arr.sort((a, b) => direction === 'asc'\n ? (labels[a] ?? a).localeCompare((labels[b] ?? b), 'en', { numeric: true })\n : (labels[b] ?? b).localeCompare((labels[a] ?? a), 'en', { numeric: true })\n );\n};\n\nexport function getCells(\n data: DataFrame,\n xColumn: ColumnName,\n yColumn: ColumnName,\n valueColumn: ColumnName,\n facetBy: ColumnName[],\n xGroupBy: ColumnName[],\n yGroupBy: ColumnName[],\n annotations: HeatmapSettingsImpl['annotations'],\n dendrogramX: HeatmapSettingsImpl['dendrogramX'],\n dendrogramY: HeatmapSettingsImpl['dendrogramY'],\n normalization: HeatmapSettingsImpl['normalization'],\n NAValueAs: HeatmapSettingsImpl['NAValueAs'],\n keysOrder: HeatmapSettingsImpl['keysOrder'],\n xAxis: HeatmapSettingsImpl['chartSettings']['xAxis'],\n yAxis: HeatmapSettingsImpl['chartSettings']['yAxis'],\n): GroupedCellsData {\n const facetKeysLists = facetBy.length\n ? facetBy.map(column => keysOrder[column.value] ?? data.getColumnCategories(column.value))\n : [['null']];\n const xGroupKeysLists = xGroupBy.length\n ? xGroupBy.map(column => keysOrder[column.value] ?? data.getColumnCategories(column.value))\n : [['null']];\n const yGroupKeysLists = yGroupBy.length\n ? yGroupBy.map(column => keysOrder[column.value] ?? data.getColumnCategories(column.value))\n : [['null']];\n const facetKeysCombinations = getKeysCombinations(facetKeysLists);\n const xGroupKeysCombinations = getKeysCombinations(xGroupKeysLists);\n const yGroupKeysCombinations = getKeysCombinations(yGroupKeysLists);\n\n const facetKeys = facetKeysCombinations.map(keys => keys.join('_'));\n const xGroupKeys = xGroupKeysCombinations.map(keys => keys.join('_'));\n const yGroupKeys = yGroupKeysCombinations.map(keys => keys.join('_'));\n\n const result: GroupedCellsData = {\n meta: {\n facetKeys,\n xGroupKeys,\n yGroupKeys,\n xKeysByGroups: {},\n yKeysByGroups: {},\n xLabels: {},\n yLabels: {},\n xGroupLabels: {},\n yGroupLabels: {},\n xDataByKeys: {},\n yDataByKeys: {},\n facetKeyValues: facetKeys.reduce((res: Record<string, string[]>, key, index) => {\n res[key] = facetKeysCombinations[index];\n return res;\n }, {}),\n xGroupKeyValues: xGroupKeys.reduce((res: Record<string, string[]>, key, index) => {\n res[key] = xGroupKeysCombinations[index];\n return res;\n }, {}),\n yGroupKeyValues: yGroupKeys.reduce((res: Record<string, string[]>, key, index) => {\n res[key] = yGroupKeysCombinations[index];\n return res;\n }, {}),\n valueExtent: [Infinity, -Infinity],\n },\n facets: {},\n };\n\n const xLabelsSource = xColumn.valueLabels ?? xColumn.value;\n const yLabelsSource = yColumn.valueLabels ?? yColumn.value;\n const annotationColumnsX = annotations.filter(item => item.axis === 'x').map(item => item.valueColumn.value);\n const annotationColumnsY = annotations.filter(item => item.axis === 'y').map(item => item.valueColumn.value);\n const dendrogramXColumns = Object.values(dendrogramX ?? {}).map(column => column.value);\n const dendrogramYColumns = Object.values(dendrogramY ?? {}).map(column => column.value);\n const additionalDataColumnsX = lodash.uniq([...annotationColumnsX, ...dendrogramXColumns, xLabelsSource]);\n const additionalDataColumnsY = lodash.uniq([...annotationColumnsY, ...dendrogramYColumns, yLabelsSource]);\n\n for (let i = 0; i < data.rowsCount; i++) {\n const facetKey = facetBy.length ? facetBy.map(column => data.getColumnValue(column.value, i)).join('_') : 'null';\n const xGroupKey = xGroupBy.length ? xGroupBy.map(column => data.getColumnValue(column.value, i)).join('_') : 'null';\n const yGroupKey = yGroupBy.length ? yGroupBy.map(column => data.getColumnValue(column.value, i)).join('_') : 'null';\n const xGroupLabel = xGroupBy.length ? xGroupBy.map(column => data.getColumnValue(column.valueLabels ?? column.value, i)).join(', ') : '';\n const yGroupLabel = yGroupBy.length ? yGroupBy.map(column => data.getColumnValue(column.valueLabels ?? column.value, i)).join(', ') : '';\n result.meta.xGroupLabels[xGroupKey] = xGroupLabel;\n result.meta.yGroupLabels[yGroupKey] = yGroupLabel;\n const x = String(data.getColumnValue(xColumn.value, i));\n const y = String(data.getColumnValue(yColumn.value, i));\n const value = (data.getColumnValue(valueColumn.value, i) ?? NAValueAs) as number | null;\n \n if (x === 'null' || y === 'null' || value === null) {\n continue;\n }\n\n if (!result.facets[facetKey]) {\n result.facets[facetKey] = {\n xKeys: [],\n yKeys: [],\n xKeysByGroups: {},\n yKeysByGroups: {},\n cells: {},\n };\n }\n if (!result.facets[facetKey].xKeysByGroups[xGroupKey]) {\n result.facets[facetKey].xKeysByGroups[xGroupKey] = [];\n }\n if (!result.facets[facetKey].yKeysByGroups[yGroupKey]) {\n result.facets[facetKey].yKeysByGroups[yGroupKey] = [];\n }\n result.facets[facetKey].xKeys.push(x);\n result.facets[facetKey].yKeys.push(y);\n result.facets[facetKey].xKeysByGroups[xGroupKey].push(x);\n result.facets[facetKey].yKeysByGroups[yGroupKey].push(y);\n\n if (!result.facets[facetKey].cells[x]) {\n result.facets[facetKey].cells[x] = {};\n }\n result.meta.valueExtent[0] = Math.min(value, result.meta.valueExtent[0]);\n result.meta.valueExtent[1] = Math.max(value, result.meta.valueExtent[1]);\n if (result.facets[facetKey].cells[x][y] && result.facets[facetKey].cells[x][y].value !== value) {\n throw Error(`More than 1 value for x=${x}, y=${y}`);\n }\n const xLabelsSourceValue = data.getColumnValue(xLabelsSource, i);\n if (result.meta.xLabels[x] && String(xLabelsSourceValue) !== result.meta.xLabels[x]) {\n throw Error(`More than 1 x-label value for x=${x}`);\n }\n const yLabelsSourceValue = data.getColumnValue(yLabelsSource, i);\n if (result.meta.yLabels[y] && String(yLabelsSourceValue) !== result.meta.yLabels[y]) {\n throw Error(`More than 1 y-label value for y=${y}`);\n }\n result.meta.xLabels[x] = String(xLabelsSourceValue);\n result.meta.yLabels[y] = String(yLabelsSourceValue);\n // data for labels, annotations and dendrograms by X\n additionalDataColumnsX.forEach(columnKey => {\n const isAddedColumn = typeof result.meta.xDataByKeys[columnKey] !== 'undefined';\n const isAddedValue = isAddedColumn && typeof result.meta.xDataByKeys[columnKey][x] !== 'undefined';\n if (!isAddedColumn) {\n result.meta.xDataByKeys[columnKey] = {};\n }\n if (isAddedValue && result.meta.xDataByKeys[columnKey][x] !== data.getColumnValue(columnKey, i)) {\n throw Error(`More than 1 value for x = ${x} and column = ${columnKey}`);\n }\n if (!isAddedValue) {\n result.meta.xDataByKeys[columnKey][x] = data.getColumnValue(columnKey, i);\n }\n });\n // data for labels, annotations and dendrograms by Y\n additionalDataColumnsY.forEach(columnKey => {\n const isAddedColumn = typeof result.meta.yDataByKeys[columnKey] !== 'undefined';\n const isAddedValue = isAddedColumn && typeof result.meta.yDataByKeys[columnKey][y] !== 'undefined';\n if (!isAddedColumn) {\n result.meta.yDataByKeys[columnKey] = {};\n }\n if (isAddedValue && result.meta.yDataByKeys[columnKey][y] !== data.getColumnValue(columnKey, i)) {\n throw Error(`More than 1 value for y = ${y} and column = ${columnKey}`);\n }\n if (!isAddedValue) {\n result.meta.yDataByKeys[columnKey][y] = data.getColumnValue(columnKey, i);\n }\n });\n result.facets[facetKey].cells[x][y] = {\n isCell: true,\n idx: i,\n id: `${x}_${y}`,\n x,\n y,\n value,\n normalizedValue: value,\n };\n }\n\n result.meta.facetKeys = result.meta.facetKeys.filter((key) => result.facets[key]); // filter only used;\n\n // make uniq x, y, x-group and y-group keys\n result.meta.facetKeys.forEach(facetKey => {\n const facet = result.facets[facetKey];\n const uniqueXKeys = lodash.uniq(facet.xKeys);\n const uniqueYKeys = lodash.uniq(facet.yKeys);\n facet.xKeys = keysOrder[xColumn.value] ? lodash.intersection(keysOrder[xColumn.value], uniqueXKeys) : uniqueXKeys;\n facet.yKeys = keysOrder[yColumn.value] ? lodash.intersection(keysOrder[yColumn.value], uniqueYKeys) : uniqueYKeys;\n xGroupKeys.forEach(xGroupKey => {\n result.facets[facetKey].xKeysByGroups[xGroupKey] = lodash.intersection(\n facet.xKeys,\n result.facets[facetKey].xKeysByGroups[xGroupKey]\n );\n });\n yGroupKeys.forEach(yGroupKey => {\n result.facets[facetKey].yKeysByGroups[yGroupKey] = lodash.intersection(\n facet.yKeys,\n result.facets[facetKey].yKeysByGroups[yGroupKey]\n );\n });\n });\n\n if (normalization) {\n const valueExtent = [Infinity, -Infinity] as [number, number];\n result.meta.facetKeys.forEach(facetKey => {\n const {xKeys, yKeys, cells} = result.facets[facetKey];\n const cellKeys = normalization.direction === 'row' ? xKeys : yKeys;\n const groupKeys = normalization.direction === 'row' ? yKeys : xKeys;\n const cellGetter = normalization.direction === 'row'\n ? (cellKey:string, groupKey:string) => cells[cellKey]?.[groupKey]\n : (cellKey:string, groupKey:string) => cells[groupKey]?.[cellKey];\n groupKeys.forEach((groupKey) => {\n const values:number[] = [];\n cellKeys.forEach((cellKey) => {\n const v = cellGetter(cellKey, groupKey)?.value;\n if (v !== undefined) {\n values.push(v as number);\n }\n });\n const normalize = getNormalizationFn(normalization.method, values);\n cellKeys.forEach((cellKey) => {\n const cell = cellGetter(cellKey, groupKey);\n if (cell !== undefined) {\n cell.normalizedValue = normalize(cell.value as number);\n valueExtent[0] = Math.min(cell.normalizedValue, valueExtent[0]);\n valueExtent[1] = Math.max(cell.normalizedValue, valueExtent[1]);\n }\n });\n });\n });\n result.meta.valueExtent = valueExtent;\n }\n\n // every facet may contain not all of available keys, but for shared axes it is necessary to have all of them\n result.meta.xKeysByGroups = xGroupKeys.reduce((res: Record<string, string[]>, xGroupKey) => {\n const existingXKeys = sortByLabels(lodash.uniq(\n lodash.flatten(result.meta.facetKeys.map(facetKey => result.facets[facetKey].xKeysByGroups[xGroupKey]))\n ), xAxis.sorting, result.meta.xLabels);\n res[xGroupKey] = keysOrder[xColumn.value] ? lodash.intersection(keysOrder[xColumn.value], existingXKeys) : existingXKeys;\n return res;\n }, {});\n result.meta.yKeysByGroups = yGroupKeys.reduce((res: Record<string, string[]>, yGroupKey) => {\n const existingYKeys = sortByLabels(lodash.uniq(\n lodash.flatten(result.meta.facetKeys.map(facetKey => result.facets[facetKey].yKeysByGroups[yGroupKey]))\n ), yAxis.sorting, result.meta.yLabels);\n res[yGroupKey] = keysOrder[yColumn.value] ? lodash.intersection(keysOrder[yColumn.value], existingYKeys) : existingYKeys;\n return res;\n }, {});\n\n // avoid render errors on empty data\n if (result.meta.valueExtent[0] === Infinity) {\n result.meta.valueExtent[0] = 0;\n }\n if (result.meta.valueExtent[1] === -Infinity) {\n result.meta.valueExtent[1] = 0;\n }\n\n return result;\n}\n"],"names":["normalizeByStd","values","stdValue","deviation","meanValue","mean","v","normalizeByMinMax","min","max","extent","getNormalizationFn","method","getKeysCombinations","keysLists","result","keys","nextResult","key","resultItem","sortByLabels","arr","direction","labels","a","b","getCells","data","xColumn","yColumn","valueColumn","facetBy","xGroupBy","yGroupBy","annotations","dendrogramX","dendrogramY","normalization","NAValueAs","keysOrder","xAxis","yAxis","facetKeysLists","column","xGroupKeysLists","yGroupKeysLists","facetKeysCombinations","xGroupKeysCombinations","yGroupKeysCombinations","facetKeys","xGroupKeys","yGroupKeys","res","index","xLabelsSource","yLabelsSource","annotationColumnsX","item","annotationColumnsY","dendrogramXColumns","dendrogramYColumns","additionalDataColumnsX","lodash","additionalDataColumnsY","i","facetKey","xGroupKey","yGroupKey","xGroupLabel","yGroupLabel","x","y","value","xLabelsSourceValue","yLabelsSourceValue","columnKey","isAddedColumn","isAddedValue","facet","uniqueXKeys","uniqueYKeys","valueExtent","xKeys","yKeys","cells","cellKeys","groupKeys","cellGetter","cellKey","groupKey","_a","normalize","cell","existingXKeys","existingYKeys"],"mappings":";;;;AAMA,SAASA,EAAeC,GAAiB;AACrC,QAAMC,IAAWC,EAAUF,CAAM,GAC3BG,IAAYC,EAAKJ,CAAM;AAE7B,SAAIC,MAAa,UAAaE,MAAc,UAAaF,MAAa,IAC3D,CAACI,MAAaA,IAElB,CAACA,OAAcA,IAAIF,KAAaF;AAC3C;AACA,SAASK,GAAkBN,GAAiB;AACxC,QAAMG,IAAYC,EAAKJ,CAAM,GACvB,CAACO,GAAKC,CAAG,IAAIC,EAAOT,CAAM;AAChC,SAAIG,MAAc,UAAaI,MAAQ,UAAaC,MAAQ,UAAaA,MAAQD,IACtE,CAACF,MAAaA,IAElB,CAACA,OAAcA,IAAIF,MAAcK,IAAMD;AAClD;AAEA,SAASG,GAAmBC,GAA4BX,GAAiB;AACrE,SAAIW,MAAW,oBACJZ,EAAeC,CAAM,IAE5BW,MAAW,sBACJL,GAAkBN,CAAM,IAE5B,CAACK,MAAaA;AACzB;AAiDA,SAASO,EAAoBC,GAAuB;AAChD,MAAI,CAACA,EAAU;AACX,WAAO,CAAA;AAEX,MAAIC,IAAqB,CAAC,EAAE;AAC5B,SAAAD,EAAU,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sourcesContent":["import { deviation, extent, mean, quantileSorted } from 'd3-array';\nimport lodash from 'lodash';\nimport type { DataFrame } from '../DataFrame';\nimport type { AggregationMethod, ColumnName, DataValue, NormalizationMethod } from '../types';\nimport type { HeatmapSettingsImpl } from './HeatmapSettingsImpl';\nimport { exhaustive } from '../utils';\n\nfunction normalizeByStd(values: number[]) {\n const stdValue = deviation(values);\n const meanValue = mean(values);\n\n if (stdValue === undefined || meanValue === undefined || stdValue === 0) {\n return (v: number) => v;\n }\n return (v: number) => (v - meanValue) / stdValue;\n}\nfunction normalizeByMinMax(values: number[]) {\n const meanValue = mean(values);\n const [min, max] = extent(values);\n if (meanValue === undefined || min === undefined || max === undefined || max === min) {\n return (v: number) => v;\n }\n return (v: number) => (v - meanValue) / (max - min);\n}\n\nfunction getNormalizationFn(method: NormalizationMethod, values: number[]) {\n if (method === 'standardScaling') {\n return normalizeByStd(values);\n }\n if (method === 'meanNormalization') {\n return normalizeByMinMax(values);\n }\n return (v: number) => v;\n}\n\nfunction aggregateNumeric(method: AggregationMethod, values: number[]) {\n switch (method) {\n case 'max': {\n let res = values[0];\n for (const v of values) {\n res = Math.max(res, v);\n }\n return res;\n }\n case 'min': {\n let res = values[0];\n for (const v of values) {\n res = Math.min(res, v);\n }\n return res;\n }\n case 'median': {\n const valuesSorted = values.sort((a, b) => a - b);\n return quantileSorted(valuesSorted, 0.5) as number;\n }\n case 'mean': {\n return mean(values) ?? values[0];\n }\n default: exhaustive(method, `Unknown aggregation function ${method}`);\n }\n}\nfunction aggregateString(values: string[]) {\n const list = [...new Set(values)].sort();\n if (list.length > 3) {\n return [...list.slice(0, 3), '...'].join(', ');\n }\n return list.join(', ');\n}\n\nexport type Cell = {\n isCell: true;\n idx: number;\n id: string;\n value: DataValue;\n normalizedValue: DataValue;\n x: DataValue;\n y: DataValue;\n};\n\nexport type GroupedCellsData = {\n meta: {\n facetKeys: string[];\n xGroupKeys: string[];\n yGroupKeys: string[];\n xKeysByGroups: Record<string, string[]>;\n yKeysByGroups: Record<string, string[]>;\n // for titles, if facet by more 1 columns title has several values separated by commas\n facetKeyValues: Record<string, string[]>;\n xGroupKeyValues: Record<string, string[]>;\n yGroupKeyValues: Record<string, string[]>;\n xLabels: Record<string, string>;\n yLabels: Record<string, string>;\n xGroupLabels: Record<string, string>;\n yGroupLabels: Record<string, string>;\n valueExtent: [number, number]; // for color scales\n // data for labels, annotations and dendrograms\n xDataByKeys: Record<string, Record<string, DataValue>>;\n yDataByKeys: Record<string, Record<string, DataValue>>;\n };\n //facet groups\n facets: Record<\n string,\n {\n // axis keys\n xKeys: string[];\n yKeys: string[];\n // axis keys grouped by group keys from meta\n xKeysByGroups: Record<string, string[]>;\n yKeysByGroups: Record<string, string[]>;\n // cells grouped by X, then by Y\n cells: Record<string, Record<string, Cell>>;\n }\n >;\n};\n\n// all combinations with 1 key from each list\nfunction getKeysCombinations(keysLists: string[][]) {\n if (!keysLists.length) {\n return [];\n }\n let result: string[][] = [[]];\n keysLists.forEach(keys => {\n const nextResult: string[][] = [];\n keys.forEach(key => {\n nextResult.push(...result.map(resultItem => [...resultItem, key]));\n });\n result = nextResult;\n });\n return result;\n}\nconst sortByLabels = (arr: string[], direction: 'asc' | 'desc', labels: Record<string, string> = {}) => {\n return arr.sort((a, b) => direction === 'asc'\n ? (labels[a] ?? a).localeCompare((labels[b] ?? b), 'en', { numeric: true })\n : (labels[b] ?? b).localeCompare((labels[a] ?? a), 'en', { numeric: true })\n );\n};\n\nfunction createEmptyGroupedCells(): GroupedCellsData {\n return {\n meta: {\n facetKeys: [],\n xGroupKeys: [],\n yGroupKeys: [],\n xKeysByGroups: {},\n yKeysByGroups: {},\n xLabels: {},\n yLabels: {},\n xGroupLabels: {},\n yGroupLabels: {},\n xDataByKeys: {},\n yDataByKeys: {},\n facetKeyValues: {},\n xGroupKeyValues: {},\n yGroupKeyValues: {},\n valueExtent: [Infinity, -Infinity],\n },\n facets: {},\n };\n}\n\nfunction applyAggregation(\n result: GroupedCellsData,\n aggregation: HeatmapSettingsImpl['aggregation'],\n additionalDataColumnsX: string[],\n additionalDataColumnsY: string[],\n annotations: HeatmapSettingsImpl['annotations']\n) {\n if (aggregation.x || aggregation.y) {\n const valueExtent = [Infinity, -Infinity] as [number, number];\n result.meta.facetKeys.forEach(facetKey => {\n const { xKeys, yKeys, cells, xKeysByGroups, yKeysByGroups } = result.facets[facetKey];\n const xGroups = aggregation.x ? xKeysByGroups : xKeys.reduce((res, xKey) => { res[xKey] = [xKey]; return res; }, {} as Record<string, string[]>);\n const yGroups = aggregation.y ? yKeysByGroups : yKeys.reduce((res, yKey) => { res[yKey] = [yKey]; return res; }, {} as Record<string, string[]>);\n const xNewKeys = Object.keys(xGroups);\n const yNewKeys = Object.keys(yGroups);\n for (const xGroupKey of xNewKeys) {\n for (const yGroupKey of yNewKeys) {\n const values: number[] = [];\n xGroups[xGroupKey].forEach((xKey) => {\n yGroups[yGroupKey].forEach((yKey) => {\n const cellValue = cells[xKey]?.[yKey]?.value;\n if (cellValue !== undefined) {\n values.push(cellValue as number);\n delete cells[xKey]?.[yKey];\n }\n });\n });\n if (values.length > 0) {\n const value = aggregateNumeric(aggregation.method, values);\n if (!result.facets[facetKey].cells[xGroupKey]) {\n result.facets[facetKey].cells[xGroupKey] = {};\n }\n result.facets[facetKey].cells[xGroupKey][yGroupKey] = {\n isCell: true,\n idx: 0,\n id: `${xGroupKey}_${yGroupKey}`,\n x: xGroupKey,\n y: yGroupKey,\n value,\n normalizedValue: value,\n };\n valueExtent[0] = Math.min(value, valueExtent[0]);\n valueExtent[1] = Math.max(value, valueExtent[1]);\n }\n }\n }\n if (aggregation.x) {\n xNewKeys.forEach(xGroupKey => {\n additionalDataColumnsX.forEach(columnKey => {\n const annotation = annotations.find((v) => v.valueColumn.value === columnKey || v.valueColumn.valueLabels === columnKey);\n if (!annotation) {\n return;\n }\n const values: DataValue[] = [];\n xGroups[xGroupKey].forEach((xKey) => {\n values.push(result.meta.xDataByKeys[columnKey][xKey]);\n delete result.meta.xDataByKeys[columnKey][xKey];\n });\n const value = annotation.type === 'continuous' ? aggregateNumeric(aggregation.method, values as number[]) : aggregateString(values as string[]);\n result.meta.xDataByKeys[columnKey][xGroupKey] = value;\n });\n });\n }\n if (aggregation.y) {\n additionalDataColumnsY.forEach(columnKey => {\n result.meta.yDataByKeys[columnKey] = {};\n });\n yNewKeys.forEach(yGroupKey => {\n additionalDataColumnsY.forEach(columnKey => {\n const annotation = annotations.find((v) => v.valueColumn.value === columnKey || v.valueColumn.valueLabels === columnKey);\n if (!annotation) {\n return;\n }\n const values: DataValue[] = [];\n yGroups[yGroupKey].forEach((yKey) => {\n values.push(result.meta.yDataByKeys[columnKey][yKey]);\n delete result.meta.yDataByKeys[columnKey][yKey];\n });\n const value = annotation.type === 'continuous' ? aggregateNumeric(aggregation.method, values as number[]) : aggregateString(values as string[]);\n result.meta.yDataByKeys[columnKey][yGroupKey] = value;\n });\n });\n }\n if (aggregation.x) {\n result.facets[facetKey].xKeys = Object.keys(xKeysByGroups);\n result.facets[facetKey].xKeysByGroups = { 'null': result.facets[facetKey].xKeys };\n result.meta.xLabels = result.meta.xGroupLabels;\n result.meta.xGroupKeys = ['null'];\n result.meta.xGroupKeyValues = { null: ['null'] };\n }\n if (aggregation.y) {\n result.facets[facetKey].yKeys = Object.keys(yKeysByGroups);\n result.facets[facetKey].yKeysByGroups = { 'null': result.facets[facetKey].yKeys };\n result.meta.yLabels = result.meta.yGroupLabels;\n result.meta.yGroupKeys = ['null'];\n result.meta.yGroupKeyValues = { null: ['null'] };\n }\n });\n result.meta.valueExtent = valueExtent;\n }\n}\nfunction applyNormalization(result: GroupedCellsData, normalization: HeatmapSettingsImpl['normalization']) {\n if (normalization) {\n const valueExtent = [Infinity, -Infinity] as [number, number];\n result.meta.facetKeys.forEach(facetKey => {\n const { xKeys, yKeys, cells } = result.facets[facetKey];\n const cellKeys = normalization.direction === 'row' ? xKeys : yKeys;\n const groupKeys = normalization.direction === 'row' ? yKeys : xKeys;\n const cellGetter = normalization.direction === 'row'\n ? (cellKey: string, groupKey: string) => cells[cellKey]?.[groupKey]\n : (cellKey: string, groupKey: string) => cells[groupKey]?.[cellKey];\n groupKeys.forEach((groupKey) => {\n const values: number[] = [];\n cellKeys.forEach((cellKey) => {\n const v = cellGetter(cellKey, groupKey)?.value;\n if (v !== undefined) {\n values.push(v as number);\n }\n });\n const normalize = getNormalizationFn(normalization.method, values);\n cellKeys.forEach((cellKey) => {\n const cell = cellGetter(cellKey, groupKey);\n if (cell !== undefined) {\n cell.normalizedValue = normalize(cell.value as number);\n valueExtent[0] = Math.min(cell.normalizedValue, valueExtent[0]);\n valueExtent[1] = Math.max(cell.normalizedValue, valueExtent[1]);\n }\n });\n });\n });\n result.meta.valueExtent = valueExtent;\n }\n}\n\nexport function getCells(\n data: DataFrame,\n xColumn: ColumnName,\n yColumn: ColumnName,\n valueColumn: ColumnName,\n facetBy: ColumnName[],\n xGroupBy: ColumnName[],\n yGroupBy: ColumnName[],\n annotations: HeatmapSettingsImpl['annotations'],\n dendrogramX: HeatmapSettingsImpl['dendrogramX'],\n dendrogramY: HeatmapSettingsImpl['dendrogramY'],\n normalization: HeatmapSettingsImpl['normalization'],\n NAValueAs: HeatmapSettingsImpl['NAValueAs'],\n keysOrder: HeatmapSettingsImpl['keysOrder'],\n xAxis: HeatmapSettingsImpl['chartSettings']['xAxis'],\n yAxis: HeatmapSettingsImpl['chartSettings']['yAxis'],\n aggregation: HeatmapSettingsImpl['aggregation'],\n): GroupedCellsData {\n const result: GroupedCellsData = createEmptyGroupedCells();\n\n const facetKeysLists = facetBy.length\n ? facetBy.map(column => keysOrder[column.value] ?? data.getColumnCategories(column.value))\n : [['null']];\n const xGroupKeysLists = xGroupBy.length\n ? xGroupBy.map(column => keysOrder[column.value] ?? data.getColumnCategories(column.value))\n : [['null']];\n const yGroupKeysLists = yGroupBy.length\n ? yGroupBy.map(column => keysOrder[column.value] ?? data.getColumnCategories(column.value))\n : [['null']];\n const facetKeysCombinations = getKeysCombinations(facetKeysLists);\n const xGroupKeysCombinations = getKeysCombinations(xGroupKeysLists);\n const yGroupKeysCombinations = getKeysCombinations(yGroupKeysLists);\n\n const facetKeys = facetKeysCombinations.map(keys => keys.join('_'));\n const xGroupKeys = xGroupKeysCombinations.map(keys => keys.join('_'));\n const yGroupKeys = yGroupKeysCombinations.map(keys => keys.join('_'));\n\n result.meta.facetKeys = facetKeys;\n result.meta.xGroupKeys = xGroupKeys;\n result.meta.yGroupKeys = yGroupKeys;\n result.meta.facetKeyValues = facetKeys.reduce((res: Record<string, string[]>, key, index) => {\n res[key] = facetKeysCombinations[index];\n return res;\n }, {});\n result.meta.xGroupKeyValues = xGroupKeys.reduce((res: Record<string, string[]>, key, index) => {\n res[key] = xGroupKeysCombinations[index];\n return res;\n }, {});\n result.meta.yGroupKeyValues = yGroupKeys.reduce((res: Record<string, string[]>, key, index) => {\n res[key] = yGroupKeysCombinations[index];\n return res;\n }, {});\n\n const xLabelsSource = xColumn.valueLabels ?? xColumn.value;\n const yLabelsSource = yColumn.valueLabels ?? yColumn.value;\n const annotationColumnsX = annotations.filter(item => item.axis === 'x').map(item => item.valueColumn.valueLabels ?? item.valueColumn.value);\n const annotationColumnsY = annotations.filter(item => item.axis === 'y').map(item => item.valueColumn.valueLabels ?? item.valueColumn.value);\n const dendrogramXColumns = Object.values(dendrogramX ?? {}).map(column => column.value);\n const dendrogramYColumns = Object.values(dendrogramY ?? {}).map(column => column.value);\n const additionalDataColumnsX = lodash.uniq([...annotationColumnsX, ...dendrogramXColumns, xLabelsSource]);\n const additionalDataColumnsY = lodash.uniq([...annotationColumnsY, ...dendrogramYColumns, yLabelsSource]);\n\n for (let i = 0; i < data.rowsCount; i++) {\n const facetKey = facetBy.length ? facetBy.map(column => data.getColumnValue(column.value, i)).join('_') : 'null';\n const xGroupKey = xGroupBy.length ? xGroupBy.map(column => data.getColumnValue(column.value, i)).join('_') : 'null';\n const yGroupKey = yGroupBy.length ? yGroupBy.map(column => data.getColumnValue(column.value, i)).join('_') : 'null';\n const xGroupLabel = xGroupBy.length ? xGroupBy.map(column => data.getColumnValue(column.valueLabels ?? column.value, i)).join(', ') : '';\n const yGroupLabel = yGroupBy.length ? yGroupBy.map(column => data.getColumnValue(column.valueLabels ?? column.value, i)).join(', ') : '';\n result.meta.xGroupLabels[xGroupKey] = xGroupLabel;\n result.meta.yGroupLabels[yGroupKey] = yGroupLabel;\n const x = String(data.getColumnValue(xColumn.value, i));\n const y = String(data.getColumnValue(yColumn.value, i));\n const value = (data.getColumnValue(valueColumn.value, i) ?? NAValueAs) as number | null;\n\n if (x === 'null' || y === 'null' || value === null) {\n continue;\n }\n\n if (!result.facets[facetKey]) {\n result.facets[facetKey] = {\n xKeys: [],\n yKeys: [],\n xKeysByGroups: {},\n yKeysByGroups: {},\n cells: {},\n };\n }\n if (!result.facets[facetKey].xKeysByGroups[xGroupKey]) {\n result.facets[facetKey].xKeysByGroups[xGroupKey] = [];\n }\n if (!result.facets[facetKey].yKeysByGroups[yGroupKey]) {\n result.facets[facetKey].yKeysByGroups[yGroupKey] = [];\n }\n result.facets[facetKey].xKeys.push(x);\n result.facets[facetKey].yKeys.push(y);\n result.facets[facetKey].xKeysByGroups[xGroupKey].push(x);\n result.facets[facetKey].yKeysByGroups[yGroupKey].push(y);\n\n if (!result.facets[facetKey].cells[x]) {\n result.facets[facetKey].cells[x] = {};\n }\n result.meta.valueExtent[0] = Math.min(value, result.meta.valueExtent[0]);\n result.meta.valueExtent[1] = Math.max(value, result.meta.valueExtent[1]);\n if (result.facets[facetKey].cells[x][y] && result.facets[facetKey].cells[x][y].value !== value) {\n throw Error(`More than 1 value for x=${x}, y=${y}`);\n }\n const xLabelsSourceValue = data.getColumnValue(xLabelsSource, i);\n if (result.meta.xLabels[x] && String(xLabelsSourceValue) !== result.meta.xLabels[x]) {\n throw Error(`More than 1 x-label value for x=${x}`);\n }\n const yLabelsSourceValue = data.getColumnValue(yLabelsSource, i);\n if (result.meta.yLabels[y] && String(yLabelsSourceValue) !== result.meta.yLabels[y]) {\n throw Error(`More than 1 y-label value for y=${y}`);\n }\n result.meta.xLabels[x] = String(xLabelsSourceValue);\n result.meta.yLabels[y] = String(yLabelsSourceValue);\n // data for labels, annotations and dendrograms by X\n additionalDataColumnsX.forEach(columnKey => {\n const isAddedColumn = typeof result.meta.xDataByKeys[columnKey] !== 'undefined';\n const isAddedValue = isAddedColumn && typeof result.meta.xDataByKeys[columnKey][x] !== 'undefined';\n if (!isAddedColumn) {\n result.meta.xDataByKeys[columnKey] = {};\n }\n if (isAddedValue && result.meta.xDataByKeys[columnKey][x] !== data.getColumnValue(columnKey, i)) {\n throw Error(`More than 1 value for x = ${x} and column = ${columnKey}`);\n }\n if (!isAddedValue) {\n result.meta.xDataByKeys[columnKey][x] = data.getColumnValue(columnKey, i);\n }\n });\n // data for labels, annotations and dendrograms by Y\n additionalDataColumnsY.forEach(columnKey => {\n const isAddedColumn = typeof result.meta.yDataByKeys[columnKey] !== 'undefined';\n const isAddedValue = isAddedColumn && typeof result.meta.yDataByKeys[columnKey][y] !== 'undefined';\n if (!isAddedColumn) {\n result.meta.yDataByKeys[columnKey] = {};\n }\n if (isAddedValue && result.meta.yDataByKeys[columnKey][y] !== data.getColumnValue(columnKey, i)) {\n throw Error(`More than 1 value for y = ${y} and column = ${columnKey}`);\n }\n if (!isAddedValue) {\n result.meta.yDataByKeys[columnKey][y] = data.getColumnValue(columnKey, i);\n }\n });\n result.facets[facetKey].cells[x][y] = {\n isCell: true,\n idx: i,\n id: `${x}_${y}`,\n x,\n y,\n value,\n normalizedValue: value,\n };\n }\n\n result.meta.facetKeys = result.meta.facetKeys.filter((key) => result.facets[key]); // filter only used;\n\n // make uniq x, y, x-group and y-group keys\n result.meta.facetKeys.forEach(facetKey => {\n const facet = result.facets[facetKey];\n const uniqueXKeys = lodash.uniq(facet.xKeys);\n const uniqueYKeys = lodash.uniq(facet.yKeys);\n facet.xKeys = keysOrder[xColumn.value] ? lodash.intersection(keysOrder[xColumn.value], uniqueXKeys) : uniqueXKeys;\n facet.yKeys = keysOrder[yColumn.value] ? lodash.intersection(keysOrder[yColumn.value], uniqueYKeys) : uniqueYKeys;\n xGroupKeys.forEach(xGroupKey => {\n result.facets[facetKey].xKeysByGroups[xGroupKey] = lodash.intersection(\n facet.xKeys,\n result.facets[facetKey].xKeysByGroups[xGroupKey]\n );\n });\n yGroupKeys.forEach(yGroupKey => {\n result.facets[facetKey].yKeysByGroups[yGroupKey] = lodash.intersection(\n facet.yKeys,\n result.facets[facetKey].yKeysByGroups[yGroupKey]\n );\n });\n });\n\n applyAggregation(result, aggregation, additionalDataColumnsX, additionalDataColumnsY, annotations);\n applyNormalization(result, normalization);\n\n // every facet may contain not all of available keys, but for shared axes it is necessary to have all of them\n result.meta.xKeysByGroups = result.meta.xGroupKeys.reduce((res: Record<string, string[]>, xGroupKey) => {\n const existingXKeys = sortByLabels(lodash.uniq(\n lodash.flatten(result.meta.facetKeys.map(facetKey => result.facets[facetKey].xKeysByGroups[xGroupKey]))\n ), xAxis.sorting, result.meta.xLabels);\n res[xGroupKey] = keysOrder[xColumn.value] ? lodash.intersection(keysOrder[xColumn.value], existingXKeys) : existingXKeys;\n return res;\n }, {});\n result.meta.yKeysByGroups = result.meta.yGroupKeys.reduce((res: Record<string, string[]>, yGroupKey) => {\n const existingYKeys = sortByLabels(lodash.uniq(\n lodash.flatten(result.meta.facetKeys.map(facetKey => result.facets[facetKey].yKeysByGroups[yGroupKey]))\n ), yAxis.sorting, result.meta.yLabels);\n res[yGroupKey] = keysOrder[yColumn.value] ? lodash.intersection(keysOrder[yColumn.value], existingYKeys) : existingYKeys;\n return res;\n }, {});\n\n // avoid render errors on empty data\n if (result.meta.valueExtent[0] === Infinity) {\n result.meta.valueExtent[0] = 0;\n }\n if (result.meta.valueExtent[1] === -Infinity) {\n result.meta.valueExtent[1] = 0;\n }\n\n return result;\n}\n"],"names":["normalizeByStd","values","stdValue","deviation","meanValue","mean","v","normalizeByMinMax","min","max","extent","getNormalizationFn","method","aggregateNumeric","res","valuesSorted","a","b","quantileSorted","exhaustive","aggregateString","list","getKeysCombinations","keysLists","result","keys","nextResult","key","resultItem","sortByLabels","arr","direction","labels","createEmptyGroupedCells","applyAggregation","aggregation","additionalDataColumnsX","additionalDataColumnsY","annotations","valueExtent","facetKey","xKeys","yKeys","cells","xKeysByGroups","yKeysByGroups","xGroups","xKey","yGroups","yKey","xNewKeys","yNewKeys","xGroupKey","yGroupKey","cellValue","_b","_a","_c","value","columnKey","annotation","applyNormalization","normalization","cellKeys","groupKeys","cellGetter","cellKey","groupKey","normalize","cell","getCells","data","xColumn","yColumn","valueColumn","facetBy","xGroupBy","yGroupBy","dendrogramX","dendrogramY","NAValueAs","keysOrder","xAxis","yAxis","facetKeysLists","column","xGroupKeysLists","yGroupKeysLists","facetKeysCombinations","xGroupKeysCombinations","yGroupKeysCombinations","facetKeys","xGroupKeys","yGroupKeys","index","xLabelsSource","yLabelsSource","annotationColumnsX","item","annotationColumnsY","dendrogramXColumns","dendrogramYColumns","lodash","i","xGroupLabel","yGroupLabel","x","y","xLabelsSourceValue","yLabelsSourceValue","isAddedColumn","isAddedValue","facet","uniqueXKeys","uniqueYKeys","existingXKeys","existingYKeys"],"mappings":";;;;;;AAOA,SAASA,GAAeC,GAAkB;AACtC,QAAMC,IAAWC,GAAUF,CAAM,GAC3BG,IAAYC,EAAKJ,CAAM;AAE7B,SAAIC,MAAa,UAAaE,MAAc,UAAaF,MAAa,IAC3D,CAACI,MAAcA,IAEnB,CAACA,OAAeA,IAAIF,KAAaF;AAC5C;AACA,SAASK,GAAkBN,GAAkB;AACzC,QAAMG,IAAYC,EAAKJ,CAAM,GACvB,CAACO,GAAKC,CAAG,IAAIC,GAAOT,CAAM;AAChC,SAAIG,MAAc,UAAaI,MAAQ,UAAaC,MAAQ,UAAaA,MAAQD,IACtE,CAACF,MAAcA,IAEnB,CAACA,OAAeA,IAAIF,MAAcK,IAAMD;AACnD;AAEA,SAASG,GAAmBC,G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EAAIuC,CAAS,IAAI4B,EAAUR,EAAQ,KAAK,IAAI6B,EAAO,aAAarB,EAAUR,EAAQ,KAAK,GAAG2C,CAAa,IAAIA,GACpGtG;AAAA,EACX,GAAG,CAAA,CAAE,GAGDU,EAAO,KAAK,YAAY,CAAC,MAAM,UAC/BA,EAAO,KAAK,YAAY,CAAC,IAAI,IAE7BA,EAAO,KAAK,YAAY,CAAC,MAAM,WAC/BA,EAAO,KAAK,YAAY,CAAC,IAAI,IAG1BA;AACX;"}
|
|
@@ -1,9 +1,86 @@
|
|
|
1
1
|
import { Cluster } from './components/types';
|
|
2
2
|
import { DendrogramDistance, DendrogramLinkage } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Calculate squared Euclidean distance between two vectors
|
|
5
|
+
* This is faster than regular Euclidean distance since it avoids the square root
|
|
6
|
+
* Formula: Σ(p[i] - q[i])²
|
|
7
|
+
* @param p First vector
|
|
8
|
+
* @param q Second vector
|
|
9
|
+
* @returns Squared distance (always positive)
|
|
10
|
+
*/
|
|
3
11
|
export declare function squaredEuclidean(p: number[], q: number[]): number;
|
|
12
|
+
/**
|
|
13
|
+
* Calculate Euclidean distance between two vectors
|
|
14
|
+
* This is the standard geometric distance in n-dimensional space
|
|
15
|
+
* Formula: √(Σ(p[i] - q[i])²)
|
|
16
|
+
* @param p First vector
|
|
17
|
+
* @param q Second vector
|
|
18
|
+
* @returns Euclidean distance
|
|
19
|
+
*/
|
|
4
20
|
export declare function euclidean(p: number[], q: number[]): number;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Average Linkage
|
|
23
|
+
* Calculates the average distance between all pairs of points in the two clusters
|
|
24
|
+
* This is the most commonly used linkage method as it balances between single and complete linkage
|
|
25
|
+
* @param setA Indexes of points in first cluster
|
|
26
|
+
* @param setB Indexes of points in second cluster
|
|
27
|
+
* @param getDistance Function to get distance between two point indexes
|
|
28
|
+
* @returns Average distance between clusters
|
|
29
|
+
*/
|
|
30
|
+
export declare const averageLinkage: (setA: number[], setB: number[], getDistance: (i: number, j: number) => number) => number;
|
|
31
|
+
/**
|
|
32
|
+
* Complete Linkage (Maximum Linkage)
|
|
33
|
+
* Uses the maximum distance between any pair of points in the two clusters
|
|
34
|
+
* Tends to create compact, well-separated clusters
|
|
35
|
+
* Formula: max{d(a,b)} for all a in A, b in B
|
|
36
|
+
* @param setA Indexes of points in first cluster
|
|
37
|
+
* @param setB Indexes of points in second cluster
|
|
38
|
+
* @param getDistance Function to get distance between two point indexes
|
|
39
|
+
* @returns Maximum distance between clusters
|
|
40
|
+
*/
|
|
41
|
+
export declare const completeLinkage: (setA: number[], setB: number[], getDistance: (i: number, j: number) => number) => number;
|
|
42
|
+
/**
|
|
43
|
+
* Single Linkage (Minimum Linkage)
|
|
44
|
+
* Uses the minimum distance between any pair of points in the two clusters
|
|
45
|
+
* Tends to create elongated, chain-like clusters
|
|
46
|
+
* Formula: min{d(a,b)} for all a in A, b in B
|
|
47
|
+
* @param setA Indexes of points in first cluster
|
|
48
|
+
* @param setB Indexes of points in second cluster
|
|
49
|
+
* @param getDistance Function to get distance between two point indexes
|
|
50
|
+
* @returns Minimum distance between clusters
|
|
51
|
+
*/
|
|
52
|
+
export declare const singleLinkage: (setA: number[], setB: number[], getDistance: (i: number, j: number) => number) => number;
|
|
53
|
+
/**
|
|
54
|
+
* Extract indexes from a cluster hierarchy in the correct hierarchical order
|
|
55
|
+
* This function traverses the cluster tree and collects all indexes in the order
|
|
56
|
+
* they appear in the dendrogram (left-to-right traversal)
|
|
57
|
+
* @param cluster The root cluster to extract indexes from
|
|
58
|
+
* @returns Array of indexes in hierarchical order
|
|
59
|
+
*/
|
|
60
|
+
export declare function extractOrderedIndexes(cluster: Cluster): number[];
|
|
61
|
+
export declare function getClustersApproximate(dataValues: number[][], distanceType?: DendrogramDistance, linkageType?: DendrogramLinkage): Cluster;
|
|
62
|
+
/**
|
|
63
|
+
* Main hierarchical clustering function using agglomerative approach
|
|
64
|
+
*
|
|
65
|
+
* This implements the standard agglomerative hierarchical clustering algorithm:
|
|
66
|
+
* 1. Start with each point as its own cluster
|
|
67
|
+
* 2. Compute pairwise distances between all points
|
|
68
|
+
* 3. Iteratively merge the two closest clusters
|
|
69
|
+
* 4. Continue until only one cluster remains
|
|
70
|
+
*
|
|
71
|
+
* Algorithm complexity:
|
|
72
|
+
* - Time: O(n³) - for each of n-1 iterations, scan all n² cluster pairs
|
|
73
|
+
* - Space: O(n²) - store upper triangular distance matrix
|
|
74
|
+
*
|
|
75
|
+
* Memory optimization:
|
|
76
|
+
* - Uses upper triangular matrix storage (50% memory reduction)
|
|
77
|
+
* - Only stores distances where i < j since distance matrix is symmetric
|
|
78
|
+
*
|
|
79
|
+
* @param dataKeys Labels for each data point
|
|
80
|
+
* @param dataValues Feature vectors for each data point (n×d matrix)
|
|
81
|
+
* @param distanceType Distance metric to use between points
|
|
82
|
+
* @param linkageType Linkage method to use between clusters
|
|
83
|
+
* @returns Root cluster containing the complete hierarchy
|
|
84
|
+
*/
|
|
85
|
+
export declare function getClusters(dataValues: number[][], distanceType?: DendrogramDistance, linkageType?: DendrogramLinkage): Cluster;
|
|
9
86
|
//# sourceMappingURL=getClusters.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getClusters.d.ts","sourceRoot":"","sources":["../../src/heatmap/getClusters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"getClusters.d.ts","sourceRoot":"","sources":["../../src/heatmap/getClusters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAKtE;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,UAOxD;AAED;;;;;;;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