@adecore/charts 0.62.1 → 0.63.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.
package/dist/axes.js CHANGED
@@ -5,6 +5,7 @@ import { useEffect, useId, useRef, useState, useSyncExternalStore } from 'react'
5
5
  import { createPortal } from 'react-dom';
6
6
  import { useTranslation } from 'react-i18next';
7
7
  import { useChartContext } from './context.js';
8
+ import { crisp } from './plane.js';
8
9
  import { useBeforePaint } from './register.js';
9
10
  import { decimalsOf, tickCount } from './scale.js';
10
11
  import { formatTime, timeLabelOf } from './time-format.js';
@@ -19,9 +20,7 @@ const X_TICK_SPACING = 96;
19
20
  const GUESS = 48;
20
21
  const SLANT = 40 * Math.PI / 180;
21
22
  const DASH = '2 5';
22
- /* The row an x axis title takes under its labels. */
23
23
  const X_TITLE_ROOM = 21;
24
- /* The baseline of a y axis title from the top of the chart, and the room above the plot it needs. */
25
24
  const Y_TITLE_BASELINE = 15;
26
25
  const Y_TITLE_ROOM = 28;
27
26
  /* The names of the rows of a horizontal chart: their widest and the share of the chart they may take, and their line. */
@@ -32,8 +31,6 @@ const ROW_LABEL_LINE = 16;
32
31
  const roomOf = (widest, angle) => Math.ceil(angle === 0 ? X_LABEL_LINE : widest * Math.sin(SLANT) + X_LABEL_LINE * Math.cos(SLANT));
33
32
  const textWidth = node => typeof node.getComputedTextLength === 'function' ? node.getComputedTextLength() : (node.textContent?.length ?? 0) * 7;
34
33
  const widestIn = group => Math.max(0, ...[...(group?.querySelectorAll('text') ?? [])].map(textWidth));
35
- /* A line sits on the middle of a pixel, so one pixel wide stays one pixel wide. */
36
- const crisp = pixel => Math.round(pixel) + 0.5;
37
34
  /*
38
35
  * The labels, from left to right, with every one left out that comes nearer to the one before it than `spacing`.
39
36
  * A label on an end of the axis wins over its neighbor, so both ends stay named.
@@ -52,7 +49,7 @@ const apart = (labels, spacing) => {
52
49
  };
53
50
  /* Gridlines on the ticks, a heavier one on the ground. */
54
51
  export function ChartGrid(t0) {
55
- const $ = _c(78);
52
+ const $ = _c(46);
56
53
  const {
57
54
  axis: t1,
58
55
  dashed: t2,
@@ -67,242 +64,143 @@ export function ChartGrid(t0) {
67
64
  const {
68
65
  plot,
69
66
  y,
70
- continuous,
71
- band
67
+ plane
72
68
  } = chart;
73
69
  const ground = y.domain[0] <= 0 && y.domain[1] >= 0 ? 0 : y.domain[0];
74
- if (chart.horizontal) {
75
- let t4;
76
- if ($[0] !== axis || $[1] !== ground || $[2] !== lines || $[3] !== y.ticks) {
77
- t4 = lines === "ground" ? [ground] : axis === "x" ? [] : y.ticks;
78
- $[0] = axis;
79
- $[1] = ground;
80
- $[2] = lines;
81
- $[3] = y.ticks;
82
- $[4] = t4;
70
+ let t4;
71
+ if ($[0] !== axis || $[1] !== ground || $[2] !== lines || $[3] !== y.ticks) {
72
+ t4 = lines === "ground" ? [ground] : axis === "x" ? [] : y.ticks;
73
+ $[0] = axis;
74
+ $[1] = ground;
75
+ $[2] = lines;
76
+ $[3] = y.ticks;
77
+ $[4] = t4;
78
+ } else {
79
+ t4 = $[4];
80
+ }
81
+ const ticks = t4;
82
+ let t5;
83
+ let t6;
84
+ let t7;
85
+ let t8;
86
+ let t9;
87
+ if ($[5] !== axis || $[6] !== chart || $[7] !== className || $[8] !== dashed || $[9] !== ground || $[10] !== lines || $[11] !== plane || $[12] !== plot || $[13] !== ref || $[14] !== ticks || $[15] !== y) {
88
+ const between = lines === "ground" || axis === "y" ? [] : betweenOf(chart);
89
+ t5 = ref;
90
+ if ($[21] !== className) {
91
+ t6 = clsx("pointer-events-none", className);
92
+ $[21] = className;
93
+ $[22] = t6;
83
94
  } else {
84
- t4 = $[4];
95
+ t6 = $[22];
85
96
  }
86
- const ticks = t4;
87
- let t5;
88
- let t6;
89
- let t7;
90
- let t8;
91
- let t9;
92
- if ($[5] !== axis || $[6] !== chart || $[7] !== className || $[8] !== dashed || $[9] !== ground || $[10] !== lines || $[11] !== plot || $[12] !== ref || $[13] !== ticks || $[14] !== y) {
93
- const rows = lines === "ground" || axis === "y" ? [] : chart.xs.map((_, index) => chart.centerOf(index));
94
- t5 = ref;
95
- if ($[20] !== className) {
96
- t6 = clsx("pointer-events-none", className);
97
- $[20] = className;
98
- $[21] = t6;
99
- } else {
100
- t6 = $[21];
101
- }
102
- t7 = true;
103
- if ($[22] !== dashed || $[23] !== ground || $[24] !== plot || $[25] !== ticks || $[26] !== y) {
104
- let t10;
105
- if ($[28] !== dashed || $[29] !== ground || $[30] !== plot || $[31] !== y) {
106
- t10 = tick => {
107
- const pixel = y.at(tick);
108
- return pixel === null ? null : /*#__PURE__*/_jsx("line", {
109
- x1: crisp(pixel),
110
- x2: crisp(pixel),
111
- y1: plot.top,
112
- y2: plot.bottom,
113
- strokeDasharray: dashed && tick !== ground ? DASH : undefined,
114
- className: dashed ? "stroke-border" : tick === ground ? "stroke-border-strong" : "stroke-border-soft"
115
- }, tick);
116
- };
117
- $[28] = dashed;
118
- $[29] = ground;
119
- $[30] = plot;
120
- $[31] = y;
121
- $[32] = t10;
122
- } else {
123
- t10 = $[32];
124
- }
125
- t8 = ticks.map(t10);
126
- $[22] = dashed;
127
- $[23] = ground;
128
- $[24] = plot;
129
- $[25] = ticks;
130
- $[26] = y;
131
- $[27] = t8;
132
- } else {
133
- t8 = $[27];
134
- }
97
+ t7 = true;
98
+ if ($[23] !== dashed || $[24] !== ground || $[25] !== plane || $[26] !== plot || $[27] !== ticks || $[28] !== y) {
135
99
  let t10;
136
- if ($[33] !== dashed || $[34] !== plot) {
137
- t10 = pixel_0 => /*#__PURE__*/_jsx("line", {
138
- x1: plot.left,
139
- x2: plot.right,
140
- y1: crisp(pixel_0),
141
- y2: crisp(pixel_0),
142
- strokeDasharray: dashed ? DASH : undefined,
143
- className: dashed ? "stroke-border" : "stroke-border-soft"
144
- }, pixel_0);
145
- $[33] = dashed;
146
- $[34] = plot;
100
+ if ($[30] !== dashed || $[31] !== ground || $[32] !== plane || $[33] !== plot || $[34] !== y) {
101
+ t10 = tick => {
102
+ const pixel = y.at(tick);
103
+ const line = pixel === null ? null : plane.valueLine(plot, crisp(pixel));
104
+ return line === null ? null : /*#__PURE__*/_jsx("line", {
105
+ x1: line.x1,
106
+ x2: line.x2,
107
+ y1: line.y1,
108
+ y2: line.y2,
109
+ strokeDasharray: dashed && tick !== ground ? DASH : undefined,
110
+ className: dashed ? "stroke-border" : tick === ground ? "stroke-border-strong" : "stroke-border-soft"
111
+ }, tick);
112
+ };
113
+ $[30] = dashed;
114
+ $[31] = ground;
115
+ $[32] = plane;
116
+ $[33] = plot;
117
+ $[34] = y;
147
118
  $[35] = t10;
148
119
  } else {
149
120
  t10 = $[35];
150
121
  }
151
- t9 = rows.map(t10);
152
- $[5] = axis;
153
- $[6] = chart;
154
- $[7] = className;
155
- $[8] = dashed;
156
- $[9] = ground;
157
- $[10] = lines;
158
- $[11] = plot;
159
- $[12] = ref;
160
- $[13] = ticks;
161
- $[14] = y;
162
- $[15] = t5;
163
- $[16] = t6;
164
- $[17] = t7;
165
- $[18] = t8;
166
- $[19] = t9;
122
+ t8 = ticks.map(t10);
123
+ $[23] = dashed;
124
+ $[24] = ground;
125
+ $[25] = plane;
126
+ $[26] = plot;
127
+ $[27] = ticks;
128
+ $[28] = y;
129
+ $[29] = t8;
167
130
  } else {
168
- t5 = $[15];
169
- t6 = $[16];
170
- t7 = $[17];
171
- t8 = $[18];
172
- t9 = $[19];
131
+ t8 = $[29];
173
132
  }
174
133
  let t10;
175
- if ($[36] !== t5 || $[37] !== t6 || $[38] !== t7 || $[39] !== t8 || $[40] !== t9) {
176
- t10 = /*#__PURE__*/_jsxs("g", {
177
- ref: t5,
178
- className: t6,
179
- "aria-hidden": t7,
180
- children: [t8, t9]
181
- });
182
- $[36] = t5;
183
- $[37] = t6;
184
- $[38] = t7;
185
- $[39] = t8;
186
- $[40] = t9;
187
- $[41] = t10;
188
- } else {
189
- t10 = $[41];
190
- }
191
- return t10;
192
- }
193
- if (lines === "ground") {
194
- let t4;
195
- if ($[42] !== className || $[43] !== dashed || $[44] !== ground || $[45] !== plot || $[46] !== ref || $[47] !== y) {
196
- const pixel_1 = y.at(ground);
197
- t4 = pixel_1 === null ? null : /*#__PURE__*/_jsx("g", {
198
- ref: ref,
199
- className: clsx("pointer-events-none", className),
200
- "aria-hidden": true,
201
- children: /*#__PURE__*/_jsx("line", {
202
- x1: plot.left,
203
- x2: plot.right,
204
- y1: crisp(pixel_1),
205
- y2: crisp(pixel_1),
206
- className: dashed ? "stroke-border" : "stroke-border-strong"
207
- })
208
- });
209
- $[42] = className;
210
- $[43] = dashed;
211
- $[44] = ground;
212
- $[45] = plot;
213
- $[46] = ref;
214
- $[47] = y;
215
- $[48] = t4;
216
- } else {
217
- t4 = $[48];
218
- }
219
- return t4;
220
- }
221
- let t4;
222
- let t5;
223
- let t6;
224
- let t7;
225
- let t8;
226
- if ($[49] !== axis || $[50] !== band || $[51] !== chart || $[52] !== className || $[53] !== continuous || $[54] !== dashed || $[55] !== ground || $[56] !== plot || $[57] !== ref || $[58] !== y) {
227
- const columns = continuous !== null ? continuous.ticks(tickCount(plot.width, X_TICK_SPACING)).map(tick_0 => continuous.at(tick_0)) : chart.xs.map((__0, index_0) => chart.centerOf(index_0));
228
- t4 = ref;
229
- if ($[64] !== className) {
230
- t5 = clsx("pointer-events-none", className);
231
- $[64] = className;
232
- $[65] = t5;
233
- } else {
234
- t5 = $[65];
235
- }
236
- t6 = true;
237
- if ($[66] !== axis || $[67] !== dashed || $[68] !== ground || $[69] !== plot || $[70] !== y) {
238
- t7 = axis !== "x" && y.ticks.map(tick_1 => {
239
- const pixel_2 = y.at(tick_1);
240
- return pixel_2 === null ? null : /*#__PURE__*/_jsx("line", {
241
- x1: plot.left,
242
- x2: plot.right,
243
- y1: crisp(pixel_2),
244
- y2: crisp(pixel_2),
245
- strokeDasharray: dashed && tick_1 !== ground ? DASH : undefined,
246
- className: dashed ? "stroke-border" : tick_1 === ground ? "stroke-border-strong" : "stroke-border-soft"
247
- }, tick_1);
248
- });
249
- $[66] = axis;
250
- $[67] = dashed;
251
- $[68] = ground;
252
- $[69] = plot;
253
- $[70] = y;
254
- $[71] = t7;
134
+ if ($[36] !== dashed || $[37] !== plane || $[38] !== plot) {
135
+ t10 = pixel_0 => {
136
+ const line_0 = plane.bucketLine(plot, crisp(pixel_0));
137
+ return /*#__PURE__*/_jsx("line", {
138
+ x1: line_0.x1,
139
+ x2: line_0.x2,
140
+ y1: line_0.y1,
141
+ y2: line_0.y2,
142
+ strokeDasharray: dashed ? DASH : undefined,
143
+ className: dashed ? "stroke-border" : "stroke-border-soft"
144
+ }, pixel_0);
145
+ };
146
+ $[36] = dashed;
147
+ $[37] = plane;
148
+ $[38] = plot;
149
+ $[39] = t10;
255
150
  } else {
256
- t7 = $[71];
151
+ t10 = $[39];
257
152
  }
258
- t8 = axis !== "y" && (band === null || chart.xs.length > 0) && columns.map(pixel_3 => /*#__PURE__*/_jsx("line", {
259
- x1: crisp(pixel_3),
260
- x2: crisp(pixel_3),
261
- y1: plot.top,
262
- y2: plot.bottom,
263
- strokeDasharray: dashed ? DASH : undefined,
264
- className: dashed ? "stroke-border" : "stroke-border-soft"
265
- }, pixel_3));
266
- $[49] = axis;
267
- $[50] = band;
268
- $[51] = chart;
269
- $[52] = className;
270
- $[53] = continuous;
271
- $[54] = dashed;
272
- $[55] = ground;
273
- $[56] = plot;
274
- $[57] = ref;
275
- $[58] = y;
276
- $[59] = t4;
277
- $[60] = t5;
278
- $[61] = t6;
279
- $[62] = t7;
280
- $[63] = t8;
153
+ t9 = between.map(t10);
154
+ $[5] = axis;
155
+ $[6] = chart;
156
+ $[7] = className;
157
+ $[8] = dashed;
158
+ $[9] = ground;
159
+ $[10] = lines;
160
+ $[11] = plane;
161
+ $[12] = plot;
162
+ $[13] = ref;
163
+ $[14] = ticks;
164
+ $[15] = y;
165
+ $[16] = t5;
166
+ $[17] = t6;
167
+ $[18] = t7;
168
+ $[19] = t8;
169
+ $[20] = t9;
281
170
  } else {
282
- t4 = $[59];
283
- t5 = $[60];
284
- t6 = $[61];
285
- t7 = $[62];
286
- t8 = $[63];
171
+ t5 = $[16];
172
+ t6 = $[17];
173
+ t7 = $[18];
174
+ t8 = $[19];
175
+ t9 = $[20];
287
176
  }
288
- let t9;
289
- if ($[72] !== t4 || $[73] !== t5 || $[74] !== t6 || $[75] !== t7 || $[76] !== t8) {
290
- t9 = /*#__PURE__*/_jsxs("g", {
291
- ref: t4,
292
- className: t5,
293
- "aria-hidden": t6,
294
- children: [t7, t8]
177
+ let t10;
178
+ if ($[40] !== t5 || $[41] !== t6 || $[42] !== t7 || $[43] !== t8 || $[44] !== t9) {
179
+ t10 = /*#__PURE__*/_jsxs("g", {
180
+ ref: t5,
181
+ className: t6,
182
+ "aria-hidden": t7,
183
+ children: [t8, t9]
295
184
  });
296
- $[72] = t4;
297
- $[73] = t5;
298
- $[74] = t6;
299
- $[75] = t7;
300
- $[76] = t8;
301
- $[77] = t9;
185
+ $[40] = t5;
186
+ $[41] = t6;
187
+ $[42] = t7;
188
+ $[43] = t8;
189
+ $[44] = t9;
190
+ $[45] = t10;
302
191
  } else {
303
- t9 = $[77];
192
+ t10 = $[45];
304
193
  }
305
- return t9;
194
+ return t10;
195
+ }
196
+ /* Where the lines between the buckets stand: on the ticks of a continuous axis, else through the middle of every bucket. */
197
+ function betweenOf({
198
+ continuous,
199
+ plot,
200
+ xs,
201
+ centerOf
202
+ }) {
203
+ return continuous !== null ? continuous.ticks(tickCount(plot.width, X_TICK_SPACING)).map(tick => continuous.at(tick)) : xs.map((_, index) => centerOf(index));
306
204
  }
307
205
  /*
308
206
  * The labels under the plot: one per bucket on a band scale as far as they fit, round ticks on a continuous one. In a
@@ -1131,7 +1029,7 @@ export function ChartGroupAxis(t0) {
1131
1029
  } = t0;
1132
1030
  const chart = useChartContext("Chart.GroupAxis");
1133
1031
  const target = chart.elements.groups;
1134
- if (target === null || chart.band === null || chart.horizontal) {
1032
+ if (target === null || chart.band === null || !chart.plane.draws("groups")) {
1135
1033
  return null;
1136
1034
  }
1137
1035
  const rows = chart.data;
package/dist/band.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export declare const GROUP_GAP = 16;
2
- export interface BandGroup {
2
+ interface BandGroup {
3
3
  readonly key: string;
4
4
  readonly first: number;
5
5
  readonly last: number;
@@ -13,11 +13,6 @@ export interface BandLayout {
13
13
  readonly groups: readonly BandGroup[];
14
14
  readonly gap: number;
15
15
  }
16
- export declare function groupRuns(keys: readonly string[]): {
17
- key: string;
18
- first: number;
19
- last: number;
20
- }[];
21
16
  export declare function bandLayout(count: number, groupKeys: readonly string[] | null, room: number, minBucketWidth?: number, groupGap?: number): BandLayout;
22
17
  export interface Column {
23
18
  readonly x: number;
@@ -42,7 +37,7 @@ declare const LABEL_SIZES: {
42
37
  readonly char: 9;
43
38
  };
44
39
  };
45
- export type ValueLabelSize = keyof typeof LABEL_SIZES;
40
+ type ValueLabelSize = keyof typeof LABEL_SIZES;
46
41
  export declare const guessLabelWidth: (text: string, size?: ValueLabelSize) => number;
47
42
  export declare function placeValueLabels(columns: readonly {
48
43
  center: number;
package/dist/band.js CHANGED
@@ -5,7 +5,7 @@ const MAX_COLUMN = 56;
5
5
  /* Share of a bucket a column takes when it is alone in it; the rest is air between buckets. */
6
6
  const COLUMN_SHARE = 0.72;
7
7
  /* The run of equal keys each bucket belongs to, in the order of the data; a key that comes back later starts a run of its own. */
8
- export function groupRuns(keys) {
8
+ function groupRuns(keys) {
9
9
  const runs = [];
10
10
  keys.forEach((key, index) => {
11
11
  const run = runs.at(-1);
package/dist/context.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import type { BandLayout } from './band.ts';
2
2
  import type { AxisWidths } from './group-axes.ts';
3
+ import type { ChartPlane } from './plane.ts';
3
4
  import type { ContinuousXScale, Stacked, YAxisScale } from './scale.ts';
4
5
  import type { BandEntry, ChartStore, MarkerEntry, SeriesEntry } from './store.ts';
5
6
  import type { ChartNote, ChartRect, ChartX, ChartXScale } from './types.ts';
6
- export interface ChartSlots {
7
+ interface ChartSlots {
7
8
  readonly legend: HTMLElement | null;
8
9
  readonly table: HTMLElement | null;
9
10
  readonly tooltip: HTMLElement | null;
@@ -20,6 +21,7 @@ export interface ChartContextValue {
20
21
  readonly xs: readonly ChartX[];
21
22
  readonly xScale: ChartXScale;
22
23
  readonly horizontal: boolean;
24
+ readonly plane: ChartPlane;
23
25
  readonly valueRoom: number;
24
26
  readonly height: number;
25
27
  readonly plot: ChartRect;
@@ -86,7 +88,7 @@ export declare const BarsContext: import("react").Context<{
86
88
  id: string;
87
89
  stack: boolean;
88
90
  } | null>;
89
- export interface GroupCursor {
91
+ interface GroupCursor {
90
92
  readonly x: ChartX | null;
91
93
  readonly owner: string | null;
92
94
  readonly setX: (x: ChartX | null, owner: string) => void;
@@ -95,3 +97,4 @@ export declare const GroupContext: import("react").Context<{
95
97
  cursor: GroupCursor | null;
96
98
  widths: AxisWidths | null;
97
99
  } | null>;
100
+ export {};
package/dist/index.d.ts CHANGED
@@ -9,7 +9,8 @@ export { CHARTS_NAMESPACE, CHARTS_RESOURCES } from './locales.ts';
9
9
  export type { ChartBucket, ChartBucketValue, ChartLegendProps, ChartTableData, ChartTableProps, ChartTooltipProps, ChartTooltipPlacement } from './overlays.tsx';
10
10
  export type { ChartRootProps } from './Root.tsx';
11
11
  export type { ChartEndLabelsProps, ChartFrontierProps, ChartPointSeries } from './scatter.tsx';
12
- export { SeriesLegend, type SeriesLegendGroup, type SeriesLegendItem, type SeriesLegendProps } from './SeriesLegend.tsx';
12
+ export { SeriesLegend, type SeriesLegendGroup, type SeriesLegendProps } from './SeriesLegend.tsx';
13
+ export type { SeriesLegendItem } from './legend.ts';
13
14
  export type { ChartAreaProps, ChartBarProps, ChartBarTone, ChartBarsProps, ChartLineProps, ChartPointProps } from './series.tsx';
14
15
  export { Sparkline, type SparklineProps } from './Sparkline.tsx';
15
16
  export type { TimelineAxisProps, TimelineLegendProps, TimelineMomentProps, TimelineRootProps, TimelineRowState, TimelineRowsProps } from './timeline.tsx';
package/dist/legend.d.ts CHANGED
@@ -1,3 +1,11 @@
1
- import type { SeriesLegendItem } from './SeriesLegend.tsx';
1
+ export interface SeriesLegendItem {
2
+ readonly key: string;
3
+ readonly label: string;
4
+ readonly name?: string;
5
+ readonly group?: string;
6
+ readonly color?: string;
7
+ readonly disabled?: boolean;
8
+ readonly status?: string;
9
+ }
2
10
  export declare function matchingItems<Item extends SeriesLegendItem>(items: readonly Item[], query: string): Item[];
3
11
  export declare function toggleGroup(items: readonly SeriesLegendItem[], hidden: readonly string[], group: string, show: boolean): string[];
package/dist/overlays.js CHANGED
@@ -89,7 +89,6 @@ function rowPlace(chart, placement, card) {
89
89
  })
90
90
  };
91
91
  }
92
- /* The swatch of a series: its icon in its color, else a dash for a line and a square for a column. */
93
92
  function Swatch(t0) {
94
93
  const $ = _c(15);
95
94
  const {
@@ -168,7 +167,6 @@ function Swatch(t0) {
168
167
  }
169
168
  return t4;
170
169
  }
171
- /* A dashed stroke for a marker, a square for a band, in their color. */
172
170
  function NoteSwatch(t0) {
173
171
  const $ = _c(3);
174
172
  const {
@@ -0,0 +1,25 @@
1
+ import type { SeriesEntry } from './store.ts';
2
+ import type { ChartRect } from './types.ts';
3
+ export type Drawn = SeriesEntry['kind'] | 'marker' | 'band' | 'groups';
4
+ interface PlotLine {
5
+ readonly x1: number;
6
+ readonly x2: number;
7
+ readonly y1: number;
8
+ readonly y2: number;
9
+ }
10
+ interface RuleLabel {
11
+ readonly x: number;
12
+ readonly y: number;
13
+ readonly dy?: string;
14
+ readonly anchor: 'start' | 'end';
15
+ }
16
+ export interface ChartPlane {
17
+ readonly draws: (part: Drawn) => boolean;
18
+ readonly valueLine: (plot: ChartRect, pixel: number) => PlotLine;
19
+ readonly bucketLine: (plot: ChartRect, pixel: number) => PlotLine;
20
+ readonly ruleLabel: (plot: ChartRect, pixel: number) => RuleLabel;
21
+ }
22
+ export declare const crisp: (pixel: number) => number;
23
+ export declare const COLUMNS: ChartPlane;
24
+ export declare const ROWS: ChartPlane;
25
+ export {};
package/dist/plane.js ADDED
@@ -0,0 +1,55 @@
1
+ /* A line one pixel wide is drawn on the middle of a pixel, so it stays sharp. */
2
+ export const crisp = pixel => Math.round(pixel) + 0.5;
3
+ /* Room a label needs above its line before it moves under it instead. */
4
+ const RULE_LABEL = 18;
5
+ /* Between the line and the label it carries, above it or below it. */
6
+ const RULE_GAP = 7;
7
+ /* Between the line and the label it carries, beside it. */
8
+ const RULE_SIDE = 4;
9
+ const across = (plot, pixel) => ({
10
+ x1: plot.left,
11
+ x2: plot.right,
12
+ y1: pixel,
13
+ y2: pixel
14
+ });
15
+ const upright = (plot, pixel) => ({
16
+ x1: pixel,
17
+ x2: pixel,
18
+ y1: plot.top,
19
+ y2: plot.bottom
20
+ });
21
+ /* The buckets are columns along the bottom and the values run up. */
22
+ export const COLUMNS = {
23
+ draws: () => true,
24
+ valueLine: across,
25
+ bucketLine: upright,
26
+ ruleLabel: (plot, pixel) => {
27
+ const below = crisp(pixel) - RULE_LABEL < 0;
28
+ return {
29
+ x: Math.round(plot.right),
30
+ y: Math.round(pixel) + (below ? RULE_GAP : -RULE_GAP),
31
+ ...(below ? {
32
+ dy: '0.8em'
33
+ } : {}),
34
+ anchor: 'end'
35
+ };
36
+ }
37
+ };
38
+ /*
39
+ * The buckets are rows down the chart and the values run to the right. Only columns turn into rows: a line, a
40
+ * point, a marker or a band across rows would read nothing a bar does not.
41
+ */
42
+ export const ROWS = {
43
+ draws: part => part === 'bar',
44
+ valueLine: upright,
45
+ bucketLine: across,
46
+ ruleLabel: (plot, pixel) => {
47
+ // Above the plot, on the side of the line that has the room, so it never covers the bars of the first row.
48
+ const anchor = pixel > (plot.left + plot.right) / 2 ? 'end' : 'start';
49
+ return {
50
+ x: Math.round(pixel) + (anchor === 'end' ? RULE_SIDE : -RULE_SIDE),
51
+ y: plot.top - RULE_GAP,
52
+ anchor
53
+ };
54
+ }
55
+ };
package/dist/scale.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { ChartXOptions, ChartYOptions, ChartYScale } from './types.ts';
2
- export interface StackInput {
2
+ interface StackInput {
3
3
  readonly id: string;
4
4
  readonly values: readonly (number | null)[];
5
5
  readonly stack: string | null;
@@ -32,3 +32,4 @@ export declare function thinTicks(ticks: readonly number[], count: number): numb
32
32
  export declare function pointXScale(kind: 'time' | 'linear' | 'log', xs: readonly number[], range: [number, number], options?: ChartXOptions): ContinuousXScale;
33
33
  export declare function continuousXScale(kind: 'time' | 'linear' | 'log', xs: readonly number[], range: [number, number], step?: number, options?: ChartXOptions): ContinuousXScale;
34
34
  export declare function decimalsOf(step: number): number;
35
+ export {};
package/dist/series.js CHANGED
@@ -219,7 +219,7 @@ export function ChartLine(t0) {
219
219
  t7 = $[9];
220
220
  }
221
221
  useRegistration(chart.store, "series", id, t7);
222
- if (chart.horizontal) {
222
+ if (!chart.plane.draws("line")) {
223
223
  return null;
224
224
  }
225
225
  if (chart.points) {
@@ -383,7 +383,7 @@ export function ChartPoint(t0) {
383
383
  valueLabels: false
384
384
  });
385
385
  const fallback = chart.colors.get(id) ?? seriesColor(0);
386
- if (chart.horizontal) {
386
+ if (!chart.plane.draws("point")) {
387
387
  return null;
388
388
  }
389
389
  let t1;
@@ -517,7 +517,7 @@ export function ChartArea(t0) {
517
517
  t12 = $[11];
518
518
  }
519
519
  useRegistration(t8, "series", id, t12);
520
- if (chart.horizontal) {
520
+ if (!chart.plane.draws("area")) {
521
521
  return null;
522
522
  }
523
523
  let t13;
package/dist/spark.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export interface SparkColumn {
1
+ interface SparkColumn {
2
2
  readonly x: number;
3
3
  readonly y: number;
4
4
  readonly width: number;
@@ -7,3 +7,4 @@ export interface SparkColumn {
7
7
  readonly zero: boolean;
8
8
  }
9
9
  export declare function sparkColumns(values: readonly (number | null)[], width: number, height: number): SparkColumn[];
10
+ export {};