@fundar/data-chart-telling 1.18.0 → 1.20.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 (252) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/README.md +2 -1
  3. package/dist/configuration/config.svelte.js +1 -1
  4. package/dist/index.d.ts +4 -2
  5. package/dist/index.js +2 -1
  6. package/dist/layout/coordinates/CoordinatesLayout.svelte +3 -1
  7. package/dist/layout/facet/FacetLayout.svelte +54 -41
  8. package/dist/layout/geometry/GeometryLayout.svelte +57 -22
  9. package/dist/layout/geometry/ScaleFreeContext.d.ts +31 -0
  10. package/dist/layout/geometry/ScaleFreeContext.js +65 -0
  11. package/dist/layout/geometry/ScaleFreeMarks.svelte +14 -0
  12. package/dist/layout/geometry/ScaleFreeMarks.svelte.d.ts +7 -0
  13. package/dist/layout/geometry/ScaleGate.svelte.d.ts +8 -0
  14. package/dist/layout/geometry/ScaleGate.svelte.js +95 -0
  15. package/dist/layout/geometry/ScaleGateMarks.svelte +15 -0
  16. package/dist/layout/geometry/ScaleGateMarks.svelte.d.ts +7 -0
  17. package/dist/layout/hover/HoverShapes.d.ts +20 -8
  18. package/dist/layout/hover/HoverShapes.js +119 -59
  19. package/dist/layout/legend/ContinuousSection.svelte +10 -0
  20. package/dist/layout/legend/LegendState.svelte.d.ts +13 -1
  21. package/dist/layout/legend/LegendState.svelte.js +32 -0
  22. package/dist/layout/margins/Box.d.ts +4 -0
  23. package/dist/layout/margins/Box.js +14 -0
  24. package/dist/layout/margins/PlotMargins.svelte.js +26 -1
  25. package/dist/layout/plot/{Plot.svelte → AbstractPlot.svelte} +83 -6
  26. package/dist/layout/plot/{Plot.svelte.d.ts → AbstractPlot.svelte.d.ts} +4 -4
  27. package/dist/layout/plot/PublicPlotContext.d.ts +5 -0
  28. package/dist/layout/plot/PublicPlotContext.js +7 -0
  29. package/dist/layout/styles/ValueLabels.d.ts +109 -58
  30. package/dist/layout/styles/ValueLabels.js +299 -141
  31. package/dist/markers/MarkerKinds.d.ts +79 -1
  32. package/dist/markers/MarkerKinds.js +149 -23
  33. package/dist/markers/area/AreaMarker.svelte +1 -1
  34. package/dist/markers/band/BandMarker.svelte +2 -1
  35. package/dist/markers/bar/BarMarker.svelte +8 -6
  36. package/dist/markers/bollinger/BollingerMarker.svelte +1 -1
  37. package/dist/markers/box/BoxMarker.svelte +1 -1
  38. package/dist/markers/dot/DotRadius.d.ts +11 -0
  39. package/dist/markers/dot/DotRadius.js +21 -0
  40. package/dist/markers/geo/GeoHoverMarker.svelte +14 -11
  41. package/dist/markers/labels/CurveLabel.svelte +56 -0
  42. package/dist/markers/labels/CurveLabel.svelte.d.ts +9 -0
  43. package/dist/markers/labels/LabelMerge.d.ts +11 -0
  44. package/dist/markers/labels/LabelMerge.js +87 -0
  45. package/dist/markers/labels/MarkerLabel.svelte +36 -0
  46. package/dist/markers/labels/MarkerLabel.svelte.d.ts +10 -0
  47. package/dist/markers/labels/MarkerLabels.d.ts +52 -0
  48. package/dist/markers/labels/MarkerLabels.js +97 -0
  49. package/dist/markers/labels/geometry/BoxGeometry.d.ts +8 -0
  50. package/dist/markers/labels/geometry/BoxGeometry.js +101 -0
  51. package/dist/markers/labels/geometry/CurveGeometry.d.ts +34 -0
  52. package/dist/markers/labels/geometry/CurveGeometry.js +193 -0
  53. package/dist/markers/labels/geometry/PointGeometry.d.ts +9 -0
  54. package/dist/markers/labels/geometry/PointGeometry.js +22 -0
  55. package/dist/markers/labels/layouts/BoxLayout.d.ts +10 -0
  56. package/dist/markers/labels/layouts/BoxLayout.js +49 -0
  57. package/dist/markers/labels/layouts/PathLayout.d.ts +11 -0
  58. package/dist/markers/labels/layouts/PathLayout.js +91 -0
  59. package/dist/markers/labels/layouts/PointLayout.d.ts +19 -0
  60. package/dist/markers/labels/layouts/PointLayout.js +94 -0
  61. package/dist/markers/regression/RegressionMarker.svelte +1 -1
  62. package/dist/markers/text/Covering.d.ts +13 -0
  63. package/dist/markers/text/Covering.js +29 -0
  64. package/dist/markers/text/Declutter.d.ts +24 -3
  65. package/dist/markers/text/Declutter.js +46 -3
  66. package/dist/markers/text/TextMarker.svelte +90 -17
  67. package/dist/markers/text/TextMarker.svelte.d.ts +1 -1
  68. package/dist/markers/tick/TickMarker.svelte +1 -1
  69. package/dist/markers/utils/MarkerChannels.d.ts +1 -1
  70. package/dist/markers/utils/MarkerChannels.js +3 -2
  71. package/dist/markers/violin/ViolinMarker.svelte +1 -1
  72. package/dist/markers/waffle/WaffleMarker.svelte +1 -1
  73. package/dist/phases/context/RowContext.d.ts +2 -0
  74. package/dist/phases/context/RowContext.js +4 -2
  75. package/dist/phases/context/rowContextKey.d.ts +2 -0
  76. package/dist/phases/context/rowContextKey.js +2 -0
  77. package/dist/phases/markers/MarkerStyles.js +14 -11
  78. package/dist/phases/markers/MarkersPhase.d.ts +2 -3
  79. package/dist/phases/markers/MarkersPhase.js +17 -11
  80. package/dist/phases/sharedScales/SharedStepScales.d.ts +10 -0
  81. package/dist/phases/sharedScales/SharedStepScales.js +43 -0
  82. package/dist/phases/statistics/MarkerGrouping.js +5 -32
  83. package/dist/phases/statistics/MarkerInheritance.d.ts +11 -0
  84. package/dist/phases/statistics/MarkerInheritance.js +25 -0
  85. package/dist/phases/statistics/MarkerOrientation.d.ts +26 -0
  86. package/dist/phases/statistics/MarkerOrientation.js +29 -0
  87. package/dist/phases/statistics/StatisticsPhase.js +15 -15
  88. package/dist/phases/transforms/TransformsPhase.js +5 -3
  89. package/dist/plots/correlation/heatmap/Plot.svelte +2 -2
  90. package/dist/plots/correlation/heatmap/Plot.svelte.d.ts +0 -1
  91. package/dist/plots/correlation/heatmap/defaults.js +14 -1
  92. package/dist/plots/correlation/heatmap/markers.d.ts +0 -6
  93. package/dist/plots/correlation/heatmap/markers.js +5 -9
  94. package/dist/plots/correlation/scatter/Plot.svelte +2 -2
  95. package/dist/plots/correlation/scatter/Plot.svelte.d.ts +0 -1
  96. package/dist/plots/correlation/scatter/defaults.js +9 -3
  97. package/dist/plots/correlation/scatter/markers.d.ts +0 -9
  98. package/dist/plots/correlation/scatter/markers.js +21 -28
  99. package/dist/plots/distribution/box/BoxSummaries.d.ts +5 -0
  100. package/dist/plots/distribution/box/BoxSummaries.js +9 -0
  101. package/dist/plots/distribution/box/Plot.svelte +2 -2
  102. package/dist/plots/distribution/box/Plot.svelte.d.ts +0 -1
  103. package/dist/plots/distribution/box/defaults.js +11 -0
  104. package/dist/plots/distribution/box/markers.js +10 -1
  105. package/dist/plots/distribution/density/Plot.svelte +2 -2
  106. package/dist/plots/distribution/density/Plot.svelte.d.ts +0 -1
  107. package/dist/plots/distribution/density/defaults.js +16 -0
  108. package/dist/plots/distribution/density/markers.js +5 -1
  109. package/dist/plots/distribution/histogram/Plot.svelte +2 -2
  110. package/dist/plots/distribution/histogram/Plot.svelte.d.ts +0 -1
  111. package/dist/plots/distribution/histogram/defaults.js +16 -11
  112. package/dist/plots/distribution/histogram/markers.js +3 -3
  113. package/dist/plots/distribution/pyramid/Plot.svelte +2 -2
  114. package/dist/plots/distribution/pyramid/Plot.svelte.d.ts +0 -1
  115. package/dist/plots/distribution/pyramid/defaults.js +9 -2
  116. package/dist/plots/distribution/pyramid/markers.d.ts +0 -8
  117. package/dist/plots/distribution/pyramid/markers.js +6 -16
  118. package/dist/plots/distribution/violin/Plot.svelte +2 -2
  119. package/dist/plots/distribution/violin/Plot.svelte.d.ts +0 -1
  120. package/dist/plots/distribution/violin/defaults.js +11 -0
  121. package/dist/plots/distribution/violin/markers.js +27 -3
  122. package/dist/plots/evolution/area/Plot.svelte +2 -2
  123. package/dist/plots/evolution/area/Plot.svelte.d.ts +0 -1
  124. package/dist/plots/evolution/area/defaults.js +4 -7
  125. package/dist/plots/evolution/area/markers.js +3 -1
  126. package/dist/plots/evolution/line/Plot.svelte +2 -2
  127. package/dist/plots/evolution/line/Plot.svelte.d.ts +0 -1
  128. package/dist/plots/evolution/line/defaults.js +4 -6
  129. package/dist/plots/evolution/line/markers.js +3 -1
  130. package/dist/plots/evolution/slope/Plot.svelte +2 -2
  131. package/dist/plots/evolution/slope/Plot.svelte.d.ts +0 -1
  132. package/dist/plots/evolution/slope/defaults.js +4 -3
  133. package/dist/plots/evolution/slope/markers.d.ts +4 -3
  134. package/dist/plots/evolution/slope/markers.js +16 -9
  135. package/dist/plots/evolution/sparkline/Plot.svelte +2 -2
  136. package/dist/plots/evolution/sparkline/Plot.svelte.d.ts +0 -1
  137. package/dist/plots/evolution/sparkline/defaults.js +1 -1
  138. package/dist/plots/evolution/sparkline/markers.js +3 -1
  139. package/dist/plots/generic/Plot.svelte +42 -0
  140. package/dist/plots/generic/Plot.svelte.d.ts +25 -0
  141. package/dist/plots/generic/defaults.d.ts +4 -0
  142. package/dist/plots/generic/defaults.js +7 -0
  143. package/dist/plots/map/geo/Core.svelte +29 -6
  144. package/dist/plots/map/geo/Plot.svelte +40 -12
  145. package/dist/plots/map/geo/Plot.svelte.d.ts +0 -1
  146. package/dist/plots/map/geo/phases/data.d.ts +2 -1
  147. package/dist/plots/map/geo/phases/data.js +8 -2
  148. package/dist/plots/map/geo/phases/scales.js +6 -2
  149. package/dist/plots/map/geo/slices.d.ts +27 -3
  150. package/dist/plots/map/geo/slices.js +58 -5
  151. package/dist/plots/part-of-a-whole/treemap/Plot.svelte +2 -2
  152. package/dist/plots/part-of-a-whole/treemap/Plot.svelte.d.ts +0 -1
  153. package/dist/plots/part-of-a-whole/treemap/defaults.js +2 -2
  154. package/dist/plots/ranking/bar/Plot.svelte +2 -2
  155. package/dist/plots/ranking/bar/Plot.svelte.d.ts +0 -1
  156. package/dist/plots/ranking/bar/defaults.js +13 -3
  157. package/dist/plots/ranking/bar/markers.js +12 -29
  158. package/dist/plots/ranking/bullet/Plot.svelte +2 -2
  159. package/dist/plots/ranking/bullet/Plot.svelte.d.ts +0 -1
  160. package/dist/plots/ranking/bullet/defaults.js +20 -0
  161. package/dist/plots/ranking/bullet/markers.js +7 -1
  162. package/dist/plots/ranking/cleveland/ClevelandMarkers.d.ts +2 -9
  163. package/dist/plots/ranking/cleveland/ClevelandMarkers.js +65 -47
  164. package/dist/plots/ranking/cleveland/Plot.svelte +2 -2
  165. package/dist/plots/ranking/cleveland/Plot.svelte.d.ts +0 -1
  166. package/dist/plots/ranking/cleveland/defaults.js +33 -2
  167. package/dist/plots/ranking/dumbbell/Plot.svelte +2 -2
  168. package/dist/plots/ranking/dumbbell/Plot.svelte.d.ts +0 -1
  169. package/dist/plots/ranking/forest/Plot.svelte +2 -2
  170. package/dist/plots/ranking/forest/Plot.svelte.d.ts +0 -1
  171. package/dist/plots/ranking/lollipop/Plot.svelte +2 -2
  172. package/dist/plots/ranking/lollipop/Plot.svelte.d.ts +0 -1
  173. package/dist/types/layout/context.d.ts +2 -0
  174. package/dist/types/layout/plot.d.ts +2 -0
  175. package/dist/types/layout/styles/bullet.d.ts +4 -1
  176. package/dist/types/layout/styles/geo.d.ts +3 -3
  177. package/dist/types/layout/styles/values.d.ts +51 -11
  178. package/dist/types/markers/axis/area.d.ts +5 -1
  179. package/dist/types/markers/axis/bar.d.ts +5 -2
  180. package/dist/types/markers/axis/bollinger.d.ts +2 -1
  181. package/dist/types/markers/axis/box.d.ts +2 -1
  182. package/dist/types/markers/axis/cell.d.ts +4 -1
  183. package/dist/types/markers/axis/line.d.ts +4 -1
  184. package/dist/types/markers/axis/rect.d.ts +4 -1
  185. package/dist/types/markers/axis/regression.d.ts +2 -1
  186. package/dist/types/markers/axis/tick.d.ts +2 -1
  187. package/dist/types/markers/axis/trail.d.ts +4 -1
  188. package/dist/types/markers/axis/violin.d.ts +2 -1
  189. package/dist/types/markers/axis/waffle.d.ts +5 -1
  190. package/dist/types/markers/basic/dot.d.ts +4 -1
  191. package/dist/types/markers/basic/text.d.ts +25 -21
  192. package/dist/types/markers/channels/commonMarkerConfigWithLabel.d.ts +5 -9
  193. package/dist/types/markers/channels/commonMarkerConfigWithOrientation.d.ts +5 -0
  194. package/dist/types/markers/channels/commonMarkerConfigWithOrientation.js +1 -0
  195. package/dist/types/markers/labels/box.d.ts +57 -0
  196. package/dist/types/markers/labels/box.js +1 -0
  197. package/dist/types/markers/labels/common.d.ts +15 -0
  198. package/dist/types/markers/labels/common.js +1 -0
  199. package/dist/types/markers/labels/path.d.ts +52 -0
  200. package/dist/types/markers/labels/path.js +1 -0
  201. package/dist/types/markers/labels/point.d.ts +40 -0
  202. package/dist/types/markers/labels/point.js +1 -0
  203. package/dist/types/markers/traits.d.ts +10 -0
  204. package/dist/types/phases/markers/phase.d.ts +1 -8
  205. package/dist/types/phases/statistics/phase.d.ts +8 -3
  206. package/dist/types/phases/styles/phase.d.ts +15 -3
  207. package/dist/types/phases/transforms/phase.d.ts +2 -0
  208. package/dist/types/plots/constants.d.ts +0 -12
  209. package/dist/types/plots/correlation/heatmap/props.d.ts +3 -2
  210. package/dist/types/plots/correlation/scatter/props.d.ts +3 -2
  211. package/dist/types/plots/data/geo.d.ts +19 -5
  212. package/dist/types/plots/distribution/box/props.d.ts +6 -2
  213. package/dist/types/plots/distribution/density/props.d.ts +2 -1
  214. package/dist/types/plots/distribution/histogram/props.d.ts +3 -2
  215. package/dist/types/plots/distribution/pyramid/props.d.ts +3 -2
  216. package/dist/types/plots/distribution/violin/props.d.ts +4 -1
  217. package/dist/types/plots/evolution/area/props.d.ts +3 -2
  218. package/dist/types/plots/evolution/line/props.d.ts +3 -2
  219. package/dist/types/plots/generic/props.d.ts +16 -0
  220. package/dist/types/plots/generic/props.js +1 -0
  221. package/dist/types/plots/generic/state.d.ts +4 -0
  222. package/dist/types/plots/generic/state.js +1 -0
  223. package/dist/types/plots/map/geo/props.d.ts +9 -3
  224. package/dist/types/plots/map/geo/state.d.ts +3 -1
  225. package/dist/types/plots/part-of-a-whole/treemap/props.d.ts +4 -2
  226. package/dist/types/plots/ranking/bar/props.d.ts +3 -2
  227. package/dist/types/plots/ranking/cleveland/props.d.ts +3 -2
  228. package/dist/types/plots/ranking/dumbbell/props.d.ts +3 -2
  229. package/dist/types/plots/ranking/forest/props.d.ts +5 -2
  230. package/dist/types/plots/ranking/lollipop/props.d.ts +3 -2
  231. package/dist/utils/ConfigEquality.d.ts +11 -0
  232. package/dist/utils/ConfigEquality.js +37 -0
  233. package/docs/architecture.md +9 -9
  234. package/docs/facets.md +12 -0
  235. package/docs/geo.md +35 -7
  236. package/docs/legend.md +6 -0
  237. package/docs/markers.md +2 -4
  238. package/docs/plots/ranking/bar.md +1 -1
  239. package/docs/plots/ranking/cleveland.md +1 -1
  240. package/docs/state.md +1 -1
  241. package/docs/styles-and-segments.md +1 -14
  242. package/docs/timeline.md +1 -1
  243. package/docs/transforms-and-statistics.md +1 -1
  244. package/docs/value-labels.md +159 -0
  245. package/examples/BarValues.svelte +1 -1
  246. package/llms-full.txt +5 -5
  247. package/llms.txt +1 -0
  248. package/package.json +3 -1
  249. package/dist/markers/utils/BoxLabel.d.ts +0 -58
  250. package/dist/markers/utils/BoxLabel.js +0 -175
  251. package/dist/markers/utils/MarkerLabel.svelte +0 -33
  252. package/dist/markers/utils/MarkerLabel.svelte.d.ts +0 -10
