inkplot 0.0.1-placeholder.0 → 1.0.0-beta.1

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 (141) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +45 -1
  3. package/dist/adapt.d.ts +10 -0
  4. package/dist/adapt.js +34 -0
  5. package/dist/annotation.d.ts +120 -0
  6. package/dist/annotation.js +267 -0
  7. package/dist/aria.d.ts +24 -0
  8. package/dist/aria.js +31 -0
  9. package/dist/attrs.d.ts +81 -0
  10. package/dist/attrs.js +84 -0
  11. package/dist/axis.d.ts +137 -0
  12. package/dist/axis.js +185 -0
  13. package/dist/bars.d.ts +80 -0
  14. package/dist/bars.js +255 -0
  15. package/dist/boxplot.d.ts +57 -0
  16. package/dist/boxplot.js +177 -0
  17. package/dist/boxzoom.d.ts +39 -0
  18. package/dist/boxzoom.js +138 -0
  19. package/dist/brush.d.ts +60 -0
  20. package/dist/brush.js +185 -0
  21. package/dist/bucket.d.ts +22 -0
  22. package/dist/bucket.js +62 -0
  23. package/dist/callout.d.ts +30 -0
  24. package/dist/callout.js +98 -0
  25. package/dist/chart.d.ts +126 -0
  26. package/dist/chart.js +257 -0
  27. package/dist/crosshair.d.ts +28 -0
  28. package/dist/crosshair.js +78 -0
  29. package/dist/cursor.d.ts +76 -0
  30. package/dist/cursor.js +344 -0
  31. package/dist/curve.d.ts +50 -0
  32. package/dist/curve.js +87 -0
  33. package/dist/curves.d.ts +104 -0
  34. package/dist/curves.js +375 -0
  35. package/dist/data.d.ts +209 -0
  36. package/dist/data.js +276 -0
  37. package/dist/decimation.d.ts +86 -0
  38. package/dist/decimation.js +410 -0
  39. package/dist/density.d.ts +55 -0
  40. package/dist/density.js +252 -0
  41. package/dist/dimension.d.ts +103 -0
  42. package/dist/dimension.js +205 -0
  43. package/dist/dom-platform.d.ts +53 -0
  44. package/dist/dom-platform.js +190 -0
  45. package/dist/element.d.ts +232 -0
  46. package/dist/element.js +414 -0
  47. package/dist/errors.d.ts +85 -0
  48. package/dist/errors.js +237 -0
  49. package/dist/events.d.ts +144 -0
  50. package/dist/events.js +19 -0
  51. package/dist/focus.d.ts +22 -0
  52. package/dist/focus.js +51 -0
  53. package/dist/furniture.d.ts +70 -0
  54. package/dist/furniture.js +166 -0
  55. package/dist/geometry.d.ts +40 -0
  56. package/dist/geometry.js +7 -0
  57. package/dist/heatmap.d.ts +57 -0
  58. package/dist/heatmap.js +207 -0
  59. package/dist/hit.d.ts +103 -0
  60. package/dist/hit.js +428 -0
  61. package/dist/index.d.ts +73 -0
  62. package/dist/index.js +73 -0
  63. package/dist/input.d.ts +42 -0
  64. package/dist/input.js +166 -0
  65. package/dist/jsx-dev-runtime.d.ts +9 -0
  66. package/dist/jsx-dev-runtime.js +13 -0
  67. package/dist/jsx-runtime.d.ts +59 -0
  68. package/dist/jsx-runtime.js +81 -0
  69. package/dist/key.d.ts +118 -0
  70. package/dist/key.js +199 -0
  71. package/dist/legend.d.ts +36 -0
  72. package/dist/legend.js +220 -0
  73. package/dist/mapped.d.ts +80 -0
  74. package/dist/mapped.js +106 -0
  75. package/dist/marker.d.ts +143 -0
  76. package/dist/marker.js +213 -0
  77. package/dist/panzoom.d.ts +119 -0
  78. package/dist/panzoom.js +467 -0
  79. package/dist/plane.d.ts +173 -0
  80. package/dist/plane.js +370 -0
  81. package/dist/platform.d.ts +113 -0
  82. package/dist/platform.js +80 -0
  83. package/dist/png.d.ts +44 -0
  84. package/dist/png.js +71 -0
  85. package/dist/pointer.d.ts +54 -0
  86. package/dist/pointer.js +132 -0
  87. package/dist/quantile.d.ts +3 -0
  88. package/dist/quantile.js +11 -0
  89. package/dist/radial.d.ts +116 -0
  90. package/dist/radial.js +336 -0
  91. package/dist/react.d.ts +441 -0
  92. package/dist/react.js +252 -0
  93. package/dist/registry.d.ts +2 -0
  94. package/dist/registry.js +51 -0
  95. package/dist/renderer.d.ts +191 -0
  96. package/dist/renderer.js +164 -0
  97. package/dist/scale.d.ts +37 -0
  98. package/dist/scale.js +19 -0
  99. package/dist/scales.d.ts +69 -0
  100. package/dist/scales.js +134 -0
  101. package/dist/serialize.d.ts +77 -0
  102. package/dist/serialize.js +321 -0
  103. package/dist/series.d.ts +304 -0
  104. package/dist/series.js +513 -0
  105. package/dist/simple.d.ts +35 -0
  106. package/dist/simple.js +20 -0
  107. package/dist/sources.d.ts +116 -0
  108. package/dist/sources.js +237 -0
  109. package/dist/stack.d.ts +61 -0
  110. package/dist/stack.js +172 -0
  111. package/dist/stats.d.ts +38 -0
  112. package/dist/stats.js +159 -0
  113. package/dist/steps.d.ts +50 -0
  114. package/dist/steps.js +154 -0
  115. package/dist/stub.d.ts +3 -0
  116. package/dist/stub.js +5 -0
  117. package/dist/style-names.d.ts +1 -0
  118. package/dist/style-names.js +6 -0
  119. package/dist/summary.d.ts +44 -0
  120. package/dist/summary.js +58 -0
  121. package/dist/surface.d.ts +94 -0
  122. package/dist/surface.js +145 -0
  123. package/dist/table.d.ts +39 -0
  124. package/dist/table.js +37 -0
  125. package/dist/text.d.ts +23 -0
  126. package/dist/text.js +44 -0
  127. package/dist/theme.d.ts +174 -0
  128. package/dist/theme.js +73 -0
  129. package/dist/themes.d.ts +9 -0
  130. package/dist/themes.js +56 -0
  131. package/dist/time-intl.d.ts +194 -0
  132. package/dist/time-intl.js +144 -0
  133. package/dist/time-temporal.d.ts +236 -0
  134. package/dist/time-temporal.js +58 -0
  135. package/dist/time.d.ts +216 -0
  136. package/dist/time.js +154 -0
  137. package/dist/trend.d.ts +151 -0
  138. package/dist/trend.js +500 -0
  139. package/dist/web-components.d.ts +62 -0
  140. package/dist/web-components.js +264 -0
  141. package/package.json +48 -3
