← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12446: Map PNG impl, more descriptive variable naming

 

------------------------------------------------------------
revno: 12446
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2013-10-06 17:18:23 +0200
message:
  Map PNG impl, more descriptive variable naming
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/Interval.java
  dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/IntervalSet.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-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-09-25 11:12:56 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapGenerationService.java	2013-10-06 15:18:23 +0000
@@ -43,6 +43,8 @@
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.mapgeneration.IntervalSet.DistributionStrategy;
 import org.hisp.dhis.mapping.Map;
+import org.hisp.dhis.mapping.MapLegend;
+import org.hisp.dhis.mapping.MapLegendSet;
 import org.hisp.dhis.mapping.MapView;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
@@ -144,17 +146,13 @@
     // -------------------------------------------------------------------------
 
     private static final String DEFAULT_COLOR_HIGH = "#ff0000";
-
     private static final String DEFAULT_COLOR_LOW = "#ffff00";
 
     private static final float DEFAULT_OPACITY = 0.75f;
-
     private static final String DEFAULT_STROKE_COLOR = "#ffffff";
 
     private static final int DEFAULT_STROKE_WIDTH = 1;
-
     private static final int DEFAULT_RADIUS_HIGH = 35;
-
     private static final int DEFAULT_RADIUS_LOW = 15;
 
     private InternalMapLayer getSingleInternalMapLayer( MapView mapView )
@@ -254,7 +252,7 @@
         // Create an interval set for this map layer that distributes its map
         // objects into their respective intervals
         // TODO Make interval length a parameter
-        IntervalSet.applyIntervalSetToMapLayer( DistributionStrategy.STRATEGY_EQUAL_RANGE, mapLayer, 5 );
+        IntervalSet.applyIntervalSetToMapLayer( DistributionStrategy.STRATEGY_EQUAL_RANGE, mapLayer, 5 ); //TODO
 
         // Update the radius of each map object in this map layer according to
         // its map object's highest and lowest values
@@ -265,6 +263,20 @@
 
         return mapLayer;
     }
+    
+    private IntervalSet getIntervalSet( MapLegendSet legendSet )
+    {
+        IntervalSet intervalSet = new IntervalSet();
+        
+        for ( MapLegend legend : legendSet.getMapLegends() )
+        {
+            Color color = MapUtils.createColorFromString( legend.getColor() );
+            
+            Interval interval = new Interval( color, legend.getStartValue(), legend.getEndValue() );
+        }
+        
+        return intervalSet;
+    }
 
     /**
      * Creates a list of aggregated map values.

=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/Interval.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/Interval.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/Interval.java	2013-10-06 15:18:23 +0000
@@ -29,7 +29,7 @@
  */
 
 import java.awt.Color;
