Fixed issue #45, worked on CandleStickChart.
This commit is contained in:
parent
f36ba8de48
commit
0a33e2d6f1
8 changed files with 133 additions and 35 deletions
|
@ -102,6 +102,9 @@ public class InvertedLineChartActivity extends DemoBase implements OnSeekBarChan
|
|||
// enable/disable highlight indicators (the lines that indicate the
|
||||
// highlighted Entry)
|
||||
mChart.setHighlightIndicatorEnabled(false);
|
||||
|
||||
XLabels xl = mChart.getXLabels();
|
||||
xl.setAvoidFirstLastClipping(true);
|
||||
|
||||
// add data
|
||||
setData(25, 50);
|
||||
|
@ -287,7 +290,7 @@ public class InvertedLineChartActivity extends DemoBase implements OnSeekBarChan
|
|||
|
||||
ArrayList<String> xVals = new ArrayList<String>();
|
||||
for (int i = 0; i < count; i++) {
|
||||
xVals.add((i) + "");
|
||||
xVals.add((i % 30) + "/" + (i % 12) + "/14");
|
||||
}
|
||||
|
||||
ArrayList<Entry> yVals = new ArrayList<Entry>();
|
||||
|
|
|
@ -65,7 +65,6 @@ public class PieChartActivity extends DemoBase implements OnSeekBarChangeListene
|
|||
|
||||
// draws the corresponding description value into the slice
|
||||
mChart.setDrawXValues(true);
|
||||
mChart.setTouchEnabled(true);
|
||||
|
||||
// display percentage values
|
||||
mChart.setUsePercentValues(true);
|
||||
|
@ -74,7 +73,8 @@ public class PieChartActivity extends DemoBase implements OnSeekBarChangeListene
|
|||
|
||||
// add a selection listener
|
||||
mChart.setOnChartValueSelectedListener(this);
|
||||
|
||||
// mChart.setTouchEnabled(false);
|
||||
|
||||
mSeekBarX.setProgress(3);
|
||||
mSeekBarY.setProgress(100);
|
||||
|
||||
|
|
|
@ -14,7 +14,9 @@ import android.graphics.Rect;
|
|||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.ViewParent;
|
||||
import android.view.View.OnTouchListener;
|
||||
|
||||
import com.github.mikephil.charting.data.BarLineScatterData;
|
||||
import com.github.mikephil.charting.data.ChartData;
|
||||
|
@ -512,7 +514,7 @@ public abstract class BarLineChartBase extends Chart {
|
|||
super.calcMinMax(fixedValues); // calc min and max in the super class
|
||||
|
||||
// additional handling for space (default 15% space)
|
||||
// float space = Math.abs(mDeltaY / 100f * 15f);
|
||||
// float space = Math.abs(mDeltaY / 100f * 15f);
|
||||
float space = Math.abs(Math.max(Math.abs(mYChartMax), Math.abs(mYChartMin)) / 100f * 15f);
|
||||
|
||||
if (mStartAtZero) {
|
||||
|
@ -658,7 +660,7 @@ public abstract class BarLineChartBase extends Chart {
|
|||
} else { // BOTH SIDED
|
||||
|
||||
drawXLabels(getOffsetTop() - 7);
|
||||
drawXLabels(getHeight() - mOffsetBottom + mXLabels.mXLabelHeight + yoffset * 1.5f);
|
||||
drawXLabels(getHeight() - mOffsetBottom + mXLabels.mXLabelHeight + yoffset * 1.6f);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -686,7 +688,26 @@ public abstract class BarLineChartBase extends Chart {
|
|||
|
||||
if (position[0] >= mOffsetLeft && position[0] <= getWidth() - mOffsetRight) {
|
||||
|
||||
mDrawCanvas.drawText(mCurrentData.getXVals().get(i), position[0],
|
||||
String label = mCurrentData.getXVals().get(i);
|
||||
|
||||
if (mXLabels.isAvoidFirstLastClippingEnabled()) {
|
||||
|
||||
// avoid clipping of the last
|
||||
if (i == mCurrentData.getXValCount()- 1) {
|
||||
float width = Utils.calcTextWidth(mXLabelPaint, label);
|
||||
|
||||
if (width > getOffsetRight() * 2 && position[0] + width > getWidth())
|
||||
position[0] -= width / 2;
|
||||
|
||||
// avoid clipping of the first
|
||||
} else if (i == 0) {
|
||||
|
||||
float width = Utils.calcTextWidth(mXLabelPaint, label);
|
||||
position[0] += width / 2;
|
||||
}
|
||||
}
|
||||
|
||||
mDrawCanvas.drawText(label, position[0],
|
||||
yPos,
|
||||
mXLabelPaint);
|
||||
}
|
||||
|
@ -968,6 +989,22 @@ public abstract class BarLineChartBase extends Chart {
|
|||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/** touchlistener that handles touches and gestures on the chart */
|
||||
protected OnTouchListener mListener;
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
|
||||
if (mListener == null || mDataNotSet)
|
||||
return false;
|
||||
|
||||
// check if touch gestures are enabled
|
||||
if (!mTouchEnabled)
|
||||
return false;
|
||||
else
|
||||
return mListener.onTouch(this, event);
|
||||
}
|
||||
|
||||
/**
|
||||
* ################ ################ ################ ################
|
||||
|
@ -1203,6 +1240,16 @@ public abstract class BarLineChartBase extends Chart {
|
|||
* ################ ################ ################ ################
|
||||
*/
|
||||
/** CODE BELOW IS GETTERS AND SETTERS */
|
||||
|
||||
/**
|
||||
* set a new (e.g. custom) charttouchlistener NOTE: make sure to
|
||||
* setTouchEnabled(true); if you need touch gestures on the chart
|
||||
*
|
||||
* @param l
|
||||
*/
|
||||
public void setOnTouchListener(OnTouchListener l) {
|
||||
this.mListener = l;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the OnDrawListener
|
||||
|
|
|
@ -2,9 +2,14 @@
|
|||
package com.github.mikephil.charting.charts;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Paint;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.github.mikephil.charting.data.CandleData;
|
||||
import com.github.mikephil.charting.data.CandleDataSet;
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Chart that draws candle-sticks.
|
||||
|
@ -36,8 +41,38 @@ public class CandleStickChart extends BarLineChartBase {
|
|||
|
||||
@Override
|
||||
protected void drawData() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
ArrayList<CandleDataSet> dataSets = (ArrayList<CandleDataSet>) mCurrentData.getDataSets();
|
||||
|
||||
mRenderPaint.setStyle(Paint.Style.STROKE);
|
||||
|
||||
for (int i = 0; i < mCurrentData.getDataSetCount(); i++) {
|
||||
|
||||
CandleDataSet dataSet = dataSets.get(i);
|
||||
ArrayList<? extends Entry> entries = dataSet.getYVals();
|
||||
|
||||
float[] valuePoints = generateTransformedValues(entries, 0f);
|
||||
|
||||
for (int j = 0; j < (valuePoints.length - 2) * mPhaseX; j += 2) {
|
||||
|
||||
// get the color that is specified for this position from
|
||||
// the DataSet, this will reuse colors, if the index is out
|
||||
// of bounds
|
||||
mRenderPaint.setColor(dataSet.getColor(j / 2));
|
||||
|
||||
if (isOffContentRight(valuePoints[j]))
|
||||
break;
|
||||
|
||||
// make sure the lines don't do shitty things outside bounds
|
||||
if (j != 0 && isOffContentLeft(valuePoints[j - 1])
|
||||
&& isOffContentTop(valuePoints[j + 1])
|
||||
&& isOffContentBottom(valuePoints[j + 1]))
|
||||
continue;
|
||||
|
||||
mDrawCanvas.drawLine(valuePoints[j], valuePoints[j + 1], valuePoints[j + 2],
|
||||
valuePoints[j + 3], mRenderPaint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -871,22 +871,6 @@ public abstract class Chart extends View implements AnimatorUpdateListener {
|
|||
*/
|
||||
protected abstract void drawHighlights();
|
||||
|
||||
/** touchlistener that handles touches and gestures on the chart */
|
||||
protected OnTouchListener mListener;
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
|
||||
if (mListener == null || mDataNotSet)
|
||||
return false;
|
||||
|
||||
// check if touch gestures are enabled
|
||||
if (!mTouchEnabled)
|
||||
return false;
|
||||
else
|
||||
return mListener.onTouch(this, event);
|
||||
}
|
||||
|
||||
/**
|
||||
* ################ ################ ################ ################
|
||||
*/
|
||||
|
@ -1189,16 +1173,6 @@ public abstract class Chart extends View implements AnimatorUpdateListener {
|
|||
*/
|
||||
/** BELOW THIS ONLY GETTERS AND SETTERS */
|
||||
|
||||
/**
|
||||
* set a new (e.g. custom) charttouchlistener NOTE: make sure to
|
||||
* setTouchEnabled(true); if you need touch gestures on the chart
|
||||
*
|
||||
* @param l
|
||||
*/
|
||||
public void setOnTouchListener(OnTouchListener l) {
|
||||
this.mListener = l;
|
||||
}
|
||||
|
||||
/**
|
||||
* set a selection listener for the chart
|
||||
*
|
||||
|
|
|
@ -13,6 +13,7 @@ import android.graphics.Typeface;
|
|||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View.OnTouchListener;
|
||||
|
||||
import com.github.mikephil.charting.data.DataSet;
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
|
@ -92,6 +93,9 @@ public class PieChart extends Chart {
|
|||
* chart
|
||||
*/
|
||||
private Paint mCenterTextPaint;
|
||||
|
||||
/** the piechart touchlistener */
|
||||
private OnTouchListener mListener;
|
||||
|
||||
public PieChart(Context context) {
|
||||
super(context);
|
||||
|
@ -273,9 +277,9 @@ public class PieChart extends Chart {
|
|||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
|
||||
// use the piecharts own listener
|
||||
return mListener.onTouch(this, event);
|
||||
if(mTouchEnabled && mListener != null) return mListener.onTouch(this, event);
|
||||
else return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
/** the angle where the dragging started */
|
||||
|
@ -613,6 +617,16 @@ public class PieChart extends Chart {
|
|||
private float calcAngle(float value) {
|
||||
return value / mCurrentData.getYValueSum() * 360f;
|
||||
}
|
||||
|
||||
/**
|
||||
* set a new (e.g. custom) charttouchlistener NOTE: make sure to
|
||||
* setTouchEnabled(true); if you need touch gestures on the chart
|
||||
*
|
||||
* @param l
|
||||
*/
|
||||
public void setOnTouchListener(OnTouchListener l) {
|
||||
this.mListener = l;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the pie index for the pie at the given angle
|
||||
|
|
|
@ -37,6 +37,12 @@ public class XLabels extends LabelBase {
|
|||
/** if true, x-axis label text is centered when using barcharts */
|
||||
private boolean mCenterXAxisLabels = false;
|
||||
|
||||
/**
|
||||
* if set to true, the chart will avoid that the first and last label entry
|
||||
* in the chart "clip" off the edge of the chart
|
||||
*/
|
||||
private boolean mAvoidFirstLastClipping = false;
|
||||
|
||||
/**
|
||||
* if set to true, the x-axis label entries will adjust themselves when
|
||||
* scaling the graph
|
||||
|
@ -126,4 +132,23 @@ public class XLabels extends LabelBase {
|
|||
public int getSpaceBetweenLabels() {
|
||||
return mSpaceBetweenLabels;
|
||||
}
|
||||
|
||||
/**
|
||||
* if set to true, the chart will avoid that the first and last label entry
|
||||
* in the chart "clip" off the edge of the chart or the screen
|
||||
*
|
||||
* @param enabled
|
||||
*/
|
||||
public void setAvoidFirstLastClipping(boolean enabled) {
|
||||
mAvoidFirstLastClipping = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns true if avoid-first-lastclipping is enabled, false if not
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isAvoidFirstLastClippingEnabled() {
|
||||
return mAvoidFirstLastClipping;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue