diff --git a/src/org/hwo/ui/JDiagram.java b/src/org/hwo/ui/JDiagram.java index a7b2148..be33b5b 100644 --- a/src/org/hwo/ui/JDiagram.java +++ b/src/org/hwo/ui/JDiagram.java @@ -6,6 +6,7 @@ import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Toolkit; +import java.awt.geom.Point2D; import javax.swing.JComponent; import javax.swing.JPanel; @@ -22,6 +23,11 @@ import org.hwo.ui.diagram.SimplePlotProvider; public class JDiagram extends JComponent implements PlotProviderListener { + /** + * + */ + private static final long serialVersionUID = 1L; + private PlotProvider2 plotProvider; @@ -48,9 +54,13 @@ public class JDiagram extends JComponent implements PlotProviderListener { private int plotHeight, plotWidth; + private double abszissMinimum, abszissMaximum, abszissWindow; + //Positions of first and last abszisslabel + private int firstAbszissPos; + private int lastAbszissPos; private int screenDPI; @@ -59,7 +69,7 @@ public class JDiagram extends JComponent implements PlotProviderListener { private boolean autoOrdinateLabeling; private boolean drawHorizontalGrid; private boolean drawVerticalGrid; - private boolean logarithmic; + //private boolean logarithmic; private boolean preferLabelHints; private boolean autoScale; private boolean autoScaleMargins; @@ -74,6 +84,14 @@ public class JDiagram extends JComponent implements PlotProviderListener { private Integer selectedPlot; + //fields for zooming/ section selection + private float lastFocusPoint; + private float focusPoint; + private float focusRange; + private boolean inZoom; + //private int yMin, yMax; + + //private float average = 0; public JDiagram(){ setMinimumSize(new Dimension(80, 80)); @@ -105,6 +123,8 @@ public class JDiagram extends JComponent implements PlotProviderListener { if (this.plotProvider != null) this.plotProvider.addPlotProviderListener(this); + this.setFocus(this.plotProvider.getPositionMinimum(), this.plotProvider.getPositionMaximum()); + fundamentalsChanged(); } public PlotProvider2 getPlotProvider() { @@ -149,6 +169,7 @@ public class JDiagram extends JComponent implements PlotProviderListener { plotPainters = new PlotPainter[plotProvider.getNumGraphs()]; for (int n=0;n= 0 && graph < this.plotProvider.getNumGraphs() && this.plotProvider.getNumGraphs() != 0) + y = this.plotProvider.getValue(Math.round(x), graph); + y = y == null?0.0f : y; + p.setLocation(x, y); + return p; + } - public void autoscale(){ + public void autoscale(){ int ordinate; Double[] max,min; @@ -234,6 +266,7 @@ public class JDiagram extends JComponent implements PlotProviderListener { min = new Double[this.plotProvider.getMaxOrdinate()+1]; for (int graph=0; graph < this.plotProvider.getNumGraphs(); graph++){ + ordinate = this.plotProvider.getOrdinate(graph); for (int n=0;n max[ordinate])) max[ordinate] = value.doubleValue(); }; + + //autoscale x-axis + if(this.plotProvider.getValueCount(graph) >= this.plotProvider.getMaxSamples()) + { + this.plotProvider.setMaxSamples(this.plotProvider.getMaxSamples() + 2); + } } } - + for (int i=0;i= xMin? min : xMin; + float focusMax = max <= xMax? max : xMax; + + this.focusRange = this.focusPoint + focusMax; + } + + public float getFocusMin() { + return this.focusPoint; + } + public float getFocusMax() { + return this.focusPoint + this.focusRange; + } + + public void zoom(float zoomFactor, float focusVal) { + float z = ((zoomFactor / -100.0f) * 1.0f) + 1.0f; + float leftX = 0, rightX = 0; + float width = this.plotProvider.getPositionMaximum() - focusVal; + float widthL = this.plotProvider.getPositionMaximum() - width; + leftX = (widthL * z) - focusVal; + rightX = focusVal + (width * z); + setFocus(leftX, rightX); + } + + public int getGraphDrawStart() { + return this.firstAbszissPos; + } + + public int getGraphDrawEnd() { + return this.lastAbszissPos; + } + + public int getGraphWidth() { + return this.lastAbszissPos - this.firstAbszissPos; } @Override @@ -275,15 +364,15 @@ public class JDiagram extends JComponent implements PlotProviderListener { g.setColor(getBackground()); g.fillRect(0, 0, getWidth(), getHeight()); - if (plotProvider != null){ - - if (autoScale) - this.autoscale(); - + if(plotProvider != null){ + if(this.autoScale) { + autoscale(); + } paintOrdinates ((Graphics2D) g); paintAbszisse ((Graphics2D) g); paintGraphs ((Graphics2D) g); } + } public double[] getordinateLabelHints(int ordinate){ @@ -301,7 +390,11 @@ public class JDiagram extends JComponent implements PlotProviderListener { for (n = 0; n < hints.length; n++){ hints[n] = this.ordinateViews[ordinate].scaler.getMinValue() + (this.ordinateViews[ordinate].scaler.getWindow() * n / (hints.length-1)); } - } else { + + } else if(nHints == 0) { + hints = new double[0]; + } + else { hints = scalerHints; } @@ -315,12 +408,12 @@ public class JDiagram extends JComponent implements PlotProviderListener { d = null; for (int ordinate=0; ordinate < ordinateViews.length; ordinate++){ - labelValues[ ordinate ] = getordinateLabelHints(ordinate); + labelValues[ ordinate ] = getordinateLabelHints(ordinate); int nMarkers = labelValues[ ordinate ].length - 1; int maxWidth = 0; String[] labels = new String[ nMarkers + 1 ]; - int[] labelWidths = new int[ nMarkers + 1 ]; + int[] labelWidths = new int[ nMarkers + 1 ]; this.ordinateViews[ ordinate ].scaler.setHeight( plotHeight ); @@ -363,7 +456,6 @@ public class JDiagram extends JComponent implements PlotProviderListener { } plotWidth -= axMarkerLength; - }; g.drawLine( @@ -397,9 +489,7 @@ public class JDiagram extends JComponent implements PlotProviderListener { g.setColor( this.ordinateViews[ ordinate ].colDraw ); } } - } - } void paintAbszisse(Graphics2D g){ @@ -415,8 +505,10 @@ public class JDiagram extends JComponent implements PlotProviderListener { nMarker = plotWidth / (w*8/7); } - abszissMinimum = this.plotProvider.getPositionMinimum(); - abszissMaximum = this.plotProvider.getPositionMaximum(); + //abszissMinimum = this.plotProvider.getPositionMinimum(); + //abszissMaximum = this.plotProvider.getPositionMaximum(); + abszissMinimum = this.focusPoint; + abszissMaximum = this.focusPoint + this.focusRange; abszissWindow = abszissMaximum - abszissMinimum; g.setColor(getForeground()); @@ -454,7 +546,9 @@ public class JDiagram extends JComponent implements PlotProviderListener { ); g.setColor(getForeground()); }; - + if(n == 0)this.firstAbszissPos = getWidth() - bRight - plotWidth + xpos; + if(n == nMarker)this.lastAbszissPos = getWidth() - bRight - plotWidth + xpos; + } } @@ -478,7 +572,9 @@ public class JDiagram extends JComponent implements PlotProviderListener { graphColor = Color.BLACK; } - for (int n=0;n