svelteplot 0.0.1-alpha.9 → 0.1.3-next.12

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 (251) hide show
  1. package/LICENSE.md +5 -0
  2. package/README.md +3 -35
  3. package/dist/Mark.svelte +292 -0
  4. package/dist/Mark.svelte.d.ts +22 -0
  5. package/dist/Plot.svelte +148 -156
  6. package/dist/Plot.svelte.d.ts +15 -15
  7. package/dist/constants.d.ts +15 -0
  8. package/dist/constants.js +110 -0
  9. package/dist/core/Facet.svelte +59 -0
  10. package/dist/core/Facet.svelte.d.ts +18 -0
  11. package/dist/core/FacetAxes.svelte +66 -0
  12. package/dist/core/FacetAxes.svelte.d.ts +4 -0
  13. package/dist/core/FacetGrid.svelte +86 -0
  14. package/dist/core/FacetGrid.svelte.d.ts +13 -0
  15. package/dist/core/Plot.svelte +568 -0
  16. package/dist/core/Plot.svelte.d.ts +14 -0
  17. package/dist/helpers/arrowPath.d.ts +14 -0
  18. package/dist/helpers/arrowPath.js +129 -0
  19. package/dist/helpers/autoProjection.d.ts +19 -0
  20. package/dist/helpers/autoProjection.js +87 -0
  21. package/dist/helpers/autoScales.d.ts +23 -0
  22. package/dist/helpers/autoScales.js +203 -0
  23. package/dist/helpers/autoTicks.d.ts +3 -0
  24. package/dist/helpers/autoTicks.js +40 -0
  25. package/dist/helpers/autoTimeFormat.d.ts +2 -2
  26. package/dist/helpers/autoTimeFormat.js +34 -5
  27. package/dist/helpers/callWithProps.d.ts +8 -0
  28. package/dist/helpers/callWithProps.js +13 -0
  29. package/dist/helpers/colors.js +17 -2
  30. package/dist/helpers/curves.d.ts +3 -0
  31. package/dist/helpers/curves.js +42 -0
  32. package/dist/helpers/data.d.ts +9 -0
  33. package/dist/helpers/data.js +16 -0
  34. package/dist/helpers/facets.d.ts +12 -0
  35. package/dist/helpers/facets.js +49 -0
  36. package/dist/helpers/formats.d.ts +3 -0
  37. package/dist/helpers/formats.js +3 -0
  38. package/dist/helpers/getBaseStyles.d.ts +7 -2
  39. package/dist/helpers/getBaseStyles.js +34 -10
  40. package/dist/helpers/getLogTicks.js +5 -5
  41. package/dist/helpers/group.d.ts +6 -0
  42. package/dist/helpers/group.js +53 -0
  43. package/dist/helpers/index.d.ts +18 -0
  44. package/dist/helpers/index.js +55 -0
  45. package/dist/helpers/isRawValue.d.ts +2 -0
  46. package/dist/helpers/isRawValue.js +5 -0
  47. package/dist/helpers/isValid.d.ts +6 -0
  48. package/dist/helpers/isValid.js +6 -0
  49. package/dist/helpers/math.d.ts +19 -0
  50. package/dist/helpers/math.js +116 -0
  51. package/dist/helpers/mergeDeep.d.ts +1 -1
  52. package/dist/helpers/noise.d.ts +1 -0
  53. package/dist/helpers/noise.js +72 -0
  54. package/dist/helpers/projection.d.ts +33 -0
  55. package/dist/helpers/projection.js +100 -0
  56. package/dist/helpers/reduce.d.ts +10 -0
  57. package/dist/helpers/reduce.js +85 -0
  58. package/dist/helpers/regressionLoess.d.ts +12 -0
  59. package/dist/helpers/regressionLoess.js +47 -0
  60. package/dist/helpers/removeIdenticalLines.d.ts +8 -1
  61. package/dist/helpers/removeIdenticalLines.js +14 -7
  62. package/dist/helpers/resolve.d.ts +21 -0
  63. package/dist/helpers/resolve.js +156 -0
  64. package/dist/helpers/roundedRect.d.ts +9 -0
  65. package/dist/helpers/roundedRect.js +31 -0
  66. package/dist/helpers/scales.d.ts +42 -0
  67. package/dist/helpers/scales.js +311 -0
  68. package/dist/helpers/time.d.ts +6 -0
  69. package/dist/helpers/time.js +282 -0
  70. package/dist/helpers/typeChecks.d.ts +8 -5
  71. package/dist/helpers/typeChecks.js +27 -6
  72. package/dist/index.d.ts +49 -1
  73. package/dist/index.js +53 -2
  74. package/dist/marks/Area.svelte +146 -0
  75. package/dist/marks/Area.svelte.d.ts +30 -0
  76. package/dist/marks/AreaX.svelte +27 -0
  77. package/dist/marks/AreaX.svelte.d.ts +12 -0
  78. package/dist/marks/AreaY.svelte +38 -0
  79. package/dist/marks/AreaY.svelte.d.ts +19 -0
  80. package/dist/marks/Arrow.svelte +139 -0
  81. package/dist/marks/Arrow.svelte.d.ts +44 -0
  82. package/dist/marks/AxisX.svelte +198 -93
  83. package/dist/marks/AxisX.svelte.d.ts +17 -16
  84. package/dist/marks/AxisY.svelte +176 -62
  85. package/dist/marks/AxisY.svelte.d.ts +17 -14
  86. package/dist/marks/BarX.svelte +93 -0
  87. package/dist/marks/BarX.svelte.d.ts +4 -0
  88. package/dist/marks/BarY.svelte +103 -0
  89. package/dist/marks/BarY.svelte.d.ts +25 -0
  90. package/dist/marks/BollingerX.svelte +44 -0
  91. package/dist/marks/BollingerX.svelte.d.ts +18 -0
  92. package/dist/marks/BollingerY.svelte +39 -0
  93. package/dist/marks/BollingerY.svelte.d.ts +18 -0
  94. package/dist/marks/BoxX.svelte +89 -0
  95. package/dist/marks/BoxX.svelte.d.ts +4 -0
  96. package/dist/marks/BoxY.svelte +110 -0
  97. package/dist/marks/BoxY.svelte.d.ts +29 -0
  98. package/dist/marks/Cell.svelte +110 -0
  99. package/dist/marks/Cell.svelte.d.ts +16 -0
  100. package/dist/marks/CellX.svelte +24 -0
  101. package/dist/marks/CellX.svelte.d.ts +3 -0
  102. package/dist/marks/CellY.svelte +24 -0
  103. package/dist/marks/CellY.svelte.d.ts +3 -0
  104. package/dist/marks/ColorLegend.svelte +148 -27
  105. package/dist/marks/ColorLegend.svelte.d.ts +12 -13
  106. package/dist/marks/CustomMark.svelte +43 -0
  107. package/dist/marks/CustomMark.svelte.d.ts +16 -0
  108. package/dist/marks/CustomMarkHTML.svelte +103 -0
  109. package/dist/marks/CustomMarkHTML.svelte.d.ts +17 -0
  110. package/dist/marks/DifferenceY.svelte +144 -0
  111. package/dist/marks/DifferenceY.svelte.d.ts +30 -0
  112. package/dist/marks/Dot.svelte +128 -73
  113. package/dist/marks/Dot.svelte.d.ts +24 -14
  114. package/dist/marks/DotX.svelte +15 -3
  115. package/dist/marks/DotX.svelte.d.ts +8 -16
  116. package/dist/marks/DotY.svelte +8 -3
  117. package/dist/marks/DotY.svelte.d.ts +5 -17
  118. package/dist/marks/Frame.svelte +39 -31
  119. package/dist/marks/Frame.svelte.d.ts +7 -14
  120. package/dist/marks/Geo.svelte +102 -0
  121. package/dist/marks/Geo.svelte.d.ts +10 -0
  122. package/dist/marks/Graticule.svelte +28 -0
  123. package/dist/marks/Graticule.svelte.d.ts +9 -0
  124. package/dist/marks/GridX.svelte +67 -36
  125. package/dist/marks/GridX.svelte.d.ts +7 -18
  126. package/dist/marks/GridY.svelte +64 -25
  127. package/dist/marks/GridY.svelte.d.ts +7 -14
  128. package/dist/marks/HTMLTooltip.svelte +91 -0
  129. package/dist/marks/HTMLTooltip.svelte.d.ts +11 -0
  130. package/dist/marks/Line.svelte +219 -58
  131. package/dist/marks/Line.svelte.d.ts +30 -14
  132. package/dist/marks/LineX.svelte +8 -8
  133. package/dist/marks/LineX.svelte.d.ts +4 -17
  134. package/dist/marks/LineY.svelte +7 -8
  135. package/dist/marks/LineY.svelte.d.ts +4 -17
  136. package/dist/marks/Link.svelte +180 -0
  137. package/dist/marks/Link.svelte.d.ts +21 -0
  138. package/dist/marks/Pointer.svelte +126 -0
  139. package/dist/marks/Pointer.svelte.d.ts +23 -0
  140. package/dist/marks/Rect.svelte +103 -0
  141. package/dist/marks/Rect.svelte.d.ts +15 -0
  142. package/dist/marks/RectX.svelte +33 -0
  143. package/dist/marks/RectX.svelte.d.ts +15 -0
  144. package/dist/marks/RectY.svelte +33 -0
  145. package/dist/marks/RectY.svelte.d.ts +15 -0
  146. package/dist/marks/RegressionX.svelte +26 -0
  147. package/dist/marks/RegressionX.svelte.d.ts +4 -0
  148. package/dist/marks/RegressionY.svelte +26 -0
  149. package/dist/marks/RegressionY.svelte.d.ts +4 -0
  150. package/dist/marks/RuleX.svelte +52 -28
  151. package/dist/marks/RuleX.svelte.d.ts +14 -14
  152. package/dist/marks/RuleY.svelte +52 -28
  153. package/dist/marks/RuleY.svelte.d.ts +14 -14
  154. package/dist/marks/Sphere.svelte +8 -0
  155. package/dist/marks/Sphere.svelte.d.ts +51 -0
  156. package/dist/marks/Spike.svelte +15 -0
  157. package/dist/marks/Spike.svelte.d.ts +4 -0
  158. package/dist/marks/SymbolLegend.svelte +27 -12
  159. package/dist/marks/SymbolLegend.svelte.d.ts +8 -14
  160. package/dist/marks/Text.svelte +189 -0
  161. package/dist/marks/Text.svelte.d.ts +26 -0
  162. package/dist/marks/TickX.svelte +89 -0
  163. package/dist/marks/TickX.svelte.d.ts +22 -0
  164. package/dist/marks/TickY.svelte +90 -0
  165. package/dist/marks/TickY.svelte.d.ts +22 -0
  166. package/dist/marks/Vector.svelte +219 -0
  167. package/dist/marks/Vector.svelte.d.ts +31 -0
  168. package/dist/marks/helpers/BaseAxisX.svelte +210 -0
  169. package/dist/marks/helpers/BaseAxisX.svelte.d.ts +24 -0
  170. package/dist/marks/helpers/BaseAxisY.svelte +187 -0
  171. package/dist/marks/helpers/BaseAxisY.svelte.d.ts +23 -0
  172. package/dist/marks/helpers/CanvasLayer.svelte +38 -0
  173. package/dist/marks/helpers/CanvasLayer.svelte.d.ts +13 -0
  174. package/dist/marks/helpers/DotCanvas.svelte +184 -0
  175. package/dist/marks/helpers/DotCanvas.svelte.d.ts +11 -0
  176. package/dist/marks/helpers/GeoCanvas.svelte +165 -0
  177. package/dist/marks/helpers/GeoCanvas.svelte.d.ts +13 -0
  178. package/dist/marks/helpers/GroupMultiple.svelte +17 -0
  179. package/dist/marks/helpers/GroupMultiple.svelte.d.ts +9 -0
  180. package/dist/marks/helpers/Marker.svelte +93 -0
  181. package/dist/marks/helpers/Marker.svelte.d.ts +10 -0
  182. package/dist/marks/helpers/MarkerPath.svelte +141 -0
  183. package/dist/marks/helpers/MarkerPath.svelte.d.ts +44 -0
  184. package/dist/marks/helpers/Regression.svelte +174 -0
  185. package/dist/marks/helpers/Regression.svelte.d.ts +26 -0
  186. package/dist/marks/helpers/events.d.ts +8 -0
  187. package/dist/marks/helpers/events.js +74 -0
  188. package/dist/transforms/bin.d.ts +51 -0
  189. package/dist/transforms/bin.js +171 -0
  190. package/dist/transforms/bollinger.d.ts +21 -0
  191. package/dist/transforms/bollinger.js +53 -0
  192. package/dist/transforms/centroid.d.ts +9 -0
  193. package/dist/transforms/centroid.js +13 -0
  194. package/dist/transforms/facet.d.ts +1 -0
  195. package/dist/transforms/facet.js +1 -0
  196. package/dist/transforms/filter.d.ts +2 -0
  197. package/dist/transforms/filter.js +8 -0
  198. package/dist/transforms/group.d.ts +66 -0
  199. package/dist/transforms/group.js +109 -0
  200. package/dist/transforms/interval.d.ts +11 -0
  201. package/dist/transforms/interval.js +34 -0
  202. package/dist/transforms/jitter.d.ts +1 -0
  203. package/dist/transforms/jitter.js +1 -0
  204. package/dist/transforms/map.d.ts +10 -0
  205. package/dist/transforms/map.js +89 -0
  206. package/dist/transforms/normalize.d.ts +9 -0
  207. package/dist/transforms/normalize.js +86 -0
  208. package/dist/transforms/recordize.d.ts +15 -0
  209. package/dist/transforms/recordize.js +78 -0
  210. package/dist/transforms/rename.d.ts +14 -0
  211. package/dist/transforms/rename.js +42 -0
  212. package/dist/transforms/select.d.ts +35 -0
  213. package/dist/transforms/select.js +55 -0
  214. package/dist/transforms/shift.d.ts +13 -0
  215. package/dist/transforms/shift.js +45 -0
  216. package/dist/transforms/sort.d.ts +28 -0
  217. package/dist/transforms/sort.js +66 -0
  218. package/dist/transforms/stack.d.ts +10 -0
  219. package/dist/transforms/stack.js +110 -0
  220. package/dist/transforms/window.d.ts +24 -0
  221. package/dist/transforms/window.js +73 -0
  222. package/dist/types.d.ts +625 -188
  223. package/dist/ui/Checkbox.svelte +6 -0
  224. package/dist/ui/Checkbox.svelte.d.ts +13 -0
  225. package/dist/ui/RadioInput.svelte +27 -0
  226. package/dist/ui/RadioInput.svelte.d.ts +9 -0
  227. package/dist/ui/Select.svelte +27 -0
  228. package/dist/ui/Select.svelte.d.ts +9 -0
  229. package/dist/ui/Slider.svelte +47 -0
  230. package/dist/ui/Slider.svelte.d.ts +11 -0
  231. package/dist/ui/Spiral.svelte +46 -0
  232. package/dist/ui/Spiral.svelte.d.ts +15 -0
  233. package/dist/ui/index.d.ts +4 -0
  234. package/dist/ui/index.js +4 -0
  235. package/package.json +81 -42
  236. package/LICENSE +0 -11
  237. package/dist/classes/Channel.svelte.js +0 -74
  238. package/dist/classes/Mark.svelte.js +0 -17
  239. package/dist/classes/Plot.svelte.js +0 -98
  240. package/dist/contants.d.ts +0 -3
  241. package/dist/contants.js +0 -40
  242. package/dist/helpers/GroupMultiple.svelte +0 -8
  243. package/dist/helpers/GroupMultiple.svelte.d.ts +0 -19
  244. package/dist/helpers/createScale.d.ts +0 -5
  245. package/dist/helpers/createScale.js +0 -57
  246. package/dist/helpers/resolveChannel.d.ts +0 -2
  247. package/dist/helpers/resolveChannel.js +0 -28
  248. package/dist/helpers/wrapArray.d.ts +0 -2
  249. package/dist/helpers/wrapArray.js +0 -4
  250. package/dist/marks/BaseMark.svelte +0 -22
  251. package/dist/marks/BaseMark.svelte.d.ts +0 -19
