@easyv/charts 1.5.23 → 1.5.25

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.
@@ -163,7 +163,8 @@ var Unit = function Unit(_ref4) {
163
163
  translateY = _ref4$config$translat.y,
164
164
  _ref4$config$align = _ref4$config.align;
165
165
  _ref4$config$align = _ref4$config$align === void 0 ? defaultAlign : _ref4$config$align;
166
- var textAnchor = _ref4$config$align.textAnchor;
166
+ var textAnchor = _ref4$config$align.textAnchor,
167
+ dataUnit = _ref4.dataUnit;
167
168
  if (!show) return null;
168
169
  return /*#__PURE__*/_react["default"].createElement("text", {
169
170
  className: "__easyv-unit",
@@ -175,7 +176,7 @@ var Unit = function Unit(_ref4) {
175
176
  fontStyle: italic ? "italic" : "normal",
176
177
  letterSpacing: letterSpacing,
177
178
  textAnchor: textAnchor
178
- }, text);
179
+ }, dataUnit || text);
179
180
  };
180
181
 
181
182
  var Label = function Label(_ref5) {
@@ -279,6 +280,7 @@ var _default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef
279
280
  marginTop = _ref6$margin.marginTop,
280
281
  positions = _ref6.positions,
281
282
  xLineRange = _ref6.xLineRange,
283
+ dataUnit = _ref6.dataUnit,
282
284
  range = _ref6.range,
283
285
  axisType = _ref6.axisType,
284
286
  _ref6$isClipAxis = _ref6.isClipAxis,
@@ -451,7 +453,8 @@ var _default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef
451
453
  clipAxisRange: clipAxisRange,
452
454
  cPercent: cPercent
453
455
  }), isC && tickLine && drawAxisTickLine(), unit && /*#__PURE__*/_react["default"].createElement(Unit, {
454
- config: unit
456
+ config: unit,
457
+ dataUnit: dataUnit
455
458
  })))));
456
459
  }));
457
460
 
@@ -275,6 +275,7 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
275
275
  controlEl.current.style.transform = "translate(".concat(cBarX, "px,0)"); //计算出当前位移的百分比
276
276
 
277
277
  var percent = cBarX / (cWidth - cBarWidth);
278
+ percent = isNaN(percent) ? 1 : percent;
278
279
  var translateX = -(controlEnd + start / cPercent - chartWidth) * percent;
279
280
  curControlPercent.current = percent;
280
281
  seriesEl.current.style.transform = "translate(".concat(translateX, "px,").concat(marginTop, "px)");
@@ -441,7 +442,17 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
441
442
  config: background,
442
443
  bandLength: bandLength
