123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- package com.github.mikephil.charting.data;
- import android.graphics.Paint;
- import com.github.mikephil.charting.interfaces.datasets.ICandleDataSet;
- import com.github.mikephil.charting.utils.ColorTemplate;
- import com.github.mikephil.charting.utils.Utils;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * DataSet for the CandleStickChart.
- *
- * @author Philipp Jahoda
- */
- public class CandleDataSet extends LineScatterCandleRadarDataSet<CandleEntry> implements ICandleDataSet {
- /**
- * the width of the shadow of the candle
- */
- private float mShadowWidth = 3f;
- /**
- * should the candle bars show?
- * when false, only "ticks" will show
- * <p/>
- * - default: true
- */
- private boolean mShowCandleBar = true;
- /**
- * the space between the candle entries, default 0.1f (10%)
- */
- private float mBarSpace = 0.1f;
- /**
- * use candle color for the shadow
- */
- private boolean mShadowColorSameAsCandle = false;
- /**
- * paint style when open < close
- * increasing candlesticks are traditionally hollow
- */
- protected Paint.Style mIncreasingPaintStyle = Paint.Style.STROKE;
- /**
- * paint style when open > close
- * descreasing candlesticks are traditionally filled
- */
- protected Paint.Style mDecreasingPaintStyle = Paint.Style.FILL;
- /**
- * color for open == close
- */
- protected int mNeutralColor = ColorTemplate.COLOR_SKIP;
- /**
- * color for open < close
- */
- protected int mIncreasingColor = ColorTemplate.COLOR_SKIP;
- /**
- * color for open > close
- */
- protected int mDecreasingColor = ColorTemplate.COLOR_SKIP;
- /**
- * shadow line color, set -1 for backward compatibility and uses default
- * color
- */
- protected int mShadowColor = ColorTemplate.COLOR_SKIP;
- public CandleDataSet(List<CandleEntry> yVals, String label) {
- super(yVals, label);
- }
- @Override
- public DataSet<CandleEntry> copy() {
- List<CandleEntry> entries = new ArrayList<CandleEntry>();
- for (int i = 0; i < mEntries.size(); i++) {
- entries.add(mEntries.get(i).copy());
- }
- CandleDataSet copied = new CandleDataSet(entries, getLabel());
- copy(copied);
- return copied;
- }
- protected void copy(CandleDataSet candleDataSet) {
- super.copy(candleDataSet);
- candleDataSet.mShadowWidth = mShadowWidth;
- candleDataSet.mShowCandleBar = mShowCandleBar;
- candleDataSet.mBarSpace = mBarSpace;
- candleDataSet.mShadowColorSameAsCandle = mShadowColorSameAsCandle;
- candleDataSet.mHighLightColor = mHighLightColor;
- candleDataSet.mIncreasingPaintStyle = mIncreasingPaintStyle;
- candleDataSet.mDecreasingPaintStyle = mDecreasingPaintStyle;
- candleDataSet.mNeutralColor = mNeutralColor;
- candleDataSet.mIncreasingColor = mIncreasingColor;
- candleDataSet.mDecreasingColor = mDecreasingColor;
- candleDataSet.mShadowColor = mShadowColor;
- }
- @Override
- protected void calcMinMax(CandleEntry e) {
- if (e.getLow() < mYMin)
- mYMin = e.getLow();
- if (e.getHigh() > mYMax)
- mYMax = e.getHigh();
- calcMinMaxX(e);
- }
- @Override
- protected void calcMinMaxY(CandleEntry e) {
- if (e.getHigh() < mYMin)
- mYMin = e.getHigh();
- if (e.getHigh() > mYMax)
- mYMax = e.getHigh();
- if (e.getLow() < mYMin)
- mYMin = e.getLow();
- if (e.getLow() > mYMax)
- mYMax = e.getLow();
- }
- /**
- * Sets the space that is left out on the left and right side of each
- * candle, default 0.1f (10%), max 0.45f, min 0f
- *
- * @param space
- */
- public void setBarSpace(float space) {
- if (space < 0f)
- space = 0f;
- if (space > 0.45f)
- space = 0.45f;
- mBarSpace = space;
- }
- @Override
- public float getBarSpace() {
- return mBarSpace;
- }
- /**
- * Sets the width of the candle-shadow-line in pixels. Default 3f.
- *
- * @param width
- */
- public void setShadowWidth(float width) {
- mShadowWidth = Utils.convertDpToPixel(width);
- }
- @Override
- public float getShadowWidth() {
- return mShadowWidth;
- }
- /**
- * Sets whether the candle bars should show?
- *
- * @param showCandleBar
- */
- public void setShowCandleBar(boolean showCandleBar) {
- mShowCandleBar = showCandleBar;
- }
- @Override
- public boolean getShowCandleBar() {
- return mShowCandleBar;
- }
- // TODO
- /**
- * It is necessary to implement ColorsList class that will encapsulate
- * colors list functionality, because It's wrong to copy paste setColor,
- * addColor, ... resetColors for each time when we want to add a coloring
- * options for one of objects
- *
- * @author Mesrop
- */
- /** BELOW THIS COLOR HANDLING */
- /**
- * Sets the one and ONLY color that should be used for this DataSet when
- * open == close.
- *
- * @param color
- */
- public void setNeutralColor(int color) {
- mNeutralColor = color;
- }
- @Override
- public int getNeutralColor() {
- return mNeutralColor;
- }
- /**
- * Sets the one and ONLY color that should be used for this DataSet when
- * open <= close.
- *
- * @param color
- */
- public void setIncreasingColor(int color) {
- mIncreasingColor = color;
- }
- @Override
- public int getIncreasingColor() {
- return mIncreasingColor;
- }
- /**
- * Sets the one and ONLY color that should be used for this DataSet when
- * open > close.
- *
- * @param color
- */
- public void setDecreasingColor(int color) {
- mDecreasingColor = color;
- }
- @Override
- public int getDecreasingColor() {
- return mDecreasingColor;
- }
- @Override
- public Paint.Style getIncreasingPaintStyle() {
- return mIncreasingPaintStyle;
- }
- /**
- * Sets paint style when open < close
- *
- * @param paintStyle
- */
- public void setIncreasingPaintStyle(Paint.Style paintStyle) {
- this.mIncreasingPaintStyle = paintStyle;
- }
- @Override
- public Paint.Style getDecreasingPaintStyle() {
- return mDecreasingPaintStyle;
- }
- /**
- * Sets paint style when open > close
- *
- * @param decreasingPaintStyle
- */
- public void setDecreasingPaintStyle(Paint.Style decreasingPaintStyle) {
- this.mDecreasingPaintStyle = decreasingPaintStyle;
- }
- @Override
- public int getShadowColor() {
- return mShadowColor;
- }
- /**
- * Sets shadow color for all entries
- *
- * @param shadowColor
- */
- public void setShadowColor(int shadowColor) {
- this.mShadowColor = shadowColor;
- }
- @Override
- public boolean getShadowColorSameAsCandle() {
- return mShadowColorSameAsCandle;
- }
- /**
- * Sets shadow color to be the same color as the candle color
- *
- * @param shadowColorSameAsCandle
- */
- public void setShadowColorSameAsCandle(boolean shadowColorSameAsCandle) {
- this.mShadowColorSameAsCandle = shadowColorSameAsCandle;
- }
- }
|