use of com.jjoe64.graphview.series.DataPointInterface in project GraphView by appsthatmatter.
the class CursorMode method drawLegend.
protected void drawLegend(Canvas canvas) {
mTextPaint.setTextSize(mStyles.textSize);
mTextPaint.setColor(mStyles.textColor);
int shapeSize = (int) (mStyles.textSize * 0.8d);
// width
int legendWidth = mStyles.width;
if (legendWidth == 0) {
// auto
legendWidth = cachedLegendWidth;
if (legendWidth == 0) {
Rect textBounds = new Rect();
for (Map.Entry<BaseSeries, DataPointInterface> entry : mCurrentSelection.entrySet()) {
String txt = getTextForSeries(entry.getKey(), entry.getValue());
mTextPaint.getTextBounds(txt, 0, txt.length(), textBounds);
legendWidth = Math.max(legendWidth, textBounds.width());
}
if (legendWidth == 0)
legendWidth = 1;
// add shape size
legendWidth += shapeSize + mStyles.padding * 2 + mStyles.spacing;
cachedLegendWidth = legendWidth;
}
}
float legendPosX = mPosX - mStyles.margin - legendWidth;
if (legendPosX < 0) {
legendPosX = 0;
}
// rect
float legendHeight = (mStyles.textSize + mStyles.spacing) * (mCurrentSelection.size() + 1) - mStyles.spacing;
float legendPosY = mPosY - legendHeight - 4.5f * mStyles.textSize;
if (legendPosY < 0) {
legendPosY = 0;
}
float lLeft;
float lTop;
lLeft = legendPosX;
lTop = legendPosY;
float lRight = lLeft + legendWidth;
float lBottom = lTop + legendHeight + 2 * mStyles.padding;
mRectPaint.setColor(mStyles.backgroundColor);
canvas.drawRoundRect(new RectF(lLeft, lTop, lRight, lBottom), 8, 8, mRectPaint);
mTextPaint.setFakeBoldText(true);
canvas.drawText(mGraphView.getGridLabelRenderer().getLabelFormatter().formatLabel(mCurrentSelectionX, true), lLeft + mStyles.padding, lTop + mStyles.padding / 2 + mStyles.textSize, mTextPaint);
mTextPaint.setFakeBoldText(false);
int i = 1;
for (Map.Entry<BaseSeries, DataPointInterface> entry : mCurrentSelection.entrySet()) {
mRectPaint.setColor(entry.getKey().getColor());
canvas.drawRect(new RectF(lLeft + mStyles.padding, lTop + mStyles.padding + (i * (mStyles.textSize + mStyles.spacing)), lLeft + mStyles.padding + shapeSize, lTop + mStyles.padding + (i * (mStyles.textSize + mStyles.spacing)) + shapeSize), mRectPaint);
canvas.drawText(getTextForSeries(entry.getKey(), entry.getValue()), lLeft + mStyles.padding + shapeSize + mStyles.spacing, lTop + mStyles.padding / 2 + mStyles.textSize + (i * (mStyles.textSize + mStyles.spacing)), mTextPaint);
i++;
}
}
use of com.jjoe64.graphview.series.DataPointInterface in project GraphView by appsthatmatter.
the class CursorMode method findCurrentDataPoint.
private void findCurrentDataPoint() {
double selX = 0;
mCurrentSelection.clear();
for (Series series : mGraphView.getSeries()) {
if (series instanceof BaseSeries) {
DataPointInterface p = ((BaseSeries) series).findDataPointAtX(mPosX);
if (p != null) {
selX = p.getX();
mCurrentSelection.put((BaseSeries) series, p);
}
}
}
if (!mCurrentSelection.isEmpty()) {
mCurrentSelectionX = selX;
}
}
use of com.jjoe64.graphview.series.DataPointInterface in project GraphView by appsthatmatter.
the class Viewport method calcCompleteRange.
/**
* caches the complete range (minX, maxX, minY, maxY)
* by iterating all series and all datapoints and
* stores it into #mCompleteRange
*
* for the x-range it will respect the series on the
* second scale - not for y-values
*/
public void calcCompleteRange() {
List<Series> series = mGraphView.getSeries();
List<Series> seriesInclusiveSecondScale = new ArrayList<>(mGraphView.getSeries());
if (mGraphView.mSecondScale != null) {
seriesInclusiveSecondScale.addAll(mGraphView.mSecondScale.getSeries());
}
mCompleteRange.set(0d, 0d, 0d, 0d);
if (!seriesInclusiveSecondScale.isEmpty() && !seriesInclusiveSecondScale.get(0).isEmpty()) {
double d = seriesInclusiveSecondScale.get(0).getLowestValueX();
for (Series s : seriesInclusiveSecondScale) {
if (!s.isEmpty() && d > s.getLowestValueX()) {
d = s.getLowestValueX();
}
}
mCompleteRange.left = d;
d = seriesInclusiveSecondScale.get(0).getHighestValueX();
for (Series s : seriesInclusiveSecondScale) {
if (!s.isEmpty() && d < s.getHighestValueX()) {
d = s.getHighestValueX();
}
}
mCompleteRange.right = d;
if (!series.isEmpty() && !series.get(0).isEmpty()) {
d = series.get(0).getLowestValueY();
for (Series s : series) {
if (!s.isEmpty() && d > s.getLowestValueY()) {
d = s.getLowestValueY();
}
}
mCompleteRange.bottom = d;
d = series.get(0).getHighestValueY();
for (Series s : series) {
if (!s.isEmpty() && d < s.getHighestValueY()) {
d = s.getHighestValueY();
}
}
mCompleteRange.top = d;
}
}
// calc current viewport bounds
if (mYAxisBoundsStatus == AxisBoundsStatus.AUTO_ADJUSTED) {
mYAxisBoundsStatus = AxisBoundsStatus.INITIAL;
}
if (mYAxisBoundsStatus == AxisBoundsStatus.INITIAL) {
mCurrentViewport.top = mCompleteRange.top;
mCurrentViewport.bottom = mCompleteRange.bottom;
}
if (mXAxisBoundsStatus == AxisBoundsStatus.AUTO_ADJUSTED) {
mXAxisBoundsStatus = AxisBoundsStatus.INITIAL;
}
if (mXAxisBoundsStatus == AxisBoundsStatus.INITIAL) {
mCurrentViewport.left = mCompleteRange.left;
mCurrentViewport.right = mCompleteRange.right;
} else if (mXAxisBoundsManual && !mYAxisBoundsManual && mCompleteRange.width() != 0) {
// get highest/lowest of current viewport
// lowest
double d = Double.MAX_VALUE;
for (Series s : series) {
Iterator<DataPointInterface> values = s.getValues(mCurrentViewport.left, mCurrentViewport.right);
while (values.hasNext()) {
double v = values.next().getY();
if (d > v) {
d = v;
}
}
}
if (d != Double.MAX_VALUE) {
mCurrentViewport.bottom = d;
}
// highest
d = Double.MIN_VALUE;
for (Series s : series) {
Iterator<DataPointInterface> values = s.getValues(mCurrentViewport.left, mCurrentViewport.right);
while (values.hasNext()) {
double v = values.next().getY();
if (d < v) {
d = v;
}
}
}
if (d != Double.MIN_VALUE) {
mCurrentViewport.top = d;
}
}
// fixes blank screen when range is zero
if (mCurrentViewport.left == mCurrentViewport.right)
mCurrentViewport.right++;
if (mCurrentViewport.top == mCurrentViewport.bottom)
mCurrentViewport.top++;
}
Aggregations