@bonnard/react 0.2.1 → 0.3.1

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/dashboard.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as BarChart, i as LineChart, n as PieChart, o as BigValue, r as AreaChart, t as DataTable, u as useBonnard } from "./data-table-C3K4rPh2.js";
1
+ import { a as BarChart, i as LineChart, n as PieChart, o as BigValue, r as AreaChart, t as DataTable, u as useBonnard } from "./data-table-Db3BSi5Z.js";
2
2
  import { useCallback, useEffect, useRef, useState } from "react";
3
3
  import DOMPurify from "isomorphic-dompurify";
4
4
  import matter from "gray-matter";
@@ -807,8 +807,8 @@ function SectionRenderer({ section, queryStates }) {
807
807
  return /* @__PURE__ */ jsx("div", {
808
808
  style: {
809
809
  borderRadius: "var(--bon-radius, 8px)",
810
- border: "1px solid var(--bon-border, rgba(128,128,128,0.2))",
811
- backgroundColor: "var(--bon-card-bg, transparent)",
810
+ border: "1px solid var(--bon-border)",
811
+ backgroundColor: "var(--bon-bg-card)",
812
812
  padding: 16
813
813
  },
814
814
  children: inner
@@ -262,10 +262,14 @@ function formatAxisLabel(val) {
262
262
  }
263
263
  return val;
264
264
  }
265
- /** ECharts y-axis formatter — compact numbers */
266
- function axisValueFormatter(val) {
265
+ /** ECharts y-axis formatter — uses explicit format or compact fallback */
266
+ function axisValueFormatter(val, yFmt) {
267
+ if (yFmt) return applyFormat(val, yFmt);
267
268
  if (Math.abs(val) >= 1e6) return `${(val / 1e6).toFixed(1)}M`;
268
- if (Math.abs(val) >= 1e3) return `${(val / 1e3).toFixed(0)}K`;
269
+ if (Math.abs(val) >= 1e3) {
270
+ const k = val / 1e3;
271
+ return k % 1 === 0 ? `${k}K` : `${k.toFixed(1)}K`;
272
+ }
269
273
  return String(val);
270
274
  }
271
275
  /** Convert snake_case or camelCase field names to Title Case */
@@ -316,6 +320,21 @@ function BigValue({ data, value, title, fmt }) {
316
320
  //#endregion
317
321
  //#region src/lib/build-series.ts
318
322
  /**
323
+ * Pure data transformation: splits flat query results into multi-series datasets.
324
+ *
325
+ * Four cases:
326
+ * | y columns | series prop | Result |
327
+ * |-----------|-------------|-------------------------------|
328
+ * | Single | None | 1 dataset (current behavior) |
329
+ * | Single | Set | N datasets (per series value) |
330
+ * | Multiple | None | N datasets (per y column) |
331
+ * | Multiple | Set | N*M datasets |
332
+ */
333
+ /** Strip view/cube prefix and convert snake_case to Title Case for legend labels */
334
+ function humanizeField(name) {
335
+ return (name.includes(".") ? name.slice(name.indexOf(".") + 1) : name).replace(/_/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
336
+ }
337
+ /**
319
338
  * Build multi-series datasets from flat query data.
320
339
  *
321
340
  * @param data - Flat array of row objects from query
@@ -338,7 +357,7 @@ function buildSeries(data, x, y, series) {
338
357
  if (!series) return {
339
358
  labels: data.map((row) => String(row[x] ?? "")),
340
359
  datasets: yColumns.map((col) => ({
341
- name: col,
360
+ name: humanizeField(col),
342
361
  values: data.map((row) => {
343
362
  const val = row[col];
344
363
  return val == null ? null : Number(val);
@@ -368,7 +387,7 @@ function buildSeries(data, x, y, series) {
368
387
  }
369
388
  const datasets = [];
370
389
  for (const sk of seriesKeys) for (const col of yColumns) {
371
- const name = yColumns.length === 1 ? sk : `${sk} - ${col}`;
390
+ const name = yColumns.length === 1 ? sk : `${sk} - ${humanizeField(col)}`;
372
391
  const values = xValues.map((xRaw) => {
373
392
  const row = lookup.get(`${xRaw}\0${sk}`);
374
393
  if (!row) return null;
@@ -486,7 +505,7 @@ function BarChart({ data, x, y, title, horizontal, series, type, yFmt }) {
486
505
  axisLabel: {
487
506
  color: theme.text.label,
488
507
  fontSize: 12,
489
- formatter: axisValueFormatter
508
+ formatter: (v) => axisValueFormatter(v, yFmt)
490
509
  },
491
510
  splitLine: { lineStyle: { color: theme.gridLine } }
492
511
  };
@@ -577,7 +596,7 @@ function LineChart({ data, x, y, title, series, type, yFmt }) {
577
596
  axisLabel: {
578
597
  color: theme.text.label,
579
598
  fontSize: 12,
580
- formatter: axisValueFormatter
599
+ formatter: (v) => axisValueFormatter(v, yFmt)
581
600
  },
582
601
  splitLine: { lineStyle: { color: theme.gridLine } }
583
602
  },
@@ -651,7 +670,7 @@ function AreaChart({ data, x, y, title, series, type, yFmt }) {
651
670
  axisLabel: {
652
671
  color: theme.text.label,
653
672
  fontSize: 12,
654
- formatter: axisValueFormatter
673
+ formatter: (v) => axisValueFormatter(v, yFmt)
655
674
  },
656
675
  splitLine: { lineStyle: { color: theme.gridLine } }
657
676
  },
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as BarChart, c as PALETTES, i as LineChart, l as BonnardContext, n as PieChart, o as BigValue, r as AreaChart, s as CHART_COLORS, t as DataTable, u as useBonnard } from "./data-table-C3K4rPh2.js";
1
+ import { a as BarChart, c as PALETTES, i as LineChart, l as BonnardContext, n as PieChart, o as BigValue, r as AreaChart, s as CHART_COLORS, t as DataTable, u as useBonnard } from "./data-table-Db3BSi5Z.js";
2
2
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
3
3
  import { jsx } from "react/jsx-runtime";
4
4
  import { createClient } from "@bonnard/sdk";
@@ -1 +1 @@
1
- {"version":3,"file":"build-series.d.ts","sourceRoot":"","sources":["../../src/lib/build-series.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,WAAW,aAAa;IAC5B,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,iEAAiE;IACjE,MAAM,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,iBAAiB;IAChC,4BAA4B;IAC5B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,6BAA6B;IAC7B,QAAQ,EAAE,aAAa,EAAE,CAAC;CAC3B;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAC/B,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,MAAM,CAAC,EAAE,MAAM,GACd,iBAAiB,CA+EnB"}
1
+ {"version":3,"file":"build-series.d.ts","sourceRoot":"","sources":["../../src/lib/build-series.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAUH,MAAM,WAAW,aAAa;IAC5B,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,iEAAiE;IACjE,MAAM,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,iBAAiB;IAChC,4BAA4B;IAC5B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,6BAA6B;IAC7B,QAAQ,EAAE,aAAa,EAAE,CAAC;CAC3B;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAC/B,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,MAAM,CAAC,EAAE,MAAM,GACd,iBAAiB,CA+EnB"}
@@ -69,8 +69,8 @@ export declare function formatValue(val: unknown): string;
69
69
  export declare function tooltipFormatter(yFmt?: string): ((val: number) => string);
70
70
  /** Format axis label — detects ISO dates and formats them nicely */
71
71
  export declare function formatAxisLabel(val: string): string;
72
- /** ECharts y-axis formatter — compact numbers */
73
- export declare function axisValueFormatter(val: number): string;
72
+ /** ECharts y-axis formatter — uses explicit format or compact fallback */
73
+ export declare function axisValueFormatter(val: number, yFmt?: string): string;
74
74
  /** Convert snake_case or camelCase field names to Title Case */
75
75
  export declare function formatColumnHeader(col: string): string;
76
76
  //# sourceMappingURL=chart-theme.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"chart-theme.d.ts","sourceRoot":"","sources":["../../src/theme/chart-theme.ts"],"names":[],"mappings":"AAKA,sCAAsC;AACtC,eAAO,MAAM,QAAQ;;;;;CAuBX,CAAC;AAEX,MAAM,MAAM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MAAM,EAAE,CAAA;KAAE;EAWrI;AAED,gDAAgD;AAChD,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB;;;;;;;;;;;;;;EAWlD;AAED,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAExC,0EAA0E;AAC1E,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAQvD;AAED,kEAAkE;AAClE,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAGtD;AAED,4CAA4C;AAC5C,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,sEAAsE;AACtE,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAQhD;AAED,gFAAgF;AAChF,wBAAgB,gBAAgB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC,CAKzE;AAED,oEAAoE;AACpE,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAgBnD;AAED,0EAA0E;AAC1E,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CASrE;AAED,gEAAgE;AAChE,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAKtD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bonnard/react",
3
- "version": "0.2.1",
3
+ "version": "0.3.1",
4
4
  "description": "Bonnard embedded analytics — React charts, dashboards, and hooks",
5
5
  "repository": {
6
6
  "type": "git",