screenresize while dygraph is invisible is reseting its sizes to 0

768 views
Skip to first unread message

Siegfried De Bleeckere

unread,
Sep 6, 2012, 7:53:06 AM9/6/12
to dygraph...@googlegroups.com
Hi all,

Dygraph looks really very promising and we intend to use it for all our trending, one glitch we found was when we put it in jquery tabs/panels...
I think dygraph misbehaves when it is in an invisible div and a resize occurs.

Procedure:
-open http://jsfiddle.net/tg2YM/
-look at the 2 tabs, the dygraphs are ok
-resize the screen
-go to the other tab
-dygraph is gone with size of 0,0

Is there something obvious we are missing?

Many thanks,

Siegfried

Seema Kadian

unread,
Sep 6, 2012, 9:25:26 AM9/6/12
to dygraph...@googlegroups.com
Hi, 

I am creating a proof of concept to use dyGraph in our application and found this exactly the same issue while resizing when the parent div is not visible. 

Can you suggest some fix for this? Most of the concepts are already well  implemented by dyGraph. I would be great if I can do this too.

Thanks,
Seema

Dan Vanderkam

unread,
Sep 6, 2012, 2:14:52 PM9/6/12
to seema....@gmail.com, dygraph...@googlegroups.com
Can you guys confirm whether you are running into this issue?
http://code.google.com/p/dygraphs/issues/detail?id=238

Siegfried De Bleeckere

unread,
Sep 6, 2012, 5:40:24 PM9/6/12
to dygraph...@googlegroups.com, seema....@gmail.com
Hi Danvk,

My issue is a little bit different, but I can reproduce the 238 issue as well. Probably it has the same cause and hopefully my info gives you more information.

conclusion:
-create dygraph in invisible div, show div -> does not work (size 0,0) (as in the bug report)
-create dygraph in visible div, hide div, show div -> does work correctly
-create dygraph in visible div, hide div, resize browser window, show dif -> does not work (size 0,0)  (that is what I found)

(in my jsfiddle example if you first create the tabs and then the dygraph (move last js line to the top) than you can reproduce bug 238 as well.
Should I add this to the bug report?

Thanks for your quick response.

Regards,

Siegfried

Dan Vanderkam

unread,
Sep 11, 2012, 2:59:13 PM9/11/12
to siegfried....@gmail.com, dygraph...@googlegroups.com, seema....@gmail.com
The issue here is that, when the dygraph div is invisible, its size
really is 0x0. There's no DOM event that dygraphs can listen for that
indicates when it becomes visible or resizes, so it can't resize
itself when it becomes visible without your help.

dygraphs _does_ listen for window.resize events, which tend to be
associated with most CSS resizes. But this isn't a perfect solution.
Google Maps and other JS libraries have a similar issue.

- Dan

Siegfried De Bleeckere

unread,
Sep 11, 2012, 3:11:44 PM9/11/12
to dygraph...@googlegroups.com, siegfried....@gmail.com, seema....@gmail.com
Hi Dan,


Thanks for your quick response.
I understand the root of the behaviour. We will help dygraph to get the right size when it comes visible manually.

Thanks again and kind regards,

Siegfried

Nils Springob

unread,
Mar 4, 2013, 1:02:02 PM3/4/13
to dygraph...@googlegroups.com
The following code triggers a manual update as workaround:

  var evt = document.createEvent('UIEvents');
  evt.initUIEvent('resize', true, false,window,0);
  window.dispatchEvent(evt);



khw

unread,
Sep 26, 2013, 10:25:17 AM9/26/13
to dygraph...@googlegroups.com
Perfect solution, thanks!

Under jquery tabs, you can use

tabs.on("tabsactivate", function() {  
   var evt = document.createEvent('UIEvents');
   evt.initUIEvent('resize', true, false,window,0);
   window.dispatchEvent(evt);
});

Catia Matos

unread,
Jul 25, 2017, 6:59:25 AM7/25/17
to dygraphs-users

I need to resize my graph inside my tabs. Can anyone tell me how to do this in angular? When i load the first time my graphs didnt show unless i move the window and resize it.. I need for the first time that it loads the graphs and fill the div for that..


My directive:

(function() {
    var app = angular.module('dashboard.view', []);

    app.directive('dygraph', function(){
        return {
            restrict: 'E',
            scope: {
                data    : '=',
                options : '=?'
            },
            template: '<div style="width: 100%"></div>',
            link: function (scope, elem, attrs) {
                scope.options.width = elem.parent()[0].offsetWidth;
                var graph = new Dygraph(elem.children()[0], scope.data, scope.options);
                /*if(scope.options.title=="Scanning" || scope.options.title=="Bytes" || scope.options.title=="Pakets"){
                    graph.ready(function(){
                        var width = this.graphDiv.clientWidth;
                        if(width==0)
                            width=1129;
                            graph.resize(width,320);
                    });
                }*/

            }        
        };
    });

If i do graph.resize it will appear on laod but if i change my tab the graph width is 0 again... Please help me!
Reply all
Reply to author
Forward
0 new messages