swiftplot 0.1.1 → 0.3.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/README.md +71 -47
- package/dist/chart.d.ts +4 -0
- package/dist/chart.js +171 -86
- package/dist/charts/build.d.ts +52 -0
- package/dist/charts/build.js +63 -0
- package/dist/charts/candlestick.d.ts +8 -0
- package/dist/charts/candlestick.js +105 -0
- package/dist/charts/combo.d.ts +8 -0
- package/dist/charts/combo.js +50 -0
- package/dist/charts/controller.d.ts +2 -2
- package/dist/charts/controller.js +2 -2
- package/dist/charts/defaults.d.ts +10 -2
- package/dist/charts/defaults.js +67 -6
- package/dist/charts/distribution.d.ts +15 -0
- package/dist/charts/distribution.js +178 -0
- package/dist/charts/fields.d.ts +33 -3
- package/dist/charts/fields.js +150 -66
- package/dist/charts/flow.d.ts +15 -0
- package/dist/charts/flow.js +189 -0
- package/dist/charts/heatmap.d.ts +9 -0
- package/dist/charts/heatmap.js +104 -0
- package/dist/charts/index.d.ts +8 -1
- package/dist/charts/index.js +7 -0
- package/dist/charts/parts.d.ts +23 -0
- package/dist/charts/parts.js +66 -0
- package/dist/charts/radar.d.ts +7 -0
- package/dist/charts/radar.js +77 -0
- package/dist/charts/types.d.ts +562 -23
- package/dist/charts/xy.d.ts +35 -25
- package/dist/charts/xy.js +327 -126
- package/dist/features/animate.d.ts +10 -1
- package/dist/features/animate.js +3 -3
- package/dist/features/brush.d.ts +3 -1
- package/dist/features/brush.js +2 -1
- package/dist/features/legend.d.ts +1 -3
- package/dist/features/legend.js +4 -5
- package/dist/features/tooltip.d.ts +10 -2
- package/dist/features/tooltip.js +12 -10
- package/dist/features/zoom.d.ts +1 -0
- package/dist/features/zoom.js +22 -4
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/marks/arcs.d.ts +10 -4
- package/dist/marks/arcs.js +2 -1
- package/dist/marks/area.d.ts +9 -8
- package/dist/marks/area.js +2 -2
- package/dist/marks/bar.d.ts +18 -10
- package/dist/marks/bar.js +5 -5
- package/dist/marks/box.d.ts +7 -1
- package/dist/marks/box.js +2 -8
- package/dist/marks/candlestick.d.ts +22 -0
- package/dist/marks/candlestick.js +133 -0
- package/dist/marks/common.d.ts +18 -0
- package/dist/marks/common.js +14 -0
- package/dist/marks/dots.d.ts +6 -5
- package/dist/marks/dots.js +3 -1
- package/dist/marks/errorBars.d.ts +9 -4
- package/dist/marks/errorBars.js +21 -1
- package/dist/marks/funnel.d.ts +8 -3
- package/dist/marks/funnel.js +2 -1
- package/dist/marks/heatmap.d.ts +8 -7
- package/dist/marks/line.d.ts +8 -6
- package/dist/marks/radar.d.ts +9 -2
- package/dist/marks/radar.js +9 -2
- package/dist/marks/radialBars.d.ts +12 -5
- package/dist/marks/rule.d.ts +19 -0
- package/dist/marks/rule.js +4 -1
- package/dist/marks/sankey.d.ts +14 -2
- package/dist/marks/sankey.js +4 -1
- package/dist/marks/sunburst.d.ts +5 -0
- package/dist/marks/sunburst.js +2 -1
- package/dist/marks/ticks.d.ts +4 -1
- package/dist/marks/tree.d.ts +14 -6
- package/dist/marks/tree.js +6 -3
- package/dist/marks/treemap.d.ts +5 -0
- package/dist/marks/treemap.js +7 -2
- package/dist/paint.d.ts +6 -1
- package/dist/paint.js +6 -1
- package/dist/scale.d.ts +1 -1
- package/dist/scale.js +4 -3
- package/dist/scales/band.d.ts +3 -0
- package/dist/scales/band.js +5 -1
- package/dist/scales/bare.d.ts +4 -1
- package/dist/scales/bare.js +4 -1
- package/dist/scales/color.d.ts +2 -0
- package/dist/scales/log.d.ts +8 -1
- package/dist/scales/log.js +3 -2
- package/dist/scales/time.d.ts +7 -0
- package/dist/scales/time.js +3 -1
- package/dist/text.d.ts +8 -0
- package/dist/text.js +33 -0
- package/dist/transforms.d.ts +11 -7
- package/dist/transforms.js +8 -7
- package/dist/types.d.ts +44 -13
- package/package.json +2 -2
package/dist/types.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export type Hit = {
|
|
|
29
29
|
/**
|
|
30
30
|
* Text a mark asks to have drawn at a point of the canvas, in device pixels like the rest of what
|
|
31
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
|
|
32
|
+
* label of higher priority, and shows it as a reveal uncovers it.
|
|
33
33
|
*/
|
|
34
34
|
export type Label = {
|
|
35
35
|
x: number;
|
|
@@ -100,6 +100,8 @@ export type Mark = {
|
|
|
100
100
|
* Values written into the same array are not seen; pass a new array or view to redraw.
|
|
101
101
|
*/
|
|
102
102
|
options: object;
|
|
103
|
+
/** Which y axis the mark is drawn against and fits; 'y' when left out, and whenever the chart has no `y2`. */
|
|
104
|
+
yAxis?: 'y' | 'y2';
|
|
103
105
|
points: number;
|
|
104
106
|
/** Columns the 'nice' domains are computed from. */
|
|
105
107
|
channels: {
|
|
@@ -184,9 +186,11 @@ export type Resolved = {
|
|
|
184
186
|
hi: number;
|
|
185
187
|
ticks: Tick[];
|
|
186
188
|
};
|
|
189
|
+
/** What x, y and y2 take: a linear axis unless `scale` replaces it, as the axes time(), log(), band() and bare() return do. */
|
|
187
190
|
export type Axis = {
|
|
188
191
|
/** 'nice' widens the extent of the marks' columns to whole steps; 'data' keeps it exact. */
|
|
189
192
|
domain: [number, number] | 'nice' | 'data';
|
|
193
|
+
/** The axis title; an empty string shows none. */
|
|
190
194
|
label: string;
|
|
191
195
|
/**
|
|
192
196
|
* Replaces the built-in linear scale. It receives the axis itself, so one function serves every
|
|
@@ -210,6 +214,7 @@ export type Axis = {
|
|
|
210
214
|
format?: (value: number) => string;
|
|
211
215
|
/** A transformed axis, such as log(): a real value in the space the marks' columns are in, and back. */
|
|
212
216
|
to?(real: number, axis: Axis): number;
|
|
217
|
+
/** The inverse of `to`: a value in the marks' space back to the real one. */
|
|
213
218
|
from?(v: number, axis: Axis): number;
|
|
214
219
|
};
|
|
215
220
|
export type Margin = {
|
|
@@ -220,20 +225,29 @@ export type Margin = {
|
|
|
220
225
|
};
|
|
221
226
|
export type Span = [number, number];
|
|
222
227
|
export type Options = {
|
|
223
|
-
/** CSS pixels; when omitted the chart follows its container. */
|
|
228
|
+
/** The width in CSS pixels; when omitted the chart follows its container. */
|
|
224
229
|
width?: number;
|
|
230
|
+
/** The height in CSS pixels; when omitted the chart follows its container. */
|
|
225
231
|
height?: number;
|
|
226
232
|
/** CSS pixels around the plot area for ticks and labels. A side left out is sized from the labels. */
|
|
227
233
|
margin?: Partial<Margin>;
|
|
228
|
-
/**
|
|
234
|
+
/** The horizontal axis; `{ domain: 'nice', label: '' }` when left out. */
|
|
229
235
|
x?: Axis;
|
|
236
|
+
/** The vertical axis; `{ domain: 'nice', label: '' }` when left out. */
|
|
230
237
|
y?: Axis;
|
|
238
|
+
/**
|
|
239
|
+
* A second y axis, drawn on the right, for the marks given `yAxis: 'y2'`: it takes its extent from
|
|
240
|
+
* those marks alone. Grid lines come from `y` only. Left out, there is none and every mark is on `y`.
|
|
241
|
+
*/
|
|
242
|
+
y2?: Axis;
|
|
231
243
|
/**
|
|
232
244
|
* 'polar' and 'blank' have no axes: a mark is given the plot rectangle only, and reports a hit
|
|
233
245
|
* as fractions of it, x from the left and y from the bottom. 'polar' is for marks drawn round
|
|
234
246
|
* a centre, such as arcs(); it differs from 'blank' in how a reveal uncovers it.
|
|
247
|
+
* @default 'axes'
|
|
235
248
|
*/
|
|
236
249
|
frame?: 'axes' | 'polar' | 'blank';
|
|
250
|
+
/** What the chart draws, made by line(), bar() and the other mark functions. */
|
|
237
251
|
marks: Mark[];
|
|
238
252
|
/** Read once, when the chart is created. */
|
|
239
253
|
use?: Feature[];
|
|
@@ -242,7 +256,7 @@ export type Options = {
|
|
|
242
256
|
* the labelled marks. The data itself is not exposed.
|
|
243
257
|
*/
|
|
244
258
|
description?: string;
|
|
245
|
-
/** Opacity multiplier for every other group while one is focused. */
|
|
259
|
+
/** Opacity multiplier for every other group while one is focused. @default 1 */
|
|
246
260
|
dim?: number;
|
|
247
261
|
/** `light` when left out. Replacing it with another object repaints the chart and restyles its text. */
|
|
248
262
|
theme?: Theme;
|
|
@@ -253,14 +267,17 @@ export type Options = {
|
|
|
253
267
|
view?: {
|
|
254
268
|
x?: Span;
|
|
255
269
|
y?: Span;
|
|
270
|
+
y2?: Span;
|
|
256
271
|
};
|
|
257
272
|
/**
|
|
258
273
|
* 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
|
|
274
|
+
* when the y axis fits the x window and has no window of its own, and y2 likewise, or when there
|
|
275
|
+
* is no second axis. A gesture on y moves y2 through the same pixels.
|
|
260
276
|
*/
|
|
261
277
|
onViewChange?(view: {
|
|
262
278
|
x: Span;
|
|
263
279
|
y?: Span;
|
|
280
|
+
y2?: Span;
|
|
264
281
|
}): void;
|
|
265
282
|
/** The series not drawn, by the id a legend lists a mark under: its `group`, or its `label`. */
|
|
266
283
|
hidden?: string[];
|
|
@@ -279,27 +296,31 @@ export type Options = {
|
|
|
279
296
|
}[] | null;
|
|
280
297
|
/**
|
|
281
298
|
* 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
|
|
299
|
+
* it, or null, and the values at the click, y2 among them when there is a second axis. A hit's y is
|
|
300
|
+
* on its mark's own axis. While it is set, the cursor is a pointer over a hit.
|
|
283
301
|
*/
|
|
284
302
|
onClick?(hit: (Hit & {
|
|
285
303
|
mark: Mark;
|
|
286
304
|
}) | null, at: {
|
|
287
305
|
x: number;
|
|
288
306
|
y: number;
|
|
307
|
+
y2?: number;
|
|
289
308
|
}): void;
|
|
290
309
|
/**
|
|
291
310
|
* A pointer to show as if the user's were there, such as another chart's: a tooltip shows at it
|
|
292
311
|
* 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.
|
|
312
|
+
* nearest one shows nothing. The height may be given on the second axis instead, as y2; with both, y2 is used.
|
|
294
313
|
*/
|
|
295
314
|
pointer?: {
|
|
296
315
|
x: number;
|
|
297
316
|
y?: number;
|
|
317
|
+
y2?: number;
|
|
298
318
|
} | null;
|
|
299
319
|
/** 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
320
|
onPointerChange?(pointer: {
|
|
301
321
|
x: number;
|
|
302
322
|
y: number;
|
|
323
|
+
y2?: number;
|
|
303
324
|
} | null): void;
|
|
304
325
|
};
|
|
305
326
|
export type Chart = {
|
|
@@ -313,7 +334,7 @@ export type Chart = {
|
|
|
313
334
|
export type Painter = (draw: (reveal?: number) => void, why: 'data' | 'size' | 'focus') => void;
|
|
314
335
|
/**
|
|
315
336
|
* 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()
|
|
337
|
+
* up before the first paint: the pixel helpers, hit(), view(), fit() and propose()
|
|
317
338
|
* work from that paint on.
|
|
318
339
|
*/
|
|
319
340
|
export type Internals = {
|
|
@@ -358,38 +379,48 @@ export type Internals = {
|
|
|
358
379
|
margin(): Margin;
|
|
359
380
|
theme(): Theme;
|
|
360
381
|
xPx(x: number): number;
|
|
361
|
-
|
|
382
|
+
/** On `y` unless the second axis is named; a mark's own is yAxis(mark). */
|
|
383
|
+
yPx(y: number, axis?: 'y' | 'y2'): number;
|
|
362
384
|
xValue(px: number): number;
|
|
363
|
-
yValue(px: number): number;
|
|
364
|
-
/** The
|
|
385
|
+
yValue(px: number, axis?: 'y' | 'y2'): number;
|
|
386
|
+
/** The y axis a mark is on: 'y2' only when the chart has one and the mark asks for it. */
|
|
387
|
+
yAxis(mark: Mark): 'y' | 'y2';
|
|
388
|
+
/** The window shown on each axis, in the marks' space; y2 only when there is a second axis. */
|
|
365
389
|
view(): {
|
|
366
390
|
x: Span;
|
|
367
391
|
y: Span;
|
|
392
|
+
y2?: Span;
|
|
368
393
|
};
|
|
369
394
|
/** The whole domain on each axis: the widest window propose() shows. */
|
|
370
395
|
domain(): {
|
|
371
396
|
x: Span;
|
|
372
397
|
y: Span;
|
|
398
|
+
y2?: Span;
|
|
373
399
|
};
|
|
374
400
|
/**
|
|
375
401
|
* Shows this window, or with null the whole domain, clamped to the domain, and passes it to
|
|
376
402
|
* 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.
|
|
403
|
+
* domain. False, and nothing happens, when what is shown would not change. A y given without a y2
|
|
404
|
+
* takes the second axis with it, through the same pixels. A side given just as it is shown, with no
|
|
405
|
+
* window of its own, is not held: an axis fitted to its marks goes on fitting them.
|
|
378
406
|
*/
|
|
379
407
|
propose(view: {
|
|
380
408
|
x?: Span;
|
|
381
409
|
y?: Span;
|
|
410
|
+
y2?: Span;
|
|
382
411
|
} | null): boolean;
|
|
383
412
|
/** The window propose() would show for this view, without showing it. */
|
|
384
413
|
fit(view: {
|
|
385
414
|
x?: Span;
|
|
386
415
|
y?: Span;
|
|
416
|
+
y2?: Span;
|
|
387
417
|
} | null): {
|
|
388
418
|
x: Span;
|
|
389
419
|
y: Span;
|
|
420
|
+
y2?: Span;
|
|
390
421
|
};
|
|
391
422
|
/** A value in the marks' space as the app sees it. */
|
|
392
|
-
real(axis: 'x' | 'y', v: number): number;
|
|
423
|
+
real(axis: 'x' | 'y' | 'y2', v: number): number;
|
|
393
424
|
frame(): NonNullable<Options['frame']>;
|
|
394
425
|
/**
|
|
395
426
|
* Which feature a drag over the plot belongs to. `pan` is 'plain' when every drag pans and a brush
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swiftplot",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Small, fast charts on Canvas 2D and WebGL2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "tsc -p tsconfig.build.json",
|
|
38
|
-
"typecheck": "tsc --noEmit",
|
|
38
|
+
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.node.json",
|
|
39
39
|
"test": "vitest run",
|
|
40
40
|
"test:import": "node test/import.mjs"
|
|
41
41
|
}
|