11
|
1 <style type = text/css> |
|
2 |
|
3 * { |
|
4 font-family: "Sans-serif"; |
|
5 font-size: 14px; |
|
6 } |
|
7 |
|
8 .svg div{ |
|
9 font: 10px; |
|
10 text-align: right; |
|
11 float: left; |
|
12 display: block; |
|
13 padding: 10px; |
|
14 margin: 10px; |
|
15 color: white; |
|
16 } |
|
17 |
|
18 .axis path, |
|
19 |
|
20 .axis line { |
|
21 fill: none; |
|
22 stroke: lightgrey; |
|
23 /*opacity: 0.7;*/ |
|
24 stroke-width: 1px; |
|
25 } |
|
26 |
|
27 .y.axis path { |
|
28 display: none; |
|
29 } |
|
30 |
|
31 .line { |
|
32 fill: none; |
|
33 stroke-width: 3px; |
|
34 opacity: 1; |
|
35 } |
|
36 |
|
37 .line.critical { |
|
38 stroke: red; |
|
39 } |
|
40 |
|
41 .line.critical.legend { |
|
42 fill: red; |
|
43 } |
|
44 |
|
45 .line.urgent { |
|
46 stroke: orange; |
|
47 } |
|
48 |
|
49 .line.urgent.legend { |
|
50 fill: orange; |
|
51 } |
|
52 |
|
53 .line.bug { |
|
54 stroke: violet; |
|
55 } |
|
56 |
|
57 .line.bug.legend { |
|
58 fill: violet; |
|
59 } |
|
60 |
|
61 .line.feature { |
|
62 stroke: chartreuse; |
|
63 style: stroke-dasharray; |
|
64 } |
|
65 |
|
66 .line.feature.legend { |
|
67 fill: chartreuse; |
|
68 } |
|
69 |
|
70 .line.wish { |
|
71 stroke: blue; |
|
72 } |
|
73 |
|
74 .line.wish.legend { |
|
75 fill: blue; |
|
76 } |
|
77 |
|
78 .grid .tick { |
|
79 stroke: lightgrey; |
|
80 /*opacity: 0.7;*/ |
|
81 } |
|
82 |
|
83 .grid path { |
|
84 stroke-width: 0; |
|
85 } |
|
86 |
|
87 </style> |
|
88 |
|
89 <!-- <div id="content" style="display: inline-block"></div> --> |
|
90 <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js" charset="utf-8"></script> |
|
91 <script type="text/javascript"> |
|
92 |
|
93 // window.onresize = function(){ |
|
94 // document.getElementsByClassName("chart")[0].innerHTML = ""; |
|
95 // makeChart(); |
|
96 // }; |
|
97 |
|
98 var critical=[]; |
12
|
99 var urgent=[]; |
|
100 var bug=[]; |
|
101 var feature=[]; |
|
102 var wish=[]; |
|
103 var timestamp=[]; |
11
|
104 |
|
105 // var critical=[ |
|
106 // {points: 4}, |
|
107 // {points: 12}, |
|
108 // {points: 8}, |
|
109 // {points: 2} |
|
110 // ] |
|
111 // |
|
112 // var urgent=[ |
|
113 // {points: 3}, |
|
114 // {points: 24}, |
|
115 // {points: 17}, |
|
116 // {points: 19} |
|
117 // ] |
|
118 // |
|
119 // var bug=[ |
|
120 // {points: 10}, |
|
121 // {points: 2}, |
|
122 // {points: 2}, |
|
123 // {points: 12} |
|
124 // ] |
|
125 // |
|
126 // var feature=[ |
|
127 // {points: 4}, |
|
128 // {points: 21}, |
|
129 // {points: 12}, |
|
130 // {points: 4} |
|
131 // ] |
|
132 // |
|
133 // var wish=[ |
|
134 // {points: 22}, |
|
135 // {points: 18}, |
|
136 // {points: 32}, |
|
137 // {points: 10} |
|
138 // ] |
|
139 // |
|
140 // |
|
141 // var timestamp=[ |
|
142 // {date : new Date('2015-06-30T12:36:47')}, |
|
143 // {date : new Date('2015-07-01T12:37:26')}, |
|
144 // {date : new Date('2015-07-02T12:38:26')}, |
|
145 // {date : new Date('2015-07-03T12:39:26')} |
|
146 // ] |
|
147 |
|
148 document.addEventListener("DOMContentLoaded", function(event) { |
|
149 makeChart(); |
|
150 }); |
|
151 |
|
152 function assignIssueToDate(issueArray, dateArray){ |
|
153 a = []; |
|
154 for (var i = 0; i < issueArray.length; i++) { |
|
155 a.push({points: issueArray[i].points, date : dateArray[i].date}); |
|
156 } |
|
157 |
|
158 return a; |
|
159 } |
|
160 |
|
161 function limitDatesOnXAxis(limit){ |
|
162 if (timestamp.length < limit){ |
|
163 return timestamp.length; |
|
164 } else { |
|
165 return limit; |
|
166 } |
|
167 } |
|
168 |
|
169 function maxInObject( array ){ |
|
170 var maxVal = 0; |
|
171 for (var i = 0; i < array.length; i++) { |
|
172 if (maxVal < array[i].points){ |
|
173 maxVal = array[i].points; |
|
174 } |
|
175 } |
|
176 return maxVal; |
|
177 } |
|
178 |
|
179 |
|
180 function getMaxIssues(){ |
|
181 maxIssuesOfAllArrays = []; |
|
182 maxIssuesOfAllArrays.push(maxInObject(critical)); |
|
183 maxIssuesOfAllArrays.push(maxInObject(urgent)); |
|
184 maxIssuesOfAllArrays.push(maxInObject(bug)); |
|
185 maxIssuesOfAllArrays.push(maxInObject(feature)); |
|
186 maxIssuesOfAllArrays.push(maxInObject(wish)); |
|
187 |
|
188 return Math.max.apply(Math, maxIssuesOfAllArrays)+1; |
|
189 } |
|
190 |
|
191 |
|
192 function dayDifference(first, second) { |
|
193 "use strict"; |
|
194 var difference = (second - first) / (1000 * 60 * 60 * 24); |
|
195 |
|
196 // just to avoid the get thousands of lines... would look ugly. |
|
197 if (difference > 60){ |
|
198 difference = 60; |
|
199 } |
|
200 |
|
201 return difference; |
|
202 } |
|
203 |
|
204 |
|
205 // function for the grid lines |
|
206 function makeGrid(direction, orientation, ticknumber) { |
|
207 return d3.svg.axis() |
|
208 .scale(direction) |
|
209 .orient(orientation) |
|
210 .ticks( ticknumber ); |
|
211 } |
|
212 |
|
213 |
|
214 //append a svg_path. pretty generic |
|
215 function draw_line(svg, data_array, css_class, line_object, lineShape){ |
|
216 svg.append("path") |
|
217 .datum(assignIssueToDate(data_array, timestamp)) |
|
218 .attr("class", css_class) |
|
219 .style("stroke-dasharray", (lineShape)) |
|
220 .attr("d", line_object); |
|
221 } |
|
222 |
|
223 |
|
224 function makeLegend(svg, width){ |
|
225 |
|
226 var legend_distance = width+40; |
|
227 var top_distance = 20; |
|
228 var distance_steps = 50; |
|
229 |
|
230 |
|
231 function set_propper_distance(steps){ |
|
232 top_distance += steps; |
|
233 return top_distance; |
|
234 } |
|
235 |
|
236 function draw_legend_line(svg, width, Ypos, text, issues){ |
|
237 svg.append("svg:text") |
|
238 .attr("class", "legend") |
|
239 .attr("x", width-30 ) |
|
240 .attr("y", Ypos) |
|
241 .text(text + ":"); |
|
242 |
|
243 svg.append("svg:text") |
|
244 .attr("class", "legend") |
|
245 .attr("x", width+35 ) |
|
246 .attr("y", Ypos) |
|
247 .text(issues); |
|
248 |
|
249 svg.append("rect") |
|
250 .attr("class", "line " + text.toLowerCase() + " legend") |
|
251 .attr("x", width-30) |
|
252 .attr("y", Ypos-20) |
|
253 .attr("width", 100) |
|
254 .attr("height", 2); |
|
255 } |
|
256 |
|
257 draw_legend_line(svg, legend_distance, set_propper_distance(distance_steps), "Critical", critical[critical.length-1].points); |
|
258 draw_legend_line(svg, legend_distance, set_propper_distance(distance_steps), "Urgent", urgent[urgent.length-1].points); |
|
259 draw_legend_line(svg, legend_distance, set_propper_distance(distance_steps), "Bug", bug[bug.length-1].points); |
|
260 draw_legend_line(svg, legend_distance, set_propper_distance(distance_steps), "Feature", feature[feature.length-1].points); |
|
261 draw_legend_line(svg, legend_distance, set_propper_distance(distance_steps), "Wish", wish[wish.length-1].points); |
|
262 } |
|
263 |
|
264 |
|
265 |
|
266 //draw the chart |
|
267 function makeChart(){ |
|
268 |
|
269 //declaration |
|
270 var sizeOfSystemBorders = 20; |
|
271 // var margin = {top: 20, right: 100, bottom: 90, left: 60}; |
|
272 // var margin = {top: 0, right: 0, bottom: 0, left: 0} |
|
273 |
|
274 var width = document.getElementsByClassName("chart")[0].clientWidth; |
|
275 var height = document.getElementsByClassName("chart")[0].clientHeight; |
|
276 // var width = (document.documentElement.clientWidth-sizeOfSystemBorders) - margin.left - margin.right; |
|
277 // var height = (document.documentElement.clientHeight-sizeOfSystemBorders) - margin.top - margin.bottom; |
|
278 |
|
279 var x = d3.time.scale() |
|
280 .range([0, width]); |
|
281 |
|
282 var y = d3.scale.linear() |
|
283 .range([height, 0]); |
|
284 |
|
285 var base_line = d3.svg.line() |
|
286 .x(function(d) { return x(d.date); }) |
|
287 .y(function(d) { return y(d.points); }); |
|
288 |
|
289 //lines |
|
290 var criticalLine = base_line; |
|
291 var urgentLine = base_line; |
|
292 var bugLine = base_line; |
|
293 var featureLine = base_line; |
|
294 var wishLine = base_line; |
|
295 var timestampLine = base_line; |
|
296 |
|
297 |
|
298 //set domain of y axis |
|
299 var yDomain = [ ]; |
|
300 yDomain[0] = 0; |
|
301 yDomain[1] = getMaxIssues(); |
|
302 y.domain(d3.extent(yDomain, function(d){return d; })); |
|
303 |
|
304 //set domain of y axis |
|
305 x.domain(d3.extent(timestamp, function(d){return d.date; })); |
|
306 |
|
307 |
|
308 var xAxis = d3.svg.axis() |
|
309 .scale(x) |
|
310 .orient("bottom") |
|
311 .ticks(limitDatesOnXAxis(10)) |
|
312 .tickFormat(d3.time.format("%d.%m")); |
|
313 // .tickFormat(d3.time.format("%d.%m:%H:%M")); |
|
314 // .tickFormat(d3.time.format("%X")); |
|
315 // .tickFormat(d3.time.format.iso); |
|
316 |
|
317 |
|
318 var yAxis = d3.svg.axis() |
|
319 .scale(y) |
|
320 .orient("left"); |
|
321 |
|
322 |
|
323 var svg = d3.select(".chart") |
|
324 .append("svg") |
|
325 .attr("class", "svg") |
|
326 // .attr("width", width) |
|
327 // .attr("height", height) |
|
328 .attr("width", width-20) |
|
329 .attr("height", height-10) |
|
330 .append("g") |
|
331 // .attr("transform", "translate( +50,+0,+0,+0)"); |
|
332 .attr("transform", "translate(40 , 0)"); |
|
333 |
|
334 |
|
335 // creation |
|
336 |
|
337 |
|
338 // Draw the x Grid lines |
|
339 // svg.append("g") |
|
340 // .attr("class", "grid") |
|
341 // .attr("transform", "translate(0," + height + ")") |
|
342 // .call(makeGrid(x, "bottom", timestamp.length) |
|
343 // .tickSize(-height, 0, 0) |
|
344 // .tickFormat("") |
|
345 // ); |
|
346 |
|
347 |
|
348 // Draw the y Grid lines |
|
349 svg.append("g") |
|
350 .attr("class", "grid") |
|
351 .call(makeGrid(y, "left", function(){return Math.min(getMaxIssues(), 10);}()) |
|
352 .tickSize(-width, 0, 0) |
|
353 .tickFormat("") |
|
354 ); |
|
355 |
|
356 |
|
357 // Draw the x-axis |
|
358 svg.append("g") |
|
359 .attr("class", "x axis") |
|
360 // .attr("transform", "translate(0, " + 20-height + ")") |
|
361 .call(xAxis) |
|
362 .selectAll("text") |
|
363 .style("text-anchor", "end") |
|
364 // .attr("dx", "-.5em") |
|
365 // .attr("dy", ".1em") |
|
366 // .attr("transform", function() { |
|
367 // return "rotate(-30)"; |
|
368 // }); |
|
369 |
|
370 |
|
371 // Draw the y-axis |
|
372 svg.append("g") |
|
373 .attr("class", "y axis") |
|
374 .call(yAxis) |
|
375 .append("text") |
|
376 .attr("transform", "rotate(-90)") |
|
377 .attr("y", 6) |
|
378 .attr("dy", ".71em") |
|
379 .style("text-anchor", "end"); |
|
380 |
|
381 |
|
382 // Text for y-axis |
|
383 // svg.append("text") |
|
384 // .attr("transform", "rotate(-90)") |
|
385 // .attr("y", 10 - margin.left) |
|
386 // .attr("x", 0 - (height / 2)) |
|
387 // .attr("dy", "1em") |
|
388 // .style("text-anchor", "middle") |
|
389 // .text("Issues"); |
|
390 |
|
391 |
|
392 //Titel und Legende |
|
393 // svg.append("svg:text") |
|
394 // .attr("class", "text") |
|
395 // .attr("x", 10) |
|
396 // .attr("y", -5) |
|
397 // .text("Issues Nach Zeit"); |
|
398 |
|
399 draw_line(svg, wish, "line wish", wishLine, "0, 0"); |
|
400 draw_line(svg, feature, "line feature", featureLine, "3, 3"); |
|
401 draw_line(svg, bug, "line bug", bugLine, "7, 7"); |
|
402 draw_line(svg, urgent, "line urgent", urgentLine, "13, 13"); |
|
403 draw_line(svg, critical, "line critical", criticalLine, "17, 17"); |
|
404 |
|
405 |
|
406 // makeLegend(svg, width); |
|
407 } |
|
408 |
|
409 |
|
410 </script> |