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.
@@ -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>({ data, x, y, value, ...rest }: {
11
+ export declare function stackMarimekko<T>(args: {
12
12
  data: T[];
13
13
  x: ChannelAccessor<T>;
14
- y?: ChannelAccessor<T>;
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;
@@ -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({ data, x, y, value, ...rest }, { x: xOpt, y: yOpt } = {}) {
118
+ export function stackMarimekko(args, { x: xOpt, y: yOpt } = {}) {
118
119
  const out = [];
119
- if (rest.filter) {
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)).flatMap(([k, items]) => {
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, x2 = xPos + groupValue;
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(...grouped);
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelteplot",
3
- "version": "0.3.11-pr-153.6",
3
+ "version": "0.3.11-pr-153.7",
4
4
  "license": "ISC",
5
5
  "author": {
6
6
  "name": "Gregor Aisch",