swiftplot 0.4.0 → 0.5.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 +23 -5
- package/dist/chart.js +295 -29
- package/dist/charts/controller.d.ts +3 -4
- package/dist/charts/controller.js +74 -24
- package/dist/charts/index.d.ts +1 -1
- package/dist/charts/index.js +1 -1
- package/dist/charts/mount.js +3 -0
- package/dist/charts/types.d.ts +4 -0
- package/dist/color.d.ts +12 -0
- package/dist/color.js +61 -0
- package/dist/equal.d.ts +20 -0
- package/dist/equal.js +106 -0
- package/dist/features/legend.js +8 -7
- package/dist/features/pointer.d.ts +18 -1
- package/dist/features/pointer.js +19 -1
- package/dist/features/tooltip.js +14 -7
- package/dist/features/zoom.js +2 -2
- package/dist/gl.d.ts +2 -0
- package/dist/gl.js +8 -1
- package/dist/marks/sankey.js +3 -3
- package/dist/types.d.ts +63 -4
- package/package.json +1 -1
package/dist/types.d.ts
CHANGED
|
@@ -222,6 +222,44 @@ export type Margin = {
|
|
|
222
222
|
left: number;
|
|
223
223
|
};
|
|
224
224
|
export type Span = [number, number];
|
|
225
|
+
/** The geometry of a chart, for an app drawing its own nodes over it; each change gives a new one, never mutated. Pixels are CSS pixels relative to the chart. */
|
|
226
|
+
export type Layout = {
|
|
227
|
+
readonly width: number;
|
|
228
|
+
readonly height: number;
|
|
229
|
+
/** The plot rectangle is inside it. */
|
|
230
|
+
readonly margin: Readonly<Margin>;
|
|
231
|
+
readonly frame: NonNullable<Options['frame']>;
|
|
232
|
+
/** What is shown on an axis, in real values, as the app passes them; the axes and the conversions are there only with frame 'axes'. */
|
|
233
|
+
readonly x?: LayoutAxis;
|
|
234
|
+
readonly y?: LayoutAxis;
|
|
235
|
+
/** Only when there is a second axis. */
|
|
236
|
+
readonly y2?: LayoutAxis;
|
|
237
|
+
/** A real value as a pixel, also outside what is shown. */
|
|
238
|
+
readonly xPx?: (x: number) => number;
|
|
239
|
+
/** On `y` unless the second axis is named. */
|
|
240
|
+
readonly yPx?: (y: number, axis?: 'y' | 'y2') => number;
|
|
241
|
+
/** A pixel as a real value. */
|
|
242
|
+
readonly xValue?: (px: number) => number;
|
|
243
|
+
readonly yValue?: (px: number, axis?: 'y' | 'y2') => number;
|
|
244
|
+
};
|
|
245
|
+
export type LayoutAxis = {
|
|
246
|
+
readonly domain: Readonly<Span>;
|
|
247
|
+
readonly ticks: readonly Readonly<Tick>[];
|
|
248
|
+
};
|
|
249
|
+
/**
|
|
250
|
+
* The user's pointer, and the nearest thing within 20 px of it or null. px and py are the pointer in CSS
|
|
251
|
+
* pixels relative to the chart; the hit is the one onClick gets, in real values, and its own px and py
|
|
252
|
+
* are where it is anchored, such as a dot's centre. onClick's second argument differs: it is values, not pixels.
|
|
253
|
+
*/
|
|
254
|
+
export type Hover = {
|
|
255
|
+
px: number;
|
|
256
|
+
py: number;
|
|
257
|
+
hit: (Hit & {
|
|
258
|
+
mark: Mark;
|
|
259
|
+
px: number;
|
|
260
|
+
py: number;
|
|
261
|
+
}) | null;
|
|
262
|
+
};
|
|
225
263
|
export type Options = {
|
|
226
264
|
/** The width in CSS pixels; when omitted the chart follows its container. */
|
|
227
265
|
width?: number;
|
|
@@ -256,7 +294,7 @@ export type Options = {
|
|
|
256
294
|
description?: string;
|
|
257
295
|
/** Opacity multiplier for every other group while one is focused. @default 1 */
|
|
258
296
|
dim?: number;
|
|
259
|
-
/** `light` when left out.
|
|
297
|
+
/** `light` when left out. Replaced by another object, CSS variables are read again, and the chart is restyled if a colour changed. */
|
|
260
298
|
theme?: Theme;
|
|
261
299
|
/**
|
|
262
300
|
* The part of each axis shown, in its values; a side left out shows the whole domain. It is shown
|
|
@@ -320,10 +358,24 @@ export type Options = {
|
|
|
320
358
|
y: number;
|
|
321
359
|
y2?: number;
|
|
322
360
|
} | null): void;
|
|
361
|
+
/**
|
|
362
|
+
* Called with the chart's geometry after the first paint, inside plot(), and whenever the size, the
|
|
363
|
+
* margin, what an axis shows, its ticks or its title change; also when it is set where there was
|
|
364
|
+
* none, but not for another function in its place. Nothing is called while the chart has no room.
|
|
365
|
+
*/
|
|
366
|
+
onLayout?(layout: Layout): void;
|
|
367
|
+
/**
|
|
368
|
+
* Called as the user's pointer moves over the plot, and when what is under it at rest changes, such as
|
|
369
|
+
* after a zoom or new data; with null once as it leaves the plot or a drag starts. A mark that answers no
|
|
370
|
+
* pointer, such as a line, gives a null hit. Nothing is called twice for the same pointer and hit.
|
|
371
|
+
*/
|
|
372
|
+
onHover?(hover: Hover | null): void;
|
|
323
373
|
};
|
|
324
374
|
export type Chart = {
|
|
325
375
|
update(options: Partial<Omit<Options, 'use'>>): void;
|
|
326
376
|
destroy(): void;
|
|
377
|
+
/** An element over the whole chart, under its tooltip, for the app's own DOM. Made when first read; it takes no pointer. */
|
|
378
|
+
readonly overlay: HTMLElement;
|
|
327
379
|
};
|
|
328
380
|
/**
|
|
329
381
|
* Wraps a repaint. `draw` paints the chart now; `draw(0)` paints it with no marks. `why` says what
|
|
@@ -339,6 +391,8 @@ export type Internals = {
|
|
|
339
391
|
root: HTMLElement;
|
|
340
392
|
/** The 2D canvas holding the grid and every mark that is not on WebGL. */
|
|
341
393
|
canvas: HTMLCanvasElement;
|
|
394
|
+
/** What Chart.overlay gave, once it was read. Set to carry over that of a chart this one replaces. */
|
|
395
|
+
overlay: HTMLElement | undefined;
|
|
342
396
|
/** One painter per chart; the last one set wins. */
|
|
343
397
|
onPaint(painter: Painter | undefined): void;
|
|
344
398
|
/**
|
|
@@ -376,6 +430,8 @@ export type Internals = {
|
|
|
376
430
|
};
|
|
377
431
|
margin(): Margin;
|
|
378
432
|
theme(): Theme;
|
|
433
|
+
/** A CSS colour with its variables resolved, as the canvas draws it. */
|
|
434
|
+
color(css: string): string;
|
|
379
435
|
xPx(x: number): number;
|
|
380
436
|
/** On `y` unless the second axis is named; a mark's own is yAxis(mark). */
|
|
381
437
|
yPx(y: number, axis?: 'y' | 'y2'): number;
|
|
@@ -425,13 +481,15 @@ export type Internals = {
|
|
|
425
481
|
* gets none, and 'shift' when a drag with shift held pans and a brush keeps the plain ones; with no
|
|
426
482
|
* brush a plain drag then pans too, unless zoom() was given `drag: 'shift'`. `active` is set while
|
|
427
483
|
* a drag or a gesture is under way, and until the click after its release has gone by.
|
|
484
|
+
* `child` is set while a press that began on a child of the overlay is held.
|
|
428
485
|
*/
|
|
429
486
|
drag: {
|
|
430
487
|
brush: boolean;
|
|
431
488
|
pan: 'plain' | 'shift' | false;
|
|
432
489
|
active: boolean;
|
|
490
|
+
readonly child: boolean;
|
|
433
491
|
};
|
|
434
|
-
/** Runs every feature's update(), for a change under a resting pointer that the chart cannot see, such as the end of a drag. */
|
|
492
|
+
/** Runs every feature's update() and then reports the hover to the app, for a change under a resting pointer that the chart cannot see, such as the end of a drag. */
|
|
435
493
|
sync(): void;
|
|
436
494
|
hit(px: number, py: number, max: number): (Hit & {
|
|
437
495
|
mark: Mark;
|
|
@@ -452,8 +510,9 @@ export type Internals = {
|
|
|
452
510
|
};
|
|
453
511
|
/**
|
|
454
512
|
* update() runs whenever what is under a resting pointer may have changed: after the first paint, for
|
|
455
|
-
* new options or a new size, a series hidden or shown, a new window,
|
|
456
|
-
*
|
|
513
|
+
* new options or a new size, a series hidden or shown, a new window, at the end of a drag, and at the
|
|
514
|
+
* start and the end of a press on a child of the overlay. A theme that changes no colour is no new option.
|
|
515
|
+
* letGo() runs before the repaint for each of these but the first paint, the end of a drag, a press and an
|
|
457
516
|
* update of only `pointer` or callbacks, so a focus dropped there does not cut a data animation short.
|
|
458
517
|
*/
|
|
459
518
|
export type Feature = (chart: Internals) => {
|