← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12447: PNG maps, made legend sets follow the user-defined number of classes

 

------------------------------------------------------------
revno: 12447
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2013-10-06 19:01:11 +0200
message:
  PNG maps, made legend sets follow the user-defined number of classes
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/InternalMapLayer.java
  dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/InternalMapObject.java
  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/Legend.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-10-06 15:18:23 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapGenerationService.java	2013-10-06 17:01:11 +0000
@@ -233,6 +233,7 @@
         mapLayer.setColorLow( colorLow );
         mapLayer.setColorHigh( colorHigh );
         mapLayer.setOpacity( opacity );
+        mapLayer.setClasses( mapView.getClasses() );
         mapLayer.setStrokeColor( strokeColor );
         mapLayer.setStrokeWidth( strokeWidth );
 
@@ -252,7 +253,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 ); //TODO
+        IntervalSet.applyIntervalSetToMapLayer( DistributionStrategy.STRATEGY_EQUAL_RANGE, mapLayer, mapLayer.getClasses() );
 
         // Update the radius of each map object in this map layer according to
         // its map object's highest and lowest values

=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/InternalMapLayer.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/InternalMapLayer.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/InternalMapLayer.java	2013-10-06 17:01:11 +0000
@@ -66,6 +66,8 @@
     protected Color colorLow;
 
     protected float opacity;
+    
+    protected Integer classes;
 
     protected Color strokeColor;
 
@@ -209,6 +211,16 @@
         this.opacity = opacity;
     }
 
