@easyv/charts 1.7.31 → 1.7.33

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.
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports["default"] = void 0;
9
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
11
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
12
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
@@ -33,6 +34,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
33
34
  _ref$config$order = _ref$config.order,
34
35
  order = _ref$config$order === void 0 ? '' : _ref$config$order,
35
36
  interactive = _ref$config.interactive,
37
+ LegendType = _ref$config.LegendType,
36
38
  maxWidth = _ref$config.maxWidth,
37
39
  textOverflow = _ref$config.textOverflow,
38
40
  speed = _ref$config.speed,
@@ -122,14 +124,15 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
122
124
  d.percent = 0;
123
125
  });
124
126
  }
125
- return /*#__PURE__*/_react["default"].createElement("div", {
127
+ return LegendType == "FixedWidth" ? /*#__PURE__*/_react["default"].createElement("div", {
126
128
  className: "__easyv-legend-wrapper",
127
129
  style: _objectSpread(_objectSpread({
128
130
  position: 'absolute',
129
131
  display: 'flex'
130
132
  }, getPosition(position, _alignment, x, y)), {}, {
131
133
  height: loop.show ? height : 'auto',
132
- overflowY: loop.show ? 'scroll' : 'auto'
134
+ overflowY: loop.show ? 'scroll' : 'auto',
135
+ pointerEvents: "none" //鼠标穿透
133
136
  }),
134
137
  ref: ref_container
135
138
  }, /*#__PURE__*/_react["default"].createElement("ul", {
@@ -169,7 +172,67 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
169
172
  }),
170
173
  speed: speed
171
174
  })));
172
- })));
175
+ }))) : /*#__PURE__*/_react["default"].createElement("div", {
176
+ className: "__easyv-legend-wrapper",
177
+ style: _objectSpread(_objectSpread({
178
+ display: 'flex',
179
+ flexWrap: "wrap",
180
+ alignContent: alignment.split(" ")[0] == "center" && (alignment.split(" ")[1] == "left" || alignment.split(" ")[1] == "right") ? alignment.split(" ")[1] == "left" ? "flex-start" : "flex-end" : alignment.split(" ")[0] == "left" ? "flex-start" : alignment.split(" ")[0] == "center" ? "center" : "flex-end",
181
+ flexDirection: "column",
182
+ position: 'absolute'
183
+ }, getPosition(position, _alignment, x, y)), {}, {
184
+ height: loop.show ? height : 'auto',
185
+ overflowY: loop.show ? 'scroll' : 'auto',
186
+ width: "100%",
187
+ pointerEvents: "none"
188
+ }),
189
+ ref: ref_container
190
+ }, (0, _toConsumableArray2["default"])(Array(Math.ceil(series.length / gridTemplateColumns))).map(function (_, indexs) {
191
+ return /*#__PURE__*/_react["default"].createElement("ul", {
192
+ key: indexs,
193
+ style: (0, _defineProperty2["default"])({
194
+ display: 'flex',
195
+ width: 'fit-content',
196
+ justifyContent: alignment.split(" ")[0] == "left" ? "flex-start" : alignment.split(" ")[0] == "center" ? "center" : "flex-end",
197
+ marginBottom: "0px",
198
+ gap: "".concat(gridRowGap, "px ").concat(gridColumnGap, "px")
199
+ }, "marginBottom", gridRowGap + "px")
200
+ }, _series.map(function (series, index) {
201
+ if (Math.floor(index / gridTemplateColumns) == indexs) {
202
+ var _series$config2;
203
+ var type = series.type,
204
+ name = series.name,
205
+ displayName = series.displayName,
206
+ icon = series.icon,
207
+ selected = series.selected;
208
+ var _icon = (0, _utils.getIcon)(type, icon, series === null || series === void 0 || (_series$config2 = series.config) === null || _series$config2 === void 0 || (_series$config2 = _series$config2.line) === null || _series$config2 === void 0 ? void 0 : _series$config2.type);
209
+ return /*#__PURE__*/_react["default"].createElement("li", {
210
+ key: index,
211
+ onClick: onClick,
212
+ "data-name": name,
213
+ style: {
214
+ display: 'flex',
215
+ opacity: selected === false ? opacity / 100 : 1,
216
+ alignItems: 'center',
217
+ cursor: "pointer",
218
+ gap: _icon.gap
219
+ }
220
+ }, formatter ? formatter(series, config) : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("span", {
221
+ style: _icon
222
+ }), /*#__PURE__*/_react["default"].createElement(_TextOverflow["default"], {
223
+ ShowType: LegendType,
224
+ type: "ellipsis",
225
+ value: displayName || name,
226
+ style: _objectSpread(_objectSpread({}, font), {}, {
227
+ fontStyle: italic ? 'italic' : 'normal',
228
+ fontWeight: bold ? 'bold' : 'normal',
229
+ minWidth: getCanvasTextWidth(displayName.substring(0, 5) || name.substring(0, 5), font.letterSpacing, "".concat(font.fontSize, "px ").concat(font.fontFamily))
230
+ }),
231
+ speed: speed
232
+ })));
233
+ }
234
+ }));
235
+ }));
173
236
  });
