Skip to content

Commit 24aad78

Browse files
committed
[Frequency tests] Align the line view
- Move the axis label out of the graph. - Use the suffix 'k' to represent 1,000.
1 parent f578e2b commit 24aad78

3 files changed

Lines changed: 40 additions & 37 deletions

File tree

apps/OboeTester/app/src/main/java/com/mobileer/oboetester/DualFrequencyActivity.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ public void onSettingChanged() {
106106
mWaveformViewTests.setYRange(MIN_DBFS, MAX_DBFS);
107107
mWaveformViewTests.setLogScaleX(true);
108108
mWaveformViewTests.setGridLinesY(
109-
new float[]{MIN_DBFS, (MIN_DBFS + MAX_DBFS) / 2.0f, MAX_DBFS}, true);
109+
new float[]{MIN_DBFS, (MIN_DBFS + MAX_DBFS) / 2.0f, MAX_DBFS});
110110

111111
mWaveformViewSubtraction = findViewById(R.id.waveform_view_subtraction);
112112
mWaveformViewSubtraction.setUnits("Hz", "dBFS");
113113
mWaveformViewSubtraction.setYRange(-50.0f, 50.0f);
114114
mWaveformViewSubtraction.setLogScaleX(true);
115-
mWaveformViewSubtraction.setGridLinesY(new float[]{-50.0f, 0.0f, 50.0f}, true);
115+
mWaveformViewSubtraction.setGridLinesY(new float[]{-50.0f, 0.0f, 50.0f});
116116

