@opendata-ai/openchart-engine 6.27.0 → 6.28.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.
Files changed (36) hide show
  1. package/dist/index.d.ts +38 -6
  2. package/dist/index.js +1040 -521
  3. package/dist/index.js.map +1 -1
  4. package/package.json +2 -2
  5. package/src/__tests__/__snapshots__/compile-snapshot.test.ts.snap +31 -4
  6. package/src/__tests__/axes.test.ts +101 -3
  7. package/src/__tests__/legend.test.ts +2 -2
  8. package/src/annotations/__tests__/compute.test.ts +175 -0
  9. package/src/annotations/position.ts +37 -1
  10. package/src/annotations/resolve-range.ts +5 -5
  11. package/src/barlist/__tests__/compile-barlist.test.ts +200 -0
  12. package/src/barlist/compile-barlist.ts +380 -0
  13. package/src/barlist/types.ts +28 -0
  14. package/src/charts/bar/__tests__/compute.test.ts +222 -0
  15. package/src/charts/bar/compute.ts +77 -44
  16. package/src/charts/bar/index.ts +1 -0
  17. package/src/charts/bar/labels.ts +3 -2
  18. package/src/charts/column/compute.ts +60 -27
  19. package/src/charts/column/index.ts +1 -0
  20. package/src/charts/column/labels.ts +2 -1
  21. package/src/charts/line/__tests__/compute.test.ts +2 -2
  22. package/src/charts/line/area.ts +25 -4
  23. package/src/charts/line/compute.ts +15 -5
  24. package/src/compile.ts +26 -1
  25. package/src/compiler/normalize.ts +25 -1
  26. package/src/compiler/types.ts +5 -3
  27. package/src/compiler/validate.ts +120 -5
  28. package/src/index.ts +5 -0
  29. package/src/layout/axes/ticks.ts +37 -8
  30. package/src/layout/axes.ts +11 -4
  31. package/src/layout/dimensions.ts +10 -4
  32. package/src/layout/scales.ts +10 -0
  33. package/src/legend/wrap.ts +1 -1
  34. package/src/tilemap/__tests__/compile-tilemap.test.ts +5 -2
  35. package/src/tilemap/compile-tilemap.ts +41 -29
  36. package/src/tooltips/compute.ts +4 -2
@@ -30,7 +30,7 @@ import { resolveCurve } from './curves';
30
30
  // ---------------------------------------------------------------------------
31
31
 
32
32
  /** Default stroke width for line marks. */
33
- const DEFAULT_STROKE_WIDTH = 2.5;
33
+ const DEFAULT_STROKE_WIDTH = 1.5;
34
34
 
35
35
  /** Sparkline mode uses a thinner stroke since the chart area is tiny and a
36
36
  * 2.5px line reads as clunky. 1.25px keeps the trend legible without dominating. */
