svelteplot 0.3.11-pr-153.5 → 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 +11 -5
- 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
|
@@ -3,6 +3,8 @@ import { resolveChannel, resolveProp } from '../helpers/resolve.js';
|
|
|
3
3
|
import { stack, stackOffsetExpand, stackOffsetSilhouette, stackOffsetWiggle, stackOrderAppearance, stackOrderAscending, stackOrderInsideOut, stackOrderNone, stackOffsetDiverging } from 'd3-shape';
|
|
4
4
|
import { index, union, sum, groups as d3Groups } from 'd3-array';
|
|
5
5
|
import { groupFacetsAndZ } from '../helpers/group';
|
|
6
|
+
import { filter } from './filter.js';
|
|
7
|
+
import { sort } from './sort.js';
|
|
6
8
|
const GROUP = Symbol('group');
|
|
7
9
|
const FACET = Symbol('group');
|
|
8
10
|
const DEFAULT_STACK_OPTIONS = {
|
|
@@ -113,17 +115,21 @@ function applyDefaults(opts) {
|
|
|
113
115
|
}
|
|
114
116
|
const X = Symbol('x'), X1 = Symbol('x1'), X2 = Symbol('x2');
|
|
115
117
|
const Y = Symbol('y'), Y1 = Symbol('y1'), Y2 = Symbol('y2');
|
|
116
|
-
export function stackMarimekko(
|
|
118
|
+
export function stackMarimekko(args, { x: xOpt, y: yOpt } = {}) {
|
|
117
119
|
const out = [];
|
|
120
|
+
const { data, x, y, value, ...rest } = sort(filter(args));
|
|
118
121
|
groupFacetsAndZ(data, { ...rest }, (data) => {
|
|
119
122
|
const total = sum(data, (d) => d[value]);
|
|
120
123
|
let xPos = 0;
|
|
121
|
-
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) => {
|
|
122
127
|
const groupValue = sum(items, (d) => resolveProp(d[value], d));
|
|
123
|
-
const x1 = xPos
|
|
128
|
+
const x1 = xPos;
|
|
129
|
+
const x2 = xPos + groupValue;
|
|
124
130
|
xPos = x2;
|
|
125
131
|
let yPos = 0;
|
|
126
|
-
return items.map((d) => {
|
|
132
|
+
return (!i ? items : items.sort((a, b) => yOrder.get(a[y]) - yOrder.get(b[y]))).map((d) => {
|
|
127
133
|
const y1 = yPos, y2 = yPos + resolveProp(d[value], d);
|
|
128
134
|
yPos = y2;
|
|
129
135
|
const normX1 = xOpt?.percent ? x1 / total : x1;
|
|
@@ -141,7 +147,7 @@ export function stackMarimekko({ data, x, y, value, ...rest }, { x: xOpt, y: yOp
|
|
|
141
147
|
};
|
|
142
148
|
});
|
|
143
149
|
});
|
|
144
|
-
out.push(...
|
|
150
|
+
out.push(...flat);
|
|
145
151
|
});
|
|
146
152
|
return { ...rest, data: out, x: X, x1: X1, x2: X2, y: Y, y1: Y1, y2: Y2 };
|
|
147
153
|
}
|