svelteplot 0.0.1-alpha.2 → 0.0.1-alpha.20

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.
Files changed (87) hide show
  1. package/dist/Plot.svelte +47 -41
  2. package/dist/Plot.svelte.d.ts +3 -3
  3. package/dist/classes/Mark.svelte.js +4 -0
  4. package/dist/classes/Plot.svelte.js +50 -24
  5. package/dist/classes/Scale.svelte.js +94 -0
  6. package/dist/contants.d.ts +3 -3
  7. package/dist/contants.js +18 -16
  8. package/dist/helpers/GroupMultiple.svelte.d.ts +3 -3
  9. package/dist/helpers/autoTimeFormat.d.ts +2 -2
  10. package/dist/helpers/autoTimeFormat.js +1 -1
  11. package/dist/helpers/callWithProps.d.ts +4 -0
  12. package/dist/helpers/callWithProps.js +9 -0
  13. package/dist/helpers/colors.d.ts +1 -1
  14. package/dist/helpers/createScale.d.ts +2 -1
  15. package/dist/helpers/createScale.js +37 -16
  16. package/dist/helpers/curves.d.ts +3 -0
  17. package/dist/helpers/curves.js +42 -0
  18. package/dist/helpers/getBaseStyles.d.ts +1 -1
  19. package/dist/helpers/getBaseStyles.js +2 -3
  20. package/dist/helpers/getLogTicks.js +5 -5
  21. package/dist/helpers/isDataRecord.d.ts +1 -1
  22. package/dist/helpers/isRawValue.d.ts +2 -0
  23. package/dist/helpers/isRawValue.js +5 -0
  24. package/dist/helpers/resolveChannel.d.ts +6 -2
  25. package/dist/helpers/resolveChannel.js +16 -6
  26. package/dist/helpers/typeChecks.d.ts +1 -1
  27. package/dist/helpers/typeChecks.js +1 -1
  28. package/dist/helpers/wrapArray.d.ts +2 -2
  29. package/dist/helpers/wrapValueArray.d.ts +6 -0
  30. package/dist/helpers/wrapValueArray.js +5 -0
  31. package/dist/index.d.ts +15 -1
  32. package/dist/index.js +17 -1
  33. package/dist/marks/Area.svelte +95 -0
  34. package/dist/marks/Area.svelte.d.ts +28 -0
  35. package/dist/marks/AreaX.svelte +11 -0
  36. package/dist/marks/AreaX.svelte.d.ts +30 -0
  37. package/dist/marks/AreaY.svelte +12 -0
  38. package/dist/marks/AreaY.svelte.d.ts +30 -0
  39. package/dist/marks/AxisX.svelte +17 -17
  40. package/dist/marks/AxisX.svelte.d.ts +3 -3
  41. package/dist/marks/AxisY.svelte +25 -11
  42. package/dist/marks/AxisY.svelte.d.ts +3 -3
  43. package/dist/marks/BarX.svelte +52 -0
  44. package/dist/marks/BarX.svelte.d.ts +25 -0
  45. package/dist/marks/BarY.svelte +52 -0
  46. package/dist/marks/BarY.svelte.d.ts +25 -0
  47. package/dist/marks/BaseMark.svelte +10 -3
  48. package/dist/marks/BaseMark.svelte.d.ts +5 -4
  49. package/dist/marks/ColorLegend.svelte +26 -24
  50. package/dist/marks/ColorLegend.svelte.d.ts +2 -2
  51. package/dist/marks/Dot.svelte +28 -43
  52. package/dist/marks/Dot.svelte.d.ts +11 -3
  53. package/dist/marks/DotX.svelte.d.ts +3 -3
  54. package/dist/marks/DotY.svelte.d.ts +3 -3
  55. package/dist/marks/Frame.svelte +1 -1
  56. package/dist/marks/Frame.svelte.d.ts +4 -4
  57. package/dist/marks/GridX.svelte +29 -18
  58. package/dist/marks/GridX.svelte.d.ts +6 -6
  59. package/dist/marks/GridY.svelte +17 -7
  60. package/dist/marks/GridY.svelte.d.ts +3 -3
  61. package/dist/marks/Line.svelte +28 -29
  62. package/dist/marks/Line.svelte.d.ts +15 -3
  63. package/dist/marks/LineX.svelte +5 -7
  64. package/dist/marks/LineX.svelte.d.ts +13 -6
  65. package/dist/marks/LineY.svelte +4 -6
  66. package/dist/marks/LineY.svelte.d.ts +14 -6
  67. package/dist/marks/RuleX.svelte +17 -9
  68. package/dist/marks/RuleX.svelte.d.ts +3 -3
  69. package/dist/marks/RuleY.svelte +17 -10
  70. package/dist/marks/RuleY.svelte.d.ts +3 -3
  71. package/dist/marks/SymbolLegend.svelte +17 -17
  72. package/dist/marks/SymbolLegend.svelte.d.ts +2 -2
  73. package/dist/marks/TickX.svelte +30 -0
  74. package/dist/marks/TickX.svelte.d.ts +15 -0
  75. package/dist/marks/TickY.svelte +30 -0
  76. package/dist/marks/TickY.svelte.d.ts +15 -0
  77. package/dist/transforms/normalize.d.ts +18 -0
  78. package/dist/transforms/normalize.js +25 -0
  79. package/dist/transforms/recordize.d.ts +3 -0
  80. package/dist/transforms/recordize.js +36 -0
  81. package/dist/transforms/rename.d.ts +4 -0
  82. package/dist/transforms/rename.js +10 -0
  83. package/dist/transforms/stack.d.ts +11 -0
  84. package/dist/transforms/stack.js +80 -0
  85. package/dist/types.d.ts +60 -23
  86. package/package.json +28 -23
  87. package/dist/classes/Channel.svelte.js +0 -72
