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