Skip to content

Commit

Permalink
cursor mode position
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Gehring committed Feb 26, 2017
1 parent 34f10e0 commit cd1dc60
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/main/java/com/jjoe64/graphview/CursorMode.java
Expand Up @@ -37,13 +37,14 @@ private final static class Styles {
protected final Paint mPaintLine;
protected final GraphView mGraphView;
protected float mPosX;
protected float mPosY;
protected boolean mCursorVisible;
protected final Map<BaseSeries, DataPointInterface> mCurrentSelection;
protected final Paint mRectPaint;
protected final Paint mTextPaint;
protected double mCurrentSelectionX;
protected Styles mStyles;
private int cachedLegendWidth;
protected int cachedLegendWidth;

public CursorMode(GraphView graphView) {
mStyles = new Styles();
Expand Down Expand Up @@ -91,15 +92,19 @@ public void resetStyles() {


public void onDown(MotionEvent e) {
mPosX = e.getX();
mPosX = Math.max(e.getX(), mGraphView.getGraphContentLeft());
mPosX = Math.min(mPosX, mGraphView.getGraphContentLeft() + mGraphView.getGraphContentWidth());
mPosY = e.getY();
mCursorVisible = true;
findCurrentDataPoint();
mGraphView.invalidate();
}

public void onMove(MotionEvent e) {
if (mCursorVisible) {
mPosX = e.getX();
mPosX = Math.max(e.getX(), mGraphView.getGraphContentLeft());
mPosX = Math.min(mPosX, mGraphView.getGraphContentLeft() + mGraphView.getGraphContentWidth());
mPosY = e.getY();
findCurrentDataPoint();
mGraphView.invalidate();
}
Expand Down Expand Up @@ -132,6 +137,7 @@ protected String getTextForSeries(Series s, DataPointInterface value) {

protected void drawLegend(Canvas canvas) {
mTextPaint.setTextSize(mStyles.textSize);
mTextPaint.setColor(mStyles.textColor);

int shapeSize = (int) (mStyles.textSize*0.8d);

Expand Down Expand Up @@ -163,10 +169,16 @@ protected void drawLegend(Canvas canvas) {

// rect
float legendHeight = (mStyles.textSize+mStyles.spacing) * (mCurrentSelection.size() + 1) -mStyles.spacing;

float legendPosY = mPosY;
if (legendPosY + legendHeight > canvas.getHeight()) {
legendPosY = canvas.getHeight() - legendHeight;
}

float lLeft;
float lTop;
lLeft = legendPosX;
lTop = mGraphView.getGraphContentTop() + mStyles.margin;
lTop = legendPosY;

float lRight = lLeft+legendWidth;
float lBottom = lTop+legendHeight+2*mStyles.padding;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/jjoe64/graphview/GraphView.java
Expand Up @@ -635,6 +635,7 @@ public void setCursorMode(boolean b) {
}
} else {
mCursorMode = null;
invalidate();
}
for (Series series : mSeries) {
if (series instanceof BaseSeries) {
Expand Down

0 comments on commit cd1dc60

Please sign in to comment.