mirror of
https://github.com/frappe/books.git
synced 2025-01-11 02:36:14 +00:00
fix: improve chart min max scaler
This commit is contained in:
parent
fc7130e776
commit
4b51d15de7
@ -29,18 +29,27 @@ export function euclideanDistance(
|
|||||||
return Math.sqrt(dsq);
|
return Math.sqrt(dsq);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getRoundingConst(val: number): number {
|
||||||
|
const pow = Math.max(Math.log10(Math.abs(val)) - 1, 0);
|
||||||
|
return 10 ** Math.floor(pow);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getVal(minOrMaxVal: number): number {
|
||||||
|
const rc = getRoundingConst(minOrMaxVal);
|
||||||
|
const sign = minOrMaxVal >= 0 ? 1 : -1;
|
||||||
|
if (sign === 1) {
|
||||||
|
return Math.ceil(minOrMaxVal / rc) * rc;
|
||||||
|
}
|
||||||
|
return Math.floor(minOrMaxVal / rc) * rc;
|
||||||
|
}
|
||||||
|
|
||||||
export function getYMax(points: Array<Array<number>>): number {
|
export function getYMax(points: Array<Array<number>>): number {
|
||||||
const maxVal = Math.max(...points.flat());
|
const maxVal = Math.max(...points.flat());
|
||||||
if (maxVal === 0) {
|
if (maxVal === 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const sign = maxVal >= 0 ? 1 : -1;
|
return getVal(maxVal);
|
||||||
const texp = 10 ** Math.floor(Math.log10(Math.abs(maxVal)));
|
|
||||||
if (sign === 1) {
|
|
||||||
return Math.ceil(maxVal / texp) * texp;
|
|
||||||
}
|
|
||||||
return Math.floor(maxVal / texp) * texp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getYMin(points: Array<Array<number>>): number {
|
export function getYMin(points: Array<Array<number>>): number {
|
||||||
@ -49,10 +58,5 @@ export function getYMin(points: Array<Array<number>>): number {
|
|||||||
return minVal;
|
return minVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
const sign = minVal >= 0 ? 1 : -1;
|
return getVal(minVal);
|
||||||
const texp = 10 ** Math.floor(Math.log10(Math.abs(minVal)));
|
|
||||||
if (sign === 1) {
|
|
||||||
return Math.ceil(minVal / texp) * texp;
|
|
||||||
}
|
|
||||||
return Math.floor(minVal / texp) * texp;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user