shannah / CN1aChartEngine

A port of Android aChartEngine Library for Codename One
7 stars 6 forks source link

Caching charts #5

Open Munken opened 10 years ago

Munken commented 10 years ago

As mentioned early some charts are quite slow to render. Some of this can be solved by rendering to an image an then just have CN1 draw this.

Currently I use this code to achieve it:

    private static Image g(GraphicalView g, int w, int h) {
        Image buf = Image.createImage(w, h, 0xF0F0F0);
        buf.getGraphics().setClip(0, 0, w, h);

        Canvas canvas = new Canvas();
        Paint paint = new Paint();
        canvas.g = buf.getGraphics();
        Paint.g = buf.getGraphics();
        g.getChart().draw(canvas, 0, 0, w, h, paint);

        return buf;
    }

There should however be a way to invalidate the cache or it should detect automatically.

Munken commented 10 years ago

Here is some code that relies entirely on the pisces pipeline to render the chart. Please note that it is note complete. Needs scaling, translation, rotation and other stuff.

https://gist.github.com/Munken/6fae6ec805fabc626c9f

shannah commented 10 years ago

Have you found that this gives better performance?

Munken commented 10 years ago

Before it would scroll heavily when scrolling a tab that contained a chart. With caching it as an image scrolling is fluent.

The Pisces canvas solves the rest