-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
45d2d9f
commit e1db420
Showing
7 changed files
with
297 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
186 changes: 186 additions & 0 deletions
186
app/src/main/java/com/bogueratcreations/eaftoolkit/DCP/PointsChart.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
package com.bogueratcreations.eaftoolkit.DCP; | ||
|
||
import android.content.Intent; | ||
import android.graphics.Color; | ||
import android.os.Bundle; | ||
import android.support.design.widget.FloatingActionButton; | ||
import android.support.design.widget.Snackbar; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.Toolbar; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.widget.Toast; | ||
|
||
import com.bogueratcreations.eaftoolkit.DCP.model.Reading; | ||
import com.bogueratcreations.eaftoolkit.R; | ||
import com.github.mikephil.charting.animation.Easing; | ||
import com.github.mikephil.charting.charts.LineChart; | ||
|
||
import io.realm.Realm; | ||
|
||
import com.bogueratcreations.eaftoolkit.DCP.model.Point; | ||
import com.bogueratcreations.eaftoolkit.DCP.model.Project; | ||
import com.github.mikephil.charting.components.AxisBase; | ||
import com.github.mikephil.charting.components.Legend; | ||
import com.github.mikephil.charting.components.XAxis; | ||
import com.github.mikephil.charting.components.YAxis; | ||
import com.github.mikephil.charting.data.Entry; | ||
import com.github.mikephil.charting.data.LineData; | ||
import com.github.mikephil.charting.data.LineDataSet; | ||
import com.github.mikephil.charting.formatter.IAxisValueFormatter; | ||
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet; | ||
|
||
import java.text.DecimalFormat; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class PointsChart extends AppCompatActivity { | ||
|
||
long passedProjectID; | ||
|
||
private Realm realm; | ||
Project passedProject; | ||
|
||
LineChart chart; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_points_chart); | ||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | ||
setSupportActionBar(toolbar); | ||
|
||
passedProjectID = getIntent().getLongExtra("projId",-1); | ||
realm = Realm.getDefaultInstance(); | ||
passedProject = realm.where(Project.class) | ||
.equalTo("id",passedProjectID) | ||
.findFirst(); | ||
|
||
// Customize the Chart | ||
chart = (LineChart) findViewById(R.id.chartProject); | ||
chart.setKeepPositionOnRotation(true); | ||
chart.animateY(1000, Easing.EasingOption.EaseInOutQuad); | ||
chart.setHighlightPerTapEnabled(false); | ||
chart.setHighlightPerDragEnabled(false); | ||
chart.setNoDataText("No data to display."); | ||
chart.getDescription().setText(passedProject.getProjName()); | ||
Legend legend = chart.getLegend(); | ||
legend.setWordWrapEnabled(true); | ||
XAxis xAxis = chart.getXAxis(); | ||
xAxis.setAxisMinimum(1f); | ||
xAxis.setAxisMaximum(101f); | ||
xAxis.setLabelCount(8); | ||
xAxis.setDrawLabels(true); | ||
xAxis.setValueFormatter(new IAxisValueFormatter() { | ||
@Override | ||
public String getFormattedValue(float value, AxisBase axis) { | ||
DecimalFormat mFormat; | ||
mFormat = new DecimalFormat("##0.#"); // use one decimal | ||
if (value <= 0) { | ||
return "0"; | ||
} else { | ||
return mFormat.format(unScaleCbr(value)); | ||
} | ||
} | ||
}); | ||
YAxis yAxis = chart.getAxisLeft(); | ||
yAxis.setInverted(true); | ||
yAxis.setAxisMaximum(1020f); | ||
yAxis.setAxisMinimum(0f); | ||
YAxis yAxis1 = chart.getAxisRight(); | ||
yAxis1.setInverted(true); | ||
yAxis1.setAxisMaximum(1020f); | ||
yAxis1.setAxisMinimum(0f); | ||
yAxis1.setValueFormatter(new IAxisValueFormatter() { | ||
@Override | ||
public String getFormattedValue(float value, AxisBase axis) { | ||
DecimalFormat mFormat; | ||
mFormat = new DecimalFormat("##0"); // use one decimal | ||
return mFormat.format(value/25.4); | ||
} | ||
}); | ||
|
||
// Retrieve applicable readings from the realm...Now to use them in chart. | ||
Long[] pointIds = new Long[passedProject.getPoints().size()]; | ||
int counter = 0; | ||
// TODO: Get me some better colors! | ||
int[] colors = new int[]{ | ||
Color.RED, | ||
Color.BLUE, | ||
Color.GREEN | ||
}; | ||
// use the interface ILineDataSet | ||
String seriesTitle[] = new String[passedProject.getPoints().size()]; | ||
List<ILineDataSet> dataSets = new ArrayList<ILineDataSet>(); | ||
|
||
for (Point p : passedProject.getPoints()) { | ||
// Reinitialize the series for each point. | ||
List<Entry> series = new ArrayList<Entry>(); | ||
String title = p.getPointNum(); | ||
for (Reading r : p.getReadings().sort("readingNum")) { | ||
// Store x,y values for this series. | ||
double cbrMax = r.getCbr(); | ||
if (cbrMax > 100.0) {cbrMax = 100.0;} | ||
Log.d("EAF", "r.getCbr(): " + cbrMax + " scaleCbr(cbrMax: " + scaleCbr(cbrMax)); | ||
Entry entry = new Entry( scaleCbr(cbrMax),(float)(r.getTotalDepth())); | ||
series.add(entry); | ||
} | ||
// Find out if there are any readings and force an empty one to prevent crash. | ||
if (p.getReadings().size() > 0) { | ||
LineDataSet seriesDataSet = new LineDataSet(series, title); | ||
seriesDataSet.setColor(colors[counter]); | ||
seriesDataSet.setCircleColor(colors[counter]); | ||
dataSets.add(seriesDataSet); | ||
if (counter == 2) { | ||
counter = 0; | ||
} else { | ||
counter++; | ||
} | ||
} | ||
} | ||
|
||
LineData data = new LineData(dataSets); | ||
data.setDrawValues(false); | ||
chart.setData(data); | ||
chart.invalidate(); | ||
|
||
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); | ||
fab.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
String fileName = passedProject.getProjName() + "_" + (int)(Math.random() * 100); | ||
chart.saveToGallery(fileName, 100); | ||
Toast.makeText(getBaseContext(), "Saved this graph to your Gallery", Toast.LENGTH_LONG).show(); | ||
} | ||
}); | ||
// Will crash if I do, removing for consistency... | ||
//getSupportActionBar().setDisplayHomeAsUpEnabled(true); | ||
} | ||
|
||
public float scaleCbr(double cbr) { | ||
|
||
return (float)(Math.log(cbr) / Math.log(100)) * 100; | ||
} | ||
public float unScaleCbr(double cbr) { | ||
double calcVal = Math.pow(10,(cbr/50)); | ||
return (float)(calcVal); | ||
} | ||
|
||
@Override | ||
public void onBackPressed() { | ||
// TODO: Update the lowestCBR for Point here or in onItemSwipedDismiss | ||
Intent intent = new Intent(); | ||
intent.putExtra("projId", passedProjectID); | ||
setResult(RESULT_OK, intent); | ||
finish(); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
if(realm != null) { | ||
realm.close(); | ||
realm = null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:fitsSystemWindows="true" | ||
tools:context="com.bogueratcreations.eaftoolkit.DCP.PointsChart"> | ||
|
||
<android.support.design.widget.AppBarLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:theme="@style/CustomActionBarTheme.AppBarOverlay"> | ||
|
||
<android.support.v7.widget.Toolbar | ||
android:id="@+id/toolbar" | ||
android:layout_width="match_parent" | ||
android:layout_height="?attr/actionBarSize" | ||
android:background="@color/BRCgreen" | ||
app:popupTheme="@style/CustomActionBarTheme.PopupOverlay" /> | ||
|
||
</android.support.design.widget.AppBarLayout> | ||
|
||
<include layout="@layout/content_points_chart" /> | ||
|
||
<android.support.design.widget.FloatingActionButton | ||
android:id="@+id/fab" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="bottom|end" | ||
android:layout_margin="@dimen/fab_margin" | ||
app:srcCompat="@android:drawable/ic_menu_gallery" /> | ||
|
||
</android.support.design.widget.CoordinatorLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
app:layout_behavior="@string/appbar_scrolling_view_behavior" | ||
tools:context="com.bogueratcreations.eaftoolkit.DCP.PointsChart" | ||
tools:showIn="@layout/activity_points_chart"> | ||
|
||
<com.github.mikephil.charting.charts.LineChart | ||
android:id="@+id/chartProject" | ||
android:layout_marginBottom="8dp" | ||
android:layout_marginLeft="0dp" | ||
android:layout_marginRight="8dp" | ||
android:layout_marginTop="0dp" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintHorizontal_bias="0.0" | ||
app:layout_constraintLeft_toRightOf="@+id/tvYlabelL" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/tvXlabel" | ||
app:layout_constraintVertical_bias="0.0" | ||
android:layout_width="312dp" | ||
android:layout_height="473dp" /> | ||
|
||
<TextView | ||
android:id="@+id/tvXlabel" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="8dp" | ||
android:text="CBR" | ||
android:textSize="14sp" | ||
android:textStyle="bold" | ||
app:layout_constraintTop_toTopOf="parent" | ||
android:layout_marginRight="8dp" | ||
app:layout_constraintRight_toRightOf="parent" | ||
android:layout_marginLeft="8dp" | ||
app:layout_constraintLeft_toLeftOf="parent" /> | ||
|
||
<TextView | ||
android:id="@+id/tvYlabelL" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginBottom="8dp" | ||
android:layout_marginLeft="8dp" | ||
android:layout_marginTop="8dp" | ||
android:text="D\nE\nP\nT\nH\n\nmm" | ||
android:textSize="14sp" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
</android.support.constraint.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters