swiftplot 0.0.1 → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +324 -3
- package/dist/chart.d.ts +3 -0
- package/dist/chart.js +1226 -0
- package/dist/charts/controller.d.ts +32 -0
- package/dist/charts/controller.js +231 -0
- package/dist/charts/defaults.d.ts +12 -0
- package/dist/charts/defaults.js +60 -0
- package/dist/charts/fields.d.ts +34 -0
- package/dist/charts/fields.js +167 -0
- package/dist/charts/index.d.ts +6 -0
- package/dist/charts/index.js +3 -0
- package/dist/charts/mount.d.ts +5 -0
- package/dist/charts/mount.js +21 -0
- package/dist/charts/source.d.ts +24 -0
- package/dist/charts/source.js +225 -0
- package/dist/charts/types.d.ts +104 -0
- package/dist/charts/types.js +1 -0
- package/dist/charts/xy.d.ts +36 -0
- package/dist/charts/xy.js +220 -0
- package/dist/features/animate.d.ts +11 -0
- package/dist/features/animate.js +118 -0
- package/dist/features/brush.d.ts +13 -0
- package/dist/features/brush.js +127 -0
- package/dist/features/legend.d.ts +15 -0
- package/dist/features/legend.js +237 -0
- package/dist/features/pointer.d.ts +29 -0
- package/dist/features/pointer.js +23 -0
- package/dist/features/tooltip.d.ts +14 -0
- package/dist/features/tooltip.js +190 -0
- package/dist/features/zoom.d.ts +13 -0
- package/dist/features/zoom.js +228 -0
- package/dist/gl.d.ts +5 -0
- package/dist/gl.js +52 -0
- package/dist/index.d.ts +60 -0
- package/dist/index.js +31 -0
- package/dist/marks/arcs.d.ts +25 -0
- package/dist/marks/arcs.js +124 -0
- package/dist/marks/area.d.ts +24 -0
- package/dist/marks/area.js +106 -0
- package/dist/marks/bar.d.ts +44 -0
- package/dist/marks/bar.js +243 -0
- package/dist/marks/box.d.ts +27 -0
- package/dist/marks/box.js +188 -0
- package/dist/marks/common.d.ts +84 -0
- package/dist/marks/common.js +236 -0
- package/dist/marks/dots.d.ts +15 -0
- package/dist/marks/dots.js +156 -0
- package/dist/marks/errorBars.d.ts +19 -0
- package/dist/marks/errorBars.js +79 -0
- package/dist/marks/funnel.d.ts +25 -0
- package/dist/marks/funnel.js +121 -0
- package/dist/marks/heatmap.d.ts +19 -0
- package/dist/marks/heatmap.js +139 -0
- package/dist/marks/line.d.ts +19 -0
- package/dist/marks/line.js +75 -0
- package/dist/marks/radar.d.ts +22 -0
- package/dist/marks/radar.js +155 -0
- package/dist/marks/radialBars.d.ts +27 -0
- package/dist/marks/radialBars.js +111 -0
- package/dist/marks/rects.d.ts +43 -0
- package/dist/marks/rects.js +120 -0
- package/dist/marks/rule.d.ts +28 -0
- package/dist/marks/rule.js +80 -0
- package/dist/marks/sankey.d.ts +41 -0
- package/dist/marks/sankey.js +366 -0
- package/dist/marks/sunburst.d.ts +26 -0
- package/dist/marks/sunburst.js +185 -0
- package/dist/marks/ticks.d.ts +9 -0
- package/dist/marks/ticks.js +26 -0
- package/dist/marks/tree.d.ts +41 -0
- package/dist/marks/tree.js +110 -0
- package/dist/marks/treemap.d.ts +25 -0
- package/dist/marks/treemap.js +159 -0
- package/dist/paint.d.ts +30 -0
- package/dist/paint.js +66 -0
- package/dist/scale.d.ts +16 -0
- package/dist/scale.js +96 -0
- package/dist/scales/band.d.ts +9 -0
- package/dist/scales/band.js +23 -0
- package/dist/scales/bare.d.ts +3 -0
- package/dist/scales/bare.js +7 -0
- package/dist/scales/color.d.ts +18 -0
- package/dist/scales/color.js +21 -0
- package/dist/scales/log.d.ts +20 -0
- package/dist/scales/log.js +97 -0
- package/dist/scales/time.d.ts +30 -0
- package/dist/scales/time.js +181 -0
- package/dist/theme.d.ts +10 -0
- package/dist/theme.js +8 -0
- package/dist/transforms.d.ts +43 -0
- package/dist/transforms.js +118 -0
- package/dist/types.d.ts +434 -0
- package/dist/types.js +1 -0
- package/package.json +31 -6
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
import type { Theme } from './theme.js';
|
|
2
|
+
export type Col = ArrayLike<number>;
|
|
3
|
+
/** Device pixels: px = ox + x * kx, py = oy - y * ky. left/top/width/height is the plot rectangle. */
|
|
4
|
+
export type View = {
|
|
5
|
+
kx: number;
|
|
6
|
+
ox: number;
|
|
7
|
+
ky: number;
|
|
8
|
+
oy: number;
|
|
9
|
+
left: number;
|
|
10
|
+
top: number;
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
dpr: number;
|
|
14
|
+
ctx: CanvasRenderingContext2D;
|
|
15
|
+
theme: Theme;
|
|
16
|
+
};
|
|
17
|
+
/** A data point and its distance from the pointer in CSS pixels. */
|
|
18
|
+
export type Hit = {
|
|
19
|
+
x: number;
|
|
20
|
+
y: number;
|
|
21
|
+
distance: number;
|
|
22
|
+
/** The row's own value where y is not it, such as a stacked bar's, which y places at its top. */
|
|
23
|
+
value?: number;
|
|
24
|
+
/** Which row of the mark was hit, when it draws one shape per row. */
|
|
25
|
+
row?: number;
|
|
26
|
+
/** The colour of what was hit, where the rows of a mark differ in colour and are not its entries. */
|
|
27
|
+
color?: string;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Text a mark asks to have drawn at a point of the canvas, in device pixels like the rest of what
|
|
31
|
+
* a mark computes. The chart draws it as DOM, leaves out what would run off the chart or onto a
|
|
32
|
+
* label of higher priority (judged at 7 px a character), and shows it as a reveal uncovers it.
|
|
33
|
+
*/
|
|
34
|
+
export type Label = {
|
|
35
|
+
x: number;
|
|
36
|
+
y: number;
|
|
37
|
+
text: string;
|
|
38
|
+
/** Which edge of the text sits at x; 'center' by default. */
|
|
39
|
+
align?: 'start' | 'center' | 'end';
|
|
40
|
+
color?: string;
|
|
41
|
+
/** The higher wins a collision; ties go to the earlier label. */
|
|
42
|
+
priority?: number;
|
|
43
|
+
};
|
|
44
|
+
export type Prepared = {
|
|
45
|
+
labels?: Label[];
|
|
46
|
+
/** Lines across the whole plot at a device pixel, drawn as DOM over every canvas and never dimmed. */
|
|
47
|
+
rules?: {
|
|
48
|
+
x?: number;
|
|
49
|
+
y?: number;
|
|
50
|
+
color: string;
|
|
51
|
+
width: number;
|
|
52
|
+
dashed: boolean;
|
|
53
|
+
}[];
|
|
54
|
+
/**
|
|
55
|
+
* With a row, that row is drawn at `alpha` and the mark's other rows at `alpha * rest`.
|
|
56
|
+
* A mark that does not draw one shape per row ignores both.
|
|
57
|
+
*/
|
|
58
|
+
paint(alpha: number, row?: number, rest?: number): void;
|
|
59
|
+
/** Draws these rows again over what paint() drew, at full strength, outlined inside in `outline`. */
|
|
60
|
+
select?(rows: readonly number[], outline: string): void;
|
|
61
|
+
/**
|
|
62
|
+
* Present when the mark can move from the shape of the mark it replaced: sets what paint() draws,
|
|
63
|
+
* from that shape (0) to its own (1). It starts at 1, and hit() always answers for 1.
|
|
64
|
+
*/
|
|
65
|
+
morph?(t: number): void;
|
|
66
|
+
/**
|
|
67
|
+
* px, py and max are CSS pixels relative to the chart. A mark hit anywhere on its shape, not
|
|
68
|
+
* at a point, reports `max` as its distance, so a point within reach wins over it.
|
|
69
|
+
*/
|
|
70
|
+
hit?(px: number, py: number, max: number): Hit | null;
|
|
71
|
+
};
|
|
72
|
+
export type GlLayer = {
|
|
73
|
+
gl: WebGL2RenderingContext;
|
|
74
|
+
clear(): void;
|
|
75
|
+
/** Scales everything drawn so far by k, so a focused group can be drawn on top at full strength. */
|
|
76
|
+
fade(k: number): void;
|
|
77
|
+
destroy(): void;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Where a filled mark lies at an x. Its value is the real distance between the edges for a band,
|
|
81
|
+
* else `value`, else y2.
|
|
82
|
+
*/
|
|
83
|
+
export type Sample = {
|
|
84
|
+
y1: number;
|
|
85
|
+
y2: number;
|
|
86
|
+
band?: boolean;
|
|
87
|
+
value?: number;
|
|
88
|
+
};
|
|
89
|
+
export type Mark = {
|
|
90
|
+
/** Names the implementation, e.g. 'line'. */
|
|
91
|
+
type: string;
|
|
92
|
+
/** Identity across update(); defaults to the position in `marks`. */
|
|
93
|
+
key?: string;
|
|
94
|
+
label?: string;
|
|
95
|
+
/** Marks of one group are focused and dimmed together. */
|
|
96
|
+
group?: string;
|
|
97
|
+
color: string;
|
|
98
|
+
/**
|
|
99
|
+
* Compared shallowly, with `type`, across update(): an equal mark keeps its prepared geometry.
|
|
100
|
+
* Values written into the same array are not seen; pass a new array or view to redraw.
|
|
101
|
+
*/
|
|
102
|
+
options: object;
|
|
103
|
+
points: number;
|
|
104
|
+
/** Columns the 'nice' domains are computed from. */
|
|
105
|
+
channels: {
|
|
106
|
+
x: Col[];
|
|
107
|
+
y: Col[];
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Called once per view change; the result is kept and repainted. `previous` is the mark of the
|
|
111
|
+
* same type and key that an update replaced with this one; it has been released by then.
|
|
112
|
+
*/
|
|
113
|
+
prepare(view: View, previous?: Mark): Prepared;
|
|
114
|
+
/**
|
|
115
|
+
* Used instead of prepare() once the marks sharing the chart's layer hold enough points.
|
|
116
|
+
* The first such mark's `layer` makes the chart's layer; a mark with another `layer` stays on canvas.
|
|
117
|
+
*/
|
|
118
|
+
gl?: {
|
|
119
|
+
layer: (canvas: HTMLCanvasElement) => GlLayer | null;
|
|
120
|
+
prepare: (view: View, layer: GlLayer) => Prepared;
|
|
121
|
+
/** The points at which this mark alone asks for the layer: 10,000 when left out. Marks add up by their shares. */
|
|
122
|
+
from?: number;
|
|
123
|
+
/** The mark belongs under those after it, so it stays on the canvas unless they are all on the layer. */
|
|
124
|
+
under?: true;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* What the mark shows at x: a y, or for a filled mark its value and the y range it covers there.
|
|
128
|
+
* A step holds its last sample from there on; a straight line has nothing outside its samples.
|
|
129
|
+
* `straight` asks for a smooth curve as drawn where its rows share a pixel column: straight.
|
|
130
|
+
*/
|
|
131
|
+
sampleAtX?(x: number, straight?: boolean): number | Sample | undefined;
|
|
132
|
+
/** A chart has dropped the mark; `layer` is that chart's, so only what was made for it is freed. */
|
|
133
|
+
release?(layer: GlLayer | null): void;
|
|
134
|
+
/**
|
|
135
|
+
* For a mark coloured by value: the colours, as the pixels of a ColorScale's table, and the
|
|
136
|
+
* values that get the first and the last of them. A legend draws it as a strip.
|
|
137
|
+
*/
|
|
138
|
+
ramp?(): {
|
|
139
|
+
table: Uint32Array;
|
|
140
|
+
lo: number;
|
|
141
|
+
hi: number;
|
|
142
|
+
};
|
|
143
|
+
/** Drawn at full strength whatever is focused, and always on the canvas: a grid behind other marks, say. */
|
|
144
|
+
backdrop?: true;
|
|
145
|
+
/**
|
|
146
|
+
* How far past the plot area the mark may show, in CSS pixels: a point's radius, half a line's
|
|
147
|
+
* width. Without it a point on the edge of the domain is cut in half.
|
|
148
|
+
*/
|
|
149
|
+
overhang?: number;
|
|
150
|
+
/** A reveal uncovers the chart downwards when a mark asks for it; otherwise from the left. */
|
|
151
|
+
reveal?: 'down';
|
|
152
|
+
/**
|
|
153
|
+
* The named parts of a mark that draws several, such as slices, in row order. A legend lists
|
|
154
|
+
* these in place of the mark's own label, and pointing at one focuses that row.
|
|
155
|
+
*/
|
|
156
|
+
entries?: {
|
|
157
|
+
label: string;
|
|
158
|
+
color: string;
|
|
159
|
+
}[];
|
|
160
|
+
/** paint() draws every row alike, so a focused row focuses the mark's group instead; select() still picks rows out. */
|
|
161
|
+
rowsAlike?: true;
|
|
162
|
+
/** paint() draws the mark as one shape and ignores a row, so selecting any of its rows draws it whole. */
|
|
163
|
+
oneShape?: true;
|
|
164
|
+
/**
|
|
165
|
+
* Laid out by the chart with the other shown marks of the same key, such as a stack: `lay` is
|
|
166
|
+
* given them in listed order and returns the marks drawn in their place.
|
|
167
|
+
*/
|
|
168
|
+
arrange?: {
|
|
169
|
+
key: string;
|
|
170
|
+
lay(members: readonly Mark[]): Mark[];
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
/** The rough length of an axis in CSS pixels, and whether its labels run along it (x) or across it (y). */
|
|
174
|
+
export type Room = {
|
|
175
|
+
length: number;
|
|
176
|
+
horizontal: boolean;
|
|
177
|
+
};
|
|
178
|
+
export type Tick = {
|
|
179
|
+
value: number;
|
|
180
|
+
label: string;
|
|
181
|
+
};
|
|
182
|
+
export type Resolved = {
|
|
183
|
+
lo: number;
|
|
184
|
+
hi: number;
|
|
185
|
+
ticks: Tick[];
|
|
186
|
+
};
|
|
187
|
+
export type Axis = {
|
|
188
|
+
/** 'nice' widens the extent of the marks' columns to whole steps; 'data' keeps it exact. */
|
|
189
|
+
domain: [number, number] | 'nice' | 'data';
|
|
190
|
+
label: string;
|
|
191
|
+
/**
|
|
192
|
+
* Replaces the built-in linear scale. It receives the axis itself, so one function serves every
|
|
193
|
+
* axis of its kind and two axes with equal fields compare as equal across update(); a function
|
|
194
|
+
* giving the extent of the marks' columns on this axis, which scans them the first time it is
|
|
195
|
+
* called; and the room there is for ticks. It runs again whenever that room may have changed.
|
|
196
|
+
*/
|
|
197
|
+
scale?(axis: Axis, extent: () => [number, number], room?: Room): Resolved;
|
|
198
|
+
/**
|
|
199
|
+
* Which marks the extent is taken from: those shown (the default), or all of them, hidden or not.
|
|
200
|
+
* 'window', on a y axis with an automatic domain, takes it from the shown marks inside the x window
|
|
201
|
+
* while there is one and y has no window of its own.
|
|
202
|
+
*/
|
|
203
|
+
fit?: 'shown' | 'all' | 'window';
|
|
204
|
+
/**
|
|
205
|
+
* Ticks at the multiples of this, thinned to every k-th when their labels do not fit; 'nice' rounds to it.
|
|
206
|
+
* A step that would give 990 ticks or more across what is shown gives way to the automatic one.
|
|
207
|
+
*/
|
|
208
|
+
step?: number;
|
|
209
|
+
/** The text of each tick, on the built-in scale and on time(); define it once, not anew in each update. */
|
|
210
|
+
format?: (value: number) => string;
|
|
211
|
+
/** A transformed axis, such as log(): a real value in the space the marks' columns are in, and back. */
|
|
212
|
+
to?(real: number, axis: Axis): number;
|
|
213
|
+
from?(v: number, axis: Axis): number;
|
|
214
|
+
};
|
|
215
|
+
export type Margin = {
|
|
216
|
+
top: number;
|
|
217
|
+
right: number;
|
|
218
|
+
bottom: number;
|
|
219
|
+
left: number;
|
|
220
|
+
};
|
|
221
|
+
export type Span = [number, number];
|
|
222
|
+
export type Options = {
|
|
223
|
+
/** CSS pixels; when omitted the chart follows its container. */
|
|
224
|
+
width?: number;
|
|
225
|
+
height?: number;
|
|
226
|
+
/** CSS pixels around the plot area for ticks and labels. A side left out is sized from the labels. */
|
|
227
|
+
margin?: Partial<Margin>;
|
|
228
|
+
/** Each axis is `{ domain: 'nice', label: '' }` when left out. */
|
|
229
|
+
x?: Axis;
|
|
230
|
+
y?: Axis;
|
|
231
|
+
/**
|
|
232
|
+
* 'polar' and 'blank' have no axes: a mark is given the plot rectangle only, and reports a hit
|
|
233
|
+
* as fractions of it, x from the left and y from the bottom. 'polar' is for marks drawn round
|
|
234
|
+
* a centre, such as arcs(); it differs from 'blank' in how a reveal uncovers it.
|
|
235
|
+
*/
|
|
236
|
+
frame?: 'axes' | 'polar' | 'blank';
|
|
237
|
+
marks: Mark[];
|
|
238
|
+
/** Read once, when the chart is created. */
|
|
239
|
+
use?: Feature[];
|
|
240
|
+
/**
|
|
241
|
+
* What assistive technology reads for the chart; by default the axis labels and the names of
|
|
242
|
+
* the labelled marks. The data itself is not exposed.
|
|
243
|
+
*/
|
|
244
|
+
description?: string;
|
|
245
|
+
/** Opacity multiplier for every other group while one is focused. */
|
|
246
|
+
dim?: number;
|
|
247
|
+
/** `light` when left out. Replacing it with another object repaints the chart and restyles its text. */
|
|
248
|
+
theme?: Theme;
|
|
249
|
+
/**
|
|
250
|
+
* The part of each axis shown, in its values; a side left out shows the whole domain. It is shown
|
|
251
|
+
* clamped to the domain but kept as given, so it comes back when the domain grows again.
|
|
252
|
+
*/
|
|
253
|
+
view?: {
|
|
254
|
+
x?: Span;
|
|
255
|
+
y?: Span;
|
|
256
|
+
};
|
|
257
|
+
/**
|
|
258
|
+
* Called with the window shown once a feature has moved it; never for update(). y is left out
|
|
259
|
+
* when the y axis fits the x window and has no window of its own.
|
|
260
|
+
*/
|
|
261
|
+
onViewChange?(view: {
|
|
262
|
+
x: Span;
|
|
263
|
+
y?: Span;
|
|
264
|
+
}): void;
|
|
265
|
+
/** The series not drawn, by the id a legend lists a mark under: its `group`, or its `label`. */
|
|
266
|
+
hidden?: string[];
|
|
267
|
+
/** Called with the hidden ids once a feature has changed them; never for update(). */
|
|
268
|
+
onHiddenChange?(hidden: string[]): void;
|
|
269
|
+
/**
|
|
270
|
+
* Rows the app has picked out, by the id `hidden` uses: drawn at full strength, and every other row
|
|
271
|
+
* at `dim`, while nothing is focused. Bars and dots outline them; a mark drawn as one shape, such as
|
|
272
|
+
* a line or an area, is drawn whole, and other marks draw the rows without an outline. Unknown ids
|
|
273
|
+
* and rows are ignored. A translucent row is drawn over its dimmed copy, so it shows a little
|
|
274
|
+
* stronger than when focused.
|
|
275
|
+
*/
|
|
276
|
+
selected?: {
|
|
277
|
+
id: string;
|
|
278
|
+
rows: number[];
|
|
279
|
+
}[] | null;
|
|
280
|
+
/**
|
|
281
|
+
* Called for a click on the plot, but not for one that ends a drag: with what is within 20 px of
|
|
282
|
+
* it, or null, and the values at the click. While it is set, the cursor is a pointer over a hit.
|
|
283
|
+
*/
|
|
284
|
+
onClick?(hit: (Hit & {
|
|
285
|
+
mark: Mark;
|
|
286
|
+
}) | null, at: {
|
|
287
|
+
x: number;
|
|
288
|
+
y: number;
|
|
289
|
+
}): void;
|
|
290
|
+
/**
|
|
291
|
+
* A pointer to show as if the user's were there, such as another chart's: a tooltip shows at it
|
|
292
|
+
* while the user's own is not on the chart. Without y, an x tooltip focuses no series and a
|
|
293
|
+
* nearest one shows nothing.
|
|
294
|
+
*/
|
|
295
|
+
pointer?: {
|
|
296
|
+
x: number;
|
|
297
|
+
y?: number;
|
|
298
|
+
} | null;
|
|
299
|
+
/** Called as the user's pointer moves over the plot, and with null once as it leaves or a drag starts; never for update(). */
|
|
300
|
+
onPointerChange?(pointer: {
|
|
301
|
+
x: number;
|
|
302
|
+
y: number;
|
|
303
|
+
} | null): void;
|
|
304
|
+
};
|
|
305
|
+
export type Chart = {
|
|
306
|
+
update(options: Partial<Omit<Options, 'use'>>): void;
|
|
307
|
+
destroy(): void;
|
|
308
|
+
};
|
|
309
|
+
/**
|
|
310
|
+
* Wraps a repaint. `draw` paints the chart now; `draw(0)` paints it with no marks. `why` says what
|
|
311
|
+
* changed: the data, the size, or only focus and dimming.
|
|
312
|
+
*/
|
|
313
|
+
export type Painter = (draw: (reveal?: number) => void, why: 'data' | 'size' | 'focus') => void;
|
|
314
|
+
/**
|
|
315
|
+
* What a feature works with. Pixel values are CSS pixels relative to the chart. A feature is set
|
|
316
|
+
* up before the first paint: the pixel helpers, hit(), view() and propose()
|
|
317
|
+
* work from that paint on.
|
|
318
|
+
*/
|
|
319
|
+
export type Internals = {
|
|
320
|
+
root: HTMLElement;
|
|
321
|
+
/** The 2D canvas holding the grid and every mark that is not on WebGL. */
|
|
322
|
+
canvas: HTMLCanvasElement;
|
|
323
|
+
/** One painter per chart; the last one set wins. */
|
|
324
|
+
onPaint(painter: Painter | undefined): void;
|
|
325
|
+
/**
|
|
326
|
+
* Moves the marks changed by the last update between their previous shape (0) and their own (1).
|
|
327
|
+
* False, and nothing moves, unless every changed mark can morph and none was added or removed.
|
|
328
|
+
*/
|
|
329
|
+
morph(t: number): boolean;
|
|
330
|
+
/**
|
|
331
|
+
* The outline, in CSS pixels, of what a reveal has uncovered at this progress: the plot from
|
|
332
|
+
* the left or from the top, or in a polar frame swept round from twelve o'clock.
|
|
333
|
+
*/
|
|
334
|
+
revealed(progress: number): [number, number][];
|
|
335
|
+
/**
|
|
336
|
+
* Keeps room above the plot. `space` is asked on every layout, with the plot's left edge and
|
|
337
|
+
* width in CSS pixels, for the height it needs; it must be cheap and measure nothing.
|
|
338
|
+
* ponytail: one caller, and the top only; other sides when a feature needs them.
|
|
339
|
+
*/
|
|
340
|
+
reserve(space: (left: number, width: number) => number): void;
|
|
341
|
+
/**
|
|
342
|
+
* Uncovers the WebGL layer and the marks' labels to this progress, at an opacity; the next
|
|
343
|
+
* draw() shows all of them again.
|
|
344
|
+
*/
|
|
345
|
+
reveal(progress: number, opacity?: number): void;
|
|
346
|
+
layer<K extends keyof HTMLElementTagNameMap>(tag: K, css?: string): HTMLElementTagNameMap[K];
|
|
347
|
+
/** The marks shown: those listed, less the hidden ones. */
|
|
348
|
+
marks(): readonly Mark[];
|
|
349
|
+
/** Every mark in `marks`, hidden or not. */
|
|
350
|
+
listed(): readonly Mark[];
|
|
351
|
+
hidden(): readonly string[];
|
|
352
|
+
/** Hides these ids, shows the rest, and passes them to onHiddenChange; nothing when they are already hidden. */
|
|
353
|
+
hide(ids: string[]): void;
|
|
354
|
+
size(): {
|
|
355
|
+
width: number;
|
|
356
|
+
height: number;
|
|
357
|
+
};
|
|
358
|
+
margin(): Margin;
|
|
359
|
+
theme(): Theme;
|
|
360
|
+
xPx(x: number): number;
|
|
361
|
+
yPx(y: number): number;
|
|
362
|
+
xValue(px: number): number;
|
|
363
|
+
yValue(px: number): number;
|
|
364
|
+
/** The window shown on each axis, in the marks' space. */
|
|
365
|
+
view(): {
|
|
366
|
+
x: Span;
|
|
367
|
+
y: Span;
|
|
368
|
+
};
|
|
369
|
+
/** The whole domain on each axis: the widest window propose() shows. */
|
|
370
|
+
domain(): {
|
|
371
|
+
x: Span;
|
|
372
|
+
y: Span;
|
|
373
|
+
};
|
|
374
|
+
/**
|
|
375
|
+
* Shows this window, or with null the whole domain, clamped to the domain, and passes it to
|
|
376
|
+
* onViewChange; a side left out keeps its window, and a side given as undefined shows its whole
|
|
377
|
+
* domain. False, and nothing happens, when what is shown would not change.
|
|
378
|
+
*/
|
|
379
|
+
propose(view: {
|
|
380
|
+
x?: Span;
|
|
381
|
+
y?: Span;
|
|
382
|
+
} | null): boolean;
|
|
383
|
+
/** The window propose() would show for this view, without showing it. */
|
|
384
|
+
fit(view: {
|
|
385
|
+
x?: Span;
|
|
386
|
+
y?: Span;
|
|
387
|
+
} | null): {
|
|
388
|
+
x: Span;
|
|
389
|
+
y: Span;
|
|
390
|
+
};
|
|
391
|
+
/** A value in the marks' space as the app sees it. */
|
|
392
|
+
real(axis: 'x' | 'y', v: number): number;
|
|
393
|
+
frame(): NonNullable<Options['frame']>;
|
|
394
|
+
/**
|
|
395
|
+
* Which feature a drag over the plot belongs to. `pan` is 'plain' when every drag pans and a brush
|
|
396
|
+
* gets none, and 'shift' when a drag with shift held pans and a brush keeps the plain ones; with no
|
|
397
|
+
* brush a plain drag then pans too, unless zoom() was given `drag: 'shift'`. `active` is set while
|
|
398
|
+
* a drag or a gesture is under way, and until the click after its release has gone by.
|
|
399
|
+
*/
|
|
400
|
+
drag: {
|
|
401
|
+
brush: boolean;
|
|
402
|
+
pan: 'plain' | 'shift' | false;
|
|
403
|
+
active: boolean;
|
|
404
|
+
};
|
|
405
|
+
/** Runs every feature's update(), for a change under a resting pointer that the chart cannot see, such as the end of a drag. */
|
|
406
|
+
sync(): void;
|
|
407
|
+
hit(px: number, py: number, max: number): (Hit & {
|
|
408
|
+
mark: Mark;
|
|
409
|
+
}) | null;
|
|
410
|
+
/** The app's `pointer`, or null when there is none or its x is outside the plot; a y outside the plot is dropped. */
|
|
411
|
+
pointer(): {
|
|
412
|
+
x: number;
|
|
413
|
+
y?: number;
|
|
414
|
+
} | null;
|
|
415
|
+
/**
|
|
416
|
+
* Dims everything outside the group. When the chart holds no second group to dim, a row focuses
|
|
417
|
+
* that one row of its mark instead and dims the mark's other rows.
|
|
418
|
+
*/
|
|
419
|
+
focus(group: string | null, row?: {
|
|
420
|
+
mark: Mark;
|
|
421
|
+
row: number;
|
|
422
|
+
}): void;
|
|
423
|
+
};
|
|
424
|
+
/**
|
|
425
|
+
* update() runs whenever what is under a resting pointer may have changed: after the first paint, for
|
|
426
|
+
* new options or a new size, a series hidden or shown, a new window, and at the end of a drag.
|
|
427
|
+
* letGo() runs before the repaint for each of these but the first paint, the end of a drag and an
|
|
428
|
+
* update of only `pointer` or callbacks, so a focus dropped there does not cut a data animation short.
|
|
429
|
+
*/
|
|
430
|
+
export type Feature = (chart: Internals) => {
|
|
431
|
+
update?(): void;
|
|
432
|
+
letGo?(): void;
|
|
433
|
+
destroy(): void;
|
|
434
|
+
};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,17 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swiftplot",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Small, fast charts on Canvas 2D and WebGL2
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Small, fast charts on Canvas 2D and WebGL2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/GusevP/swiftplot.git"
|
|
8
|
+
"url": "git+https://github.com/GusevP/swiftplot.git",
|
|
9
|
+
"directory": "packages/core"
|
|
9
10
|
},
|
|
10
11
|
"homepage": "https://github.com/GusevP/swiftplot#readme",
|
|
11
12
|
"bugs": {
|
|
12
13
|
"url": "https://github.com/GusevP/swiftplot/issues"
|
|
13
14
|
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"default": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./charts": {
|
|
23
|
+
"types": "./dist/charts/index.d.ts",
|
|
24
|
+
"default": "./dist/charts/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
14
27
|
"files": [
|
|
15
|
-
"
|
|
16
|
-
]
|
|
17
|
-
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@vitest/browser-playwright": "^5.1.1",
|
|
32
|
+
"playwright": "^1.65.1",
|
|
33
|
+
"typescript": "^7.0.2",
|
|
34
|
+
"vitest": "^5.1.1"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc -p tsconfig.build.json",
|
|
38
|
+
"typecheck": "tsc --noEmit",
|
|
39
|
+
"test": "vitest run",
|
|
40
|
+
"test:import": "node test/import.mjs"
|
|
41
|
+
}
|
|
42
|
+
}
|