}
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;
}
});
- drawer.svg = d3.select(drawer.selector).append("svg")
+ var wrapper = d3.select(drawer.selector).append("div")
+ .style("display", "flex")
+ .style("align-items", "flex-start");
+
+ drawer.svg = wrapper.append("svg")
.attr("width", WeightsDrawer.width + WeightsDrawer.margin.left + WeightsDrawer.margin.right)
.attr("height", WeightsDrawer.height + WeightsDrawer.margin.top + WeightsDrawer.margin.bottom)
.append("g")
}
});
+ 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) {
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,
.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")
.attr("class", "y axis")
.call(WeightsDrawer.yAxis);
- var legend = drawer.svg.selectAll(".legend")
- .data(WeightsDrawer.color.domain().slice().reverse())
- .enter().append("g")
- .attr("class", "legend")
- .attr("transform", function(d, i) { return "translate(0," + ((i * 20) - WeightsDrawer.margin.top) + ")"; });
-
- legend.append("rect")
- .attr("x", WeightsDrawer.width - 18)
- .attr("width", 18)
- .attr("height", 18)
- .style("fill", WeightsDrawer.color);
-
- legend.append("text")
- .attr("x", WeightsDrawer.width - 24)
- .attr("y", 9)
- .attr("dy", ".35em")
- .style("text-anchor", "end")
- .text(function(d) {
- return nos_oignons_relays.filter(function(r) { return r.fingerprint == d; })[0].name;
- });
+ var legendDiv = wrapper.append("div")
+ .style("overflow-y", "auto")
+ .style("max-height", (WeightsDrawer.height + WeightsDrawer.margin.top + WeightsDrawer.margin.bottom) + "px")
+ .style("min-width", "90px")
+ .style("padding-left", "10px")
+ .style("padding-top", WeightsDrawer.margin.top + "px")
+ .style("box-sizing", "border-box");
+
+ WeightsDrawer.color.domain().slice().reverse().forEach(function(name) {
+ var item = legendDiv.append("div")
+ .style("display", "flex")
+ .style("align-items", "center")
+ .style("margin-bottom", "3px")
+ .style("white-space", "nowrap");
+ item.append("span")
+ .style("display", "inline-block")
+ .style("width", "14px")
+ .style("min-width", "14px")
+ .style("height", "14px")
+ .style("background-color", WeightsDrawer.color(name))
+ .style("margin-right", "5px");
+ item.append("span")
+ .style("font-size", "11px")
+ .text(name);
+ });
};
WeightsDrawer.prototype.refresh_graph = function() {