← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3386: WIP: support for target lines in charts

 

------------------------------------------------------------
revno: 3386
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-04-14 15:06:10 +0200
message:
  WIP: support for target lines in charts
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/Chart.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/chart/hibernate/Chart.hbm.xml
  dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/chart/action/SaveChartAction.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addChartForm.vm


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/Chart.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/Chart.java	2011-04-08 10:48:03 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/Chart.java	2011-04-14 13:06:10 +0000
@@ -77,6 +77,10 @@
     private Boolean horizontalPlotOrientation;
     
     private Boolean regression;
+    
+    private Boolean targetLine;
+
+    private Double targetLineValue;
 
     private List<Indicator> indicators = new ArrayList<Indicator>();
 
@@ -204,6 +208,11 @@
     {
         return regression != null && regression;
     }
+
+    public boolean isTargetLine()
+    {
+        return targetLine != null && targetLine;
+    }
     
     public int getWidth()
     {
@@ -327,6 +336,26 @@
     {
         this.regression = regression;
     }
+
+    public void setTargetLine( Boolean targetLine )
+    {
+        this.targetLine = targetLine;
+    }
+
+    public Boolean getTargetLine()
+    {
+        return targetLine;
+    }
+
+    public void setTargetLineValue( Double targetLineValue )
+    {
+        this.targetLineValue = targetLineValue;
+    }
+    
+    public Double getTargetLineValue()
+    {
+        return targetLineValue;
+    }
     
     public List<Indicator> getIndicators()
     {

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java	2011-04-10 10:59:28 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java	2011-04-14 13:06:10 +0000
@@ -414,12 +414,25 @@
     }
 
     /**
+     * Returns a line and shape renderer (for target lines).
+     */
+    private LineAndShapeRenderer getTargetLineRenderer()
+    {
+        LineAndShapeRenderer renderer = new LineAndShapeRenderer();
+        renderer.setBaseShapesVisible( false );
+        renderer.setBasePaint( Color.BLUE );
+
+        return renderer;
+    }
+
+    /**
      * Returns a JFreeChart of type defined in the chart argument.
      */
     private JFreeChart getJFreeChart( Chart chart, boolean subTitle )
     {
         final BarRenderer barRenderer = getBarRenderer();
         final LineAndShapeRenderer lineRenderer = getLineRenderer();
+        final LineAndShapeRenderer targetLineRenderer = getTargetLineRenderer();
 
         // ---------------------------------------------------------------------
         // Plot
@@ -489,6 +502,12 @@
             plot.setRenderer( 1, lineRenderer );
         }
 
+        if ( chart.isTargetLine() )
+        {
+            plot.setDataset( 2, dataSets[2] );
+            plot.setRenderer( 2, targetLineRenderer );
+        }
+
         JFreeChart jFreeChart = new JFreeChart( chart.getTitle(), titleFont, plot, !chart.isHideLegend() );
 
         if ( subTitle )
@@ -532,6 +551,7 @@
 
         final DefaultCategoryDataset regularDataSet = new DefaultCategoryDataset();
         final DefaultCategoryDataset regressionDataSet = new DefaultCategoryDataset();
+        final DefaultCategoryDataset targetDataSet = new DefaultCategoryDataset();
 
         if ( chart != null )
         {
@@ -599,6 +619,15 @@
                             }
                         }
                     }
+
+                    if ( chart.isTargetLine() )
+                    {
+                        for ( Period period : chart.getAllPeriods() )
+                        {
+                            targetDataSet.addValue( chart.getTargetLineValue(), indicator.getShortName(), chart
+                                .getFormat().formatPeriod( period ) );
+                        }
+                    }
                 }
                 else if ( chart.isDimension( DIMENSION_ORGANISATIONUNIT ) )
                 {
@@ -625,7 +654,7 @@
             }
         }
 
