Skip to content

Commit

Permalink
Merge pull request PhilJay#1565 from leoMehlig/rotation
Browse files Browse the repository at this point in the history
Keep position on rotation
  • Loading branch information
PhilJay committed Mar 10, 2016
2 parents f11ddec + 33692d7 commit 0214e19
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ public abstract class BarLineChartBase<T extends BarLineScatterCandleBubbleData<
*/
protected float mMinOffset = 15.f;

/**
* flag indicating if the chart should stay at the same position after a rotation. Default is false.
*/
protected boolean mKeepPositionOnRotation = false;

/**
* the listener for user drawing on the chart
*/
Expand Down Expand Up @@ -288,6 +293,22 @@ protected void onDraw(Canvas canvas) {
}
}

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
//Saving current position of chart.
float[] pts = new float[2];
pts[0] = mViewPortHandler.contentLeft();
pts[1] = mViewPortHandler.contentTop();
getTransformer(AxisDependency.LEFT).pixelsToValue(pts);

//Superclass transforms chart.
super.onSizeChanged(w, h, oldw, oldh);

//Restoring old position of chart.
getTransformer(AxisDependency.LEFT).pointValuesToPixel(pts);
mViewPortHandler.centerViewPort(pts, this);
}

/**
* RESET PERFORMANCE TRACKING FIELDS
*/
Expand Down Expand Up @@ -1209,6 +1230,20 @@ public void setMinOffset(float minOffset) {
mMinOffset = minOffset;
}

/**
* Returns true if keeping the position on rotation is enabled and false if not.
*/
public boolean isKeepPositionOnRotation() {
return mKeepPositionOnRotation;
}

/**
* Sets the whether the chart should keep its position after a rotation.
*/
public void setKeepPositionOnRotation(boolean keepPositionOnRotation) {
mKeepPositionOnRotation = keepPositionOnRotation;
}

/**
* Returns the Highlight object (contains x-index and DataSet index) of the
* selected value at the given touch point inside the Line-, Scatter-, or
Expand Down

0 comments on commit 0214e19

Please sign in to comment.