@@ -0,0 +1,144 @@
1
+ <script lang="ts">
2
+ import type {
3
+ BaseMarkProps,
4
+ ChannelAccessor,
5
+ ConstantAccessor,
6
+ CurveName,
7
+ DataRecord,
8
+ PlotContext
9
+ } from '../types.js';
10
+ import { Line, Area } from '../index.js';
11
+ import { randomId, coalesce } from '../helpers/index.js';
12
+ import { getContext } from 'svelte';
13
+ import { extent, max, min } from 'd3-array';
14
+ import { resolveChannel } from '../helpers/resolve.js';
15
+ import type { CurveFactory } from 'd3-shape';
16
+
17
+ type DifferenceYMarkProps = {
18
+ data: DataRecord[];
19
+ /*
20
+ * the horizontal position of the comparison; bound to the x scale
21
+ */
22
+ x1: ChannelAccessor;
23
+ /**
24
+ * the horizontal position of the metric; bound to the x scale
25
+ */
26
+ x2: ChannelAccessor;
27
+ x: ChannelAccessor;
28
+ /**
29
+ * the vertical position of the comparison; bound to the y scale
30
+ */
31
+ y1: ChannelAccessor;
32
+ /**
33
+ * the vertical position of the metric; bound to the y scale
34
+ */
35
+ y2: ChannelAccessor;
36
+ y: ChannelAccessor;
37
+ positiveFill?: string;
38
+ positiveFillOpacity?: number;
39
+ negativeFill?: string;
40
+ negativeFillOpacity?: number;
41
+ stroke: boolean | ChannelAccessor;
42
+ curve?: CurveName | CurveFactory;
43
+ tension?: number;
44
+ } & BaseMarkProps;
45
+
46
+ const { getPlotState } = getContext<PlotContext>('svelteplot');
47
+ let plot = $derived(getPlotState());
48
+
49
+ let { data, stroke, class: className = null, ...options }: DifferenceYMarkProps = $props();
50
+ let { x, x1, x2, y, y1, y2 } = $derived(options);
51
+
52
+ const x1x2Differ = $derived((x1 == null || x2 == null) && x1 !== x2);
53
+
54
+ const xExtent = $derived(
55
+ x1x2Differ && x != null ? extent(data, (d) => resolveChannel('x', d, options)) : null
56
+ );
57
+ const x1Extent = $derived(
58
+ x1x2Differ && x1 != null ? extent(data, (d) => resolveChannel('x1', d, options)) : null
59
+ );
60
+ const x2Extent = $derived(
61
+ x1x2Differ && x2 != null ? extent(data, (d) => resolveChannel('x2', d, options)) : null
62
+ );
63
+
64
+ const maxMin = $derived(
65
+ max([xExtent, x1Extent, x2Extent].filter((d) => d != null).map((d) => d[0]))
66
+ );
67
+ const minMax = $derived(
68
+ min([xExtent, x1Extent, x2Extent].filter((d) => d != null).map((d) => d[1]))
69
+ );
70
+
71
+ const croppedX1 = $derived(
72
+ x1x2Differ
73
+ ? data.filter((d) => {
74
+ const x1val = resolveChannel(x1 != null ? 'x1' : 'x', d, options);
75
+ return x1val >= maxMin && x1val <= minMax;
76
+ })
77
+ : data
78
+ );
79
+
80
+ const croppedX2 = $derived(
81
+ x1x2Differ
82
+ ? data.filter((d) => {
83
+ const x2val = resolveChannel(x2 != null ? 'x2' : 'x', d, options);
84
+ return x2val >= maxMin && x2val <= minMax;
85
+ })
86
+ : data
87
+ );
88
+
89
+ const id = randomId();
90
+ </script>
91
+
92
+ <g class="positive difference {className || ''}">
93
+ <!-- pos clips goes from bottom of plot area to the line 2 -->
94
+ <clipPath id="pos-clip-{id}">
95
+ <Area
96
+ data={croppedX2}
97
+ {...options}
98
+ fill={options.positiveFill || 'red'}
99
+ x1={coalesce(x2, x)}
100
+ y1={coalesce(y2, y)}
101
+ y2={{ scale: null, value: plot.options.marginTop + plot.facetHeight }} />
102
+ </clipPath>
103
+ <!-- pos area goes from top to line 1 -->
104
+ <Area
105
+ clipPath="url(#pos-clip-{id})"
106
+ data={croppedX1}
107
+ {...options}
108
+ fill={options.positiveFill || 'pink'}
109
+ fillOpacity={coalesce(options.positiveFillOpacity, 1)}
110
+ x1={coalesce(x1, x2, x)}
111
+ y1={{ scale: null, value: 0 }}
112
+ y2={coalesce(y1, x1x2Differ ? coalesce(y2, y) : 0)} />
113
+ </g>
114
+ <g class="negative difference {className || ''}">
115
+ <!-- neg clips goes from bottom of plot area to the line 1 -->
116
+ <clipPath id="neg-clip-{id}">
117
+ <Area
118
+ data={croppedX1}
119
+ {...options}
120
+ fill={options.negativeFill || 'blue'}
121
+ x1={coalesce(x1, x2, x)}
122
+ y1={coalesce(y1, x1x2Differ ? coalesce(y2, y) : 0)}
123
+ y2={{ scale: null, value: plot.options.marginTop + plot.facetHeight }} />
124
+ </clipPath>
125
+ <!-- neg area goes from top to line 2 -->
126
+ <Area
127
+ clipPath="url(#neg-clip-{id})"
128
+ data={croppedX2}
129
+ {...options}
130
+ fill={options.negativeFill || 'cyan'}
131
+ fillOpacity={coalesce(options.negativeFillOpacity, 1)}
132
+ x1={coalesce(x2, x)}
133
+ y1={{ scale: null, value: 0 }}
134
+ y2={coalesce(y2, y)} />
135
+ </g>
136
+ {#if stroke != null}
137
+ <!-- set stroke to false to hide the line -->
138
+ <Line
139
+ data={croppedX2}
140
+ {...options}
141
+ stroke={stroke === true ? 'currentColor' : stroke}
142
+ x={coalesce(x2, x)}
143
+ y={coalesce(y2, y)} />
144
+ {/if}
@@ -0,0 +1,30 @@
1
+ import type { BaseMarkProps, ChannelAccessor, CurveName, DataRecord } from '../types.js';
2
+ import type { CurveFactory } from 'd3-shape';
3
+ type DifferenceYMarkProps = {
4
+ data: DataRecord[];
5
+ x1: ChannelAccessor;
6
+ /**
7
+ * the horizontal position of the metric; bound to the x scale
8
+ */
9
+ x2: ChannelAccessor;
10
+ x: ChannelAccessor;
11
+ /**
12
+ * the vertical position of the comparison; bound to the y scale
13
+ */
14
+ y1: ChannelAccessor;
15
+ /**
16
+ * the vertical position of the metric; bound to the y scale
17
+ */
18
+ y2: ChannelAccessor;
19
+ y: ChannelAccessor;
20
+ positiveFill?: string;
21
+ positiveFillOpacity?: number;
22
+ negativeFill?: string;
23
+ negativeFillOpacity?: number;
24
+ stroke: boolean | ChannelAccessor;
25
+ curve?: CurveName | CurveFactory;
26
+ tension?: number;
27
+ } & BaseMarkProps;
28
+ declare const DifferenceY: import("svelte").Component<DifferenceYMarkProps, {}, "">;
29
+ type DifferenceY = ReturnType<typeof DifferenceY>;
30
+ export default DifferenceY;
@@ -1,82 +1,137 @@
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
- }
1
+ <script lang="ts">
2
+ import { getContext, type Snippet } from 'svelte';
3
+ import type {
4
+ PlotContext,
5
+ DataRecord,
6
+ BaseMarkProps,
7
+ ConstantAccessor,
8
+ ChannelAccessor,
9
+ FacetContext,
10
+ PlotDefaults
11
+ } from '../types.js';
12
+ import {
13
+ resolveChannel,
14
+ resolveProp,
15
+ resolveScaledStyles,
16
+ resolveStyles
17
+ } from '../helpers/resolve.js';
18
+ import { maybeSymbol } from '../helpers/symbols.js';
19
+ import { symbol as d3Symbol } from 'd3-shape';
20
+ import { projectXY } from '../helpers/scales.js';
21
+ import { sort } from '../index.js';
22
+ import Mark from '../Mark.svelte';
23
+ import DotCanvas from './helpers/DotCanvas.svelte';
24
+ import { maybeData, testFilter, isValid } from '../helpers/index.js';
25
+ import { recordizeXY } from '../transforms/recordize.js';
26
+ import { addEventHandlers } from './helpers/events.js';
27
+
28
+ type DotProps = BaseMarkProps & {
29
+ data: DataRecord[];
30
+ x: ChannelAccessor;
31
+ y: ChannelAccessor;
32
+ r?: ChannelAccessor;
33
+ fill?: ChannelAccessor;
34
+ stroke?: ChannelAccessor;
35
+ symbol?: ChannelAccessor | Snippet<[number, string]>;
36
+ children?: Snippet;
37
+ dx?: ConstantAccessor<number>;
38
+ dy?: ConstantAccessor<number>;
39
+ canvas: boolean;
40
+ dotClass: ConstantAccessor<string>;
41
+ in: any;
42
+ inParams: any;
43
+ out: any;
44
+ outParams: any;
45
+ transition: any;
46
+ wrap: Snippet;
47
+ };
48
+
49
+ let {
50
+ data = [{}],
51
+ canvas = false,
52
+ class: className = '',
53
+ dotClass = null,
54
+ in: tIn = undefined,
55
+ inParams = undefined,
56
+ out: tOut = undefined,
57
+ outParams = undefined,
58
+ ...options
59
+ }: DotProps = $props();
60
+
61
+ const { getPlotState } = getContext<PlotContext>('svelteplot');
62
+ let plot = $derived(getPlotState());
63
+
64
+ function getSymbolPath(symbolType, size) {
65
+ return d3Symbol(maybeSymbol(symbolType), size)();
66
+ }
67
+
68
+ const { getTestFacet } = getContext<FacetContext>('svelteplot/facet');
69
+ const { dotRadius } = getContext<PlotDefaults>('svelteplot/_defaults');
70
+ let testFacet = $derived(getTestFacet());
71
+
72
+ const args = $derived(
73
+ // todo: move sorting to Mark
74
+ sort(
75
+ recordizeXY({
76
+ data: maybeData(data),
77
+ // sort by descending radius by default
78
+ ...(options.r ? { sort: { channel: '-r' } } : {}),
79
+ ...options,
80
+ ...(options.fill === true ? { fill: 'currentColor' } : {})
81
+ })
82
+ )
83
+ );
26
84
  </script>
