Changeset 187


Ignore:
Timestamp:
09/08/11 19:13:44 (13 years ago)
Author:
vmipsl
Message:

Servlet _ TimeSerie? :

  • 1 paramètre ok
  • même paramètre sur différentes plateformes ok
Location:
ether_megapoli/trunk/service/implementation/com/ether
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ether_megapoli/trunk/service/implementation/com/ether/BouchonHelper.java

    r186 r187  
    259259        for( int i = 0; i < size; i++ ) 
    260260        { 
    261             values[i] = (double) i * Math.random(); 
     261            values[i] = (double) i * Math.random() * delta; 
    262262            cal.set( Calendar.MINUTE, (int) ( 2 + i + ( Math.random() * 8 ) ) ); 
    263263            dates[i] = cal.getTime(); 
  • ether_megapoli/trunk/service/implementation/com/ether/EtherPlotContentServiceImpl.java

    r186 r187  
    8585        final List<Pair> pIdPIdListForSecondAxis = listPairOfPIdPIdForTwoAxes.getSecondValue(); 
    8686 
    87  
    88         /** *********** FIRST Y-AXIS ************ **/ 
    89         final List<SimpleLine> lines = createLines( pIdPIdListForFirstAxis, megapoliPlot.getBeginDate(), megapoliPlot.getEndDate() ); 
     87        final List<SimpleLine> lines = createLines( pIdPIdListForFirstAxis, megapoliPlot.getBeginDate(), megapoliPlot.getEndDate(), 1 ); 
     88        final List<SimpleLine> linesForSecondAxis = createLines( pIdPIdListForSecondAxis, megapoliPlot.getBeginDate(), megapoliPlot.getEndDate(), 10 ); 
    9089        final SimpleLine firstLine = lines.get( 0 ); 
    9190 
     91        /** *********** RANGES ************ **/ 
    9292        final SoTRange xnRange = firstLine.getXRange(); 
    9393        final SoTRange yRange = firstLine.getYRange(); 
    9494        for( final SimpleLine line : lines ) 
     95        { 
    9596            yRange.add( line.getYRange() ); 
     97            xnRange.add( line.getXRange() ); 
     98        } 
     99 
     100        for( final SimpleLine line : linesForSecondAxis ) 
     101            xnRange.add( line.getXRange() ); 
    96102 
    97103        // TODO : automatiser le nb d'intervalles en fonction des valeurs de y 
    98         final Integer intervalsNumber = 10; 
    99         final SoTRange ynRange = Graph.computeRange( yRange, intervalsNumber ); 
     104        final SoTRange ynRange = Graph.computeRange( yRange, _intervalsNumber ); 
    100105 
    101106        // Origin point 
    102107        final SoTPoint originPoint = new SoTPoint( ynRange.getStart(), xnRange.getStart() ); 
    103108 
    104         // Create the time axis, set its range in user units and its origin. 
     109 
     110        /** ************ X-AXIS ********** **/ 
    105111        // Time axis is the same for the two y-axis 
    106112        final TimeAxis xbot = new TimeAxis( "X-Axis", TimeAxis.AUTO ); 
     
    108114        xbot.setLocationU( originPoint ); 
    109115        xbot.setLabelFont( _axisFont ); 
    110 //        xbot.setMinorLabelInterval( 1 ); 
     116        xbot.setLabelHeightP( _heightAxisFont ); 
     117        xbot.setMajorLabelFormat( "yyyy-MM-dd HH:mm:ss" ); 
    111118 
    112119        // Create the vertical axis, set its range in user units and its origin. Create the axis title. 
    113         final PlainAxis yleft = new PlainAxis( "Y-Axis" ); 
    114         yleft.setRangeU( ynRange ); 
    115         yleft.setLocationU( originPoint ); 
    116         yleft.setLabelFont( _axisFont ); 
    117         final String yLabel = firstLine.getYMetaData().getName() + " (" + firstLine.getYMetaData().getUnits() + ")"; 
    118         final SGLabel ytitle = new SGLabel( "Y-Axis Title", yLabel, new Point2D.Double( 0.0, 0.0 ) ); 
    119         ytitle.setFont( _axisFont ); 
    120         ytitle.setHeightP( _heightAxisFont ); 
    121         yleft.setTitle( ytitle ); 
     120        final PlainAxis yleft = createYAxis( firstLine, ynRange, originPoint, null ); 
    122121 
    123122        /** ************ GRAPH ********** **/ 
     
    133132 
    134133        SimpleLine firstLineForSecondAxis = null; 
    135         List<SimpleLine> linesForSecondAxis = new ArrayList<SimpleLine>(); 
     134 
    136135        LinearTransform ytForSecondAxis = null; 
    137136        if( !pIdPIdListForSecondAxis.isEmpty() ) 
    138137        { 
    139             linesForSecondAxis = createLines( pIdPIdListForSecondAxis, megapoliPlot.getBeginDate(), megapoliPlot.getEndDate() ); 
    140138            firstLineForSecondAxis = linesForSecondAxis.get( 0 ); 
    141139 
     
    144142                yRangeForSecondAxis.add( line.getYRange() ); 
    145143 
    146             final SoTRange ynRangeForSecondAxis = Graph.computeRange( yRangeForSecondAxis, intervalsNumber ); 
     144            final SoTRange ynRangeForSecondAxis = Graph.computeRange( yRangeForSecondAxis, _intervalsNumber ); 
    147145            final SoTPoint endPointForSecondAxis = new SoTPoint( ynRangeForSecondAxis.getStart(), xnRange.getEnd() ); 
    148146 
    149             final PlainAxis yleftForSecondAxis = new PlainAxis( "YY-Axis" ); 
    150             yleftForSecondAxis.setRangeU( yRangeForSecondAxis ); 
    151             yleftForSecondAxis.setLocationU( endPointForSecondAxis ); 
    152             yleftForSecondAxis.setLabelFont( _axisFont ); 
    153             yleftForSecondAxis.setLabelPosition( Axis.POSITIVE_SIDE ); 
    154             final String yLabelForSecondAxis = firstLineForSecondAxis.getYMetaData().getName() + " (" + firstLineForSecondAxis.getYMetaData().getUnits() + ")"; 
    155             final SGLabel ytitleForSecondAxis = new SGLabel( "Y-Axis Title", yLabelForSecondAxis, new Point2D.Double( 0.0, 0.0 ) ); 
    156             ytitleForSecondAxis.setFont( _axisFont ); 
    157             ytitleForSecondAxis.setHeightP( _heightAxisFont ); 
    158             yleftForSecondAxis.setTitle( ytitleForSecondAxis ); 
     147            final PlainAxis yleftForSecondAxis = createYAxis( firstLineForSecondAxis, ynRangeForSecondAxis, endPointForSecondAxis, Axis.POSITIVE_SIDE ); 
    159148 
    160149            ytForSecondAxis = new LinearTransform( new Range2D( ystart, yend ), ynRangeForSecondAxis ); 
    161             graph.setYTransform( ytForSecondAxis ); 
     150            if( ytForSecondAxis.getRangeU().end > yt.getRangeU().end ) 
     151                graph.setYTransform( ytForSecondAxis ); 
    162152            graph.addYAxis( yleftForSecondAxis ); 
    163153        } 
     
    167157        final LineAttribute lineAttribute = createRandomLineAttrbute( megapoliPlot.getAxeType() ); 
    168158        graph.setData( firstLine, lineAttribute ); 
    169  
    170 //        if( !pIdPIdListForSecondAxis.isEmpty() ) 
    171 //        { 
    172 //            final LineAttribute attrForSecondAxis = createRandomLineAttrbute( megapoliPlot.getAxeType() ); 
    173 //            graph.setData( firstLineForSecondAxis, attrForSecondAxis ); 
    174 //        } 
    175159 
    176160        /** *********** LEGEND ********* **/ 
     
    185169        } 
    186170 
    187         /** ********************************** **/ 
    188171        /** *********** OTHER LAYERS ********* **/ 
    189         /** ********************************** **/ 
    190         for( final SimpleLine line : lines.subList( 1, lines.size() ) ) 
     172        addOtherLinesForOneAxis( megapoliPlot.getAxeType(), mainPane, xsize, ysize, lines, xt, yt, lkey, 1 ); 
     173 
     174        if( !pIdPIdListForSecondAxis.isEmpty() ) 
     175            addOtherLinesForOneAxis( megapoliPlot.getAxeType(), mainPane, xsize, ysize, linesForSecondAxis, xt, ytForSecondAxis, lkey, 0 ); 
     176 
     177        return mainPane; 
     178    } 
     179 
     180    /** 
     181     * This method adds layers corresponding to the other lines to display 
     182     * 
     183     * @param axeType 
     184     * @param mainPane 
     185     * @param xsize 
     186     * @param ysize 
     187     * @param lines 
     188     * @param xt 
     189     * @param yt 
     190     * @param lkey 
     191     * @param indexLineToBegin 
     192     */ 
     193    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 ) 
     194    { 
     195        for( final SimpleLine line : lines.subList( indexLineToBegin, lines.size() ) ) 
    191196        { 
    192197            final Layer otherLayer = new Layer( "Other Layer", new Dimension2D( xsize, ysize ) ); 
    193198            mainPane.add( otherLayer ); 
    194             final CartesianGraph otherGraph = new CartesianGraph( "Second Graph", xt, yt ); 
     199            final CartesianGraph otherGraph = new CartesianGraph( "Other Graph", xt, yt ); 
    195200            otherLayer.setGraph( otherGraph ); 
    196201 
    197             final LineAttribute otherLineAttribute = createRandomLineAttrbute( megapoliPlot.getAxeType() ); 
     202            final LineAttribute otherLineAttribute = createRandomLineAttrbute( axeType ); 
    198203            otherGraph.setData( line, otherLineAttribute ); 
    199204            lkey.addLineGraph( (LineCartesianRenderer) otherGraph.getRenderer(), line.getKeyTitle() ); 
    200205        } 
    201  
    202         /** *********** SECOND Y-AXIS (optional) ************ **/ 
    203         if( !pIdPIdListForSecondAxis.isEmpty() ) 
    204         { 
    205 //            final Layer layerForSecondAxis = new Layer( "First Layer", new Dimension2D( xsize, ysize ) ); 
    206 //            mainPane.add( layerForSecondAxis ); 
    207 // 
    208 //            final List<SimpleLine> linesForSecondAxis = createLines( pIdPIdListForSecondAxis, megapoliPlot.getBeginDate(), megapoliPlot.getEndDate() ); 
    209 //            final SimpleLine firstLineForSecondAxis = linesForSecondAxis.get( 0 ); 
    210  
    211 //            final SoTRange yRangeForSecondAxis = firstLineForSecondAxis.getYRange(); 
    212 //            for( final SimpleLine line : linesForSecondAxis ) 
    213 //                yRangeForSecondAxis.add( line.getYRange() ); 
    214 // 
    215 //            final SoTRange ynRangeForSecondAxis = Graph.computeRange( yRangeForSecondAxis, intervalsNumber ); 
    216 //            final SoTPoint endPointForSecondAxis = new SoTPoint( ynRangeForSecondAxis.getStart(), xnRange.getEnd() ); 
    217 // 
    218 //            final PlainAxis yleftForSecondAxis = new PlainAxis( "YY-Axis" ); 
    219 //            yleftForSecondAxis.setRangeU( yRangeForSecondAxis ); 
    220 //            yleftForSecondAxis.setLocationU( endPointForSecondAxis ); 
    221 //            yleftForSecondAxis.setLabelFont( _axisFont ); 
    222 //            yleftForSecondAxis.setLabelPosition( Axis.POSITIVE_SIDE ); 
    223 //            final String yLabelForSecondAxis = firstLineForSecondAxis.getYMetaData().getName() + " (" + firstLineForSecondAxis.getYMetaData().getUnits() + ")"; 
    224 //            final SGLabel ytitleForSecondAxis = new SGLabel( "Y-Axis Title", yLabelForSecondAxis, new Point2D.Double( 0.0, 0.0 ) ); 
    225 //            ytitleForSecondAxis.setFont( _axisFont ); 
    226 //            ytitleForSecondAxis.setHeightP( _heightAxisFont ); 
    227 //            yleftForSecondAxis.setTitle( ytitleForSecondAxis ); 
    228  
    229             /** ************ GRAPH ********** **/ 
    230 //            final CartesianGraph graphForSecondAxis = new CartesianGraph( "First Graph" ); 
    231 //            final LinearTransform ytForSecondAxis = new LinearTransform( new Range2D( ystart, yend ), ynRangeForSecondAxis ); 
    232 //            graphForSecondAxis.setYTransform( ytForSecondAxis ); 
    233 //            graphForSecondAxis.addYAxis( yleftForSecondAxis ); 
    234 //            layerForSecondAxis.setGraph( graphForSecondAxis ); 
    235  
    236  
    237             for( final SimpleLine line : linesForSecondAxis.subList( 0, linesForSecondAxis.size() ) ) 
    238             { 
    239                 final Layer otherLayerForSecondAxis = new Layer( "Other Layer 2", new Dimension2D( xsize, ysize ) ); 
    240                 mainPane.add( otherLayerForSecondAxis ); 
    241                 final CartesianGraph otherGraphForSecondAxis = new CartesianGraph( "Second Graph 2", xt, ytForSecondAxis ); 
    242                 otherLayerForSecondAxis.setGraph( otherGraphForSecondAxis ); 
    243  
    244                 final LineAttribute otherLineAttribute = createRandomLineAttrbute( megapoliPlot.getAxeType() ); 
    245                 otherGraphForSecondAxis.setData( line, otherLineAttribute ); 
    246                 lkey.addLineGraph( (LineCartesianRenderer) otherGraphForSecondAxis.getRenderer(), line.getKeyTitle() ); 
    247             } 
    248         } 
    249  
    250         return mainPane; 
    251     } 
     206    } 
     207 
     208    @NotNull 
     209    private PlainAxis createYAxis( final SimpleLine line, final SoTRange ynRange, final SoTPoint originPoint, @Nullable final Integer labelPosition ) 
     210    { 
     211        final PlainAxis yleft = new PlainAxis( "Y-Axis" ); 
     212        yleft.setRangeU( ynRange ); 
     213        yleft.setLocationU( originPoint ); 
     214        yleft.setLabelFont( _axisFont ); 
     215        if( null != labelPosition ) 
     216            yleft.setLabelPosition( labelPosition ); 
     217 
     218        final String yLabel = line.getYMetaData().getName() + " (" + line.getYMetaData().getUnits() + ")"; 
     219        final SGLabel ytitle = new SGLabel( "Y-Axis Title", yLabel, new Point2D.Double( 0.0, 0.0 ) ); 
     220        ytitle.setFont( _axisFont ); 
     221        ytitle.setHeightP( _heightAxisFont ); 
     222        yleft.setTitle( ytitle ); 
     223        return yleft; 
     224    } 
     225 
    252226 
    253227    /** 
     
    311285     */ 
    312286    @NotNull 
    313     private List<SimpleLine> createLines( @NotNull final List<Pair> pIdPIdList, @Nullable final Date beginDate, @Nullable final Date endDate ) 
     287    private List<SimpleLine> createLines( @NotNull final List<Pair> pIdPIdList, @Nullable final Date beginDate, @Nullable final Date endDate, final Integer delta ) 
    314288            throws ServiceException 
    315289    { 
     
    333307 
    334308//            final Data valuesLists = _etherService.getListsByPlateformByParameterByPeriodForTimeSerie( plateformId, parameterId, beginDate, endDate ); 
    335             final Data valuesLists = BouchonHelper.createValuesForTimeSerie( 50, 5 ); 
     309            final Data valuesLists = BouchonHelper.createValuesForTimeSerie( 50, delta ); 
    336310 
    337311            final double[] dataArray = (double[]) valuesLists.getFirstArray(); 
     
    889863    protected static final int ERROR_FONT_SIZE = 10; 
    890864 
    891     protected static final Font _axisFont = new Font( "Helvetica", Font.PLAIN, 12 ); 
    892     protected static final double _heightAxisFont = 0.2; 
     865    protected static final Font _axisFont = new Font( "Helvetica", Font.PLAIN, 6 ); 
     866    protected static final double _heightAxisFont = 0.14; 
    893867    protected static final double _markHeight = 0.1; 
     868    // Number of intervals on a Y-Axis 
     869    protected Integer _intervalsNumber = 10; 
    894870 
    895871    private EtherService _etherService; 
Note: See TracChangeset for help on using the changeset viewer.