X-Git-Url: https://www.nos-oignons.net/gitweb/website.git/blobdiff_plain/cc6fb6f60b162b3f5fbe2596859d445ca2aecc62..50cd0d282feac1e57750fbb841921298d0ae879a:/assets/weights_graphs.js diff --git a/assets/weights_graphs.js b/assets/weights_graphs.js index 17a845d..af18990 100644 --- a/assets/weights_graphs.js +++ b/assets/weights_graphs.js @@ -37,7 +37,7 @@ WeightsDrawer.area = d3.svg.area() WeightsDrawer.stack = d3.layout.stack() .values(function(d) { return d.values; }); -WeightsDrawer.onionoo_url = "https://onionoo.torproject.org/bandwidth?type=relay&contact=%20%20%20%200x9F29C15D42A8B6F3%20Nos%20oignons%20-%2017WLwtW63FrHeMAEVkALnwhfmizBxGXDW1%20email:adminsys[]nos-oignons.net%20url:https://nos-oignons.net%20proof:uri-rsa%20ciissversion:2"; +WeightsDrawer.onionoo_url = "https://onionoo.torproject.org/weights?type=relay&contact=%20%20%20%200x9F29C15D42A8B6F3"; WeightsDrawer.periods = [ { id: "1_month", label: L10n.t_1_month }, @@ -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; @@ -100,7 +100,11 @@ WeightsDrawer.prototype.draw_weights_graph = function(raw_data) { } }); - 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") @@ -124,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) { @@ -144,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, @@ -174,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") @@ -188,26 +189,31 @@ WeightsDrawer.prototype.draw_weights_graph = function(raw_data) { .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() {