]> nos-oignons.net Git - website.git/blobdiff - assets/weights_graphs.js
Les graphs sont maintenant groupés par noms!
[website.git] / assets / weights_graphs.js
index 8a30862e3fbc0afc1f02eddc794d2f31cac4e356..af18990861af7c95127eee6be4b26c556175c2de 100644 (file)
@@ -69,8 +69,8 @@ WeightsDrawer.extract_values = function(history, interval, minTime, maxTime) {
 }
 
 WeightsDrawer.color = d3.scale.ordinal();
-WeightsDrawer.color.domain(nos_oignons_relays.map(function(r) {return r.fingerprint}));
-WeightsDrawer.color.range(nos_oignons_relays.map(function(r) {return r.color}));
+WeightsDrawer.color.domain(nos_oignons_groups.map(function(g) {return g.name}));
+WeightsDrawer.color.range(nos_oignons_groups.map(function(g) {return g.color}));
 
 WeightsDrawer.prototype.draw_weights_graph = function(raw_data) {
   var drawer = this;
@@ -128,6 +128,8 @@ WeightsDrawer.prototype.draw_weights_graph = function(raw_data) {
     }
   });
 
+  var relayIndex = buildRelayIndex(raw_data.relays);
+
   WeightsDrawer.sources.map(function(s) { return s.id; }).forEach(function(source) {
     drawer.weights_data[source] = {};
     WeightsDrawer.periods.map(function(p) { return p.id; }).forEach(function(period) {
@@ -148,17 +150,12 @@ WeightsDrawer.prototype.draw_weights_graph = function(raw_data) {
 
       var maxValue = 0;
 
-      var relays = WeightsDrawer.color.domain().map(function(fingerprint) {
-        var relay_data = raw_data["relays"].filter(function(d) { return d.fingerprint == fingerprint; })[0];
-
-        var history = relay_data[source][period];
-        var values = WeightsDrawer.extract_values(history, interval, minTime, maxTime);
-        maxValue = maxValue + d3.max(values, function(d) { return d.y; });
-
-        return {
-          fingerprint: fingerprint,
-          values: values,
-        };
+      var relays = nos_oignons_groups.map(function(group) {
+        var group_values = sumGroupRelayValues(group, relayIndex, function(r) {
+          return WeightsDrawer.extract_values(r[source][period], interval, minTime, maxTime);
+        });
+        maxValue += (d3.max(group_values, function(d) { return d.y; }) || 0);
+        return { group: group.name, values: group_values };
       });
       drawer.weights_data[source][period] = {
         minTime: minTime,
@@ -178,7 +175,7 @@ WeightsDrawer.prototype.draw_weights_graph = function(raw_data) {
     .enter().append("path")
       .attr("class", "weight_graph area")
       .attr("d", function(d) { return WeightsDrawer.area(d.values); })
-      .style("fill", function(d) { return WeightsDrawer.color(d.fingerprint); });
+      .style("fill", function(d) { return WeightsDrawer.color(d.group); });
 
   drawer.svg.append("g")
       .attr("class", "x axis")
@@ -200,8 +197,7 @@ WeightsDrawer.prototype.draw_weights_graph = function(raw_data) {
       .style("padding-top", WeightsDrawer.margin.top + "px")
       .style("box-sizing", "border-box");
 
-  WeightsDrawer.color.domain().slice().reverse().forEach(function(d) {
-    var name = nos_oignons_relays.filter(function(r) { return r.fingerprint == d; })[0].name;
+  WeightsDrawer.color.domain().slice().reverse().forEach(function(name) {
     var item = legendDiv.append("div")
         .style("display", "flex")
         .style("align-items", "center")
@@ -212,7 +208,7 @@ WeightsDrawer.prototype.draw_weights_graph = function(raw_data) {
         .style("width", "14px")
         .style("min-width", "14px")
         .style("height", "14px")
-        .style("background-color", WeightsDrawer.color(d))
+        .style("background-color", WeightsDrawer.color(name))
         .style("margin-right", "5px");
     item.append("span")
         .style("font-size", "11px")