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:
Jeff Sharkey
2012-03-15 18:38:13 -07:00
parent 3235ddb7aa
commit a8106f248c
2 changed files with 48 additions and 33 deletions

View File

@@ -237,7 +237,7 @@ public class ChartDataUsageView extends ChartView {
final long maxSweep = Math.max(mSweepWarning.getValue(), mSweepLimit.getValue());
final long maxSeries = Math.max(mSeries.getMaxVisible(), mDetailSeries.getMaxVisible());
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);
// only invalidate when vertMax actually changed
@@ -636,15 +636,9 @@ public class ChartDataUsageView extends ChartView {
/** {@inheritDoc} */
public float[] getTickPoints() {
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 float[] tickPoints = new float[tickCount];
long value = mMin;
@@ -681,4 +675,21 @@ public class ChartDataUsageView extends ChartView {
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;
}
}

View File

@@ -44,6 +44,8 @@ public class ChartNetworkSeriesView extends View {
private static final String TAG = "ChartNetworkSeriesView";
private static final boolean LOGD = false;
private static final boolean ESTIMATE_ENABLED = false;
private ChartAxis mHoriz;
private ChartAxis mVert;
@@ -252,6 +254,7 @@ public class ChartNetworkSeriesView extends View {
mMax = totalData;
if (ESTIMATE_ENABLED) {
// build estimated data
mPathEstimate.moveTo(lastX, lastY);
@@ -282,6 +285,7 @@ public class ChartNetworkSeriesView extends View {
}
mMaxEstimate = totalData;
}
invalidate();
}
@@ -291,7 +295,7 @@ public class ChartNetworkSeriesView extends View {
}
public void setEstimateVisible(boolean estimateVisible) {
mEstimateVisible = estimateVisible;
mEstimateVisible = ESTIMATE_ENABLED ? estimateVisible : false;
invalidate();
}