svelteplot 0.10.3 → 0.11.0

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 (222) hide show
  1. package/dist/Mark.svelte +42 -25
  2. package/dist/Mark.svelte.d.ts +111 -32
  3. package/dist/Plot.svelte +21 -15
  4. package/dist/core/Facet.svelte +1 -1
  5. package/dist/core/FacetAxes.svelte +13 -8
  6. package/dist/core/FacetGrid.svelte +4 -4
  7. package/dist/core/Plot.svelte +41 -35
  8. package/dist/helpers/autoScales.d.ts +3 -3
  9. package/dist/helpers/autoScales.js +28 -18
  10. package/dist/helpers/autoTicks.js +2 -0
  11. package/dist/helpers/callWithProps.d.ts +1 -2
  12. package/dist/helpers/facets.js +0 -1
  13. package/dist/helpers/index.js +1 -1
  14. package/dist/helpers/mergeDeep.d.ts +1 -3
  15. package/dist/helpers/mergeDeep.js +15 -16
  16. package/dist/helpers/projection.d.ts +4 -3
  17. package/dist/helpers/projection.js +17 -5
  18. package/dist/helpers/reduce.d.ts +4 -4
  19. package/dist/helpers/reduce.js +6 -4
  20. package/dist/helpers/regressionLoess.js +2 -1
  21. package/dist/helpers/resolve.d.ts +6 -3
  22. package/dist/helpers/resolve.js +25 -16
  23. package/dist/helpers/scales.d.ts +10 -10
  24. package/dist/helpers/scales.js +43 -13
  25. package/dist/helpers/time.d.ts +10 -3
  26. package/dist/helpers/time.js +2 -1
  27. package/dist/hooks/index.d.ts +2 -0
  28. package/dist/hooks/index.js +2 -0
  29. package/dist/hooks/plotDefaults.d.ts +3 -1
  30. package/dist/hooks/plotDefaults.js +33 -1
  31. package/dist/hooks/usePlot.svelte.d.ts +10 -25
  32. package/dist/hooks/usePlot.svelte.js +8 -7
  33. package/dist/index.d.ts +1 -2
  34. package/dist/index.js +1 -3
  35. package/dist/marks/Area.svelte +24 -13
  36. package/dist/marks/Area.svelte.d.ts +118 -34
  37. package/dist/marks/AreaX.svelte +42 -8
  38. package/dist/marks/AreaX.svelte.d.ts +154 -71
  39. package/dist/marks/AreaY.svelte +42 -8
  40. package/dist/marks/AreaY.svelte.d.ts +154 -71
  41. package/dist/marks/Arrow.svelte +42 -23
  42. package/dist/marks/Arrow.svelte.d.ts +114 -35
  43. package/dist/marks/AxisX.svelte +43 -28
  44. package/dist/marks/AxisX.svelte.d.ts +125 -40
  45. package/dist/marks/AxisY.svelte +43 -26
  46. package/dist/marks/AxisY.svelte.d.ts +127 -40
  47. package/dist/marks/BarX.svelte +12 -10
  48. package/dist/marks/BarX.svelte.d.ts +104 -32
  49. package/dist/marks/BarY.svelte +11 -10
  50. package/dist/marks/BarY.svelte.d.ts +106 -34
  51. package/dist/marks/BollingerX.svelte +4 -7
  52. package/dist/marks/BollingerX.svelte.d.ts +105 -30
  53. package/dist/marks/BollingerY.svelte +3 -0
  54. package/dist/marks/BollingerY.svelte.d.ts +105 -30
  55. package/dist/marks/BoxX.svelte +3 -3
  56. package/dist/marks/BoxY.svelte +12 -9
  57. package/dist/marks/BoxY.svelte.d.ts +128 -53
  58. package/dist/marks/Brush.svelte +26 -21
  59. package/dist/marks/Brush.svelte.d.ts +119 -60
  60. package/dist/marks/Cell.svelte +13 -9
  61. package/dist/marks/Cell.svelte.d.ts +105 -30
  62. package/dist/marks/CellX.svelte +2 -1
  63. package/dist/marks/CellX.svelte.d.ts +105 -32
  64. package/dist/marks/CellY.svelte +2 -1
  65. package/dist/marks/CellY.svelte.d.ts +105 -32
  66. package/dist/marks/ColorLegend.svelte +24 -13
  67. package/dist/marks/ColorLegend.svelte.d.ts +1 -0
  68. package/dist/marks/CustomMark.svelte +16 -10
  69. package/dist/marks/CustomMark.svelte.d.ts +112 -31
  70. package/dist/marks/CustomMarkHTML.svelte +8 -2
  71. package/dist/marks/CustomMarkHTML.svelte.d.ts +8 -2
  72. package/dist/marks/DifferenceY.svelte +31 -20
  73. package/dist/marks/DifferenceY.svelte.d.ts +134 -55
  74. package/dist/marks/Dot.svelte +21 -11
  75. package/dist/marks/Dot.svelte.d.ts +117 -38
  76. package/dist/marks/DotX.svelte +2 -0
  77. package/dist/marks/DotX.svelte.d.ts +136 -62
  78. package/dist/marks/DotY.svelte +1 -0
  79. package/dist/marks/DotY.svelte.d.ts +135 -62
  80. package/dist/marks/Frame.svelte +47 -9
  81. package/dist/marks/Frame.svelte.d.ts +124 -41
  82. package/dist/marks/Geo.svelte +21 -12
  83. package/dist/marks/Geo.svelte.d.ts +105 -30
  84. package/dist/marks/Graticule.svelte +3 -0
  85. package/dist/marks/Graticule.svelte.d.ts +3 -0
  86. package/dist/marks/GridX.svelte +31 -16
  87. package/dist/marks/GridX.svelte.d.ts +108 -32
  88. package/dist/marks/GridY.svelte +30 -15
  89. package/dist/marks/GridY.svelte.d.ts +108 -32
  90. package/dist/marks/HTMLTooltip.svelte +14 -7
  91. package/dist/marks/HTMLTooltip.svelte.d.ts +7 -0
  92. package/dist/marks/Image.svelte +50 -25
  93. package/dist/marks/Image.svelte.d.ts +117 -35
  94. package/dist/marks/Line.svelte +67 -44
  95. package/dist/marks/Line.svelte.d.ts +119 -30
  96. package/dist/marks/LineX.svelte +2 -1
  97. package/dist/marks/LineX.svelte.d.ts +142 -69
  98. package/dist/marks/LineY.svelte +2 -1
  99. package/dist/marks/LineY.svelte.d.ts +142 -69
  100. package/dist/marks/Link.svelte +70 -46
  101. package/dist/marks/Link.svelte.d.ts +126 -41
  102. package/dist/marks/Pointer.svelte +24 -15
  103. package/dist/marks/Pointer.svelte.d.ts +7 -0
  104. package/dist/marks/Rect.svelte +13 -5
  105. package/dist/marks/Rect.svelte.d.ts +116 -35
  106. package/dist/marks/RectX.svelte +6 -3
  107. package/dist/marks/RectX.svelte.d.ts +158 -12
  108. package/dist/marks/RectY.svelte +6 -3
  109. package/dist/marks/RectY.svelte.d.ts +158 -12
  110. package/dist/marks/RegressionX.svelte +13 -6
  111. package/dist/marks/RegressionX.svelte.d.ts +8 -3
  112. package/dist/marks/RegressionY.svelte +13 -6
  113. package/dist/marks/RegressionY.svelte.d.ts +8 -3
  114. package/dist/marks/RuleX.svelte +18 -11
  115. package/dist/marks/RuleX.svelte.d.ts +112 -32
  116. package/dist/marks/RuleY.svelte +19 -12
  117. package/dist/marks/RuleY.svelte.d.ts +114 -34
  118. package/dist/marks/Spike.svelte +11 -5
  119. package/dist/marks/Spike.svelte.d.ts +146 -68
  120. package/dist/marks/Text.svelte +24 -7
  121. package/dist/marks/Text.svelte.d.ts +253 -75
  122. package/dist/marks/TickX.svelte +56 -48
  123. package/dist/marks/TickX.svelte.d.ts +114 -40
  124. package/dist/marks/TickY.svelte +59 -51
  125. package/dist/marks/TickY.svelte.d.ts +117 -43
  126. package/dist/marks/Trail.svelte +25 -13
  127. package/dist/marks/Trail.svelte.d.ts +116 -33
  128. package/dist/marks/Vector.svelte +20 -11
  129. package/dist/marks/Vector.svelte.d.ts +116 -35
  130. package/dist/marks/WaffleX.svelte +18 -16
  131. package/dist/marks/WaffleX.svelte.d.ts +131 -57
  132. package/dist/marks/WaffleY.svelte +16 -15
  133. package/dist/marks/WaffleY.svelte.d.ts +129 -56
  134. package/dist/marks/helpers/Anchor.svelte +17 -2
  135. package/dist/marks/helpers/Anchor.svelte.d.ts +16 -1
  136. package/dist/marks/helpers/AreaCanvas.svelte +8 -8
  137. package/dist/marks/helpers/BaseAxisX.svelte +38 -41
  138. package/dist/marks/helpers/BaseAxisX.svelte.d.ts +11 -17
  139. package/dist/marks/helpers/BaseAxisY.svelte +35 -35
  140. package/dist/marks/helpers/BaseAxisY.svelte.d.ts +12 -15
  141. package/dist/marks/helpers/Box.svelte +35 -28
  142. package/dist/marks/helpers/Box.svelte.d.ts +122 -50
  143. package/dist/marks/helpers/DotCanvas.svelte +11 -9
  144. package/dist/marks/helpers/GeoCanvas.svelte +7 -6
  145. package/dist/marks/helpers/LineCanvas.svelte +7 -7
  146. package/dist/marks/helpers/LinearGradientX.svelte +2 -2
  147. package/dist/marks/helpers/LinearGradientX.svelte.d.ts +1 -1
  148. package/dist/marks/helpers/LinearGradientY.svelte +2 -2
  149. package/dist/marks/helpers/LinearGradientY.svelte.d.ts +1 -1
  150. package/dist/marks/helpers/Marker.svelte +2 -2
  151. package/dist/marks/helpers/MarkerPath.svelte +15 -12
  152. package/dist/marks/helpers/MarkerPath.svelte.d.ts +105 -32
  153. package/dist/marks/helpers/MultilineText.svelte +24 -17
  154. package/dist/marks/helpers/MultilineText.svelte.d.ts +1 -1
  155. package/dist/marks/helpers/RectCanvas.svelte +31 -26
  156. package/dist/marks/helpers/RectPath.svelte +2 -2
  157. package/dist/marks/helpers/Regression.svelte +176 -86
  158. package/dist/marks/helpers/Regression.svelte.d.ts +20 -8
  159. package/dist/marks/helpers/RuleCanvas.svelte +9 -6
  160. package/dist/marks/helpers/TextCanvas.svelte +13 -9
  161. package/dist/marks/helpers/TextCanvas.svelte.d.ts +6 -6
  162. package/dist/marks/helpers/TickCanvas.svelte +6 -5
  163. package/dist/marks/helpers/TrailCanvas.svelte +16 -18
  164. package/dist/marks/helpers/TrailCanvas.svelte.d.ts +3 -5
  165. package/dist/marks/helpers/canvas.js +16 -9
  166. package/dist/marks/helpers/events.d.ts +2 -2
  167. package/dist/marks/helpers/events.js +14 -7
  168. package/dist/marks/helpers/waffle.d.ts +3 -3
  169. package/dist/marks/helpers/waffle.js +6 -4
  170. package/dist/regression/polynomial.d.ts +1 -1
  171. package/dist/regression/polynomial.js +5 -5
  172. package/dist/regression/utils/determination.d.ts +1 -1
  173. package/dist/regression/utils/determination.js +1 -1
  174. package/dist/regression/utils/geometry.d.ts +1 -1
  175. package/dist/regression/utils/interpose.d.ts +1 -1
  176. package/dist/regression/utils/interpose.js +1 -1
  177. package/dist/regression/utils/points.d.ts +1 -1
  178. package/dist/transforms/bin.d.ts +3 -3
  179. package/dist/transforms/bin.js +29 -20
  180. package/dist/transforms/bollinger.d.ts +8 -0
  181. package/dist/transforms/bollinger.js +9 -1
  182. package/dist/transforms/centroid.d.ts +4 -0
  183. package/dist/transforms/centroid.js +4 -0
  184. package/dist/transforms/density.d.ts +4 -4
  185. package/dist/transforms/density.js +20 -13
  186. package/dist/transforms/dodge.d.ts +12 -1
  187. package/dist/transforms/dodge.js +15 -6
  188. package/dist/transforms/group.d.ts +141 -4
  189. package/dist/transforms/group.js +4 -1
  190. package/dist/transforms/interval.d.ts +204 -60
  191. package/dist/transforms/jitter.d.ts +421 -4
  192. package/dist/transforms/jitter.js +10 -1
  193. package/dist/transforms/map.d.ts +412 -4
  194. package/dist/transforms/map.js +3 -3
  195. package/dist/transforms/normalize.d.ts +276 -5
  196. package/dist/transforms/normalize.js +5 -3
  197. package/dist/transforms/recordize.d.ts +17 -5
  198. package/dist/transforms/recordize.js +13 -9
  199. package/dist/transforms/rename.d.ts +11 -4
  200. package/dist/transforms/rename.js +7 -2
  201. package/dist/transforms/select.d.ts +722 -210
  202. package/dist/transforms/select.js +13 -1
  203. package/dist/transforms/shift.d.ts +8 -0
  204. package/dist/transforms/shift.js +20 -6
  205. package/dist/transforms/sort.d.ts +13 -258
  206. package/dist/transforms/sort.js +13 -10
  207. package/dist/transforms/stack.d.ts +58 -9
  208. package/dist/transforms/stack.js +27 -11
  209. package/dist/transforms/window.d.ts +221 -66
  210. package/dist/transforms/window.js +8 -2
  211. package/dist/types/axes.d.ts +43 -0
  212. package/dist/types/axes.js +1 -0
  213. package/dist/types/channel.d.ts +30 -2
  214. package/dist/types/data.d.ts +14 -1
  215. package/dist/types/facet.d.ts +5 -0
  216. package/dist/types/index.d.ts +33 -8
  217. package/dist/types/index.js +11 -7
  218. package/dist/types/mark.d.ts +124 -35
  219. package/dist/types/plot.d.ts +118 -16
  220. package/dist/types/scale.d.ts +125 -8
  221. package/package.json +178 -175
  222. package/dist/helpers/autoTicks.d.ts +0 -12
