diff --git a/public/pure.html b/public/pure.html
index 5abdd76..a57c96f 100644
--- a/public/pure.html
+++ b/public/pure.html
@@ -43,48 +43,84 @@
};
const UI = {
+ /* https://medium.com/@heyoka/scratch-made-svg-donut-pie-charts-in-html5-2c587e935d72 */
donut: ( element, dataset ) => {
+ const thickness = 9;
let filed_percent = 0;
const data_to_donut_segment = ( data ) => {
- const stroke_dashoffset = ( percent ) => {
- let offset = ( 100 - filed_percent ) + 25;
+ if ( data.amount > 0 ) {
+ const stroke_dashoffset = ( percent ) => {
+ let offset = 100 - filed_percent;
- return offset > 100 ? offset - 100 : offset;
- };
+ return offset > 100 ? offset - 100 : offset;
+ };
- const donut_segment = `
${JSON.stringify( dataset )}`; } }; + + let current_period; + const Period = { + set: ( period ) => { + current_period = period; + document.querySelector( "#period #display" ).innerHTML = current_period.toISOString(); + + monthly( current_period.toISOString().split("T")[0].slice( 0, -3 ), "#month" ); + }, + get: () => current_period, + prev: () => { + current_period.setMonth( current_period.getMonth() - 1 ); + Period.set( current_period ); + }, + next: () => { + current_period.setMonth( current_period.getMonth() + 1 ); + Period.set( current_period ); + }, + }; + + const monthly = ( month, element_selector ) => { + API.balance( month, ["Expenses"].join(" "), 3 ) + .then( balance => { + const total = balance.reduce( (memo, line) => memo + line.amount, 0 ); + + UI.donut( document.querySelector( `${element_selector} #donut` ), + balance.sort( (a, b) => b.amount - a.amount ) + .map( line => { + line.color = Utils.text_to_color( line.account ); + line.percent = ( line.amount / total ) * 100; + line.tooltip = `${line.account} : ${line.amount} €`; + + return line; + } ) ); + } ); + }; - +