@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.
- package/dist/index.d.ts +2 -8
- package/dist/index.js +793 -91
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/compile-snapshot.test.ts.snap +62 -0
- package/src/__tests__/annotation-behavior.test.ts +131 -0
- package/src/__tests__/facet.test.ts +144 -0
- package/src/annotations/geometry.ts +7 -1
- package/src/annotations/resolve-text.ts +6 -0
- package/src/compile/layer.ts +4 -0
- package/src/compile/size-scale.ts +2 -0
- package/src/compile/spec-sugar.ts +10 -1
- package/src/compile.ts +106 -8
- package/src/compiler/__tests__/keys.test.ts +3 -9
- package/src/compiler/__tests__/validate-did-you-mean.test.ts +84 -0
- package/src/compiler/__tests__/validate-near-miss.test.ts +162 -0
- package/src/compiler/__tests__/validate.test.ts +102 -0
- package/src/compiler/keys.ts +5 -4
- package/src/compiler/normalize.ts +1 -0
- package/src/compiler/validate.ts +326 -43
- package/src/geo/__tests__/compile-map.test.ts +507 -0
- package/src/geo/compile-map.ts +555 -35
- package/src/geo/projections.ts +21 -1
- package/src/geo/types.ts +2 -0
- package/src/layout/axes.ts +5 -4
- package/src/legend/compute.ts +4 -3
package/src/geo/projections.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
}
|
package/src/layout/axes.ts
CHANGED
|
@@ -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
|
-
|
|
709
|
-
|
|
710
|
-
const
|
|
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 +
|
|
714
|
+
y: chartArea.y + chartArea.height + titleY,
|
|
714
715
|
};
|
|
715
716
|
}
|
|
716
717
|
}
|
package/src/legend/compute.ts
CHANGED
|
@@ -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
|
-
|
|
393
|
-
|
|
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) {
|