dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #23820
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11607: Map generation, made sure maps fit well within dashboard items
------------------------------------------------------------
revno: 11607
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-08-07 16:42:55 +0200
message:
Map generation, made sure maps fit well within dashboard items
modified:
dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapGenerationService.java
dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/MapUtils.java
dhis-2/dhis-services/dhis-service-mapgeneration/src/test/java/org/hisp/dhis/mapgenerator/MapUtilsTest.java
dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/dashboard.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-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapGenerationService.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapGenerationService.java 2013-08-07 14:07:18 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapGenerationService.java 2013-08-07 14:42:55 +0000
@@ -194,8 +194,7 @@
int radiusLow = !isIndicator ? mapView.getRadiusLow() : DEFAULT_RADIUS_LOW;
int radiusHigh = !isIndicator ? mapView.getRadiusHigh() : DEFAULT_RADIUS_HIGH;
- // Get the low and high colors, typically in hexadecimal form, e.g.
- // '#ff3200' is an orange color
+ // Get the low and high colors, typically in hexadecimal form, e.g. #ff3200
Color colorLow = MapUtils.createColorFromString( StringUtils.trimToNull( mapView.getColorLow() ) != null ? mapView.getColorLow()
: DEFAULT_COLOR_LOW );
Color colorHigh = MapUtils.createColorFromString( StringUtils.trimToNull( mapView.getColorHigh() ) != null ? mapView.getColorHigh()
=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/MapUtils.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/MapUtils.java 2013-08-07 14:32:02 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/MapUtils.java 2013-08-07 14:42:55 +0000
@@ -177,7 +177,7 @@
ReferencedEnvelope mapBounds = mapContent.getMaxBounds();
double widthToHeightFactor = mapBounds.getSpan( 0 ) / mapBounds.getSpan( 1 );
- int[] widthHeight = getWidthHeight( maxWidth, maxHeight, widthToHeightFactor );
+ int[] widthHeight = getWidthHeight( maxWidth, maxHeight, LegendSet.LEGEND_TOTAL_WIDTH, 0, widthToHeightFactor );
//LegendSet.LEGEND_TOTAL_WIDTH;
@@ -198,19 +198,22 @@
}
/**
- * Calcuates the width and height of an two-dimensional area. If width is set,
- * the width will be used and the height will be calculated. If the height is
- * set, the height will be used and the width will be calculated. If both width
- * and height are set, the width or height will be adjusted to the greatest
- * value possible without exceeding any of max width and max height.
+ * Calcuates the width and height of an two-dimensional area. If width is not
+ * null, the width will be used and the height will be calculated. If the height
+ * is not null, the height will be used and the width will be calculated. If
+ * both width and height are not null, the width or height will be adjusted
+ * to the greatest value possible without exceeding any of max width and max
+ * height.
*
* @param maxWidth the maximum width.
* @param maxHeight the maxium height.
+ * @param subtractWidth the value to subtract from final width
+ * @param subtractHeight the value to subtract from final height
* @param widthFactor the width to height factor.
* @return array where first position holds the width and second the height.
* @throws IllegalArgumentException if none of width and height are specified.
*/
- public static int[] getWidthHeight( Integer maxWidth, Integer maxHeight, double widthFactor )
+ public static int[] getWidthHeight( Integer maxWidth, Integer maxHeight, int subtractWidth, int subtractHeight, double widthFactor )
{
if ( maxWidth == null && maxHeight == null )
{
@@ -219,14 +222,19 @@
if ( maxWidth == null )
{
+ maxHeight -= subtractHeight;
maxWidth = (int) Math.ceil( maxHeight * widthFactor );
}
else if ( maxHeight == null )
{
+ maxWidth -= subtractWidth;
maxHeight = (int) Math.ceil( maxWidth / widthFactor );
}
else // Both set
{
+ maxWidth -= subtractWidth;
+ maxHeight -= subtractHeight;
+
double maxWidthFactor = (double) maxWidth / maxHeight;
if ( maxWidthFactor > widthFactor ) // Canvas wider than area
=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/test/java/org/hisp/dhis/mapgenerator/MapUtilsTest.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/test/java/org/hisp/dhis/mapgenerator/MapUtilsTest.java 2013-08-07 14:32:02 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/test/java/org/hisp/dhis/mapgenerator/MapUtilsTest.java 2013-08-07 14:42:55 +0000
@@ -37,27 +37,27 @@
@Test
public void testGetWidthHeight()
{
- assertEquals( 150, getWidthHeight( 200, 300, 0.5 )[0] );
- assertEquals( 300, getWidthHeight( 200, 300, 0.5 )[1] );
- assertEquals( 200, getWidthHeight( 200, 300, 2 )[0] );
- assertEquals( 100, getWidthHeight( 200, 300, 2 )[1] );
- assertEquals( 300, getWidthHeight( 600, 300, 1d )[0] );
- assertEquals( 300, getWidthHeight( 600, 300, 1d )[1] );
-
- assertEquals( 200, getWidthHeight( 200, null, 0.5 )[0] );
- assertEquals( 400, getWidthHeight( 200, null, 0.5 )[1] );
- assertEquals( 200, getWidthHeight( 200, null, 2 )[0] );
- assertEquals( 100, getWidthHeight( 200, null, 2 )[1] );
-
- assertEquals( 150, getWidthHeight( null, 300, 0.5 )[0] );
- assertEquals( 300, getWidthHeight( null, 300, 0.5 )[1] );
- assertEquals( 600, getWidthHeight( null, 300, 2 )[0] );
- assertEquals( 300, getWidthHeight( null, 300, 2 )[1] );
+ assertEquals( 150, getWidthHeight( 200, 300, 0, 0, 0.5 )[0] );
+ assertEquals( 300, getWidthHeight( 200, 300, 0, 0, 0.5 )[1] );
+ assertEquals( 200, getWidthHeight( 200, 300, 0, 0, 2 )[0] );
+ assertEquals( 100, getWidthHeight( 200, 300, 0, 0, 2 )[1] );
+ assertEquals( 300, getWidthHeight( 600, 300, 0, 0, 1d )[0] );
+ assertEquals( 300, getWidthHeight( 600, 300, 0, 0, 1d )[1] );
+
+ assertEquals( 200, getWidthHeight( 200, null, 0, 0, 0.5 )[0] );
+ assertEquals( 400, getWidthHeight( 200, null, 0, 0, 0.5 )[1] );
+ assertEquals( 200, getWidthHeight( 200, null, 0, 0, 2 )[0] );
+ assertEquals( 100, getWidthHeight( 200, null, 0, 0, 2 )[1] );
+
+ assertEquals( 150, getWidthHeight( null, 300, 0, 0, 0.5 )[0] );
+ assertEquals( 300, getWidthHeight( null, 300, 0, 0, 0.5 )[1] );
+ assertEquals( 600, getWidthHeight( null, 300, 0, 0, 2 )[0] );
+ assertEquals( 300, getWidthHeight( null, 300, 0, 0, 2 )[1] );
}
@Test( expected = IllegalArgumentException.class )
public void testGetWidthHeightIllegalArgument()
{
- getWidthHeight( null, null, 0.5 );
+ getWidthHeight( null, null, 0, 0, 0.5 );
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/dashboard.js'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/dashboard.js 2013-08-07 10:03:12 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/dashboard.js 2013-08-07 14:42:55 +0000
@@ -63,7 +63,7 @@
"<li id='li-${itemId}' class='liItem'><div class='item' id='${itemId}'><div class='itemHeader'><a href='javascript:dhis2.db.removeItem( \"${itemId}\" )'>${i18n_remove}</a>" +
"<a href='javascript:dhis2.db.viewImage( \"../api/maps/${id}/data?width=690\", \"${name}\" )'>${i18n_view}</a>" +
"<a href='javascript:dhis2.db.viewShareForm( \"${id}\", \"map\", \"${name}\" )'>${i18n_share}</a></div>" +
- "<img src='../api/maps/${id}/data?width=405' onclick='dhis2.db.exploreMap( \"${id}\" )' title='${i18n_click}'></div></li>"
+ "<img src='../api/maps/${id}/data?width=405&height=295' onclick='dhis2.db.exploreMap( \"${id}\" )' title='${i18n_click}'></div></li>"
};
dhis2.db.dashboardReady = function( id )