Skip to content

Commit

Permalink
Merge pull request #3657 from VisActor/fix/axis-break
Browse files Browse the repository at this point in the history
Fix/axis break
  • Loading branch information
xile611 authored Jan 9, 2025
2 parents fd3d692 + 18151d0 commit 9b53f44
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vchart",
"comment": "fix: axis break's scope calculate error, fix#3656",
"type": "none"
}
],
"packageName": "@visactor/vchart"
}
4 changes: 3 additions & 1 deletion packages/vchart/src/component/axis/mixin/util/break-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,18 @@ function breakScope(data: number[], points: number[], scopeType: 'count' | 'leng
const res: [number, number][] = [];
let acc = 0;

let resIndex = 0; // 因为有的结果会被剔除,所以要从 res 的真实索引上拿
bins.forEach((bin, i) => {
if (totalLength === 0) {
res.push([0, i / bins.length - 1]);
} else {
const length = scopeType === 'count' ? bin.count : bin.max - bin.min;
const b0 = res[i - 1] ? res[i - 1][1] : 0;
const b0 = res[resIndex - 1] ? res[resIndex - 1][1] : 0;
const b1 = i === bins.length - 1 ? 1 : Math.min((acc + length) / totalLength, 1);

if (b0 === b1 && (b0 === 0 || b0 === 1)) {
} else {
resIndex += 1;
res.push([b0, b1]);
acc += length;
}
Expand Down

0 comments on commit 9b53f44

Please sign in to comment.