@@ -1,18 +1,31 @@
1
1
  import type { ScaledChannelName, ScaledChannelType } from './channel.js';
2
+ /** a raw data value that can be used in channels */
2
3
  export type RawValue = number | Date | boolean | string | symbol | object | null;
4
+ /** a data record passed to marks; generic over the user's row shape */
3
5
  export type DataRecord<T = Record<string | symbol, RawValue>> = T;
6
+ /** a data record after channel accessors have been resolved to concrete values */
4
7
  export type ResolvedDataRecord<T = Record<string | symbol, RawValue>> = Partial<Record<ScaledChannelName, any>> & {
8
+ /** the original data record before resolution */
5
9
  datum: DataRecord<T>;
10
+ /** the index of this record in the original data array */
6
11
  index: number;
7
12
  };
13
+ /** a data record after scale functions have been applied to channel values */
8
14
  export type ScaledDataRecord<T = Record<string | symbol, RawValue>> = Partial<{
9
15
  [K in ScaledChannelName]?: ScaledChannelType<K>;
10
16
  }> & {
17
+ /** horizontal pixel offset applied after scaling */
11
18
  dx: number;
19
+ /** vertical pixel offset applied after scaling */
12
20
  dy: number;
21
+ /** the original data record */
13
22
  datum: DataRecord<T>;
23
+ /** the resolved (pre-scaling) channel values */
14
24
  resolved: ResolvedDataRecord<T>;
15
- valid: Boolean;
25
+ /** whether this record has valid values for all required channels */
26
+ valid: boolean;
27
+ /** the index of this record in the original data array */
16
28
  index: number;
17
29
  };
