ialexei / gwt-charts

Automatically exported from code.google.com/p/gwt-charts
0 stars 0 forks source link

ApiLoader is not a singleton #58

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,
I'm using your library but I cannot use more than a charts widget at time in
the same root panel.
What steps will reproduce the problem?
1. In the module load I write this code (it's quite similar to your example)

        // Create the API Loader
        ChartLoader chartLoader = new ChartLoader(ChartPackage.CORECHART);
        chartLoader.loadApi(new Runnable() {
            @Override
            public void run() {
                PieChart pieChart = getPieChart();
                flowPanel.insert(pieChart, 0);
                drawPieChart(pieChart, createDataTable("_1"));
            }
        });
        chartLoader.loadApi(new Runnable() {
            @Override
            public void run() {
                PieChart pieChart = getPieChart();
                flowPanel.insert(pieChart, 0);
                drawPieChart(pieChart, createDataTable("_2"));
            }
        });     

What is the expected output? 
I expect to see two charts...

What do you see instead?
I see only one chart

What operating system, browser and version are you using?
I'm using ubuntu 12.04 with Chrome

Appling my patch all works fine.

Tell me if you need more information.

Cheers

Original issue reported on code.google.com by antonio....@gmail.com on 19 Dec 2014 at 9:57

Attachments:

GoogleCodeExporter commented 8 years ago
You're not supposed to load the api twice.
But mainly it looks like you're inserting the same PieChart object into the 
FlowPanel.

Original comment by rglafo...@gmail.com on 24 Feb 2015 at 3:46

GoogleCodeExporter commented 8 years ago
No, the problem is that is a singleton in the javascript environment.
If you call Apiloader more than one time in quick succession in the entry point 
your load will be deferred and inserted inside queuedApiLoads vector. 
When the api finish initialization only the last call will be executed because 
queuedApiLoads is the last builded and contains only one reference.

After this initialization 

        if ($wnd['google'] && $wnd.google['load']) {
            // The API has already been loaded.
            return true;
        }

will return true and no more runnable are stored inside the vector, and so all 
works fine.

Cheers

Original comment by antonio....@gmail.com on 4 Mar 2015 at 11:09