From 4ec22d799514ec37fe735069a5760ea03d1bb0f2 Mon Sep 17 00:00:00 2001 From: Daniel Cohen Gindi Date: Tue, 2 Jun 2015 23:53:51 +0300 Subject: [PATCH] Allow to `setHighlightEnabled` on a single DataSet https://github.com/danielgindi/ios-charts/issues/114 --- .../InvertedLineChartActivity.java | 2 +- .../mpchartexample/LineChartActivity1.java | 2 +- .../mpchartexample/PerformanceLineChart.java | 2 +- .../fragments/BarChartFrag.java | 2 +- .../fragments/ComplexityFragment.java | 2 +- .../fragments/ScatterChartFrag.java | 2 +- .../fragments/SineCosineFragment.java | 2 +- .../charting/charts/BarLineChartBase.java | 20 +---------------- .../mikephil/charting/charts/Chart.java | 8 +++---- .../mikephil/charting/charts/PieChart.java | 2 +- .../mikephil/charting/charts/RadarChart.java | 2 +- .../mikephil/charting/data/ChartData.java | 22 +++++++++++++++++++ .../mikephil/charting/data/DataSet.java | 22 +++++++++++++++++++ .../charting/renderer/BarChartRenderer.java | 2 +- .../renderer/BubbleChartRenderer.java | 2 +- .../renderer/CandleStickChartRenderer.java | 2 +- .../charting/renderer/LineChartRenderer.java | 2 +- .../charting/renderer/PieChartRenderer.java | 14 ++++++------ .../charting/renderer/RadarChartRenderer.java | 2 +- .../renderer/ScatterChartRenderer.java | 2 +- 20 files changed, 70 insertions(+), 46 deletions(-) diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/InvertedLineChartActivity.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/InvertedLineChartActivity.java index 2ee5e9cd9c..7d25228a1b 100644 --- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/InvertedLineChartActivity.java +++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/InvertedLineChartActivity.java @@ -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); diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity1.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity1.java index db47e161fe..b19f814418 100644 --- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity1.java +++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity1.java @@ -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"); diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/PerformanceLineChart.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/PerformanceLineChart.java index ed91daf4f4..fa8a393d09 100644 --- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/PerformanceLineChart.java +++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/PerformanceLineChart.java @@ -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); diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/fragments/BarChartFrag.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/fragments/BarChartFrag.java index e1c5aa4309..dcaace51f9 100644 --- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/fragments/BarChartFrag.java +++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/fragments/BarChartFrag.java @@ -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); diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/fragments/ComplexityFragment.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/fragments/ComplexityFragment.java index 6968d09b1f..c4fdd7580f 100644 --- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/fragments/ComplexityFragment.java +++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/fragments/ComplexityFragment.java @@ -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()); diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/fragments/ScatterChartFrag.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/fragments/ScatterChartFrag.java index 878aab976d..3e07869555 100644 --- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/fragments/ScatterChartFrag.java +++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/fragments/ScatterChartFrag.java @@ -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)); diff --git a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/fragments/SineCosineFragment.java b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/fragments/SineCosineFragment.java index 35f459eff4..ec783286cb 100644 --- a/MPChartExample/src/com/xxmassdeveloper/mpchartexample/fragments/SineCosineFragment.java +++ b/MPChartExample/src/com/xxmassdeveloper/mpchartexample/fragments/SineCosineFragment.java @@ -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()); diff --git a/MPChartLib/src/com/github/mikephil/charting/charts/BarLineChartBase.java b/MPChartLib/src/com/github/mikephil/charting/charts/BarLineChartBase.java index 707afaa883..261c17a84e 100644 --- a/MPChartLib/src/com/github/mikephil/charting/charts/BarLineChartBase.java +++ b/MPChartLib/src/com/github/mikephil/charting/charts/BarLineChartBase.java @@ -75,12 +75,6 @@ public abstract class BarLineChartBase 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. diff --git a/MPChartLib/src/com/github/mikephil/charting/data/DataSet.java b/MPChartLib/src/com/github/mikephil/charting/data/DataSet.java index 366f63de96..e5b813349b 100644 --- a/MPChartLib/src/com/github/mikephil/charting/data/DataSet.java +++ b/MPChartLib/src/com/github/mikephil/charting/data/DataSet.java @@ -69,6 +69,9 @@ public abstract class DataSet { /** 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 @@ -614,6 +617,25 @@ public void resetColors() { mColors = new ArrayList(); } + /** + * 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. diff --git a/MPChartLib/src/com/github/mikephil/charting/renderer/BarChartRenderer.java b/MPChartLib/src/com/github/mikephil/charting/renderer/BarChartRenderer.java index d06fb15223..feae3e4606 100644 --- a/MPChartLib/src/com/github/mikephil/charting/renderer/BarChartRenderer.java +++ b/MPChartLib/src/com/github/mikephil/charting/renderer/BarChartRenderer.java @@ -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; diff --git a/MPChartLib/src/com/github/mikephil/charting/renderer/BubbleChartRenderer.java b/MPChartLib/src/com/github/mikephil/charting/renderer/BubbleChartRenderer.java index 3031b460b9..40d4f06074 100644 --- a/MPChartLib/src/com/github/mikephil/charting/renderer/BubbleChartRenderer.java +++ b/MPChartLib/src/com/github/mikephil/charting/renderer/BubbleChartRenderer.java @@ -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); diff --git a/MPChartLib/src/com/github/mikephil/charting/renderer/CandleStickChartRenderer.java b/MPChartLib/src/com/github/mikephil/charting/renderer/CandleStickChartRenderer.java index 598cbae367..2dacf4daa5 100644 --- a/MPChartLib/src/com/github/mikephil/charting/renderer/CandleStickChartRenderer.java +++ b/MPChartLib/src/com/github/mikephil/charting/renderer/CandleStickChartRenderer.java @@ -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()); diff --git a/MPChartLib/src/com/github/mikephil/charting/renderer/LineChartRenderer.java b/MPChartLib/src/com/github/mikephil/charting/renderer/LineChartRenderer.java index 604681459c..9aab70863f 100644 --- a/MPChartLib/src/com/github/mikephil/charting/renderer/LineChartRenderer.java +++ b/MPChartLib/src/com/github/mikephil/charting/renderer/LineChartRenderer.java @@ -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()); diff --git a/MPChartLib/src/com/github/mikephil/charting/renderer/PieChartRenderer.java b/MPChartLib/src/com/github/mikephil/charting/renderer/PieChartRenderer.java index 05df5ee483..6764225934 100644 --- a/MPChartLib/src/com/github/mikephil/charting/renderer/PieChartRenderer.java +++ b/MPChartLib/src/com/github/mikephil/charting/renderer/PieChartRenderer.java @@ -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 @@ -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(); diff --git a/MPChartLib/src/com/github/mikephil/charting/renderer/RadarChartRenderer.java b/MPChartLib/src/com/github/mikephil/charting/renderer/RadarChartRenderer.java index 7496c6a451..44cf2e3b4d 100644 --- a/MPChartLib/src/com/github/mikephil/charting/renderer/RadarChartRenderer.java +++ b/MPChartLib/src/com/github/mikephil/charting/renderer/RadarChartRenderer.java @@ -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()); diff --git a/MPChartLib/src/com/github/mikephil/charting/renderer/ScatterChartRenderer.java b/MPChartLib/src/com/github/mikephil/charting/renderer/ScatterChartRenderer.java index 3d279091f5..cb154ef20e 100644 --- a/MPChartLib/src/com/github/mikephil/charting/renderer/ScatterChartRenderer.java +++ b/MPChartLib/src/com/github/mikephil/charting/renderer/ScatterChartRenderer.java @@ -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());