@easyv/charts 1.6.4 → 1.6.6

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.
@@ -28,16 +28,22 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref) {
28
28
  _ref$config$tip$data = _ref$config$tip.data,
29
29
  xAxis = _ref$config$tip$data.xAxis,
30
30
  _ref$config$tip$data$ = _ref$config$tip$data.xAxis,
31
+ background = _ref$config$tip$data$.background,
32
+ gap = _ref$config$tip$data$.gap,
31
33
  align = _ref$config$tip$data$.align,
32
34
  font = _ref$config$tip$data$.font,
33
35
  translateXAxis = _ref$config$tip$data$.translate,
34
36
  dataConfig = _ref$config$tip$data.data,
35
37
  _ref$config$tip$data$2 = _ref$config$tip$data.data,
36
38
  lineHeight = _ref$config$tip$data$2.lineHeight,
39
+ dataGap = _ref$config$tip$data$2.gap,
37
40
  iconSize = _ref$config$tip$data$2.iconSize,
41
+ dataBg = _ref$config$tip$data$2.background,
38
42
  name = _ref$config$tip$data$2.name,
39
43
  value = _ref$config$tip$data$2.value,
40
44
  suffix = _ref$config$tip$data$2.suffix,
45
+ bgType = _ref$config$tip.bgType,
46
+ bgColor = _ref$config$tip.bgColor,
41
47
  image = _ref$config$tip.image,
42
48
  margin = _ref$config$tip.margin,
43
49
  _ref$config$tip$size = _ref$config$tip.size,
@@ -74,9 +80,9 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref) {
74
80
  pointerEvents: 'none',
75
81
  transform: tipPosition,
76
82
  width: tipWidth,
77
- height: tipHeight,
83
+ minHeight: tipHeight,
78
84
  padding: (0, _utils.getMargin)(margin),
79
- background: image ? '50% 50% / 100% 100% no-repeat url(' + window.appConfig.ASSETS_URL + image + ')' : 'rgba(48, 55, 66, 0.85)'
85
+ background: bgType == "image" ? image ? '50% 50% / 100% 100% no-repeat url(' + window.appConfig.ASSETS_URL + image + ')' : "transparent" : bgColor
80
86
  }, (0, _utils.getFontStyle)(font))
81
87
  }, formatter ? formatter({
82
88
  series: series,
@@ -88,19 +94,28 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref) {
88
94
  data: data,
89
95
  config: dataConfig
90
96
  }
91
- }) : /*#__PURE__*/React.createElement("dl", {
97
+ }) : /*#__PURE__*/React.createElement("div", {
92
98
  style: {
93
99
  display: 'flex',
94
100
  flexDirection: 'column',
95
101
  justifyContent: 'space-between',
102
+ gap: gap,
96
103
  height: '100%'
97
104
  }
98
- }, /*#__PURE__*/React.createElement("dt", {
105
+ }, /*#__PURE__*/React.createElement("div", {
99
106
  style: _objectSpread({
100
107
  textAlign: align,
101
- transform: (0, _utils.getTranslate3d)(translateXAxis)
108
+ transform: (0, _utils.getTranslate3d)(translateXAxis),
109
+ background: background ? "url(".concat(window.appConfig.ASSETS_URL + background, ") 0 0/100% 100%") : "transparent"
102
110
  }, font)
103
- }, x), data.map(function (_ref2, index) {
111
+ }, x), /*#__PURE__*/React.createElement("div", {
112
+ style: {
113
+ display: "flex",
114
+ flexFlow: "column nowrap",
115
+ gap: dataGap,
116
+ background: dataBg ? "url(".concat(window.appConfig.ASSETS_URL + dataBg, ") 0 0/100% 100%") : "transparent"
117
+ }
118
+ }, data.map(function (_ref2, index) {
104
119
  var showY = _ref2.showY,
105
120
  s = _ref2.s;
106
121
 
@@ -151,7 +166,7 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref) {
151
166
  transform: (0, _utils.getTranslate3d)(suffixTranslate)
152
167
  })
153
168
  }, tmp.get(s))));
154
- })));
169
+ }))));
155
170
  });
156
171
 
157
172
  exports["default"] = _default;
