Skip to content

Commit 243152b

Browse files
committed
Renamed XY to XYCoords. Renamed XYPlotZoomPan to InteractiveXYPlot. Removed a bunch of dead code and added comments. Uprev minSdk from 4 to 5.
1 parent 6106561 commit 243152b

9 files changed

Lines changed: 36 additions & 156 deletions

File tree

androidplot-core/src/main/java/com/androidplot/xy/CatmullRomInterpolator.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ public void setType(Type type) {
6666
* Wraps a normal XYSeries, inserting a new point at the beginning and end of the series.
6767
*/
6868
static class ExtrapolatedXYSeries implements XYSeries {
69-
private final XY first;
70-
private final XY last;
69+
private final XYCoords first;
70+
private final XYCoords last;
7171
private final XYSeries series;
7272

73-
public ExtrapolatedXYSeries(XYSeries series, XY first, XY last) {
73+
public ExtrapolatedXYSeries(XYSeries series, XYCoords first, XYCoords last) {
7474
this.series = series;
7575
this.first = first;
7676
this.last = last;
@@ -119,7 +119,7 @@ public String getTitle() {
119119
* @throws java.lang.IllegalArgumentException if pointsPerSegment is less than 2.
120120
*/
121121
@Override
122-
public List<XY> interpolate(XYSeries series, Params params) {
122+
public List<XYCoords> interpolate(XYSeries series, Params params) {
123123
if (params.getPointPerSegment() < 2) {
124124
throw new IllegalArgumentException(
125125
"pointsPerSegment must be greater than 2, since 2 points is just the linear segment.");
@@ -140,15 +140,15 @@ public List<XY> interpolate(XYSeries series, Params params) {
140140
double y1 = series.getY(0).doubleValue() - dy;
141141

142142
// Actually create the start point from the extrapolated values.
143-
XY start = new XY(x1, y1);
143+
XYCoords start = new XYCoords(x1, y1);
144144

145145
// Repeat for the end control point.
146146
int n = series.size() -1;
147147
dx = series.getX(n).doubleValue() - series.getX(n-1).doubleValue();
148148
dy = series.getY(n).doubleValue() - series.getY(n - 1).doubleValue();
149149
double xn = series.getX(n).doubleValue() + dx;
150150
double yn = series.getY(n).doubleValue() + dy;
151-
XY end = new XY(xn, yn);
151+
XYCoords end = new XYCoords(xn, yn);
152152

153153
// TODO: figure out whether this extra control-point synthesis is
154154
// TODO: really necessary and either remove the above or fix the below.
@@ -162,14 +162,14 @@ public List<XY> interpolate(XYSeries series, Params params) {
162162
ExtrapolatedXYSeries extrapolatedXYSeries = new ExtrapolatedXYSeries(series, start, end);
163163

164164
// Dimension a result list of coordinates.
165-
List<XY> result = new ArrayList<>();
165+
List<XYCoords> result = new ArrayList<>();
166166

167167
// When looping, remember that each cycle requires 4 points, starting
168168
// with i and ending with i+3. So we don't loop through all the points.
169169
for (int i = 0; i < extrapolatedXYSeries.size() - 3; i++) {
170170

171171
// Actually calculate the Catmull-Rom curve for one segment.
172-
List<XY> points = interpolate(extrapolatedXYSeries, i, params);
172+
List<XYCoords> points = interpolate(extrapolatedXYSeries, i, params);
173173

174174
// Since the middle points are added twice, once for each bordering
175175
// segment, we only add the 0 index result point for the first
@@ -196,8 +196,8 @@ public List<XY> interpolate(XYSeries series, Params params) {
196196
* @return the list of coordinates that define the CatmullRom curve
197197
* between the points defined by index+1 and index+2.
198198
*/
199-
public List<XY> interpolate(XYSeries series, int index, Params params) {
200-
List<XY> result = new ArrayList<>();
199+
public List<XYCoords> interpolate(XYSeries series, int index, Params params) {
200+
List<XYCoords> result = new ArrayList<>();
201201
double[] x = new double[4];
202202
double[] y = new double[4];
203203
double[] time = new double[4];
@@ -226,13 +226,13 @@ public List<XY> interpolate(XYSeries series, int index, Params params) {
226226
}
227227

228228
int segments = params.getPointPerSegment() - 1;
229-
result.add(new XY(series.getX(index + 1), series.getY(index + 1)));
229+
result.add(new XYCoords(series.getX(index + 1), series.getY(index + 1)));
230230
for (int i = 1; i < segments; i++) {
231231
double xi = interpolate(x, time, tstart + (i * (tend - tstart)) / segments);
232232
double yi = interpolate(y, time, tstart + (i * (tend - tstart)) / segments);
233-
result.add(new XY(xi, yi));
233+
result.add(new XYCoords(xi, yi));
234234
}
235-
result.add(new XY(series.getX(index + 2), series.getY(index + 2)));
235+
result.add(new XYCoords(series.getX(index + 2), series.getY(index + 2)));
236236
return result;
237237
}
238238

androidplot-core/src/main/java/com/androidplot/xy/XYPlotZoomPan.java renamed to androidplot-core/src/main/java/com/androidplot/xy/InteractiveXYPlot.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
import android.view.View;
2424
import android.view.View.OnTouchListener;
2525

26-
public class XYPlotZoomPan extends XYPlot implements OnTouchListener {
26+
/**
27+
* An {@link XYPlot} that supports pan and zoom via touch gestures.
28+
*/
29+
public class InteractiveXYPlot extends XYPlot implements OnTouchListener {
2730
private static final float MIN_DIST_2_FING = 5f;
2831

2932
// Definition of the touch states
@@ -53,12 +56,12 @@ private enum State
5356
private boolean mZoomVerticallyInit;
5457
private boolean mZoomHorizontallyInit;
5558

56-
public XYPlotZoomPan(Context context, String title, RenderMode mode) {
59+
public InteractiveXYPlot(Context context, String title, RenderMode mode) {
5760
super(context, title, mode);
5861
setZoomEnabled(true); //Default is ZoomEnabled if instantiated programmatically
5962
}
6063

61-
public XYPlotZoomPan(final Context context, final AttributeSet attrs) {
64+
public InteractiveXYPlot(final Context context, final AttributeSet attrs) {
6265
super(context, attrs);
6366
if(mZoomEnabled || !mZoomEnabledInit) {
6467
setZoomEnabled(true);
@@ -71,7 +74,7 @@ public XYPlotZoomPan(final Context context, final AttributeSet attrs) {
7174
}
7275
}
7376

74-
public XYPlotZoomPan(final Context context, final AttributeSet attrs, final int defStyle) {
77+
public InteractiveXYPlot(final Context context, final AttributeSet attrs, final int defStyle) {
7578
super(context, attrs, defStyle);
7679
if(mZoomEnabled || !mZoomEnabledInit) {
7780
setZoomEnabled(true);
@@ -84,7 +87,7 @@ public XYPlotZoomPan(final Context context, final AttributeSet attrs, final int
8487
}
8588
}
8689

87-
public XYPlotZoomPan(final Context context, final String title) {
90+
public InteractiveXYPlot(final Context context, final String title) {
8891
super(context, title);
8992
}
9093

androidplot-core/src/main/java/com/androidplot/xy/Interpolator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@
2424
public interface Interpolator<ParamsType extends InterpolationParams> {
2525

2626

27-
List<XY> interpolate(XYSeries series, ParamsType params);
27+
List<XYCoords> interpolate(XYSeries series, ParamsType params);
2828
}

androidplot-core/src/main/java/com/androidplot/xy/LineAndPointRenderer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ protected void drawSeries(Canvas canvas, RectF plotArea, XYSeries series, LineAn
122122
}
123123
if(linePaint != null) {
124124
if(formatter.getInterpolationParams() != null) {
125-
List<XY> interpolatedPoints = getInterpolator(
125+
List<XYCoords> interpolatedPoints = getInterpolator(
126126
formatter.getInterpolationParams()).interpolate(series,
127127
formatter.getInterpolationParams());
128128
firstPoint = convertPoint(interpolatedPoints.get(ZERO), plotArea);
@@ -157,7 +157,7 @@ protected Interpolator getInterpolator(InterpolationParams params) {
157157
}
158158
}
159159

160-
protected PointF convertPoint(XY coord, RectF plotArea) {
160+
protected PointF convertPoint(XYCoords coord, RectF plotArea) {
161161
return ValPixConverter.valToPix(
162162
coord.x.doubleValue(),
163163
coord.y.doubleValue(),

androidplot-core/src/main/java/com/androidplot/xy/SimpleXYSeries.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,15 @@ public void addFirst(Number x, Number y) {
216216

217217
/**
218218
*
219-
* @return {@link XY} with first equal to x-val and second equal to y-val.
219+
* @return {@link XYCoords} with first equal to x-val and second equal to y-val.
220220
*/
221-
public XY removeFirst() {
221+
public XYCoords removeFirst() {
222222
lock.writeLock().lock();
223223
try {
224224
if (size() <= 0) {
225225
throw new NoSuchElementException();
226226
}
227-
return new XY(xVals != null ? xVals.removeFirst() : 0, yVals.removeFirst());
227+
return new XYCoords(xVals != null ? xVals.removeFirst() : 0, yVals.removeFirst());
228228
} finally {
229229
lock.writeLock().unlock();
230230
}
@@ -244,15 +244,15 @@ public void addLast(Number x, Number y) {
244244

245245
/**
246246
*
247-
* @return {@link XY} with first equal to x-val and second equal to y-val.
247+
* @return {@link XYCoords} with first equal to x-val and second equal to y-val.
248248
*/
249-
public XY removeLast() {
249+
public XYCoords removeLast() {
250250
lock.writeLock().lock();
251251
try {
252252
if (size() <= 0) {
253253
throw new NoSuchElementException();
254254
}
255-
return new XY(xVals != null ? xVals.removeLast() : yVals.size() - 1, yVals.removeLast());
255+
return new XYCoords(xVals != null ? xVals.removeLast() : yVals.size() - 1, yVals.removeLast());
256256
} finally {
257257
lock.writeLock().unlock();
258258
}

androidplot-core/src/main/java/com/androidplot/xy/StepRenderer.java

Lines changed: 0 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -32,133 +32,7 @@ public StepRenderer(XYPlot plot) {
3232

3333
@Override
3434
protected void appendToPath(Path path, PointF thisPoint, PointF lastPoint) {
35-
//path.lineTo(thisPoint.x, thisPoint.y);
36-
3735
path.lineTo(thisPoint.x, lastPoint.y);
3836
path.lineTo(thisPoint.x, thisPoint.y);
39-
//canvas.drawPoint(point.x, lastPoint.y, format.getVertexPaint());
40-
// next the vertical:
41-
//canvas.drawLine(point.x, lastPoint.y, point.x, point.y, format.getLinePaint());
42-
}
43-
}
44-
/*
45-
public class StepRenderer extends XYSeriesRenderer<StepFormatter> {
46-
47-
private PointF lastPoint;
48-
49-
private boolean drawLinesEnabled = true;
50-
private boolean drawPointsEnabled = true;
51-
52-
private XYAxisType stepAxis = XYAxisType.DOMAIN;
53-
54-
55-
56-
public StepRenderer(XYPlot plot) {
57-
super(plot);
58-
}
59-
60-
@Override
61-
public void onRender(Canvas canvas, RectF plotArea) throws PlotRenderException {
62-
63-
64-
65-
for(XYSeries series : getPlot().getSeriesListForRenderer(this.getClass())) {
66-
67-
drawSeries(canvas, plotArea, series, getFormatter(series));
68-
}
69-
//foreach(this.)
70-
//foreach()
71-
}
72-
73-
@Override
74-
public void doDrawLegendIcon(Canvas canvas, RectF rect, String text, StepFormatter getFormatter) {
75-
// horizontal icon:
76-
float centerY = rect.centerY();
77-
float centerX = rect.centerX();
78-
canvas.drawLine(rect.left, rect.top, rect.right, rect.bottom, getFormatter.getLinePaint());
79-
canvas.drawPoint(centerX, centerY, getFormatter.getVertexPaint());
80-
//canvas.drawRect(rect, getFormatter.getLinePaint());
81-
82-
}
83-
84-
85-
private void drawSeries(Canvas canvas, RectF plotArea, XYSeries series, StepFormatter getFormatter) throws PlotRenderException {
86-
beginSeries(canvas, plotArea, getFormatter);
87-
//XYDataset series = bundle.getDataset();
88-
//int seriesIndex = bundle.getSeriesIndex();
89-
PointF thisPoint;
90-
for (int i = 0; i < series.size(); i++) {
91-
Number y = series.getY(i);
92-
Number x = series.getD(i);
93-
94-
if (y != null && x != null) {
95-
96-
thisPoint = ValPixConverter.valToPix(
97-
x,
98-
y,
99-
plotArea,
100-
getPlot().getCalculatedMinX(),
101-
getPlot().getCalculatedMaxX(),
102-
getPlot().getCalculatedMinY(),
103-
getPlot().getCalculatedMaxY());
104-
//float pixX = ValPixConverter.valToPix(x.doubleValue(), getPlot().getCalculatedMinX().doubleValue(), getPlot().getCalculatedMaxX().doubleValue(), plotArea.width(), false) + (plotArea.left);
105-
//float pixY = ValPixConverter.valToPix(y.doubleValue(), getPlot().getCalculatedMinY().doubleValue(), getPlot().getCalculatedMaxY().doubleValue(), plotArea.height(), true) + plotArea.top;
106-
107-
//thisPoint = new PointF(pixX, pixY);
108-
} else {
109-
thisPoint = null;
110-
}
111-
drawPoint(canvas, thisPoint, plotArea, getFormatter);
112-
}
113-
endSeries(canvas, plotArea, getFormatter);
114-
}
115-
116-
private void beginSeries(Canvas canvas, RectF plotArea, StepFormatter format) throws PlotRenderException {
117-
lastPoint = null;
118-
}
119-
120-
private void drawPoint(Canvas canvas, PointF point, RectF plotArea, StepFormatter format) throws PlotRenderException {
121-
if (lastPoint != null) {
122-
if (point != null) {
123-
124-
switch(stepAxis) {
125-
case DOMAIN:
126-
// first draw the horizontal line:
127-
canvas.drawLine(lastPoint.x, lastPoint.y, point.x, lastPoint.y, format.getLinePaint());
128-
canvas.drawPoint(point.x, lastPoint.y, format.getVertexPaint());
129-
// next the vertical:
130-
canvas.drawLine(point.x, lastPoint.y, point.x, point.y, format.getLinePaint());
131-
break;
132-
case RANGE:
133-
break;
134-
}
135-
//doDrawLine(canvas, lastPoint, point, plotArea, format);
136-
137-
138-
}
139-
drawLastPoint(canvas, plotArea, format);
140-
}
141-
142-
lastPoint = point;
143-
}
144-
145-
private void endSeries(Canvas canvas, RectF plotArea, StepFormatter format) throws PlotRenderException {
146-
if(lastPoint != null) {
147-
drawLastPoint(canvas, plotArea, format);
148-
}
149-
}
150-
151-
protected void drawLastPoint(Canvas canvas, RectF plotArea, StepFormatter format) throws PlotRenderException {
152-
canvas.drawPoint(lastPoint.x, lastPoint.y, format.getVertexPaint());
153-
}
154-
155-
156-
public XYAxisType getStepAxis() {
157-
return stepAxis;
158-
}
159-
160-
public void setStepAxis(XYAxisType stepAxis) {
161-
this.stepAxis = stepAxis;
16237
}
16338
}
164-
*/

androidplot-core/src/main/java/com/androidplot/xy/XY.java renamed to androidplot-core/src/main/java/com/androidplot/xy/XYCoords.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
/**
2020
* A pair of x/y coordinates
2121
*/
22-
public class XY {
22+
public class XYCoords {
2323
public Number x;
2424
public Number y;
2525

26-
public XY(Number x, Number y) {
26+
public XYCoords(Number x, Number y) {
2727
this.x = x;
2828
this.y = y;
2929
}

androidplot-core/src/main/java/com/androidplot/xy/XYLegendWidget.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
import java.util.*;
2828

29+
/**
30+
* Displays a legend for each series added to the owning {@link XYPlot}.
31+
*/
2932
public class XYLegendWidget extends Widget {
3033

3134
/**

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ext {
99
theBuildToolsVersion = '21.1.2'
1010
theCompileSdkVersion = 23
1111
theTargetSdkVersion = 23
12-
theMinSdkVersion = 4
12+
theMinSdkVersion = 5
1313
theVersionName = '0.9.9'
1414
theVersionCode = 15
1515
}

0 commit comments

Comments
 (0)