dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #14091
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4651: Added chart resource
------------------------------------------------------------
revno: 4651
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-09-22 16:26:27 +0200
message:
Added chart resource
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/ChartService.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ChartResource.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ReportResource.java
--
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/ChartService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/ChartService.java 2011-09-21 17:22:32 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/ChartService.java 2011-09-22 14:26:27 +0000
@@ -50,7 +50,9 @@
JFreeChart getJFreeChart( int id, I18nFormat format );
- JFreeChart getJFreeChart( Indicator indicator, OrganisationUnit unit, I18nFormat format );
+ JFreeChart getPeriodJFreeChart( Indicator indicator, OrganisationUnit unit, boolean title, I18nFormat format );
+
+ JFreeChart getOrganisationUnitJFreeChart( Indicator indicator, OrganisationUnit parent, boolean title, I18nFormat format );
JFreeChart getJFreeChart( List<Indicator> indicators, List<DataElement> dataElements, List<Period> periods,
List<OrganisationUnit> organisationUnits, String dimension, boolean regression, I18nFormat format );
=== 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-09-22 09:15:51 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java 2011-09-22 14:26:27 +0000
@@ -122,7 +122,7 @@
public class DefaultChartService
implements ChartService
{
- private static final Font titleFont = new Font( "Tahoma", Font.BOLD, 14 );
+ private static final Font titleFont = new Font( "Tahoma", Font.BOLD, 15 );
private static final Font subTitleFont = new Font( "Tahoma", Font.PLAIN, 12 );
private static final Font labelFont = new Font( "Tahoma", Font.PLAIN, 10 );
@@ -235,7 +235,7 @@
return getJFreeChart( chart, !chart.getHideSubtitle() );
}
- public JFreeChart getJFreeChart( Indicator indicator, OrganisationUnit unit, I18nFormat format )
+ public JFreeChart getPeriodJFreeChart( Indicator indicator, OrganisationUnit unit, boolean title, I18nFormat format )
{
RelativePeriods relatives = new RelativePeriods();
relatives.setMonthsThisYear( true );
@@ -243,8 +243,12 @@
Chart chart = new Chart();
- chart.setTitle( indicator.getName() );
- chart.setType( TYPE_BAR );
+ if ( title )
+ {
+ chart.setTitle( indicator.getName() );
+ }
+
+ chart.setType( TYPE_LINE );
chart.setSize( SIZE_NORMAL );
chart.setDimension( DIMENSION_PERIOD_INDICATOR );
chart.setHideLegend( true );
@@ -256,9 +260,37 @@
chart.init();
- return getJFreeChart( chart, true );
- }
-
+ return getJFreeChart( chart, title );
+ }
+
+ public JFreeChart getOrganisationUnitJFreeChart( Indicator indicator, OrganisationUnit parent, boolean title, I18nFormat format )
+ {
+ RelativePeriods relatives = new RelativePeriods();
+ relatives.setThisYear( true );
+ List<Period> periods = periodService.reloadPeriods( relatives.getRelativePeriods( 1, format, true ) );
+
+ Chart chart = new Chart();
+
+ if ( title )
+ {
+ chart.setTitle( indicator.getName() );
+ }
+
+ chart.setType( TYPE_BAR );
+ chart.setSize( SIZE_NORMAL );
+ chart.setDimension( DIMENSION_ORGANISATIONUNIT_INDICATOR );
+ chart.setHideLegend( true );
+ chart.setVerticalLabels( true );
+ chart.getIndicators().add( indicator );
+ chart.setPeriods( periods );
+ chart.setOrganisationUnits( parent.getSortedChildren() );
+ chart.setFormat( format );
+
+ chart.init();
+
+ return getJFreeChart( chart, title );
+ }
+
public JFreeChart getJFreeChart( List<Indicator> indicators, List<DataElement> dataElements, List<Period> periods,
List<OrganisationUnit> organisationUnits, String dimension, boolean regression, I18nFormat format )
{
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ChartResource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ChartResource.java 2011-09-22 07:35:27 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ChartResource.java 2011-09-22 14:26:27 +0000
@@ -13,7 +13,6 @@
import org.hisp.dhis.chart.Chart;
import org.hisp.dhis.chart.ChartService;
-import org.hisp.dhis.i18n.I18nFormat;
import org.hisp.dhis.i18n.I18nManager;
import org.hisp.dhis.indicator.Indicator;
import org.hisp.dhis.indicator.IndicatorService;
@@ -74,39 +73,67 @@
public void write( OutputStream out )
throws IOException, WebApplicationException
{
- ChartUtilities.writeChartAsPNG( out, jFreeChart, 600, 400 );
+ ChartUtilities.writeChartAsPNG( out, jFreeChart, 600, 400, true, 0 );
}
} ).build();
}
@GET
- @Path( "/indicator/{indicator}/{orgUnit}" )
- @Produces( ContextUtils.CONTENT_TYPE_PNG )
- public Response getIndicatorChart( @PathParam("indicator") String indicatorUuid, @PathParam("orgUnit") String orgUnitUuid )
- throws Exception
- {
- final Indicator indicator = indicatorService.getIndicator( indicatorUuid );
-
- final OrganisationUnit unit = organisationUnitService.getOrganisationUnit( orgUnitUuid );
-
- if ( indicator == null || unit == null )
- {
- return null;
- }
-
- final I18nFormat format = i18nManager.getI18nFormat();
-
- final String filename = CodecUtils.filenameEncode( indicator.getName() + ".png" );
-
- final JFreeChart jFreeChart = chartService.getJFreeChart( indicator, unit, format );
-
- return ResponseUtils.response( true, filename, false ).entity( new StreamingOutput()
- {
- @Override
- public void write( OutputStream out )
- throws IOException, WebApplicationException
- {
- ChartUtilities.writeChartAsPNG( out, jFreeChart, 600, 400 );
+ @Path( "/period/{indicator}/{orgUnit}/{width}/{height}/{title}" )
+ @Produces( ContextUtils.CONTENT_TYPE_PNG )
+ public Response getPeriodChart( @PathParam("indicator") String indicatorUuid, @PathParam("orgUnit") String orgUnitUuid,
+ @PathParam("width") final Integer width, @PathParam("height") final Integer height, @PathParam("title") Boolean title )
+ throws Exception
+ {
+ final Indicator indicator = indicatorService.getIndicator( indicatorUuid );
+
+ final OrganisationUnit unit = organisationUnitService.getOrganisationUnit( orgUnitUuid );
+
+ if ( indicator == null || unit == null )
+ {
+ return null;
+ }
+
+ final String filename = CodecUtils.filenameEncode( indicator.getName() + ".png" );
+
+ final JFreeChart jFreeChart = chartService.getPeriodJFreeChart( indicator, unit, title, i18nManager.getI18nFormat() );
+
+ return ResponseUtils.response( true, filename, false ).entity( new StreamingOutput()
+ {
+ public void write( OutputStream out )
+ throws IOException, WebApplicationException
+ {
+ ChartUtilities.writeChartAsPNG( out, jFreeChart, width, height, true, 0 );
+ }
+ } ).build();
+ }
+
+ @GET
+ @Path( "/orgUnit/{indicator}/{orgUnit}/{width}/{height}/{title}" )
+ @Produces( ContextUtils.CONTENT_TYPE_PNG )
+ public Response getOrganisationUnitChart( @PathParam("indicator") String indicatorUuid, @PathParam("orgUnit") String orgUnitUuid,
+ @PathParam("width") final Integer width, @PathParam("height") final Integer height, @PathParam("title") Boolean title )
+ throws Exception
+ {
+ final Indicator indicator = indicatorService.getIndicator( indicatorUuid );
+
+ final OrganisationUnit unit = organisationUnitService.getOrganisationUnit( orgUnitUuid );
+
+ if ( indicator == null || unit == null )
+ {
+ return null;
+ }
+
+ final String filename = CodecUtils.filenameEncode( indicator.getName() + ".png" );
+
+ final JFreeChart jFreeChart = chartService.getOrganisationUnitJFreeChart( indicator, unit, title, i18nManager.getI18nFormat() );
+
+ return ResponseUtils.response( true, filename, false ).entity( new StreamingOutput()
+ {
+ public void write( OutputStream out )
+ throws IOException, WebApplicationException
+ {
+ ChartUtilities.writeChartAsPNG( out, jFreeChart, width, height, true, 0 );
}
} ).build();
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ReportResource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ReportResource.java 2011-09-18 14:36:11 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ReportResource.java 2011-09-22 14:26:27 +0000
@@ -68,7 +68,6 @@
return ResponseUtils.response( true, filename, false ).entity( new StreamingOutput()
{
- @Override
public void write( OutputStream out )
throws IOException, WebApplicationException
{