@opendata-ai/openchart-engine 6.25.3 → 6.25.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opendata-ai/openchart-engine",
3
- "version": "6.25.3",
3
+ "version": "6.25.4",
4
4
  "description": "Headless compiler for openchart: spec validation, data compilation, scales, and layout",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Riley Hilliard",
@@ -48,7 +48,7 @@
48
48
  "typecheck": "tsc --noEmit"
49
49
  },
50
50
  "dependencies": {
51
- "@opendata-ai/openchart-core": "6.25.3",
51
+ "@opendata-ai/openchart-core": "6.25.4",
52
52
  "d3-array": "^3.2.0",
53
53
  "d3-format": "^3.1.2",
54
54
  "d3-interpolate": "^3.0.0",
package/src/compile.ts CHANGED
@@ -237,14 +237,23 @@ export function compileChart(spec: unknown, options: CompileOptions): ChartLayou
237
237
  },
238
238
  };
239
239
  }
240
- if (bp.labels) {
241
- chartSpec = {
242
- ...chartSpec,
243
- labels: {
244
- ...chartSpec.labels,
245
- ...(bp.labels as NormalizedChartSpec['labels']),
246
- },
247
- };
240
+ if (bp.labels !== undefined) {
241
+ if (typeof bp.labels === 'boolean') {
242
+ chartSpec = {
243
+ ...chartSpec,
244
+ labels: bp.labels
245
+ ? { density: 'auto', format: '', prefix: '' }
246
+ : { density: 'none', format: '', prefix: '' },
247
+ };
248
+ } else {
249
+ chartSpec = {
250
+ ...chartSpec,
251
+ labels: {
252
+ ...chartSpec.labels,
253
+ ...(bp.labels as NormalizedChartSpec['labels']),
254
+ },
255
+ };
256
+ }
248
257
  }
249
258
  if (bp.legend) {
250
259
  chartSpec = {
@@ -17,6 +17,7 @@ import type {
17
17
  Encoding,
18
18
  FieldType,
19
19
  GraphSpec,
20
+ LabelSpec,
20
21
  LayerSpec,
21
22
  SankeySpec,
22
23
  TableSpec,
@@ -189,6 +190,21 @@ function normalizeAnnotations(annotations: Annotation[] | undefined): Annotation
189
190
  });
190
191
  }
191
192
 
193
+ // ---------------------------------------------------------------------------
194
+ // Label normalization
195
+ // ---------------------------------------------------------------------------
196
+
197
+ function normalizeLabels(labels?: LabelSpec): NormalizedChartSpec['labels'] {
198
+ if (labels === false) return { density: 'none', format: '', prefix: '' };
199
+ if (labels === true || labels === undefined) return { density: 'auto', format: '', prefix: '' };
200
+ return {
201
+ density: labels.density ?? 'auto',
202
+ format: labels.format ?? '',
203
+ prefix: labels.prefix ?? '',
204
+ offsets: labels.offsets,
205
+ };
206
+ }
207
+
192
208
  // ---------------------------------------------------------------------------
193
209
  // Spec-level normalization
194
210
  // ---------------------------------------------------------------------------
@@ -205,12 +221,7 @@ function normalizeChartSpec(spec: ChartSpec, warnings: string[]): NormalizedChar
205
221
  encoding,
206
222
  chrome: normalizeChrome(spec.chrome),
207
223
  annotations: normalizeAnnotations(spec.annotations),
208
- labels: {
209
- density: spec.labels?.density ?? 'auto',
210
- format: spec.labels?.format ?? '',
211
- prefix: spec.labels?.prefix ?? '',
212
- offsets: spec.labels?.offsets,
213
- },
224
+ labels: normalizeLabels(spec.labels),
214
225
  legend: spec.legend,
215
226
  responsive: spec.responsive ?? true,
216
227
  theme: spec.theme ?? {},