=== 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-12-21 13:57:22 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/Chart.java 2011-12-21 22:11:29 +0000 @@ -32,6 +32,7 @@ import org.hisp.dhis.common.BaseIdentifiableObject; import org.hisp.dhis.common.BaseNameableObject; import org.hisp.dhis.common.Dxf2Namespace; +import org.hisp.dhis.common.NameableObject; import org.hisp.dhis.common.adapter.DataElementXmlAdapter; import org.hisp.dhis.common.adapter.DataSetXmlAdapter; import org.hisp.dhis.common.adapter.IndicatorXmlAdapter; @@ -67,14 +68,6 @@ public static final String DIMENSION_PERIOD_DATAELEMENT = "period_dataElement"; public static final String DIMENSION_ORGANISATIONUNIT_DATAELEMENT = "organisationUnit_dataElement"; public static final String DIMENSION_DATAELEMENT_PERIOD = "dataElement_period"; - public static final String DIMENSION_PERIOD_COMPLETENESS = "period_completeness"; - public static final String DIMENSION_ORGANISATIONUNIT_COMPLETENESS = "organisationUnit_completeness"; - public static final String DIMENSION_COMPLETENESS_PERIOD = "completeness_period"; - - public static final String TYPE_BAR3D = "bar3d"; - public static final String TYPE_STACKED_BAR3D = "stackedBar3d"; - public static final String TYPE_LINE3D = "line3d"; - public static final String TYPE_PIE3D = "pie3d"; public static final String SIZE_NORMAL = "normal"; public static final String SIZE_WIDE = "wide"; @@ -98,10 +91,6 @@ private String type; - private String size; - - private String dimension; - private String series; private String category; @@ -110,10 +99,6 @@ private boolean hideLegend; - private boolean verticalLabels; - - private boolean horizontalPlotOrientation; - private boolean regression; private boolean targetLine; @@ -210,7 +195,98 @@ addChartGroup( group ); } } + + public List series() + { + return dimensionToList( series ); + } + + public List category() + { + return dimensionToList( category ); + } + + public NameableObject filter() + { + List list = dimensionToList( filter ); + + return list != null && !list.isEmpty() ? list.iterator().next() : null; + } + public String getTitle() + { + if ( DIMENSION_PERIOD.equals( filter ) ) + { + return format.formatPeriod( getAllPeriods().get( 0 ) ); + } + + return filter().getName(); + } + + private List dimensionToList( String dimension ) + { + List list = new ArrayList(); + + if ( DIMENSION_DATA.equals( dimension ) ) + { + list.addAll( getDataElements() ); + list.addAll( getIndicators() ); + } + else if ( DIMENSION_PERIOD.equals( dimension ) ) + { + namePeriods( getAllPeriods(), format ); + + list.addAll( getAllPeriods() ); + } + else if ( DIMENSION_ORGANISATIONUNIT.equals( dimension ) ) + { + list.addAll( getAllOrganisationUnits() ); + } + + return list; + } + + private void namePeriods( List periods, I18nFormat format ) + { + for ( Period period : periods ) + { + period.setName( format.formatPeriod( period ) ); + } + } + + /** + * TODO This method is a temporary hack while we phase out the old chart UI. + */ + public String getDimension() + { + if ( DIMENSION_DATA.equals( series ) && DIMENSION_PERIOD.equals( category ) && !indicators.isEmpty() ) + { + return DIMENSION_PERIOD_INDICATOR; + } + else if ( DIMENSION_DATA.equals( series ) && DIMENSION_ORGANISATIONUNIT.equals( category ) && !indicators.isEmpty() ) + { + return DIMENSION_ORGANISATIONUNIT_INDICATOR; + } + else if ( DIMENSION_PERIOD.equals( series ) && DIMENSION_DATA.equals( category ) && !indicators.isEmpty() ) + { + return DIMENSION_INDICATOR_PERIOD; + } + else if ( DIMENSION_DATA.equals( series ) && DIMENSION_PERIOD.equals( category ) ) + { + return DIMENSION_PERIOD_DATAELEMENT; + } + else if ( DIMENSION_DATA.equals( series ) && DIMENSION_ORGANISATIONUNIT.equals( category ) ) + { + return DIMENSION_ORGANISATIONUNIT_DATAELEMENT; + } + else if ( DIMENSION_PERIOD.equals( series ) && DIMENSION_DATA.equals( category ) ) + { + return DIMENSION_DATAELEMENT_PERIOD; + } + + return null; + } + // ------------------------------------------------------------------------- // hashCode, equals, toString // ------------------------------------------------------------------------- @@ -254,21 +330,35 @@ // Logic // ------------------------------------------------------------------------- + /** + * Sets all dimensions for this chart. + * + * @param series the series dimension. + * @param category the category dimension. + * @param filter the filter dimension. + */ + public void setDimensions( String series, String category, String filter ) + { + this.series = series; + this.category = category; + this.filter = filter; + } + + public boolean hasIndicators() + { + return indicators != null && indicators.size() > 0; + } + + public boolean hasDataElements() + { + return dataElements != null && dataElements.size() > 0; + } + public boolean isType( String type ) { return this.type != null && this.type.equals( type ); } - public boolean isSize( String size ) - { - return this.size != null && this.size.equals( size ); - } - - public boolean isDimension( String dimension ) - { - return this.dimension != null && this.dimension.equals( dimension ); - } - public int getWidth() { return 700; @@ -321,30 +411,6 @@ @XmlElement @JsonProperty - public String getSize() - { - return size; - } - - public void setSize( String size ) - { - this.size = size; - } - - @XmlElement - @JsonProperty - public String getDimension() - { - return dimension; - } - - public void setDimension( String dimension ) - { - this.dimension = dimension; - } - - @XmlElement - @JsonProperty public String getSeries() { return series; @@ -393,30 +459,6 @@ @XmlElement @JsonProperty - public boolean isVerticalLabels() - { - return verticalLabels; - } - - public void setVerticalLabels( boolean verticalLabels ) - { - this.verticalLabels = verticalLabels; - } - - @XmlElement - @JsonProperty - public boolean isHorizontalPlotOrientation() - { - return horizontalPlotOrientation; - } - - public void setHorizontalPlotOrientation( boolean horizontalPlotOrientation ) - { - this.horizontalPlotOrientation = horizontalPlotOrientation; - } - - @XmlElement - @JsonProperty public boolean isRegression() { return regression; === 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-12-15 10:32:22 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/ChartService.java 2011-12-21 11:59:13 +0000 @@ -60,7 +60,7 @@ JFreeChart getJFreeOrganisationUnitChart( Indicator indicator, OrganisationUnit parent, boolean title, I18nFormat format ); JFreeChart getJFreeChart( List indicators, List dataElements, List dataSets, List periods, - List organisationUnits, String dimension, boolean regression, I18nFormat format ); + List organisationUnits, String series, String category, String filter, boolean regression, I18nFormat format ); JFreeChart getJFreeChart( String name, PlotOrientation orientation, CategoryLabelPositions labelPositions, Map categoryValues ); === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseIdentifiableObject.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseIdentifiableObject.java 2011-12-19 09:36:33 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseIdentifiableObject.java 2011-12-21 20:06:49 +0000 @@ -93,6 +93,16 @@ } // ------------------------------------------------------------------------- + // Comparable implementation + // ------------------------------------------------------------------------- + + @Override + public int compareTo( IdentifiableObject object ) + { + return name == null ? ( object.getName() == null ? 0 : -1 ) : name.compareTo( object.getName() ); + } + + // ------------------------------------------------------------------------- // Setters and getters // ------------------------------------------------------------------------- === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObject.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObject.java 2011-12-03 12:53:47 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObject.java 2011-12-21 20:06:49 +0000 @@ -31,7 +31,7 @@ */ public interface IdentifiableObject - extends ImportableObject, LinkableObject + extends ImportableObject, LinkableObject, Comparable { public abstract int getId(); === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java 2011-12-19 19:01:47 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java 2011-12-21 20:06:49 +0000 @@ -539,7 +539,7 @@ return column.length() > 0 ? column.substring( 0, column.lastIndexOf( SEPARATOR ) ) : TOTAL_COLUMN_NAME; } - + /** * Generates a grid identifier based on the internal identifiers of the * argument objects. === modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/sms/config/GenericHttpGatewayConfigTest.java' --- dhis-2/dhis-api/src/test/java/org/hisp/dhis/sms/config/GenericHttpGatewayConfigTest.java 2011-12-20 12:46:37 +0000 +++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/sms/config/GenericHttpGatewayConfigTest.java 2011-12-21 20:06:49 +0000 @@ -1,8 +1,8 @@ package org.hisp.dhis.sms.config; -import static org.junit.Assert.*; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.io.IOException; import java.io.StringReader; @@ -19,6 +19,7 @@ import javax.xml.bind.Unmarshaller; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; /* @@ -73,6 +74,7 @@ } @Test + @Ignore public void testMarshalling() throws IOException, JAXBException { === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java 2011-12-21 11:19:47 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java 2011-12-21 22:11:29 +0000 @@ -224,7 +224,7 @@ executeSql( "ALTER TABLE section DROP CONSTRAINT section_name_key" ); executeSql( "UPDATE patientattribute set inheritable=false where inheritable is null" ); - executeSql( "UPDATE dataelement set numbertype='number' where numbertype is null and valuetype='int'" ); + executeSql( "UPDATE dataelement SET numbertype='number' where numbertype is null and valuetype='int'" ); // revert prepare aggregate*Value tables for offline diffs @@ -235,6 +235,30 @@ // program executeSql( "ALTER TABLE programinstance ALTER COLUMN patientid DROP NOT NULL" ); + + // migrate charts from dimension to category, series, filter + + executeSql( "UPDATE chart SET series='PERIOD', category='DATA', filter='ORGANISATIONUNIT' WHERE dimension='indicator'" ); + executeSql( "UPDATE chart SET series='DATA', category='ORGANISATIONUNIT', filter='PERIOD' WHERE dimension='organisationUnit'" ); + executeSql( "UPDATE chart SET series='PERIOD', category='DATA', filter='ORGANISATIONUNIT' WHERE dimension='dataElement_period'" ); + executeSql( "UPDATE chart SET series='DATA', category='ORGANISATIONUNIT', filter='PERIOD' WHERE dimension='organisationUnit_dataElement'" ); + executeSql( "UPDATE chart SET series='DATA', category='PERIOD', filter='ORGANISATIONUNIT' WHERE dimension='period'" ); + executeSql( "UPDATE chart SET series='DATA', category='PERIOD', filter='ORGANISATIONUNIT' WHERE dimension='period_dataElement'" ); + + executeSql( "UPDATE chart SET type='BAR' where type='bar'" ); + executeSql( "UPDATE chart SET type='BAR' where type='bar3d'" ); + executeSql( "UPDATE chart SET type='STACKEDBAR' where type='stackedBar'" ); + executeSql( "UPDATE chart SET type='STACKEDBAR' where type='stackedBar3d'" ); + executeSql( "UPDATE chart SET type='LINE' where type='line'" ); + executeSql( "UPDATE chart SET type='LINE' where type='line3d'" ); + executeSql( "UPDATE chart SET type='PIE' where type='pie'" ); + executeSql( "UPDATE chart SET type='PIE' where type='pie3d'" ); + + executeSql( "ALTER TABLE chart RENAME COLUMN title TO name" ); + executeSql( "ALTER TABLE chart ALTER COLUMN dimension DROP NOT NULL" ); + executeSql( "ALTER TABLE chart DROP COLUMN size" ); + executeSql( "ALTER TABLE chart DROP COLUMN verticallabels" ); + executeSql( "ALTER TABLE chart DROP COLUMN horizontalplotorientation" ); // remove outdated relative periods @@ -261,9 +285,6 @@ executeSql( "ALTER TABLE chart DROP COLUMN last12individualmonths" ); executeSql( "ALTER TABLE chart DROP COLUMN individualmonthsthisyear" ); executeSql( "ALTER TABLE chart DROP COLUMN individualquartersthisyear" ); - executeSql( "ALTER TABLE chart RENAME COLUMN title TO name" ); - executeSql( "ALTER TABLE chart ALTER COLUMN dimension DROP NOT NULL" ); - executeSql( "ALTER TABLE chart DROP COLUMN size" ); executeSql( "ALTER TABLE datamartexport DROP COLUMN last3months" ); executeSql( "ALTER TABLE datamartexport DROP COLUMN last6months" ); === modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/ChartConverter.java' --- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/ChartConverter.java 2011-12-19 14:32:26 +0000 +++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/ChartConverter.java 2011-12-21 20:41:22 +0000 @@ -58,11 +58,7 @@ private static final String FIELD_CODE = "code"; private static final String FIELD_TITLE = "title"; private static final String FIELD_TYPE = "type"; - private static final String FIELD_SIZE = "size"; - private static final String FIELD_DIMENSION = "dimension"; private static final String FIELD_HIDE_LEGEND = "hideLegend"; - private static final String FIELD_VERTICAL_LABELS = "verticalLabels"; - private static final String FIELD_HORIZONTAL_PLOT_ORIENTATION = "horizontalPlotOrientation"; private static final String FIELD_REGRESSION = "regression"; private static final String FIELD_INDICATORS = "indicators"; @@ -137,11 +133,7 @@ writer.writeElement( FIELD_CODE, chart.getCode() ); // v1.2.1 writer.writeElement( FIELD_TITLE, chart.getName() ); writer.writeElement( FIELD_TYPE, chart.getType() ); - writer.writeElement( FIELD_SIZE, String.valueOf( chart.getSize() ) ); - writer.writeElement( FIELD_DIMENSION, String.valueOf( chart.getDimension() ) ); writer.writeElement( FIELD_HIDE_LEGEND, String.valueOf( chart.isHideLegend() ) ); - writer.writeElement( FIELD_VERTICAL_LABELS, String.valueOf( chart.isVerticalLabels() ) ); - writer.writeElement( FIELD_HORIZONTAL_PLOT_ORIENTATION, String.valueOf( chart.isHorizontalPlotOrientation() ) ); writer.writeElement( FIELD_REGRESSION, String.valueOf( chart.isRegression() ) ); writer.openElement( FIELD_INDICATORS ); @@ -206,21 +198,9 @@ reader.moveToStartElement( FIELD_TYPE ); chart.setType( reader.getElementValue() ); - reader.moveToStartElement( FIELD_SIZE ); - chart.setSize( reader.getElementValue() ); - - reader.moveToStartElement( FIELD_DIMENSION ); - chart.setDimension( reader.getElementValue() ); - reader.moveToStartElement( FIELD_HIDE_LEGEND ); chart.setHideLegend( Boolean.parseBoolean( reader.getElementValue() ) ); - reader.moveToStartElement( FIELD_VERTICAL_LABELS ); - chart.setVerticalLabels( Boolean.parseBoolean( reader.getElementValue() ) ); - - reader.moveToStartElement( FIELD_HORIZONTAL_PLOT_ORIENTATION ); - chart.setHorizontalPlotOrientation( Boolean.parseBoolean( reader.getElementValue() ) ); - reader.moveToStartElement( FIELD_REGRESSION ); chart.setRegression( Boolean.parseBoolean( reader.getElementValue() ) ); === modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/ChartImporter.java' --- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/ChartImporter.java 2011-11-12 18:43:35 +0000 +++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/ChartImporter.java 2011-12-21 20:41:22 +0000 @@ -67,11 +67,7 @@ { match.setName( object.getName() ); match.setType( object.getType() ); - match.setSize( object.getSize() ); - match.setDimension( object.getDimension() ); match.setHideLegend( object.isHideLegend() ); - match.setVerticalLabels( object.isVerticalLabels() ); - match.setHorizontalPlotOrientation( object.isHorizontalPlotOrientation() ); match.setRegression( object.isRegression() ); match.getRelatives().setReportingMonth( object.getRelatives().isReportingMonth() ); @@ -102,26 +98,10 @@ { return false; } - if ( !isSimiliar( object.getSize(), existing.getSize() ) || ( isNotNull( object.getSize(), existing.getSize() ) && !object.getSize().equals( existing.getSize() ) ) ) - { - return false; - } - if ( !isSimiliar( object.getDimension(), existing.getDimension() ) || ( isNotNull( object.getDimension(), existing.getDimension() ) && !object.getDimension().equals( existing.getDimension() ) ) ) - { - return false; - } if ( object.isHideLegend() != existing.isHideLegend() ) { return false; } - if ( object.isVerticalLabels() != existing.isVerticalLabels() ) - { - return false; - } - if ( object.isHorizontalPlotOrientation() != existing.isHorizontalPlotOrientation() ) - { - return false; - } if ( object.isRegression() != existing.isRegression() ) { return false; === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientchart/DefaultPatientChartService.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientchart/DefaultPatientChartService.java 2011-10-03 09:40:38 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientchart/DefaultPatientChartService.java 2011-12-21 20:06:49 +0000 @@ -28,9 +28,7 @@ package org.hisp.dhis.patientchart; import static org.hisp.dhis.chart.Chart.TYPE_BAR; -import static org.hisp.dhis.chart.Chart.TYPE_BAR3D; import static org.hisp.dhis.chart.Chart.TYPE_LINE; -import static org.hisp.dhis.chart.Chart.TYPE_LINE3D; import java.awt.Color; import java.awt.Font; @@ -50,9 +48,7 @@ import org.jfree.chart.plot.DatasetRenderingOrder; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.renderer.category.BarRenderer; -import org.jfree.chart.renderer.category.BarRenderer3D; import org.jfree.chart.renderer.category.LineAndShapeRenderer; -import org.jfree.chart.renderer.category.LineRenderer3D; import org.jfree.data.category.CategoryDataset; import org.jfree.data.category.DefaultCategoryDataset; import org.springframework.transaction.annotation.Transactional; @@ -154,9 +150,7 @@ private JFreeChart getJFreeChart( PatientChart patientChart ) { final BarRenderer barRenderer = getBarRenderer(); - final BarRenderer bar3dRenderer = getBar3DRenderer(); final LineAndShapeRenderer lineRenderer = getLineRenderer(); - final LineRenderer3D line3dRenderer = getLineRenderer3D(); // --------------------------------------------------------------------- // Plot @@ -170,14 +164,6 @@ { plot = new CategoryPlot( dataSets[0], new CategoryAxis(), new NumberAxis(), lineRenderer ); } - if ( patientChart.isType( TYPE_LINE3D ) ) - { - plot = new CategoryPlot( dataSets[0], new CategoryAxis(), new NumberAxis(), line3dRenderer ); - } - else if ( patientChart.isType( TYPE_BAR3D ) ) - { - plot = new CategoryPlot( dataSets[0], new CategoryAxis(), new NumberAxis(), bar3dRenderer ); - } else if ( patientChart.isType( TYPE_BAR ) ) { plot = new CategoryPlot( dataSets[0], new CategoryAxis(), new NumberAxis(), barRenderer ); @@ -234,24 +220,6 @@ } /** - * Returns a bar3d renderer. - */ - private BarRenderer getBar3DRenderer() - { - BarRenderer3D renderer = new BarRenderer3D(); - - renderer.setMaximumBarWidth( 0.07 ); - - for ( int i = 0; i < colors.length; i++ ) - { - renderer.setSeriesPaint( i, colors[i] ); - renderer.setShadowVisible( false ); - } - - return renderer; - } - - /** * Returns a line and shape renderer. */ private LineAndShapeRenderer getLineRenderer() @@ -267,21 +235,6 @@ } /** - * Returns a line3d renderer. - */ - private LineRenderer3D getLineRenderer3D() - { - LineRenderer3D renderer = new LineRenderer3D(); - - for ( int i = 0; i < colors.length; i++ ) - { - renderer.setSeriesPaint( i, colors[i] ); - } - - return renderer; - } - - /** * Returns a DefaultCategoryDataSet based on patient-data-values for the * patient-chart. */ === 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-12-21 11:19:47 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java 2011-12-21 20:41:22 +0000 @@ -27,20 +27,35 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +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_STACKED_BAR; +import static org.hisp.dhis.reporttable.ReportTable.getIdentifier; +import static org.hisp.dhis.system.util.ConversionUtils.getArray; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Font; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + import org.apache.commons.math.MathException; import org.apache.commons.math.analysis.SplineInterpolator; import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.UnivariateRealInterpolator; import org.apache.commons.math.stat.regression.SimpleRegression; -import org.hisp.dhis.aggregation.AggregatedDataValueService; import org.hisp.dhis.aggregation.AggregationService; import org.hisp.dhis.chart.Chart; import org.hisp.dhis.chart.ChartGroup; import org.hisp.dhis.chart.ChartService; import org.hisp.dhis.common.GenericIdentifiableObjectStore; import org.hisp.dhis.common.NameableObject; -import org.hisp.dhis.completeness.DataSetCompletenessResult; -import org.hisp.dhis.completeness.DataSetCompletenessService; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; import org.hisp.dhis.dataset.DataSet; @@ -55,6 +70,7 @@ import org.hisp.dhis.period.Period; import org.hisp.dhis.period.PeriodService; import org.hisp.dhis.period.RelativePeriods; +import org.hisp.dhis.reporttable.jdbc.ReportTableManager; import org.hisp.dhis.system.util.Filter; import org.hisp.dhis.system.util.FilterUtils; import org.hisp.dhis.system.util.MathUtils; @@ -67,8 +83,16 @@ import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.labels.StandardPieSectionLabelGenerator; -import org.jfree.chart.plot.*; -import org.jfree.chart.renderer.category.*; +import org.jfree.chart.plot.CategoryPlot; +import org.jfree.chart.plot.DatasetRenderingOrder; +import org.jfree.chart.plot.Marker; +import org.jfree.chart.plot.MultiplePiePlot; +import org.jfree.chart.plot.PiePlot; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.plot.ValueMarker; +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.DefaultCategoryDataset; @@ -76,15 +100,6 @@ import org.jfree.util.TableOrder; import org.springframework.transaction.annotation.Transactional; -import java.awt.*; -import java.util.*; -import java.util.List; -import java.util.Map.Entry; - -import static org.hisp.dhis.chart.Chart.*; -import static org.hisp.dhis.options.SystemSettingManager.*; -import static org.hisp.dhis.system.util.ConversionUtils.getArray; - /** * @author Lars Helge Overland * @version $Id$ @@ -100,9 +115,7 @@ private static final Font labelFont = new Font( "Tahoma", Font.PLAIN, 10 ); private static final String TREND_PREFIX = "Trend - "; - private static final String TITLE_SEPARATOR = " - "; - private static final String DEFAULT_TITLE_PIVOT_CHART = "Pivot Chart"; private static final Color[] colors = {Color.decode( "#d54a4a" ), Color.decode( "#2e4e83" ), @@ -149,13 +162,6 @@ this.aggregationService = aggregationService; } - private AggregatedDataValueService aggregatedDataValueService; - - public void setAggregatedDataValueService( AggregatedDataValueService aggregatedDataValueService ) - { - this.aggregatedDataValueService = aggregatedDataValueService; - } - private SystemSettingManager systemSettingManager; public void setSystemSettingManager( SystemSettingManager systemSettingManager ) @@ -170,19 +176,19 @@ this.currentUserService = currentUserService; } - private DataSetCompletenessService dataSetCompletenessService; - - public void setDataSetCompletenessService( DataSetCompletenessService dataSetCompletenessService ) - { - this.dataSetCompletenessService = dataSetCompletenessService; - } - private GenericIdentifiableObjectStore chartGroupStore; public void setChartGroupStore( GenericIdentifiableObjectStore chartGroupStore ) { this.chartGroupStore = chartGroupStore; } + + private ReportTableManager reportTableManager; + + public void setReportTableManager( ReportTableManager reportTableManager ) + { + this.reportTableManager = reportTableManager; + } // ------------------------------------------------------------------------- // ChartService implementation @@ -240,9 +246,8 @@ } chart.setType( TYPE_LINE ); - chart.setDimension( DIMENSION_PERIOD_INDICATOR ); + chart.setDimensions( Chart.DIMENSION_DATA, Chart.DIMENSION_PERIOD, Chart.DIMENSION_ORGANISATIONUNIT ); chart.setHideLegend( true ); - chart.setVerticalLabels( true ); chart.getIndicators().add( indicator ); chart.setPeriods( periods ); chart.setOrganisationUnit( unit ); @@ -267,9 +272,8 @@ } chart.setType( TYPE_BAR ); - chart.setDimension( DIMENSION_ORGANISATIONUNIT_INDICATOR ); + chart.setDimensions( Chart.DIMENSION_DATA, Chart.DIMENSION_ORGANISATIONUNIT, Chart.DIMENSION_PERIOD ); chart.setHideLegend( true ); - chart.setVerticalLabels( true ); chart.getIndicators().add( indicator ); chart.setPeriods( periods ); chart.setOrganisationUnits( parent.getSortedChildren() ); @@ -281,29 +285,15 @@ } public JFreeChart getJFreeChart( List indicators, List dataElements, - List dataSets, List periods, List organisationUnits, String dimension, + List dataSets, List periods, List organisationUnits, + String series, String category, String filter, boolean regression, I18nFormat format ) { Chart chart = new Chart(); - if ( indicators != null && !indicators.isEmpty() ) - { - chart.setName( getTitle( indicators.get( 0 ), periods, organisationUnits, format ) ); - } - else if ( dataElements != null && !dataElements.isEmpty() ) - { - chart.setName( getTitle( dataElements.get( 0 ), periods, organisationUnits, format ) ); - } - else if ( dataSets != null && !dataSets.isEmpty() ) - { - chart.setName( getTitle( dataSets.get( 0 ), periods, organisationUnits, format ) ); - } - chart.setType( TYPE_BAR ); - chart.setDimension( dimension ); + chart.setDimensions( series, category, filter ); chart.setHideLegend( false ); - chart.setVerticalLabels( true ); - chart.setHorizontalPlotOrientation( false ); chart.setRegression( regression ); chart.setIndicators( indicators ); chart.setDataElements( dataElements ); @@ -311,6 +301,7 @@ chart.setPeriods( periods ); chart.setOrganisationUnits( organisationUnits ); chart.setFormat( format ); + chart.setName( chart.getTitle() ); chart.init(); @@ -571,24 +562,6 @@ } /** - * Returns a bar3d renderer. - */ - private BarRenderer getBar3DRenderer() - { - BarRenderer3D renderer = new BarRenderer3D(); - - renderer.setMaximumBarWidth( 0.07 ); - - for ( int i = 0; i < colors.length; i++ ) - { - renderer.setSeriesPaint( i, colors[i] ); - renderer.setShadowVisible( false ); - } - - return renderer; - } - - /** * Returns a line and shape renderer. */ private LineAndShapeRenderer getLineRenderer() @@ -604,29 +577,12 @@ } /** - * Returns a line3d renderer. - */ - private LineRenderer3D getLineRenderer3D() - { - LineRenderer3D renderer = new LineRenderer3D(); - - for ( int i = 0; i < colors.length; i++ ) - { - renderer.setSeriesPaint( i, colors[i] ); - } - - return renderer; - } - - /** * Returns a JFreeChart of type defined in the chart argument. */ private JFreeChart getJFreeChart( Chart chart, boolean subTitle ) { final BarRenderer barRenderer = getBarRenderer(); - final BarRenderer bar3dRenderer = getBar3DRenderer(); final LineAndShapeRenderer lineRenderer = getLineRenderer(); - final LineRenderer3D line3dRenderer = getLineRenderer3D(); // --------------------------------------------------------------------- // Plot @@ -640,23 +596,15 @@ { plot = new CategoryPlot( dataSets[0], new CategoryAxis(), new NumberAxis(), lineRenderer ); } - if ( chart.isType( TYPE_LINE3D ) ) - { - plot = new CategoryPlot( dataSets[0], new CategoryAxis(), new NumberAxis(), line3dRenderer ); - } - else if ( chart.isType( TYPE_BAR3D ) ) - { - plot = new CategoryPlot( dataSets[0], new CategoryAxis(), new NumberAxis(), bar3dRenderer ); - } else if ( chart.isType( TYPE_BAR ) ) { plot = new CategoryPlot( dataSets[0], new CategoryAxis(), new NumberAxis(), barRenderer ); } - else if ( chart.isType( TYPE_PIE ) || chart.isType( TYPE_PIE3D ) ) + else if ( chart.isType( TYPE_PIE ) ) { return getMultiplePieChart( chart, dataSets ); } - else if ( chart.isType( TYPE_STACKED_BAR ) || chart.isType( TYPE_STACKED_BAR3D ) ) + else if ( chart.isType( TYPE_STACKED_BAR ) ) { return getStackedBarChart( chart, dataSets[0] ); } @@ -683,15 +631,14 @@ if ( subTitle ) { - jFreeChart.addSubtitle( getSubTitle( chart, chart.getFormat() ) ); + jFreeChart.addSubtitle( getSubTitle( chart ) ); } // --------------------------------------------------------------------- // Plot orientation // --------------------------------------------------------------------- - plot.setOrientation( chart.isHorizontalPlotOrientation() ? PlotOrientation.HORIZONTAL - : PlotOrientation.VERTICAL ); + plot.setOrientation( PlotOrientation.VERTICAL ); plot.setDatasetRenderingOrder( DatasetRenderingOrder.FORWARD ); // --------------------------------------------------------------------- @@ -699,8 +646,7 @@ // --------------------------------------------------------------------- CategoryAxis xAxis = plot.getDomainAxis(); - xAxis.setCategoryLabelPositions( chart.isVerticalLabels() ? CategoryLabelPositions.UP_45 - : CategoryLabelPositions.STANDARD ); + xAxis.setCategoryLabelPositions( CategoryLabelPositions.UP_45 ); xAxis.setLabel( chart.getDomainAxixLabel() ); ValueAxis yAxis = plot.getRangeAxis(); @@ -718,20 +664,17 @@ private JFreeChart getStackedBarChart( Chart chart, CategoryDataset dataSet ) { - PlotOrientation orientation = chart.isHorizontalPlotOrientation() ? PlotOrientation.HORIZONTAL - : PlotOrientation.VERTICAL; - JFreeChart stackedBarChart = null; if ( chart.isType( TYPE_STACKED_BAR ) ) { stackedBarChart = ChartFactory.createStackedBarChart( chart.getName(), chart.getDomainAxixLabel(), - chart.getRangeAxisLabel(), dataSet, orientation, true, false, false ); + chart.getRangeAxisLabel(), dataSet, PlotOrientation.VERTICAL, true, false, false ); } else { stackedBarChart = ChartFactory.createStackedBarChart3D( chart.getName(), chart.getDomainAxixLabel(), - chart.getRangeAxisLabel(), dataSet, orientation, true, false, false ); + chart.getRangeAxisLabel(), dataSet, PlotOrientation.VERTICAL, true, false, false ); } CategoryPlot plot = (CategoryPlot) stackedBarChart.getPlot(); @@ -739,11 +682,10 @@ plot.setOutlinePaint( Color.WHITE ); CategoryAxis xAxis = plot.getDomainAxis(); - xAxis.setCategoryLabelPositions( chart.isVerticalLabels() ? CategoryLabelPositions.UP_45 - : CategoryLabelPositions.STANDARD ); + xAxis.setCategoryLabelPositions( CategoryLabelPositions.UP_45 ); stackedBarChart.getTitle().setFont( titleFont ); - stackedBarChart.addSubtitle( getSubTitle( chart, chart.getFormat() ) ); + stackedBarChart.addSubtitle( getSubTitle( chart ) ); stackedBarChart.setAntiAlias( true ); return stackedBarChart; @@ -765,7 +707,7 @@ } multiplePieChart.getTitle().setFont( titleFont ); - multiplePieChart.addSubtitle( getSubTitle( chart, chart.getFormat() ) ); + multiplePieChart.addSubtitle( getSubTitle( chart ) ); multiplePieChart.getLegend().setItemFont( subTitleFont ); multiplePieChart.setBackgroundPaint( Color.WHITE ); multiplePieChart.setAntiAlias( true ); @@ -790,40 +732,64 @@ return multiplePieChart; } - private boolean isIndicatorChart( Chart chart ) - { - return chart.isDimension( DIMENSION_INDICATOR_PERIOD ) - || chart.isDimension( DIMENSION_ORGANISATIONUNIT_INDICATOR ) - || chart.isDimension( DIMENSION_PERIOD_INDICATOR ); - } - - private boolean isDataElementChart( Chart chart ) - { - return chart.isDimension( DIMENSION_DATAELEMENT_PERIOD ) - || chart.isDimension( DIMENSION_ORGANISATIONUNIT_DATAELEMENT ) - || chart.isDimension( DIMENSION_PERIOD_DATAELEMENT ); - } - - private boolean isCompletenessChart( Chart chart ) - { - return chart.isDimension( DIMENSION_COMPLETENESS_PERIOD ) - || chart.isDimension( DIMENSION_ORGANISATIONUNIT_COMPLETENESS ) - || chart.isDimension( DIMENSION_PERIOD_COMPLETENESS ); - } - - private boolean hasPeriodDimension( Chart chart ) - { - return chart.isDimension( DIMENSION_PERIOD_INDICATOR ) - || chart.isDimension( DIMENSION_INDICATOR_PERIOD ) - || chart.isDimension( DIMENSION_PERIOD_DATAELEMENT ) - || chart.isDimension( DIMENSION_DATAELEMENT_PERIOD ) - || chart.isDimension( DIMENSION_PERIOD_COMPLETENESS ) - || chart.isDimension( DIMENSION_COMPLETENESS_PERIOD ); - } - + private CategoryDataset[] getCategoryDataSet( Chart chart ) + { + Map valueMap = reportTableManager.getAggregatedValueMap( chart ); + + DefaultCategoryDataset regularDataSet = new DefaultCategoryDataset(); + DefaultCategoryDataset regressionDataSet = new DefaultCategoryDataset(); + + SimpleRegression regression = new SimpleRegression(); + + double count = 0; + + for ( NameableObject series : chart.series() ) + { + for ( NameableObject category : chart.category() ) + { + count++; + + String key = getIdentifier( Arrays.asList( series, category, chart.filter() ) ); + + Double value = valueMap.get( key ); + + regularDataSet.addValue( value, series.getName(), category.getName() ); + + if ( chart.isRegression() && MathUtils.isEqual( value, MathUtils.ZERO ) ) + { + regression.addData( ++count, value ); + } + } + } + + if ( chart.isRegression() ) // Period must be category + { + count = 0; + + for ( NameableObject series : chart.series() ) + { + for ( NameableObject category : chart.category() ) + { + final double value = regression.predict( count++ ); + + // Enough values must exist for regression + + if ( !Double.isNaN( value ) ) + { + regressionDataSet.addValue( value, TREND_PREFIX + series.getName(), category.getName() ); + + } + } + } + } + + return new CategoryDataset[] { regularDataSet, regressionDataSet }; + } + /** * Returns a DefaultCategoryDataSet based on aggregated data for the chart. */ + /* private CategoryDataset[] getCategoryDataSet( Chart chart ) { boolean realTimeAggregation = systemSettingManager.getSystemSetting( KEY_AGGREGATION_STRATEGY, @@ -872,10 +838,6 @@ { shortName = dataElements.get( i ).getShortName(); } - else if ( completenessChart ) - { - shortName = dataSets.get( i ).getShortName(); - } if ( hasPeriodDimension( chart ) ) { @@ -899,31 +861,16 @@ aggregationService.getAggregatedDataValue( dataElements.get( i ), null, period.getStartDate(), period.getEndDate(), selectedOrganisationUnit ) : aggregatedDataValueService.getAggregatedValue( dataElements.get( i ), period, selectedOrganisationUnit ); } - else if ( completenessChart ) - { - List dataSetCompleteness = new ArrayList( - dataSetCompletenessService.getDataSetCompleteness( period.getId(), - Arrays.asList( selectedOrganisationUnit.getId() ), dataSets.get( i ).getId() ) ); - - if ( !dataSetCompleteness.isEmpty() ) - { - DataSetCompletenessResult dataSetCompletenessResult = dataSetCompleteness.get( 0 ); - value = dataSetCompletenessResult.getPercentage(); - } - else - { - value = 0d; - } - } - - if ( chart.isDimension( DIMENSION_PERIOD_INDICATOR ) - || chart.isDimension( DIMENSION_PERIOD_DATAELEMENT ) - || chart.isDimension( DIMENSION_PERIOD_COMPLETENESS ) ) + + // categorydataset: value - series - category + + if ( chart.isDimension( DIMENSION_PERIOD_INDICATOR ) // if category is PERIOD + || chart.isDimension( DIMENSION_PERIOD_DATAELEMENT ) ) { regularDataSet.addValue( value != null ? value : 0, shortName, chart.getFormat() .formatPeriod( period ) ); } - else + else // if category is DATA { regularDataSet.addValue( value != null ? value : 0, chart.getFormat().formatPeriod( period ), shortName ); @@ -945,7 +892,7 @@ columnIndex = 0; - if ( chart.isRegression() ) + if ( chart.isRegression() ) // Regression only when category is PERIOD { for ( Period period : chart.getAllPeriods() ) { @@ -962,9 +909,8 @@ } } } - else if ( chart.isDimension( DIMENSION_ORGANISATIONUNIT_INDICATOR ) - || chart.isDimension( DIMENSION_ORGANISATIONUNIT_DATAELEMENT ) - || chart.isDimension( DIMENSION_ORGANISATIONUNIT_COMPLETENESS ) ) + else if ( chart.isDimension( DIMENSION_ORGANISATIONUNIT_INDICATOR ) // if category is ORG UNIT + || chart.isDimension( DIMENSION_ORGANISATIONUNIT_DATAELEMENT ) ) { // --------------------------------------------------------- // Regular dataset @@ -986,22 +932,6 @@ aggregationService.getAggregatedDataValue( dataElements.get( i ), null, selectedPeriod.getStartDate(), selectedPeriod.getEndDate(), unit ) : aggregatedDataValueService.getAggregatedValue( dataElements.get( i ), selectedPeriod, unit ); } - else if ( completenessChart ) - { - List dataSetCompleteness = new ArrayList( - dataSetCompletenessService.getDataSetCompleteness( selectedPeriod.getId(), - Arrays.asList( unit.getId() ), dataSets.get( i ).getId() ) ); - - if ( !dataSetCompleteness.isEmpty() ) - { - DataSetCompletenessResult dataSetCompletenessResult = dataSetCompleteness.get( 0 ); - value = dataSetCompletenessResult.getPercentage(); - } - else - { - value = 0d; - } - } regularDataSet.addValue( value != null ? value : 0, shortName, unit.getShortName() ); @@ -1015,92 +945,18 @@ } return new CategoryDataset[]{regularDataSet, regressionDataSet}; - } + }*/ - /** - * Returns a title based on the chart meta data. - */ - private String getTitle( NameableObject nameableObject, List periods, - List organisationUnits, I18nFormat format ) + private TextTitle getSubTitle( Chart chart ) { - String title = ""; - - if ( nameableObject != null ) - { - title += nameableObject.getShortName() + TITLE_SEPARATOR; - } - - if ( periods != null && periods.size() > 0 ) - { - title += format.formatPeriod( periods.get( 0 ) ) + TITLE_SEPARATOR; - } - - if ( organisationUnits != null && organisationUnits.size() > 0 ) - { - title += organisationUnits.get( 0 ).getShortName() + TITLE_SEPARATOR; - } - - if ( title.length() == 0 ) - { - title = DEFAULT_TITLE_PIVOT_CHART; - } - else - { - title = title.substring( 0, (title.length() - TITLE_SEPARATOR.length()) ); - } - + TextTitle title = new TextTitle(); + + title.setFont( subTitleFont ); + title.setText( chart.getTitle() ); + 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_INDICATOR ) && chart.getAllOrganisationUnits().size() > 0 ) - { - subTitle.setText( chart.getAllOrganisationUnits().get( 0 ).getName() ); - } - else if ( chart.isDimension( DIMENSION_ORGANISATIONUNIT_INDICATOR ) && chart.getAllPeriods().size() > 0 ) - { - subTitle.setText( format.formatPeriod( chart.getAllPeriods().get( 0 ) ) ); - } - else if ( chart.isDimension( DIMENSION_INDICATOR_PERIOD ) && chart.getIndicators().size() > 0 ) - { - subTitle.setText( chart.getAllOrganisationUnits().get( 0 ).getName() ); - } - else if ( chart.isDimension( DIMENSION_PERIOD_DATAELEMENT ) && chart.getAllOrganisationUnits().size() > 0 ) - { - subTitle.setText( chart.getAllOrganisationUnits().get( 0 ).getName() ); - } - else if ( chart.isDimension( DIMENSION_ORGANISATIONUNIT_DATAELEMENT ) && chart.getAllPeriods().size() > 0 ) - { - subTitle.setText( format.formatPeriod( chart.getAllPeriods().get( 0 ) ) ); - } - else if ( chart.isDimension( DIMENSION_DATAELEMENT_PERIOD ) && chart.getDataElements().size() > 0 ) - { - subTitle.setText( chart.getAllOrganisationUnits().get( 0 ).getName() ); - } - else if ( chart.isDimension( DIMENSION_PERIOD_COMPLETENESS ) && chart.getAllOrganisationUnits().size() > 0 ) - { - subTitle.setText( chart.getAllOrganisationUnits().get( 0 ).getName() ); - } - else if ( chart.isDimension( DIMENSION_ORGANISATIONUNIT_COMPLETENESS ) && chart.getAllPeriods().size() > 0 ) - { - subTitle.setText( format.formatPeriod( chart.getAllPeriods().get( 0 ) ) ); - } - else if ( chart.isDimension( DIMENSION_COMPLETENESS_PERIOD ) && chart.getDataSets().size() > 0 ) - { - subTitle.setText( chart.getAllOrganisationUnits().get( 0 ).getName() ); - } - - return subTitle; - } - + // ------------------------------------------------------------------------- // CRUD operations // ------------------------------------------------------------------------- === modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/jdbc/JDBCReportTableManager.java' --- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/jdbc/JDBCReportTableManager.java 2011-02-23 21:08:31 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/jdbc/JDBCReportTableManager.java 2011-12-21 20:06:49 +0000 @@ -35,6 +35,7 @@ import org.amplecode.quick.StatementHolder; import org.amplecode.quick.StatementManager; +import org.hisp.dhis.chart.Chart; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dataelement.DataElementCategoryOption; import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; @@ -45,6 +46,8 @@ import org.hisp.dhis.reporttable.ReportTable; import org.hisp.dhis.system.util.ConversionUtils; import org.hisp.dhis.system.util.TextUtils; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.support.rowset.SqlRowSet; /** * @author Lars Helge Overland @@ -63,6 +66,13 @@ { this.statementManager = statementManager; } + + private JdbcTemplate jdbcTemplate; + + public void setJdbcTemplate( JdbcTemplate jdbcTemplate ) + { + this.jdbcTemplate = jdbcTemplate; + } // ------------------------------------------------------------------------- // ReportTableManager implementation @@ -70,7 +80,7 @@ public Map getAggregatedValueMap( ReportTable reportTable ) { - // TODO move agg value methods to agg datavalueservice and move this method to service layer? + // TODO use jdbc template StatementHolder holder = statementManager.getHolder(); @@ -196,4 +206,57 @@ holder.close(); } } + + public Map getAggregatedValueMap( Chart chart ) + { + // A bit misplaced but we will merge chart and report table soon + + Map map = new HashMap(); + + String dataElementIds = TextUtils.getCommaDelimitedString( + ConversionUtils.getIdentifiers( DataElement.class, chart.getDataElements() ) ); + String indicatorIds = TextUtils.getCommaDelimitedString( + ConversionUtils.getIdentifiers( Indicator.class, chart.getIndicators() ) ); + String periodIds = TextUtils.getCommaDelimitedString( + ConversionUtils.getIdentifiers( Period.class, chart.getAllPeriods() ) ); + String unitIds = TextUtils.getCommaDelimitedString( + ConversionUtils.getIdentifiers( OrganisationUnit.class, chart.getAllOrganisationUnits() ) ); + + if ( chart.hasDataElements() ) + { + final String sql = "SELECT dataelementid, periodid, organisationunitid, SUM(value) FROM aggregateddatavalue " + + "WHERE dataelementid IN (" + dataElementIds + ") AND periodid IN (" + periodIds + ") AND organisationunitid IN (" + unitIds + ") " + + "GROUP BY dataelementid, periodid, organisationunitid"; // Sum of category option combos + + SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql ); + + while ( rowSet.next() ) + { + String id = getIdentifier( getIdentifier( DataElement.class, rowSet.getInt( 1 ) ), + getIdentifier( Period.class, rowSet.getInt( 2 ) ), + getIdentifier( OrganisationUnit.class, rowSet.getInt( 3 ) ) ); + + map.put( id, rowSet.getDouble( 4 ) ); + } + } + + if ( chart.hasIndicators() ) + { + final String sql = "SELECT indicatorid, periodid, organisationunitid, value FROM aggregatedindicatorvalue " + + "WHERE indicatorid IN (" + indicatorIds + ") AND periodid IN (" + periodIds + ") AND organisationunitid IN (" + unitIds + ")"; + + SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql ); + + while ( rowSet.next() ) + { + String id = getIdentifier( getIdentifier( Indicator.class, rowSet.getInt( 1 ) ), + getIdentifier( Period.class, rowSet.getInt( 2 ) ), + getIdentifier( OrganisationUnit.class, rowSet.getInt( 3 ) ) ); + + map.put( id, rowSet.getDouble( 4 ) ); + } + } + + return map; + } } === modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/jdbc/ReportTableManager.java' --- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/jdbc/ReportTableManager.java 2011-02-23 21:08:31 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/jdbc/ReportTableManager.java 2011-12-21 20:06:49 +0000 @@ -29,6 +29,7 @@ import java.util.Map; +import org.hisp.dhis.chart.Chart; import org.hisp.dhis.reporttable.ReportTable; /** @@ -40,9 +41,16 @@ String ID = ReportTableManager.class.getName(); /** - * Generates a map with a key identifiying the dimensions of each value. + * Generates a map with a key identifying the dimensions of each value. * * @param reportTable the ReportTable for which to create the value map. */ Map getAggregatedValueMap( ReportTable reportTable ); + + /** + * Generates a map with a key identifying the dimensions of each value. + * + * @param chart the Chart for which to create the value map. + */ + Map getAggregatedValueMap( Chart chart ); } === modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml 2011-12-14 16:53:56 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml 2011-12-21 20:06:49 +0000 @@ -15,6 +15,7 @@ + @@ -86,9 +87,8 @@ - - + @@ -354,7 +354,6 @@ method="intercept" /> - - - @@ -31,10 +29,6 @@ - - - - === modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java' --- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java 2011-06-12 08:23:05 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java 2011-12-21 20:31:10 +0000 @@ -43,6 +43,7 @@ public class MathUtils { public static final double INVALID = -1.0; + public static final Double ZERO = new Double( 0 ); private static final double TOLERANCE = 0.01; === modified file 'dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java' --- dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java 2011-12-19 16:44:56 +0000 +++ dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java 2011-12-21 20:06:49 +0000 @@ -821,10 +821,10 @@ Chart chart = new Chart(); chart.setName( "Chart" + uniqueCharacter ); - chart.setDimension( Chart.DIMENSION_PERIOD_INDICATOR ); chart.setIndicators( indicators ); chart.setPeriods( periods ); chart.setOrganisationUnits( units ); + chart.setDimensions( Chart.DIMENSION_DATA, Chart.DIMENSION_PERIOD, Chart.DIMENSION_ORGANISATIONUNIT ); return chart; } === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/chart/action/GenerateChartAction.java' --- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/chart/action/GenerateChartAction.java 2011-10-29 14:16:54 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/chart/action/GenerateChartAction.java 2011-12-21 20:06:49 +0000 @@ -148,11 +148,25 @@ this.organisationUnitId = organisationUnitId; } - private String dimension; - - public void setDimension( String dimension ) - { - this.dimension = dimension; + private String series; + + public void setSeries( String series ) + { + this.series = series; + } + + private String category; + + public void setCategory( String category ) + { + this.category = category; + } + + private String filter; + + public void setFilter( String filter ) + { + this.filter = filter; } private boolean regression; @@ -240,8 +254,8 @@ height = 500; - chart = chartService.getJFreeChart( indicators, dataElements, dataSets, periods, organisationUnits, dimension, - regression, format ); + chart = chartService.getJFreeChart( indicators, dataElements, dataSets, periods, organisationUnits, + series, category, filter, regression, format ); return SUCCESS; } === 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-12-21 11:19:47 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/chart/action/SaveChartAction.java 2011-12-21 20:41:22 +0000 @@ -150,11 +150,25 @@ this.type = type; } - private String dimension; - - public void setDimension( String dimension ) - { - this.dimension = dimension; + private String series; + + public void setSeries( String series ) + { + this.series = series; + } + + private String category; + + public void setCategory( String category ) + { + this.category = category; + } + + private String filter; + + public void setFilter( String filter ) + { + this.filter = filter; } private boolean hideLegend; @@ -164,20 +178,6 @@ this.hideLegend = hideLegend; } - private boolean verticalLabels; - - public void setVerticalLabels( boolean verticalLabels ) - { - this.verticalLabels = verticalLabels; - } - - private boolean horizontalPlotOrientation; - - public void setHorizontalPlotOrientation( boolean horizontalPlotOrientation ) - { - this.horizontalPlotOrientation = horizontalPlotOrientation; - } - private boolean regression; public void setRegression( boolean regression ) @@ -359,10 +359,10 @@ chart.setRangeAxisLabel( StringUtils.trimToNull( rangeAxisLabel ) ); chart.setHideSubtitle( hideSubtitle ); chart.setType( type ); - chart.setDimension( dimension ); + chart.setSeries( series ); + chart.setCategory( category ); + chart.setFilter( filter ); chart.setHideLegend( hideLegend ); - chart.setVerticalLabels( verticalLabels ); - chart.setHorizontalPlotOrientation( horizontalPlotOrientation ); chart.setRegression( regression ); chart.setTargetLine( targetLine ); chart.setTargetLineValue( targetLineValue ); === 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-12-21 11:19:47 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addChartForm.vm 2011-12-21 22:11:29 +0000 @@ -32,20 +32,14 @@ $i18n.getString( "create_period_by_indicator_chart" ) #elseif( $dimension == "period_dataElement" ) $i18n.getString( "create_period_by_dataelement_chart" ) - #elseif( $dimension == "period_completeness" ) - $i18n.getString( "create_period_by_completeness_chart" ) #elseif ( $dimension == "organisationUnit" ) $i18n.getString( "create_indicator_by_organisation_unit_chart" ) #elseif ( $dimension == "organisationUnit_dataElement" ) $i18n.getString( "create_dataelement_by_organisation_unit_chart" ) - #elseif ( $dimension == "organisationUnit_completeness" ) - $i18n.getString( "create_completeness_by_organisation_unit_chart" ) #elseif ( $dimension == "indicator" ) $i18n.getString( "create_indicator_by_period_chart" ) #elseif ( $dimension == "dataElement_period" ) $i18n.getString( "create_dataelement_by_period_chart" ) - #elseif ( $dimension == "completeness_period" ) - $i18n.getString( "create_completeness_by_period_chart" ) #end #end @@ -56,6 +50,20 @@ +#if ( $dimension == "period" || $dimension == "period_dataElement" ) + + + +#elseif ( $dimension == "indicator" || $dimension == "dataElement_period" ) + + + +#elseif ( $dimension == "organisationUnit" || $dimension == "organisationUnit_dataElement" ) + + + +#end + @@ -80,14 +88,10 @@ @@ -96,14 +100,6 @@ - - - - - - - - === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewChartForm.vm' --- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewChartForm.vm 2011-12-21 11:19:47 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewChartForm.vm 2011-12-21 22:11:29 +0000 @@ -28,11 +28,8 @@ - - ## - ##
$i18n.getString( "chart" )