svelteplot 0.3.11-pr-153.6 → 0.3.11-pr-153.7
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/stack.d.ts +3 -13
- package/dist/transforms/stack.js +10 -9
- package/package.json +1 -1
|
@@ -8,10 +8,10 @@ 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 stackMarimekko<T>(
|
|
11
|
+
export declare function stackMarimekko<T>(args: {
|
|
12
12
|
data: T[];
|
|
13
13
|
x: ChannelAccessor<T>;
|
|
14
|
-
y
|
|
14
|
+
y: ChannelAccessor<T>;
|
|
15
15
|
value: ChannelAccessor<T>;
|
|
16
16
|
fx?: ChannelAccessor<T>;
|
|
17
17
|
fy?: ChannelAccessor<T>;
|
|
@@ -22,14 +22,4 @@ export declare function stackMarimekko<T>({ data, x, y, value, ...rest }: {
|
|
|
22
22
|
y?: {
|
|
23
23
|
percent?: boolean;
|
|
24
24
|
};
|
|
25
|
-
}):
|
|
26
|
-
data: T[];
|
|
27
|
-
x: symbol;
|
|
28
|
-
x1: symbol;
|
|
29
|
-
x2: symbol;
|
|
30
|
-
y: symbol;
|
|
31
|
-
y1: symbol;
|
|
32
|
-
y2: symbol;
|
|
33
|
-
fx?: ChannelAccessor<T>;
|
|
34
|
-
fy?: ChannelAccessor<T>;
|
|
35
|
-
};
|
|
25
|
+
}): any;
|
package/dist/transforms/stack.js
CHANGED
|
@@ -4,6 +4,7 @@ import { stack, stackOffsetExpand, stackOffsetSilhouette, stackOffsetWiggle, sta
|
|
|
4
4
|
import { index, union, sum, groups as d3Groups } from 'd3-array';
|
|
5
5
|
import { groupFacetsAndZ } from '../helpers/group';
|
|
6
6
|
import { filter } from './filter.js';
|
|
7
|
+
import { sort } from './sort.js';
|
|
7
8
|
const GROUP = Symbol('group');
|
|
8
9
|
const FACET = Symbol('group');
|
|
9
10
|
const DEFAULT_STACK_OPTIONS = {
|
|
@@ -114,21 +115,21 @@ function applyDefaults(opts) {
|
|
|
114
115
|
}
|
|
115
116
|
const X = Symbol('x'), X1 = Symbol('x1'), X2 = Symbol('x2');
|
|
116
117
|
const Y = Symbol('y'), Y1 = Symbol('y1'), Y2 = Symbol('y2');
|
|
117
|
-
export function stackMarimekko(
|
|
118
|
+
export function stackMarimekko(args, { x: xOpt, y: yOpt } = {}) {
|
|
118
119
|
const out = [];
|
|
119
|
-
|
|
120
|
-
const d = filter({ data, ...rest });
|
|
121
|
-
data = d.data;
|
|
122
|
-
}
|
|
120
|
+
const { data, x, y, value, ...rest } = sort(filter(args));
|
|
123
121
|
groupFacetsAndZ(data, { ...rest }, (data) => {
|
|
124
122
|
const total = sum(data, (d) => d[value]);
|
|
125
123
|
let xPos = 0;
|
|
126
|
-
const grouped = d3Groups(data, (d) => resolveProp(d[x], d))
|
|
124
|
+
const grouped = d3Groups(data, (d) => resolveProp(d[x], d));
|
|
125
|
+
const yOrder = new Map(grouped[0][1].map((d, i) => [d[y], i]));
|
|
126
|
+
const flat = grouped.flatMap(([k, items], i) => {
|
|
127
127
|
const groupValue = sum(items, (d) => resolveProp(d[value], d));
|
|
128
|
-
const x1 = xPos
|
|
128
|
+
const x1 = xPos;
|
|
129
|
+
const x2 = xPos + groupValue;
|
|
129
130
|
xPos = x2;
|
|
130
131
|
let yPos = 0;
|
|
131
|
-
return items.map((d) => {
|
|
132
|
+
return (!i ? items : items.sort((a, b) => yOrder.get(a[y]) - yOrder.get(b[y]))).map((d) => {
|
|
132
133
|
const y1 = yPos, y2 = yPos + resolveProp(d[value], d);
|
|
133
134
|
yPos = y2;
|
|
134
135
|
const normX1 = xOpt?.percent ? x1 / total : x1;
|
|
@@ -146,7 +147,7 @@ export function stackMarimekko({ data, x, y, value, ...rest }, { x: xOpt, y: yOp
|
|
|
146
147
|
};
|
|
147
148
|
});
|
|
148
149
|
});
|
|
149
|
-
out.push(...
|
|
150
|
+
out.push(...flat);
|
|
150
151
|
});
|
|
151
152
|
return { ...rest, data: out, x: X, x1: X1, x2: X2, y: Y, y1: Y1, y2: Y2 };
|
|
152
153
|
}
|