swiftplot 0.1.1 → 0.4.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 +86 -61
- package/dist/chart.d.ts +4 -0
- package/dist/chart.js +172 -89
- package/dist/charts/build.d.ts +53 -0
- package/dist/charts/build.js +69 -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 +564 -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 +20 -15
- 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 +20 -5
- 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/rects.js +15 -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 -15
- 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: {
|
|
@@ -157,8 +159,6 @@ export type Mark = {
|
|
|
157
159
|
label: string;
|
|
158
160
|
color: string;
|
|
159
161
|
}[];
|
|
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
162
|
/** paint() draws the mark as one shape and ignores a row, so selecting any of its rows draws it whole. */
|
|
163
163
|
oneShape?: true;
|
|
164
164
|
/**
|
|
@@ -184,9 +184,11 @@ export type Resolved = {
|
|
|
184
184
|
hi: number;
|
|
185
185
|
ticks: Tick[];
|
|
186
186
|
};
|
|
187
|
+
/** What x, y and y2 take: a linear axis unless `scale` replaces it, as the axes time(), log(), band() and bare() return do. */
|
|
187
188
|
export type Axis = {
|
|
188
189
|
/** 'nice' widens the extent of the marks' columns to whole steps; 'data' keeps it exact. */
|
|
189
190
|
domain: [number, number] | 'nice' | 'data';
|
|
191
|
+
/** The axis title; an empty string shows none. */
|
|
190
192
|
label: string;
|
|
191
193
|
/**
|
|
192
194
|
* Replaces the built-in linear scale. It receives the axis itself, so one function serves every
|
|
@@ -210,6 +212,7 @@ export type Axis = {
|
|
|
210
212
|
format?: (value: number) => string;
|
|
211
213
|
/** A transformed axis, such as log(): a real value in the space the marks' columns are in, and back. */
|
|
212
214
|
to?(real: number, axis: Axis): number;
|
|
215
|
+
/** The inverse of `to`: a value in the marks' space back to the real one. */
|
|
213
216
|
from?(v: number, axis: Axis): number;
|
|
214
217
|
};
|
|
215
218
|
export type Margin = {
|
|
@@ -220,20 +223,29 @@ export type Margin = {
|
|
|
220
223
|
};
|
|
221
224
|
export type Span = [number, number];
|
|
222
225
|
export type Options = {
|
|
223
|
-
/** CSS pixels; when omitted the chart follows its container. */
|
|
226
|
+
/** The width in CSS pixels; when omitted the chart follows its container. */
|
|
224
227
|
width?: number;
|
|
228
|
+
/** The height in CSS pixels; when omitted the chart follows its container. */
|
|
225
229
|
height?: number;
|
|
226
230
|
/** CSS pixels around the plot area for ticks and labels. A side left out is sized from the labels. */
|
|
227
231
|
margin?: Partial<Margin>;
|
|
228
|
-
/**
|
|
232
|
+
/** The horizontal axis; `{ domain: 'nice', label: '' }` when left out. */
|
|
229
233
|
x?: Axis;
|
|
234
|
+
/** The vertical axis; `{ domain: 'nice', label: '' }` when left out. */
|
|
230
235
|
y?: Axis;
|
|
236
|
+
/**
|
|
237
|
+
* A second y axis, drawn on the right, for the marks given `yAxis: 'y2'`: it takes its extent from
|
|
238
|
+
* those marks alone. Grid lines come from `y` only. Left out, there is none and every mark is on `y`.
|
|
239
|
+
*/
|
|
240
|
+
y2?: Axis;
|
|
231
241
|
/**
|
|
232
242
|
* 'polar' and 'blank' have no axes: a mark is given the plot rectangle only, and reports a hit
|
|
233
243
|
* as fractions of it, x from the left and y from the bottom. 'polar' is for marks drawn round
|
|
234
244
|
* a centre, such as arcs(); it differs from 'blank' in how a reveal uncovers it.
|
|
245
|
+
* @default 'axes'
|
|
235
246
|
*/
|
|
236
247
|
frame?: 'axes' | 'polar' | 'blank';
|
|
248
|
+
/** What the chart draws, made by line(), bar() and the other mark functions. */
|
|
237
249
|
marks: Mark[];
|
|
238
250
|
/** Read once, when the chart is created. */
|
|
239
251
|
use?: Feature[];
|
|
@@ -242,7 +254,7 @@ export type Options = {
|
|
|
242
254
|
* the labelled marks. The data itself is not exposed.
|
|
243
255
|
*/
|
|
244
256
|
description?: string;
|
|
245
|
-
/** Opacity multiplier for every other group while one is focused. */
|
|
257
|
+
/** Opacity multiplier for every other group while one is focused. @default 1 */
|
|
246
258
|
dim?: number;
|
|
247
259
|
/** `light` when left out. Replacing it with another object repaints the chart and restyles its text. */
|
|
248
260
|
theme?: Theme;
|
|
@@ -253,14 +265,17 @@ export type Options = {
|
|
|
253
265
|
view?: {
|
|
254
266
|
x?: Span;
|
|
255
267
|
y?: Span;
|
|
268
|
+
y2?: Span;
|
|
256
269
|
};
|
|
257
270
|
/**
|
|
258
271
|
* 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
|
|
272
|
+
* when the y axis fits the x window and has no window of its own, and y2 likewise, or when there
|
|
273
|
+
* is no second axis. A gesture on y moves y2 through the same pixels.
|
|
260
274
|
*/
|
|
261
275
|
onViewChange?(view: {
|
|
262
276
|
x: Span;
|
|
263
277
|
y?: Span;
|
|
278
|
+
y2?: Span;
|
|
264
279
|
}): void;
|
|
265
280
|
/** The series not drawn, by the id a legend lists a mark under: its `group`, or its `label`. */
|
|
266
281
|
hidden?: string[];
|
|
@@ -279,27 +294,31 @@ export type Options = {
|
|
|
279
294
|
}[] | null;
|
|
280
295
|
/**
|
|
281
296
|
* 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
|
|
297
|
+
* it, or null, and the values at the click, y2 among them when there is a second axis. A hit's y is
|
|
298
|
+
* on its mark's own axis. While it is set, the cursor is a pointer over a hit.
|
|
283
299
|
*/
|
|
284
300
|
onClick?(hit: (Hit & {
|
|
285
301
|
mark: Mark;
|
|
286
302
|
}) | null, at: {
|
|
287
303
|
x: number;
|
|
288
304
|
y: number;
|
|
305
|
+
y2?: number;
|
|
289
306
|
}): void;
|
|
290
307
|
/**
|
|
291
308
|
* A pointer to show as if the user's were there, such as another chart's: a tooltip shows at it
|
|
292
309
|
* 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.
|
|
310
|
+
* nearest one shows nothing. The height may be given on the second axis instead, as y2; with both, y2 is used.
|
|
294
311
|
*/
|
|
295
312
|
pointer?: {
|
|
296
313
|
x: number;
|
|
297
314
|
y?: number;
|
|
315
|
+
y2?: number;
|
|
298
316
|
} | null;
|
|
299
317
|
/** 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
318
|
onPointerChange?(pointer: {
|
|
301
319
|
x: number;
|
|
302
320
|
y: number;
|
|
321
|
+
y2?: number;
|
|
303
322
|
} | null): void;
|
|
304
323
|
};
|
|
305
324
|
export type Chart = {
|
|
@@ -313,7 +332,7 @@ export type Chart = {
|
|
|
313
332
|
export type Painter = (draw: (reveal?: number) => void, why: 'data' | 'size' | 'focus') => void;
|
|
314
333
|
/**
|
|
315
334
|
* 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()
|
|
335
|
+
* up before the first paint: the pixel helpers, hit(), view(), fit() and propose()
|
|
317
336
|
* work from that paint on.
|
|
318
337
|
*/
|
|
319
338
|
export type Internals = {
|
|
@@ -358,38 +377,48 @@ export type Internals = {
|
|
|
358
377
|
margin(): Margin;
|
|
359
378
|
theme(): Theme;
|
|
360
379
|
xPx(x: number): number;
|
|
361
|
-
|
|
380
|
+
/** On `y` unless the second axis is named; a mark's own is yAxis(mark). */
|
|
381
|
+
yPx(y: number, axis?: 'y' | 'y2'): number;
|
|
362
382
|
xValue(px: number): number;
|
|
363
|
-
yValue(px: number): number;
|
|
364
|
-
/** The
|
|
383
|
+
yValue(px: number, axis?: 'y' | 'y2'): number;
|
|
384
|
+
/** The y axis a mark is on: 'y2' only when the chart has one and the mark asks for it. */
|
|
385
|
+
yAxis(mark: Mark): 'y' | 'y2';
|
|
386
|
+
/** The window shown on each axis, in the marks' space; y2 only when there is a second axis. */
|
|
365
387
|
view(): {
|
|
366
388
|
x: Span;
|
|
367
389
|
y: Span;
|
|
390
|
+
y2?: Span;
|
|
368
391
|
};
|
|
369
392
|
/** The whole domain on each axis: the widest window propose() shows. */
|
|
370
393
|
domain(): {
|
|
371
394
|
x: Span;
|
|
372
395
|
y: Span;
|
|
396
|
+
y2?: Span;
|
|
373
397
|
};
|
|
374
398
|
/**
|
|
375
399
|
* Shows this window, or with null the whole domain, clamped to the domain, and passes it to
|
|
376
400
|
* 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.
|
|
401
|
+
* domain. False, and nothing happens, when what is shown would not change. A y given without a y2
|
|
402
|
+
* takes the second axis with it, through the same pixels. A side given just as it is shown, with no
|
|
403
|
+
* window of its own, is not held: an axis fitted to its marks goes on fitting them.
|
|
378
404
|
*/
|
|
379
405
|
propose(view: {
|
|
380
406
|
x?: Span;
|
|
381
407
|
y?: Span;
|
|
408
|
+
y2?: Span;
|
|
382
409
|
} | null): boolean;
|
|
383
410
|
/** The window propose() would show for this view, without showing it. */
|
|
384
411
|
fit(view: {
|
|
385
412
|
x?: Span;
|
|
386
413
|
y?: Span;
|
|
414
|
+
y2?: Span;
|
|
387
415
|
} | null): {
|
|
388
416
|
x: Span;
|
|
389
417
|
y: Span;
|
|
418
|
+
y2?: Span;
|
|
390
419
|
};
|
|
391
420
|
/** A value in the marks' space as the app sees it. */
|
|
392
|
-
real(axis: 'x' | 'y', v: number): number;
|
|
421
|
+
real(axis: 'x' | 'y' | 'y2', v: number): number;
|
|
393
422
|
frame(): NonNullable<Options['frame']>;
|
|
394
423
|
/**
|
|
395
424
|
* 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.4.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
|
}
|