@lightdash/cli 2.323.0 → 2.324.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.
@@ -3,6 +3,14 @@
3
3
  "category": "orders_status",
4
4
  "value": "orders_total_revenue"
5
5
  },
6
+ "fields": {
7
+ "orders_status": { "label": "Status", "tableLabel": "Orders" },
8
+ "orders_total_revenue": {
9
+ "label": "Total revenue",
10
+ "tableLabel": "Orders",
11
+ "format": { "type": "currency", "currency": "USD", "round": 0 }
12
+ }
13
+ },
6
14
  "rows": [
7
15
  {
8
16
  "orders_status": {
@@ -11,6 +11,8 @@ contract in `references/lightdash-library-theme.md`): `--ll-*` tokens for axes,
11
11
  grids, legends, tooltips, and typography; transparent canvas; series colors from
12
12
  the instance palette, never the theme.
13
13
 
14
+ Name fields with `getFieldLabel(context, id)` — labels, never raw query ids.
15
+
14
16
  The one difference from that skill here: the declaration is not emitted as structured output. It lives in this folder's `lightdash-app.yml` under `vizSchema`, and **must stay in lockstep with the component** — every key `src/App.jsx` reads from `fieldMapping` or `options` is declared there, and everything declared there is read. When you change what the component reads, update `vizSchema` in the same edit.
15
17
 
16
18
  Edit only `src/`. Root config files are read-only reference — the server rebuilds against a trusted template.
@@ -24,7 +26,7 @@ Run these commands from this folder under `chart-types/<slug>/`. The upload path
24
26
  3. `lightdash upload --chart-types <slug> --path ../..` — the server rebuilds; the chart type then appears in the explorer's chart type picker for that project.
25
27
  4. Verify in Lightdash: open any explore, run a query, pick this chart type, and map its fields.
26
28
 
27
- Preview locally with the fixture: `useVizContext()` normally waits for the Lightdash host, but the SDK has a dev-only fallback. Run `lightdash apps preview` (or `npm run dev`) and open the dev URL with `?vizFixture=/viz-fixture.json` — the scaffold's `viz-fixture.json` seeds `useVizContext()` so the chart renders. Edit that file to match your `vizSchema` (fieldMapping, rows as `{ value: { raw, formatted } }` cells, options, colorPalette, pivotDetails). It's fake data for layout/option iteration and never fires in production; the explorer with real data is still the source of truth — upload and verify there before finishing.
29
+ Preview locally with the fixture: `useVizContext()` normally waits for the Lightdash host, but the SDK has a dev-only fallback. Run `lightdash apps preview` (or `npm run dev`) and open the dev URL with `?vizFixture=/viz-fixture.json` — the scaffold's `viz-fixture.json` seeds `useVizContext()` so the chart renders. Edit that file to match your `vizSchema` (fieldMapping, fields labels, rows as `{ value: { raw, formatted } }` cells, options, colorPalette, pivotDetails). It's fake data for layout/option iteration and never fires in production; the explorer with real data is still the source of truth — upload and verify there before finishing.
28
30
 
29
31
  Build with the template's preinstalled dependency set (see `package.json` — React, Recharts, d3, and more). Do not add npm packages or vendor library source into `src/`; chart types published to the official registry must stay template-deps-only.
30
32
 
@@ -1,4 +1,5 @@
1
1
  import {
2
+ getFieldLabel,
2
3
  getFormatted,
3
4
  getRaw,
4
5
  resolveValueColor,
@@ -80,10 +81,15 @@ function App() {
80
81
  ink: token('--ll-ink'),
81
82
  };
82
83
  const axisTick = { fill: ll.text, fontSize: 11.5, fontWeight: 500 };
84
+ // Name fields with their host labels ("Total revenue"), never the raw
85
+ // query ids; getFieldLabel falls back to the id only on hosts that send
86
+ // no field metadata.
87
+ const valueLabel = getFieldLabel(context, valField);
83
88
  const data = rows.slice(0, maxBars).map((row) => ({
84
89
  label: getFormatted(row, catField),
85
90
  category: getRaw(row, catField),
86
91
  value: Number(getRaw(row, valField) ?? 0),
92
+ formatted: getFormatted(row, valField),
87
93
  }));
88
94
 
89
95
  return (
@@ -112,8 +118,15 @@ function App() {
112
118
  axisLine={false}
113
119
  tickFormatter={(v) => v.toLocaleString()}
114
120
  />
115
- <Tooltip wrapperClassName="ll-tooltip" cursor={false} />
116
- <Bar dataKey="value">
121
+ <Tooltip
122
+ wrapperClassName="ll-tooltip"
123
+ cursor={false}
124
+ formatter={(value, name, item) => [
125
+ item.payload.formatted,
126
+ name,
127
+ ]}
128
+ />
129
+ <Bar dataKey="value" name={valueLabel}>
117
130
  {data.map((d, i) => (
118
131
  <Cell
119
132
  key={`${d.label}-${i}`}
@@ -3,6 +3,14 @@
3
3
  "category": "orders_status",
4
4
  "value": "orders_total_revenue"
5
5
  },
6
+ "fields": {
7
+ "orders_status": { "label": "Status", "tableLabel": "Orders" },
8
+ "orders_total_revenue": {
9
+ "label": "Total revenue",
10
+ "tableLabel": "Orders",
11
+ "format": { "type": "currency", "currency": "USD", "round": 0 }
12
+ }
13
+ },
6
14
  "rows": [
7
15
  {
8
16
  "orders_status": {
@@ -38,7 +38,7 @@ The scaffold ships a `viz-fixture.json` at the folder root. To use it:
38
38
 
39
39
  1. `lightdash apps preview` (or `npm run dev`) to start the dev server.
40
40
  2. Open the dev URL with the param, e.g. `http://localhost:5173/?vizFixture=/viz-fixture.json`. The chart renders from the fixture.
41
- 3. Edit `viz-fixture.json` to match your declared `vizSchema` — `fieldMapping` (input name → string id, or an ordered array of ids for multiple-field inputs), `rows` (each cell is `{ "value": { "raw": ..., "formatted": "..." } }`, keyed by those ids), `options` (declared option name → value), `colorPalette`, and `pivotDetails` (`null` unless you map a `series` field). Reload to see changes.
41
+ 3. Edit `viz-fixture.json` to match your declared `vizSchema` — `fieldMapping` (input name → string id, or an ordered array of ids for multiple-field inputs), `fields` (id → `{ "label": ..., "format": ... }`, so labels render as they will in Lightdash), `rows` (each cell is `{ "value": { "raw": ..., "formatted": "..." } }`, keyed by those ids), `options` (declared option name → value), `colorPalette`, and `pivotDetails` (`null` unless you map a `series` field). Reload to see changes.
42
42
 
43
43
  For multiple-field inputs, set `multiple: true` on the `vizSchema.fields` entry and iterate
44
44
  the array at `useVizContext().fieldMapping[name]` in its existing order, narrowing with
@@ -30,6 +30,7 @@ returns.
30
30
  const context = useVizContext();
31
31
  const {
32
32
  fieldMapping,
33
+ fields,
33
34
  rows,
34
35
  options,
35
36
  colorPalette,
@@ -45,6 +46,12 @@ const {
45
46
  to one query field id; inputs declared with `multiple: true` map to ordered arrays.
46
47
  Narrow with `Array.isArray(binding)` before iterating. Read each id with
47
48
  `getFormatted(row, fieldId)` (display text) and `getRaw(row, fieldId)` (raw value).
49
+ - `fields` — `Record<string, { label, tableLabel?, format? }>`: display metadata for
50
+ each bound query field id. Name fields with `getFieldLabel(context, fieldId)` — the
51
+ field's label ("Total revenue"), or the raw id only when the host sent no metadata.
52
+ `format` is the semantic-layer format (`type` such as `currency`/`percent`/`number`,
53
+ plus `round`, `currency`, `compact`, `prefix`, `suffix`) for formatters that have no
54
+ cell to hand, such as axis ticks; per-value text still comes from `getFormatted`.
48
55
  - `rows` — the host-fetched result rows, keyed by query field id.
49
56
  - `options` — `Record<string, boolean | number | string>`: the current value of each config
50
57
  option you declared (the viewer's choice, else your declared `default`).
@@ -91,6 +98,10 @@ shadcn, charting, theming, floating surfaces, screenshots) still applies.
91
98
  - **Fundamentals.** Clear axes and labels, readable spacing, a tooltip on hover.
92
99
  Give every axis a `tickFormatter` (compact numbers, shortened labels) or `hide`
93
100
  it — raw ticks overflow and overlap on a chart the viewer can resize.
101
+ - **Labels, never ids.** Wherever the chart names a field — axis titles, legend and
102
+ series names, table headers, tooltip rows, default labels — use
103
+ `getFieldLabel(context, fieldId)`. Never show the query id (`orders_total_revenue`)
104
+ or a name derived from it (humanized, or with the table prefix stripped).
94
105
 
95
106
  ## Series colours
96
107
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash/cli",
3
- "version": "2.323.0",
3
+ "version": "2.324.0",
4
4
  "description": "Lightdash CLI tool",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -22,8 +22,8 @@
22
22
  "@actions/core": "1.11.1",
23
23
  "@aws-sdk/credential-providers": "3.995.0",
24
24
  "@casl/ability": "6.8.0",
25
- "@lightdash/common": "2.323.0",
26
- "@lightdash/warehouses": "2.323.0",
25
+ "@lightdash/common": "2.324.0",
26
+ "@lightdash/warehouses": "2.324.0",
27
27
  "@sidvind/better-ajv-errors": "7.0.0",
28
28
  "@types/columnify": "1.5.1",
29
29
  "ajv": "8.18.0",