@lionad/cx-comps-tanstack-charts 0.1.0-alpha.16 → 0.1.0-alpha.17

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 CHANGED
@@ -1110,6 +1110,7 @@ const GEO_PROJECTION_FACTORIES = {
1110
1110
  function translateGeoShape(spec, datasets) {
1111
1111
  const rows = resolveMarkData(spec.data, datasets);
1112
1112
  const projectionName = spec.projection ?? "mercator";
1113
+ if (typeof projectionName === "object") throw new Error("translateGeoShape: projection {$by} 仅允许出现在 facet chart 子模板内");
1113
1114
  const factory = GEO_PROJECTION_FACTORIES[projectionName];
1114
1115
  if (!factory) throw new Error(`translateGeoShape: 未知投影 "${String(projectionName)}"`);
1115
1116
  const options = { projection: {
@@ -1138,6 +1139,25 @@ function translateGeoShape(spec, datasets) {
1138
1139
  return geoShape(rows, options);
1139
1140
  }
1140
1141
  /**
1142
+ * facet 子模板按组实例化:深度遍历,把 {$by:{组名:值}} 形态字段替换为当前组映射值。
1143
+ * 未声明 $by 的字段原样保留;$by 表未命中当前组时抛错(静默回退会让分面悄悄同参)。
1144
+ */
1145
+ function instantiateFacetTemplate(node, groupKey) {
1146
+ if (Array.isArray(node)) return node.map((item) => instantiateFacetTemplate(item, groupKey));
1147
+ if (node && typeof node === "object") {
1148
+ const record = node;
1149
+ const keys = Object.keys(record);
1150
+ if (keys.length === 1 && keys[0] === "$by") {
1151
+ const table = record.$by;
1152
+ const hit = table[String(groupKey)];
1153
+ if (hit === void 0) throw new Error(`instantiateFacetTemplate: $by 映射未命中分组 "${String(groupKey)}"(可用键: ${Object.keys(table).join(", ")})`);
1154
+ return hit;
1155
+ }
1156
+ return Object.fromEntries(Object.entries(record).map(([k, v]) => [k, instantiateFacetTemplate(v, groupKey)]));
1157
+ }
1158
+ return node;
1159
+ }
1160
+ /**
1141
1161
  * facet:chart 回调固化为递归子 spec 翻译——translateChild 由 definition.ts 注入
1142
1162
  * (子 spec 翻译与顶层同路径,仅数据集换为 facet 分组行;规避 composite ↔ definition 循环 import)。
1143
1163
  * label 语义:true 显示分组 key 标签(库的函数形态不可 JSON,布尔即可覆盖声明式场景)。
@@ -1147,9 +1167,10 @@ function translateFacet(spec, datasets, translateChild) {
1147
1167
  if (!spec.by) throw new Error("translateFacet: facet 必须声明 by 分组字段");
1148
1168
  if (!spec.chart) throw new Error("translateFacet: facet 必须声明 chart 子 spec 模板");
1149
1169
  const childTemplate = spec.chart;
1170
+ const byField = spec.by;
1150
1171
  const options = {
1151
- by: spec.by,
1152
- chart: (facetRows) => translateChild(childTemplate, facetRows)
1172
+ by: byField,
1173
+ chart: (facetRows) => translateChild(instantiateFacetTemplate(childTemplate, facetRows[0]?.[byField]), facetRows)
1153
1174
  };
1154
1175
  if (spec.id !== void 0) options.id = spec.id;
1155
1176
  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' | 'identity' | {
238
+ $by: Record<string, 'mercator' | 'orthographic' | 'naturalEarth1' | 'albersUsa' | 'equalEarth' | 'identity'>;
239
+ };
238
240
  fit?: 'data' | 'sphere' | {
239
241
  data: string;
240
242
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lionad/cx-comps-tanstack-charts",
3
- "version": "0.1.0-alpha.16",
3
+ "version": "0.1.0-alpha.17",
4
4
  "description": "cx material components wrapping TanStack Charts (@tanstack/charts/vue)",
5
5
  "keywords": [
6
6
  "charts",