Skip to content

Commit dcd8f31

Browse files
committed
Fixed drawing graphs with equally min-max values.
1 parent f0e06fe commit dcd8f31

File tree

6 files changed

+52
-36
lines changed

6 files changed

+52
-36
lines changed

graphview/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
android:label="@string/app_name"
99
android:roundIcon="@mipmap/ic_launcher_round"
1010
android:supportsRtl="true"
11-
android:theme="@style/AppTheme">
11+
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
1212
<activity android:name=".MainActivity">
1313
<intent-filter>
1414
<action android:name="android.intent.action.MAIN" />

graphview/src/main/java/com/vk59/graphview/MainActivity.java

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import android.graphics.Color;
66
import android.os.Bundle;
7-
import android.provider.ContactsContract;
87
import android.util.Log;
98
import android.view.View;
109
import android.widget.Button;
@@ -30,7 +29,7 @@ public class MainActivity extends AppCompatActivity
3029
private GraphData graphTC;
3130
private GraphData graphPC;
3231
private GraphView graphView;
33-
private int currentAxes = 3;
32+
private int currentAxes = 0;
3433

3534
private RadioGroup switcherAxises;
3635
private Button buttonStop;
@@ -66,9 +65,9 @@ private void initializeViews() {
6665
graphView = findViewById(R.id.graphView);
6766
dataView = findViewById(R.id.dataView);
6867
int color = Color.rgb(61, 165, 244);
69-
graphPC = new GraphData(new ArrayList<Moment>(), color, " ");
70-
graphTC = new GraphData(new ArrayList<Moment>(), color, " ");
71-
graphTP = new GraphData(new ArrayList<Moment>(), color, " ");
68+
graphPC = new GraphData(new ArrayList<Moment>(), color, "Sinusoid");
69+
graphTC = new GraphData(new ArrayList<Moment>(), color, "Sinusoid");
70+
graphTP = new GraphData(new ArrayList<Moment>(), color, "Sinusoid");
7271
graphData = graphTP;
7372
}
7473

@@ -97,22 +96,22 @@ public void onClick(View v) {
9796
private RadioGroup.OnCheckedChangeListener onSwitchAxises = new RadioGroup.OnCheckedChangeListener() {
9897
@Override
9998
public void onCheckedChanged(RadioGroup group, int checkedId) {
100-
switch (checkedId) {
101-
case R.id.radioGraphPT:
102-
currentAxes = 0;
103-
break;
104-
case R.id.radioGraphCT:
105-
currentAxes = 1;
106-
break;
107-
case R.id.radioGraphCP:
108-
currentAxes = 2;
109-
break;
110-
case R.id.radioNumbers:
111-
currentAxes = 3;
112-
break;
113-
}
114-
setLabelAxises();
115-
drawChart();
99+
switch (checkedId) {
100+
case R.id.radioGraphPT:
101+
currentAxes = 0;
102+
break;
103+
case R.id.radioGraphCT:
104+
currentAxes = 1;
105+
break;
106+
case R.id.radioGraphCP:
107+
currentAxes = 2;
108+
break;
109+
case R.id.radioNumbers:
110+
currentAxes = 3;
111+
break;
112+
}
113+
setLabelAxises();
114+
drawChart();
116115
}
117116
};
118117

@@ -136,7 +135,7 @@ private void prepareNewData(MomentTest testData) {
136135
}
137136

138137
private void customizeGraphView() {
139-
graphView.setLegendEnable(false);
138+
graphView.setLegendEnable(true);
140139
graphView.addGraphData(graphData);
141140
dataView.addGraphData(graphData);
142141
setLabelAxises();

graphview/src/main/res/layout/activity_main.xml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,25 @@
44
xmlns:tools="http://schemas.android.com/tools"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7+
android:background="@color/background"
78
tools:context=".MainActivity">
89

9-
<com.vk59.graphviewlibrary.GraphView
10-
android:id="@+id/graphView"
10+
<com.vk59.graphview.DataView
11+
android:id="@+id/dataView"
1112
android:layout_width="0dp"
1213
android:layout_height="0dp"
13-
android:visibility="visible"
14+
android:visibility="invisible"
15+
app:layout_constraintBottom_toTopOf="@+id/guideline"
1416
app:layout_constraintEnd_toEndOf="parent"
1517
app:layout_constraintStart_toStartOf="parent"
1618
app:layout_constraintTop_toTopOf="parent" />
1719

18-
<com.vk59.graphview.DataView
19-
android:id="@+id/dataView"
20+
<com.vk59.graphviewlibrary.GraphView
21+
android:id="@+id/graphView"
2022
android:layout_width="0dp"
2123
android:layout_height="0dp"
22-
android:visibility="invisible"
23-
app:layout_constraintBottom_toTopOf="@+id/guideline"
24+
android:visibility="visible"
25+
app:layout_constraintBottom_toBottomOf="@+id/dataView"
2426
app:layout_constraintEnd_toEndOf="parent"
2527
app:layout_constraintStart_toStartOf="parent"
2628
app:layout_constraintTop_toTopOf="parent" />
@@ -29,7 +31,9 @@
2931
android:id="@+id/buttonStop"
3032
android:layout_width="wrap_content"
3133
android:layout_height="wrap_content"
32-
android:text="Stop"
34+
android:text="@string/button_stop"
35+
android:background="@color/colorPrimary"
36+
android:textColor="@color/background"
3337
app:layout_constraintBottom_toBottomOf="parent"
3438
app:layout_constraintEnd_toEndOf="parent"
3539
app:layout_constraintHorizontal_bias="0.5"
@@ -41,7 +45,9 @@
4145
android:id="@+id/buttonStart"
4246
android:layout_width="wrap_content"
4347
android:layout_height="wrap_content"
44-
android:text="Start"
48+
android:text="@string/button_start"
49+
android:background="@color/colorPrimary"
50+
android:textColor="@color/background"
4551
app:layout_constraintBottom_toBottomOf="parent"
4652
app:layout_constraintEnd_toEndOf="parent"
4753
app:layout_constraintStart_toEndOf="@+id/radio_group"
@@ -53,7 +59,7 @@
5359
android:layout_width="wrap_content"
5460
android:layout_height="wrap_content"
5561
android:orientation="horizontal"
56-
app:layout_constraintGuide_percent="0.7017784" />
62+
app:layout_constraintGuide_percent="0.75" />
5763

5864
<RadioGroup
5965
android:id="@+id/radio_group"
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<color name="colorPrimary">#6200EE</color>
4-
<color name="colorPrimaryDark">#3700B3</color>
5-
<color name="colorAccent">#03DAC5</color>
3+
<color name="colorPrimary">#5566FF</color>
4+
<color name="colorPrimaryDark">#641FFF</color>
5+
<color name="colorAccent">#03A9F4</color>
6+
<color name="background">#FFFFFF</color>
67
</resources>

graphview/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
<string name="chartAxisTime">Time, sec</string>
44
<string name="chartAxisPotential">Potential, V</string>
55
<string name="chartAxisCurrent">Current, uA</string>
6+
<string name="button_stop">Stop</string>
7+
<string name="button_start">Start</string>
68
</resources>

graphviewlibrary/src/main/java/com/vk59/graphviewlibrary/GraphView.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,5 +369,13 @@ private void getMinMaxValues() {
369369
if (graph.getMaxY() > maxY) maxY = graph.getMaxY();
370370
if (graph.getMinY() < minY) minY = graph.getMinY();
371371
}
372+
if (maxX == minX) {
373+
maxX = maxX + 3 * 0.1f;
374+
minX = minX - 2 * 0.1f;
375+
}
376+
if (maxY == minY) {
377+
maxY = maxY + 3 * 0.1f;
378+
minY = minY - 2 * 0.1f;
379+
}
372380
}
373381
}

0 commit comments

Comments
 (0)