@rokkit/chart 1.3.7 → 1.3.9

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 (162) hide show
  1. package/dist/AnimatedPlot.svelte +26 -8
  2. package/dist/AnimatedPlot.svelte.d.ts +5 -0
  3. package/dist/Chart.svelte +51 -65
  4. package/dist/FacetPlot.svelte +1 -1
  5. package/dist/Plot/Axis.svelte +19 -10
  6. package/dist/Plot/Root.svelte +67 -46
  7. package/dist/Plot/Root.svelte.d.ts +29 -2
  8. package/dist/Plot/Timeline.svelte +39 -13
  9. package/dist/Plot/index.d.ts +5 -5
  10. package/dist/Plot/index.js +5 -5
  11. package/dist/Plot.svelte +95 -178
  12. package/dist/Plot.svelte.d.ts +4 -0
  13. package/dist/PlotState.svelte.d.ts +29 -1
  14. package/dist/PlotState.svelte.js +163 -19
  15. package/dist/PlotSurface.svelte +162 -0
  16. package/dist/PlotSurface.svelte.d.ts +25 -0
  17. package/dist/charts/AreaChart.svelte +12 -2
  18. package/dist/charts/AreaChart.svelte.d.ts +6 -0
  19. package/dist/charts/BarChart.svelte +40 -4
  20. package/dist/charts/BarChart.svelte.d.ts +15 -1
  21. package/dist/charts/BoxPlot.svelte +7 -3
  22. package/dist/charts/BoxPlot.svelte.d.ts +2 -0
  23. package/dist/charts/BubbleChart.svelte +37 -4
  24. package/dist/charts/BubbleChart.svelte.d.ts +12 -1
  25. package/dist/charts/LineChart.svelte +4 -2
  26. package/dist/charts/LineChart.svelte.d.ts +1 -0
  27. package/dist/charts/PieChart.svelte +5 -3
  28. package/dist/charts/PieChart.svelte.d.ts +1 -0
  29. package/dist/charts/ScatterPlot.svelte +35 -4
  30. package/dist/charts/ScatterPlot.svelte.d.ts +11 -1
  31. package/dist/charts/ViolinPlot.svelte +7 -3
  32. package/dist/charts/ViolinPlot.svelte.d.ts +2 -0
  33. package/dist/examples/BarChartExample.svelte +1 -1
  34. package/dist/geoms/Arc.svelte +21 -54
  35. package/dist/geoms/Arc.svelte.d.ts +4 -4
  36. package/dist/geoms/Area.svelte +45 -44
  37. package/dist/geoms/Area.svelte.d.ts +8 -1
  38. package/dist/geoms/Bar.svelte +33 -45
  39. package/dist/geoms/Bar.svelte.d.ts +9 -0
  40. package/dist/geoms/Box.svelte +103 -61
  41. package/dist/geoms/Box.svelte.d.ts +12 -3
  42. package/dist/geoms/Candlestick.svelte +26 -75
  43. package/dist/geoms/Candlestick.svelte.d.ts +2 -0
  44. package/dist/geoms/Heatmap.svelte +21 -66
  45. package/dist/geoms/Heatmap.svelte.d.ts +2 -0
  46. package/dist/geoms/Hexbin.svelte +20 -100
  47. package/dist/geoms/Hexbin.svelte.d.ts +2 -0
  48. package/dist/geoms/Jitter.svelte +67 -0
  49. package/dist/geoms/Jitter.svelte.d.ts +17 -0
  50. package/dist/geoms/Line.svelte +27 -31
  51. package/dist/geoms/Line.svelte.d.ts +5 -0
  52. package/dist/geoms/Point.svelte +31 -60
  53. package/dist/geoms/Point.svelte.d.ts +5 -1
  54. package/dist/geoms/Ribbon.svelte +30 -124
  55. package/dist/geoms/Ribbon.svelte.d.ts +2 -0
  56. package/dist/geoms/Rule.svelte +117 -0
  57. package/dist/geoms/Rule.svelte.d.ts +19 -0
  58. package/dist/geoms/Violin.svelte +36 -31
  59. package/dist/geoms/Violin.svelte.d.ts +10 -3
  60. package/dist/geoms/Waterfall.svelte +25 -79
  61. package/dist/geoms/Waterfall.svelte.d.ts +2 -0
  62. package/dist/geoms/lib/GeomState.svelte.d.ts +51 -0
  63. package/dist/geoms/lib/GeomState.svelte.js +79 -0
  64. package/dist/geoms/lib/aesthetics.d.ts +36 -0
  65. package/dist/geoms/lib/aesthetics.js +45 -0
  66. package/dist/geoms/lib/areas.d.ts +6 -2
  67. package/dist/geoms/lib/areas.js +20 -12
  68. package/dist/geoms/lib/bars.d.ts +18 -3
  69. package/dist/geoms/lib/bars.js +80 -101
  70. package/dist/geoms/lib/marks/arc.d.ts +24 -0
  71. package/dist/geoms/lib/marks/arc.js +28 -0
  72. package/dist/geoms/lib/marks/area.d.ts +23 -0
  73. package/dist/geoms/lib/marks/area.js +38 -0
  74. package/dist/geoms/lib/marks/bar.d.ts +16 -0
  75. package/dist/geoms/lib/marks/bar.js +43 -0
  76. package/dist/geoms/lib/marks/box.d.ts +14 -0
  77. package/dist/geoms/lib/marks/box.js +30 -0
  78. package/dist/geoms/lib/marks/candlestick.d.ts +27 -0
  79. package/dist/geoms/lib/marks/candlestick.js +52 -0
  80. package/dist/geoms/lib/marks/heatmap.d.ts +24 -0
  81. package/dist/geoms/lib/marks/heatmap.js +41 -0
  82. package/dist/geoms/lib/marks/hexbin.d.ts +29 -0
  83. package/dist/geoms/lib/marks/hexbin.js +62 -0
  84. package/dist/geoms/lib/marks/jitter.d.ts +21 -0
  85. package/dist/geoms/lib/marks/jitter.js +36 -0
  86. package/dist/geoms/lib/marks/line.d.ts +26 -0
  87. package/dist/geoms/lib/marks/line.js +25 -0
  88. package/dist/geoms/lib/marks/point.d.ts +25 -0
  89. package/dist/geoms/lib/marks/point.js +58 -0
  90. package/dist/geoms/lib/marks/ribbon.d.ts +31 -0
  91. package/dist/geoms/lib/marks/ribbon.js +77 -0
  92. package/dist/geoms/lib/marks/violin.d.ts +13 -0
  93. package/dist/geoms/lib/marks/violin.js +31 -0
  94. package/dist/geoms/lib/marks/waterfall.d.ts +25 -0
  95. package/dist/geoms/lib/marks/waterfall.js +58 -0
  96. package/dist/index.d.ts +25 -12
  97. package/dist/index.js +26 -13
  98. package/dist/lib/brewing/marks/arcs.js +7 -1
  99. package/dist/lib/brewing/marks/boxes.d.ts +11 -2
  100. package/dist/lib/brewing/marks/boxes.js +32 -11
  101. package/dist/lib/brewing/marks/lines.d.ts +4 -1
  102. package/dist/lib/brewing/marks/lines.js +18 -15
  103. package/dist/lib/brewing/marks/swarm.d.ts +32 -0
  104. package/dist/lib/brewing/marks/swarm.js +125 -0
  105. package/dist/lib/brewing/marks/violins.d.ts +4 -20
  106. package/dist/lib/brewing/marks/violins.js +41 -25
  107. package/dist/lib/brewing/stats.d.ts +3 -1
  108. package/dist/lib/brewing/stats.js +28 -11
  109. package/dist/lib/plot/scales.js +12 -7
  110. package/dist/lib/plot/types.d.ts +9 -1
  111. package/dist/lib/plot/types.js +3 -1
  112. package/dist/lib/preset.d.ts +11 -1
  113. package/dist/lib/preset.js +16 -4
  114. package/package.json +1 -1
  115. package/dist/Plot/Arc.svelte +0 -30
  116. package/dist/Plot/Arc.svelte.d.ts +0 -18
  117. package/dist/Plot/Area.svelte +0 -54
  118. package/dist/Plot/Area.svelte.d.ts +0 -14
  119. package/dist/Plot/Bar.svelte +0 -69
  120. package/dist/Plot/Bar.svelte.d.ts +0 -11
  121. package/dist/Plot/Line.svelte +0 -54
  122. package/dist/Plot/Line.svelte.d.ts +0 -13
  123. package/dist/Plot/Point.svelte +0 -58
  124. package/dist/Plot/Point.svelte.d.ts +0 -13
  125. package/dist/lib/brewer.d.ts +0 -9
  126. package/dist/lib/brewer.js +0 -25
  127. package/dist/lib/brewing/BoxBrewer.svelte.d.ts +0 -8
  128. package/dist/lib/brewing/BoxBrewer.svelte.js +0 -14
  129. package/dist/lib/brewing/CartesianBrewer.svelte.d.ts +0 -8
  130. package/dist/lib/brewing/CartesianBrewer.svelte.js +0 -21
  131. package/dist/lib/brewing/PieBrewer.svelte.d.ts +0 -8
  132. package/dist/lib/brewing/PieBrewer.svelte.js +0 -14
  133. package/dist/lib/brewing/QuartileBrewer.svelte.d.ts +0 -9
  134. package/dist/lib/brewing/QuartileBrewer.svelte.js +0 -51
  135. package/dist/lib/brewing/ViolinBrewer.svelte.d.ts +0 -8
  136. package/dist/lib/brewing/ViolinBrewer.svelte.js +0 -14
  137. package/dist/lib/brewing/axes.svelte.d.ts +0 -66
  138. package/dist/lib/brewing/axes.svelte.js +0 -270
  139. package/dist/lib/brewing/bars.svelte.d.ts +0 -56
  140. package/dist/lib/brewing/bars.svelte.js +0 -201
  141. package/dist/lib/brewing/brewer.svelte.d.ts +0 -124
  142. package/dist/lib/brewing/brewer.svelte.js +0 -277
  143. package/dist/lib/brewing/dimensions.svelte.d.ts +0 -35
  144. package/dist/lib/brewing/dimensions.svelte.js +0 -56
  145. package/dist/lib/brewing/index.svelte.d.ts +0 -118
  146. package/dist/lib/brewing/index.svelte.js +0 -205
  147. package/dist/lib/brewing/legends.svelte.d.ts +0 -48
  148. package/dist/lib/brewing/legends.svelte.js +0 -137
  149. package/dist/lib/brewing/marks/areas.d.ts +0 -31
  150. package/dist/lib/brewing/marks/areas.js +0 -72
  151. package/dist/lib/brewing/marks/bars.d.ts +0 -1
  152. package/dist/lib/brewing/marks/bars.js +0 -49
  153. package/dist/lib/brewing/scales.svelte.d.ts +0 -24
  154. package/dist/lib/brewing/scales.svelte.js +0 -82
  155. package/dist/lib/context.d.ts +0 -13
  156. package/dist/lib/context.js +0 -131
  157. package/dist/lib/plot/chartProps.d.ts +0 -177
  158. package/dist/lib/plot/chartProps.js +0 -76
  159. package/dist/lib/scales.svelte.d.ts +0 -35
  160. package/dist/lib/scales.svelte.js +0 -151
  161. package/dist/lib/ticks.d.ts +0 -36
  162. package/dist/lib/ticks.js +0 -46
