Skip to content

Commit

Permalink
Implemented icon support
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgindi committed Feb 20, 2017
1 parent ccf6b7e commit a02e108
Show file tree
Hide file tree
Showing 20 changed files with 698 additions and 76 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.mikephil.charting.data;

import android.annotation.SuppressLint;
import android.graphics.drawable.Drawable;

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

Expand Down Expand Up @@ -33,10 +34,54 @@ public class BarEntry extends Entry {
private float mPositiveSum;

/**
* Constructor for stacked bar entries.
* Constructor for normal bars (not stacked).
*
* @param x
* @param y
*/
public BarEntry(float x, float y) {
super(x, y);
}

/**
* Constructor for normal bars (not stacked).
*
* @param x
* @param y
* @param data - Spot for additional data this Entry represents.
*/
public BarEntry(float x, float y, Object data) {
super(x, y, data);
}

/**
* Constructor for normal bars (not stacked).
*
* @param x
* @param y
* @param icon - icon image
*/
public BarEntry(float x, float y, Drawable icon) {
super(x, y, icon);
}

/**
* Constructor for normal bars (not stacked).
*
* @param x
* @param vals - the stack values, use at lest 2
* @param y
* @param icon - icon image
* @param data - Spot for additional data this Entry represents.
*/
public BarEntry(float x, float y, Drawable icon, Object data) {
super(x, y, icon, data);
}

/**
* Constructor for stacked bar entries. One data object for whole stack
*
* @param x
* @param vals - the stack values, use at least 2
*/
public BarEntry(float x, float[] vals) {
super(x, calcSum(vals));
Expand All @@ -47,39 +92,49 @@ public BarEntry(float x, float[] vals) {
}

/**
* Constructor for normal bars (not stacked).
* Constructor for stacked bar entries. One data object for whole stack
*
* @param x
* @param y
* @param vals - the stack values, use at least 2
* @param data - Spot for additional data this Entry represents.
*/
public BarEntry(float x, float y) {
super(x, y);
public BarEntry(float x, float[] vals, Object data) {
super(x, calcSum(vals), data);

this.mYVals = vals;
calcPosNegSum();
calcRanges();
}

/**
* Constructor for stacked bar entries.
* Constructor for stacked bar entries. One data object for whole stack
*
* @param x
* @param vals - the stack values, use at least 2
* @param label Additional description label.
* @param vals - the stack values, use at least 2
* @param icon - icon image
*/
public BarEntry(float x, float[] vals, String label) {
super(x, calcSum(vals), label);
public BarEntry(float x, float[] vals, Drawable icon) {
super(x, calcSum(vals), icon);

this.mYVals = vals;
calcPosNegSum();
calcRanges();
}

/**
* Constructor for normal bars (not stacked).
* Constructor for stacked bar entries. One data object for whole stack
*
* @param x
* @param y
* @param data Spot for additional data this Entry represents.
* @param vals - the stack values, use at least 2
* @param icon - icon image
* @param data - Spot for additional data this Entry represents.
*/
public BarEntry(float x, float y, Object data) {
super(x, y, data);
public BarEntry(float x, float[] vals, Drawable icon, Object data) {
super(x, calcSum(vals), icon, data);

this.mYVals = vals;
calcPosNegSum();
calcRanges();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
import com.github.mikephil.charting.formatter.IValueFormatter;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.utils.MPPointF;
import com.github.mikephil.charting.utils.Utils;

import java.lang.annotation.Documented;
import java.lang.annotation.Inherited;
import java.util.ArrayList;
import java.util.List;

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

/**
* if true, y-icons are drawn on the chart
*/
protected boolean mDrawIcons = true;

/**
* the offset for drawing icons (in dp)
*/
protected MPPointF mIconsOffset = new MPPointF();

/**
* the size of the value-text labels
*/
Expand Down Expand Up @@ -371,6 +384,28 @@ public boolean isDrawValuesEnabled() {
return mDrawValues;
}

@Override
public void setDrawIcons(boolean enabled) {
mDrawIcons = enabled;
}

@Override
public boolean isDrawIconsEnabled() {
return mDrawIcons;
}

@Override
public void setIconsOffset(MPPointF offsetDp) {

mIconsOffset.x = offsetDp.x;
mIconsOffset.y = offsetDp.y;
}

@Override
public MPPointF getIconsOffset() {
return mIconsOffset;
}

@Override
public void setVisible(boolean visible) {
mVisible = visible;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.mikephil.charting.data;

import android.graphics.drawable.Drawable;

/**
* Created by Philipp Jahoda on 02/06/16.
*/
Expand All @@ -11,6 +13,9 @@ public abstract class BaseEntry {
/** optional spot for additional data this Entry represents */
private Object mData = null;

/** optional icon image */
private Drawable mIcon = null;

public BaseEntry() {

}
Expand All @@ -24,6 +29,17 @@ public BaseEntry(float y, Object data) {
this.mData = data;
}

public BaseEntry(float y, Drawable icon) {
this(y);
this.mIcon = icon;
}

public BaseEntry(float y, Drawable icon, Object data) {
this(y);
this.mIcon = icon;
this.mData = data;
}

/**
* Returns the y value of this Entry.
*
Expand All @@ -33,6 +49,24 @@ public float getY() {
return y;
}

/**
* Sets the icon drawable
*
* @param icon
*/
public void setIcon(Drawable icon) {
this.mIcon = icon;
}

/**
* Returns the icon of this Entry.
*
* @return
*/
public Drawable getIcon() {
return mIcon;
}

/**
* Sets the y-value for the Entry.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package com.github.mikephil.charting.data;

import android.annotation.SuppressLint;
import android.graphics.drawable.Drawable;

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

/**
* Constructor.
*
* @param x The value on the x-axis.
* @param y The value on the y-axis.
* @param size The size of the bubble.
* @param icon Icon image
*/
public BubbleEntry(float x, float y, float size, Drawable icon) {
super(x, y, icon);
this.mSize = size;
}

/**
* Constructor.
*
* @param x The value on the x-axis.
* @param y The value on the y-axis.
* @param size The size of the bubble.
* @param icon Icon image
* @param data Spot for additional data this Entry represents.
*/
public BubbleEntry(float x, float y, float size, Drawable icon, Object data) {
super(x, y, icon, data);
this.mSize = size;
}

public BubbleEntry copy() {

BubbleEntry c = new BubbleEntry(getX(), getY(), mSize, getData());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package com.github.mikephil.charting.data;

import android.annotation.SuppressLint;
import android.graphics.drawable.Drawable;

/**
* Subclass of Entry that holds all values for one entry in a CandleStickChart.
Expand All @@ -26,11 +27,11 @@ public class CandleEntry extends Entry {
/**
* Constructor.
*
* @param x The value on the x-axis.
* @param shadowH The (shadow) high value.
* @param shadowL The (shadow) low value.
* @param open The open value.
* @param close The close value.
* @param x The value on the x-axis
* @param shadowH The (shadow) high value
* @param shadowL The (shadow) low value
* @param open The open value
* @param close The close value
*/
public CandleEntry(float x, float shadowH, float shadowL, float open, float close) {
super(x, (shadowH + shadowL) / 2f);
Expand All @@ -43,16 +44,16 @@ public CandleEntry(float x, float shadowH, float shadowL, float open, float clos

/**
* Constructor.
*
* @param x The value on the x-axis.
* @param shadowH The (shadow) high value.
* @param shadowL The (shadow) low value.
*
* @param x The value on the x-axis
* @param shadowH The (shadow) high value
* @param shadowL The (shadow) low value
* @param open
* @param close
* @param data Spot for additional data this Entry represents.
* @param data Spot for additional data this Entry represents
*/
public CandleEntry(float x, float shadowH, float shadowL, float open, float close,
Object data) {
Object data) {
super(x, (shadowH + shadowL) / 2f, data);

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

/**
* Constructor.
*
* @param x The value on the x-axis
* @param shadowH The (shadow) high value
* @param shadowL The (shadow) low value
* @param open
* @param close
* @param icon Icon image
*/
public CandleEntry(float x, float shadowH, float shadowL, float open, float close,
Drawable icon) {
super(x, (shadowH + shadowL) / 2f, icon);

this.mShadowHigh = shadowH;
this.mShadowLow = shadowL;
this.mOpen = open;
this.mClose = close;
}

/**
* Constructor.
*
* @param x The value on the x-axis
* @param shadowH The (shadow) high value
* @param shadowL The (shadow) low value
* @param open
* @param close
* @param icon Icon image
* @param data Spot for additional data this Entry represents
*/
public CandleEntry(float x, float shadowH, float shadowL, float open, float close,
Drawable icon, Object data) {
super(x, (shadowH + shadowL) / 2f, icon, data);

this.mShadowHigh = shadowH;
this.mShadowLow = shadowL;
this.mOpen = open;
this.mClose = close;
}

/**
* Returns the overall range (difference) between shadow-high and
* shadow-low.
Expand Down
Loading

0 comments on commit a02e108

Please sign in to comment.