Skip to content

Commit

Permalink
Merged pull requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilJay committed Aug 15, 2014
2 parents 06ac484 + 4f151cd commit 81b883f
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -655,24 +655,21 @@ private void drawXLabels(float yPos) {
0f, 0f
};

for (int i = 0; i < mCurrentData.getXValCount(); i++) {
for (int i = 0; i < mCurrentData.getXValCount(); i += mXLabels.mXAxisLabelModulus) {

if (i % mXLabels.mXAxisLabelModulus == 0) {
position[0] = i;

position[0] = i;
// center the text
if (mXLabels.isCenterXLabelsEnabled())
position[0] += 0.5f;

// center the text
if (mXLabels.isCenterXLabelsEnabled())
position[0] += 0.5f;
transformPointArray(position);

transformPointArray(position);
if (position[0] >= mOffsetLeft && position[0] <= getWidth() - mOffsetRight) {

if (position[0] >= mOffsetLeft && position[0] <= getWidth() - mOffsetRight) {

mDrawCanvas.drawText(mCurrentData.getXVals().get(i), position[0],
yPos,
mXLabelPaint);
}
mDrawCanvas.drawText(mCurrentData.getXVals().get(i), position[0],
yPos,
mXLabelPaint);
}
}
}
Expand Down Expand Up @@ -848,19 +845,16 @@ protected void drawVerticalGrid() {
0f, 0f
};

for (int i = 0; i < mCurrentData.getXValCount(); i++) {

if (i % mXLabels.mXAxisLabelModulus == 0) {
for (int i = 0; i < mCurrentData.getXValCount(); i += mXLabels.mXAxisLabelModulus) {

position[0] = i;
position[0] = i;

transformPointArray(position);
transformPointArray(position);

if (position[0] >= mOffsetLeft && position[0] <= getWidth()) {
if (position[0] >= mOffsetLeft && position[0] <= getWidth()) {

mDrawCanvas.drawLine(position[0], mOffsetTop, position[0], getHeight()
- mOffsetBottom, mGridPaint);
}
mDrawCanvas.drawLine(position[0], mOffsetTop, position[0], getHeight()
- mOffsetBottom, mGridPaint);
}
}
}
Expand Down Expand Up @@ -1517,6 +1511,11 @@ public Highlight getHighlightByTouchPoint(float x, float y) {
}
}

if(mDataNotSet) {
Log.i(LOG_TAG, "no data set");
return null;
}

ArrayList<SelInfo> valsAtIndex = getYValsAtIndex(xIndex);

dataSetIndex = getClosestDataSetIndex(valsAtIndex, (float) yTouchVal);
Expand Down
68 changes: 65 additions & 3 deletions MPChartLib/src/com/github/mikephil/charting/charts/Chart.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.graphics.Typeface;
import android.os.Environment;
import android.provider.MediaStore.Images;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
Expand Down Expand Up @@ -193,6 +194,15 @@ public abstract class Chart extends View {
/** listener that is called when a value on the chart is selected */
protected OnChartValueSelectedListener mSelectionListener;

/** text that is displayed when the chart is empty */
private String mNoDataText = "No chart data available.";

/**
* text that is displayed when the chart is empty that describes why the
* chart is empty
*/
private String mNoDataTextDescription;

/** default constructor for initialization in code */
public Chart(Context context) {
super(context);
Expand Down Expand Up @@ -340,6 +350,32 @@ public void setData(ChartData data) {
// setData(data);
// }

// /**
// * Sets primitive data for the chart. Internally, this is converted into a
// * ChartData object with one DataSet (type 0). If you have more specific
// * requirements for your data, use the setData(ChartData data) method and
// * create your own ChartData object with as many DataSets as you like.
// *
// * @param xVals
// * @param yVals
// */
// public void setData(ArrayList<String> xVals, ArrayList<Float> yVals) {
//
// ArrayList<Entry> series = new ArrayList<Entry>();
//
// for (int i = 0; i < yVals.size(); i++) {
// series.add(new Entry(yVals.get(i), i));
// }
//
// DataSet set = new DataSet(series, "DataSet");
// ArrayList<DataSet> dataSets = new ArrayList<DataSet>();
// dataSets.add(set);
//
// ChartData data = new ChartData(xVals, dataSets);
//
// setData(data);
// }

/**
* does needed preparations for drawing
*/
Expand Down Expand Up @@ -384,7 +420,13 @@ protected void onDraw(Canvas canvas) {
if (mDataNotSet) { // check if there is data

// if no data, inform the user
canvas.drawText("No chart data available.", getWidth() / 2, getHeight() / 2, mInfoPaint);
canvas.drawText(mNoDataText, getWidth() / 2, getHeight() / 2, mInfoPaint);

if (!TextUtils.isEmpty(mNoDataTextDescription)) {
float textOffset = -mInfoPaint.ascent() + mInfoPaint.descent();
canvas.drawText(mNoDataTextDescription, getWidth() / 2, (getHeight() / 2)
+ textOffset, mInfoPaint);
}
return;
}

Expand Down Expand Up @@ -413,7 +455,7 @@ protected void prepareMatrix() {
mMatrixValueToPx.postScale(scaleX, -scaleY);

mMatrixOffset.reset();

mMatrixOffset.postTranslate(mOffsetLeft, getHeight() - mOffsetBottom);

// mMatrixOffset.setTranslate(mOffsetLeft, 0);
Expand Down Expand Up @@ -852,7 +894,7 @@ protected void drawDescription() {
@Override
public boolean onTouchEvent(MotionEvent event) {

if (mListener == null)
if (mListener == null || mDataNotSet)
return false;

// check if touch gestures are enabled
Expand Down Expand Up @@ -1176,6 +1218,26 @@ public void setDescription(String desc) {
this.mDescription = desc;
}

/**
* Sets the text that informs the user that there is no data available with
* which to draw the chart.
*
* @param text
*/
public void setNoDataText(String text) {
mNoDataText = text;
}

/**
* Sets descriptive text to explain to the user why there is no chart
* available Defaults to empty if not set
*
* @param text
*/
public void setNoDataTextDescription(String text) {
mNoDataTextDescription = text;
}

/**
* Sets the offsets from the border of the view to the actual chart in every
* direction manually. Provide density pixels -> they are then rendered to
Expand Down
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@ Remember: *It's all about the looks.*

The **experimental** branch might contain new features that are still buggy. It is recommended to be safe and only make use of the code on the **master** branch.

If you are having questions or problems, feel free to contact me, **create issues** for this project on GitHub or open questions on [**stackoverflow**](https://stackoverflow.com) with the `mpandroidchart` tag.

Forks, pull-requests or any other forms of contribution are always welcome.
Forks, pull-requests or any other forms of contribution are **always welcome**.

Demo
-----

For a brief overview of the most important features, please download the **PlayStore Demo** [**MPAndroidChart Example.apk**](https://play.google.com/store/apps/details?id=com.xxmassdeveloper.mpchartexample) and try it out.
For a brief overview of the most important features, please download the **PlayStore Demo** [**MPAndroidChart Example.apk**](https://play.google.com/store/apps/details?id=com.xxmassdeveloper.mpchartexample) and try it out. The corresponding code for the demo-application is also included in this repository inside the **MPChartExample folder**.

Questions & Issues
-----

If you are having questions or problems, feel free to contact me. Since I would very much like that other users of this library **can also benefit** from your question, I am asking you to contact me via e-mail **only as a last option**. Instead, you should:

- Open questions on [**stackoverflow**](https://stackoverflow.com) with the `mpandroidchart` tag
- Create Issues here on GitHub

Please let me know via e-mail that you have opened a stackoverflow question so that I can get to answering it right away. Thank you.

Features
=======
Expand Down

0 comments on commit 81b883f

Please sign in to comment.