117117
android.widget.CheckBox logScaleCheckbox = findViewById(R.id.checkboxLogScale);
118118
logScaleCheckbox.setOnCheckedChangeListener(
@@ -284,8 +284,8 @@ public void run() {
284284
for (int i = 0; i < anchors.length; i++) {
285285
cursorFreqs[i] = anchors[i];
286286
}
287-
mWaveformViewTests.setGridLinesX(cursorFreqs, true);
288-
mWaveformViewSubtraction.setGridLinesX(cursorFreqs, true);
287+
mWaveformViewTests.setGridLinesX(cursorFreqs);
288+
mWaveformViewSubtraction.setGridLinesX(cursorFreqs);
289289
}
290290
mWaveformViewTests.setXRange(minFreq, maxFreq);
291291
mWaveformViewSubtraction.setXRange(minFreq, maxFreq);

apps/OboeTester/app/src/main/java/com/mobileer/oboetester/FrequencyActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ protected void onCreate(Bundle savedInstanceState) {
7070
mLineView.setUnits("Hz", "dBFS");
7171
mLineView.setYRange(gridLinesYDbfs[0], gridLinesYDbfs[gridLinesYDbfs.length - 1]);
7272
mLineView.setLogScaleX(true);
73-
mLineView.setGridLinesY(gridLinesYDbfs, true);
73+
mLineView.setGridLinesY(gridLinesYDbfs);
7474

7575
android.widget.CheckBox logScaleCheckbox = findViewById(R.id.checkboxLogScale);
7676
logScaleCheckbox.setOnCheckedChangeListener(
@@ -318,7 +318,7 @@ public void run() {
318318
for (int i = 0; i < anchors.length; i++) {
319319
cursorFreqs[i] = anchors[i];
320320
}
321-
mLineView.setGridLinesX(cursorFreqs, true);
321+
mLineView.setGridLinesX(cursorFreqs);
322322
}
323323

324324
if (mTopThresholdLineId == -1) {

apps/OboeTester/app/src/main/java/com/mobileer/oboetester/LineView.java

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@ private static class LineData {
6060
private int mNextLineId = 1;
6161

6262
private float[] mGridLinesX;
63-
private boolean mShowGridLabelsX = true;
64-
6563
private float[] mGridLinesY;
66-
private boolean mShowGridLabelsY = true;
6764

6865
private Paint mGridPaintX;
6966
private Paint mGridTextPaintX;
@@ -140,15 +137,13 @@ public void setYRange(float minY, float maxY) {
140137
postInvalidate();
141138
}
142139

143-
public void setGridLinesX(float[] xValues, boolean showLabels) {
140+
public void setGridLinesX(float[] xValues) {
144141
mGridLinesX = xValues;
145-
mShowGridLabelsX = showLabels;
146142
postInvalidate();
147143
}
148144

149-
public void setGridLinesY(float[] yValues, boolean showLabels) {
145+
public void setGridLinesY(float[] yValues) {
150146
mGridLinesY = yValues;
151-
mShowGridLabelsY = showLabels;
152147
postInvalidate();
153148
}
154149

@@ -195,21 +190,21 @@ private float mapYToView(float y, float scaleY, float offsetY) {
195190
return (mapped * scaleY) + offsetY;
196191
}
197192

198-
private float mapXToView(float xVal, float graphWidth) {
193+
private float mapXToView(float xVal, float graphWidth, float paddingLeft) {
199194
if (mLogScaleX) {
200195
if (mMinX <= 0 || mMaxX <= mMinX) {
201-
return 0.0f;
196+
return paddingLeft;
202197
}
203198
double logMin = Math.log(mMinX);
204199
double logMax = Math.log(mMaxX);
205200
double logX = Math.log(xVal);
206-
return (float) (((logX - logMin) / (logMax - logMin)) * graphWidth);
201+
return (float) (((logX - logMin) / (logMax - logMin)) * graphWidth) + paddingLeft;
207202
} else {
208203
float rangeX = mMaxX - mMinX;
209204
if (rangeX <= 0) {
210-
return 0.0f;
205+
return paddingLeft;
211206
}
212-
return ((xVal - mMinX) / rangeX) * graphWidth;
207+
return ((xVal - mMinX) / rangeX) * graphWidth + paddingLeft;
213208
}
214209
}
215210

@@ -230,8 +225,10 @@ protected void onDraw(Canvas canvas) {
230225
}
231226

232227
float paddingBottom = 60.0f;
233-
float paddingTop = 40.0f;
234-
float graphWidth = width;
228+
float paddingTop = 60.0f;
229+
float paddingLeft = 100.0f;
230+
float paddingRight = 100.0f;
231+
float graphWidth = width - paddingLeft - paddingRight;
235232
float graphHeight = height - paddingBottom - paddingTop;
236233
float offsetY = paddingTop + (graphHeight / 2.0f);
237234
float scaleY = -0.90f * (graphHeight / 2.0f);
@@ -253,7 +250,7 @@ protected void onDraw(Canvas canvas) {
253250
if (xVal < mMinX || xVal > mMaxX) {
254251
continue;
255252
}
256-
float x = mapXToView(xVal, graphWidth);
253+
float x = mapXToView(xVal, graphWidth, paddingLeft);
257254
float y = mapYToView(line.yValues[i], scaleY, offsetY);
258255
canvas.drawLine(x, yBottom, x, y, line.paint);
259256
}
@@ -265,7 +262,7 @@ protected void onDraw(Canvas canvas) {
265262
if (xVal < mMinX || xVal > mMaxX) {
266263
continue;
267264
}
268-
float x1 = mapXToView(xVal, graphWidth);
265+
float x1 = mapXToView(xVal, graphWidth, paddingLeft);
269266
float y1 = mapYToView(line.yValues[i], scaleY, offsetY);
270267
if (x0 != -1) {
271268
canvas.drawLine(x0, y0, x1, y1, line.paint);
@@ -280,13 +277,14 @@ protected void onDraw(Canvas canvas) {
280277
if (mGridLinesY != null) {
281278
for (float yVal : mGridLinesY) {
282279
float yPos = mapYToView(yVal, scaleY, offsetY);
283-
canvas.drawLine(0, yPos, width, yPos, mGridPaintY);
284-
if (mShowGridLabelsY) {
285-
String label =
286-
mUnitY.isEmpty() ? String.format(Locale.getDefault(), "%.0f", yVal)
287-
: String.format(Locale.getDefault(), "%.0f %s", yVal, mUnitY);
288-
canvas.drawText(label, 10, yPos - 10, mGridTextPaintY);
289-
}
280+
canvas.drawLine(paddingLeft, yPos, width - paddingRight, yPos, mGridPaintY);
281+
String label = String.format(Locale.getDefault(), "%.0f", yVal);
282+
mGridTextPaintY.setTextAlign(Paint.Align.LEFT);
283+
canvas.drawText(label, 10, yPos - 10, mGridTextPaintY);
284+
}
285+
if (!mUnitY.isEmpty()) {
286+
mGridTextPaintY.setTextAlign(Paint.Align.LEFT);
287+
canvas.drawText(mUnitY, 10, 30, mGridTextPaintY);
290288
}
291289
}
292290

@@ -296,15 +294,20 @@ protected void onDraw(Canvas canvas) {
296294
if (xVal < mMinX || xVal > mMaxX) {
297295
continue;
298296
}
299-
float x = mapXToView(xVal, graphWidth);
300-
canvas.drawLine(x, 0, x, height - paddingBottom, mGridPaintX);
301-
if (mShowGridLabelsX) {
302-
String label =
303-
mUnitX.isEmpty() ? String.format(Locale.getDefault(), "%.0f", xVal)
304-
: String.format(Locale.getDefault(), "%.0f %s", xVal, mUnitX);
305-
float xOffset = xVal >= mMaxX ? -120 : 5;
306-
canvas.drawText(label, x + xOffset, height - 15, mGridTextPaintX);
297+
float x = mapXToView(xVal, graphWidth, paddingLeft);
298+
canvas.drawLine(x, paddingTop, x, height - paddingBottom, mGridPaintX);
299+
String label;
300+
if (Math.abs(xVal) >= 1000 && xVal % 1000 == 0) {
301+
label = String.format(Locale.getDefault(), "%.0fk", xVal / 1000);
302+
} else {
303+
label = String.format(Locale.getDefault(), "%.0f", xVal);
307304
}
305+
mGridTextPaintX.setTextAlign(Paint.Align.LEFT);
306+
canvas.drawText(label, x + 5, height - 15, mGridTextPaintX);
307+
}
308+
if (!mUnitX.isEmpty()) {
309+
mGridTextPaintX.setTextAlign(Paint.Align.RIGHT);
310+
canvas.drawText(mUnitX, width - 5, height - 15, mGridTextPaintX);
308311
}
309312
}
310313
}

0 commit comments

Comments
 (0)