Skip to content

Commit

Permalink
Added min/max for widget "plotter" as requested in #713.
Browse files Browse the repository at this point in the history
Set custom:showValue to false to disable.
  • Loading branch information
fesch committed Aug 22, 2021
1 parent 53dfd45 commit d74ed7e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/lu/fisch/canze/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
2021-08-22 [Bob] added min/max for widget "plotter". Set custom:showValue to false to disable
2021-08-20 [Bob] moved logging to shared storage (will not work for Anrdoid 11 yet ...)
2020-02-16 [Jeroen] Extended addressing and ZE50 test code (aplha!)
2020-02-02 [Jeroen] Removed phases count in advanced charging. Already show in Mains Current Type
2020-01-25 [Jeroen] Switch off CANsee chatter on USB when on master branch
Expand Down
32 changes: 32 additions & 0 deletions app/src/main/java/lu/fisch/canze/widgets/Plotter.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

package lu.fisch.canze.widgets;

import android.content.res.Resources;
import android.util.TypedValue;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

Expand All @@ -37,6 +40,7 @@
import lu.fisch.canze.activities.MainActivity;
import lu.fisch.canze.actors.Field;
import lu.fisch.canze.actors.Fields;
import lu.fisch.canze.classes.TimePoint;
import lu.fisch.canze.database.CanzeDataSource;
import lu.fisch.canze.fragments.MainFragment;
import lu.fisch.canze.interfaces.DrawSurfaceInterface;
Expand Down Expand Up @@ -261,9 +265,17 @@ public void draw(Graphics g) {

double lastX = Double.NaN;
double lastY = Double.NaN;
double min = Double.NaN;
double max = Double.NaN;
g.setColor(Color.RED);
for(int i=0; i<values.size(); i++)
{
// calculate min / max
if(values.get(i)<min || min==Double.NaN)
min=values.get(i);
if(values.get(i)>max || max==Double.NaN)
max=values.get(i);

try {
//MainActivity.debug("Value "+i+": "+values.get(i));
//MainActivity.debug("Value "+i+": "+values.get(i)+" Max: "+getMax()+" Min: "+getMin()+" height: "+getHeight()+" h: "+h);
Expand All @@ -283,6 +295,26 @@ public void draw(Graphics g) {
/* simply ignore */
}
}

// draw min & max
if (showValue) {
g.setColor(getTitleColor());
g.setTextSize(20);

int tx = getX() + width - 8 - spaceAlt;
int ty = getY();
int dy = g.stringHeight("Ip") + 4; // full height and undersling

String text = "min: "+min;
int tw = g.stringWidth(text);
ty += dy;
g.drawString(text, tx - tw, ty);

text = "max: "+max;
tw = g.stringWidth(text);
ty += dy;
g.drawString(text, tx - tw, ty);
}
}

// draw the title
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_battery.xml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@
custom:text="@string/graph_ModuleTemperatures"
custom:titleColor="?android:attr/colorForeground"
custom:widget="plotter"
custom:showValue="false"
custom:intervals="{
'7bb.6104.32':10000,
'7bb.6104.56':10000,
Expand Down

0 comments on commit d74ed7e

Please sign in to comment.