@martinomagnifico/tablechart 1.0.3 → 1.0.4
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 +27 -0
- package/README.md +2 -2
- package/dist/tablechart-core.d.mts +26 -0
- package/dist/tablechart-core.mjs +1 -2
- package/dist/tablechart-shared.d.mts +302 -0
- package/dist/tablechart-shared.mjs +825 -744
- package/dist/tablechart.css +1 -1
- package/dist/tablechart.d.mts +2 -0
- package/dist/tablechart.js +1 -1
- package/dist/tablechart.mjs +1 -2
- package/package.json +12 -8
- package/dist/tablechart-core.d.ts +0 -313
- package/dist/tablechart.d.ts +0 -85
|
@@ -1,313 +0,0 @@
|
|
|
1
|
-
/** A Markdown table, or a caption with chart attributes, is wrapped in a div with the caption and annotations beside it. */
|
|
2
|
-
export declare const adoptTables: (figures: HTMLElement[]) => HTMLElement[];
|
|
3
|
-
|
|
4
|
-
/** `create` runs before layout, so a translation script finds its text; `draw` only places it. */
|
|
5
|
-
declare interface AnnotationType {
|
|
6
|
-
create: (spec: HTMLElement, plot: HTMLElement) => HTMLElement | null;
|
|
7
|
-
draw: (spec: HTMLElement, badge: HTMLElement | null, geo: Geometry) => void;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/** Writes translation keys such as `harvest-row1` onto a figure with `data-chart-keys`; a duplicate prefix gets a number. */
|
|
11
|
-
export declare const assignKeys: (figures: HTMLElement[], langattribute: string | false) => void;
|
|
12
|
-
|
|
13
|
-
/** Pass 2: everything a reader will read, before a translation script looks. */
|
|
14
|
-
export declare const build: (figure: HTMLElement, config: Config, asKind?: string | null) => ChartState | null;
|
|
15
|
-
|
|
16
|
-
declare interface Cell {
|
|
17
|
-
raw: string;
|
|
18
|
-
/** As written, so its decimal places survive. Empty when the cell holds no number. */
|
|
19
|
-
number: string;
|
|
20
|
-
/** Text around the number, such as `%` or a footnote `*`, kept either side of the formatted number. */
|
|
21
|
-
prefix: string;
|
|
22
|
-
suffix: string;
|
|
23
|
-
/** No number, such as "n/a": no mark, and the label says what the cell says. Counts as zero. */
|
|
24
|
-
missing: boolean;
|
|
25
|
-
value: number;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export declare interface ChartState {
|
|
29
|
-
figure: HTMLElement;
|
|
30
|
-
plot: HTMLElement;
|
|
31
|
-
svg: SVGSVGElement;
|
|
32
|
-
rows: Row[];
|
|
33
|
-
decimals: number;
|
|
34
|
-
type: ChartType;
|
|
35
|
-
values: HTMLElement[];
|
|
36
|
-
series: Series[];
|
|
37
|
-
seriesValues: HTMLElement[][];
|
|
38
|
-
names: HTMLElement[];
|
|
39
|
-
categories: HTMLElement[];
|
|
40
|
-
centre: HTMLElement | null;
|
|
41
|
-
stacked: boolean;
|
|
42
|
-
totals: HTMLElement[];
|
|
43
|
-
totalCell: HTMLElement | null;
|
|
44
|
-
/** In screen pixels from the plot's corner. Null for a chart whose rows are not side by side. */
|
|
45
|
-
rowAt: ((x: number, y: number) => number | null) | null;
|
|
46
|
-
/** As percentages: left, top, width and height. */
|
|
47
|
-
rowBox: ((index: number) => [number, number, number, number]) | null;
|
|
48
|
-
annotations: {
|
|
49
|
-
spec: HTMLElement;
|
|
50
|
-
type: AnnotationType;
|
|
51
|
-
badge: HTMLElement | null;
|
|
52
|
-
/** From 0; `data-series` counts from 1. */
|
|
53
|
-
series: number;
|
|
54
|
-
after: number;
|
|
55
|
-
}[];
|
|
56
|
-
/** The steps of a chart that steps (`data-fragment`); null for one that does not. */
|
|
57
|
-
plan: StepPlan | null;
|
|
58
|
-
/** How many steps are shown. */
|
|
59
|
-
step: number;
|
|
60
|
-
/** The Previous and Next buttons, if Tablechart made them. */
|
|
61
|
-
controls: HTMLElement | null;
|
|
62
|
-
checks: Check[];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
declare interface ChartType {
|
|
66
|
-
aspect?: number;
|
|
67
|
-
/** A row marked as a total goes in the middle rather than among the marks. */
|
|
68
|
-
centre?: boolean;
|
|
69
|
-
/** A break in the scale works here; a waterfall keeps its floating steps clear of it. */
|
|
70
|
-
breakable?: boolean;
|
|
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;
|
|
74
|
-
totals?: boolean;
|
|
75
|
-
/** The sample in front of a legend name when it is not a line; the legend shows only when asked. */
|
|
76
|
-
swatch?: "box";
|
|
77
|
-
categories?: "under" | "beside";
|
|
78
|
-
series?: boolean;
|
|
79
|
-
/** With several series, always a legend, with a sample of this shape. */
|
|
80
|
-
legend?: "box";
|
|
81
|
-
headroom?: (geo: HeadroomInput) => number;
|
|
82
|
-
minHeight?: (input: {
|
|
83
|
-
labelHeight: number;
|
|
84
|
-
nameHeight: number;
|
|
85
|
-
unit: number;
|
|
86
|
-
rows: number;
|
|
87
|
-
series: number;
|
|
88
|
-
stacked: boolean;
|
|
89
|
-
}) => number;
|
|
90
|
-
/** Room under the baseline for numbers that hang below a mark near it. */
|
|
91
|
-
footroom?: (geo: HeadroomInput) => number;
|
|
92
|
-
/** Default: one bar per row from the baseline. */
|
|
93
|
-
segments?: (rows: Row[]) => Segment[];
|
|
94
|
-
draw: (geo: Geometry) => void;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
declare interface Check {
|
|
98
|
-
label: string;
|
|
99
|
-
computed: number;
|
|
100
|
-
stated: number;
|
|
101
|
-
agrees: boolean;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export declare interface Config {
|
|
105
|
-
/** Which elements Tablechart turns into charts. */
|
|
106
|
-
selector: string;
|
|
107
|
-
/** Height of the plot as a share of its width. */
|
|
108
|
-
aspect: number;
|
|
109
|
-
/** Share of a band that a bar fills. */
|
|
110
|
-
barfill: number;
|
|
111
|
-
/** Share of a donut's radius that the ring itself takes. */
|
|
112
|
-
ringfill: number;
|
|
113
|
-
/** Locale for numbers. Unset, the document's language is used and followed when it changes. */
|
|
114
|
-
locale?: string;
|
|
115
|
-
/** Animate a chart when it builds. `"up"` grows lines and areas from zero instead of across; a figure overrides it with `data-chart-animate`. */
|
|
116
|
-
animate: boolean | "across" | "up";
|
|
117
|
-
/** How far an animated parent is in before its chart builds: 0 when it starts moving, 1 when it is in. A figure overrides it with `data-chart-entrance`. */
|
|
118
|
-
entrance: number;
|
|
119
|
-
/** Where a column's number goes: on the bar, or inside it. A figure overrides it with `data-chart-labels`. */
|
|
120
|
-
labels: "outside" | "inside";
|
|
121
|
-
/** How a line or area runs between points: `straight`, `step` or `smooth`. A figure overrides it with `data-chart-shape`. */
|
|
122
|
-
shape: "straight" | "step" | "smooth";
|
|
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
|
-
legend: boolean;
|
|
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"`. */
|
|
126
|
-
hover: boolean;
|
|
127
|
-
/** The name of the total that a donut without a total row works out, for screen readers. */
|
|
128
|
-
totallabel: string;
|
|
129
|
-
/** Previous and Next buttons under a chart that steps (`data-fragment`). `false` leaves them out, for buttons of your own. */
|
|
130
|
-
controls: boolean;
|
|
131
|
-
/** The text of the Previous button. */
|
|
132
|
-
previouslabel: string;
|
|
133
|
-
/** The text of the Next button. */
|
|
134
|
-
nextlabel: string;
|
|
135
|
-
/** Read by screen readers after the text of each button, so they know it only changes the chart. */
|
|
136
|
-
stephint: string;
|
|
137
|
-
/** How much of a chart must be in view before it builds, from 0 to 1. */
|
|
138
|
-
threshold: number;
|
|
139
|
-
/** Build again each time a chart scrolls back into view, not only the first time. */
|
|
140
|
-
replay: boolean;
|
|
141
|
-
/** The attribute for translation keys, for a translation script. `false` turns keys off. */
|
|
142
|
-
langattribute: string | false;
|
|
143
|
-
/** Show messages in the console for whoever is working on the page. */
|
|
144
|
-
debug?: boolean;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export declare const defaultConfig: Config;
|
|
148
|
-
|
|
149
|
-
/** How far an animated parent is in before the chart builds: the figure's `data-chart-entrance`, or else the option. */
|
|
150
|
-
export declare const entranceOf: (figure: HTMLElement, config: Config) => number;
|
|
151
|
-
|
|
152
|
-
/** Scales only, no pixel positions, so an annotation follows the data. */
|
|
153
|
-
declare interface Geometry {
|
|
154
|
-
rows: Row[];
|
|
155
|
-
segments: Segment[];
|
|
156
|
-
cx: (index: number) => number;
|
|
157
|
-
y: (value: number) => number;
|
|
158
|
-
barWidth: number;
|
|
159
|
-
barMax: number;
|
|
160
|
-
height: number;
|
|
161
|
-
/** viewBox units per screen pixel. */
|
|
162
|
-
unit: number;
|
|
163
|
-
labelHeight: number;
|
|
164
|
-
badgeHeight: number;
|
|
165
|
-
/** How many stagger steps the data takes, so commentary can land after it. */
|
|
166
|
-
after: number;
|
|
167
|
-
/** An annotation's number in the figure, from 1, set as `data-note` on its marks. Zero for the chart. */
|
|
168
|
-
note: number;
|
|
169
|
-
/** Where the break's mark goes, as a value. Null when the scale runs straight through. */
|
|
170
|
-
breakAt: number | null;
|
|
171
|
-
/** The break itself, for a chart that makes a scale of its own, such as a bar chart. */
|
|
172
|
-
squeeze: Squeeze | null;
|
|
173
|
-
/** The empty space where the scale jumps, in viewBox units. */
|
|
174
|
-
breakGap: number;
|
|
175
|
-
/** Where a bar chart is cut across, in viewBox units; set by its drawing. */
|
|
176
|
-
breakX?: number;
|
|
177
|
-
labels: "outside" | "inside";
|
|
178
|
-
/** Where a number inside its bar goes, from `--tablechart-inside-align`; null for the chart's own default. */
|
|
179
|
-
insideAlign: "start" | "center" | "end" | null;
|
|
180
|
-
stacked: boolean;
|
|
181
|
-
shape: Shape;
|
|
182
|
-
/** Empty when the chart is not stacked or its kind shows no totals. */
|
|
183
|
-
totals: HTMLElement[];
|
|
184
|
-
svg: SVGSVGElement;
|
|
185
|
-
plot: HTMLElement;
|
|
186
|
-
/** Made by `build`; a chart only places them. */
|
|
187
|
-
values: HTMLElement[];
|
|
188
|
-
series: Series[];
|
|
189
|
-
seriesValues: HTMLElement[][];
|
|
190
|
-
/** Empty with one series. */
|
|
191
|
-
names: HTMLElement[];
|
|
192
|
-
/** A chart with its names beside the marks places these; one with them under the plot does not. */
|
|
193
|
-
categories: HTMLElement[];
|
|
194
|
-
centre: HTMLElement | null;
|
|
195
|
-
config: Config;
|
|
196
|
-
/** Numbers an annotation worked out, against the ones the author wrote. */
|
|
197
|
-
checks: Check[];
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
declare interface HeadroomInput {
|
|
201
|
-
labelHeight: number;
|
|
202
|
-
badgeHeight: number;
|
|
203
|
-
hasAnnotations: boolean;
|
|
204
|
-
unit: number;
|
|
205
|
-
series: number;
|
|
206
|
-
focused: boolean;
|
|
207
|
-
stacked: boolean;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/** Pass 3. Needs layout; makes no text, only places it. */
|
|
211
|
-
export declare const layout: (state: ChartState, config: Config) => boolean;
|
|
212
|
-
|
|
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. */
|
|
214
|
-
export declare const loadSources: (figures: HTMLElement[]) => Promise<void>;
|
|
215
|
-
|
|
216
|
-
export declare const PLACED_CLASS = "is-placed";
|
|
217
|
-
|
|
218
|
-
export declare const PLOT_CLASS = "tablechart-plot";
|
|
219
|
-
|
|
220
|
-
/** Turns elements into figures with a table and translation keys, all at once, so duplicate keys are found. */
|
|
221
|
-
export declare const prepare: (found: HTMLElement[], config: Config) => Promise<HTMLElement[]>;
|
|
222
|
-
|
|
223
|
-
export declare const QUEUED_CLASS = "tablechart-queued";
|
|
224
|
-
|
|
225
|
-
/** In a Markdown table, a bold label makes the row a total, and a bold header puts that series in focus. */
|
|
226
|
-
export declare const readMarkdownRows: (figures: HTMLElement[]) => void;
|
|
227
|
-
|
|
228
|
-
/** Numbers are reformatted in place, so a language change costs no redraw. */
|
|
229
|
-
export declare const relabel: (state: ChartState, config: Config) => void;
|
|
230
|
-
|
|
231
|
-
export declare interface Row extends Cell {
|
|
232
|
-
label: string;
|
|
233
|
-
key: string | null;
|
|
234
|
-
cells: Cell[];
|
|
235
|
-
/** Copied to everything drawn for the row, so one class styles all of it. */
|
|
236
|
-
classes: string[];
|
|
237
|
-
isTotal: boolean;
|
|
238
|
-
/** The stagger counts from here. */
|
|
239
|
-
slot: number;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
declare interface Segment extends Row {
|
|
243
|
-
from: number;
|
|
244
|
-
to: number;
|
|
245
|
-
kind: "bar" | "up" | "down" | "total";
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
export declare interface Series {
|
|
249
|
-
name: string;
|
|
250
|
-
key: string | null;
|
|
251
|
-
/** `data-kind="focus"`, or bold in Markdown: the others are shown fainter. */
|
|
252
|
-
focus: boolean;
|
|
253
|
-
/** `data-marker` on the header, such as `square` or `diamond open`. */
|
|
254
|
-
marker: string | null;
|
|
255
|
-
line: "dashed" | "dotted" | null;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/** One class, `is-shown`, starts the whole build. */
|
|
259
|
-
export declare const setShown: (state: ChartState, shown: boolean) => void;
|
|
260
|
-
|
|
261
|
-
/** How a line or an area runs from one point to the next. */
|
|
262
|
-
declare type Shape = "straight" | "step" | "smooth";
|
|
263
|
-
|
|
264
|
-
export declare const SHOWN_CLASS = "is-shown";
|
|
265
|
-
|
|
266
|
-
/** A break in the scale: values from `lo` to `hi` get `share` of the length, and the cut is at `gap`. */
|
|
267
|
-
declare interface Squeeze {
|
|
268
|
-
lo: number;
|
|
269
|
-
hi: number;
|
|
270
|
-
gap: number;
|
|
271
|
-
share: number;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/** The steps of one chart: which step shows each row, column and annotation, and how many steps there are. */
|
|
275
|
-
export declare interface StepPlan {
|
|
276
|
-
rows: {
|
|
277
|
-
step: number | null;
|
|
278
|
-
slot: number;
|
|
279
|
-
}[];
|
|
280
|
-
series: {
|
|
281
|
-
step: number | null;
|
|
282
|
-
}[];
|
|
283
|
-
/** A cell on a step of its own, by row and then by column. */
|
|
284
|
-
cells: {
|
|
285
|
-
step: number | null;
|
|
286
|
-
slot: number;
|
|
287
|
-
}[][];
|
|
288
|
-
notes: {
|
|
289
|
-
step: number | null;
|
|
290
|
-
after: number;
|
|
291
|
-
}[];
|
|
292
|
-
count: number;
|
|
293
|
-
/** The `data-fragment-index` of each step, if it asked for one, so a presentation can make a fragment for each. */
|
|
294
|
-
indexes: (string | null)[];
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* Shows the chart up to step `step`, from 0 (only what has no step) to the number of steps (all of it).
|
|
299
|
-
* Says so with a `tablechart:step` event on the figure, unless `quietly`.
|
|
300
|
-
*/
|
|
301
|
-
export declare const stepTo: (state: ChartState, step: number, quietly?: boolean) => void;
|
|
302
|
-
|
|
303
|
-
/** Removes what `build` added, so the chart can be built again. */
|
|
304
|
-
export declare const unbuild: (state: ChartState) => void;
|
|
305
|
-
|
|
306
|
-
export { }
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
declare global {
|
|
310
|
-
interface HTMLElement {
|
|
311
|
-
tablechart?: TablechartChart;
|
|
312
|
-
}
|
|
313
|
-
}
|
package/dist/tablechart.d.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/** Makes a chart of one element; returns the existing chart if there is one, or null without data. */
|
|
2
|
-
export declare const create: (element: HTMLElement, options?: Partial<TablechartConfig>) => Promise<TablechartChart | null>;
|
|
3
|
-
|
|
4
|
-
export declare const defaultConfig: TablechartConfig;
|
|
5
|
-
|
|
6
|
-
/** Makes a chart of every element in `root` that matches the selector, skipping existing charts. */
|
|
7
|
-
export declare const init: (options?: Partial<TablechartConfig>, root?: ParentNode) => Promise<TablechartInstance>;
|
|
8
|
-
|
|
9
|
-
export declare interface TablechartChart {
|
|
10
|
-
figure: HTMLElement;
|
|
11
|
-
/** Lays the chart out again, for example after a script has changed its text. */
|
|
12
|
-
refresh(): void;
|
|
13
|
-
/** Stops watching scroll, size and language. The chart stays as it is. */
|
|
14
|
-
destroy(): void;
|
|
15
|
-
/** On a chart that steps (`data-fragment`): shows one step more. */
|
|
16
|
-
next(): void;
|
|
17
|
-
/** On a chart that steps: shows one step less. */
|
|
18
|
-
previous(): void;
|
|
19
|
-
/** On a chart that steps: shows the chart up to `step`, from 0 to `steps`. */
|
|
20
|
-
stepTo(step: number): void;
|
|
21
|
-
/** How many steps are shown. */
|
|
22
|
-
readonly step: number;
|
|
23
|
-
/** How many steps the chart has; 0 for a chart that does not step. */
|
|
24
|
-
readonly steps: number;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export declare interface TablechartConfig {
|
|
28
|
-
/** Which elements Tablechart turns into charts. */
|
|
29
|
-
selector: string;
|
|
30
|
-
/** Height of the plot as a share of its width. */
|
|
31
|
-
aspect: number;
|
|
32
|
-
/** Share of a band that a bar fills. */
|
|
33
|
-
barfill: number;
|
|
34
|
-
/** Share of a donut's radius that the ring itself takes. */
|
|
35
|
-
ringfill: number;
|
|
36
|
-
/** Locale for numbers. Unset, the document's language is used and followed when it changes. */
|
|
37
|
-
locale?: string;
|
|
38
|
-
/** Animate a chart when it builds. `"up"` grows lines and areas from zero instead of across; a figure overrides it with `data-chart-animate`. */
|
|
39
|
-
animate: boolean | "across" | "up";
|
|
40
|
-
/** How far an animated parent is in before its chart builds: 0 when it starts moving, 1 when it is in. A figure overrides it with `data-chart-entrance`. */
|
|
41
|
-
entrance: number;
|
|
42
|
-
/** Where a column's number goes: on the bar, or inside it. A figure overrides it with `data-chart-labels`. */
|
|
43
|
-
labels: "outside" | "inside";
|
|
44
|
-
/** How a line or area runs between points: `straight`, `step` or `smooth`. A figure overrides it with `data-chart-shape`. */
|
|
45
|
-
shape: "straight" | "step" | "smooth";
|
|
46
|
-
/** Names of several lines in a legend instead of at the end of each line. A figure overrides it with `data-chart-legend`. */
|
|
47
|
-
legend: boolean;
|
|
48
|
-
/** Pointing at a row shows numbers that were left out for lack of room. A figure turns it off with `data-chart-hover="false"`. */
|
|
49
|
-
hover: boolean;
|
|
50
|
-
/** The name of the total that a donut without a total row works out, for screen readers. */
|
|
51
|
-
totallabel: string;
|
|
52
|
-
/** Previous and Next buttons under a chart that steps (`data-fragment`). `false` leaves them out, for buttons of your own. */
|
|
53
|
-
controls: boolean;
|
|
54
|
-
/** The text of the Previous button. */
|
|
55
|
-
previouslabel: string;
|
|
56
|
-
/** The text of the Next button. */
|
|
57
|
-
nextlabel: string;
|
|
58
|
-
/** Read by screen readers after the text of each button, so they know it only changes the chart. */
|
|
59
|
-
stephint: string;
|
|
60
|
-
/** How much of a chart must be in view before it builds, from 0 to 1. */
|
|
61
|
-
threshold: number;
|
|
62
|
-
/** Build again each time a chart scrolls back into view, not only the first time. */
|
|
63
|
-
replay: boolean;
|
|
64
|
-
/** The attribute for translation keys, for a translation script. `false` turns keys off. */
|
|
65
|
-
langattribute: string | false;
|
|
66
|
-
/** Show messages in the console for whoever is working on the page. */
|
|
67
|
-
debug?: boolean;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export declare interface TablechartInstance {
|
|
71
|
-
charts: TablechartChart[];
|
|
72
|
-
/** Lays out every chart again, for example after a script has changed its text. */
|
|
73
|
-
refresh(): void;
|
|
74
|
-
/** Stops watching scroll, size and language. The charts stay as they are. */
|
|
75
|
-
destroy(): void;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export { }
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
declare global {
|
|
82
|
-
interface HTMLElement {
|
|
83
|
-
tablechart?: TablechartChart;
|
|
84
|
-
}
|
|
85
|
-
}
|