svelteplot 0.3.11-pr-153.10 → 0.3.11-pr-153.12
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/transforms/index.d.ts +1 -1
- package/dist/transforms/index.js +1 -1
- package/dist/transforms/stack.d.ts +19 -16
- package/dist/transforms/stack.js +48 -34
- package/package.json +1 -1
|
@@ -12,5 +12,5 @@ export { renameChannels, replaceChannels } from './rename.js';
|
|
|
12
12
|
export { select, selectFirst, selectLast, selectMaxX, selectMaxY, selectMinX, selectMinY } from './select.js';
|
|
13
13
|
export { shiftX, shiftY } from './shift.js';
|
|
14
14
|
export { sort, shuffle, reverse } from './sort.js';
|
|
15
|
-
export { stackX, stackY,
|
|
15
|
+
export { stackX, stackY, stackMosaicX, stackMosaicY } from './stack.js';
|
|
16
16
|
export { windowX, windowY } from './window.js';
|
package/dist/transforms/index.js
CHANGED
|
@@ -12,5 +12,5 @@ export { renameChannels, replaceChannels } from './rename.js';
|
|
|
12
12
|
export { select, selectFirst, selectLast, selectMaxX, selectMaxY, selectMinX, selectMinY } from './select.js';
|
|
13
13
|
export { shiftX, shiftY } from './shift.js';
|
|
14
14
|
export { sort, shuffle, reverse } from './sort.js';
|
|
15
|
-
export { stackX, stackY,
|
|
15
|
+
export { stackX, stackY, stackMosaicX, stackMosaicY } from './stack.js';
|
|
16
16
|
export { windowX, windowY } from './window.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TransformArg } from '../types/index.js';
|
|
2
2
|
export type StackOrder = 'none' | 'appearance' | 'inside-out' | 'sum';
|
|
3
3
|
export type StackOffset = 'none' | 'wiggle' | 'center' | 'normalize' | 'diverging';
|
|
4
4
|
export type StackOptions = {
|
|
@@ -8,18 +8,21 @@ export type StackOptions = {
|
|
|
8
8
|
};
|
|
9
9
|
export declare function stackY<T>({ data, ...channels }: T, opts?: Partial<StackOptions>): T;
|
|
10
10
|
export declare function stackX({ data, ...channels }: TransformArg, opts?: Partial<StackOptions>): TransformArg;
|
|
11
|
-
export declare function
|
|
12
|
-
data:
|
|
13
|
-
x:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
11
|
+
export declare function stackMosaicX<T>(args: any, opts: any): {
|
|
12
|
+
data: unknown[];
|
|
13
|
+
x: symbol;
|
|
14
|
+
x1: symbol;
|
|
15
|
+
x2: symbol;
|
|
16
|
+
y: symbol;
|
|
17
|
+
y1: symbol;
|
|
18
|
+
y2: symbol;
|
|
19
|
+
};
|
|
20
|
+
export declare function stackMosaicY<T>(args: any, opts: any): {
|
|
21
|
+
data: unknown[];
|
|
22
|
+
x: symbol;
|
|
23
|
+
x1: symbol;
|
|
24
|
+
x2: symbol;
|
|
25
|
+
y: symbol;
|
|
26
|
+
y1: symbol;
|
|
27
|
+
y2: symbol;
|
|
28
|
+
};
|
package/dist/transforms/stack.js
CHANGED
|
@@ -119,49 +119,63 @@ const X2 = Symbol('x2');
|
|
|
119
119
|
const Y = Symbol('y');
|
|
120
120
|
const Y1 = Symbol('y1');
|
|
121
121
|
const Y2 = Symbol('y2');
|
|
122
|
-
|
|
122
|
+
function stackMosaic({ data, x, y, value, fx, fy, ...rest }, { outer, inner }, { x: xOpt, y: yOpt } = {}) {
|
|
123
123
|
const out = [];
|
|
124
|
-
const { data, x, y, value, ...rest }
|
|
125
|
-
if (
|
|
124
|
+
const { data: filtered, ...restArgs } = sort(filter({ data, x, y, value, fx, fy, ...rest }));
|
|
125
|
+
if (!filtered)
|
|
126
126
|
throw new Error('stackMosaic: missing data');
|
|
127
|
-
if (x
|
|
127
|
+
if (!x)
|
|
128
128
|
throw new Error('stackMosaic: missing x channel');
|
|
129
|
-
if (y
|
|
129
|
+
if (!y)
|
|
130
130
|
throw new Error('stackMosaic: missing y channel');
|
|
131
|
-
if (value
|
|
131
|
+
if (!value)
|
|
132
132
|
throw new Error('stackMosaic: missing value channel');
|
|
133
|
-
if (min(
|
|
133
|
+
if (min(filtered, (d) => resolveProp(d[value], d)) < 0)
|
|
134
134
|
throw new Error('stackMosaic: negative values not supported');
|
|
135
|
-
groupFacetsAndZ(
|
|
136
|
-
const total = sum(data, (d) => d[value]);
|
|
137
|
-
let
|
|
138
|
-
const
|
|
139
|
-
const
|
|
140
|
-
const
|
|
135
|
+
groupFacetsAndZ(filtered, restArgs, (data) => {
|
|
136
|
+
const total = sum(data, (d) => resolveProp(d[value], d));
|
|
137
|
+
let outerPos = 0;
|
|
138
|
+
const outerChannel = outer === 'x' ? x : y;
|
|
139
|
+
const innerChannel = inner === 'x' ? x : y;
|
|
140
|
+
const outerSym1 = outer === 'x' ? X1 : Y1;
|
|
141
|
+
const outerSym2 = outer === 'x' ? X2 : Y2;
|
|
142
|
+
const innerSym1 = inner === 'x' ? X1 : Y1;
|
|
143
|
+
const innerSym2 = inner === 'x' ? X2 : Y2;
|
|
144
|
+
const outerOpt = outer === 'x' ? xOpt : yOpt;
|
|
145
|
+
const innerOpt = inner === 'x' ? xOpt : yOpt;
|
|
146
|
+
const grouped = d3Groups(data, (d) => resolveProp(d[outerChannel], d));
|
|
147
|
+
const innerOrder = new Map(grouped[0][1].map((d, i) => [d[innerChannel], i]));
|
|
148
|
+
grouped.forEach(([k, items], i) => {
|
|
141
149
|
const groupValue = sum(items, (d) => resolveProp(d[value], d));
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
const
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
150
|
+
const o1 = outerPos, o2 = outerPos + groupValue;
|
|
151
|
+
outerPos = o2;
|
|
152
|
+
let innerPos = 0;
|
|
153
|
+
(i
|
|
154
|
+
? items.sort((a, b) => innerOrder.get(a[innerChannel]) - innerOrder.get(b[innerChannel]))
|
|
155
|
+
: items).forEach((d) => {
|
|
156
|
+
const iv = resolveProp(d[value], d);
|
|
157
|
+
const i1 = innerPos, i2 = innerPos + iv;
|
|
158
|
+
innerPos = i2;
|
|
159
|
+
const normO1 = outerOpt?.percent ? o1 / total : o1;
|
|
160
|
+
const normO2 = outerOpt?.percent ? o2 / total : o2;
|
|
161
|
+
const normI1 = innerOpt?.percent ? i1 / groupValue : i1;
|
|
162
|
+
const normI2 = innerOpt?.percent ? i2 / groupValue : i2;
|
|
163
|
+
const result = { ...d };
|
|
164
|
+
result[outerSym1] = normO1;
|
|
165
|
+
result[outerSym2] = normO2;
|
|
166
|
+
result[innerSym1] = normI1;
|
|
167
|
+
result[innerSym2] = normI2;
|
|
168
|
+
result[X] = (result[X1] + result[X2]) / 2;
|
|
169
|
+
result[Y] = (result[Y1] + result[Y2]) / 2;
|
|
170
|
+
out.push(result);
|
|
162
171
|
});
|
|
163
172
|
});
|
|
164
|
-
out.push(...flat);
|
|
165
173
|
});
|
|
166
174
|
return { ...rest, data: out, x: X, x1: X1, x2: X2, y: Y, y1: Y1, y2: Y2 };
|
|
167
175
|
}
|
|
176
|
+
export function stackMosaicX(args, opts) {
|
|
177
|
+
return stackMosaic(args, { outer: 'x', inner: 'y' }, opts);
|
|
178
|
+
}
|
|
179
|
+
export function stackMosaicY(args, opts) {
|
|
180
|
+
return stackMosaic(args, { outer: 'y', inner: 'x' }, opts);
|
|
181
|
+
}
|