Skip to content

Commit

Permalink
Clearing D3 plot before to plot. Following the instructions raised at…
Browse files Browse the repository at this point in the history
… the issue rstudio/r2d3#52
  • Loading branch information
lgsilvaesilva committed Mar 11, 2020
1 parent ed6517d commit a5da1bd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions shiny/www/js/barchartrace.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ let frame = options.first_frame;
let last_frame = options.last_frame;

r2d3.onRender(function(data, svg, width, height, options) {

svg.selectAll("g").remove();

data.forEach(d => {
d.value = +d.value,
d.last_value = +d.last_value,
Expand Down
4 changes: 3 additions & 1 deletion shiny/www/js/barchartrace2.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ r2d3.onRender(function(data, svg, width, height, options) {
.ticks(width > 500 ? 5:2)
.tickSize(-(height-margin.top-margin.bottom))
.tickFormat(d => d3.format(',')(d));

svg.append('g')
.attr('class', 'axis xAxis')
.attr('transform', `translate(0, ${margin.top})`)
Expand All @@ -81,6 +81,7 @@ r2d3.onRender(function(data, svg, width, height, options) {
.attr('height', y(1)-y(0)-bar_padding)
.style('fill', d => d.colour);

svg.selectAll('text.label').remove();
svg.selectAll('text.label')
.data(frameSlice, d => d.name)
.enter()
Expand All @@ -91,6 +92,7 @@ r2d3.onRender(function(data, svg, width, height, options) {
.style('text-anchor', 'end')
.html(d => d.name);

svg.selectAll('text.valueLabel').remove();
svg.selectAll('text.valueLabel')
.data(frameSlice, d => d.name)
.enter()
Expand Down

0 comments on commit a5da1bd

Please sign in to comment.