Changeset 191 for ether_megapoli/trunk/service/implementation/com/ether/EtherPlotContentServiceImpl.java
- Timestamp:
- 09/12/11 18:11:46 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ether_megapoli/trunk/service/implementation/com/ether/EtherPlotContentServiceImpl.java
r190 r191 5 5 import gov.noaa.pmel.sgt.Axis; 6 6 import gov.noaa.pmel.sgt.CartesianGraph; 7 import gov.noaa.pmel.sgt.ColorMap; 8 import gov.noaa.pmel.sgt.ContourLevels; 7 9 import gov.noaa.pmel.sgt.Graph; 10 import gov.noaa.pmel.sgt.GridAttribute; 11 import gov.noaa.pmel.sgt.IndexedColorMap; 8 12 import gov.noaa.pmel.sgt.JPane; 9 13 import gov.noaa.pmel.sgt.Layer; … … 16 20 import gov.noaa.pmel.sgt.StackedLayout; 17 21 import gov.noaa.pmel.sgt.TimeAxis; 22 import gov.noaa.pmel.sgt.demo.TestData; 23 import gov.noaa.pmel.sgt.dm.SGTData; 18 24 import gov.noaa.pmel.sgt.dm.SGTMetaData; 25 import gov.noaa.pmel.sgt.dm.SimpleGrid; 19 26 import gov.noaa.pmel.sgt.dm.SimpleLine; 27 import gov.noaa.pmel.sgt.swing.JPlotLayout; 20 28 import gov.noaa.pmel.util.Dimension2D; 21 29 import gov.noaa.pmel.util.GeoDateArray; … … 30 38 import java.awt.*; 31 39 import java.util.ArrayList; 40 import java.util.Collections; 32 41 import java.util.Date; 33 42 import java.util.List; … … 79 88 final List<Pair> pIdPIdListForSecondAxis = listPairOfPIdPIdForTwoAxes.getSecondValue(); 80 89 81 final List<SimpleLine> allLines = createLines( pIdPIdListForFirstAxis, megapoliPlot.getBeginDate(), megapoliPlot.getEndDate(), null, locale );82 final List<SimpleLine> allLinesForSecondAxis = createLines( pIdPIdListForSecondAxis, megapoliPlot.getBeginDate(), megapoliPlot.getEndDate(), 10, locale );90 final List<SimpleLine> allLines = createLines( pIdPIdListForFirstAxis, megapoliPlot.getBeginDate(), megapoliPlot.getEndDate(), 10, locale ); 91 final List<SimpleLine> allLinesForSecondAxis = createLines( pIdPIdListForSecondAxis, megapoliPlot.getBeginDate(), megapoliPlot.getEndDate(), 50, locale ); 83 92 List<SimpleLine> lines = extractRealLines( allLines ); 84 93 List<SimpleLine> linesForSecondAxis = extractRealLines( allLinesForSecondAxis ); … … 171 180 } 172 181 182 @NotNull 183 public JPane create2DPlot( @NotNull final MegapoliPlot megapoliPlot, @NotNull final Integer plotWidth, @NotNull final Integer plotHeight, @Nullable final Locale locale ) 184 { 185 // final JPane mainPane = new JPane( "2D Pane", new Dimension( plotWidth, plotHeight ) ); 186 187 final ResourceBundle bundle = WebHelper.getBundle( locale ); 188 189 final List<Double> parameterValues = (List<Double>) megapoliPlot.getData().getFirstArray(); 190 final List<Double> latitudeValues = (List<Double>) megapoliPlot.getData().getSecondArray(); 191 final List<Double> longitudeValues = (List<Double>) megapoliPlot.getData().getThirdArray(); 192 193 SGTData newData; 194 TestData td; 195 196 /* 197 * Create a test grid with sinasoidal-ramp data. 198 */ 199 // Range2D xr = new Range2D( 190.0f, 250.0f, 1.0f ); 200 // Range2D yr = new Range2D( 0.0f, 45.0f, 1.0f ); 201 Range2D xr = new Range2D( 190.0f, 200.0f, 1.0f ); 202 Range2D yr = new Range2D( 0.0f, 4.0f, 1.0f ); 203 // newData = testDataa( xr, yr, TestData.SINE_RAMP, 12.0f, 30.f, 5.0f, parameterArray, latitudeArray, longitudeValues ); 204 205 206 // public SGTData testDataa( Range2D range1, Range2D range2, int type, float amp, float off, float per, final double[] parameterArray, final double[] latitudeArray, final double[] longitudeValues ) 207 final SimpleGrid simpleGrid; 208 final SGTMetaData xMeta; 209 final SGTMetaData yMeta; 210 final SGTMetaData zMeta; 211 212 final int num1 = (int) ( ( xr.end - xr.start ) / xr.delta ) + 1; 213 final double[] axis1 = new double[num1]; 214 final int num2 = (int) ( ( yr.end - yr.start ) / yr.delta ) + 1; 215 final double[] axis2 = new double[num2]; 216 217 for( int count = 0; count < num1; count++ ) 218 axis1[count] = xr.start + count * xr.delta; 219 220 for( int count = 0; count < num2; count++ ) 221 axis2[count] = yr.start + count * yr.delta; 222 223 // final double[] valuesOrigPetites = getValues( axis1, num1, axis2, 2, TestData.SINE_RAMP, 12.0f, 30.f, 5.0f ); 224 // final double[] valuesOrigPetites = getValues( longitudeValues, longitudeValues.length, latitudeValues, latitudeValues.length, TestData.SINE_RAMP, 12.0f, 30.f, 5.0f ); 225 226 // final double[] valuesOrig = new double[num1 * num2]; 227 // for( int count = 0; count < valuesOrigPetites.length; count++ ) 228 // { 229 // valuesOrig[count] = valuesOrigPetites[count]; 230 // } 231 // for( int count = valuesOrigPetites.length; count < num1 * num2; count++ ) 232 // { 233 // valuesOrig[count] = Double.NaN; 234 // } 235 236 final double[] parameterValuesArray = EtherHelper.convertListDoubleToDoubleArray( parameterValues ); 237 final double[] parameterValuesMap = new double[latitudeValues.size() * longitudeValues.size()]; 238 for( int i = 0; i < parameterValuesArray.length; i++ ) 239 parameterValuesMap[i] = parameterValuesArray[i]; 240 241 for( int i = parameterValuesArray.length; i < latitudeValues.size() * longitudeValues.size(); i++ ) 242 parameterValuesMap[i] = Double.NaN; 243 244 SGLabel keyLabel = new SGLabel( "Key Label", "", new Point2D.Double( 0.0, 0.0 ) ); 245 keyLabel.setHeightP( 0.16 ); 246 // 247 // create SimpleGrid 248 // 249 zMeta = new SGTMetaData( "ts", "m s-1" ); 250 keyLabel.setText( "XY test grid" ); 251 xMeta = new SGTMetaData( bundle.getString( "plot.longitude" ), bundle.getString( "plot.degres" ) ); 252 yMeta = new SGTMetaData( bundle.getString( "plot.latitude" ), bundle.getString( "plot.degres" ) ); 253 // final SimpleGrid sg = new SimpleGrid( valuesOrig, axis1, axis2, "Test Series" ); 254 // simpleGrid = new SimpleGrid( parameterValues, longitudeValues, latitudeValues, "Test Series" ); 255 // simpleGrid = new SimpleGrid( valuesOrig, longitudeValues, latitudeValues, "Test Series" ); 256 // simpleGrid = new SimpleGrid( valuesOrig, axis1, axis2, "Test Series" ); 257 258 final double[] longitudeValuesArray = EtherHelper.convertListDoubleToDoubleArray( longitudeValues ); 259 final double[] latitudeValuesArray = EtherHelper.convertListDoubleToDoubleArray( latitudeValues ); 260 simpleGrid = new SimpleGrid( parameterValuesMap, longitudeValuesArray, latitudeValuesArray, "Test Series" ); 261 262 simpleGrid.setXMetaData( xMeta ); 263 simpleGrid.setYMetaData( yMeta ); 264 simpleGrid.setZMetaData( zMeta ); 265 simpleGrid.setKeyTitle( keyLabel ); 266 simpleGrid.setRealFullGrid( false ); 267 268 269 // Create the contour levels and color map 270 final Double min = Collections.min( parameterValues ); 271 final Double max = Collections.max( parameterValues ); 272 final Double delta = ( max - min ) / 64; 273 final Range2D datar = new Range2D( min, max, delta ); 274 // final Range2D datar = new Range2D( Collections.min( Arrays.asList( parameterValuesMap ) ), 35f, 0.5f ); 275 final ContourLevels clevels = ContourLevels.getDefault( datar ); 276 final ColorMap cmap = createColorMap( datar ); 277 278 // final Range2D datarOrig = new Range2D( 5f, 10.0f, 1f ); 279 // final ContourLevels clevelsOrig = ContourLevels.getDefault( datarOrig ); 280 // final ColorMap cmapOrig = createColorMap( datarOrig ); 281 // final GridAttribute gridAttributeOrig = new GridAttribute( clevelsOrig ); 282 // gridAttributeOrig.setColorMap( cmapOrig ); 283 // gridAttributeOrig.setStyle( GridAttribute.RASTER_CONTOUR ); 284 285 286 // Create a grid for contour data 287 final GridAttribute gridAttribute = new GridAttribute( clevels ); 288 gridAttribute.setColorMap( cmap ); 289 gridAttribute.setStyle( GridAttribute.RASTER ); 290 291 // Create the plot 292 final JPlotLayout jPlotLayout = new JPlotLayout( true, false, false, "JPlotLayout Pane", null, true ); 293 jPlotLayout.setEditClasses( false ); 294 jPlotLayout.addData( simpleGrid, gridAttribute, "First Data" ); 295 jPlotLayout.setTitles( "", "", "" ); 296 jPlotLayout.setSize( new Dimension( plotWidth, plotHeight ) ); 297 298 /* 299 * Resize the key Pane, both the device size and the physical 300 * size. Set the size of the key in physical units and place 301 * the key pane at the "South" of the frame. 302 */ 303 // rpl.setKeyLayerSizeP(new Dimension2D(6.0, 1.02)); 304 // rpl.setKeyBoundsP(new Rectangle2D.Double(0.01, 1.01, 5.98, 1.0)); 305 306 return jPlotLayout; 307 // return mainPane; 308 } 309 310 @NotNull 311 protected String formatTitle( @Nullable final String title ) 312 { 313 if( null == title ) 314 return ""; 315 else 316 { 317 final String formatTitle = title.replaceAll( "\\n", "<br>" ); 318 return "<html>" + formatTitle + "</html>"; 319 } 320 } 321 173 322 private List<SimpleLine> createEmptyLinesList( final List<SimpleLine> allLines, final List<SimpleLine> allLinesForSecondAxis, final List<SimpleLine> lines ) 174 323 { … … 211 360 212 361 return lines; 213 }214 215 @NotNull216 public JPane create2DPlot( @NotNull final MegapoliPlot megapoliPlot, @NotNull final Integer plotWidth, @NotNull final Integer plotHeight, @Nullable final Locale locale )217 {218 final JPane mainPane = new JPane( "2D Pane", new Dimension( plotWidth, plotHeight ) );219 220 final ResourceBundle bundle = WebHelper.getBundle( locale );221 222 final Data realValuesFor2D = BouchonHelper.createRealValuesFor2D();223 // final double[] parameterValues = (double[]) megapoliPlot.getData().getFirstArray();224 // final double[] latitudeValues = (double[]) megapoliPlot.getData().getSecondArray();225 // final double[] longitudeValues = (double[]) megapoliPlot.getData().getThirdArray();226 227 final double[] parameterValues = (double[]) realValuesFor2D.getFirstArray();228 final double[] latitudeValues = (double[]) realValuesFor2D.getSecondArray();229 final double[] longitudeValues = (double[]) realValuesFor2D.getThirdArray();230 231 return mainPane;232 }233 234 @NotNull235 protected String formatTitle( @Nullable final String title )236 {237 if( null == title )238 return "";239 else240 {241 final String formatTitle = title.replaceAll( "\\n", "<br>" );242 return "<html>" + formatTitle + "</html>";243 }244 362 } 245 363 … … 459 577 } 460 578 579 private double[] getValues( double[] axis1, int num1, double[] axis2, int num2, 580 int type, float amp, float off, float per ) 581 { 582 double[] values; 583 int count1, count2, count; 584 values = new double[num1 * num2]; 585 switch( type ) 586 { 587 default: 588 case TestData.RANDOM: 589 for( count = 0; count < num1 * num2; count++ ) 590 { 591 values[count] = amp * Math.random() + off; 592 } 593 break; 594 case TestData.SINE: 595 count = 0; 596 for( count1 = 0; count1 < num1; count1++ ) 597 { 598 for( count2 = 0; count2 < num2; count2++ ) 599 { 600 values[count] = amp * Math.sin( axis1[count1] / per ) * 601 Math.sin( axis2[count2] / per ) + off; 602 count++; 603 } 604 } 605 break; 606 case TestData.SINE_RAMP: 607 count = 0; 608 double ax1factr = 0.08 * Math.abs( axis1[0] - axis1[num1 - 1] ) / 609 Math.max( Math.abs( axis1[0] ), Math.abs( axis1[num1 - 1] ) ); 610 double ax2factr = 0.08 * Math.abs( axis2[0] - axis2[num2 - 1] ) / 611 Math.max( Math.abs( axis2[0] ), Math.abs( axis2[num2 - 1] ) ); 612 for( count1 = 0; count1 < num1; count1++ ) 613 { 614 for( count2 = 0; count2 < num2; count2++ ) 615 { 616 values[count] = amp * Math.sin( axis1[count1] / per ) * 617 Math.sin( axis2[count2] / per ) + off + 618 amp * ( ax1factr * count1 - ax2factr * count2 ); 619 count++; 620 } 621 } 622 } 623 return values; 624 } 625 626 627 @NotNull 628 private ColorMap createColorMap( final Range2D datar ) 629 { 630 final int[] red = 631 {0, 0, 0, 0, 0, 0, 0, 0, 632 0, 0, 0, 0, 0, 0, 0, 0, 633 0, 0, 0, 0, 0, 0, 0, 0, 634 0, 7, 23, 39, 55, 71, 87, 103, 635 119, 135, 151, 167, 183, 199, 215, 231, 636 247, 255, 255, 255, 255, 255, 255, 255, 637 255, 255, 255, 255, 255, 255, 255, 255, 638 255, 246, 228, 211, 193, 175, 158, 140}; 639 final int[] green = 640 {0, 0, 0, 0, 0, 0, 0, 0, 641 0, 11, 27, 43, 59, 75, 91, 107, 642 123, 139, 155, 171, 187, 203, 219, 235, 643 251, 255, 255, 255, 255, 255, 255, 255, 644 255, 255, 255, 255, 255, 255, 255, 255, 645 255, 247, 231, 215, 199, 183, 167, 151, 646 135, 119, 103, 87, 71, 55, 39, 23, 647 7, 0, 0, 0, 0, 0, 0, 0}; 648 final int[] blue = 649 {0, 143, 159, 175, 191, 207, 223, 239, 650 255, 255, 255, 255, 255, 255, 255, 255, 651 255, 255, 255, 255, 255, 255, 255, 255, 652 255, 247, 231, 215, 199, 183, 167, 151, 653 135, 119, 103, 87, 71, 55, 39, 23, 654 7, 0, 0, 0, 0, 0, 0, 0, 655 0, 0, 0, 0, 0, 0, 0, 0, 656 0, 0, 0, 0, 0, 0, 0, 0}; 657 658 final IndexedColorMap cmap = new IndexedColorMap( red, green, blue ); 659 cmap.setTransform( new LinearTransform( 0.0, (double) red.length, datar.start, datar.end ) ); 660 return cmap; 661 } 461 662 462 663 public EtherService getEtherService()
Note: See TracChangeset
for help on using the changeset viewer.