Auto grid lines, lower minimum, disable estimates.
Show automatic grid lines with power-of-two spacing, avoiding ANR when trying to render thousands of gridlines. Lower minimum chart height to 50MB to give better view of linear data. Also disable estimates rendering. Bug: 5500204, 6005240 Change-Id: Iacfed11b32c0095c9c2d08bee6a1b5e29637de98
This commit is contained in:
@@ -237,7 +237,7 @@ public class ChartDataUsageView extends ChartView {
|
|||||||
final long maxSweep = Math.max(mSweepWarning.getValue(), mSweepLimit.getValue());
|
final long maxSweep = Math.max(mSweepWarning.getValue(), mSweepLimit.getValue());
|
||||||
final long maxSeries = Math.max(mSeries.getMaxVisible(), mDetailSeries.getMaxVisible());
|
final long maxSeries = Math.max(mSeries.getMaxVisible(), mDetailSeries.getMaxVisible());
|
||||||
final long maxVisible = Math.max(maxSeries, maxSweep) * 12 / 10;
|
final long maxVisible = Math.max(maxSeries, maxSweep) * 12 / 10;
|
||||||
final long maxDefault = Math.max(maxVisible, 2 * GB_IN_BYTES);
|
final long maxDefault = Math.max(maxVisible, 50 * MB_IN_BYTES);
|
||||||
newMax = Math.max(maxDefault, newMax);
|
newMax = Math.max(maxDefault, newMax);
|
||||||
|
|
||||||
// only invalidate when vertMax actually changed
|
// only invalidate when vertMax actually changed
|
||||||
@@ -636,15 +636,9 @@ public class ChartDataUsageView extends ChartView {
|
|||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
public float[] getTickPoints() {
|
public float[] getTickPoints() {
|
||||||
final long range = mMax - mMin;
|
final long range = mMax - mMin;
|
||||||
final long tickJump;
|
|
||||||
if (range < 6 * GB_IN_BYTES) {
|
|
||||||
tickJump = 256 * MB_IN_BYTES;
|
|
||||||
} else if (range < 12 * GB_IN_BYTES) {
|
|
||||||
tickJump = 512 * MB_IN_BYTES;
|
|
||||||
} else {
|
|
||||||
tickJump = 1 * GB_IN_BYTES;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// target about 16 ticks on screen, rounded to nearest power of 2
|
||||||
|
final long tickJump = roundUpToPowerOfTwo(range / 16);
|
||||||
final int tickCount = (int) (range / tickJump);
|
final int tickCount = (int) (range / tickJump);
|
||||||
final float[] tickPoints = new float[tickCount];
|
final float[] tickPoints = new float[tickCount];
|
||||||
long value = mMin;
|
long value = mMin;
|
||||||
@@ -681,4 +675,21 @@ public class ChartDataUsageView extends ChartView {
|
|||||||
return new int[] { start, end };
|
return new int[] { start, end };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static long roundUpToPowerOfTwo(long i) {
|
||||||
|
// NOTE: borrowed from Hashtable.roundUpToPowerOfTwo()
|
||||||
|
|
||||||
|
i--; // If input is a power of two, shift its high-order bit right
|
||||||
|
|
||||||
|
// "Smear" the high-order bit all the way to the right
|
||||||
|
i |= i >>> 1;
|
||||||
|
i |= i >>> 2;
|
||||||
|
i |= i >>> 4;
|
||||||
|
i |= i >>> 8;
|
||||||
|
i |= i >>> 16;
|
||||||
|
i |= i >>> 32;
|
||||||
|
|
||||||
|
i++;
|
||||||
|
|
||||||
|
return i > 0 ? i : Long.MAX_VALUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -44,6 +44,8 @@ public class ChartNetworkSeriesView extends View {
|
|||||||
private static final String TAG = "ChartNetworkSeriesView";
|
private static final String TAG = "ChartNetworkSeriesView";
|
||||||
private static final boolean LOGD = false;
|
private static final boolean LOGD = false;
|
||||||
|
|
||||||
|
private static final boolean ESTIMATE_ENABLED = false;
|
||||||
|
|
||||||
private ChartAxis mHoriz;
|
private ChartAxis mHoriz;
|
||||||
private ChartAxis mVert;
|
private ChartAxis mVert;
|
||||||
|
|
||||||
@@ -252,37 +254,39 @@ public class ChartNetworkSeriesView extends View {
|
|||||||
|
|
||||||
mMax = totalData;
|
mMax = totalData;
|
||||||
|
|
||||||
// build estimated data
|
if (ESTIMATE_ENABLED) {
|
||||||
mPathEstimate.moveTo(lastX, lastY);
|
// build estimated data
|
||||||
|
mPathEstimate.moveTo(lastX, lastY);
|
||||||
|
|
||||||
final long now = System.currentTimeMillis();
|
final long now = System.currentTimeMillis();
|
||||||
final long bucketDuration = mStats.getBucketDuration();
|
final long bucketDuration = mStats.getBucketDuration();
|
||||||
|
|
||||||
// long window is average over two weeks
|
// long window is average over two weeks
|
||||||
entry = mStats.getValues(lastTime - WEEK_IN_MILLIS * 2, lastTime, now, entry);
|
entry = mStats.getValues(lastTime - WEEK_IN_MILLIS * 2, lastTime, now, entry);
|
||||||
final long longWindow = (entry.rxBytes + entry.txBytes) * bucketDuration
|
final long longWindow = (entry.rxBytes + entry.txBytes) * bucketDuration
|
||||||
/ entry.bucketDuration;
|
|
||||||
|
|
||||||
long futureTime = 0;
|
|
||||||
while (lastX < width) {
|
|
||||||
futureTime += bucketDuration;
|
|
||||||
|
|
||||||
// short window is day average last week
|
|
||||||
final long lastWeekTime = lastTime - WEEK_IN_MILLIS + (futureTime % WEEK_IN_MILLIS);
|
|
||||||
entry = mStats.getValues(lastWeekTime - DAY_IN_MILLIS, lastWeekTime, now, entry);
|
|
||||||
final long shortWindow = (entry.rxBytes + entry.txBytes) * bucketDuration
|
|
||||||
/ entry.bucketDuration;
|
/ entry.bucketDuration;
|
||||||
|
|
||||||
totalData += (longWindow * 7 + shortWindow * 3) / 10;
|
long futureTime = 0;
|
||||||
|
while (lastX < width) {
|
||||||
|
futureTime += bucketDuration;
|
||||||
|
|
||||||
lastX = mHoriz.convertToPoint(lastTime + futureTime);
|
// short window is day average last week
|
||||||
lastY = mVert.convertToPoint(totalData);
|
final long lastWeekTime = lastTime - WEEK_IN_MILLIS + (futureTime % WEEK_IN_MILLIS);
|
||||||
|
entry = mStats.getValues(lastWeekTime - DAY_IN_MILLIS, lastWeekTime, now, entry);
|
||||||
|
final long shortWindow = (entry.rxBytes + entry.txBytes) * bucketDuration
|
||||||
|
/ entry.bucketDuration;
|
||||||
|
|
||||||
mPathEstimate.lineTo(lastX, lastY);
|
totalData += (longWindow * 7 + shortWindow * 3) / 10;
|
||||||
|
|
||||||
|
lastX = mHoriz.convertToPoint(lastTime + futureTime);
|
||||||
|
lastY = mVert.convertToPoint(totalData);
|
||||||
|
|
||||||
|
mPathEstimate.lineTo(lastX, lastY);
|
||||||
|
}
|
||||||
|
|
||||||
|
mMaxEstimate = totalData;
|
||||||
}
|
}
|
||||||
|
|
||||||
mMaxEstimate = totalData;
|
|
||||||
|
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,7 +295,7 @@ public class ChartNetworkSeriesView extends View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setEstimateVisible(boolean estimateVisible) {
|
public void setEstimateVisible(boolean estimateVisible) {
|
||||||
mEstimateVisible = estimateVisible;
|
mEstimateVisible = ESTIMATE_ENABLED ? estimateVisible : false;
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user