Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(828)

Unified Diff: static/js/requests.js

Issue 11479045: Two graphs created with D3.js library and with little boostrap navbar. Base URL: https://code.google.com/p/swarming.isolate-server@master
Patch Set: Created 12 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: static/js/requests.js
diff --git a/static/js/requests.js b/static/js/requests.js
new file mode 100644
index 0000000000000000000000000000000000000000..c5b58c58ba40e1ca1962ba74d13db51448a98435
--- /dev/null
+++ b/static/js/requests.js
@@ -0,0 +1,64 @@
+var margin = {top: 20, right: 20, bottom: 30, left: 50},
+ width = 960 - margin.left - margin.right,
+ height = 500 - margin.top - margin.bottom;
+
+var parseDate = d3.time.format("%Y-%m-%d %H:%M:%S.%L").parse;
+
+var x = d3.time.scale()
+ .range([0, width]);
+
+var y = d3.scale.linear()
+ .range([height, 0]);
+
+var xAxis = d3.svg.axis()
+ .scale(x)
+ .orient("bottom");
+
+var yAxis = d3.svg.axis()
+ .scale(y)
+ .orient("left")
+ .tickFormat(d3.format(".2s"));
+
+
+var line = d3.svg.line()
+ .x(function(d) { return x(d.date); })
+ .y(function(d) { return y(d.close); });
+
+var svg = d3.select("#box").append("svg")
+ .attr("width", width + margin.left + margin.right)
+ .attr("height", height + margin.top + margin.bottom)
+ .append("g")
+ .attr("transform", "translate(" + margin.left + "," + margin.top + ")");
+
+var url = "https://isolateserver.appspot.com/stats/json?days=30";
+
+d3.json(url, function(error, data) {
+ data.days.forEach(function(d) {
+ var str = d.modified;
+ d.date = parseDate( str.substring(0, str.length - 3) );
+ d.close = +d.values.requests;
+ });
+
+ x.domain(d3.extent(data.days, function(d) { return d.date; }));
+ y.domain(d3.extent(data.days, function(d) { return d.close; }));
+
+ svg.append("g")
+ .attr("class", "x axis")
+ .attr("transform", "translate(0," + height + ")")
+ .call(xAxis);
+
+ svg.append("g")
+ .attr("class", "y axis")
+ .call(yAxis)
+ .append("text")
+ .attr("transform", "rotate(-90)")
+ .attr("y", 6)
+ .attr("dy", ".71em")
+ .style("text-anchor", "end")
+ .text("Request");
+
+ svg.append("path")
+ .datum(data.days)
+ .attr("class", "line")
+ .attr("d", line);
+});

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b