@martinomagnifico/tablechart 1.0.2 → 1.0.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.0.3] - 2026-10-11
4
+
5
+ ### Added
6
+
7
+ - Changes to handling of JSON data sources. A header row written in the figure table markup, if missing from the data source, is then used.
8
+ - Values below zero on column, bar, line, area and waterfall charts, also in stacks.
9
+
10
+ ### Changed
11
+
12
+ - A waterfall builds one step at a time: a column grows, then its connector draws, then the next column.
13
+
14
+ ### Removed
15
+
16
+ - The `closing` option and `data-chart-closing`. The last total of a waterfall always grows from the last connector to the baseline.
17
+
18
+ ### Fixed
19
+
20
+ - A chart's hidden table no longer adds empty pages in print.
21
+
22
+
3
23
  ## [1.0.2] - 2026-10-10
4
24
 
5
25
  ### Added
package/README.md CHANGED
@@ -1,13 +1,30 @@
1
1
  # Tablechart
2
2
 
3
- Simple charts from an HTML or Markdown table: column, bar, line, area,
4
- waterfall and donut, with annotations. A chart builds when it scrolls into
5
- view. Charts are SVG and use the colours of the page, which you can change with
6
- CSS variables.
3
+ [![Version](https://img.shields.io/npm/v/@martinomagnifico/tablechart)](https://www.npmjs.com/package/@martinomagnifico/tablechart)
7
4
 
8
- > Work in progress. The documentation site is in `docs/`.
5
+ [<img src="screenshot.png" width="100%" alt="Tablechart: a column chart, a donut and a waterfall">](https://martinomagnifico.github.io/tablechart/)
9
6
 
10
- ## Install
7
+ ----
8
+
9
+ ## What is it?
10
+
11
+ Tablechart makes simple charts from a table: an HTML table, a Markdown table or a JSON file. You write the table, Tablechart shows it as a chart.
12
+
13
+ * **Chart types:** column, bar, line, area, waterfall and donut
14
+ * **The table stays:** it is hidden from sight, but screen readers, search engines and translation scripts still read it. Without JavaScript, the table is all there is.
15
+ * **Real text:** names and numbers are HTML, so they use the font of the page and do not scale with the drawing.
16
+ * **CSS for the looks:** colours, sizes and animation are CSS variables. Light and dark mode follow the page.
17
+ * **Annotations:** callouts, brackets, trend arrows and a break in the scale
18
+ * **Step by step:** show the rows one at a time, with Previous and Next buttons
19
+ * **Animation:** a chart builds when it scrolls into view
20
+
21
+ ----
22
+
23
+ **Documentation:** every chart type, option and CSS variable, with live examples, is at <https://martinomagnifico.github.io/tablechart/>. This README is a quick start.
24
+
25
+ ----
26
+
27
+ ## Installation
11
28
 
12
29
  ```sh
13
30
  npm install @martinomagnifico/tablechart
@@ -26,46 +43,48 @@ Or with a script tag:
26
43
  <link rel="stylesheet" href="tablechart.css">
27
44
  <script src="tablechart.js"></script>
28
45
  <script>
29
- Tablechart.init();
46
+ Tablechart.init();
30
47
  </script>
31
48
  ```
32
49
 
33
- ## Markup
50
+ ## A chart
34
51
 
35
- A chart is an element with `data-chart` and a table in it. The first cell of a
36
- row is the label, the second the value.
52
+ A chart is a `figure` with `data-chart` and a table in it. The first cell of a row is its name, the other cells are its values. The `figcaption` is the title; text after a `br` is the subtitle.
37
53
 
38
54
  ```html
39
55
  <figure data-chart="column">
40
- <figcaption><b>Apples picked</b><br><span>thousands</span></figcaption>
41
- <table>
42
- <tbody>
43
- <tr><th>Spring</th><td>58</td></tr>
44
- <tr><th>Summer</th><td>72</td></tr>
45
- <tr><th>Autumn</th><td>70</td></tr>
46
- </tbody>
47
- </table>
56
+ <figcaption><b>Apples picked</b><br><span>thousands</span></figcaption>
57
+ <table>
58
+ <tbody>
59
+ <tr><th>Spring</th><td>58</td></tr>
60
+ <tr><th>Summer</th><td>72</td></tr>
61
+ <tr><th>Autumn</th><td>70</td></tr>
62
+ </tbody>
63
+ </table>
48
64
  </figure>
49
65
  ```
50
66
 
67
+ Use `bar`, `line`, `area`, `waterfall` or `donut` for the other types. With more than one value column, each column is a line, or a bar in each group. Add `data-chart-stack` to stack them.
68
+
51
69
  ## Options
52
70
 
53
71
  ```js
54
72
  init({
55
- selector: "[data-chart]", // The elements to make charts of
56
- threshold: 0.5, // How much of a chart must be in view before it builds
57
- replay: false, // Build again each time a chart scrolls back into view
58
- animate: true, // Animate the chart when it builds
59
- langattribute: "data-i18n", // The attribute for translation keys, or false for none
60
- debug: false
73
+ animate: true, // Animate a chart when it builds: true, false, "across" or "up"
74
+ threshold: 0.5, // How much of a chart must be in view before it builds
75
+ replay: false, // Build again each time a chart scrolls back into view
76
+ controls: true, // Previous and Next buttons on a chart that steps
77
+ locale: undefined, // Locale for numbers; the language of the page if not set
61
78
  });
62
79
  ```
63
80
 
64
- `init` returns `{ charts, refresh, destroy }`. `refresh()` lays out every chart
65
- again. `destroy()` stops watching scroll, size and language changes.
81
+ Most options can also be set on one chart with a `data-chart-*` attribute. All options are in the [options reference](https://martinomagnifico.github.io/tablechart/reference/options.html).
66
82
 
67
- To make a chart of one element, use `create`. Each chart is also on its element,
68
- as `element.tablechart`:
83
+ ## API
84
+
85
+ `init()` returns `{ charts, refresh, destroy }`. `refresh()` lays out every chart again. `destroy()` stops watching scroll, size and language changes.
86
+
87
+ To make a chart of one element, use `create()`. Each chart is also on its element, as `element.tablechart`.
69
88
 
70
89
  ```js
71
90
  import { create } from "@martinomagnifico/tablechart";
@@ -74,19 +93,27 @@ const chart = await create(document.querySelector("#sales"));
74
93
  chart.refresh();
75
94
  ```
76
95
 
77
- ## Bar width
96
+ For a script that decides itself when a chart builds, `@martinomagnifico/tablechart/core` has the separate steps. See the [API reference](https://martinomagnifico.github.io/tablechart/reference/api.html).
97
+
98
+ ## Styling
99
+
100
+ Tablechart uses the colours of the page. To change them, set CSS variables on a chart or on a parent:
101
+
102
+ ```css
103
+ .sales {
104
+ --tablechart-bar-color: teal;
105
+ --tablechart-value-size: 1.2em;
106
+ }
107
+ ```
108
+
109
+ All variables are in the [CSS variables reference](https://martinomagnifico.github.io/tablechart/reference/variables.html).
78
110
 
79
- A column, a waterfall step or a bar is never wider than `--tablechart-bar-max`,
80
- 60px by default. Use any of `px`, `%` (of the chart's width), `em` or `rem`. In a
81
- narrow chart, bars are 58% of their space. Set `--tablechart-bar-max: none` for
82
- no maximum.
111
+ ## Reveal.js
83
112
 
84
- ## Height
113
+ For charts in a Reveal.js presentation, with fragments that step a chart, use [reveal.js-tablechart](https://github.com/Martinomagnifico/reveal.js-tablechart).
85
114
 
86
- The height of a chart is a share of its width: `data-chart-aspect`, 0.38 by
87
- default. On a narrow screen it is never less than `--tablechart-min-height`,
88
- 200px by default. Use `px`, `em` or `rem`, or `none` for no minimum.
115
+ Tablechart is free and open source. If it saves you time, consider [sponsoring my work](https://ko-fi.com/martinomagnifico).
89
116
 
90
- ## Licence
117
+ ## License
91
118
 
92
- MIT
119
+ MIT © [Martinomagnifico](https://github.com/martinomagnifico)
@@ -69,6 +69,8 @@ declare interface ChartType {
69
69
  /** A break in the scale works here; a waterfall keeps its floating steps clear of it. */
70
70
  breakable?: boolean;
71
71
  stackable?: boolean;
72
+ /** A stack is a running sum, so each line follows the one under it; otherwise values below zero stack down from zero. */
73
+ running?: boolean;
72
74
  totals?: boolean;
73
75
  /** The sample in front of a legend name when it is not a line; the legend shows only when asked. */
74
76
  swatch?: "box";
@@ -118,8 +120,6 @@ export declare interface Config {
118
120
  labels: "outside" | "inside";
119
121
  /** How a line or area runs between points: `straight`, `step` or `smooth`. A figure overrides it with `data-chart-shape`. */
120
122
  shape: "straight" | "step" | "smooth";
121
- /** How the closing total of a waterfall grows: `down` from the step before it to the baseline, or `up` from the baseline. A figure overrides it with `data-chart-closing`. */
122
- closing: "down" | "up";
123
123
  /** Names of several lines in a legend instead of at the end of each line. A figure overrides it with `data-chart-legend`. */
124
124
  legend: boolean;
125
125
  /** Pointing at a row shows numbers that were left out for lack of room. A figure turns it off with `data-chart-hover="false"`. */
@@ -175,7 +175,6 @@ declare interface Geometry {
175
175
  /** Where a bar chart is cut across, in viewBox units; set by its drawing. */
176
176
  breakX?: number;
177
177
  labels: "outside" | "inside";
178
- closing: "down" | "up";
179
178
  /** Where a number inside its bar goes, from `--tablechart-inside-align`; null for the chart's own default. */
180
179
  insideAlign: "start" | "center" | "end" | null;
181
180
  stacked: boolean;
@@ -211,7 +210,7 @@ declare interface HeadroomInput {
211
210
  /** Pass 3. Needs layout; makes no text, only places it. */
212
211
  export declare const layout: (state: ChartState, config: Config) => boolean;
213
212
 
214
- /** `data-chart-src` replaces any table in the figure with one made from a JSON file; a file that fails is reported. */
213
+ /** `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. */
215
214
  export declare const loadSources: (figures: HTMLElement[]) => Promise<void>;
216
215
 
217
216
  export declare const PLACED_CLASS = "is-placed";