Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep position on rotation #1565

Merged
merged 1 commit into from
Mar 10, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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