@datalabz_/dashboard-kit 6.0.11 → 6.0.13

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.
Files changed (4) hide show
  1. package/package.json +1 -1
  2. package/v4.js +1 -1
  3. package/v5.js +1 -1
  4. package/v6.js +33 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datalabz_/dashboard-kit",
3
- "version": "6.0.11",
3
+ "version": "6.0.13",
4
4
  "description": "DashboardKit runtime + styles, served from jsDelivr",
5
5
  "license": "UNLICENSED",
6
6
  "files": [
package/v4.js CHANGED
@@ -20,7 +20,7 @@
20
20
  let _activeTabId = '';
21
21
  let _sections = []; // { id, label, load, loaded, errors }
22
22
  let _title = '';
23
- let _gitVer = '679acd7'; // replaced at deploy: sed -i "s/679acd7/$(git rev-parse --short HEAD)/g" v4.js
23
+ let _gitVer = 'df0ab1d'; // replaced at deploy: sed -i "s/df0ab1d/$(git rev-parse --short HEAD)/g" v4.js
24
24
  let _calls = []; // System Info call log
25
25
  let _sectionErrors = {}; // sectionId → error count
26
26
  let _generation = 0;
package/v5.js CHANGED
@@ -20,7 +20,7 @@
20
20
  let _activeTabId = '';
21
21
  let _sections = []; // { id, label, load, loaded, errors }
22
22
  let _title = '';
23
- let _gitVer = '679acd7'; // replaced at deploy: sed -i "s/679acd7/$(git rev-parse --short HEAD)/g" v4.js
23
+ let _gitVer = 'df0ab1d'; // replaced at deploy: sed -i "s/df0ab1d/$(git rev-parse --short HEAD)/g" v4.js
24
24
  let _calls = []; // System Info call log
25
25
  let _sectionErrors = {}; // sectionId → error count
26
26
  let _generation = 0;
package/v6.js CHANGED
@@ -20,7 +20,7 @@
20
20
  let _activeTabId = '';
21
21
  let _sections = []; // { id, label, load, loaded, errors }
22
22
  let _title = '';
23
- let _gitVer = '679acd7'; // replaced at deploy: sed -i "s/679acd7/$(git rev-parse --short HEAD)/g" v6.js
23
+ let _gitVer = 'df0ab1d'; // replaced at deploy: sed -i "s/df0ab1d/$(git rev-parse --short HEAD)/g" v6.js
24
24
  let _calls = []; // System Info call log
25
25
  let _pageErrors = []; // System Info: errors no load() caught (a handler's, a timer's, the page script's)
26
26
  let _sectionErrors = {}; // sectionId → error count
@@ -1090,6 +1090,15 @@ html[data-dk-setup="true"] .dk-resp-toggle {
1090
1090
  return n.toFixed(typeof decimals === 'number' ? decimals : 2) + '%';
1091
1091
  }
1092
1092
 
1093
+ // A ratio shown as a percentage: 0.123 → 12.30%, where formatPercent takes 12.3. Which one a
1094
+ // value is, the call says, and the ×100 is the kit's: in a page, null * 100 is 0, so a ratio
1095
+ // with no base (NULLIF) would show 0.00% instead of —. Same type-check as _fmtDate.
1096
+ function formatRatio(v, decimals) {
1097
+ const n = parseFloat(v);
1098
+ if (isNaN(n)) return '—';
1099
+ return formatPercent(n * 100, decimals);
1100
+ }
1101
+
1093
1102
  function colorClass(v) {
1094
1103
  const n = Number(v);
1095
1104
  return n > 0 ? 'pos' : n < 0 ? 'neg' : '';
@@ -1633,6 +1642,7 @@ html[data-dk-setup="true"] .dk-resp-toggle {
1633
1642
  runQuery: function (s, l, q, a, p) { return runQuery(s, l, q, a, p, running ? gen : null); },
1634
1643
  formatCurrency,
1635
1644
  formatPercent,
1645
+ formatRatio,
1636
1646
  formatInteger: fmtInt,
1637
1647
  formatDate: fmtDate,
1638
1648
  formatDatetime: fmtDatetime,
@@ -2686,12 +2696,26 @@ html[data-dk-setup="true"] .dk-resp-toggle {
2686
2696
  html += '<td>' + esc(cell ?? '—') + '</td>';
2687
2697
  } else if (cell && cell.agg === 'sum') {
2688
2698
  const sum = rows.reduce(function (a, r) { return a + (Number(r[cell.key]) || 0); }, 0);
2689
- const fmt = col.format || function (v) { return v; };
2690
- // Totals have no single row; pass an empty row so a per-row-currency
2691
- // formatter degrades gracefully instead of throwing. Don't sum a
2692
- // mixed-currency column (see the all-currencies note in the docs).
2693
2699
  let out;
2694
- try { out = fmt(sum, {}); } catch { out = '—'; }
2700
+ if (cell.currency !== undefined) {
2701
+ // A money total bound to the rows' currency field: one currency, the sum in it; more than
2702
+ // one (a row without any counts as one more), — rather than a number of mixed money.
2703
+ if (typeof cell.currency !== 'string' || !cell.currency) {
2704
+ throw new Error('renderTable: totalsRow[' + i + '].currency must name the rows\' currency field, such as "currency"');
2705
+ }
2706
+ const seen = {};
2707
+ rows.forEach(function (r) {
2708
+ const c = r[cell.currency];
2709
+ seen[typeof c === 'string' ? c : ''] = true;
2710
+ });
2711
+ const found = Object.keys(seen);
2712
+ out = found.length > 1 ? '—' : formatCurrency(sum, found[0]);
2713
+ } else {
2714
+ const fmt = col.format || function (v) { return v; };
2715
+ // Totals have no single row; pass an empty row so a per-row-currency
2716
+ // formatter degrades gracefully instead of throwing.
2717
+ try { out = fmt(sum, {}); } catch { out = '—'; }
2718
+ }
2695
2719
  html += '<td>' + totalsSlots.html(out, '—') + '</td>';
2696
2720
  } else {
2697
2721
  html += '<td>—</td>';
@@ -3304,6 +3328,7 @@ html[data-dk-setup="true"] .dk-resp-toggle {
3304
3328
  formatCurrency,
3305
3329
  formatInteger: fmtInt,
3306
3330
  formatPercent,
3331
+ formatRatio,
3307
3332
  formatDate: fmtDate,
3308
3333
  formatDatetime: fmtDatetime,
3309
3334
  colorClass,
@@ -3322,8 +3347,8 @@ html[data-dk-setup="true"] .dk-resp-toggle {
3322
3347
  // it, where a declaration here would make that a SyntaxError. A name the window already holds for
3323
3348
  // something else is left as it is.
3324
3349
  ['runQuery', 'renderTable', 'renderKpiCard', 'renderKpiStrip', 'renderInfoGrid', 'renderTotalsStrip',
3325
- 'formatCurrency', 'formatInteger', 'formatPercent', 'formatDate', 'formatDatetime', 'colorClass',
3326
- 'escHtml'].forEach(function (name) {
3350
+ 'formatCurrency', 'formatInteger', 'formatPercent', 'formatRatio', 'formatDate', 'formatDatetime',
3351
+ 'colorClass', 'escHtml'].forEach(function (name) {
3327
3352
  const ours = earlier && global[name] === earlier[name];
3328
3353
  if (Object.prototype.hasOwnProperty.call(global, name) && !ours) {
3329
3354
  console.warn('[DashboardKit] window.' + name + ' is already taken; use DashboardKit.' + name);