@@ -184,17 +184,42 @@ var getTicksOfAxis = function getTicksOfAxis(domain, ticksCount, showLast) {
184
184
  var len = domain.length;
185
185
  if (ticksCount < 2 || ticksCount > len) return domain;
186
186
  var step = Math.floor((len - ticksCount) / (ticksCount - 1));
187
- var ticksArr = domain.filter(function (d, i) {
188
- return i % (step + 1) === 0;
189
- });
190
- var Tlen = ticksArr.length;
191
- var lastIndex = domain.findIndex(function (d) {
192
- return d == ticksArr[Tlen - 1];
193
- });
187
+ var ticksArr = [];
194
188
 
195
189
  if (showLast) {
196
- len % ticksCount == 0 || len - 1 - lastIndex >= Math.round(len / Tlen / 2) ? null : ticksArr.pop();
197
- ticksArr.push(domain[len - 1]);
190
+ var count = ticksCount,
191
+ gap = 0;
192
+ step = (len - 1) / (count - 1);
193
+ var maxGap = Math.max(count - 2, len - count); //循环计算出最接近count值且能让step为整数的值
194
+
195
+ if (!Number.isInteger(step)) {
196
+ while (gap <= maxGap) {
197
+ gap++;
198
+ var left = (len - 1) / (count - gap - 1),
199
+ right = (len - 1) / (count + gap - 1);
200
+
201
+ if (Number.isInteger(left)) {
202
+ step = left;
203
+ break;
204
+ }
205
+
206
+ if (Number.isInteger(right)) {
207
+ step = right;
208
+ break;
209
+ }
210
+ }
211
+ }
212
+
213
+ if (!Number.isInteger(step)) step = 1; //如果找不到整数的step,直接取1,返回所有刻度
214
+
215
+ ticksArr = domain.filter(function (d, i) {
216
+ return i % step === 0;
217
+ });
218
+ } else {
219
+ console.log("noLast");
220
+ ticksArr = domain.filter(function (d, i) {
221
+ return i % (step + 1) === 0;
222
+ });
198
223
  }
199
224
 
200
225
  return ticksArr;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.6.4",
3
+ "version": "1.6.6",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -16,10 +16,12 @@ export default memo(
16
16
  tip: {
17
17
  data: {
18
18
  xAxis,
19
- xAxis: { align, font, translate: translateXAxis },
19
+ xAxis: { background, gap, align, font, translate: translateXAxis },
20
20
  data: dataConfig,
21
- data: { lineHeight, iconSize, name, value, suffix },
21
+ data: { lineHeight, gap:dataGap, iconSize, background:dataBg, name, value, suffix },
22
22
  },
23
+ bgType,
24
+ bgColor,
23
25
  image,
24
26
  margin,
25
27
  size: { width: tipWidth, height: tipHeight },
@@ -67,14 +69,14 @@ export default memo(
67
69
  pointerEvents: 'none',
68
70
  transform: tipPosition,
69
71
  width: tipWidth,
70
- height: tipHeight,
72
+ minHeight: tipHeight,
71
73
  padding: getMargin(margin),
72
- background: image
74
+ background: bgType=="image"?image
73
75
  ? '50% 50% / 100% 100% no-repeat url(' +
74
76
  window.appConfig.ASSETS_URL +
75
77
  image +
76
78
  ')'
77
- : 'rgba(48, 55, 66, 0.85)',
79
+ : "transparent":bgColor,
78
80
  ...getFontStyle(font),
79
81
  }}
80
82
  >
@@ -85,82 +87,92 @@ export default memo(
85
87
  data: { data, config: dataConfig },
86
88
  })
87
89
  ) : (
88
- <dl
90
+ <div
89
91
  style={{
90
92
  display: 'flex',
91
93
  flexDirection: 'column',
92
94
  justifyContent: 'space-between',
95
+ gap,
93
96
  height: '100%',
94
97
  }}
95
98
  >
96
- <dt
99
+ <div
97
100
  style={{
98
101
  textAlign: align,
99
102
  transform: getTranslate3d(translateXAxis),
103
+ background:background?`url(${window.appConfig.ASSETS_URL+background}) 0 0/100% 100%`:"transparent",
100
104
  ...font,
101
105
  }}
102
106
  >
103
107
  {x}
104
- </dt>
105
- {data.map(({ showY, s }, index) => {
106
- const { type, icon, displayName } = series.find(
107
- (series) => series.name == s
108
- );
109
- const {
110
- show: showSuffix,
111
- content,
112
- font: suffiixFont,
113
- translate: suffixTranslate,
114
- } = suffix;
115
- const tmp = new Map();
116
- Object.values(content).forEach((item) => {
117
- tmp.set(item['suffix'].name, item['suffix'].suffix);
118
- });
119
- const _icon = getIcon(type, icon);
120
- return (
121
- <dd
122
- style={{
123
- display: 'flex',
124
- justifyContent: 'space-between',
125
- lineHeight: lineHeight + 'px',
126
- }}
127
- key={index}
128
- >
129
- <span
108
+ </div>
109
+ <div style={{
110
+ display:"flex",
111
+ flexFlow:"column nowrap",
112
+ gap:dataGap,
113
+ background:dataBg?`url(${window.appConfig.ASSETS_URL+dataBg}) 0 0/100% 100%`:"transparent"
114
+ }}>
115
+ {data.map(({ showY, s }, index) => {
116
+ const { type, icon, displayName } = series.find(
117
+ (series) => series.name == s
118
+ );
119
+ const {
120
+ show: showSuffix,
121
+ content,
122
+ font: suffiixFont,
123
+ translate: suffixTranslate,
124
+ } = suffix;
125
+ const tmp = new Map();
126
+ Object.values(content).forEach((item) => {
127
+ tmp.set(item['suffix'].name, item['suffix'].suffix);
128
+ });
129
+ const _icon = getIcon(type, icon);
130
+ return (
131
+ <dd
130
132
  style={{
131
- border: '1px solid red',
132
133
  display: 'flex',
133
- alignItems: 'center',
134
- gap: icon.iconGap,
134
+ justifyContent: 'space-between',
135
+ lineHeight: lineHeight + 'px',
135
136
  }}
137
+ key={index}
136
138
  >
137
139
  <span
138
140
  style={{
139
- ..._icon,
140
- width: iconSize + 'px',
141
- height: iconSize + 'px',
141
+ border: '1px solid red',
142
+ display: 'flex',
143
+ alignItems: 'center',
144
+ gap: icon.iconGap,
142
145
  }}
143
- />
144
- <span style={getFontStyle(name)}>{displayName || s}</span>
145
- </span>
146
- <span style={getFontStyle(value)}>
147
- {showY}
148
- {showSuffix && (
146
+ >
149
147
  <span
150
148
  style={{
151
- ...getFontStyle(suffiixFont),
152
- display:"inline-block",
153
- transform: getTranslate3d(suffixTranslate),
149
+ ..._icon,
150
+ width: iconSize + 'px',
151
+ height: iconSize + 'px',
154
152
  }}
155
- >
156
- {tmp.get(s)}
157
- </span>
158
- )}
159
- </span>
160
- </dd>
161
- );
162
- })}
163
- </dl>
153
+ />
154
+ <span style={getFontStyle(name)}>{displayName || s}</span>
155
+ </span>
156
+ <span style={getFontStyle(value)}>
157
+ {showY}
158
+ {showSuffix && (
159
+ <span
160
+ style={{
161
+ ...getFontStyle(suffiixFont),
162
+ display:"inline-block",
163
+ transform: getTranslate3d(suffixTranslate),
164
+ }}
165
+ >
166
+ {tmp.get(s)}
167
+ </span>
168
+ )}
169
+ </span>
170
+ </dd>
171
+ );
172
+ })}
173
+ </div>
174
+
175
+ </div>
164
176
  )}
