dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #11565
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3322: WIP: support for rendering of pie/pie3d with multiple indicators
------------------------------------------------------------
revno: 3322
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-04-08 12:48:03 +0200
message:
WIP: support for rendering of pie/pie3d with multiple indicators
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-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
dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/chart.js
--
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-01-18 18:58:06 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/Chart.java 2011-04-08 10:48:03 +0000
@@ -45,13 +45,17 @@
public class Chart
implements Serializable, ImportableObject
{
+ private static final long serialVersionUID = 2570074075484545534L;
+
public static final String DIMENSION_PERIOD = "period";
public static final String DIMENSION_ORGANISATIONUNIT = "organisationUnit";
public static final String DIMENSION_INDICATOR = "indicator";
public static final String TYPE_BAR = "bar";
public static final String TYPE_LINE = "line";
-
+ public static final String TYPE_PIE = "pie";
+ public static final String TYPE_PIE3D = "pie3d";
+
public static final String SIZE_NORMAL = "normal";
public static final String SIZE_WIDE = "wide";
public static final String SIZE_TALL = "tall";
=== 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-01-28 21:44:54 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java 2011-04-08 10:48:03 +0000
@@ -33,6 +33,8 @@
import static org.hisp.dhis.chart.Chart.SIZE_NORMAL;
import static org.hisp.dhis.chart.Chart.TYPE_BAR;
import static org.hisp.dhis.chart.Chart.TYPE_LINE;
+import static org.hisp.dhis.chart.Chart.TYPE_PIE;
+import static org.hisp.dhis.chart.Chart.TYPE_PIE3D;
import static org.hisp.dhis.system.util.ConversionUtils.getArray;
import java.awt.Color;
@@ -70,19 +72,27 @@
import org.hisp.dhis.system.util.MathUtils;
import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.user.User;
+import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
+import org.jfree.chart.plot.MultiplePiePlot;
+import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.DatasetRenderingOrder;
+import org.jfree.chart.plot.Plot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
+import org.jfree.data.category.CategoryToPieDataset;
import org.jfree.data.category.DefaultCategoryDataset;
+import org.jfree.data.general.DefaultPieDataset;
+import org.jfree.data.general.PieDataset;
+import org.jfree.util.TableOrder;
import org.springframework.transaction.annotation.Transactional;
import static org.hisp.dhis.options.SystemSettingManager.*;
@@ -150,7 +160,7 @@
}
private AggregatedDataValueService aggregatedDataValueService;
-
+
public void setAggregatedDataValueService( AggregatedDataValueService aggregatedDataValueService )
{
this.aggregatedDataValueService = aggregatedDataValueService;
@@ -162,9 +172,11 @@
{
this.systemSettingManager = systemSettingManager;
}
-
+
private CurrentUserService currentUserService;
+ private List keys;
+
public void setCurrentUserService( CurrentUserService currentUserService )
{
this.currentUserService = currentUserService;
@@ -184,12 +196,12 @@
if ( chart.getRelatives() != null )
{
- chart.setRelativePeriods( periodService.reloadPeriods(
- chart.getRelatives().getRelativePeriods( 1, null, false ) ) );
+ chart.setRelativePeriods( periodService.reloadPeriods( chart.getRelatives().getRelativePeriods( 1, null,
+ false ) ) );
}
-
+
User user = currentUserService.getCurrentUser();
-
+
if ( chart.isUserOrganisationUnit() && user != null && user.getOrganisationUnit() != null )
{
chart.setOrganisationUnit( user.getOrganisationUnit() );
@@ -403,7 +415,7 @@
return renderer;
}
-
+
/**
* Returns a JFreeChart of type defined in the chart argument.
*/
@@ -424,6 +436,46 @@
{
plot = new CategoryPlot( dataSets[0], new CategoryAxis(), new NumberAxis(), lineRenderer );
}
+ else if ( chart.isType( TYPE_PIE ) )
+ {
+ JFreeChart multiplePieChart = ChartFactory.createMultiplePieChart( chart.getTitle(), dataSets[0],
+ TableOrder.BY_ROW, !chart.getHideLegend(), true, false );
+ multiplePieChart.setBackgroundPaint( Color.WHITE );
+ multiplePieChart.setAntiAlias( true );
+
+ MultiplePiePlot multiplePiePlot = (MultiplePiePlot) multiplePieChart.getPlot();
+ PiePlot piePlot = (PiePlot) multiplePiePlot.getPieChart().getPlot();
+ piePlot.setBackgroundPaint( Color.WHITE );
+ piePlot.setShadowXOffset( 0 );
+ piePlot.setShadowYOffset( 0 );
+
+ for ( int i = 0; i < dataSets[0].getColumnCount(); i++ )
+ {
+ piePlot.setSectionPaint( dataSets[0].getColumnKey( i ), colors[i] );
+ }
+
+ return multiplePieChart;
+ }
+ else if ( chart.isType( TYPE_PIE3D ) )
+ {
+ JFreeChart multiplePieChart = ChartFactory.createMultiplePieChart3D( chart.getTitle(), dataSets[0],
+ TableOrder.BY_ROW, !chart.getHideLegend(), true, false );
+ multiplePieChart.setBackgroundPaint( Color.WHITE );
+ multiplePieChart.setAntiAlias( true );
+
+ MultiplePiePlot multiplePiePlot = (MultiplePiePlot) multiplePieChart.getPlot();
+ PiePlot piePlot = (PiePlot) multiplePiePlot.getPieChart().getPlot();
+ piePlot.setBackgroundPaint( Color.WHITE );
+ piePlot.setShadowXOffset( 0 );
+ piePlot.setShadowYOffset( 0 );
+
+ for ( int i = 0; i < dataSets[0].getColumnCount(); i++ )
+ {
+ piePlot.setSectionPaint( dataSets[0].getColumnKey( i ), colors[i] );
+ }
+
+ return multiplePieChart;
+ }
else
{
plot = new CategoryPlot( dataSets[0], new CategoryAxis(), new NumberAxis(), barRenderer );
@@ -473,8 +525,9 @@
*/
private CategoryDataset[] getCategoryDataSet( Chart chart )
{
- String aggregationStrategy = (String) systemSettingManager.getSystemSetting( KEY_AGGREGATION_STRATEGY, DEFAULT_AGGREGATION_STRATEGY );
-
+ String aggregationStrategy = (String) systemSettingManager.getSystemSetting( KEY_AGGREGATION_STRATEGY,
+ DEFAULT_AGGREGATION_STRATEGY );
+
final DefaultCategoryDataset regularDataSet = new DefaultCategoryDataset();
final DefaultCategoryDataset regressionDataSet = new DefaultCategoryDataset();
@@ -498,9 +551,10 @@
for ( Period period : chart.getAllPeriods() )
{
- final Double value = aggregationStrategy.equals( AGGREGATION_STRATEGY_REAL_TIME ) ?
- aggregationService.getAggregatedIndicatorValue( indicator, period.getStartDate(), period.getEndDate(), selectedOrganisationUnit ) :
- aggregatedDataValueService.getAggregatedValue( indicator, period, selectedOrganisationUnit );
+ final Double value = aggregationStrategy.equals( AGGREGATION_STRATEGY_REAL_TIME ) ? aggregationService
+ .getAggregatedIndicatorValue( indicator, period.getStartDate(), period.getEndDate(),
+ selectedOrganisationUnit ) : aggregatedDataValueService.getAggregatedValue( indicator,
+ period, selectedOrganisationUnit );
if ( chart.isDimension( DIMENSION_PERIOD ) )
{
@@ -513,10 +567,10 @@
chart.getFormat().formatPeriod( period ), indicator.getShortName() );
}
columnIndex++;
-
+
// Omit missing values and 0 from regression
-
- if ( value != null && value != 0.0 )
+
+ if ( value != null && value != 0.0 )
{
regression.addData( columnIndex, value );
}
@@ -533,10 +587,10 @@
for ( Period period : chart.getAllPeriods() )
{
final double value = regression.predict( columnIndex++ );
-
+
// Enough values must exist for regression
-
- if ( !Double.isNaN( value ) )
+
+ if ( !Double.isNaN( value ) )
{
regressionDataSet.addValue( value, TREND_PREFIX + indicator.getShortName(), chart
.getFormat().formatPeriod( period ) );
@@ -553,12 +607,13 @@
for ( OrganisationUnit unit : chart.getAllOrganisationUnits() )
{
- final Double value = aggregationStrategy.equals( AGGREGATION_STRATEGY_REAL_TIME ) ?
- aggregationService.getAggregatedIndicatorValue( indicator, selectedPeriod.getStartDate(), selectedPeriod.getEndDate(), unit ) :
- aggregatedDataValueService.getAggregatedValue( indicator, selectedPeriod, unit );
+ final Double value = aggregationStrategy.equals( AGGREGATION_STRATEGY_REAL_TIME ) ? aggregationService
+ .getAggregatedIndicatorValue( indicator, selectedPeriod.getStartDate(),
+ selectedPeriod.getEndDate(), unit ) : aggregatedDataValueService.getAggregatedValue(
+ indicator, selectedPeriod, unit );
- regularDataSet.addValue( value != null ? value : 0, indicator.getShortName(), unit
- .getShortName() );
+ regularDataSet.addValue( value != null ? value : 0, indicator.getShortName(),
+ unit.getShortName() );
columnIndex++;
}
=== 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-03-29 20:06:47 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties 2011-04-08 10:48:03 +0000
@@ -170,6 +170,8 @@
chart_type= Chart type
bar_chart= Bar chart
line_chart= Line chart
+pie_chart= Pie chart
+pie3d_chart= Pie 3D chart
chart_size= Chart size
normal= Normal
wide= Wide
=== 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-03-28 20:09:32 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addChartForm.vm 2011-04-08 10:48:03 +0000
@@ -35,6 +35,8 @@
<select id="type" name="type" style="width:300px">
<option value="bar"#if ( $!chart.type == "bar" ) selected#end>$i18n.getString( "bar_chart" )</option>
<option value="line"#if ( $!chart.type == "line" ) selected#end>$i18n.getString( "line_chart" )</option>
+ <option value="pie"#if ( $!chart.type == "pie" ) selected#end>$i18n.getString( "pie_chart" )</option>
+ <option value="pie3d"#if ( $!chart.type == "pie3d" ) selected#end>$i18n.getString( "pie3d_chart" )</option>
</select>
</td>
</tr>
=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/chart.js'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/chart.js 2011-01-13 15:44:09 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/chart.js 2011-04-08 10:48:03 +0000
@@ -86,28 +86,38 @@
}
}
+function selectedChartType()
+{
+ return $("#type").val();
+}
+
+function selectedIndicatorsCount()
+{
+ return $("#selectedIndicators option").length;
+}
+
function validateCollections()
{
if ( !hasElements( "selectedIndicators" ) )
{
setMessage( i18n_must_select_at_least_one_indicator );
-
+
return false;
}
-
+
if ( !hasElements( "selectedOrganisationUnits" ) && !isChecked( "userOrganisationUnit" ) )
{
setMessage( i18n_must_select_at_least_one_unit );
-
+
return false;
}
-
+
if ( !hasElements( "selectedPeriods" ) && !relativePeriodsChecked() )
{
setMessage( i18n_must_select_at_least_one_period );
return false;
}
-
+
return true;
}