From f86951c035b38e70f7471ea083fe41cea27a75ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AA=86=E5=A4=A7=E5=B3=B0?= Date: Fri, 12 May 2017 10:20:46 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E4=BD=BFLimitLine=E6=88=90=E4=B8=BApublic?= =?UTF-8?q?=20=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/hqyxjy/ldf/chartroidlib/component/LimitLine.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/LimitLine.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/LimitLine.java index e817904..ee4a165 100644 --- a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/LimitLine.java +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/LimitLine.java @@ -4,5 +4,6 @@ * Created by ldf on 17/5/12. */ -class LimitLine { +public class LimitLine { + } From 41b9c9a8bd62b4fe97f03bea5a5ac12e3a34ce00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AA=86=E5=A4=A7=E5=B3=B0?= Date: Fri, 12 May 2017 10:36:45 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0LimitLine=E7=9A=84?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=AE=9E=E7=8E=B0=EF=BC=8C=E4=BB=96=E7=9A=84?= =?UTF-8?q?=E7=BB=98=E5=88=B6=E5=B0=86=E5=9C=A8Axis=E7=9A=84Render?= =?UTF-8?q?=E4=B8=AD=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ldf/chartroidlib/component/LimitLine.java | 202 +++++++++++++++++- 1 file changed, 201 insertions(+), 1 deletion(-) diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/LimitLine.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/LimitLine.java index ee4a165..798fc97 100644 --- a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/LimitLine.java +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/LimitLine.java @@ -1,9 +1,209 @@ package com.hqyxjy.ldf.chartroidlib.component; +import android.graphics.Color; +import android.graphics.DashPathEffect; +import android.graphics.Paint; + +import com.hqyxjy.ldf.chartroidlib.utils.UserInterfaceUtils; + /** * Created by ldf on 17/5/12. */ -public class LimitLine { +public class LimitLine extends Component{ + /** limit / maximum (the y-value or xIndex) */ + private float mLimit = 0f; + + /** the width of the limit line */ + private float mLineWidth = 2f; + + /** the color of the limit line */ + private int mLineColor = Color.rgb(237, 91, 91); + + /** the style of the label text */ + private Paint.Style mTextStyle = Paint.Style.FILL_AND_STROKE; + + /** label string that is drawn next to the limit line */ + private String mLabel = ""; + + /** the path effect of this LimitLine that makes dashed lines possible */ + private DashPathEffect mDashPathEffect = null; + + /** indicates the position of the LimitLine label */ + private LimitLabelPosition mLabelPosition = LimitLabelPosition.RIGHT_TOP; + + /** enum that indicates the position of the LimitLine label */ + public enum LimitLabelPosition { + LEFT_TOP, LEFT_BOTTOM, RIGHT_TOP, RIGHT_BOTTOM + } + + /** + * Constructor with limit. + * + * @param limit - the position (the value) on the y-axis (y-value) or x-axis + * (xIndex) where this line should appear + */ + public LimitLine(float limit) { + mLimit = limit; + } + + /** + * Constructor with limit and label. + * + * @param limit - the position (the value) on the y-axis (y-value) or x-axis + * (xIndex) where this line should appear + * @param label - provide "" if no label is required + */ + public LimitLine(float limit, String label) { + mLimit = limit; + mLabel = label; + } + + /** + * Returns the limit that is set for this line. + * + * @return + */ + public float getLimit() { + return mLimit; + } + + /** + * set the line width of the chart (min = 0.2f, max = 12f); default 2f NOTE: + * thinner line == better performance, thicker line == worse performance + * + * @param width + */ + public void setLineWidth(float width) { + + if (width < 0.2f) + width = 0.2f; + if (width > 12.0f) + width = 12.0f; + mLineWidth = UserInterfaceUtils.dp2px(width); + } + + /** + * returns the width of limit line + * + * @return + */ + public float getLineWidth() { + return mLineWidth; + } + + /** + * Sets the linecolor for this LimitLine. Make sure to use + * getResources().getColor(...) + * + * @param color + */ + public void setLineColor(int color) { + mLineColor = color; + } + + /** + * Returns the color that is used for this LimitLine + * + * @return + */ + public int getLineColor() { + return mLineColor; + } + + /** + * Enables the line to be drawn in dashed mode, e.g. like this "- - - - - -" + * + * @param lineLength the length of the line pieces + * @param spaceLength the length of space inbetween the pieces + * @param phase offset, in degrees (normally, use 0) + */ + public void enableDashedLine(float lineLength, float spaceLength, float phase) { + mDashPathEffect = new DashPathEffect(new float[] { + lineLength, spaceLength + }, phase); + } + + /** + * Disables the line to be drawn in dashed mode. + */ + public void disableDashedLine() { + mDashPathEffect = null; + } + + /** + * Returns true if the dashed-line effect is enabled, false if not. Default: + * disabled + * + * @return + */ + public boolean isDashedLineEnabled() { + return mDashPathEffect == null ? false : true; + } + + /** + * returns the DashPathEffect that is set for this LimitLine + * + * @return + */ + public DashPathEffect getDashPathEffect() { + return mDashPathEffect; + } + + /** + * Sets the color of the value-text that is drawn next to the LimitLine. + * Default: Paint.Style.FILL_AND_STROKE + * + * @param style + */ + public void setTextStyle(Paint.Style style) { + this.mTextStyle = style; + } + + /** + * Returns the color of the value-text that is drawn next to the LimitLine. + * + * @return + */ + public Paint.Style getTextStyle() { + return mTextStyle; + } + + /** + * Sets the position of the LimitLine value label (either on the right or on + * the left edge of the chart). Not supported for RadarChart. + * + * @param pos + */ + public void setLabelPosition(LimitLabelPosition pos) { + mLabelPosition = pos; + } + + /** + * Returns the position of the LimitLine label (value). + * + * @return + */ + public LimitLabelPosition getLabelPosition() { + return mLabelPosition; + } + + /** + * Sets the label that is drawn next to the limit line. Provide "" if no + * label is required. + * + * @param label + */ + public void setLabel(String label) { + mLabel = label; + } + /** + * Returns the label that is drawn next to the limit line. + * + * @return + */ + public String getLabel() { + return mLabel; + } } From 4950b015f3f5fbe9039655e11c66ad1ce0da8f92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AA=86=E5=A4=A7=E5=B3=B0?= Date: Mon, 15 May 2017 19:29:42 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=20=E6=B7=BB=E5=8A=A0transformer=E7=B1=BB?= =?UTF-8?q?=20=E6=AD=A4=E7=B1=BB=E6=97=B6=E8=AE=A1=E7=AE=97=E7=9A=84?= =?UTF-8?q?=E5=85=B3=E9=94=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Chartroid/.idea/checkstyle-idea.xml | 10 + Chartroid/.idea/vcs.xml | 6 + .../hqyxjy/ldf/chartroidlib/base/Chart.java | 26 +- .../chartroidlib/base/ChartTrackHandler.java | 18 +- .../ldf/chartroidlib/component/Point.java | 22 ++ .../chartroidlib/component/Transformer.java | 273 ++++++++++++++++++ 6 files changed, 353 insertions(+), 2 deletions(-) create mode 100644 Chartroid/.idea/checkstyle-idea.xml create mode 100644 Chartroid/.idea/vcs.xml create mode 100644 Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/Point.java create mode 100644 Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/Transformer.java diff --git a/Chartroid/.idea/checkstyle-idea.xml b/Chartroid/.idea/checkstyle-idea.xml new file mode 100644 index 0000000..9d5b48d --- /dev/null +++ b/Chartroid/.idea/checkstyle-idea.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/Chartroid/.idea/vcs.xml b/Chartroid/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Chartroid/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/base/Chart.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/base/Chart.java index b78ab4e..9c8fff1 100644 --- a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/base/Chart.java +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/base/Chart.java @@ -1,8 +1,32 @@ package com.hqyxjy.ldf.chartroidlib.base; +import android.content.Context; +import android.view.ViewGroup; + /** * Created by ldf on 17/5/8. */ -public class Chart { +public class Chart extends ViewGroup{ + /** + * Extra offsets to be appended to the viewport + */ + private float mExtraTopOffset = 0.f, + mExtraRightOffset = 0.f, + mExtraBottomOffset = 0.f, + mExtraLeftOffset = 0.f; + + public Chart(Context context){ + super(context); + init(); + } + + @Override + protected void onLayout(boolean b, int i, int i1, int i2, int i3) { + + } + + private void init() { + + } } diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/base/ChartTrackHandler.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/base/ChartTrackHandler.java index b1d7fca..5eecd7c 100644 --- a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/base/ChartTrackHandler.java +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/base/ChartTrackHandler.java @@ -20,9 +20,13 @@ public class ChartTrackHandler { private float offsetBottom; /** - * transMatrix used for touch events + * transMatrix used for transfrom events */ protected final Matrix transMatrix = new Matrix(); + /** + * touchMatrix used for touch events + */ + protected final Matrix touchMatrix = new Matrix(); private float chartWidth; private float chartHeight; @@ -194,4 +198,16 @@ public Matrix translate(final float[] aimPoint) { return save; } + + public float getChartHeight() { + return 0; + } + + public Matrix getTouchMatrix() { + return touchMatrix; + } + + public Matrix getTransMatrix() { + return transMatrix; + } } diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/Point.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/Point.java new file mode 100644 index 0000000..54e4c96 --- /dev/null +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/Point.java @@ -0,0 +1,22 @@ +package com.hqyxjy.ldf.chartroidlib.component; + +/** + * Created by ldf on 17/5/15. + */ + +public class Point { + public double x; + public double y; + + public Point(double x, double y) { + this.x = x; + this.y = y; + } + + /** + * returns a string representation of the object + */ + public String toString() { + return "PointD, x: " + x + ", y: " + y; + } +} diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/Transformer.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/Transformer.java new file mode 100644 index 0000000..43b01be --- /dev/null +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/Transformer.java @@ -0,0 +1,273 @@ +package com.hqyxjy.ldf.chartroidlib.component; + +/** + * Created by ldf on 17/5/15. + */ + +import android.graphics.Matrix; +import android.graphics.Path; +import android.graphics.RectF; + +import com.hqyxjy.ldf.chartroidlib.base.ChartTrackHandler; + +import java.util.List; + +/** + * Transformer class that contains all matrices and is responsible for + * transforming values into pixels on the screen and backwards. + * + * @author Philipp Jahoda + */ +public class Transformer { + + /** + * matrix to map the values to the screen pixels + */ + protected Matrix mMatrixValueToPx = new Matrix(); + + /** + * matrix for handling the different offsets of the chart + */ + protected Matrix mMatrixOffset = new Matrix(); + + protected ChartTrackHandler chartTrackHandler; + + public Transformer(ChartTrackHandler chartTrackHandler) { + this.chartTrackHandler = chartTrackHandler; + } + + /** + * Prepares the matrix that transforms values to pixels. Calculates the + * scale factors from the charts size and offsets. + * + * @param xChartMin + * @param deltaX + * @param deltaY + * @param yChartMin + */ + public void prepareMatrixValuePx(float xChartMin, float deltaX, float deltaY, float yChartMin) { + + float scaleX = ((chartTrackHandler.contentWidth()) / deltaX); + float scaleY = ((chartTrackHandler.contentHeight()) / deltaY); + if (Float.isInfinite(scaleX)) + { + scaleX = 0; + } + if (Float.isInfinite(scaleY)) + { + scaleY = 0; + } + + // setup all matrices + mMatrixValueToPx.reset(); + mMatrixValueToPx.postTranslate(-xChartMin, -yChartMin); + mMatrixValueToPx.postScale(scaleX, - scaleY); + } + + /** + * Prepares the matrix that contains all offsets. + * + * @param inverted + */ + public void prepareMatrixOffset(boolean inverted) { + + mMatrixOffset.reset(); + + // offset.postTranslate(mOffsetLeft, getHeight() - mOffsetBottom); + + if (!inverted) + mMatrixOffset.postTranslate(chartTrackHandler.offsetLeft(), + chartTrackHandler.getChartHeight() - chartTrackHandler.offsetBottom()); + else { + mMatrixOffset + .setTranslate(chartTrackHandler.offsetLeft(), -chartTrackHandler.offsetTop()); + mMatrixOffset.postScale(1.0f, -1.0f); + } + + // mMatrixOffset.set(offset); + + // mMatrixOffset.reset(); + // + // mMatrixOffset.postTranslate(mOffsetLeft, getHeight() - + // mOffsetBottom); + } + + /** + * transform a path with all the given matrices VERY IMPORTANT: keep order + * to value-touch-offset + * + * @param path + */ + public void pathValueToPixel(Path path) { + + path.transform(mMatrixValueToPx); + path.transform(chartTrackHandler.getTouchMatrix()); + path.transform(mMatrixOffset); + } + + /** + * Transforms multiple paths will all matrices. + * + * @param paths + */ + public void pathValuesToPixel(List paths) { + + for (int i = 0; i < paths.size(); i++) { + pathValueToPixel(paths.get(i)); + } + } + + /** + * Transform an array of points with all matrices. VERY IMPORTANT: Keep + * matrix order "value-touch-offset" when transforming. + * + * @param pts + */ + public void pointValuesToPixel(float[] pts) { + + mMatrixValueToPx.mapPoints(pts); + chartTrackHandler.getTouchMatrix().mapPoints(pts); + mMatrixOffset.mapPoints(pts); + } + + /** + * Transform a rectangle with all matrices. + * + * @param r + */ + public void rectValueToPixel(RectF r) { + + mMatrixValueToPx.mapRect(r); + chartTrackHandler.getTouchMatrix().mapRect(r); + mMatrixOffset.mapRect(r); + } + + /** + * Transform a rectangle with all matrices with potential animation phases. + * + * @param r + * @param phaseY + */ + public void rectValueToPixel(RectF r, float phaseY) { + + // multiply the height of the rect with the phase + r.top *= phaseY; + r.bottom *= phaseY; + + mMatrixValueToPx.mapRect(r); + chartTrackHandler.getTouchMatrix().mapRect(r); + mMatrixOffset.mapRect(r); + } + + /** + * Transform a rectangle with all matrices with potential animation phases. + * + * @param r + */ + public void rectValueToPixelHorizontal(RectF r) { + + mMatrixValueToPx.mapRect(r); + chartTrackHandler.getTouchMatrix().mapRect(r); + mMatrixOffset.mapRect(r); + } + + /** + * Transform a rectangle with all matrices with potential animation phases. + * + * @param r + * @param phaseY + */ + public void rectValueToPixelHorizontal(RectF r, float phaseY) { + + // multiply the height of the rect with the phase + r.left *= phaseY; + r.right *= phaseY; + + mMatrixValueToPx.mapRect(r); + chartTrackHandler.getTouchMatrix().mapRect(r); + mMatrixOffset.mapRect(r); + } + + /** + * transforms multiple rects with all matrices + * + * @param rects + */ + public void rectValuesToPixel(List rects) { + + Matrix m = getValueToPixelMatrix(); + + for (int i = 0; i < rects.size(); i++) + m.mapRect(rects.get(i)); + } + + /** + * Transforms the given array of touch positions (pixels) (x, y, x, y, ...) + * into values on the chart. + * + * @param pixels + */ + public void pixelsToValue(float[] pixels) { + + Matrix tmp = new Matrix(); + + // invert all matrixes to convert back to the original value + mMatrixOffset.invert(tmp); + tmp.mapPoints(pixels); + + chartTrackHandler.getTouchMatrix().invert(tmp); + tmp.mapPoints(pixels); + + mMatrixValueToPx.invert(tmp); + tmp.mapPoints(pixels); + } + + /** + * Returns the x and y values in the chart at the given touch point + * (encapsulated in a PointD). This method transforms pixel coordinates to + * coordinates / values in the chart. This is the opposite method to + * getPixelsForValues(...). + * + * @param x + * @param y + * @return + */ + public Point getValuesByTouchPoint(float x, float y) { + + // create an array of the touch-point + float[] pts = new float[2]; + pts[0] = x; + pts[1] = y; + + pixelsToValue(pts); + + double xTouchVal = pts[0]; + double yTouchVal = pts[1]; + + return new Point(xTouchVal, yTouchVal); + } + + public Matrix getValueMatrix() { + return mMatrixValueToPx; + } + + public Matrix getOffsetMatrix() { + return mMatrixOffset; + } + + private Matrix mMBuffer1 = new Matrix(); + + public Matrix getValueToPixelMatrix() { + mMBuffer1.set(mMatrixValueToPx); + mMBuffer1.postConcat(chartTrackHandler.getTouchMatrix()); + mMBuffer1.postConcat(mMatrixOffset); + return mMBuffer1; + } + + private Matrix mMBuffer2 = new Matrix(); + + public Matrix getPixelToValueMatrix() { + getValueToPixelMatrix().invert(mMBuffer2); + return mMBuffer2; + } +} From 895f641a1b34b06d8d8851de912460cdbf309dab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AA=86=E5=A4=A7=E5=B3=B0?= Date: Wed, 17 May 2017 09:30:27 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=20=E5=AE=8C=E5=96=84Entry=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ldf/chartroidlib/component/Entry.java | 157 ++++++- .../ldf/chartroidlib/component/Point.java | 2 +- .../ldf/chartroidlib/component/YAxis.java | 3 + .../ldf/chartroidlib/data/ChartData.java | 10 + .../ldf/chartroidlib/data/IDataSet.java | 395 ++++++++++++++++++ .../data/dataset/BaseDataSet.java | 380 +++++++++++++++++ .../chartroidlib/data/dataset/DataSet.java | 381 +++++++++++++++++ .../data/dataset/DefaultValueFormatter.java | 14 + .../data/provider/BarDataProvider.java | 9 + .../ldf/chartroidlib/utils/ColorFactory.java | 116 +++++ 10 files changed, 1454 insertions(+), 13 deletions(-) create mode 100644 Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/ChartData.java create mode 100644 Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/IDataSet.java create mode 100644 Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/dataset/BaseDataSet.java create mode 100644 Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/dataset/DataSet.java create mode 100644 Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/dataset/DefaultValueFormatter.java create mode 100644 Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/provider/BarDataProvider.java create mode 100644 Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/utils/ColorFactory.java diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/Entry.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/Entry.java index e0a78f1..8ddeeeb 100644 --- a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/Entry.java +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/Entry.java @@ -1,6 +1,7 @@ package com.hqyxjy.ldf.chartroidlib.component; import android.os.Parcel; +import android.os.ParcelFormatException; import android.os.Parcelable; /** @@ -8,9 +9,135 @@ */ public class Entry implements Parcelable{ - private float xVal; - private float xIndex; - private float data; + private float val; + private int xIndex; + private Object data; + + public Entry() { + } + + /** + * A Entry represents one single entry in the chart. + * + * @param val the y value (the actual value of the entry) + * @param xIndex the corresponding index in the x value array (index on the + * x-axis of the chart, must NOT be higher than the length of the + * x-values String array) + */ + public Entry(float val, int xIndex) { + this.val = val; + this.xIndex = xIndex; + } + + /** + * A Entry represents one single entry in the chart. + * + * @param val the y value (the actual value of the entry) + * @param xIndex the corresponding index in the x value array (index on the + * x-axis of the chart, must NOT be higher than the length of the + * x-values String array) + * @param data Spot for additional data this Entry represents. + */ + public Entry(float val, int xIndex, Object data) { + this(val, xIndex); + this.data = data; + } + /** + * returns the x-index the value of this object is mapped to + * + * @return + */ + public int getXIndex() { + return xIndex; + } + + /** + * sets the x-index for the entry + * + * @param x + */ + public void setXIndex(int x) { + this.xIndex = x; + } + + /** + * Returns the total value the entry represents. + * + * @return + */ + public float getVal() { + return val; + } + + /** + * Sets the value for the entry. + * + * @param val + */ + public void setVal(float val) { + this.val = val; + } + + /** + * Returns the data, additional information that this Entry represents, or + * null, if no data has been specified. + * + * @return + */ + public Object getData() { + return data; + } + + /** + * Sets additional data this Entry should represent. + * + * @param data + */ + public void setData(Object data) { + this.data = data; + } + + /** + * returns an exact copy of the entry + * + * @return + */ + public Entry copy() { + Entry e = new Entry(val, xIndex, data); + return e; + } + + /** + * Compares value, xIndex and data of the entries. Returns true if entries + * are equal in those points, false if not. Does not check by hash-code like + * it's done by the "equals" method. + * + * @param e + * @return + */ + public boolean equalTo(Entry e) { + + if (e == null) + return false; + + if (e.data != this.data) + return false; + if (e.xIndex != this.xIndex) + return false; + + if (Math.abs(e.val - this.val) > 0.00001f) + return false; + + return true; + } + + /** + * returns a string representation of the entry containing x-index and value + */ + @Override + public String toString() { + return "Entry, xIndex: " + xIndex + " val (sum): " + getVal(); + } @Override public int describeContents() { @@ -19,18 +146,24 @@ public int describeContents() { @Override public void writeToParcel(Parcel dest, int flags) { - dest.writeFloat(this.xVal); - dest.writeFloat(this.xIndex); - dest.writeFloat(this.data); - } - - public Entry() { + dest.writeFloat(this.val); + dest.writeInt(this.xIndex); + if (data != null) { + if (data instanceof Parcelable) { + dest.writeInt(1); + dest.writeParcelable((Parcelable) this.data, flags); + } else { + throw new ParcelFormatException("Cannot parcel an Entry with non-parcelable data"); + } + } else { + dest.writeInt(0); + } } protected Entry(Parcel in) { - this.xVal = in.readFloat(); - this.xIndex = in.readFloat(); - this.data = in.readFloat(); + this.val = in.readFloat(); + this.xIndex = in.readInt(); + this.data = in.readParcelable(Object.class.getClassLoader()); } public static final Creator CREATOR = new Creator() { diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/Point.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/Point.java index 54e4c96..59066bb 100644 --- a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/Point.java +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/Point.java @@ -17,6 +17,6 @@ public Point(double x, double y) { * returns a string representation of the object */ public String toString() { - return "PointD, x: " + x + ", y: " + y; + return "Point, x: " + x + ", y: " + y; } } diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/YAxis.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/YAxis.java index dd091ab..caadf5f 100644 --- a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/YAxis.java +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/YAxis.java @@ -5,6 +5,9 @@ */ public class YAxis extends Axis{ + public enum AxisDependency { + LEFT , RIGHT + } @Override public String getLongestLabel() { return null; diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/ChartData.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/ChartData.java new file mode 100644 index 0000000..5ef44e4 --- /dev/null +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/ChartData.java @@ -0,0 +1,10 @@ +package com.hqyxjy.ldf.chartroidlib.data; + +import com.hqyxjy.ldf.chartroidlib.component.Entry; + +/** + * Created by ldf on 17/5/17. + */ + +public abstract class ChartData>{ +} diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/IDataSet.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/IDataSet.java new file mode 100644 index 0000000..5bac9a3 --- /dev/null +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/IDataSet.java @@ -0,0 +1,395 @@ +package com.hqyxjy.ldf.chartroidlib.data; + +import android.graphics.Typeface; + +import com.hqyxjy.ldf.chartroidlib.component.Entry; +import com.hqyxjy.ldf.chartroidlib.component.ValueFormatter; +import com.hqyxjy.ldf.chartroidlib.component.YAxis; +import com.hqyxjy.ldf.chartroidlib.data.dataset.DataSet; + +import java.util.List; + +/** + * Created by ldf on 17/5/17. + */ + +public interface IDataSet { + /** ###### ###### DATA RELATED METHODS ###### ###### */ + + /** + * returns the minimum y-value this DataSet holds + * + * @return + */ + float getYMin(); + + /** + * returns the maximum y-value this DataSet holds + * + * @return + */ + float getYMax(); + + /** + * Returns the number of y-values this DataSet represents -> the size of the y-values array + * -> yvals.size() + * + * @return + */ + int getEntryCount(); + + /** + * Calculates the minimum and maximum y value (mYMin, mYMax). From the specified starting to ending index. + * + * @param start starting index in your data list + * @param end ending index in your data list + */ + void calcMinMax(int start, int end); + + /** + * Returns the first Entry object found at the given xIndex with binary + * search. If the no Entry at the specified x-index is found, this method + * returns the index at the closest x-index. Returns null if no Entry object + * at that index. INFORMATION: This method does calculations at runtime. Do + * not over-use in performance critical situations. + * + * @param xIndex + * @param rounding determine to round up/down/closest if there is no Entry matching the provided x-index + * @return + */ + T getEntryForXIndex(int xIndex, DataSet.Rounding rounding); + + /** + * Returns the first Entry object found at the given xIndex with binary + * search. If the no Entry at the specified x-index is found, this method + * returns the index at the closest x-index. Returns null if no Entry object + * at that index. INFORMATION: This method does calculations at runtime. Do + * not over-use in performance critical situations. + * + * @param xIndex + * @return + */ + T getEntryForXIndex(int xIndex); + + /** + * Returns all Entry objects found at the given xIndex with binary + * search. An empty array if no Entry object at that index. + * INFORMATION: This method does calculations at runtime. Do + * not over-use in performance critical situations. + * + * @param xIndex + * @return + */ + List getEntriesForXIndex(int xIndex); + + /** + * Returns the Entry object found at the given index (NOT xIndex) in the values array. + * + * @param index + * @return + */ + T getEntryForIndex(int index); + + /** + * Returns the first Entry index found at the given xIndex with binary + * search. If the no Entry at the specified x-index is found, this method + * returns the index at the closest x-index. Returns -1 if no Entry object + * at that index. INFORMATION: This method does calculations at runtime. Do + * not over-use in performance critical situations. + * + * @param xIndex + * @param rounding determine to round up/down/closest if there is no Entry matching the provided x-index + * @return + */ + int getEntryIndex(int xIndex, DataSet.Rounding rounding); + + /** + * Returns the position of the provided entry in the DataSets Entry array. + * Returns -1 if doesn't exist. + * + * @param e + * @return + */ + int getEntryIndex(T e); + + /** + * Returns the value of the Entry object at the given xIndex. Returns + * Float.NaN if no value is at the given x-index. INFORMATION: This method + * does calculations at runtime. Do not over-use in performance critical + * situations. + * + * @param xIndex + * @return + */ + float getYValForXIndex(int xIndex); + + /** + * Returns all of the y values of the Entry objects at the given xIndex. Returns + * Float.NaN if no value is at the given x-index. INFORMATION: This method + * does calculations at runtime. Do not over-use in performance critical + * situations. + * + * @param xIndex + * @return + */ + float[] getYValsForXIndex(int xIndex); + + /** + * This method returns the actual + * index in the Entry array of the DataSet for a given xIndex. IMPORTANT: This method does + * calculations at runtime, do not over-use in performance critical + * situations. + * + * @param xIndex + * @return + */ + int getIndexInEntries(int xIndex); + + /** + * Adds an Entry to the DataSet dynamically. + * Entries are added to the end of the list. + * This will also recalculate the current minimum and maximum + * values of the DataSet and the value-sum. + * + * @param e + */ + boolean addEntry(T e); + + /** + * Removes an Entry from the DataSets entries array. This will also + * recalculate the current minimum and maximum values of the DataSet and the + * value-sum. Returns true if an Entry was removed, false if no Entry could + * be removed. + * + * @param e + */ + boolean removeEntry(T e); + + /** + * Adds an Entry to the DataSet dynamically. + * Entries are added to their appropriate index respective to it's x-index. + * This will also recalculate the current minimum and maximum + * values of the DataSet and the value-sum. + * + * @param e + */ + void addEntryOrdered(T e); + + /** + * Removes the first Entry (at index 0) of this DataSet from the entries array. + * Returns true if successful, false if not. + * + * @return + */ + boolean removeFirst(); + + /** + * Removes the last Entry (at index size-1) of this DataSet from the entries array. + * Returns true if successful, false if not. + * + * @return + */ + boolean removeLast(); + + /** + * Removes the Entry object that has the given xIndex from the DataSet. + * Returns true if an Entry was removed, false if no Entry could be removed. + * + * @param xIndex + */ + boolean removeEntry(int xIndex); + + /** + * Checks if this DataSet contains the specified Entry. Returns true if so, + * false if not. NOTE: Performance is pretty bad on this one, do not + * over-use in performance critical situations. + * + * @param entry + * @return + */ + boolean contains(T entry); + + /** + * Removes all values from this DataSet and does all necessary recalculations. + */ + void clear(); + + + /** ###### ###### STYLING RELATED (& OTHER) METHODS ###### ###### */ + + /** + * Returns the label string that describes the DataSet. + * + * @return + */ + String getLabel(); + + /** + * Sets the label string that describes the DataSet. + * + * @param label + */ + void setLabel(String label); + + /** + * Returns the axis this DataSet should be plotted against. + * + * @return + */ + YAxis.AxisDependency getAxisDependency(); + + /** + * Set the y-axis this DataSet should be plotted against (either LEFT or + * RIGHT). Default: LEFT + * + * @param dependency + */ + void setAxisDependency(YAxis.AxisDependency dependency); + + /** + * returns all the colors that are set for this DataSet + * + * @return + */ + List getColors(); + + /** + * Returns the first color (index 0) of the colors-array this DataSet + * contains. This is only used for performance reasons when only one color is in the colors array (size == 1) + * + * @return + */ + int getColor(); + + /** + * Returns the color at the given index of the DataSet's color array. + * Performs a IndexOutOfBounds check by modulus. + * + * @param index + * @return + */ + int getColor(int index); + + /** + * returns true if highlighting of values is enabled, false if not + * + * @return + */ + boolean isHighlightEnabled(); + + /** + * If set to true, value highlighting is enabled which means that values can + * be highlighted programmatically or by touch gesture. + * + * @param enabled + */ + void setHighlightEnabled(boolean enabled); + + /** + * Sets the formatter to be used for drawing the values inside the chart. If + * no formatter is set, the chart will automatically determine a reasonable + * formatting (concerning decimals) for all the values that are drawn inside + * the chart. Use chart.getDefaultValueFormatter() to use the formatter + * calculated by the chart. + * + * @param f + */ + void setValueFormatter(ValueFormatter f); + + /** + * Returns the formatter used for drawing the values inside the chart. + * + * @return + */ + ValueFormatter getValueFormatter(); + + /** + * Sets the color the value-labels of this DataSet should have. + * + * @param color + */ + void setValueTextColor(int color); + + /** + * Sets a list of colors to be used as the colors for the drawn values. + * + * @param colors + */ + void setValueTextColors(List colors); + + /** + * Sets a Typeface for the value-labels of this DataSet. + * + * @param tf + */ + void setValueTypeface(Typeface tf); + + /** + * Sets the text-size of the value-labels of this DataSet in dp. + * + * @param size + */ + void setValueTextSize(float size); + + /** + * Returns only the first color of all colors that are set to be used for the values. + * + * @return + */ + int getValueTextColor(); + + /** + * Returns the color at the specified index that is used for drawing the values inside the chart. + * Uses modulus internally. + * + * @param index + * @return + */ + int getValueTextColor(int index); + + /** + * Returns the typeface that is used for drawing the values inside the chart + * + * @return + */ + Typeface getValueTypeface(); + + /** + * Returns the text size that is used for drawing the values inside the chart + * + * @return + */ + float getValueTextSize(); + + /** + * set this to true to draw y-values on the chart NOTE (for bar and + * linechart): if "maxvisiblecount" is reached, no values will be drawn even + * if this is enabled + * + * @param enabled + */ + void setDrawValues(boolean enabled); + + /** + * Returns true if y-value drawing is enabled, false if not + * + * @return + */ + boolean isDrawValuesEnabled(); + + /** + * Set the visibility of this DataSet. If not visible, the DataSet will not + * be drawn to the chart upon refreshing it. + * + * @param visible + */ + void setVisible(boolean visible); + + /** + * Returns true if this DataSet is visible inside the chart, or false if it + * is currently hidden. + * + * @return + */ + boolean isVisible(); +} diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/dataset/BaseDataSet.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/dataset/BaseDataSet.java new file mode 100644 index 0000000..f36102c --- /dev/null +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/dataset/BaseDataSet.java @@ -0,0 +1,380 @@ +package com.hqyxjy.ldf.chartroidlib.data.dataset; + +import android.content.Context; +import android.graphics.Color; +import android.graphics.Typeface; + +import com.hqyxjy.ldf.chartroidlib.component.Entry; +import com.hqyxjy.ldf.chartroidlib.component.ValueFormatter; +import com.hqyxjy.ldf.chartroidlib.component.YAxis; +import com.hqyxjy.ldf.chartroidlib.data.IDataSet; +import com.hqyxjy.ldf.chartroidlib.utils.ColorFactory; +import com.hqyxjy.ldf.chartroidlib.utils.UserInterfaceUtils; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by ldf on 17/5/17. + */ + +public abstract class BaseDataSet implements IDataSet { + /** + * List representing all colors that are used for this DataSet + */ + protected List mColors = null; + + /** + * List representing all colors that are used for drawing the actual values for this DataSet + */ + protected List mValueColors = null; + + /** + * label that describes the DataSet or the data the DataSet represents + */ + private String mLabel = "DataSet"; + + /** + * this specifies which axis this DataSet should be plotted against + */ + protected YAxis.AxisDependency mAxisDependency = YAxis.AxisDependency.LEFT; + + /** + * if true, value highlightning is enabled + */ + protected boolean mHighlightEnabled = true; + + /** + * custom formatter that is used instead of the auto-formatter if set + */ + protected transient ValueFormatter mValueFormatter; + + /** + * the typeface used for the value text + */ + protected Typeface mValueTypeface; + + /** + * if true, y-values are drawn on the chart + */ + protected boolean mDrawValues = true; + + /** + * the size of the value-text labels + */ + protected float mValueTextSize = 17f; + + /** + * flag that indicates if the DataSet is visible or not + */ + protected boolean mVisible = true; + + /** + * Default constructor. + */ + public BaseDataSet() { + mColors = new ArrayList(); + mValueColors = new ArrayList(); + + // default color + mColors.add(Color.rgb(140, 234, 255)); + mValueColors.add(Color.BLACK); + } + + /** + * Constructor with label. + * + * @param label + */ + public BaseDataSet(String label) { + this(); + this.mLabel = label; + } + + /** + * Use this method to tell the data set that the underlying data has changed. + */ + public void notifyDataSetChanged() { + calcMinMax(0, getEntryCount() - 1); + } + + + /** + * ###### ###### COLOR GETTING RELATED METHODS ##### ###### + */ + + @Override + public List getColors() { + return mColors; + } + + public List getValueColors() { return mValueColors; } + + @Override + public int getColor() { + return mColors.get(0); + } + + @Override + public int getColor(int index) { + return mColors.get(index % mColors.size()); + } + + /** + * ###### ###### COLOR SETTING RELATED METHODS ##### ###### + */ + + /** + * Sets the colors that should be used fore this DataSet. Colors are reused + * as soon as the number of Entries the DataSet represents is higher than + * the size of the colors array. If you are using colors from the resources, + * make sure that the colors are already prepared (by calling + * getResources().getColor(...)) before adding them to the DataSet. + * + * @param colors + */ + public void setColors(List colors) { + this.mColors = colors; + } + + /** + * Sets the colors that should be used fore this DataSet. Colors are reused + * as soon as the number of Entries the DataSet represents is higher than + * the size of the colors array. If you are using colors from the resources, + * make sure that the colors are already prepared (by calling + * getResources().getColor(...)) before adding them to the DataSet. + * + * @param colors + */ + public void setColors(int[] colors) { + this.mColors = ColorFactory.createColors(colors); + } + + /** + * Sets the colors that should be used fore this DataSet. Colors are reused + * as soon as the number of Entries the DataSet represents is higher than + * the size of the colors array. You can use + * "new int[] { R.color.red, R.color.green, ... }" to provide colors for + * this method. Internally, the colors are resolved using + * getResources().getColor(...) + * + * @param colors + */ + public void setColors(int[] colors, Context c) { + + List clrs = new ArrayList(); + + for (int color : colors) { + clrs.add(c.getResources().getColor(color)); + } + + mColors = clrs; + } + + /** + * Adds a new color to the colors array of the DataSet. + * + * @param color + */ + public void addColor(int color) { + if (mColors == null) + mColors = new ArrayList(); + mColors.add(color); + } + + /** + * Sets the one and ONLY color that should be used for this DataSet. + * Internally, this recreates the colors array and adds the specified color. + * + * @param color + */ + public void setColor(int color) { + resetColors(); + mColors.add(color); + } + + /** + * Sets a color with a specific alpha value. + * + * @param color + * @param alpha from 0-255 + */ + public void setColor(int color, int alpha) { + setColor(Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color))); + } + + /** + * Sets colors with a specific alpha value. + * + * @param colors + * @param alpha + */ + public void setColors(int[] colors, int alpha) { + resetColors(); + for (int color : colors) { + addColor(Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color))); + } + } + + /** + * Resets all colors of this DataSet and recreates the colors array. + */ + public void resetColors() { + mColors = new ArrayList(); + } + + /** ###### ###### OTHER STYLING RELATED METHODS ##### ###### */ + + @Override + public void setLabel(String label) { + mLabel = label; + } + + @Override + public String getLabel() { + return mLabel; + } + + @Override + public void setHighlightEnabled(boolean enabled) { + mHighlightEnabled = enabled; + } + + @Override + public boolean isHighlightEnabled() { + return mHighlightEnabled; + } + + @Override + public void setValueFormatter(ValueFormatter f) { + + if (f == null) + return; + else + mValueFormatter = f; + } + + @Override + public ValueFormatter getValueFormatter() { + if (mValueFormatter == null) + return new DefaultValueFormatter(1); + return mValueFormatter; + } + + @Override + public void setValueTextColor(int color) { + mValueColors.clear(); + mValueColors.add(color); + } + + @Override + public void setValueTextColors(List colors) { + mValueColors = colors; + } + + @Override + public void setValueTypeface(Typeface tf) { + mValueTypeface = tf; + } + + @Override + public void setValueTextSize(float size) { + mValueTextSize = UserInterfaceUtils.dp2px(size); + } + + @Override + public int getValueTextColor() { + return mValueColors.get(0); + } + + @Override + public int getValueTextColor(int index) { + return mValueColors.get(index % mValueColors.size()); + } + + @Override + public Typeface getValueTypeface() { + return mValueTypeface; + } + + @Override + public float getValueTextSize() { + return mValueTextSize; + } + + @Override + public void setDrawValues(boolean enabled) { + this.mDrawValues = enabled; + } + + @Override + public boolean isDrawValuesEnabled() { + return mDrawValues; + } + + @Override + public void setVisible(boolean visible) { + mVisible = visible; + } + + @Override + public boolean isVisible() { + return mVisible; + } + + @Override + public YAxis.AxisDependency getAxisDependency() { + return mAxisDependency; + } + + @Override + public void setAxisDependency(YAxis.AxisDependency dependency) { + mAxisDependency = dependency; + } + + + /** ###### ###### DATA RELATED METHODS ###### ###### */ + + @Override + public int getIndexInEntries(int xIndex) { + + for (int i = 0; i < getEntryCount(); i++) { + if (xIndex == getEntryForIndex(i).getXIndex()) + return i; + } + + return -1; + } + + @Override + public boolean removeFirst() { + + T entry = getEntryForIndex(0); + return removeEntry(entry); + } + + @Override + public boolean removeLast() { + + T entry = getEntryForIndex(getEntryCount() - 1); + return removeEntry(entry); + } + + @Override + public boolean removeEntry(int xIndex) { + + T e = getEntryForXIndex(xIndex); + return removeEntry(e); + } + + @Override + public boolean contains(T e) { + + for(int i = 0; i < getEntryCount(); i++) { + if(getEntryForIndex(i).equals(e)) + return true; + } + + return false; + } +} diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/dataset/DataSet.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/dataset/DataSet.java new file mode 100644 index 0000000..4374dc5 --- /dev/null +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/dataset/DataSet.java @@ -0,0 +1,381 @@ +package com.hqyxjy.ldf.chartroidlib.data.dataset; + +import com.hqyxjy.ldf.chartroidlib.component.Entry; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by ldf on 17/5/17. + */ + +public abstract class DataSet extends BaseDataSet { + /** + * the entries that this dataset represents / holds together + */ + protected List mYVals = null; + + /** + * maximum y-value in the y-value array + */ + protected float mYMax = 0.0f; + + /** + * the minimum y-value in the y-value array + */ + protected float mYMin = 0.0f; + + + /** + * Creates a new DataSet object with the given values it represents. Also, a + * label that describes the DataSet can be specified. The label can also be + * used to retrieve the DataSet from a ChartData object. + * + * @param yVals + * @param label + */ + public DataSet(List yVals, String label) { + super(label); + this.mYVals = yVals; + + if (mYVals == null) + mYVals = new ArrayList(); + + calcMinMax(0, mYVals.size()); + } + + @Override + public void calcMinMax(int start, int end) { + + if (mYVals == null) + return; + + final int yValCount = mYVals.size(); + + if (yValCount == 0) + return; + + int endValue; + + if (end == 0 || end >= yValCount) + endValue = yValCount - 1; + else + endValue = end; + + mYMin = Float.MAX_VALUE; + mYMax = -Float.MAX_VALUE; + + for (int i = start; i <= endValue; i++) { + + T e = mYVals.get(i); + + if (e != null && !Float.isNaN(e.getVal())) { + + if (e.getVal() < mYMin) + mYMin = e.getVal(); + + if (e.getVal() > mYMax) + mYMax = e.getVal(); + } + } + + if (mYMin == Float.MAX_VALUE) { + mYMin = 0.f; + mYMax = 0.f; + } + } + + @Override + public int getEntryCount() { + return mYVals.size(); + } + + /** + * Returns the array of y-values that this DataSet represents. + * + * @return + */ + public List getYVals() { + return mYVals; + } + + /** + * Sets the array of y-values that this DataSet represents, and calls notifyDataSetChanged() + * + * @return + */ + public void setYVals(List yVals) { + mYVals = yVals; + notifyDataSetChanged(); + } + + /** + * Provides an exact copy of the DataSet this method is used on. + * + * @return + */ + public abstract DataSet copy(); + + @Override + public String toString() { + StringBuffer buffer = new StringBuffer(); + buffer.append(toSimpleString()); + for (int i = 0; i < mYVals.size(); i++) { + buffer.append(mYVals.get(i).toString() + " "); + } + return buffer.toString(); + } + + /** + * Returns a simple string representation of the DataSet with the type and + * the number of Entries. + * + * @return + */ + public String toSimpleString() { + StringBuffer buffer = new StringBuffer(); + buffer.append("DataSet, label: " + (getLabel() == null ? "" : getLabel()) + ", entries: " + mYVals.size() + "\n"); + return buffer.toString(); + } + + @Override + public float getYMin() { + return mYMin; + } + + @Override + public float getYMax() { + return mYMax; + } + + @Override + public void addEntryOrdered(T e) { + + if (e == null) + return; + + float val = e.getVal(); + + if (mYVals == null) { + mYVals = new ArrayList(); + } + + if (mYVals.size() == 0) { + mYMax = val; + mYMin = val; + } else { + if (mYMax < val) + mYMax = val; + if (mYMin > val) + mYMin = val; + } + + if (mYVals.size() > 0 && mYVals.get(mYVals.size() - 1).getXIndex() > e.getXIndex()) { + int closestIndex = getEntryIndex(e.getXIndex(), Rounding.UP); + mYVals.add(closestIndex, e); + return; + } + + mYVals.add(e); + } + + @Override + public void clear() { + mYVals.clear(); + notifyDataSetChanged(); + } + + @Override + public boolean addEntry(T e) { + + if (e == null) + return false; + + float val = e.getVal(); + + List yVals = getYVals(); + if (yVals == null) { + yVals = new ArrayList(); + } + + if (yVals.size() == 0) { + mYMax = val; + mYMin = val; + } else { + if (mYMax < val) + mYMax = val; + if (mYMin > val) + mYMin = val; + } + + // add the entry + yVals.add(e); + return true; + } + + @Override + public boolean removeEntry(T e) { + + if (e == null) + return false; + + if (mYVals == null) + return false; + + // remove the entry + boolean removed = mYVals.remove(e); + + if (removed) { + calcMinMax(0, mYVals.size()); + } + + return removed; + } + + @Override + public int getEntryIndex(Entry e) { + return mYVals.indexOf(e); + } + + @Override + public T getEntryForXIndex(int xIndex, Rounding rounding) { + + int index = getEntryIndex(xIndex, rounding); + if (index > -1) + return mYVals.get(index); + return null; + } + + @Override + public T getEntryForXIndex(int xIndex) { + return getEntryForXIndex(xIndex, Rounding.CLOSEST); + } + + @Override + public T getEntryForIndex(int index) { + return mYVals.get(index); + } + + @Override + public int getEntryIndex(int xIndex, Rounding rounding) { + + int low = 0; + int high = mYVals.size() - 1; + int closest = -1; + + while (low <= high) { + int m = (high + low) / 2; + + if (xIndex == mYVals.get(m).getXIndex()) { + while (m > 0 && mYVals.get(m - 1).getXIndex() == xIndex) + m--; + + return m; + } + + if (xIndex > mYVals.get(m).getXIndex()) + low = m + 1; + else + high = m - 1; + + closest = m; + } + + if (closest != -1) { + int closestXIndex = mYVals.get(closest).getXIndex(); + if (rounding == Rounding.UP) { + if (closestXIndex < xIndex && closest < mYVals.size() - 1) { + ++closest; + } + } else if (rounding == Rounding.DOWN) { + if (closestXIndex > xIndex && closest > 0) { + --closest; + } + } + } + + return closest; + } + + @Override + public float getYValForXIndex(int xIndex) { + + Entry e = getEntryForXIndex(xIndex); + + if (e != null && e.getXIndex() == xIndex) + return e.getVal(); + else + return Float.NaN; + } + + @Override + public float[] getYValsForXIndex(int xIndex) { + + List entries = getEntriesForXIndex(xIndex); + + float[] yVals = new float[entries.size()]; + int i = 0; + + for (T e : entries) + yVals[i++] = e.getVal(); + + return yVals; + } + + /** + * Returns all Entry objects at the given xIndex. INFORMATION: This method + * does calculations at runtime. Do not over-use in performance critical + * situations. + * + * @param xIndex + * @return + */ + @Override + public List getEntriesForXIndex(int xIndex) { + + List entries = new ArrayList(); + + int low = 0; + int high = mYVals.size() - 1; + + while (low <= high) { + int m = (high + low) / 2; + T entry = mYVals.get(m); + + if (xIndex == entry.getXIndex()) { + while (m > 0 && mYVals.get(m - 1).getXIndex() == xIndex) + m--; + + high = mYVals.size(); + for (; m < high; m++) { + entry = mYVals.get(m); + if (entry.getXIndex() == xIndex) { + entries.add(entry); + } else { + break; + } + } + + break; + } else { + if (xIndex > entry.getXIndex()) + low = m + 1; + else + high = m - 1; + } + } + + return entries; + } + + /** + * Determines how to round DataSet index values for + * {@link DataSet#getEntryIndex(int, Rounding)} DataSet.getEntryIndex()} + * when an exact x-index is not found. + */ + public enum Rounding { + UP, + DOWN, + CLOSEST, + } +} diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/dataset/DefaultValueFormatter.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/dataset/DefaultValueFormatter.java new file mode 100644 index 0000000..96a8f9d --- /dev/null +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/dataset/DefaultValueFormatter.java @@ -0,0 +1,14 @@ +package com.hqyxjy.ldf.chartroidlib.data.dataset; + +import com.hqyxjy.ldf.chartroidlib.component.ValueFormatter; + +/** + * Created by ldf on 17/5/17. + */ + +class DefaultValueFormatter extends ValueFormatter { + public DefaultValueFormatter(int i) { + super( + ); + } +} diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/provider/BarDataProvider.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/provider/BarDataProvider.java new file mode 100644 index 0000000..7a2ff01 --- /dev/null +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/provider/BarDataProvider.java @@ -0,0 +1,9 @@ +package com.hqyxjy.ldf.chartroidlib.data.provider; + +/** + * Created by ldf on 17/5/17. + */ + +public class BarDataProvider { + +} diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/utils/ColorFactory.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/utils/ColorFactory.java new file mode 100644 index 0000000..b937072 --- /dev/null +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/utils/ColorFactory.java @@ -0,0 +1,116 @@ +package com.hqyxjy.ldf.chartroidlib.utils; + +import android.content.res.Resources; +import android.graphics.Color; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by ldf on 17/5/17. + */ + +public class ColorFactory { + /** + * an "invalid" color that indicates that no color is set + */ + public static final int COLOR_NONE = 0x00112233; + + /** + * this "color" is used for the Legend creation and indicates that the next + * form should be skipped + */ + public static final int COLOR_SKIP = 0x00112234; + + /** + * THE COLOR THEMES ARE PREDEFINED (predefined color integer arrays), FEEL + * FREE TO CREATE YOUR OWN WITH AS MANY DIFFERENT COLORS AS YOU WANT + */ + public static final int[] LIBERTY_COLORS = { + Color.rgb(207, 248, 246), Color.rgb(148, 212, 212), Color.rgb(136, 180, 187), + Color.rgb(118, 174, 175), Color.rgb(42, 109, 130) + }; + public static final int[] JOYFUL_COLORS = { + Color.rgb(217, 80, 138), Color.rgb(254, 149, 7), Color.rgb(254, 247, 120), + Color.rgb(106, 167, 134), Color.rgb(53, 194, 209) + }; + public static final int[] PASTEL_COLORS = { + Color.rgb(64, 89, 128), Color.rgb(149, 165, 124), Color.rgb(217, 184, 162), + Color.rgb(191, 134, 134), Color.rgb(179, 48, 80) + }; + public static final int[] COLORFUL_COLORS = { + Color.rgb(193, 37, 82), Color.rgb(255, 102, 0), Color.rgb(245, 199, 0), + Color.rgb(106, 150, 31), Color.rgb(179, 100, 53) + }; + public static final int[] VORDIPLOM_COLORS = { + Color.rgb(192, 255, 140), Color.rgb(255, 247, 140), Color.rgb(255, 208, 140), + Color.rgb(140, 234, 255), Color.rgb(255, 140, 157) + }; + public static final int[] MATERIAL_COLORS = { + rgb("#2ecc71"), rgb("#f1c40f"), rgb("#e74c3c"), rgb("#3498db") + }; + + /** + * Converts the given hex-color-string to rgb. + * + * @param hex + * @return + */ + public static int rgb(String hex) { + int color = (int) Long.parseLong(hex.replace("#", ""), 16); + int r = (color >> 16) & 0xFF; + int g = (color >> 8) & 0xFF; + int b = (color >> 0) & 0xFF; + return Color.rgb(r, g, b); + } + + /** + * Returns the Android ICS holo blue light color. + * + * @return + */ + public static int getHoloBlue() { + return Color.rgb(51, 181, 229); + } + + public static int getColorWithAlphaComponent(int color, int alpha) { + return (color & 0xffffff) | ((alpha & 0xff) << 24); + } + + /** + * turn an array of resource-colors (contains resource-id integers) into an + * array list of actual color integers + * + * @param r + * @param colors an integer array of resource id's of colors + * @return + */ + public static List createColors(Resources r, int[] colors) { + + List result = new ArrayList(); + + for (int i : colors) { + result.add(r.getColor(i)); + } + + return result; + } + + /** + * Turns an array of colors (integer color values) into an ArrayList of + * colors. + * + * @param colors + * @return + */ + public static List createColors(int[] colors) { + + List result = new ArrayList(); + + for (int i : colors) { + result.add(i); + } + + return result; + } +} From ac349b8775c3d04497e9423cff7fb4ae4a823862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AA=86=E5=A4=A7=E5=B3=B0?= Date: Thu, 1 Jun 2017 17:48:33 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9Entry=E7=9A=84XIndex?= =?UTF-8?q?=E4=B8=BAXVal=20=E4=B8=94=E5=9F=BA=E6=9C=AC=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E7=94=B1int=E6=94=B9=E4=B8=BAfloat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Chartroid/.idea/misc.xml | 2 +- .../hqyxjy/ldf/chartroidlib/base/Chart.java | 19 +++- .../ldf/chartroidlib/component/ChartData.java | 8 -- .../ldf/chartroidlib/component/Entry.java | 94 +++++++++---------- .../ldf/chartroidlib/component/XAxis.java | 4 + .../ldf/chartroidlib/data/ChartData.java | 1 + .../ldf/chartroidlib/data/IDataSet.java | 8 +- .../data/dataset/BaseDataSet.java | 2 +- .../chartroidlib/data/dataset/DataSet.java | 49 +++++----- .../ldf/chartroidlib/intf/ChartInterface.java | 2 +- .../listener/OnChartGestureListener.java | 1 + 11 files changed, 98 insertions(+), 92 deletions(-) delete mode 100644 Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/ChartData.java diff --git a/Chartroid/.idea/misc.xml b/Chartroid/.idea/misc.xml index 32c7e5b..2ea8a49 100644 --- a/Chartroid/.idea/misc.xml +++ b/Chartroid/.idea/misc.xml @@ -120,7 +120,7 @@ - + diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/base/Chart.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/base/Chart.java index 9c8fff1..8b73a15 100644 --- a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/base/Chart.java +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/base/Chart.java @@ -7,14 +7,23 @@ * Created by ldf on 17/5/8. */ -public class Chart extends ViewGroup{ +import com.hqyxjy.ldf.chartroidlib.component.Entry; +import com.hqyxjy.ldf.chartroidlib.data.ChartData; +import com.hqyxjy.ldf.chartroidlib.data.IDataSet; + +public abstract class Chart>> extends ViewGroup{ /** * Extra offsets to be appended to the viewport */ - private float mExtraTopOffset = 0.f, - mExtraRightOffset = 0.f, - mExtraBottomOffset = 0.f, - mExtraLeftOffset = 0.f; + private float extraTopOffset = 0.f, + extraRightOffset = 0.f, + extraBottomOffset = 0.f, + extraLeftOffset = 0.f; + + private float mMinTopOffset = 0.f, + minRightOffset = 0.f, + minBottomOffset = 0.f, + minLeftOffset = 0.f; public Chart(Context context){ super(context); diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/ChartData.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/ChartData.java deleted file mode 100644 index 73bcba6..0000000 --- a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/ChartData.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.hqyxjy.ldf.chartroidlib.component; - -/** - * Created by ldf on 17/5/12. - */ - -public class ChartData { -} diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/Entry.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/Entry.java index 8ddeeeb..4335429 100644 --- a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/Entry.java +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/Entry.java @@ -9,9 +9,9 @@ */ public class Entry implements Parcelable{ - private float val; - private int xIndex; - private Object data; + private float yVal; + private float xVal; + private Object attachment;// 附件 public Entry() { } @@ -19,36 +19,34 @@ public Entry() { /** * A Entry represents one single entry in the chart. * - * @param val the y value (the actual value of the entry) - * @param xIndex the corresponding index in the x value array (index on the - * x-axis of the chart, must NOT be higher than the length of the - * x-values String array) + * @param yVal the y value (the actual value of the entry) + * @param xVal 对应X轴值的链表中的index,所以此数值不能超过X轴链表的长度 */ - public Entry(float val, int xIndex) { - this.val = val; - this.xIndex = xIndex; + public Entry(float yVal, float xVal) { + this.yVal = yVal; + this.xVal = xVal; } /** * A Entry represents one single entry in the chart. * - * @param val the y value (the actual value of the entry) - * @param xIndex the corresponding index in the x value array (index on the + * @param yVal the y value (the actual value of the entry) + * @param xVal the corresponding index in the x value array (index on the * x-axis of the chart, must NOT be higher than the length of the * x-values String array) - * @param data Spot for additional data this Entry represents. + * @param data Spot for additional attachment this Entry represents. */ - public Entry(float val, int xIndex, Object data) { - this(val, xIndex); - this.data = data; + public Entry(float yVal, float xVal, Object data) { + this(yVal, xVal); + this.attachment = data; } /** * returns the x-index the value of this object is mapped to * * @return */ - public int getXIndex() { - return xIndex; + public float getXVal() { + return xVal; } /** @@ -56,8 +54,8 @@ public int getXIndex() { * * @param x */ - public void setXIndex(int x) { - this.xIndex = x; + public void setXVal(int x) { + this.xVal = x; } /** @@ -65,36 +63,36 @@ public void setXIndex(int x) { * * @return */ - public float getVal() { - return val; + public float getYVal() { + return yVal; } /** * Sets the value for the entry. * - * @param val + * @param yVal */ - public void setVal(float val) { - this.val = val; + public void setYVal(float yVal) { + this.yVal = yVal; } /** - * Returns the data, additional information that this Entry represents, or - * null, if no data has been specified. + * Returns the attachment, additional information that this Entry represents, or + * null, if no attachment has been specified. * * @return */ - public Object getData() { - return data; + public Object getAttachment() { + return attachment; } /** - * Sets additional data this Entry should represent. + * Sets additional attachment this Entry should represent. * - * @param data + * @param attachment */ - public void setData(Object data) { - this.data = data; + public void setAttachment(Object attachment) { + this.attachment = attachment; } /** @@ -103,12 +101,12 @@ public void setData(Object data) { * @return */ public Entry copy() { - Entry e = new Entry(val, xIndex, data); + Entry e = new Entry(yVal, xVal, attachment); return e; } /** - * Compares value, xIndex and data of the entries. Returns true if entries + * Compares value, xVal and attachment of the entries. Returns true if entries * are equal in those points, false if not. Does not check by hash-code like * it's done by the "equals" method. * @@ -120,12 +118,12 @@ public boolean equalTo(Entry e) { if (e == null) return false; - if (e.data != this.data) + if (e.attachment != this.attachment) return false; - if (e.xIndex != this.xIndex) + if (e.xVal != this.xVal) return false; - if (Math.abs(e.val - this.val) > 0.00001f) + if (Math.abs(e.yVal - this.yVal) > 0.00001f) return false; return true; @@ -136,7 +134,7 @@ public boolean equalTo(Entry e) { */ @Override public String toString() { - return "Entry, xIndex: " + xIndex + " val (sum): " + getVal(); + return "Entry, xVal: " + xVal + " yVal (sum): " + getYVal(); } @Override @@ -146,14 +144,14 @@ public int describeContents() { @Override public void writeToParcel(Parcel dest, int flags) { - dest.writeFloat(this.val); - dest.writeInt(this.xIndex); - if (data != null) { - if (data instanceof Parcelable) { + dest.writeFloat(this.yVal); + dest.writeFloat(this.xVal); + if (attachment != null) { + if (attachment instanceof Parcelable) { dest.writeInt(1); - dest.writeParcelable((Parcelable) this.data, flags); + dest.writeParcelable((Parcelable) this.attachment, flags); } else { - throw new ParcelFormatException("Cannot parcel an Entry with non-parcelable data"); + throw new ParcelFormatException("Cannot parcel an Entry with non-parcelable attachment"); } } else { dest.writeInt(0); @@ -161,9 +159,9 @@ public void writeToParcel(Parcel dest, int flags) { } protected Entry(Parcel in) { - this.val = in.readFloat(); - this.xIndex = in.readInt(); - this.data = in.readParcelable(Object.class.getClassLoader()); + this.yVal = in.readFloat(); + this.xVal = in.readInt(); + this.attachment = in.readParcelable(Object.class.getClassLoader()); } public static final Creator CREATOR = new Creator() { diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/XAxis.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/XAxis.java index 61f6433..e217ca0 100644 --- a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/XAxis.java +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/XAxis.java @@ -5,4 +5,8 @@ */ public class XAxis extends Axis{ + @Override + public String getLongestLabel() { + return null; + } } diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/ChartData.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/ChartData.java index 5ef44e4..acf6285 100644 --- a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/ChartData.java +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/ChartData.java @@ -7,4 +7,5 @@ */ public abstract class ChartData>{ + } diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/IDataSet.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/IDataSet.java index 5bac9a3..fcf487b 100644 --- a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/IDataSet.java +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/IDataSet.java @@ -60,16 +60,16 @@ public interface IDataSet { T getEntryForXIndex(int xIndex, DataSet.Rounding rounding); /** - * Returns the first Entry object found at the given xIndex with binary + * Returns the first Entry object found at the given position with binary * search. If the no Entry at the specified x-index is found, this method * returns the index at the closest x-index. Returns null if no Entry object * at that index. INFORMATION: This method does calculations at runtime. Do * not over-use in performance critical situations. * - * @param xIndex + * @param position * @return */ - T getEntryForXIndex(int xIndex); + T getEntryForXIndex(int position); /** * Returns all Entry objects found at the given xIndex with binary @@ -101,7 +101,7 @@ public interface IDataSet { * @param rounding determine to round up/down/closest if there is no Entry matching the provided x-index * @return */ - int getEntryIndex(int xIndex, DataSet.Rounding rounding); + int getEntryIndex(float xIndex, DataSet.Rounding rounding); /** * Returns the position of the provided entry in the DataSets Entry array. diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/dataset/BaseDataSet.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/dataset/BaseDataSet.java index f36102c..e648668 100644 --- a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/dataset/BaseDataSet.java +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/dataset/BaseDataSet.java @@ -339,7 +339,7 @@ public void setAxisDependency(YAxis.AxisDependency dependency) { public int getIndexInEntries(int xIndex) { for (int i = 0; i < getEntryCount(); i++) { - if (xIndex == getEntryForIndex(i).getXIndex()) + if (xIndex == getEntryForIndex(i).getXVal()) return i; } diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/dataset/DataSet.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/dataset/DataSet.java index 4374dc5..1395465 100644 --- a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/dataset/DataSet.java +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/dataset/DataSet.java @@ -69,13 +69,13 @@ public void calcMinMax(int start, int end) { T e = mYVals.get(i); - if (e != null && !Float.isNaN(e.getVal())) { + if (e != null && !Float.isNaN(e.getYVal())) { - if (e.getVal() < mYMin) - mYMin = e.getVal(); + if (e.getYVal() < mYMin) + mYMin = e.getYVal(); - if (e.getVal() > mYMax) - mYMax = e.getVal(); + if (e.getYVal() > mYMax) + mYMax = e.getYVal(); } } @@ -154,7 +154,7 @@ public void addEntryOrdered(T e) { if (e == null) return; - float val = e.getVal(); + float val = e.getYVal(); if (mYVals == null) { mYVals = new ArrayList(); @@ -170,8 +170,8 @@ public void addEntryOrdered(T e) { mYMin = val; } - if (mYVals.size() > 0 && mYVals.get(mYVals.size() - 1).getXIndex() > e.getXIndex()) { - int closestIndex = getEntryIndex(e.getXIndex(), Rounding.UP); + if (mYVals.size() > 0 && mYVals.get(mYVals.size() - 1).getXVal() > e.getXVal()) { + int closestIndex = getEntryIndex(e.getXVal(), Rounding.UP); mYVals.add(closestIndex, e); return; } @@ -191,7 +191,7 @@ public boolean addEntry(T e) { if (e == null) return false; - float val = e.getVal(); + float val = e.getYVal(); List yVals = getYVals(); if (yVals == null) { @@ -247,8 +247,8 @@ public T getEntryForXIndex(int xIndex, Rounding rounding) { } @Override - public T getEntryForXIndex(int xIndex) { - return getEntryForXIndex(xIndex, Rounding.CLOSEST); + public T getEntryForXIndex(int position) { + return getEntryForXIndex(position, Rounding.CLOSEST); } @Override @@ -257,7 +257,7 @@ public T getEntryForIndex(int index) { } @Override - public int getEntryIndex(int xIndex, Rounding rounding) { + public int getEntryIndex(float xIndex, Rounding rounding) { int low = 0; int high = mYVals.size() - 1; @@ -266,14 +266,14 @@ public int getEntryIndex(int xIndex, Rounding rounding) { while (low <= high) { int m = (high + low) / 2; - if (xIndex == mYVals.get(m).getXIndex()) { - while (m > 0 && mYVals.get(m - 1).getXIndex() == xIndex) + if (xIndex == mYVals.get(m).getXVal()) { + while (m > 0 && mYVals.get(m - 1).getXVal() == xIndex) m--; return m; } - if (xIndex > mYVals.get(m).getXIndex()) + if (xIndex > mYVals.get(m).getXVal()) low = m + 1; else high = m - 1; @@ -282,7 +282,7 @@ public int getEntryIndex(int xIndex, Rounding rounding) { } if (closest != -1) { - int closestXIndex = mYVals.get(closest).getXIndex(); + float closestXIndex = mYVals.get(closest).getXVal(); if (rounding == Rounding.UP) { if (closestXIndex < xIndex && closest < mYVals.size() - 1) { ++closest; @@ -302,8 +302,8 @@ public float getYValForXIndex(int xIndex) { Entry e = getEntryForXIndex(xIndex); - if (e != null && e.getXIndex() == xIndex) - return e.getVal(); + if (e != null && e.getXVal() == xIndex) + return e.getYVal(); else return Float.NaN; } @@ -317,7 +317,7 @@ public float[] getYValsForXIndex(int xIndex) { int i = 0; for (T e : entries) - yVals[i++] = e.getVal(); + yVals[i++] = e.getYVal(); return yVals; } @@ -342,14 +342,14 @@ public List getEntriesForXIndex(int xIndex) { int m = (high + low) / 2; T entry = mYVals.get(m); - if (xIndex == entry.getXIndex()) { - while (m > 0 && mYVals.get(m - 1).getXIndex() == xIndex) + if (xIndex == entry.getXVal()) { + while (m > 0 && mYVals.get(m - 1).getXVal() == xIndex) m--; high = mYVals.size(); for (; m < high; m++) { entry = mYVals.get(m); - if (entry.getXIndex() == xIndex) { + if (entry.getXVal() == xIndex) { entries.add(entry); } else { break; @@ -358,7 +358,7 @@ public List getEntriesForXIndex(int xIndex) { break; } else { - if (xIndex > entry.getXIndex()) + if (xIndex > entry.getXVal()) low = m + 1; else high = m - 1; @@ -370,9 +370,10 @@ public List getEntriesForXIndex(int xIndex) { /** * Determines how to round DataSet index values for - * {@link DataSet#getEntryIndex(int, Rounding)} DataSet.getEntryIndex()} + * {@link DataSet#getEntryIndex(float, Rounding)} DataSet.getEntryIndex()} * when an exact x-index is not found. */ + public enum Rounding { UP, DOWN, diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/intf/ChartInterface.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/intf/ChartInterface.java index 88818ff..4b04cc5 100644 --- a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/intf/ChartInterface.java +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/intf/ChartInterface.java @@ -3,8 +3,8 @@ import android.graphics.PointF; import android.graphics.RectF; -import com.hqyxjy.ldf.chartroidlib.component.ChartData; import com.hqyxjy.ldf.chartroidlib.component.ValueFormatter; +import com.hqyxjy.ldf.chartroidlib.data.ChartData; /** * Created by ldf on 17/5/12. diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/listener/OnChartGestureListener.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/listener/OnChartGestureListener.java index 7623824..38532bf 100644 --- a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/listener/OnChartGestureListener.java +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/listener/OnChartGestureListener.java @@ -17,6 +17,7 @@ public interface OnChartGestureListener { /** * Callbacks when a touch-gesture has ended on the Chart (ACTION_UP, ACTION_CANCEL) + * So onChartGestureEnd will call with onChartGestureStart in pair * * @param me * @param lastPerformedGesture From ccdcaf4c9f652d886488458c4585ccdd664a7b34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AA=86=E5=A4=A7=E5=B3=B0?= Date: Mon, 5 Jun 2017 10:01:12 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0BarData=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加了极坐标类型和周坐标类型 定义了dataset的基本方法 --- Chartroid/.idea/misc.xml | 2 +- .../hqyxjy/ldf/chartroidlib/base/Chart.java | 2 +- .../chartroidlib/data/AxisCoordinateData.java | 12 ++ .../hqyxjy/ldf/chartroidlib/data/BarData.java | 12 ++ .../ldf/chartroidlib/data/ChartData.java | 54 +++++ .../data/PolarCoordinateData.java | 12 ++ .../data/dataset/BaseDataSet.java | 4 +- .../chartroidlib/data/dataset/DataSet.java | 189 +++++++++--------- .../ldf/chartroidlib/data/iset/BarEntry.java | 10 + .../chartroidlib/data/iset/IBarDataSet.java | 11 + .../data/{ => iset}/IDataSet.java | 60 ++---- 11 files changed, 226 insertions(+), 142 deletions(-) create mode 100644 Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/AxisCoordinateData.java create mode 100644 Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/BarData.java create mode 100644 Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/PolarCoordinateData.java create mode 100644 Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/iset/BarEntry.java create mode 100644 Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/iset/IBarDataSet.java rename Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/{ => iset}/IDataSet.java (88%) diff --git a/Chartroid/.idea/misc.xml b/Chartroid/.idea/misc.xml index 2ea8a49..32c7e5b 100644 --- a/Chartroid/.idea/misc.xml +++ b/Chartroid/.idea/misc.xml @@ -120,7 +120,7 @@ - + diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/base/Chart.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/base/Chart.java index 8b73a15..44e1183 100644 --- a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/base/Chart.java +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/base/Chart.java @@ -9,7 +9,7 @@ import com.hqyxjy.ldf.chartroidlib.component.Entry; import com.hqyxjy.ldf.chartroidlib.data.ChartData; -import com.hqyxjy.ldf.chartroidlib.data.IDataSet; +import com.hqyxjy.ldf.chartroidlib.data.iset.IDataSet; public abstract class Chart>> extends ViewGroup{ /** diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/AxisCoordinateData.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/AxisCoordinateData.java new file mode 100644 index 0000000..8c1bd7d --- /dev/null +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/AxisCoordinateData.java @@ -0,0 +1,12 @@ +package com.hqyxjy.ldf.chartroidlib.data; + +import com.hqyxjy.ldf.chartroidlib.component.Entry; +import com.hqyxjy.ldf.chartroidlib.data.iset.IDataSet; + +/** + * Created by ldf on 17/6/1. + */ + +public abstract class AxisCoordinateData> extends ChartData{ + +} diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/BarData.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/BarData.java new file mode 100644 index 0000000..2d6b8eb --- /dev/null +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/BarData.java @@ -0,0 +1,12 @@ +package com.hqyxjy.ldf.chartroidlib.data; + +import com.hqyxjy.ldf.chartroidlib.component.Entry; +import com.hqyxjy.ldf.chartroidlib.data.iset.IBarDataSet; + +/** + * Created by ldf on 17/6/5. + */ + +public class BarData extends AxisCoordinateData { + +} diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/ChartData.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/ChartData.java index acf6285..61849b7 100644 --- a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/ChartData.java +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/ChartData.java @@ -1,11 +1,65 @@ package com.hqyxjy.ldf.chartroidlib.data; import com.hqyxjy.ldf.chartroidlib.component.Entry; +import com.hqyxjy.ldf.chartroidlib.data.iset.IDataSet; + +import java.util.ArrayList; +import java.util.List; /** * Created by ldf on 17/5/17. */ public abstract class ChartData>{ + /** + * array that holds all DataSets the ChartData object represents + */ + protected List mDataSets; + + /** + * Default constructor. + */ + public ChartData() { + mDataSets = new ArrayList(); + } + + /** + * Constructor taking single or multiple DataSet objects. + * + * @param dataSets + */ + public ChartData(T... dataSets) { + mDataSets = arrayToList(dataSets); + notifyDataChanged(); + } + + /** + * Created because Arrays.asList(...) does not support modification. + * + * @param array + * @return + */ + private List arrayToList(T[] array) { + + List list = new ArrayList<>(); + + for (T set : array) { + list.add(set); + } + + return list; + } + + /** + * Call this method to let the ChartData know that the underlying data has + * changed. Calling this performs all necessary recalculations needed when + * the contained data has changed. + */ + public void notifyDataChanged() { + calcMinMax(); + } + + private void calcMinMax() { + } } diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/PolarCoordinateData.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/PolarCoordinateData.java new file mode 100644 index 0000000..c8d3476 --- /dev/null +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/PolarCoordinateData.java @@ -0,0 +1,12 @@ +package com.hqyxjy.ldf.chartroidlib.data; + +import com.hqyxjy.ldf.chartroidlib.component.Entry; +import com.hqyxjy.ldf.chartroidlib.data.iset.IDataSet; + +/** + * Created by ldf on 17/6/5. + */ + +public class PolarCoordinateData > extends ChartData{ + +} diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/dataset/BaseDataSet.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/dataset/BaseDataSet.java index e648668..babe5d2 100644 --- a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/dataset/BaseDataSet.java +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/dataset/BaseDataSet.java @@ -7,7 +7,7 @@ import com.hqyxjy.ldf.chartroidlib.component.Entry; import com.hqyxjy.ldf.chartroidlib.component.ValueFormatter; import com.hqyxjy.ldf.chartroidlib.component.YAxis; -import com.hqyxjy.ldf.chartroidlib.data.IDataSet; +import com.hqyxjy.ldf.chartroidlib.data.iset.IDataSet; import com.hqyxjy.ldf.chartroidlib.utils.ColorFactory; import com.hqyxjy.ldf.chartroidlib.utils.UserInterfaceUtils; @@ -95,7 +95,7 @@ public BaseDataSet(String label) { * Use this method to tell the data set that the underlying data has changed. */ public void notifyDataSetChanged() { - calcMinMax(0, getEntryCount() - 1); + calcMinMax(); } diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/dataset/DataSet.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/dataset/DataSet.java index 1395465..1a95315 100644 --- a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/dataset/DataSet.java +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/dataset/DataSet.java @@ -10,21 +10,31 @@ */ public abstract class DataSet extends BaseDataSet { + /** * the entries that this dataset represents / holds together */ - protected List mYVals = null; + protected List vals = null; /** * maximum y-value in the y-value array */ - protected float mYMax = 0.0f; + protected float yMax = 0.0f; /** * the minimum y-value in the y-value array */ - protected float mYMin = 0.0f; + protected float yMin = 0.0f; + /** + * maximum y-value in the y-value array + */ + protected float xMax = 0.0f; + + /** + * the minimum y-value in the y-value array + */ + protected float xMin = 0.0f; /** * Creates a new DataSet object with the given values it represents. Also, a @@ -36,58 +46,76 @@ public abstract class DataSet extends BaseDataSet { */ public DataSet(List yVals, String label) { super(label); - this.mYVals = yVals; + this.vals = yVals; - if (mYVals == null) - mYVals = new ArrayList(); + if (vals == null) + vals = new ArrayList(); - calcMinMax(0, mYVals.size()); + calcYMinMax(0, vals.size()); } @Override - public void calcMinMax(int start, int end) { - - if (mYVals == null) + public void calcMinMax() { + if (vals == null || vals.isEmpty()) return; - final int yValCount = mYVals.size(); + yMax = -Float.MAX_VALUE; + yMin = Float.MAX_VALUE; + xMax = -Float.MAX_VALUE; + xMin = Float.MAX_VALUE; - if (yValCount == 0) + for (T e : vals) { + calcMinMax(e); + } + } + + protected void calcMinMax(T e) { + if (e == null) return; - int endValue; + calcMinMaxX(e); - if (end == 0 || end >= yValCount) - endValue = yValCount - 1; - else - endValue = end; + calcMinMaxY(e); + } - mYMin = Float.MAX_VALUE; - mYMax = -Float.MAX_VALUE; + private void calcMinMaxY(T e) { + if (e.getXVal() < xMin) + xMin = e.getXVal(); - for (int i = start; i <= endValue; i++) { + if (e.getXVal() > xMax) + xMax = e.getXVal(); + } - T e = mYVals.get(i); + private void calcMinMaxX(T e) { + if (e.getYVal() < yMin) + yMin = e.getYVal(); - if (e != null && !Float.isNaN(e.getYVal())) { + if (e.getYVal() > yMax) + yMax = e.getYVal(); + } - if (e.getYVal() < mYMin) - mYMin = e.getYVal(); + @Override + public void calcYMinMax(int start, int end) { - if (e.getYVal() > mYMax) - mYMax = e.getYVal(); - } - } + if (vals == null || vals.isEmpty()) + return; - if (mYMin == Float.MAX_VALUE) { - mYMin = 0.f; - mYMax = 0.f; + yMax = -Float.MAX_VALUE; + yMin = Float.MAX_VALUE; + + int indexFrom = getEntryIndex(start, Rounding.DOWN); + int indexTo = getEntryIndex(end, Rounding.UP); + + for (int i = indexFrom; i <= indexTo; i++) { + + // only recalculate y + calcMinMaxY(vals.get(i)); } } @Override public int getEntryCount() { - return mYVals.size(); + return vals.size(); } /** @@ -96,7 +124,7 @@ public int getEntryCount() { * @return */ public List getYVals() { - return mYVals; + return vals; } /** @@ -105,7 +133,7 @@ public List getYVals() { * @return */ public void setYVals(List yVals) { - mYVals = yVals; + vals = yVals; notifyDataSetChanged(); } @@ -120,8 +148,8 @@ public void setYVals(List yVals) { public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append(toSimpleString()); - for (int i = 0; i < mYVals.size(); i++) { - buffer.append(mYVals.get(i).toString() + " "); + for (int i = 0; i < vals.size(); i++) { + buffer.append(vals.get(i).toString() + " "); } return buffer.toString(); } @@ -134,54 +162,23 @@ public String toString() { */ public String toSimpleString() { StringBuffer buffer = new StringBuffer(); - buffer.append("DataSet, label: " + (getLabel() == null ? "" : getLabel()) + ", entries: " + mYVals.size() + "\n"); + buffer.append("DataSet, label: " + (getLabel() == null ? "" : getLabel()) + ", entries: " + vals.size() + "\n"); return buffer.toString(); } @Override - public float getYMin() { - return mYMin; - } - - @Override - public float getYMax() { - return mYMax; + public float getYMinVal() { + return yMin; } @Override - public void addEntryOrdered(T e) { - - if (e == null) - return; - - float val = e.getYVal(); - - if (mYVals == null) { - mYVals = new ArrayList(); - } - - if (mYVals.size() == 0) { - mYMax = val; - mYMin = val; - } else { - if (mYMax < val) - mYMax = val; - if (mYMin > val) - mYMin = val; - } - - if (mYVals.size() > 0 && mYVals.get(mYVals.size() - 1).getXVal() > e.getXVal()) { - int closestIndex = getEntryIndex(e.getXVal(), Rounding.UP); - mYVals.add(closestIndex, e); - return; - } - - mYVals.add(e); + public float getYMaxVal() { + return yMax; } @Override public void clear() { - mYVals.clear(); + vals.clear(); notifyDataSetChanged(); } @@ -199,13 +196,13 @@ public boolean addEntry(T e) { } if (yVals.size() == 0) { - mYMax = val; - mYMin = val; + yMax = val; + yMin = val; } else { - if (mYMax < val) - mYMax = val; - if (mYMin > val) - mYMin = val; + if (yMax < val) + yMax = val; + if (yMin > val) + yMin = val; } // add the entry @@ -219,14 +216,14 @@ public boolean removeEntry(T e) { if (e == null) return false; - if (mYVals == null) + if (vals == null) return false; // remove the entry - boolean removed = mYVals.remove(e); + boolean removed = vals.remove(e); if (removed) { - calcMinMax(0, mYVals.size()); + calcYMinMax(0, vals.size()); } return removed; @@ -234,7 +231,7 @@ public boolean removeEntry(T e) { @Override public int getEntryIndex(Entry e) { - return mYVals.indexOf(e); + return vals.indexOf(e); } @Override @@ -242,7 +239,7 @@ public T getEntryForXIndex(int xIndex, Rounding rounding) { int index = getEntryIndex(xIndex, rounding); if (index > -1) - return mYVals.get(index); + return vals.get(index); return null; } @@ -253,27 +250,27 @@ public T getEntryForXIndex(int position) { @Override public T getEntryForIndex(int index) { - return mYVals.get(index); + return vals.get(index); } @Override public int getEntryIndex(float xIndex, Rounding rounding) { int low = 0; - int high = mYVals.size() - 1; + int high = vals.size() - 1; int closest = -1; while (low <= high) { int m = (high + low) / 2; - if (xIndex == mYVals.get(m).getXVal()) { - while (m > 0 && mYVals.get(m - 1).getXVal() == xIndex) + if (xIndex == vals.get(m).getXVal()) { + while (m > 0 && vals.get(m - 1).getXVal() == xIndex) m--; return m; } - if (xIndex > mYVals.get(m).getXVal()) + if (xIndex > vals.get(m).getXVal()) low = m + 1; else high = m - 1; @@ -282,9 +279,9 @@ public int getEntryIndex(float xIndex, Rounding rounding) { } if (closest != -1) { - float closestXIndex = mYVals.get(closest).getXVal(); + float closestXIndex = vals.get(closest).getXVal(); if (rounding == Rounding.UP) { - if (closestXIndex < xIndex && closest < mYVals.size() - 1) { + if (closestXIndex < xIndex && closest < vals.size() - 1) { ++closest; } } else if (rounding == Rounding.DOWN) { @@ -336,19 +333,19 @@ public List getEntriesForXIndex(int xIndex) { List entries = new ArrayList(); int low = 0; - int high = mYVals.size() - 1; + int high = vals.size() - 1; while (low <= high) { int m = (high + low) / 2; - T entry = mYVals.get(m); + T entry = vals.get(m); if (xIndex == entry.getXVal()) { - while (m > 0 && mYVals.get(m - 1).getXVal() == xIndex) + while (m > 0 && vals.get(m - 1).getXVal() == xIndex) m--; - high = mYVals.size(); + high = vals.size(); for (; m < high; m++) { - entry = mYVals.get(m); + entry = vals.get(m); if (entry.getXVal() == xIndex) { entries.add(entry); } else { diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/iset/BarEntry.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/iset/BarEntry.java new file mode 100644 index 0000000..6c2e8a7 --- /dev/null +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/iset/BarEntry.java @@ -0,0 +1,10 @@ +package com.hqyxjy.ldf.chartroidlib.data.iset; + +import com.hqyxjy.ldf.chartroidlib.component.Entry; + +/** + * Created by ldf on 17/6/5. + */ + +class BarEntry extends Entry{ +} diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/iset/IBarDataSet.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/iset/IBarDataSet.java new file mode 100644 index 0000000..18e7b70 --- /dev/null +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/iset/IBarDataSet.java @@ -0,0 +1,11 @@ +package com.hqyxjy.ldf.chartroidlib.data.iset; + +import com.hqyxjy.ldf.chartroidlib.component.Entry; + +/** + * Created by ldf on 17/6/5. + */ + +public interface IBarDataSet extends IDataSet{ + +} diff --git a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/IDataSet.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/iset/IDataSet.java similarity index 88% rename from Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/IDataSet.java rename to Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/iset/IDataSet.java index fcf487b..640db40 100644 --- a/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/IDataSet.java +++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/iset/IDataSet.java @@ -1,4 +1,4 @@ -package com.hqyxjy.ldf.chartroidlib.data; +package com.hqyxjy.ldf.chartroidlib.data.iset; import android.graphics.Typeface; @@ -16,35 +16,19 @@ public interface IDataSet { /** ###### ###### DATA RELATED METHODS ###### ###### */ - /** - * returns the minimum y-value this DataSet holds - * - * @return - */ - float getYMin(); + float getXMinVal(); - /** - * returns the maximum y-value this DataSet holds - * - * @return - */ - float getYMax(); + float getXMaxVal(); + + float getYMinVal(); + + float getYMaxVal(); - /** - * Returns the number of y-values this DataSet represents -> the size of the y-values array - * -> yvals.size() - * - * @return - */ int getEntryCount(); - /** - * Calculates the minimum and maximum y value (mYMin, mYMax). From the specified starting to ending index. - * - * @param start starting index in your data list - * @param end ending index in your data list - */ - void calcMinMax(int start, int end); + void calcMinMax(); + + void calcYMinMax(int start, int end); /** * Returns the first Entry object found at the given xIndex with binary @@ -61,13 +45,8 @@ public interface IDataSet { /** * Returns the first Entry object found at the given position with binary - * search. If the no Entry at the specified x-index is found, this method - * returns the index at the closest x-index. Returns null if no Entry object - * at that index. INFORMATION: This method does calculations at runtime. Do - * not over-use in performance critical situations. - * + * search. it will takeout entry from array specfic position * @param position - * @return */ T getEntryForXIndex(int position); @@ -165,16 +144,6 @@ public interface IDataSet { */ boolean removeEntry(T e); - /** - * Adds an Entry to the DataSet dynamically. - * Entries are added to their appropriate index respective to it's x-index. - * This will also recalculate the current minimum and maximum - * values of the DataSet and the value-sum. - * - * @param e - */ - void addEntryOrdered(T e); - /** * Removes the first Entry (at index 0) of this DataSet from the entries array. * Returns true if successful, false if not. @@ -285,6 +254,13 @@ public interface IDataSet { */ void setHighlightEnabled(boolean enabled); + /** + * Returns the color that is used for drawing the highlight indicators. + * + * @return + */ + int getHighLightColor(); + /** * Sets the formatter to be used for drawing the values inside the chart. If * no formatter is set, the chart will automatically determine a reasonable