@hikae/ledger-core 0.4.0 → 0.4.2
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/dashboard.d.ts +23 -0
- package/dashboard.js +367 -0
- package/package.json +8 -2
package/dashboard.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface DashboardGraph {
|
|
2
|
+
id: string;
|
|
3
|
+
scope: string;
|
|
4
|
+
title: string;
|
|
5
|
+
width: string;
|
|
6
|
+
}
|
|
7
|
+
export function graphLayout(scopes: string[], layout?: {id:string, width?:string, hidden?:boolean}[]): DashboardGraph[];
|
|
8
|
+
export function renderDashboard(options: {
|
|
9
|
+
graphs: (DashboardGraph & {panel: HTMLElement})[];
|
|
10
|
+
cards: readonly object[];
|
|
11
|
+
loaded: boolean;
|
|
12
|
+
data: unknown;
|
|
13
|
+
failed: boolean;
|
|
14
|
+
issueDate: HTMLSelectElement;
|
|
15
|
+
issueUnit: HTMLSelectElement;
|
|
16
|
+
tableArea: HTMLElement;
|
|
17
|
+
status: HTMLElement;
|
|
18
|
+
retry: HTMLElement;
|
|
19
|
+
}): void;
|
|
20
|
+
|
|
21
|
+
export function stageAt(card: object, at: Date): string | null;
|
|
22
|
+
export function ledgerMetrics(cards: readonly object[], periods: {start:Date,end:Date,label:string}[]): {open:number,stage:Record<string,number>}[];
|
|
23
|
+
export function mountDashboardNavigation(container: HTMLElement): void;
|
package/dashboard.js
ADDED
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
// Graph IDs name trusted renderers. Layout data cannot supply code, URLs or permissions.
|
|
2
|
+
export const bundledPlugins = [
|
|
3
|
+
{scope: 'ledger', graphs: [{id: 'ledger-flow', title: 'cumulative flow', renderer: 'cumulative', width: 'full'}]},
|
|
4
|
+
{scope: 'issues', graphs: [{
|
|
5
|
+
id: 'issue-counts', title: 'Issue 件数',
|
|
6
|
+
series: [
|
|
7
|
+
{label: '流入(新規・再open)', color: '--blue', average: true, value: row =>
|
|
8
|
+
row.created == null || row.reopened == null ? null : row.created + row.reopened},
|
|
9
|
+
{label: '実close', color: '--green', average: true, value: row => row.closed},
|
|
10
|
+
],
|
|
11
|
+
}]},
|
|
12
|
+
...['5h', '7d'].map(window => ({scope: 'quota', graphs: [{
|
|
13
|
+
id: 'quota-' + window, optional: window === '5h', window, title: window === '5h' ? 'アカウント残量(5時間枠)' : 'Quota Weekly',
|
|
14
|
+
}]})),
|
|
15
|
+
{scope: 'issues', columns: [{label: '初回P90(時間)', value: row => row.firstHours?.p90}]},
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
export function dashboardExtensions(scope, plugins = bundledPlugins) {
|
|
19
|
+
const selected = plugins.filter(plugin => plugin.scope === scope);
|
|
20
|
+
return {
|
|
21
|
+
graphs: selected.flatMap(plugin => plugin.graphs ?? []),
|
|
22
|
+
columns: selected.flatMap(plugin => plugin.columns ?? []),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function graphLayout(scopes, layout = [], plugins = bundledPlugins) {
|
|
27
|
+
const available = new Map();
|
|
28
|
+
for (const {scope, graphs = []} of plugins) {
|
|
29
|
+
if (scopes.includes(scope)) for (const graph of graphs) available.set(graph.id, {...graph, scope});
|
|
30
|
+
}
|
|
31
|
+
const panels = [];
|
|
32
|
+
for (const entry of Array.isArray(layout) ? layout : []) {
|
|
33
|
+
const graph = available.get(entry?.id);
|
|
34
|
+
if (!graph) continue;
|
|
35
|
+
available.delete(entry.id);
|
|
36
|
+
if (entry.hidden !== true) panels.push({...graph, width: ['full','half'].includes(entry.width) ? entry.width : graph.width ?? 'half'});
|
|
37
|
+
}
|
|
38
|
+
return panels.concat([...available.values()].filter(graph => !graph.optional).map(graph => ({width: 'half', ...graph})));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function movingAverage(history, value, hourly) {
|
|
42
|
+
const size = hourly ? 24 : 7;
|
|
43
|
+
const interval = hourly ? 3600000 : 86400000;
|
|
44
|
+
const averages = new Map();
|
|
45
|
+
let sum = 0, count = 0;
|
|
46
|
+
for (const [index, row] of history.entries()) {
|
|
47
|
+
const sample = value(row);
|
|
48
|
+
if (!Number.isFinite(sample) || index && row.start - history[index - 1].start !== interval) {
|
|
49
|
+
sum = 0;
|
|
50
|
+
count = 0;
|
|
51
|
+
}
|
|
52
|
+
if (!Number.isFinite(sample)) continue;
|
|
53
|
+
sum += sample;
|
|
54
|
+
if (++count > size) sum -= value(history[index - size]);
|
|
55
|
+
if (count >= size) averages.set(row.start, sum / size);
|
|
56
|
+
}
|
|
57
|
+
return averages;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
var S = [
|
|
61
|
+
['added', '--s1'],
|
|
62
|
+
['approved', '--s2'],
|
|
63
|
+
['merged', '--s3'],
|
|
64
|
+
['done', '--s4'],
|
|
65
|
+
],
|
|
66
|
+
y = [
|
|
67
|
+
['done', '--s4'],
|
|
68
|
+
['merged', '--s3'],
|
|
69
|
+
['approved', '--s2'],
|
|
70
|
+
['added', '--s1'],
|
|
71
|
+
['responded', '--s5'],
|
|
72
|
+
['need_respond', '--s6'],
|
|
73
|
+
],
|
|
74
|
+
U = { day: 30, week: 12 },
|
|
75
|
+
x = e => e.completed_at || (e.status === 'closed' ? e.updated_at : null);
|
|
76
|
+
function G(e, n) {
|
|
77
|
+
let t = o => !!o && new Date(o) < n;
|
|
78
|
+
if (!t(e.added_at)) return null;
|
|
79
|
+
return t(x(e))
|
|
80
|
+
? 'done'
|
|
81
|
+
: t(e.merged_at)
|
|
82
|
+
? 'merged'
|
|
83
|
+
: t(e.approved_at)
|
|
84
|
+
? 'approved'
|
|
85
|
+
: e.kind !== 'authored'
|
|
86
|
+
? 'added'
|
|
87
|
+
: e.status === 'mine_changes_requested'
|
|
88
|
+
? 'need_respond'
|
|
89
|
+
: 'responded';
|
|
90
|
+
}
|
|
91
|
+
function ledgerPeriods(unit, selectedDay) {
|
|
92
|
+
const day = 86400000, hour = 3600000;
|
|
93
|
+
const today = Date.parse(jstStamp(Date.now()).slice(0, 10) + 'T00:00:00+09:00');
|
|
94
|
+
let last = today, step = day, count = U.day;
|
|
95
|
+
if (unit === 'weekly') {
|
|
96
|
+
last -= (new Date(today + 9 * hour).getUTCDay() + 6) % 7 * day;
|
|
97
|
+
step = 7 * day;
|
|
98
|
+
count = U.week;
|
|
99
|
+
} else if (unit === 'hourly') {
|
|
100
|
+
last = Date.parse(selectedDay + 'T00:00:00+09:00') + 23 * hour;
|
|
101
|
+
step = hour;
|
|
102
|
+
count = 24;
|
|
103
|
+
}
|
|
104
|
+
return Array.from({length: count}, (_, index) => {
|
|
105
|
+
const start = new Date(last - (count - 1 - index) * step);
|
|
106
|
+
const stamp = jstStamp(start);
|
|
107
|
+
return {start, end: new Date(+start + step), label: unit === 'hourly' ? stamp.slice(11, 16) : stamp.slice(5, 10)};
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
function ledgerMetrics(e, periods) {
|
|
111
|
+
let o = e.filter(r => r.status !== 'delivery_abandoned'),
|
|
112
|
+
i = (r, s) => !!r && new Date(r) >= s.start && new Date(r) < s.end;
|
|
113
|
+
return periods.map(r => ({
|
|
114
|
+
start: r.start, label: r.label,
|
|
115
|
+
added: o.filter(s => i(s.added_at, r)).length,
|
|
116
|
+
approved: o.filter(s => i(s.approved_at, r)).length,
|
|
117
|
+
merged: o.filter(s => i(s.merged_at, r)).length,
|
|
118
|
+
done: o.filter(s => i(x(s), r)).length,
|
|
119
|
+
open: o.filter(s => s.added_at && new Date(s.added_at) < r.end && !(x(s) && new Date(x(s)) < r.end)).length,
|
|
120
|
+
stage: Object.fromEntries(y.map(([s]) => [s, o.filter(l => G(l, r.end) === s).length])),
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
function R(e) {
|
|
124
|
+
if (e <= 4) return 4;
|
|
125
|
+
let n = 10 ** Math.floor(Math.log10(e));
|
|
126
|
+
return (Math.ceil((e / n) * 2) / 2) * n;
|
|
127
|
+
}
|
|
128
|
+
const a = (e, n, t) => {
|
|
129
|
+
let o = document.createElement(e);
|
|
130
|
+
if (n) o.className = n;
|
|
131
|
+
if (t != null) o.textContent = String(t);
|
|
132
|
+
return o;
|
|
133
|
+
},
|
|
134
|
+
v = (e, n) => {
|
|
135
|
+
let t = document.createElementNS('http://www.w3.org/2000/svg', e);
|
|
136
|
+
for (let o in n) t.setAttribute(o, String(n[o]));
|
|
137
|
+
return t;
|
|
138
|
+
};
|
|
139
|
+
function ne(e, n, t) {
|
|
140
|
+
let s = v('svg', { viewBox: `0 0 960 ${t}` }),
|
|
141
|
+
l = g => t - 20 - (g / n) * (t - 20 - 8);
|
|
142
|
+
for (let g = 0; g <= 4; g++) {
|
|
143
|
+
let m = (n / 4) * g;
|
|
144
|
+
s.append(v('line', { class: 'grid', x1: 32, x2: 960, y1: l(m), y2: l(m) }));
|
|
145
|
+
let h = v('text', { x: 26, y: l(m) + 4, 'text-anchor': 'end' });
|
|
146
|
+
(h.textContent = String(Math.round(m))), s.append(h);
|
|
147
|
+
}
|
|
148
|
+
let u = 928 / e.length,
|
|
149
|
+
p = g => 32 + u * (g + 0.5),
|
|
150
|
+
d = Math.ceil(e.length / 12);
|
|
151
|
+
return (
|
|
152
|
+
e.forEach((g, m) => {
|
|
153
|
+
if (m % d) return;
|
|
154
|
+
let h = v('text', { x: p(m), y: t - 4, 'text-anchor': 'middle' });
|
|
155
|
+
(h.textContent = g.label), s.append(h);
|
|
156
|
+
}),
|
|
157
|
+
{ svg: s, y: l, step: u, cx: p, L: 32, W: 960, H: t, B: 20 }
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
function re(e) {
|
|
161
|
+
let n = r => y.reduce((s, [l]) => s + r.stage[l], 0),
|
|
162
|
+
t = ne(e, R(Math.max(1, ...e.map(n))), 260),
|
|
163
|
+
o = e.map(r => {
|
|
164
|
+
let s = 0;
|
|
165
|
+
return y.map(([l]) => (s += r.stage[l]));
|
|
166
|
+
});
|
|
167
|
+
y.forEach(([, r], s) => {
|
|
168
|
+
let l = e.map((p, d) => `${t.cx(d)},${t.y(o[d][s])}`),
|
|
169
|
+
u = e.map((p, d) => `${t.cx(d)},${t.y(s ? o[d][s - 1] : 0)}`).reverse();
|
|
170
|
+
t.svg.append(v('polygon', { points: [...l, ...u].join(' '), fill: `var(${r})`, 'fill-opacity': 0.85 }));
|
|
171
|
+
}),
|
|
172
|
+
t.svg.append(
|
|
173
|
+
v('polyline', {
|
|
174
|
+
points: e.map((r, s) => `${t.cx(s)},${t.y(r.open)}`).join(' '),
|
|
175
|
+
fill: 'none',
|
|
176
|
+
stroke: 'var(--text)',
|
|
177
|
+
'stroke-width': 2,
|
|
178
|
+
'stroke-dasharray': '4 3',
|
|
179
|
+
}),
|
|
180
|
+
);
|
|
181
|
+
return t.svg;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// The panel remains mounted when its SVG is redrawn, preserving keyboard focus.
|
|
185
|
+
function inspectChart(panel, dates, series, unit, left, right) {
|
|
186
|
+
const svg = panel.querySelector('svg');
|
|
187
|
+
const output = a('output', 'chart-reading');
|
|
188
|
+
output.hidden = true;
|
|
189
|
+
panel.append(output);
|
|
190
|
+
panel.tabIndex = 0;
|
|
191
|
+
let selected = -1;
|
|
192
|
+
function clear() {
|
|
193
|
+
selected = -1;
|
|
194
|
+
output.hidden = true;
|
|
195
|
+
output.textContent = '';
|
|
196
|
+
}
|
|
197
|
+
function show(index) {
|
|
198
|
+
selected = Math.max(0, Math.min(index, dates.length - 1));
|
|
199
|
+
output.textContent = [dates[selected], ...series.map(([name, , values]) => {
|
|
200
|
+
const value = values[selected];
|
|
201
|
+
return name + ' ' + (Number.isFinite(value) ? Number(value.toFixed(2)) + unit : '未計測');
|
|
202
|
+
})].join(' · ');
|
|
203
|
+
output.hidden = false;
|
|
204
|
+
}
|
|
205
|
+
function indexAt(event) {
|
|
206
|
+
const point = new DOMPoint(event.clientX, event.clientY).matrixTransform(svg.getScreenCTM().inverse());
|
|
207
|
+
const width = svg.viewBox.baseVal.width || svg.clientWidth;
|
|
208
|
+
if (dates.length === 1) return 0;
|
|
209
|
+
return Math.round((point.x / width - left) / (right - left) * (dates.length - 1));
|
|
210
|
+
}
|
|
211
|
+
svg.onpointermove = event => { if (event.pointerType !== 'touch') show(indexAt(event)); };
|
|
212
|
+
svg.onpointerleave = event => { if (event.pointerType !== 'touch') clear(); };
|
|
213
|
+
svg.onclick = event => show(indexAt(event));
|
|
214
|
+
output.onclick = clear;
|
|
215
|
+
panel.onblur = clear;
|
|
216
|
+
panel.onkeydown = event => {
|
|
217
|
+
if (event.key === 'Escape') clear();
|
|
218
|
+
else if (['ArrowRight','ArrowLeft','Home','End','Enter',' '].includes(event.key)) {
|
|
219
|
+
event.preventDefault();
|
|
220
|
+
show(event.key === 'End' ? dates.length - 1 : event.key === 'Home' ? 0 :
|
|
221
|
+
selected + (event.key === 'ArrowLeft' ? -1 : 1));
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
function oe(e) {
|
|
226
|
+
let n = a('span', 'legend');
|
|
227
|
+
for (let [t, o] of e) {
|
|
228
|
+
let i = a('span'),
|
|
229
|
+
r = a('span', 'sw');
|
|
230
|
+
(r.style.background = `var(${o})`), i.append(r, t), n.append(i);
|
|
231
|
+
}
|
|
232
|
+
return n;
|
|
233
|
+
}
|
|
234
|
+
function appendGraphs(area, graphs, rows, label, history, hourly) {
|
|
235
|
+
if (!rows.length) return;
|
|
236
|
+
for (const graph of graphs) {
|
|
237
|
+
const series = graph.series.map(({label, color, value}) => [label, color, rows.map(value)]);
|
|
238
|
+
for (const item of graph.series.filter(item => item.average)) {
|
|
239
|
+
const averages = movingAverage(history, item.value, hourly);
|
|
240
|
+
series.push([item.label + ' 平均', item.color,
|
|
241
|
+
rows.map(row => averages.get(row.start)), true]);
|
|
242
|
+
}
|
|
243
|
+
const plot = ne(rows.map(row => ({label: label(row)})), R(Math.max(0, ...series.flatMap(([, , values]) => values.filter(Number.isFinite)))), 180);
|
|
244
|
+
plot.svg.setAttribute('role', 'img');
|
|
245
|
+
plot.svg.setAttribute('aria-label', graph.description ?? graph.title);
|
|
246
|
+
const heading = a('h2', null, graph.title);
|
|
247
|
+
const legend = a('span', 'legend');
|
|
248
|
+
const keys = series.filter(([, , , average]) => !average);
|
|
249
|
+
if (series.some(([, , , average]) => average)) keys.push(['平均', '--text', null, true]);
|
|
250
|
+
for (const [name, color, , average] of keys) {
|
|
251
|
+
const key = a('span', 'line-key');
|
|
252
|
+
key.style.color = `var(${color})`;
|
|
253
|
+
key.style.borderStyle = average ? 'dotted' : 'solid';
|
|
254
|
+
const entry = a('span');
|
|
255
|
+
entry.append(key, name);
|
|
256
|
+
legend.append(entry);
|
|
257
|
+
}
|
|
258
|
+
heading.append(legend);
|
|
259
|
+
for (const [, color, values, average] of series) {
|
|
260
|
+
let previous;
|
|
261
|
+
values.forEach((value, index) => {
|
|
262
|
+
if (!Number.isFinite(value)) { previous = null; return; }
|
|
263
|
+
const cx = plot.cx(index), cy = plot.y(value);
|
|
264
|
+
if (previous) plot.svg.append(v('line', {x1: previous.cx, y1: previous.cy, x2: cx, y2: cy, stroke: `var(${color})`, 'stroke-width': 2, ...(average && {'stroke-dasharray':'2 4'})}));
|
|
265
|
+
plot.svg.append(v('circle', {cx, cy, r: 2.5, fill: `var(${color})`}));
|
|
266
|
+
previous = {cx, cy};
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
area.append(heading, plot.svg);
|
|
270
|
+
inspectChart(area, rows.map(row => jstStamp(row.start) + ' JST'), series, '件', plot.cx(0)/960, plot.cx(rows.length - 1)/960);
|
|
271
|
+
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
var ie = new Intl.DateTimeFormat('sv-SE', {
|
|
275
|
+
timeZone: 'Asia/Tokyo',
|
|
276
|
+
year: 'numeric',
|
|
277
|
+
month: '2-digit',
|
|
278
|
+
day: '2-digit',
|
|
279
|
+
hour: '2-digit',
|
|
280
|
+
minute: '2-digit',
|
|
281
|
+
second: '2-digit',
|
|
282
|
+
}),
|
|
283
|
+
M = e => (e && !Number.isNaN(Date.parse(e)) ? ie.format(new Date(e)) : (e ?? ''));
|
|
284
|
+
const jstStamp = at => M(new Date(at).toISOString());
|
|
285
|
+
function drawGraphs(graphs, scope, rows, label, history = rows, hourly = false) {
|
|
286
|
+
for (const graph of graphs.filter(item => item.scope === scope)) {
|
|
287
|
+
const area = graph.panel;
|
|
288
|
+
area.replaceChildren();
|
|
289
|
+
if (graph.renderer === 'cumulative') {
|
|
290
|
+
const heading = a('h2', null, graph.title);
|
|
291
|
+
heading.append(oe([...[...y].reverse(), ['open', '--text']]));
|
|
292
|
+
area.append(heading, re(rows));
|
|
293
|
+
const series = [['open', '--text', rows.map(row => row.open)],
|
|
294
|
+
...y.map(([name, color]) => [name, color, rows.map(row => row.stage[name])])];
|
|
295
|
+
inspectChart(area, rows.map(row => jstStamp(row.start).slice(0, 16)), series, '件',
|
|
296
|
+
(32 + 464/rows.length)/960, (960 - 464/rows.length)/960);
|
|
297
|
+
} else appendGraphs(area, [graph], rows, label, history, hourly);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const metricValue = value => value == null ? '—' : value.toLocaleString('ja-JP', {maximumFractionDigits: 2});
|
|
302
|
+
export function renderDashboard({graphs, cards, loaded, data, failed, issueDate, issueUnit, tableArea, status, retry}) {
|
|
303
|
+
tableArea.replaceChildren();
|
|
304
|
+
for (const graph of graphs.filter(item => item.scope === 'issues')) graph.panel.replaceChildren();
|
|
305
|
+
const hourly = issueUnit.value === 'hourly', weekly = issueUnit.value === 'weekly';
|
|
306
|
+
issueDate.hidden = !hourly;
|
|
307
|
+
status.textContent = failed ? 'Issue 集計を取得できません。再取得します。' : data?.refreshFailed ? '更新失敗。前回の集計を表示しています。' : data?.complete === false ? '部分取得(' + data.covered + '/' + data.repositories + ' リポジトリ)' : data?.daily ? '' : 'Issue 未計測';
|
|
308
|
+
status.hidden = !status.textContent;
|
|
309
|
+
retry.hidden = !failed;
|
|
310
|
+
const day = row => jstStamp(row.start).slice(0, 10);
|
|
311
|
+
const dates = new Set((data?.daily ?? []).map(day));
|
|
312
|
+
if (loaded || !dates.size) for (const period of ledgerPeriods('daily')) dates.add(day(period));
|
|
313
|
+
const selected = issueDate.value;
|
|
314
|
+
issueDate.replaceChildren(...[...dates].sort().reverse().map(date => new Option(date, date)));
|
|
315
|
+
if (dates.has(selected)) issueDate.value = selected;
|
|
316
|
+
const rows = weekly ? [] : hourly ? (data?.hourly ?? []).filter(row => day(row) === issueDate.value) : data?.daily ?? [];
|
|
317
|
+
const ledger = loaded ? ledgerMetrics(cards, ledgerPeriods(issueUnit.value, issueDate.value).filter(period => +period.start <= Date.now())) : [];
|
|
318
|
+
if (ledger.length) drawGraphs(graphs, 'ledger', ledger, row => row.label);
|
|
319
|
+
const extensions = dashboardExtensions('issues');
|
|
320
|
+
drawGraphs(graphs, 'issues', rows, row => hourly ? jstStamp(row.start).slice(11, 16) : day(row).slice(5), hourly ? data?.hourly : data?.daily, hourly);
|
|
321
|
+
const table = a('table'), head = a('tr');
|
|
322
|
+
const ledgerColumns = ['open', ...S.map(([key]) => key)].map(key => ({label:key, value:row => row[key]}))
|
|
323
|
+
.concat(dashboardExtensions('ledger').columns);
|
|
324
|
+
const issueLabels = ['新規','再open','実close','うち完了理由','純増減','期末未完了','年齢中央値(日)','年齢P90(日)',
|
|
325
|
+
'初回close件数','初回中央値(時間)',...extensions.columns.map(column => column.label)];
|
|
326
|
+
const groups = a('tr');
|
|
327
|
+
const period = a('th', null, '期間(JST)');
|
|
328
|
+
period.rowSpan = 2;
|
|
329
|
+
groups.append(period);
|
|
330
|
+
for (const [name, labels] of [['台帳', ledgerColumns.map(column => column.label)], ...(weekly ? [] : [['全 Issue', issueLabels]])]) {
|
|
331
|
+
const group = a('th', null, name);
|
|
332
|
+
group.colSpan = labels.length;
|
|
333
|
+
groups.append(group);
|
|
334
|
+
for (const label of labels) head.append(a('th', null, label));
|
|
335
|
+
}
|
|
336
|
+
table.createTHead().append(groups, head);
|
|
337
|
+
const body = table.createTBody();
|
|
338
|
+
const cardRows = new Map(ledger.map(row => [+row.start, row]));
|
|
339
|
+
const issues = new Map(rows.map(row => [+row.start, row]));
|
|
340
|
+
for (const start of [...new Set([...cardRows.keys(), ...issues.keys()])].sort((a,b) => b-a)) {
|
|
341
|
+
const card = cardRows.get(start), row = issues.get(start), line = a('tr');
|
|
342
|
+
line.append(a('td', null, hourly ? jstStamp(start).slice(11,16) : jstStamp(start).slice(0,10)));
|
|
343
|
+
const values = ledgerColumns.map(column => card && column.value(card));
|
|
344
|
+
if (!weekly) values.push(row?.created,row?.reopened,row?.closed,row?.completed,row?.net,row?.open,row?.ageDays?.median,row?.ageDays?.p90,
|
|
345
|
+
row?.first,row?.firstHours?.median,...extensions.columns.map(column => row && column.value(row)));
|
|
346
|
+
for (const value of values) line.append(a('td', null, metricValue(value)));
|
|
347
|
+
body.append(line);
|
|
348
|
+
}
|
|
349
|
+
tableArea.append(table);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export {inspectChart, G as stageAt, ledgerMetrics};
|
|
353
|
+
|
|
354
|
+
export function mountDashboardNavigation(container) {
|
|
355
|
+
const buttons = [['ledger','ledger'],['dash','dashboard'],['decide','decide']].map(([view,label]) => {
|
|
356
|
+
const button = a('button', null, label);
|
|
357
|
+
button.dataset.v = view;
|
|
358
|
+
if (view === 'decide') {
|
|
359
|
+
const badge = a('span', 'badge');
|
|
360
|
+
badge.id = 'decidecount';
|
|
361
|
+
badge.hidden = true;
|
|
362
|
+
button.append(badge);
|
|
363
|
+
}
|
|
364
|
+
return button;
|
|
365
|
+
});
|
|
366
|
+
container.replaceChildren(...buttons);
|
|
367
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hikae/ledger-core",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Pure core shared by the local ledger agent and a host: model tier policy, issue stage machine, port interfaces.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,12 +45,18 @@
|
|
|
45
45
|
"./issueObservation": {
|
|
46
46
|
"types": "./dist/issueObservation.d.ts",
|
|
47
47
|
"default": "./dist/issueObservation.js"
|
|
48
|
+
},
|
|
49
|
+
"./dashboard": {
|
|
50
|
+
"types": "./dashboard.d.ts",
|
|
51
|
+
"default": "./dashboard.js"
|
|
48
52
|
}
|
|
49
53
|
},
|
|
50
54
|
"files": [
|
|
51
55
|
"dist",
|
|
52
56
|
"README.md",
|
|
53
|
-
"LICENSE"
|
|
57
|
+
"LICENSE",
|
|
58
|
+
"dashboard.js",
|
|
59
|
+
"dashboard.d.ts"
|
|
54
60
|
],
|
|
55
61
|
"sideEffects": false,
|
|
56
62
|
"engines": {
|