@@ -1,5 +1,17 @@
1
- import { SvelteComponent } from "svelte";
2
- import type { LineMarkProps } from '../types';
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { MarkProps, BaseMarkStyleProps, ChannelAccessor, Curve, DataRow } from '../types.js';
3
+ export type LineMarkProps = MarkProps & BaseMarkStyleProps & {
4
+ data: DataRow[];
5
+ x?: ChannelAccessor;
6
+ y?: ChannelAccessor;
7
+ z?: ChannelAccessor;
8
+ sort?: ChannelAccessor | {
9
+ channel: 'stroke' | 'fill';
10
+ };
11
+ curve: Curve | CurveFactory;
12
+ tension: number;
13
+ };
14
+ import { type CurveFactory } from 'd3-shape';
3
15
  declare const __propDef: {
4
16
  props: LineMarkProps;
5
17
  events: {
@@ -10,6 +22,6 @@ declare const __propDef: {
10
22
  export type LineProps = typeof __propDef.props;
11
23
  export type LineEvents = typeof __propDef.events;
12
24
  export type LineSlots = typeof __propDef.slots;
13
- export default class Line extends SvelteComponent<LineProps, LineEvents, LineSlots> {
25
+ export default class Line extends SvelteComponentTyped<LineProps, LineEvents, LineSlots> {
14
26
  }
15
27
  export {};
@@ -1,10 +1,8 @@
1
- <script>import Line from "./Line.svelte";
1
+ <script context="module"></script>
2
+
3
+ <script>import wrapValueArray from "../helpers/wrapValueArray.js";
4
+ import Line from "./Line.svelte";
2
5
  let { data, ...rest } = $props();
3
6
  </script>
4
7
 
5
- <Line
6
- data={data.map((value, index) => ({ value, index, ___orig___: value }))}
7
- x="value"
8
- y="index"
9
- {...rest}
10
- />
8
+ <Line data={wrapValueArray(data)} x="value" y="index" {...rest} />
@@ -1,9 +1,16 @@
1
- import { SvelteComponent } from "svelte";
2
- import type { RawValue } from '../types';
3
- declare const __propDef: {
4
- props: {
5
- data: RawValue[];
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { CurveFactory } from 'd3-shape';
3
+ import type { MarkProps, BaseMarkStyleProps, ChannelAccessor, Curve, RawValue } from '../types.js';
4
+ export type LineXMarkProps = MarkProps & BaseMarkStyleProps & {
5
+ data: RawValue[];
6
+ sort?: ChannelAccessor | {
7
+ channel: 'stroke' | 'fill';
6
8
  };
9
+ curve?: Curve | CurveFactory;
10
+ tension?: number;
11
+ };
12
+ declare const __propDef: {
13
+ props: LineXMarkProps;
7
14
  events: {
8
15
  [evt: string]: CustomEvent<any>;
9
16
  };
@@ -12,6 +19,6 @@ declare const __propDef: {
12
19
  export type LineXProps = typeof __propDef.props;
13
20
  export type LineXEvents = typeof __propDef.events;
14
21
  export type LineXSlots = typeof __propDef.slots;
15
- export default class LineX extends SvelteComponent<LineXProps, LineXEvents, LineXSlots> {
22
+ export default class LineX extends SvelteComponentTyped<LineXProps, LineXEvents, LineXSlots> {
16
23
  }
17
24
  export {};
@@ -1,10 +1,8 @@
1
+ <script context="module"></script>
2
+
1
3
  <script>import Line from "./Line.svelte";
4
+ import wrapValueArray from "../helpers/wrapValueArray.js";
2
5
  let { data, ...rest } = $props();
3
6
  </script>
4
7
 
5
- <Line
6
- data={data.map((value, index) => ({ value, index, ___orig___: value }))}
7
- x="index"
8
- y="value"
9
- {...rest}
10
- />
8
+ <Line data={wrapValueArray(data)} x="index" y="value" {...rest} />
@@ -1,9 +1,17 @@
1
- import { SvelteComponent } from "svelte";
2
- import type { RawValue } from '../types';
3
- declare const __propDef: {
4
- props: {
5
- data: RawValue[];
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { MarkProps, BaseMarkStyleProps, ChannelAccessor, Curve } from '../types.js';
3
+ export type LineYMarkProps = MarkProps & BaseMarkStyleProps & {
4
+ data: RawValue[];
5
+ sort?: ChannelAccessor | {
6
+ channel: 'stroke' | 'fill';
6
7
  };
8
+ curve?: Curve | CurveFactory;
9
+ tension?: number;
10
+ };
11
+ import type { RawValue } from '../types.js';
12
+ import type { CurveFactory } from 'd3-shape';
13
+ declare const __propDef: {
14
+ props: LineYMarkProps;
7
15
  events: {
8
16
  [evt: string]: CustomEvent<any>;
9
17
  };
@@ -12,6 +20,6 @@ declare const __propDef: {
12
20
  export type LineYProps = typeof __propDef.props;
13
21
  export type LineYEvents = typeof __propDef.events;
14
22
  export type LineYSlots = typeof __propDef.slots;
15
- export default class LineY extends SvelteComponent<LineYProps, LineYEvents, LineYSlots> {
23
+ export default class LineY extends SvelteComponentTyped<LineYProps, LineYEvents, LineYSlots> {
16
24
  }
17
25
  export {};
@@ -1,22 +1,30 @@
1
1
  <script>import { getContext } from "svelte";
2
2
  import BaseMark from "./BaseMark.svelte";
3
- import getBaseStyles from "../helpers/getBaseStyles";
4
- import resolveChannel from "../helpers/resolveChannel";
3
+ import getBaseStyles from "../helpers/getBaseStyles.js";
4
+ import resolveChannel from "../helpers/resolveChannel.js";
5
5
  const BaseMark_RuleX = BaseMark;
6
6
  const plot = getContext("svelteplot");
7
- let { data = [], x, y1, y2, ...styleProps } = $props();
8
- let dataWrapped = $derived(x ? data : data.map((d) => ({ x: d, ___orig___: d })));
7
+ let { data = [], ...channels } = $props();
8
+ let { x, y1, y2 } = $derived(channels);
9
+ let dataWrapped = $derived(x ? data : data.map((d) => ({ __x: d, ___orig___: d })));
9
10
  </script>
10
11
 
11
- <BaseMark_RuleX type="rule-x" data={dataWrapped} channels={['x', 'y']} {x} {y1} {y2}>
12
+ <BaseMark_RuleX
13
+ type="rule-x"
14
+ data={dataWrapped}
15
+ channels={['x', 'y1', 'y2']}
16
+ {...{ x: '__x', ...channels }}
17
+ >
12
18
  <g class="rule-x">
13
19
  {#each data as datum}
14
20
  <line
15
- transform="translate({plot.xScale(resolveChannel('x', datum, x))}, {0})"
16
- style={getBaseStyles(datum, styleProps)}
17
- y1={y1 != null ? plot.yScale(resolveChannel('y', datum, y1)) : plot.margins.top}
21
+ transform="translate({plot.xScale(resolveChannel('x', datum, channels))}, {0})"
22
+ style={getBaseStyles(datum, channels)}
23
+ y1={y1 != null
24
+ ? plot.yScale(resolveChannel('y1', datum, channels))
25
+ : plot.margins.top}
18
26
  y2={y2 != null
19
- ? plot.yScale(resolveChannel('y', datum, y2))
27
+ ? plot.yScale(resolveChannel('y2', datum, channels))
20
28
  : plot.plotHeight + plot.margins.top}
21
29
  />
22
30
  {/each}
@@ -1,5 +1,5 @@
1
- import { SvelteComponent } from "svelte";
2
- import type { RuleXMarkProps } from '../types';
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { RuleXMarkProps } from '../types.js';
3
3
  declare const __propDef: {
4
4
  props: RuleXMarkProps;
5
5
  events: {
@@ -10,6 +10,6 @@ declare const __propDef: {
10
10
  export type RuleXProps = typeof __propDef.props;
11
11
  export type RuleXEvents = typeof __propDef.events;
12
12
  export type RuleXSlots = typeof __propDef.slots;
13
- export default class RuleX extends SvelteComponent<RuleXProps, RuleXEvents, RuleXSlots> {
13
+ export default class RuleX extends SvelteComponentTyped<RuleXProps, RuleXEvents, RuleXSlots> {
14
14
  }
15
15
  export {};
@@ -1,23 +1,30 @@
1
1
  <script>import { getContext } from "svelte";
2
2
  import BaseMark from "./BaseMark.svelte";
3
- import getBaseStyles from "../helpers/getBaseStyles";
4
- import resolveChannel from "../helpers/resolveChannel";
5
- import wrapArray from "../helpers/wrapArray";
3
+ import getBaseStyles from "../helpers/getBaseStyles.js";
4
+ import resolveChannel from "../helpers/resolveChannel.js";
6
5
  const BaseMark_RuleY = BaseMark;
7
6
  const plot = getContext("svelteplot");
8
- let { data = [], y, x1, x2, ...styleProps } = $props();
9
- let dataWrapped = $derived(y ? data : data.map((d) => ({ y: d, ___orig___: d })));
7
+ let { data = [], ...channels } = $props();
8
+ let { y, x1, x2 } = $derived(channels);
9
+ let dataWrapped = $derived(y ? data : data.map((d) => ({ __y: d, ___orig___: d })));
10
10
  </script>
11
11
 
12
- <BaseMark_RuleY type="rule-y" data={dataWrapped} channels={['y', 'x']} {y} {x1} {x2}>
12
+ <BaseMark_RuleY
13
+ type="rule-y"
14
+ data={dataWrapped}
15
+ channels={['y', 'x1', 'x2']}
16
+ {...{ y: '__y', ...channels }}
17
+ >
13
18
  <g class="rule-y">
14
19
  {#each data as datum}
15
20
  <line
16
- transform="translate(0,{plot.yScale(resolveChannel('y', datum, y))})"
17
- style={getBaseStyles(datum, styleProps)}
18
- x1={x1 != null ? plot.xScale(resolveChannel('x', datum, x1)) : plot.margins.left}
21
+ transform="translate(0,{plot.yScale(resolveChannel('y', datum, channels))})"
22
+ style={getBaseStyles(datum, channels)}
23
+ x1={x1 != null
24
+ ? plot.xScale(resolveChannel('x1', datum, channels))
25
+ : plot.margins.left}
19
26
  x2={x2 != null
20
- ? plot.xScale(resolveChannel('x', datum, x2))
27
+ ? plot.xScale(resolveChannel('x2', datum, channels))
21
28
  : plot.plotWidth + plot.margins.left}
22
29
  />
23
30
  {/each}
@@ -1,5 +1,5 @@
1
- import { SvelteComponent } from "svelte";
2
- import type { RuleYMarkProps } from '../types';
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { RuleYMarkProps } from '../types.js';
3
3
  declare const __propDef: {
4
4
  props: RuleYMarkProps;
5
5
  events: {
@@ -10,6 +10,6 @@ declare const __propDef: {
10
10
  export type RuleYProps = typeof __propDef.props;
11
11
  export type RuleYEvents = typeof __propDef.events;
12
12
  export type RuleYSlots = typeof __propDef.slots;
13
- export default class RuleY extends SvelteComponent<RuleYProps, RuleYEvents, RuleYSlots> {
13
+ export default class RuleY extends SvelteComponentTyped<RuleYProps, RuleYEvents, RuleYSlots> {
14
14
  }
15
15
  export {};
@@ -1,32 +1,30 @@
1
1
  <script>import { getContext } from "svelte";
2
2
  import { symbol as d3Symbol } from "d3-shape";
3
- import { maybeSymbol } from "../helpers/symbols";
3
+ import { maybeSymbol } from "../helpers/symbols.js";
4
4
  const plot = getContext("svelteplot");
5
5
  </script>
6
6
 
7
7
  {#if plot.color.manualActiveMarks.length > 0 && !(plot.options.color?.legend && plot.colorSymbolRedundant)}
8
- <div class="symbol-legend">
9
- {#each plot.symbolScale.domain() as value}
10
- {@const symbolV = plot.symbolScale(value)}
11
- {@const symbolType = maybeSymbol(symbolV)}
12
- {@const color = plot.colorSymbolRedundant ? plot.colorScale(value) : 'currentColor'}
13
- <div class="item">
14
- <div class="swatch">
15
- <svg width="15" height="15"
16
- >
8
+ <div class="symbol-legend">
9
+ {#each plot.symbolScale.domain() as value}
10
+ {@const symbolV = plot.symbolScale(value)}
11
+ {@const symbolType = maybeSymbol(symbolV)}
12
+ {@const color = plot.colorSymbolRedundant ? plot.colorScale(value) : 'currentColor'}
13
+ <div class="item">
14
+ <div class="swatch">
15
+ <svg width="15" height="15">
17
16
  <path
18
17
  transform="translate(7.5,7.5)"
19
18
  fill={plot.hasFilledDotMarks ? color : 'none'}
20
19
  stroke={plot.hasFilledDotMarks ? null : color}
21
20
  d={d3Symbol(symbolType, 40)()}
22
21
  />
23
- </svg
24
- >
22
+ </svg>
23
+ </div>
24
+ <span class="item-label">{value}</span>
25
25
  </div>
26
- <span class="item-label">{value}</span>
27
- </div>
28
- {/each}
29
- </div>
26
+ {/each}
27
+ </div>
30
28
  {/if}
31
29
 
32
30
  <style>
@@ -38,7 +36,9 @@ const plot = getContext("svelteplot");
38
36
  .item {
39
37
  margin: 0 1em 0.5ex 0;
40
38
  }
41
- path { stroke-width: 1.5;}
39
+ path {
40
+ stroke-width: 1.5;
41
+ }
42
42
  .item,
43
43
  .item-label,
44
44
  .swatch {
@@ -1,4 +1,4 @@
1
- import { SvelteComponent } from "svelte";
1
+ import { SvelteComponentTyped } from "svelte";
2
2
  declare const __propDef: {
3
3
  props: Record<string, never>;
4
4
  events: {
@@ -9,6 +9,6 @@ declare const __propDef: {
9
9
  export type SymbolLegendProps = typeof __propDef.props;
10
10
  export type SymbolLegendEvents = typeof __propDef.events;
11
11
  export type SymbolLegendSlots = typeof __propDef.slots;
12
- export default class SymbolLegend extends SvelteComponent<SymbolLegendProps, SymbolLegendEvents, SymbolLegendSlots> {
12
+ export default class SymbolLegend extends SvelteComponentTyped<SymbolLegendProps, SymbolLegendEvents, SymbolLegendSlots> {
13
13
  }
14
14
  export {};
@@ -0,0 +1,30 @@
1
+ <script>import { getContext } from "svelte";
2
+ import BaseMark from "./BaseMark.svelte";
3
+ import getBaseStyles from "../helpers/getBaseStyles.js";
4
+ import resolveChannel from "../helpers/resolveChannel.js";
5
+ const BaseMark_TickX = BaseMark;
6
+ const plot = getContext("svelteplot");
7
+ let { data = [], ...channels } = $props();
8
+ </script>
9
+
10
+ <BaseMark_TickX type="tick-x" {data} channels={['x', 'y', 'stroke']} {...channels}>
11
+ <g class="tick-x">
12
+ {#each data as datum}
13
+ <line
14
+ transform="translate({plot.xScale(resolveChannel('x', datum, channels))}, {0})"
15
+ style:stroke={channels.stroke
16
+ ? plot.colorScale(resolveChannel('stroke', datum, channels))
17
+ : null}
18
+ style={getBaseStyles(datum, channels)}
19
+ y1={plot.yScale(resolveChannel('y', datum, channels))}
20
+ y2={plot.yScale(resolveChannel('y', datum, channels)) + plot.yScale.bandwidth()}
21
+ />
22
+ {/each}
23
+ </g>
24
+ </BaseMark_TickX>
25
+
26
+ <style>
27
+ .tick-x line {
28
+ stroke: currentColor;
29
+ }
30
+ </style>
@@ -0,0 +1,15 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { TickMarkProps } from '../types.js';
3
+ declare const __propDef: {
4
+ props: TickMarkProps;
5
+ events: {
6
+ [evt: string]: CustomEvent<any>;
7
+ };
8
+ slots: {};
9
+ };
10
+ export type TickXProps = typeof __propDef.props;
11
+ export type TickXEvents = typeof __propDef.events;
12
+ export type TickXSlots = typeof __propDef.slots;
13
+ export default class TickX extends SvelteComponentTyped<TickXProps, TickXEvents, TickXSlots> {
14
+ }
15
+ export {};
@@ -0,0 +1,30 @@
1
+ <script>import { getContext } from "svelte";
2
+ import BaseMark from "./BaseMark.svelte";
3
+ import getBaseStyles from "../helpers/getBaseStyles.js";
4
+ import resolveChannel from "../helpers/resolveChannel.js";
5
+ const BaseMark_TickY = BaseMark;
6
+ const plot = getContext("svelteplot");
7
+ let { data = [], ...channels } = $props();
8
+ </script>
9
+
10
+ <BaseMark_TickY type="tick-y" {data} channels={['x', 'y', 'stroke']} {...channels}>
11
+ <g class="tick-y">
12
+ {#each data as datum}
13
+ <line
14
+ transform="translate(0, {plot.yScale(resolveChannel('y', datum, channels))})"
15
+ style:stroke={channels.stroke
16
+ ? plot.colorScale(resolveChannel('stroke', datum, channels))
17
+ : null}
18
+ style={getBaseStyles(datum, channels)}
19
+ x1={plot.xScale(resolveChannel('x', datum, channels))}
20
+ x2={plot.xScale(resolveChannel('x', datum, channels)) + plot.xScale.bandwidth()}
21
+ />
22
+ {/each}
23
+ </g>
24
+ </BaseMark_TickY>
25
+
26
+ <style>
27
+ .tick-y line {
28
+ stroke: currentColor;
29
+ }
30
+ </style>
@@ -0,0 +1,15 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { TickMarkProps } from '../types.js';
3
+ declare const __propDef: {
4
+ props: TickMarkProps;
5
+ events: {
6
+ [evt: string]: CustomEvent<any>;
7
+ };
8
+ slots: {};
9
+ };
10
+ export type TickYProps = typeof __propDef.props;
11
+ export type TickYEvents = typeof __propDef.events;
12
+ export type TickYSlots = typeof __propDef.slots;
13
+ export default class TickY extends SvelteComponentTyped<TickYProps, TickYEvents, TickYSlots> {
14
+ }
15
+ export {};
@@ -0,0 +1,18 @@
1
+ export declare function normalizeY({ data, y, y1, y2, stroke, fill, z, ...restProps }: {
2
+ [x: string]: any;
3
+ data: any;
4
+ y: any;
5
+ y1: any;
6
+ y2: any;
7
+ stroke: any;
8
+ fill: any;
9
+ z: any;
10
+ }): {
11
+ data: any[];
12
+ y: any;
13
+ y1: any;
14
+ y2: any;
15
+ stroke: any;
16
+ fill: any;
17
+ z: any;
18
+ };
@@ -0,0 +1,25 @@
1
+ import groupBy from 'underscore/modules/groupBy.js';
2
+ export function normalizeY({ data, y, y1, y2, stroke, fill, z, ...restProps }) {
3
+ const groupBy = stroke || fill || z;
4
+ const normalizedData = normalize(data, groupBy, ['y', 'y1', 'y2']);
5
+ return {
6
+ data: normalizedData,
7
+ y,
8
+ y1,
9
+ y2,
10
+ stroke,
11
+ fill,
12
+ z,
13
+ ...restProps
14
+ };
15
+ }
16
+ function normalize(data, groupKey, props) {
17
+ const filteredProps = props.filter((p) => data[0][p] != null);
18
+ const groups = Object.values(groupBy(data, groupKey));
19
+ return groups
20
+ .map((data) => data.map((datum) => ({
21
+ ...datum,
22
+ ...Object.fromEntries(filteredProps.map((prop) => [prop, datum[prop] / data[0][prop]]))
23
+ })))
24
+ .flat(1);
25
+ }
@@ -0,0 +1,3 @@
1
+ import type { TransformArg } from '../types.js';
2
+ export declare function recordizeX({ data, ...channels }: TransformArg): TransformArg;
3
+ export declare function recordizeY({ data, ...channels }: TransformArg): TransformArg;
@@ -0,0 +1,36 @@
1
+ import isDataRecord from '../helpers/isDataRecord.js';
2
+ // This transform takes an array of raw values as input and returns
3
+ export function recordizeX({ data, ...channels }) {
4
+ const dataIsRawValueArray = !isDataRecord(data[0]);
5
+ if (dataIsRawValueArray) {
6
+ return {
7
+ data: data.map((value, index) => ({
8
+ __value: value,
9
+ __index: index,
10
+ ___orig___: value
11
+ })),
12
+ ...channels,
13
+ x: '__value',
14
+ y: '__index'
15
+ };
16
+ }
17
+ return { data, ...channels };
18
+ }
19
+ export function recordizeY({ data, ...channels }) {
20
+ if (!data)
21
+ return { data, ...channels };
22
+ const dataIsRawValueArray = !isDataRecord(data[0]);
23
+ if (dataIsRawValueArray) {
24
+ return {
25
+ data: data.map((value, index) => ({
26
+ __value: value,
27
+ __index: index,
28
+ ___orig___: value
29
+ })),
30
+ ...channels,
31
+ x: '__index',
32
+ y: '__value'
33
+ };
34
+ }
35
+ return { data, ...channels };
36
+ }
@@ -0,0 +1,4 @@
1
+ import type { ChannelName, TransformArg } from '../types.js';
2
+ type RenameChannelsOptions = Record<ChannelName, ChannelName>;
3
+ export declare function renameChannels({ data, ...channels }: TransformArg, options: RenameChannelsOptions): TransformArg;
4
+ export {};
@@ -0,0 +1,10 @@
1
+ export function renameChannels({ data, ...channels }, options) {
2
+ const newChannels = channels;
3
+ for (const [from, to] of Object.entries(options)) {
4
+ if (newChannels[from] !== undefined) {
5
+ newChannels[to] = newChannels[from];
6
+ delete newChannels[from];
7
+ }
8
+ }
9
+ return { data, ...newChannels };
10
+ }
@@ -0,0 +1,11 @@
1
+ import type { TransformArg } from '../types.js';
2
+ type StackOrder = 'none' | 'appearance' | 'inside-out' | 'sum';
3
+ type StackOffset = 'none' | 'wiggle' | 'center' | 'normalize';
4
+ export type StackOptions = {
5
+ offset: null | StackOffset;
6
+ order: null | StackOrder;
7
+ reverse: boolean;
8
+ };
9
+ export declare function stackY({ data, ...channels }: TransformArg, opts?: Partial<StackOptions>): TransformArg;
10
+ export declare function stackX({ data, ...channels }: TransformArg, opts?: Partial<StackOptions>): TransformArg;
11
+ export {};
@@ -0,0 +1,80 @@
1
+ import isDataRecord from '../helpers/isDataRecord.js';
2
+ import resolveChannel from '../helpers/resolveChannel.js';
3
+ import { stack, stackOffsetExpand, stackOffsetSilhouette, stackOffsetWiggle, stackOrderAppearance, stackOrderAscending, stackOrderInsideOut, stackOrderNone } from 'd3-shape';
4
+ import { index, union } from 'd3-array';
5
+ const DEFAULT_STACK_OPTIONS = {
6
+ order: null,
7
+ offset: null,
8
+ reverse: false
9
+ };
10
+ const STACK_ORDER = {
11
+ // null
12
+ // TODO: value: ,
13
+ none: stackOrderNone,
14
+ sum: stackOrderAscending,
15
+ appearance: stackOrderAppearance,
16
+ 'inside-out': stackOrderInsideOut
17
+ };
18
+ const STACK_OFFSET = {
19
+ none: null,
20
+ wiggle: stackOffsetWiggle,
21
+ center: stackOffsetSilhouette,
22
+ normalize: stackOffsetExpand
23
+ };
24
+ function stackXY(byDim, data, channels, options) {
25
+ const groupBy = channels.z ? 'z' : channels.fill ? 'fill' : channels.stroke ? 'stroke' : true;
26
+ const secondDim = byDim === 'x' ? 'y' : 'x';
27
+ const byLow = `${byDim}1`;
28
+ const byHigh = `${byDim}2`;
29
+ if (channels[byDim] !== undefined &&
30
+ channels[`${byLow}`] === undefined &&
31
+ channels[`${byHigh}`] === undefined) {
32
+ const resolvedData = data.map((d) => ({
33
+ ...(isDataRecord(d) ? d : { __orig: d }),
34
+ [`__${secondDim}`]: resolveChannel(secondDim, d, channels),
35
+ __group: groupBy === true ? 'G' : resolveChannel(groupBy, d, channels),
36
+ [`__${byDim}`]: resolveChannel(byDim, d, channels)
37
+ }));
38
+ const indexed = index(resolvedData, (d) => d[`__${secondDim}`], (d) => d.__group);
39
+ const stackOrder = (series) => {
40
+ const f = STACK_ORDER[options.order || 'none'];
41
+ return options.reverse ? f(series).reverse() : f(series);
42
+ };
43
+ const series = stack()
44
+ .order(stackOrder)
45
+ .offset(STACK_OFFSET[options.offset])
46
+ .keys(union(resolvedData.map((d) => d.__group)))
47
+ .value(([, group], key) => (group.get(key) ? group.get(key)[`__${byDim}`] : 0))(indexed);
48
+ const newData = series
49
+ .map((values) => {
50
+ const groupKey = values.key;
51
+ return values
52
+ .filter((d) => d.data[1].get(groupKey))
53
+ .map((d) => {
54
+ const { [`__${byDim}`]: unused1, [`__${secondDim}`]: unused2, ...datum } = d.data[1].get(groupKey);
55
+ return { ...datum, [`__${byLow}`]: d[0], [`__${byHigh}`]: d[1] };
56
+ });
57
+ })
58
+ .flat(1);
59
+ console.log({ newData });
60
+ return {
61
+ data: newData,
62
+ ...channels,
63
+ [byDim]: undefined,
64
+ ...{ [byLow]: `__${byLow}`, [byHigh]: `__${byHigh}` }
65
+ };
66
+ }
67
+ return { data, ...channels };
68
+ }
69
+ export function stackY({ data, ...channels }, opts = {}) {
70
+ return stackXY('y', data, channels, applyDefaults(opts));
71
+ }
72
+ export function stackX({ data, ...channels }, opts = {}) {
73
+ return stackXY('x', data, channels, applyDefaults(opts));
74
+ }
75
+ function applyDefaults(opts) {
76
+ if (opts.offset === 'wiggle' && opts.order === undefined) {
77
+ return { ...DEFAULT_STACK_OPTIONS, order: 'inside-out', ...opts };
78
+ }
79
+ return { ...DEFAULT_STACK_OPTIONS, ...opts };
80
+ }