Account chart can do live update

This commit is contained in:
James Cole
2025-07-27 07:36:23 +02:00
parent a16cc73c77
commit 28b2ddde18
7 changed files with 142 additions and 66 deletions

View File

@@ -53,6 +53,11 @@ export default () => ({
eventListeners: {
['@convert-to-native.window'](event){
console.log('I heard that! it is now ' + event.detail);
this.convertToNative = event.detail;
this.accountList = [];
chartData = null;
this.loadChart();
this.loadAccounts();
}
},
@@ -61,6 +66,7 @@ export default () => ({
console.log('doSomeReload');
},
getFreshData() {
console.log('get fresh data');
const start = new Date(window.store.get('start'));
const end = new Date(window.store.get('end'));
const chartCacheKey = getCacheKey(this.localCacheKey('chart'), {start: start, end: end})
@@ -101,18 +107,20 @@ export default () => ({
dataset.label = current.label;
// use the "native" currency code and use the "native_entries" as array
// if (this.convertToNative) {
// currencies.push(current.native_currency_code);
// dataset.currency_code = current.native_currency_code;
// collection = Object.values(current.native_entries);
// yAxis = 'y' + current.native_currency_code;
// }
// if (!this.convertToNative) {
if (this.convertToNative) {
console.log('Convert to native!');
currencies.push(current.native_currency_code);
dataset.currency_code = current.native_currency_code;
collection = Object.values(current.native_entries);
yAxis = 'y' + current.native_currency_code;
}
if (!this.convertToNative) {
console.log('NO convert to native!', this.convertToNative);
yAxis = 'y' + current.currency_code;
dataset.currency_code = current.currency_code;
currencies.push(current.currency_code);
collection = Object.values(current.entries);
// }
}
dataset.yAxisID = yAxis;
dataset.data = collection;
@@ -147,7 +155,9 @@ export default () => ({
return options;
},
loadChart() {
console.log('loadChart');
if (true === this.loading) {
console.log('already loading chart');
return;
}
this.loading = true;
@@ -165,6 +175,7 @@ export default () => ({
chart.options = options.options;
chart.data = options.data;
chart.update();
console.log('refresh chart');
return;
}
chart = new Chart(document.querySelector("#account-chart"), options);
@@ -294,6 +305,7 @@ export default () => ({
this.convertToNative = values[1] && values[3];
this.convertToNativeAvailable = values[3];
afterPromises = true;
console.log('convertToNative in accounts.js: ', values);
// main dashboard chart:
this.loadChart();