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
@@ -0,0 +1,25 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { MarkProps, BaseMarkStyleProps, ChannelAccessor, DataRow } from '../types.js';
3
+ import type { StackOptions } from '../transforms/stack.js';
4
+ export type BarXMarkProps = MarkProps & BaseMarkStyleProps & {
5
+ data: DataRow[];
6
+ x?: ChannelAccessor;
7
+ x1?: ChannelAccessor;
8
+ x2?: ChannelAccessor;
9
+ y?: ChannelAccessor;
10
+ inset: number;
11
+ stack: StackOptions;
12
+ };
13
+ declare const __propDef: {
14
+ props: BarXMarkProps;
15
+ events: {
16
+ [evt: string]: CustomEvent<any>;
17
+ };
18
+ slots: {};
19
+ };
20
+ export type BarXProps = typeof __propDef.props;
21
+ export type BarXEvents = typeof __propDef.events;
22
+ export type BarXSlots = typeof __propDef.slots;
23
+ export default class BarX extends SvelteComponentTyped<BarXProps, BarXEvents, BarXSlots> {
24
+ }
25
+ export {};
@@ -0,0 +1,52 @@
1
+ <script context="module"></script>
2
+
3
+ <script>import { getContext } from "svelte";
4
+ import BaseMark from "./BaseMark.svelte";
5
+ import getBaseStyles from "../helpers/getBaseStyles.js";
6
+ import resolveChannel from "../helpers/resolveChannel.js";
7
+ import { stackY } from "../transforms/stack.js";
8
+ import { recordizeY } from "../transforms/recordize.js";
9
+ const BaseMark_BarY = BaseMark;
10
+ const plot = getContext("svelteplot");
11
+ let { data: rawData, insetLeft, insetRight, ...rawChannels } = $props();
12
+ let { data, ...channels } = $derived(stackY(recordizeY({ data: rawData, ...rawChannels })));
13
+ function isValid(value) {
14
+ return value !== null && !Number.isNaN(value);
15
+ }
16
+ </script>
17
+
18
+ <BaseMark_BarY type="bar-y" {data} channels={['x', 'y1', 'y2', 'fill', 'stroke']} {...channels}>
19
+ <g class="bars-y">
20
+ {#each data as datum}
21
+ {@const cx = resolveChannel('x', datum, channels)}
22
+ {@const cy1 = resolveChannel('y1', datum, channels)}
23
+ {@const cy2 = resolveChannel('y2', datum, channels)}
24
+ {@const miny = Math.min(plot.yScale(cy1), plot.yScale(cy2))}
25
+ {@const maxy = Math.max(plot.yScale(cy1), plot.yScale(cy2))}
26
+ {@const maybeFillColor = resolveChannel('fill', datum, channels)}
27
+ {@const maybeStrokeColor = resolveChannel('stroke', datum, channels)}
28
+ {#if isValid(cx) && isValid(cy1) && isValid(cy2)}
29
+ <rect
30
+ style={getBaseStyles(datum, channels)}
31
+ style:fill={maybeFillColor
32
+ ? plot.colorScale(maybeFillColor)
33
+ : maybeStrokeColor
34
+ ? null
35
+ : 'currentColor'}
36
+ style:stroke={maybeStrokeColor ? plot.colorScale(maybeStrokeColor) : null}
37
+ transform="translate({[plot.xScale(cx), miny]})"
38
+ height={maxy - miny}
39
+ width={plot.xScale.bandwidth()}
40
+ />
41
+ {/if}
42
+ {/each}
43
+ </g>
44
+ </BaseMark_BarY>
45
+
46
+ <style>
47
+ rect {
48
+ fill: none;
49
+ stroke: none;
50
+ stroke-width: 1.6px;
51
+ }
52
+ </style>
@@ -0,0 +1,25 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { MarkProps, BaseMarkStyleProps, ChannelAccessor, DataRow } from '../types.js';
3
+ import type { StackOptions } from '../transforms/stack.js';
4
+ export type BarYMarkProps = MarkProps & BaseMarkStyleProps & {
5
+ data: DataRow[];
6
+ x?: ChannelAccessor;
7
+ y?: ChannelAccessor;
8
+ y1?: ChannelAccessor;
9
+ y2?: ChannelAccessor;
10
+ stack: StackOptions;
11
+ inset: number;
12
+ };
13
+ declare const __propDef: {
14
+ props: BarYMarkProps;
15
+ events: {
16
+ [evt: string]: CustomEvent<any>;
17
+ };
18
+ slots: {};
19
+ };
20
+ export type BarYProps = typeof __propDef.props;
21
+ export type BarYEvents = typeof __propDef.events;
22
+ export type BarYSlots = typeof __propDef.slots;
23
+ export default class BarY extends SvelteComponentTyped<BarYProps, BarYEvents, BarYSlots> {
24
+ }
25
+ export {};
@@ -1,10 +1,17 @@
1
1
  <script context="module"></script>
2
2
 
3
- <script generics="T extends BaseMarkProps">import { Mark } from "../classes/Mark.svelte";
3
+ <script generics="T extends BaseMarkProps">import { Mark } from "../classes/Mark.svelte.js";
4
4
  import { getContext } from "svelte";
5
5
  const plot = getContext("svelteplot");
6
- let { type, data = [], channels = [], children, automatic, ...rest } = $props();
7
- const mark = new Mark(type, channels, automatic, { data, ...rest });
6
+ let {
7
+ type,
8
+ data = [],
9
+ channels = [],
10
+ children,
11
+ automatic,
12
+ ...rest
13
+ } = $props();
14
+ const mark = new Mark(type, channels, !!automatic, { data, ...rest });
8
15
  plot.addMark(mark);
9
16
  $effect(() => {
10
17
  mark.channels = new Set(channels);
@@ -1,8 +1,9 @@
1
- import { SvelteComponent } from "svelte";
2
- import type { BaseMarkProps } from '../types';
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { BaseMarkProps } from '../types.js';
3
+ import { type Snippet } from 'svelte';
3
4
  declare class __sveltets_Render<T extends BaseMarkProps> {
4
5
  props(): T & {
5
- children?: Function | undefined;
6
+ children?: Snippet<void> | undefined;
6
7
  };
7
8
  events(): {} & {
8
9
  [evt: string]: CustomEvent<any>;
@@ -14,6 +15,6 @@ declare class __sveltets_Render<T extends BaseMarkProps> {
14
15
  export type BaseMarkProps<T extends BaseMarkProps> = ReturnType<__sveltets_Render<T>['props']>;
15
16
  export type BaseMarkEvents<T extends BaseMarkProps> = ReturnType<__sveltets_Render<T>['events']>;
16
17
  export type BaseMarkSlots<T extends BaseMarkProps> = ReturnType<__sveltets_Render<T>['slots']>;
17
- export default class BaseMark<T extends BaseMarkProps> extends SvelteComponent<BaseMarkProps<T>, BaseMarkEvents<T>, BaseMarkSlots<T>> {
18
+ export default class BaseMark<T extends BaseMarkProps> extends SvelteComponentTyped<BaseMarkProps<T>, BaseMarkEvents<T>, BaseMarkSlots<T>> {
18
19
  }
19
20
  export {};
@@ -1,33 +1,33 @@
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}
8
- <div class="color-legend">
9
- {#each plot.colorScale.domain() as value}
10
- {@const symbolV = plot.symbolScale(value)}
11
- {@const symbolType = maybeSymbol(symbolV)}
12
- <div class="item">
13
- <div class="swatch">
14
- <svg width="15" height="15"
15
- >{#if plot.colorSymbolRedundant}
16
- <path
17
- transform="translate(7.5,7.5)"
18
- fill={plot.hasFilledDotMarks ? plot.colorScale(value) : 'none'}
19
- stroke={plot.hasFilledDotMarks ? null : plot.colorScale(value)}
20
- d={d3Symbol(symbolType, 40)()}
21
- />
22
- {:else}
23
- <rect fill={plot.colorScale(value)} width="15" height="15" />
24
- {/if}</svg
25
- >
8
+ <div class="color-legend">
9
+ {#each plot.colorScale.domain() as value}
10
+ {@const symbolV = plot.symbolScale(value)}
11
+ {@const symbolType = maybeSymbol(symbolV)}
12
+ <div class="item">
13
+ <div class="swatch">
14
+ <svg width="15" height="15"
15
+ >{#if plot.colorSymbolRedundant}
16
+ <path
17
+ transform="translate(7.5,7.5)"
18
+ fill={plot.hasFilledDotMarks ? plot.colorScale(value) : 'none'}
19
+ stroke={plot.hasFilledDotMarks ? null : plot.colorScale(value)}
20
+ d={d3Symbol(symbolType, 40)()}
21
+ />
22
+ {:else}
23
+ <rect fill={plot.colorScale(value)} width="15" height="15" />
24
+ {/if}</svg
25
+ >
26
+ </div>
27
+ <span class="item-label">{value}</span>
26
28
  </div>
27
- <span class="item-label">{value}</span>
28
- </div>
29
- {/each}
30
- </div>
29
+ {/each}
30
+ </div>
31
31
  {/if}
32
32
 
33
33
  <style>
@@ -40,7 +40,9 @@ const plot = getContext("svelteplot");
40
40
  .item {
41
41
  margin: 0 1em 0.5ex 0;
42
42
  }
43
- path { stroke-width: 1.5;}
43
+ path {
44
+ stroke-width: 1.5;
45
+ }
44
46
  .item,
45
47
  .item-label,
46
48
  .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 ColorLegendProps = typeof __propDef.props;
10
10
  export type ColorLegendEvents = typeof __propDef.events;
11
11
  export type ColorLegendSlots = typeof __propDef.slots;
12
- export default class ColorLegend extends SvelteComponent<ColorLegendProps, ColorLegendEvents, ColorLegendSlots> {
12
+ export default class ColorLegend extends SvelteComponentTyped<ColorLegendProps, ColorLegendEvents, ColorLegendSlots> {
13
13
  }
14
14
  export {};
@@ -1,66 +1,51 @@
1
- <script>import resolveChannel from "../helpers/resolveChannel";
2
- import { getContext } from "svelte";
1
+ <script context="module"></script>
2
+
3
+ <script>import { getContext } from "svelte";
3
4
  import BaseMark from "./BaseMark.svelte";
4
- import getBaseStyles from "../helpers/getBaseStyles";
5
+ import getBaseStyles from "../helpers/getBaseStyles.js";
6
+ import resolveChannel from "../helpers/resolveChannel.js";
7
+ import { isSymbol, maybeSymbol } from "../helpers/symbols.js";
5
8
  import { symbol as d3Symbol } from "d3-shape";
6
- import { isSymbol, maybeSymbol } from "../helpers/symbols";
7
- import chroma from "chroma-js";
8
9
  const BaseMark_Dot = BaseMark;
9
10
  const plot = getContext("svelteplot");
10
- let {
11
- data,
12
- x = null,
13
- y = null,
14
- r = 3,
15
- symbol = "circle",
16
- stroke = null,
17
- fill = null,
18
- ...styleProps
19
- } = $props();
20
- let styleProps2 = $derived({
21
- ...styleProps,
22
- ...!styleProps.fill && !styleProps.stroke ? { stroke: "currentColor" } : {}
23
- });
11
+ let { data, ...channels } = $props();
12
+ let { r = 3, symbol = "circle" } = $derived(channels);
13
+ let channelsWithDefaults = $derived({ ...channels, r, symbol });
14
+ $inspect(channelsWithDefaults);
24
15
  function isValid(value) {
25
16
  return value !== null && !Number.isNaN(value);
26
17
  }
18
+ function getSymbolPath(symbolT, size) {
19
+ const symbolType = isSymbol(symbolT) ? maybeSymbol(symbolT) : maybeSymbol(plot.symbolScale(symbolT));
20
+ return d3Symbol(symbolType, size)();
21
+ }
27
22
  </script>
28
23
 
29
24
  <BaseMark_Dot
30
25
  type="dot"
31
26
  {data}
32
- channels={[
33
- ...(x ? ['x' as 'x'] : []),
34
- ...(y ? ['y' as 'y'] : []),
35
- ...(r ? ['radius'] : []),
36
- ...(symbol ? ['symbol'] : []),
37
- ...(fill || stroke ? ['color']: [])
38
- ]}
39
- {x}
40
- {y}
41
- {r}
42
- {fill}
43
- {stroke}
44
- {symbol}
45
- {...styleProps}
27
+ channels={['x', 'y', 'r', 'symbol', 'fill', 'stroke']}
28
+ {...channels}
46
29
  >
47
30
  <g class="dots">
48
31
  {#each data as datum, i}
49
- {@const cx = resolveChannel('x', datum, x)}
50
- {@const cy = resolveChannel('y', datum, y)}
51
- {@const symbolT = resolveChannel('symbol', datum, symbol) as string|SymbolType}
32
+ {@const cx = resolveChannel('x', datum, channelsWithDefaults)}
33
+ {@const cy = resolveChannel('y', datum, channelsWithDefaults)}
34
+ {@const maybeFillColor = resolveChannel('fill', datum, channelsWithDefaults)}
35
+ {@const maybeStrokeColor = resolveChannel('stroke', datum, channelsWithDefaults)}
36
+ {@const radius =
37
+ typeof r === 'number'
38
+ ? r
39
+ : plot.radiusScale(resolveChannel('r', datum, channelsWithDefaults))}
40
+ {@const size = radius * radius * Math.PI}
41
+ {@const symbolT = resolveChannel('symbol', datum, channelsWithDefaults)}
52
42
  {@const symbolType = isSymbol(symbolT)
53
43
  ? maybeSymbol(symbolT)
54
44
  : maybeSymbol(plot.symbolScale(symbolT))}
55
- {@const radius =
56
- typeof r === 'number' ? r : plot.radiusScale(resolveChannel('radius', datum, r))}
57
- {@const size = radius * radius * Math.PI}
58
- {@const maybeFillColor = resolveChannel('color', datum, fill)}
59
- {@const maybeStrokeColor = resolveChannel('color', datum, stroke)}
60
45
  {#if isValid(cx) && isValid(cy)}
61
46
  <path
62
- d={d3Symbol(symbolType, size)()}
63
- style={getBaseStyles(datum, styleProps)}
47
+ d={getSymbolPath(symbolType, size)}
48
+ style={getBaseStyles(datum, channels)}
64
49
  style:fill={maybeFillColor ? plot.colorScale(maybeFillColor) : null}
65
50
  style:stroke={maybeStrokeColor
66
51
  ? plot.colorScale(maybeStrokeColor)
@@ -1,5 +1,13 @@
1
- import { SvelteComponent } from "svelte";
2
- import type { DotMarkProps } from '../types';
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { MarkProps, BaseMarkStyleProps, ChannelAccessor, DataRow } from '../types.js';
3
+ export type DotMarkProps = MarkProps & BaseMarkStyleProps & {
4
+ data: DataRow[];
5
+ x?: ChannelAccessor;
6
+ y?: ChannelAccessor;
7
+ r?: ChannelAccessor;
8
+ rotate?: ChannelAccessor;
9
+ symbol?: ChannelAccessor;
10
+ };
3
11
  declare const __propDef: {
4
12
  props: DotMarkProps;
5
13
  events: {
@@ -10,6 +18,6 @@ declare const __propDef: {
10
18
  export type DotProps = typeof __propDef.props;
11
19
  export type DotEvents = typeof __propDef.events;
12
20
  export type DotSlots = typeof __propDef.slots;
13
- export default class Dot extends SvelteComponent<DotProps, DotEvents, DotSlots> {
21
+ export default class Dot extends SvelteComponentTyped<DotProps, DotEvents, DotSlots> {
14
22
  }
15
23
  export {};
@@ -1,5 +1,5 @@
1
- import { SvelteComponent } from "svelte";
2
- import type { RawValue } from '../types';
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { RawValue } from '../types.js';
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  data: RawValue[];
@@ -12,6 +12,6 @@ declare const __propDef: {
12
12
  export type DotXProps = typeof __propDef.props;
13
13
  export type DotXEvents = typeof __propDef.events;
14
14
  export type DotXSlots = typeof __propDef.slots;
15
- export default class DotX extends SvelteComponent<DotXProps, DotXEvents, DotXSlots> {
15
+ export default class DotX extends SvelteComponentTyped<DotXProps, DotXEvents, DotXSlots> {
16
16
  }
17
17
  export {};
@@ -1,5 +1,5 @@
1
- import { SvelteComponent } from "svelte";
2
- import type { RawValue } from '../types';
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { RawValue } from '../types.js';
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  data: RawValue[];
@@ -12,6 +12,6 @@ declare const __propDef: {
12
12
  export type DotYProps = typeof __propDef.props;
13
13
  export type DotYEvents = typeof __propDef.events;
14
14
  export type DotYSlots = typeof __propDef.slots;
15
- export default class DotY extends SvelteComponent<DotYProps, DotYEvents, DotYSlots> {
15
+ export default class DotY extends SvelteComponentTyped<DotYProps, DotYEvents, DotYSlots> {
16
16
  }
17
17
  export {};
@@ -1,6 +1,6 @@
1
1
  <script>import { getContext } from "svelte";
2
2
  import BaseMark from "./BaseMark.svelte";
3
- import getBaseStyles from "../helpers/getBaseStyles";
3
+ import getBaseStyles from "../helpers/getBaseStyles.js";
4
4
  const plot = getContext("svelteplot");
5
5
  let { ...styleProps } = $props();
6
6
  let styleProps2 = $derived({
@@ -1,7 +1,7 @@
1
- import { SvelteComponent } from "svelte";
2
- import type { FrameProps } from '../types';
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { FrameProps } from '../types.js';
3
3
  declare const __propDef: {
4
- props: import("../types").BaseMarkStyleProps;
4
+ props: import("../types.js").BaseMarkStyleProps;
5
5
  events: {
6
6
  [evt: string]: CustomEvent<any>;
7
7
  };
@@ -11,5 +11,5 @@ type FrameProps_ = typeof __propDef.props;
11
11
  export { FrameProps_ as FrameProps };
12
12
  export type FrameEvents = typeof __propDef.events;
13
13
  export type FrameSlots = typeof __propDef.slots;
14
- export default class Frame extends SvelteComponent<FrameProps, FrameEvents, FrameSlots> {
14
+ export default class Frame extends SvelteComponentTyped<FrameProps, FrameEvents, FrameSlots> {
15
15
  }
@@ -1,33 +1,43 @@
1
1
  <script>import { getContext } from "svelte";
2
- import BaseMark from "./BaseMark.svelte";
3
- import resolveChannel from "../helpers/resolveChannel";
4
- import getBaseStyles from "../helpers/getBaseStyles";
5
2
  import { get } from "underscore";
3
+ import BaseMark from "./BaseMark.svelte";
4
+ import resolveChannel from "../helpers/resolveChannel.js";
5
+ import getBaseStyles from "../helpers/getBaseStyles.js";
6
6
  const BaseMark_GridX = BaseMark;
7
7
  const plot = getContext("svelteplot");
8
- let {
9
- ticks = [],
10
- y1 = null,
11
- y2 = null,
12
- automatic = false,
13
- ...styleProps
14
- } = $props();
15
- let autoTickCount = $derived(plot.plotWidth / get(plot, "options.x.tickSpacing", 80));
8
+ let { ticks = [], automatic = false, ...channels } = $props();
9
+ let autoTickCount = $derived(
10
+ Math.max(2, Math.round(plot.plotWidth / (plot.options?.x?.tickSpacing || 80)))
11
+ );
12
+ $inspect(autoTickCount);
16
13
  let autoTicks = $derived(
17
14
  ticks.length > 0 ? ticks : get(plot, "options.x.ticks", plot.xScale.ticks(autoTickCount))
18
15
  );
16
+ let { y1, y2 } = $derived(channels);
19
17
  </script>
20
18
 
21
- <BaseMark_GridX type="grid-x" data={ticks} channels={['x']} {y1} {y2} {automatic}>
19
+ <BaseMark_GridX
20
+ type="grid-x"
21
+ data={ticks.length ? ticks.map((tick) => ({ __x: tick })) : undefined}
22
+ channels={['y']}
23
+ x="__x"
24
+ {...channels}
25
+ {automatic}
26
+ >
22
27
  <g class="grid-x">
23
- {#each autoTicks as tick, t}
24
- <g class="x-tick" transform="translate({plot.xScale(tick)},{plot.margins.top})">
28
+ {#each autoTicks as tick}
29
+ <g
30
+ class="x-tick"
31
+ transform="translate({plot.xScale(tick) +
32
+ (plot.xScale.bandwidth ? plot.xScale.bandwidth() * 0.5 : 0)},{plot.margins
33
+ .top})"
34
+ >
25
35
  <line
26
36
  class="grid"
27
- style={getBaseStyles(tick, styleProps)}
28
- y1={y1 ? plot.yScale(resolveChannel('y', tick, y1)) : 0}
37
+ style={getBaseStyles(tick, channels)}
38
+ y1={y1 ? plot.yScale(resolveChannel('y1', tick, channels)) : 0}
29
39
  y2={y2
30
- ? plot.yScale(resolveChannel('y', tick, y2))
40
+ ? plot.yScale(resolveChannel('y2', tick, channels))
31
41
  : plot.height - plot.margins.top - plot.margins.bottom}
32
42
  />
33
43
  </g>
@@ -37,6 +47,7 @@ let autoTicks = $derived(
37
47
 
38
48
  <style>
39
49
  .x-tick line.grid {
40
- stroke: #d9d9d9;
50
+ stroke: currentColor;
51
+ stroke-opacity: 0.1;
41
52
  }
42
53
  </style>
@@ -1,9 +1,9 @@
1
- import { SvelteComponent } from "svelte";
2
- import type { GridOptions } from '../types';
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { GridOptions, ChannelAccessor } from '../types.js';
3
3
  declare const __propDef: {
4
- props: Partial<import("../types").MarkProps> & GridOptions & {
5
- y1?: import("../types").ChannelAccessor | undefined;
6
- y2?: import("../types").ChannelAccessor | undefined;
4
+ props: Partial<import("../types.js").MarkProps> & GridOptions & {
5
+ y1?: ChannelAccessor;
6
+ y2?: ChannelAccessor;
7
7
  automatic?: boolean | undefined;
8
8
  };
9
9
  events: {
@@ -14,6 +14,6 @@ declare const __propDef: {
14
14
  export type GridXProps = typeof __propDef.props;
15
15
  export type GridXEvents = typeof __propDef.events;
16
16
  export type GridXSlots = typeof __propDef.slots;
17
- export default class GridX extends SvelteComponent<GridXProps, GridXEvents, GridXSlots> {
17
+ export default class GridX extends SvelteComponentTyped<GridXProps, GridXEvents, GridXSlots> {
18
18
  }
19
19
  export {};
@@ -1,19 +1,28 @@
1
1
  <script>import { getContext } from "svelte";
2
2
  import BaseMark from "./BaseMark.svelte";
3
- import getBaseStyles from "../helpers/getBaseStyles";
4
- import { get } from "underscore";
3
+ import getBaseStyles from "../helpers/getBaseStyles.js";
5
4
  const plot = getContext("svelteplot");
6
5
  let { ticks = [], automatic = false, ...styleProps } = $props();
7
- let autoTickCount = $derived(plot.plotHeight / get(plot, "options.y.tickSpacing", 80));
6
+ let autoTickCount = $derived(plot.plotHeight / (plot.options.y?.tickSpacing || 80));
8
7
  let autoTicks = $derived(
9
- ticks.length > 0 ? ticks : get(plot, "options.y.ticks", plot.yScale.ticks(autoTickCount))
8
+ ticks.length > 0 ? ticks : plot.options.y?.ticks || plot.yScale.ticks(autoTickCount)
10
9
  );
11
10
  </script>
12
11
 
13
- <BaseMark type="grid-y" data={ticks} channels={['y']} {automatic}>
12
+ <BaseMark
13
+ type="grid-y"
14
+ data={ticks.length ? ticks.map((tick) => ({ __y: tick })) : undefined}
15
+ channels={['y']}
16
+ y="__y"
17
+ {automatic}
18
+ >
14
19
  <g class="grid-y">
15
20
  {#each autoTicks as tick}
16
- <g class="y-tick" transform="translate({plot.margins.left},{plot.yScale(tick)})">
21
+ <g
22
+ class="y-tick"
23
+ transform="translate({plot.margins.left},{plot.yScale(tick) +
24
+ (plot.yScale.bandwidth ? plot.yScale.bandwidth() * 0.5 : 0)})"
25
+ >
17
26
  <line
18
27
  style={getBaseStyles(tick, styleProps)}
19
28
  class="grid"
@@ -26,6 +35,7 @@ let autoTicks = $derived(
26
35
 
27
36
  <style>
28
37
  .y-tick line.grid {
29
- stroke: #d9d9d9;
38
+ stroke: currentColor;
39
+ stroke-opacity: 0.2;
30
40
  }
31
41
  </style>
@@ -1,5 +1,5 @@
1
- import { SvelteComponent } from "svelte";
2
- import type { GridYMarkProps } from '../types';
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { GridYMarkProps } from '../types.js';
3
3
  declare const __propDef: {
4
4
  props: GridYMarkProps;
5
5
  events: {
@@ -10,6 +10,6 @@ declare const __propDef: {
10
10
  export type GridYProps = typeof __propDef.props;
11
11
  export type GridYEvents = typeof __propDef.events;
12
12
  export type GridYSlots = typeof __propDef.slots;
13
- export default class GridY extends SvelteComponent<GridYProps, GridYEvents, GridYSlots> {
13
+ export default class GridY extends SvelteComponentTyped<GridYProps, GridYEvents, GridYSlots> {
14
14
  }
15
15
  export {};
@@ -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>