From f6ba8f25e4f213d3bbc1ac0f4aa797bec625d805 Mon Sep 17 00:00:00 2001 From: Sylvain Mariel Date: Sat, 1 Apr 2023 18:57:46 +0200 Subject: [PATCH] load stats --- html/stats.html | 3 ++- js/class.Stats.js | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/html/stats.html b/html/stats.html index dfcc704..e6e76ac 100644 --- a/html/stats.html +++ b/html/stats.html @@ -17,9 +17,10 @@

diff --git a/js/class.Stats.js b/js/class.Stats.js index ccb0b13..0e422df 100644 --- a/js/class.Stats.js +++ b/js/class.Stats.js @@ -38,6 +38,9 @@ class Stats { else if('tags' === chartType) { this.updateTags(); } + else if('loads' === chartType) { + this.updateLoads(); + } } @@ -227,6 +230,39 @@ class Stats { } } + + // update the Canvas by displaying the stats of the loads + updateLoads() { + let datasets = {typ:[], max:[]}; + let labels = []; + let max = 0; + + // display the title + $('.title').html('Loads Power'); + + // hide the 'go to parent' button + $('.goToParent').fadeOut(200); + + // fill the chart with loads power + this.tree.forEachLoad((load) => { + let name = load.characs.name; + let ptyp = load.getInputPower('typ'); + let pmax = load.getInputPower('max'); + + datasets.typ.push(ptyp); + datasets.max.push(pmax); + labels.push(name); + + if(ptyp > max) max = ptyp; + if(pmax > max) max = pmax; + }); + + // create two charts and fill them, without click callback + this.plotChart('typ', datasets.typ, labels, max, 'power (W)', null); + this.plotChart('max', datasets.max, labels, max, 'power (W)', null); + } + + // remove both canvas and print a default text empty(title = 'No selection') { if(null !== this.charts.typ) this.charts.typ.destroy();