174
237
  var getPosition = function getPosition(position, alignment) {
175
238
  var x = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
@@ -203,4 +266,12 @@ var getPosition = function getPosition(position, alignment) {
203
266
  transform: "translate3d(calc(".concat(alignment == 'center' ? '-50%' : '0px', " + ").concat(x, "px), ").concat(y, "px, 0px)")
204
267
  };
205
268
  }
269
+ };
270
+ var getCanvasTextWidth = function getCanvasTextWidth(text, letterSpacing) {
271
+ var font = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '16px Arial';
272
+ var canvas = document.createElement('canvas');
273
+ var ctx = canvas.getContext('2d');
274
+ ctx.font = font;
275
+ return ctx.measureText(text).width + text.length * letterSpacing + "px";
276
+ // return ctx.measureText(text).width+(text.length-1)*letterSpacing+"px";//-1有bug
206
277
  };
@@ -24,7 +24,8 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(
24
24
  _props$speed = props.speed,
25
25
  speed = _props$speed === void 0 ? 5 : _props$speed,
26
26
  _props$config = props.config,
27
- config = _props$config === void 0 ? {} : _props$config;
27
+ config = _props$config === void 0 ? {} : _props$config,
28
+ ShowType = props.ShowType;
28
29
  var _config$needTitle = config.needTitle,
29
30
  needTitle = _config$needTitle === void 0 ? true : _config$needTitle;
30
31
  var getTextOverflow = function getTextOverflow(type) {
@@ -59,7 +60,9 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(
59
60
  style: styles,
60
61
  ref: ref
61
62
  }) : /*#__PURE__*/_react["default"].createElement("div", {
62
- style: styles,
63
+ style: _objectSpread(_objectSpread({}, styles), {}, {
64
+ whiteSpace: ShowType == "Adaptive" ? "normal" : styles.whiteSpace
65
+ }),
63
66
  ref: ref,
64
67
  title: needTitle && type == "ellipsis" ? text || undefined : undefined,
65
68
  dangerouslySetInnerHTML: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.7.31",
3
+ "version": "1.7.33",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -19,6 +19,7 @@ export default memo(
19
19
  show,
20
20
  order = '',
21
21
  interactive,
22
+ LegendType,//类型
22
23
  maxWidth,
23
24
  textOverflow,
24
25
  speed,
@@ -100,6 +101,7 @@ export default memo(
100
101
  }
101
102
 
102
103
  return (
104
+ LegendType=="FixedWidth"?
103
105
  <div
104
106
  className='__easyv-legend-wrapper'
105
107
  style={{
@@ -108,6 +110,7 @@ export default memo(
108
110
  ...getPosition(position, _alignment, x, y),
109
111
  height: loop.show ? height : 'auto',
110
112
  overflowY: loop.show ? 'scroll' : 'auto',
113
+ pointerEvents:"none"//鼠标穿透
111
114
  }}
112
115
  ref={ref_container}
113
116
  >
@@ -153,6 +156,73 @@ export default memo(
153
156
  );
154
157
  })}
155
158
  </ul>
159
+ </div>:<div
160
+ className='__easyv-legend-wrapper'
161
+ style={{
162
+ display:'flex',
163
+ flexWrap:"wrap",
164
+ alignContent:alignment.split(" ")[0]=="center"&&(alignment.split(" ")[1]=="left"||alignment.split(" ")[1]=="right")?alignment.split(" ")[1]=="left"?"flex-start":"flex-end":alignment.split(" ")[0]=="left"?"flex-start":alignment.split(" ")[0]=="center"?"center":"flex-end",
165
+ flexDirection: "column",
166
+ position: 'absolute',
167
+ ...getPosition(position, _alignment, x, y),
168
+ height: loop.show ? height : 'auto',
169
+ overflowY: loop.show ? 'scroll' : 'auto',
170
+ width:"100%",
171
+ pointerEvents:"none"
172
+ }}
173
+ ref={ref_container}
174
+ >
175
+
176
+ {[...Array(Math.ceil(series.length/gridTemplateColumns))].map((_,indexs)=>(
177
+ <ul
178
+ key={indexs}
179
+ style={{
180
+ display: 'flex',
181
+ width: 'fit-content',
182
+ justifyContent:alignment.split(" ")[0]=="left"?"flex-start":alignment.split(" ")[0]=="center"?"center":"flex-end",
183
+ marginBottom:"0px",
184
+ gap:`${gridRowGap}px ${gridColumnGap}px`,
185
+ marginBottom:gridRowGap+"px"
186
+ }}
187
+ >
188
+ {_series.map((series, index) => {
189
+ if(Math.floor(index/gridTemplateColumns)==indexs){
190
+ const { type, name, displayName, icon, selected } = series;
191
+ const _icon = getIcon(type, icon, series?.config?.line?.type);
192
+ return (
193
+ <li
194
+ key={index}
195
+ onClick={onClick}
196
+ data-name={name}
197
+ style={{
198
+ display: 'flex',
199
+ opacity: selected === false ? opacity / 100 : 1,
200
+ alignItems: 'center',
201
+ cursor: "pointer",
202
+ gap: _icon.gap,
203
+ }}
204
+ >
205
+ {formatter ? (
206
+ formatter(series, config)
207
+ ) : (
208
+ <>
209
+ <span style={_icon} />
210
+ <TextOverflow ShowType={LegendType} type="ellipsis" value={displayName || name} style={{
211
+ ...font,
212
+ fontStyle: italic ? 'italic' : 'normal',
213
+ fontWeight: bold ? 'bold' : 'normal',
214
+ minWidth:getCanvasTextWidth(displayName.substring(0,5) || name.substring(0,5),font.letterSpacing,`${font.fontSize}px ${font.fontFamily}` )
215
+ }} speed={speed}></TextOverflow>
216
+
217
+ </>
218
+ )}
219
+ </li>
220
+ );
221
+ }
222
+ })}
223
+ </ul>
224
+ ))
225
+ }
156
226
  </div>
157
227
  );
158
228
  }
@@ -188,3 +258,10 @@ const getPosition = (position, alignment, x = 0, y = 0) => {
188
258
  };
189
259
  }
