0

I am working on an educational tool that mainly uses the D3js library. To make parts of my code reusable, I want to put as much code as possible inside a constructor, so that I can work with instances of that constructor. However, a very weird bug shows up when I try to update parts (for instance the border-color) of the graphic: only a small part of the border changes color and, for extra weirdness, the rest of the border changes when I switch to a different in my browser and then come back.

This jsfiddle shows the problem. Upon loading the canvas border is black. When "Red"/"Blue" is clicked, the border should turn red/blue. In Firefox this works fine, but in both Chrome and Safari only a small part of the border changes color…

Border that is partly red

The code I use is the following:

var Canvas = function(B, H){
    this.canvas = d3.select("#holder").append("svg:svg").attr("width",B).attr("height",H)
            .style({'border':'5px solid black'});
    this.red = function(){this.canvas.style({'border':'5px solid red'});};
    this.blue = function(){this.canvas.style({'border':'5px solid blue'});};
}
var Canvas1 = new Canvas(200,70);

Click "Red"/"Blue" class the red/blue functions that should change the color:

$("#red").click(function(){Canvas1.red();});
$("#blue").click(function(){Canvas1.blue()});

Since this works fine with Firefox I suppose the problem has something to do with the Webkit, but I have no idea how to fix it…

Any help is much appreciated!

  • This is indeed an issue with webkit, more details and a solution [here](http://www.eccesignum.org/blog/solving-display-refreshredrawrepaint-issues-in-webkit-browsers). [This question](http://stackoverflow.com/questions/3485365/how-can-i-force-webkit-to-redraw-repaint-to-propagate-style-changes) may also help. – Lars Kotthoff Apr 16 '14 at 11:37
  • @LarsKotthoff Thanks for the directions! After going through some of the options, I found something that worked for me. Update fiddle can be found [here](http://jsfiddle.net/s8j4M/1/). – JonasVoorzanger Apr 17 '14 at 08:06

0 Answers0