@easyv/charts 1.10.8 → 1.10.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.
@@ -14,7 +14,9 @@ export default memo(
14
14
  ({
15
15
  series,
16
16
  height,
17
+ data,
17
18
  config,
19
+ columnsSeries,
18
20
  config: {
19
21
  show,
20
22
  order = "",
@@ -83,7 +85,7 @@ export default memo(
83
85
  table.scrollTo({ top: ref_scrollTop.current, behavior: "smooth" });
84
86
  };
85
87
 
86
- const _series = sortPie(series, order);
88
+ const _series = sortPie(series, order, columnsSeries);
87
89
  const [_alignment, position] = alignment.split(" ");
88
90
  const length = _series.length;
89
91
 
@@ -145,6 +147,56 @@ export default memo(
145
147
  }),
146
148
  );
147
149
  const nameMaxWidth = config.name?.maxWidth || 80;
150
+ const fieldColumnKeys = [];
151
+ if (columnsSeries?.columns) {
152
+ Object.values(columnsSeries.columns).forEach((col) => {
153
+ if (col.field && !fieldColumnKeys.includes(col.field)) {
154
+ fieldColumnKeys.push(col.field);
155
+ }
156
+ });
157
+ }
158
+ const fieldsColumnWidths = fieldColumnKeys.map((fieldName) => {
159
+ let maxMeasured = 0;
160
+ let maxCfg = 0;
161
+ _series.forEach((s) => {
162
+ const cfg = s.fields?.[fieldName];
163
+ if (
164
+ !cfg ||
165
+ !s.data ||
166
+ !Object.prototype.hasOwnProperty.call(s.data, fieldName)
167
+ ) {
168
+ return;
169
+ }
170
+ const f = cfg.font || {};
171
+ const fontStack = `${f.fontSize || 12}px ${f.fontFamily || "Arial"}`;
172
+ const letter = f.letterSpacing || 0;
173
+ let w = parseFloat(
174
+ getCanvasTextWidth(
175
+ String(s.data[fieldName] ?? ""),
176
+ letter,
177
+ fontStack,
178
+ ),
179
+ );
180
+ const suf = cfg.suffix;
181
+ if (suf?.show && suf.text != null && String(suf.text) !== "") {
182
+ const sufFont = `${suf.fontSize || f.fontSize || 12}px ${
183
+ f.fontFamily || "Arial"
184
+ }`;
185
+ w += parseFloat(
186
+ getCanvasTextWidth(String(suf.text), letter, sufFont),
187
+ );
188
+ }
189
+ const tx = Number(cfg.translate?.x) || 0;
190
+ const stx =
191
+ suf?.show && suf.text != null && String(suf.text) !== ""
192
+ ? Number(suf.translate?.x) || 0
193
+ : 0;
194
+ w += Math.max(0, tx) + Math.max(0, stx);
195
+ maxMeasured = Math.max(maxMeasured, w);
196
+ maxCfg = Math.max(maxCfg, Number(cfg.maxWidth) || 0);
197
+ });
198
+ return Math.max(maxMeasured, maxCfg);
199
+ });
148
200
 
149
201
  const stylePieOrAxis = formatter
150
202
  ? {
@@ -233,6 +285,7 @@ export default memo(
233
285
  alignItems: "center",
234
286
  cursor: "pointer",
235
287
  gap: _icon.gap,
288
+ overflow: formatter ? "visible" : undefined,
236
289
  }}
237
290
  >
238
291
  {formatter ? (
@@ -241,6 +294,10 @@ export default memo(
241
294
  valueMaxWidth,
242
295
  percentMaxWidth,
243
296
  nameMaxWidth,
297
+ otherData: data,
298
+ columnsSeries,
299
+ fieldColumnKeys,
300
+ fieldsColumnWidths,
244
301
  })
245
302
  ) : (
246
303
  <>
@@ -311,6 +368,7 @@ export default memo(
311
368
  alignItems: "center",
312
369
  cursor: "pointer",
313
370
  gap: _icon.gap,
371
+ overflow: formatter ? "visible" : undefined,
314
372
  }}
315
373
  >
316
374
  {formatter ? (
@@ -319,6 +377,10 @@ export default memo(
319
377
  valueMaxWidth,
320
378
  percentMaxWidth,
321
379
  nameMaxWidth,
380
+ otherData: data,
381
+ columnsSeries,
382
+ fieldColumnKeys,
383
+ fieldsColumnWidths,
322
384
  })
323
385
  ) : (
324
386
  <>
@@ -1,23 +1,27 @@
1
1
  /**
2
2
  * 折线图
3
3
  */
4
- import React, { memo, useMemo } from 'react';
5
- import { line as d3Line, area as d3Area, curveCatmullRom, curveMonotoneX } from 'd3v7';
6
- import { getColorList } from '../utils';
7
- import { Lighter, LinearGradient } from '.';
4
+ import React, { memo, useMemo } from "react";
5
+ import {
6
+ line as d3Line,
7
+ area as d3Area,
8
+ curveCatmullRom,
9
+ curveMonotoneX,
10
+ } from "d3v7";
11
+ import { getColorList } from "../utils";
12
+ import { Lighter, LinearGradient } from ".";
8
13
 
9
14
  const defined = (d) => d.data.y != null;
10
- const getLineData = (data, connectNulls) =>{
11
- return data.flatMap(d=>{
15
+ const getLineData = (data, connectNulls) => {
16
+ return data.flatMap((d) => {
12
17
  const y = d.data.y;
13
- return isNaN(y)?
14
- connectNulls?
15
- []:
16
- {...d,data:{...d.data,y:null}}:
17
- d
18
+ return isNaN(y)
19
+ ? connectNulls
20
+ ? []
21
+ : { ...d, data: { ...d.data, y: null } }
22
+ : d;
18
23
  });
19
- }
20
-
24
+ };
21
25
 
22
26
  const Area = ({
23
27
  data,
@@ -30,11 +34,11 @@ const Area = ({
30
34
  opacity,
31
35
  size: { width: patternW, height: patternH },
32
36
  curve,
33
- tension
37
+ tension,
34
38
  },
35
39
  xScaler,
36
40
  yScaler,
37
- opacity:Areaopacity
41
+ opacity: Areaopacity,
38
42
  }) => {
39
43
  const [height] = yScaler.range();
40
44
  const area = useMemo(() => getColorList(fill), [fill]);
@@ -43,7 +47,7 @@ const Area = ({
43
47
  const areaGen = d3Area()
44
48
  .x(({ data: { x } }) => xScaler(x))
45
49
  .y1(({ data: { y } }) => yScaler(y))
46
- .y0(({})=>yScaler(0))
50
+ .y0(({}) => yScaler(0))
47
51
  .defined(defined);
48
52
  curve && areaGen.curve(curveCatmullRom.alpha(tension));
49
53
  curve && areaGen.curve(curveMonotoneX);
@@ -52,11 +56,28 @@ const Area = ({
52
56
 
53
57
  return (
54
58
  <>
55
- <path d={areaGen(data)} style={{pointerEvents:"none",opacity:Areaopacity}} stroke='none' fill={'url(#' + id + ')'} />
59
+ <path
60
+ d={areaGen(data)}
61
+ style={{ pointerEvents: "none", opacity: Areaopacity }}
62
+ stroke="none"
63
+ fill={"url(#" + id + ")"}
64
+ />
56
65
  <defs>
57
- {type && type == 'pattern' ? (
58
- <pattern id={id} patternUnits="userSpaceOnUse" width={patternW} height={patternH}>
59
- {url && <image opacity={opacity} width={patternW} height={patternH} xlinkHref={window.appConfig.ASSETS_URL + url} />}
66
+ {type && type == "pattern" ? (
67
+ <pattern
68
+ id={id}
69
+ patternUnits="userSpaceOnUse"
70
+ width={patternW}
71
+ height={patternH}
72
+ >
73
+ {url && (
74
+ <image
75
+ opacity={opacity}
76
+ width={patternW}
77
+ height={patternH}
78
+ xlinkHref={window.appConfig.ASSETS_URL + url}
79
+ />
80
+ )}
60
81
  </pattern>
61
82
  ) : (
62
83
  <LinearGradient id={id} colors={area} rotate={0} />
@@ -91,32 +112,32 @@ export default memo(
91
112
  }) => {
92
113
  if (!data.length) return null;
93
114
  const ticks = xScaler.domain();
94
-
115
+
95
116
  const sortData = useMemo(() => {
96
117
  const usefulData = data.filter(
97
- ({ data: { x } }) => ticks.indexOf(x) > -1
118
+ ({ data: { x } }) => ticks.indexOf(x) > -1,
98
119
  );
99
120
  return usefulData.sort(
100
121
  ({ data: { x: a } }, { data: { x: b } }) =>
101
- ticks.indexOf(a) - ticks.indexOf(b)
122
+ ticks.indexOf(a) - ticks.indexOf(b),
102
123
  );
103
124
  }, [data, ticks]);
104
-
125
+
105
126
  const _data = useMemo(
106
127
  () => getLineData(sortData, connectNulls),
107
- [sortData, connectNulls]
128
+ [sortData, connectNulls],
108
129
  );
109
130
  const lineGen = useMemo(() => {
110
- const isVertical = direction === 'vertical';
131
+ const isVertical = direction === "vertical";
111
132
 
112
133
  let lineGen = (
113
134
  isVertical
114
135
  ? d3Line()
115
- .y(({ data: { x } }) => xScaler(x))
116
- .x(({ data: { y } }) => yScaler(y))
136
+ .y(({ data: { x } }) => xScaler(x))
137
+ .x(({ data: { y } }) => yScaler(y))
117
138
  : d3Line()
118
- .x(({ data: { x } }) => xScaler(x))
119
- .y(({ data: { y } }) => yScaler(y))
139
+ .x(({ data: { x } }) => xScaler(x))
140
+ .y(({ data: { y } }) => yScaler(y))
120
141
  ).defined(defined);
121
142
  curve && lineGen.curve(curveCatmullRom.alpha(tension));
122
143
  curve && lineGen.curve(curveMonotoneX);
@@ -128,29 +149,31 @@ export default memo(
128
149
  const show = lineShadow && lineShadow.show;
129
150
  const shadow = lineShadow && lineShadow.shadow;
130
151
  return (
131
- <g className='__easyv-line'>
152
+ <g className="__easyv-line">
132
153
  <path
133
154
  d={path}
134
155
  stroke={stroke}
135
156
  style={{
136
- filter:show?`drop-shadow(${shadow.hShadow}px ${shadow.vShadow}px ${shadow.blur}px ${shadow.color})`:"none",
137
- pointerEvents:"none"
157
+ filter: show
158
+ ? `drop-shadow(${shadow.hShadow}px ${shadow.vShadow}px ${shadow.blur}px ${shadow.color})`
159
+ : "none",
160
+ pointerEvents: "none",
138
161
  }}
139
- fill='none'
140
- strokeDasharray={lineType === 'dash' ? '3 3' : null}
162
+ fill="none"
163
+ strokeDasharray={lineType === "dash" ? "3 3" : null}
141
164
  strokeWidth={lineWidth}
142
165
  />
143
- {type == 'area' && (
166
+ {type == "area" && (
144
167
  <Area
145
168
  data={_data}
146
169
  config={{ ...area, curve, tension }}
147
170
  xScaler={xScaler}
148
171
  yScaler={yScaler}
149
- opacity={areaColor?areaColor.linear.opacity:1}
172
+ opacity={areaColor ? areaColor.linear.opacity : 1}
150
173
  />
151
174
  )}
152
175
  {showLighter && <Lighter path={path} config={lighter} />}
153
176
  </g>
154
177
  );
155
- }
178
+ },
156
179
  );
@@ -186,7 +186,7 @@ const getArc = (
186
186
  ...rest
187
187
  },
188
188
  series_,
189
- index
189
+ index,
190
190
  ) => {
191
191
  const series =
192
192
  series_.find((s) => s.fieldName == rest.data.s) ||
@@ -268,6 +268,7 @@ const Component = memo(
268
268
  current,
269
269
  } = {},
270
270
  order,
271
+ columnsSeries,
271
272
  series,
272
273
  animation: {
273
274
  on,
@@ -378,7 +379,7 @@ const Component = memo(
378
379
  padAngle: _padAngle,
379
380
  innerRadius,
380
381
  outerRadius: scaler(arc.value),
381
- })
382
+ }),
382
383
  );
383
384
  }
384
385
  return _legendDataWithPercent.map((arc, index) => ({
@@ -410,7 +411,7 @@ const Component = memo(
410
411
  type: "onClick",
411
412
  });
412
413
  },
413
- [onEvent]
414
+ [onEvent],
414
415
  );
415
416
 
416
417
  const onMouseEnter = useCallback(
@@ -423,7 +424,7 @@ const Component = memo(
423
424
  type: "onMouseEnter",
424
425
  });
425
426
  },
426
- [onEvent, triggerOnRelative, onEmit]
427
+ [onEvent, triggerOnRelative, onEmit],
427
428
  );
428
429
 
429
430
  const onMouseLeave = useCallback(
@@ -437,7 +438,7 @@ const Component = memo(
437
438
  type: "onMouseLeave",
438
439
  });
439
440
  },
440
- [onEvent]
441
+ [onEvent],
441
442
  );
442
443
 
443
444
  useLayoutEffect(() => {
@@ -557,7 +558,7 @@ const Component = memo(
557
558
  .innerRadius(centerRadius)
558
559
  .outerRadius(centerRadius)(value);
559
560
  const dashLength = Math.ceil(
560
- (Math.PI * centerRadius * 2) / _arcs.length
561
+ (Math.PI * centerRadius * 2) / _arcs.length,
561
562
  );
562
563
  const pie = getColorList(series.color);
563
564
  return (
@@ -600,7 +601,7 @@ const Component = memo(
600
601
  </defs>
601
602
  </Fragment>
602
603
  );
603
- }
604
+ },
604
605
  )}
605
606
  {label && (
606
607
  <RingLabel
@@ -649,6 +650,8 @@ const Component = memo(
649
650
  <Legend
650
651
  {...legend}
651
652
  height={chartHeight}
653
+ columnsSeries={columnsSeries}
654
+ data={data}
652
655
  series={_arcs.map((arc) => ({
653
656
  ...arc,
654
657
  percent: arc.percent.toFixed(legendPrecision),
@@ -697,7 +700,7 @@ const Component = memo(
697
700
  outerRadius,
698
701
  index: dataIndex,
699
702
  },
700
- index
703
+ index,
701
704
  ) => {
702
705
  const current = index == currentIndex;
703
706
  const prev = index == prevIndex.current;
@@ -706,14 +709,14 @@ const Component = memo(
706
709
  const fillOpacity = animateColor
707
710
  ? 1
708
711
  : current
709
- ? opacity / 100
710
- : 1;
712
+ ? opacity / 100
713
+ : 1;
711
714
  const deltaWidthen = offset * widthen;
712
715
  const deltaHeighten = offset * heighten;
713
716
  const path = arc
714
717
  .innerRadius(innerRadius + deltaWidthen)
715
718
  .outerRadius(outerRadius + deltaHeighten + deltaWidthen)(
716
- value
719
+ value,
717
720
  );
718
721
  const pie = getColorList(series.color);
719
722
  const currentPie = animateColor
@@ -726,15 +729,15 @@ const Component = memo(
726
729
  //let offsetWidth=decorate2.radiusWidth/2 + radiusWidthAdd/2; //当前文字需生成在装饰物内,故而半径需要减小
727
730
  let textArc = arc
728
731
  .innerRadius(
729
- outerRadius + (current ? gap : categoryText.gap)
732
+ outerRadius + (current ? gap : categoryText.gap),
730
733
  )
731
734
  .outerRadius(
732
- outerRadius + (current ? gap : categoryText.gap)
735
+ outerRadius + (current ? gap : categoryText.gap),
733
736
  )(value);
734
737
  let lastA = textArc.lastIndexOf("A");
735
738
  textPath = textArc.slice(
736
739
  0,
737
- lastA > 0 ? lastA : textArc.length
740
+ lastA > 0 ? lastA : textArc.length,
738
741
  ); //文字路径
739
742
  categoryTextStyle = current
740
743
  ? animateCTS
@@ -779,7 +782,7 @@ const Component = memo(
779
782
  .outerRadius(
780
783
  outerRadius +
781
784
  decorate2.radiusWidth +
782
- (current ? radiusWidthAdd : 0)
785
+ (current ? radiusWidthAdd : 0),
783
786
  )(value)}
784
787
  stroke={show ? color : "none"}
785
788
  strokeWidth={show ? strokeWidth : "0"}
@@ -843,7 +846,7 @@ const Component = memo(
843
846
  </defs>
844
847
  </Fragment>
845
848
  );
846
- }
849
+ },
847
850
  )}
848
851
  {label && (
849
852
  <Label
@@ -918,6 +921,8 @@ const Component = memo(
918
921
  <Legend
919
922
  {...legend}
920
923
  height={chartHeight}
924
+ data={data}
925
+ columnsSeries={columnsSeries}
921
926
  series={_arcs.map((arc) => ({
922
927
  ...arc,
923
928
  percent: arc.percent.toFixed(legendPrecision),
@@ -928,7 +933,7 @@ const Component = memo(
928
933
  />
929
934
  </div>
930
935
  );
931
- }
936
+ },
932
937
  );
933
938
 
934
939
  const Current = ({
@@ -979,7 +984,7 @@ const Current = ({
979
984
  //数据容错,当data都为零那么需要进行以下容错
980
985
  if (judge == 0) {
981
986
  _data.forEach((d) => {
982
- (d.percent = 0), (d.value = 0);
987
+ ((d.percent = 0), (d.value = 0));
983
988
  });
984
989
  }
985
990
 
@@ -1143,7 +1148,7 @@ const Label = ({
1143
1148
  }) => {
1144
1149
  const _arcs = useMemo(
1145
1150
  () => getDataWithPercent(arcs, precision),
1146
- [arcs, precision]
1151
+ [arcs, precision],
1147
1152
  );
1148
1153
  //数据做出容错
1149
1154
  if (judge == 0) {
@@ -1171,14 +1176,14 @@ const Label = ({
1171
1176
  outerRadius,
1172
1177
  index: actualIndex,
1173
1178
  },
1174
- index
1179
+ index,
1175
1180
  ) => {
1176
1181
  const [x, y] = arc.centroid();
1177
1182
  const midAngle = Math.atan2(y, x);
1178
1183
 
1179
1184
  const [x1, y1] = getCoord(
1180
1185
  midAngle,
1181
- maxRadius ? maxRadius : outerRadius
1186
+ maxRadius ? maxRadius : outerRadius,
1182
1187
  );
1183
1188
 
1184
1189
  const radius = (maxRadius ? maxRadius : outerRadius) + distance;
@@ -1223,8 +1228,8 @@ const Label = ({
1223
1228
  lineColor
1224
1229
  ? lineColor
1225
1230
  : type == "pure"
1226
- ? pure
1227
- : stops[0].color
1231
+ ? pure
1232
+ : stops[0].color
1228
1233
  }
1229
1234
  fill="none"
1230
1235
  />
@@ -1253,8 +1258,8 @@ const Label = ({
1253
1258
  align == "left"
1254
1259
  ? "flex-start"
1255
1260
  : align == "center"
1256
- ? "center"
1257
- : "flex-end",
1261
+ ? "center"
1262
+ : "flex-end",
1258
1263
  justifyContent: "center",
1259
1264
  }}
1260
1265
  >
@@ -1315,7 +1320,7 @@ const Label = ({
1315
1320
  </g>
1316
1321
  )
1317
1322
  );
1318
- }
1323
+ },
1319
1324
  )}
1320
1325
  </g>
1321
1326
  );
@@ -1376,7 +1381,7 @@ const RingLabel = ({
1376
1381
  }) => {
1377
1382
  const _arcs = useMemo(
1378
1383
  () => getDataWithPercent(arcs, precision),
1379
- [arcs, precision]
1384
+ [arcs, precision],
1380
1385
  );
1381
1386
 
1382
1387
  //数据做出容错
@@ -1406,14 +1411,14 @@ const RingLabel = ({
1406
1411
  outerRadius,
1407
1412
  index: actualIndex,
1408
1413
  },
1409
- index
1414
+ index,
1410
1415
  ) => {
1411
1416
  const [x, y] = arc.centroid();
1412
1417
  const midAngle = Math.atan2(y, x);
1413
1418
 
1414
1419
  const [x1, y1] = getCoord(
1415
1420
  midAngle,
1416
- maxRadius ? maxRadius : outerRadius
1421
+ maxRadius ? maxRadius : outerRadius,
1417
1422
  );
1418
1423
 
1419
1424
  const radius = (maxRadius ? maxRadius : outerRadius) + distance;
@@ -1456,8 +1461,8 @@ const RingLabel = ({
1456
1461
  lineColor
1457
1462
  ? lineColor
1458
1463
  : type == "pure"
1459
- ? pure
1460
- : stops[0].color
1464
+ ? pure
1465
+ : stops[0].color
1461
1466
  }
1462
1467
  fill="none"
1463
1468
  />
@@ -1546,7 +1551,7 @@ const RingLabel = ({
1546
1551
  </g>
1547
1552
  )
1548
1553
  );
1549
- }
1554
+ },
1550
1555
  )}
1551
1556
  </g>
1552
1557
  );