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

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
@@ -4,7 +4,7 @@ import { Chart } from "@tanstack/charts/vue";
4
4
  import { useCxBEM } from "@lionad/cx-vue";
5
5
  import { areaX, areaY, arrow, bandX, bandY, barX, barY, binX, binXY, binY, boxRows, boxX, boxY, cell, colorGradientLegend, colorLegend, cumulative, d3Curve, defaultChartTheme, defineChart, delta, deviation, differenceX, differenceY, dodgeX, dodgeY, dot, first, fold, frame, group, groupBy, hexagon, last, lineX, lineY, linearRegressionRowsX, linearRegressionRowsY, linearRegressionX, linearRegressionY, link, median, mosaicX, mosaicY, normalize, quantile, rank, ratio, rect, ridgelineX, ridgelineY, rollingWindow, ruleX, ruleY, select, stack, stackRowsX, stackRowsY, text, tickX, tickY, variance, vector, violinX, violinY, waffleX, waffleY, waterfall } from "@tanstack/charts";
6
6
  import { d3AreaXCurve } from "@tanstack/charts/d3/area-x";
7
- import { curveBasis, curveCatmullRom, curveLinear, curveLinearClosed, curveMonotoneX, curveNatural, curveStep, curveStepAfter, curveStepBefore } from "d3-shape";
7
+ import { curveBasis, curveBumpX, curveCatmullRom, curveLinear, curveLinearClosed, curveMonotoneX, curveNatural, curveStep, curveStepAfter, curveStepBefore } from "d3-shape";
8
8
  import { scaleLinear } from "@tanstack/charts/scales/linear";
9
9
  import { scaleOrdinal } from "@tanstack/charts/scales/ordinal";
10
10
  import { scalePoint } from "@tanstack/charts/scales/point";
@@ -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";
@@ -910,6 +910,18 @@ function hierarchyOptions(spec, idKey) {
910
910
  function hierarchyFieldChannel(field) {
911
911
  return (node) => node?.data?.[field];
912
912
  }
913
+ /**
914
+ * sankey 布局行顶层只有 canonical 字段(key/width/坐标),原 datum 收纳在 .data 下;
915
+ * 声明式样式字段名(如 stroke:"色调"、color:"id")须穿透到原 datum 解析,
916
+ * 否则 channel 按顶层查表得 undefined 而静默退回默认样式。
917
+ */
918
+ function sankeyDatumField(field) {
919
+ return (row) => {
920
+ const record = row;
921
+ if (record.data != null && field in record.data) return record.data[field];
922
+ return record[field];
923
+ };
924
+ }
913
925
  /** sankey:固化 marks 回调 = link(布局连线) + rect(布局节点),样式取自声明 */
914
926
  function translateSankey(spec, datasets) {
915
927
  const nodes = resolveMarkData(spec.nodes, datasets);
@@ -922,25 +934,30 @@ function translateSankey(spec, datasets) {
922
934
  source: spec.source,
923
935
  target: spec.target,
924
936
  value: spec.value,
925
- marks: (context) => [looseLink(context.links, {
926
- x1: "x1",
927
- y1: "y1",
928
- x2: "x2",
929
- y2: "y2",
930
- key: "key",
931
- strokeWidth: "width",
932
- lineCap: "butt",
933
- stroke: spec.stroke ?? void 0,
934
- strokeOpacity: spec.strokeOpacity ?? .55
935
- }), looseRect(context.nodes, {
936
- x1: "x0",
937
- x2: "x1",
938
- y1: "y0",
939
- y2: "y1",
940
- key: "key",
941
- color: spec.color ?? "key",
942
- fillOpacity: spec.fillOpacity ?? void 0
943
- })]
937
+ marks: (context) => {
938
+ const strokeField = typeof spec.stroke === "string" && context.links.some((l) => l?.data?.[spec.stroke] !== void 0) ? spec.stroke : null;
939
+ return [looseLink(context.links, {
940
+ x1: "x1",
941
+ y1: "y1",
942
+ x2: "x2",
943
+ y2: "y2",
944
+ key: "key",
945
+ strokeWidth: (row) => Math.max(1, Number(row.width) || 1),
946
+ lineCap: "butt",
947
+ curve: d3Curve(curveBumpX),
948
+ color: strokeField ? sankeyDatumField(strokeField) : void 0,
949
+ stroke: strokeField ? void 0 : spec.stroke ?? void 0,
950
+ strokeOpacity: spec.strokeOpacity ?? .55
951
+ }), looseRect(context.nodes, {
952
+ x1: "x0",
953
+ x2: "x1",
954
+ y1: "y0",
955
+ y2: "y1",
956
+ key: "key",
957
+ color: typeof spec.color === "string" ? sankeyDatumField(spec.color) : spec.color ?? "key",
958
+ fillOpacity: spec.fillOpacity ?? void 0
959
+ })];
960
+ }
944
961
  };
945
962
  if (spec.id !== void 0) options.id = spec.id;
946
963
  if (spec.align !== void 0) options.align = spec.align;
@@ -1097,13 +1114,16 @@ function translateForceGraph(spec, datasets) {
1097
1114
  yDomain: [graph.yDomain[0], graph.yDomain[1]]
1098
1115
  };
1099
1116
  }
1100
- /** d3-geo 投影名称枚举 → 工厂(descriptor.type 形态:() => projection) */
1117
+ /** d3-geo 投影名称枚举 → 工厂(descriptor.type 形态:() => projection);
1118
+ * 等距圆柱必须用 equirectangular 而非 identity:identity 的 stream 无 sphere 方法,
1119
+ * fit/渲染 Sphere 几何(球面描边层)直接抛 TypeError */
1101
1120
  const GEO_PROJECTION_FACTORIES = {
1102
1121
  mercator: geoMercator,
1103
1122
  orthographic: geoOrthographic,
1104
1123
  naturalEarth1: geoNaturalEarth1,
1105
1124
  albersUsa: geoAlbersUsa,
1106
1125
  equalEarth: geoEqualEarth,
1126
+ equirectangular: geoEquirectangular,
1107
1127
  identity: geoIdentity
1108
1128
  };
1109
1129
  /** geoShape:projection 名称枚举 → descriptor {type, fit, inset};fit:'data' 由库拟合数据本体,{data:'<name>'} 拟合另一命名数据集 */
@@ -234,8 +234,8 @@ 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
- $by: Record<string, '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
239
  };
240
240
  fit?: 'data' | 'sphere' | {
241
241
  data: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lionad/cx-comps-tanstack-charts",
3
- "version": "0.1.0-alpha.17",
3
+ "version": "0.1.0-alpha.19",
4
4
  "description": "cx material components wrapping TanStack Charts (@tanstack/charts/vue)",
5
5
  "keywords": [
6
6
  "charts",