A Pen by Jezen Thomas on CodePen.
Created
October 26, 2015 08:02
-
-
Save artpar/ca27df774ba501c97deb to your computer and use it in GitHub Desktop.
Underscore.js LOC Stats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- | |
| http://jezenthomas.com/visualising-code-growth-with-git-and-d3 | |
| --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var margin = { | |
| top: 20, | |
| right: 20, | |
| bottom: 30, | |
| left: 50 | |
| }; | |
| var width = window.innerWidth - 80; | |
| var height = window.innerHeight - 80; | |
| var parseDate = d3.time.format("%d-%b-%y").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"); | |
| var area = d3.svg.area() | |
| .x(function(d) { | |
| return x(d.date); | |
| }) | |
| .y0(height) | |
| .y1(function(d) { | |
| return y(d.loc); | |
| }); | |
| var svg = d3.select("body").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 + ")"); | |
| d3.text("https://s3-us-west-2.amazonaws.com/s.cdpn.io/58652/data.tsv", function(text) {var dataset = d3.tsv.parseRows(text).map(function(row) { | |
| return { | |
| date: new Date(row[1]), | |
| loc: +row[0], | |
| }; | |
| }); | |
| x.domain(d3.extent(dataset, function(d) { | |
| return d.date; | |
| })); | |
| y.domain([d3.min(dataset, function(d) { | |
| return d.loc; | |
| }), d3.max(dataset, function(d) { | |
| return d.loc; | |
| })]); | |
| svg.append("path") | |
| .datum(dataset) | |
| .attr("class", "area") | |
| .attr("d", area); | |
| 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("LOC"); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script src="//cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| * { | |
| margin: 0; | |
| padding: 0; | |
| } | |
| body { | |
| font: 10px Arial; | |
| } | |
| .axis path, | |
| .axis line { | |
| fill: none; | |
| stroke: #000; | |
| stroke-width: 1; | |
| shape-rendering: crispEdges; | |
| } | |
| .area { | |
| fill: rgba(70, 130, 180, .3); | |
| stroke: rgb(70, 130, 180); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment