dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #05126
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1701: (GIS) - finished export map to image/excel
------------------------------------------------------------
revno: 1701
committer: Tran Thanh Tri <Tran Thanh Tri@compaq>
branch nick: trunk
timestamp: Thu 2010-03-25 23:59:41 +0100
message:
(GIS) - finished export map to image/excel
modified:
dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportExcelAction.java
dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportImageAction.java
dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/export/SVGDocument.java
dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/index.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-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportExcelAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportExcelAction.java 2010-03-25 19:27:31 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportExcelAction.java 2010-03-25 22:59:41 +0000
@@ -201,11 +201,11 @@
this.includeValues = includeValues;
}
- private boolean includeLegend;
+ private boolean includeLegends;
- public void setIncludeLegend( boolean includeLegend )
+ public void setIncludeLegends( boolean includeLegends )
{
- this.includeLegend = includeLegend;
+ this.includeLegends = includeLegends;
}
// -------------------------------------------
@@ -241,6 +241,11 @@
svgDocument.setPeriod( p );
svgDocument.setIndicator( i );
+
+ svgDocument.setLegends( this.legends );
+
+ svgDocument.setIncludeLegends( this.includeLegends );
+
int random = (int) (Math.random() * 1000);
@@ -295,26 +300,11 @@
sheet.addCell( new Label( titlePositionCol + 2, titlePositionRow + 1, i.getName(), header ) );
sheet.addCell( new Label( titlePositionCol, titlePositionRow + 2, i18n.getString( "period" ), header ) );
sheet.addCell( new Label( titlePositionCol + 2, titlePositionRow + 2, p.getName(), header ) );
-
- if ( includeLegend )
- {
-
- WritableCellFormat legendHeader = new WritableCellFormat();
- legendHeader.setBorder( Border.ALL, BorderLineStyle.THIN );
- legendHeader.setAlignment( Alignment.CENTRE );
- legendHeader.setBackground( Colour.ICE_BLUE );
-
- sheet.mergeCells( legendPositionCol, legendPositionRow, legendPositionCol + 2, legendPositionRow );
- sheet.addCell( new Label( legendPositionCol, legendPositionRow, i18n.getString( "legend" ), legendHeader ) );
- sheet
- .addCell( new Label( legendPositionCol, legendPositionRow + 1, i18n.getString( "color" ), legendHeader ) );
- sheet.addCell( new Label( legendPositionCol + 1, legendPositionRow + 1, i18n.getString( "min" ),
- legendHeader ) );
- sheet.addCell( new Label( legendPositionCol + 2, legendPositionRow + 1, i18n.getString( "max" ),
- legendHeader ) );
-
- }
-
+
+
+
+ /* TODO write data values*/
+
if ( includeValues )
{
WritableCellFormat datavalueHeader = new WritableCellFormat();
=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportImageAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportImageAction.java 2010-03-25 11:32:49 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportImageAction.java 2010-03-25 22:59:41 +0000
@@ -1,4 +1,5 @@
package org.hisp.dhis.mapping.action;
+
/*
* Copyright (c) 2004-2007, University of Oslo
* All rights reserved.
@@ -112,11 +113,18 @@
this.period = period;
}
- private String outputFile;
-
- public String getOutputFile()
- {
- return outputFile;
+ private String legends;
+
+ public void setLegends( String legends )
+ {
+ this.legends = legends;
+ }
+
+ private boolean includeLegends;
+
+ public void setIncludeLegends( boolean includeLegends )
+ {
+ this.includeLegends = includeLegends;
}
private Integer width;
@@ -133,32 +141,43 @@
this.height = height;
}
+ private String outputFile;
+
+ public String getOutputFile()
+ {
+ return outputFile;
+ }
+
@Override
public String execute()
throws Exception
{
Period p = periodService.getPeriod( period );
-
+
p.setName( format.formatPeriod( p ) );
-
+
Indicator i = indicatorService.getIndicator( indicator );
-
+
int random = (int) (Math.random() * 100);
File temporaryDir = locationManager.getFileForWriting( MappingService.MAP_TEMPL_DIR );
File svgTemporary = new File( temporaryDir, "svg_" + random + ".svg" );
- SVGDocument svgDocument = new SVGDocument();
-
+ SVGDocument svgDocument = new SVGDocument();
+
svgDocument.setTitle( this.title );
svgDocument.setSvg( this.svg );
-
+
svgDocument.setPeriod( p );
-
- svgDocument.setIndicator( i );
+
+ svgDocument.setIndicator( i );
+
+ svgDocument.setLegends( legends );
+
+ svgDocument.setIncludeLegends( includeLegends );
StreamUtils.writeContent( svgTemporary, svgDocument.getSVGForImage() );
=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/export/SVGDocument.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/export/SVGDocument.java 2010-03-25 11:32:49 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/export/SVGDocument.java 2010-03-25 22:59:41 +0000
@@ -1,8 +1,42 @@
package org.hisp.dhis.mapping.export;
+/*
+ * Copyright (c) 2004-2007, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+import net.sf.json.JSONSerializer;
+
import org.hisp.dhis.indicator.Indicator;
import org.hisp.dhis.period.Period;
+/**
+ * @author Tran Thanh Tri
+ * @version $Id$
+ */
public class SVGDocument
{
@@ -16,12 +50,14 @@
private String svg;
- private String legend;
+ private String legends;
private Period period;
private Indicator indicator;
+ private boolean includeLegends;
+
public SVGDocument()
{
@@ -44,6 +80,11 @@
svg_ = svg_.replaceFirst( "</svg>", title_ + period_ + indicator_ + "</svg>" );
+ if ( this.includeLegends )
+ {
+ svg_ = svg_.replaceFirst( "</svg>", this.getLegendScript( 30, 70 ) + "</svg>" );
+ }
+
return new StringBuffer( svg_ );
}
@@ -51,11 +92,102 @@
{
String svg_ = doctype + this.svg;
- svg_ = svg_.replaceFirst( "<svg", "<svg " + namespace );
-
+ svg_ = svg_.replaceFirst( "<svg", "<svg " + namespace );
+
+ if ( this.includeLegends )
+ {
+ svg_ = svg_.replaceFirst( "</svg>", this.getLegendScript( 10, 10 ) + "</svg>" );
+ }
+
return new StringBuffer( svg_ );
}
+ public String getLegendScriptForExcel()
+ {
+
+ JSONObject legend;
+
+ JSONObject json = (JSONObject) JSONSerializer.toJSON( this.legends );
+
+ JSONArray jsonLegends = json.getJSONArray( "legends" );
+
+ String result = doctype;
+ result += "<svg width='100%' height='100%' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' ";
+ result += "xmlns:attrib='http://www.carto.net/attrib/' viewBox='0 0 1 " + jsonLegends.size() + "'>";
+ result += "<g id='legend'>";
+
+ int x = 0;
+
+ int y = 0;
+
+ for ( int index = 0; index < jsonLegends.size(); index++ )
+ {
+
+ legend = jsonLegends.getJSONObject( index );
+
+ String label = legend.getString( "label" );
+
+ String color = legend.getString( "color" );
+
+ result += "<rect x='" + x + "' y='" + (y + 1) + "' height='1' width='1' fill='" + color
+ + "' stroke='#000000' stroke-width='0.001'/>";
+
+ result += "<text id=\"indicator\" x='" + (x + 1.5) + "' y='" + (y + 1) + "' font-size=\"10\"><tspan>"
+ + label + "</tspan></text>";
+
+ y += 1;
+ }
+
+ result += "</g>";
+ result += "</svg>";
+
+ return result;
+ }
+
+ private String getLegendScript( int x, int y )
+ {
+ String result = "<g id='legend'>";
+ result += "<text id=\"indicator\" x=\"" + x + "\" y=\"" + y + "\" font-size=\"14\"><tspan>Legends</tspan></text>";
+
+ JSONObject legend;
+
+ JSONObject json = (JSONObject) JSONSerializer.toJSON( this.legends );
+
+ JSONArray jsonLegends = json.getJSONArray( "legends" );
+
+ for ( int index = 0; index < jsonLegends.size(); index++ )
+ {
+
+ legend = jsonLegends.getJSONObject( index );
+
+ String label = legend.getString( "label" );
+
+ String color = legend.getString( "color" );
+
+ result += "<rect x='" + x + "' y='" + (y + 10) + "' height='10' width='30' fill='" + color
+ + "' stroke='#000000' stroke-width='1'/>";
+
+ result += "<text id=\"indicator\" x='" + (x + 35) + "' y='" + (y + 22) + "' font-size=\"12\"><tspan>"
+ + label + "</tspan></text>";
+
+ y += 10;
+ }
+
+ result += "</g>";
+
+ return result;
+ }
+
+ public boolean isIncludeLegends()
+ {
+ return includeLegends;
+ }
+
+ public void setIncludeLegends( boolean includeLegends )
+ {
+ this.includeLegends = includeLegends;
+ }
+
public String getTitle()
{
return title;
@@ -77,14 +209,14 @@
}
- public String getLegend()
+ public String getLegends()
{
- return legend;
+ return legends;
}
- public void setLegend( String legend )
+ public void setLegends( String legends )
{
- this.legend = legend;
+ this.legends = legends;
}
public Period getPeriod()
=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/index.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/index.js 2010-03-25 19:27:31 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/index.js 2010-03-25 22:59:41 +0000
@@ -615,35 +615,23 @@
value: 'Image Title'
},
{
- xtype: 'numberfield',
- id: 'export_image_width',
- fieldLabel: 'Image width',
- labelSeparator: labelseparator,
- editable: true,
- valueField: 'id',
- displayField: 'text',
- isFormField: true,
- width: combo_width_fieldset,
- minListWidth: combo_list_width_fieldset,
- mode: 'local',
- triggerAction: 'all',
- value: 1000
-
- },
- {
- xtype: 'numberfield',
- id: 'export_image_height',
- fieldLabel: 'Image height',
- labelSeparator: labelseparator,
- editable: true,
- valueField: 'id',
- displayField: 'text',
- isFormField: true,
- width: combo_width_fieldset,
- minListWidth: combo_list_width_fieldset,
- mode: 'local',
- triggerAction: 'all',
- value: 1000
+ xtype: 'combo',
+ id: 'export_image_quality',
+ fieldLabel: 'Image Quality',
+ labelSeparator: labelseparator,
+ editable: false,
+ valueField: 'id',
+ displayField: 'text',
+ isFormField: true,
+ width: combo_width_fieldset,
+ minListWidth: combo_list_width_fieldset,
+ mode: 'local',
+ triggerAction: 'all',
+ value: 2,
+ store: new Ext.data.SimpleStore({
+ fields: ['id', 'text'],
+ data: [[1, 'Small'], [2, 'Medium'], [4, 'Large']]
+ })
},
{
xtype: 'checkbox',
@@ -664,9 +652,17 @@
MASK.msg = 'Exporting image...';
MASK.show();
var svg = document.getElementById('OpenLayers.Layer.Vector_17').innerHTML;
+
+ var objectSVGDocument = document.getElementById('OpenLayers.Layer.Vector_17').childNodes[0];
+
+ var viewBox = objectSVGDocument.getAttribute('viewBox');
+
var title = Ext.getCmp('export_image_title').getValue();
- var w = Ext.getCmp('export_image_width').getValue();
- var h = Ext.getCmp('export_image_height').getValue();
+
+ var q = Ext.getCmp('export_image_quality').getValue();
+
+ var w = objectSVGDocument.getAttribute('width') * q;
+ var h = objectSVGDocument.getAttribute('height') * q;
var includeLegend = Ext.getCmp('export_image_include_legend').getValue();
var period = Ext.getCmp('period_cb').getValue();
var indicator = Ext.getCmp('indicator_cb').getValue();
@@ -675,12 +671,14 @@
method: 'POST',
params: {
title: title,
+ viewBox: viewBox,
svg: svg,
width: w,
height: h,
- includeLegend: includeLegend,
+ includeLegends: includeLegend,
period: period,
- indicator: indicator
+ indicator: indicator,
+ legends: getLegendsJSON()
},
success: function( responseObject ) {
MASK.hide();
@@ -738,8 +736,11 @@
MASK.msg = 'Exporting excel...';
MASK.show();
var title = Ext.getCmp('export_excel_title').getValue();
- var svg = document.getElementById('OpenLayers.Layer.Vector_17').innerHTML;
- var includeLegend = Ext.getCmp('export_image_include_legend').getValue();
+
+ var svg = document.getElementById('OpenLayers.Layer.Vector_17').innerHTML;
+
+
+ var includeLegend = Ext.getCmp('export_excel_include_legend').getValue();
var includeValues = Ext.getCmp('export_excel_include_value').getValue();
var period = Ext.getCmp('period_cb').getValue();
var indicator = Ext.getCmp('indicator_cb').getValue();
@@ -751,11 +752,12 @@
width:500,
height:500,
svg: svg,
- includeLegend: includeLegend,
+ includeLegends: includeLegend,
includeValues: includeValues,
period: period,
indicator: indicator,
- datavalues: EXPORTVALUES
+ datavalues: EXPORTVALUES,
+ legends: getLegendsJSON()
},
success: function( responseObject ) {
MASK.hide();
@@ -3483,6 +3485,7 @@
});
function showExportMap() {
+
if (ACTIVEPANEL == thematicMap
&& Ext.getCmp('period_cb').getValue()!=''
&& Ext.getCmp('indicator_cb').getValue()!=''
@@ -3503,6 +3506,7 @@
else {
Ext.messageRed.msg('Please render the map fist!','Form does not completed');
}
+
}
var exportMapButton = new Ext.Button({
@@ -3937,6 +3941,50 @@
});
}
+function getExportDataValueJSON( mapvalues ){
+ var json = '{';
+ json += '"datavalues":';
+ json += '[';
+ for (var i = 0; i < mapvalues.length; i++) {
+ json += '{';
+ json += '"organisation": "' + mapvalues[i].orgUnitId + '",';
+ json += '"value": "' + mapvalues[i].value + '" ';
+ if(i < mapvalues.length-1){
+ json += '},';
+ }else{
+ json += '}';
+ }
+ }
+ json += ']';
+ json += '}';
+
+ return json;
+
+}
+
+function getLegendsJSON(){
+ var legends = choropleth.imageLegend;
+ var json = '{';
+ json += '"legends":';
+ json += '[';
+
+ for ( var i=0; i<legends.length; i++ ) {
+ json += '{';
+ json += '"label": "' + legends[i].label + '",';
+ json += '"color": "' + legends[i].color + '" ';
+ if(i < legends.length-1){
+ json += '},';
+ }else{
+ json += '}';
+ }
+ }
+
+ json += ']';
+ json += '}';
+
+ return json;
+}
+
/*CHOROPLETH*/
function getChoroplethData() {
MASK.msg = 'Creating choropleth...';