@lionad/cx-comps-tanstack-charts 0.1.0-alpha.16 → 0.1.0-alpha.18
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.mjs +28 -4
- package/dist/shared/translate/types.d.ts +3 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -23,7 +23,7 @@ import { treeLayout } from "@tanstack/charts/hierarchy/tree";
|
|
|
23
23
|
import { treemap } from "@tanstack/charts/hierarchy/treemap";
|
|
24
24
|
import { forceLayout } from "@tanstack/charts/network/force";
|
|
25
25
|
import { sankeyDiagram } from "@tanstack/charts/network/sankey";
|
|
26
|
-
import { geoAlbersUsa, geoEqualEarth, geoIdentity, geoMercator, geoNaturalEarth1, geoOrthographic } from "d3-geo";
|
|
26
|
+
import { geoAlbersUsa, geoEqualEarth, geoEquirectangular, geoIdentity, geoMercator, geoNaturalEarth1, geoOrthographic } from "d3-geo";
|
|
27
27
|
import { decorative } from "@tanstack/charts/mark/decorative";
|
|
28
28
|
import { tooltip } from "@tanstack/charts/tooltip";
|
|
29
29
|
import { viewGrid } from "@tanstack/charts/view";
|
|
@@ -1097,19 +1097,23 @@ function translateForceGraph(spec, datasets) {
|
|
|
1097
1097
|
yDomain: [graph.yDomain[0], graph.yDomain[1]]
|
|
1098
1098
|
};
|
|
1099
1099
|
}
|
|
1100
|
-
/** d3-geo 投影名称枚举 → 工厂(descriptor.type 形态:() => projection
|
|
1100
|
+
/** d3-geo 投影名称枚举 → 工厂(descriptor.type 形态:() => projection);
|
|
1101
|
+
* 等距圆柱必须用 equirectangular 而非 identity:identity 的 stream 无 sphere 方法,
|
|
1102
|
+
* fit/渲染 Sphere 几何(球面描边层)直接抛 TypeError */
|
|
1101
1103
|
const GEO_PROJECTION_FACTORIES = {
|
|
1102
1104
|
mercator: geoMercator,
|
|
1103
1105
|
orthographic: geoOrthographic,
|
|
1104
1106
|
naturalEarth1: geoNaturalEarth1,
|
|
1105
1107
|
albersUsa: geoAlbersUsa,
|
|
1106
1108
|
equalEarth: geoEqualEarth,
|
|
1109
|
+
equirectangular: geoEquirectangular,
|
|
1107
1110
|
identity: geoIdentity
|
|
1108
1111
|
};
|
|
1109
1112
|
/** geoShape:projection 名称枚举 → descriptor {type, fit, inset};fit:'data' 由库拟合数据本体,{data:'<name>'} 拟合另一命名数据集 */
|
|
1110
1113
|
function translateGeoShape(spec, datasets) {
|
|
1111
1114
|
const rows = resolveMarkData(spec.data, datasets);
|
|
1112
1115
|
const projectionName = spec.projection ?? "mercator";
|
|
1116
|
+
if (typeof projectionName === "object") throw new Error("translateGeoShape: projection {$by} 仅允许出现在 facet chart 子模板内");
|
|
1113
1117
|
const factory = GEO_PROJECTION_FACTORIES[projectionName];
|
|
1114
1118
|
if (!factory) throw new Error(`translateGeoShape: 未知投影 "${String(projectionName)}"`);
|
|
1115
1119
|
const options = { projection: {
|
|
@@ -1138,6 +1142,25 @@ function translateGeoShape(spec, datasets) {
|
|
|
1138
1142
|
return geoShape(rows, options);
|
|
1139
1143
|
}
|
|
1140
1144
|
/**
|
|
1145
|
+
* facet 子模板按组实例化:深度遍历,把 {$by:{组名:值}} 形态字段替换为当前组映射值。
|
|
1146
|
+
* 未声明 $by 的字段原样保留;$by 表未命中当前组时抛错(静默回退会让分面悄悄同参)。
|
|
1147
|
+
*/
|
|
1148
|
+
function instantiateFacetTemplate(node, groupKey) {
|
|
1149
|
+
if (Array.isArray(node)) return node.map((item) => instantiateFacetTemplate(item, groupKey));
|
|
1150
|
+
if (node && typeof node === "object") {
|
|
1151
|
+
const record = node;
|
|
1152
|
+
const keys = Object.keys(record);
|
|
1153
|
+
if (keys.length === 1 && keys[0] === "$by") {
|
|
1154
|
+
const table = record.$by;
|
|
1155
|
+
const hit = table[String(groupKey)];
|
|
1156
|
+
if (hit === void 0) throw new Error(`instantiateFacetTemplate: $by 映射未命中分组 "${String(groupKey)}"(可用键: ${Object.keys(table).join(", ")})`);
|
|
1157
|
+
return hit;
|
|
1158
|
+
}
|
|
1159
|
+
return Object.fromEntries(Object.entries(record).map(([k, v]) => [k, instantiateFacetTemplate(v, groupKey)]));
|
|
1160
|
+
}
|
|
1161
|
+
return node;
|
|
1162
|
+
}
|
|
1163
|
+
/**
|
|
1141
1164
|
* facet:chart 回调固化为递归子 spec 翻译——translateChild 由 definition.ts 注入
|
|
1142
1165
|
* (子 spec 翻译与顶层同路径,仅数据集换为 facet 分组行;规避 composite ↔ definition 循环 import)。
|
|
1143
1166
|
* label 语义:true 显示分组 key 标签(库的函数形态不可 JSON,布尔即可覆盖声明式场景)。
|
|
@@ -1147,9 +1170,10 @@ function translateFacet(spec, datasets, translateChild) {
|
|
|
1147
1170
|
if (!spec.by) throw new Error("translateFacet: facet 必须声明 by 分组字段");
|
|
1148
1171
|
if (!spec.chart) throw new Error("translateFacet: facet 必须声明 chart 子 spec 模板");
|
|
1149
1172
|
const childTemplate = spec.chart;
|
|
1173
|
+
const byField = spec.by;
|
|
1150
1174
|
const options = {
|
|
1151
|
-
by:
|
|
1152
|
-
chart: (facetRows) => translateChild(childTemplate, facetRows)
|
|
1175
|
+
by: byField,
|
|
1176
|
+
chart: (facetRows) => translateChild(instantiateFacetTemplate(childTemplate, facetRows[0]?.[byField]), facetRows)
|
|
1153
1177
|
};
|
|
1154
1178
|
if (spec.id !== void 0) options.id = spec.id;
|
|
1155
1179
|
if (spec.columns !== void 0) options.columns = spec.columns;
|
|
@@ -234,7 +234,9 @@ export interface CxChartMarkSpec {
|
|
|
234
234
|
labelFontWeight?: number;
|
|
235
235
|
orientation?: 'left' | 'right' | 'top' | 'bottom';
|
|
236
236
|
nodeSize?: [number, number];
|
|
237
|
-
projection?: 'mercator' | 'orthographic' | 'naturalEarth1' | 'albersUsa' | 'equalEarth' | 'identity'
|
|
237
|
+
projection?: 'mercator' | 'orthographic' | 'naturalEarth1' | 'albersUsa' | 'equalEarth' | 'equirectangular' | 'identity' | {
|
|
238
|
+
$by: Record<string, 'mercator' | 'orthographic' | 'naturalEarth1' | 'albersUsa' | 'equalEarth' | 'equirectangular' | 'identity'>;
|
|
239
|
+
};
|
|
238
240
|
fit?: 'data' | 'sphere' | {
|
|
239
241
|
data: string;
|
|
240
242
|
};
|