source: ether_megapoli/trunk/service/implementation/com/ether/EtherPlotContentServiceImpl.java @ 191

Last change on this file since 191 was 191, checked in by vmipsl, 13 years ago

Servlet _ Contour en cours

File size: 28.9 KB
Line 
1package com.ether;
2
3import com.medias.database.objects.Parametre;
4import com.medias.database.objects.Plateforme;
5import gov.noaa.pmel.sgt.Axis;
6import gov.noaa.pmel.sgt.CartesianGraph;
7import gov.noaa.pmel.sgt.ColorMap;
8import gov.noaa.pmel.sgt.ContourLevels;
9import gov.noaa.pmel.sgt.Graph;
10import gov.noaa.pmel.sgt.GridAttribute;
11import gov.noaa.pmel.sgt.IndexedColorMap;
12import gov.noaa.pmel.sgt.JPane;
13import gov.noaa.pmel.sgt.Layer;
14import gov.noaa.pmel.sgt.LineAttribute;
15import gov.noaa.pmel.sgt.LineCartesianRenderer;
16import gov.noaa.pmel.sgt.LineKey;
17import gov.noaa.pmel.sgt.LinearTransform;
18import gov.noaa.pmel.sgt.PlainAxis;
19import gov.noaa.pmel.sgt.SGLabel;
20import gov.noaa.pmel.sgt.StackedLayout;
21import gov.noaa.pmel.sgt.TimeAxis;
22import gov.noaa.pmel.sgt.demo.TestData;
23import gov.noaa.pmel.sgt.dm.SGTData;
24import gov.noaa.pmel.sgt.dm.SGTMetaData;
25import gov.noaa.pmel.sgt.dm.SimpleGrid;
26import gov.noaa.pmel.sgt.dm.SimpleLine;
27import gov.noaa.pmel.sgt.swing.JPlotLayout;
28import gov.noaa.pmel.util.Dimension2D;
29import gov.noaa.pmel.util.GeoDateArray;
30import gov.noaa.pmel.util.Point2D;
31import gov.noaa.pmel.util.Range2D;
32import gov.noaa.pmel.util.SoTPoint;
33import gov.noaa.pmel.util.SoTRange;
34import org.jetbrains.annotations.NotNull;
35import org.jetbrains.annotations.Nullable;
36import org.springframework.beans.factory.annotation.Required;
37
38import java.awt.*;
39import java.util.ArrayList;
40import java.util.Collections;
41import java.util.Date;
42import java.util.List;
43import java.util.Locale;
44import java.util.Random;
45import java.util.ResourceBundle;
46
47/**
48 * @author vmipsl
49 * @date 05 sept. 2011
50 */
51public class EtherPlotContentServiceImpl
52{
53    /**
54     * First layer contains axes, labels and the first set of data
55     * Others layers contains only the other sets of data
56     *
57     * @param megapoliPlot
58     * @param locale
59     * @return
60     */
61    @Nullable
62    public JPane createTimeSeriePlot( @NotNull final MegapoliPlot megapoliPlot, @NotNull final Integer plotWidth, @NotNull final Integer plotHeight, final Locale locale )
63            throws ServiceException
64    {
65        final JPane mainPane = new JPane( "Time Serie Pane", new Dimension( plotWidth, plotHeight ) );
66        mainPane.setLayout( new StackedLayout() );
67
68        // TODO : revoir les tailles ! mettre en automatique par rapport à plotWidth et plotHeight
69        /*
70        * xsize, ysize are the width and height in physical units
71        * of the Layer graphics region.
72        *
73        * xstart, xend are the start and end points for the TimeAxis
74        * ystart, yend are the start and end points for the Y axis
75        */
76        final double xsize = 5.0;
77        final double ysize = 3.5;
78        final double xstart = 0.3;
79        final double xend = xsize - xstart;
80        final double ystart = 0.5;
81        final double yend = ysize - ystart;
82
83        final Layer layer = new Layer( "First Layer", new Dimension2D( xsize, ysize ) );
84        mainPane.add( layer );
85
86        final Pair<List, List> listPairOfPIdPIdForTwoAxes = extractListPairForAxes( megapoliPlot.getpIdPIdList() );
87        final List<Pair> pIdPIdListForFirstAxis = listPairOfPIdPIdForTwoAxes.getFirstValue();
88        final List<Pair> pIdPIdListForSecondAxis = listPairOfPIdPIdForTwoAxes.getSecondValue();
89
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 );
92        List<SimpleLine> lines = extractRealLines( allLines );
93        List<SimpleLine> linesForSecondAxis = extractRealLines( allLinesForSecondAxis );
94
95        final List<SimpleLine> emptyLineToDisplayOnlyInLegend = createEmptyLinesList( allLines, allLinesForSecondAxis, lines );
96        if( lines.isEmpty() )
97        {
98            if( linesForSecondAxis.isEmpty() )
99                return null;
100            else
101            {
102                lines = linesForSecondAxis;
103                linesForSecondAxis = new ArrayList<SimpleLine>();
104            }
105        }
106
107        final SimpleLine firstLine = lines.get( 0 );
108
109        /** ********** AXIS RANGES ********* **/
110        final SoTRange xnRange = firstLine.getXRange();
111        final SoTRange yRange = firstLine.getYRange();
112        for( final SimpleLine line : lines )
113        {
114            yRange.add( line.getYRange() );
115            xnRange.add( line.getXRange() );
116        }
117
118        for( final SimpleLine line : linesForSecondAxis )
119            xnRange.add( line.getXRange() );
120
121        final SoTRange ynRange = Graph.computeRange( yRange, _intervalsNumber );
122
123        // Origin point
124        final SoTPoint originPoint = new SoTPoint( ynRange.getStart(), xnRange.getStart() );
125
126
127        /** ************ AXIS ********** **/
128        // Time axis is the same for the two y-axis
129        final TimeAxis xTimeAxis = createXTimeAxis( xnRange, originPoint );
130        final PlainAxis yLeftAxis = createYAxis( firstLine, ynRange, originPoint, null );
131
132        /** ************ GRAPH ********** **/
133        final CartesianGraph graph = new CartesianGraph( "First Graph" );
134        layer.setGraph( graph );
135
136        final LinearTransform xt = new LinearTransform( new Range2D( xstart, xend ), xnRange );
137        graph.setXTransform( xt );
138        final LinearTransform yt = new LinearTransform( new Range2D( ystart, yend ), ynRange );
139        graph.setYTransform( yt );
140
141        graph.addXAxis( xTimeAxis );
142        graph.addYAxis( yLeftAxis );
143
144        final LineAttribute lineAttribute = createRandomLineAttribute( megapoliPlot.getAxeType() );
145        graph.setData( firstLine, lineAttribute );
146
147        /** *********** LEGEND ********* **/
148        final LineKey lkey = createLineKey( megapoliPlot, ysize, layer, firstLine, graph );
149
150        /** *********** OTHER LAYERS ********* **/
151        // First axis
152        addOtherLinesForOneAxis( megapoliPlot.getAxeType(), mainPane, xsize, ysize, lines, xt, yt, lkey, 1 );
153
154        // Second axis
155        if( !linesForSecondAxis.isEmpty() )
156        {
157            final SimpleLine firstLineForSecondAxis = linesForSecondAxis.get( 0 );
158
159            final SoTRange yRangeForSecondAxis = firstLineForSecondAxis.getYRange();
160            for( final SimpleLine line : linesForSecondAxis )
161                yRangeForSecondAxis.add( line.getYRange() );
162
163            final SoTRange ynRangeForSecondAxis = Graph.computeRange( yRangeForSecondAxis, _intervalsNumber );
164            final SoTPoint endPointForSecondAxis = new SoTPoint( ynRangeForSecondAxis.getStart(), xnRange.getEnd() );
165
166            final PlainAxis yRightAxis = createYAxis( firstLineForSecondAxis, ynRangeForSecondAxis, endPointForSecondAxis, Axis.POSITIVE_SIDE );
167
168            final LinearTransform ytForSecondAxis = new LinearTransform( new Range2D( ystart, yend ), ynRangeForSecondAxis );
169
170            // It transforms the graph with the maximum yAxis
171            if( ytForSecondAxis.getRangeU().end > yt.getRangeU().end )
172                graph.setYTransform( ytForSecondAxis );
173            graph.addYAxis( yRightAxis );
174
175            addOtherLinesForOneAxis( megapoliPlot.getAxeType(), mainPane, xsize, ysize, linesForSecondAxis, xt, ytForSecondAxis, lkey, 0 );
176        }
177        displayLegendForEmptyLines( emptyLineToDisplayOnlyInLegend, lkey, mainPane, xsize, ysize, xt, yt, megapoliPlot.getAxeType() );
178
179        return mainPane;
180    }
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
322    private List<SimpleLine> createEmptyLinesList( final List<SimpleLine> allLines, final List<SimpleLine> allLinesForSecondAxis, final List<SimpleLine> lines )
323    {
324        final List<SimpleLine> emptyLinesList = allLines;
325        emptyLinesList.removeAll( lines );
326        emptyLinesList.addAll( allLinesForSecondAxis );
327        emptyLinesList.removeAll( allLinesForSecondAxis );
328
329        return emptyLinesList;
330    }
331
332    private void displayLegendForEmptyLines( @NotNull final List<SimpleLine> lines, @NotNull final LineKey lkey, @NotNull final JPane mainPane, final double xsize, final double ysize, final LinearTransform xt, final LinearTransform yt, final String axeType )
333    {
334        for( final SimpleLine line : lines )
335        {
336            final Layer otherLayer = new Layer( "Other Layer", new Dimension2D( xsize, ysize ) );
337            mainPane.add( otherLayer );
338            final CartesianGraph otherGraph = new CartesianGraph( "Other Graph", xt, yt );
339            otherLayer.setGraph( otherGraph );
340
341            final LineAttribute otherLineAttribute = createRandomLineAttribute( axeType );
342            otherGraph.setData( line, otherLineAttribute );
343            lkey.addLineGraph( (LineCartesianRenderer) otherGraph.getRenderer(), line.getKeyTitle() );
344        }
345    }
346
347    /**
348     * This method removes from a list the lines with no data
349     *
350     * @param allLines
351     * @return
352     */
353    @NotNull
354    private List<SimpleLine> extractRealLines( @NotNull final List<SimpleLine> allLines )
355    {
356        final List<SimpleLine> lines = new ArrayList<SimpleLine>();
357        for( final SimpleLine line : allLines )
358            if( 0 < line.getYArray().length )
359                lines.add( line );
360
361        return lines;
362    }
363
364    /**
365     * This method creates a legend
366     *
367     * @param megapoliPlot
368     * @param ysize
369     * @param layer
370     * @param firstLine
371     * @param graph
372     * @return
373     */
374    @NotNull
375    private LineKey createLineKey( final MegapoliPlot megapoliPlot, final double ysize, final Layer layer, final SimpleLine firstLine, final CartesianGraph graph )
376    {
377        final LineKey lkey = new LineKey();
378        if( !megapoliPlot.isLegendToHide() )
379        {
380            lkey.setId( "Legend" );
381            lkey.setLocationP( new Point2D.Double( 0.1, ysize - 0.1 ) );
382            lkey.setBorderStyle( LineKey.NO_BORDER );
383            lkey.setVAlign( LineKey.TOP );
384            lkey.setHAlign( LineKey.LEFT );
385            layer.addChild( lkey );
386            lkey.addLineGraph( (LineCartesianRenderer) graph.getRenderer(), firstLine.getKeyTitle() );
387        }
388        return lkey;
389    }
390
391    /**
392     * This method creates a x-axis for time serie
393     *
394     * @param xnRange
395     * @param originPoint
396     * @return
397     */
398    @NotNull
399    private TimeAxis createXTimeAxis( final SoTRange xnRange, final SoTPoint originPoint )
400    {
401        final TimeAxis xbot = new TimeAxis( "X-Axis", TimeAxis.AUTO );
402        xbot.setRangeU( xnRange );
403        xbot.setLocationU( originPoint );
404        xbot.setLabelFont( _axisFont );
405        xbot.setLabelHeightP( _heightAxisFont );
406        xbot.setMajorLabelFormat( _majorLabelFormat );
407        return xbot;
408    }
409
410    /**
411     * This method adds layers corresponding to the other lines to display
412     *
413     * @param axeType
414     * @param mainPane
415     * @param xsize
416     * @param ysize
417     * @param lines
418     * @param xt
419     * @param yt
420     * @param lkey
421     * @param indexLineToBegin
422     */
423    private void addOtherLinesForOneAxis( @NotNull final String axeType, @NotNull final JPane mainPane, final double xsize, final double ysize, @NotNull final List<SimpleLine> lines, @NotNull final LinearTransform xt, @NotNull final LinearTransform yt, @NotNull final LineKey lkey, @NotNull final Integer indexLineToBegin )
424    {
425        for( final SimpleLine line : lines.subList( indexLineToBegin, lines.size() ) )
426        {
427            final Layer otherLayer = new Layer( "Other Layer", new Dimension2D( xsize, ysize ) );
428            mainPane.add( otherLayer );
429            final CartesianGraph otherGraph = new CartesianGraph( "Other Graph", xt, yt );
430            otherLayer.setGraph( otherGraph );
431
432            final LineAttribute otherLineAttribute = createRandomLineAttribute( axeType );
433            otherGraph.setData( line, otherLineAttribute );
434            lkey.addLineGraph( (LineCartesianRenderer) otherGraph.getRenderer(), line.getKeyTitle() );
435        }
436    }
437
438    /**
439     * This method creates a vertical axis, set its range in user units and its origin and creates the axis title
440     *
441     * @param line
442     * @param ynRange
443     * @param originPoint
444     * @param labelPosition
445     * @return
446     */
447    @NotNull
448    private PlainAxis createYAxis( final SimpleLine line, final SoTRange ynRange, final SoTPoint originPoint, @Nullable final Integer labelPosition )
449    {
450        final PlainAxis yAxis = new PlainAxis( "Y-Axis" );
451        yAxis.setRangeU( ynRange );
452        yAxis.setLocationU( originPoint );
453        yAxis.setLabelFont( _axisFont );
454        if( null != labelPosition )
455            yAxis.setLabelPosition( labelPosition );
456
457        final String yLabel = line.getYMetaData().getName() + " (" + line.getYMetaData().getUnits() + ")";
458        final SGLabel ytitle = new SGLabel( "Y-Axis Title", yLabel, new Point2D.Double( 0.0, 0.0 ) );
459        ytitle.setFont( _axisFont );
460        ytitle.setHeightP( _heightAxisFont );
461        yAxis.setTitle( ytitle );
462        return yAxis;
463    }
464
465    /**
466     * This method returns a new LineAttribute with a random color
467     *
468     * @param axeType
469     * @return
470     */
471    @NotNull
472    private LineAttribute createRandomLineAttribute( @NotNull final String axeType )
473    {
474        final LineAttribute attr;
475        final Color color = new Color( new Random().nextInt( 256 ), new Random().nextInt( 256 ), new Random().nextInt( 256 ) );
476
477        if( axeType.equals( AxeTypeForFixedPlateform.TIME_POINTS.toString() ) )
478            attr = new LineAttribute( LineAttribute.MARK, 1, color );
479        else
480            attr = new LineAttribute( LineAttribute.SOLID, 1, color );
481
482        attr.setMarkHeightP( _markHeight );
483
484        return attr;
485    }
486
487    /**
488     * This method extracts from a list of <plateformId, parameterId> two lists of <plateformId, parameterId> corresponding for the 2 axes needed for the graph
489     * The second list can be empty, in this case, only one axis is needed
490     *
491     * @param pIdPIdList
492     * @return
493     */
494    @NotNull
495    private Pair<List, List> extractListPairForAxes( @NotNull final List<Pair> pIdPIdList )
496    {
497        final List<Pair<Integer, Integer>> pIdPIdListForFirstAxis = new ArrayList<Pair<Integer, Integer>>();
498        final List<Pair<Integer, Integer>> pIdPIdListForSecondAxis = new ArrayList<Pair<Integer, Integer>>();
499
500        for( final Pair pIdPId : pIdPIdList )
501        {
502            final List<Integer> secondValuesForFirstAxis = EtherHelper.getSecondValues( pIdPIdListForFirstAxis );
503            final Integer parameterId = (Integer) pIdPId.getSecondValue();
504
505            if( pIdPIdListForFirstAxis.isEmpty() || secondValuesForFirstAxis.contains( parameterId ) )
506                pIdPIdListForFirstAxis.add( pIdPId );
507            else
508                pIdPIdListForSecondAxis.add( pIdPId );
509        }
510
511        return new Pair( pIdPIdListForFirstAxis, pIdPIdListForSecondAxis );
512    }
513
514    /**
515     * This method extracts data from BD for the plateform and parameter given as parameters
516     * and creates the corresponded simpleLine
517     * Some lines can be empty if there's no data in this period by example
518     *
519     * @param pIdPIdList
520     * @param beginDate
521     * @param endDate
522     * @param locale
523     * @return
524     * @throws ServiceException
525     */
526    @NotNull
527    private List<SimpleLine> createLines( @NotNull final List<Pair> pIdPIdList, @Nullable final Date beginDate, @Nullable final Date endDate, final Integer delta, final Locale locale )
528            throws ServiceException
529    {
530        final ResourceBundle bundle = WebHelper.getBundle( locale );
531        final String messageData = bundle.getString( "plot.noData" );
532
533        final List<SimpleLine> lines = new ArrayList<SimpleLine>( pIdPIdList.size() );
534        boolean isFirstLine = true;
535
536        for( final Pair<Integer, Integer> pIdPId : pIdPIdList )
537        {
538            final Integer plateformId = pIdPId.getFirstValue();
539            final Integer parameterId = pIdPId.getSecondValue();
540
541//            final Plateforme plateform = _etherService.getPlateformById( plateformId );
542            final Plateforme plateform = BouchonHelper.getPlateformById( plateformId );
543            if( null == plateform )
544                throw new ServiceException( ServiceException.ServiceCode.PLATEFORM_IS_NULL, new Throwable( ServiceException.ServiceCode.PLATEFORM_IS_NULL.toString() ) );
545
546//            final Parametre parametre = _etherService.getParameterById( parameterId );
547            final Parametre parametre = BouchonHelper.getParameterById( parameterId );
548            if( null == parametre )
549                throw new ServiceException( ServiceException.ServiceCode.PARAMETER_IS_NULL, new Throwable( ServiceException.ServiceCode.PARAMETER_IS_NULL.toString() ) );
550
551//            final Data valuesLists = _etherService.getListsByPlateformByParameterByPeriodForTimeSerie( plateformId, parameterId, beginDate, endDate );
552            final Data valuesLists = BouchonHelper.createValuesForTimeSerie( 50, delta );
553
554            final double[] dataArray = (double[]) valuesLists.getFirstArray();
555            final Date[] dateValues = (Date[]) valuesLists.getSecondArray();
556
557            final SimpleLine line = new SimpleLine( new GeoDateArray( dateValues ), dataArray, "legend" );
558            SGTMetaData meta = new SGTMetaData( "", "", false, false );
559            line.setXMetaData( meta );
560            final SGLabel sgLabel;
561            if( 0 < dataArray.length && 0 < dateValues.length )
562                sgLabel = new SGLabel( "Line", plateform.getPlateformeNom() + "-" + parametre.getParametreNom(), new Point2D.Double( 0.0, 0.0 ) );
563            else
564                sgLabel = new SGLabel( "Line", plateform.getPlateformeNom() + "-" + parametre.getParametreNom() + " " + messageData, new Point2D.Double( 0.0, 0.0 ) );
565            line.setKeyTitle( sgLabel );
566
567            if( isFirstLine )
568                meta = new SGTMetaData( parametre.getParametreNom(), parametre.getUnite().getUniteCode(), false, false );
569            else
570                meta = new SGTMetaData( "", "", false, false );
571            line.setYMetaData( meta );
572
573            lines.add( line );
574            isFirstLine = false;
575        }
576        return lines;
577    }
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    }
662
663    public EtherService getEtherService()
664    {
665        return _etherService;
666    }
667
668    @Required
669    public void setEtherService( final EtherService etherService )
670    {
671        _etherService = etherService;
672    }
673
674    // Dimensions of the jPanes
675    protected static final int MAX_WIDTH = 800;
676    protected static final int MAX_HEIGHT = 700;
677    protected static final int MARGIN_LEFT_RIGHT = 50;
678
679    protected static final int TITLE_FONT_SIZE = 20;
680    protected static final int FONT_SIZE = 12;
681    protected static final int ERROR_FONT_SIZE = 10;
682
683    protected static final Font _axisFont = new Font( "Helvetica", Font.PLAIN, 15 );
684    protected static final double _heightAxisFont = 0.14;
685    protected static final double _markHeight = 0.1;
686    protected static final String _majorLabelFormat = "yyyy-MM-dd HH:mm";
687    // Number of intervals on a Y-Axis
688    protected Integer _intervalsNumber = 10;
689
690    private EtherService _etherService;
691}
Note: See TracBrowser for help on using the repository browser.