Fixes related to setting visible axis range for horizontal barchart
This commit is contained in:
parent
f345d164ce
commit
b5bfc3e2bd
4 changed files with 59 additions and 11 deletions
|
@ -111,7 +111,8 @@ public class HorizontalBarChartActivity extends DemoBase implements OnSeekBarCha
|
|||
l.setFormSize(8f);
|
||||
l.setXEntrySpace(4f);
|
||||
|
||||
// mChart.setDrawLegend(false);
|
||||
// mChart.setVisibleXRange(50, 10);
|
||||
// mChart.moveViewToX(20);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -746,8 +746,8 @@ public abstract class BarLineChartBase<T extends BarLineScatterCandleBubbleData<
|
|||
* @param maxXRange
|
||||
*/
|
||||
public void setVisibleXRange(float minXRange, float maxXRange) {
|
||||
float maxScale = mXAxis.mAxisRange / minXRange;
|
||||
float minScale = mXAxis.mAxisRange / maxXRange;
|
||||
float minScale = mXAxis.mAxisRange / minXRange;
|
||||
float maxScale = mXAxis.mAxisRange / maxXRange;
|
||||
mViewPortHandler.setMinMaxScaleX(minScale, maxScale);
|
||||
}
|
||||
|
||||
|
@ -756,13 +756,37 @@ public abstract class BarLineChartBase<T extends BarLineScatterCandleBubbleData<
|
|||
* visible at once.
|
||||
*
|
||||
* @param maxYRange the maximum visible range on the y-axis
|
||||
* @param axis - the axis for which this limit should apply
|
||||
* @param axis the axis for which this limit should apply
|
||||
*/
|
||||
public void setVisibleYRangeMaximum(float maxYRange, AxisDependency axis) {
|
||||
float yScale = getDeltaY(axis) / maxYRange;
|
||||
mViewPortHandler.setMinimumScaleY(yScale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the size of the area (range on the y-axis) that should be minimum visible at once, no further zooming in possible.
|
||||
*
|
||||
* @param minYRange
|
||||
* @param axis the axis for which this limit should apply
|
||||
*/
|
||||
public void setVisibleYRangeMinimum(float minYRange, AxisDependency axis) {
|
||||
float yScale = getDeltaY(axis) / minYRange;
|
||||
mViewPortHandler.setMaximumScaleY(yScale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Limits the maximum and minimum y range that can be visible by pinching and zooming.
|
||||
*
|
||||
* @param minYRange
|
||||
* @param maxYRange
|
||||
* @param axis
|
||||
*/
|
||||
public void setVisibleYRange(float minYRange, float maxYRange, AxisDependency axis) {
|
||||
float minScale = getDeltaY(axis) / minYRange;
|
||||
float maxScale = getDeltaY(axis) / maxYRange;
|
||||
mViewPortHandler.setMinMaxScaleY(minScale, maxScale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the left side of the current viewport to the specified x-position.
|
||||
* This also refreshes the chart by calling invalidate().
|
||||
|
|
|
@ -7,13 +7,13 @@ import android.util.AttributeSet;
|
|||
import android.util.Log;
|
||||
|
||||
import com.github.mikephil.charting.components.XAxis.XAxisPosition;
|
||||
import com.github.mikephil.charting.components.YAxis;
|
||||
import com.github.mikephil.charting.components.YAxis.AxisDependency;
|
||||
import com.github.mikephil.charting.data.BarEntry;
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.highlight.Highlight;
|
||||
import com.github.mikephil.charting.highlight.HorizontalBarHighlighter;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
|
||||
import com.github.mikephil.charting.jobs.MoveViewJob;
|
||||
import com.github.mikephil.charting.renderer.HorizontalBarChartRenderer;
|
||||
import com.github.mikephil.charting.renderer.XAxisRendererHorizontalBarChart;
|
||||
import com.github.mikephil.charting.renderer.YAxisRendererHorizontalBarChart;
|
||||
|
@ -207,12 +207,29 @@ public class HorizontalBarChart extends BarChart {
|
|||
return (float) Math.min(mXAxis.mAxisMaximum, pos.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* ###### VIEWPORT METHODS BELOW THIS ######
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void setVisibleXRangeMaximum(float maxXRange) {
|
||||
float xScale = mXAxis.mAxisRange / (maxXRange);
|
||||
mViewPortHandler.setMinimumScaleY(xScale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisibleXRangeMinimum(float minXRange) {
|
||||
float xScale = mXAxis.mAxisRange / (minXRange);
|
||||
mViewPortHandler.setMaximumScaleY(xScale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisibleXRange(float minXRange, float maxXRange) {
|
||||
float minScale = mXAxis.mAxisRange / minXRange;
|
||||
float maxScale = mXAxis.mAxisRange / maxXRange;
|
||||
mViewPortHandler.setMinMaxScaleY(minScale, maxScale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisibleYRangeMaximum(float maxYRange, AxisDependency axis) {
|
||||
float yScale = getDeltaY(axis) / maxYRange;
|
||||
|
@ -220,9 +237,15 @@ public class HorizontalBarChart extends BarChart {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setVisibleXRange(float minXRange, float maxXRange) {
|
||||
float maxScale = mXAxis.mAxisRange / minXRange;
|
||||
float minScale = mXAxis.mAxisRange / maxXRange;
|
||||
mViewPortHandler.setMinMaxScaleY(minScale, maxScale);
|
||||
public void setVisibleYRangeMinimum(float minYRange, AxisDependency axis) {
|
||||
float yScale = getDeltaY(axis) / minYRange;
|
||||
mViewPortHandler.setMaximumScaleX(yScale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisibleYRange(float minYRange, float maxYRange, AxisDependency axis) {
|
||||
float minScale = getDeltaY(axis) / minYRange;
|
||||
float maxScale = getDeltaY(axis) / maxYRange;
|
||||
mViewPortHandler.setMinMaxScaleX(minScale, maxScale);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -517,8 +517,8 @@ public class ViewPortHandler {
|
|||
if (maxScaleY == 0.f)
|
||||
maxScaleY = Float.MAX_VALUE;
|
||||
|
||||
mMinScaleX = minScaleY;
|
||||
mMaxScaleX = maxScaleY;
|
||||
mMinScaleY = minScaleY;
|
||||
mMaxScaleY = maxScaleY;
|
||||
|
||||
limitTransAndScale(mMatrixTouch, mContentRect);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue