From fe4ac79498dcc488ea4437c028efb2cc19d79b17 Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Sat, 22 May 2021 09:44:54 +0200 Subject: [PATCH] [WIP] accounts sliders Signed-off-by: Gwenhael Le Moine --- public/ploty.html | 116 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 86 insertions(+), 30 deletions(-) diff --git a/public/ploty.html b/public/ploty.html index fd452fa..e5f92ab 100644 --- a/public/ploty.html +++ b/public/ploty.html @@ -33,23 +33,27 @@ const Controls = { accounts_list: { - ui_id: "accounts", - init: async () => { + init: async ( ui_id ) => { let accounts = await API.accounts(); - let ui_accounts = document.querySelector(`#${Controls.accounts_list.ui_id}`); - ui_accounts.innerHTML = ''; + let ui_accounts = document.querySelector(`#${ui_id}`); + let content = ""; - ui_accounts.addEventListener( 'change', event => Controls.accounts_list.onchange( event.target ) ); - Controls.accounts_list.onchange( ui_accounts ); + ui_accounts.innerHTML = content; + + let ui_accounts_select = document.querySelector(`#${ui_id} select`); + + ui_accounts_select.addEventListener( 'change', event => Controls.accounts_list.onchange( event.target ) ); + Controls.accounts_list.onchange( ui_accounts_select ); }, onchange: element => { selected_accounts = Array.from( element.options ).filter( o => o.selected ).map( o => o.value ); @@ -57,28 +61,79 @@ Controls.main_graph.set( selected_accounts ); } }, - main_graph: { - ui_id: 'mainGraph', - init: () => Controls.main_graph.set( selected_accounts ), - set: async accounts => { - /* 1. get graph_values for accounts */ - let values = await API.graph_values( "", accounts.join(" "), "monthly" ); - Plotly.newPlot( Controls.main_graph.ui_id, - Object.keys(values).map( act => { - return { - name: act, - type: "bar", - x: values[ act ].map( reg => Utils.readable_date( new Date( reg.date ) ) ), - y: values[ act ].map( reg => reg.amount) - }; - }), - { - xaxis: {title: 'Dates'}, - yaxis: {title: 'Montant'}, - barmode: 'relative', - title: 'Relative Barmode' + accounts_sliders: { + init: async ( ui_id ) => { + let accounts = await API.accounts(); + let ui_accounts = document.querySelector(`#${ui_id}`); + let content = "`; + }).join(''); + + Object.keys( accounts_depths ).forEach( act => { + document.querySelector( `#myRange-${act}` ) + .addEventListener( 'change', event => { + accounts_depths[act] = event.target.value; + + onchange(); + }); }); + + onchange(); + } + }, + + main_graph: { + init: ( ui_id ) => { + let layout = { + xaxis: {title: 'Dates'}, + yaxis: {title: 'Montant'}, + barmode: 'relative', + title: 'Relative Barmode' + }; + + Controls.main_graph.set = async ( accounts ) => { + console.log(accounts) + if (accounts.length < 1) + return; + + let values = await API.graph_values( "", accounts.map(a => a.join(':')).join(" "), "monthly" ); + + Plotly.react( ui_id, + Object.keys(values) + .map( act => { + let v = values[ act ].sort( (a, b) => b.date - a.date ); + return { + name: act, + type: "bar", + x: v.map( reg => new Date( reg.date ) ), //Utils.readable_date( new Date( reg.date ) ) ), + y: v.map( reg => reg.amount) + }; + } ), + layout ); + }; } }, }; @@ -86,14 +141,15 @@ - +