@easyv/charts 1.9.28 → 1.9.29
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.
- package/lib/components/Axis.js +16 -12
- package/package.json +1 -1
- package/src/components/Axis.tsx +42 -14
package/lib/components/Axis.js
CHANGED
|
@@ -34,8 +34,8 @@ var getCanvasContext = function getCanvasContext() {
|
|
|
34
34
|
return canvasContext;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
var calculateTextWidth = exports.calculateTextWidth = function calculateTextWidth(text, fontConfig) {
|
|
37
|
+
//计算文本宽度/高度的函数
|
|
38
|
+
var calculateTextWidth = exports.calculateTextWidth = function calculateTextWidth(text, fontConfig, isVertical) {
|
|
39
39
|
if (!text) return 0;
|
|
40
40
|
var ctx = getCanvasContext();
|
|
41
41
|
ctx.save();
|
|
@@ -47,16 +47,19 @@ var calculateTextWidth = exports.calculateTextWidth = function calculateTextWidt
|
|
|
47
47
|
var letterSpacingWithUnit = "".concat(letterSpacing, "px");
|
|
48
48
|
ctx.font = "".concat(fontWeight, " ").concat(fontStyle, " ").concat(fontSize, " ").concat(fontFamily);
|
|
49
49
|
ctx.letterSpacing = letterSpacingWithUnit;
|
|
50
|
-
var totalWidth;
|
|
50
|
+
var totalWidth = 0;
|
|
51
|
+
var totalHeight = 0;
|
|
52
|
+
var textMetrics = ctx.measureText(text);
|
|
51
53
|
if (typeof ctx.letterSpacing !== "undefined") {
|
|
52
|
-
totalWidth =
|
|
54
|
+
totalWidth = textMetrics.width;
|
|
53
55
|
} else {
|
|
54
|
-
var baseWidth =
|
|
55
|
-
var spacingWidth = text.length * letterSpacing;
|
|
56
|
+
var baseWidth = textMetrics.width;
|
|
57
|
+
var spacingWidth = (text.length - 1) * letterSpacing;
|
|
56
58
|
totalWidth = baseWidth + spacingWidth;
|
|
57
59
|
}
|
|
60
|
+
totalHeight = textMetrics.fontBoundingBoxAscent + textMetrics.fontBoundingBoxDescent;
|
|
58
61
|
ctx.restore();
|
|
59
|
-
return totalWidth;
|
|
62
|
+
return isVertical ? totalHeight : totalWidth;
|
|
60
63
|
};
|
|
61
64
|
var defaultEvent = function defaultEvent() {};
|
|
62
65
|
var defaultAppearance = {
|
|
@@ -190,7 +193,7 @@ var Unit = function Unit(_ref4) {
|
|
|
190
193
|
textAnchor: textAnchor
|
|
191
194
|
}, dataUnit || text);
|
|
192
195
|
};
|
|
193
|
-
function maxLabelFT(data, config, formatter, font) {
|
|
196
|
+
function maxLabelFT(data, config, formatter, font, isVertical) {
|
|
194
197
|
var max = 0;
|
|
195
198
|
data.length ? data.forEach(function (item) {
|
|
196
199
|
if (calculateTextWidth(formatter(item, _objectSpread(_objectSpread({}, config), {}, {
|
|
@@ -198,12 +201,12 @@ function maxLabelFT(data, config, formatter, font) {
|
|
|
198
201
|
type: config.format,
|
|
199
202
|
showType: config.showType
|
|
200
203
|
}
|
|
201
|
-
})), font) > max) max = calculateTextWidth(formatter(item, _objectSpread(_objectSpread({}, config), {}, {
|
|
204
|
+
})), font, isVertical) > max) max = calculateTextWidth(formatter(item, _objectSpread(_objectSpread({}, config), {}, {
|
|
202
205
|
format: {
|
|
203
206
|
type: config.format,
|
|
204
207
|
showType: config.showType
|
|
205
208
|
}
|
|
206
|
-
})), font);
|
|
209
|
+
})), font, isVertical);
|
|
207
210
|
}) : "";
|
|
208
211
|
return max;
|
|
209
212
|
}
|
|
@@ -341,6 +344,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(
|
|
|
341
344
|
var cHeight = controlInfo.cHeight,
|
|
342
345
|
isC = controlInfo.isC,
|
|
343
346
|
cPercent = controlInfo.cPercent;
|
|
347
|
+
var isVertical = orientation == "left" || orientation == "right";
|
|
344
348
|
var x = orientation == "right" ? width : 0;
|
|
345
349
|
var y = orientation == "bottom" ? height - cHeight : 0;
|
|
346
350
|
var LabelWidth = 1;
|
|
@@ -348,10 +352,10 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(
|
|
|
348
352
|
LabelWidth = label.appearance.width;
|
|
349
353
|
} else {
|
|
350
354
|
if (allTicks.length && typeof allTicks[0] == "string") {
|
|
351
|
-
LabelWidth = maxLabelFT(allTicks, label, formatter, label.font);
|
|
355
|
+
LabelWidth = maxLabelFT(allTicks, label, formatter, label.font, isVertical);
|
|
352
356
|
}
|
|
353
357
|
}
|
|
354
|
-
var LabelNum = Math.floor(width / (isC ? cPercent : 1) * (1 - paddingOuter) / LabelWidth);
|
|
358
|
+
var LabelNum = !isVertical ? Math.floor(width / (isC ? cPercent : 1) * (1 - paddingOuter) / LabelWidth) : Math.floor(height / LabelWidth);
|
|
355
359
|
var ticks = !label.adaptive ? tickss : getEvenlySpacedElements(allTicks, LabelNum < allTicks.length ? LabelNum > allTicks.length / 2 ? Math.ceil(allTicks.length / 2) : LabelNum : allTicks.length, label.showLast);
|
|
356
360
|
if (!(on && ticks.length > 0)) return null;
|
|
357
361
|
|
package/package.json
CHANGED
package/src/components/Axis.tsx
CHANGED
|
@@ -28,8 +28,12 @@ const getCanvasContext = (): CanvasRenderingContext2D => {
|
|
|
28
28
|
return canvasContext;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
export const calculateTextWidth = (
|
|
31
|
+
//计算文本宽度/高度的函数
|
|
32
|
+
export const calculateTextWidth = (
|
|
33
|
+
text: string,
|
|
34
|
+
fontConfig: any,
|
|
35
|
+
isVertical: any
|
|
36
|
+
): number => {
|
|
33
37
|
if (!text) return 0;
|
|
34
38
|
const ctx = getCanvasContext();
|
|
35
39
|
ctx.save();
|
|
@@ -45,16 +49,22 @@ export const calculateTextWidth = (text: string, fontConfig: any): number => {
|
|
|
45
49
|
const letterSpacingWithUnit = `${letterSpacing}px`;
|
|
46
50
|
ctx.font = `${fontWeight} ${fontStyle} ${fontSize} ${fontFamily}`;
|
|
47
51
|
ctx.letterSpacing = letterSpacingWithUnit;
|
|
48
|
-
|
|
52
|
+
|
|
53
|
+
let totalWidth = 0;
|
|
54
|
+
let totalHeight = 0;
|
|
55
|
+
const textMetrics = ctx.measureText(text);
|
|
56
|
+
|
|
49
57
|
if (typeof ctx.letterSpacing !== "undefined") {
|
|
50
|
-
totalWidth =
|
|
58
|
+
totalWidth = textMetrics.width;
|
|
51
59
|
} else {
|
|
52
|
-
const baseWidth =
|
|
53
|
-
const spacingWidth = text.length * letterSpacing;
|
|
60
|
+
const baseWidth = textMetrics.width;
|
|
61
|
+
const spacingWidth = (text.length - 1) * letterSpacing;
|
|
54
62
|
totalWidth = baseWidth + spacingWidth;
|
|
55
63
|
}
|
|
64
|
+
totalHeight =
|
|
65
|
+
textMetrics.fontBoundingBoxAscent + textMetrics.fontBoundingBoxDescent;
|
|
56
66
|
ctx.restore();
|
|
57
|
-
return totalWidth;
|
|
67
|
+
return isVertical ? totalHeight : totalWidth;
|
|
58
68
|
};
|
|
59
69
|
const defaultEvent = () => {};
|
|
60
70
|
const defaultAppearance = {
|
|
@@ -238,7 +248,13 @@ type LabelType = {
|
|
|
238
248
|
LabelWidth: any;
|
|
239
249
|
};
|
|
240
250
|
|
|
241
|
-
function maxLabelFT(
|
|
251
|
+
function maxLabelFT(
|
|
252
|
+
data: any,
|
|
253
|
+
config: any,
|
|
254
|
+
formatter: any,
|
|
255
|
+
font: any,
|
|
256
|
+
isVertical: any
|
|
257
|
+
) {
|
|
242
258
|
let max = 0;
|
|
243
259
|
data.length
|
|
244
260
|
? data.forEach((item: any) => {
|
|
@@ -248,7 +264,8 @@ function maxLabelFT(data: any, config: any, formatter: any, font: any) {
|
|
|
248
264
|
...config,
|
|
249
265
|
format: { type: config.format, showType: config.showType },
|
|
250
266
|
}),
|
|
251
|
-
font
|
|
267
|
+
font,
|
|
268
|
+
isVertical
|
|
252
269
|
) > max
|
|
253
270
|
)
|
|
254
271
|
max = calculateTextWidth(
|
|
@@ -256,7 +273,8 @@ function maxLabelFT(data: any, config: any, formatter: any, font: any) {
|
|
|
256
273
|
...config,
|
|
257
274
|
format: { type: config.format, showType: config.showType },
|
|
258
275
|
}),
|
|
259
|
-
font
|
|
276
|
+
font,
|
|
277
|
+
isVertical
|
|
260
278
|
);
|
|
261
279
|
})
|
|
262
280
|
: "";
|
|
@@ -395,6 +413,7 @@ export default memo(
|
|
|
395
413
|
) => {
|
|
396
414
|
const { width, height, isIOS } = useContext(chartContext);
|
|
397
415
|
const { cHeight, isC, cPercent } = controlInfo;
|
|
416
|
+
const isVertical = orientation == "left" || orientation == "right";
|
|
398
417
|
const x = orientation == "right" ? width : 0;
|
|
399
418
|
const y = orientation == "bottom" ? height - cHeight : 0;
|
|
400
419
|
let LabelWidth = 1;
|
|
@@ -402,12 +421,21 @@ export default memo(
|
|
|
402
421
|
LabelWidth = label.appearance.width;
|
|
403
422
|
} else {
|
|
404
423
|
if (allTicks.length && typeof allTicks[0] == "string") {
|
|
405
|
-
LabelWidth = maxLabelFT(
|
|
424
|
+
LabelWidth = maxLabelFT(
|
|
425
|
+
allTicks,
|
|
426
|
+
label,
|
|
427
|
+
formatter,
|
|
428
|
+
label.font,
|
|
429
|
+
isVertical
|
|
430
|
+
);
|
|
406
431
|
}
|
|
407
432
|
}
|
|
408
|
-
const LabelNum =
|
|
409
|
-
|
|
410
|
-
|
|
433
|
+
const LabelNum = !isVertical
|
|
434
|
+
? Math.floor(
|
|
435
|
+
((width / (isC ? cPercent : 1)) * (1 - paddingOuter)) / LabelWidth
|
|
436
|
+
)
|
|
437
|
+
: Math.floor(height / LabelWidth);
|
|
438
|
+
|
|
411
439
|
const ticks: any = !label.adaptive
|
|
412
440
|
? tickss
|
|
413
441
|
: getEvenlySpacedElements(
|