30
+ /** a data row as passed by the user; can be a record, a raw value, a coordinate pair, or null */
18
31
  export type DataRow<T = Record<string | symbol, RawValue>> = DataRecord<T> | RawValue | [number, number] | null;
@@ -1,6 +1,9 @@
1
1
  import type { ChannelAccessor, ChannelName, DataRecord, RawValue } from './index.js';
2
+ /** the state of a single facet panel within a faceted plot */
2
3
  type FacetState = {
4
+ /** the current horizontal facet value */
3
5
  fx: RawValue;
6
+ /** the current vertical facet value */
4
7
  fy: RawValue;
5
8
  /**
6
9
  * True, if the facet is the leftmost in its row
@@ -39,12 +42,14 @@ type FacetState = {
39
42
  * Test if the given data record is visible in the current facet.
40
43
  */
41
44
  type TestFacetFunction = (datum: DataRecord<any>, channels: Record<ChannelName, ChannelAccessor>) => boolean;
45
+ /** context provided to marks for facet-aware filtering and state access */
42
46
  export type FacetContext = {
43
47
  /**
44
48
  * Returns a stateful function that tests whether a specific data
45
49
  * record is visible in the current facet or not.
46
50
  */
47
51
  getTestFacet: () => TestFacetFunction;
52
+ /** returns the current facet panel state (position, edge flags) */
48
53
  getFacetState: () => FacetState;
49
54
  };
50
55
  export {};
@@ -4,7 +4,9 @@ import type { MarkerShape } from '../marks/helpers/Marker.svelte';
4
4
  import type { Channels, ScaledChannelName } from './channel.js';
5
5
  import type { RawValue } from './data.js';
6
6
  import type { BaseMarkProps } from './mark.js';
7
+ /** a generic record type used when the specific mark options type is not known */
7
8
  export type GenericMarkOptions = Record<string | symbol, any>;
9
+ /** the name of a d3 curve interpolation method */
8
10
  export type CurveName = 'basis' | 'basis-closed' | 'basis-open' | 'bundle' | 'bump-x' | 'bump-y' | 'cardinal' | 'cardinal-closed' | 'cardinal-open' | 'catmull-rom' | 'catmull-rom-closed' | 'catmull-rom-open' | 'linear' | 'linear-closed' | 'monotone-x' | 'monotone-y' | 'natural' | 'step' | 'step-after' | 'step-before';
9
11
  export type MarkerOptions = {
10
12
  /**
@@ -28,41 +30,64 @@ export type MarkerOptions = {
28
30
  */
29
31
  markerScale?: ConstantAccessor<number>;
30
32
  };
31
- export type ConstantAccessor<K, T = Record<string | symbol, RawValue>> = K | ((d: T, index: number) => K) | null | undefined;
33
+ /** a value that is either a constant or a function that computes a per-datum value */
34
+ type BivariantCallback<TArgs extends unknown[], TResult> = {
35
+ bivarianceHack(...args: TArgs): TResult;
36
+ }['bivarianceHack'];
37
+ export type ConstantAccessor<K, T = Record<string | symbol, RawValue>> = K | BivariantCallback<[d: T, index: number], K> | null | undefined;
38
+ /** the input argument to a data transform: data array plus channel mappings and mark props */
32
39
  export type TransformArg<T> = Channels<T> & BaseMarkProps<T> & {
33
40
  data: T[];
34
41
  };
42
+ /** the input argument to a map transform: data array plus channel mappings */
35
43
  export type MapArg<T> = Channels<T> & {
36
44
  data: T[];
37
45
  };
46
+ /** transform input for raw data rows (before recordization) */
38
47
  export type TransformArgsRow<T extends RawValue | object> = Partial<Channels<T>> & {
39
48
  data: T[];
40
49
  };
50
+ /** transform input for data records (after recordization) */
41
51
  export type TransformArgsRecord<T extends object> = Partial<Channels<T>> & {
42
52
  data: T[];
43
53
  };
54
+ /** the return type of a transform, ensuring data is always present */
44
55
  export type TransformReturn<C extends TransformArg<T>, T> = C & Required<Pick<Channels<T>, 'data'>>;
56
+ /** writable stores used by marks to contribute to automatic margin computation */
45
57
  export type AutoMarginStores = {
58
+ /** per-mark contributions to the top margin */
46
59
  autoMarginTop: Writable<Map<string, number>>;
60
+ /** per-mark contributions to the left margin */
47
61
  autoMarginLeft: Writable<Map<string, number>>;
62
+ /** per-mark contributions to the right margin */
48
63
  autoMarginRight: Writable<Map<string, number>>;
64
+ /** per-mark contributions to the bottom margin */
49
65
  autoMarginBottom: Writable<Map<string, number>>;
50
66
  };
67
+ /** a function that maps source values (S) to target values (T) for the given indices (I) */
51
68
  export type MapIndexFunction = (I: number[], S: RawValue[], T: RawValue[]) => void;
69
+ /** an object implementing the mapIndex interface for custom map transforms */
52
70
  export type MapIndexObject = {
71
+ /** the function that performs the index-based mapping */
53
72
  mapIndex: MapIndexFunction;
54
73
  };
74
+ /** a named map method, a custom mapping function, or a MapIndexObject */
55
75
  export type MapMethod = 'cumsum' | 'rank' | 'quantile' | ((I: number[], S: number[]) => number[]) | MapIndexObject;
56
76
  /**
57
77
  * An object specifying mapping methods for one or more scaled channels
58
78
  * e.g. ```{ x: 'rank' }```
59
79
  */
60
80
  export type MapOptions = Partial<Record<ScaledChannelName, MapMethod>>;
81
+ /** a record indicating which scaled channels are actively used by a mark */
61
82
  export type UsedScales = Record<ScaledChannelName, boolean>;
62
- export * from './channel';
63
- export * from './colorScheme';
64
- export * from './data';
65
- export * from './facet';
66
- export * from './mark';
67
- export * from './plot';
68
- export * from './scale';
83
+ export * from './channel.js';
84
+ export * from './axes.js';
85
+ export * from './colorScheme.js';
86
+ export * from './data.js';
87
+ export * from './facet.js';
88
+ export * from './mark.js';
89
+ export * from './plot.js';
90
+ export * from './scale.js';
91
+ export * from '../transforms/density.js';
92
+ export * from '../transforms/window.js';
93
+ export * from '../helpers/reduce.js';
@@ -1,7 +1,11 @@
1
- export * from './channel';
2
- export * from './colorScheme';
3
- export * from './data';
4
- export * from './facet';
5
- export * from './mark';
6
- export * from './plot';
7
- export * from './scale';
1
+ export * from './channel.js';
2
+ export * from './axes.js';
3
+ export * from './colorScheme.js';
4
+ export * from './data.js';
5
+ export * from './facet.js';
6
+ export * from './mark.js';
7
+ export * from './plot.js';
8
+ export * from './scale.js';
9
+ export * from '../transforms/density.js';
10
+ export * from '../transforms/window.js';
11
+ export * from '../helpers/reduce.js';
@@ -6,79 +6,158 @@ export type Mark<T> = {
6
6
  data: DataRecord<T>[];
7
7
  options: T;
8
8
  };
9
- export type MarkType = 'area' | 'arrow' | 'barX' | 'barY' | 'cell' | 'custom' | 'dot' | 'vector' | 'frame' | 'geo' | 'gridX' | 'gridY' | 'line' | 'rect' | 'regression' | 'ruleX' | 'ruleY' | 'swoopyArrow' | 'text' | 'tickX' | 'tickY' | 'trail' | 'waffleX' | 'waffleY';
9
+ export type MarkType = 'area' | 'arrow' | 'axisX' | 'axisY' | 'barX' | 'barY' | 'cell' | 'custom' | 'dot' | 'vector' | 'frame' | 'geo' | 'gridX' | 'gridY' | 'image' | 'link' | 'line' | 'rect' | 'regression' | 'ruleX' | 'ruleY' | 'swoopyArrow' | 'text' | 'tickX' | 'tickY' | 'trail' | 'waffleX' | 'waffleY';
10
10
  export type MarkStyleProps = 'strokeDasharray' | 'strokeLinejoin' | 'strokeLinecap' | 'opacity' | 'cursor' | 'pointerEvents' | 'blend' | 'fill' | 'fillOpacity' | 'fontFamily' | 'fontWeight' | 'fontVariant' | 'fontSize' | 'fontStyle' | 'letterSpacing' | 'wordSpacing' | 'stroke' | 'strokeWidth' | 'strokeOpacity' | 'x' | 'y' | 'clipPath' | 'mask' | 'filter' | 'angle' | 'radius' | 'symbol' | 'textAnchor' | 'textTransform' | 'textDecoration' | 'width';
11
- import type { MouseEventHandler } from 'svelte/elements';
12
11
  import type { ChannelAccessor, ConstantAccessor, DataRecord, RawValue } from './index.js';
13
12
  import type * as CSS from 'csstype';
14
13
  import type { ScaledChannelName } from './channel.js';
15
14
  import type { ScaleName } from './scale.js';
16
15
  import type { DodgeXOptions, DodgeYOptions } from '../transforms/dodge.js';
17
- export type BaseMarkProps<T> = Partial<{
16
+ type MarkEventHandler<TDatum, TTarget extends EventTarget = EventTarget> = (event: Event & {
17
+ currentTarget: TTarget;
18
+ }, datum: TDatum, index: number) => void;
19
+ export type BaseMarkProps<T = DataRecord> = Partial<{
18
20
  /**
19
21
  * Filter the data without modifying the inferred scales
20
22
  */
21
23
  filter: ConstantAccessor<boolean, T>;
24
+ /** controls whether this mark participates in faceting; "exclude" to ignore facet filters, "include" to require matching facet values */
22
25
  facet: 'auto' | 'include' | 'exclude';
26
+ /** the horizontal facet channel */
23
27
  fx: ChannelAccessor<T>;
28
+ /** the vertical facet channel */
24
29
  fy: ChannelAccessor<T>;
30
+ /** a horizontal offset in pixels applied after scaling */
25
31
  dx: ConstantAccessor<number, T>;
32
+ /** a vertical offset in pixels applied after scaling */
26
33
  dy: ConstantAccessor<number, T>;
34
+ /** options for horizontal dodge positioning to avoid overlapping marks */
27
35
  dodgeX: DodgeXOptions;
36
+ /** options for vertical dodge positioning to avoid overlapping marks */
28
37
  dodgeY: DodgeYOptions;
38
+ /** the fill color; can be a fixed CSS color string or a channel accessor bound to the color scale */
29
39
  fill: ChannelAccessor<T>;
40
+ /** the fill opacity; a number between 0 and 1 */
30
41
  fillOpacity: ConstantAccessor<number, T>;
42
+ /** font family for text-capable marks */
43
+ fontFamily: ConstantAccessor<CSS.Property.FontFamily, T>;
44
+ /** font size for text-capable marks */
45
+ fontSize: ConstantAccessor<CSS.Property.FontSize | number, T>;
46
+ /** font style for text-capable marks */
47
+ fontStyle: ConstantAccessor<CSS.Property.FontStyle, T>;
48
+ /** font variant for text-capable marks */
49
+ fontVariant: ConstantAccessor<CSS.Property.FontVariant, T>;
50
+ /** font weight for text-capable marks */
51
+ fontWeight: ConstantAccessor<CSS.Property.FontWeight, T>;
52
+ /** letter spacing for text-capable marks */
53
+ letterSpacing: ConstantAccessor<CSS.Property.LetterSpacing, T>;
54
+ /** word spacing for text-capable marks */
55
+ wordSpacing: ConstantAccessor<CSS.Property.WordSpacing, T>;
56
+ /** text anchor for text-capable marks */
57
+ textAnchor: ConstantAccessor<CSS.Property.TextAnchor, T>;
58
+ /** text transform for text-capable marks */
59
+ textTransform: ConstantAccessor<CSS.Property.TextTransform, T>;
60
+ /** text decoration for text-capable marks */
61
+ textDecoration: ConstantAccessor<CSS.Property.TextDecoration, T>;
62
+ /** how to sort the mark data before rendering; can be a channel name string, an accessor, a comparator, or an object with channel and order */
31
63
  sort: string | ConstantAccessor<RawValue, T> | ((a: RawValue, b: RawValue) => number) | {
32
64
  /** sort data using an already defined channel */
33
65
  channel: string;
34
66
  /** sort order */
35
67
  order?: 'ascending' | 'descending';
36
68
  };
69
+ /** the stroke color; can be a fixed CSS color string or a channel accessor bound to the color scale */
37
70
  stroke: ChannelAccessor<T>;
71
+ /** the stroke width in pixels */
38
72
  strokeWidth: ConstantAccessor<number, T>;
73
+ /** the stroke opacity; a number between 0 and 1 */
39
74
  strokeOpacity: ConstantAccessor<number, T>;
75
+ /** the SVG stroke line join style (e.g. "round", "bevel") */
40
76
  strokeLinejoin: ConstantAccessor<CSS.Property.StrokeLinejoin, T>;
77
+ /** the SVG stroke line cap style (e.g. "round", "butt") */
41
78
  strokeLinecap: ConstantAccessor<CSS.Property.StrokeLinecap, T>;
79
+ /** the SVG stroke miter limit */
42
80
  strokeMiterlimit: ConstantAccessor<number, T>;
81
+ /** the overall element opacity; can be a fixed number or a channel accessor bound to the opacity scale */
43
82
  opacity: ChannelAccessor<T>;
83
+ /** the SVG stroke dash pattern (e.g. "4 2") */
44
84
  strokeDasharray: ConstantAccessor<string, T>;
85
+ /** the SVG stroke dash offset in pixels */
45
86
  strokeDashoffset: ConstantAccessor<number, T>;
87
+ /** the CSS mix-blend-mode for compositing (e.g. "multiply", "screen") */
88
+ blend: ConstantAccessor<CSS.Property.MixBlendMode, T>;
89
+ /** legacy alias of blend */
46
90
  mixBlendMode: ConstantAccessor<CSS.Property.MixBlendMode, T>;
91
+ /** a CSS clip-path to clip the mark element */
47
92
  clipPath: string;
93
+ /** a CSS mask to apply to the mark element */
48
94
  mask: string;
95
+ /** a CSS filter to apply to the mark element (e.g. "blur(2px)") */
49
96
  imageFilter: ConstantAccessor<string, T>;
97
+ /** the SVG shape-rendering attribute (e.g. "crispEdges", "geometricPrecision") */
50
98
  shapeRendering: ConstantAccessor<CSS.Property.ShapeRendering, T>;
99
+ /** the SVG paint-order attribute (e.g. "stroke" to render stroke behind fill) */
51
100
  paintOrder: ConstantAccessor<string, T>;
52
- onclick: MouseEventHandler<SVGPathElement>;
53
- ondblclick: MouseEventHandler<SVGPathElement>;
54
- onmouseup: MouseEventHandler<SVGPathElement>;
55
- onmousedown: MouseEventHandler<SVGPathElement>;
56
- onmouseenter: MouseEventHandler<SVGPathElement>;
57
- onmousemove: MouseEventHandler<SVGPathElement>;
58
- onmouseleave: MouseEventHandler<SVGPathElement>;
59
- onmouseout: MouseEventHandler<SVGPathElement>;
60
- onmouseover: MouseEventHandler<SVGPathElement>;
61
- onpointercancel: MouseEventHandler<SVGPathElement>;
62
- onpointerdown: MouseEventHandler<SVGPathElement>;
63
- onpointerup: MouseEventHandler<SVGPathElement>;
64
- onpointerenter: MouseEventHandler<SVGPathElement>;
65
- onpointerleave: MouseEventHandler<SVGPathElement>;
66
- onpointermove: MouseEventHandler<SVGPathElement>;
67
- onpointerover: MouseEventHandler<SVGPathElement>;
68
- onpointerout: MouseEventHandler<SVGPathElement>;
69
- ondrag: MouseEventHandler<SVGPathElement>;
70
- ondrop: MouseEventHandler<SVGPathElement>;
71
- ondragstart: MouseEventHandler<SVGPathElement>;
72
- ondragenter: MouseEventHandler<SVGPathElement>;
73
- ondragleave: MouseEventHandler<SVGPathElement>;
74
- ondragover: MouseEventHandler<SVGPathElement>;
75
- ondragend: MouseEventHandler<SVGPathElement>;
76
- ontouchstart: MouseEventHandler<SVGPathElement>;
77
- ontouchmove: MouseEventHandler<SVGPathElement>;
78
- ontouchend: MouseEventHandler<SVGPathElement>;
79
- ontouchcancel: MouseEventHandler<SVGPathElement>;
80
- oncontextmenu: MouseEventHandler<SVGPathElement>;
81
- onwheel: MouseEventHandler<SVGPathElement>;
101
+ /** fired when the mark element is clicked */
102
+ onclick: MarkEventHandler<T, SVGPathElement>;
103
+ /** fired when the mark element is double-clicked */
104
+ ondblclick: MarkEventHandler<T, SVGPathElement>;
105
+ /** fired when a mouse button is released over the mark */
106
+ onmouseup: MarkEventHandler<T, SVGPathElement>;
107
+ /** fired when a mouse button is pressed over the mark */
108
+ onmousedown: MarkEventHandler<T, SVGPathElement>;
109
+ /** fired when the pointer enters the mark element */
110
+ onmouseenter: MarkEventHandler<T, SVGPathElement>;
111
+ /** fired when the pointer moves within the mark element */
112
+ onmousemove: MarkEventHandler<T, SVGPathElement>;
113
+ /** fired when the pointer leaves the mark element */
114
+ onmouseleave: MarkEventHandler<T, SVGPathElement>;
115
+ /** fired when the pointer moves out of the mark element */
116
+ onmouseout: MarkEventHandler<T, SVGPathElement>;
117
+ /** fired when the pointer moves onto the mark element */
118
+ onmouseover: MarkEventHandler<T, SVGPathElement>;
119
+ /** fired when a pointer event is canceled */
120
+ onpointercancel: MarkEventHandler<T, SVGPathElement>;
121
+ /** fired when a pointer becomes active over the mark */
122
+ onpointerdown: MarkEventHandler<T, SVGPathElement>;
123
+ /** fired when a pointer is released over the mark */
124
+ onpointerup: MarkEventHandler<T, SVGPathElement>;
125
+ /** fired when a pointer enters the mark element */
126
+ onpointerenter: MarkEventHandler<T, SVGPathElement>;
127
+ /** fired when a pointer leaves the mark element */
128
+ onpointerleave: MarkEventHandler<T, SVGPathElement>;
129
+ /** fired when a pointer moves within the mark element */
130
+ onpointermove: MarkEventHandler<T, SVGPathElement>;
131
+ /** fired when a pointer moves onto the mark element */
132
+ onpointerover: MarkEventHandler<T, SVGPathElement>;
133
+ /** fired when a pointer moves out of the mark element */
134
+ onpointerout: MarkEventHandler<T, SVGPathElement>;
135
+ /** fired continuously while the mark is being dragged */
136
+ ondrag: MarkEventHandler<T, SVGPathElement>;
137
+ /** fired when a dragged element is dropped on the mark */
138
+ ondrop: MarkEventHandler<T, SVGPathElement>;
139
+ /** fired when a drag operation begins on the mark */
140
+ ondragstart: MarkEventHandler<T, SVGPathElement>;
141
+ /** fired when a dragged element enters the mark */
142
+ ondragenter: MarkEventHandler<T, SVGPathElement>;
143
+ /** fired when a dragged element leaves the mark */
144
+ ondragleave: MarkEventHandler<T, SVGPathElement>;
145
+ /** fired when a dragged element is over the mark */
146
+ ondragover: MarkEventHandler<T, SVGPathElement>;
147
+ /** fired when a drag operation ends */
148
+ ondragend: MarkEventHandler<T, SVGPathElement>;
149
+ /** fired when a touch point is placed on the mark */
150
+ ontouchstart: MarkEventHandler<T, SVGPathElement>;
151
+ /** fired when a touch point moves along the mark */
152
+ ontouchmove: MarkEventHandler<T, SVGPathElement>;
153
+ /** fired when a touch point is removed from the mark */
154
+ ontouchend: MarkEventHandler<T, SVGPathElement>;
155
+ /** fired when a touch event is canceled */
156
+ ontouchcancel: MarkEventHandler<T, SVGPathElement>;
157
+ /** fired when the context menu is triggered on the mark */
158
+ oncontextmenu: MarkEventHandler<T, SVGPathElement>;
159
+ /** fired when the mouse wheel is scrolled over the mark */
160
+ onwheel: MarkEventHandler<T, SVGPathElement>;
82
161
  /**
83
162
  * if you want to give your mark element an extra CSS class
84
163
  */
@@ -87,7 +166,10 @@ export type BaseMarkProps<T> = Partial<{
87
166
  * if you want to give your mark element an extra inline style
88
167
  */
89
168
  style: string;
169
+ /** the CSS cursor style when hovering over the mark (e.g. "pointer", "crosshair") */
90
170
  cursor: ConstantAccessor<CSS.Property.Cursor, T>;
171
+ /** tooltip text shown in an SVG <title> element when provided */
172
+ title: ConstantAccessor<string, T>;
91
173
  }>;
92
174
  export type LinkableMarkProps<T> = {
93
175
  /**
@@ -113,8 +195,8 @@ export type LinkableMarkProps<T> = {
113
195
  * if set to true, the link will be downloaded instead of navigating to it
114
196
  * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#download
115
197
  */
116
- download?: ConstantAccessor<boolean, T>;
117
- [key: `data-sveltekit-${string}`]: string | boolean | undefined;
198
+ download?: ConstantAccessor<string, T>;
199
+ [key: `data-sveltekit-${string}`]: unknown;
118
200
  };
119
201
  export type BorderRadius = number | {
120
202
  topLeft?: number;
@@ -123,10 +205,17 @@ export type BorderRadius = number | {
123
205
  bottomLeft?: number;
124
206
  };
125
207
  export type BaseRectMarkProps<T> = {
208
+ /** shorthand to inset the rectangle on all sides, in pixels */
126
209
  inset?: ConstantAccessor<number, T>;
210
+ /** inset the rectangle from the left edge, in pixels */
127
211
  insetLeft?: ConstantAccessor<number, T>;
212
+ /** inset the rectangle from the top edge, in pixels */
128
213
  insetTop?: ConstantAccessor<number, T>;
214
+ /** inset the rectangle from the right edge, in pixels */
129
215
  insetRight?: ConstantAccessor<number, T>;
216
+ /** inset the rectangle from the bottom edge, in pixels */
130
217
  insetBottom?: ConstantAccessor<number, T>;
218
+ /** the border radius of the rectangle; can be a number or a per-corner object */
131
219
  borderRadius?: ConstantAccessor<BorderRadius, T>;
132
220
  };
221
+ export {};
@@ -8,10 +8,12 @@ import type { Clip } from '../helpers/projection.js';
8
8
  import type { Area, AreaX, AreaY, Arrow, AxisX, AxisY, BarX, BarY, BoxX, BoxY, Brush, BrushX, BrushY, Cell, DifferenceY, Dot, Frame, Geo, Graticule, GridX, GridY, Image, Line, Link, Pointer, Rect, RectX, RectY, RuleX, RuleY, Sphere, Spike, Text, TickX, TickY, Trail, Vector } from '../marks/index.js';
9
9
  import type WaffleX from '../marks/WaffleX.svelte';
10
10
  import type WaffleY from '../marks/WaffleY.svelte';
11
+ import type BaseAxisX from '../marks/helpers/BaseAxisX.svelte';
12
+ import type BaseAxisY from '../marks/helpers/BaseAxisY.svelte';
11
13
  export type PlotState = {
12
14
  width: number;
13
15
  height: number;
14
- options: PlotOptions;
16
+ options: ResolvedPlotOptions;
15
17
  facetWidth: number;
16
18
  facetHeight: number;
17
19
  plotWidth: number;
@@ -54,7 +56,7 @@ export type PlotContext = {
54
56
  */
55
57
  updateDimensions: (width: number, height: number) => void;
56
58
  };
57
- type IgnoreDefaults = 'data' | 'facet' | ChannelName | 'title' | 'automatic' | 'children';
59
+ type IgnoreDefaults = 'data' | 'facet' | Exclude<ChannelName, 'stroke' | 'fill'> | 'title' | 'automatic' | 'children';
58
60
  export type PlotMargin = {
59
61
  top?: number | 'auto';
60
62
  right?: number | 'auto';
@@ -208,7 +210,7 @@ export type PlotDefaults = {
208
210
  */
209
211
  frame: Partial<ComponentProps<typeof Frame> & {
210
212
  implicit: boolean;
211
- }>;
213
+ }> | true;
212
214
  /**
213
215
  * default props for geo marks
214
216
  */
@@ -222,19 +224,19 @@ export type PlotDefaults = {
222
224
  */
223
225
  grid: Partial<Omit<ComponentProps<typeof GridX>, IgnoreDefaults> & {
224
226
  implicit: boolean;
225
- }>;
227
+ }> | true;
226
228
  /**
227
229
  * default props for gridX marks
228
230
  */
229
231
  gridX: Partial<Omit<ComponentProps<typeof GridX>, IgnoreDefaults> & {
230
232
  implicit: boolean;
231
- }>;
233
+ }> | true;
232
234
  /**
233
235
  * default props for gridY marks
234
236
  */
235
237
  gridY: Partial<Omit<ComponentProps<typeof GridY>, IgnoreDefaults> & {
236
238
  implicit: boolean;
237
- }>;
239
+ }> | true;
238
240
  /**
239
241
  * default props for image marks
240
242
  */
@@ -439,18 +441,66 @@ export type PlotOptions = {
439
441
  * Options for the shared radius scale
440
442
  */
441
443
  r: Partial<ScaleOptions>;
444
+ /**
445
+ * Options for the shared color scale
446
+ */
442
447
  color: Partial<ColorScaleOptions>;
448
+ /**
449
+ * Options for the shared opacity scale
450
+ */
443
451
  opacity: Partial<ScaleOptions>;
452
+ /**
453
+ * Options for the shared symbol scale
454
+ */
444
455
  symbol: Partial<LegendScaleOptions>;
456
+ /**
457
+ * Options for the shared length scale (e.g. for vectors and spikes)
458
+ */
445
459
  length: Partial<ScaleOptions>;
446
- fx: Partial<XScaleOptions> | false | RawValue[];
447
- fy: Partial<YScaleOptions> | false | RawValue[];
460
+ /**
461
+ * Options for the horizontal facet scale, or false to disable, or an
462
+ * array of domain values
463
+ */
464
+ fx: (Partial<XScaleOptions> & {
465
+ /**
466
+ * customize base axis props used for rendering facet axis
467
+ */
468
+ axisProps?: Partial<ComponentProps<typeof BaseAxisX>>;
469
+ /**
470
+ * customize base axis options used for rendering facet axis
471
+ */
472
+ axisOptions?: Partial<ComponentProps<typeof BaseAxisX>['options']>;
473
+ }) | false | RawValue[];
474
+ /**
475
+ * Options for the vertical facet scale, or false to disable, or an
476
+ * array of domain values
477
+ */
478
+ fy: (Partial<YScaleOptions> & {
479
+ /**
480
+ * customize base axis props used for rendering facet axis
481
+ */
482
+ axisProps?: Partial<ComponentProps<typeof BaseAxisY>>;
483
+ /**
484
+ * customize base axis options used for rendering facet axis
485
+ */
486
+ axisOptions?: Partial<ComponentProps<typeof BaseAxisY>['options']>;
487
+ }) | false | RawValue[];
488
+ /**
489
+ * The plot content as a Svelte snippet. Receives the plot dimensions,
490
+ * options, and resolved scales as arguments.
491
+ */
448
492
  children: Snippet<[
449
493
  {
450
494
  width: number;
451
495
  height: number;
452
- options: PlotOptions;
496
+ options: ResolvedPlotOptions;
453
497
  scales: PlotScales;
498
+ hasProjection: boolean;
499
+ hasExplicitAxisX: boolean;
500
+ hasExplicitAxisY: boolean;
501
+ hasExplicitGridX: boolean;
502
+ hasExplicitGridY: boolean;
503
+ [key: string]: any;
454
504
  }
455
505
  ]>;
456
506
  /**
@@ -458,22 +508,37 @@ export type PlotOptions = {
458
508
  * your plot, or place a legend above the visualization.
459
509
  */
460
510
  header: Snippet;
511
+ /**
512
+ * The footer snippet is useful for rendering custom markup below the SVG body
513
+ * of your plot, e.g. for a caption or legend.
514
+ */
461
515
  footer: Snippet;
462
516
  /**
463
517
  * The underlay snippet is useful for adding a layer of custom HTML markup
464
518
  * behind the SVG body of your plot, e.g. for a watermark or background image.
465
519
  */
466
- underlay: Snippet<[PlotOptions]>;
520
+ underlay: Snippet<[ResolvedPlotOptions]>;
467
521
  /**
468
522
  * The overlay snippet is useful for adding a layer of custom HTML markup
469
523
  * in front of the SVG body of your plot, e.g. for HTML tooltips.
470
524
  */
471
- overlay: Snippet<[{
472
- width: number;
473
- height: number;
474
- options: PlotOptions;
475
- scales: PlotScales;
476
- }]>;
525
+ overlay: Snippet<[
526
+ {
527
+ width: number;
528
+ height: number;
529
+ options: ResolvedPlotOptions;
530
+ scales: PlotScales;
531
+ hasProjection: boolean;
532
+ hasExplicitAxisX: boolean;
533
+ hasExplicitAxisY: boolean;
534
+ hasExplicitGridX: boolean;
535
+ hasExplicitGridY: boolean;
536
+ [key: string]: any;
537
+ }
538
+ ]>;
539
+ /**
540
+ * snippet for rendering custom facet axes
541
+ */
477
542
  facetAxes: Snippet;
478
543
  /**
479
544
  * if you set testid, the plot container will get a data-testid attribute which
@@ -501,4 +566,41 @@ export type PlotOptions = {
501
566
  */
502
567
  sortOrdinalDomains: boolean;
503
568
  };
569
+ type ResolvedFacetXOptions = Partial<XScaleOptions> & {
570
+ /**
571
+ * customize base axis props used for rendering facet axis
572
+ */
573
+ axisProps?: Partial<ComponentProps<typeof BaseAxisX>>;
574
+ /**
575
+ * customize base axis options used for rendering facet axis
576
+ */
577
+ axisOptions?: Partial<ComponentProps<typeof BaseAxisX>['options']>;
578
+ };
579
+ type ResolvedFacetYOptions = Partial<YScaleOptions> & {
580
+ /**
581
+ * customize base axis props used for rendering facet axis
582
+ */
583
+ axisProps?: Partial<ComponentProps<typeof BaseAxisY>>;
584
+ /**
585
+ * customize base axis options used for rendering facet axis
586
+ */
587
+ axisOptions?: Partial<ComponentProps<typeof BaseAxisY>['options']>;
588
+ };
589
+ /**
590
+ * Internal plot options shape after shorthand forms (`false`, arrays) are normalized.
591
+ */
592
+ type ResolvedXScaleOptions = Partial<XScaleOptions> & {
593
+ tickSpacing: number;
594
+ ticks?: RawValue[];
595
+ };
596
+ type ResolvedYScaleOptions = Partial<YScaleOptions> & {
597
+ tickSpacing: number;
598
+ ticks?: RawValue[];
599
+ };
600
+ export type ResolvedPlotOptions = Omit<PlotOptions, 'x' | 'y' | 'fx' | 'fy'> & {
601
+ x: ResolvedXScaleOptions;
602
+ y: ResolvedYScaleOptions;
603
+ fx: ResolvedFacetXOptions;
604
+ fy: ResolvedFacetYOptions;
605
+ };
504
606
  export {};