svelteplot 0.0.1-alpha.1 → 0.0.1-alpha.10

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 (78) hide show
  1. package/dist/Plot.svelte +172 -0
  2. package/dist/Plot.svelte.d.ts +15 -0
  3. package/dist/classes/Channel.svelte.js +74 -0
  4. package/dist/classes/Mark.svelte.js +17 -0
  5. package/dist/classes/Plot.svelte.js +98 -0
  6. package/dist/contants.d.ts +3 -0
  7. package/dist/contants.js +40 -0
  8. package/dist/helpers/GroupMultiple.svelte +8 -0
  9. package/dist/helpers/GroupMultiple.svelte.d.ts +19 -0
  10. package/dist/helpers/autoTimeFormat.d.ts +2 -0
  11. package/dist/helpers/autoTimeFormat.js +10 -0
  12. package/dist/helpers/callWithProps.d.ts +4 -0
  13. package/dist/helpers/callWithProps.js +9 -0
  14. package/dist/helpers/colors.d.ts +13 -0
  15. package/dist/helpers/colors.js +200 -0
  16. package/dist/helpers/createScale.d.ts +5 -0
  17. package/dist/helpers/createScale.js +57 -0
  18. package/dist/helpers/getBaseStyles.d.ts +2 -0
  19. package/dist/helpers/getBaseStyles.js +18 -0
  20. package/dist/helpers/getLogTicks.d.ts +1 -0
  21. package/dist/helpers/getLogTicks.js +57 -0
  22. package/dist/helpers/isDataRecord.d.ts +2 -0
  23. package/dist/helpers/isDataRecord.js +13 -0
  24. package/dist/helpers/mergeDeep.d.ts +5 -0
  25. package/dist/helpers/mergeDeep.js +26 -0
  26. package/dist/helpers/removeIdenticalLines.d.ts +1 -0
  27. package/dist/helpers/removeIdenticalLines.js +16 -0
  28. package/dist/helpers/resolveChannel.d.ts +2 -0
  29. package/dist/helpers/resolveChannel.js +28 -0
  30. package/dist/helpers/symbols.d.ts +5 -0
  31. package/dist/helpers/symbols.js +51 -0
  32. package/dist/helpers/typeChecks.d.ts +7 -0
  33. package/dist/helpers/typeChecks.js +21 -0
  34. package/dist/helpers/wrapArray.d.ts +2 -0
  35. package/dist/helpers/wrapArray.js +4 -0
  36. package/dist/index.d.ts +19 -0
  37. package/dist/index.js +20 -0
  38. package/dist/marks/Area.svelte +81 -0
  39. package/dist/marks/Area.svelte.d.ts +15 -0
  40. package/dist/marks/AreaX.svelte +19 -0
  41. package/dist/marks/AreaX.svelte.d.ts +17 -0
  42. package/dist/marks/AreaY.svelte +14 -0
  43. package/dist/marks/AreaY.svelte.d.ts +17 -0
  44. package/dist/marks/AxisX.svelte +102 -0
  45. package/dist/marks/AxisX.svelte.d.ts +17 -0
  46. package/dist/marks/AxisY.svelte +80 -0
  47. package/dist/marks/AxisY.svelte.d.ts +15 -0
  48. package/dist/marks/BaseMark.svelte +22 -0
  49. package/dist/marks/BaseMark.svelte.d.ts +19 -0
  50. package/dist/marks/ColorLegend.svelte +54 -0
  51. package/dist/marks/ColorLegend.svelte.d.ts +14 -0
  52. package/dist/marks/Dot.svelte +82 -0
  53. package/dist/marks/Dot.svelte.d.ts +15 -0
  54. package/dist/marks/DotX.svelte +5 -0
  55. package/dist/marks/DotX.svelte.d.ts +17 -0
  56. package/dist/marks/DotY.svelte +5 -0
  57. package/dist/marks/DotY.svelte.d.ts +17 -0
  58. package/dist/marks/Frame.svelte +37 -0
  59. package/dist/marks/Frame.svelte.d.ts +15 -0
  60. package/dist/marks/GridX.svelte +42 -0
  61. package/dist/marks/GridX.svelte.d.ts +19 -0
  62. package/dist/marks/GridY.svelte +31 -0
  63. package/dist/marks/GridY.svelte.d.ts +15 -0
  64. package/dist/marks/Line.svelte +59 -0
  65. package/dist/marks/Line.svelte.d.ts +15 -0
  66. package/dist/marks/LineX.svelte +10 -0
  67. package/dist/marks/LineX.svelte.d.ts +17 -0
  68. package/dist/marks/LineY.svelte +10 -0
  69. package/dist/marks/LineY.svelte.d.ts +17 -0
  70. package/dist/marks/RuleX.svelte +30 -0
  71. package/dist/marks/RuleX.svelte.d.ts +15 -0
  72. package/dist/marks/RuleY.svelte +30 -0
  73. package/dist/marks/RuleY.svelte.d.ts +15 -0
  74. package/dist/marks/SymbolLegend.svelte +50 -0
  75. package/dist/marks/SymbolLegend.svelte.d.ts +14 -0
  76. package/dist/types.d.ts +209 -0
  77. package/dist/types.js +1 -0
  78. package/package.json +5 -3
@@ -0,0 +1,81 @@
1
+ <script>import resolveChannel from "../helpers/resolveChannel.js";
2
+ import { getContext } from "svelte";
3
+ import BaseMark from "./BaseMark.svelte";
4
+ import getBaseStyles from "../helpers/getBaseStyles.js";
5
+ import { area } from "d3-shape";
6
+ import { groupBy } from "underscore";
7
+ import callWithProps from "../helpers/callWithProps.js";
8
+ const BaseMark_Area = BaseMark;
9
+ const plot = getContext("svelteplot");
10
+ let {
11
+ data,
12
+ x1 = null,
13
+ x2 = null,
14
+ y1 = null,
15
+ y2 = null,
16
+ z = null,
17
+ fill,
18
+ stroke,
19
+ sort,
20
+ ...styleProps
21
+ } = $props();
22
+ let groups = $derived(
23
+ z || fill || stroke ? Object.values(groupBy(data, (d) => resolveChannel("z", d, z || fill || stroke))) : [data]
24
+ );
25
+ let sortedGroups = $derived(
26
+ sort ? groups.sort(
27
+ (a, b) => resolveChannel("sort", a[0], sort) > resolveChannel("sort", b[0], sort) ? 1 : -1
28
+ ) : groups
29
+ );
30
+ let areaPath = $derived(
31
+ callWithProps(
32
+ area,
33
+ [],
34
+ x1 != null && x2 != null ? {
35
+ // vertical area
36
+ x0: (d) => plot.xScale(resolveChannel("x", d, x1)),
37
+ x1: (d) => plot.xScale(resolveChannel("x", d, x2)),
38
+ y: (d) => plot.yScale(resolveChannel("y", d, y1))
39
+ } : {
40
+ // horizontal area
41
+ x: (d) => plot.xScale(resolveChannel("x", d, x1)),
42
+ y0: (d) => plot.yScale(resolveChannel("y", d, y1)),
43
+ y1: (d) => plot.yScale(resolveChannel("y", d, y2))
44
+ }
45
+ )
46
+ );
47
+ </script>
48
+
49
+ <BaseMark_Area
50
+ type="area"
51
+ {data}
52
+ channels={['x', 'y', 'color']}
53
+ {x1}
54
+ {x2}
55
+ {y1}
56
+ {y2}
57
+ {fill}
58
+ {stroke}
59
+ {...styleProps}
60
+ >
61
+ <g class="areas">
62
+ {#each sortedGroups as areaData}
63
+ <path
64
+ d={areaPath(areaData)}
65
+ style:stroke={stroke
66
+ ? plot.colorScale(resolveChannel('color', areaData[0], stroke))
67
+ : 'none'}
68
+ style:fill={fill
69
+ ? plot.colorScale(resolveChannel('color', areaData[0], fill))
70
+ : 'currentColor'}
71
+ style={getBaseStyles(areaData[0], styleProps)}
72
+ />
73
+ {/each}
74
+ </g>
75
+ </BaseMark_Area>
76
+
77
+ <style>
78
+ .lines path {
79
+ stroke-width: 1.4px;
80
+ }
81
+ </style>
@@ -0,0 +1,15 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import type { AreaMarkProps } from '../types.js';
3
+ declare const __propDef: {
4
+ props: AreaMarkProps;
5
+ events: {
6
+ [evt: string]: CustomEvent<any>;
7
+ };
8
+ slots: {};
9
+ };
10
+ export type AreaProps = typeof __propDef.props;
11
+ export type AreaEvents = typeof __propDef.events;
12
+ export type AreaSlots = typeof __propDef.slots;
13
+ export default class Area extends SvelteComponent<AreaProps, AreaEvents, AreaSlots> {
14
+ }
15
+ export {};
@@ -0,0 +1,19 @@
1
+ <script>import isDataRecord from "../helpers/isDataRecord.js";
2
+ import Area from "./Area.svelte";
3
+ let { data, x, x1, x2, y, ...rest } = $props();
4
+ let dataIsRawValueArray = $derived(!isDataRecord(data[0]));
5
+ let transformedData = $derived(dataIsRawValueArray ? data.map((value, index) => ({ value, index, ___orig___: value })) : data);
6
+ $inspect({
7
+ y1: dataIsRawValueArray ? "index" : y,
8
+ x1: dataIsRawValueArray ? 0 : x ? 0 : x1,
9
+ x2: dataIsRawValueArray ? "value" : x ? x : x2
10
+ });
11
+ </script>
12
+
13
+ <Area
14
+ data={transformedData}
15
+ y1={dataIsRawValueArray ? 'index' : y}
16
+ x1={dataIsRawValueArray ? 0 : x ? 0 : x1}
17
+ x2={dataIsRawValueArray ? 'value' : x ? x : x2}
18
+ {...rest}
19
+ />
@@ -0,0 +1,17 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import type { RawValue } from '../types.js';
3
+ declare const __propDef: {
4
+ props: {
5
+ data: RawValue[];
6
+ };
7
+ events: {
8
+ [evt: string]: CustomEvent<any>;
9
+ };
10
+ slots: {};
11
+ };
12
+ export type AreaXProps = typeof __propDef.props;
13
+ export type AreaXEvents = typeof __propDef.events;
14
+ export type AreaXSlots = typeof __propDef.slots;
15
+ export default class AreaX extends SvelteComponent<AreaXProps, AreaXEvents, AreaXSlots> {
16
+ }
17
+ export {};
@@ -0,0 +1,14 @@
1
+ <script>import isDataRecord from "../helpers/isDataRecord.js";
2
+ import Area from "./Area.svelte";
3
+ let { data, x, y, y1, y2, ...rest } = $props();
4
+ let dataIsRawValueArray = $derived(!isDataRecord(data[0]));
5
+ let transformedData = $derived(dataIsRawValueArray ? data.map((value, index) => ({ value, index, ___orig___: value })) : data);
6
+ </script>
7
+
8
+ <Area
9
+ data={transformedData}
10
+ x1={dataIsRawValueArray ? 'index' : x}
11
+ y1={dataIsRawValueArray ? 0 : y ? 0 : y1}
12
+ y2={dataIsRawValueArray ? 'value' : y ? y : y2}
13
+ {...rest}
14
+ />
@@ -0,0 +1,17 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import type { RawValue } from '../types.js';
3
+ declare const __propDef: {
4
+ props: {
5
+ data: RawValue[];
6
+ };
7
+ events: {
8
+ [evt: string]: CustomEvent<any>;
9
+ };
10
+ slots: {};
11
+ };
12
+ export type AreaYProps = typeof __propDef.props;
13
+ export type AreaYEvents = typeof __propDef.events;
14
+ export type AreaYSlots = typeof __propDef.slots;
15
+ export default class AreaY extends SvelteComponent<AreaYProps, AreaYEvents, AreaYSlots> {
16
+ }
17
+ export {};
@@ -0,0 +1,102 @@
1
+ <script>import { getContext } from "svelte";
2
+ import dayjs from "dayjs";
3
+ import BaseMark from "./BaseMark.svelte";
4
+ import getBaseStyles from "../helpers/getBaseStyles.js";
5
+ import removeIdenticalLines from "../helpers/removeIdenticalLines.js";
6
+ import autoTimeFormat from "../helpers/autoTimeFormat.js";
7
+ const BaseMark_AxisX = BaseMark;
8
+ const plot = getContext("svelteplot");
9
+ let {
10
+ ticks = [],
11
+ anchor = "bottom",
12
+ tickSize = 6,
13
+ tickPadding = 3,
14
+ tickFormat = null,
15
+ automatic = false,
16
+ title = null,
17
+ tickFontSize = null,
18
+ fill = null,
19
+ ...styleProps
20
+ } = $props();
21
+ let autoTickCount = $derived(
22
+ Math.max(2, Math.round(plot.plotWidth / (plot.options?.x?.tickSpacing || 80)))
23
+ );
24
+ $inspect(autoTickCount);
25
+ let autoTicks = $derived(
26
+ ticks.length > 0 ? ticks : plot.options?.x?.ticks ?? plot.xScale.ticks(autoTickCount)
27
+ );
28
+ let useTickFormat = $derived(
29
+ typeof tickFormat === "function" ? tickFormat : plot.x.scaleType === "time" ? typeof tickFormat === "string" ? (d) => dayjs(d).format(tickFormat).split("\n") : autoTimeFormat(plot.x, plot.plotWidth) : (d) => String(d)
30
+ );
31
+ let tickTexts = $derived(
32
+ removeIdenticalLines(
33
+ autoTicks.map(useTickFormat).map((tick) => Array.isArray(tick) ? tick : [tick])
34
+ )
35
+ );
36
+ let optionsLabel = $derived(plot.options?.x?.label);
37
+ let useTitle = $derived(
38
+ title || (optionsLabel === null ? null : optionsLabel !== void 0 ? optionsLabel : plot.x.autoTitle ? plot.options.x?.reverse ? `\u2190 ${plot.x.autoTitle}` : `${plot.x.autoTitle} \u2192` : "")
39
+ );
40
+ </script>
41
+
42
+ <BaseMark_AxisX type="axis-x" data={ticks} channels={['x']} {automatic}>
43
+ <g class="axis-x">
44
+ {#if useTitle}
45
+ <text
46
+ x={plot.plotWidth + plot.margins.left}
47
+ y={plot.height - 10}
48
+ class="axis-title"
49
+ dominant-baseline="hanging">{useTitle}</text
50
+ >
51
+ {/if}
52
+ {#each autoTicks as tick, t}
53
+ {@const textLines = tickTexts[t]}
54
+ {@const prevTextLines = t && tickTexts[t - 1]}
55
+ <g
56
+ class="x-tick"
57
+ transform="translate({plot.xScale(tick)},{anchor === 'bottom'
58
+ ? plot.margins.top + plot.plotHeight
59
+ : plot.margins.top})"
60
+ >
61
+ <text
62
+ style={getBaseStyles(tick, { fill, fontSize: tickFontSize })}
63
+ y={(tickSize + tickPadding) * (anchor === 'bottom' ? 1 : -1)}
64
+ dominant-baseline={anchor === 'bottom' ? 'hanging' : 'auto'}
65
+ >
66
+ {#if typeof textLines === 'string' || textLines.length === 1}
67
+ {textLines}
68
+ {:else}
69
+ {#each textLines as line, i}
70
+ <tspan x="0" dy={i ? 12 : 0}
71
+ >{!prevTextLines || prevTextLines[i] !== line ? line : ''}</tspan
72
+ >
73
+ {/each}
74
+ {/if}
75
+ </text>
76
+ <line
77
+ style={getBaseStyles(tick, styleProps)}
78
+ y2={anchor === 'bottom' ? tickSize : -tickSize}
79
+ />
80
+ </g>
81
+ {/each}
82
+ </g>
83
+ </BaseMark_AxisX>
84
+
85
+ <style>
86
+ text {
87
+ text-anchor: middle;
88
+ font-size: 11px;
89
+
90
+ fill: #4a4a4a;
91
+ }
92
+
93
+ text.axis-title {
94
+ text-anchor: end;
95
+ }
96
+ .x-tick line {
97
+ stroke: currentColor;
98
+ }
99
+ .x-tick line.grid {
100
+ stroke: #d9d9d9;
101
+ }
102
+ </style>
@@ -0,0 +1,17 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import type { AxisMarkOptions } from '../types.js';
3
+ declare const __propDef: {
4
+ props: AxisMarkOptions & {
5
+ anchor?: "bottom" | "top" | undefined;
6
+ };
7
+ events: {
8
+ [evt: string]: CustomEvent<any>;
9
+ };
10
+ slots: {};
11
+ };
12
+ export type AxisXProps = typeof __propDef.props;
13
+ export type AxisXEvents = typeof __propDef.events;
14
+ export type AxisXSlots = typeof __propDef.slots;
15
+ export default class AxisX extends SvelteComponent<AxisXProps, AxisXEvents, AxisXSlots> {
16
+ }
17
+ export {};
@@ -0,0 +1,80 @@
1
+ <script>import { getContext } from "svelte";
2
+ import { get } from "underscore";
3
+ import BaseMark from "./BaseMark.svelte";
4
+ import getBaseStyles from "../helpers/getBaseStyles.js";
5
+ import autoTimeFormat from "../helpers/autoTimeFormat.js";
6
+ const BaseMark_AxisX = BaseMark;
7
+ const plot = getContext("svelteplot");
8
+ let {
9
+ ticks = [],
10
+ anchor = "left",
11
+ automatic = false,
12
+ tickSize = 6,
13
+ tickPadding = 3,
14
+ title = null,
15
+ tickFormat,
16
+ tickFontSize = null,
17
+ fill = null,
18
+ ...styleProps
19
+ } = $props();
20
+ let autoTickCount = $derived(plot.plotHeight / get(plot, "options.y.tickSpacing", 80));
21
+ let autoTicks = $derived(
22
+ ticks.length > 0 ? ticks : get(plot, "options.y.ticks", plot.yScale.ticks(autoTickCount))
23
+ );
24
+ let useTickFormat = $derived(
25
+ typeof tickFormat === "function" ? tickFormat : plot.y.scaleType === "time" ? typeof tickFormat === "string" ? (d) => dayjs(d).format(tickFormat).split("\n") : autoTimeFormat(plot.y, plot.plotHeight) : (d) => String(d) + "x"
26
+ );
27
+ let optionsLabel = $derived(plot.options.y?.label);
28
+ let useTitle = $derived(
29
+ title || (optionsLabel === null ? null : optionsLabel !== void 0 ? optionsLabel : `\u2191 ${plot.y.autoTitle}`)
30
+ );
31
+ </script>
32
+
33
+ <BaseMark_AxisX type="axis-y" data={ticks} channels={['y']} {automatic}>
34
+ <g class="axis-y">
35
+ {#if useTitle}
36
+ <text
37
+ style:text-anchor={anchor === 'left' ? 'start' : 'end'}
38
+ x={anchor === 'left' ? 0 : plot.width}
39
+ y={5}
40
+ class="axis-title"
41
+ dominant-baseline="hanging">{useTitle}</text
42
+ >
43
+ {/if}
44
+ {#each autoTicks as tick}
45
+ {@const tickText = useTickFormat(tick)}
46
+ <g
47
+ class="y-tick"
48
+ transform="translate({plot.margins.left +
49
+ (anchor === 'left' ? 0 : plot.plotWidth)},{plot.yScale(tick)})"
50
+ >
51
+ <text
52
+ class:is-left={anchor === 'left'}
53
+ style={getBaseStyles(tick, { fill, fontSize: tickFontSize })}
54
+ x={(tickSize + tickPadding) * (anchor === 'left' ? -1 : 1)}
55
+ dominant-baseline="middle">{Array.isArray(tickText) ? tickText.join(' ') : tickText}</text
56
+ >
57
+ <line
58
+ style={getBaseStyles(tick, styleProps)}
59
+ x2={anchor === 'left' ? -tickSize : tickSize}
60
+ />
61
+ </g>
62
+ {/each}
63
+ </g>
64
+ </BaseMark_AxisX>
65
+
66
+ <style>
67
+ text {
68
+ font-size: 11px;
69
+ fill: #4a4a4a;
70
+ }
71
+ text.is-left {
72
+ text-anchor: end;
73
+ }
74
+ text.axis-title {
75
+ text-anchor: start;
76
+ }
77
+ .y-tick line {
78
+ stroke: currentColor;
79
+ }
80
+ </style>
@@ -0,0 +1,15 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import type { AxisYMarkProps } from '../types.js';
3
+ declare const __propDef: {
4
+ props: AxisYMarkProps;
5
+ events: {
6
+ [evt: string]: CustomEvent<any>;
7
+ };
8
+ slots: {};
9
+ };
10
+ export type AxisYProps = typeof __propDef.props;
11
+ export type AxisYEvents = typeof __propDef.events;
12
+ export type AxisYSlots = typeof __propDef.slots;
13
+ export default class AxisY extends SvelteComponent<AxisYProps, AxisYEvents, AxisYSlots> {
14
+ }
15
+ export {};
@@ -0,0 +1,22 @@
1
+ <script context="module"></script>
2
+
3
+ <script generics="T extends BaseMarkProps">import { Mark } from "../classes/Mark.svelte";
4
+ import { getContext } from "svelte";
5
+ const plot = getContext("svelteplot");
6
+ let { type, data = [], channels = [], children, automatic, ...rest } = $props();
7
+ const mark = new Mark(type, channels, automatic, { data, ...rest });
8
+ plot.addMark(mark);
9
+ $effect(() => {
10
+ mark.channels = new Set(channels);
11
+ });
12
+ $effect(() => {
13
+ mark.props = { data, ...rest };
14
+ });
15
+ $effect(() => {
16
+ return () => {
17
+ plot.removeMark(mark);
18
+ };
19
+ });
20
+ </script>
21
+
22
+ <slot />
@@ -0,0 +1,19 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import type { BaseMarkProps } from '../types.js';
3
+ declare class __sveltets_Render<T extends BaseMarkProps> {
4
+ props(): T & {
5
+ children?: Function | undefined;
6
+ };
7
+ events(): {} & {
8
+ [evt: string]: CustomEvent<any>;
9
+ };
10
+ slots(): {
11
+ default: {};
12
+ };
13
+ }
14
+ export type BaseMarkProps<T extends BaseMarkProps> = ReturnType<__sveltets_Render<T>['props']>;
15
+ export type BaseMarkEvents<T extends BaseMarkProps> = ReturnType<__sveltets_Render<T>['events']>;
16
+ 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
+ }
19
+ export {};
@@ -0,0 +1,54 @@
1
+ <script>import { getContext } from "svelte";
2
+ import { symbol as d3Symbol } from "d3-shape";
3
+ import { maybeSymbol } from "../helpers/symbols.js";
4
+ const plot = getContext("svelteplot");
5
+ </script>
6
+
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
+ >
26
+ </div>
27
+ <span class="item-label">{value}</span>
28
+ </div>
29
+ {/each}
30
+ </div>
31
+ {/if}
32
+
33
+ <style>
34
+ .color-legend {
35
+ text-align: left;
36
+ font-size: 12px;
37
+ display: inline-block;
38
+ margin-right: 2em;
39
+ }
40
+ .item {
41
+ margin: 0 1em 0.5ex 0;
42
+ }
43
+ path {
44
+ stroke-width: 1.5;
45
+ }
46
+ .item,
47
+ .item-label,
48
+ .swatch {
49
+ display: inline-block;
50
+ }
51
+ .item-label {
52
+ vertical-align: text-bottom;
53
+ }
54
+ </style>
@@ -0,0 +1,14 @@
1
+ import { SvelteComponent } from "svelte";
2
+ declare const __propDef: {
3
+ props: Record<string, never>;
4
+ events: {
5
+ [evt: string]: CustomEvent<any>;
6
+ };
7
+ slots: {};
8
+ };
9
+ export type ColorLegendProps = typeof __propDef.props;
10
+ export type ColorLegendEvents = typeof __propDef.events;
11
+ export type ColorLegendSlots = typeof __propDef.slots;
12
+ export default class ColorLegend extends SvelteComponent<ColorLegendProps, ColorLegendEvents, ColorLegendSlots> {
13
+ }
14
+ export {};
@@ -0,0 +1,82 @@
1
+ <script>import { getContext } from "svelte";
2
+ import { symbol as d3Symbol } from "d3-shape";
3
+ import BaseMark from "./BaseMark.svelte";
4
+ import resolveChannel from "../helpers/resolveChannel.js";
5
+ import getBaseStyles from "../helpers/getBaseStyles.js";
6
+ import { isSymbol, maybeSymbol } from "../helpers/symbols.js";
7
+ const BaseMark_Dot = BaseMark;
8
+ const plot = getContext("svelteplot");
9
+ let {
10
+ data,
11
+ x = null,
12
+ y = null,
13
+ r = 3,
14
+ symbol = "circle",
15
+ stroke = null,
16
+ fill = null,
17
+ ...styleProps
18
+ } = $props();
19
+ let styleProps2 = $derived({
20
+ ...styleProps,
21
+ ...!styleProps.fill && !styleProps.stroke ? { stroke: "currentColor" } : {}
22
+ });
23
+ function isValid(value) {
24
+ return value !== null && !Number.isNaN(value);
25
+ }
26
+ </script>
27
+
28
+ <BaseMark_Dot
29
+ type="dot"
30
+ {data}
31
+ channels={[
32
+ ...(x ? ['x'] : []),
33
+ ...(y ? ['y'] : []),
34
+ ...(r ? ['radius'] : []),
35
+ ...(symbol ? ['symbol'] : []),
36
+ ...(fill || stroke ? ['color'] : [])
37
+ ]}
38
+ {x}
39
+ {y}
40
+ {r}
41
+ {fill}
42
+ {stroke}
43
+ {symbol}
44
+ {...styleProps}
45
+ >
46
+ <g class="dots">
47
+ {#each data as datum, i}
48
+ {@const cx = resolveChannel('x', datum, x)}
49
+ {@const cy = resolveChannel('y', datum, y)}
50
+ {@const symbolT = resolveChannel('symbol', datum, symbol)}
51
+ {@const symbolType = isSymbol(symbolT)
52
+ ? maybeSymbol(symbolT)
53
+ : maybeSymbol(plot.symbolScale(symbolT))}
54
+ {@const radius =
55
+ typeof r === 'number' ? r : plot.radiusScale(resolveChannel('radius', datum, r))}
56
+ {@const size = radius * radius * Math.PI}
57
+ {@const maybeFillColor = resolveChannel('color', datum, fill)}
58
+ {@const maybeStrokeColor = resolveChannel('color', datum, stroke)}
59
+ {#if isValid(cx) && isValid(cy)}
60
+ <path
61
+ d={d3Symbol(symbolType, size)()}
62
+ style={getBaseStyles(datum, styleProps)}
63
+ style:fill={maybeFillColor ? plot.colorScale(maybeFillColor) : null}
64
+ style:stroke={maybeStrokeColor
65
+ ? plot.colorScale(maybeStrokeColor)
66
+ : maybeFillColor
67
+ ? null
68
+ : 'currentColor'}
69
+ transform="translate({[plot.xScale(cx), plot.yScale(cy)]})"
70
+ />
71
+ {/if}
72
+ {/each}
73
+ </g>
74
+ </BaseMark_Dot>
75
+
76
+ <style>
77
+ path {
78
+ fill: none;
79
+ stroke: none;
80
+ stroke-width: 1.6px;
81
+ }
82
+ </style>
@@ -0,0 +1,15 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import type { DotMarkProps } from '../types.js';
3
+ declare const __propDef: {
4
+ props: DotMarkProps;
5
+ events: {
6
+ [evt: string]: CustomEvent<any>;
7
+ };
8
+ slots: {};
9
+ };
10
+ export type DotProps = typeof __propDef.props;
11
+ export type DotEvents = typeof __propDef.events;
12
+ export type DotSlots = typeof __propDef.slots;
13
+ export default class Dot extends SvelteComponent<DotProps, DotEvents, DotSlots> {
14
+ }
15
+ export {};
@@ -0,0 +1,5 @@
1
+ <script>import Dot from "./Dot.svelte";
2
+ let { data, ...rest } = $props();
3
+ </script>
4
+
5
+ <Dot {data} x={(d) => d} y={0} {...rest} />
@@ -0,0 +1,17 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import type { RawValue } from '../types.js';
3
+ declare const __propDef: {
4
+ props: {
5
+ data: RawValue[];
6
+ };
7
+ events: {
8
+ [evt: string]: CustomEvent<any>;
9
+ };
10
+ slots: {};
11
+ };
12
+ export type DotXProps = typeof __propDef.props;
13
+ export type DotXEvents = typeof __propDef.events;
14
+ export type DotXSlots = typeof __propDef.slots;
15
+ export default class DotX extends SvelteComponent<DotXProps, DotXEvents, DotXSlots> {
16
+ }
17
+ export {};
@@ -0,0 +1,5 @@
1
+ <script>import Dot from "./Dot.svelte";
2
+ let { data, ...rest } = $props();
3
+ </script>
4
+
5
+ <Dot {data} y={(d) => d} x={0} {...rest} />
@@ -0,0 +1,17 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import type { RawValue } from '../types.js';
3
+ declare const __propDef: {
4
+ props: {
5
+ data: RawValue[];
6
+ };
7
+ events: {
8
+ [evt: string]: CustomEvent<any>;
9
+ };
10
+ slots: {};
11
+ };
12
+ export type DotYProps = typeof __propDef.props;
13
+ export type DotYEvents = typeof __propDef.events;
14
+ export type DotYSlots = typeof __propDef.slots;
15
+ export default class DotY extends SvelteComponent<DotYProps, DotYEvents, DotYSlots> {
16
+ }
17
+ export {};