Skip to content

Commit 4b058a5

Browse files
committed
Fixes regarding drawing of markerview
1 parent ac3eafa commit 4b058a5

2 files changed

Lines changed: 26 additions & 35 deletions

File tree

MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public void onStopTrackingTouch(SeekBar seekBar) {
234234

235235
private void setData(int count, float range) {
236236

237-
float start = 0f;
237+
float start = 1f;
238238

239239
mChart.getXAxis().setAxisMinValue(start);
240240
mChart.getXAxis().setAxisMaxValue(start + count + 2);

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

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -699,48 +699,39 @@ protected void drawMarkers(Canvas canvas) {
699699
for (int i = 0; i < mIndicesToHighlight.length; i++) {
700700

701701
Highlight highlight = mIndicesToHighlight[i];
702-
float xVal = highlight.getX();
703-
int dataSetIndex = highlight.getDataSetIndex();
704702

705-
float deltaX = mXAxis != null
706-
? mXAxis.mAxisRange
707-
: 1f;
703+
Entry e = mData.getEntryForHighlight(mIndicesToHighlight[i]);
708704

709-
if (xVal <= deltaX && xVal <= deltaX * mAnimator.getPhaseX()) {
705+
// make sure entry not null
706+
if (e == null || e.getX() != mIndicesToHighlight[i].getX())
707+
continue;
710708

711-
Entry e = mData.getEntryForHighlight(mIndicesToHighlight[i]);
709+
float[] pos = getMarkerPosition(e, highlight);
712710

713-
// make sure entry not null
714-
if (e == null || e.getX() != mIndicesToHighlight[i].getX())
715-
continue;
711+
// check bounds
712+
if (!mViewPortHandler.isInBounds(pos[0], pos[1]))
713+
continue;
716714

717-
float[] pos = getMarkerPosition(e, highlight);
715+
// callbacks to update the content
716+
mMarkerView.refreshContent(e, highlight);
718717

719-
// check bounds
720-
if (!mViewPortHandler.isInBounds(pos[0], pos[1]))
721-
continue;
718+
// mMarkerView.measure(MeasureSpec.makeMeasureSpec(0,
719+
// MeasureSpec.UNSPECIFIED),
720+
// MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
721+
// mMarkerView.layout(0, 0, mMarkerView.getMeasuredWidth(),
722+
// mMarkerView.getMeasuredHeight());
723+
// mMarkerView.draw(mDrawCanvas, pos[0], pos[1]);
722724

723-
// callbacks to update the content
724-
mMarkerView.refreshContent(e, highlight);
725+
mMarkerView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
726+
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
727+
mMarkerView.layout(0, 0, mMarkerView.getMeasuredWidth(),
728+
mMarkerView.getMeasuredHeight());
725729

726-
// mMarkerView.measure(MeasureSpec.makeMeasureSpec(0,
727-
// MeasureSpec.UNSPECIFIED),
728-
// MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
729-
// mMarkerView.layout(0, 0, mMarkerView.getMeasuredWidth(),
730-
// mMarkerView.getMeasuredHeight());
731-
// mMarkerView.draw(mDrawCanvas, pos[0], pos[1]);
732-
733-
mMarkerView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
734-
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
735-
mMarkerView.layout(0, 0, mMarkerView.getMeasuredWidth(),
736-
mMarkerView.getMeasuredHeight());
737-
738-
if (pos[1] - mMarkerView.getHeight() <= 0) {
739-
float y = mMarkerView.getHeight() - pos[1];
740-
mMarkerView.draw(canvas, pos[0], pos[1] + y);
741-
} else {
742-
mMarkerView.draw(canvas, pos[0], pos[1]);
743-
}
730+
if (pos[1] - mMarkerView.getHeight() <= 0) {
731+
float y = mMarkerView.getHeight() - pos[1];
732+
mMarkerView.draw(canvas, pos[0], pos[1] + y);
733+
} else {
734+
mMarkerView.draw(canvas, pos[0], pos[1]);
744735
}
745736
}
746737
}

0 commit comments

Comments
 (0)