Java Code Examples for lecho.lib.hellocharts.model.PointValue#getY()

The following examples show how to use lecho.lib.hellocharts.model.PointValue#getY() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LineChartRenderer.java    From hellocharts-android with Apache License 2.0 6 votes vote down vote up
private void calculateMaxViewport() {
    tempMaximumViewport.set(Float.MAX_VALUE, Float.MIN_VALUE, Float.MIN_VALUE, Float.MAX_VALUE);
    LineChartData data = dataProvider.getLineChartData();

    for (Line line : data.getLines()) {
        // Calculate max and min for viewport.
        for (PointValue pointValue : line.getValues()) {
            if (pointValue.getX() < tempMaximumViewport.left) {
                tempMaximumViewport.left = pointValue.getX();
            }
            if (pointValue.getX() > tempMaximumViewport.right) {
                tempMaximumViewport.right = pointValue.getX();
            }
            if (pointValue.getY() < tempMaximumViewport.bottom) {
                tempMaximumViewport.bottom = pointValue.getY();
            }
            if (pointValue.getY() > tempMaximumViewport.top) {
                tempMaximumViewport.top = pointValue.getY();
            }

        }
    }
}
 
Example 2
Source File: BgGraphBuilder.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private void addBloodTests() {
    // enumerate blood tests
    try {
        for (BgWatchData bloodtest : btDataList) {
            if(bloodtest.timestamp > start_time) {
                final long adjusted_timestamp = (Math.round(bloodtest.timestamp) + (estimatedInterstitialLagSeconds * 1000));
                final PointValueExtended this_point = new PointValueExtended((float) (adjusted_timestamp / FUZZER), (float) unitized(bloodtest.sgv));
                this_point.type = PointValueExtended.BloodTest;
                //this_point.uuid = bloodtest.uuid; //TODO
                this_point.real_timestamp = (long)bloodtest.timestamp;
                // exclude any which have been used for calibration
                boolean matches = false;
                for (PointValue calibration_point : calibrationValues) {
                    if ((Math.abs(calibration_point.getX() - this_point.getX())) <= ((estimatedInterstitialLagSeconds * 1000) / FUZZER) && (calibration_point.getY() == calibration_point.getY())) {
                        matches = true;
                        break;
                    }
                }
                //if (!matches) bloodTestValues.add(this_point);
                if (!matches)
                    bloodTestValues.add(new PointValue(fuzz(adjusted_timestamp), (float) unitized(bloodtest.sgv)));//KS bloodtest.timestamp
                if (d)
                    Log.d(TAG, "bloodtest total record: " + bloodtest.sgv + " " + " adjusted_timestamp: " + fuzz(bloodtest.timestamp) + " timestamp=" + JoH.dateTimeText((long) bloodtest.timestamp));
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "Exception doing bloodtest values in bggraphbuilder: " + e.toString());
    }

}
 
Example 3
Source File: BgGraphBuilder.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private void addBloodTests() {
    // enumerate blood tests
    try {
        for (BgWatchData bloodtest : btDataList) {
            if(bloodtest.timestamp > start_time) {
                final long adjusted_timestamp = (Math.round(bloodtest.timestamp) + (estimatedInterstitialLagSeconds * 1000));
                final PointValueExtended this_point = new PointValueExtended((float) (adjusted_timestamp / FUZZER), (float) unitized(bloodtest.sgv));
                this_point.type = PointValueExtended.BloodTest;
                //this_point.uuid = bloodtest.uuid; //TODO
                this_point.real_timestamp = (long)bloodtest.timestamp;
                // exclude any which have been used for calibration
                boolean matches = false;
                for (PointValue calibration_point : calibrationValues) {
                    if ((Math.abs(calibration_point.getX() - this_point.getX())) <= ((estimatedInterstitialLagSeconds * 1000) / FUZZER) && (calibration_point.getY() == calibration_point.getY())) {
                        matches = true;
                        break;
                    }
                }
                //if (!matches) bloodTestValues.add(this_point);
                if (!matches)
                    bloodTestValues.add(new PointValue(fuzz(adjusted_timestamp), (float) unitized(bloodtest.sgv)));//KS bloodtest.timestamp
                if (d)
                    Log.d(TAG, "bloodtest total record: " + bloodtest.sgv + " " + " adjusted_timestamp: " + fuzz(bloodtest.timestamp) + " timestamp=" + JoH.dateTimeText((long) bloodtest.timestamp));
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "Exception doing bloodtest values in bggraphbuilder: " + e.toString());
    }

}
 
Example 4
Source File: BgGraphBuilder.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
@Override
public synchronized void onValueSelected(int i, int i1, PointValue pointValue) {

    Log.d(TAG, "onValueSelected pointValue=" + pointValue.getX() + "," + pointValue.getY());
    String filtered = "";
    String alternate = "";
    String uuid = "";
    int type = 0;
    long real_timestamp = 0;
    try {
        PointValueExtended pve = (PointValueExtended) pointValue;
        type = pve.type;
        if (pve.calculatedFilteredValue != -1) {
            filtered = " (" + Math.round(pve.calculatedFilteredValue * 10) / 10d + ")";
        }
        if (pve.note != null) {
            alternate = pve.note;
        }
        if (pve.uuid != null) {
            uuid = pve.uuid;
        }
        real_timestamp = pve.real_timestamp;

    } catch (ClassCastException e) {
        Log.e(TAG, "Error casting a point from pointValue to PointValueExtended", e);
    }

    final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(context);
    //Won't give the exact time of the reading but the time on the grid: close enough.
    final Long time = (real_timestamp > 0) ? real_timestamp : ((long) pointValue.getX()) * FUZZER;
    final double ypos = pointValue.getY();

    final String message;

    if (alternate.length() > 0) {
        message = timeFormat.format(time) + "    " + alternate;
    } else {
        message = timeFormat.format(time) + "      " + (Math.round(pointValue.getY() * 10) / 10d) + " " + unit() + filtered;
    }
    Log.d(TAG, "onValueSelected message=" + message);
    JoH.static_toast(xdrip.getAppContext(), message, Toast.LENGTH_SHORT);

    /*switch (type) {
        case com.eveningoutpost.dexdrip.UtilityModels.PointValueExtended.BloodTest:
            final String fuuid = uuid;
            final View.OnClickListener mBtOnClickListener = new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Home.startHomeWithExtra(xdrip.getAppContext(), Home.BLOOD_TEST_ACTION, time.toString(), fuuid);
                }
            };
            Home.snackBar(R.string.blood_test, message, mBtOnClickListener, callerActivity);
            break;
        default:
            final View.OnClickListener mOnClickListener = new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Home.startHomeWithExtra(xdrip.getAppContext(), Home.CREATE_TREATMENT_NOTE, time.toString(), Double.toString(ypos));
                }
            };
            Home.snackBar(R.string.add_note, message, mOnClickListener, callerActivity);
            break;
    }*/
}
 
Example 5
Source File: BgGraphBuilder.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
@Override
public synchronized void onValueSelected(int i, int i1, PointValue pointValue) {

    Log.d(TAG, "onValueSelected pointValue=" + pointValue.getX() + "," + pointValue.getY());
    String filtered = "";
    String alternate = "";
    String uuid = "";
    int type = 0;
    long real_timestamp = 0;
    try {
        PointValueExtended pve = (PointValueExtended) pointValue;
        type = pve.type;
        if (pve.calculatedFilteredValue != -1) {
            filtered = " (" + Math.round(pve.calculatedFilteredValue * 10) / 10d + ")";
        }
        if (pve.note != null) {
            alternate = pve.note;
        }
        if (pve.uuid != null) {
            uuid = pve.uuid;
        }
        real_timestamp = pve.real_timestamp;

    } catch (ClassCastException e) {
        Log.e(TAG, "Error casting a point from pointValue to PointValueExtended", e);
    }

    final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(context);
    //Won't give the exact time of the reading but the time on the grid: close enough.
    final Long time = (real_timestamp > 0) ? real_timestamp : ((long) pointValue.getX()) * FUZZER;
    final double ypos = pointValue.getY();

    final String message;

    if (alternate.length() > 0) {
        message = timeFormat.format(time) + "    " + alternate;
    } else {
        message = timeFormat.format(time) + "      " + (Math.round(pointValue.getY() * 10) / 10d) + " " + unit() + filtered;
    }
    Log.d(TAG, "onValueSelected message=" + message);
    JoH.static_toast(xdrip.getAppContext(), message, Toast.LENGTH_SHORT);

    /*switch (type) {
        case com.eveningoutpost.dexdrip.UtilityModels.PointValueExtended.BloodTest:
            final String fuuid = uuid;
            final View.OnClickListener mBtOnClickListener = new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Home.startHomeWithExtra(xdrip.getAppContext(), Home.BLOOD_TEST_ACTION, time.toString(), fuuid);
                }
            };
            Home.snackBar(R.string.blood_test, message, mBtOnClickListener, callerActivity);
            break;
        default:
            final View.OnClickListener mOnClickListener = new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Home.startHomeWithExtra(xdrip.getAppContext(), Home.CREATE_TREATMENT_NOTE, time.toString(), Double.toString(ypos));
                }
            };
            Home.snackBar(R.string.add_note, message, mOnClickListener, callerActivity);
            break;
    }*/
}
 
Example 6
Source File: LineChartRenderer.java    From hellocharts-android with Apache License 2.0 4 votes vote down vote up
private void drawLabel(Canvas canvas, Line line, PointValue pointValue, float rawX, float rawY, float offset) {
    final Rect contentRect = computator.getContentRectMinusAllMargins();
    final int numChars = line.getFormatter().formatChartValue(labelBuffer, pointValue);
    if (numChars == 0) {
        // No need to draw empty label
        return;
    }

    final float labelWidth = labelPaint.measureText(labelBuffer, labelBuffer.length - numChars, numChars);
    final int labelHeight = Math.abs(fontMetrics.ascent);
    float left = rawX - labelWidth / 2 - labelMargin;
    float right = rawX + labelWidth / 2 + labelMargin;

    float top;
    float bottom;

    if (pointValue.getY() >= baseValue) {
        top = rawY - offset - labelHeight - labelMargin * 2;
        bottom = rawY - offset;
    } else {
        top = rawY + offset;
        bottom = rawY + offset + labelHeight + labelMargin * 2;
    }

    if (top < contentRect.top) {
        top = rawY + offset;
        bottom = rawY + offset + labelHeight + labelMargin * 2;
    }
    if (bottom > contentRect.bottom) {
        top = rawY - offset - labelHeight - labelMargin * 2;
        bottom = rawY - offset;
    }
    if (left < contentRect.left) {
        left = rawX;
        right = rawX + labelWidth + labelMargin * 2;
    }
    if (right > contentRect.right) {
        left = rawX - labelWidth - labelMargin * 2;
        right = rawX;
    }

    labelBackgroundRect.set(left, top, right, bottom);
    drawLabelTextAndBackground(canvas, labelBuffer, labelBuffer.length - numChars, numChars,
            line.getDarkenColor());
}