() {
58 | /**
59 | * Return a new point from the data in the specified parcel.
60 | */
61 | public MPPointF createFromParcel(Parcel in) {
62 | MPPointF r = new MPPointF(0,0);
63 | r.my_readFromParcel(in);
64 | return r;
65 | }
66 |
67 | /**
68 | * Return an array of rectangles of the specified size.
69 | */
70 | public MPPointF[] newArray(int size) {
71 | return new MPPointF[size];
72 | }
73 | };
74 |
75 | /**
76 | * Set the point's coordinates from the data stored in the specified
77 | * parcel. To write a point to a parcel, call writeToParcel().
78 | * Provided to support older Android devices.
79 | *
80 | * @param in The parcel to read the point's coordinates from
81 | */
82 | public void my_readFromParcel(Parcel in) {
83 | x = in.readFloat();
84 | y = in.readFloat();
85 | }
86 |
87 | public float getX(){
88 | return this.x;
89 | }
90 |
91 | public float getY(){
92 | return this.y;
93 | }
94 |
95 | @Override
96 | protected ObjectPool.Poolable instantiate() {
97 | return new MPPointF(0,0);
98 | }
99 | }
--------------------------------------------------------------------------------
/MPChartLib/src/main/java/com/github/mikephil/charting/view/LineChartInViewPager.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.view;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.graphics.PointF;
6 | import android.util.AttributeSet;
7 | import android.view.MotionEvent;
8 |
9 | import com.github.mikephil.charting.charts.LineChart;
10 |
11 | /**
12 | * *************************************************************
13 | *
14 | * .=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-. *
15 | * | ______ | *
16 | * | .-" "-. | *
17 | * | / \ | *
18 | * | _ | | _ | *
19 | * | ( \ |, .-. .-. ,| / ) | *
20 | * | > "=._ | )(__/ \__)( | _.=" < | *
21 | * | (_/"=._"=._ |/ /\ \| _.="_.="\_) | *
22 | * | "=._"(_ ^^ _)"_.=" | *
23 | * | "=\__|IIIIII|__/=" | *
24 | * | _.="| \IIIIII/ |"=._ | *
25 | * | _ _.="_.="\ /"=._"=._ _ | *
26 | * | ( \_.="_.=" `--------` "=._"=._/ ) | *
27 | * | > _.=" "=._ < | *
28 | * | (_/ \_) | *
29 | * | | *
30 | * '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=' *
31 | *
32 | * *************************************************************
33 | *
Created by 坚果-王健(wangjian3@kuyumall.com) on 2017/5/12.
34 | */
35 |
36 | public class LineChartInViewPager extends LineChart {
37 |
38 | PointF downPoint = new PointF();
39 |
40 | public LineChartInViewPager(Context context) {
41 | super(context);
42 | }
43 |
44 | public LineChartInViewPager(Context context, AttributeSet attrs) {
45 | super(context, attrs);
46 | }
47 |
48 | public LineChartInViewPager(Context context, AttributeSet attrs, int defStyle) {
49 | super(context, attrs, defStyle);
50 | }
51 |
52 | @SuppressLint("ClickableViewAccessibility")
53 | @Override
54 | public boolean onTouchEvent(MotionEvent evt) {
55 | switch (evt.getAction()) {
56 | case MotionEvent.ACTION_DOWN:
57 | downPoint.x = evt.getX();
58 | downPoint.y = evt.getY();
59 | break;
60 | case MotionEvent.ACTION_MOVE:
61 | if (getScaleX() > 1 && Math.abs(evt.getX() - downPoint.x) > 5) {
62 | getParent().requestDisallowInterceptTouchEvent(true);
63 | }
64 | break;
65 | }
66 | return super.onTouchEvent(evt);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/MPChartLib/src/main/java/com/github/mikephil/charting/highlight/RadarHighlighter.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.highlight;
2 |
3 | import com.github.mikephil.charting.charts.RadarChart;
4 | import com.github.mikephil.charting.data.Entry;
5 | import com.github.mikephil.charting.interfaces.datasets.IDataSet;
6 | import com.github.mikephil.charting.utils.MPPointF;
7 | import com.github.mikephil.charting.utils.Utils;
8 |
9 | import java.util.List;
10 |
11 | /**
12 | * Created by philipp on 12/06/16.
13 | */
14 | public class RadarHighlighter extends PieRadarHighlighter {
15 |
16 | public RadarHighlighter(RadarChart chart) {
17 | super(chart);
18 | }
19 |
20 | @Override
21 | protected Highlight getClosestHighlight(int index, float x, float y) {
22 |
23 | List highlights = getHighlightsAtIndex(index);
24 |
25 | float distanceToCenter = mChart.distanceToCenter(x, y) / mChart.getFactor();
26 |
27 | Highlight closest = null;
28 | float distance = Float.MAX_VALUE;
29 |
30 | for (int i = 0; i < highlights.size(); i++) {
31 |
32 | Highlight high = highlights.get(i);
33 |
34 | float cdistance = Math.abs(high.getY() - distanceToCenter);
35 | if (cdistance < distance) {
36 | closest = high;
37 | distance = cdistance;
38 | }
39 | }
40 |
41 | return closest;
42 | }
43 | /**
44 | * Returns an array of Highlight objects for the given index. The Highlight
45 | * objects give information about the value at the selected index and the
46 | * DataSet it belongs to. INFORMATION: This method does calculations at
47 | * runtime. Do not over-use in performance critical situations.
48 | *
49 | * @param index
50 | * @return
51 | */
52 | protected List getHighlightsAtIndex(int index) {
53 |
54 | mHighlightBuffer.clear();
55 |
56 | float phaseX = mChart.getAnimator().getPhaseX();
57 | float phaseY = mChart.getAnimator().getPhaseY();
58 | float sliceangle = mChart.getSliceAngle();
59 | float factor = mChart.getFactor();
60 |
61 | MPPointF pOut = MPPointF.getInstance(0,0);
62 | for (int i = 0; i < mChart.getData().getDataSetCount(); i++) {
63 |
64 | IDataSet> dataSet = mChart.getData().getDataSetByIndex(i);
65 |
66 | final Entry entry = dataSet.getEntryForIndex(index);
67 |
68 | float y = (entry.getY() - mChart.getYChartMin());
69 |
70 | Utils.getPosition(
71 | mChart.getCenterOffsets(), y * factor * phaseY,
72 | sliceangle * index * phaseX + mChart.getRotationAngle(), pOut);
73 |
74 | mHighlightBuffer.add(new Highlight(index, entry.getY(), pOut.x, pOut.y, i, dataSet.getAxisDependency()));
75 | }
76 |
77 | return mHighlightBuffer;
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/app/src/main/java/com/smartchart/cn/mpandroidchart/view/NewMarkerView.java:
--------------------------------------------------------------------------------
1 | package com.smartchart.cn.mpandroidchart.view;
2 |
3 | /**
4 | *
5 | * Created by 坚果-王健(wangjian3@kuyumall.com) on 2016/12/14.
6 | */
7 |
8 |
9 | import android.content.Context;
10 | import android.widget.TextView;
11 |
12 | import com.github.mikephil.charting.components.MarkerView;
13 | import com.github.mikephil.charting.data.CandleEntry;
14 | import com.github.mikephil.charting.data.Entry;
15 | import com.github.mikephil.charting.highlight.Highlight;
16 | import com.github.mikephil.charting.utils.MPPointF;
17 | import com.github.mikephil.charting.utils.Utils;
18 | import com.smartchart.cn.mpandroidchart.R;
19 |
20 |
21 | /**
22 | * Custom implementation of the MarkerView.
23 | *
24 | * @author Philipp Jahoda
25 | */
26 | public class NewMarkerView extends MarkerView {
27 |
28 | private TextView tvContent;
29 | private CallBack mCallBack;
30 | private Boolean needFormat=true;
31 | public NewMarkerView(Context context, int layoutResource) {
32 | super(context, layoutResource);
33 | tvContent = (TextView) findViewById(R.id.tvContent);
34 | }
35 |
36 | /*部分数据不需要格式化处理*/
37 | public NewMarkerView(Context context, int layoutResource,boolean needFormat) {
38 | super(context, layoutResource);
39 | this.needFormat = needFormat;
40 | tvContent = (TextView) findViewById(R.id.tvContent);
41 | }
42 |
43 | // callbacks everytime the MarkerView is redrawn, can be used to update the
44 | // content (user-interface)
45 | @Override
46 | public void refreshContent(Entry e, Highlight highlight) {
47 |
48 | String values;
49 | if (e instanceof CandleEntry) {
50 | CandleEntry ce = (CandleEntry) e;
51 | values = "" + Utils.formatNumber(ce.getHigh(), 0, true);
52 | } else {
53 | if(!needFormat){
54 | values=""+e.getY();
55 | }else{
56 | values = "" + Utils.formatNumber(e.getY(), 0, true);
57 | }
58 | }
59 |
60 | if (mCallBack != null) {
61 | mCallBack.onCallBack(e.getX(), values);
62 | }
63 | super.refreshContent(e, highlight);
64 | }
65 |
66 | @Override
67 | public MPPointF getOffset() {
68 | tvContent.setBackgroundResource(R.drawable.chart_popu);
69 | return new MPPointF(0, -getHeight());
70 | }
71 |
72 | @Override
73 | public MPPointF getOffsetRight() {
74 | tvContent.setBackgroundResource(R.drawable.chart_popu_right);
75 | return new MPPointF(-getWidth(), -getHeight());
76 | }
77 |
78 | public void setCallBack (CallBack callBack) {
79 | this.mCallBack = callBack;
80 | }
81 | public interface CallBack {
82 | void onCallBack(float x, String value);
83 | }
84 |
85 | public TextView getTvContent() {
86 | return tvContent;
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/ILineDataSet.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.interfaces.datasets;
2 |
3 | import android.graphics.DashPathEffect;
4 |
5 | import com.github.mikephil.charting.data.Entry;
6 | import com.github.mikephil.charting.data.LineDataSet;
7 | import com.github.mikephil.charting.formatter.IFillFormatter;
8 |
9 | /**
10 | * Created by Philpp Jahoda on 21/10/15.
11 | */
12 | public interface ILineDataSet extends ILineRadarDataSet {
13 |
14 | /**
15 | * Returns the drawing mode for this line dataset
16 | *
17 | * @return
18 | */
19 | LineDataSet.Mode getMode();
20 |
21 | /**
22 | * Returns the intensity of the cubic lines (the effect intensity).
23 | * Max = 1f = very cubic, Min = 0.05f = low cubic effect, Default: 0.2f
24 | *
25 | * @return
26 | */
27 | float getCubicIntensity();
28 |
29 | @Deprecated
30 | boolean isDrawCubicEnabled();
31 |
32 | @Deprecated
33 | boolean isDrawSteppedEnabled();
34 |
35 | /**
36 | * Returns the size of the drawn circles.
37 | */
38 | float getCircleRadius();
39 |
40 | /**
41 | * Returns the hole radius of the drawn circles.
42 | */
43 | float getCircleHoleRadius();
44 |
45 | /**
46 | * Returns the color at the given index of the DataSet's circle-color array.
47 | * Performs a IndexOutOfBounds check by modulus.
48 | *
49 | * @param index
50 | * @return
51 | */
52 | int getCircleColor(int index);
53 |
54 | /**
55 | * Returns the number of colors in this DataSet's circle-color array.
56 | *
57 | * @return
58 | */
59 | int getCircleColorCount();
60 |
61 | /**
62 | * Returns true if drawing circles for this DataSet is enabled, false if not
63 | *
64 | * @return
65 | */
66 | boolean isDrawCirclesEnabled();
67 |
68 | /**
69 | * Returns the color of the inner circle (the circle-hole).
70 | *
71 | * @return
72 | */
73 | int getCircleHoleColor();
74 |
75 | /**
76 | * Returns true if drawing the circle-holes is enabled, false if not.
77 | *
78 | * @return
79 | */
80 | boolean isDrawCircleHoleEnabled();
81 |
82 | /**
83 | * Returns the DashPathEffect that is used for drawing the lines.
84 | *
85 | * @return
86 | */
87 | DashPathEffect getDashPathEffect();
88 |
89 | /**
90 | * Returns true if the dashed-line effect is enabled, false if not.
91 | * If the DashPathEffect object is null, also return false here.
92 | *
93 | * @return
94 | */
95 | boolean isDashedLineEnabled();
96 |
97 | /**
98 | * Returns the IFillFormatter that is set for this DataSet.
99 | *
100 | * @return
101 | */
102 | IFillFormatter getFillFormatter();
103 | }
--------------------------------------------------------------------------------
/MPChartLib/src/main/java/com/github/mikephil/charting/jobs/AnimatedViewPortJob.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.jobs;
2 |
3 | import android.animation.Animator;
4 | import android.animation.ObjectAnimator;
5 | import android.animation.ValueAnimator;
6 | import android.annotation.SuppressLint;
7 | import android.view.View;
8 |
9 | import com.github.mikephil.charting.utils.Transformer;
10 | import com.github.mikephil.charting.utils.ViewPortHandler;
11 |
12 | /**
13 | * Created by Philipp Jahoda on 19/02/16.
14 | */
15 | @SuppressLint("NewApi")
16 | public abstract class AnimatedViewPortJob extends ViewPortJob implements ValueAnimator.AnimatorUpdateListener, Animator.AnimatorListener {
17 |
18 | protected ObjectAnimator animator;
19 |
20 | protected float phase;
21 |
22 | protected float xOrigin;
23 | protected float yOrigin;
24 |
25 | public AnimatedViewPortJob(ViewPortHandler viewPortHandler, float xValue, float yValue, Transformer trans, View v, float xOrigin, float yOrigin, long duration) {
26 | super(viewPortHandler, xValue, yValue, trans, v);
27 | this.xOrigin = xOrigin;
28 | this.yOrigin = yOrigin;
29 | animator = ObjectAnimator.ofFloat(this, "phase", 0f, 1f);
30 | animator.setDuration(duration);
31 | animator.addUpdateListener(this);
32 | animator.addListener(this);
33 | }
34 |
35 | @SuppressLint("NewApi")
36 | @Override
37 | public void run() {
38 | animator.start();
39 | }
40 |
41 | public float getPhase() {
42 | return phase;
43 | }
44 |
45 | public void setPhase(float phase) {
46 | this.phase = phase;
47 | }
48 |
49 | public float getXOrigin() {
50 | return xOrigin;
51 | }
52 |
53 | public float getYOrigin() {
54 | return yOrigin;
55 | }
56 |
57 | public abstract void recycleSelf();
58 |
59 | protected void resetAnimator(){
60 | animator.removeAllListeners();
61 | animator.removeAllUpdateListeners();
62 | animator.reverse();
63 | animator.addUpdateListener(this);
64 | animator.addListener(this);
65 | }
66 |
67 | @Override
68 | public void onAnimationStart(Animator animation) {
69 |
70 | }
71 |
72 | @Override
73 | public void onAnimationEnd(Animator animation) {
74 | try{
75 | recycleSelf();
76 | }catch (IllegalArgumentException e){
77 | // don't worry about it.
78 | }
79 | }
80 |
81 | @Override
82 | public void onAnimationCancel(Animator animation) {
83 | try{
84 | recycleSelf();
85 | }catch (IllegalArgumentException e){
86 | // don't worry about it.
87 | }
88 | }
89 |
90 | @Override
91 | public void onAnimationRepeat(Animator animation) {
92 |
93 | }
94 |
95 | @Override
96 | public void onAnimationUpdate(ValueAnimator animation) {
97 |
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/MPChartLib/src/main/java/com/github/mikephil/charting/newchart/GroupBarChartEntity.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.newchart;
2 |
3 |
4 |
5 | import com.github.mikephil.charting.charts.BarChart;
6 | import com.github.mikephil.charting.charts.BarLineChartBase;
7 | import com.github.mikephil.charting.components.YAxis;
8 | import com.github.mikephil.charting.data.BarData;
9 | import com.github.mikephil.charting.data.BarDataSet;
10 | import com.github.mikephil.charting.data.BarEntry;
11 |
12 | import java.util.List;
13 |
14 | /**
15 | *
16 | * 组合柱状图
17 | * Created by jin
18 | */
19 |
20 | public class GroupBarChartEntity extends BaseChartEntity {
21 |
22 | public GroupBarChartEntity(BarLineChartBase chart, List[] entries, String[] labels, int[] chartColor, int valueColor, float textSize) {
23 | super(chart, entries, labels, chartColor, valueColor, textSize);
24 |
25 | }
26 |
27 | @Override
28 | protected void setChartData() {
29 |
30 | BarDataSet[] barDataSets = new BarDataSet[mEntries.length];
31 | if (mChart.getData() != null && mChart.getData().getDataSetCount() == mEntries.length) {
32 | for(int index = 0, len = mEntries.length; index < len; index ++) {
33 | List list = mEntries[index];
34 | barDataSets[index] = (BarDataSet) mChart.getData().getDataSetByIndex(index);
35 | barDataSets[index].setValues(list);
36 | }
37 | mChart.getData().notifyDataChanged();
38 | mChart.notifyDataSetChanged();
39 | } else {
40 | for (int index = 0, len = mEntries.length; index < len; index ++) {
41 | barDataSets[index] = new BarDataSet(mEntries[index], labels[index]);
42 | barDataSets[index].setAxisDependency(YAxis.AxisDependency.LEFT);
43 | barDataSets[index].setColor(mChartColors[index]);
44 | barDataSets[index].setValueTextColor(mValueColor);
45 | barDataSets[index].setValueTextSize(mTextSize);
46 | }
47 | }
48 |
49 | float groupSpace = 0.45f;
50 | float barSpace = 0.0f; // x2 dataset
51 | float barWidth = 0.45f; // x2 dataset
52 |
53 | BarData data = new BarData(barDataSets);
54 | data.setBarWidth(barWidth);
55 | // make this BarData object grouped
56 | data.groupBars(0, groupSpace, barSpace);
57 | mChart.setData(data);
58 | }
59 | /**
60 | * 设置bar宽度
61 | * @param barWidth float
62 | */
63 | public void setBarWidth(float barWidth) {
64 | float groupSpace = 1f;
65 | float barSpace = 0.0f; // x2 dataset
66 | // float barWidth = 0.45f; // x2 dataset
67 | ((BarChart)mChart).getData().setBarWidth(barWidth);
68 | ((BarChart)mChart).getData().groupBars(0, groupSpace, barSpace);
69 | }
70 |
71 | public void setDrawValueAboveBar(boolean aboveBar) {
72 | ((BarChart)mChart).setDrawValueAboveBar(aboveBar);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/scatter/TriangleShapeRenderer.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.renderer.scatter;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.Path;
6 |
7 | import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
8 | import com.github.mikephil.charting.utils.ColorTemplate;
9 | import com.github.mikephil.charting.utils.Utils;
10 | import com.github.mikephil.charting.utils.ViewPortHandler;
11 |
12 | /**
13 | * Created by wajdic on 15/06/2016.
14 | * Created at Time 09:08
15 | */
16 | public class TriangleShapeRenderer implements IShapeRenderer
17 | {
18 |
19 | protected Path mTrianglePathBuffer = new Path();
20 |
21 | @Override
22 | public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
23 | float posX, float posY, Paint renderPaint) {
24 |
25 | final float shapeSize = dataSet.getScatterShapeSize();
26 | final float shapeHalf = shapeSize / 2f;
27 | final float shapeHoleSizeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeHoleRadius());
28 | final float shapeHoleSize = shapeHoleSizeHalf * 2.f;
29 | final float shapeStrokeSize = (shapeSize - shapeHoleSize) / 2.f;
30 |
31 | final int shapeHoleColor = dataSet.getScatterShapeHoleColor();
32 |
33 | renderPaint.setStyle(Paint.Style.FILL);
34 |
35 | // create a triangle path
36 | Path tri = mTrianglePathBuffer;
37 | tri.reset();
38 |
39 | tri.moveTo(posX, posY - shapeHalf);
40 | tri.lineTo(posX + shapeHalf, posY + shapeHalf);
41 | tri.lineTo(posX - shapeHalf, posY + shapeHalf);
42 |
43 | if (shapeSize > 0.0) {
44 | tri.lineTo(posX, posY - shapeHalf);
45 |
46 | tri.moveTo(posX - shapeHalf + shapeStrokeSize,
47 | posY + shapeHalf - shapeStrokeSize);
48 | tri.lineTo(posX + shapeHalf - shapeStrokeSize,
49 | posY + shapeHalf - shapeStrokeSize);
50 | tri.lineTo(posX,
51 | posY - shapeHalf + shapeStrokeSize);
52 | tri.lineTo(posX - shapeHalf + shapeStrokeSize,
53 | posY + shapeHalf - shapeStrokeSize);
54 | }
55 |
56 | tri.close();
57 |
58 | c.drawPath(tri, renderPaint);
59 | tri.reset();
60 |
61 | if (shapeSize > 0.0 &&
62 | shapeHoleColor != ColorTemplate.COLOR_NONE) {
63 |
64 | renderPaint.setColor(shapeHoleColor);
65 |
66 | tri.moveTo(posX,
67 | posY - shapeHalf + shapeStrokeSize);
68 | tri.lineTo(posX + shapeHalf - shapeStrokeSize,
69 | posY + shapeHalf - shapeStrokeSize);
70 | tri.lineTo(posX - shapeHalf + shapeStrokeSize,
71 | posY + shapeHalf - shapeStrokeSize);
72 | tri.close();
73 |
74 | c.drawPath(tri, renderPaint);
75 | tri.reset();
76 | }
77 |
78 | }
79 |
80 | }
--------------------------------------------------------------------------------
/MPChartLib/src/main/java/com/github/mikephil/charting/jobs/ZoomJob.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.jobs;
3 |
4 | import android.graphics.Matrix;
5 | import android.view.View;
6 |
7 | import com.github.mikephil.charting.charts.BarLineChartBase;
8 | import com.github.mikephil.charting.components.YAxis;
9 | import com.github.mikephil.charting.utils.ObjectPool;
10 | import com.github.mikephil.charting.utils.Transformer;
11 | import com.github.mikephil.charting.utils.ViewPortHandler;
12 |
13 | /**
14 | * Created by Philipp Jahoda on 19/02/16.
15 | */
16 | public class ZoomJob extends ViewPortJob {
17 |
18 | private static ObjectPool pool;
19 |
20 | static {
21 | pool = ObjectPool.create(1, new ZoomJob(null, 0, 0, 0, 0, null, null, null));
22 | pool.setReplenishPercentage(0.5f);
23 | }
24 |
25 | public static ZoomJob getInstance(ViewPortHandler viewPortHandler, float scaleX, float scaleY, float xValue, float yValue,
26 | Transformer trans, YAxis.AxisDependency axis, View v) {
27 | ZoomJob result = pool.get();
28 | result.xValue = xValue;
29 | result.yValue = yValue;
30 | result.scaleX = scaleX;
31 | result.scaleY = scaleY;
32 | result.mViewPortHandler = viewPortHandler;
33 | result.mTrans = trans;
34 | result.axisDependency = axis;
35 | result.view = v;
36 | return result;
37 | }
38 |
39 | public static void recycleInstance(ZoomJob instance) {
40 | pool.recycle(instance);
41 | }
42 |
43 | protected float scaleX;
44 | protected float scaleY;
45 |
46 | protected YAxis.AxisDependency axisDependency;
47 |
48 | public ZoomJob(ViewPortHandler viewPortHandler, float scaleX, float scaleY, float xValue, float yValue, Transformer trans,
49 | YAxis.AxisDependency axis, View v) {
50 | super(viewPortHandler, xValue, yValue, trans, v);
51 |
52 | this.scaleX = scaleX;
53 | this.scaleY = scaleY;
54 | this.axisDependency = axis;
55 | }
56 |
57 | protected Matrix mRunMatrixBuffer = new Matrix();
58 |
59 | @Override
60 | public void run() {
61 |
62 | Matrix save = mRunMatrixBuffer;
63 | mViewPortHandler.zoom(scaleX, scaleY, save);
64 | mViewPortHandler.refresh(save, view, false);
65 |
66 | float yValsInView = ((BarLineChartBase) view).getAxis(axisDependency).mAxisRange / mViewPortHandler.getScaleY();
67 | float xValsInView = ((BarLineChartBase) view).getXAxis().mAxisRange / mViewPortHandler.getScaleX();
68 |
69 | pts[0] = xValue - xValsInView / 2f;
70 | pts[1] = yValue + yValsInView / 2f;
71 |
72 | mTrans.pointValuesToPixel(pts);
73 |
74 | mViewPortHandler.translate(pts, save);
75 | mViewPortHandler.refresh(save, view, false);
76 |
77 | ((BarLineChartBase) view).calculateOffsets();
78 | view.postInvalidate();
79 |
80 | recycleInstance(this);
81 | }
82 |
83 | @Override
84 | protected ObjectPool.Poolable instantiate() {
85 | return new ZoomJob(null, 0, 0, 0, 0, null, null, null);
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/MPChartLib/src/main/java/com/github/mikephil/charting/newchart/BarChartEntity.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.newchart;
2 |
3 | import android.graphics.Color;
4 |
5 |
6 | import com.github.mikephil.charting.charts.BarChart;
7 | import com.github.mikephil.charting.charts.BarLineChartBase;
8 | import com.github.mikephil.charting.data.BarData;
9 | import com.github.mikephil.charting.data.BarDataSet;
10 | import com.github.mikephil.charting.data.BarEntry;
11 | import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
12 |
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | /**
17 | * 柱状图
18 | * Created by jin
19 | */
20 |
21 | public class BarChartEntity extends BaseChartEntity {
22 | public BarChartEntity(BarLineChartBase chart, List[] entries, String[] labels, int[] chartColor, int valueColor, float textSize) {
23 | super(chart, entries, labels, chartColor, valueColor, textSize);
24 | }
25 |
26 | @Override
27 | protected void initChart() {
28 | super.initChart();
29 | mChart.getAxisLeft().setDrawGridLines(true);
30 | mChart.getAxisLeft().enableGridDashedLine(10f, 15f, 0f);
31 | mChart.getAxisLeft().setGridLineWidth(0.5f);
32 | mChart.getAxisLeft().setGridColor(Color.parseColor("#f5f5f5"));
33 | mChart.getAxisLeft().setDrawZeroLine(false);
34 | mChart.getAxisRight().setDrawZeroLine(false);
35 | mChart.getAxisRight().setZeroLineWidth(0f);
36 | mChart.getAxisLeft().setZeroLineWidth(0f);
37 | mChart.getAxisLeft().setDrawAxisLine(false);
38 | mChart.getXAxis().setDrawAxisLine(false);
39 | mChart.getXAxis().setAxisMinimum(0);
40 |
41 | }
42 |
43 | @Override
44 | protected void setChartData() {
45 | BarDataSet barDataSet;
46 | if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) {
47 | barDataSet = (BarDataSet) mChart.getData().getDataSetByIndex(0);
48 | barDataSet.setValues(mEntries[0]);
49 | mChart.getData().notifyDataChanged();
50 | mChart.notifyDataSetChanged();
51 | } else {
52 | barDataSet = new BarDataSet(mEntries[0], labels == null ? "" : labels[0]);
53 | barDataSet.setColors(mChartColors);
54 | List colors = new ArrayList<>();
55 | for (int color : mChartColors) {
56 | colors.add(color);
57 | }
58 | barDataSet.setValueTextColors(colors);
59 | ArrayList dataSets = new ArrayList<>();
60 | dataSets.add(barDataSet);
61 | BarData data = new BarData(dataSets);
62 | data.setValueTextSize(mTextSize);
63 | data.setBarWidth(0.9f);
64 | mChart.setData(data);
65 | }
66 | }
67 |
68 |
69 |
70 | public void setDrawValueAboveBar(boolean aboveBar) {
71 | ((BarChart)mChart).setDrawValueAboveBar(aboveBar);
72 | }
73 |
74 | /**
75 | * 设置bar宽度
76 | * @param barWidth float
77 | */
78 | public void setBarWidth(float barWidth) {
79 | ((BarChart)mChart).getData().setBarWidth(barWidth);
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineRadarRenderer.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.renderer;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.Path;
6 | import android.graphics.drawable.Drawable;
7 |
8 | import com.github.mikephil.charting.animation.ChartAnimator;
9 | import com.github.mikephil.charting.utils.Utils;
10 | import com.github.mikephil.charting.utils.ViewPortHandler;
11 |
12 | /**
13 | * Created by Philipp Jahoda on 25/01/16.
14 | */
15 | public abstract class LineRadarRenderer extends LineScatterCandleRadarRenderer {
16 |
17 | public LineRadarRenderer(ChartAnimator animator, ViewPortHandler viewPortHandler) {
18 | super(animator, viewPortHandler);
19 | }
20 |
21 | /**
22 | * Draws the provided path in filled mode with the provided drawable.
23 | *
24 | * @param c
25 | * @param filledPath
26 | * @param drawable
27 | */
28 | protected void drawFilledPath(Canvas c, Path filledPath, Drawable drawable) {
29 |
30 | if (clipPathSupported()) {
31 |
32 | int save = c.save();
33 | c.clipPath(filledPath);
34 |
35 | drawable.setBounds((int) mViewPortHandler.contentLeft(),
36 | (int) mViewPortHandler.contentTop(),
37 | (int) mViewPortHandler.contentRight(),
38 | (int) mViewPortHandler.contentBottom());
39 | drawable.draw(c);
40 |
41 | c.restoreToCount(save);
42 | } else {
43 | throw new RuntimeException("Fill-drawables not (yet) supported below API level 18, " +
44 | "this code was run on API level " + Utils.getSDKInt() + ".");
45 | }
46 | }
47 |
48 | /**
49 | * Draws the provided path in filled mode with the provided color and alpha.
50 | * Special thanks to Angelo Suzuki (https://github.com/tinsukE) for this.
51 | *
52 | * @param c
53 | * @param filledPath
54 | * @param fillColor
55 | * @param fillAlpha
56 | */
57 | protected void drawFilledPath(Canvas c, Path filledPath, int fillColor, int fillAlpha) {
58 |
59 | int color = (fillAlpha << 24) | (fillColor & 0xffffff);
60 |
61 | if (clipPathSupported()) {
62 |
63 | int save = c.save();
64 |
65 | c.clipPath(filledPath);
66 |
67 | c.drawColor(color);
68 | c.restoreToCount(save);
69 | } else {
70 |
71 | // save
72 | Paint.Style previous = mRenderPaint.getStyle();
73 | int previousColor = mRenderPaint.getColor();
74 |
75 | // set
76 | mRenderPaint.setStyle(Paint.Style.FILL);
77 | mRenderPaint.setColor(color);
78 |
79 | c.drawPath(filledPath, mRenderPaint);
80 |
81 | // restore
82 | mRenderPaint.setColor(previousColor);
83 | mRenderPaint.setStyle(previous);
84 | }
85 | }
86 |
87 | /**
88 | * Clip path with hardware acceleration only working properly on API level 18 and above.
89 | *
90 | * @return
91 | */
92 | private boolean clipPathSupported() {
93 | return Utils.getSDKInt() >= 18;
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/MPChartLib/src/main/java/com/github/mikephil/charting/buffer/HorizontalBarBuffer.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.buffer;
3 |
4 | import com.github.mikephil.charting.data.BarEntry;
5 | import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
6 |
7 | public class HorizontalBarBuffer extends BarBuffer {
8 |
9 | public HorizontalBarBuffer(int size, int dataSetCount, boolean containsStacks) {
10 | super(size, dataSetCount, containsStacks);
11 | }
12 |
13 | @Override
14 | public void feed(IBarDataSet data) {
15 |
16 | float size = data.getEntryCount() * phaseX;
17 | float barWidthHalf = mBarWidth / 2f;
18 |
19 | for (int i = 0; i < size; i++) {
20 |
21 | BarEntry e = data.getEntryForIndex(i);
22 |
23 | if(e == null)
24 | continue;
25 |
26 | float x = e.getX();
27 | float y = e.getY();
28 | float[] vals = e.getYVals();
29 |
30 | if (!mContainsStacks || vals == null) {
31 |
32 | float bottom = x - barWidthHalf;
33 | float top = x + barWidthHalf;
34 | float left, right;
35 | if (mInverted) {
36 | left = y >= 0 ? y : 0;
37 | right = y <= 0 ? y : 0;
38 | } else {
39 | right = y >= 0 ? y : 0;
40 | left = y <= 0 ? y : 0;
41 | }
42 |
43 | // multiply the height of the rect with the phase
44 | if (right > 0)
45 | right *= phaseY;
46 | else
47 | left *= phaseY;
48 |
49 | addBar(left, top, right, bottom);
50 |
51 | } else {
52 |
53 | float posY = 0f;
54 | float negY = -e.getNegativeSum();
55 | float yStart = 0f;
56 |
57 | // fill the stack
58 | for (int k = 0; k < vals.length; k++) {
59 |
60 | float value = vals[k];
61 |
62 | if (value >= 0f) {
63 | y = posY;
64 | yStart = posY + value;
65 | posY = yStart;
66 | } else {
67 | y = negY;
68 | yStart = negY + Math.abs(value);
69 | negY += Math.abs(value);
70 | }
71 |
72 | float bottom = x - barWidthHalf;
73 | float top = x + barWidthHalf;
74 | float left, right;
75 | if (mInverted) {
76 | left = y >= yStart ? y : yStart;
77 | right = y <= yStart ? y : yStart;
78 | } else {
79 | right = y >= yStart ? y : yStart;
80 | left = y <= yStart ? y : yStart;
81 | }
82 |
83 | // multiply the height of the rect with the phase
84 | right *= phaseY;
85 | left *= phaseY;
86 |
87 | addBar(left, top, right, bottom);
88 | }
89 | }
90 | }
91 |
92 | reset();
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/MPChartLib/src/main/java/com/github/mikephil/charting/data/filter/Approximator.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.mikephil.charting.data.filter;
3 |
4 | import android.annotation.TargetApi;
5 | import android.os.Build;
6 |
7 | import java.util.Arrays;
8 |
9 | /**
10 | * Implemented according to Wiki-Pseudocode {@link}
11 | * http://en.wikipedia.org/wiki/Ramer�Douglas�Peucker_algorithm
12 | *
13 | * @author Philipp Baldauf & Phliipp Jahoda
14 | */
15 | public class Approximator {
16 |
17 | @TargetApi(Build.VERSION_CODES.GINGERBREAD)
18 | public float[] reduceWithDouglasPeucker(float[] points, float tolerance) {
19 |
20 | int greatestIndex = 0;
21 | float greatestDistance = 0f;
22 |
23 | Line line = new Line(points[0], points[1], points[points.length - 2], points[points.length - 1]);
24 |
25 | for (int i = 2; i < points.length - 2; i += 2) {
26 |
27 | float distance = line.distance(points[i], points[i + 1]);
28 |
29 | if (distance > greatestDistance) {
30 | greatestDistance = distance;
31 | greatestIndex = i;
32 | }
33 | }
34 |
35 | if (greatestDistance > tolerance) {
36 |
37 | float[] reduced1 = reduceWithDouglasPeucker(Arrays.copyOfRange(points, 0, greatestIndex + 2), tolerance);
38 | float[] reduced2 = reduceWithDouglasPeucker(Arrays.copyOfRange(points, greatestIndex, points.length),
39 | tolerance);
40 |
41 | float[] result1 = reduced1;
42 | float[] result2 = Arrays.copyOfRange(reduced2, 2, reduced2.length);
43 |
44 | return concat(result1, result2);
45 | } else {
46 | return line.getPoints();
47 | }
48 | }
49 |
50 | /**
51 | * Combine arrays.
52 | *
53 | * @param arrays
54 | * @return
55 | */
56 | float[] concat(float[]... arrays) {
57 | int length = 0;
58 | for (float[] array : arrays) {
59 | length += array.length;
60 | }
61 | float[] result = new float[length];
62 | int pos = 0;
63 | for (float[] array : arrays) {
64 | for (float element : array) {
65 | result[pos] = element;
66 | pos++;
67 | }
68 | }
69 | return result;
70 | }
71 |
72 | private class Line {
73 |
74 | private float[] points;
75 |
76 | private float sxey;
77 | private float exsy;
78 |
79 | private float dx;
80 | private float dy;
81 |
82 | private float length;
83 |
84 | public Line(float x1, float y1, float x2, float y2) {
85 | dx = x1 - x2;
86 | dy = y1 - y2;
87 | sxey = x1 * y2;
88 | exsy = x2 * y1;
89 | length = (float) Math.sqrt(dx * dx + dy * dy);
90 |
91 | points = new float[]{x1, y1, x2, y2};
92 | }
93 |
94 | public float distance(float x, float y) {
95 | return Math.abs(dy * x - dx * y + sxey - exsy) / length;
96 | }
97 |
98 | public float[] getPoints() {
99 | return points;
100 | }
101 | }
102 | }
103 |
--------------------------------------------------------------------------------