@sheetpane/charts 0.0.0-stage → 0.3.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/dist/ui.js ADDED
@@ -0,0 +1,143 @@
1
+ // @sheetpane/charts/ui — what charts adds to the grid's slots (W-21 DoD 1, "the action").
2
+ // Opt-in: the headless entry never imports this file.
3
+ //
4
+ // The action itself — **Show source cells** — is a button on each chart's frame, in both modes:
5
+ // it is the only place that knows which chart is meant. This entry adds two things the frame
6
+ // cannot give:
7
+ // - the status line: `Chart source: Holdings!E3:E15, H3:H15` while the selection lies in a
8
+ // chart's plotted cells or under its frame, else `2 charts` on a sheet that has some;
9
+ // - a keyboard path to the same action (Mod+Shift+U, listed in the grid's keyboard help): it
10
+ // shows the source of the chart over the active cell, or of the sheet's only chart. The frame
11
+ // sits inside the grid's `role="img"` overlay wrapper, where a screen reader does not reach its
12
+ // button — the shortcut is the accessible route until the overlay contract lets an item be a group.
13
+ // Not a `selbar` button: a selbar control has no "applies here" test, so it would show on every
14
+ // selection, chart or not.
15
+ import { registerPlugin } from '@sheetpane/grid';
16
+ import { chartAt, chartModel, chartModelNow, charts, chartsOn, showSource } from './index.js';
17
+ import { intersects, parseArea, parseCell, qualified, uniqueRanges } from './refs.js';
18
+ /** The controls plugin's id. */
19
+ export const UI_ID = 'charts-ui';
20
+ /** The keyboard shortcut for Show source cells. */
21
+ export const SHORTCUT = 'Mod+Shift+U';
22
+ /**
23
+ * The ranges a chart reads, categories before values — the order the status line names them in.
24
+ *
25
+ * @param m - The chart model.
26
+ * @returns The ranges, without duplicates.
27
+ */
28
+ export function sourceList(m) {
29
+ return uniqueRanges(m.series.flatMap((s) => [...(s.cat?.ranges ?? []), ...(s.val?.ranges ?? [])]));
30
+ }
31
+ /** Every parsed chart in the workbook whose plotted cells meet the selection. */
32
+ function chartsReading(snap, sel) {
33
+ const book = snap.book;
34
+ const area = parseArea(sel.range ?? sel.ref);
35
+ if (!book || !area)
36
+ return [];
37
+ const out = [];
38
+ for (const s of book.sheets) {
39
+ for (const { path } of chartsOn(book, s.name)) {
40
+ const m = chartModelNow(book, path);
41
+ if (m && m.plotted.some((r) => r.sheet === sel.sheet && intersects(r, area)))
42
+ out.push(m);
43
+ }
44
+ }
45
+ return out;
46
+ }
47
+ /**
48
+ * The status line's text for a selection: `Chart source: Holdings!E3:E15, H3:H15` while it lies in a chart's plotted
49
+ * cells or under its frame, else `2 charts` on a sheet that has some. Charts not yet read count, but cannot be named.
50
+ *
51
+ * @param snap - A snapshot of the store.
52
+ * @param sel - The selection.
53
+ * @returns The text, or `''`.
54
+ */
55
+ export function statusText(snap, sel) {
56
+ const book = snap.book;
57
+ if (!book)
58
+ return '';
59
+ let m = chartsReading(snap, sel)[0];
60
+ if (!m) {
61
+ const p = parseCell(sel.ref), hit = p && chartAt(book, sel.sheet, p.row, p.col);
62
+ m = (hit && chartModelNow(book, hit.path)) || undefined;
63
+ }
64
+ if (m) {
65
+ const list = sourceList(m);
66
+ return list.length ? `Chart source: ${list.map(qualified).join(', ')}` : 'Chart source: values stored in the chart';
67
+ }
68
+ const n = chartsOn(book, sel.sheet).length;
69
+ return n ? `${n} ${n === 1 ? 'chart' : 'charts'}` : '';
70
+ }
71
+ /**
72
+ * The chart the shortcut acts on: the one over the active cell, else the sheet's only chart.
73
+ *
74
+ * @param store - The workbook store.
75
+ * @param sel - The selection.
76
+ * @returns The chart part's path, or `undefined`.
77
+ */
78
+ export function targetChart(store, sel) {
79
+ const p = parseCell(sel.ref);
80
+ const hit = p && chartAt(store.book, sel.sheet, p.row, p.col);
81
+ if (hit)
82
+ return hit.path;
83
+ const all = chartsOn(store.book, sel.sheet);
84
+ return all.length === 1 ? all[0].path : undefined;
85
+ }
86
+ const source = {
87
+ id: 'charts-source',
88
+ slot: 'status',
89
+ group: 'charts',
90
+ label: 'Show chart source cells',
91
+ shortcut: SHORTCUT,
92
+ mode: 'both',
93
+ text: (snap, sel) => statusText(snap, sel),
94
+ run: (store, sel) => {
95
+ const book = store.book, path = book && targetChart(store, sel);
96
+ if (!book || !path)
97
+ return;
98
+ void chartModel(book, path).then((m) => { if (m && store.book === book)
99
+ showSource(store, m); });
100
+ },
101
+ };
102
+ /**
103
+ * The charts controls: no hooks; a status line naming the source of the chart under the selection (or the sheet's
104
+ * chart count), and Mod+Shift+U for Show source cells — the keyboard route to each frame's button. Pair it with
105
+ * {@link charts}; importing this module makes `plugins="charts"` enable both.
106
+ *
107
+ * @returns The controls plugin (`id: 'charts-ui'`).
108
+ * @see https://github.com/arpitarya/sheetpane/blob/main/records/0113_CHARTS.md
109
+ * @example
110
+ * ```ts
111
+ * import { createWorkbook } from '@sheetpane/grid';
112
+ * import { charts } from '@sheetpane/charts';
113
+ * import { ui } from '@sheetpane/charts/ui';
114
+ *
115
+ * const book = createWorkbook({ plugins: [charts(), ui()] });
116
+ * ```
117
+ * @example
118
+ * ```ts
119
+ * import '@sheetpane/charts/ui'; // registers `charts` with its controls
120
+ * excel.setAttribute('plugins', 'charts');
121
+ * ```
122
+ */
123
+ export function ui() {
124
+ return { id: UI_ID, provides: [], controls: [source] };
125
+ }
126
+ /**
127
+ * The charts plugin and its controls together.
128
+ *
129
+ * @param o - The charts plugin's options.
130
+ * @returns `[charts(o), ui()]`.
131
+ * @example
132
+ * ```ts
133
+ * import { createWorkbook } from '@sheetpane/grid';
134
+ * import { chartsWithUi } from '@sheetpane/charts/ui';
135
+ *
136
+ * const book = createWorkbook({ plugins: chartsWithUi({ draw: false }) });
137
+ * ```
138
+ */
139
+ export function chartsWithUi(o = {}) {
140
+ return [charts(o), ui()];
141
+ }
142
+ registerPlugin('charts', () => chartsWithUi());
143
+ //# sourceMappingURL=ui.js.map
package/dist/ui.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ui.js","sourceRoot":"","sources":["../src/ui.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,sDAAsD;AACtD,EAAE;AACF,gGAAgG;AAChG,6FAA6F;AAC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EAAE,IAAI,GAAG,IAAI,IAAI,WAAW,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAChE,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI;YAAE,OAAO;QAC3B,KAAK,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI;YAAE,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACnG,CAAC;CACF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,EAAE;IAChB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC;AACzD,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAAC,CAAC,GAAkB,EAAE;IAChD,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAC3B,CAAC;AAED,cAAc,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,YAAY,EAAE,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,52 @@
1
1
  {
2
2
  "name": "@sheetpane/charts",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.3.0",
4
+ "description": "Charts for sheetpane — a frame at the chart's anchor with its title and Show source cells; later, own SVG for bar, column, line, pie and scatter — through the `overlay` hook.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/arpitarya/sheetpane.git",
9
+ "directory": "packages/charts"
10
+ },
11
+ "type": "module",
12
+ "sideEffects": [
13
+ "./dist/index.js",
14
+ "./dist/ui.js",
15
+ "./src/index.ts",
16
+ "./src/ui.ts"
17
+ ],
18
+ "engines": {
19
+ "node": ">=22"
20
+ },
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "import": "./dist/index.js"
25
+ },
26
+ "./ui": {
27
+ "types": "./dist/ui.d.ts",
28
+ "import": "./dist/ui.js"
29
+ }
30
+ },
31
+ "files": [
32
+ "dist"
33
+ ],
34
+ "peerDependencies": {
35
+ "@sheetpane/grid": "0.3.0",
36
+ "@sheetpane/images": "0.3.0"
37
+ },
38
+ "dependencies": {
39
+ "@sheetpane/skills": "0.3.0"
40
+ },
41
+ "devDependencies": {
42
+ "@sheetpane/grid": "0.3.0",
43
+ "@sheetpane/images": "0.3.0"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "scripts": {
49
+ "build": "tsc -p tsconfig.build.json",
50
+ "typecheck": "tsc -p tsconfig.json --noEmit"
51
+ }
6
52
  }