@easyv/charts 1.9.18 → 1.9.19
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 +46 -34
- package/package.json +1 -1
- package/src/components/Axis.tsx +53 -38
package/lib/components/Axis.js
CHANGED
|
@@ -339,6 +339,11 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(
|
|
|
339
339
|
width = _useContext.width,
|
|
340
340
|
height = _useContext.height,
|
|
341
341
|
isIOS = _useContext.isIOS;
|
|
342
|
+
var cHeight = controlInfo.cHeight,
|
|
343
|
+
isC = controlInfo.isC,
|
|
344
|
+
cPercent = controlInfo.cPercent;
|
|
345
|
+
var x = orientation == "right" ? width : 0;
|
|
346
|
+
var y = orientation == "bottom" ? height - cHeight : 0;
|
|
342
347
|
var LabelWidth = 1;
|
|
343
348
|
if (label.labelNum == "Fixed") {
|
|
344
349
|
LabelWidth = label.appearance.width;
|
|
@@ -347,53 +352,59 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(
|
|
|
347
352
|
LabelWidth = maxLabelFT(allTicks, label, formatter, label.font);
|
|
348
353
|
}
|
|
349
354
|
}
|
|
350
|
-
var LabelNum = Math.floor(width * (1 - paddingOuter) / LabelWidth);
|
|
351
|
-
var ticks = label.labelNum == "Fixed" ? tickss : getEvenlySpacedElements(allTicks, LabelNum < allTicks.length ? LabelNum > allTicks.length / 2 ? Math.ceil(allTicks.length
|
|
355
|
+
var LabelNum = Math.floor(width / (isC ? cPercent : 1) * (1 - paddingOuter) / LabelWidth);
|
|
356
|
+
var ticks = label.labelNum == "Fixed" ? tickss : getEvenlySpacedElements(allTicks, LabelNum < allTicks.length ? LabelNum > allTicks.length / 2 ? Math.ceil(allTicks.length / 2) : LabelNum : allTicks.length, label.showLast);
|
|
352
357
|
if (!(on && ticks.length > 0)) return null;
|
|
353
|
-
|
|
354
|
-
isC = controlInfo.isC,
|
|
355
|
-
cPercent = controlInfo.cPercent;
|
|
356
|
-
var x = orientation == "right" ? width : 0;
|
|
357
|
-
var y = orientation == "bottom" ? height - cHeight : 0;
|
|
358
|
+
|
|
358
359
|
//数据抽取逻辑
|
|
359
360
|
function getEvenlySpacedElements(arr, expectCount) {
|
|
360
361
|
var acc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
361
362
|
if (!arr.length || expectCount <= 0) return [];
|
|
362
363
|
if (expectCount >= arr.length) return (0, _toConsumableArray2["default"])(arr);
|
|
363
|
-
|
|
364
|
-
// 如果只需要取1个,直接返回第一个
|
|
365
|
-
if (expectCount === 1) {
|
|
366
|
-
return [arr[0]];
|
|
367
|
-
}
|
|
364
|
+
if (expectCount === 1) return [arr[0]];
|
|
368
365
|
if (acc) {
|
|
369
|
-
|
|
370
|
-
var result = [
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
result.length = 0;
|
|
379
|
-
result.push(arr[0]);
|
|
380
|
-
for (var i = 1; i <= needMiddleCount; i++) {
|
|
381
|
-
var index = i * step;
|
|
382
|
-
result.push(arr[index]);
|
|
366
|
+
var totalLength = arr.length;
|
|
367
|
+
var result = [];
|
|
368
|
+
var bestCount = 2;
|
|
369
|
+
for (var k = expectCount; k >= 2; k--) {
|
|
370
|
+
var denominator = k - 1;
|
|
371
|
+
var numerator = totalLength - 1;
|
|
372
|
+
if (denominator > 0 && numerator % denominator === 0) {
|
|
373
|
+
bestCount = k;
|
|
374
|
+
break;
|
|
383
375
|
}
|
|
384
|
-
result.push(arr[arr.length - 1]);
|
|
385
376
|
}
|
|
377
|
+
var step = (totalLength - 1) / (bestCount - 1);
|
|
378
|
+
for (var i = 0; i < bestCount; i++) {
|
|
379
|
+
var rawIndex = i * step;
|
|
380
|
+
var index = Math.ceil(rawIndex);
|
|
381
|
+
var safeIndex = Math.max(0, Math.min(totalLength - 1, index));
|
|
382
|
+
result.push(arr[safeIndex]);
|
|
383
|
+
}
|
|
384
|
+
if (result.length > 0) result[0] = arr[0];
|
|
385
|
+
if (result.length >= 2) result[result.length - 1] = arr[totalLength - 1];
|
|
386
386
|
return result;
|
|
387
387
|
} else {
|
|
388
|
+
// 重构acc=false逻辑:优先均匀分布,不强制首尾
|
|
388
389
|
var _result = [];
|
|
389
390
|
var arrLen = arr.length;
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
_result.push(arr[
|
|
393
|
-
|
|
391
|
+
if (expectCount === 2) {
|
|
392
|
+
_result.push(arr[0]);
|
|
393
|
+
_result.push(arr[arrLen - 1]);
|
|
394
|
+
return _result;
|
|
394
395
|
}
|
|
395
|
-
|
|
396
|
-
|
|
396
|
+
var idealStep = (arrLen - 1) / (expectCount - 1);
|
|
397
|
+
var isIdealStepInteger = Math.abs(idealStep - Math.round(idealStep)) < 1e-10;
|
|
398
|
+
if (isIdealStepInteger) {
|
|
399
|
+
for (var _i = 0; _i < expectCount; _i++) {
|
|
400
|
+
var _index = _i * idealStep;
|
|
401
|
+
_result.push(arr[_index]);
|
|
402
|
+
}
|
|
403
|
+
} else {
|
|
404
|
+
var _step = Math.max(1, Math.floor(arrLen / expectCount));
|
|
405
|
+
for (var _i2 = 0; _i2 < arrLen && _result.length < expectCount; _i2 += _step) {
|
|
406
|
+
_result.push(arr[_i2]);
|
|
407
|
+
}
|
|
397
408
|
}
|
|
398
409
|
return _result;
|
|
399
410
|
}
|
|
@@ -474,7 +485,8 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(
|
|
|
474
485
|
return draw(ticks, scaler[index]);
|
|
475
486
|
}));
|
|
476
487
|
} else if (isC && orientation == "bottom") {
|
|
477
|
-
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, draw(
|
|
488
|
+
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, draw(ticks, scaler));
|
|
489
|
+
// return <>{draw(rawTicks, scaler)}</>;
|
|
478
490
|
} else {
|
|
479
491
|
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, draw(ticks, scaler));
|
|
480
492
|
}
|
package/package.json
CHANGED
package/src/components/Axis.tsx
CHANGED
|
@@ -392,6 +392,9 @@ export default memo(
|
|
|
392
392
|
ref
|
|
393
393
|
) => {
|
|
394
394
|
const { width, height, isIOS } = useContext(chartContext);
|
|
395
|
+
const { cHeight, isC, cPercent } = controlInfo;
|
|
396
|
+
const x = orientation == "right" ? width : 0;
|
|
397
|
+
const y = orientation == "bottom" ? height - cHeight : 0;
|
|
395
398
|
let LabelWidth = 1;
|
|
396
399
|
if (label.labelNum == "Fixed") {
|
|
397
400
|
LabelWidth = label.appearance.width;
|
|
@@ -400,7 +403,9 @@ export default memo(
|
|
|
400
403
|
LabelWidth = maxLabelFT(allTicks, label, formatter, label.font);
|
|
401
404
|
}
|
|
402
405
|
}
|
|
403
|
-
const LabelNum = Math.floor(
|
|
406
|
+
const LabelNum = Math.floor(
|
|
407
|
+
((width / (isC ? cPercent : 1)) * (1 - paddingOuter)) / LabelWidth
|
|
408
|
+
);
|
|
404
409
|
const ticks: any =
|
|
405
410
|
label.labelNum == "Fixed"
|
|
406
411
|
? tickss
|
|
@@ -408,16 +413,13 @@ export default memo(
|
|
|
408
413
|
allTicks,
|
|
409
414
|
LabelNum < allTicks.length
|
|
410
415
|
? LabelNum > allTicks.length / 2
|
|
411
|
-
? Math.ceil(allTicks.length
|
|
416
|
+
? Math.ceil(allTicks.length / 2)
|
|
412
417
|
: LabelNum
|
|
413
418
|
: allTicks.length,
|
|
414
419
|
label.showLast
|
|
415
420
|
);
|
|
416
421
|
if (!(on && ticks.length > 0)) return null;
|
|
417
422
|
|
|
418
|
-
const { cHeight, isC, cPercent } = controlInfo;
|
|
419
|
-
const x = orientation == "right" ? width : 0;
|
|
420
|
-
const y = orientation == "bottom" ? height - cHeight : 0;
|
|
421
423
|
//数据抽取逻辑
|
|
422
424
|
function getEvenlySpacedElements(
|
|
423
425
|
arr: any[],
|
|
@@ -426,51 +428,63 @@ export default memo(
|
|
|
426
428
|
): any[] {
|
|
427
429
|
if (!arr.length || expectCount <= 0) return [];
|
|
428
430
|
if (expectCount >= arr.length) return [...arr];
|
|
429
|
-
|
|
430
|
-
// 如果只需要取1个,直接返回第一个
|
|
431
|
-
if (expectCount === 1) {
|
|
432
|
-
return [arr[0]];
|
|
433
|
-
}
|
|
431
|
+
if (expectCount === 1) return [arr[0]];
|
|
434
432
|
|
|
435
433
|
if (acc) {
|
|
436
|
-
|
|
437
|
-
const result: any[] = [
|
|
438
|
-
if (expectCount === 2) {
|
|
439
|
-
return result;
|
|
440
|
-
}
|
|
441
|
-
const needMiddleCount = expectCount - 2;
|
|
442
|
-
const availableMiddleLength = arr.length - 2;
|
|
434
|
+
const totalLength = arr.length;
|
|
435
|
+
const result: any[] = [];
|
|
443
436
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
result.push(arr[0]);
|
|
452
|
-
for (let i = 1; i <= needMiddleCount; i++) {
|
|
453
|
-
const index = i * step;
|
|
454
|
-
result.push(arr[index]);
|
|
437
|
+
let bestCount = 2;
|
|
438
|
+
for (let k = expectCount; k >= 2; k--) {
|
|
439
|
+
const denominator = k - 1;
|
|
440
|
+
const numerator = totalLength - 1;
|
|
441
|
+
if (denominator > 0 && numerator % denominator === 0) {
|
|
442
|
+
bestCount = k;
|
|
443
|
+
break;
|
|
455
444
|
}
|
|
445
|
+
}
|
|
456
446
|
|
|
457
|
-
|
|
447
|
+
const step = (totalLength - 1) / (bestCount - 1);
|
|
448
|
+
for (let i = 0; i < bestCount; i++) {
|
|
449
|
+
const rawIndex = i * step;
|
|
450
|
+
const index = Math.ceil(rawIndex);
|
|
451
|
+
const safeIndex = Math.max(0, Math.min(totalLength - 1, index));
|
|
452
|
+
result.push(arr[safeIndex]);
|
|
458
453
|
}
|
|
459
454
|
|
|
455
|
+
if (result.length > 0) result[0] = arr[0];
|
|
456
|
+
if (result.length >= 2)
|
|
457
|
+
result[result.length - 1] = arr[totalLength - 1];
|
|
458
|
+
|
|
460
459
|
return result;
|
|
461
460
|
} else {
|
|
461
|
+
// 重构acc=false逻辑:优先均匀分布,不强制首尾
|
|
462
462
|
const result: any[] = [];
|
|
463
463
|
const arrLen = arr.length;
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
result
|
|
468
|
-
if (result.length >= expectCount) break;
|
|
469
|
-
}
|
|
470
|
-
if (expectCount === 2 && result.length >= 2) {
|
|
471
|
-
result[1] = arr[arr.length - 1];
|
|
464
|
+
if (expectCount === 2) {
|
|
465
|
+
result.push(arr[0]);
|
|
466
|
+
result.push(arr[arrLen - 1]);
|
|
467
|
+
return result;
|
|
472
468
|
}
|
|
469
|
+
const idealStep = (arrLen - 1) / (expectCount - 1);
|
|
470
|
+
const isIdealStepInteger =
|
|
471
|
+
Math.abs(idealStep - Math.round(idealStep)) < 1e-10;
|
|
473
472
|
|
|
473
|
+
if (isIdealStepInteger) {
|
|
474
|
+
for (let i = 0; i < expectCount; i++) {
|
|
475
|
+
const index = i * idealStep;
|
|
476
|
+
result.push(arr[index]);
|
|
477
|
+
}
|
|
478
|
+
} else {
|
|
479
|
+
const step = Math.max(1, Math.floor(arrLen / expectCount));
|
|
480
|
+
for (
|
|
481
|
+
let i = 0;
|
|
482
|
+
i < arrLen && result.length < expectCount;
|
|
483
|
+
i += step
|
|
484
|
+
) {
|
|
485
|
+
result.push(arr[i]);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
474
488
|
return result;
|
|
475
489
|
}
|
|
476
490
|
}
|
|
@@ -588,7 +602,8 @@ export default memo(
|
|
|
588
602
|
</>
|
|
589
603
|
);
|
|
590
604
|
} else if (isC && orientation == "bottom") {
|
|
591
|
-
return <>{draw(
|
|
605
|
+
return <>{draw(ticks, scaler)}</>;
|
|
606
|
+
// return <>{draw(rawTicks, scaler)}</>;
|
|
592
607
|
} else {
|
|
593
608
|
return <>{draw(ticks, scaler)}</>;
|
|
594
609
|
}
|