Skip to content
Snippets Groups Projects
Commit 840b8e4d authored by pompert's avatar pompert
Browse files

701

Additions:
-Value removal from plots
Mods:
-Improved handling of empty plots and value additions/removals.
parent 708e948f
No related branches found
No related tags found
No related merge requests found
...@@ -36,6 +36,7 @@ import gov.noaa.pmel.sgt.AxisNotFoundException; ...@@ -36,6 +36,7 @@ import gov.noaa.pmel.sgt.AxisNotFoundException;
import gov.noaa.pmel.sgt.CartesianGraph; import gov.noaa.pmel.sgt.CartesianGraph;
import gov.noaa.pmel.sgt.DataNotFoundException; import gov.noaa.pmel.sgt.DataNotFoundException;
import gov.noaa.pmel.sgt.JPane; import gov.noaa.pmel.sgt.JPane;
import gov.noaa.pmel.sgt.LayerChild;
import gov.noaa.pmel.sgt.LineAttribute; import gov.noaa.pmel.sgt.LineAttribute;
import gov.noaa.pmel.sgt.LineCartesianRenderer; import gov.noaa.pmel.sgt.LineCartesianRenderer;
import gov.noaa.pmel.sgt.LogAxis; import gov.noaa.pmel.sgt.LogAxis;
...@@ -56,12 +57,12 @@ import gov.noaa.pmel.util.GeoDate; ...@@ -56,12 +57,12 @@ import gov.noaa.pmel.util.GeoDate;
import gov.noaa.pmel.util.Point2D; import gov.noaa.pmel.util.Point2D;
import gov.noaa.pmel.util.Range2D; import gov.noaa.pmel.util.Range2D;
import gov.noaa.pmel.util.SoTPoint; import gov.noaa.pmel.util.SoTPoint;
import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.beans.PropertyVetoException; import java.beans.PropertyVetoException;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import javax.swing.JComponent; import javax.swing.JComponent;
...@@ -125,66 +126,101 @@ public class PlotSGTImpl implements IPlot{ ...@@ -125,66 +126,101 @@ public class PlotSGTImpl implements IPlot{
try{ try{
aNewPlot.setBatch(true); aNewPlot.setBatch(true);
CartesianGraph gp = (CartesianGraph)aNewPlot.getFirstLayer().getGraph(); String xAxisTitle = (String)data.get(PlotConstants.DATASET_XAXISLABEL);
String xAxisTitle = gp.getXAxis("Bottom Axis").getTitle().getText().toString(); String xAxisUnits = (String)data.get(PlotConstants.DATASET_XAXISUNIT);
String yAxisTitle = gp.getYAxis("Left Axis").getTitle().getText().toString(); String yAxisTitle = (String)data.get(PlotConstants.DATASET_YAXISLABEL);
String xAxisUnits = gp.getXAxis("Bottom Axis").getTitle().getText().toString(); String yAxisUnits = (String)data.get(PlotConstants.DATASET_YAXISUNIT);
String yAxisUnits = gp.getYAxis("Left Axis").getTitle().getText().toString();
LinkedList<HashMap> values = (LinkedList<HashMap>)data.get(PlotConstants.DATASET_VALUES); LinkedList<HashMap> values = (LinkedList<HashMap>)data.get(PlotConstants.DATASET_VALUES);
//Loop through X and Y Value data //Loop through X and Y Value data
if(values != null && values.size()> 0){ //System.out.println("Updating plot "+aNewPlot.getId()+": Old size :"+aNewPlot.getData().size()+" New Size: "+values.size());
if(values != null && values.size()>= 0){
Iterator linesIterator = values.iterator();
//Loop through all XY pairs if(values.size() >= aNewPlot.getData().size()){
while(linesIterator.hasNext()){
double[] xArray = null;
double[] yArray = null;
GeoDate[] xArrayDate = null;
GeoDate[] yArrayDate = null;
SGTMetaData meta = new SGTMetaData(xAxisTitle,
xAxisUnits,
false,
false);
SGTMetaData ymeta = new SGTMetaData(yAxisTitle,
yAxisUnits,
false,
false);
String lineLabel = "Unknown value";
HashMap line = (HashMap)linesIterator.next();
Iterator lineIterator = line.keySet().iterator();
//Retrieve XY pair label and xy values Iterator linesIterator = values.iterator();
while(lineIterator.hasNext()){ //Loop through all XY pairs
String key = (String)lineIterator.next(); while(linesIterator.hasNext()){
if(key.equalsIgnoreCase(PlotConstants.DATASET_VALUELABEL)){
lineLabel = (String)line.get(key); double[] xArray = null;
double[] yArray = null;
} else if(key.equalsIgnoreCase(PlotConstants.DATASET_XVALUES)){ GeoDate[] xArrayDate = null;
xArray = (double[])line.get(key); GeoDate[] yArrayDate = null;
SGTMetaData meta = new SGTMetaData(xAxisTitle,
} else if(key.equalsIgnoreCase(PlotConstants.DATASET_YVALUES)){ xAxisUnits,
yArray = (double[])line.get(key); false,
false);
SGTMetaData ymeta = new SGTMetaData(yAxisTitle,
yAxisUnits,
false,
false);
String lineLabel = "Unknown value";
HashMap line = (HashMap)linesIterator.next();
Iterator lineIterator = line.keySet().iterator();
//Retrieve XY pair label and xy values
while(lineIterator.hasNext()){
String key = (String)lineIterator.next();
if(key.equalsIgnoreCase(PlotConstants.DATASET_VALUELABEL)){
lineLabel = (String)line.get(key);
} else if(key.equalsIgnoreCase(PlotConstants.DATASET_XVALUES)){
xArray = (double[])line.get(key);
} else if(key.equalsIgnoreCase(PlotConstants.DATASET_YVALUES)){
yArray = (double[])line.get(key);
}else{
throw new InvalidDataSetException("(A value array was found that is not supported for a Line Plot: "+key.toString()+")");
}
}
SimpleLine lineData = new SimpleLine(
xArray,yArray,lineLabel);
lineData.setXMetaData(meta);
lineData.setYMetaData(ymeta);
lineData.setId(lineLabel);
if(aNewPlot.getData(lineLabel) == null){
aNewPlot.addData(lineData, lineLabel);
}else{ }else{
throw new InvalidDataSetException("(A value array was found that is not supported for a Line Plot: "+key.toString()+")"); SGTData someData = aNewPlot.getData(lineLabel);
someData = lineData;
} }
} }
}else if(values.size() < aNewPlot.getData().size()){
//System.out.println("Removing from plot...");
SimpleLine lineData = new SimpleLine( HashSet<SGTData> toBeDeletedData = new HashSet<SGTData>();
xArray,yArray,lineLabel);
lineData.setXMetaData(meta);
lineData.setYMetaData(ymeta);
lineData.setId(lineLabel);
if(aNewPlot.getData(lineLabel) == null){ Iterator anIterator = aNewPlot.getData().iterator();
aNewPlot.addData(lineData, lineLabel); while(anIterator.hasNext()){
SGTData someData = (SGTData)anIterator.next();
boolean presentInNewData = false;
Iterator linesIterator = values.iterator();
//Loop through all XY pairs
while(linesIterator.hasNext()){
HashMap line = (HashMap)linesIterator.next();
String valueLabel = (String)line.get(PlotConstants.DATASET_VALUELABEL);
if(valueLabel.equalsIgnoreCase(someData.getId())){
presentInNewData = true;
}
}
if(!presentInNewData){
toBeDeletedData.add(someData);
}
}
//System.out.println("Removing "+toBeDeletedData.size()+" value from plot "+aNewPlot.getId());
CartesianGraph gp2 = (CartesianGraph)aNewPlot.getFirstLayer().getGraph();
for (SGTData aData : toBeDeletedData){
aNewPlot.clear(aData.getId());
} }
} }
} }
aNewPlot.setBatch(false); aNewPlot.setBatch(false);
}catch(Exception e){ }catch(Exception e){
InvalidDataSetException exx = new InvalidDataSetException("( The data set provided was not sufficient to update the line plot "+aNewPlot.getName()+". Please check the log file )"); InvalidDataSetException exx = new InvalidDataSetException("( The data set provided was not sufficient to update the line plot "+aNewPlot.getName()+". Please check the log file )");
exx.initCause(e); exx.initCause(e);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment