Skip to content

Instantly share code, notes, and snippets.

@slattery
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slattery/10483969 to your computer and use it in GitHub Desktop.
Save slattery/10483969 to your computer and use it in GitHub Desktop.
d3-timeline setWidth check construction attrs for width before rejecting on behalf of FF

setWidth was failing for us in FF, even though we had constructed our attempt as entered in the README:

var chart = d3.timeline();

var svg = d3.select("#timeline1").append("svg").attr("width", 500)
  .datum(testData).call(chart);

It looks like setWidth does ask for the attribute as entered during initial construction:

width = gParentItem.attr("width");

So we juggled the tests to include that earlier in the chain, throwing the error if no width value is found.

@slattery @rrotaru

function setWidth() {
if (!width && !gParentSize.width) {
try {
width = gParentItem.attr("width");
if ( !width )
throw "width of the timeline is not set. As of Firefox 27, timeline().with(x) needs to be explicitly set in order to render";
} catch (err){
console.log( err );
}
} else if (!(width && gParentSize.width)) {
gParentItem.attr("width", width);
}
// if both are set, do nothing
}
function setWidth() {
if (!width && !gParentSize.width) {
throw "width of the timeline is not set. As of Firefox 27, timeline().with(x) needs to be explicitly set in order to render";
} else if (!(width && gParentSize.width)) {
if (!width) {
width = gParentItem.attr("width");
} else {
gParentItem.attr("width", width);
}
}
// if both are set, do nothing
}
Copy link

ghost commented Sep 17, 2014

nice fix, did you ever get around to submitting a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment