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..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
@@ -1,8 +1,41 @@
package com.hqyxjy.ldf.chartroidlib.base;
+import android.content.Context;
+import android.view.ViewGroup;
+
/**
* Created by ldf on 17/5/8.
*/
-public class Chart {
+import com.hqyxjy.ldf.chartroidlib.component.Entry;
+import com.hqyxjy.ldf.chartroidlib.data.ChartData;
+import com.hqyxjy.ldf.chartroidlib.data.iset.IDataSet;
+
+public abstract class Chart>> extends ViewGroup{
+ /**
+ * Extra offsets to be appended to the viewport
+ */
+ 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);
+ 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/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 e0a78f1..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
@@ -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,133 @@
*/
public class Entry implements Parcelable{
+ private float yVal;
private float xVal;
- private float xIndex;
- private float data;
+ private Object attachment;// 附件
+
+ public Entry() {
+ }
+
+ /**
+ * A Entry represents one single entry in the chart.
+ *
+ * @param yVal the y value (the actual value of the entry)
+ * @param xVal 对应X轴值的链表中的index,所以此数值不能超过X轴链表的长度
+ */
+ public Entry(float yVal, float xVal) {
+ this.yVal = yVal;
+ this.xVal = xVal;
+ }
+
+ /**
+ * A Entry represents one single entry in the chart.
+ *
+ * @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 attachment this Entry represents.
+ */
+ 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 float getXVal() {
+ return xVal;
+ }
+
+ /**
+ * sets the x-index for the entry
+ *
+ * @param x
+ */
+ public void setXVal(int x) {
+ this.xVal = x;
+ }
+
+ /**
+ * Returns the total value the entry represents.
+ *
+ * @return
+ */
+ public float getYVal() {
+ return yVal;
+ }
+
+ /**
+ * Sets the value for the entry.
+ *
+ * @param yVal
+ */
+ public void setYVal(float yVal) {
+ this.yVal = yVal;
+ }
+
+ /**
+ * Returns the attachment, additional information that this Entry represents, or
+ * null, if no attachment has been specified.
+ *
+ * @return
+ */
+ public Object getAttachment() {
+ return attachment;
+ }
+
+ /**
+ * Sets additional attachment this Entry should represent.
+ *
+ * @param attachment
+ */
+ public void setAttachment(Object attachment) {
+ this.attachment = attachment;
+ }
+
+ /**
+ * returns an exact copy of the entry
+ *
+ * @return
+ */
+ public Entry copy() {
+ Entry e = new Entry(yVal, xVal, attachment);
+ return e;
+ }
+
+ /**
+ * 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.
+ *
+ * @param e
+ * @return
+ */
+ public boolean equalTo(Entry e) {
+
+ if (e == null)
+ return false;
+
+ if (e.attachment != this.attachment)
+ return false;
+ if (e.xVal != this.xVal)
+ return false;
+
+ if (Math.abs(e.yVal - this.yVal) > 0.00001f)
+ return false;
+
+ return true;
+ }
+
+ /**
+ * returns a string representation of the entry containing x-index and value
+ */
+ @Override
+ public String toString() {
+ return "Entry, xVal: " + xVal + " yVal (sum): " + getYVal();
+ }
@Override
public int describeContents() {
@@ -19,18 +144,24 @@ public int describeContents() {
@Override
public void writeToParcel(Parcel dest, int flags) {
+ dest.writeFloat(this.yVal);
dest.writeFloat(this.xVal);
- dest.writeFloat(this.xIndex);
- dest.writeFloat(this.data);
- }
-
- public Entry() {
+ if (attachment != null) {
+ if (attachment instanceof Parcelable) {
+ dest.writeInt(1);
+ dest.writeParcelable((Parcelable) this.attachment, flags);
+ } else {
+ throw new ParcelFormatException("Cannot parcel an Entry with non-parcelable attachment");
+ }
+ } else {
+ dest.writeInt(0);
+ }
}
protected Entry(Parcel in) {
- this.xVal = in.readFloat();
- this.xIndex = in.readFloat();
- this.data = in.readFloat();
+ 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/LimitLine.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/component/LimitLine.java
index e817904..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,8 +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.
*/
-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;
+ }
}
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..59066bb
--- /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 "Point, 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;
+ }
+}
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/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/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
new file mode 100644
index 0000000..61849b7
--- /dev/null
+++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/ChartData.java
@@ -0,0 +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
new file mode 100644
index 0000000..babe5d2
--- /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.iset.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();
+ }
+
+
+ /**
+ * ###### ###### 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).getXVal())
+ 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..1a95315
--- /dev/null
+++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/dataset/DataSet.java
@@ -0,0 +1,379 @@
+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 vals = null;
+
+ /**
+ * maximum y-value in the y-value array
+ */
+ protected float yMax = 0.0f;
+
+ /**
+ * the minimum y-value in the y-value array
+ */
+ 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
+ * 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.vals = yVals;
+
+ if (vals == null)
+ vals = new ArrayList();
+
+ calcYMinMax(0, vals.size());
+ }
+
+ @Override
+ public void calcMinMax() {
+ if (vals == null || vals.isEmpty())
+ return;
+
+ yMax = -Float.MAX_VALUE;
+ yMin = Float.MAX_VALUE;
+ xMax = -Float.MAX_VALUE;
+ xMin = Float.MAX_VALUE;
+
+ for (T e : vals) {
+ calcMinMax(e);
+ }
+ }
+
+ protected void calcMinMax(T e) {
+ if (e == null)
+ return;
+
+ calcMinMaxX(e);
+
+ calcMinMaxY(e);
+ }
+
+ private void calcMinMaxY(T e) {
+ if (e.getXVal() < xMin)
+ xMin = e.getXVal();
+
+ if (e.getXVal() > xMax)
+ xMax = e.getXVal();
+ }
+
+ private void calcMinMaxX(T e) {
+ if (e.getYVal() < yMin)
+ yMin = e.getYVal();
+
+ if (e.getYVal() > yMax)
+ yMax = e.getYVal();
+ }
+
+ @Override
+ public void calcYMinMax(int start, int end) {
+
+ if (vals == null || vals.isEmpty())
+ return;
+
+ 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 vals.size();
+ }
+
+ /**
+ * Returns the array of y-values that this DataSet represents.
+ *
+ * @return
+ */
+ public List getYVals() {
+ return vals;
+ }
+
+ /**
+ * Sets the array of y-values that this DataSet represents, and calls notifyDataSetChanged()
+ *
+ * @return
+ */
+ public void setYVals(List yVals) {
+ vals = 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 < vals.size(); i++) {
+ buffer.append(vals.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: " + vals.size() + "\n");
+ return buffer.toString();
+ }
+
+ @Override
+ public float getYMinVal() {
+ return yMin;
+ }
+
+ @Override
+ public float getYMaxVal() {
+ return yMax;
+ }
+
+ @Override
+ public void clear() {
+ vals.clear();
+ notifyDataSetChanged();
+ }
+
+ @Override
+ public boolean addEntry(T e) {
+
+ if (e == null)
+ return false;
+
+ float val = e.getYVal();
+
+ List yVals = getYVals();
+ if (yVals == null) {
+ yVals = new ArrayList();
+ }
+
+ if (yVals.size() == 0) {
+ yMax = val;
+ yMin = val;
+ } else {
+ if (yMax < val)
+ yMax = val;
+ if (yMin > val)
+ yMin = val;
+ }
+
+ // add the entry
+ yVals.add(e);
+ return true;
+ }
+
+ @Override
+ public boolean removeEntry(T e) {
+
+ if (e == null)
+ return false;
+
+ if (vals == null)
+ return false;
+
+ // remove the entry
+ boolean removed = vals.remove(e);
+
+ if (removed) {
+ calcYMinMax(0, vals.size());
+ }
+
+ return removed;
+ }
+
+ @Override
+ public int getEntryIndex(Entry e) {
+ return vals.indexOf(e);
+ }
+
+ @Override
+ public T getEntryForXIndex(int xIndex, Rounding rounding) {
+
+ int index = getEntryIndex(xIndex, rounding);
+ if (index > -1)
+ return vals.get(index);
+ return null;
+ }
+
+ @Override
+ public T getEntryForXIndex(int position) {
+ return getEntryForXIndex(position, Rounding.CLOSEST);
+ }
+
+ @Override
+ public T getEntryForIndex(int index) {
+ return vals.get(index);
+ }
+
+ @Override
+ public int getEntryIndex(float xIndex, Rounding rounding) {
+
+ int low = 0;
+ int high = vals.size() - 1;
+ int closest = -1;
+
+ while (low <= high) {
+ int m = (high + low) / 2;
+
+ if (xIndex == vals.get(m).getXVal()) {
+ while (m > 0 && vals.get(m - 1).getXVal() == xIndex)
+ m--;
+
+ return m;
+ }
+
+ if (xIndex > vals.get(m).getXVal())
+ low = m + 1;
+ else
+ high = m - 1;
+
+ closest = m;
+ }
+
+ if (closest != -1) {
+ float closestXIndex = vals.get(closest).getXVal();
+ if (rounding == Rounding.UP) {
+ if (closestXIndex < xIndex && closest < vals.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.getXVal() == xIndex)
+ return e.getYVal();
+ 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.getYVal();
+
+ 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 = vals.size() - 1;
+
+ while (low <= high) {
+ int m = (high + low) / 2;
+ T entry = vals.get(m);
+
+ if (xIndex == entry.getXVal()) {
+ while (m > 0 && vals.get(m - 1).getXVal() == xIndex)
+ m--;
+
+ high = vals.size();
+ for (; m < high; m++) {
+ entry = vals.get(m);
+ if (entry.getXVal() == xIndex) {
+ entries.add(entry);
+ } else {
+ break;
+ }
+ }
+
+ break;
+ } else {
+ if (xIndex > entry.getXVal())
+ low = m + 1;
+ else
+ high = m - 1;
+ }
+ }
+
+ return entries;
+ }
+
+ /**
+ * Determines how to round DataSet index values for
+ * {@link DataSet#getEntryIndex(float, 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/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/iset/IDataSet.java b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/iset/IDataSet.java
new file mode 100644
index 0000000..640db40
--- /dev/null
+++ b/Chartroid/chartroidlib/src/main/java/com/hqyxjy/ldf/chartroidlib/data/iset/IDataSet.java
@@ -0,0 +1,371 @@
+package com.hqyxjy.ldf.chartroidlib.data.iset;
+
+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 ###### ###### */
+
+ float getXMinVal();
+
+ float getXMaxVal();
+
+ float getYMinVal();
+
+ float getYMaxVal();
+
+ int getEntryCount();
+
+ void calcMinMax();
+
+ void calcYMinMax(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 position with binary
+ * search. it will takeout entry from array specfic position
+ * @param position
+ */
+ T getEntryForXIndex(int position);
+
+ /**
+ * 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(float 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);
+
+ /**
+ * 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);
+
+ /**
+ * 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
+ * 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/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/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
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;
+ }
+}