Skip to content

Commit ded930a

Browse files
committed
Work on viewport modifications for horizontal barchart (issue PhilJay#1842)
1 parent 72890af commit ded930a

4 files changed

Lines changed: 45 additions & 12 deletions

File tree

MPChartExample/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ dependencies {
5757
compile project(':MPChartLib') // remove this if you only imported the example project
5858
compile 'com.android.support:appcompat-v7:23.1.1'
5959
compile 'io.realm:realm-android:0.87.5' // dependency for realm-database API (http://realm.io)
60-
//compile 'com.github.PhilJay:MPAndroidChart:v2.2.0'
60+
//compile 'com.github.PhilJay:MPAndroidChart:v2.2.5'
6161
}

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ public void setScaleMinima(float scaleX, float scaleY) {
719719
/**
720720
* Sets the size of the area (range on the x-axis) that should be maximum
721721
* visible at once (no further zooming out allowed). If this is e.g. set to
722-
* 10, no more than 10 values on the x-axis can be viewed at once without
722+
* 10, no more than a range of 10 on the x-axis can be viewed at once without
723723
* scrolling.
724724
*
725725
* @param maxXRange The maximum visible range of x-values.
@@ -732,7 +732,7 @@ public void setVisibleXRangeMaximum(float maxXRange) {
732732
/**
733733
* Sets the size of the area (range on the x-axis) that should be minimum
734734
* visible at once (no further zooming in allowed). If this is e.g. set to
735-
* 10, no less than 10 values on the x-axis can be viewed at once without
735+
* 10, no less than a range of 10 on the x-axis can be viewed at once without
736736
* scrolling.
737737
*
738738
* @param minXRange The minimum visible range of x-values.
@@ -743,9 +743,8 @@ public void setVisibleXRangeMinimum(float minXRange) {
743743
}
744744

745745
/**
746-
* Limits the maximum and minimum value count that can be visible by
747-
* pinching and zooming. e.g. minRange=10, maxRange=100 no less than 10
748-
* values and no more that 100 values can be viewed at once without
746+
* Limits the maximum and minimum x range that can be visible by pinching and zooming. e.g. minRange=10, maxRange=100 the
747+
* smallest range to be displayed at once is 10, and no more than a range of 100 values can be viewed at once without
749748
* scrolling
750749
*
751750
* @param minXRange
@@ -770,14 +769,14 @@ public void setVisibleYRangeMaximum(float maxYRange, AxisDependency axis) {
770769
}
771770

772771
/**
773-
* Moves the left side of the current viewport to the specified x-index.
772+
* Moves the left side of the current viewport to the specified x-position.
774773
* This also refreshes the chart by calling invalidate().
775774
*
776-
* @param xIndex
775+
* @param xValue
777776
*/
778-
public void moveViewToX(float xIndex) {
777+
public void moveViewToX(float xValue) {
779778

780-
Runnable job = new MoveViewJob(mViewPortHandler, xIndex, 0f,
779+
Runnable job = new MoveViewJob(mViewPortHandler, xValue, 0f,
781780
getTransformer(AxisDependency.LEFT), this);
782781

783782
addViewportJob(job);
@@ -802,7 +801,7 @@ public void moveViewToY(float yValue, AxisDependency axis) {
802801

803802
/**
804803
* This will move the left side of the current viewport to the specified
805-
* x value on the x-axis, and center the viewport to the specified y value on the y-axis.
804+
* x-value on the x-axis, and center the viewport to the specified y value on the y-axis.
806805
* This also refreshes the chart by calling invalidate().
807806
*
808807
* @param xValue
@@ -820,7 +819,7 @@ public void moveViewTo(float xValue, float yValue, AxisDependency axis) {
820819
}
821820

822821
/**
823-
* This will move the left side of the current viewport to the specified x value
822+
* This will move the left side of the current viewport to the specified x-value
824823
* and center the viewport to the y value animated.
825824
* This also refreshes the chart by calling invalidate().
826825
*

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.util.Log;
88

99
import com.github.mikephil.charting.components.XAxis.XAxisPosition;
10+
import com.github.mikephil.charting.components.YAxis;
1011
import com.github.mikephil.charting.components.YAxis.AxisDependency;
1112
import com.github.mikephil.charting.data.BarEntry;
1213
import com.github.mikephil.charting.data.Entry;
@@ -205,4 +206,23 @@ public float getHighestVisibleX() {
205206
mViewPortHandler.contentTop());
206207
return (float) Math.min(mXAxis.mAxisMaximum, pos.y);
207208
}
209+
210+
@Override
211+
public void setVisibleXRangeMaximum(float maxXRange) {
212+
float xScale = mXAxis.mAxisRange / (maxXRange);
213+
mViewPortHandler.setMinimumScaleY(xScale);
214+
}
215+
216+
@Override
217+
public void setVisibleYRangeMaximum(float maxYRange, AxisDependency axis) {
218+
float yScale = getDeltaY(axis) / maxYRange;
219+
mViewPortHandler.setMinimumScaleX(yScale);
220+
}
221+
222+
@Override
223+
public void setVisibleXRange(float minXRange, float maxXRange) {
224+
float maxScale = mXAxis.mAxisRange / minXRange;
225+
float minScale = mXAxis.mAxisRange / maxXRange;
226+
mViewPortHandler.setMinMaxScaleY(minScale, maxScale);
227+
}
208228
}

MPChartLib/src/main/java/com/github/mikephil/charting/utils/ViewPortHandler.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,20 @@ public void setMaximumScaleY(float yScale) {
509509
limitTransAndScale(mMatrixTouch, mContentRect);
510510
}
511511

512+
public void setMinMaxScaleY(float minScaleY, float maxScaleY) {
513+
514+
if (minScaleY < 1f)
515+
minScaleY = 1f;
516+
517+
if (maxScaleY == 0.f)
518+
maxScaleY = Float.MAX_VALUE;
519+
520+
mMinScaleX = minScaleY;
521+
mMaxScaleX = maxScaleY;
522+
523+
limitTransAndScale(mMatrixTouch, mContentRect);
524+
}
525+
512526
/**
513527
* Returns the charts-touch matrix used for translation and scale on touch.
514528
*

0 commit comments

Comments
 (0)