@easyv/charts 1.8.9 → 1.8.11

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.
@@ -13,8 +13,9 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
13
13
  var _react = _interopRequireWildcard(require("react"));
14
14
  var _d3v = require("d3v7");
15
15
  var _utils = require("../utils");
16
- var _excluded = ["pattern", "seriesIntervalWidth", "paddingInner", "highlight"],
17
- _excluded2 = ["bgAttr"];
16
+ var _excluded = ["show", "extent"],
17
+ _excluded2 = ["pattern", "seriesIntervalWidth", "paddingInner", "highlight"],
18
+ _excluded3 = ["bgAttr"];
18
19
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
19
20
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
20
21
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
@@ -103,8 +104,8 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
103
104
  _ref3$config$highligh = _ref3$config.highlight,
104
105
  showHighlight = _ref3$config$highligh.show,
105
106
  extent = _ref3$config$highligh.extent,
106
- highlightFill = _ref3$config$highligh.fill,
107
- other = (0, _objectWithoutProperties2["default"])(_ref3$config, _excluded),
107
+ highlightStyle = (0, _objectWithoutProperties2["default"])(_ref3$config$highligh, _excluded),
108
+ other = (0, _objectWithoutProperties2["default"])(_ref3$config, _excluded2),
108
109
  curXLabel = _ref3.curXLabel,
109
110
  selectStyle = _ref3.selectStyle,
110
111
  _ref3$bandLength = _ref3.bandLength,
@@ -136,6 +137,10 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
136
137
  });
137
138
  }
138
139
  }
140
+ var highlightConfig = other;
141
+ if (highlightStyle) {
142
+ highlightConfig = _objectSpread(_objectSpread({}, other), highlightStyle);
143
+ }
139
144
  var step = isControlChart ? controlStep : normalStep;
140
145
  var xScaler = isControlChart ? controlDragScaler : normalScaler;
141
146
  var _getSeriesInfo = (0, _utils.getSeriesInfo)({
@@ -176,7 +181,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
176
181
  y1 = yScaler(isVertical ? end : start);
177
182
  y2 = yScaler(isVertical ? start : end);
178
183
  }
179
- var _ref5 = x == curXLabel ? selectConfig : other,
184
+ var _ref5 = x == curXLabel ? selectConfig : flag ? highlightConfig : other,
180
185
  style = _ref5.style,
181
186
  fillType = _ref5.fillType,
182
187
  _ref5$fillMode = _ref5.fillMode,
@@ -227,7 +232,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
227
232
  seriesWidth: seriesWidth
228
233
  }),
229
234
  bgAttr = _getAttr.bgAttr,
