implements IChartTitle {
18 |
19 | /**
20 | * 图表标题最大占比
21 | */
22 | private static final float MAX_PERCENT =0.4f;
23 | /**
24 | * 标题字体样式
25 | */
26 | private FontStyle fontStyle= new FontStyle();
27 |
28 | private Path path = new Path();
29 |
30 | /**
31 | * 设置标题占比
32 | * @param percent 百分比
33 | */
34 | @Override
35 | public void setPercent(float percent) {
36 | if(percent > MAX_PERCENT){
37 | percent = MAX_PERCENT;
38 | }
39 | super.setPercent(percent);
40 | }
41 |
42 | /**
43 | * 绘制标题
44 | * 通过设置标题方位绘制标题
45 | * @param canvas 画布
46 | * @param chartName 图表标题
47 | * @param paint 画笔
48 | */
49 | @Override
50 | public void draw(Canvas canvas, String chartName, Paint paint) {
51 | fontStyle.fillPaint(paint);
52 | Paint.FontMetrics fontMetrics = paint.getFontMetrics();
53 | paint.setTextAlign(Paint.Align.LEFT);
54 | float textHeight = fontMetrics.descent - fontMetrics.ascent;
55 | int textWidth = (int)paint.measureText(chartName);
56 | Rect rect = getRect();
57 | int startY = rect.centerY();
58 | int startX = rect.centerX();
59 | path.rewind();
60 | switch (direction) {
61 | case TOP:
62 | case BOTTOM:
63 | startY-= textHeight/2;
64 | startX -=textWidth/2;
65 | canvas.drawText(chartName, startX, startY, paint);
66 | break;
67 | case LEFT:
68 | case RIGHT:
69 | path.moveTo(startX,rect.top);
70 | path.lineTo(startX,rect.bottom);
71 | canvas.drawTextOnPath(chartName,path,(rect.height()-textWidth)/2,0,paint);
72 | break;
73 | }
74 | }
75 |
76 | /**
77 | * 获取标题字体样式
78 | * @return 标题字体样式
79 | */
80 | public FontStyle getFontStyle() {
81 | return fontStyle;
82 | }
83 | /**
84 | * 设置标题字体样式
85 | * @param fontStyle 标题字体样式
86 | */
87 | public void setFontStyle(FontStyle fontStyle) {
88 | this.fontStyle = fontStyle;
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/component/EmptyView.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.component;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.Rect;
6 |
7 | import com.daivd.chart.component.base.IEmpty;
8 | import com.daivd.chart.data.style.FontStyle;
9 |
10 | /**
11 | * 空白提示
12 | * @author huangyanbin
13 | */
14 |
15 | public class EmptyView implements IEmpty {
16 | /**
17 | * 空白提示字体样式
18 | */
19 | private FontStyle fontStyle = new FontStyle();
20 | /**
21 | * 空白文字
22 | */
23 | private String emptyTip = "No Data";
24 | /**
25 | * 空白范围
26 | */
27 | private Rect rect;
28 |
29 | /**
30 | * 绘制空白
31 | * @param canvas 画布
32 | * @param paint 画笔
33 | */
34 | @Override
35 | public void draw(Canvas canvas, Paint paint) {
36 | draw(canvas,emptyTip,paint);
37 | }
38 |
39 | /**
40 | * 获取空白字体样式
41 | * @return 空白字体样式
42 | */
43 | public FontStyle getFontStyle() {
44 | return fontStyle;
45 | }
46 | /**
47 | * 设置空白字体样式
48 | * @param fontStyle 空白字体样式
49 | */
50 | public void setFontStyle(FontStyle fontStyle) {
51 | this.fontStyle = fontStyle;
52 | }
53 | /**
54 | * 设置空白提示
55 | * @return 空白提示
56 | */
57 | @Override
58 | public String getEmptyTip() {
59 | return emptyTip;
60 | }
61 | /**
62 | * 获取空白提示
63 | * @param emptyTip 空白提示
64 | */
65 | @Override
66 | public void setEmptyTip(String emptyTip) {
67 | this.emptyTip = emptyTip;
68 | }
69 |
70 | /**
71 | * 计算空白大小
72 | * 因为空白提示是占整个图表不需要计算>
73 | * @param chartRect 图表范围
74 | */
75 | @Override
76 | public void computeRect(Rect chartRect) {
77 | rect = chartRect;
78 | }
79 |
80 | /**
81 | * 绘制空白
82 | * @param canvas 画布
83 | * @param emptyTip 空白提示
84 | * @param paint 画笔
85 | */
86 | @Override
87 | public void draw(Canvas canvas, String emptyTip, Paint paint) {
88 | fontStyle.fillPaint(paint);
89 | paint.setTextAlign(Paint.Align.LEFT);
90 | Paint.FontMetrics fontMetrics = paint.getFontMetrics();
91 | int textHeight = (int) (fontMetrics.descent - fontMetrics.ascent);
92 | int textWidth = (int) paint.measureText(emptyTip);
93 | canvas.drawText(emptyTip,rect.left +(rect.right-rect.left-textWidth)/2,rect.top+(rect.bottom - rect.top-textHeight)/2,paint);
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/component/PicGeneration.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.component;
2 |
3 | import android.content.ContentValues;
4 | import android.graphics.Bitmap;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.drawable.Drawable;
8 | import android.os.Environment;
9 | import android.provider.MediaStore;
10 | import android.view.View;
11 |
12 | import com.daivd.chart.data.PicOption;
13 |
14 | import java.io.File;
15 | import java.io.FileOutputStream;
16 | import java.io.IOException;
17 |
18 | /**
19 | * Created by huang on 2017/10/30.
20 | * 图片生成
21 | */
22 |
23 | public class PicGeneration {
24 |
25 | public boolean save(V v,PicOption option){
26 | getChartBitmap(v);
27 | return saveToGallery(v,option);
28 | }
29 |
30 | private Bitmap getChartBitmap(V v) {
31 | // 创建一个bitmap 根据我们自定义view的大小
32 | Bitmap returnedBitmap = Bitmap.createBitmap(v.getWidth(),
33 | v.getHeight(), Bitmap.Config.RGB_565);
34 | // 绑定canvas
35 | Canvas canvas = new Canvas(returnedBitmap);
36 | // 获取视图的背景
37 | Drawable bgDrawable = v.getBackground();
38 | if (bgDrawable != null)
39 | // 如果有就绘制
40 | bgDrawable.draw(canvas);
41 | else
42 | // 没有就绘制白色
43 | canvas.drawColor(Color.WHITE);
44 | // 绘制
45 | v.draw(canvas);
46 | return returnedBitmap;
47 | }
48 |
49 | private boolean saveToGallery(V v, PicOption option) {
50 | String mFilePath;
51 | // 控制图片质量
52 | if (option.getQuality() < 0 || option.getQuality() > 100)
53 | option.setQuality(50);
54 | long currentTime = System.currentTimeMillis();
55 |
56 | File extBaseDir = Environment.getExternalStorageDirectory();
57 | File file = new File(extBaseDir.getAbsolutePath() + "/DCIM/" + option.getSubFolderPath());
58 | if (!file.exists()) {
59 | if (!file.mkdirs()) {
60 | return false;
61 | }
62 | }
63 |
64 | String mimeType = "";
65 | String fileName = option.getFileName();
66 | switch (option.getFormat()) {
67 | case PNG:
68 | mimeType = "image/png";
69 | if (!fileName.endsWith(".png"))
70 | fileName += ".png";
71 | break;
72 | case WEBP:
73 | mimeType = "image/webp";
74 | if (!fileName.endsWith(".webp"))
75 | fileName += ".webp";
76 | break;
77 | case JPEG:
78 | default:
79 | mimeType = "image/jpeg";
80 | if (!(fileName.endsWith(".jpg") || fileName.endsWith(".jpeg")))
81 | fileName += ".jpg";
82 | break;
83 | }
84 | mFilePath = file.getAbsolutePath() + "/" + fileName;
85 | FileOutputStream out = null;
86 | try {
87 | out = new FileOutputStream(mFilePath);
88 | Bitmap b = getChartBitmap(v);
89 | b.compress(option.getFormat(), option.getQuality(), out);
90 |
91 | out.flush();
92 | out.close();
93 |
94 | } catch (IOException e) {
95 | e.printStackTrace();
96 |
97 | return false;
98 | }
99 |
100 | long size = new File(mFilePath).length();
101 |
102 | ContentValues values = new ContentValues(8);
103 |
104 | // store the details
105 | values.put(MediaStore.Images.Media.TITLE, fileName);
106 | values.put(MediaStore.Images.Media.DISPLAY_NAME, fileName);
107 | values.put(MediaStore.Images.Media.DATE_ADDED, currentTime);
108 | values.put(MediaStore.Images.Media.MIME_TYPE, mimeType);
109 | values.put(MediaStore.Images.Media.DESCRIPTION, option.getFileDescription());
110 | values.put(MediaStore.Images.Media.ORIENTATION, 0);
111 | values.put(MediaStore.Images.Media.DATA, mFilePath);
112 | values.put(MediaStore.Images.Media.SIZE, size);
113 | return v.getContext().getContentResolver().
114 | insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values) != null;
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/component/base/IAxis.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.component.base;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.Rect;
6 |
7 | import com.daivd.chart.data.ChartData;
8 | import com.daivd.chart.data.format.IFormat;
9 | import com.daivd.chart.data.BarData;
10 | import com.daivd.chart.matrix.MatrixHelper;
11 |
12 | /**
13 | * Created by huangYanBin on 2017/9/26.
14 | * 轴接口
15 | */
16 |
17 | public interface IAxis {
18 |
19 | void draw(Canvas canvas, Rect rect, MatrixHelper helper, Paint paint, ChartData extends BarData> chartData);
20 | void computeScale(ChartData extends BarData> chartData, Rect rect, Paint paint);
21 | void setAxisDirection(int axisDirection);
22 | void setFormat(IFormat format);
23 | IFormat getFormat();
24 | void setDisplay(boolean isShow);
25 |
26 | /**
27 | * Created by huangYanBin on 2017/9/26.
28 | * 轴方向
29 | */
30 |
31 | interface AxisDirection {
32 | int TOP = 1;
33 | int BOTTOM=2;
34 | int LEFT = 3;
35 | int RIGHT = 4;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/component/base/IChartTitle.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.component.base;
2 |
3 | import com.daivd.chart.data.style.FontStyle;
4 |
5 | /**
6 | * Created by huang on 2017/10/26.
7 | */
8 |
9 | public interface IChartTitle extends IComponent {
10 |
11 | float getPercent();
12 |
13 | void setPercent(float percent);
14 |
15 | FontStyle getFontStyle();
16 |
17 | int getDirection();
18 |
19 | void setDirection(int direction);
20 |
21 | void setFontStyle(FontStyle fontStyle);
22 | }
23 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/component/base/IComponent.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.component.base;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.Rect;
6 |
7 | /** 图表组件
8 | * Created by huang on 2017/10/26.
9 | */
10 |
11 | public interface IComponent {
12 |
13 | int LEFT = 0;
14 | int TOP = 1;
15 | int RIGHT =2;
16 | int BOTTOM = 3;
17 | /**
18 | * 计算组件Rect
19 | * @param chartRect
20 | */
21 | void computeRect(Rect chartRect);
22 |
23 | /**
24 | * 绘制组件
25 | * @param canvas 画布
26 | * @param t 数据
27 | * @param paint 画笔
28 | */
29 | void draw(Canvas canvas, T t, Paint paint);
30 | }
31 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/component/base/IEmpty.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.component.base;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.Rect;
6 |
7 | import com.daivd.chart.data.style.FontStyle;
8 |
9 | /**
10 | * Created by huang on 2017/9/30.
11 | */
12 |
13 | public interface IEmpty extends IComponent {
14 |
15 | void draw(Canvas canvas, Paint paint);
16 |
17 | FontStyle getFontStyle();
18 |
19 | void setFontStyle(FontStyle fontStyle) ;
20 |
21 | String getEmptyTip();
22 |
23 | void setEmptyTip(String emptyTip);
24 | }
25 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/component/base/ILegend.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.component.base;
2 |
3 | import android.graphics.PointF;
4 |
5 | import com.daivd.chart.data.ChartData;
6 | import com.daivd.chart.data.ColumnData;
7 | import com.daivd.chart.data.style.FontStyle;
8 | import com.daivd.chart.provider.component.point.ILegendPoint;
9 | import com.daivd.chart.provider.component.point.IPoint;
10 | import com.daivd.chart.listener.OnClickLegendListener;
11 |
12 | /**
13 | * Created by huang on 2017/10/26.
14 | */
15 |
16 | public interface ILegend extends IComponent> {
17 |
18 | float getPercent();
19 |
20 | void setPercent(float percent);
21 |
22 | FontStyle getFontStyle();
23 |
24 | int getDirection();
25 |
26 | void setDirection(int direction);
27 |
28 | void setFontStyle(FontStyle fontStyle);
29 |
30 | void onClickLegend(PointF pointF);
31 |
32 | void setOnClickLegendListener(OnClickLegendListener onClickLegendListener);
33 |
34 |
35 | int getPadding();
36 |
37 | void setPadding(int padding);
38 |
39 | IPoint getPoint();
40 |
41 | void setPoint(ILegendPoint point);
42 |
43 | void setSelectColumn(boolean selectColumn);
44 |
45 | void setDisplay(boolean isDisplay);
46 | }
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/component/base/PercentComponent.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.component.base;
2 |
3 | import android.graphics.Rect;
4 |
5 | /**图表百分百组件
6 | * Created by huang on 2017/10/26.
7 | */
8 |
9 | public abstract class PercentComponent implements IComponent {
10 |
11 | private static final float DEFAULT_PERCENT = 0.1f;
12 | private float percent = DEFAULT_PERCENT;
13 | private Rect rect = new Rect();
14 | protected int direction;
15 |
16 | @Override
17 | public void computeRect(Rect chartRect) {
18 | rect.left = chartRect.left;
19 | rect.right = chartRect.right;
20 | rect.top = chartRect.top;
21 | rect.bottom = chartRect.bottom;
22 | int h = (int) (chartRect.height()*percent);
23 | int w = (int) (chartRect.width()*percent);
24 | switch (direction){
25 | case TOP:
26 | rect.bottom = rect.top+h;
27 | chartRect.top = chartRect.top+h;
28 | break;
29 | case LEFT:
30 | rect.right = rect.left + w;
31 | chartRect.left = chartRect.left + w;
32 | break;
33 | case RIGHT:
34 | rect.left = rect.right -w;
35 | chartRect.right = chartRect.right - w;
36 | break;
37 | case BOTTOM:
38 | rect.top = rect.bottom -h;
39 | chartRect.bottom = chartRect.bottom -h;
40 | break;
41 | }
42 | }
43 |
44 |
45 | public float getPercent() {
46 | return percent;
47 | }
48 |
49 | public void setPercent(float percent) {
50 | this.percent = percent;
51 | }
52 |
53 | public Rect getRect() {
54 | return rect;
55 | }
56 |
57 | public void setRect(Rect rect) {
58 | this.rect = rect;
59 | }
60 |
61 | public int getDirection() {
62 | return direction;
63 | }
64 |
65 | public void setDirection(int direction) {
66 | this.direction = direction;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/core/Bar3DChart.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.core;
2 |
3 | import android.content.Context;
4 | import android.os.Build;
5 | import android.util.AttributeSet;
6 |
7 | import com.daivd.chart.core.base.BaseBarLineChart;
8 | import com.daivd.chart.data.BarData;
9 | import com.daivd.chart.provider.barLine.Bar3DProvider;
10 |
11 | /**
12 | * Created by huang on 2017/9/26.
13 | * 3DBar图表
14 | */
15 |
16 | public class Bar3DChart extends BaseBarLineChart {
17 |
18 | public Bar3DChart(Context context) {
19 | super(context);
20 | }
21 |
22 | public Bar3DChart(Context context, AttributeSet attrs) {
23 | super(context, attrs);
24 | }
25 |
26 | public Bar3DChart(Context context, AttributeSet attrs, int defStyleAttr) {
27 | super(context, attrs, defStyleAttr);
28 | }
29 |
30 |
31 |
32 |
33 |
34 | @Override
35 | protected Bar3DProvider initProvider() {
36 | return new Bar3DProvider();
37 | }
38 |
39 |
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/core/BarChart.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.core;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 |
6 | import com.daivd.chart.core.base.BaseBarLineChart;
7 | import com.daivd.chart.data.BarData;
8 | import com.daivd.chart.provider.barLine.BarProvider;
9 |
10 | /**
11 | * Created by huang on 2017/9/26.
12 | * 柱状图
13 | */
14 |
15 | public class BarChart extends BaseBarLineChart,BarData> {
16 |
17 | public BarChart(Context context) {
18 | super(context);
19 | }
20 |
21 | public BarChart(Context context, AttributeSet attrs) {
22 | super(context, attrs);
23 | }
24 |
25 | public BarChart(Context context, AttributeSet attrs, int defStyleAttr) {
26 | super(context, attrs, defStyleAttr);
27 | }
28 |
29 |
30 |
31 |
32 | @Override
33 | protected BarProvider initProvider() {
34 | return new BarProvider();
35 | }
36 |
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/core/BarLineChart.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.core;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 |
6 | import com.daivd.chart.core.base.BaseBarLineChart;
7 | import com.daivd.chart.data.BarLineData;
8 | import com.daivd.chart.provider.barLine.BarLineProvider;
9 |
10 | /**
11 | * Created by huang on 2017/9/26.
12 | * 柱状图
13 | */
14 |
15 | public class BarLineChart extends BaseBarLineChart {
16 |
17 | public BarLineChart(Context context) {
18 | super(context);
19 | }
20 |
21 | public BarLineChart(Context context, AttributeSet attrs) {
22 | super(context, attrs);
23 | }
24 |
25 | public BarLineChart(Context context, AttributeSet attrs, int defStyleAttr) {
26 | super(context, attrs, defStyleAttr);
27 | }
28 |
29 |
30 |
31 |
32 | @Override
33 | protected BarLineProvider initProvider() {
34 | return new BarLineProvider();
35 | }
36 |
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/core/LineChart.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.core;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.Gravity;
6 |
7 | import com.daivd.chart.core.base.BaseBarLineChart;
8 | import com.daivd.chart.data.LineData;
9 | import com.daivd.chart.exception.ChartException;
10 | import com.daivd.chart.provider.barLine.LineProvider;
11 | import com.daivd.chart.provider.component.line.CurveLineModel;
12 | import com.daivd.chart.provider.component.line.BrokenLineModel;
13 |
14 | /**
15 | * Created by huang on 2017/9/26.
16 | * 线性图
17 | */
18 |
19 | public class LineChart extends BaseBarLineChart {
20 |
21 | public static final int LINE_MODEL = 0;
22 | public static final int CURVE_MODEL = 1;
23 |
24 | public LineChart(Context context) {
25 | super(context);
26 | }
27 |
28 | public LineChart(Context context, AttributeSet attrs) {
29 | super(context, attrs);
30 | }
31 |
32 | public LineChart(Context context, AttributeSet attrs, int defStyleAttr) {
33 | super(context, attrs, defStyleAttr);
34 | }
35 |
36 |
37 |
38 | @Override
39 | protected LineProvider initProvider() {
40 | horizontalAxis.setGravity(Gravity.LEFT);
41 | horizontalAxis.isLine(true);
42 | return new LineProvider();
43 | }
44 |
45 | public void setLineModel(int model){
46 | if(model == LINE_MODEL){
47 | provider.setLineModel(new BrokenLineModel());
48 | }else if( model == CURVE_MODEL){
49 | provider.setLineModel(new CurveLineModel());
50 | }else {
51 | throw new ChartException("Please set the correct Line model");
52 | }
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/core/Pie3DChart.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.core;
2 |
3 | import android.content.Context;
4 | import android.os.Build;
5 | import android.util.AttributeSet;
6 |
7 | import com.daivd.chart.core.base.BaseRotateChart;
8 | import com.daivd.chart.data.PieData;
9 | import com.daivd.chart.matrix.RotateHelper;
10 | import com.daivd.chart.provider.pie.Pie3DProvider;
11 |
12 | /**
13 | * Created by huang on 2017/10/9.
14 | * 饼图
15 | */
16 |
17 | public class Pie3DChart extends BaseRotateChart {
18 |
19 |
20 | public Pie3DChart(Context context) {
21 | super(context);
22 | }
23 |
24 | public Pie3DChart(Context context, AttributeSet attrs) {
25 | super(context, attrs);
26 | }
27 |
28 | public Pie3DChart(Context context, AttributeSet attrs, int defStyleAttr) {
29 | super(context, attrs, defStyleAttr);
30 | }
31 |
32 |
33 |
34 |
35 | @Override
36 | protected Pie3DProvider initProvider(RotateHelper rotateHelper) {
37 | Pie3DProvider provider = new Pie3DProvider(getContext());
38 | provider.setRotateHelper(rotateHelper);
39 | return provider;
40 | }
41 |
42 |
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/core/PieChart.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.core;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 |
6 | import com.daivd.chart.core.base.BaseRotateChart;
7 | import com.daivd.chart.data.PieData;
8 | import com.daivd.chart.matrix.RotateHelper;
9 | import com.daivd.chart.provider.pie.PieProvider;
10 |
11 | /**
12 | * Created by huang on 2017/10/9.
13 | * 饼图
14 | */
15 |
16 | public class PieChart extends BaseRotateChart {
17 |
18 |
19 | public PieChart(Context context) {
20 | super(context);
21 | }
22 |
23 | public PieChart(Context context, AttributeSet attrs) {
24 | super(context, attrs);
25 | }
26 |
27 | public PieChart(Context context, AttributeSet attrs, int defStyleAttr) {
28 | super(context, attrs, defStyleAttr);
29 | }
30 |
31 |
32 |
33 |
34 | @Override
35 | protected PieProvider initProvider(RotateHelper rotateHelper) {
36 | PieProvider provider = new PieProvider();
37 | provider.setRotateHelper(rotateHelper);
38 | return provider;
39 | }
40 |
41 |
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/core/RadarChart.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.core;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 |
6 | import com.daivd.chart.core.base.BaseRotateChart;
7 | import com.daivd.chart.data.RadarData;
8 | import com.daivd.chart.matrix.RotateHelper;
9 | import com.daivd.chart.provider.radar.RadarProvider;
10 |
11 | /**
12 | * Created by huang on 2017/10/9.
13 | * 雷达图
14 | */
15 |
16 | public class RadarChart extends BaseRotateChart implements RotateHelper.OnRotateListener{
17 |
18 |
19 | public RadarChart(Context context) {
20 | super(context);
21 | }
22 |
23 | public RadarChart(Context context, AttributeSet attrs) {
24 | super(context, attrs);
25 | }
26 |
27 | public RadarChart(Context context, AttributeSet attrs, int defStyleAttr) {
28 | super(context, attrs, defStyleAttr);
29 | }
30 |
31 |
32 |
33 |
34 | @Override
35 | protected RadarProvider initProvider(RotateHelper rotateHelper) {
36 | RadarProvider provider = new RadarProvider();
37 | provider.setRotateHelper(rotateHelper);
38 | return provider;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/core/RoseChart.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.core;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 |
6 | import com.daivd.chart.core.base.BaseRotateChart;
7 | import com.daivd.chart.data.RoseData;
8 | import com.daivd.chart.matrix.RotateHelper;
9 | import com.daivd.chart.provider.rose.RoseProvider;
10 |
11 | /**
12 | * Created by huang on 2017/10/9.
13 | * 饼图
14 | */
15 |
16 | public class RoseChart extends BaseRotateChart {
17 |
18 |
19 | public RoseChart(Context context) {
20 | super(context);
21 | }
22 |
23 | public RoseChart(Context context, AttributeSet attrs) {
24 | super(context, attrs);
25 | }
26 |
27 | public RoseChart(Context context, AttributeSet attrs, int defStyleAttr) {
28 | super(context, attrs, defStyleAttr);
29 | }
30 |
31 |
32 |
33 | @Override
34 | protected RoseProvider initProvider(RotateHelper rotateHelper) {
35 | RoseProvider provider = new RoseProvider();
36 | provider.setRotateHelper(rotateHelper);
37 | return provider;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/core/base/BaseBarLineChart.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.core.base;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Rect;
6 | import android.os.Build;
7 | import android.util.AttributeSet;
8 |
9 | import com.daivd.chart.component.axis.HorizontalAxis;
10 | import com.daivd.chart.component.base.IAxis;
11 | import com.daivd.chart.component.axis.VerticalAxis;
12 | import com.daivd.chart.data.BarData;
13 | import com.daivd.chart.provider.IProvider;
14 |
15 |
16 | /**
17 | * Created by huang on 2017/9/26.
18 | * 线性和柱状图
19 | */
20 |
21 | public abstract class BaseBarLineChart,C extends BarData> extends BaseChart
{
22 |
23 |
24 | protected HorizontalAxis horizontalAxis; //横轴
25 | protected VerticalAxis leftVerticalAxis;//竖轴
26 | protected VerticalAxis rightVerticalAxis;//竖轴
27 |
28 |
29 | public BaseBarLineChart(Context context) {
30 | super(context);
31 |
32 | }
33 |
34 | public BaseBarLineChart(Context context, AttributeSet attrs) {
35 | super(context, attrs);
36 |
37 | }
38 |
39 | public BaseBarLineChart(Context context, AttributeSet attrs, int defStyleAttr) {
40 | super(context, attrs, defStyleAttr);
41 | }
42 |
43 |
44 | protected void init(){
45 | horizontalAxis = new HorizontalAxis();
46 | leftVerticalAxis = new VerticalAxis(IAxis.AxisDirection.LEFT);
47 | rightVerticalAxis = new VerticalAxis(IAxis.AxisDirection.RIGHT);
48 | super.init();
49 |
50 | }
51 |
52 |
53 |
54 | protected void drawContent(Canvas canvas){
55 | horizontalAxis.computeScale(chartData, chartRect, paint);
56 | if (chartData.getScaleData().isLeftHasValue)
57 | leftVerticalAxis.computeScale(chartData, chartRect, paint);
58 | if (chartData.getScaleData().isRightHasValue)
59 | rightVerticalAxis.computeScale(chartData, chartRect, paint);
60 | if (chartData.getScaleData().isLeftHasValue)
61 | leftVerticalAxis.draw(canvas, chartRect, matrixHelper, paint, chartData);
62 | if (chartData.getScaleData().isRightHasValue)
63 | rightVerticalAxis.draw(canvas, chartRect, matrixHelper, paint, chartData);
64 | horizontalAxis.draw(canvas, chartRect, matrixHelper, paint, chartData);
65 | computeScaleRect();
66 | provider.drawProvider(canvas, chartRect, matrixHelper, paint);
67 | }
68 |
69 |
70 |
71 | /**
72 | * 计算绘制刻度之后的大小
73 | */
74 | private void computeScaleRect(){
75 |
76 | Rect rect = chartData.getScaleData().scaleRect;
77 | computeChartRect(rect);
78 | }
79 |
80 |
81 | public void setHeightPercent(){
82 |
83 | }
84 |
85 |
86 |
87 | public HorizontalAxis getHorizontalAxis() {
88 | return horizontalAxis;
89 | }
90 |
91 |
92 |
93 | public VerticalAxis getLeftVerticalAxis() {
94 | return leftVerticalAxis;
95 | }
96 |
97 |
98 |
99 | public VerticalAxis getRightVerticalAxis() {
100 | return rightVerticalAxis;
101 | }
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/core/base/BaseRotateChart.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.core.base;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.os.Build;
6 | import android.util.AttributeSet;
7 | import android.view.MotionEvent;
8 |
9 | import com.daivd.chart.data.ColumnData;
10 | import com.daivd.chart.matrix.RotateHelper;
11 | import com.daivd.chart.provider.IProvider;
12 |
13 | /**
14 | * Created by huang on 2017/10/9.
15 | * 饼图
16 | */
17 |
18 | public abstract class BaseRotateChart
,C extends ColumnData> extends BaseChart
implements RotateHelper.OnRotateListener{
19 | private RotateHelper rotateHelper;
20 | private boolean isOnRotate;
21 |
22 | public BaseRotateChart(Context context) {
23 | super(context);
24 | }
25 |
26 | public BaseRotateChart(Context context, AttributeSet attrs) {
27 | super(context, attrs);
28 | }
29 |
30 | public BaseRotateChart(Context context, AttributeSet attrs, int defStyleAttr) {
31 | super(context, attrs, defStyleAttr);
32 | }
33 |
34 |
35 |
36 | @Override
37 | protected void drawContent(Canvas canvas) {
38 | provider.drawProvider(canvas, chartRect, matrixHelper, paint);
39 | }
40 |
41 | @Override
42 | protected P initProvider() {
43 | rotateHelper = new RotateHelper(this);
44 | return initProvider(rotateHelper);
45 | }
46 |
47 | protected abstract P initProvider(RotateHelper rotateHelper);
48 |
49 | @Override
50 | public boolean onTouchEvent(MotionEvent event) {
51 | if(event.getAction()== MotionEvent.ACTION_DOWN){
52 | isOnRotate = rotateHelper.containsPoint(event);
53 | }
54 | if(isOnRotate){
55 | super.onTouchEvent(event);
56 | return rotateHelper.handlerTouchEvent(event);
57 | }
58 | return super.onTouchEvent(event);
59 | }
60 |
61 | @Override
62 | public boolean dispatchTouchEvent(MotionEvent event) {
63 | if(isOnRotate){
64 | rotateHelper.onDisallowInterceptEvent(this,event);
65 | }
66 | return super.dispatchTouchEvent(event);
67 |
68 | }
69 |
70 | public void setRotate(boolean rotate) {
71 | if(rotate){
72 | setZoom(false);
73 | }
74 | rotateHelper.setRotate(rotate);
75 | }
76 |
77 | @Override
78 | public void onRotate(double angle) {
79 | invalidate();
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/data/BarData.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.data;
2 |
3 | import com.daivd.chart.component.base.IAxis;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * Created by huang on 2017/9/26.
9 | */
10 |
11 | public class BarData extends ColumnData> {
12 |
13 |
14 |
15 |
16 |
17 | public BarData(String name, String unit, int color, List chartYDataList) {
18 |
19 | super(name,unit,color,chartYDataList);
20 | }
21 | public BarData(String name, String unit, int direction, int color, List datas) {
22 | super(name,unit,direction,color,datas);
23 |
24 | }
25 |
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/data/BarLineData.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.data;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by huang on 2017/10/19.
7 | */
8 |
9 | public class BarLineData extends BarData {
10 | public static final int BROKEN= 0;
11 | public static final int CURVE = 1;
12 | public static final int BAR = 2;
13 |
14 | private int model = BAR;
15 |
16 | public BarLineData(String name, String unit, int color, List chartYDataList) {
17 | super(name, unit, color, chartYDataList);
18 | }
19 |
20 | public BarLineData(String name, int model,String unit, int color,List chartYDataList) {
21 | super(name, unit, color, chartYDataList);
22 | this.model = model;
23 | }
24 | public BarLineData(String name, String unit, int direction, int color, List datas) {
25 | super(name, unit, direction, color, datas);
26 | }
27 |
28 |
29 | public BarLineData(String name,int model, String unit, int direction, int color, List datas) {
30 | super(name, unit, direction, color, datas);
31 | this.model = model;
32 | }
33 |
34 | public int getModel() {
35 | return model;
36 | }
37 |
38 | public void setModel(int model) {
39 | this.model = model;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/data/ChartData.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.data;
2 |
3 | import java.util.Arrays;
4 | import java.util.List;
5 |
6 | /**
7 | * Created by huang on 2017/9/26.
8 | * chart data
9 | */
10 |
11 | public class ChartData {
12 |
13 | private String chartName;
14 | private List charXDataList;
15 | private ScaleData scaleData = new ScaleData();
16 | private List columnDataList;
17 |
18 | public ChartData(String chartName,List charXDataList, T... columnDataList){
19 | this.chartName = chartName;
20 | this.charXDataList = charXDataList;
21 | this.columnDataList = Arrays.asList(columnDataList);
22 | }
23 |
24 | public ChartData(String chartName,List charXDataList, List columnDataList){
25 | this.chartName = chartName;
26 | this.charXDataList = charXDataList;
27 | this.columnDataList = columnDataList;
28 | }
29 | public String getChartName() {
30 | return chartName;
31 | }
32 |
33 | public void setChartName(String chartName) {
34 | this.chartName = chartName;
35 | }
36 |
37 | public boolean isEmpty() {
38 | return columnDataList== null || this.columnDataList.size() ==0 ;
39 | }
40 |
41 | public List getCharXDataList() {
42 | return charXDataList;
43 | }
44 |
45 | public void setCharXDataList(List charXDataList) {
46 | this.charXDataList = charXDataList;
47 | }
48 |
49 | public ScaleData getScaleData() {
50 | return scaleData;
51 | }
52 |
53 | public void setScaleData(ScaleData scaleData) {
54 | this.scaleData = scaleData;
55 | }
56 |
57 | public List getColumnDataList() {
58 | return columnDataList;
59 | }
60 |
61 | public void setColumnDataList(List columnDataList) {
62 | this.columnDataList = columnDataList;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/data/ColumnData.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.data;
2 |
3 | import com.daivd.chart.component.base.IAxis;
4 |
5 | /**
6 | * Created by huang on 2017/9/26.
7 | */
8 |
9 | public class ColumnData {
10 |
11 | public String name;
12 |
13 | private String unit;
14 | private int color;
15 | private boolean isDraw = true;
16 | private int direction = IAxis.AxisDirection.LEFT;
17 | private T chartYDataList;
18 |
19 |
20 | public ColumnData(String name, String unit, int color, T chartYDataList) {
21 | this.name = name;
22 | this.unit = unit;
23 | this.color = color;
24 | this.chartYDataList = chartYDataList;
25 | }
26 | public ColumnData(String name, String unit, int direction, int color, T datas) {
27 |
28 | this.name = name;
29 | this.unit = unit;
30 | this.color = color;
31 | this.chartYDataList = datas;
32 | if(direction == IAxis.AxisDirection.LEFT || direction == IAxis.AxisDirection.RIGHT){
33 | this.direction = direction;
34 | }
35 | }
36 |
37 | public int getDirection() {
38 | return direction;
39 | }
40 |
41 | public void setDirection(int direction) {
42 | this.direction = direction;
43 | }
44 |
45 | public String getName() {
46 | return name;
47 | }
48 |
49 | public void setName(String name) {
50 | this.name = name;
51 | }
52 |
53 | public String getUnit() {
54 | return unit;
55 | }
56 |
57 | public void setUnit(String unit) {
58 | this.unit = unit;
59 | }
60 |
61 | public int getColor() {
62 | return color;
63 | }
64 |
65 | public void setColor(int color) {
66 | this.color = color;
67 | }
68 |
69 | public T getChartYDataList() {
70 | return chartYDataList;
71 | }
72 |
73 | public void setChartYDataList(T chartYDataList) {
74 | this.chartYDataList = chartYDataList;
75 | }
76 |
77 | public boolean isDraw() {
78 | return isDraw;
79 | }
80 |
81 | public void setDraw(boolean draw) {
82 | isDraw = draw;
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/data/LineData.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.data;
2 |
3 | import com.daivd.chart.data.style.LineStyle;
4 | import com.daivd.chart.provider.component.line.ILineModel;
5 | import com.daivd.chart.provider.component.point.IPoint;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * Created by huang on 2017/9/26.
11 | */
12 |
13 | public class LineData extends BarData {
14 |
15 | private IPoint point;
16 | private ILineModel lineModel;
17 | private LineStyle lineStyle;
18 |
19 |
20 |
21 | public LineData(String name, String unit, int color, List chartYDataList) {
22 |
23 | super(name,unit,color,chartYDataList);
24 | }
25 | public LineData(String name, String unit, int direction, int color, List datas) {
26 | super(name,unit,direction,color,datas);
27 | }
28 |
29 | public IPoint getPoint() {
30 | return point;
31 | }
32 |
33 | public void setPoint(IPoint point) {
34 | this.point = point;
35 | }
36 |
37 | public ILineModel getLineModel() {
38 | return lineModel;
39 | }
40 |
41 | public void setLineModel(ILineModel lineModel) {
42 | this.lineModel = lineModel;
43 | }
44 |
45 | public LineStyle getLineStyle() {
46 | return lineStyle;
47 | }
48 |
49 | public void setLineStyle(LineStyle lineStyle) {
50 | this.lineStyle = lineStyle;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/data/PicOption.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.data;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | /**
6 | * Created by huang on 2017/10/30.
7 | * 保存图片Option
8 | */
9 |
10 | public class PicOption {
11 |
12 | private String fileName;
13 | private String subFolderPath ="chart";
14 | private String fileDescription="chart pic";
15 | private Bitmap.CompressFormat format= Bitmap.CompressFormat.PNG;
16 | private int quality = 100;
17 |
18 | public PicOption(String fileName) {
19 | this.fileName = fileName;
20 | }
21 |
22 | public String getFileName() {
23 | return fileName;
24 | }
25 |
26 |
27 |
28 | public String getSubFolderPath() {
29 | return subFolderPath;
30 | }
31 |
32 | public PicOption setSubFolderPath(String subFolderPath) {
33 | this.subFolderPath = subFolderPath;
34 | return this;
35 | }
36 |
37 | public String getFileDescription() {
38 | return fileDescription;
39 | }
40 |
41 | public PicOption setFileDescription(String fileDescription) {
42 | this.fileDescription = fileDescription;
43 | return this;
44 | }
45 |
46 | public Bitmap.CompressFormat getFormat() {
47 | return format;
48 | }
49 |
50 | public PicOption setFormat(Bitmap.CompressFormat format) {
51 | this.format = format;
52 | return this;
53 | }
54 |
55 | public int getQuality() {
56 | return quality;
57 | }
58 |
59 | public PicOption setQuality(int quality) {
60 | this.quality = quality;
61 | return this;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/data/PieData.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.data;
2 |
3 | import com.daivd.chart.component.base.IAxis;
4 |
5 | /**
6 | * Created by huang on 2017/9/26.
7 | */
8 |
9 | public class PieData extends ColumnData {
10 |
11 |
12 | public PieData(String name, String unit, int color, Double chartYDataList) {
13 |
14 | super(name, unit, color, chartYDataList);
15 | }
16 |
17 | public PieData(String name, String unit, IAxis.AxisDirection direction, int color, Double datas) {
18 | super(name, unit, color, datas);
19 |
20 | }
21 |
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/data/RadarData.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.data;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by huang on 2017/9/26.
7 | */
8 |
9 | public class RadarData extends BarData {
10 |
11 |
12 | public RadarData(String name, String unit, int color, List chartYDataList) {
13 |
14 | super(name,unit,color,chartYDataList);
15 | }
16 |
17 |
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/data/RoseData.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.data;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by huang on 2017/9/26.
7 | */
8 |
9 | public class RoseData extends BarData {
10 |
11 |
12 | public RoseData(String name, String unit, int color, List chartYDataList) {
13 |
14 | super(name,unit,color,chartYDataList);
15 | }
16 |
17 |
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/data/ScaleData.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.data;
2 |
3 | import android.graphics.Rect;
4 |
5 | import com.daivd.chart.component.base.IAxis;
6 | import com.daivd.chart.matrix.MatrixHelper;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | /**
12 | * Created by huang on 2017/9/26.
13 | * Scale data
14 | */
15 |
16 | public class ScaleData {
17 |
18 | public boolean isLeftHasValue = false;
19 | public boolean isRightHasValue = false;
20 | //竖轴数据
21 | public double maxLeftValue; //最大值
22 | public double minLeftValue; //最小值
23 |
24 | //竖轴数据
25 | public double maxRightValue; //最大值
26 | public double minRightValue; //最小值
27 |
28 | public int totalScale = 5; //刻度数量
29 |
30 | public Rect scaleRect = new Rect();
31 |
32 | //横轴数据
33 | public int rowSize; //列数据
34 | public float zoom = MatrixHelper.MIN_ZOOM; //放大比例
35 |
36 |
37 | public List getScaleList(int direction){
38 |
39 | List scaleList = new ArrayList<>();
40 | int total = (int) (totalScale *zoom);
41 | double scale = getTotalScaleLength(direction) /(total-1);
42 | double minValue = getMinScaleValue(direction);
43 | for(int i = 0;i < total;i++){
44 | scaleList.add(minValue +scale*i);
45 | }
46 | return scaleList;
47 | }
48 |
49 | /**
50 | * 获取最大刻度
51 | * @param direction
52 | * @return
53 | */
54 | public double getMaxScaleValue(int direction){
55 | if(direction == IAxis.AxisDirection.LEFT){
56 | return maxLeftValue;
57 | }
58 | return maxRightValue;
59 | }
60 |
61 | /**
62 | * 获取最小刻度
63 | * @param direction
64 | * @return
65 | */
66 | public double getMinScaleValue(int direction){
67 | if(direction == IAxis.AxisDirection.LEFT){
68 | return minLeftValue;
69 | }
70 | return minRightValue;
71 | }
72 |
73 | /**
74 | *获取总刻度值
75 | * @param direction 方向
76 | * @return 总刻度
77 | */
78 | public double getTotalScaleLength(int direction){
79 | if(direction == IAxis.AxisDirection.LEFT){
80 | return maxLeftValue - minLeftValue;
81 | }
82 | return maxRightValue - minRightValue;
83 | }
84 |
85 |
86 | public Rect getOffsetRect(Rect rect, Rect offsetRect){
87 | rect.left = rect.left + offsetRect.left;
88 | rect.right = rect.right - offsetRect.right;
89 | rect.top = rect.top + offsetRect.top;
90 | rect.bottom = rect.bottom - offsetRect.bottom;
91 | return rect;
92 |
93 | }
94 |
95 | public void resetScale(ScaleSetData scaleSetData,int direction){
96 | if(direction == IAxis.AxisDirection.LEFT){
97 | if(scaleSetData.isStartZoom()){
98 | minLeftValue = 0;
99 | }else {
100 | if(scaleSetData.isHasMinValue()){
101 | minLeftValue = scaleSetData.getMinValue();
102 | }
103 | }
104 | if(scaleSetData.isHasMaxValue()){
105 | maxLeftValue = scaleSetData.getMaxValue();
106 | }
107 | }else{
108 | if(scaleSetData.isStartZoom()){
109 | minRightValue = 0;
110 | }else {
111 | if(scaleSetData.isHasMinValue()){
112 | minRightValue = scaleSetData.getMinValue();
113 | }
114 | }
115 | if(scaleSetData.isHasMaxValue()){
116 | maxRightValue = scaleSetData.getMaxValue();
117 | }
118 | }
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/data/ScaleSetData.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.data;
2 |
3 | /**
4 | * Created by huang on 2017/10/18.
5 | */
6 |
7 | public class ScaleSetData {
8 |
9 | private boolean isStartZoom;
10 | private boolean isHasMaxValue;
11 | private boolean isHasMinValue;
12 | private double maxValue;
13 | private double minValue;
14 |
15 | public boolean isStartZoom() {
16 | return isStartZoom;
17 | }
18 |
19 | public void setStartZoom(boolean startZoom) {
20 | isHasMinValue = false;
21 | isStartZoom = startZoom;
22 | }
23 |
24 | public boolean isHasMaxValue() {
25 | return isHasMaxValue;
26 | }
27 |
28 | public boolean isHasMinValue() {
29 | return isHasMinValue;
30 | }
31 |
32 |
33 | public double getMaxValue() {
34 | return maxValue;
35 | }
36 |
37 | public void setMaxValue(double maxValue) {
38 | isHasMaxValue = true;
39 | this.maxValue = maxValue;
40 | }
41 |
42 | public double getMinValue() {
43 | return minValue;
44 | }
45 |
46 | public void setMinValue(double minValue) {
47 | isHasMinValue = true;
48 | this.minValue = minValue;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/data/format/IFormat.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.data.format;
2 |
3 | /**
4 | * 格式化
5 | * 用于横轴和竖轴文本格式化
6 | * @author huangyanbin
7 | */
8 |
9 | public interface IFormat {
10 |
11 | String format( T t);
12 | }
13 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/data/style/FontStyle.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.data.style;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.graphics.Paint;
6 |
7 | import com.daivd.chart.utils.DensityUtils;
8 |
9 | /**
10 | * Created by huang on 2017/9/27.
11 | */
12 |
13 | public class FontStyle implements IStyle{
14 |
15 | public static int defaultFontSize = 12;
16 | public static int defaultFontColor = Color.parseColor("#333333");
17 | private int textSize;
18 | private int textColor;
19 | private int padding = 10;
20 |
21 | public static void setDefaultTextSize(int defaultTextSize){
22 | defaultFontSize = defaultTextSize;
23 | }
24 |
25 | public static void setDefaultTextSpSize(Context context,int defaultTextSpSize){
26 | defaultFontSize = DensityUtils.sp2px(context,defaultTextSpSize);
27 | }
28 | public static void setDefaultTextColor(int defaultTextColor){
29 | defaultFontColor = defaultTextColor;
30 | }
31 |
32 | public FontStyle() {
33 | }
34 |
35 | public FontStyle(int textSize, int textColor) {
36 | this.textSize = textSize;
37 | this.textColor = textColor;
38 | }
39 |
40 | public FontStyle(Context context,int sp, int textColor) {
41 | this.textSize = DensityUtils.sp2px(context,sp);
42 | this.textColor = textColor;
43 | }
44 |
45 |
46 |
47 |
48 | public int getTextSize() {
49 | if(textSize == 0){
50 | return defaultFontSize;
51 | }
52 | return textSize;
53 | }
54 |
55 | public FontStyle setTextSize(int textSize) {
56 | this.textSize = textSize;
57 | return this;
58 | }
59 |
60 | public FontStyle setTextSpSize(Context context,int sp){
61 | this.setTextSize(DensityUtils.sp2px(context,sp));
62 | return this;
63 | }
64 |
65 | public int getTextColor() {
66 | if(textColor == 0){
67 | return defaultFontColor;
68 | }
69 | return textColor;
70 | }
71 |
72 | public FontStyle setTextColor(int textColor) {
73 |
74 | this.textColor = textColor;
75 | return this;
76 | }
77 |
78 | public int getPadding() {
79 | return padding;
80 | }
81 |
82 | public void setPadding(int padding) {
83 | this.padding = padding;
84 | }
85 | @Override
86 | public void fillPaint(Paint paint){
87 | paint.setColor(getTextColor());
88 | paint.setTextSize(getTextSize());
89 | paint.setStyle(Paint.Style.FILL);
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/data/style/IStyle.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.data.style;
2 |
3 | import android.graphics.Paint;
4 |
5 | /**
6 | * Created by huang on 2017/9/27.
7 | */
8 |
9 | public interface IStyle {
10 |
11 | void fillPaint(Paint paint);
12 | }
13 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/data/style/LineStyle.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.data.style;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.graphics.DashPathEffect;
6 | import android.graphics.Paint;
7 | import android.graphics.PathEffect;
8 |
9 | import com.daivd.chart.utils.DensityUtils;
10 |
11 | /**
12 | * Created by huang on 2017/9/27.
13 | */
14 |
15 | public class LineStyle implements IStyle {
16 |
17 | private float width;
18 | private int color;
19 | private PathEffect effect = new PathEffect();
20 | private static float defaultLineSize = 2f;
21 | private static int defaultLineColor = Color.parseColor("#888888");
22 |
23 | public LineStyle() {
24 | }
25 |
26 | public LineStyle(float width, int color) {
27 | this.width = width;
28 | this.color = color;
29 | }
30 | public LineStyle(Context context,float dp, int color) {
31 | this.width = DensityUtils.dp2px(context,dp);
32 | this.color = color;
33 | }
34 | public static void setDefaultLineSize(float width){
35 | defaultLineSize = width;
36 | }
37 |
38 | public static void setDefaultLineSize(Context context,float dp){
39 | defaultLineSize = DensityUtils.dp2px(context,dp);
40 | }
41 |
42 | public static void setDefaultLineColor(int color){
43 | defaultLineColor = color;
44 | }
45 |
46 | public float getWidth() {
47 | if(width == 0){
48 | return defaultLineSize;
49 | }
50 | return width;
51 | }
52 |
53 |
54 |
55 | public LineStyle setWidth(float width) {
56 | this.width = width;
57 | return this;
58 | }
59 | public LineStyle setWidth(Context context,int dp) {
60 | this.width = DensityUtils.dp2px(context,dp);
61 | return this;
62 | }
63 |
64 | public int getColor() {
65 | if(color == 0){
66 | return defaultLineColor;
67 | }
68 | return color;
69 | }
70 |
71 | public LineStyle setColor(int color) {
72 |
73 | this.color = color;
74 | return this;
75 | }
76 |
77 | public LineStyle setEffect(PathEffect effect) {
78 | this.effect = effect;
79 | return this;
80 | }
81 |
82 | @Override
83 | public void fillPaint(Paint paint){
84 | paint.setColor(getColor());
85 | paint.setStyle(Paint.Style.STROKE);
86 | paint.setStrokeWidth(getWidth());
87 | paint.setPathEffect(effect);
88 |
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/data/style/PointStyle.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.data.style;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.graphics.DashPathEffect;
6 | import android.graphics.Paint;
7 |
8 | import com.daivd.chart.utils.DensityUtils;
9 |
10 | /**
11 | * Created by huang on 2017/9/27.
12 | */
13 |
14 | public class PointStyle implements IStyle {
15 |
16 | public static final int CIRCLE = 0;
17 | public static final int SQUARE = 1;
18 | public static final int RECT = 2;
19 | private float width;
20 | private int color;
21 | private int shape;
22 | private Paint.Style style;
23 | private static float defaultPointSize = 10f;
24 | private static int defaultPointColor = Color.parseColor("#888888");
25 | private boolean isDraw = true;
26 | public PointStyle() {
27 | }
28 |
29 | public PointStyle(float width, int color) {
30 | this.width = width;
31 | this.color = color;
32 | }
33 | public PointStyle(Context context, float dp, int color) {
34 | this.width = DensityUtils.dp2px(context,dp);
35 | this.color = color;
36 | }
37 | public static void setDefaultPointSize(float width){
38 | defaultPointSize = width;
39 | }
40 |
41 | public static void setDefaultLineSize(Context context,float dp){
42 | defaultPointSize = DensityUtils.dp2px(context,dp);
43 | }
44 |
45 | public static void setDefaultPointColor(int color){
46 | defaultPointColor = color;
47 | }
48 |
49 | public float getWidth() {
50 | if(width == 0){
51 | return defaultPointSize;
52 | }
53 | return width;
54 | }
55 |
56 | public void setWidth(float width) {
57 | this.width = width;
58 | }
59 | public void setWidth(Context context,int dp) {
60 | this.width = DensityUtils.dp2px(context,dp);
61 | }
62 |
63 | public int getColor() {
64 | if(color == 0){
65 | return defaultPointColor;
66 | }
67 | return color;
68 | }
69 |
70 | public void setColor(int color) {
71 |
72 | this.color = color;
73 | }
74 |
75 | public int getShape() {
76 | return shape;
77 | }
78 |
79 | public void setShape(int shape) {
80 | this.shape = shape;
81 | }
82 |
83 | public Paint.Style getStyle() {
84 | if(style == null){
85 | return Paint.Style.FILL;
86 | }
87 | return style;
88 | }
89 |
90 | public void setStyle(Paint.Style style) {
91 | this.style = style;
92 | }
93 |
94 | public boolean isDraw() {
95 | return isDraw;
96 | }
97 |
98 | public void setDraw(boolean draw) {
99 | isDraw = draw;
100 | }
101 |
102 | @Override
103 | public void fillPaint(Paint paint){
104 | paint.setColor(getColor());
105 | paint.setStyle(getStyle());
106 | paint.setStrokeWidth(getWidth());
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/exception/ChartException.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.exception;
2 |
3 | /**
4 | * Created by huang on 2017/9/26.
5 | */
6 |
7 | public class ChartException extends RuntimeException {
8 |
9 | public ChartException(String message) {
10 | super(message);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/listener/ChartGestureObserver.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.listener;
2 |
3 | /**
4 | * Created by huang on 2017/9/29.
5 | */
6 |
7 | public interface ChartGestureObserver {
8 |
9 | void onClick(float x,float y);
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/listener/Observable.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.listener;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | /**
7 | * Created by huang on 2017/9/29.
8 | */
9 |
10 | public abstract class Observable {
11 |
12 | public final ArrayList observables = new ArrayList<>();
13 |
14 | /**AttachObserver(通过实例注册观察者)
15 | **/
16 | public void register(T observer){
17 | if(observer==null) throw new NullPointerException();
18 | synchronized(observables){
19 | if(!observables.contains(observer)){
20 | observables.add(observer);
21 | }
22 | }
23 | }
24 |
25 |
26 |
27 | /**UnattachObserver(注销观察者)
28 | **/
29 | public void unRegister(T observer){
30 | if(observer==null) throw new NullPointerException();
31 | if(observables.contains(observer)){
32 | observables.remove(observer);
33 | }
34 | }
35 |
36 |
37 | public void unRegisterAll(){
38 | synchronized(observables){
39 | observables.clear();
40 | }
41 | }
42 |
43 | /**Ruturnthesizeofobservers*/
44 | public int countObservers(){
45 | synchronized(observables){
46 | return observables.size();
47 | }
48 | }
49 |
50 | /**
51 | *notify all observer(通知所有观察者,在子类中实现)
52 | */
53 | public abstract void notifyObservers(List observers);
54 |
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/listener/OnChartChangeListener.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.listener;
2 |
3 | /**
4 | * Created by huang on 2017/11/4.
5 | */
6 |
7 | public interface OnChartChangeListener {
8 |
9 | void onTableChanged(float translateX, float translateY);
10 | }
11 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/listener/OnClickColumnListener.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.listener;
2 |
3 | import com.daivd.chart.data.ColumnData;
4 |
5 | /**
6 | * Created by huang on 2017/9/30.
7 | */
8 |
9 | public interface OnClickColumnListener {
10 |
11 | void onClickColumn(C c,int position);
12 | }
13 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/listener/OnClickLegendListener.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.listener;
2 |
3 | import com.daivd.chart.component.Legend;
4 | import com.daivd.chart.data.ColumnData;
5 |
6 | /**
7 | * Created by huang on 2017/9/30.
8 | */
9 |
10 | public interface OnClickLegendListener {
11 |
12 | void onClickLegend(C c, Legend legend);
13 | }
14 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/matrix/ITouch.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.matrix;
2 |
3 | import android.view.MotionEvent;
4 |
5 | import com.daivd.chart.core.base.BaseChart;
6 |
7 | /**
8 | * Created by huang on 2017/10/18.
9 | */
10 |
11 | public interface ITouch {
12 | /**
13 | * 用于判断是否请求不拦截事件
14 | * 解决手势冲突问题
15 | * @param chart
16 | * @param event
17 | */
18 | void onDisallowInterceptEvent(BaseChart chart, MotionEvent event);
19 |
20 | /**
21 | * 处理touchEvent
22 | * @param event
23 | */
24 | boolean handlerTouchEvent(MotionEvent event);
25 | }
26 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/matrix/PointEvaluator.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.matrix;
2 |
3 | import android.animation.TypeEvaluator;
4 | import android.graphics.Point;
5 |
6 | /**
7 | * Created by huang on 2017/11/3.
8 | */
9 | public class PointEvaluator implements TypeEvaluator {
10 |
11 | private Point point = new Point();
12 |
13 | @Override
14 | public Object evaluate(float fraction, Object startValue, Object endValue) {
15 | Point startPoint = (Point) startValue;
16 | Point endPoint = (Point) endValue;
17 | int x = (int) (startPoint.x + fraction * (endPoint.x - startPoint.x));
18 | int y = (int) (startPoint.y + fraction * (endPoint.y - startPoint.y));
19 | point.set(x,y);
20 | return point;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/provider/IProvider.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.provider;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.PointF;
6 | import android.graphics.Rect;
7 | import android.view.animation.Interpolator;
8 |
9 | import com.daivd.chart.core.base.BaseChart;
10 | import com.daivd.chart.data.ChartData;
11 | import com.daivd.chart.data.ColumnData;
12 | import com.daivd.chart.listener.OnClickColumnListener;
13 | import com.daivd.chart.provider.component.mark.IMark;
14 | import com.daivd.chart.matrix.MatrixHelper;
15 |
16 |
17 | /**
18 | * Created by huang on 2017/9/26.
19 | */
20 |
21 | public interface IProvider {
22 |
23 | boolean calculation( ChartData chartData);
24 |
25 | void drawProvider(Canvas canvas, Rect rect, MatrixHelper helper, Paint paint);
26 |
27 | void clickPoint(PointF point);
28 | void startAnim(BaseChart chartView, int duration, Interpolator interpolator);
29 |
30 | void setMarkView(IMark markView);
31 |
32 | void setOnClickColumnListener(OnClickColumnListener onClickColumnListener);
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/provider/barLine/Bar3DProvider.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.provider.barLine;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.Path;
6 | import android.graphics.Rect;
7 |
8 | import com.daivd.chart.data.BarData;
9 |
10 |
11 | /**柱状内容绘制
12 | * Created by huang on 2017/9/26.
13 | */
14 |
15 | public class Bar3DProvider extends BarProvider {
16 |
17 | /**
18 | * 绘制柱
19 | * @param canvas 画布
20 | * @param rect 范围
21 | * @param value 数值
22 | * @param position 位置
23 | * @param line 线位置
24 | * @param paint 画笔
25 | */
26 | @Override
27 | protected void drawBar(Canvas canvas,Rect rect,double value,int position,int line,Paint paint){
28 | canvas.drawRect(rect, paint);
29 | float w = rect.right - rect.left;
30 | float offsetY= w/2;
31 | float offsetX = w/3f;
32 | Path path = new Path();
33 | path.moveTo(rect.left,rect.top);
34 | path.lineTo(rect.left+offsetX,rect.top-offsetY);
35 | path.lineTo(rect.right+offsetX,rect.top-offsetY);
36 | path.lineTo(rect.right,rect.top);
37 | path.close();
38 | canvas.drawPath(path,paint);
39 | path.reset();
40 | path.moveTo(rect.right,rect.top);
41 | path.lineTo(rect.right,rect.bottom);
42 | path.lineTo(rect.right+offsetX,rect.bottom-offsetY);
43 | path.lineTo(rect.right+offsetX,rect.top-offsetY);
44 | path.close();
45 | canvas.drawPath(path,paint);
46 | drawPointText(canvas,value,(rect.right + rect.left) / 2, rect.top-offsetY,position,line, paint );
47 |
48 | }
49 |
50 |
51 | @Override
52 | public double[] setMaxMinValue(double maxValue, double minValue) {
53 | double dis = Math.abs(maxValue -minValue);
54 | maxValue = maxValue + dis*0.4;
55 | if(minValue >0){
56 | minValue = 0;
57 | }else{
58 | minValue = minValue - dis*0.4;
59 | }
60 | return new double[]{maxValue,minValue};
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/provider/component/cross/DoubleDriCross.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.provider.component.cross;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.PointF;
6 | import android.graphics.Rect;
7 |
8 | import com.daivd.chart.data.style.LineStyle;
9 |
10 | /**
11 | * Created by huang on 2017/10/19.
12 | * 双方向
13 | */
14 |
15 | public class DoubleDriCross implements ICross{
16 |
17 | LineStyle crossStyle = new LineStyle();
18 | @Override
19 | public void drawCross(Canvas canvas, PointF pointF, Rect rect, Paint paint) {
20 | crossStyle.fillPaint(paint);
21 | canvas.drawLine(pointF.x, rect.top, pointF.x, rect.bottom, paint);
22 | canvas.drawLine(rect.left, pointF.y, rect.right, pointF.y, paint);
23 | }
24 |
25 | public LineStyle getCrossStyle() {
26 | return crossStyle;
27 | }
28 |
29 | public void setCrossStyle(LineStyle crossStyle) {
30 | this.crossStyle = crossStyle;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/provider/component/cross/ICross.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.provider.component.cross;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.PointF;
6 | import android.graphics.Rect;
7 |
8 | /**
9 | * Created by huang on 2017/10/19.
10 | * 十字轴
11 | */
12 |
13 | public interface ICross {
14 |
15 | void drawCross(Canvas canvas, PointF pointF, Rect rect, Paint paint);
16 | }
17 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/provider/component/cross/VerticalCross.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.provider.component.cross;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.PointF;
6 | import android.graphics.Rect;
7 |
8 | import com.daivd.chart.data.style.LineStyle;
9 | import com.daivd.chart.provider.component.point.IPoint;
10 | import com.daivd.chart.provider.component.point.Point;
11 |
12 | /**
13 | * Created by huang on 2017/10/19.
14 | * 竖轴方向
15 | */
16 |
17 | public class VerticalCross implements ICross{
18 |
19 | LineStyle crossStyle = new LineStyle();
20 | IPoint point = new Point();
21 | @Override
22 | public void drawCross(Canvas canvas, PointF pointF, Rect rect, Paint paint) {
23 | crossStyle.fillPaint(paint);
24 | canvas.drawLine(pointF.x, rect.top, pointF.x, rect.bottom, paint);
25 | if(point != null){
26 | point.drawPoint(canvas,pointF.x,pointF.y,0,false,paint);
27 | }
28 | }
29 |
30 | public IPoint getPoint() {
31 | return point;
32 | }
33 |
34 | public void setPoint(IPoint point) {
35 | this.point = point;
36 | }
37 |
38 | public LineStyle getCrossStyle() {
39 | return crossStyle;
40 | }
41 |
42 | public void setCrossStyle(LineStyle crossStyle) {
43 | this.crossStyle = crossStyle;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/provider/component/grid/IGrid.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.provider.component.grid;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.PointF;
6 | import android.graphics.Rect;
7 |
8 | /**
9 | * Created by huang on 2017/12/1.
10 | */
11 |
12 | public interface IGrid {
13 | /**
14 | * 绘制网格
15 | * @param canvas
16 | * @param x
17 | * @param rect
18 | * @param perWidth
19 | * @param paint
20 | */
21 | void drawGrid(Canvas canvas, float x, Rect rect, int perWidth, Paint paint);
22 |
23 | /**
24 | * 绘制点击背景
25 | * @param canvas
26 | * @param pointF
27 | * @param rect
28 | * @param perWidth
29 | * @param paint
30 | */
31 | void drawClickBg(Canvas canvas, PointF pointF, Rect rect, int perWidth, Paint paint);
32 |
33 | /**
34 | * 绘制列内容
35 | * @param canvas
36 | * @param position
37 | * @param rect
38 | * @param perWidth
39 | * @param paint
40 | */
41 | void drawColumnContent(Canvas canvas, int position, Rect zoomRect, Rect rect, int perWidth, Paint paint);
42 | }
43 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/provider/component/level/ILevel.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.provider.component.level;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.Rect;
6 |
7 | /**
8 | * Created by huang on 2017/10/19.
9 | */
10 |
11 | public interface ILevel {
12 |
13 | int getAxisDirection();
14 |
15 | void drawLevel(Canvas canvas, Rect rect, float y, Paint paint);
16 |
17 | double getValue();
18 | }
19 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/provider/component/level/LevelLine.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.provider.component.level;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.Path;
6 | import android.graphics.Rect;
7 |
8 | import com.daivd.chart.component.base.IAxis;
9 | import com.daivd.chart.data.style.FontStyle;
10 | import com.daivd.chart.data.style.LineStyle;
11 |
12 | /**
13 | * Created by huang on 2017/9/30.
14 | * LevelLine
15 | */
16 |
17 | public class LevelLine implements ILevel{
18 | public static int left = 0;
19 | public static int right = 1;
20 | private LineStyle lineStyle = new LineStyle();
21 | private double value;
22 | private int textDirection = right;
23 | private FontStyle textStyle = new FontStyle();
24 | private int direction = IAxis.AxisDirection.LEFT;
25 |
26 | public LevelLine(double value) {
27 | this.value = value;
28 | }
29 |
30 |
31 | public LineStyle getLineStyle() {
32 | return lineStyle;
33 | }
34 |
35 | public void setLineStyle(LineStyle lineStyle) {
36 | this.lineStyle = lineStyle;
37 | }
38 |
39 | public double getValue() {
40 | return value;
41 | }
42 |
43 | public void setValue(double value) {
44 | this.value = value;
45 | }
46 |
47 |
48 | public int getTextDirection() {
49 | return textDirection;
50 | }
51 |
52 | public void setTextDirection(int textDirection) {
53 | this.textDirection = textDirection;
54 | }
55 |
56 | public FontStyle getTextStyle() {
57 | return textStyle;
58 | }
59 |
60 | public int getAxisDirection() {
61 | return direction;
62 | }
63 |
64 | public void setDirection(int direction) {
65 | this.direction = direction;
66 | }
67 |
68 | public void setTextStyle(FontStyle textStyle) {
69 | this.textStyle = textStyle;
70 | }
71 |
72 |
73 |
74 | @Override
75 | public void drawLevel(Canvas canvas, Rect rect, float y, Paint paint) {
76 | getLineStyle().fillPaint(paint);
77 | Path path = new Path();
78 | path.moveTo(rect.left, y);
79 | path.lineTo(rect.right, y);
80 | canvas.drawPath(path, paint);
81 | getTextStyle().fillPaint(paint);
82 | float textHeight = paint.measureText("1", 0, 1);
83 | float startX;
84 | float startY = y - textHeight + getLineStyle().getWidth();
85 | String levelLineValue = String.valueOf(getValue());
86 | if (getTextDirection() == LevelLine.left) {
87 | startX = rect.left;
88 | } else {
89 | startX = rect.right - textHeight * levelLineValue.length();
90 | }
91 | canvas.drawText(levelLineValue, startX, startY, paint);
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/provider/component/line/BrokenLineModel.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.provider.component.line;
2 |
3 | import android.graphics.Path;
4 |
5 | import java.util.List;
6 |
7 |
8 |
9 | public class BrokenLineModel implements ILineModel {
10 |
11 |
12 |
13 | @Override
14 | public Path getLinePath(List pointX, List pointY) {
15 | Path path = new Path();
16 | for(int i = 0; i < pointY.size();i++){
17 | float x = pointX.get(i);
18 | float y = pointY.get(i);
19 | if(i == 0){
20 | path.moveTo(x,y);
21 | }else{
22 | path.lineTo(x,y);
23 | }
24 | }
25 | return path;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/provider/component/line/CurveLineModel.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.provider.component.line;
2 |
3 | import android.graphics.Path;
4 |
5 | import java.util.LinkedList;
6 | import java.util.List;
7 |
8 | /**曲线内容绘制
9 | * Created by huang on 2017/9/27.
10 | */
11 |
12 | public class CurveLineModel implements ILineModel {
13 | private final int STEP = 12;
14 |
15 | @Override
16 | public Path getLinePath(List pointX, List pointY) {
17 | List calculate_x = calculate(pointX);
18 | List calculate_y = calculate(pointY);
19 | Path path = new Path();
20 | if (null != calculate_x && null != calculate_y && calculate_y.size() >= calculate_x.size()) {
21 | path.moveTo(calculate_x.get(0).eval(0), calculate_y.get(0).eval(0));
22 | for (int i = 0; i < calculate_x.size(); i++) {
23 | for (int j = 1; j <= STEP; j++) {
24 | float u = j / (float) STEP;
25 | path.lineTo(calculate_x.get(i).eval(u), calculate_y.get(i).eval(u));
26 | }
27 | }
28 | }
29 | return path;
30 | }
31 |
32 |
33 |
34 | /**
35 | * 计算曲线.
36 | * @param x
37 | * @return
38 | */
39 | private List calculate(List x) {
40 | if (null != x && x.size() > 0) {
41 | int n = x.size() - 1;
42 | float[] gamma = new float[n + 1];
43 | float[] delta = new float[n + 1];
44 | float[] D = new float[n + 1];
45 | int i;
46 | gamma[0] = 1.0f / 2.0f;
47 | for (i = 1; i < n; i++) {
48 | gamma[i] = 1 / (4 - gamma[i - 1]);
49 | }
50 | gamma[n] = 1 / (2 - gamma[n - 1]);
51 |
52 | delta[0] = 3 * (x.get(1) - x.get(0)) * gamma[0];
53 | for (i = 1; i < n; i++) {
54 | delta[i] = (3 * (x.get(i + 1) - x.get(i - 1)) - delta[i - 1]) * gamma[i];
55 | }
56 | delta[n] = (3 * (x.get(n) - x.get(n - 1)) - delta[n - 1]) * gamma[n];
57 |
58 | D[n] = delta[n];
59 | for (i = n - 1; i >= 0; i--) {
60 | D[i] = delta[i] - gamma[i] * D[i + 1];
61 | }
62 |
63 | List cubicList = new LinkedList<>();
64 | for (i = 0; i < n; i++) {
65 | Cubic c = new Cubic(x.get(i), D[i], 3 * (x.get(i + 1) - x.get(i)) - 2 * D[i] - D[i + 1], 2 * (x.get(i) - x.get(i + 1)) + D[i] + D[i + 1]);
66 | cubicList.add(c);
67 | }
68 | return cubicList;
69 | }
70 | return null;
71 | }
72 |
73 |
74 |
75 |
76 | private class Cubic {
77 |
78 | float a, b, c, d; /* a + b*u + c*u^2 +d*u^3 */
79 |
80 | Cubic(float a, float b, float c, float d) {
81 | this.a = a;
82 | this.b = b;
83 | this.c = c;
84 | this.d = d;
85 | }
86 |
87 | /** evaluate cubic */
88 | float eval(float u) {
89 | return (((d * u) + c) * u + b) * u + a;
90 | }
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/provider/component/line/ILineModel.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.provider.component.line;
2 |
3 | import android.graphics.Path;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * Created by huang on 2017/10/15.
9 | */
10 |
11 | public interface ILineModel {
12 |
13 | Path getLinePath(List pointX, List pointY);
14 | }
15 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/provider/component/mark/BubbleMarkView.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.provider.component.mark;
2 |
3 |
4 | import android.content.Context;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.Paint;
8 | import android.graphics.Rect;
9 |
10 | import com.daivd.chart.provider.component.tip.SingleLineBubbleTip;
11 | import com.daivd.chart.data.BarData;
12 | import com.daivd.chart.utils.DensityUtils;
13 | import com.david.chart.R;
14 |
15 | /**
16 | * Created by huang on 2017/9/28.
17 | */
18 |
19 | public class BubbleMarkView implements IMark {
20 |
21 | private SingleLineBubbleTip bubbleTip;
22 | private Paint paint;
23 |
24 | public BubbleMarkView(Context context) {
25 | paint = new Paint();
26 | paint.setAntiAlias(true);
27 | paint.setTextSize(DensityUtils.sp2px(context,13));
28 | paint.setStyle(Paint.Style.FILL);
29 | paint.setColor(Color.WHITE);
30 | bubbleTip = new SingleLineBubbleTip(context,R.mipmap.round_rect,R.mipmap.triangle,paint){
31 |
32 | @Override
33 | public boolean isShowTip(String s,int position) {
34 | return true;
35 | }
36 |
37 | @Override
38 | public String format(String s, int position) {
39 | return s;
40 | }
41 | };
42 | }
43 |
44 |
45 |
46 | public Paint getPaint() {
47 | return paint;
48 | }
49 |
50 | @Override
51 | public void drawMark(Canvas canvas, float x, float y, Rect rect, String content, BarData data, int position) {
52 |
53 | String text = content + data.getChartYDataList().get(position) + data.getUnit();
54 | bubbleTip.drawTip(canvas, x, y, rect, text,position);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/provider/component/mark/IMark.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.provider.component.mark;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Rect;
5 |
6 | import com.daivd.chart.data.ColumnData;
7 |
8 | /**
9 | * Created by huang on 2017/9/28.
10 | */
11 |
12 | public interface IMark {
13 | /**
14 | * 绘制Mark
15 | */
16 | void drawMark(Canvas canvas,float x, float y,Rect rect, String content, C data, int position);
17 | }
18 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/provider/component/path/IPath.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.provider.component.path;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.Path;
6 | import android.graphics.Rect;
7 |
8 | /**
9 | * Created by huang on 2017/11/30.
10 | */
11 |
12 | public interface IPath {
13 |
14 | void drawPath(Canvas canvas, Rect rect, Path path, int perWidth, Paint paint, float progress);
15 | }
16 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/provider/component/path/LinePath.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.provider.component.path;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.Path;
6 | import android.graphics.Rect;
7 |
8 | /**
9 | * Created by huang on 2017/11/30.
10 | */
11 |
12 | public class LinePath implements IPath{
13 |
14 | public void drawPath(Canvas canvas, Rect rect, Path path, int perWidth, Paint paint,float progress){
15 | canvas.drawPath(path, paint);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/provider/component/point/ILegendPoint.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.provider.component.point;
2 |
3 | /**
4 | * Created by huang on 2017/12/13.
5 | */
6 |
7 | public interface ILegendPoint extends IPoint{
8 |
9 | float getWidth();
10 | float getHeight();
11 | }
12 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/provider/component/point/IPoint.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.provider.component.point;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 |
6 | /**
7 | * Created by huang on 2017/10/20.
8 | */
9 |
10 | public interface IPoint {
11 |
12 | void drawPoint(Canvas canvas, float x, float y, int position, boolean isShowDefaultColor, Paint paint);
13 |
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/provider/component/point/LegendPoint.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.provider.component.point;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 |
6 | import com.daivd.chart.data.style.PointStyle;
7 |
8 |
9 | /**
10 | * Created by huang on 2017/10/20.
11 | */
12 |
13 | public class LegendPoint implements ILegendPoint {
14 |
15 | private PointStyle pointStyle = new PointStyle();
16 |
17 | public void drawPoint(Canvas canvas, float x, float y, int position,boolean isShowDefaultColor, Paint paint){
18 | float w = pointStyle.getWidth();
19 | if(isShowDefaultColor){
20 | pointStyle.fillPaint(paint);
21 | }else {
22 | int oldColor =paint.getColor();
23 | pointStyle.fillPaint(paint);
24 | paint.setColor(oldColor);
25 | }
26 | if (pointStyle.getShape() == PointStyle.CIRCLE) {
27 | canvas.drawCircle(x, y, w/2, paint);
28 | } else if (pointStyle.getShape() == PointStyle.SQUARE) {
29 | canvas.drawRect(x - w/2 , y - w/2 , x + w/2, y + w/2 , paint);
30 | } else if (pointStyle.getShape() == PointStyle.RECT) {
31 | canvas.drawRect(x - w * 2 / 3, y - w/2 , x + w * 2 / 3, y + w/2, paint);
32 | }
33 | }
34 |
35 |
36 | @Override
37 | public float getWidth() {
38 | if(pointStyle.getShape() == PointStyle.RECT){
39 | return pointStyle.getWidth() * 4/ 3;
40 | }
41 | return pointStyle.getWidth();
42 | }
43 |
44 | @Override
45 | public float getHeight() {
46 |
47 | return pointStyle.getWidth();
48 | }
49 |
50 |
51 | public PointStyle getPointStyle() {
52 | return pointStyle;
53 | }
54 |
55 |
56 | }
57 |
58 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/provider/component/point/Point.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.provider.component.point;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 |
6 | import com.daivd.chart.data.style.PointStyle;
7 |
8 | /**
9 | * Created by huang on 2017/10/20.
10 | */
11 |
12 | public class Point implements IPoint {
13 |
14 | private PointStyle pointStyle = new PointStyle();
15 |
16 | public void drawPoint(Canvas canvas,float x, float y,int position,boolean isShowDefaultColor, Paint paint){
17 | float w = pointStyle.getWidth();
18 | if(isShowDefaultColor){
19 | pointStyle.fillPaint(paint);
20 | }else {
21 | int oldColor =paint.getColor();
22 | pointStyle.fillPaint(paint);
23 | paint.setColor(oldColor);
24 | }
25 | if (pointStyle.getShape() == PointStyle.CIRCLE) {
26 | canvas.drawCircle(x, y, w/2, paint);
27 | } else if (pointStyle.getShape() == PointStyle.SQUARE) {
28 | canvas.drawRect(x - w/2 , y - w/2 , x + w/2, y + w/2 , paint);
29 | } else if (pointStyle.getShape() == PointStyle.RECT) {
30 | canvas.drawRect(x - w * 2 / 3, y - w/2 , x + w * 2 / 3, y + w/2, paint);
31 | }
32 | }
33 |
34 |
35 |
36 |
37 |
38 | public PointStyle getPointStyle() {
39 | return pointStyle;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/provider/component/text/IText.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.provider.component.text;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 |
6 | /**
7 | * Created by huang on 2017/11/30.
8 | */
9 |
10 | public interface IText {
11 |
12 | void drawText(Canvas canvas, String value, float x, float y, int position, int line, Paint paint);
13 | }
14 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/provider/component/tip/ITip.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.provider.component.tip;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Rect;
5 |
6 |
7 | /**
8 | * Created by huang on 2017/10/20.
9 | */
10 |
11 | public interface ITip {
12 |
13 | void drawTip(Canvas canvas, float x, float y, Rect rect, C content,int position);
14 |
15 | boolean isShowTip(C c,int position);
16 |
17 | S format(C c,int position);
18 | }
19 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/provider/component/tip/MultiLineBubbleTip.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.provider.component.tip;
2 |
3 |
4 | import android.content.Context;
5 | import android.graphics.Canvas;
6 | import android.graphics.Paint;
7 | import android.graphics.Rect;
8 |
9 | import com.daivd.chart.utils.DensityUtils;
10 |
11 | /**
12 | * Created by huang on 2017/10/20.
13 | * 气泡提示
14 | */
15 |
16 | public abstract class MultiLineBubbleTip extends BaseBubbleTip{
17 |
18 | private int lineSpacing;
19 |
20 | public MultiLineBubbleTip(Context context, int backgroundDrawableID, int triangleDrawableID, Paint paint) {
21 | super(context, backgroundDrawableID, triangleDrawableID, paint);
22 | lineSpacing = DensityUtils.dp2px(context,3);
23 | }
24 |
25 | @Override
26 | public int getTextHeight(String[] content) {
27 | Paint.FontMetrics fontMetrics = getPaint().getFontMetrics();
28 | int textHeight= (int) (fontMetrics.bottom - fontMetrics.top);
29 | return (textHeight +lineSpacing)*content.length - lineSpacing;
30 | }
31 |
32 | @Override
33 | public int getTextWidth(String[] content) {
34 | int maxLength = 0;
35 | for(int i = 0;i < content.length;i++) {
36 | int length = (int) getPaint().measureText(content[i]);
37 | if (length > maxLength) {
38 | maxLength = length;
39 | }
40 | }
41 | return maxLength;
42 | }
43 |
44 | @Override
45 | public void drawText(Canvas canvas, Rect tipRect, String[] content, int textWidth, int textHeight, Paint paint) {
46 | int lineHeight =textHeight/content.length;
47 | for(int i = 0;i < content.length;i++) {
48 | String c = content[i];
49 | int bottom = tipRect.top+getVerticalPadding()+lineHeight+ (lineHeight)*i - lineSpacing-deviation/2;
50 | int left = tipRect.centerX()-textWidth/2;
51 | canvas.drawText(c,left,bottom,paint);
52 |
53 | }
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/provider/component/tip/SingleLineBubbleTip.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.provider.component.tip;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Paint;
6 | import android.graphics.Rect;
7 |
8 |
9 |
10 | /**
11 | * Created by huang on 2017/10/20.
12 | * 单行气泡提示
13 | */
14 |
15 | public abstract class SingleLineBubbleTip extends BaseBubbleTip {
16 |
17 | public SingleLineBubbleTip(Context context, int backgroundDrawableID, int triangleDrawableID, Paint paint){
18 | super(context,backgroundDrawableID,triangleDrawableID,paint);
19 | }
20 |
21 | @Override
22 | public int getTextHeight(String content) {
23 | Paint.FontMetrics fontMetrics = getPaint().getFontMetrics();
24 | return (int) (fontMetrics.bottom - fontMetrics.top);
25 | }
26 |
27 |
28 | @Override
29 | public int getTextWidth(String content) {
30 | return (int) getPaint().measureText(content);
31 | }
32 |
33 | @Override
34 | public void drawText(Canvas canvas, Rect tipRect, String content, int textWidth,int textHeight, Paint paint) {
35 | canvas.drawText(content,tipRect.centerX()-textWidth/2,tipRect.centerY()+textHeight/2-deviation/2,paint);
36 | }
37 |
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/provider/pie/Pie3DProvider.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.provider.pie;
2 |
3 | import android.content.Context;
4 | import android.graphics.Camera;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.Paint;
8 | import android.graphics.PointF;
9 | import android.graphics.Rect;
10 | import android.util.DisplayMetrics;
11 |
12 | import com.daivd.chart.data.ChartData;
13 | import com.daivd.chart.data.PieData;
14 |
15 | /**
16 | * Created by huang on 2017/10/9.
17 | * 3D饼图
18 | * 试验中,未完成
19 | */
20 |
21 | public class Pie3DProvider extends PieProvider {
22 | private int borderWidth = 20;
23 |
24 | //提供摄像头
25 | private Camera camera = new Camera();
26 |
27 | public Pie3DProvider(Context context){
28 | //拉远摄像头Z轴
29 | DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
30 | float newZ = -displayMetrics.density * 6;
31 | camera.setLocation(0,0,newZ);
32 | }
33 | @Override
34 | public boolean calculationChild(ChartData chartData) {
35 | return true;
36 | }
37 |
38 | /**
39 | * 变形开始
40 | *
41 | */
42 | @Override
43 | protected void matrixRectStart(Canvas canvas, Rect rect) {
44 | canvas.save();
45 | camera.save();
46 | canvas.translate(rect.centerX(),rect.centerY());
47 | camera.rotateX(60);
48 | camera.applyToCanvas(canvas);
49 | canvas.translate(-rect.centerX(),-rect.centerY());
50 | canvas.clipRect(rect);
51 | if(rotateHelper != null && rotateHelper.isRotate()){
52 | canvas.rotate((float) rotateHelper.getStartAngle(),rect.centerX(),rect.centerY());
53 | }
54 |
55 | }
56 |
57 | @Override
58 | protected void drawProvider(Canvas canvas, Rect zoomRect, Rect rect, Paint paint) {
59 |
60 | super.drawProvider(canvas, zoomRect, rect, paint);
61 | PointF centerPoint = getCenterPoint();
62 | paint.setStrokeWidth(borderWidth);
63 | paint.setStyle(Paint.Style.STROKE);
64 | paint.setColor(Color.parseColor("#80FFFFFF"));
65 | int radius = getCenterRadius();
66 | canvas.drawCircle(centerPoint.x,centerPoint.y,radius*getCenterCirclePercent()+borderWidth/2,paint);
67 | canvas.drawCircle(centerPoint.x,centerPoint.y,radius-borderWidth/2,paint);
68 | }
69 |
70 | /**
71 | * 变形结束
72 | *
73 | */
74 | @Override
75 | protected void matrixRectEnd(Canvas canvas, Rect rect) {
76 | camera.restore();
77 | super.matrixRectEnd(canvas, rect);
78 |
79 | }
80 |
81 |
82 | }
83 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/utils/ColorUtils.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.utils;
2 |
3 | import android.graphics.Color;
4 |
5 | /**
6 | * Created by huang on 2017/9/28.
7 | */
8 |
9 | public class ColorUtils {
10 |
11 | public static int getDarkerColor(int color){
12 | float[] hsv = new float[3];
13 | Color.colorToHSV(color, hsv); // convert to hsv
14 | // make darker
15 | hsv[1] = hsv[1] + 0.1f; // more saturation
16 | hsv[2] = hsv[2] - 0.1f; // less brightness
17 | int darkerColor = Color.HSVToColor(hsv);
18 | return darkerColor ;
19 | }
20 |
21 | public static int getBrighterColor(int color){
22 | float[] hsv = new float[3];
23 | Color.colorToHSV(color, hsv); // convert to hsv
24 |
25 | hsv[1] = hsv[1] - 0.1f; // less saturation
26 | hsv[2] = hsv[2] + 0.1f; // more brightness
27 | int darkerColor = Color.HSVToColor(hsv);
28 | return darkerColor ;
29 | }
30 |
31 | /**
32 | * 修改颜色透明度
33 | * @param color
34 | * @param alpha
35 | * @return
36 | */
37 | public static int changeAlpha(int color, int alpha) {
38 | int red = Color.red(color);
39 | int green = Color.green(color);
40 | int blue = Color.blue(color);
41 |
42 | return Color.argb(alpha, red, green, blue);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/utils/DensityUtils.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.utils;
2 |
3 | import android.content.Context;
4 |
5 | import android.util.TypedValue;
6 |
7 |
8 | //常用单位转换的辅助类
9 |
10 | public class DensityUtils {
11 |
12 | private DensityUtils() {
13 |
14 | /* cannot be instantiated */
15 |
16 | throw new UnsupportedOperationException("cannot be instantiated");
17 |
18 | }
19 |
20 |
21 | /**
22 | * dp转px
23 | *
24 | * @param context
25 | * @return
26 | */
27 |
28 | public static int dp2px(Context context, float dpVal)
29 |
30 | {
31 |
32 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
33 |
34 | dpVal, context.getResources().getDisplayMetrics());
35 |
36 | }
37 |
38 |
39 | /**
40 | * sp转px
41 | *
42 | * @param context
43 | * @return
44 | */
45 |
46 | public static int sp2px(Context context, float spVal)
47 |
48 | {
49 |
50 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
51 |
52 | spVal, context.getResources().getDisplayMetrics());
53 |
54 | }
55 |
56 |
57 | /**
58 | * px转dp
59 | *
60 | * @param context
61 | * @param pxVal
62 | * @return
63 | */
64 |
65 | public static float px2dp(Context context, float pxVal)
66 |
67 | {
68 |
69 | final float scale = context.getResources().getDisplayMetrics().density;
70 |
71 | return (pxVal / scale);
72 |
73 | }
74 |
75 |
76 | /**
77 | * px转sp
78 | *
79 | * @param pxVal
80 | * @return
81 | */
82 |
83 | public static float px2sp(Context context, float pxVal)
84 |
85 | {
86 |
87 | return (pxVal / context.getResources().getDisplayMetrics().scaledDensity);
88 |
89 | }
90 |
91 |
92 | }
--------------------------------------------------------------------------------
/chart/src/main/java/com/daivd/chart/utils/DrawUtils.java:
--------------------------------------------------------------------------------
1 | package com.daivd.chart.utils;
2 |
3 | import android.graphics.Paint;
4 | import android.graphics.PointF;
5 | import android.graphics.Rect;
6 |
7 | import com.daivd.chart.data.style.FontStyle;
8 |
9 |
10 | /**
11 | * Created by huang on 2017/11/1.
12 | */
13 |
14 | public class DrawUtils {
15 |
16 | public static int getTextHeight(FontStyle style, Paint paint){
17 | style.fillPaint(paint);
18 | Paint.FontMetrics fontMetrics = paint.getFontMetrics();
19 | return (int) (fontMetrics.descent - fontMetrics.ascent);
20 | }
21 |
22 | public static int getTextHeight(Paint paint){
23 | Paint.FontMetrics fontMetrics = paint.getFontMetrics();
24 | return (int) (fontMetrics.descent - fontMetrics.ascent);
25 | }
26 |
27 | public static float getTextCenterY(int centerY,Paint paint){
28 | return centerY-((paint.descent() + paint.ascent()) / 2);
29 | }
30 |
31 | public static boolean isMixRect(Rect rect,int left,int top,int right,int bottom){
32 |
33 | return rect.bottom>= top && rect.right >= left && rect.top = left && clickPoint.x <=right && clickPoint.y>=top && clickPoint.y <=bottom;
38 | }
39 |
40 |
41 |
42 | public static boolean isMixHorizontalRect(Rect rect,int left,int right){
43 |
44 | return rect.right >= left && rect.left<= right;
45 | }
46 | public static boolean isVerticalMixRect(Rect rect,int top,int bottom){
47 |
48 | return rect.bottom>= top && rect.top <=bottom;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/chart/src/main/res/drawable/ic_tri.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/chart/src/main/res/drawable/msg.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huangyanbin/SmartChart/cb8016111dcdccaa43f08a2d90dfe45285c38aee/chart/src/main/res/drawable/msg.9.png
--------------------------------------------------------------------------------
/chart/src/main/res/mipmap-xxhdpi/round_rect.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huangyanbin/SmartChart/cb8016111dcdccaa43f08a2d90dfe45285c38aee/chart/src/main/res/mipmap-xxhdpi/round_rect.9.png
--------------------------------------------------------------------------------
/chart/src/main/res/mipmap-xxhdpi/triangle.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huangyanbin/SmartChart/cb8016111dcdccaa43f08a2d90dfe45285c38aee/chart/src/main/res/mipmap-xxhdpi/triangle.png
--------------------------------------------------------------------------------
/chart/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/chart/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Smartchart
3 |
4 |
--------------------------------------------------------------------------------
/chart/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huangyanbin/SmartChart/cb8016111dcdccaa43f08a2d90dfe45285c38aee/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Oct 27 15:18:51 CST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/img/bar1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huangyanbin/SmartChart/cb8016111dcdccaa43f08a2d90dfe45285c38aee/img/bar1.png
--------------------------------------------------------------------------------
/img/bar2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huangyanbin/SmartChart/cb8016111dcdccaa43f08a2d90dfe45285c38aee/img/bar2.png
--------------------------------------------------------------------------------
/img/dashBorad.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huangyanbin/SmartChart/cb8016111dcdccaa43f08a2d90dfe45285c38aee/img/dashBorad.png
--------------------------------------------------------------------------------
/img/gif/chart.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huangyanbin/SmartChart/cb8016111dcdccaa43f08a2d90dfe45285c38aee/img/gif/chart.gif
--------------------------------------------------------------------------------
/img/gif/rotate.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huangyanbin/SmartChart/cb8016111dcdccaa43f08a2d90dfe45285c38aee/img/gif/rotate.gif
--------------------------------------------------------------------------------
/img/gif/tip.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huangyanbin/SmartChart/cb8016111dcdccaa43f08a2d90dfe45285c38aee/img/gif/tip.gif
--------------------------------------------------------------------------------
/img/gif/viewpager.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huangyanbin/SmartChart/cb8016111dcdccaa43f08a2d90dfe45285c38aee/img/gif/viewpager.gif
--------------------------------------------------------------------------------
/img/gif/zoom.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huangyanbin/SmartChart/cb8016111dcdccaa43f08a2d90dfe45285c38aee/img/gif/zoom.gif
--------------------------------------------------------------------------------
/img/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huangyanbin/SmartChart/cb8016111dcdccaa43f08a2d90dfe45285c38aee/img/icon.png
--------------------------------------------------------------------------------
/img/line1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huangyanbin/SmartChart/cb8016111dcdccaa43f08a2d90dfe45285c38aee/img/line1.png
--------------------------------------------------------------------------------
/img/line2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huangyanbin/SmartChart/cb8016111dcdccaa43f08a2d90dfe45285c38aee/img/line2.png
--------------------------------------------------------------------------------
/img/line3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huangyanbin/SmartChart/cb8016111dcdccaa43f08a2d90dfe45285c38aee/img/line3.png
--------------------------------------------------------------------------------
/img/line4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huangyanbin/SmartChart/cb8016111dcdccaa43f08a2d90dfe45285c38aee/img/line4.png
--------------------------------------------------------------------------------
/img/pie.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huangyanbin/SmartChart/cb8016111dcdccaa43f08a2d90dfe45285c38aee/img/pie.png
--------------------------------------------------------------------------------
/img/radar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huangyanbin/SmartChart/cb8016111dcdccaa43f08a2d90dfe45285c38aee/img/radar.png
--------------------------------------------------------------------------------
/img/rose1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huangyanbin/SmartChart/cb8016111dcdccaa43f08a2d90dfe45285c38aee/img/rose1.png
--------------------------------------------------------------------------------
/img/rose2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huangyanbin/SmartChart/cb8016111dcdccaa43f08a2d90dfe45285c38aee/img/rose2.png
--------------------------------------------------------------------------------
/img/smartChart.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huangyanbin/SmartChart/cb8016111dcdccaa43f08a2d90dfe45285c38aee/img/smartChart.apk
--------------------------------------------------------------------------------
/img/zuoping.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huangyanbin/SmartChart/cb8016111dcdccaa43f08a2d90dfe45285c38aee/img/zuoping.jpg
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':chart'
2 |
--------------------------------------------------------------------------------