@easyv/charts 1.6.4 → 1.6.5

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,21 @@ 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
+ dataBackground = _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
+ bgColor = _ref$config$tip.bgColor,
41
46
  image = _ref$config$tip.image,
42
47
  margin = _ref$config$tip.margin,
43
48
  _ref$config$tip$size = _ref$config$tip.size,
@@ -74,9 +79,9 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref) {
74
79
  pointerEvents: 'none',
75
80
  transform: tipPosition,
76
81
  width: tipWidth,
77
- height: tipHeight,
82
+ minHeight: tipHeight,
78
83
  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)'
84
+ background: image ? '50% 50% / 100% 100% no-repeat url(' + window.appConfig.ASSETS_URL + image + ')' : bgColor
80
85
  }, (0, _utils.getFontStyle)(font))
81
86
  }, formatter ? formatter({
82
87
  series: series,
@@ -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.5",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -16,10 +16,11 @@ 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
+ bgColor,
23
24
  image,
24
25
  margin,
25
26
  size: { width: tipWidth, height: tipHeight },
@@ -67,14 +68,14 @@ export default memo(
67
68
  pointerEvents: 'none',
68
69
  transform: tipPosition,
69
70
  width: tipWidth,
70
- height: tipHeight,
71
+ minHeight: tipHeight,
71
72
  padding: getMargin(margin),
72
73
  background: image
73
74
  ? '50% 50% / 100% 100% no-repeat url(' +
74
75
  window.appConfig.ASSETS_URL +
75
76
  image +
76
77
  ')'
77
- : 'rgba(48, 55, 66, 0.85)',
78
+ : bgColor,
78
79
  ...getFontStyle(font),
79
80
  }}
80
81
  >
@@ -85,82 +86,92 @@ export default memo(
85
86
  data: { data, config: dataConfig },
86
87
  })
87
88
  ) : (
88
- <dl
89
+ <div
89
90
  style={{
90
91
  display: 'flex',
91
92
  flexDirection: 'column',
92
93
  justifyContent: 'space-between',
94
+ gap,
93
95
  height: '100%',
94
96
  }}
95
97
  >
96
- <dt
98
+ <div
97
99
  style={{
98
100
  textAlign: align,
99
101
  transform: getTranslate3d(translateXAxis),
102
+ background:background?`url(${window.appConfig.ASSETS_URL+background}) 0 0/100% 100%`:"transparent",
100
103
  ...font,
101
104
  }}
102
105
  >
103
106
  {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
107
+ </div>
108
+ <div style={{
109
+ display:"flex",
110
+ flexFlow:"column nowrap",
111
+ gap:dataGap,
112
+ background:dataBg?`url(${window.appConfig.ASSETS_URL+dataBg}) 0 0/100% 100%`:"transparent"
113
+ }}>
114
+ {data.map(({ showY, s }, index) => {
115
+ const { type, icon, displayName } = series.find(
116
+ (series) => series.name == s
117
+ );
118
+ const {
119
+ show: showSuffix,
120
+ content,
121
+ font: suffiixFont,
122
+ translate: suffixTranslate,
123
+ } = suffix;
124
+ const tmp = new Map();
125
+ Object.values(content).forEach((item) => {
126
+ tmp.set(item['suffix'].name, item['suffix'].suffix);
127
+ });
128
+ const _icon = getIcon(type, icon);
129
+ return (
130
+ <dd
130
131
  style={{
131
- border: '1px solid red',
132
132
  display: 'flex',
133
- alignItems: 'center',
134
- gap: icon.iconGap,
133
+ justifyContent: 'space-between',
134
+ lineHeight: lineHeight + 'px',
135
135
  }}
136
+ key={index}
136
137
  >
137
138
  <span
138
139
  style={{
139
- ..._icon,
140
- width: iconSize + 'px',
141
- height: iconSize + 'px',
140
+ border: '1px solid red',
141
+ display: 'flex',
142
+ alignItems: 'center',
143
+ gap: icon.iconGap,
142
144
  }}
143
- />
144
- <span style={getFontStyle(name)}>{displayName || s}</span>
145
- </span>
146
- <span style={getFontStyle(value)}>
147
- {showY}
148
- {showSuffix && (
145
+ >
149
146
  <span
150
147
  style={{
151
- ...getFontStyle(suffiixFont),
152
- display:"inline-block",
153
- transform: getTranslate3d(suffixTranslate),
148
+ ..._icon,
149
+ width: iconSize + 'px',
150
+ height: iconSize + 'px',
154
151
  }}
155
- >
156
- {tmp.get(s)}
157
- </span>
158
- )}
159
- </span>
160
- </dd>
161
- );
162
- })}
163
- </dl>
152
+ />
153
+ <span style={getFontStyle(name)}>{displayName || s}</span>
154
+ </span>
155
+ <span style={getFontStyle(value)}>
156
+ {showY}
157
+ {showSuffix && (
158
+ <span
159
+ style={{
160
+ ...getFontStyle(suffiixFont),
161
+ display:"inline-block",
162
+ transform: getTranslate3d(suffixTranslate),
163
+ }}
164
+ >
165
+ {tmp.get(s)}
166
+ </span>
167
+ )}
168
+ </span>
169
+ </dd>
170
+ );
171
+ })}
172
+ </div>
173
+
174
+ </div>
164
175
  )}
165
176
  </div>
166
177
  );
@@ -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
  };