@lionad/cx-comps-tanstack-charts 0.1.0-alpha.15 → 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
@@ -785,7 +785,23 @@ function translatePolarGuide(spec) {
785
785
  "shape",
786
786
  "labels",
787
787
  "labelAngle",
788
- "labelOffset"
788
+ "labelOffset",
789
+ "id",
790
+ "className",
791
+ "labelClassName",
792
+ "stroke",
793
+ "strokeOpacity",
794
+ "strokeWidth",
795
+ "strokeDasharray",
796
+ "fill",
797
+ "fillOpacity",
798
+ "labelFill",
799
+ "labelFontSize",
800
+ "labelAnchor",
801
+ "labelBaseline",
802
+ "labelDx",
803
+ "labelDy",
804
+ "labelRotate"
789
805
  ]) if (spec[key] !== void 0) options[key] = spec[key];
790
806
  return factory(options);
791
807
  }
@@ -1090,15 +1106,19 @@ const GEO_PROJECTION_FACTORIES = {
1090
1106
  equalEarth: geoEqualEarth,
1091
1107
  identity: geoIdentity
1092
1108
  };
1093
- /** geoShape:projection 名称枚举 → descriptor {type, fit, inset};fit:'data' 由库拟合数据本体 */
1109
+ /** geoShape:projection 名称枚举 → descriptor {type, fit, inset};fit:'data' 由库拟合数据本体,{data:'<name>'} 拟合另一命名数据集 */
1094
1110
  function translateGeoShape(spec, datasets) {
1095
1111
  const rows = resolveMarkData(spec.data, datasets);
1096
1112
  const projectionName = spec.projection ?? "mercator";
1113
+ if (typeof projectionName === "object") throw new Error("translateGeoShape: projection {$by} 仅允许出现在 facet chart 子模板内");
1097
1114
  const factory = GEO_PROJECTION_FACTORIES[projectionName];
1098
1115
  if (!factory) throw new Error(`translateGeoShape: 未知投影 "${String(projectionName)}"`);
1099
1116
  const options = { projection: {
1100
1117
  type: factory,
1101
- fit: spec.fit ?? "data",
1118
+ fit: typeof spec.fit === "object" && spec.fit !== null ? {
1119
+ type: "FeatureCollection",
1120
+ features: resolveMarkData(spec.fit.data, datasets)
1121
+ } : spec.fit ?? "data",
1102
1122
  ...spec.inset !== void 0 ? { inset: spec.inset } : {}
1103
1123
  } };
1104
1124
  if (spec.id !== void 0) options.id = spec.id;
@@ -1119,6 +1139,25 @@ function translateGeoShape(spec, datasets) {
1119
1139
  return geoShape(rows, options);
1120
1140
  }
1121
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
+ /**
1122
1161
  * facet:chart 回调固化为递归子 spec 翻译——translateChild 由 definition.ts 注入
1123
1162
  * (子 spec 翻译与顶层同路径,仅数据集换为 facet 分组行;规避 composite ↔ definition 循环 import)。
1124
1163
  * label 语义:true 显示分组 key 标签(库的函数形态不可 JSON,布尔即可覆盖声明式场景)。
@@ -1128,9 +1167,10 @@ function translateFacet(spec, datasets, translateChild) {
1128
1167
  if (!spec.by) throw new Error("translateFacet: facet 必须声明 by 分组字段");
1129
1168
  if (!spec.chart) throw new Error("translateFacet: facet 必须声明 chart 子 spec 模板");
1130
1169
  const childTemplate = spec.chart;
1170
+ const byField = spec.by;
1131
1171
  const options = {
1132
- by: spec.by,
1133
- chart: (facetRows) => translateChild(childTemplate, facetRows)
1172
+ by: byField,
1173
+ chart: (facetRows) => translateChild(instantiateFacetTemplate(childTemplate, facetRows[0]?.[byField]), facetRows)
1134
1174
  };
1135
1175
  if (spec.id !== void 0) options.id = spec.id;
1136
1176
  if (spec.columns !== void 0) options.columns = spec.columns;
@@ -234,8 +234,12 @@ 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';
238
- fit?: 'data' | 'sphere';
237
+ projection?: 'mercator' | 'orthographic' | 'naturalEarth1' | 'albersUsa' | 'equalEarth' | 'identity' | {
238
+ $by: Record<string, 'mercator' | 'orthographic' | 'naturalEarth1' | 'albersUsa' | 'equalEarth' | 'identity'>;
239
+ };
240
+ fit?: 'data' | 'sphere' | {
241
+ data: string;
242
+ };
239
243
  by?: string;
240
244
  axes?: 'outer' | 'cell';
241
245
  minWidth?: number;
@@ -252,6 +256,22 @@ export interface CxChartPolarGuideSpec {
252
256
  labels?: boolean;
253
257
  labelAngle?: number;
254
258
  labelOffset?: number;
259
+ id?: string;
260
+ className?: string;
261
+ labelClassName?: string;
262
+ stroke?: string;
263
+ strokeOpacity?: number;
264
+ strokeWidth?: number;
265
+ strokeDasharray?: string;
266
+ fill?: string;
267
+ fillOpacity?: number;
268
+ labelFill?: string;
269
+ labelFontSize?: number;
270
+ labelAnchor?: 'start' | 'middle' | 'end';
271
+ labelBaseline?: 'auto' | 'middle' | 'hanging';
272
+ labelDx?: number;
273
+ labelDy?: number;
274
+ labelRotate?: number;
255
275
  }
256
276
  /**
257
277
  * forceGraph 力集声明式:库 ForceDescriptor 的 JSON 子集。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lionad/cx-comps-tanstack-charts",
3
- "version": "0.1.0-alpha.15",
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",