Example usage for com.google.gwt.widgetideas.graphics.client GWTCanvas restoreContext

List of usage examples for com.google.gwt.widgetideas.graphics.client GWTCanvas restoreContext

Introduction

In this page you can find the example usage for com.google.gwt.widgetideas.graphics.client GWTCanvas restoreContext.

Prototype

public void restoreContext() 

Source Link

Document

Restores the last saved context from the context stack.

Usage

From source file:org.utgenome.gwt.utgb.client.canvas.GWTGraphCanvas.java

License:Apache License

protected void drawWigGraph(GraphCanvas graphCanvas) {

    for (CompactWIGData data : graphCanvas.graphData) {

        // get graph color
        Color graphColor = new Color(DEFAULT_COLOR);
        if (style.color.isDefined()) {
            graphColor = new Color(style.color.get());
        } else if (data.getTrack().containsKey("color")) {
            String colorStr = data.getTrack().get("color");
            String c[] = colorStr.split(",");
            if (c.length == 3)
                graphColor = new Color(Integer.valueOf(c[0]), Integer.valueOf(c[1]), Integer.valueOf(c[2]));
        }//from www  . jav  a 2s.co m

        // draw graph
        GWTCanvas canvas = graphCanvas.canvas;

        canvas.saveContext();
        canvas.setLineWidth(1.0f);
        canvas.setStrokeStyle(graphColor);

        //canvas.scale(viewWindow.convertToPixelLength(graphCanvas.window.getSequenceLength()) / (double) data.getPixelSize(), 1.0f);

        float y2 = getYPosition(0.0f);

        // draw data graph
        final boolean isReverse = graphCanvas.window.isReverseStrand();
        final int pixelWidth = data.getData().length;

        float min = style.autoScale ? autoScaledMinValue : style.minValue;
        float max = style.autoScale ? autoScaledMaxValue : style.maxValue;

        for (int i = 0; i < pixelWidth; ++i) {
            float value = data.getData()[i];
            float y1;
            if (value == 0.0f) {
                if (!style.drawZeroValue)
                    continue;
                else {
                    y1 = y2 + ((min < max) ? -0.5f : 0.5f);
                }
            } else {
                y1 = getYPosition(value);
            }

            int x = i;
            if (isReverse) {
                x = pixelWidth - x - 1;
            }

            canvas.saveContext();
            canvas.beginPath();
            canvas.translate(x + 0.5f, 0);
            canvas.moveTo(0, y1);
            canvas.lineTo(0, y2);
            canvas.stroke();
            canvas.restoreContext();
        }
        canvas.restoreContext();
    }

}