← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12457: Map PNG, sorting of intervals (legends)

 

------------------------------------------------------------
revno: 12457
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-10-07 11:27:49 +0200
message:
  Map PNG, sorting of intervals (legends)
added:
  dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/comparator/
  dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/comparator/IntervalLowValueAscComparator.java
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/Interval.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-07 08:56:46 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapGenerationService.java	2013-10-07 09:27:49 +0000
@@ -272,7 +272,7 @@
             }
             else
             {
-                mapLayer.applyIntervalSetToMapLayer( DistributionStrategy.STRATEGY_EQUAL_RANGE, mapLayer.getClasses() );
+                mapLayer.setAutomaticIntervalSet( DistributionStrategy.STRATEGY_EQUAL_RANGE, mapLayer.getClasses() );
                 mapLayer.distributeAndUpdateMapObjectsInIntervalSet();
             }
             

=== 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-10-06 22:11:27 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/InternalMapLayer.java	2013-10-07 09:27:49 +0000
@@ -30,9 +30,11 @@
 
 import java.awt.Color;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import org.hisp.dhis.mapgeneration.IntervalSet.DistributionStrategy;
+import org.hisp.dhis.mapgeneration.comparator.IntervalLowValueAscComparator;
 import org.hisp.dhis.mapping.MapLegend;
 import org.hisp.dhis.mapping.MapLegendSet;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -166,6 +168,11 @@
         mapObject.setMapLayer( this );
     }
     
+    /**
+     * Adds a map object for the given organisation unit to this map layer.
+     * 
+     * @param unit the organisation unit.
+     */
     public void addBoundaryMapObject( OrganisationUnit unit )
     {
         InternalMapObject mapObject = new InternalMapObject();
@@ -197,6 +204,8 @@
             
             intervalSet.getIntervals().add( interval );
         }
+
+        Collections.sort( intervalSet.getIntervals(), IntervalLowValueAscComparator.INSTANCE );
         
         this.intervalSet = intervalSet;
     }
@@ -264,11 +273,11 @@
      * @param length the number of intervals in the set
      * @return the created interval set that was applied to this map layer
      */
-    public void applyIntervalSetToMapLayer( DistributionStrategy strategy, int length )
+    public void setAutomaticIntervalSet( DistributionStrategy strategy, int length )
     {
         if ( DistributionStrategy.STRATEGY_EQUAL_RANGE == strategy )
         {
-            applyEqualRangeIntervalSetToMapLayer( length );
+            setEqualRangeIntervalSetToMapLayer( length );
         }
         else if ( DistributionStrategy.STRATEGY_EQUAL_SIZE == strategy )
         {
@@ -288,7 +297,7 @@
      * @param length the number of equal sized intervals
      * @return the created interval set that was applied to this map layer
      */
-    public void applyEqualRangeIntervalSetToMapLayer( int length )
+    public void setEqualRangeIntervalSetToMapLayer( int length )
     {
         Assert.isTrue( length > 0 );
         Assert.isTrue( mapObjects != null );
@@ -329,7 +338,8 @@
             intervalSet.getIntervals().add( interval );
         }
 
-        // Set this interval set for the map layer
+        Collections.sort( intervalSet.getIntervals(), IntervalLowValueAscComparator.INSTANCE );
+        
         this.intervalSet = intervalSet;
     }
 

=== 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-10-06 15:18:23 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/Interval.java	2013-10-07 09:27:49 +0000
@@ -63,6 +63,10 @@
      */
     private List<InternalMapObject> members;
 
+    // -------------------------------------------------------------------------
+    // Constructors
+    // -------------------------------------------------------------------------
+
     public Interval( double valueLow, double valueHigh )
     {
         this.valueLow = valueLow;
@@ -78,6 +82,30 @@
         this.members = new ArrayList<InternalMapObject>();
     }
 
+    // -------------------------------------------------------------------------
+    // Logic
+    // -------------------------------------------------------------------------
+
+    /**
+     * Adds a map object to this interval category.
+     * 
+     * @param member the member to add
+     */
+    public void addMember( InternalMapObject member )
+    {
+        this.members.add( member );
+    }
+
+    @Override
+    public String toString()
+    {
+        return "[Low value: " + valueLow + ", high value: " + valueHigh + ", color: " + color + "]";
+    }
+
+    // -------------------------------------------------------------------------
+    // Getters and setters
+    // -------------------------------------------------------------------------
+
     /**
      * Gets the low value of this interval.
      * 
@@ -85,7 +113,7 @@
      */
     public double getValueLow()
     {
-        return this.valueLow;
+        return valueLow;
     }
 
     /**
@@ -105,7 +133,7 @@
      */
     public double getValueHigh()
     {
-        return this.valueHigh;
+        return valueHigh;
     }
 
     /**
@@ -125,7 +153,7 @@
      */
     public Color getColor()
     {
-        return this.color;
+        return color;
     }
 
     /**
@@ -139,16 +167,6 @@
     }
 
     /**
-     * Adds a map object to this interval category.
-     * 
-     * @param member the member to add
-     */
-    public void addMember( InternalMapObject member )
-    {
-        this.members.add( member );
-    }
-
-    /**
      * Returns a list of the members that have fallen into this interval
      * category, or null if none.
      * 
@@ -156,6 +174,6 @@
      */
     public List<InternalMapObject> getMembers()
     {
-        return this.members;
+        return members;
     }
 }

=== added directory 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/comparator'
=== added file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/comparator/IntervalLowValueAscComparator.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/comparator/IntervalLowValueAscComparator.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/comparator/IntervalLowValueAscComparator.java	2013-10-07 09:27:49 +0000
@@ -0,0 +1,48 @@
+package org.hisp.dhis.mapgeneration.comparator;
+
+/*
+ * Copyright (c) 2004-2013, 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 java.util.Comparator;
+
+import org.hisp.dhis.mapgeneration.Interval;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class IntervalLowValueAscComparator
+    implements Comparator<Interval>
+{
+    public static IntervalLowValueAscComparator INSTANCE = new IntervalLowValueAscComparator();
+    
+    @Override
+    public int compare( Interval i1, Interval i2 )
+    {
+        return new Double( i1.getValueLow() ).compareTo( new Double( i2.getValueLow() ) );
+    }
+}