Data usage chart fixes.
Always draw first data point at 0. Each point should include full value of current bucket, instead of lagging behind by one. Bug: 5404917, 5404861, 5178305 Change-Id: I5fa63bc84cc1f9c0403fb03effd5affd2f01ad4c
This commit is contained in:
@@ -181,10 +181,13 @@ public class ChartNetworkSeriesView extends View {
|
|||||||
final int height = getHeight();
|
final int height = getHeight();
|
||||||
|
|
||||||
boolean started = false;
|
boolean started = false;
|
||||||
float firstX = 0;
|
|
||||||
float lastX = 0;
|
float lastX = 0;
|
||||||
float lastY = 0;
|
float lastY = height;
|
||||||
long lastTime = Long.MIN_VALUE;
|
long lastTime = mHoriz.convertToValue(lastX);
|
||||||
|
|
||||||
|
// move into starting position
|
||||||
|
mPathStroke.moveTo(lastX, lastY);
|
||||||
|
mPathFill.moveTo(lastX, lastY);
|
||||||
|
|
||||||
// TODO: count fractional data from first bucket crossing start;
|
// TODO: count fractional data from first bucket crossing start;
|
||||||
// currently it only accepts first full bucket.
|
// currently it only accepts first full bucket.
|
||||||
@@ -198,36 +201,42 @@ public class ChartNetworkSeriesView extends View {
|
|||||||
for (int i = start; i <= end; i++) {
|
for (int i = start; i <= end; i++) {
|
||||||
entry = mStats.getValues(i, entry);
|
entry = mStats.getValues(i, entry);
|
||||||
|
|
||||||
lastTime = entry.bucketStart + entry.bucketDuration;
|
final long startTime = entry.bucketStart;
|
||||||
final float x = mHoriz.convertToPoint(lastTime);
|
final long endTime = startTime + entry.bucketDuration;
|
||||||
final float y = mVert.convertToPoint(totalData);
|
|
||||||
|
final float startX = mHoriz.convertToPoint(startTime);
|
||||||
|
final float endX = mHoriz.convertToPoint(endTime);
|
||||||
|
|
||||||
// skip until we find first stats on screen
|
// skip until we find first stats on screen
|
||||||
if (i > 0 && !started && x > 0) {
|
if (endX < 0) continue;
|
||||||
mPathStroke.moveTo(lastX, lastY);
|
|
||||||
mPathFill.moveTo(lastX, lastY);
|
// increment by current bucket total
|
||||||
started = true;
|
totalData += entry.rxBytes + entry.txBytes;
|
||||||
firstX = x;
|
|
||||||
|
final float startY = lastY;
|
||||||
|
final float endY = mVert.convertToPoint(totalData);
|
||||||
|
|
||||||
|
if (lastTime != startTime) {
|
||||||
|
// gap in buckets; line to start of current bucket
|
||||||
|
mPathStroke.lineTo(startX, startY);
|
||||||
|
mPathFill.lineTo(startX, startY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (started) {
|
// always draw to end of current bucket
|
||||||
mPathStroke.lineTo(x, y);
|
mPathStroke.lineTo(endX, endY);
|
||||||
mPathFill.lineTo(x, y);
|
mPathFill.lineTo(endX, endY);
|
||||||
totalData += entry.rxBytes + entry.txBytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
lastX = x;
|
lastX = endX;
|
||||||
lastY = y;
|
lastY = endY;
|
||||||
|
lastTime = endTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
// when data falls short, extend to requested end time
|
// when data falls short, extend to requested end time
|
||||||
if (lastTime < mEndTime) {
|
if (lastTime < mEndTime) {
|
||||||
lastX = mHoriz.convertToPoint(mEndTime);
|
lastX = mHoriz.convertToPoint(mEndTime);
|
||||||
|
|
||||||
if (started) {
|
mPathStroke.lineTo(lastX, lastY);
|
||||||
mPathStroke.lineTo(lastX, lastY);
|
mPathFill.lineTo(lastX, lastY);
|
||||||
mPathFill.lineTo(lastX, lastY);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LOGD) {
|
if (LOGD) {
|
||||||
@@ -239,7 +248,7 @@ public class ChartNetworkSeriesView extends View {
|
|||||||
|
|
||||||
// drop to bottom of graph from current location
|
// drop to bottom of graph from current location
|
||||||
mPathFill.lineTo(lastX, height);
|
mPathFill.lineTo(lastX, height);
|
||||||
mPathFill.lineTo(firstX, height);
|
mPathFill.lineTo(0, height);
|
||||||
|
|
||||||
mMax = totalData;
|
mMax = totalData;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user