svelteplot 0.0.1-alpha.2 → 0.0.1-alpha.21

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 +56 -42
  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,49 +1,48 @@
1
- <script>import resolveChannel from "../helpers/resolveChannel";
1
+ <script context="module"></script>
2
+
3
+ <script>import resolveChannel from "../helpers/resolveChannel.js";
2
4
  import { getContext } from "svelte";
3
5
  import BaseMark from "./BaseMark.svelte";
4
- import getBaseStyles from "../helpers/getBaseStyles";
6
+ import getBaseStyles from "../helpers/getBaseStyles.js";
5
7
  import { line } from "d3-shape";
6
8
  import { groupBy } from "underscore";
9
+ import { maybeCurve } from "../helpers/curves.js";
7
10
  const BaseMark_Line = BaseMark;
8
11
  const plot = getContext("svelteplot");
9
- let {
10
- data,
11
- x = null,
12
- y = null,
13
- z = null,
14
- fill,
15
- stroke,
16
- r = 5,
17
- ...styleProps
18
- } = $props();
12
+ let { data, curve, tension, ...channels } = $props();
13
+ let { sort, z, fill, stroke } = $derived(channels);
19
14
  let groups = $derived(
20
- z ? Object.values(groupBy(data, (d) => resolveChannel("z", d, z))) : [data]
15
+ z || fill || stroke ? Object.values(groupBy(data, (d) => resolveChannel("z", d, channels))) : [data]
16
+ );
17
+ let sortedGroups = $derived(
18
+ sort ? groups.sort(
19
+ (a, b) => resolveChannel("sort", a[0], channels) > resolveChannel("sort", b[0], channels) ? 1 : -1
20
+ ) : groups
21
+ );
22
+ let linePath = $derived(
23
+ line().curve(maybeCurve(curve, tension)).x((d) => plot.xScale(resolveChannel("x", d, channels))).y((d) => plot.yScale(resolveChannel("y", d, channels)))
21
24
  );
22
- let linePath = line().x((d) => plot.xScale(resolveChannel("x", d, x))).y((d) => plot.yScale(resolveChannel("y", d, y)));
23
25
  </script>
24
26
 
25
- <BaseMark_Line
26
- type="dot"
27
- {data}
28
- channels={['x', 'y', 'radius', 'color']}
29
- {x}
30
- {y}
31
- {r}
32
- {fill}
33
- {stroke}
34
- {...styleProps}
35
- >
27
+ <BaseMark_Line type="line" {data} channels={['x', 'y', 'color']} {...channels}>
36
28
  <g class="lines">
37
- {#each groups as lineData}
38
- <path d={linePath(lineData)} style={getBaseStyles(lineData[0], styleProps)} />
29
+ {#each sortedGroups as lineData}
30
+ <path
31
+ d={linePath(lineData)}
32
+ stroke={stroke
33
+ ? plot.colorScale(resolveChannel('stroke', lineData[0], channels))
34
+ : 'currentColor'}
35
+ fill={fill
36
+ ? plot.colorScale(resolveChannel('fill', lineData[0], channels))
37
+ : 'none'}
38
+ style={getBaseStyles(lineData[0], channels)}
39
+ />
39
40
  {/each}
40
41
  </g>
41
42
  </BaseMark_Line>
42
43
 
43
44
  <style>
44
45
  .lines path {
45
- stroke: currentColor;
46
- fill: none;
47
46
  stroke-width: 1.4px;
48
47
  }
49
48
  </style>
@@ -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 {};