Skip to content

Commit a02e108

Browse files
committed
Implemented icon support
1 parent ccf6b7e commit a02e108

20 files changed

+698
-76
lines changed

MPChartLib/src/main/java/com/github/mikephil/charting/data/BarEntry.java

Lines changed: 71 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.mikephil.charting.data;
22

33
import android.annotation.SuppressLint;
4+
import android.graphics.drawable.Drawable;
45

56
import com.github.mikephil.charting.highlight.Range;
67

@@ -33,10 +34,54 @@ public class BarEntry extends Entry {
3334
private float mPositiveSum;
3435

3536
/**
36-
* Constructor for stacked bar entries.
37+
* Constructor for normal bars (not stacked).
38+
*
39+
* @param x
40+
* @param y
41+
*/
42+
public BarEntry(float x, float y) {
43+
super(x, y);
44+
}
45+
46+
/**
47+
* Constructor for normal bars (not stacked).
48+
*
49+
* @param x
50+
* @param y
51+
* @param data - Spot for additional data this Entry represents.
52+
*/
53+
public BarEntry(float x, float y, Object data) {
54+
super(x, y, data);
55+
}
56+
57+
/**
58+
* Constructor for normal bars (not stacked).
59+
*
60+
* @param x
61+
* @param y
62+
* @param icon - icon image
63+
*/
64+
public BarEntry(float x, float y, Drawable icon) {
65+
super(x, y, icon);
66+
}
67+
68+
/**
69+
* Constructor for normal bars (not stacked).
3770
*
3871
* @param x
39-
* @param vals - the stack values, use at lest 2
72+
* @param y
73+
* @param icon - icon image
74+
* @param data - Spot for additional data this Entry represents.
75+
*/
76+
public BarEntry(float x, float y, Drawable icon, Object data) {
77+
super(x, y, icon, data);
78+
}
79+
80+
/**
81+
* Constructor for stacked bar entries. One data object for whole stack
82+
*
83+
* @param x
84+
* @param vals - the stack values, use at least 2
4085
*/
4186
public BarEntry(float x, float[] vals) {
4287
super(x, calcSum(vals));
@@ -47,39 +92,49 @@ public BarEntry(float x, float[] vals) {
4792
}
4893

4994
/**
50-
* Constructor for normal bars (not stacked).
95+
* Constructor for stacked bar entries. One data object for whole stack
5196
*
5297
* @param x
53-
* @param y
98+
* @param vals - the stack values, use at least 2
99+
* @param data - Spot for additional data this Entry represents.
54100
*/
55-
public BarEntry(float x, float y) {
56-
super(x, y);
101+
public BarEntry(float x, float[] vals, Object data) {
102+
super(x, calcSum(vals), data);
103+
104+
this.mYVals = vals;
105+
calcPosNegSum();
106+
calcRanges();
57107
}
58108

59109
/**
60-
* Constructor for stacked bar entries.
110+
* Constructor for stacked bar entries. One data object for whole stack
61111
*
62112
* @param x
63-
* @param vals - the stack values, use at least 2
64-
* @param label Additional description label.
113+
* @param vals - the stack values, use at least 2
114+
* @param icon - icon image
65115
*/
66-
public BarEntry(float x, float[] vals, String label) {
67-
super(x, calcSum(vals), label);
116+
public BarEntry(float x, float[] vals, Drawable icon) {
117+
super(x, calcSum(vals), icon);
68118

69119
this.mYVals = vals;
70120
calcPosNegSum();
71121
calcRanges();
72122
}
73123

74124
/**
75-
* Constructor for normal bars (not stacked).
125+
* Constructor for stacked bar entries. One data object for whole stack
76126
*
77127
* @param x
78-
* @param y
79-
* @param data Spot for additional data this Entry represents.
128+
* @param vals - the stack values, use at least 2
129+
* @param icon - icon image
130+
* @param data - Spot for additional data this Entry represents.
80131
*/
81-
public BarEntry(float x, float y, Object data) {
82-
super(x, y, data);
132+
public BarEntry(float x, float[] vals, Drawable icon, Object data) {
133+
super(x, calcSum(vals), icon, data);
134+
135+
this.mYVals = vals;
136+
calcPosNegSum();
137+
calcRanges();
83138
}
84139

85140
/**

MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
import com.github.mikephil.charting.formatter.IValueFormatter;
1212
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
1313
import com.github.mikephil.charting.utils.ColorTemplate;
14+
import com.github.mikephil.charting.utils.MPPointF;
1415
import com.github.mikephil.charting.utils.Utils;
1516

17+
import java.lang.annotation.Documented;
18+
import java.lang.annotation.Inherited;
1619
import java.util.ArrayList;
1720
import java.util.List;
1821

@@ -68,6 +71,16 @@ public abstract class BaseDataSet<T extends Entry> implements IDataSet<T> {
6871
*/
6972
protected boolean mDrawValues = true;
7073

74+
/**
75+
* if true, y-icons are drawn on the chart
76+
*/
77+
protected boolean mDrawIcons = true;
78+
79+
/**
80+
* the offset for drawing icons (in dp)
81+
*/
82+
protected MPPointF mIconsOffset = new MPPointF();
83+
7184
/**
7285
* the size of the value-text labels
7386
*/
@@ -371,6 +384,28 @@ public boolean isDrawValuesEnabled() {
371384
return mDrawValues;
372385
}
373386

387+
@Override
388+
public void setDrawIcons(boolean enabled) {
389+
mDrawIcons = enabled;
390+
}
391+
392+
@Override
393+
public boolean isDrawIconsEnabled() {
394+
return mDrawIcons;
395+
}
396+
397+
@Override
398+
public void setIconsOffset(MPPointF offsetDp) {
399+
400+
mIconsOffset.x = offsetDp.x;
401+
mIconsOffset.y = offsetDp.y;
402+
}
403+
404+
@Override
405+
public MPPointF getIconsOffset() {
406+
return mIconsOffset;
407+
}
408+
374409
@Override
375410
public void setVisible(boolean visible) {
376411
mVisible = visible;

MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseEntry.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.github.mikephil.charting.data;
22

3+
import android.graphics.drawable.Drawable;
4+
35
/**
46
* Created by Philipp Jahoda on 02/06/16.
57
*/
@@ -11,6 +13,9 @@ public abstract class BaseEntry {
1113
/** optional spot for additional data this Entry represents */
1214
private Object mData = null;
1315

16+
/** optional icon image */
17+
private Drawable mIcon = null;
18+
1419
public BaseEntry() {
1520

1621
}
@@ -24,6 +29,17 @@ public BaseEntry(float y, Object data) {
2429
this.mData = data;
2530
}
2631

32+
public BaseEntry(float y, Drawable icon) {
33+
this(y);
34+
this.mIcon = icon;
35+
}
36+
37+
public BaseEntry(float y, Drawable icon, Object data) {
38+
this(y);
39+
this.mIcon = icon;
40+
this.mData = data;
41+
}
42+
2743
/**
2844
* Returns the y value of this Entry.
2945
*
@@ -33,6 +49,24 @@ public float getY() {
3349
return y;
3450
}
3551

52+
/**
53+
* Sets the icon drawable
54+
*
55+
* @param icon
56+
*/
57+
public void setIcon(Drawable icon) {
58+
this.mIcon = icon;
59+
}
60+
61+
/**
62+
* Returns the icon of this Entry.
63+
*
64+
* @return
65+
*/
66+
public Drawable getIcon() {
67+
return mIcon;
68+
}
69+
3670
/**
3771
* Sets the y-value for the Entry.
3872
*

MPChartLib/src/main/java/com/github/mikephil/charting/data/BubbleEntry.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package com.github.mikephil.charting.data;
33

44
import android.annotation.SuppressLint;
5+
import android.graphics.drawable.Drawable;
56

67
/**
78
* Subclass of Entry that holds a value for one entry in a BubbleChart. Bubble
@@ -41,6 +42,33 @@ public BubbleEntry(float x, float y, float size, Object data) {
4142
this.mSize = size;
4243
}
4344

45+
/**
46+
* Constructor.
47+
*
48+
* @param x The value on the x-axis.
49+
* @param y The value on the y-axis.
50+
* @param size The size of the bubble.
51+
* @param icon Icon image
52+
*/
53+
public BubbleEntry(float x, float y, float size, Drawable icon) {
54+
super(x, y, icon);
55+
this.mSize = size;
56+
}
57+
58+
/**
59+
* Constructor.
60+
*
61+
* @param x The value on the x-axis.
62+
* @param y The value on the y-axis.
63+
* @param size The size of the bubble.
64+
* @param icon Icon image
65+
* @param data Spot for additional data this Entry represents.
66+
*/
67+
public BubbleEntry(float x, float y, float size, Drawable icon, Object data) {
68+
super(x, y, icon, data);
69+
this.mSize = size;
70+
}
71+
4472
public BubbleEntry copy() {
4573

4674
BubbleEntry c = new BubbleEntry(getX(), getY(), mSize, getData());

MPChartLib/src/main/java/com/github/mikephil/charting/data/CandleEntry.java

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package com.github.mikephil.charting.data;
33

44
import android.annotation.SuppressLint;
5+
import android.graphics.drawable.Drawable;
56

67
/**
78
* Subclass of Entry that holds all values for one entry in a CandleStickChart.
@@ -26,11 +27,11 @@ public class CandleEntry extends Entry {
2627
/**
2728
* Constructor.
2829
*
29-
* @param x The value on the x-axis.
30-
* @param shadowH The (shadow) high value.
31-
* @param shadowL The (shadow) low value.
32-
* @param open The open value.
33-
* @param close The close value.
30+
* @param x The value on the x-axis
31+
* @param shadowH The (shadow) high value
32+
* @param shadowL The (shadow) low value
33+
* @param open The open value
34+
* @param close The close value
3435
*/
3536
public CandleEntry(float x, float shadowH, float shadowL, float open, float close) {
3637
super(x, (shadowH + shadowL) / 2f);
@@ -43,16 +44,16 @@ public CandleEntry(float x, float shadowH, float shadowL, float open, float clos
4344

4445
/**
4546
* Constructor.
46-
*
47-
* @param x The value on the x-axis.
48-
* @param shadowH The (shadow) high value.
49-
* @param shadowL The (shadow) low value.
47+
*
48+
* @param x The value on the x-axis
49+
* @param shadowH The (shadow) high value
50+
* @param shadowL The (shadow) low value
5051
* @param open
5152
* @param close
52-
* @param data Spot for additional data this Entry represents.
53+
* @param data Spot for additional data this Entry represents
5354
*/
5455
public CandleEntry(float x, float shadowH, float shadowL, float open, float close,
55-
Object data) {
56+
Object data) {
5657
super(x, (shadowH + shadowL) / 2f, data);
5758

5859
this.mShadowHigh = shadowH;
@@ -61,6 +62,47 @@ public CandleEntry(float x, float shadowH, float shadowL, float open, float clos
6162
this.mClose = close;
6263
}
6364

65+
/**
66+
* Constructor.
67+
*
68+
* @param x The value on the x-axis
69+
* @param shadowH The (shadow) high value
70+
* @param shadowL The (shadow) low value
71+
* @param open
72+
* @param close
73+
* @param icon Icon image
74+
*/
75+
public CandleEntry(float x, float shadowH, float shadowL, float open, float close,
76+
Drawable icon) {
77+
super(x, (shadowH + shadowL) / 2f, icon);
78+
79+
this.mShadowHigh = shadowH;
80+
this.mShadowLow = shadowL;
81+
this.mOpen = open;
82+
this.mClose = close;
83+
}
84+
85+
/**
86+
* Constructor.
87+
*
88+
* @param x The value on the x-axis
89+
* @param shadowH The (shadow) high value
90+
* @param shadowL The (shadow) low value
91+
* @param open
92+
* @param close
93+
* @param icon Icon image
94+
* @param data Spot for additional data this Entry represents
95+
*/
96+
public CandleEntry(float x, float shadowH, float shadowL, float open, float close,
97+
Drawable icon, Object data) {
98+
super(x, (shadowH + shadowL) / 2f, icon, data);
99+
100+
this.mShadowHigh = shadowH;
101+
this.mShadowLow = shadowL;
102+
this.mOpen = open;
103+
this.mClose = close;
104+
}
105+
64106
/**
65107
* Returns the overall range (difference) between shadow-high and
66108
* shadow-low.

0 commit comments

Comments
 (0)