← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 67: Added subtitles to charts.

 

------------------------------------------------------------
revno: 67
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Sat 2009-03-14 12:05:58 +0100
message:
  Added subtitles to charts.
modified:
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java
  dhis-2/dhis-web/dhis-web-portal/pom.xml

=== 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	2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java	2009-03-14 11:05:58 +0000
@@ -62,6 +62,7 @@
 import org.jfree.chart.plot.PlotOrientation;
 import org.jfree.chart.renderer.category.BarRenderer;
 import org.jfree.chart.renderer.category.LineAndShapeRenderer;
+import org.jfree.chart.title.TextTitle;
 import org.jfree.data.category.CategoryDataset;
 import org.jfree.data.category.DefaultCategoryDataset;
 
@@ -73,6 +74,7 @@
     implements ChartService
 {
     private static final Font titleFont = new Font( "Tahoma", Font.BOLD, 14 );
+    private static final Font subTitleFont = new Font( "Tahoma", Font.PLAIN, 12 );
     private static final String TREND_PREFIX = "Trend - ";
     private static final String TITLE_SEPARATOR = " - ";
     private static final String DEFAULT_TITLE_PIVOT_CHART = "Pivot Chart";
@@ -115,7 +117,7 @@
         
         chart.setFormat( format );
         
-        return getJFreeChart( chart );
+        return getJFreeChart( chart, true );
     }
 
     public JFreeChart getJFreeChart( List<Indicator> indicators, List<Period> periods, 
@@ -136,7 +138,7 @@
         chart.setOrganisationUnits( organisationUnits );
         chart.setFormat( format );
         
-        return getJFreeChart( chart );
+        return getJFreeChart( chart, false );
     }
     
     public JFreeChart getJFreeChart( String title, PlotOrientation orientation, 
@@ -205,7 +207,7 @@
     /**
      * Returns a JFreeChart of type defined in the chart argument.
      */
-    private JFreeChart getJFreeChart( Chart chart )
+    private JFreeChart getJFreeChart( Chart chart, boolean subTitle )
     {
         final BarRenderer barRenderer = getBarRenderer();
         final LineAndShapeRenderer lineRenderer = getLineRenderer();
@@ -235,6 +237,11 @@
         
         JFreeChart jFreeChart = new JFreeChart( chart.getTitle(), titleFont, plot, !chart.isHideLegend() );
         
+        if ( subTitle )
+        {
+            jFreeChart.addSubtitle( getSubTitle( chart, chart.getFormat() ) );
+        }
+        
         // ---------------------------------------------------------------------
         // Plot orientation
         // ---------------------------------------------------------------------
@@ -379,6 +386,27 @@
         return title;
     }
     
+    /**
+     * Returns a subtitle based on the chart dimension.
+     */
+    private TextTitle getSubTitle( Chart chart, I18nFormat format )
+    {
+        TextTitle subTitle = new TextTitle();
+        
+        subTitle.setFont( subTitleFont );
+        
+        if ( chart.isDimension( DIMENSION_PERIOD ) && chart.getOrganisationUnits().size() > 0 )
+        {
+            subTitle.setText( chart.getOrganisationUnits().get( 0 ).getName() );
+        }
+        else if ( chart.isDimension( DIMENSION_ORGANISATIONUNIT ) && chart.getPeriods().size() > 0 )
+        {
+            subTitle.setText( format.formatPeriod( chart.getPeriods().get( 0 ) ) );
+        }
+        
+        return subTitle;
+    }
+    
     // -------------------------------------------------------------------------
     // CRUD operations
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-portal/pom.xml'
--- dhis-2/dhis-web/dhis-web-portal/pom.xml	2009-03-11 15:16:35 +0000
+++ dhis-2/dhis-web/dhis-web-portal/pom.xml	2009-03-14 11:05:58 +0000
@@ -30,22 +30,6 @@
       <artifactId>dhis-web-commons-resources</artifactId>
       <type>war</type>
     </dependency>
-    <dependency>
-      <groupId>org.hisp.dhis</groupId>
-      <artifactId>dhis-support-hibernate</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.hisp.dhis</groupId>
-      <artifactId>dhis-support-system</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.hisp.dhis</groupId>
-      <artifactId>dhis-service-user-hibernate</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.hisp.dhis</groupId>
-      <artifactId>dhis-options</artifactId>
-    </dependency>
     
     <!-- Web maintenance modules -->
     
@@ -149,7 +133,7 @@
     
     <!-- India modules -->
     
-    <!-- 
+    <!--    
     <dependency>
       <groupId>org.hisp.dhis</groupId>
       <artifactId>dhis-web-dashboard</artifactId>



--

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.