+    public Integer getClasses()
+    {
+        return classes;
+    }
+
+    public void setClasses( Integer classes )
+    {
+        this.classes = classes;
+    }
+
     public Color getStrokeColor()
     {
         return this.strokeColor;

=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/InternalMapObject.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/InternalMapObject.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/InternalMapObject.java	2013-10-06 17:01:11 +0000
@@ -46,7 +46,7 @@
 import com.vividsolutions.jts.geom.Polygon;
 
 /**
- * An internal representation of a map object in a map layer.
+ * An internal representation of a map object (feature) in a map layer.
  * 
  * It encapsulates all the information of an atomic object on a map, i.e. its
  * name, value, fill color, fill opacity, stroke color, stroke width, and

=== 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-10-06 15:18:23 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/IntervalSet.java	2013-10-06 17:01:11 +0000
@@ -29,7 +29,7 @@
  */
 
 import java.awt.Color;
-import java.util.LinkedList;
+import java.util.ArrayList;
 import java.util.List;
 
 import org.springframework.util.Assert;
@@ -47,15 +47,16 @@
  */
 public class IntervalSet
 {
-    // The intervals in this set
-    private List<Interval> intervals;
+    private List<Interval> intervals = new ArrayList<Interval>();
 
-    // The map object in this interval set with the lowest and highest values
     private InternalMapObject objectLow;
     
     private InternalMapObject objectHigh;
 
-    // The interval distrubution strategies
+    public IntervalSet()
+    {
+    }
+    
     public enum DistributionStrategy
     {
         STRATEGY_EQUAL_RANGE, STRATEGY_EQUAL_SIZE
@@ -132,20 +133,16 @@
         Assert.isTrue( mapLayer.getMapObjects().size() > 0 );
 
         IntervalSet intervalSet = new IntervalSet();
-        intervalSet.intervals = new LinkedList<Interval>();
-
-        intervalSet.objectLow = null;
-        intervalSet.objectHigh = null;
 
         // Determine the objects with the min and max values
         for ( InternalMapObject mapObject : mapLayer.getMapObjects() )
         {
-            if ( intervalSet.objectLow == null || mapObject.getValue() < intervalSet.objectLow.getValue() )
+            if ( intervalSet.getObjectLow() == null || mapObject.getValue() < intervalSet.getObjectLow().getValue() )
             {
                 intervalSet.objectLow = mapObject;
             }
             
-            if ( intervalSet.objectHigh == null || mapObject.getValue() > intervalSet.objectHigh.getValue() )
+            if ( intervalSet.getObjectHigh() == null || mapObject.getValue() > intervalSet.getObjectHigh().getValue() )
             {
                 intervalSet.objectHigh = mapObject;
             }
@@ -156,8 +153,8 @@
         for ( int i = 0; i < length; i++ )
         {
             // Determine the boundaries the interval covers
-            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 );
+            double low = MapUtils.lerp( intervalSet.getObjectLow().getValue(), intervalSet.getObjectHigh().getValue(), (i + 0.0) / length );
+            double high = MapUtils.lerp( intervalSet.getObjectLow().getValue(), intervalSet.getObjectHigh().getValue(), (i + 1.0) / length );
 
             // Determine the color of the interval
             Color color = MapUtils.lerp( mapLayer.getColorLow(), mapLayer.getColorHigh(), (i + 0.5) / length );
@@ -167,7 +164,7 @@
             interval.setColor( color );
 
             // Add it to the set
-            intervalSet.intervals.add( interval );
+            intervalSet.getIntervals().add( interval );
         }
 
         // Distribute this map layer's objects among the intervals in the set
@@ -190,11 +187,6 @@
      */
     private static IntervalSet applyEqualSizeIntervalSetToMapLayer( InternalMapLayer mapLayer, int length )
     {
-        Assert.isTrue( mapLayer != null );
-        Assert.isTrue( length > 0 );
-        Assert.isTrue( mapLayer.getMapObjects() != null );
-        Assert.isTrue( mapLayer.getMapObjects().size() > 0 );
-
         throw new RuntimeException( "This distribution strategy is not implemented yet!" );
     }
 
@@ -203,21 +195,19 @@
      * update each map object with its interval.
      * 
      * @param mapLayer the map layer whose objects to distribute
-     * @param set the interval set
+     * @param intervalSet the interval set
      */
-    private static void distributeAndUpdateMapObjectsForMapLayer( InternalMapLayer mapLayer, IntervalSet set )
+    private static void distributeAndUpdateMapObjectsForMapLayer( InternalMapLayer mapLayer, IntervalSet intervalSet )
     {
-        // For each map object, determine in which interval it belongs
         for ( InternalMapObject mapObject : mapLayer.getMapObjects() )
         {
-            for ( Interval interval : set.intervals )
+            for ( Interval interval : intervalSet.getIntervals() )
             {
                 // If the map object's value is within this interval's
                 // boundaries, add it to this interval
                 if ( mapObject.getValue() >= interval.getValueLow() && mapObject.getValue() <= interval.getValueHigh() )
                 {
-                    // Add map object to interval and set interval for map
-                    // object
+                    // Add map object to interval and set interval for map object
                     interval.addMember( mapObject );
                     mapObject.setInterval( interval );
 
@@ -225,8 +215,6 @@
                     break;
                 }
             }
-
-            Assert.isTrue( mapObject.getInterval() != null );
         }
     }
 
@@ -235,9 +223,9 @@
      * 
      * @return the list of intervals
      */
-    public List<Interval> getAllIntervals()
+    public List<Interval> getIntervals()
     {
-        return this.intervals;
+        return intervals;
     }
 
     /**
@@ -247,7 +235,7 @@
      */
     public InternalMapObject getObjectLow()
     {
-        return this.objectLow;
+        return objectLow;
     }
 
     /**
@@ -257,6 +245,6 @@
      */
     public InternalMapObject getObjectHigh()
     {
-        return this.objectHigh;
+        return objectHigh;
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/Legend.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/Legend.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/Legend.java	2013-10-06 17:01:11 +0000
@@ -59,7 +59,7 @@
         this.mapLayer = mapLayer;
         this.legendItems = new LinkedList<LegendItem>();
 
-        for ( Interval interval : mapLayer.getIntervalSet().getAllIntervals() )
+        for ( Interval interval : mapLayer.getIntervalSet().getIntervals() )
         {
             addLegendItem( new LegendItem( interval ) );
         }