-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomplexity-file-trend.html
119 lines (97 loc) · 3.02 KB
/
complexity-file-trend.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE html>
<meta charset="utf-8">
<style> /* set the CSS */
.line {
fill: none;
stroke: blue;
stroke-width: 2px;
}
</style>
<body>
<h1>Complexity trend</h1>
<h2></h2>
<a href="../index.html">< back</a>
<ul>
<li>
<span style="display: inline-block; width: 1em; height: 1em; background-color: blue; vertical-align: middle;"></span>
Indentation complexity
</li>
<li>
<span style="display: inline-block; width: 1em; height: 1em; background-color: red; vertical-align: middle;"></span>
Lines of code
</li>
</ul>
<!-- load the d3.js library -->
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
// set the dimensions and margins of the graph
var margin = {top: 20, right: 20, bottom: 60, left: 50},
width = 960 - margin.left - margin.right,
height = 550 - margin.top - margin.bottom;
// parse the date / time
var parseTime = d3.timeParse("%d-%b-%y");
// set the ranges
var x = d3.scaleTime().range([0, width]);
var y = d3.scaleLinear().range([height, 0]);
// define the 1st line
var valueline = d3.line()
.x(function(d) { return x(d.date); })
.y(function(d) { return y(d.complexity); });
// define the 2nd line
var valueline2 = d3.line()
.x(function(d) { return x(d.date); })
.y(function(d) { return y(d.lines); });
// append the svg object to the body of the page
// appends a 'group' element to 'svg'
// moves the 'group' element to the top left margin
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 + ")");
const querystring = new URLSearchParams(window.location.search)
const fileName = querystring.get('file') + '.csv'
// Get the data
d3.csv(fileName, function(error, data) {
if (error) throw error;
var pageTitle = data[0].file;
document.querySelector("h2").innerHTML = pageTitle;
document.title = pageTitle;
// format the data
data.forEach(function(d) {
d.date = new Date(d.date);
d.complexity = +d.complexity;
d.lines = +d.lines;
});
// Scale the range of the data
x.domain(d3.extent(data, function(d) { return d.date; }));
y.domain([0, d3.max(data, function(d) {
return Math.max(d.complexity, d.lines); })]);
// Add the valueline path.
svg.append("path")
.data([data])
.attr("class", "line")
.attr("d", valueline);
// Add the valueline2 path.
svg.append("path")
.data([data])
.attr("class", "line")
.style("stroke", "red")
.attr("d", valueline2)
// Add the X Axis
svg.append("g")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x))
.append("text")
.attr("fill", "#000")
.attr("x", width / 2)
.attr("y", 35)
.attr("text-anchor", "middle")
.text("Time");
// Add the Y Axis
svg.append("g")
.call(d3.axisLeft(y));
});
</script>
</body>