@martinomagnifico/tablechart 1.3.0 → 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 {
@@ -363,6 +402,7 @@ interface ChartState {
363
402
  titles: HTMLElement[];
364
403
  ticks: HTMLElement;
365
404
  numbers: boolean;
405
+ right: boolean;
366
406
  } | null;
367
407
  stacked: boolean;
368
408
  totals: HTMLElement[];
@@ -373,6 +413,12 @@ interface ChartState {
373
413
  rowBox: ((index: number) => [number, number, number, number]) | null;
374
414
  /** Where the tooltip of a row points, in viewBox units; set by a chart such as a line. */
375
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;
376
422
  annotations: {
377
423
  spec: HTMLElement;
378
424
  type: AnnotationType;
@@ -389,6 +435,8 @@ interface ChartState {
389
435
  controls: HTMLElement | null;
390
436
  checks: Check[];
391
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;
392
440
  /** One marker per row, across by its first value and up by its second; a third value makes it a bubble. */
393
441
  declare const scatter: ChartType;
394
442
  /** Adds a chart type for `data-chart="name"`, such as one from `@martinomagnifico/tablechart/additional-types`, before `init()`. */
@@ -445,7 +493,7 @@ declare const entranceOf: (figure: HTMLElement, config: Config) => number;
445
493
  declare const prepare: (found: HTMLElement[], config: Config) => Promise<HTMLElement[]>;
446
494
  /** Makes a chart of one figure; returns the existing chart if there is one, or null without data. */
447
495
  declare const create: (element: HTMLElement, options?: Partial<Config>) => Promise<TablechartChart | null>;
448
- declare const init: (options?: Partial<Config>, root?: ParentNode) => Promise<TablechartInstance>;
496
+ declare const init$1: (options?: Partial<Config>, root?: ParentNode) => Promise<TablechartInstance>;
449
497
  /** A Markdown table, or a caption with chart attributes, is wrapped in a figure with the caption and annotations beside it. */
450
498
  declare const adoptTables: (figures: HTMLElement[]) => HTMLElement[];
451
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. */
@@ -458,4 +506,36 @@ declare const assignKeys: (figures: HTMLElement[], langattribute: string | false
458
506
  declare const checkContrast: (figure: HTMLElement) => void;
459
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. */
460
508
  declare const checkTextContrast: (figure: HTMLElement) => void;
461
- 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, unbuild as _, loadSources as a, ChartState as b, TablechartInstance as c, init as d, prepare as f, relabel as g, build as h, adoptTables as i, QUEUED_CLASS as j, PLOT_CLASS as k, create as l, layout as m, checkTextContrast as n, readMarkdownRows as o, setShown as p, assignKeys as r, TablechartChart as s, checkContrast as t, entranceOf as u, addType 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 };