Skip to content

Commit

Permalink
fix: fix the issue of tickAlign accuracy
Browse files Browse the repository at this point in the history
  • Loading branch information
xuefei1313 committed Feb 11, 2025
1 parent 118bf74 commit 39c497c
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ export interface ITickAlignOpt {
currentAxis: () => CartesianAxis;
}

function saveTick(value: number, minInput: number, maxInput: number, minOutput: number, outputRange: number) {
function saveTick(value: number, minInput: number, inputRange: number, minOutput: number, outputRange: number) {
const sub = precisionSub(value, minInput);
const decimalPlaces = Math.max(getDecimalPlaces(maxInput), getDecimalPlaces(sub));
const percent = Math.round(sub * 10 ** decimalPlaces) / Math.round(maxInput * 10 ** decimalPlaces);
const decimalPlaces = Math.max(getDecimalPlaces(inputRange), getDecimalPlaces(sub));
const percent = Math.round(sub * 10 ** decimalPlaces) / Math.round(inputRange * 10 ** decimalPlaces);
return outputRange * percent + minOutput;
}

Expand Down Expand Up @@ -61,7 +61,7 @@ export const tickAlign = (data: Array<Datum>, op: ITickAlignOpt) => {
}
// make the tickData of the current axis consistent with the tickData of the target axis
const newTicks: number[] = targetData.map((d: { value: number }) =>
saveTick(d.value, targetDomain[0], targetDomain[1], currentDomain[0], currentRange)
saveTick(d.value, targetDomain[0], targetRange, currentDomain[0], currentRange)
);
return convertDomainToTickData(newTicks);
};

0 comments on commit 39c497c

Please sign in to comment.