Commit a48677c466a7aa1445def41b9c8b743484297f2e
1 parent
6b44860d
Exists in
master
and in
4 other branches
Make a draw_categories_bars method to run only when needed
Showing
1 changed file
with
34 additions
and
23 deletions
Show diff stats
app/main/static/js/charges.js
... | ... | @@ -40,12 +40,13 @@ function build_chart(div_selector, data_url, project_name, category) { |
40 | 40 | if (category == 'capacity') { |
41 | 41 | var chart_title = "Charges par fonction" |
42 | 42 | var category_title = "Fonction" |
43 | - var draw_total_line = function(data){ //do nothing | |
44 | - } | |
43 | + var draw_total_line = function (data) { } | |
44 | + var draw_categories_bars = draw_categories_grouped | |
45 | 45 | } else if (category == 'service') { |
46 | 46 | var chart_title = "Charges par service" |
47 | 47 | var category_title = "Service" |
48 | 48 | var draw_total_line = draw_totalcharge_line |
49 | + var draw_categories_bars = draw_categories_stacked | |
49 | 50 | } else { |
50 | 51 | alert("ALERT ! Every body shall quit the boat, we are sinking ! ALERT !") |
51 | 52 | } |
... | ... | @@ -135,6 +136,36 @@ function build_chart(div_selector, data_url, project_name, category) { |
135 | 136 | .text(d => d); |
136 | 137 | } |
137 | 138 | |
139 | + function draw_categories_grouped(data){ | |
140 | + // do nothing at the moment | |
141 | + console.log("HEY grouped ") | |
142 | + } | |
143 | + | |
144 | + function draw_categories_stacked(stacked_data) { | |
145 | + // first one group for one category containing all bars over periods | |
146 | + let groups = svg.selectAll("g.category") | |
147 | + .data(stacked_data) | |
148 | + .enter() | |
149 | + .append("g") | |
150 | + .style("fill", (d) => color_scale(d.key)); | |
151 | + | |
152 | + // then each period/category bar | |
153 | + let rect = groups.selectAll("rect") | |
154 | + .data(d => d) | |
155 | + .enter() | |
156 | + .append("rect") | |
157 | + .attr("class", "bar") | |
158 | + .attr("x", d => xScale(d.data.period)) | |
159 | + .attr("width", xScale.bandwidth()) | |
160 | + // .attr("width", 5) | |
161 | + .attr("y", d => yScale(d[1])) | |
162 | + .attr("height", d => height - yScale(d[1] - d[0])) | |
163 | + .on("mouseover", mouseover) | |
164 | + .on("mousemove", mousemove) | |
165 | + .on("mouseleave", mouseleave); | |
166 | + | |
167 | + } | |
168 | + | |
138 | 169 | function draw_totalcharge_line(data) { |
139 | 170 | // Build the total charge by period; |
140 | 171 | // it will be used for the line drawing above bars. |
... | ... | @@ -309,27 +340,7 @@ function build_chart(div_selector, data_url, project_name, category) { |
309 | 340 | // Draw the stacked bars |
310 | 341 | // |
311 | 342 | |
312 | - // first one group for one category containing all bars over periods | |
313 | - let groups = svg.selectAll("g.category") | |
314 | - .data(stacked_data) | |
315 | - .enter() | |
316 | - .append("g") | |
317 | - .style("fill", (d) => color_scale(d.key)); | |
318 | - | |
319 | - // then each period/category bar | |
320 | - let rect = groups.selectAll("rect") | |
321 | - .data(d => d) | |
322 | - .enter() | |
323 | - .append("rect") | |
324 | - .attr("class", "bar") | |
325 | - .attr("x", d => xScale(d.data.period)) | |
326 | - .attr("width", xScale.bandwidth()) | |
327 | - // .attr("width", 5) | |
328 | - .attr("y", d => yScale(d[1])) | |
329 | - .attr("height", d => height - yScale(d[1] - d[0])) | |
330 | - .on("mouseover", mouseover) | |
331 | - .on("mousemove", mousemove) | |
332 | - .on("mouseleave", mouseleave); | |
343 | + draw_categories_bars(stacked_data) | |
333 | 344 | |
334 | 345 | |
335 | 346 | }); // end of d3.csv().then({}) | ... | ... |