@@ -180,6 +180,7 @@ export function computeLineMarks(
180
180
  stroke: strokeColor,
181
181
  strokeWidth:
182
182
  styleOverride?.strokeWidth ??
183
+ spec.markDef.strokeWidth ??
183
184
  (spec.display === 'sparkline' ? SPARKLINE_STROKE_WIDTH : DEFAULT_STROKE_WIDTH),
184
185
  strokeDasharray,
185
186
  opacity: styleOverride?.opacity,
@@ -194,29 +195,38 @@ export function computeLineMarks(
194
195
  // Emit PointMark objects when markDef.point is truthy, or when sequential
195
196
  // color is active (points carry the gradient since SVG paths are single-color).
196
197
  const markPoint = spec.markDef.point;
197
- const showPoints = markPoint === true || markPoint === 'transparent' || isSequentialColor;
198
+ const showPoints =
199
+ markPoint === true ||
200
+ markPoint === 'transparent' ||
201
+ markPoint === 'endpoints' ||
202
+ isSequentialColor;
198
203
 
199
204
  if (showPoints) {
200
205
  const isTransparent = markPoint === 'transparent';
206
+ const isEndpoints = markPoint === 'endpoints';
201
207
  // Also respect per-series showPoints override
202
208
  const seriesShowPoints = styleOverride?.showPoints !== false;
209
+ const lastIdx = pointsWithData.length - 1;
203
210
 
204
211
  for (let i = 0; i < pointsWithData.length; i++) {
205
212
  const p = pointsWithData[i];
206
- const visible = seriesShowPoints && !isTransparent;
213
+ const isEndpoint = i === 0 || i === lastIdx;
214
+ const visible = seriesShowPoints && !isTransparent && (!isEndpoints || isEndpoint);
207
215
  // Sequential color: each point gets colored by its data value
208
216
  let pointColor = color;
209
217
  if (isSequentialColor) {
210
218
  const val = Number(p.row[sequentialColorField!]);
211
219
  pointColor = Number.isFinite(val) ? getSequentialColor(scales, val) : color;
212
220
  }
221
+ const hollow = isEndpoints && visible;
222
+ const pointColorStr = getRepresentativeColor(pointColor);
213
223
  const pointMark: PointMark = {
214
224
  type: 'point',
215
225
  cx: p.x,
216
226
  cy: p.y,
217
227
  r: visible ? DEFAULT_POINT_RADIUS : 0,
218
- fill: pointColor,
219
- stroke: visible ? '#ffffff' : 'transparent',
228
+ fill: hollow ? 'transparent' : pointColorStr,
229
+ stroke: hollow ? pointColorStr : visible ? '#ffffff' : 'transparent',
220
230
  strokeWidth: visible ? 1.5 : 0,
221
231
  fillOpacity: isTransparent ? 0 : 1,
222
232
  data: p.row,
package/src/compile.ts CHANGED
@@ -55,6 +55,7 @@ import { computeAnnotations } from './annotations/compute';
55
55
  // registry on module load. Tests that clear the registry can import
56
56
  // `registerBuiltinRenderers` from `./charts/builtin` to restore defaults.
57
57
  import './charts/builtin';
58
+ import { compileBarList as compileBarListImpl } from './barlist/compile-barlist';
58
59
  import {
59
60
  assignAnimationIndices,
60
61
  computeMarkObstacles,
@@ -816,7 +817,8 @@ function compileLayerIndependent(
816
817
  const theme = resolveTheme(layerSpec.theme ?? leaf1.theme);
817
818
  const axisFontSize = theme.fonts?.sizes?.axisTick ?? 11;
818
819
  const rightAxisWidth = estimateYAxisLabelWidth(leaf1.data, leaf1.encoding, axisFontSize);
819
- const hasRightAxisTitle = !!leaf1.encoding?.y?.axis?.title;
820
+ const yAxisConfig = leaf1.encoding?.y?.axis || undefined;
821
+ const hasRightAxisTitle = !!yAxisConfig?.title;
820
822
  const tickExtent = TICK_LABEL_OFFSET + rightAxisWidth;
821
823
  const bodyFontSize = theme.fonts?.sizes?.body ?? 13;
822
824
  const axisTitleOffset = getAxisTitleOffset(options.width);
@@ -1316,3 +1318,26 @@ export function compileTileMap(
1316
1318
  ): import('@opendata-ai/openchart-core').TileMapLayout {
1317
1319
  return compileTileMapImpl(spec, options);
1318
1320
  }
1321
+
1322
+ // ---------------------------------------------------------------------------
1323
+ // BarList compilation
1324
+ // ---------------------------------------------------------------------------
1325
+
1326
+ /**
1327
+ * Compile a barlist spec into a BarListLayout.
1328
+ *
1329
+ * Takes a raw barlist spec, validates, normalizes, resolves theme and chrome,
1330
+ * computes row layout with proportional bars, builds tooltips, and returns
1331
+ * a BarListLayout ready for rendering.
1332
+ *
1333
+ * @param spec - Raw barlist spec (validated and normalized internally).
1334
+ * @param options - Compile options (width, height, theme, darkMode).
1335
+ * @returns BarListLayout with computed positions and visual properties.
1336
+ * @throws Error if spec is invalid or not a barlist type.
1337
+ */
1338
+ export function compileBarList(
1339
+ spec: unknown,
1340
+ options: CompileOptions,
1341
+ ): import('@opendata-ai/openchart-core').BarListLayout {
1342
+ return compileBarListImpl(spec, options);
1343
+ }
@@ -10,6 +10,7 @@
10
10
 
11
11
  import type {
12
12
  Annotation,
13
+ BarListSpec,
13
14
  ChartSpec,
14
15
  Chrome,
15
16
  ChromeText,
@@ -25,6 +26,7 @@ import type {
25
26
  VizSpec,
26
27
  } from '@opendata-ai/openchart-core';
27
28
  import {
29
+ isBarListSpec,
28
30
  isChartSpec,
29
31
  isGraphSpec,
30
32
  isLayerSpec,
@@ -34,6 +36,7 @@ import {
34
36
  resolveMarkDef,
35
37
  resolveMarkType,
36
38
  } from '@opendata-ai/openchart-core';
39
+ import type { NormalizedBarListSpec } from '../barlist/types';
37
40
  import type { NormalizedSankeySpec } from '../sankey/types';
38
41
  import { STATE_CODE_SET } from '../tilemap/layout';
39
42
  import type { NormalizedTileMapSpec } from '../tilemap/types';
@@ -206,6 +209,7 @@ function normalizeLabels(labels?: LabelSpec): NormalizedChartSpec['labels'] {
206
209
  format: labels.format ?? '',
207
210
  prefix: labels.prefix ?? '',
208
211
  offsets: labels.offsets,
212
+ color: labels.color,
209
213
  };
210
214
  }
211
215
 
@@ -382,6 +386,23 @@ function normalizeTileMapSpec(spec: TileMapSpec, warnings: string[]): Normalized
382
386
  };
383
387
  }
384
388
 
389
+ function normalizeBarListSpec(spec: BarListSpec, _warnings: string[]): NormalizedBarListSpec {
390
+ return {
391
+ type: 'barlist',
392
+ data: spec.data,
393
+ encoding: spec.encoding,
394
+ barHeight: spec.barHeight ?? 6,
395
+ cornerRadius: spec.cornerRadius ?? 'pill',
396
+ maxItems: spec.maxItems ?? 20,
397
+ chrome: normalizeChrome(spec.chrome),
398
+ theme: spec.theme ?? {},
399
+ darkMode: spec.darkMode ?? 'off',
400
+ watermark: spec.watermark ?? true,
401
+ animation: spec.animation ?? true,
402
+ valueFormat: spec.valueFormat,
403
+ };
404
+ }
405
+
385
406
  // ---------------------------------------------------------------------------
386
407
  // Public API
387
408
  // ---------------------------------------------------------------------------
@@ -419,9 +440,12 @@ export function normalizeSpec(spec: VizSpec, warnings: string[] = []): Normalize
419
440
  if (isTileMapSpec(spec)) {
420
441
  return normalizeTileMapSpec(spec, warnings);
421
442
  }
443
+ if (isBarListSpec(spec)) {
444
+ return normalizeBarListSpec(spec, warnings);
445
+ }
422
446
  // Should never happen after validation
423
447
  throw new Error(
424
- `Unknown spec shape. Expected mark (chart), layer, type: 'table', type: 'graph', type: 'sankey', or type: 'tilemap'.`,
448
+ `Unknown spec shape. Expected mark (chart), layer, type: 'table', type: 'graph', type: 'sankey', type: 'tilemap', or type: 'barlist'.`,
425
449
  );
426
450
  }
427
451
 
@@ -29,6 +29,7 @@ import type {
29
29
  ScaleConfig,
30
30
  ThemeConfig,
31
31
  } from '@opendata-ai/openchart-core';
32
+ import type { NormalizedBarListSpec } from '../barlist/types';
32
33
  import type { NormalizedSankeySpec } from '../sankey/types';
33
34
  import type { NormalizedTileMapSpec } from '../tilemap/types';
34
35
 
@@ -101,9 +102,9 @@ export interface NormalizedChartSpec {
101
102
  encoding: Encoding;
102
103
  chrome: NormalizedChrome;
103
104
  annotations: Annotation[];
104
- /** Normalized label configuration with defaults applied. density, format, and prefix are always set; offsets stays optional. */
105
+ /** Normalized label configuration with defaults applied. density, format, and prefix are always set; offsets and color stay optional. */
105
106
  labels: Required<Pick<LabelConfig, 'density' | 'format' | 'prefix'>> &
106
- Pick<LabelConfig, 'offsets'>;
107
+ Pick<LabelConfig, 'offsets' | 'color'>;
107
108
  /** Legend configuration (position override). */
108
109
  legend?: LegendConfig;
109
110
  responsive: boolean;
@@ -164,7 +165,8 @@ export type NormalizedSpec =
164
165
  | NormalizedTableSpec
165
166
  | NormalizedGraphSpec
166
167
  | NormalizedSankeySpec
167
- | NormalizedTileMapSpec;
168
+ | NormalizedTileMapSpec
169
+ | NormalizedBarListSpec;
168
170
 
169
171
  // ---------------------------------------------------------------------------
170
172
  // Validation types
@@ -759,6 +759,117 @@ function validateTileMapSpec(spec: Record<string, unknown>, errors: ValidationEr
759
759
  }
760
760
  }
761
761
 
762
+ // ---------------------------------------------------------------------------
763
+ // BarList validation
764
+ // ---------------------------------------------------------------------------
765
+
766
+ function validateBarListSpec(spec: Record<string, unknown>, errors: ValidationError[]): void {
767
+ if (!Array.isArray(spec.data)) {
768
+ errors.push({
769
+ message: 'Spec error: barlist spec requires a "data" array',
770
+ path: 'data',
771
+ code: 'INVALID_TYPE',
772
+ suggestion:
773
+ 'Provide data as an array of objects, e.g. data: [{ label: "Category A", value: 42 }]',
774
+ });
775
+ return;
776
+ }
777
+
778
+ if (spec.data.length === 0) {
779
+ errors.push({
780
+ message: 'Spec error: "data" array must be non-empty',
781
+ path: 'data',
782
+ code: 'EMPTY_DATA',
783
+ suggestion: 'Add at least one data row',
784
+ });
785
+ return;
786
+ }
787
+
788
+ const firstRow = spec.data[0] as unknown;
789
+ if (typeof firstRow !== 'object' || firstRow === null || Array.isArray(firstRow)) {
790
+ errors.push({
791
+ message: 'Spec error: each item in "data" must be a plain object',
792
+ path: 'data[0]',
793
+ code: 'INVALID_TYPE',
794
+ suggestion: 'Each data item should be an object, e.g. { label: "Category A", value: 42 }',
795
+ });
796
+ return;
797
+ }
798
+
799
+ if (!spec.encoding || typeof spec.encoding !== 'object') {
800
+ errors.push({
801
+ message:
802
+ 'Spec error: barlist spec requires an "encoding" object with label and value channels',
803
+ path: 'encoding',
804
+ code: 'MISSING_FIELD',
805
+ suggestion:
806
+ 'Add an encoding object, e.g. encoding: { label: { field: "name", type: "nominal" }, value: { field: "count", type: "quantitative" } }',
807
+ });
808
+ return;
809
+ }
810
+
811
+ const encoding = spec.encoding as Record<string, unknown>;
812
+ const dataColumns = new Set(Object.keys(firstRow as Record<string, unknown>));
813
+ const availableColumns = [...dataColumns].join(', ');
814
+
815
+ for (const channel of ['label', 'value'] as const) {
816
+ const ch = encoding[channel] as Record<string, unknown> | undefined;
817
+ if (!ch || typeof ch !== 'object') {
818
+ errors.push({
819
+ message: `Spec error: barlist encoding requires "${channel}" channel`,
820
+ path: `encoding.${channel}`,
821
+ code: 'MISSING_FIELD',
822
+ suggestion: `Add encoding.${channel} with a field from your data (${availableColumns}). Example: ${channel}: { field: "${[...dataColumns][0] ?? 'myField'}", type: "${channel === 'value' ? 'quantitative' : 'nominal'}" }`,
823
+ });
824
+ continue;
825
+ }
826
+
827
+ if (!ch.field || typeof ch.field !== 'string') {
828
+ errors.push({
829
+ message: `Spec error: encoding.${channel} must have a "field" string`,
830
+ path: `encoding.${channel}.field`,
831
+ code: 'MISSING_FIELD',
832
+ suggestion: `Add a field name from your data columns: ${availableColumns}`,
833
+ });
834
+ continue;
835
+ }
836
+
837
+ if (!dataColumns.has(ch.field as string)) {
838
+ errors.push({
839
+ message: `Spec error: encoding.${channel}.field "${ch.field}" does not exist in data. Available columns: ${availableColumns}`,
840
+ path: `encoding.${channel}.field`,
841
+ code: 'DATA_FIELD_MISSING',
842
+ suggestion: `Use one of the available data columns: ${availableColumns}`,
843
+ });
844
+ }
845
+ }
846
+
847
+ // Validate optional encoding channels
848
+ for (const channel of ['subtitle', 'color', 'tooltip'] as const) {
849
+ const ch = encoding[channel] as Record<string, unknown> | undefined;
850
+ if (!ch) continue;
851
+ const field = ch.field;
852
+ if (field && typeof field === 'string' && !dataColumns.has(field)) {
853
+ errors.push({
854
+ message: `Spec error: encoding.${channel}.field "${field}" does not exist in data. Available columns: ${availableColumns}`,
855
+ path: `encoding.${channel}.field`,
856
+ code: 'DATA_FIELD_MISSING',
857
+ suggestion: `Use one of the available data columns: ${availableColumns}`,
858
+ });
859
+ }
860
+ }
861
+
862
+ if (spec.darkMode !== undefined && !VALID_DARK_MODES.has(spec.darkMode as string)) {
863
+ errors.push({
864
+ message: 'Spec error: darkMode must be "auto", "force", or "off"',
865
+ path: 'darkMode',
866
+ code: 'INVALID_VALUE',
867
+ suggestion:
868
+ 'Use one of: "auto" (system preference), "force" (always dark), or "off" (always light)',
869
+ });
870
+ }
871
+ }
872
+
762
873
  // ---------------------------------------------------------------------------
763
874
  // Layer validation
764
875
  // ---------------------------------------------------------------------------
@@ -897,19 +1008,21 @@ export function validateSpec(spec: unknown): ValidationResult {
897
1008
  const isGraph = obj.type === 'graph';
898
1009
  const isSankey = obj.type === 'sankey';
899
1010
  const isTileMap = obj.type === 'tilemap';
900
- const isLayer = hasLayer && !isTable && !isGraph && !isSankey && !isTileMap;
901
- const isChart = hasMark && !hasLayer && !isTable && !isGraph && !isSankey && !isTileMap;
1011
+ const isBarList = obj.type === 'barlist';
1012
+ const isLayer = hasLayer && !isTable && !isGraph && !isSankey && !isTileMap && !isBarList;
1013
+ const isChart =
1014
+ hasMark && !hasLayer && !isTable && !isGraph && !isSankey && !isTileMap && !isBarList;
902
1015
 
903
- if (!isChart && !isTable && !isGraph && !isSankey && !isTileMap && !isLayer) {
1016
+ if (!isChart && !isTable && !isGraph && !isSankey && !isTileMap && !isBarList && !isLayer) {
904
1017
  return {
905
1018
  valid: false,
906
1019
  errors: [
907
1020
  {
908
1021
  message:
909
- 'Spec error: spec must have a "mark" field for charts, a "layer" array for layered charts, or a "type" field for tables/graphs/sankey/tilemap',
1022
+ 'Spec error: spec must have a "mark" field for charts, a "layer" array for layered charts, or a "type" field for tables/graphs/sankey/tilemap/barlist',
910
1023
  path: 'mark',
911
1024
  code: 'MISSING_FIELD',
912
- suggestion: `Add a "mark" field for charts (e.g. mark: "bar"), a "layer" array for layered charts, or a "type" field for tables/graphs/sankey/tilemap (type: "table", type: "graph", type: "sankey", or type: "tilemap"). Valid mark types: ${[...MARK_TYPES].join(', ')}`,
1025
+ suggestion: `Add a "mark" field for charts (e.g. mark: "bar"), a "layer" array for layered charts, or a "type" field (type: "table", type: "graph", type: "sankey", type: "tilemap", or type: "barlist"). Valid mark types: ${[...MARK_TYPES].join(', ')}`,
913
1026
  },
914
1027
  ],
915
1028
  normalized: null,
@@ -956,6 +1069,8 @@ export function validateSpec(spec: unknown): ValidationResult {
956
1069
  validateSankeySpec(obj, errors);
957
1070
  } else if (isTileMap) {
958
1071
  validateTileMapSpec(obj, errors);
1072
+ } else if (isBarList) {
1073
+ validateBarListSpec(obj, errors);
959
1074
  }
960
1075
 
961
1076
  if (errors.length > 0) {
package/src/index.ts CHANGED
@@ -13,6 +13,7 @@
13
13
  // ---------------------------------------------------------------------------
14
14
 
15
15
  export {
16
+ compileBarList,
16
17
  compileChart,
17
18
  compileGraph,
18
19
  compileLayer,
@@ -48,6 +49,8 @@ export type { NormalizedSankeySpec } from './sankey/types';
48
49
  // TileMap compilation types
49
50
  // ---------------------------------------------------------------------------
50
51
 
52
+ export type { NormalizedBarListSpec } from './barlist/types';
53
+
51
54
  export type { NormalizedTileMapSpec } from './tilemap/types';
52
55
 
53
56
  // ---------------------------------------------------------------------------
@@ -102,6 +105,8 @@ export {
102
105
  // ---------------------------------------------------------------------------
103
106
 
104
107
  export type {
108
+ BarListLayout,
109
+ BarListSpec,
105
110
  ChartLayout,
106
111
  ChartSpec,
107
112
  CompileOptions,
@@ -38,13 +38,18 @@ import type { D3CategoricalScale, D3ContinuousScale, ResolvedScale } from '../sc
38
38
  * "full" is the publication-ready default; "reduced" and "minimal" step down as the
39
39
  * responsive breakpoint system shifts to smaller containers.
40
40
  *
41
+ * Y full is set to 40px/tick (tighter than Observable Plot's 50) because chart areas
42
+ * are measured after chrome subtraction. A 400px container with title+subtitle leaves
43
+ * ~270px of chart area; 55px/tick would only produce 4 ticks. 40px/tick reaches 5-6
44
+ * on typical chart areas (150-300px) and the overlap check acts as a safety net.
45
+ *
41
46
  * @internal — these are tuning constants, not part of the configuration API.
42
47
  * Consumers should configure tick density through `axis.tickCount` on the spec.
43
48
  */
44
49
  const Y_PX_PER_TICK: Record<AxisLabelDensity, number> = {
45
- full: 55,
46
- reduced: 90,
47
- minimal: 140,
50
+ full: 40,
51
+ reduced: 70,
52
+ minimal: 120,
48
53
  };
49
54
 
50
55
  const X_PX_PER_TICK: Record<AxisLabelDensity, number> = {
@@ -125,7 +130,8 @@ const TEMPORAL_SCALE_TYPES = new Set(['time', 'utc']);
125
130
 
126
131
  /** Format a tick value based on the scale type. */
127
132
  function formatTickLabel(value: unknown, resolvedScale: ResolvedScale): string {
128
- const formatStr = resolvedScale.channel.axis?.format;
133
+ const axisConfig = resolvedScale.channel.axis || undefined;
134
+ const formatStr = axisConfig?.format;
129
135
 
130
136
  if (TEMPORAL_SCALE_TYPES.has(resolvedScale.type)) {
131
137
  const temporalFmt = buildTemporalFormatter(formatStr);
@@ -174,8 +180,8 @@ export function continuousTicks(
174
180
  }));
175
181
  }
176
182
 
177
- const explicitCount = resolvedScale.channel.axis?.tickCount;
178
- const count = explicitCount ?? targetCount ?? TICK_COUNTS[density];
183
+ const axCfg = resolvedScale.channel.axis || undefined;
184
+ const count = axCfg?.tickCount ?? targetCount ?? TICK_COUNTS[density];
179
185
  return buildContinuousTicks(resolvedScale, count);
180
186
  }
181
187
 
@@ -194,7 +200,29 @@ export function buildContinuousTicks(resolvedScale: ResolvedScale, count: number
194
200
  return continuousTicks(resolvedScale, 'full');
195
201
  }
196
202
  const raw: unknown[] = scale.ticks(count);
197
- return raw.map((value: unknown) => ({
203
+
204
+ // D3 log scales ignore the count hint and return ticks at every sub-power
205
+ // position (e.g. 5, 6, 7, 8, 9, 10, 20, 30... for a domain of [5, 25000]).
206
+ // Filter down to powers of the base only when the raw set overshoots.
207
+ let ticks = raw;
208
+ if (resolvedScale.type === 'log' && raw.length > count) {
209
+ const base = resolvedScale.channel.scale?.base ?? 10;
210
+ const logBase = Math.log(base);
211
+ const powered = raw.filter((v) => {
212
+ const n = v as number;
213
+ if (n <= 0) return false;
214
+ const exp = Math.log(n) / logBase;
215
+ return Math.abs(exp - Math.round(exp)) < 1e-9;
216
+ });
217
+ // Only use the filtered set if it has at least 2 ticks; otherwise fall back
218
+ // to raw ticks. This handles domains like [5, 9] (no powers of 10 at all) or
219
+ // [5, 50] (only one power: 10) where filtering would leave too few meaningful ticks.
220
+ if (powered.length >= 2) {
221
+ ticks = powered;
222
+ }
223
+ }
224
+
225
+ return ticks.map((value: unknown) => ({
198
226
  value,
199
227
  position: scale(value as number & Date) as number,
200
228
  label: formatTickLabel(value, resolvedScale),
@@ -230,7 +258,8 @@ export function categoricalTicks(
230
258
  ): AxisTick[] {
231
259
  const scale = resolvedScale.scale as D3CategoricalScale;
232
260
  const domain: string[] = scale.domain();
233
- const explicitTickCount = resolvedScale.channel.axis?.tickCount;
261
+ const catAxisCfg = resolvedScale.channel.axis || undefined;
262
+ const explicitTickCount = catAxisCfg?.tickCount;
234
263
 
235
264
  let selectedValues = domain;
236
265
 
@@ -44,9 +44,16 @@ export { thinTicksUntilFit, ticksOverlap } from './axes/thinning';
44
44
  * Below these pixel heights, we step down the density regardless of the
45
45
  * width-based strategy. This prevents overlapping y-axis labels in short
46
46
  * containers like thumbnail previews.
47
+ *
48
+ * These thresholds apply to the chart area height (after chrome/margins),
49
+ * not the total container height. A 400px container with title+subtitle
50
+ * leaves ~270px of chart area; a 320px container leaves ~186px. The old
51
+ * HEIGHT_REDUCED_THRESHOLD of 200 kicked in on nearly every common chart
52
+ * size, producing only 3 ticks. Lowering to 100 keeps 'full' density for
53
+ * all but the most compact thumbnail-style containers.
47
54
  */
48
- const HEIGHT_MINIMAL_THRESHOLD = 120;
49
- const HEIGHT_REDUCED_THRESHOLD = 200;
55
+ const HEIGHT_MINIMAL_THRESHOLD = 80;
56
+ const HEIGHT_REDUCED_THRESHOLD = 100;
50
57
 
51
58
  /**
52
59
  * Width thresholds for reducing x-axis tick density.
@@ -264,7 +271,7 @@ export function computeAxes(
264
271
  const { fontSize } = tickLabelStyle;
265
272
  const { fontWeight } = tickLabelStyle;
266
273
 
267
- if (scales.x && !dataContext?.skipX) {
274
+ if (scales.x && !dataContext?.skipX && scales.x.channel.axis !== false) {
268
275
  const axisConfig = scales.x.channel.axis;
269
276
  const isContinuousX =
270
277
  scales.x.type !== 'band' && scales.x.type !== 'point' && scales.x.type !== 'ordinal';
@@ -366,7 +373,7 @@ export function computeAxes(
366
373
  };
367
374
  }
368
375
 
369
- if (scales.y && !dataContext?.skipY) {
376
+ if (scales.y && !dataContext?.skipY && scales.y.channel.axis !== false) {
370
377
  const axisConfig = scales.y.channel.axis;
371
378
  const isContinuousY =
372
379
  scales.y.type !== 'band' && scales.y.type !== 'point' && scales.y.type !== 'ordinal';
@@ -114,7 +114,9 @@ function getMinChartDims(display: import('@opendata-ai/openchart-core').Display)
114
114
  */
115
115
  function getSparklinePad(spec: NormalizedChartSpec): number {
116
116
  const strokeWidth = (spec.markDef as { strokeWidth?: number }).strokeWidth ?? 2;
117
- return Math.max(strokeWidth / 2 + 1, 2);
117
+ const hasPoints = !!(spec.markDef as { point?: unknown }).point;
118
+ const pointRadius = hasPoints ? 3 : 0;
119
+ return Math.max(strokeWidth / 2 + 1, pointRadius + 1, 2);
118
120
  }
119
121
 
120
122
  // ---------------------------------------------------------------------------
@@ -222,12 +224,15 @@ export function computeDimensions(
222
224
  // Estimate x-axis height below chart area: tick labels sit 14px below,
223
225
  // axis title sits 35px below. These extend past the chart area bottom
224
226
  // and source/footer chrome must be positioned below them.
225
- const xAxis = encoding.x?.axis as (Record<string, unknown> & { labelAngle?: number }) | undefined;
227
+ const xAxisSuppressed = encoding.x?.axis === false;
228
+ const xAxis = (!xAxisSuppressed && encoding.x?.axis) as
229
+ | (Record<string, unknown> & { labelAngle?: number })
230
+ | undefined;
226
231
  const hasXAxisLabel = !!xAxis?.title;
227
232
  const xTickAngle = xAxis?.labelAngle;
228
233
 
229
234
  let xAxisHeight: number;
230
- if (isRadial) {
235
+ if (isRadial || xAxisSuppressed) {
231
236
  xAxisHeight = 0;
232
237
  } else if (xTickAngle && Math.abs(xTickAngle) > 10) {
233
238
  // Rotated labels: estimate height from the longest label text.
@@ -339,7 +344,8 @@ export function computeDimensions(
339
344
  }
340
345
 
341
346
  // Dynamic left margin for y-axis labels
342
- if (encoding.y && !isRadial) {
347
+ const yAxisSuppressed = encoding.y?.axis === false;
348
+ if (encoding.y && !isRadial && !yAxisSuppressed) {
343
349
  if (
344
350
  spec.markType === 'bar' ||
345
351
  spec.markType === 'circle' ||
@@ -256,6 +256,16 @@ function buildLinearScale(
256
256
 
257
257
  if (!channel.scale?.domain && channel.scale?.nice !== false) {
258
258
  scale.nice();
259
+
260
+ // nice() can round the domain min down to 0 even when zero: false.
261
+ // Re-nice with more ticks to tighten the domain around the data range.
262
+ if (channel.scale?.zero === false) {
263
+ const [nicedMin, nicedMax] = scale.domain();
264
+ if (nicedMin < domainMin || nicedMax > domainMax) {
265
+ scale.domain([domainMin, domainMax]);
266
+ scale.nice(20);
267
+ }
268
+ }
259
269
  }
260
270
  applyContinuousConfig(scale, channel);
261
271
 
@@ -32,7 +32,7 @@ export const ENTRY_GAP = 16;
32
32
  export const ENTRY_GAP_COMPACT = 10;
33
33
 
34
34
  /** Default gap between legend bounds and chart area. Zero on narrow viewports. */
35
- export const LEGEND_GAP = 4;
35
+ export const LEGEND_GAP = 8;
36
36
 
37
37
  /** Gap between legend and chart area, responsive to container width. */
38
38
  export function legendGap(width: number): number {
@@ -112,7 +112,7 @@ describe('compileTileMap', () => {
112
112
  }
113
113
  });
114
114
 
115
- it('data tiles have fill colors from the sequential palette', () => {
115
+ it('data tiles use opacity-based encoding with a single base color', () => {
116
116
  const result = compileTileMap(basicSpec, defaultOptions);
117
117
 
118
118
  const dataTiles = result.tiles.filter((t) => t.hasData);
@@ -122,7 +122,10 @@ describe('compileTileMap', () => {
122
122
  }
123
123
 
124
124
  const fills = new Set(dataTiles.map((t) => t.fill));
125
- expect(fills.size).toBeGreaterThan(1);
125
+ expect(fills.size).toBe(1);
126
+
127
+ const opacities = new Set(dataTiles.map((t) => t.fillOpacity));
128
+ expect(opacities.size).toBeGreaterThan(1);
126
129
  });
127
130
 
128
131
  it('compiles tabular DataRow[] data with encoding', () => {