190
260
  };
261
+ const getCanvasTextWidth=(text,letterSpacing, font = '16px Arial')=>{
262
+ const canvas = document.createElement('canvas');
263
+ const ctx = canvas.getContext('2d');
264
+ ctx.font = font;
265
+ return ctx.measureText(text).width+(text.length)*letterSpacing+"px";
266
+ // return ctx.measureText(text).width+(text.length-1)*letterSpacing+"px";//-1有bug
267
+ }
@@ -10,7 +10,8 @@ interface flowText{
10
10
  value:string,
11
11
  speed:number,
12
12
  style:CSSProperties,
13
- config?:any
13
+ config?:any,
14
+ ShowType:string
14
15
  }
15
16
 
16
17
  export default memo(forwardRef((props:flowText, ref:any) => {
@@ -19,7 +20,8 @@ export default memo(forwardRef((props:flowText, ref:any) => {
19
20
  value, // 文本
20
21
  style, // 样式
21
22
  speed = 5, // 动画速度
22
- config = {}
23
+ config = {},
24
+ ShowType
23
25
  } = props;
24
26
  const { needTitle = true } = config;
25
27
 
@@ -60,6 +62,7 @@ export default memo(forwardRef((props:flowText, ref:any) => {
60
62
  style={styles}
61
63
  ref={ref} />
62
64
  ) : (
63
- <div style={styles} ref={ref} title={needTitle && type=="ellipsis"?text || undefined:undefined} dangerouslySetInnerHTML={{__html:value}}></div>
65
+ <div style={{...styles,
66
+ whiteSpace:ShowType=="Adaptive"?"normal":styles.whiteSpace}} ref={ref} title={needTitle && type=="ellipsis"?text || undefined:undefined} dangerouslySetInnerHTML={{__html:value}}></div>
64
67
  );
65
68
  }));