165
177
  </div>
166
178
  );
@@ -143,21 +143,39 @@ const getBreakWord = (str, breakNumber) => {
143
143
  };
144
144
 
145
145
  //x轴标签逻辑
146
-
147
146
  const getTicksOfAxis = (domain, ticksCount, showLast) => {
148
147
  let len = domain.length;
149
148
  if (ticksCount < 2 || ticksCount > len) return domain;
150
149
  let step = Math.floor((len - ticksCount) / (ticksCount - 1));
151
- const ticksArr = domain.filter(function (d, i) {
152
- return i % (step + 1) === 0;
153
- });
154
- let Tlen = ticksArr.length;
155
- let lastIndex = domain.findIndex((d) => d == ticksArr[Tlen - 1]);
150
+ let ticksArr = [];
156
151
  if (showLast) {
157
- len % ticksCount == 0 || len - 1 - lastIndex >= Math.round(len / Tlen / 2)
158
- ? null
159
- : ticksArr.pop();
160
- ticksArr.push(domain[len - 1]);
152
+ let count = ticksCount, gap = 0;
153
+ step = (len - 1) / (count - 1);
154
+ const maxGap = Math.max(count-2,len-count);
155
+ //循环计算出最接近count值且能让step为整数的值
156
+ if(!Number.isInteger(step)){
157
+ while(gap<=maxGap){
158
+ gap++;
159
+ const left = (len-1)/(count-gap-1), right = (len-1)/(count+gap-1);
160
+ if(Number.isInteger(left)){
161
+ step = left;
162
+ break;
163
+ }
164
+ if(Number.isInteger(right)){
165
+ step = right;
166
+ break;
167
+ }
168
+ }
169
+ }
170
+ if(!Number.isInteger(step)) step = 1; //如果找不到整数的step,直接取1,返回所有刻度
171
+ ticksArr = domain.filter(function (d, i) {
172
+ return i % step === 0;
173
+ });
174
+ }else{
175
+ console.log("noLast")
176
+ ticksArr = domain.filter(function (d, i) {
177
+ return i % (step + 1) === 0;
178
+ });
161
179
  }
162
180
  return ticksArr;
163
181
  };