Skip to content

Commit

Permalink
Added feature to enable/disable dragging and scaling separately.
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilJay committed Oct 15, 2014
1 parent 2cde3f5 commit cee1021
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ protected void onCreate(Bundle savedInstanceState) {
mChart.setTouchEnabled(true);

// enable scaling and dragging
mChart.setDragScaleEnabled(true);
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);

// if disabled, scaling can be done on x- and y-axis separately
mChart.setPinchZoom(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ protected void onCreate(Bundle savedInstanceState) {
// enable drawing with the finger
// mChart.setDrawingEnabled(true);

// enable dragging and scaling
mChart.setDragScaleEnabled(true);

mChart.setDrawYValues(false);
// mChart.setLineWidth(5f);
// mChart.setCircleSize(5f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ protected void onCreate(Bundle savedInstanceState) {
mChart.setTouchEnabled(true);

// enable scaling and dragging
mChart.setDragScaleEnabled(true);
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);

// if disabled, scaling can be done on x- and y-axis separately
mChart.setPinchZoom(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ protected void onCreate(Bundle savedInstanceState) {
mChart.setTouchEnabled(true);

// enable scaling and dragging
mChart.setDragScaleEnabled(true);
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);

// if disabled, scaling can be done on x- and y-axis separately
mChart.setPinchZoom(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ private void setupChart(LineChart chart, LineData data, int color) {
chart.setTouchEnabled(true);

// enable scaling and dragging
chart.setDragScaleEnabled(true);
chart.setDragEnabled(true);
chart.setScaleEnabled(true);

// if disabled, scaling can be done on x- and y-axis separately
chart.setPinchZoom(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ protected void onCreate(Bundle savedInstanceState) {
mChart.setTouchEnabled(true);

// enable scaling and dragging
mChart.setDragScaleEnabled(true);
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);

// if disabled, scaling can be done on x- and y-axis separately
mChart.setPinchZoom(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ protected void onCreate(Bundle savedInstanceState) {
mChart.setHighlightEnabled(true);
mChart.setDrawYValues(false);

mChart.setDragScaleEnabled(true);
// enable scaling and dragging
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);

mChart.setMaxVisibleValueCount(200);
mChart.setPinchZoom(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,11 @@ public abstract class BarLineChartBase<T extends BarLineScatterCandleData<? exte
/** flat that indicates if double tap zoom is enabled or not */
protected boolean mDoubleTapToZoomEnabled = true;

/** if true, dragging / scaling is enabled for the chart */
protected boolean mDragScaleEnabled = true;
/** if true, dragging is enabled for the chart */
private boolean mDragEnabled = true;

/** if true, scaling is enabled for the chart */
private boolean mScaleEnabled = true;

/** if true, the y range is predefined */
protected boolean mFixedYValues = false;
Expand Down Expand Up @@ -928,22 +931,26 @@ private void drawLimitLines() {

if (limitLines == null)
return;

float [] pts = new float[4];

for (int i = 0; i < limitLines.size(); i++) {

LimitLine l = limitLines.get(i);

pts[1] = l.getLimit();
pts[3] = l.getLimit();

Path line = new Path();
line.moveTo(0f, l.getLimit());
line.lineTo(mDeltaX, l.getLimit());

transformPath(line);
transformPointArray(pts);

pts[0] = 0;
pts[2] = getWidth();

mLimitLinePaint.setColor(l.getLineColor());
mLimitLinePaint.setPathEffect(l.getDashPathEffect());
mLimitLinePaint.setStrokeWidth(l.getLineWidth());

mDrawCanvas.drawPath(line, mLimitLinePaint);
mDrawCanvas.drawLines(pts, mLimitLinePaint);

// if drawing the limit-value is enabled
if (l.isDrawValueEnabled()) {
Expand Down Expand Up @@ -1518,21 +1525,42 @@ public void setGridWidth(float width) {
}

/**
* set this to true to enable dragging / scaling for the chart
* Set this to true to enable dragging (moving the chart with the finger)
* for the chart (this does not effect scaling).
*
* @param enabled
*/
public void setDragEnabled(boolean enabled) {
this.mDragEnabled = enabled;
}

/**
* Returns true if dragging is enabled for the chart, false if not.
*
* @return
*/
public boolean isDragEnabled() {
return mDragEnabled;
}

/**
* Set this to true to enable scaling (zooming in and out by gesture) for
* the chart (this does not effect dragging).
*
* @param enabled
*/
public void setDragScaleEnabled(boolean enabled) {
this.mDragScaleEnabled = enabled;
public void setScaleEnabled(boolean enabled) {
this.mScaleEnabled = enabled;
}

/**
* returns true if dragging / scaling is enabled for the chart, false if not
* Returns true if scaling (zooming in and out by gesture) is enabled for
* the chart, false if not.
*
* @return
*/
public boolean isDragScaleEnabled() {
return mDragScaleEnabled;
public boolean isScaleEnabled() {
return mScaleEnabled;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public boolean onTouch(View v, MotionEvent event) {
mGestureDetector.onTouchEvent(event);
}

if (!mChart.isDragScaleEnabled())
if (!mChart.isDragEnabled() && !mChart.isScaleEnabled())
return true;

// Handle touch events here...
Expand Down Expand Up @@ -119,7 +119,7 @@ public boolean onTouch(View v, MotionEvent event) {
}

// determine the touch-pointer center
midPoint(mTouchPointCenter, event);
midPoint(mTouchPointCenter, event);
}
break;
case MotionEvent.ACTION_MOVE:
Expand All @@ -128,13 +128,15 @@ public boolean onTouch(View v, MotionEvent event) {

mChart.disableScroll();

performDrag(event);
if (mChart.isDragEnabled())
performDrag(event);

} else if (mTouchMode == X_ZOOM || mTouchMode == Y_ZOOM || mTouchMode == PINCH_ZOOM) {

mChart.disableScroll();

performZoom(event);
if (mChart.isScaleEnabled())
performZoom(event);

} else if (mTouchMode == NONE
&& Math.abs(distance(event.getX(), mTouchStartPoint.x, event.getY(),
Expand Down Expand Up @@ -399,7 +401,7 @@ public void onLongPress(MotionEvent e) {
if (l != null) {

l.onChartLongPressed(e);
} else if(mTouchMode == NONE) {
} else if (mTouchMode == NONE) {

mChart.fitScreen();

Expand Down

0 comments on commit cee1021

Please sign in to comment.