Improved budget chart.

This commit is contained in:
James Cole
2025-07-26 06:47:21 +02:00
parent f62e49090c
commit 46395e350a
7 changed files with 93 additions and 61 deletions

View File

@@ -60,7 +60,8 @@ export default () => ({
const start = new Date(window.store.get('start'));
const end = new Date(window.store.get('end'));
const cacheKey = getCacheKey('ds_bdg_chart', {start: start, end: end});
const cacheValid = window.store.get('cacheValid');
//const cacheValid = window.store.get('cacheValid');
const cacheValid = false;
let cachedData = window.store.get(cacheKey);
if (cacheValid && typeof cachedData !== 'undefined') {
@@ -80,7 +81,7 @@ export default () => ({
},
generateOptions(data) {
currencies = [];
let options = getDefaultChartSettings('column');
let options = getDefaultChartSettings('bar');
options.options.locale = window.store.get('locale').replace('_', '-');
options.options.plugins = {
tooltip: {
@@ -94,7 +95,7 @@ export default () => ({
if (label) {
label += ': ';
}
return label + ' ' + formatMoney(context.parsed.y, currencies[context.parsed.x] ?? 'EUR');
return label + ' ' + formatMoney(context.parsed.x, currencies[context.parsed.x] ?? 'EUR');
}
}
}
@@ -103,55 +104,40 @@ export default () => ({
labels: [],
datasets: [
{
label: i18next.t('firefly.budgeted'),
data: [],
borderWidth: 1,
backgroundColor: getColors('budgeted', 'background'),
borderColor: getColors('budgeted', 'border'),
},
{
//label: i18next.t('firefly.budgeted'),
label: i18next.t('firefly.spent'),
data: [],
borderWidth: 1,
stack: 1,
backgroundColor: getColors('spent', 'background'),
borderColor: getColors('spent', 'border'),
},
{
label: i18next.t('firefly.left'),
data: [],
borderWidth: 1,
stack: 1,
backgroundColor: getColors('left', 'background'),
borderColor: getColors('left', 'border'),
},
{
label: i18next.t('firefly.overspent'),
data: [],
borderWidth: 1,
stack: 1,
backgroundColor: getColors('overspent', 'background'),
borderColor: getColors('overspent', 'border'),
}
]
};
for (const i in data) {
if (data.hasOwnProperty(i)) {
let current = data[i];
console.log('Now at');
console.log(current);
// // convert to EUR yes no?
let label = current.label + ' (' + current.currency_code + ')';
options.data.labels.push(label);
if (this.convertToNative) {
currencies.push(current.native_currency_code);
// series 0: spent
options.data.datasets[0].data.push(parseFloat(current.native_entries.spent) * -1);
// series 1: left
options.data.datasets[1].data.push(parseFloat(current.native_entries.left));
// series 2: overspent
options.data.datasets[2].data.push(parseFloat(current.native_entries.overspent));
}
if (!this.convertToNative) {
currencies.push(current.currency_code);
// series 0: spent
options.data.datasets[0].data.push(parseFloat(current.entries.spent) * -1);
// series 1: left
options.data.datasets[1].data.push(parseFloat(current.entries.left));
// series 2: overspent
options.data.datasets[2].data.push(parseFloat(current.entries.overspent));
}
// label = current.label + ' (' + current.currency_code + ') b';
// options.data.labels.push(label);
currencies.push(current.currency_code);
// series 0: budgeted
options.data.datasets[0].data.push(parseFloat(current.entries.budgeted));
// series 1: spent
options.data.datasets[1].data.push(parseFloat(current.entries.spent) * -1);
// series 2: overspent
// options.data.datasets[2].data.push(parseFloat(current.entries.overspent));
}
}
// the currency format callback for the Y axis is AlWAYS based on whatever the first currency is.
@@ -160,9 +146,10 @@ export default () => ({
options.options.scales = {
y: {
ticks: {
callback: function (context) {
return formatMoney(context, currencies[0] ?? 'EUR');
}
// callback: function (context) {
// return 'abc';
// return formatMoney(context, currencies[0] ?? 'EUR');
// }
}
}
};