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