@opendata-ai/openchart-engine 2.11.0 → 2.12.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opendata-ai/openchart-engine",
3
- "version": "2.11.0",
3
+ "version": "2.12.1",
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",
@@ -45,7 +45,7 @@
45
45
  "typecheck": "tsc --noEmit"
46
46
  },
47
47
  "dependencies": {
48
- "@opendata-ai/openchart-core": "2.11.0",
48
+ "@opendata-ai/openchart-core": "2.12.1",
49
49
  "d3-array": "^3.2.0",
50
50
  "d3-format": "^3.1.2",
51
51
  "d3-interpolate": "^3.0.0",
@@ -410,12 +410,13 @@ function resolveRangeAnnotation(
410
410
 
411
411
  // Label positioned within the range, with optional offset.
412
412
  // labelAnchor controls horizontal placement:
413
- // "left" (default): left edge, text-anchor start
414
- // "top"/"auto": horizontally centered, text-anchor middle
413
+ // "top" (default): horizontally centered, text-anchor middle
414
+ // "left": left edge, text-anchor start
415
415
  // "right": right edge, text-anchor end
416
+ // "bottom"/"auto": horizontally centered, text-anchor middle
416
417
  let label: ResolvedLabel | undefined;
417
418
  if (annotation.label) {
418
- const anchor = annotation.labelAnchor ?? 'left';
419
+ const anchor = annotation.labelAnchor ?? 'top';
419
420
  const centered = anchor === 'top' || anchor === 'bottom' || anchor === 'auto';
420
421
  const baseDx = centered ? 0 : anchor === 'right' ? -4 : 4;
421
422
  const baseDy = 14;
@@ -428,6 +429,8 @@ function resolveRangeAnnotation(
428
429
  style.textAnchor = 'end';
429
430
  }
430
431
 
432
+ // Position label horizontally centered within the range band by default.
433
+ // For left/right anchors, position at the respective edge.
431
434
  const baseX = centered ? x + width / 2 : anchor === 'right' ? x + width : x;
432
435
 
433
436
  label = {
@@ -83,6 +83,11 @@ function buildFields(row: DataRow, encoding: Encoding, color?: string): TooltipF
83
83
 
84
84
  /** Determine the title for a tooltip based on encoding. */
85
85
  function getTooltipTitle(row: DataRow, encoding: Encoding): string | undefined {
86
+ // Detail channel provides an explicit label (e.g. district name in scatter)
87
+ if (encoding.detail) {
88
+ return String(row[encoding.detail.field] ?? '');
89
+ }
90
+
86
91
  // For charts with a temporal x-axis, use the date as the title
87
92
  if (encoding.x?.type === 'temporal') {
88
93
  return formatValue(row[encoding.x.field], 'temporal');