-import java.util.LinkedList;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -49,9 +49,14 @@
     private Color color;
 
     /**
-     * The low and high boundaries of values this interval covers.
-     */
-    private double valueLow, valueHigh;
+     * The low boundary of values this interval covers.
+     */
+    private double valueLow;
+
+    /**
+     * The high boundary of values this interval covers.
+     */
+    private double valueHigh;
 
     /**
      * The map object members that fall into this interval category.
@@ -62,8 +67,15 @@
     {
         this.valueLow = valueLow;
         this.valueHigh = valueHigh;
+        this.members = new ArrayList<InternalMapObject>();
+    }
 
-        this.members = new LinkedList<InternalMapObject>();
+    public Interval( Color color, double valueLow, double valueHigh )
+    {
+        this.color = color;
+        this.valueLow = valueLow;
+        this.valueHigh = valueHigh;
+        this.members = new ArrayList<InternalMapObject>();
     }
 
     /**

=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/IntervalSet.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/IntervalSet.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/IntervalSet.java	2013-10-06 15:18:23 +0000
@@ -51,7 +51,9 @@
     private List<Interval> intervals;
 
     // The map object in this interval set with the lowest and highest values
-    private InternalMapObject objectLow, objectHigh;
+    private InternalMapObject objectLow;
+    
+    private InternalMapObject objectHigh;
 
     // The interval distrubution strategies
     public enum DistributionStrategy
@@ -129,23 +131,23 @@
         Assert.isTrue( mapLayer.getMapObjects() != null );
         Assert.isTrue( mapLayer.getMapObjects().size() > 0 );
 
-        IntervalSet set = new IntervalSet();
-        set.intervals = new LinkedList<Interval>();
+        IntervalSet intervalSet = new IntervalSet();
+        intervalSet.intervals = new LinkedList<Interval>();
 
-        set.objectLow = null;
-        set.objectHigh = null;
+        intervalSet.objectLow = null;
+        intervalSet.objectHigh = null;
 
         // Determine the objects with the min and max values
         for ( InternalMapObject mapObject : mapLayer.getMapObjects() )
         {
-            if ( set.objectLow == null || mapObject.getValue() < set.objectLow.getValue() )
+            if ( intervalSet.objectLow == null || mapObject.getValue() < intervalSet.objectLow.getValue() )
             {
-                set.objectLow = mapObject;
+                intervalSet.objectLow = mapObject;
             }
             
-            if ( set.objectHigh == null || mapObject.getValue() > set.objectHigh.getValue() )
+            if ( intervalSet.objectHigh == null || mapObject.getValue() > intervalSet.objectHigh.getValue() )
             {
-                set.objectHigh = mapObject;
+                intervalSet.objectHigh = mapObject;
             }
         }
 
@@ -154,27 +156,27 @@
         for ( int i = 0; i < length; i++ )
         {
             // Determine the boundaries the interval covers
-            double low = MapUtils.lerp( set.objectLow.getValue(), set.objectHigh.getValue(), (i + 0.0) / length );
-            double high = MapUtils.lerp( set.objectLow.getValue(), set.objectHigh.getValue(), (i + 1.0) / length );
+            double low = MapUtils.lerp( intervalSet.objectLow.getValue(), intervalSet.objectHigh.getValue(), (i + 0.0) / length );
+            double high = MapUtils.lerp( intervalSet.objectLow.getValue(), intervalSet.objectHigh.getValue(), (i + 1.0) / length );
 
             // Determine the color of the interval
             Color color = MapUtils.lerp( mapLayer.getColorLow(), mapLayer.getColorHigh(), (i + 0.5) / length );
 
             // Create and setup a new interval
-            Interval in = new Interval( low, high );
-            in.setColor( color );
+            Interval interval = new Interval( low, high );
+            interval.setColor( color );
 
             // Add it to the set
-            set.intervals.add( in );
+            intervalSet.intervals.add( interval );
         }
 
         // Distribute this map layer's objects among the intervals in the set
-        distributeAndUpdateMapObjectsForMapLayer( mapLayer, set );
+        distributeAndUpdateMapObjectsForMapLayer( mapLayer, intervalSet );
 
         // Set this interval set for the map layer
-        mapLayer.setIntervalSet( set );
+        mapLayer.setIntervalSet( intervalSet );
 
-        return set;
+        return intervalSet;
     }
 
     /**
@@ -206,25 +208,25 @@
     private static void distributeAndUpdateMapObjectsForMapLayer( InternalMapLayer mapLayer, IntervalSet set )
     {
         // For each map object, determine in which interval it belongs
-        for ( InternalMapObject obj : mapLayer.getMapObjects() )
+        for ( InternalMapObject mapObject : mapLayer.getMapObjects() )
         {
-            for ( Interval in : set.intervals )
+            for ( Interval interval : set.intervals )
             {
                 // If the map object's value is within this interval's
                 // boundaries, add it to this interval
-                if ( obj.getValue() >= in.getValueLow() && obj.getValue() <= in.getValueHigh() )
+                if ( mapObject.getValue() >= interval.getValueLow() && mapObject.getValue() <= interval.getValueHigh() )
                 {
                     // Add map object to interval and set interval for map
                     // object
-                    in.addMember( obj );
-                    obj.setInterval( in );
+                    interval.addMember( mapObject );
+                    mapObject.setInterval( interval );
 
                     // Do not add to more than one interval
                     break;
                 }
             }
 
-            Assert.isTrue( obj.getInterval() != null );
+            Assert.isTrue( mapObject.getInterval() != null );
         }
     }