mirror of
https://github.com/frappe/books.git
synced 2024-12-24 11:55:46 +00:00
refactor: shift yMax logic out
This commit is contained in:
parent
e576fda569
commit
d7f753f476
@ -28,3 +28,23 @@ export function euclideanDistance(
|
||||
const dsq = Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2);
|
||||
return Math.sqrt(dsq);
|
||||
}
|
||||
|
||||
export function getYMax(points: Array<Array<number>>): number {
|
||||
const maxVal = Math.max(...points.flat());
|
||||
const sign = maxVal >= 0 ? 1 : -1;
|
||||
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 {
|
||||
const minVal = Math.min(...points.flat());
|
||||
const sign = minVal >= 0 ? 1 : -1;
|
||||
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;
|
||||
}
|
||||
|
@ -101,6 +101,7 @@ import PeriodSelector from './PeriodSelector';
|
||||
import Cashflow from '../../../reports/Cashflow/Cashflow';
|
||||
import { getDatesAndPeriodicity } from './getDatesAndPeriodicity';
|
||||
import LineChart from '@/components/Charts/LineChart.vue';
|
||||
import { getYMax } from '@/components/Charts/chartUtils';
|
||||
|
||||
export default {
|
||||
name: 'Cashflow',
|
||||
@ -126,17 +127,13 @@ export default {
|
||||
return !(totalInflow === 0 && totalOutflow === 0);
|
||||
},
|
||||
chartData() {
|
||||
const xLabels = this.periodList.map((l) => l.split(' ')[0]);
|
||||
const xLabels = this.periodList;
|
||||
const points = ['inflow', 'outflow'].map((k) =>
|
||||
this.data.map((d) => d[k])
|
||||
);
|
||||
const colors = ['#2490EF', '#B7BFC6'];
|
||||
const format = (value) => frappe.format(value ?? 0, 'Currency');
|
||||
|
||||
const maxVal = Math.max(...points.flat());
|
||||
const texp = 10 ** Math.floor(Math.log10(maxVal));
|
||||
const yMax = Math.ceil(maxVal / texp) * texp;
|
||||
|
||||
const yMax = getYMax(points);
|
||||
return { points, xLabels, colors, format, yMax };
|
||||
},
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user