GithubHelp home page GithubHelp logo

Comments (5)

krullert avatar krullert commented on July 18, 2024 2

fugly workaround;

replace all ChartLoaders with ConcurrentChartLoader;

public class ConcurrentChartLoader extends ChartLoader {

    private static final Queue<DelegatingLoaderRunnable> LOADING_QUEUE = new ArrayDeque<>();

    public ConcurrentChartLoader(ChartPackage... packages) {
        super(packages);
    }

    @Override
    public void loadApi(Runnable callback) {
        doLoadApi(this, callback);
    }

    protected void doLoadApi(ConcurrentChartLoader loader, Runnable callback) {
        // @see https://github.com/google/gwt-charts/issues/66
        if (LOADING_QUEUE.isEmpty()) {
            LOADING_QUEUE.add(new DelegatingLoaderRunnable(callback, loader));
            final Runnable delegatingCallback = new Runnable() {
                @Override
                public void run() {
                    try {
                        LOADING_QUEUE.poll().run();
                    } finally {
                        final DelegatingLoaderRunnable peek = LOADING_QUEUE.peek();
                        if (peek != null) {
                            peek.loader.doLoadApi(this);
                        }
                    }
                }
            };

            doLoadApi(delegatingCallback);
        } else {
            LOADING_QUEUE.add(new DelegatingLoaderRunnable(callback, loader));
        }
    }

    protected void doLoadApi(Runnable callback) {
        super.loadApi(callback);
    }

    protected static class DelegatingLoaderRunnable implements Runnable {

        private final Runnable delegate;
        private final ConcurrentChartLoader loader;

        public DelegatingLoaderRunnable(Runnable delegate, ConcurrentChartLoader loader) {
            this.delegate = delegate;
            this.loader = loader;
        }

        @Override
        public void run() {
            delegate.run();
        }
    }
}

from gwt-charts.

ccrvincent avatar ccrvincent commented on July 18, 2024

Looks like this is possibly a duplicate/regression of #58 .

from gwt-charts.

sauldeleon avatar sauldeleon commented on July 18, 2024

Hello @ccrvincent

I am facing the same issue, and it is really annoying. I have two pie Charts which are generated at the same tame woth 2 data sources and only one gets painted.

Could you please provide some hints of your solution? I have trying to make it work using GoogleApiLoader with no success...

Thanks in advance!

Saรบl

from gwt-charts.

ccrvincent avatar ccrvincent commented on July 18, 2024

I no longer have access to the codebase where I was using this, so this is totally off of memory.

I wrote a class that either extended or wrapped ChartLoader and used it to manage the callbacks myself. Something like this (VERY loose psuedocode):

load(callback) {
if (!loaded) {
queue.add(callback);
if (!loading) {
ChartLoader.dowhateveritneedstodo(getLocalCallback());
loading = true;
}
} else {
callback.run();
}
}

LocalCallback.run() {
loaded = true;
for (callback : queue) {
callback.run();
}
}

GoogleApiLoader was only referenced here as an example of how to manage the loader. I never used it directly with gwt-charts.

from gwt-charts.

sauldeleon avatar sauldeleon commented on July 18, 2024

Thank you very much @ccrvincent for your support and effort looking for this in your memory. I will give a try.

Again, thanks a lot :)

from gwt-charts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.