@@ -1,177 +0,0 @@
1
- /**
2
- * Common props shared by all high-level chart wrappers.
3
- */
4
- export type ChartProps = {
5
- /**
6
- * - Data array to visualize
7
- */
8
- data?: Object[] | undefined;
9
- /**
10
- * - Field name for the X axis
11
- */
12
- x?: string | undefined;
13
- /**
14
- * - Field name for the Y axis
15
- */
16
- y?: string | undefined;
17
- /**
18
- * - Field name for fill color grouping (alias for color)
19
- */
20
- fill?: string | undefined;
21
- /**
22
- * - Field name for color grouping
23
- */
24
- color?: string | undefined;
25
- /**
26
- * - Field name for pattern fill grouping
27
- */
28
- pattern?: string | undefined;
29
- /**
30
- * - Aggregation stat: 'identity' | 'sum' | 'mean' | 'count' | 'min' | 'max' | 'median' | 'boxplot'
31
- */
32
- stat?: string | undefined;
33
- /**
34
- * - SVG width in pixels
35
- */
36
- width?: number | undefined;
37
- /**
38
- * - SVG height in pixels
39
- */
40
- height?: number | undefined;
41
- /**
42
- * - Color mode: 'light' | 'dark'
43
- */
44
- mode?: string | undefined;
45
- /**
46
- * - Whether to show grid lines
47
- */
48
- grid?: boolean | undefined;
49
- /**
50
- * - Whether to show the legend
51
- */
52
- legend?: boolean | undefined;
53
- };
54
- export type BarChartProps = Object;
55
- export type PieChartProps = {
56
- /**
57
- * - Data array to visualize
58
- */
59
- data?: Object[] | undefined;
60
- /**
61
- * - Field name for slice labels (drives color key)
62
- */
63
- label?: string | undefined;
64
- /**
65
- * - Field name for slice values (theta)
66
- */
67
- y?: string | undefined;
68
- /**
69
- * - Alternative to label for color grouping
70
- */
71
- fill?: string | undefined;
72
- /**
73
- * - Inner radius as fraction of outer (0=pie, 0.5=donut)
74
- */
75
- innerRadius?: number | undefined;
76
- /**
77
- * - Aggregation stat (default sum for pie charts)
78
- */
79
- stat?: string | undefined;
80
- /**
81
- * - SVG width in pixels
82
- */
83
- width?: number | undefined;
84
- /**
85
- * - SVG height in pixels
86
- */
87
- height?: number | undefined;
88
- /**
89
- * - Color mode: 'light' | 'dark'
90
- */
91
- mode?: string | undefined;
92
- /**
93
- * - Whether to show the legend
94
- */
95
- legend?: boolean | undefined;
96
- };
97
- export type BoxViolinChartProps = {
98
- /**
99
- * - Data array to visualize
100
- */
101
- data?: Object[] | undefined;
102
- /**
103
- * - Field name for the category axis (groups)
104
- */
105
- x?: string | undefined;
106
- /**
107
- * - Field name for the value axis (raw observations)
108
- */
109
- y?: string | undefined;
110
- /**
111
- * - Field name for fill color; when different from x, sub-groups within each x-band (like grouped bars); lighter shade used for body, darker shade for whiskers/outline
112
- */
113
- fill?: string | undefined;
114
- /**
115
- * - SVG width in pixels
116
- */
117
- width?: number | undefined;
118
- /**
119
- * - SVG height in pixels
120
- */
121
- height?: number | undefined;
122
- /**
123
- * - Color mode: 'light' | 'dark'
124
- */
125
- mode?: string | undefined;
126
- /**
127
- * - Whether to show grid lines
128
- */
129
- grid?: boolean | undefined;
130
- /**
131
- * - Whether to show the legend
132
- */
133
- legend?: boolean | undefined;
134
- };
135
- export type ScatterBubbleChartProps = {
136
- /**
137
- * - Data array to visualize
138
- */
139
- data?: Object[] | undefined;
140
- /**
141
- * - Field name for X position
142
- */
143
- x?: string | undefined;
144
- /**
145
- * - Field name for Y position
146
- */
147
- y?: string | undefined;
148
- /**
149
- * - Field name for color grouping
150
- */
151
- color?: string | undefined;
152
- /**
153
- * - Field name for point radius (BubbleChart: required)
154
- */
155
- size?: string | undefined;
156
- /**
157
- * - SVG width in pixels
158
- */
159
- width?: number | undefined;
160
- /**
161
- * - SVG height in pixels
162
- */
163
- height?: number | undefined;
164
- /**
165
- * - Color mode: 'light' | 'dark'
166
- */
167
- mode?: string | undefined;
168
- /**
169
- * - Whether to show grid lines
170
- */
171
- grid?: boolean | undefined;
172
- /**
173
- * - Whether to show the legend
174
- */
175
- legend?: boolean | undefined;
176
- };
177
- export type LineAreaChartProps = Object;
@@ -1,76 +0,0 @@
1
- /**
2
- * Shared JSDoc type definitions for chart component props.
3
- * Import these in chart components with:
4
- * @type {import('./lib/plot/chartProps.js').ChartProps}
5
- */
6
-
7
- /**
8
- * @typedef {Object} ChartProps
9
- * Common props shared by all high-level chart wrappers.
10
- *
11
- * @property {Object[]} [data=[]] - Data array to visualize
12
- * @property {string} [x] - Field name for the X axis
13
- * @property {string} [y] - Field name for the Y axis
14
- * @property {string} [fill] - Field name for fill color grouping (alias for color)
15
- * @property {string} [color] - Field name for color grouping
16
- * @property {string} [pattern] - Field name for pattern fill grouping
17
- * @property {string} [stat='identity']- Aggregation stat: 'identity' | 'sum' | 'mean' | 'count' | 'min' | 'max' | 'median' | 'boxplot'
18
- * @property {number} [width=600] - SVG width in pixels
19
- * @property {number} [height=400] - SVG height in pixels
20
- * @property {string} [mode='light'] - Color mode: 'light' | 'dark'
21
- * @property {boolean} [grid=true] - Whether to show grid lines
22
- * @property {boolean} [legend=false] - Whether to show the legend
23
- */
24
-
25
- /**
26
- * @typedef {Object} BarChartProps
27
- * @extends ChartProps
28
- * @property {boolean} [stack=false] - Stack bars (true) or group them (false)
29
- */
30
-
31
- /**
32
- * @typedef {Object} PieChartProps
33
- * @property {Object[]} [data=[]] - Data array to visualize
34
- * @property {string} [label] - Field name for slice labels (drives color key)
35
- * @property {string} [y] - Field name for slice values (theta)
36
- * @property {string} [fill] - Alternative to label for color grouping
37
- * @property {number} [innerRadius=0] - Inner radius as fraction of outer (0=pie, 0.5=donut)
38
- * @property {string} [stat='sum'] - Aggregation stat (default sum for pie charts)
39
- * @property {number} [width=400] - SVG width in pixels
40
- * @property {number} [height=400] - SVG height in pixels
41
- * @property {string} [mode='light'] - Color mode: 'light' | 'dark'
42
- * @property {boolean} [legend=false] - Whether to show the legend
43
- */
44
-
45
- /**
46
- * @typedef {Object} BoxViolinChartProps
47
- * @property {Object[]} [data=[]] - Data array to visualize
48
- * @property {string} [x] - Field name for the category axis (groups)
49
- * @property {string} [y] - Field name for the value axis (raw observations)
50
- * @property {string} [fill] - Field name for fill color; when different from x, sub-groups within each x-band (like grouped bars); lighter shade used for body, darker shade for whiskers/outline
51
- * @property {number} [width=600] - SVG width in pixels
52
- * @property {number} [height=400] - SVG height in pixels
53
- * @property {string} [mode='light'] - Color mode: 'light' | 'dark'
54
- * @property {boolean} [grid=true] - Whether to show grid lines
55
- * @property {boolean} [legend=false] - Whether to show the legend
56
- */
57
-
58
- /**
59
- * @typedef {Object} ScatterBubbleChartProps
60
- * @property {Object[]} [data=[]] - Data array to visualize
61
- * @property {string} [x] - Field name for X position
62
- * @property {string} [y] - Field name for Y position
63
- * @property {string} [color] - Field name for color grouping
64
- * @property {string} [size] - Field name for point radius (BubbleChart: required)
65
- * @property {number} [width=600] - SVG width in pixels
66
- * @property {number} [height=400] - SVG height in pixels
67
- * @property {string} [mode='light'] - Color mode: 'light' | 'dark'
68
- * @property {boolean} [grid=true] - Whether to show grid lines
69
- * @property {boolean} [legend=false] - Whether to show the legend
70
- */
71
-
72
- /**
73
- * @typedef {Object} LineAreaChartProps
74
- * @extends ChartProps
75
- * @property {string} [curve] - Line interpolation: 'linear' | 'smooth' | 'step'
76
- */
@@ -1,35 +0,0 @@
1
- export function createScales(data: any, dimensions: any, options: any): {
2
- xScale?: undefined;
3
- yScale?: undefined;
4
- colorScale?: undefined;
5
- } | {
6
- xScale: import("d3-scale").ScaleBand<any> | import("d3-scale").ScaleContinuousNumeric<any, any, never>;
7
- yScale: import("d3-scale").ScaleLinear<number, number, never>;
8
- colorScale: Object | null;
9
- };
10
- /**
11
- * Calculates the actual chart dimensions after applying margins
12
- *
13
- * @param {number} width
14
- * @param {number} height
15
- * @param {Object} margin
16
- * @returns {Object} Dimensions with calculated inner width and height
17
- */
18
- export function calculateChartDimensions(width: number, height: number, margin: Object): Object;
19
- /**
20
- * Gets the axis origin value
21
- *
22
- * @param {Object} scale D3 scale
23
- * @returns {number} Origin value
24
- */
25
- export function getOriginValue(scale: Object): number;
26
- /**
27
- * Creates axis ticks
28
- *
29
- * @param {Object} scale D3 scale
30
- * @param {string} axis Axis type ('x' or 'y')
31
- * @param {number} count Number of ticks
32
- * @param {number} fontSize Font size for determining tick density
33
- * @returns {Array} Array of tick objects
34
- */
35
- export function createTicks(scale: Object, axis: string, count?: number, fontSize?: number): any[];
@@ -1,151 +0,0 @@
1
- import { SvelteSet } from 'svelte/reactivity'
2
- import { scaleLinear, scaleOrdinal } from 'd3-scale'
3
- import { schemeCategory10 } from 'd3-scale-chromatic'
4
- import { min, max } from 'd3-array'
5
- import { buildXScale } from './xscale.js'
6
-
7
- /**
8
- * Creates appropriate scales based on data and dimensions
9
- *
10
- * @param {Array} data The dataset
11
- * @param {Object} dimensions Chart dimensions
12
- * @param {Object} options Additional options
13
- * @param {string} options.xKey Field to use for x-axis
14
- * @param {string} options.yKey Field to use for y-axis
15
- * @param {string} [options.colorKey] Field to use for color mapping
16
- * @param {number} [options.padding=0.2] Padding for band scales
17
- * @returns {Object} Object containing xScale, yScale, and colorScale
18
- */
19
- /**
20
- * @param {Array} data
21
- * @param {string} colorKey
22
- * @returns {Object}
23
- */
24
- function buildColorScale(data, colorKey) {
25
- const uniqueCategories = [...new SvelteSet(data.map((d) => d[colorKey]))]
26
- return scaleOrdinal().domain(uniqueCategories).range(schemeCategory10)
27
- }
28
-
29
- /**
30
- * @param {Object} options
31
- * @returns {{ xKey: string, yKey: string, colorKey: string|undefined, padding: number }}
32
- */
33
- function parseScaleOptions(options) {
34
- const opts = options || {}
35
- return {
36
- xKey: opts.xKey,
37
- yKey: opts.yKey,
38
- colorKey: opts.colorKey,
39
- padding: opts.padding !== undefined ? opts.padding : 0.2
40
- }
41
- }
42
-
43
- export function createScales(data, dimensions, options) {
44
- if (!data || !data.length) return {}
45
-
46
- const { xKey, yKey, colorKey, padding } = parseScaleOptions(options)
47
- const xValues = data.map((d) => d[xKey])
48
- const yValues = data.map((d) => d[yKey])
49
- const colorScale = colorKey ? buildColorScale(data, colorKey) : null
50
-
51
- return {
52
- xScale: buildXScale(xValues, dimensions, padding),
53
- yScale: scaleLinear()
54
- .domain([0, max(yValues) * 1.1])
55
- .nice()
56
- .range([dimensions.innerHeight, 0]),
57
- colorScale
58
- }
59
- }
60
-
61
- /**
62
- * Calculates the actual chart dimensions after applying margins
63
- *
64
- * @param {number} width
65
- * @param {number} height
66
- * @param {Object} margin
67
- * @returns {Object} Dimensions with calculated inner width and height
68
- */
69
- export function calculateChartDimensions(width, height, margin) {
70
- return {
71
- width,
72
- height,
73
- margin,
74
- innerWidth: width - margin.left - margin.right,
75
- innerHeight: height - margin.top - margin.bottom
76
- }
77
- }
78
-
79
- /**
80
- * Gets the axis origin value
81
- *
82
- * @param {Object} scale D3 scale
83
- * @returns {number} Origin value
84
- */
85
- export function getOriginValue(scale) {
86
- return scale.ticks ? scale(Math.max(0, min(scale.domain()))) : scale.range()[0]
87
- }
88
-
89
- /**
90
- * Resolve tick values for a band scale, applying downsampling when needed
91
- * @param {Object} scale
92
- * @param {number} count
93
- * @returns {{ ticks: Array, offset: number }}
94
- */
95
- function bandTicks(scale, count) {
96
- const offset = scale.bandwidth() / 2
97
- const domain = scale.domain()
98
- const cappedCount = Math.min(Math.round(count), domain.length)
99
- const step = Math.ceil(domain.length / cappedCount)
100
- const ticks = cappedCount < domain.length ? domain.filter((_, i) => i % step === 0) : domain
101
- return { ticks, offset }
102
- }
103
-
104
- /**
105
- * @param {number} rangeSize
106
- * @param {string} axis
107
- * @param {number} fontSize
108
- * @returns {number}
109
- */
110
- function defaultTickCount(rangeSize, axis, fontSize) {
111
- const divisor = fontSize * (axis === 'y' ? 3 : 6)
112
- return Math.abs(rangeSize / divisor)
113
- }
114
-
115
- /**
116
- * @param {Array} ticks
117
- * @param {Object} scale
118
- * @param {number} offset
119
- * @param {boolean} isXAxis
120
- * @returns {Array}
121
- */
122
- function formatTicks(ticks, scale, offset, isXAxis) {
123
- const pos = isXAxis ? offset : 0
124
- return ticks.map((t) => ({ value: t, position: scale(t) + pos }))
125
- }
126
-
127
- /**
128
- * Creates axis ticks
129
- *
130
- * @param {Object} scale D3 scale
131
- * @param {string} axis Axis type ('x' or 'y')
132
- * @param {number} count Number of ticks
133
- * @param {number} fontSize Font size for determining tick density
134
- * @returns {Array} Array of tick objects
135
- */
136
- export function createTicks(scale, axis, count = null, fontSize = 12) {
137
- const [minRange, maxRange] = scale.range()
138
- const tickCount = count ?? defaultTickCount(maxRange - minRange, axis, fontSize)
139
-
140
- let ticks, offset
141
- if (scale.ticks) {
142
- ticks = scale.ticks(Math.round(tickCount))
143
- offset = 0
144
- } else {
145
- const band = bandTicks(scale, tickCount)
146
- ticks = band.ticks
147
- offset = band.offset
148
- }
149
-
150
- return formatTicks(ticks, scale, offset, axis === 'x')
151
- }
@@ -1,36 +0,0 @@
1
- /**
2
- * @typedef {Object} TickSteps
3
- * @property {number} major - count of major ticks
4
- * @property {number} minor - count of minor ticks
5
- */
6
- /**
7
- * Generate an array of ticks for a given axis and the tick type
8
- *
9
- * @param {number} lower - The lower bound of the axis
10
- * @param {number} upper - The upper bound of the axis
11
- * @param {TickSteps} steps - The number of steps between major and minor ticks
12
- * @param {string} type - The type of tick to generate
13
- *
14
- * @returns {Array} - An array of objects representing the ticks
15
- */
16
- export function ticksByType(lower: number, upper: number, steps: TickSteps, type: string): any[];
17
- /**
18
- * Generate an array of ticks for a given axis
19
- *
20
- * @param {number} lower - The lower bound of the axis
21
- * @param {number} upper - The upper bound of the axis
22
- * @param {TickSteps} steps - The number of steps between major and minor ticks
23
- *
24
- * @returns {Array} - An array of objects representing the ticks
25
- */
26
- export function getTicks(lower: number, upper: number, steps?: TickSteps): any[];
27
- export type TickSteps = {
28
- /**
29
- * - count of major ticks
30
- */
31
- major: number;
32
- /**
33
- * - count of minor ticks
34
- */
35
- minor: number;
36
- };
package/dist/lib/ticks.js DELETED
@@ -1,46 +0,0 @@
1
- /**
2
- * @typedef {Object} TickSteps
3
- * @property {number} major - count of major ticks
4
- * @property {number} minor - count of minor ticks
5
- */
6
-
7
- /**
8
- * Generate an array of ticks for a given axis and the tick type
9
- *
10
- * @param {number} lower - The lower bound of the axis
11
- * @param {number} upper - The upper bound of the axis
12
- * @param {TickSteps} steps - The number of steps between major and minor ticks
13
- * @param {string} type - The type of tick to generate
14
- *
15
- * @returns {Array} - An array of objects representing the ticks
16
- */
17
- export function ticksByType(lower, upper, steps, type) {
18
- if (steps <= 0) return []
19
- return Array.from({ length: Math.floor((upper - lower) / steps) + 1 }, (_, i) => ({
20
- position: i * steps,
21
- label: i * steps,
22
- type
23
- })).filter((tick) => tick.position > lower && tick.position < upper)
24
- }
25
-
26
- /**
27
- * Generate an array of ticks for a given axis
28
- *
29
- * @param {number} lower - The lower bound of the axis
30
- * @param {number} upper - The upper bound of the axis
31
- * @param {TickSteps} steps - The number of steps between major and minor ticks
32
- *
33
- * @returns {Array} - An array of objects representing the ticks
34
- */
35
- export function getTicks(lower, upper, steps = { major: 10, minor: 0 }) {
36
- const majorTicks = ticksByType(lower, upper, steps.major, 'major')
37
- const minorTicks = ticksByType(lower, upper, steps.minor, 'minor').filter(
38
- (tick) => !majorTicks.find((major) => major.position === tick.position)
39
- )
40
- const end = [
41
- { position: upper, label: upper, type: 'end' },
42
- { position: lower, label: lower, type: 'end' }
43
- ]
44
-
45
- return [...minorTicks, ...majorTicks, ...end].sort((a, b) => a.position - b.position)
46
- }