Commit 8dad7ce76569867899aa4bbd3f4fb4562bf43a91

Authored by Anais Amato
Committed by hitier
1 parent fd63e06e

Add animations to load bars in d3.js graphs

Showing 1 changed file with 23 additions and 3 deletions   Show diff stats
app/main/static/js/charges.js
... ... @@ -255,15 +255,26 @@ function build_chart(div_selector, data_url, entity_name, category_type) {
255 255 })
256 256 .enter().append("rect")
257 257 .attr("x", d => xCategories(d.key))
258   - .attr("y", d => yScale(d.value))
259 258 .attr("width", xCategories.bandwidth())
  259 + /* Transition part */
  260 + .attr("y", d => { return height; })
  261 + .attr("height", 0)
  262 + .transition()
  263 + .duration(750)
  264 + .delay(function (d, i) {
  265 + return i * 150;
  266 + })
  267 + .attr("y", d => yScale(d.value))
260 268 .attr("height", d => height - yScale(d.value))
261 269 .attr("fill", d => colorScale(d.key))
262   - .attr("class", "bar")
  270 + .attr("class", "bar");
  271 +
  272 + svg.selectAll("rect")
263 273 .on("mouseover", mouseovergrouped)
264 274 .on("mousemove", mousemove)
265 275 .on("mouseleave", mouseleave);
266 276  
  277 +
267 278 }
268 279  
269 280 function draw_categories_stacked(data, categories) {
... ... @@ -301,9 +312,18 @@ function build_chart(div_selector, data_url, entity_name, category_type) {
301 312 .attr("class", "bar")
302 313 .attr("x", d => xScale(d.data.period))
303 314 .attr("width", xScale.bandwidth())
304   - // .attr("width", 5)
  315 + /* transition part */
  316 + .attr("y", d => { return height; })
  317 + .attr("height", 0)
  318 + .transition()
  319 + .duration(750)
  320 + .delay(function (d, i) {
  321 + return i * 150;
  322 + })
305 323 .attr("y", d => yScale(d[1]))
306 324 .attr("height", d => height - yScale(d[1] - d[0]))
  325 +
  326 + groups.selectAll("rect")
307 327 .on("mouseover", mouseover)
308 328 .on("mousemove", mousemove)
309 329 .on("mouseleave", mouseleave);
... ...