Class RectangleArranger<T>

  • Type Parameters:
    T - Key type

    public class RectangleArranger<T>
    extends java.lang.Object
    This is a rather naive rectangle arrangement class. It will try to place rectangles on a canvas while maintaining the canvas size ratio as good as possible. It does not do an exhaustive search for optimizing the layout, but a greedy placement strategy, extending the canvas as little as possible.
    Since:
    0.4.0
    Author:
    Erich Schubert
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private DoubleArray heights
      Column heights
      private static Logging LOG
      Logging class
      private java.util.Map<T,​double[]> map
      Data
      private double ratio
      Target height/width ratio
      private double theight
      Height
      private double twidth
      Width
      private java.util.ArrayList<java.util.ArrayList<java.lang.Object>> usage
      Map indicating which cells are used.
      private DoubleArray widths
      Column widths
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private boolean assertConsistent()  
      protected double computeIncreaseArea​(double winc, double hinc)  
      java.util.Set<java.util.Map.Entry<T,​double[]>> entrySet()
      The items contained in the map.
      double[] get​(T object)
      Get the position data of the object
      double getHeight()
      Get the total canvas height
      double getWidth()
      Get the total canvas width
      java.util.Set<T> keySet()
      The item keys contained in the map.
      protected void logSizes()
      Debug logging
      void put​(double w, double h, T data)
      Add a new recangle.
      double relativeFill()
      Compute the relative fill.
      private void resize​(double inc)  
      protected void splitCol​(int bestex, double bestwi)  
      protected void splitRow​(int bestey, double besthi)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOG

        private static final Logging LOG
        Logging class
      • ratio

        private double ratio
        Target height/width ratio
      • twidth

        private double twidth
        Width
      • theight

        private double theight
        Height
      • usage

        private java.util.ArrayList<java.util.ArrayList<java.lang.Object>> usage
        Map indicating which cells are used.
      • map

        private java.util.Map<T,​double[]> map
        Data
    • Constructor Detail

      • RectangleArranger

        public RectangleArranger​(double ratio)
        Constructor.
        Parameters:
        ratio -
      • RectangleArranger

        public RectangleArranger​(double width,
                                 double height)
        Constructor.
        Parameters:
        width - Canvas width
        height - Canvas height
    • Method Detail

      • put

        public void put​(double w,
                        double h,
                        T data)
        Add a new recangle.
        Parameters:
        w - Width
        h - Height
        data - Data object to add (key)
      • computeIncreaseArea

        protected double computeIncreaseArea​(double winc,
                                             double hinc)
      • splitRow

        protected void splitRow​(int bestey,
                                double besthi)
      • splitCol

        protected void splitCol​(int bestex,
                                double bestwi)
      • resize

        private void resize​(double inc)
      • get

        public double[] get​(T object)
        Get the position data of the object
        Parameters:
        object - Query object
        Returns:
        Position information: x,y,w,h
      • assertConsistent

        private boolean assertConsistent()
      • logSizes

        protected void logSizes()
        Debug logging
      • relativeFill

        public double relativeFill()
        Compute the relative fill. Useful for triggering a relayout if the relative fill is not satisfactory.
        Returns:
        relative fill
      • getWidth

        public double getWidth()
        Get the total canvas width
        Returns:
        Width
      • getHeight

        public double getHeight()
        Get the total canvas height
        Returns:
        Height
      • entrySet

        public java.util.Set<java.util.Map.Entry<T,​double[]>> entrySet()
        The items contained in the map.
        Returns:
        entry set
      • keySet

        public java.util.Set<T> keySet()
        The item keys contained in the map.
        Returns:
        key set