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

Allow highlight per drag when drag is disabled on a scaled chart #5244

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -1159,6 +1159,13 @@ public void setScaleEnabled(boolean enabled) {
this.mScaleYEnabled = enabled;
}

/**
* Returns true if scale X or scale Y is enabled, false otherwise.
*
* @return
*/
public boolean isScaleEnabled() { return mScaleXEnabled || mScaleYEnabled; }

public void setScaleXEnabled(boolean enabled) {
mScaleXEnabled = enabled;
}
Expand Down
Expand Up @@ -112,9 +112,6 @@ public boolean onTouch(View v, MotionEvent event) {
mGestureDetector.onTouchEvent(event);
}

if (!mChart.isDragEnabled() && (!mChart.isScaleXEnabled() && !mChart.isScaleYEnabled()))
return true;

// Handle touch events here...
switch (event.getAction() & MotionEvent.ACTION_MASK) {

Expand All @@ -130,7 +127,7 @@ public boolean onTouch(View v, MotionEvent event) {

case MotionEvent.ACTION_POINTER_DOWN:

if (event.getPointerCount() >= 2) {
if (mChart.isScaleEnabled() && event.getPointerCount() >= 2) {

mChart.disableScroll();

Expand Down Expand Up @@ -178,43 +175,30 @@ public boolean onTouch(View v, MotionEvent event) {

mChart.disableScroll();

if (mChart.isScaleXEnabled() || mChart.isScaleYEnabled())
performZoom(event);
performZoom(event);

} else if (mTouchMode == NONE
&& Math.abs(distance(event.getX(), mTouchStartPoint.x, event.getY(),
mTouchStartPoint.y)) > mDragTriggerDist) {

if (mChart.isDragEnabled()) {

boolean shouldPan = !mChart.isFullyZoomedOut() ||
!mChart.hasNoDragOffset();

if (shouldPan) {

float distanceX = Math.abs(event.getX() - mTouchStartPoint.x);
float distanceY = Math.abs(event.getY() - mTouchStartPoint.y);

// Disable dragging in a direction that's disallowed
if ((mChart.isDragXEnabled() || distanceY >= distanceX) &&
(mChart.isDragYEnabled() || distanceY <= distanceX)) {

mLastGesture = ChartGesture.DRAG;
mTouchMode = DRAG;
}
if (mChart.isDragEnabled() && (!mChart.isFullyZoomedOut() || !mChart.hasNoDragOffset())) {

} else {
float distanceX = Math.abs(event.getX() - mTouchStartPoint.x);
float distanceY = Math.abs(event.getY() - mTouchStartPoint.y);

if (mChart.isHighlightPerDragEnabled()) {
mLastGesture = ChartGesture.DRAG;
// Disable dragging in a direction that's disallowed
if ((mChart.isDragXEnabled() || distanceY >= distanceX) &&
(mChart.isDragYEnabled() || distanceY <= distanceX)) {

if (mChart.isHighlightPerDragEnabled())
performHighlightDrag(event);
}
mLastGesture = ChartGesture.DRAG;
mTouchMode = DRAG;
}

}
} else if (mChart.isHighlightPerDragEnabled()) {

mLastGesture = ChartGesture.DRAG;
performHighlightDrag(event);
}
}
break;

Expand Down Expand Up @@ -246,7 +230,7 @@ public boolean onTouch(View v, MotionEvent event) {
}
}

if (mTouchMode == X_ZOOM ||
if (mChart.isScaleEnabled() && mTouchMode == X_ZOOM ||
mTouchMode == Y_ZOOM ||
mTouchMode == PINCH_ZOOM ||
mTouchMode == POST_ZOOM) {
Expand Down Expand Up @@ -282,9 +266,11 @@ public boolean onTouch(View v, MotionEvent event) {
break;
}

// perform the transformation, update the chart
mMatrix = mChart.getViewPortHandler().refresh(mMatrix, mChart, true);

if (mChart.isDragEnabled() || mChart.isScaleEnabled()) {
// perform the transformation, update the chart
mMatrix = mChart.getViewPortHandler().refresh(mMatrix, mChart, true);
}
return true; // indicate event was handled
}

Expand Down