gavioto / clientsidegchart

Automatically exported from code.google.com/p/clientsidegchart
0 stars 2 forks source link

GWT 2.2.0 Canvas is not supported (well, not easily anyway) #24

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Upgrade to GWT 2.2.0 and remove gwt-incubator jar.

What is the expected output? What do you see instead?
- Should be compatible with new Canvas

What version of the product are you using? On what operating system?
- 2.7

Please provide any additional information below.
- GWTCanvasBasedCanvasLite can not extend Canvas, and therefore is no longer a 
widget, as you are not allowed to construct Canvas directly.  However, here is 
a work-around (not fully tested):

/**
 * Set the chart to use the GWT Canvas
 */
static final class GWTCanvasBasedCanvasLite extends Widget implements 
GChartCanvasLite {
    Canvas canvas;
    Context2d canvasContext;

    public GWTCanvasBasedCanvasLite() {
        canvas = Canvas.createIfSupported();
        canvasContext = canvas.getContext2d();
    }
    @Override
    public Element getElement() {
        return canvas.getElement();
    }
    public void setStrokeStyle(String cssColor) {
        // Sharp angles of default MITER can overwrite adjacent pie slices
        canvasContext.setLineJoin(LineJoin.ROUND);
        canvasContext.setStrokeStyle(cssColor);
    }
    public void setFillStyle(String cssColor) {
        canvasContext.setFillStyle(cssColor);
    }
    public void arc(double x, double y, double radius, double startAngle, double endAngle, boolean antiClockwise) {
        canvasContext.arc(x, y, radius, startAngle, endAngle, antiClockwise);
    }
    public void beginPath() {
        canvasContext.beginPath();
    }
    public void clear() {
        canvasContext.clearRect(0, 0, canvas.getCoordinateSpaceWidth(), canvas.getCoordinateSpaceHeight());
    }
    public void closePath() {
        canvasContext.closePath();
    }
    public void fill() {
        canvasContext.fill();
    }
    public void lineTo(double x, double y) {
        canvasContext.lineTo(x, y);
    }
    public void moveTo(double x, double y) {
        canvasContext.moveTo(x, y);
    }
    public void resize(int width, int height) {
        canvas.setCoordinateSpaceWidth(width);
        canvas.setCoordinateSpaceHeight(height);
    }
    public void setLineWidth(double width) {
        canvasContext.setLineWidth(width);
    }
    public void stroke() {
        canvasContext.stroke();
    }
}

Original issue reported on code.google.com by craig...@gmail.com on 2 Mar 2011 at 2:44

GoogleCodeExporter commented 9 years ago
this implementation works great in our project. thanks a lot!

Original comment by whust...@googlemail.com on 21 Mar 2011 at 5:17

GoogleCodeExporter commented 9 years ago
Problem is, GChart needs to support older IE browsers, but the new GWT 2.2 
Canvas capability does not support IE 6, 7, and 8. For this reason, I don't 
currently plan to better integrate its use into GChart.

Original comment by gchartco...@gmail.com on 3 Apr 2011 at 4:11

GoogleCodeExporter commented 9 years ago
That's fine.  I was just suggesting that GChart should not rely on the fact 
that GChartCanvasLite is a widget, rather GChartCanvasLite should have a method 
like getWidget().  That way it will easily work with both GWTCanvas and the new 
Canvas.

However, I suspect the only method on Widget that GChart cares about is 
getElement(), and therefore, the work-around above will work fine.

Original comment by craig...@gmail.com on 4 Apr 2011 at 6:39

GoogleCodeExporter commented 9 years ago
gwt-incubator is deprecated and unsupported now

Original comment by stanisla...@gmail.com on 16 Sep 2011 at 9:37