-        return new CategoryDataset[] { regularDataSet, regressionDataSet };
+        return new CategoryDataset[] { regularDataSet, regressionDataSet, targetDataSet };
     }
 
     /**

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/chart/hibernate/Chart.hbm.xml'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/chart/hibernate/Chart.hbm.xml	2011-04-12 13:30:10 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/chart/hibernate/Chart.hbm.xml	2011-04-14 13:06:10 +0000
@@ -26,6 +26,10 @@
 
     <property name="regression" />
 
+    <property name="targetLine" />
+
+    <property name="targetLineValue" />
+
     <list name="indicators" table="chart_indicators">
       <key column="chartid" />
       <list-index column="sort_order" base="0" />

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/chart/action/SaveChartAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/chart/action/SaveChartAction.java	2011-01-13 15:44:09 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/chart/action/SaveChartAction.java	2011-04-14 13:06:10 +0000
@@ -77,14 +77,14 @@
     {
         this.periodService = periodService;
     }
-    
+
     private OrganisationUnitService organisationUnitService;
 
     public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
     {
         this.organisationUnitService = organisationUnitService;
     }
-    
+
     // -------------------------------------------------------------------------
     // Input
     // -------------------------------------------------------------------------
@@ -95,7 +95,7 @@
     {
         this.id = id;
     }
-    
+
     private String title;
 
     public void setTitle( String title )
@@ -109,7 +109,7 @@
     {
         this.type = type;
     }
-    
+
     private String size;
 
     public void setSize( String size )
@@ -123,21 +123,21 @@
     {
         this.dimension = dimension;
     }
-    
+
     private boolean hideLegend;
 
     public void setHideLegend( boolean hideLegend )
     {
         this.hideLegend = hideLegend;
     }
-    
+
     private boolean verticalLabels;
 
     public void setVerticalLabels( boolean verticalLabels )
     {
         this.verticalLabels = verticalLabels;
     }
-    
+
     private boolean horizontalPlotOrientation;
 
     public void setHorizontalPlotOrientation( boolean horizontalPlotOrientation )
@@ -151,9 +151,23 @@
     {
         this.regression = regression;
     }
-    
+
+    private boolean targetLine;
+
+    public void setTargetLine( boolean targetLine )
+    {
+        this.targetLine = targetLine;
+    }
+
+    private Double targetLineValue;
+
+    public void setTargetLineValue( Double targetLineValue )
+    {
+        this.targetLineValue = targetLineValue;
+    }
+
     private boolean userOrganisationUnit;
-    
+
     public void setUserOrganisationUnit( boolean userOrganisationUnit )
     {
         this.userOrganisationUnit = userOrganisationUnit;
@@ -223,7 +237,7 @@
     }
 
     private boolean lastYear;
-    
+
     public void setLastYear( boolean lastYear )
     {
         this.lastYear = lastYear;
@@ -240,19 +254,19 @@
         List<Indicator> indicators = new ArrayList<Indicator>();
         List<OrganisationUnit> organisationUnits = new ArrayList<OrganisationUnit>();
         List<Period> periods = new ArrayList<Period>( periodService.getPeriodsByExternalIds( selectedPeriods ) );
-     
+
         for ( Integer id : getIntegerCollection( selectedIndicators ) )
         {
             indicators.add( indicatorService.getIndicator( id ) );
         }
-        
+
         for ( Integer id : getIntegerCollection( selectedOrganisationUnits ) )
         {
             organisationUnits.add( organisationUnitService.getOrganisationUnit( id ) );
         }
-        
+
         Collections.sort( periods, new AscendingPeriodComparator() );
-        
+
         chart.setTitle( title );
         chart.setType( type );
         chart.setSize( size );
@@ -261,17 +275,20 @@
         chart.setVerticalLabels( verticalLabels );
         chart.setHorizontalPlotOrientation( horizontalPlotOrientation );
         chart.setRegression( regression );
+        chart.setTargetLine( targetLine );
+        chart.setTargetLineValue( targetLineValue );
         chart.setUserOrganisationUnit( userOrganisationUnit );
         chart.setIndicators( indicators );
         chart.setPeriods( periods );
         chart.setOrganisationUnits( organisationUnits );
 
-        RelativePeriods relatives = new RelativePeriods( reportingMonth, monthsThisYear, quartersThisYear, thisYear, monthsLastYear, quartersLastYear, lastYear );
-        
+        RelativePeriods relatives = new RelativePeriods( reportingMonth, monthsThisYear, quartersThisYear, thisYear,
+            monthsLastYear, quartersLastYear, lastYear );
+
         chart.setRelatives( relatives );
-        
+
         chartService.saveChart( chart );
-        
+
         return SUCCESS;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties	2011-04-08 10:48:03 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties	2011-04-14 13:06:10 +0000
@@ -199,6 +199,8 @@
 data= Data
 include_regression_line= Include regression line
 include_regression= Include regression
+include_target_line= Include target line
+target_line_value= Target line value
 select = Select
 criteria = Criteria
 this_indicator_and_periods = This indicator and periods

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addChartForm.vm'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addChartForm.vm	2011-04-08 10:48:03 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addChartForm.vm	2011-04-14 13:06:10 +0000
@@ -1,4 +1,15 @@
 <script type="text/javascript">
+	jQuery(document).ready(function() {
+		if( jQuery("#targetLine").attr("checked") !== true )
+		{
+			jQuery("#targetLineValueTr").hide();
+		}
+	
+		jQuery("#targetLine").change(function() {
+			jQuery("#targetLineValueTr").toggle();		
+		});
+	});
+
     var i18n_must_select_at_least_one_indicator = '$encoder.jsEscape( $i18n.getString( "must_select_at_least_one_indicator" ), "'")';
     var i18n_must_select_at_least_one_unit = '$encoder.jsEscape( $i18n.getString( "must_select_at_least_one_unit" ), "'")';
     var i18n_must_select_at_least_one_period = '$encoder.jsEscape( $i18n.getString( "must_select_at_least_one_period" ), "'")';
@@ -66,6 +77,14 @@
         <td><label for="regression">$i18n.getString( "include_regression_line" )</label></td>
         <td><input type="checkbox" id="regression" name="regression" value="true"#if( $!chart.regression ) checked#end></td>
     </tr>
+    <tr>
+        <td><label for="targetLine">$i18n.getString( "include_target_line" )</label></td>
+        <td><input type="checkbox" id="targetLine" name="targetLine" value="true"#if( $!chart.targetLine ) checked#end></td>
+    </tr>
+    <tr id="targetLineValueTr">
+        <td><label for="targetLineValue">$i18n.getString( "target_line_value" )</label></td>
+        <td><input type="text" id="targetLineValue" name="targetLineValue" style="width:80px" value="$!chart.targetLineValue"></td>
+    </tr>
     #if ( $currentUser && $currentUser.hasOrganisationUnit() )
     <tr>
         <td><label for="userOrganisationUnit">$i18n.getString( "user_organisation_unit" )</label></td>