summaryrefslogtreecommitdiff
path: root/AndroidPlot-Core/src/main/java/com/androidplot/xy/StepRenderer.java
blob: 17f01c34a8940c1c31c92db121e50aeec52afe47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
 * Copyright 2012 AndroidPlot.com
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.androidplot.xy;

import android.graphics.Path;
import android.graphics.PointF;

/**
 * Renders a point as a line with the vertices marked.  Requires 2 or more points to
 * be rendered.
 */

public class StepRenderer extends LineAndPointRenderer<StepFormatter> {

    public StepRenderer(XYPlot plot) {
        super(plot);
    }

    @Override
    protected void appendToPath(Path path, PointF thisPoint, PointF lastPoint) {
        //path.lineTo(thisPoint.x, thisPoint.y);

        path.lineTo(thisPoint.x, lastPoint.y);
        path.lineTo(thisPoint.x, thisPoint.y);
                        //canvas.drawPoint(point.x, lastPoint.y, format.getVertexPaint());
                        // next the vertical:
                        //canvas.drawLine(point.x, lastPoint.y, point.x, point.y, format.getLinePaint());
    }
}
/*
public class StepRenderer extends XYSeriesRenderer<StepFormatter> {

    private PointF lastPoint;

    private boolean drawLinesEnabled = true;
    private boolean drawPointsEnabled = true;

    private XYAxisType stepAxis = XYAxisType.DOMAIN;



    public StepRenderer(XYPlot plot) {
        super(plot);
    }

    @Override
    public void onRender(Canvas canvas, RectF plotArea) throws PlotRenderException {



        for(XYSeries series : getPlot().getSeriesListForRenderer(this.getClass())) {

            drawSeries(canvas, plotArea, series, getFormatter(series));
        }
        //foreach(this.)
        //foreach()
    }

    @Override
    public void doDrawLegendIcon(Canvas canvas, RectF rect, String text, StepFormatter formatter) {
        // horizontal icon:
        float centerY = rect.centerY();
        float centerX = rect.centerX();
        canvas.drawLine(rect.left, rect.top, rect.right, rect.bottom, formatter.getLinePaint());
        canvas.drawPoint(centerX, centerY, formatter.getVertexPaint());
        //canvas.drawRect(rect, formatter.getLinePaint());

    }


    private void drawSeries(Canvas canvas, RectF plotArea, XYSeries series, StepFormatter formatter) throws PlotRenderException {
        beginSeries(canvas, plotArea, formatter);
        //XYDataset series = bundle.getDataset();
        //int seriesIndex = bundle.getSeriesIndex();
        PointF thisPoint;
        for (int i = 0; i < series.size(); i++) {
            Number y = series.getY(i);
            Number x = series.getD(i);

            if (y != null && x != null) {

                thisPoint = ValPixConverter.valToPix(
                        x,
                        y,
                        plotArea,
                        getPlot().getCalculatedMinX(),
                        getPlot().getCalculatedMaxX(),
                        getPlot().getCalculatedMinY(),
                        getPlot().getCalculatedMaxY());
                //float pixX = ValPixConverter.valToPix(x.doubleValue(), getPlot().getCalculatedMinX().doubleValue(), getPlot().getCalculatedMaxX().doubleValue(), plotArea.width(), false) + (plotArea.left);
                //float pixY = ValPixConverter.valToPix(y.doubleValue(), getPlot().getCalculatedMinY().doubleValue(), getPlot().getCalculatedMaxY().doubleValue(), plotArea.height(), true) + plotArea.top;

                //thisPoint = new PointF(pixX, pixY);
            } else {
                thisPoint = null;
            }
            drawPoint(canvas, thisPoint, plotArea, formatter);
        }
        endSeries(canvas, plotArea, formatter);
    }

    private void beginSeries(Canvas canvas, RectF plotArea, StepFormatter format) throws PlotRenderException {
        lastPoint = null;
    }

    private void drawPoint(Canvas canvas, PointF point, RectF plotArea, StepFormatter format) throws PlotRenderException {
        if (lastPoint != null) {
            if (point != null) {

                switch(stepAxis) {
                    case DOMAIN:
                        // first draw the horizontal line:
                        canvas.drawLine(lastPoint.x, lastPoint.y, point.x, lastPoint.y, format.getLinePaint());
                        canvas.drawPoint(point.x, lastPoint.y, format.getVertexPaint());
                        // next the vertical:
                        canvas.drawLine(point.x, lastPoint.y, point.x, point.y, format.getLinePaint());
                        break;
                    case RANGE:
                        break;
                }
                //doDrawLine(canvas, lastPoint, point, plotArea, format);


            }
            drawLastPoint(canvas, plotArea, format);
        }

        lastPoint = point;
    }

    private void endSeries(Canvas canvas, RectF plotArea, StepFormatter format) throws PlotRenderException {
        if(lastPoint != null) {
            drawLastPoint(canvas, plotArea, format);
        }
    }

    protected void drawLastPoint(Canvas canvas, RectF plotArea, StepFormatter format) throws PlotRenderException {
        canvas.drawPoint(lastPoint.x, lastPoint.y, format.getVertexPaint());
    }


    public XYAxisType getStepAxis() {
        return stepAxis;
    }

    public void setStepAxis(XYAxisType stepAxis) {
        this.stepAxis = stepAxis;
    }
}
*/