@opendata-ai/openchart-engine 8.0.0-rc.1 → 8.0.0-rc.10

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.
@@ -12,8 +12,18 @@ export function createProjection(
12
12
  width: number,
13
13
  height: number,
14
14
  geojson: GeoPermissibleObjects,
15
+ inset = 0,
15
16
  ): GeoProjection | GeoIdentityTransform {
16
17
  if (type === 'identity') {
18
+ if (inset > 0) {
19
+ return geoIdentity().fitExtent(
20
+ [
21
+ [inset, inset],
22
+ [width - inset, height - inset],
23
+ ],
24
+ geojson,
25
+ );
26
+ }
17
27
  return geoIdentity().fitSize([width, height], geojson);
18
28
  }
19
29
 
@@ -21,7 +31,17 @@ export function createProjection(
21
31
  type === 'albersUsa' ? geoAlbersUsa() : type === 'equalEarth' ? geoEqualEarth() : geoMercator();
22
32
 
23
33
  const fitGeometry = type === 'mercator' ? excludePolarFeatures(geojson) : geojson;
24
- projection.fitSize([width, height], fitGeometry);
34
+ if (inset > 0) {
35
+ projection.fitExtent(
36
+ [
37
+ [inset, inset],
38
+ [width - inset, height - inset],
39
+ ],
40
+ fitGeometry,
41
+ );
42
+ } else {
43
+ projection.fitSize([width, height], fitGeometry);
44
+ }
25
45
  return projection;
26
46
  }
27
47
 
package/src/geo/types.ts CHANGED
@@ -4,6 +4,7 @@ import type {
4
4
  LegendConfig,
5
5
  MapEncoding,
6
6
  MapGeo,
7
+ MapPointsLayer,
7
8
  ThemeConfig,
8
9
  } from '@opendata-ai/openchart-core';
9
10
 
@@ -21,4 +22,5 @@ export interface NormalizedMapSpec {
21
22
  watermark: boolean;
22
23
  animation?: AnimationSpec;
23
24
  valueFormat?: string;
25
+ points?: MapPointsLayer;
24
26
  }
@@ -25,6 +25,7 @@ import {
25
25
  estimateTextWidth,
26
26
  getAxisTitleOffset,
27
27
  truncateRotatedLabel,
28
+ X_AXIS_TITLE_BAND,
28
29
  X_AXIS_TITLE_BAND_ROTATED,
29
30
  } from '@opendata-ai/openchart-core';
30
31
  import type { ScaleBand } from 'd3-scale';
@@ -705,12 +706,12 @@ export function computeAxes(
705
706
  });
706
707
 
707
708
  if (result.x.label) {
708
- // Rotated: place the title just below the tick band (extent already
709
- // includes the rotated label height and the title band). Flat: fixed 35px.
710
- const rotatedBand = isRotated ? result.x.extent - X_AXIS_TITLE_BAND_ROTATED + 14 : 35;
709
+ const titleBand = isRotated ? X_AXIS_TITLE_BAND_ROTATED : X_AXIS_TITLE_BAND;
710
+ const tickBand = result.x.extent - titleBand;
711
+ const titleY = isRotated ? tickBand + 14 : tickBand + 9;
711
712
  result.x.titlePosition = {
712
713
  x: chartArea.x + chartArea.width / 2,
713
- y: chartArea.y + chartArea.height + rotatedBand,
714
+ y: chartArea.y + chartArea.height + titleY,
714
715
  };
715
716
  }
716
717
  }
@@ -388,9 +388,10 @@ export function computeLegendContent(
388
388
  lineHeight: 1.3,
389
389
  };
390
390
 
391
- // Resolve position: spec-level override wins, then responsive strategy
392
- const resolvedPosition =
393
- spec.legend?.position ?? (strategy.legendPosition === 'right' ? 'right' : 'top');
391
+ // Resolve position: spec-level override wins, then responsive strategy.
392
+ // 'top-left' is a map-only overlay position; charts fold it into 'top'.
393
+ const specPosition = spec.legend?.position === 'top-left' ? 'top' : spec.legend?.position;
394
+ const resolvedPosition = specPosition ?? (strategy.legendPosition === 'right' ? 'right' : 'top');
394
395
 
395
396
  // No entries = empty legend with no space
396
397
  if (entries.length === 0) {