Skip to content

Commit 690dd87

Browse files
committed
Work on highlighting
1 parent 7db6b7e commit 690dd87

28 files changed

Lines changed: 672 additions & 665 deletions

‎MPChartExample/src/com/xxmassdeveloper/mpchartexample/StackedBarActivity.java‎

Lines changed: 231 additions & 229 deletions
Large diffs are not rendered by default.

‎MPChartExample/src/com/xxmassdeveloper/mpchartexample/StackedBarActivityNegative.java‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,17 @@ protected void onCreate(Bundle savedInstanceState) {
8080

8181
// IMPORTANT: When using negative values in stacked bars, always make sure the negative values are in the array first
8282
ArrayList<BarEntry> yValues = new ArrayList<BarEntry>();
83-
yValues.add(new BarEntry(new float[]{ -10, 10 }, 0));
84-
yValues.add(new BarEntry(new float[]{ -12, 13 }, 1));
85-
yValues.add(new BarEntry(new float[]{ -15, 15 }, 2));
86-
yValues.add(new BarEntry(new float[]{ -17, 17 }, 3));
87-
yValues.add(new BarEntry(new float[]{ -19, 20 }, 4));
88-
yValues.add(new BarEntry(new float[]{ -19, 19 }, 5));
89-
yValues.add(new BarEntry(new float[]{ -16, 16 }, 6));
90-
yValues.add(new BarEntry(new float[]{ -13, 14 }, 7));
91-
yValues.add(new BarEntry(new float[]{ -10, 11 }, 8));
92-
yValues.add(new BarEntry(new float[]{ -5, 6 }, 9));
93-
yValues.add(new BarEntry(new float[]{ -1, 2 }, 10));
83+
yValues.add(new BarEntry(0, new float[]{ -10, 10 }));
84+
yValues.add(new BarEntry(1, new float[]{ -12, 13 }));
85+
yValues.add(new BarEntry(2, new float[]{ -15, 15 }));
86+
yValues.add(new BarEntry(3, new float[]{ -17, 17 }));
87+
yValues.add(new BarEntry(4, new float[]{ -19, 20 }));
88+
yValues.add(new BarEntry(5, new float[]{ -19, 19 }));
89+
yValues.add(new BarEntry(6, new float[]{ -16, 16 }));
90+
yValues.add(new BarEntry(7, new float[]{ -13, 14 }));
91+
yValues.add(new BarEntry(8, new float[]{ -10, 11 }));
92+
yValues.add(new BarEntry(9, new float[]{ -5, 6 }));
93+
yValues.add(new BarEntry(10, new float[]{ -1, 2 }));
9494

9595
BarDataSet set = new BarDataSet(yValues, "Age Distribution");
9696
set.setValueFormatter(new CustomFormatter());

‎MPChartLib/src/com/github/mikephil/charting/charts/Chart.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ public void highlightValue(Highlight high, boolean callListener) {
614614
} else {
615615
if (this instanceof BarLineChartBase
616616
&& ((BarLineChartBase)this).isHighlightFullBarEnabled())
617-
high = new Highlight(high.getXIndex(), Float.NaN, -1, -1, -1);
617+
high = new Highlight(high.getX(), Float.NaN, -1, -1, -1);
618618

619619
// set the indices to highlight
620620
mIndicesToHighlight = new Highlight[]{
@@ -681,19 +681,19 @@ protected void drawMarkers(Canvas canvas) {
681681
for (int i = 0; i < mIndicesToHighlight.length; i++) {
682682

683683
Highlight highlight = mIndicesToHighlight[i];
684-
int xIndex = highlight.getXIndex();
684+
float xVal = highlight.getX();
685685
int dataSetIndex = highlight.getDataSetIndex();
686686

687687
float deltaX = mXAxis != null
688688
? mXAxis.mAxisRange
689689
: ((mData == null ? 0.f : mData.getXValCount()) - 1.f);
690690

691-
if (xIndex <= deltaX && xIndex <= deltaX * mAnimator.getPhaseX()) {
691+
if (xVal <= deltaX && xVal <= deltaX * mAnimator.getPhaseX()) {
692692

693693
Entry e = mData.getEntryForHighlight(mIndicesToHighlight[i]);
694694

695695
// make sure entry not null
696-
if (e == null || e.getX() != mIndicesToHighlight[i].getXIndex())
696+
if (e == null || e.getX() != mIndicesToHighlight[i].getX())
697697
continue;
698698

699699
float[] pos = getMarkerPosition(e, highlight);

‎MPChartLib/src/com/github/mikephil/charting/charts/PieChart.java‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.util.AttributeSet;
1111

1212
import com.github.mikephil.charting.components.XAxis;
13+
import com.github.mikephil.charting.data.DataSet;
1314
import com.github.mikephil.charting.data.Entry;
1415
import com.github.mikephil.charting.data.PieData;
1516
import com.github.mikephil.charting.highlight.Highlight;
@@ -180,17 +181,17 @@ protected float[] getMarkerPosition(Entry e, Highlight highlight) {
180181

181182
float rotationAngle = getRotationAngle();
182183

183-
int i = highlight.getXIndex();
184+
int entryIndex = getData().getDataSet().getEntryIndex(highlight.getX(), DataSet.Rounding.CLOSEST);
184185

185186
// offset needed to center the drawn text in the slice
186-
float offset = mDrawAngles[i] / 2;
187+
float offset = mDrawAngles[entryIndex] / 2;
187188

188189
// calculate the text position
189190
float x = (float) (r
190-
* Math.cos(Math.toRadians((rotationAngle + mAbsoluteAngles[i] - offset)
191+
* Math.cos(Math.toRadians((rotationAngle + mAbsoluteAngles[entryIndex] - offset)
191192
* mAnimator.getPhaseY())) + center.x);
192193
float y = (float) (r
193-
* Math.sin(Math.toRadians((rotationAngle + mAbsoluteAngles[i] - offset)
194+
* Math.sin(Math.toRadians((rotationAngle + mAbsoluteAngles[entryIndex] - offset)
194195
* mAnimator.getPhaseY())) + center.y);
195196

196197
return new float[]{x, y};
@@ -247,7 +248,7 @@ public boolean needsHighlight(int xIndex, int dataSetIndex) {
247248
for (int i = 0; i < mIndicesToHighlight.length; i++)
248249

249250
// check if the xvalue for the given dataset needs highlight
250-
if (mIndicesToHighlight[i].getXIndex() == xIndex
251+
if (mIndicesToHighlight[i].getX() == xIndex
251252
&& mIndicesToHighlight[i].getDataSetIndex() == dataSetIndex)
252253
return true;
253254

‎MPChartLib/src/com/github/mikephil/charting/charts/PieRadarChartBase.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import com.github.mikephil.charting.animation.Easing;
1616
import com.github.mikephil.charting.components.Legend;
17-
import com.github.mikephil.charting.components.Legend.LegendPosition;
1817
import com.github.mikephil.charting.components.XAxis;
1918
import com.github.mikephil.charting.data.ChartData;
2019
import com.github.mikephil.charting.data.Entry;
@@ -458,7 +457,7 @@ public List<SelectionDetail> getSelectionDetailsAtIndex(int xIndex) {
458457
IDataSet<?> dataSet = mData.getDataSetByIndex(i);
459458

460459
// extract all y-values from all DataSets at the given x-index
461-
final float yVal = dataSet.getYValForXIndex(xIndex);
460+
final float yVal = dataSet.getYValueForXValue(xIndex);
462461
if (Float.isNaN(yVal))
463462
continue;
464463

0 commit comments

Comments
 (0)