rickshaw icon indicating copy to clipboard operation
rickshaw copied to clipboard

TypeError: style is null

Open haroldo-ok opened this issue 11 years ago • 1 comments

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.

haroldo-ok avatar Aug 29 '12 16:08 haroldo-ok

@hexicle Sounds good to me. Want to open a small PR?

RichardLitt avatar Dec 14 '17 20:12 RichardLitt