changed return Value of getValue Method in PlotProvider (and inherited) from Float to Double

implemented time based x_axis
master
Niclas Thobaben 2018-02-14 11:11:06 +01:00 committed by Harald Wolff
parent f45db5f242
commit ac96878a66
4 changed files with 34 additions and 20 deletions

View File

@ -27,6 +27,7 @@ import javax.swing.JPanel;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import org.hwo.ui.diagram.CirclePlotPainter;
import org.hwo.ui.diagram.DiagramListener; import org.hwo.ui.diagram.DiagramListener;
import org.hwo.ui.diagram.DiagramViewEvent; import org.hwo.ui.diagram.DiagramViewEvent;
import org.hwo.ui.diagram.LinePlotPainter; import org.hwo.ui.diagram.LinePlotPainter;
@ -112,6 +113,10 @@ public class JDiagram extends JComponent implements PlotProviderListener, Bounde
private double mouseWheelZoom = 1.03; private double mouseWheelZoom = 1.03;
private double abzissSpacing;
private boolean pointsEnabled;
public JDiagram(){ public JDiagram(){
setMinimumSize(new Dimension(80, 80)); setMinimumSize(new Dimension(80, 80));
setDoubleBuffered(true); setDoubleBuffered(true);
@ -119,7 +124,8 @@ public class JDiagram extends JComponent implements PlotProviderListener, Bounde
defaultLabeler = new SimplePlotLabeler(); defaultLabeler = new SimplePlotLabeler();
abszissLabeler = defaultLabeler; abszissLabeler = defaultLabeler;
bTop = bBottom = bLeft = 10; bTop = 40;
bBottom = bLeft = 10;
bRight = 30; bRight = 30;
axMarkerLength = 3; axMarkerLength = 3;
@ -258,6 +264,8 @@ public class JDiagram extends JComponent implements PlotProviderListener, Bounde
} }
}); });
this.abzissSpacing = 1.2;
} }
private void fireViewWindowChanged(){ private void fireViewWindowChanged(){
@ -324,7 +332,7 @@ public class JDiagram extends JComponent implements PlotProviderListener, Bounde
for (int n=0; n < plotProvider.getMaxOrdinate() + 1; n++) for (int n=0; n < plotProvider.getMaxOrdinate() + 1; n++)
ordinateViews[n] = new OrdinateView(n); ordinateViews[n] = new OrdinateView(n);
PlotPainter pp = new LinePlotPainter(); PlotPainter pp = new CirclePlotPainter();
plotPainters = new PlotPainter[plotProvider.getNumGraphs()]; plotPainters = new PlotPainter[plotProvider.getNumGraphs()];
for (int n=0;n<plotProvider.getNumGraphs();n++) for (int n=0;n<plotProvider.getNumGraphs();n++)
plotPainters[n] = pp; plotPainters[n] = pp;
@ -402,6 +410,12 @@ public class JDiagram extends JComponent implements PlotProviderListener, Bounde
this.abszissLabeler = abszissLabeler; this.abszissLabeler = abszissLabeler;
} }
public double getAbzissSpacing() {
return this.abzissSpacing;
}
public void setAbszissSpacing(double spacing) {
this.abzissSpacing = spacing;
}
public void autoscale(){ public void autoscale(){
int ordinate; int ordinate;
@ -591,7 +605,7 @@ public class JDiagram extends JComponent implements PlotProviderListener, Bounde
if (nMarker == 0){ if (nMarker == 0){
int w = g.getFontMetrics().stringWidth( labeler.getAbzisseLabel(this, (double)this.plotProvider.getPositionMaximum())); int w = g.getFontMetrics().stringWidth( labeler.getAbzisseLabel(this, (double)this.plotProvider.getPositionMaximum()));
nMarker = plotWidth / (w*8/7); nMarker = plotWidth / (int)(w*this.abzissSpacing);
} }
// TODO change for zoom // TODO change for zoom
@ -663,7 +677,7 @@ public class JDiagram extends JComponent implements PlotProviderListener, Bounde
for (int n=0;n<this.plotProvider.getLength(); n++){ for (int n=0;n<this.plotProvider.getLength(); n++){
int x,y; int x,y;
Float value = this.plotProvider.getValue(n, graph); Float value = this.plotProvider.getValue(n, graph);
Float position = this.plotProvider.getPosition(n, graph); Double position = this.plotProvider.getPosition(n, graph);
if ((value != null) && (position != null) && (position >= this.abszissMinimum) && (position <= amax)) if ((value != null) && (position != null) && (position >= this.abszissMinimum) && (position <= amax))
{ {

View File

@ -291,18 +291,18 @@ public class AnnotatedPlotProvider implements PlotProvider2{
} }
@Override @Override
public Float getPosition(int x, int graph) { public Double getPosition(int x, int graph) {
return (float)x; return (double)x;
} }
@Override @Override
public Float getPositionMinimum() { public Double getPositionMinimum() {
return 0.0f; return 0.0;
} }
@Override @Override
public Float getPositionMaximum() { public Double getPositionMaximum() {
return this.values.size()-1.0f; return this.values.size()-1.0;
} }
private LinkedList<PlotProviderListener> plotProviderListeners = new LinkedList<PlotProviderListener>(); private LinkedList<PlotProviderListener> plotProviderListeners = new LinkedList<PlotProviderListener>();

View File

@ -9,11 +9,11 @@ public interface PlotProvider2 {
public int getNumGraphs(); public int getNumGraphs();
public String getLabel(int graph); public String getLabel(int graph);
public Float getValue(int x,int graph); public Float getValue(int x,int graph);
public Float getPosition(int x,int graph); public Double getPosition(int x,int graph);
public int getOrdinate(int graph); public int getOrdinate(int graph);
public Float getPositionMinimum(); public Double getPositionMinimum();
public Float getPositionMaximum(); public Double getPositionMaximum();
public Color[] getColors(); public Color[] getColors();

View File

@ -83,8 +83,8 @@ public class SimplePlotProvider implements PlotProvider2 {
} }
@Override @Override
public Float getPosition(int x, int graph) { public Double getPosition(int x, int graph) {
return (float)x; return x * 1.0;
} }
@Override @Override
@ -97,12 +97,12 @@ public class SimplePlotProvider implements PlotProvider2 {
} }
@Override @Override
public Float getPositionMaximum() { public Double getPositionMaximum() {
return (float)(this.points-1); return (double)(this.points-1);
} }
@Override @Override
public Float getPositionMinimum() { public Double getPositionMinimum() {
return (float)0; return 0.0;
} }