rickshaw
rickshaw copied to clipboard
TypeError: style is null
There's a bug on Rickshaw where it will fail to render the graph if the component container is hidden. This is happening because getComputedStyle is returning null. So far, I've located the cause of the bug in two places:
Here:
if (typeof window !== undefined) {
var style = window.getComputedStyle(this.element, null);
var elementWidth = parseInt(style.getPropertyValue('width'));
var elementHeight = parseInt(style.getPropertyValue('height'));
}
And here:
if (typeof window !== 'undefined') {
var style = window.getComputedStyle(this.element.parentNode, null);
var elementWidth = parseInt(style.getPropertyValue('width'));
if (!args.auto) {
var elementHeight = parseInt(style.getPropertyValue('height'));
}
}
I fixed them by replacing them with:
This:
if (typeof window !== undefined) {
var style = window.getComputedStyle(this.element, null);
var elementWidth = style && parseInt(style.getPropertyValue('width'));
var elementHeight = style && parseInt(style.getPropertyValue('height'));
}
and this:
if (typeof window !== 'undefined') {
var style = window.getComputedStyle(this.element.parentNode, null);
var elementWidth = style && parseInt(style.getPropertyValue('width'));
if (!args.auto) {
var elementHeight = style && parseInt(style.getPropertyValue('height'));
}
}
With those two modifications, as long as you set the width and height explicitly, it will work okay.
@hexicle Sounds good to me. Want to open a small PR?