create-pmos 0.270.0 → 0.271.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.
@@ -1,10 +1,13 @@
1
- /* pm/premium-studio.js — the Insight Studio on the premium Insights page, part 1: dashboards (initiative premium-studio-dashboard).
2
- * The mockup's Studio (prototype/premium-ux-concept/build-src/stu.js.txt) in its Dashboard mode: a conversation on the left, and on the right a brief of
3
- * chips, a library, a live preview and checks. A turn changes the draft in the page and writes nothing. The one write is Save (or Remove), through the
4
- * existing POST /api/premium-dashboards/save behind the launch nonce. Every title and chart comes from the page's model: the KR metric records and the
5
- * board's saved dashboards. No demo measure is drawn.
1
+ /* pm/premium-studio.js — the Insight Studio on the premium Insights page: its Dashboard mode (initiative premium-studio-dashboard) and its Chart mode
2
+ * (initiative premium-studio-chart). The mockup's Studio (prototype/premium-ux-concept/build-src/stu.js.txt): a conversation on the left, and on the right a
3
+ * mode switch, a brief of chips, a library, a live preview and checks. Each mode keeps its own draft and its own Undo. A turn changes the draft in the
4
+ * page and writes nothing. The writes are Save and Remove, each behind the launch nonce: POST /api/premium-dashboards/save for a dashboard, and
5
+ * POST /api/premium-charts/save for a chart (then the dashboard's save when the chart is added to one). Every title, value and point comes from the page's
6
+ * model: the KR metric records, the board's saved charts and its saved dashboards. No demo measure is drawn.
6
7
  *
7
- * openStudio(P) P = { M, D (the saved dashboard to edit, or null), tile (the page's chart tile), save (body → answer), done (saved id | null) } */
8
+ * openStudio(P) P = { M, mode ('dash' | 'chart'), D (the saved dashboard to edit, or null), C (the saved chart to edit, or null), tile (the page's
9
+ * chart tile), derive (a measure's chart and a draft → the draft's chart), save (dashboard body → answer), saveChart (chart body →
10
+ * answer), done (saved dashboard id | null) } */
8
11
  import { $, esc, openDlg, closeDlg, toast, turnA, turnU, ptx, setFull } from './premium-shell.js';
9
12
 
10
13
  const ICO = (p) => `<svg class="i" viewBox="0 0 24 24">${p}</svg>`;
@@ -12,38 +15,83 @@ const UPI = ICO('<path d="M12 19V5M6 11l6-6 6 6"/>'), DNI = ICO('<path d="M12 5v
12
15
  const OKI = ICO('<path d="M5 12.5l4.5 4.5L19 7.5"/>'), WRN = ICO('<path d="M12 4 2.5 20h19z"/><path d="M12 10v4M12 17v.5"/>'), CHV = ICO('<path d="M6 9l6 6 6-6"/>');
13
16
  const DSI = ICO('<rect x="3" y="3" width="8" height="8" rx="2"/><rect x="13" y="3" width="8" height="8" rx="2"/><rect x="3" y="13" width="8" height="8" rx="2"/><rect x="13" y="13" width="8" height="8" rx="2"/>');
14
17
  const MAX_UNDO = 30;
18
+ const MODES = { chart: 'Chart', dash: 'Dashboard' };
19
+ const FORMN = { line: 'Line', bars: 'Bars', number: 'Number', meter: 'Meter' };
20
+ const FORMD = { line: 'How it moves over time. The default for a trend.', bars: 'One reading against another. Bars start at zero.', number: 'One current value, with its change and a small line.', meter: 'How far it is from its target or limit.' };
15
21
 
16
- let P = null; // the page's hand: { M, D, tile, save, done }
17
- let st = null; // the Studio: { d: draft, h: undo stack, pop, lib, ck, msg, armed, busy }
22
+ let P = null; // the page's hand
23
+ let st = null; // the Studio: { mode, d: dashboard draft, c: chart draft, h: { dash, chart } undo stacks, pop, more, lib, ck, msg, armed, busy }
18
24
 
19
25
  const measures = () => P.M.measures || [];
20
- const chartOf = (id) => (P.M.charts || []).find((c) => c.id === id) || null;
21
- const titleOf = (id) => { const m = measures().find((x) => x.id === id); return m ? m.title : id; };
26
+ const mineSaved = () => P.M.mineSaved || [];
27
+ const chartOf = (id) => (P.M.charts || []).concat(P.M.mine || []).find((c) => c.id === id) || null;
28
+ const baseOf = (id) => (P.M.charts || []).find((c) => c.id === id) || null;
29
+ const titleOf = (id) => { const m = measures().find((x) => x.id === id) || mineSaved().find((x) => x.id === id); return m ? m.title : id; };
22
30
  const savedDash = () => (P.M.dashboards || []).filter((x) => x.saved);
23
31
  const plural = (n, a, b) => n + ' ' + (n === 1 ? a : b);
32
+ const draft = () => (st.mode === 'chart' ? st.c : st.d);
24
33
 
25
- /* ── the draft and its undo ── */
26
- const snap = () => { const h = st.h, cur = JSON.stringify(st.d); if (h.length && h[h.length - 1] === cur) return; h.push(cur); if (h.length > MAX_UNDO) h.shift(); };
27
- const undo = () => { if (!st.h.length) return false; st.d = JSON.parse(st.h.pop()); return true; };
34
+ /* ── the drafts and their undo, one stack per mode ── */
35
+ const snap = () => { const h = st.h[st.mode], cur = JSON.stringify(draft()); if (h.length && h[h.length - 1] === cur) return; h.push(cur); if (h.length > MAX_UNDO) h.shift(); };
36
+ const undo = () => { const h = st.h[st.mode]; if (!h.length) return false; const v = JSON.parse(h.pop()); if (st.mode === 'chart') st.c = v; else st.d = v; return true; };
28
37
  const blank = () => ({ id: null, name: '', use: '', charts: [], main: false });
38
+ /* A new chart starts from the measure PMOS ranks first in What stands out, else the first measure with a series. */
39
+ function chartFrom(id) {
40
+ const top = (P.M.findings || [])[0], byKey = top && top.chart ? (P.M.charts || []).find((c) => c.key === top.chart) : null;
41
+ const b = (id && baseOf(id)) || byKey || (P.M.charts || [])[0];
42
+ return b ? { id: null, measure: b.id, title: b.title.slice(0, 60), question: '', form: 'line', range: null, target: b.target === null ? '' : String(b.target), better: b.dir < 0 ? 'lower' : 'higher', note: '', addTo: '', ft: false } : null;
43
+ }
44
+ const chartSaved = (C) => ({ id: C.id, measure: C.measure, title: C.title, question: C.question || '', form: C.form || 'line', range: C.range || null, target: C.target === null ? '' : String(C.target), better: C.better || 'higher', note: C.note || '', addTo: '', ft: true });
45
+ const tgOf = (c) => (c.target === '' || c.target === '-' || Number.isNaN(+c.target) ? null : +c.target);
46
+ const drawn = (c) => { const b = c && baseOf(c.measure); return b ? P.derive(b, { range: c.range, target: tgOf(c), form: c.form, better: c.better, title: c.title, note: c.note }) : null; };
47
+ function suggestForm(q) {
48
+ q = q.toLowerCase();
49
+ return /\b(on target|on track|reach|hit|meet|how far|goal|limit|close to)\b/.test(q) ? 'meter' : /\b(now|current|today|latest|how much|what is|status)\b/.test(q) ? 'number' : /\b(compare|each|per|versus|against|which)\b/.test(q) ? 'bars' : 'line';
50
+ }
51
+ const formWhy = (c) => ({ line: 'A line, because it shows how the measure moves over time.', bars: 'Bars, because they set one reading against another. They start at zero, so their length is honest.', number: 'A number tile, because one current value is the point. The small line gives the shape.', meter: 'A meter, because the question is how far the measure is from its target.' })[c.form];
29
52
 
30
53
  /* ── the canvas ── */
31
54
  const chip = (k, l, v) => `<button type="button" class="suc${st.pop === k ? ' on' : ''}${v === 'Not set' ? ' req' : ''}" data-st="chip|${k}" aria-expanded="${st.pop === k}"><em>${esc(l)}</em><b>${esc(v)}</b></button>`;
55
+ const rangeTxt = (c) => { const b = baseOf(c.measure), n = b ? b.pts.length : 0; return c.range && c.range < n ? 'Last ' + c.range + ' readings' : 'All ' + plural(n, 'reading', 'readings'); };
32
56
  function briefHtml() {
57
+ if (st.mode === 'chart') {
58
+ const c = st.c; if (!c) return '';
59
+ const more = st.more ? chip('title', 'Title', c.title || 'Not set') + chip('better', 'Better when', c.better === 'lower' ? 'Lower' : 'Higher') + chip('note', 'Note', c.note || 'None')
60
+ + chip('addTo', 'Add to', c.addTo ? (savedDash().find((x) => x.id === c.addTo) || { name: 'No dashboard' }).name : 'No dashboard') : '';
61
+ return `<div class="stbr" role="group" aria-label="Brief">${chip('q', 'Question', c.question || 'Not set')}${chip('measure', 'Measure', titleOf(c.measure))}${chip('form', 'Form', FORMN[c.form])}${chip('range', 'Range', rangeTxt(c))}${chip('target', 'Target', tgOf(c) === null ? 'None' : String(tgOf(c)))}`
62
+ + `<button type="button" class="suc stmore" data-st="more" aria-expanded="${st.more}"><em>${st.more ? 'Fewer' : 'More'}</em><b>${st.more ? 'Title, better when, note' : 'Title, note, add to'}</b></button>${more}</div>`;
63
+ }
33
64
  const d = st.d;
34
65
  return `<div class="stbr" role="group" aria-label="Brief">${chip('name', 'Name', d.name || 'Not set')}${chip('use', 'Purpose', d.use || 'Not set')}${chip('charts', 'Charts', String(d.charts.length))}${chip('main', 'Main dashboard', d.main ? 'Yes' : 'No')}</div>`;
35
66
  }
36
67
  const opt = (act, l, sub, on) => `<button type="button" class="sto" data-st="${act}" aria-pressed="${!!on}"><b>${esc(l)}</b>${sub ? `<small>${esc(sub)}</small>` : ''}</button>`;
37
- const field = (f, v, ph, max) => `<input class="sti" id="stI" data-stf="${f}" value="${esc(v)}" placeholder="${esc(ph)}" maxlength="${max}" aria-label="${esc(ph)}" autocomplete="off">`;
68
+ const field = (f, v, ph, max, mode) => `<input class="sti" id="stI" data-stf="${f}" value="${esc(v)}" placeholder="${esc(ph)}" maxlength="${max}" aria-label="${esc(ph)}" autocomplete="off"${mode ? ` inputmode="${mode}"` : ''}>`;
69
+ function chartTray(p) {
70
+ const c = st.c, b = baseOf(c.measure), n = b ? b.pts.length : 0, sg = suggestForm(c.question || '');
71
+ if (p === 'q') return field('question', c.question, 'For example: Are new partners activating?', 100) + '<p class="note">Write the question the chart answers. The form follows from it.</p>';
72
+ if (p === 'measure') return `<div class="sol">${(P.M.charts || []).map((m) => opt('set|measure|' + m.id, m.title, m.sub, c.measure === m.id)).join('')}</div>` + (measures().some((m) => !m.charted) ? '<p class="note">A measure with fewer than two readings has no series, so it cannot be charted yet.</p>' : '');
73
+ if (p === 'form') return `<div class="sol">${Object.keys(FORMN).map((f) => opt('set|form|' + f, FORMN[f] + (f === sg && c.question ? ' · suggested' : ''), FORMD[f], c.form === f)).join('')}</div>`;
74
+ if (p === 'range') return `<div class="sol">${opt('set|range|', 'All ' + plural(n, 'reading', 'readings'), 'Every reading the record holds', !c.range || c.range >= n)}${[3, 4, 6, 8, 12].filter((k) => k < n).map((k) => opt('set|range|' + k, 'Last ' + k + ' readings', '', c.range === k)).join('')}</div><p class="note">The range counts readings, because KR metric readings are not taken every week.</p>`;
75
+ if (p === 'target') return field('target', c.target, 'A number, or leave empty for none', 12, 'decimal') + `<div class="sor"><button type="button" class="dmcta alt" data-st="set|target|">No target</button>${b && b.target !== null ? `<button type="button" class="dmcta alt" data-st="set|target|${b.target}">Use the record's own (${esc(String(b.target))})</button>` : ''}</div>`;
76
+ if (p === 'title') return field('title', c.title, 'The name on the chart', 60);
77
+ if (p === 'better') return `<div class="sol">${opt('set|better|higher', 'Higher', 'Above the target is good', c.better !== 'lower')}${opt('set|better|lower', 'Lower', 'Below the target is good', c.better === 'lower')}</div>`;
78
+ if (p === 'note') return field('note', c.note, 'One line under the chart', 200);
79
+ if (p === 'addTo') return `<div class="sol">${opt('set|addTo|', 'No dashboard', 'Keep it under Your charts only', !c.addTo)}${savedDash().map((x) => opt('set|addTo|' + x.id, x.name, plural(x.charts.length, 'chart', 'charts') + (x.charts.includes(c.id) ? ' · it is on it' : ''), c.addTo === x.id)).join('')}</div>`;
80
+ return '';
81
+ }
38
82
  function trayHtml() {
39
- const p = st.pop, d = st.d; if (!p) return '';
83
+ const p = st.pop; if (!p || !draft()) return '';
40
84
  let h = '';
41
- if (p === 'name') h = field('name', d.name, 'For example: Weekly partner review', 60);
42
- else if (p === 'use') h = field('use', d.use, 'What routine is this for?', 200);
43
- else if (p === 'main') h = `<div class="sol">${opt('set|main|1', 'Yes', 'It opens first on this board. One dashboard is main.', d.main)}${opt('set|main|0', 'No', 'Keep it as another dashboard', !d.main)}</div>`;
44
- else if (p === 'charts') {
45
- h = (d.charts.length ? `<ul class="sul">${d.charts.map((id, i) => `<li><span>${esc(titleOf(id))}${chartOf(id) ? '' : '<small>No series yet</small>'}</span><span class="stlc"><button type="button" data-st="mv|${i}|-1" aria-label="Move ${esc(titleOf(id))} up"${i ? '' : ' disabled'}>${UPI}</button><button type="button" data-st="mv|${i}|1" aria-label="Move ${esc(titleOf(id))} down"${i < d.charts.length - 1 ? '' : ' disabled'}>${DNI}</button><button type="button" data-st="rm|${i}" aria-label="Remove ${esc(titleOf(id))}">${XI}</button></span></li>`).join('')}</ul>` : '<p class="note">No charts yet.</p>')
46
- + '<button type="button" class="dmcta alt" data-st="lib">Add from the library</button>';
85
+ if (st.mode === 'chart') h = chartTray(p);
86
+ else {
87
+ const d = st.d;
88
+ if (p === 'name') h = field('name', d.name, 'For example: Weekly partner review', 60);
89
+ else if (p === 'use') h = field('use', d.use, 'What routine is this for?', 200);
90
+ else if (p === 'main') h = `<div class="sol">${opt('set|main|1', 'Yes', 'It opens first on this board. One dashboard is main.', d.main)}${opt('set|main|0', 'No', 'Keep it as another dashboard', !d.main)}</div>`;
91
+ else if (p === 'charts') {
92
+ h = (d.charts.length ? `<ul class="sul">${d.charts.map((id, i) => `<li><span>${esc(titleOf(id))}${chartOf(id) ? '' : '<small>No series yet</small>'}</span><span class="stlc"><button type="button" data-st="mv|${i}|-1" aria-label="Move ${esc(titleOf(id))} up"${i ? '' : ' disabled'}>${UPI}</button><button type="button" data-st="mv|${i}|1" aria-label="Move ${esc(titleOf(id))} down"${i < d.charts.length - 1 ? '' : ' disabled'}>${DNI}</button><button type="button" data-st="rm|${i}" aria-label="Remove ${esc(titleOf(id))}">${XI}</button></span></li>`).join('')}</ul>` : '<p class="note">No charts yet.</p>')
93
+ + '<button type="button" class="dmcta alt" data-st="lib">Add from the library</button>';
94
+ }
47
95
  }
48
96
  return h ? `<div class="sup" role="group" aria-label="Change this">${h}<button type="button" class="lk stdone" data-st="chip|${p}">Done</button></div>` : '';
49
97
  }
@@ -55,21 +103,49 @@ function spark(c) {
55
103
  }
56
104
  function libHtml() {
57
105
  if (!st.lib) return '';
58
- const d = st.d, L = measures(), S = savedDash().filter((x) => x.id !== d.id);
59
- const rows = L.map((m) => { const on = d.charts.includes(m.id), c = chartOf(m.id); return `<button type="button" class="stli" data-st="libc|${esc(m.id)}"${on ? ' disabled' : ''}>${spark(c)}<span><b>${esc(m.title)}</b><small>${esc(c ? c.sub : 'No series yet')}</small></span><em>${on ? 'Added' : 'Add'}</em></button>`; }).join('');
60
- const dl = S.map((x) => `<button type="button" class="stli" data-st="libd|${esc(x.id)}"><span class="stlic">${DSI}</span><span><b>${esc(x.name)}</b><small>${plural(x.charts.length, 'chart', 'charts')}</small></span><em>Add its charts</em></button>`).join('');
106
+ const L = measures(), Y = mineSaved();
107
+ let rows, yours, dl = '';
108
+ if (st.mode === 'chart') {
109
+ const c = st.c;
110
+ rows = L.map((m) => { const b = baseOf(m.id); return `<button type="button" class="stli" data-st="libm|${esc(m.id)}"${b ? '' : ' disabled'}>${spark(b)}<span><b>${esc(m.title)}</b><small>${esc(b ? b.sub : 'No series yet')}</small></span><em>${b ? (c && c.measure === m.id && !c.id ? 'Drawn' : 'Start from this') : 'Not drawn'}</em></button>`; }).join('');
111
+ yours = Y.map((y) => `<button type="button" class="stli" data-st="libs|${esc(y.id)}"${c && c.id === y.id ? ' disabled' : ''}>${spark(chartOf(y.id))}<span><b>${esc(y.title)}</b><small>${esc(FORMN[y.form] + ' · ' + titleOf(y.measure))}</small></span><em>${c && c.id === y.id ? 'Open' : 'Edit'}</em></button>`).join('');
112
+ } else {
113
+ const d = st.d, S = savedDash().filter((x) => x.id !== d.id);
114
+ const row = (id, title, sub, c) => { const on = d.charts.includes(id); return `<button type="button" class="stli" data-st="libc|${esc(id)}"${on ? ' disabled' : ''}>${spark(c)}<span><b>${esc(title)}</b><small>${esc(sub)}</small></span><em>${on ? 'Added' : 'Add'}</em></button>`; };
115
+ rows = L.map((m) => { const c = chartOf(m.id); return row(m.id, m.title, c ? c.sub : 'No series yet', c); }).join('');
116
+ yours = Y.map((y) => row(y.id, y.title, FORMN[y.form] + ' · ' + titleOf(y.measure), chartOf(y.id))).join('');
117
+ dl = S.map((x) => `<button type="button" class="stli" data-st="libd|${esc(x.id)}"><span class="stlic">${DSI}</span><span><b>${esc(x.name)}</b><small>${plural(x.charts.length, 'chart', 'charts')}</small></span><em>Add its charts</em></button>`).join('');
118
+ }
61
119
  return `<div class="stlib" role="region" aria-label="Library of ${esc(P.M.board.name || 'this board')}"><div class="stlh"><b>Library</b><small>${esc(P.M.board.name || '')}</small><button type="button" class="lk" data-st="lib">Close</button></div>`
62
120
  + `<p class="label">Measures · ${L.length}</p>${L.length ? `<div class="stlg">${rows}</div>` : '<p class="note">No KR metric is recorded for this workspace.</p>'}`
63
- + (dl ? `<p class="label">Dashboards · ${S.length}</p><div class="stlg">${dl}</div>` : '') + '</div>';
121
+ + (yours ? `<p class="label">Your charts · ${Y.length}</p><div class="stlg">${yours}</div>` : '')
122
+ + (dl ? `<p class="label">Dashboards · ${savedDash().filter((x) => x.id !== st.d.id).length}</p><div class="stlg">${dl}</div>` : '') + '</div>';
64
123
  }
65
124
  function previewHtml() {
125
+ if (st.mode === 'chart') {
126
+ const c = st.c; if (!c) return '<p class="note">Nothing to draw: no measure of this board has two readings yet.</p>';
127
+ const ch = drawn(c);
128
+ if (!ch) return `<div class="stpvw"><p class="note"><b>${esc(titleOf(c.measure))}</b> has fewer than two readings in this range, so it has no chart.</p></div>`;
129
+ return `<div class="stpvw">${P.tile(ch)}<details class="stvt"><summary>Show the values</summary><div class="vtb">${ch.pts.map((p) => `<div><span>${esc(p.d)}</span><b>${esc(p.txt)}</b></div>`).join('')}</div></details><p class="stsrc">KR metric record · ${esc(titleOf(c.measure))} · ${plural(ch.pts.length, 'reading', 'readings')}</p></div>`;
130
+ }
66
131
  const d = st.d, L = d.charts.map(chartOf).filter(Boolean), gone = d.charts.filter((id) => !chartOf(id));
67
132
  return `<div class="stpvw"><h3 class="ndt">${esc(d.name || 'Untitled dashboard')}${d.main ? '<span class="npin2">Main dashboard</span>' : ''}</h3><p class="mut stuse">${esc(d.use || 'No purpose yet.')}</p>`
68
133
  + (L.length ? `<div class="ngrid">${L.map((c) => `<div class="ntw">${P.tile(c)}</div>`).join('')}</div>` : '<p class="note">No chart is drawn yet. Add a measure with a series.</p>')
69
134
  + (gone.length ? `<p class="label ngl">Not drawn · ${gone.length}</p>${gone.map((id) => `<p class="note stgone"><b>${esc(titleOf(id))}</b> has fewer than two readings, so it has no chart.</p>`).join('')}` : '') + '</div>';
70
135
  }
71
- /* The six checks of the mockup, computed from the draft. A fix is an action the Studio can take in one press. */
136
+ /* The checks of the mockup, computed from the draft. A fix is an action the Studio can take in one press. */
72
137
  function checks() {
138
+ if (st.mode === 'chart') {
139
+ const c = st.c; if (!c) return [];
140
+ const ch = drawn(c), pts = ch ? ch.pts.length : 0, tg = tgOf(c), trendQ = /\b(moved|move|moving|trend|over time|how has|changed|changing)\b/i.test(c.question);
141
+ return [
142
+ { ok: !!c.question.trim(), l: 'It says what it answers', d: c.question.trim() ? '"' + c.question.trim() + '"' : 'There is no question. A chart without one is decoration.', fix: ['Write the question', 'chip|q'] },
143
+ { ok: tg !== null || c.form === 'number', l: c.form === 'meter' ? 'A meter needs a target' : 'A target or limit is shown', d: tg !== null ? 'The target is ' + tg + '.' : 'There is no target, so the chart cannot say whether the measure is on track.', fix: ['Set a target', 'chip|target'] },
144
+ { ok: pts >= 4 || c.form === 'number', l: 'Enough points to read a shape', d: plural(pts, 'reading', 'readings') + ' in this range.', fix: ['Use every reading', 'set|range|'] },
145
+ { ok: !(trendQ && c.form !== 'line'), l: 'The form fits the question', d: trendQ && c.form !== 'line' ? 'The question is about movement. A line shows movement better than ' + FORMN[c.form].toLowerCase() + '.' : 'The form suits the question.', fix: ['Use a line', 'set|form|line'] },
146
+ { ok: true, l: 'One scale', d: 'One measure, one axis. Bars and the meter start at zero.' },
147
+ ];
148
+ }
73
149
  const d = st.d, dup = d.charts.length - new Set(d.charts).size, other = savedDash().some((x) => x.main && x.id !== d.id);
74
150
  return [
75
151
  { ok: !!d.name.trim(), l: 'It has a name', d: d.name.trim() || 'Give it a name.', fix: ['Name it', 'chip|name'] },
@@ -81,21 +157,27 @@ function checks() {
81
157
  ];
82
158
  }
83
159
  function checksHtml() {
84
- const L = checks(), bad = L.filter((x) => !x.ok), n = L.length - bad.length;
160
+ const L = checks(); if (!L.length) return '';
161
+ const bad = L.filter((x) => !x.ok), n = L.length - bad.length;
85
162
  return `<div class="suck${bad.length ? ' bad' : ''}"><button type="button" class="suckb" data-st="ck" aria-expanded="${st.ck}">${bad.length ? WRN : OKI}<b>${n} of ${L.length} checks pass</b>${bad.length && !st.ck ? `<span>${esc(bad[0].d)}</span>` : ''}${CHV}</button>`
86
- + `<div class="mprog stbar" role="progressbar" aria-label="Checks passing" aria-valuemin="0" aria-valuemax="${L.length}" aria-valuenow="${n}" data-n="${n}"><b></b></div>`
163
+ + `<div class="mprog stbar" role="progressbar" aria-label="Checks passing" aria-valuemin="0" aria-valuemax="${L.length}" aria-valuenow="${n}" data-t="${L.length}" data-n="${n}"><b></b></div>`
87
164
  + (st.ck ? `<ul class="sucl">${L.map((x, i) => `<li class="${x.ok ? 'ok' : 'bad'}">${x.ok ? OKI : WRN}<span><b>${esc(x.l)}</b><small>${esc(x.d)}</small></span>${!x.ok && x.fix ? `<button type="button" class="dmcta alt" data-st="fix|${i}">${esc(x.fix[0])}</button>` : ''}</li>`).join('')}</ul>` : '') + '</div>';
88
165
  }
89
166
  function footHtml() {
90
- const saved = !!st.d.id;
91
- return `<div class="stft"><button type="button" class="dmcta alt" data-st="undo"${st.h.length ? '' : ' disabled'}>Undo</button>${saved ? `<button type="button" class="dmcta alt" data-st="del">${st.armed ? 'Press again to remove it' : 'Remove the dashboard'}</button>` : ''}<span class="sp"></span><button type="button" class="dmcta alt" data-st="cancel">Cancel</button><button type="button" class="dmcta" data-st="save"${st.busy ? ' disabled' : ''}>${saved ? 'Save changes' : 'Save the dashboard'}</button></div>`;
167
+ const ch = st.mode === 'chart', d = draft(), saved = !!(d && d.id), what = ch ? 'chart' : 'dashboard';
168
+ return `<div class="stft"><button type="button" class="dmcta alt" data-st="undo"${st.h[st.mode].length ? '' : ' disabled'}>Undo</button>${saved ? `<button type="button" class="dmcta alt" data-st="del">${st.armed ? 'Press again to remove it' : 'Remove the ' + what}</button>` : ''}<span class="sp"></span><button type="button" class="dmcta alt" data-st="cancel">Cancel</button><button type="button" class="dmcta" data-st="save"${st.busy || !d ? ' disabled' : ''}>${saved ? 'Save changes' : 'Save the ' + what}</button></div>`;
92
169
  }
93
- const guide = () => 'A dashboard answers one routine. Give it a purpose and keep it to six charts or fewer.' + (st.d.id ? ' <button type="button" class="lk" data-st="new">Start a new one instead</button>' : '');
170
+ function guide() {
171
+ if (st.mode === 'chart') return st.c ? esc(formWhy(st.c)) + (st.c.id ? ' <button type="button" class="lk" data-st="new">Start a new one instead</button>' : '') : 'No measure of this board has two readings yet, so there is nothing to chart.';
172
+ return 'A dashboard answers one routine. Give it a purpose and keep it to six charts or fewer.' + (st.d.id ? ' <button type="button" class="lk" data-st="new">Start a new one instead</button>' : '');
173
+ }
174
+ const modesHtml = () => `<div class="stmd" role="group" aria-label="What to make">${Object.keys(MODES).map((k) => `<button type="button" data-st="mode|${k}" aria-pressed="${st.mode === k}">${MODES[k]}</button>`).join('')}</div>`;
94
175
  function canvasHtml() {
95
- return `<div class="stu"><div class="stt"><span class="stx"><button type="button" class="lk" data-st="lib" aria-expanded="${st.lib}">Library</button></span></div><p class="stsug" id="stG">${guide()}</p><div id="stBr">${briefHtml()}</div><div id="stTr">${trayHtml()}</div><div id="stLb">${libHtml()}</div><div id="stPv">${previewHtml()}</div><div id="stCk">${checksHtml()}</div><p class="note stmsg" id="stMsg" role="status"></p><div id="stFt">${footHtml()}</div></div>`;
176
+ return `<div class="stu"><div class="stt"><span id="stMd">${modesHtml()}</span><span class="stx"><button type="button" class="lk" data-st="lib" aria-expanded="${st.lib}">Library</button></span></div><p class="stsug" id="stG">${guide()}</p><div id="stBr">${briefHtml()}</div><div id="stTr">${trayHtml()}</div><div id="stLb">${libHtml()}</div><div id="stPv">${previewHtml()}</div><div id="stCk">${checksHtml()}</div><p class="note stmsg" id="stMsg" role="status"></p><div id="stFt">${footHtml()}</div></div>`;
96
177
  }
97
178
  function draw(parts) {
98
179
  const all = !parts, set = (id, h) => { const e = $('#' + id); if (e) e.innerHTML = h; };
180
+ if (all) set('stMd', modesHtml());
99
181
  if (all || parts.includes('g')) set('stG', guide());
100
182
  if (all || parts.includes('br')) set('stBr', briefHtml());
101
183
  if (all || parts.includes('tr')) set('stTr', trayHtml());
@@ -105,21 +187,39 @@ function draw(parts) {
105
187
  if (all || parts.includes('ft')) set('stFt', footHtml());
106
188
  const m = $('#stMsg'); if (m) m.textContent = st.msg;
107
189
  const l = $('.stu [data-st="lib"]'); if (l) l.setAttribute('aria-expanded', st.lib);
190
+ if (all) { const i = $('#stIn'); if (i) { i.placeholder = 'Say what to change'; i.setAttribute('aria-label', 'Say what to change in the ' + (st.mode === 'chart' ? 'chart' : 'dashboard')); } const h = $('#stHelp'); if (h) h.textContent = help() + ' Nothing is saved until you press Save.'; }
108
191
  }
109
192
 
110
193
  /* ── doing things ── */
194
+ function setChart(f, v) {
195
+ const c = st.c;
196
+ if (f === 'measure') { const b = baseOf(v); if (!b) return; c.measure = v; if (!c.id || !c.title) c.title = b.title.slice(0, 60); c.target = b.target === null ? '' : String(b.target); c.better = b.dir < 0 ? 'lower' : 'higher'; c.range = null; }
197
+ else if (f === 'form') { c.form = v; c.ft = true; }
198
+ else if (f === 'range') c.range = v ? +v : null;
199
+ else if (f === 'target') c.target = v;
200
+ else if (f === 'better') c.better = v === 'lower' ? 'lower' : 'higher';
201
+ else if (f === 'addTo') c.addTo = v;
202
+ }
111
203
  function act(a) {
112
204
  const [k, x, y] = a; st.msg = '';
113
205
  if (k !== 'del') st.armed = false;
206
+ if (k === 'mode') { if (st.mode !== x) { st.mode = x; st.pop = null; st.ck = false; draw(); } return; }
114
207
  if (k === 'chip') { st.pop = st.pop === x ? null : x; draw(['br', 'tr', 'ft']); const i = $('#stI'); if (i) { i.focus(); try { i.setSelectionRange(i.value.length, i.value.length); } catch { /* no caret */ } } return; }
208
+ if (k === 'more') { st.more = !st.more; if (!st.more && /^(title|better|note|addTo)$/.test(st.pop || '')) st.pop = null; draw(['br', 'tr']); return; }
115
209
  if (k === 'lib') { st.lib = !st.lib; draw(['lb', 'tr', 'ft']); return; }
116
210
  if (k === 'ck') { st.ck = !st.ck; draw(['ck']); return; }
117
211
  if (k === 'fix') { const f = checks()[+x]; if (f && f.fix) act(f.fix[1].split('|')); return; }
118
212
  if (k === 'undo') { if (undo()) { st.pop = null; draw(); } return; }
119
213
  if (k === 'cancel') { closeDlg(); return; }
120
- if (k === 'save') { save(); return; }
121
- if (k === 'del') { remove(); return; }
122
- if (k === 'new') { snap(); st.d = blank(); st.pop = null; draw(); return; }
214
+ if (k === 'save') { if (st.mode === 'chart') saveChart(); else save(); return; }
215
+ if (k === 'del') { if (st.mode === 'chart') removeChart(); else remove(); return; }
216
+ if (k === 'new') { snap(); if (st.mode === 'chart') st.c = chartFrom(st.c && st.c.measure); else st.d = blank(); st.pop = null; draw(); return; }
217
+ if (st.mode === 'chart') {
218
+ if (k === 'set') { snap(); setChart(x, y || ''); st.pop = null; draw(); return; }
219
+ if (k === 'libm') { snap(); st.c = chartFrom(x); st.pop = null; draw(); return; }
220
+ if (k === 'libs') { const C = mineSaved().find((q) => q.id === x); if (!C) return; snap(); st.c = chartSaved(C); st.pop = null; draw(); }
221
+ return;
222
+ }
123
223
  if (k === 'set' && x === 'main') { snap(); st.d.main = y === '1'; st.pop = null; draw(); return; }
124
224
  if (k === 'dedup') { snap(); st.d.charts = st.d.charts.filter((id, i) => st.d.charts.indexOf(id) === i); draw(); return; }
125
225
  if (k === 'mv') { const i = +x, j = i + +y, c = st.d.charts; if (j < 0 || j >= c.length) return; snap(); [c[i], c[j]] = [c[j], c[i]]; draw(); const b = $(`#stTr [data-st="mv|${j}|${y}"]`) || $(`#stTr [data-st="mv|${j}|${-y}"]`); if (b) b.focus(); return; }
@@ -130,8 +230,13 @@ function act(a) {
130
230
  let typed = false; // one undo step per text field edit, not per key
131
231
  function onInput(e) {
132
232
  const f = e.target.dataset && e.target.dataset.stf; if (!f) return;
233
+ const o = draft(); if (!o) return;
234
+ let v = e.target.value;
235
+ if (f === 'target') { const t = v.replace(/[^0-9.-]/g, ''); if (t !== v) { v = t; e.target.value = t; } }
133
236
  if (!typed) { snap(); typed = true; }
134
- st.d[f] = e.target.value; st.msg = ''; draw(['g', 'br', 'pv', 'ck', 'ft']);
237
+ o[f] = v; st.msg = '';
238
+ if (st.mode === 'chart' && f === 'question' && !o.ft) o.form = suggestForm(v);
239
+ draw(['g', 'br', 'pv', 'ck', 'ft']);
135
240
  }
136
241
  async function save() {
137
242
  const d = st.d, name = d.name.trim(), use = d.use.trim();
@@ -151,14 +256,43 @@ async function remove() {
151
256
  if (!res || res.ok !== true) { st.armed = false; st.msg = (res && res.error) || 'The dashboard could not be removed.'; draw(['ft']); return; }
152
257
  closeDlg(); toast('Dashboard removed. The line is saved in the workspace\'s state folder.'); P.done(null);
153
258
  }
259
+ async function saveChart() {
260
+ const c = st.c, title = c.title.trim(), tg = tgOf(c);
261
+ if (!title) { st.msg = 'Give the chart a name.'; draw(['ft']); return; }
262
+ if (c.target !== '' && tg === null) { st.msg = 'The target must be a number, or none.'; draw(['ft']); return; }
263
+ if (c.form === 'meter' && tg === null) { st.msg = 'A meter needs a target. Set one, or pick another form.'; draw(['ft']); return; }
264
+ st.busy = true; st.msg = 'Saving.'; draw(['ft']);
265
+ const res = await P.saveChart({ id: c.id || undefined, measure: c.measure, title, question: c.question.trim(), form: c.form, range: c.range, target: tg, better: c.better, note: c.note.trim() });
266
+ if (!res || res.ok !== true) { st.busy = false; st.msg = (res && res.error) || 'The chart could not be saved.'; draw(['ft']); return; }
267
+ const id = res.chart ? res.chart.id : c.id, D = c.addTo ? savedDash().find((x) => x.id === c.addTo) : null;
268
+ let to = '';
269
+ if (D && !D.charts.includes(id)) {
270
+ const r2 = await P.save({ id: D.id, name: D.name, purpose: D.purpose, charts: D.charts.concat([id]), main: D.main });
271
+ if (!r2 || r2.ok !== true) { st.busy = false; c.id = id; st.msg = 'The chart is saved, but it was not added to ' + D.name + ': ' + ((r2 && r2.error) || 'the dashboard could not be saved.'); draw(); return; }
272
+ to = ' and added to ' + D.name;
273
+ }
274
+ st.busy = false;
275
+ closeDlg(); toast('Chart "' + title + '" saved' + to + ' in the workspace\'s state folder.'); P.done(D ? D.id : null);
276
+ }
277
+ async function removeChart() {
278
+ if (!st.armed) { st.armed = true; st.msg = 'Removing takes the chart off this board. A dashboard that holds it lists it as removed. The measure and its record stay.'; draw(['ft']); return; }
279
+ st.busy = true; draw(['ft']);
280
+ const res = await P.saveChart({ id: st.c.id, remove: true });
281
+ st.busy = false;
282
+ if (!res || res.ok !== true) { st.armed = false; st.msg = (res && res.error) || 'The chart could not be removed.'; draw(['ft']); return; }
283
+ closeDlg(); toast('Chart removed. The line is saved in the workspace\'s state folder.'); P.done(null);
284
+ }
154
285
 
155
286
  /* ── the conversation: the phrases the Studio understands. A turn changes the draft only; it writes nothing and starts no agent. ── */
156
287
  const HELP = 'I understand: add or remove a measure by its name, move a measure up, down or first, call it something, it is for something, make it the main dashboard (or not), undo, and start a new one.';
288
+ const HELPC = 'I understand: a measure by its name, a form (line, bars, number, meter), the last N readings or all of them, target N or no target, lower or higher is better, call it something, note something, add it to a dashboard, a question, undo, and why.';
289
+ const help = () => (st.mode === 'chart' ? HELPC : HELP);
157
290
  const clean = (s) => s.trim().replace(/^["']|["']$/g, '').replace(/[.\s]+$/, '').trim();
158
- function hits(low) { return measures().map((m) => ({ m, i: low.indexOf(m.title.toLowerCase()) })).filter((x) => x.i >= 0 && x.m.title).sort((a, b) => a.i - b.i || b.m.title.length - a.m.title.length); }
291
+ function hits(low, L) { return (L || measures()).map((m) => ({ m, i: low.indexOf(m.title.toLowerCase()) })).filter((x) => x.i >= 0 && x.m.title).sort((a, b) => a.i - b.i || b.m.title.length - a.m.title.length); }
159
292
  function command(text) {
160
293
  const t = text.trim(), low = t.toLowerCase(), d = st.d, said = [];
161
294
  if (/^undo\b/.test(low)) return undo() ? (st.pop = null, 'Done: one step undone.') : 'I changed nothing. There is nothing to undo.';
295
+ if (st.mode === 'chart') return chartCommand(t, low);
162
296
  if (/\b(start (a )?new|new dashboard|start over)\b/.test(low)) { snap(); st.d = blank(); return 'Done: a new, empty dashboard. Name it and say what it is for.'; }
163
297
  const before = JSON.stringify(d); snap();
164
298
  const nm = t.match(/(?:call it|name it|rename it to|rename it|called|named)\s+(.+?)(?=,|;|\s+and\s+(?:it|make|add|remove|for)\b|$)/i);
@@ -167,7 +301,7 @@ function command(text) {
167
301
  if (us && clean(us[1])) { d.use = clean(us[1]).slice(0, 200); said.push('the purpose is "' + d.use + '"'); }
168
302
  if (/\b(not|no longer|don't make it|do not make it)\b[^.]*\bmain\b/.test(low)) { if (d.main) { d.main = false; said.push('it is not the main dashboard'); } }
169
303
  else if (/\bmain\b/.test(low) && /\b(make|set|mark|as)\b/.test(low)) { if (!d.main) { d.main = true; said.push('it is the main dashboard'); } }
170
- const H = hits(low), verbs = H.reduce((v, x) => v.split(x.m.title.toLowerCase()).join(' '), low); // the verbs, read with the measures' names taken out ("Time to first call" is not "first")
304
+ const H = hits(low, measures().concat(mineSaved())), verbs = H.reduce((v, x) => v.split(x.m.title.toLowerCase()).join(' '), low); // the verbs, read with the names taken out ("Time to first call" is not "first")
171
305
  if (H.length && /\b(remove|take off|take out|drop|delete|without)\b/.test(verbs)) {
172
306
  H.forEach(({ m }) => { const i = d.charts.indexOf(m.id); if (i >= 0) { d.charts.splice(i, 1); said.push('removed ' + m.title); } });
173
307
  } else if (H.length && /\b(move|put|first|top|up|down|last|bottom)\b/.test(verbs)) {
@@ -179,10 +313,51 @@ function command(text) {
179
313
  } else if (H.length && /\b(add|include|show|put in|with)\b/.test(verbs)) {
180
314
  H.forEach(({ m }) => { if (!d.charts.includes(m.id)) { d.charts.push(m.id); said.push('added ' + m.title + (chartOf(m.id) ? '' : ' (it has no series yet, so it is listed, not drawn)')); } });
181
315
  }
182
- if (JSON.stringify(d) === before) { st.h.pop(); return 'I changed nothing. ' + (H.length || !/\b(add|remove)\b/.test(low) ? HELP : 'No measure of this board has that name. Open the Library to see them.'); }
316
+ if (JSON.stringify(d) === before) { st.h.dash.pop(); return 'I changed nothing. ' + (H.length || !/\b(add|remove)\b/.test(low) ? HELP : 'No measure of this board has that name. Open the Library to see them.'); }
183
317
  st.pop = null;
184
318
  return 'Done: ' + said.join(', ') + '.';
185
319
  }
320
+ function chartCommand(t, low) {
321
+ const c = st.c; if (!c) return 'No measure of this board has two readings yet, so I have nothing to chart.';
322
+ if (/^\s*why\b/.test(low)) return formWhy(c);
323
+ if (/\b(start (a )?new|new chart|start over)\b/.test(low)) { snap(); st.c = chartFrom(c.measure); return 'Done: a new chart of ' + titleOf(st.c.measure) + '. Say what it should answer.'; }
324
+ const before = JSON.stringify(c), said = []; snap();
325
+ const NAMING = /(?:call it|name it|title it|rename it to|called|named)\s+["“]?(.+?)(?=["”]|,|;|\.\s|\.$|\s+and\s|\s+with\s|\s+target|$)/i;
326
+ const nm = t.match(NAMING); if (nm && clean(nm[1])) { c.title = clean(nm[1]).slice(0, 60); said.push('named it "' + c.title + '"'); }
327
+ const nt = t.match(/\bnote[:\s]+(.+)$/i); if (nt && clean(nt[1])) { c.note = clean(nt[1]).slice(0, 200); said.push('note set'); }
328
+ const qq = t.match(/(?:question|it answers|answers)\s*[:-]\s*(.+)$/i);
329
+ const rest = low.replace(new RegExp(NAMING.source, 'gi'), ' ').replace(/\bnote[:\s]+.+$/i, ' ');
330
+ const H = hits(rest, (P.M.charts || []).map((b) => ({ id: b.id, title: b.title })));
331
+ if (H.length && H[0].m.id !== c.measure) { setChart('measure', H[0].m.id); said.push('measure: ' + H[0].m.title); }
332
+ const verbs = H.reduce((v, x) => v.split(x.m.title.toLowerCase()).join(' '), rest);
333
+ const lf = verbs.replace(/\b(no|not|without|don't want|do not want|instead of|rather than)\s+(?:a\s+|an\s+|the\s+)?(?:bars?|columns?|line|trend|number|tile|meter|gauge|progress|pie)(?:\s+chart)?/g, ' ');
334
+ let fm = null;
335
+ if (/\b(pie|donut|doughnut)\b/.test(lf)) said.push('no pie: a pie cannot show a trend or a target');
336
+ else if (/\bbars?\b|\bcolumns?\b/.test(lf)) fm = 'bars';
337
+ else if (/\b(meter|gauge|progress|bullet)\b/.test(lf)) fm = 'meter';
338
+ else if (/\b(big number|number|stat tile|kpi|tile)\b/.test(lf)) fm = 'number';
339
+ else if (/\bline\b|\btrend\b/.test(lf)) fm = 'line';
340
+ if (fm && fm !== c.form) { setChart('form', fm); said.push('form: ' + FORMN[fm].toLowerCase()); }
341
+ const rg = verbs.match(/\blast\s+(\d+)\s*(readings?|points?|values?|weeks?|days?|months?)?/);
342
+ const n = (baseOf(c.measure) || { pts: [] }).pts.length;
343
+ if (rg) {
344
+ const k = +rg[1], u = rg[2] || 'readings';
345
+ if (k < 2) said.push('range not changed: a range needs at least two readings');
346
+ else if (k >= n) { setChart('range', ''); said.push('range: all ' + n + ' readings (only ' + n + ' are recorded)'); }
347
+ else { setChart('range', String(k)); said.push('range: last ' + k + ' readings' + (/^(week|day|month)/.test(u) ? ' (readings are not taken every ' + u.replace(/s$/, '') + ', so I count readings)' : '')); }
348
+ } else if (/\b(all (the )?(readings|data|points)|whole (period|range|series)|every reading)\b/.test(verbs) && c.range) { setChart('range', ''); said.push('range: all readings'); }
349
+ if (/\bno target\b|\bwithout (a )?target\b/.test(verbs)) { if (c.target !== '') { setChart('target', ''); said.push('no target'); } }
350
+ else { const tg = verbs.match(/\b(?:target|limit)\s*(?:of|is|at|to|=)?\s*(-?\d+(?:\.\d+)?)/); if (tg) { setChart('target', tg[1]); said.push('target ' + tg[1]); } }
351
+ if (/lower is better|lower better|better when lower|lower the better/.test(verbs)) { setChart('better', 'lower'); said.push('lower is better'); }
352
+ else if (/higher is better|higher better|better when higher|higher the better/.test(verbs)) { setChart('better', 'higher'); said.push('higher is better'); }
353
+ const dh = verbs.match(/\badd (?:it )?to\s+(?:the\s+)?(.+?)(?:\s+dashboard)?(?=[,;.]|$)/);
354
+ if (dh) { const D = savedDash().find((x) => x.name.toLowerCase() === clean(dh[1]).toLowerCase()); if (D) { setChart('addTo', D.id); said.push('it will be added to ' + D.name + ' on Save'); } else said.push('no dashboard of this board is called "' + clean(dh[1]) + '"'); }
355
+ if (qq && clean(qq[1])) { c.question = clean(qq[1]).slice(0, 100); if (!c.ft && !fm) c.form = suggestForm(c.question); said.push('question set'); }
356
+ else if (/\?\s*$/.test(t) && t.split(/\s+/).length >= 3) { c.question = t.slice(0, 100); if (!c.ft && !fm) c.form = suggestForm(t); said.push('question set'); }
357
+ if (JSON.stringify(c) === before) { st.h.chart.pop(); return said.length ? 'I changed nothing: ' + said.join('; ') + '.' : 'I changed nothing. ' + HELPC; }
358
+ st.pop = null;
359
+ return 'Done: ' + said.join('; ') + '. ' + formWhy(c);
360
+ }
186
361
  function onSay(e) {
187
362
  e.preventDefault(); e.stopPropagation();
188
363
  const inp = $('#stIn'), text = inp.value.trim(); if (!text) return;
@@ -194,15 +369,19 @@ function onSay(e) {
194
369
  /* ── opening ── */
195
370
  export function openStudio(p) {
196
371
  P = p; typed = false;
197
- const D = p.D;
198
- st = { d: D ? { id: D.id, name: D.name, use: D.purpose || '', charts: D.charts.slice(), main: !!D.main } : blank(), h: [], pop: null, lib: !D, ck: false, msg: '', armed: false, busy: false };
372
+ const D = p.D || null, C = p.C || null, mode = p.mode === 'chart' ? 'chart' : 'dash';
373
+ st = { mode, d: D ? { id: D.id, name: D.name, use: D.purpose || '', charts: D.charts.slice(), main: !!D.main } : blank(), c: C ? chartSaved(C) : chartFrom(null), h: { dash: [], chart: [] }, pop: null, more: false, lib: mode === 'dash' && !D, ck: false, msg: '', armed: false, busy: false };
199
374
  const board = p.M.board.name || 'this board';
200
- const say = D ? 'This is "' + D.name + '". Tell me what to change: measures to add or remove, a new purpose, or make it the main dashboard. Nothing is saved until you press Save.'
201
- : 'Name the dashboard and say what it is for. Then add measures from the library, or tell me which. Nothing is saved until you press Save.';
202
- openDlg({ eye: 'Insight Studio · ' + board, title: 'Insight Studio', sub: 'Make a dashboard from ' + board + '. Say it, or use the brief.', stream: turnA(ptx(say)), noteKey: null, pane: canvasHtml(), label: 'Dashboard' });
375
+ const say = mode === 'chart'
376
+ ? (C ? 'This is "' + C.title + '". Tell me what to change: the form, the range, the target, or a new question. Nothing is saved until you press Save.'
377
+ : st.c ? 'I started from ' + titleOf(st.c.measure) + '. Tell me what the chart should answer, or pick another measure. I choose the form from the question and say why. Nothing is saved until you press Save.'
378
+ : 'No measure of this board has two readings yet, so there is nothing to chart.')
379
+ : D ? 'This is "' + D.name + '". Tell me what to change: measures to add or remove, a new purpose, or make it the main dashboard. Nothing is saved until you press Save.'
380
+ : 'Name the dashboard and say what it is for. Then add measures from the library, or tell me which. Nothing is saved until you press Save.';
381
+ openDlg({ eye: 'Insight Studio · ' + board, title: 'Insight Studio', sub: 'Make a chart or a dashboard from ' + board + '. Say it, or use the brief.', stream: turnA(ptx(say)), noteKey: null, pane: canvasHtml(), label: 'Insight Studio' });
203
382
  $('#dlg').classList.add('stud');
204
383
  $('#askF').hidden = true; const an = $('#askNote'); if (an) an.hidden = true;
205
- $('#dBody').insertAdjacentHTML('beforeend', `<form class="askbar" id="stF"><input id="stIn" placeholder="Say what to change" maxlength="400" autocomplete="off" aria-label="Say what to change in the dashboard"><button type="submit" aria-label="Send" title="Send">${ICO('<path d="M5 12h14M13 6l6 6-6 6"/>')}</button></form><p class="fine2">${esc(HELP)} Nothing is saved until you press Save.</p>`);
384
+ $('#dBody').insertAdjacentHTML('beforeend', `<form class="askbar" id="stF"><input id="stIn" placeholder="Say what to change" maxlength="400" autocomplete="off" aria-label="Say what to change"><button type="submit" aria-label="Send" title="Send">${ICO('<path d="M5 12h14M13 6l6 6-6 6"/>')}</button></form><p class="fine2" id="stHelp"></p>`);
206
385
  $('#stF').onsubmit = onSay;
207
386
  if (innerWidth >= 1000) setFull(true);
208
387
  draw();
@@ -897,6 +897,37 @@ a.round{color:inherit;text-decoration:none}
897
897
  .stft .sp{flex:1}
898
898
  .stft .dmcta{height:44px}
899
899
  @media (max-width:700px){.sol{grid-template-columns:minmax(0,1fr)}.stli{grid-template-columns:72px minmax(0,1fr)}.stli .spk,.stlic{width:72px}.stli em{grid-column:2}.stt{gap:8px}.sucl li{grid-template-columns:18px minmax(0,1fr)}.sucl li .dmcta{grid-column:2;justify-self:start}}
900
+ /* ── Insight Studio, Chart mode (initiative premium-studio-chart): the mode switch, More, and the four chart forms the page and the Studio share ── */
901
+ .stt{justify-content:space-between}
902
+ .stmd{display:inline-flex;gap:4px;padding:4px;border-radius:999px;background:var(--well)}
903
+ .stmd button{min-height:44px;padding:0 16px;border-radius:999px;font-size:13.5px;font-weight:600;color:var(--ink-2)}
904
+ .stmd button[aria-pressed="true"]{background:var(--card-solid);color:var(--ink);box-shadow:0 1px 2px color-mix(in oklab,var(--ink) 18%,transparent)}
905
+ .stmd button:focus-visible{outline:2px solid var(--ember);outline-offset:1px}
906
+ .suc.stmore{background:transparent;box-shadow:inset 0 0 0 1px var(--hair);border-style:dashed}
907
+ .sor{display:flex;gap:8px;flex-wrap:wrap}.sor .dmcta{height:44px}
908
+ .stbar[data-t="5"][data-n="1"] b{width:20%}.stbar[data-t="5"][data-n="2"] b{width:40%}.stbar[data-t="5"][data-n="3"] b{width:60%}.stbar[data-t="5"][data-n="4"] b{width:80%}.stbar[data-t="5"][data-n="5"] b{width:100%}
909
+ .stu{grid-template-columns:minmax(0,1fr)}
910
+ .stpvw>.mt1{grid-template-columns:minmax(0,1fr)}
911
+ .stvt{margin-top:8px;font-size:13px}.stvt summary{cursor:pointer;color:var(--ink-2);min-height:44px;display:flex;align-items:center}
912
+ .stsrc{margin:8px 0 0;font-size:12px;color:var(--ink-3)}
913
+ .mfm .mval{font-size:28px}
914
+ .mfm .mhero{font-size:44px;line-height:1;letter-spacing:-.03em}
915
+ .mfm .nspk{width:100%;height:auto;display:block;margin-top:8px;overflow:visible}
916
+ .mfm .nspk path{fill:none;stroke:var(--ink-2);stroke-width:1.6;stroke-linecap:round;stroke-linejoin:round;vector-effect:non-scaling-stroke}
917
+ .bplot{position:relative;display:flex;align-items:stretch;gap:2px;height:120px;margin-top:10px;border-bottom:1px solid var(--hair)}
918
+ .bw{flex:1 1 0;display:flex;flex-direction:column;justify-content:flex-end;align-items:center;min-width:0;position:relative}
919
+ .bw i{display:block;width:min(24px,64%);border-radius:4px 4px 0 0}
920
+ .bw i.bg{background:color-mix(in oklab,var(--ink) 20%,transparent)}
921
+ .bw i.bk{background:var(--ink)}
922
+ .bw .bl{font-size:11px!important;font-weight:650;margin-bottom:3px;white-space:nowrap;letter-spacing:0}
923
+ .btg{position:absolute;left:0;right:0;border-top:1px dashed var(--ink-3);height:0;pointer-events:none}
924
+ .mtrk{position:relative;height:12px;border-radius:999px;background:color-mix(in oklab,var(--ink) 10%,transparent);margin:16px 0 8px}
925
+ .mfil{position:absolute;inset:0 auto 0 0;border-radius:999px;background:var(--ink)}
926
+ .mfil.ok{background:var(--ok)}.mfil.warn{background:var(--ember)}
927
+ .mtgt{position:absolute;top:-5px;bottom:-5px;width:2px;background:var(--ink);border-radius:2px}
928
+ .mnote{margin:6px 0 0 4px;font-size:12.5px;color:var(--ink-2)}
929
+ .mt1 .mwhy{font-size:12px;color:var(--ink-3);margin-top:4px}
930
+ .ntf .lk+.lk{margin-left:4px}
900
931
  /* ── initiative page (initiative briefing-premium-initiative) ── */
901
932
  .ckr.current i{background:var(--ember)}
902
933
  .ckr.done i{background:var(--ok)}
@@ -0,0 +1,13 @@
1
+ {
2
+ "_comment": "Initiative premium-studio-chart: the Insight Studio's chart store and save route, the Insights model's saved charts, and the Studio's Chart mode against the real server on a scratch repository.",
3
+ "modules": [
4
+ "premium-charts.test.js"
5
+ ],
6
+ "seconds": {
7
+ "premium-charts.test.js": 5,
8
+ "premium-studio-chart-test.js": 120
9
+ },
10
+ "panels": [
11
+ "premium-studio-chart-test.js"
12
+ ]
13
+ }