@martinomagnifico/tablechart 1.2.6 → 1.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.
@@ -38,14 +38,14 @@ interface Config {
38
38
  shape: "straight" | "step" | "smooth";
39
39
  /** Names of several lines in a legend instead of at the end of each line. A figure overrides it with `data-chart-legend`. */
40
40
  legend: boolean;
41
- /** Numbers along the value axis of a column, bar, line, area or waterfall chart. A figure overrides it with `data-chart-axis`. */
42
- axis: boolean;
41
+ /** Numbers along the value axis of a column, bar, line, area or waterfall chart; `"right"` puts them on the right of an upright chart. A figure overrides it with `data-chart-axis`. */
42
+ axis: boolean | "right";
43
43
  /** Gridlines across the plot at each number of the axis. A figure overrides it with `data-chart-grid`. */
44
44
  grid: boolean;
45
45
  /** The name of each marker beside it, on a scatter chart. A figure overrides it with `data-chart-names`. */
46
46
  names: boolean;
47
- /** A tooltip with the values of a row that is pointed at or tapped: `"auto"`, the default, only on a chart that does not show all its numbers; `true` always; `false` never. A figure overrides it with `data-chart-tooltip`. */
48
- tooltip: boolean | "auto";
47
+ /** A tooltip with the values of a row that is pointed at or tapped: `"auto"`, the default, only on a chart that does not show all its numbers; `true` always; `false` never. `"crosshair"`, on a line or area chart, shows a line through the row with its values at the side. A figure overrides it with `data-chart-tooltip`. */
48
+ tooltip: boolean | "auto" | "crosshair";
49
49
  /** Where the tooltip goes in the page: an element or a selector, `body` by default. In a scaled element, such as the slides of a presentation, the tooltip has their scale. */
50
50
  tooltipparent: HTMLElement | string | null;
51
51
  /** The table under the chart: `"always"`, only in `"print"`, in print when numbers are left out (`"auto"`), or `"never"`. A figure overrides it with `data-chart-table`. */
@@ -180,6 +180,10 @@ interface Geometry {
180
180
  rowAt?: (x: number, y: number) => number | null;
181
181
  /** Where the tooltip of a row points, in viewBox units, for a row whose mark may not be drawn, such as a point of a long line. */
182
182
  pointOf?: (index: number) => [number, number] | null;
183
+ /** The crosshair of a row, on a line or area chart. */
184
+ crossingOf?: (index: number) => Crossing | null;
185
+ /** The side of the numbers of the value axis; null without them. */
186
+ axisSide: "left" | "right" | null;
183
187
  /** A CSS length set on the figure, such as `--tablechart-marker-size`, in viewBox units. */
184
188
  length: (name: string, fallback: string) => number | null;
185
189
  barWidth: number;
@@ -269,6 +273,14 @@ interface ChartType {
269
273
  groups?: boolean;
270
274
  /** False: no numbers on the chart. They stay out of the layout, which costs a lot with many rows. */
271
275
  numbers?: false;
276
+ /** The scale fits the values without reaching zero, as for prices. */
277
+ floats?: boolean;
278
+ /** The value axis is shown unless the figure has `data-chart-axis="false"`. */
279
+ valueAxis?: boolean;
280
+ /** A tick above each name under the chart, as under a line. */
281
+ ticks?: boolean;
282
+ /** A crosshair with `tooltip: "crosshair"`; the drawing sets `crossingOf`. */
283
+ crosshair?: boolean;
272
284
  /** Text of its own, made with the rest of the text so a translation script finds it, such as a legend. */
273
285
  text?: (input: {
274
286
  figure: HTMLElement;
@@ -299,6 +311,31 @@ interface ChartType {
299
311
  /** Annotations that come with this type, such as `quadrant` with `scatter`; `addType` adds them. */
300
312
  annotations?: Record<string, AnnotationType>;
301
313
  }
314
+ /** The crosshair of a row, in viewBox units: a line down at `x` from `from` to `to`, and a dot on each line where it crosses. */
315
+ interface Crossing {
316
+ x: number;
317
+ from: number;
318
+ to: number;
319
+ /** Where the value labels go: at the value axis, or the left edge of the plot without one. */
320
+ edge: number;
321
+ /** Where a line across the plot ends: at the row farthest from the axis. */
322
+ end: number;
323
+ /** The side of the axis numbers that the value labels go over. */
324
+ axis: "left" | "right" | null;
325
+ height: number;
326
+ /** `colour` is the colour of the label, if not the colour of the line. */
327
+ points: {
328
+ series: number;
329
+ y: number;
330
+ dot: SVGElement;
331
+ colour?: string;
332
+ }[];
333
+ /** With it, the line across follows the pointer, with the value of the scale there; within `snap` pixels of a point, it goes through that point. */
334
+ textAt?: (y: number) => string;
335
+ snap?: number;
336
+ /** The top and bottom of a mark that the line down leaves free, such as a candle with its wick. */
337
+ around?: [number, number];
338
+ }
302
339
  /** One line of a tooltip, under the name of the row. */
303
340
  interface TooltipLine {
304
341
  /** The name of the series; empty for a chart with one series. */
@@ -323,6 +360,8 @@ interface HeadroomInput {
323
360
  series: number;
324
361
  focused: boolean;
325
362
  stacked: boolean;
363
+ /** False with `data-chart-values="none"` and no row with `data-value="show"`: a line then needs no room for numbers. */
364
+ numbers: boolean;
326
365
  }
327
366
  /** `create` runs before layout, so a translation script finds its text; `draw` only places it. */
328
367
  interface AnnotationType {
@@ -330,6 +369,22 @@ interface AnnotationType {
330
369
  draw: (spec: HTMLElement, badge: HTMLElement | null, geo: Geometry) => void;
331
370
  }
332
371
  interface ChartState {
372
+ /** What the chart needs by itself, for a group that shares a scale; null for a chart that cannot share one. */
373
+ measured?: {
374
+ height: number;
375
+ room: number;
376
+ floor: number;
377
+ ceiling: number;
378
+ bottom: number;
379
+ } | null;
380
+ /** What its group with `data-chart-group-scale` agreed on. */
381
+ agreed?: {
382
+ height: number;
383
+ room: number;
384
+ floor: number;
385
+ ceiling: number;
386
+ bottom: number;
387
+ };
333
388
  figure: HTMLElement;
334
389
  plot: HTMLElement;
335
390
  svg: SVGSVGElement;
@@ -347,6 +402,7 @@ interface ChartState {
347
402
  titles: HTMLElement[];
348
403
  ticks: HTMLElement;
349
404
  numbers: boolean;
405
+ right: boolean;
350
406
  } | null;
351
407
  stacked: boolean;
352
408
  totals: HTMLElement[];
@@ -357,6 +413,12 @@ interface ChartState {
357
413
  rowBox: ((index: number) => [number, number, number, number]) | null;
358
414
  /** Where the tooltip of a row points, in viewBox units; set by a chart such as a line. */
359
415
  pointOf: ((index: number) => [number, number] | null) | null;
416
+ /** The crosshair of a row, on a line or area chart. */
417
+ crossingOf: ((index: number) => Crossing | null) | null;
418
+ /** The crosshair, once it is attached, so a new layout can take it away. */
419
+ crosshair: {
420
+ hide: () => void;
421
+ } | null;
360
422
  annotations: {
361
423
  spec: HTMLElement;
362
424
  type: AnnotationType;
@@ -373,18 +435,20 @@ interface ChartState {
373
435
  controls: HTMLElement | null;
374
436
  checks: Check[];
375
437
  }
438
+ /** One candle per row: a body from open to close, and a wick from low to high. A rising candle is hollow, a falling one filled. */
439
+ declare const candlestick: ChartType;
376
440
  /** One marker per row, across by its first value and up by its second; a third value makes it a bubble. */
377
441
  declare const scatter: ChartType;
378
442
  /** Adds a chart type for `data-chart="name"`, such as one from `@martinomagnifico/tablechart/additional-types`, before `init()`. */
379
443
  declare const addType: (name: string, type: ChartType) => void;
380
444
  /** Pass 2: everything a reader will read, before a translation script looks. */
381
445
  declare const build: (figure: HTMLElement, config: Config, asKind?: string | null) => ChartState | null;
382
- /** Pass 3. Needs layout; makes no text, only places it. */
383
- declare const layout: (state: ChartState, config: Config) => boolean;
384
446
  /** Numbers are reformatted in place, so a language change costs no redraw. */
385
447
  declare const relabel: (state: ChartState, config: Config) => void;
386
448
  /** Removes what `build` added, so the chart can be built again. */
387
449
  declare const unbuild: (state: ChartState) => void;
450
+ /** Pass 3. Needs layout; makes no text, only places it. */
451
+ declare const layout: (state: ChartState, config: Config) => boolean;
388
452
  /**
389
453
  * One class, `is-shown`, starts the whole build. `atOnce` skips it: the chart lands at its end, or back at its start,
390
454
  * without transitions, such as a chart in view when the page opens, or one hidden where nobody sees it.
@@ -402,6 +466,10 @@ interface TablechartChart {
402
466
  previous(): void;
403
467
  /** On a chart that steps: shows the chart up to `step`, from 0 to `steps`. */
404
468
  stepTo(step: number): void;
469
+ /** Builds the chart again, with its animation. A chart with steps goes back to its first step. */
470
+ replay(): void;
471
+ /** Takes the chart back to its start, to build when it scrolls into view. */
472
+ reset(): void;
405
473
  /** How many steps are shown. */
406
474
  readonly step: number;
407
475
  /** How many steps the chart has; 0 for a chart that does not step. */
@@ -425,8 +493,7 @@ declare const entranceOf: (figure: HTMLElement, config: Config) => number;
425
493
  declare const prepare: (found: HTMLElement[], config: Config) => Promise<HTMLElement[]>;
426
494
  /** Makes a chart of one figure; returns the existing chart if there is one, or null without data. */
427
495
  declare const create: (element: HTMLElement, options?: Partial<Config>) => Promise<TablechartChart | null>;
428
- /** Makes a chart of every figure in `root` that matches the selector, skipping existing charts. */
429
- declare const init: (options?: Partial<Config>, root?: ParentNode) => Promise<TablechartInstance>;
496
+ declare const init$1: (options?: Partial<Config>, root?: ParentNode) => Promise<TablechartInstance>;
430
497
  /** A Markdown table, or a caption with chart attributes, is wrapped in a figure with the caption and annotations beside it. */
431
498
  declare const adoptTables: (figures: HTMLElement[]) => HTMLElement[];
432
499
  /** `data-chart-src` fills the figure's table with the rows of a JSON file, keeping a header row the author wrote; a file that fails is reported. */
@@ -439,4 +506,36 @@ declare const assignKeys: (figures: HTMLElement[], langattribute: string | false
439
506
  declare const checkContrast: (figure: HTMLElement) => void;
440
507
  /** Warns about text that does not stand out enough: a number inside a bar from that bar, other text from the background, once the chart is built. */
441
508
  declare const checkTextContrast: (figure: HTMLElement) => void;
442
- export { PRINTING_CLASS as A, Series as C, Config as D, AT_ONCE_CLASS as E, SHOWN_CLASS as M, defaultConfig as N, PLACED_CLASS as O, Row as S, stepTo as T, setShown as _, loadSources as a, ChartState as b, TablechartInstance as c, init as d, prepare as f, relabel as g, layout as h, adoptTables as i, QUEUED_CLASS as j, PLOT_CLASS as k, create as l, build as m, checkTextContrast as n, readMarkdownRows as o, addType as p, assignKeys as r, TablechartChart as s, checkContrast as t, entranceOf as u, unbuild as v, StepPlan as w, ChartType as x, scatter as y };
509
+ /** The words that `{trend}`, `{change}` and `{side}` become. */
510
+ interface SummaryWords {
511
+ up: string;
512
+ down: string;
513
+ flat: string;
514
+ unclear: string;
515
+ above: string;
516
+ below: string;
517
+ }
518
+ interface SummaryConfig {
519
+ /** The charts that may have a summary. */
520
+ selector: string;
521
+ /** Around a placeholder, such as `{highest.value}`. A template engine that uses single braces needs others, such as `["[[", "]]"]`. */
522
+ delimiters: [string, string];
523
+ /** The attribute for translation keys, as in Tablechart. A name in a sentence keeps its key. */
524
+ langattribute: string | false;
525
+ /** Locale for numbers and lists. Unset, the language of the page is used and followed when it changes. */
526
+ locale?: string;
527
+ /** A trend or a change of less than this percentage is flat. */
528
+ flat: number;
529
+ /** A value more than this percentage away from the trend is an outlier. */
530
+ outliers: number;
531
+ /** For `{trend}`, `{change}` and `{side}`. A sentence per outcome, with `data-when`, translates better. */
532
+ words: SummaryWords;
533
+ /** The number of groups of rows in `groups`, for an overview of a long table. */
534
+ groups: number;
535
+ }
536
+ declare const summaryDefaults: SummaryConfig;
537
+ /** Fills the sentences of one chart again, from its table as it is now. */
538
+ declare const fill: (figure: HTMLElement, options?: Partial<SummaryConfig>) => void;
539
+ /** Fills the summary of every chart now, again when its table is ready or changes, and when a translation changes a sentence or the language. */
540
+ declare const init: (options?: Partial<SummaryConfig>) => void;
541
+ export { StepPlan as A, addType as C, ChartType as D, ChartState as E, PLOT_CLASS as F, PRINTING_CLASS as I, QUEUED_CLASS as L, AT_ONCE_CLASS as M, Config as N, Row as O, PLACED_CLASS as P, SHOWN_CLASS as R, unbuild as S, candlestick as T, prepare as _, summaryDefaults as a, build as b, assignKeys as c, readMarkdownRows as d, TablechartChart as f, init$1 as g, entranceOf as h, SummaryWords as i, stepTo as j, Series as k, adoptTables as l, create as m, fill as n, checkContrast as o, TablechartInstance as p, SummaryConfig as r, checkTextContrast as s, init as t, loadSources as u, setShown as v, scatter as w, relabel as x, layout as y, defaultConfig as z };