Skip to content

Commit

Permalink
Allow to setHighlightEnabled on a single DataSet
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgindi committed Jun 2, 2015
1 parent f32cfd0 commit 4ec22d7
Show file tree
Hide file tree
Showing 20 changed files with 70 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected void onCreate(Bundle savedInstanceState) {

// enable/disable highlight indicators (the lines that indicate the
// highlighted Entry)
mChart.setHighlightIndicatorEnabled(false);
mChart.setHighlightEnabled(false);

XAxis xl = mChart.getXAxis();
xl.setAvoidFirstLastClipping(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected void onCreate(Bundle savedInstanceState) {

// enable/disable highlight indicators (the lines that indicate the
// highlighted Entry)
mChart.setHighlightIndicatorEnabled(false);
mChart.setHighlightEnabled(false);

// x-axis limit line
// LimitLine llXAxis = new LimitLine(10f, "Index 10");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected void onCreate(Bundle savedInstanceState) {

// enable/disable highlight indicators (the lines that indicate the
// highlighted Entry)
mChart.setHighlightIndicatorEnabled(false);
mChart.setHighlightEnabled(false);

mChart.getAxisLeft().setDrawGridLines(false);
mChart.getAxisRight().setEnabled(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa

mChart.setMarkerView(mv);

mChart.setHighlightIndicatorEnabled(false);
mChart.setHighlightEnabled(false);

mChart.setDrawGridBackground(false);
mChart.setDrawBarShadow(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa

mChart.setDescription("");

mChart.setHighlightIndicatorEnabled(false);
mChart.setHighlightEnabled(false);
mChart.setDrawGridBackground(false);

mChart.setData(getComplexity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa

mChart.setMarkerView(mv);

mChart.setHighlightIndicatorEnabled(false);
mChart.setHighlightEnabled(false);
mChart.setDrawGridBackground(false);
mChart.setData(generateScatterData(6, 10000, 200));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
mChart.setDescription("");
// mChart.setCircleSize(5f);

mChart.setHighlightIndicatorEnabled(false);
mChart.setHighlightEnabled(false);
mChart.setDrawGridBackground(false);

mChart.setData(generateLineData());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,6 @@ public abstract class BarLineChartBase<T extends BarLineScatterCandleData<? exte
*/
protected boolean mHighlightPerDragEnabled = true;

/**
* if set to true, the highlight indicator (lines for linechart, dark bar
* for barchart) will be drawn upon selecting values.
*/
protected boolean mHighLightIndicatorEnabled = true;

/** if true, dragging is enabled for the chart */
private boolean mDragEnabled = true;

Expand Down Expand Up @@ -244,7 +238,7 @@ protected void onDraw(Canvas canvas) {
mAxisRendererRight.renderLimitLines(canvas);

// if highlighting is enabled
if (mHighlightEnabled && mHighLightIndicatorEnabled && valuesToHighlight())
if (valuesToHighlight())
mRenderer.drawHighlighted(canvas, mIndicesToHightlight);

// Removes clipping rectangle
Expand Down Expand Up @@ -889,18 +883,6 @@ public int getMaxVisibleCount() {
return mMaxVisibleCount;
}

/**
* If set to true, the highlight indicator (vertical line for LineChart and
* ScatterChart, dark bar overlay for BarChart) that gives visual indication
* that an Entry has been selected will be drawn upon selecting values. This
* does not depend on the MarkerView. Default: true
*
* @param enabled
*/
public void setHighlightIndicatorEnabled(boolean enabled) {
mHighLightIndicatorEnabled = enabled;
}

/**
* Set this to true to allow highlighting per dragging over the chart
* surface when it is fully zoomed out. Default: true
Expand Down
8 changes: 3 additions & 5 deletions MPChartLib/src/com/github/mikephil/charting/charts/Chart.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ public abstract class Chart<T extends ChartData<? extends DataSet<? extends Entr
/** if true, touch gestures are enabled on the chart */
protected boolean mTouchEnabled = true;

/** if true, value highlightning is enabled */
protected boolean mHighlightEnabled = true;

/** the legend object containing all data associated with the legend */
protected Legend mLegend;

Expand Down Expand Up @@ -865,7 +862,8 @@ public OnChartGestureListener getOnChartGestureListener() {
* @param enabled
*/
public void setHighlightEnabled(boolean enabled) {
mHighlightEnabled = enabled;
if (mData != null)
mData.setHighlightEnabled(enabled);
}

/**
Expand All @@ -874,7 +872,7 @@ public void setHighlightEnabled(boolean enabled) {
* @return
*/
public boolean isHighlightEnabled() {
return mHighlightEnabled;
return mData == null ? true : mData.isHighlightEnabled();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected void onDraw(Canvas canvas) {

mRenderer.drawData(canvas);

if (mHighlightEnabled && valuesToHighlight())
if (valuesToHighlight())
mRenderer.drawHighlighted(canvas, mIndicesToHightlight);

mRenderer.drawExtras(canvas);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ protected void onDraw(Canvas canvas) {

mRenderer.drawData(canvas);

if (mHighlightEnabled && valuesToHighlight())
if (valuesToHighlight())
mRenderer.drawHighlighted(canvas, mIndicesToHightlight);

mYAxisRenderer.renderAxisLabels(canvas);
Expand Down
22 changes: 22 additions & 0 deletions MPChartLib/src/com/github/mikephil/charting/data/ChartData.java
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,28 @@ public void setDrawValues(boolean enabled) {
}
}

/**
* Enables / disables highlighting values for all DataSets this data object contains.
*/
public void setHighlightEnabled(boolean enabled) {
for (DataSet<?> set : mDataSets) {
set.setHighlightEnabled(enabled);
}
}

/**
* returns true if highlighting of values is enabled, false if not
*
* @return
*/
public boolean isHighlightEnabled() {
for (DataSet<?> set : mDataSets) {
if (!set.isHighlightEnabled())
return false;
}
return true;
}

/**
* Clears this data object from all DataSets and removes all Entries. Don't
* forget to invalidate the chart after this.
Expand Down
22 changes: 22 additions & 0 deletions MPChartLib/src/com/github/mikephil/charting/data/DataSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public abstract class DataSet<T extends Entry> {
/** this specifies which axis this DataSet should be plotted against */
protected AxisDependency mAxisDependency = AxisDependency.LEFT;

/** if true, value highlightning is enabled */
protected boolean mHighlightEnabled = true;

/**
* Creates a new DataSet object with the given values it represents. Also, a
* label that describes the DataSet can be specified. The label can also be
Expand Down Expand Up @@ -614,6 +617,25 @@ public void resetColors() {
mColors = new ArrayList<Integer>();
}

/**
* If set to true, value highlighting is enabled which means that values can
* be highlighted programmatically or by touch gesture.
*
* @param enabled
*/
public void setHighlightEnabled(boolean enabled) {
mHighlightEnabled = enabled;
}

/**
* returns true if highlighting of values is enabled, false if not
*
* @return
*/
public boolean isHighlightEnabled() {
return mHighlightEnabled;
}

/**
* Returns the position of the provided entry in the DataSets Entry array.
* Returns -1 if doesn't exist.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public void drawHighlighted(Canvas c, Highlight[] indices) {
int dataSetIndex = h.getDataSetIndex();
BarDataSet set = mChart.getBarData().getDataSetByIndex(dataSetIndex);

if (set == null)
if (set == null || !set.isHighlightEnabled())
continue;

float barspaceHalf = set.getBarSpace() / 2f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public void drawHighlighted(Canvas c, Highlight[] indices) {

BubbleDataSet dataSet = bubbleData.getDataSetByIndex(indice.getDataSetIndex());

if (dataSet == null)
if (dataSet == null || !dataSet.isHighlightEnabled())
continue;

Entry entryFrom = dataSet.getEntryForXIndex(mMinX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public void drawHighlighted(Canvas c, Highlight[] indices) {
CandleDataSet set = mChart.getCandleData().getDataSetByIndex(
indices[i].getDataSetIndex());

if (set == null)
if (set == null || !set.isHighlightEnabled())
continue;

mHighlightPaint.setColor(set.getHighLightColor());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ public void drawHighlighted(Canvas c, Highlight[] indices) {
LineDataSet set = mChart.getLineData().getDataSetByIndex(indices[i]
.getDataSetIndex());

if (set == null)
if (set == null || !set.isHighlightEnabled())
continue;

mHighlightPaint.setColor(set.getHighLightColor());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,13 @@ public void drawHighlighted(Canvas c, Highlight[] indices) {
if (xIndex >= drawAngles.length)
continue;

PieDataSet set = mChart.getData()
.getDataSetByIndex(indices[i]
.getDataSetIndex());

if (set == null || !set.isHighlightEnabled())
continue;

if (xIndex == 0)
angle = rotationAngle;
else
Expand All @@ -393,13 +400,6 @@ public void drawHighlighted(Canvas c, Highlight[] indices) {

float sliceDegrees = drawAngles[xIndex];

PieDataSet set = mChart.getData()
.getDataSetByIndex(indices[i]
.getDataSetIndex());

if (set == null)
continue;

float shift = set.getSelectionShift();
RectF circleBox = mChart.getCircleBox();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public void drawHighlighted(Canvas c, Highlight[] indices) {
.getDataSetByIndex(indices[i]
.getDataSetIndex());

if (set == null)
if (set == null || !set.isHighlightEnabled())
continue;

mHighlightPaint.setColor(set.getHighLightColor());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public void drawHighlighted(Canvas c, Highlight[] indices) {
ScatterDataSet set = mChart.getScatterData().getDataSetByIndex(indices[i]
.getDataSetIndex());

if (set == null)
if (set == null || !set.isHighlightEnabled())
continue;

mHighlightPaint.setColor(set.getHighLightColor());
Expand Down

0 comments on commit 4ec22d7

Please sign in to comment.