27
85
 
28
- <BaseMark_Dot
86
+ <Mark
29
87
  type="dot"
30
- {data}
88
+ required={['x', 'y']}
31
89
  channels={[
32
- ...(x ? ['x'] : []),
33
- ...(y ? ['y'] : []),
34
- ...(r ? ['radius'] : []),
35
- ...(symbol ? ['symbol'] : []),
36
- ...(fill || stroke ? ['color'] : [])
90
+ 'x',
91
+ 'y',
92
+ 'r',
93
+ 'symbol',
94
+ 'fill',
95
+ 'opacity',
96
+ 'stroke',
97
+ 'fillOpacity',
98
+ 'strokeOpacity'
37
99
  ]}
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
- />
100
+ defaults={{ r: dotRadius, symbol: 'circle' }}
101
+ {...args}>
102
+ {#snippet children({ mark, usedScales, scaledData })}
103
+ <g class="dots {className || ''}">
104
+ {#if canvas}
105
+ <DotCanvas data={args.data} {mark} {plot} {testFacet} {usedScales} />
106
+ {:else}
107
+ {#each scaledData as d}
108
+ {#if d.valid && isValid(d.r)}
109
+ {@const [style, styleClass] = resolveStyles(
110
+ plot,
111
+ d,
112
+ { strokeWidth: 1.6, ...args },
113
+ 'stroke',
114
+ usedScales
115
+ )}
116
+ <path
117
+ transform="translate({d.x}, {d.y})"
118
+ d={getSymbolPath(d.symbol, d.r ** 2 * Math.PI)}
119
+ class={[
120
+ dotClass ? resolveProp(dotClass, d.datum, null) : null,
121
+ styleClass
122
+ ]}
123
+ {style}
124
+ use:addEventHandlers={{
125
+ getPlotState,
126
+ options: args,
127
+ datum: d.datum
128
+ }} />
129
+ {/if}
130
+ {/each}
71
131
  {/if}
72
- {/each}
73
- </g>
74
- </BaseMark_Dot>
132
+ </g>
133
+ {/snippet}
134
+ </Mark>
75
135
 
76
136
  <style>
77
- path {
78
- fill: none;
79
- stroke: none;
80
- stroke-width: 1.6px;
81
- }
82
137
  </style>
@@ -1,15 +1,25 @@
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: {};
1
+ import { type Snippet } from 'svelte';
2
+ import type { DataRecord, BaseMarkProps, ConstantAccessor, ChannelAccessor } from '../types.js';
3
+ type DotProps = BaseMarkProps & {
4
+ data: DataRecord[];
5
+ x: ChannelAccessor;
6
+ y: ChannelAccessor;
7
+ r?: ChannelAccessor;
8
+ fill?: ChannelAccessor;
9
+ stroke?: ChannelAccessor;
10
+ symbol?: ChannelAccessor | Snippet<[number, string]>;
11
+ children?: Snippet;
12
+ dx?: ConstantAccessor<number>;
13
+ dy?: ConstantAccessor<number>;
14
+ canvas: boolean;
15
+ dotClass: ConstantAccessor<string>;
16
+ in: any;
17
+ inParams: any;
18
+ out: any;
19
+ outParams: any;
20
+ transition: any;
21
+ wrap: Snippet;
9
22
  };
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 {};
23
+ declare const Dot: import("svelte").Component<DotProps, {}, "">;
24
+ type Dot = ReturnType<typeof Dot>;
25
+ export default Dot;
@@ -1,5 +1,17 @@
1
- <script>import Dot from "./Dot.svelte";
2
- let { data, ...rest } = $props();
1
+ <script lang="ts">
2
+ import Dot from './Dot.svelte';
3
+ import { recordizeX } from '../index.js';
4
+ import type { BaseMarkProps, DataRow } from '../types.js';
5
+ import type { ChannelAccessor } from '../types.js';
6
+
7
+ type DotXProps = BaseMarkProps & {
8
+ data: DataRow[];
9
+ x?: ChannelAccessor;
10
+ };
11
+
12
+ let { data = [{}], ...options }: DotXProps = $props();
13
+
14
+ const args = $derived(recordizeX({ data, ...options, y: 1 }, { withIndex: false }));
3
15
  </script>
4
16
 
5
- <Dot {data} x={(d) => d} y={0} {...rest} />
17
+ <Dot {...args} />
@@ -1,17 +1,9 @@
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: {};
1
+ import type { BaseMarkProps, DataRow } from '../types.js';
2
+ import type { ChannelAccessor } from '../types.js';
3
+ type DotXProps = BaseMarkProps & {
4
+ data: DataRow[];
5
+ x?: ChannelAccessor;
11
6
  };
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 {};
7
+ declare const DotX: import("svelte").Component<DotXProps, {}, "">;
8
+ type DotX = ReturnType<typeof DotX>;
9
+ export default DotX;
@@ -1,5 +1,10 @@
1
- <script>import Dot from "./Dot.svelte";
2
- let { data, ...rest } = $props();
1
+ <script lang="ts">
2
+ import Dot from './Dot.svelte';
3
+ import { recordizeY } from '../index.js';
4
+
5
+ let { data = [{}], ...options } = $props();
6
+
7
+ const args = $derived(recordizeY({ data, ...options, x: 0 }, { withIndex: false }));
3
8
  </script>
4
9
 
5
- <Dot {data} y={(d) => d} x={0} {...rest} />
10
+ <Dot {...args} />
@@ -1,17 +1,5 @@
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 {};
1
+ declare const DotY: import("svelte").Component<{
2
+ data?: any[];
3
+ } & Record<string, any>, {}, "">;
4
+ type DotY = ReturnType<typeof DotY>;
5
+ export default DotY;
@@ -1,37 +1,45 @@
1
- <script>import { getContext } from "svelte";
2
- import BaseMark from "./BaseMark.svelte";
3
- import getBaseStyles from "../helpers/getBaseStyles.js";
4
- const plot = getContext("svelteplot");
5
- let { ...styleProps } = $props();
6
- let styleProps2 = $derived({
7
- ...styleProps,
8
- ...!styleProps.fill && !styleProps.stroke ? { stroke: "currentColor" } : {}
9
- });
1
+ <script lang="ts">
2
+ import Mark from '../Mark.svelte';
3
+ import { getContext } from 'svelte';
4
+ import type { PlotContext, BaseRectMarkProps } from '../types.js';
5
+ import type { BaseMarkProps } from '../types.js';
6
+ import { resolveProp, resolveScaledStyles } from '../helpers/resolve.js';
7
+ import { addEventHandlers } from './helpers/events.js';
8
+
9
+ type FrameMarkProps = BaseMarkProps &
10
+ BaseRectMarkProps & {
11
+ automatic?: boolean;
12
+ };
13
+
14
+ let { automatic, class: className = null, ...options }: FrameMarkProps = $props();
15
+
16
+ const { getPlotState } = getContext<PlotContext>('svelteplot');
17
+ const plot = $derived(getPlotState());
18
+
19
+ const dx = $derived(resolveProp(options.dx, null, 0));
20
+ const dy = $derived(resolveProp(options.dy, null, 0));
21
+
22
+ const {
23
+ insetLeft = options.inset || 0,
24
+ insetTop = options.inset || 0,
25
+ insetRight = options.inset || 0,
26
+ insetBottom = options.inset || 0
27
+ } = $derived(options);
10
28
  </script>
11
29
 
12
- <BaseMark type="frame" data={[]} channels={[]}>
30
+ <Mark type="frame" {automatic}>
13
31
  <rect
14
- class="frame"
15
- style={getBaseStyles(null, styleProps2)}
16
- x={plot.margins.left}
17
- y={plot.margins.top}
18
- width={plot.plotWidth}
19
- height={plot.plotHeight}
20
- />
21
- </BaseMark>
22
-
23
- <!--
24
- <text
25
- style="font-size: 40px;text-anchor:middle"
26
- dominant-baseline="central"
27
- opacity={0.1}
28
- transform="translate({plot.margins.left + plot.plotWidth * 0.5}, {plot.margins.top +
29
- plot.plotHeight * 0.5})">{plot.plotWidth} x {plot.plotHeight}</text
30
- > -->
32
+ class={['frame', className]}
33
+ transform={dx || dy ? `translate(${dx},${dy})` : null}
34
+ style={resolveScaledStyles({}, options, {}, plot, 'stroke')}
35
+ x={plot.options.marginLeft + +insetLeft}
36
+ y={plot.options.marginTop + +insetTop}
37
+ rx={resolveProp(options.rx, null, null)}
38
+ ry={resolveProp(options.ry, null, null)}
39
+ width={plot.facetWidth - (insetLeft || 0) - (insetRight || 0)}
40
+ height={plot.facetHeight - (insetBottom || 0) - (insetTop || 0)}
41
+ use:addEventHandlers={{ getPlotState, options: options, datum: {} }} />
42
+ </Mark>
31
43
 
32
44
  <style>
33
- .frame {
34
- stroke: none;
35
- fill: none;
36
- }
37
45
  </style>
@@ -1,15 +1,8 @@
1
- import { SvelteComponent } from "svelte";
2
- import type { FrameProps } from '../types.js';
3
- declare const __propDef: {
4
- props: import("../types.js").BaseMarkStyleProps;
5
- events: {
6
- [evt: string]: CustomEvent<any>;
7
- };
8
- slots: {};
1
+ import type { BaseRectMarkProps } from '../types.js';
2
+ import type { BaseMarkProps } from '../types.js';
3
+ type FrameMarkProps = BaseMarkProps & BaseRectMarkProps & {
4
+ automatic?: boolean;
9
5
  };
10
- type FrameProps_ = typeof __propDef.props;
11
- export { FrameProps_ as FrameProps };
12
- export type FrameEvents = typeof __propDef.events;
13
- export type FrameSlots = typeof __propDef.slots;
14
- export default class Frame extends SvelteComponent<FrameProps, FrameEvents, FrameSlots> {
15
- }
6
+ declare const Frame: import("svelte").Component<FrameMarkProps, {}, "">;
7
+ type Frame = ReturnType<typeof Frame>;
8
+ export default Frame;