230
- attr = (0, _objectWithoutProperties2["default"])(_getAttr, _excluded2);
235
+ attr = (0, _objectWithoutProperties2["default"])(_getAttr, _excluded3);
231
236
  return /*#__PURE__*/_react["default"].createElement(_react.Fragment, {
232
237
  key: i
233
238
  }, /*#__PURE__*/_react["default"].createElement("foreignObject", (0, _extends2["default"])({
@@ -295,8 +300,8 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
295
300
  window.appConfig.ASSETS_URL + headUrl, ") 0 0/100% 100%"),
296
301
  width: headWidth,
297
302
  height: headHeight,
298
- left: isVertical ? "100%" : "50%",
299
- top: isVertical ? "50%" : "0",
303
+ left: isVertical ? y < 0 ? "0%" : "100%" : "50%",
304
+ top: isVertical ? "50%" : y < 0 ? "100%" : "0%",
300
305
  zIndex: 1,
301
306
  transform: "translate(calc(-50% + ".concat(headTranslate.x, "px), calc(-50% + ").concat(headTranslate.y, "px))")
302
307
  }
@@ -328,7 +333,8 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
328
333
  opacity: fillType == "pattern" ? opacity : 1,
329
334
  background: fillType == "pattern" ? "".concat(isVertical ? y < 0 ? "100%" : "0%" : "50%", " ").concat(isVertical ? "50%" : y < 0 ? "0%" : "100%", " / ").concat(fillMode == "tile" ? size.width + "px " + size.height + "px" : "100% 100%", " repeat ") + "url(" +
330
335
  //@ts-ignore
331
- window.appConfig.ASSETS_URL + url + ")" : (0, _utils.getBandBackground)(pattern, extent === flag ? highlightFill : fill),
336
+ window.appConfig.ASSETS_URL + url + ")" : (0, _utils.getBandBackground)(pattern, fill, y //是否小于0
337
+ ),
332
338
  borderRadius: style == "square" ? "0 0 0 0" : getBorderRadius({
333
339
  isVertical: isVertical,
334
340
  positive: y > 0,
@@ -531,8 +531,38 @@ var getCurrentStack = exports.getCurrentStack = function getCurrentStack(stack,
531
531
  return _type == stack.type && _stack == stack.stack && _yOrZ == stack.yOrZ && _s.includes(stack.name);
532
532
  });
533
533
  };
534
- var getBandBackground = exports.getBandBackground = function getBandBackground(pattern, fill) {
535
- if (!(pattern && pattern.path)) return (0, _utils.getColor)(fill);
534
+ var reverseGradientStops = function reverseGradientStops(gradient) {
535
+ var _gradient$linear;
536
+ if (gradient.type !== 'linear' || !((_gradient$linear = gradient.linear) !== null && _gradient$linear !== void 0 && _gradient$linear.stops)) {
537
+ return gradient;
538
+ }
539
+ var stops = gradient.linear.stops;
540
+ //先按 offset 排序(升序),确保输入是规范的
541
+ var sortedStops = (0, _toConsumableArray2["default"])(stops).sort(function (a, b) {
542
+ return a.offset - b.offset;
543
+ });
544
+
545
+ // 反转每个 stop 的 offset: newOffset = 100 - oldOffset
546
+ // 颜色保持不变,只是位置镜像翻转
547
+ var reversedStops = sortedStops.map(function (stop) {
548
+ return _objectSpread(_objectSpread({}, stop), {}, {
549
+ offset: 100 - stop.offset
550
+ });
551
+ });
552
+ //再按新的 offset 升序排序,确保输出结构正确
553
+ var finalStops = reversedStops.sort(function (a, b) {
554
+ return a.offset - b.offset;
555
+ });
556
+ return _objectSpread(_objectSpread({}, gradient), {}, {
557
+ linear: _objectSpread(_objectSpread({}, gradient.linear), {}, {
558
+ stops: finalStops
559
+ })
560
+ });
561
+ };
562
+ var getBandBackground = exports.getBandBackground = function getBandBackground(pattern, fill, y) {
563
+ if (!(pattern && pattern.path)) {
564
+ return (0, _utils.getColor)(y < 0 ? reverseGradientStops(fill) : fill); //小于0颜色翻转
565
+ }
536
566
  try {
537
567
  var _pattern$backgroundSi = pattern.backgroundSize,
538
568
  backgroundSize = _pattern$backgroundSi === void 0 ? '100% 100%' : _pattern$backgroundSi,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.8.9",
3
+ "version": "1.8.11",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -92,7 +92,7 @@ export default memo(
92
92
  pattern = {},
93
93
  seriesIntervalWidth: paddingInner = 0,
94
94
  paddingInner: paddingOuter = 0,
95
- highlight: { show: showHighlight, extent, fill: highlightFill },
95
+ highlight: { show: showHighlight, extent, ...highlightStyle },
96
96
  ...other
97
97
  },
98
98
  curXLabel,
@@ -111,6 +111,10 @@ export default memo(
111
111
  selectConfig = { ...barStyle, headDecorate };
112
112
  }
113
113
  }
114
+ let highlightConfig = other;
115
+ if(highlightStyle){
116
+ highlightConfig = { ...other, ...highlightStyle };
117
+ }
114
118
  const step = isControlChart?controlStep:normalStep;
115
119
  const xScaler = isControlChart?controlDragScaler:normalScaler;
116
120
  const { seriesWidth, seriesStep, seriesStart } = getSeriesInfo({
@@ -159,7 +163,7 @@ export default memo(
159
163
  border,
160
164
  opacity,
161
165
  headDecorate
162
- } = x==curXLabel?selectConfig:other;
166
+ } = x==curXLabel?selectConfig:flag?highlightConfig:other;
163
167
  const { borderColor:{
164
168
  type="pure", pure="transparent", linear
165
169
  }, borderWidth=0 } = border || {};
@@ -254,8 +258,8 @@ export default memo(
254
258
  }) 0 0/100% 100%`,
255
259
  width: headWidth,
256
260
  height: headHeight,
257
- left: isVertical ? "100%" : "50%",
258
- top: isVertical ? "50%" : "0",
261
+ left: isVertical ? (y<0?"0%":"100%") : "50%",
262
+ top: isVertical ? "50%" :(y<0?"100%":"0%"),
259
263
  zIndex: 1,
260
264
  transform: `translate(calc(-50% + ${headTranslate.x}px), calc(-50% + ${headTranslate.y}px))`,
261
265
  }}
@@ -293,7 +297,8 @@ export default memo(
293
297
  ")"
294
298
  : getBandBackground(
295
299
  pattern,
296
- extent === flag ? highlightFill : fill
300
+ fill,
301
+ y//是否小于0
297
302
  ),
298
303
  borderRadius:
299
304
  style == "square"
@@ -513,9 +513,35 @@ const getCurrentStack = (stack, stackMap) =>
513
513
  _yOrZ == stack.yOrZ &&
514
514
  _s.includes(stack.name)
515
515
  );
516
-
517
- const getBandBackground = (pattern, fill) => {
518
- if (!(pattern && pattern.path)) return getColor(fill);
516
+ const reverseGradientStops=(gradient)=>{
517
+ if (gradient.type !== 'linear' || !gradient.linear?.stops) {
518
+ return gradient;
519
+ }
520
+ const stops = gradient.linear.stops;
521
+ //先按 offset 排序(升序),确保输入是规范的
522
+ const sortedStops = [...stops].sort((a, b) => a.offset - b.offset);
523
+
524
+ // 反转每个 stop 的 offset: newOffset = 100 - oldOffset
525
+ // 颜色保持不变,只是位置镜像翻转
526
+ const reversedStops = sortedStops.map(stop => ({
527
+ ...stop,
528
+ offset: 100 - stop.offset
529
+ }));
530
+ //再按新的 offset 升序排序,确保输出结构正确
531
+ const finalStops = reversedStops.sort((a, b) => a.offset - b.offset);
532
+
533
+ return {
534
+ ...gradient,
535
+ linear: {
536
+ ...gradient.linear,
537
+ stops: finalStops
538
+ }
539
+ };
540
+ }
541
+ const getBandBackground = (pattern, fill,y) => {
542
+ if (!(pattern && pattern.path)){
543
+ return getColor(y<0?reverseGradientStops(fill):fill);//小于0颜色翻转
544
+ }
519
545
  try{
520
546
  const { backgroundSize = '100% 100%', ..._pattern } = pattern;
521
547
  return (