@@ -1,58 +0,0 @@
1
- import type { TextMarkerConfig } from '../../types/markers/common';
2
- import type { TextLabelConfig } from '../../types/markers/basic/text';
3
- /** Where a row's edge along an axis is: a field of the rows, the symbol a transform keyed it by, a function of the row, or a literal. */
4
- type Edge = unknown;
5
- /** The edges of the box each row spans, in the data's own terms. */
6
- export type BoxChannels = {
7
- x1: Edge;
8
- x2: Edge;
9
- y1: Edge;
10
- y2: Edge;
11
- };
12
- /** The scales a box is measured on. */
13
- export type BoxScales = Record<string, {
14
- type?: string;
15
- fn: any;
16
- } | undefined>;
17
- /** The pixel size of the box of a row, for the markers whose boxes are bands of a category axis rather than edges. */
18
- export type BoxSizer = (row: unknown, scales: BoxScales) => {
19
- width: number;
20
- height: number;
21
- } | undefined;
22
- /** The `text` marker that labels the boxes a marker draws, and where each label's box is. */
23
- export type BoxLabelMarker = {
24
- marker: TextMarkerConfig;
25
- box: BoxChannels | BoxSizer;
26
- };
27
- /** What a marker has to say for its boxes to be labelled. */
28
- export type Labelled = {
29
- type?: string;
30
- data?: unknown[];
31
- label?: TextLabelConfig;
32
- x?: Edge;
33
- y?: Edge;
34
- x1?: Edge;
35
- x2?: Edge;
36
- y1?: Edge;
37
- y2?: Edge;
38
- isHorizontal?: boolean;
39
- role?: string;
40
- thickness?: number;
41
- /** The marker's styles: the insets of a cell or a bar are read off them. */
42
- styles?: object;
43
- };
44
- /**
45
- * How a marker that draws a box per row writes a label in each: the `text` marker for them, centred on the box,
46
- * and where the box is for it to fit to. A `rect` says it with its edges, a `cell` is a band of each axis, and a bar
47
- * or a waffle is a band of its category axis and the stretch of its value.
48
- */
49
- export declare class BoxLabel {
50
- #private;
51
- /** `undefined` when the marker has no label, or does not say where its boxes are. */
52
- static of(marker: Labelled, plot?: {
53
- isHorizontal?: boolean;
54
- scales?: () => BoxScales | undefined;
55
- gap?: number;
56
- }): BoxLabelMarker | undefined;
57
- }
58
- export {};
@@ -1,175 +0,0 @@
1
- const read = (edge) => (row) => typeof edge === 'function'
2
- ? edge(row)
3
- : typeof edge === 'string' || typeof edge === 'symbol'
4
- ? row?.[edge]
5
- : edge;
6
- /** The middle of two positions along an axis, whether numbers or dates. */
7
- const middle = (from, to) => from instanceof Date || to instanceof Date
8
- ? new Date((Number(from) + Number(to)) / 2)
9
- : (Number(from) + Number(to)) / 2;
10
- const bandwidth = (scale) => scale?.type === 'band' ? Number(scale.fn.bandwidth()) : undefined;
11
- const distance = (scale, from, to) => scale ? Math.abs(Number(scale.fn(to)) - Number(scale.fn(from))) : undefined;
12
- /**
13
- * How a marker that draws a box per row writes a label in each: the `text` marker for them, centred on the box,
14
- * and where the box is for it to fit to. A `rect` says it with its edges, a `cell` is a band of each axis, and a bar
15
- * or a waffle is a band of its category axis and the stretch of its value.
16
- */
17
- export class BoxLabel {
18
- /** `undefined` when the marker has no label, or does not say where its boxes are. */
19
- static of(marker, plot = {}) {
20
- if (!marker.label)
21
- return undefined;
22
- const own = BoxLabel.#shape(marker, plot.isHorizontal ?? marker.isHorizontal ?? false);
23
- if (!own)
24
- return undefined;
25
- const { anchor, outside, gap, ...label } = marker.label;
26
- const size = typeof own.box === 'function' ? own.box : own.size;
27
- const placed = BoxLabel.#anchored({
28
- anchor,
29
- outside,
30
- gap: gap ?? plot.gap
31
- }, label, size, plot.scales);
32
- return {
33
- box: own.box,
34
- marker: {
35
- // A label outside its shape has nothing to fit to.
36
- fit: !outside,
37
- ...label,
38
- ...placed,
39
- type: 'text',
40
- data: marker.data,
41
- x: own.x,
42
- y: own.y
43
- }
44
- };
45
- }
46
- /**
47
- * What puts a label at `anchor` of its shape: the pixels it is moved from the middle - a function of the row, for
48
- * the size of its shape is the row's own - and the sides of its point it is written on. `{}` for the middle.
49
- */
50
- static #anchored(where, label, size, scales) {
51
- const { anchor = 'middle', outside = false } = where;
52
- if (anchor === 'middle' || !size)
53
- return {};
54
- const gap = where.gap ?? 4;
55
- const horizontal = anchor.endsWith('left') ? -1 : anchor.endsWith('right') ? 1 : 0;
56
- const vertical = anchor.startsWith('top') ? -1 : anchor.startsWith('bottom') ? 1 : 0;
57
- // Beyond an edge only means something for an edge: a corner is inside its shape.
58
- const beyond = outside && horizontal * vertical === 0;
59
- const away = beyond ? 1 : -1;
60
- const move = (axis, side, row) => {
61
- // Read when a label is drawn, not when its marker is made: the scales move as the labels register.
62
- const current = scales?.();
63
- const box = current ? size(row, current) : undefined;
64
- return box ? side * (box[axis] / 2 + away * gap) : 0;
65
- };
66
- // A number of the label's own (or its styles') is added to the move: it is the push from the anchor.
67
- const own = (value, fallback) => Number(typeof value === 'number' ? value : (fallback ?? 0));
68
- const baseX = own(label.dx, label.styles?.dx);
69
- const baseY = own(label.dy, label.styles?.dy);
70
- return {
71
- dx: horizontal === 0 ? label.dx : (row) => baseX + move('width', horizontal, row),
72
- dy: vertical === 0 ? label.dy : (row) => baseY + move('height', vertical, row),
73
- styles: {
74
- ...label.styles,
75
- textAnchor: label.styles?.textAnchor ??
76
- (horizontal === 0 ? 'middle' : (horizontal === 1) === beyond ? 'start' : 'end'),
77
- lineAnchor: label.styles?.lineAnchor ??
78
- (vertical === 0 ? 'middle' : (vertical === 1) === beyond ? 'top' : 'bottom')
79
- }
80
- };
81
- }
82
- /** A style of the marker, when it is a number: a function of the row says nothing of a box in general. */
83
- static #style(marker, name) {
84
- const value = marker.styles?.[name];
85
- return typeof value === 'number' ? value : undefined;
86
- }
87
- static #shape(marker, isHorizontal) {
88
- if (marker.type === 'cell')
89
- return BoxLabel.#cell(marker);
90
- if (marker.type === 'bar') {
91
- return marker.role === 'segment'
92
- ? BoxLabel.#bar(marker, marker.isHorizontal ?? false)
93
- : undefined;
94
- }
95
- if (marker.type === 'waffle')
96
- return BoxLabel.#bar(marker, isHorizontal);
97
- return BoxLabel.#edges(marker);
98
- }
99
- /** A rectangle: the box is between its edges. */
100
- static #edges({ x, y, x1, x2, y1, y2 }) {
101
- // A side with a value and no start, next to one with both its edges, runs from zero to it, as a bar does.
102
- if (y1 === undefined &&
103
- y2 === undefined &&
104
- y !== undefined &&
105
- x1 !== undefined &&
106
- x2 !== undefined) {
107
- [y1, y2] = [0, y];
108
- }
109
- if (x1 === undefined &&
110
- x2 === undefined &&
111
- x !== undefined &&
112
- y1 !== undefined &&
113
- y2 !== undefined) {
114
- [x1, x2] = [0, x];
115
- }
116
- if ([x1, x2, y1, y2].some((edge) => edge === undefined))
117
- return undefined;
118
- const [left, right, top, bottom] = [x1, x2, y1, y2].map(read);
119
- const size = (row, scales) => {
120
- const [width, height] = [
121
- distance(scales.x, left(row), right(row)),
122
- distance(scales.y, top(row), bottom(row))
123
- ];
124
- return width === undefined || height === undefined ? undefined : { width, height };
125
- };
126
- return {
127
- box: { x1, x2, y1, y2 },
128
- size,
129
- x: (row) => middle(left(row), right(row)),
130
- y: (row) => middle(top(row), bottom(row))
131
- };
132
- }
133
- /** A cell: a band of each axis, less its inset. */
134
- static #cell(marker) {
135
- if (marker.x === undefined || marker.y === undefined)
136
- return undefined;
137
- const inset = Number(BoxLabel.#style(marker, 'inset') ?? 0.5);
138
- const box = (_, scales) => {
139
- const [width, height] = [bandwidth(scales.x), bandwidth(scales.y)];
140
- return width === undefined || height === undefined
141
- ? undefined
142
- : { width: width - 2 * inset, height: height - 2 * inset };
143
- };
144
- return { box: box, x: marker.x, y: marker.y };
145
- }
146
- /** A bar or a waffle: a band of the category axis, as wide as its insets leave it, and as long as its value. */
147
- static #bar(marker, isHorizontal) {
148
- const [category, from, to] = isHorizontal
149
- ? [marker.y, marker.x1, marker.x2]
150
- : [marker.x, marker.y1, marker.y2];
151
- const value = isHorizontal ? marker.x : marker.y;
152
- // Without both ends, the bar runs from zero to its value.
153
- const [start, end] = from !== undefined && to !== undefined ? [from, to] : [0, value];
154
- if (category === undefined || end === undefined)
155
- return undefined;
156
- const [first, last] = [start, end].map(read);
157
- const [before, after] = isHorizontal
158
- ? [BoxLabel.#style(marker, 'insetTop'), BoxLabel.#style(marker, 'insetBottom')]
159
- : [BoxLabel.#style(marker, 'insetLeft'), BoxLabel.#style(marker, 'insetRight')];
160
- const middleOf = (row) => middle(first(row), last(row));
161
- const box = (row, scales) => {
162
- const band = bandwidth(isHorizontal ? scales.y : scales.x);
163
- const length = distance(isHorizontal ? scales.x : scales.y, first(row), last(row));
164
- if (band === undefined || length === undefined)
165
- return undefined;
166
- const thickness = marker.thickness ?? band * (1 - Number(before ?? 0) - Number(after ?? 0));
167
- return isHorizontal
168
- ? { width: length, height: thickness }
169
- : { width: thickness, height: length };
170
- };
171
- return isHorizontal
172
- ? { box: box, x: middleOf, y: category }
173
- : { box: box, x: category, y: middleOf };
174
- }
175
- }
@@ -1,33 +0,0 @@
1
- <script lang="ts">
2
- import TextMarker from '../text/TextMarker.svelte';
3
- import { getConfiguration } from '../../configuration/config.svelte';
4
- import { usePlot } from '../../layout/plot/usePlot';
5
- import { BoxLabel, type Labelled } from './BoxLabel';
6
- import { MARK_EVENTS } from '../../types/markers/channels/commonMarkerEvents';
7
- import type { TextLabelConfig } from '../../types/markers/basic/text';
8
-
9
- /**
10
- * The `label` of a marker that draws a box per row: a `text` marker anchored in each box and fitted to it. A marker
11
- * with a label only has to render `<MarkerLabel {marker} />` after its own shapes. Nothing is drawn without a
12
- * `label`, or when the marker does not say where its boxes are.
13
- */
14
- const { marker }: { marker: Labelled & { label?: TextLabelConfig } } = $props();
15
- const plot = usePlot();
16
- const cfg = $derived(getConfiguration());
17
-
18
- const labelled = $derived(
19
- BoxLabel.of(marker, {
20
- isHorizontal: plot.axes?.isHorizontal,
21
- gap: cfg.text.label.gap,
22
- scales: () => plot.svelteplot.scales as never
23
- })
24
- );
25
- /** A label with a handler of its own listens for the pointer; one without leaves it to the shape under it. */
26
- const listens = $derived(MARK_EVENTS.some((name) => !!marker.label?.[name]));
27
- </script>
28
-
29
- {#if labelled}
30
- <g pointer-events={listens ? undefined : 'none'}>
31
- <TextMarker marker={labelled.marker} box={labelled.box} />
32
- </g>
33
- {/if}
@@ -1,10 +0,0 @@
1
- import { type Labelled } from './BoxLabel';
2
- import type { TextLabelConfig } from '../../types/markers/basic/text';
3
- type $$ComponentProps = {
4
- marker: Labelled & {
5
- label?: TextLabelConfig;
6
- };
7
- };
8
- declare const MarkerLabel: import("svelte").Component<$$ComponentProps, {}, "">;
9
- type MarkerLabel = ReturnType<typeof MarkerLabel>;
10
- export default MarkerLabel;