question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Firefox fails to draw charts in jquery UI tabs

See original GitHub issue

Hello, I noticed a strange issue with firefox when using your chart library inside tabs of jquery UI. The chart is rendered correctly on the first tab, however it fails completely on other tabs. I’m using tabsactivate event to create a chart, at this moment tab panel is fully visible. While investigating I see it throws exception NS_ERROR_FAILURE excecuting function getBBox() inside getMaxTickWidth() at line 784:

    function getMaxTickWidth(id) {
        var maxWidth = 0, axisClass = id === 'x' ? CLASS.axisX : id === 'y' ? CLASS.axisY : CLASS.axisY2;
        d3.selectAll('.' + axisClass + ' .tick text').each(function () {
            var box = this.getBBox();
            if (maxWidth < box.width) { maxWidth = box.width; }
        });
        return maxWidth < 20 ? 20 : maxWidth;
    }

I’m using latest firefox v28, however IE9-11 and latest chrome work fine in this case. Please take a look at live example here: http://jsfiddle.net/Lm2e5/4/ Line 784 is not the only one where getBBox() is used, so if I configure to hide axis, exception will be rised in a different place of the code.

I tracked down that jquery UI is not responsible for this exception, because it can be reproduced by toggling visibility of adjanced DIVs. The key is to create a chart and hide it with visibility:none. Then set visibilty:block to nearby DIV and draw a new chart, while the first one is still there hidden in the DOM.

As a temporary workaround I replaced getBBox() with getBoundingClientRect(). It seems to work fine in Firefox, but I can’t understand why getBBox() fails. For instance another D3 based charting library called Dimple also uses getBBox function, but it’s charts work well inside tabs.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lblbcommented, Apr 8, 2014

Hi Masayuki, thanks for looking into this. I also noticed that IE has problems evaluating getBBox in similar cases, however it returns {0,0,0,0} object instead exception as Firefox. Hence only axis fails to render but not all the chart. So it looks like not a browser bug. I did some further investigation and I believe getBBox should be changed into getBoundingClientRect, because it seems to work pretty well with SVG elements in all modern browsers. Even though it gives large errors for more complex shapes with transformation applied, but it’s still better than getBBox, see example: http://jsfiddle.net/6M5zf/15/ (Unfortunatelly getBBox does not return correct X and Y offsets, so it’s not possible to draw bounding boxes…)

In addition getBoundingClientRect is computed significantly faster: http://jsperf.com/getboundingclientrect-vs-offsetwidth/8

However If you can track down why getBBox fails, probably it would be better to leave it as it is, because it’s a specific function for SVG. In contrast getBoundingClientRect gives different results in different browsers. IE and firefox include stroke width in calculations, however chrome excludes it.

0reactions
CHR15-commented, Apr 12, 2014

Great I’ll give it a shot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

jQuery UI Tabs and Highcharts display/rendering issue
This is my solution (only tested in Safari and Firefox). It works great if you want to load the chart into a hidden...
Read more >
Tabs not working in firefox with authentication in the URL
Don't know if it is a bug in jQuery or Firefox. When opening a webpage with Firefox (checked with 35.01) with user credentials...
Read more >
graph will not show on browser window | Firefox Support Forum
Since updating Firefox to v.56.0.1 I have found a graph no longer shows on a website (notebook/desktop using W7). The same problem happens ......
Read more >
HighCharts line graph with jQuery UI tabs
Now the nice line graph that displayed in one of the tabs ... Even on Windows clients this does not happen if I...
Read more >
jQuery UI Tabs instance() Method - GeeksforGeeks
The jQuery UI Tabs widget is used to create a single content area with multiple ... If the tabs element does not have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found