package/dist/react.js ADDED
@@ -0,0 +1,252 @@
1
+ /**
2
+ * The React adapter: a chart written as React components, drawing through the same element tree as any other chart.
3
+ *
4
+ * import { Chart, CartesianPlane, Axis, LinearScale } from 'inkplot/react';
5
+ * import { lightTheme } from 'inkplot';
6
+ *
7
+ * <Chart theme={lightTheme} hostProps={{ style: { height: 300 } }}>
8
+ * <CartesianPlane>
9
+ * <Axis meta-title="Time"><LinearScale /></Axis>
10
+ * …
11
+ *
12
+ * Every concrete element class has a component of the same name, exported from here. Each is made by a call marked pure,
13
+ * so a bundler keeps only the ones you use, and the classes behind the rest stay out. For a class of your own, make
14
+ * its component with `reactWrapper(MyClass)`. The one with no wrapper above it is the root: it
15
+ * renders a `<div>` and attaches the chart to it (`hostProps` are that div's props, `platformOptions` the DOMPlatform's).
16
+ *
17
+ * How the two trees stay one:
18
+ * - Every wrapper instance owns one element, made on its first render and never swapped. React decides which instance is
19
+ * which (by position and key), so a reorder moves instances and a changed tag type makes a new one.
20
+ * - Rendering only collects. Each wrapper, as it renders, adds its element to the list its parent started. Nothing in the
21
+ * element tree is touched until React commits: then each wrapper links its element into its parent's, puts the
22
+ * parent's children in the order the list says, and writes the attributes that differ. So an abandoned render (Strict
23
+ * Mode, an interrupted transition) changes nothing, and unchanged attributes cost a comparison.
24
+ * - Attributes come from props (`meta-title`, `style-axis-color` nest as in attrs.ts). Plain objects and arrays are compared by content, so
25
+ * `meta={{ title }}` written in a render does not invalidate the chart each time. Functions are compared by identity: memoize them.
26
+ *
27
+ * Limits, which follow from the element tree having no idea where React put things:
28
+ * - A chart element that appears through state in a component *between* chart elements joins its parent in the right
29
+ * place only if the parent renders too; otherwise it goes last. Keep the condition in the component that renders the parent.
30
+ * - Do not wrap a component that renders chart elements in `React.memo`, or hand chart elements down as `children` through a
31
+ * component that re-renders by itself: a child that does not render is not in the list, so it cannot be reordered (it stays where it is).
32
+ * - Fixed children (an axis' scale) come first in the order the class' documentation gives; the order is not type-checked.
33
+ */
34
+ import { createContext, createElement, forwardRef, useContext, useImperativeHandle, useLayoutEffect, useRef } from 'react';
35
+ import { attributesOf, difference } from './adapt.js';
36
+ import { DOMPlatform } from './dom-platform.js';
37
+ import * as annotation_ from './annotation.js';
38
+ import * as boxplot_ from './boxplot.js';
39
+ import * as boxzoom_ from './boxzoom.js';
40
+ import * as brush_ from './brush.js';
41
+ import * as axis_ from './axis.js';
42
+ import * as bars_ from './bars.js';
43
+ import * as chart_ from './chart.js';
44
+ import * as crosshair_ from './crosshair.js';
45
+ import * as errors_ from './errors.js';
46
+ import * as cursor_ from './cursor.js';
47
+ import * as curve_ from './curve.js';
48
+ import * as curves_ from './curves.js';
49
+ import * as decimation_ from './decimation.js';
50
+ import * as furniture_ from './furniture.js';
51
+ import * as key_ from './key.js';
52
+ import * as legend_ from './legend.js';
53
+ import * as mapped_ from './mapped.js';
54
+ import * as trend_ from './trend.js';
55
+ import * as heatmap_ from './heatmap.js';
56
+ import * as marker_ from './marker.js';
57
+ import * as panzoom_ from './panzoom.js';
58
+ import * as plane_ from './plane.js';
59
+ import * as pointer_ from './pointer.js';
60
+ import * as radial_ from './radial.js';
61
+ import * as renderer_ from './renderer.js';
62
+ import * as scales_ from './scales.js';
63
+ import * as series_ from './series.js';
64
+ import * as sources_ from './sources.js';
65
+ import * as stack_ from './stack.js';
66
+ import * as density_ from './density.js';
67
+ import * as stats_ from './stats.js';
68
+ import * as steps_ from './steps.js';
69
+ import * as summary_ from './summary.js';
70
+ import * as time_intl_ from './time-intl.js';
71
+ import * as time_temporal_ from './time-temporal.js';
72
+ const ParentContext = createContext(null);
73
+ /** Put `element` among the parent's children before the first later sibling in the render list that is already there. */
74
+ function place(parent, element) {
75
+ let found = false;
76
+ for (const other of parent.list) {
77
+ if (found && other.parent === parent.element) {
78
+ parent.element.insertBefore(element, other);
79
+ return;
80
+ }
81
+ if (other === element)
82
+ found = true;
83
+ }
84
+ parent.element.append(element);
85
+ }
86
+ /**
87
+ * Bring a parent's children into the order its render listed them. Only when every child linked now was in the list: a child
88
+ * that did not render this time (memoized, say) is not in it, and nothing is known about where it belongs.
89
+ */
90
+ function reorder(self) {
91
+ if (self.list.size !== self.mounted.size)
92
+ return;
93
+ let at = self.element.firstChild;
94
+ for (const child of self.list) {
95
+ if (child === at) {
96
+ at = at.nextSibling;
97
+ continue;
98
+ }
99
+ if (child.parent === self.element)
100
+ self.element.remove(child);
101
+ self.element.insertBefore(child, at);
102
+ }
103
+ }
104
+ /** Attach `chart` to a div and release it again; used by the root wrapper and by `ChartView`. */
105
+ function useAttached(chart, hostRef, options) {
106
+ const size = options?.size;
107
+ useLayoutEffect(() => {
108
+ const host = hostRef.current;
109
+ if (!host)
110
+ return;
111
+ const platform = new DOMPlatform(host, options);
112
+ // oxlint-disable-next-line typescript/consistent-type-assertions -- the ref holds a chart element, which a React ref cannot be typed as
113
+ chart.attach(platform);
114
+ return () => {
115
+ // oxlint-disable-next-line typescript/consistent-type-assertions -- the ref holds a chart element, which a React ref cannot be typed as
116
+ chart.detach();
117
+ platform.dispose();
118
+ };
119
+ // The platform is made again only for a change that needs a new one.
120
+ // eslint-disable-next-line react-hooks/exhaustive-deps
121
+ }, [chart, size?.width, size?.height, options?.preciseText, options?.schedule]);
122
+ }
123
+ /** The host div's props: it fills what it is in unless told otherwise. */
124
+ const hostPropsOf = (props, ref) => ({ ...props, ref, style: { width: '100%', height: '100%', ...props?.style } });
125
+ /**
126
+ * A React component for a chart element class. Its props are the element's attributes (hyphenated names nest) and its
127
+ * children are the element's children. A `ref` receives the element. See the notes at the top of this file.
128
+ */
129
+ export function reactWrapper(cls) {
130
+ const Wrapper = forwardRef((props, ref) => {
131
+ const parent = useContext(ParentContext);
132
+ const host = useRef(null);
133
+ const state = useRef(null);
134
+ // oxlint-disable-next-line typescript/consistent-type-assertions -- the props of a generic component, split into the ones this wrapper owns
135
+ const { children, hostProps, platformOptions, ...rest } = props;
136
+ const next = attributesOf(rest);
137
+ if (!state.current) {
138
+ const element = new cls(next);
139
+ state.current = { element, applied: next, self: { element, list: new Set(), mounted: new Set() } };
140
+ }
141
+ const s = state.current;
142
+ // Rendering only collects: this render's children report to the list as they render, and this element reports to its parent's.
143
+ s.self.list.clear();
144
+ parent?.list.add(s.element);
145
+ useImperativeHandle(ref, () => s.element, [s.element]);
146
+ // Committing: attributes first, then the place among the siblings, then the children's order. Children's effects ran before these.
147
+ useLayoutEffect(() => {
148
+ const patch = difference(s.applied, next);
149
+ if (patch)
150
+ s.element.setAttributes(patch);
151
+ s.applied = next;
152
+ });
153
+ useLayoutEffect(() => {
154
+ if (!parent)
155
+ return;
156
+ parent.mounted.add(s.element);
157
+ place(parent, s.element);
158
+ return () => {
159
+ parent.mounted.delete(s.element);
160
+ if (s.element.parent === parent.element)
161
+ parent.element.remove(s.element);
162
+ };
163
+ }, [parent, s.element]);
164
+ useLayoutEffect(() => reorder(s.self));
165
+ // The root is attached last, to a tree that is complete.
166
+ useAttached(s.element, host, parent ? undefined : platformOptions);
167
+ const inside = createElement(ParentContext.Provider, { value: s.self }, children);
168
+ return parent ? inside : createElement('div', hostPropsOf(hostProps, host), inside);
169
+ });
170
+ Wrapper.displayName = cls.name || 'Element';
171
+ // oxlint-disable-next-line typescript/consistent-type-assertions -- the wrapper is typed per element class by the caller's declaration
172
+ return Wrapper;
173
+ }
174
+ /**
175
+ * Shows a chart made some other way (with `new`, or with the JSX runtime) in React. The chart is attached while this is mounted
176
+ * and detached when it is not; its attributes and children are yours to change, as the chart is not React's.
177
+ */
178
+ export function ChartView(props) {
179
+ const host = useRef(null);
180
+ useAttached(props.chart, host, props.platformOptions);
181
+ return createElement('div', hostPropsOf(props.hostProps, host));
182
+ }
183
+ // ── Built-in components: one per concrete element class (the ones in `registry`). Each is a pure call, so a bundler drops the
184
+ // wrappers you do not use, and with them the classes they name. `reactWrapper` stays for classes of your own.
185
+ export const Chart = /* @__PURE__ */ reactWrapper(chart_.Chart);
186
+ export const ChartTitle = /* @__PURE__ */ reactWrapper(furniture_.ChartTitle);
187
+ export const ChartTooltip = /* @__PURE__ */ reactWrapper(furniture_.ChartTooltip);
188
+ export const ChartSummary = /* @__PURE__ */ reactWrapper(summary_.ChartSummary);
189
+ export const Cursor = /* @__PURE__ */ reactWrapper(cursor_.Cursor);
190
+ export const Crosshair = /* @__PURE__ */ reactWrapper(crosshair_.Crosshair);
191
+ export const Legend = /* @__PURE__ */ reactWrapper(legend_.Legend);
192
+ export const CartesianPlane = /* @__PURE__ */ reactWrapper(plane_.CartesianPlane);
193
+ export const PolarPlane = /* @__PURE__ */ reactWrapper(radial_.PolarPlane);
194
+ export const RadarPlane = /* @__PURE__ */ reactWrapper(radial_.RadarPlane);
195
+ export const Axis = /* @__PURE__ */ reactWrapper(axis_.Axis);
196
+ export const ColorAxis = /* @__PURE__ */ reactWrapper(mapped_.ColorAxis);
197
+ export const SizeAxis = /* @__PURE__ */ reactWrapper(mapped_.SizeAxis);
198
+ export const ColorKey = /* @__PURE__ */ reactWrapper(key_.ColorKey);
199
+ export const SizeKey = /* @__PURE__ */ reactWrapper(key_.SizeKey);
200
+ export const LinearScale = /* @__PURE__ */ reactWrapper(scales_.LinearScale);
201
+ export const LogScale = /* @__PURE__ */ reactWrapper(scales_.LogScale);
202
+ export const SqrtScale = /* @__PURE__ */ reactWrapper(scales_.SqrtScale);
203
+ export const BandScale = /* @__PURE__ */ reactWrapper(scales_.BandScale);
204
+ export const IntlTimeScale = /* @__PURE__ */ reactWrapper(time_intl_.IntlTimeScale);
205
+ export const TemporalTimeScale = /* @__PURE__ */ reactWrapper(time_temporal_.TemporalTimeScale);
206
+ export const DomainSeries = /* @__PURE__ */ reactWrapper(series_.DomainSeries);
207
+ export const XYSeries = /* @__PURE__ */ reactWrapper(series_.XYSeries);
208
+ export const Stack = /* @__PURE__ */ reactWrapper(stack_.Stack);
209
+ export const FlatDataSource = /* @__PURE__ */ reactWrapper(sources_.FlatDataSource);
210
+ export const ObjectDataSource = /* @__PURE__ */ reactWrapper(sources_.ObjectDataSource);
211
+ export const CompositeDataSource = /* @__PURE__ */ reactWrapper(sources_.CompositeDataSource);
212
+ export const SyntheticDataSource = /* @__PURE__ */ reactWrapper(sources_.SyntheticDataSource);
213
+ export const Decimator = /* @__PURE__ */ reactWrapper(decimation_.Decimator);
214
+ export const MinMaxKernel = /* @__PURE__ */ reactWrapper(decimation_.MinMaxKernel);
215
+ export const M4Kernel = /* @__PURE__ */ reactWrapper(decimation_.M4Kernel);
216
+ export const LttbKernel = /* @__PURE__ */ reactWrapper(decimation_.LttbKernel);
217
+ export const StrideKernel = /* @__PURE__ */ reactWrapper(decimation_.StrideKernel);
218
+ export const LinePath = /* @__PURE__ */ reactWrapper(renderer_.LinePath);
219
+ export const AreaPath = /* @__PURE__ */ reactWrapper(renderer_.AreaPath);
220
+ export const LinearCurve = /* @__PURE__ */ reactWrapper(curve_.LinearCurve);
221
+ export const MonotoneCurve = /* @__PURE__ */ reactWrapper(curves_.MonotoneCurve);
222
+ export const NaturalCurve = /* @__PURE__ */ reactWrapper(curves_.NaturalCurve);
223
+ export const CardinalCurve = /* @__PURE__ */ reactWrapper(curves_.CardinalCurve);
224
+ export const CatmullRomCurve = /* @__PURE__ */ reactWrapper(curves_.CatmullRomCurve);
225
+ export const BasisCurve = /* @__PURE__ */ reactWrapper(curves_.BasisCurve);
226
+ export const BumpCurve = /* @__PURE__ */ reactWrapper(curves_.BumpCurve);
227
+ export const QuadraticCurve = /* @__PURE__ */ reactWrapper(curves_.QuadraticCurve);
228
+ export const ArcCurve = /* @__PURE__ */ reactWrapper(curves_.ArcCurve);
229
+ export const StepCurve = /* @__PURE__ */ reactWrapper(steps_.StepCurve);
230
+ export const BarPath = /* @__PURE__ */ reactWrapper(bars_.BarPath);
231
+ export const BarLinePath = /* @__PURE__ */ reactWrapper(bars_.BarLinePath);
232
+ export const BoxPath = /* @__PURE__ */ reactWrapper(boxplot_.BoxPath);
233
+ export const BoxStats = /* @__PURE__ */ reactWrapper(stats_.BoxStats);
234
+ export const Density = /* @__PURE__ */ reactWrapper(density_.Density);
235
+ export const ErrorBars = /* @__PURE__ */ reactWrapper(errors_.ErrorBars);
236
+ export const ErrorBand = /* @__PURE__ */ reactWrapper(errors_.ErrorBand);
237
+ export const LinearTrend = /* @__PURE__ */ reactWrapper(trend_.LinearTrend);
238
+ export const PolynomialTrend = /* @__PURE__ */ reactWrapper(trend_.PolynomialTrend);
239
+ export const SinusoidalTrend = /* @__PURE__ */ reactWrapper(trend_.SinusoidalTrend);
240
+ export const LoessTrend = /* @__PURE__ */ reactWrapper(trend_.LoessTrend);
241
+ export const HeatMap = /* @__PURE__ */ reactWrapper(heatmap_.HeatMap);
242
+ export const DotMarker = /* @__PURE__ */ reactWrapper(marker_.DotMarker);
243
+ export const CrossMarker = /* @__PURE__ */ reactWrapper(marker_.CrossMarker);
244
+ export const PlusMarker = /* @__PURE__ */ reactWrapper(marker_.PlusMarker);
245
+ export const CircleMarker = /* @__PURE__ */ reactWrapper(marker_.CircleMarker);
246
+ export const SquareMarker = /* @__PURE__ */ reactWrapper(marker_.SquareMarker);
247
+ export const LineAnnotation = /* @__PURE__ */ reactWrapper(annotation_.LineAnnotation);
248
+ export const CalloutAnnotation = /* @__PURE__ */ reactWrapper(annotation_.CalloutAnnotation);
249
+ export const BoxZoom = /* @__PURE__ */ reactWrapper(boxzoom_.BoxZoom);
250
+ export const Brush = /* @__PURE__ */ reactWrapper(brush_.Brush);
251
+ export const PanZoom = /* @__PURE__ */ reactWrapper(panzoom_.PanZoom);
252
+ export const PointerListener = /* @__PURE__ */ reactWrapper(pointer_.PointerListener);
@@ -0,0 +1,2 @@
1
+ import type { ElementRegistry } from './serialize.ts';
2
+ export declare const registry: ElementRegistry;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Every element class the library ships, by the name it is written under in JSON (see serialize.ts). This module names
3
+ * every class, so importing it brings them all into a bundle: it is for tools and configuration-driven pages, and a page
4
+ * that builds its charts in code never needs it. To add classes of your own: `{ ...registry, MyScale }`.
5
+ */
6
+ import { CalloutAnnotation, LineAnnotation } from './annotation.js';
7
+ import { Axis } from './axis.js';
8
+ import { BarLinePath, BarPath } from './bars.js';
9
+ import { BoxPath } from './boxplot.js';
10
+ import { BoxStats } from './stats.js';
11
+ import { Chart } from './chart.js';
12
+ import { ErrorBand, ErrorBars } from './errors.js';
13
+ import { LinearCurve } from './curve.js';
14
+ import { ArcCurve, BasisCurve, BumpCurve, CardinalCurve, CatmullRomCurve, MonotoneCurve, NaturalCurve, QuadraticCurve } from './curves.js';
15
+ import { CompositeDataSource, FlatDataSource, ObjectDataSource, SyntheticDataSource } from './sources.js';
16
+ import { Decimator, LttbKernel, M4Kernel, MinMaxKernel, StrideKernel } from './decimation.js';
17
+ import { ChartTitle, ChartTooltip } from './furniture.js';
18
+ import { Cursor } from './cursor.js';
19
+ import { Crosshair } from './crosshair.js';
20
+ import { ColorKey, SizeKey } from './key.js';
21
+ import { Legend } from './legend.js';
22
+ import { ColorAxis, SizeAxis } from './mapped.js';
23
+ import { LinearTrend, LoessTrend, PolynomialTrend, SinusoidalTrend } from './trend.js';
24
+ import { HeatMap } from './heatmap.js';
25
+ import { CircleMarker, CrossMarker, DotMarker, PlusMarker, SquareMarker } from './marker.js';
26
+ import { BoxZoom } from './boxzoom.js';
27
+ import { Density } from './density.js';
28
+ import { Brush } from './brush.js';
29
+ import { PanZoom } from './panzoom.js';
30
+ import { ChartSummary } from './summary.js';
31
+ import { CartesianPlane } from './plane.js';
32
+ import { PointerListener } from './pointer.js';
33
+ import { PolarPlane, RadarPlane } from './radial.js';
34
+ import { AreaPath, LinePath } from './renderer.js';
35
+ import { BandScale, LinearScale, LogScale, SqrtScale } from './scales.js';
36
+ import { DomainSeries, XYSeries } from './series.js';
37
+ import { Stack } from './stack.js';
38
+ import { StepCurve } from './steps.js';
39
+ import { IntlTimeScale } from './time-intl.js';
40
+ import { TemporalTimeScale } from './time-temporal.js';
41
+ export const registry = {
42
+ Chart, ChartTitle, ChartTooltip, ChartSummary, Cursor, Crosshair, Legend,
43
+ CartesianPlane, PolarPlane, RadarPlane,
44
+ Axis, ColorAxis, SizeAxis, ColorKey, SizeKey,
45
+ LinearScale, LogScale, SqrtScale, BandScale, IntlTimeScale, TemporalTimeScale,
46
+ DomainSeries, XYSeries, Stack,
47
+ FlatDataSource, ObjectDataSource, CompositeDataSource, SyntheticDataSource,
48
+ Decimator, MinMaxKernel, M4Kernel, LttbKernel, StrideKernel,
49
+ LinePath, AreaPath, LinearCurve, MonotoneCurve, NaturalCurve, CardinalCurve, CatmullRomCurve, BasisCurve, BumpCurve, QuadraticCurve, ArcCurve, StepCurve, BarPath, BarLinePath, BoxPath, BoxStats, Density, HeatMap, LinearTrend, PolynomialTrend, SinusoidalTrend, LoessTrend, ErrorBars, ErrorBand, DotMarker, CrossMarker, PlusMarker, CircleMarker, SquareMarker,
50
+ LineAnnotation, CalloutAnnotation, PanZoom, BoxZoom, Brush, PointerListener,
51
+ };
@@ -0,0 +1,191 @@
1
+ import type { PointBuffer } from './data.ts';
2
+ import type { Extent } from './geometry.ts';
3
+ import type { HitMode } from './hit.ts';
4
+ import { Curve } from './curve.ts';
5
+ import { type AnyElement, type BaseAttributes, ChartElement } from './element.ts';
6
+ import { type ChartEvent } from './events.ts';
7
+ import type { Bindings, MappedDimension } from './mapped.ts';
8
+ import type { PlatformNode } from './platform.ts';
9
+ import type { Series } from './series.ts';
10
+ import type { Surface } from './surface.ts';
11
+ /** The attributes any renderer can bind. Colours are CSS colour strings; widths and opacity are numbers. */
12
+ export interface StyleBindable {
13
+ stroke: string;
14
+ fill: string;
15
+ strokeWidth: number;
16
+ opacity: number;
17
+ }
18
+ export interface SeriesRendererAttributes<Bindable extends object = StyleBindable> extends BaseAttributes {
19
+ /** Outline colour (a CSS colour). Default: from the theme. */
20
+ stroke?: string;
21
+ /** Outline width in pixels. Default: from the theme. */
22
+ strokeWidth?: number;
23
+ /** Fill colour (a CSS colour; 'none' for no fill). Default: from the theme. */
24
+ fill?: string;
25
+ /** Opacity from 0 to 1. Default 1. */
26
+ opacity?: number;
27
+ /**
28
+ * Attributes fed from data instead of fixed. The constant above stays as the fallback, so
29
+ * `{ strokeWidth: 0.5, bind: { stroke: { axis: heat, channel: 'p' } } }` mixes the two freely.
30
+ * Binding an attribute the renderer cannot vary is a compile error; so is a dimension of the wrong type.
31
+ */
32
+ bind?: Bindings<Bindable>;
33
+ /**
34
+ * Most paths this renderer may create. Each stylistic binding (one that has to vary per path: a colour, a width,
35
+ * an opacity) is quantized to `floor(maxNodes ** (1 / k))` buckets for k such bindings, so the count of paths
36
+ * in use cannot exceed it. Geometric bindings (a cross's size, a bubble's radius) go into the path data and cost
37
+ * nothing. Attaching throws if that leaves fewer than 2 buckets. Default 1000.
38
+ */
39
+ maxNodes?: number;
40
+ }
41
+ /** The rows a renderer is asked about by `spread`: the series' values as they sit, which columns hold what, and where a stack puts each row. */
42
+ export interface SpreadView {
43
+ readonly raw: Float64Array;
44
+ readonly count: number;
45
+ readonly stride: number;
46
+ readonly firstColumn: number;
47
+ readonly secondColumn: number;
48
+ /** The column of a channel in `raw`, or -1. */
49
+ channelColumn(name: string): number;
50
+ /** Where a stack plots each row's value, or null outside a stack. */
51
+ readonly top: Float64Array | null;
52
+ }
53
+ /** Extents a renderer asks of the series' two axes, in data units. */
54
+ export interface Spread {
55
+ first?: Extent;
56
+ second?: Extent;
57
+ }
58
+ /** What a renderer ended up binding, after resolving refs. The series reads this to know which channels to request. */
59
+ export interface ResolvedBinding {
60
+ readonly property: string;
61
+ readonly channel: string;
62
+ readonly axis: MappedDimension<unknown>;
63
+ /** True when the value varies per path (and so is quantized), false when it goes into the path data. */
64
+ readonly stylistic: boolean;
65
+ }
66
+ /** Closed outlines in plot pixels, `perShape` points each (a `NaN` shape is left out): what a renderer that draws shapes can say it drew. */
67
+ export interface PolygonSet {
68
+ readonly data: Float64Array;
69
+ readonly perShape: number;
70
+ readonly count: number;
71
+ }
72
+ /**
73
+ * The line a renderer actually draws, when it is not the straight one through the series' points (steps, curves): the
74
+ * path of placed points that a pointer is measured against, so that a hit or a reading is on what is on the screen.
75
+ */
76
+ export interface Trace {
77
+ /** The path in plot pixels, each run of it (a stretch between gaps) ended by a NaN point. */
78
+ readonly line: PointBuffer;
79
+ /** For each vertex of `line`, the index of the series' own point it belongs to, which is what a hit on it reports; -1 at the NaN ending a run. */
80
+ readonly owner: Int32Array;
81
+ /** For a filled shape, the path it closes back along (its baseline), run for run with `line`, and null for a line. */
82
+ readonly base: PointBuffer | null;
83
+ }
84
+ /** Any series renderer. `any` because renderers are invariant in their attributes and children, so no concrete renderer type accepts every one. */
85
+ export type AnySeriesRenderer = SeriesRenderer<any, any>;
86
+ /** Draws a series' projected points into its own surface. */
87
+ export declare abstract class SeriesRenderer<A extends SeriesRendererAttributes<object> = SeriesRendererAttributes, Children extends readonly AnyElement[] = []> extends ChartElement<Series, Children, A> {
88
+ static attrTypes: {
89
+ fill: 1;
90
+ maxNodes: 2;
91
+ stroke: 1;
92
+ strokeWidth: 2;
93
+ id: 1;
94
+ meta: {
95
+ title: 1;
96
+ description: 1;
97
+ role: 1;
98
+ };
99
+ };
100
+ /** Create or update this renderer's nodes from the placed points. Runs on every PAINT, so it must be idempotent. */
101
+ protected abstract draw(points: Readonly<PointBuffer>): void;
102
+ /**
103
+ * The one colour that stands for what this draws, for a key or a tooltip to show beside the series' name: its line, its
104
+ * fill. Null when it has none (the colour is bound to data, so there is not one).
105
+ */
106
+ get swatch(): string | null;
107
+ /**
108
+ * Draw a sample of what this draws into `parent` (a node of `surface`, the caller's), in a box `width` by `height` from
109
+ * its own top left corner: a short line for a line, a box for an area or bars, one marker for markers. It takes the look
110
+ * the renderer would draw with (theme, attributes, dashes), so a legend or a tooltip shows what is on the plot. Several
111
+ * renderers on a series draw their samples one over another. Nodes are keyed `key…` in `surface`. Default: a box of the
112
+ * `swatch` colour, or nothing for a renderer that has none.
113
+ */
114
+ sample(surface: Surface, parent: PlatformNode, key: string, width: number, height: number): void;
115
+ /** Values this renderer needs the value axis to reach whatever the data says: the baseline bars grow from. Default none. */
116
+ get includes(): readonly number[];
117
+ /**
118
+ * Pixels this draws beyond the places of its points (a marker's radius), which the axes leave room for so that a mark
119
+ * on the end of the data is not cut by the edge of the plot. Default 0.
120
+ */
121
+ get reach(): number;
122
+ /** Half the width of what this draws along the domain, as a fraction of the gap between neighbouring points (bars), which the domain axis leaves room for. Default 0. */
123
+ get spans(): number;
124
+ /** What a pointer hit on the series should measure by default, if this renderer knows: bars say 'shape'. Default no opinion. */
125
+ get hitMode(): HitMode | undefined;
126
+ /** The shapes this draws, one for each point of the series in the same order, for a 'shape' hit. Default none. */
127
+ shapes?(): PolygonSet | null;
128
+ /** The path this draws as a line (or the top of a shape), if it is not the straight one through the points. Hits and readings follow it. Default none. */
129
+ trace?(): Trace | null;
130
+ /**
131
+ * Channels of the data this needs as plain numbers beside each point (error bars: how far each value may be out), with no mapped
132
+ * axis to turn them into anything. The series requests them with the bound ones; in `points` they follow the two coordinates,
133
+ * raw, in the order of `Series.channels`. Default none.
134
+ */
135
+ get channelNames(): readonly string[];
136
+ /**
137
+ * What this draws beyond the values on each axis, over the rows now in view (a stack's rows are at their stacked places):
138
+ * the extents the series adds to its axes, so that error bars are not cut off by the plot. Default none.
139
+ */
140
+ spread?(view: SpreadView): Spread | null;
141
+ /** The same over all the data, for the range zooming is held to. It may be generous. Default none. */
142
+ limit?(series: Series): Spread | null;
143
+ /** Nothing is bound until bindings are written; a renderer that has some will report them here. */
144
+ get bindings(): readonly ResolvedBinding[];
145
+ /** Buckets per stylistic binding, from `maxNodes`. 0 when nothing is stylistically bound. */
146
+ get stepsPerBinding(): number;
147
+ onEvent(ev: ChartEvent): void;
148
+ }
149
+ /** A box in the look of a filled shape: what an area and a bar are in a legend. */
150
+ export declare function paintBox(s: Surface, parent: PlatformNode, key: string, width: number, height: number, look: {
151
+ fill: string;
152
+ stroke: string;
153
+ strokeWidth: number;
154
+ opacity: number;
155
+ }): void;
156
+ export interface LinePathAttributes extends SeriesRendererAttributes {
157
+ }
158
+ /**
159
+ * One path through the points, in the way its `Curve` says: straight lines (`LinearCurve`), a spline, steps. A gap in the
160
+ * data lifts the pen, or is crossed if the series says its `gaps` are 'connect'.
161
+ */
162
+ export declare class LinePath extends SeriesRenderer<LinePathAttributes, [curve: Curve]> {
163
+ /** How the points are joined. */
164
+ get curve(): Curve;
165
+ /** The series' palette colour is the default; a dash pattern is style only (`style: { seriesLine: { dash } }`). */
166
+ protected look(): import("./theme.ts").LineProps;
167
+ get swatch(): string;
168
+ trace(): Trace | null;
169
+ sample(s: Surface, parent: PlatformNode, key: string, width: number, height: number): void;
170
+ protected draw(): void;
171
+ }
172
+ export interface AreaPathAttributes extends SeriesRendererAttributes {
173
+ /** The value the area is filled from, kept inside the value axis' range. Default 0. */
174
+ baseline?: number;
175
+ }
176
+ /**
177
+ * The region between a line and a baseline, the line drawn in the way its `Curve` says. It is the data forward and the
178
+ * baseline backward, closed: the baseline is placed by the plane exactly as the data is, so on a rectangle this is the
179
+ * usual area under a line, and on a PolarPlane it is the ring or wedge between the curve and the baseline circle, with
180
+ * nothing here to say so. A gap in the data splits it into separate shapes. Outlines are off by default; give a `stroke`
181
+ * to draw one.
182
+ */
183
+ export declare class AreaPath extends SeriesRenderer<AreaPathAttributes, [curve: Curve]> {
184
+ /** How the points are joined. */
185
+ get curve(): Curve;
186
+ protected look(): import("./theme.ts").ShapeProps;
187
+ get swatch(): string;
188
+ trace(): Trace | null;
189
+ sample(s: Surface, parent: PlatformNode, key: string, width: number, height: number): void;
190
+ protected draw(): void;
191
+ }