443
444
  }))), (0, _toConsumableArray2["default"])(axes.values()).reverse().map(function (item, index) {
444
- var config = item.axisType == "x" ? axisX : item;
445
+ var axisType = item.axisType;
446
+ var dataUnit = "";
447
+ var config = axisType == "x" ? axisX : item;
448
+ var target = series.find(function (d) {
449
+ return d.yOrZ == axisType;
450
+ });
451
+
452
+ if (target && target.data[0]) {
453
+ dataUnit = target.data[0].data.__unit__;
454
+ }
455
+
445
456
  return /*#__PURE__*/_react["default"].createElement(_.Axis, (0, _extends2["default"])({
446
457
  ref: function ref(d) {
447
458
  axisElList.current[index] = d;
@@ -453,7 +464,8 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
453
464
  margin: {
454
465
  marginLeft: marginLeft,
455
466
  marginTop: marginTop
456
- }
467
+ },
468
+ dataUnit: dataUnit
457
469
  }, config, {
458
470
  key: index
459
471
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.5.23",
3
+ "version": "1.5.25",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -137,6 +137,7 @@ const AxisLine: ({
137
137
 
138
138
  const Unit: ({
139
139
  config: { show, text, font, translate, align },
140
+ dataUnit
140
141
  }: any) => ReactComponentElement<ComponentType> | null = ({
141
142
  config: {
142
143
  show,
@@ -145,6 +146,7 @@ const Unit: ({
145
146
  translate: { x: translateX, y: translateY },
146
147
  align: { textAnchor } = defaultAlign,
147
148
  },
149
+ dataUnit
148
150
  }) => {
149
151
  if (!show) return null;
150
152
  return (
@@ -159,7 +161,7 @@ const Unit: ({
159
161
  letterSpacing={letterSpacing}
160
162
  textAnchor={textAnchor}
161
163
  >
162
- {text}
164
+ {dataUnit || text}
163
165
  </text>
164
166
  );
165
167
  };
@@ -277,6 +279,7 @@ export default memo(
277
279
  margin:{ marginLeft, marginTop },
278
280
  positions,
279
281
  xLineRange,
282
+ dataUnit,
280
283
  range,
281
284
  axisType,
282
285
  //断轴图相关
@@ -499,7 +502,7 @@ export default memo(
499
502
  cPercent={cPercent}
500
503
  />}
501
504
  {isC && tickLine && drawAxisTickLine()}
502
- {unit && <Unit config={unit} />}
505
+ {unit && <Unit config={unit} dataUnit={dataUnit}/>}
503
506
  </g>
504
507
  </g>
505
508
  </svg>
@@ -236,7 +236,8 @@ const Chart = memo(
236
236
  if(controlEl.current){
237
237
  controlEl.current.style.transform = `translate(${cBarX}px,0)`;
238
238
  //计算出当前位移的百分比
239
- const percent = cBarX / (cWidth - cBarWidth);
239
+ let percent = cBarX / (cWidth - cBarWidth);
240
+ percent = isNaN(percent)?1:percent;
240
241
  const translateX = -(controlEnd + start/cPercent - chartWidth) * percent;
241
242
  curControlPercent.current = percent;
242
243
  seriesEl.current.style.transform = `translate(${translateX}px,${marginTop}px)`;
@@ -378,7 +379,13 @@ const Chart = memo(
378
379
  )}
379
380
  {/* 坐标轴 */}
380
381
  {[...axes.values()].reverse().map((item, index) => {
381
- const config = item.axisType == "x" ? axisX : item;
382
+ const { axisType } = item;
383
+ let dataUnit = "";
384
+ const config = axisType == "x" ? axisX : item;
385
+ const target = series.find(d=>d.yOrZ==axisType);
386
+ if(target && target.data[0]){
387
+ dataUnit = target.data[0].data.__unit__;
388
+ }
382
389
  return (
383
390
  <Axis
384
391
  ref={(d) => {
@@ -389,6 +396,7 @@ const Chart = memo(
389
396
  yLineRange={yLineRange}
390
397
  controlInfo={controlInfo}
391
398
  margin={{marginLeft,marginTop}}
399
+ dataUnit={dataUnit}
392
400
  {...config}
393
401
  key={index}
394
402
  />
@@ -397,7 +405,6 @@ const Chart = memo(
397
405
  {showTooltip && !control && (
398
406
  <Indicator {...indicator} {...indicatorAttr} />
399
407
  )}
400
-
401
408
  <foreignObject
402
409
  style={
403
410
  {
@@ -480,7 +487,6 @@ const Chart = memo(
480
487
  })}
481
488
  </svg>
482
489
  </foreignObject>
483
-
484
490
  {baseLineData &&
485
491
  baseLineData.length > 0 &&
486
492
  baseLineData.map((item, index) => {
@@ -539,7 +545,6 @@ const Chart = memo(
539
545
  height={height}
540
546
  />
541
547
  )}
542
-
543
548
  {showCtl && !!control && (
544
549
  <Tooltip
545
550
  isVertical={isVertical}
@@ -95,6 +95,7 @@ export default ({
95
95
  };
96
96
  }, [auto, tickLength, interval, isHover, active]);
97
97
  const name = currentIndex === null ? null : axisX.allTicks[currentIndex];
98
+
98
99
  return {
99
100
  name,
100
101
  x: axisX.scaler(name),