Coverage Report - sk.baka.webvm.misc.GraphStyle
 
Classes in this File Line Coverage Branch Coverage Complexity
GraphStyle
0%
0/34
0%
0/18
4.25
GraphStyle$GraphStyleEnum
0%
0/3
N/A
4.25
 
 1  
 /**
 2  
  * Copyright 2009 Martin Vysny.
 3  
  *
 4  
  * This file is part of WebVM.
 5  
  *
 6  
  * WebVM is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License, or
 9  
  * (at your option) any later version.
 10  
  *
 11  
  * WebVM is distributed in the hope that it will be useful,
 12  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14  
  * GNU General Public License for more details.
 15  
  *
 16  
  * You should have received a copy of the GNU General Public License
 17  
  * along with WebVM.  If not, see <http://www.gnu.org/licenses/>.
 18  
  */
 19  
 package sk.baka.webvm.misc;
 20  
 
 21  
 import java.io.Serializable;
 22  
 
 23  
 /**
 24  
  * Describes a style of graph to be drawn.
 25  
  * @author Martin Vysny
 26  
  */
 27  
 public final class GraphStyle implements Serializable {
 28  
 
 29  
     private static final long serialVersionUID = 1L;
 30  
     /**
 31  
      * The caption of the graph.
 32  
      */
 33  
     public String caption;
 34  
 
 35  
     /**
 36  
      * Creates new object instance.
 37  
      */
 38  0
     public GraphStyle() {
 39  0
     }
 40  
 
 41  
     /**
 42  
      * Copy-constructor.
 43  
      * @param other copy this instance, must not be null
 44  
      */
 45  0
     public GraphStyle(final GraphStyle other) {
 46  0
         vertical = other.vertical;
 47  0
         width = other.width;
 48  0
         height = other.height;
 49  0
         colors = other.colors;
 50  0
         showValues = other.showValues;
 51  0
         showPercentage = other.showPercentage;
 52  0
         yLegend = other.yLegend;
 53  0
         border = other.border;
 54  0
     }
 55  
     /**
 56  
      * Draw a legend for the Y axis.
 57  
      */
 58  0
     public boolean yLegend = false;
 59  
     /**
 60  
      * Draw a thin border around the table if not null. Use a regular HTML color specification.
 61  
      */
 62  0
     public String border = null;
 63  
     /**
 64  
      * Vertical draws vertical (zero is in the left side) or horizontal bar (zero is on the bottom).
 65  
      */
 66  0
     public boolean vertical = false;
 67  
     /**
 68  
      * The width of the graph in pixels. Must be a positive integer.
 69  
      */
 70  0
     public int width = 0;
 71  
     /**
 72  
      * The height of the graph in pixels. Must be a positive integer.
 73  
      */
 74  0
     public int height = 0;
 75  
     /**
 76  
      * Display data in given colors. Use CSS-style notation, like "red" or "#00ffee". null color is a transparent color, i.e. a div without a background.
 77  
      */
 78  0
     public String[] colors = null;
 79  
     /**
 80  
      * Display data captions in given colors. Use CSS-style notation, like "red" or "#00ffee". null color is a transparent color, i.e. a div without a background. Optional.
 81  
      */
 82  0
     public String[] fontColors = null;
 83  
     /**
 84  
      * Draw values to the graph.
 85  
      */
 86  0
     public boolean showValues = false;
 87  
     /**
 88  
      * Draw percentage values to the graph.
 89  
      */
 90  0
     public boolean showPercentage = false;
 91  
     /**
 92  
      * The graph legend.
 93  
      */
 94  0
     public GraphStyleEnum style = GraphStyleEnum.StackedBar;
 95  
 
 96  
     /**
 97  
      * A type of graph to draw.
 98  
      */
 99  0
     public static enum GraphStyleEnum {
 100  
 
 101  
         /**
 102  
          * A stacked bar graph.
 103  
          */
 104  0
         StackedBar,
 105  
         /**
 106  
          * A line graph.
 107  
          */
 108  0
         Line;
 109  
     }
 110  
 
 111  
     /**
 112  
      * Validates this value object.
 113  
      */
 114  
     public void validate() {
 115  0
         if (width <= 0) {
 116  0
             throw new IllegalArgumentException("width must be a positive integer");
 117  
         }
 118  0
         if (height <= 0) {
 119  0
             throw new IllegalArgumentException("height must be a positive integer");
 120  
         }
 121  0
         if (colors.length == 0) {
 122  0
             throw new IllegalArgumentException("colors must contain at least one color");
 123  
         }
 124  0
         if (isCaptionColorDifferToBarColor() && (colors.length != fontColors.length)) {
 125  0
             throw new IllegalArgumentException("fontColors must have the same length as colors");
 126  
         }
 127  0
         if (style == null) {
 128  0
             throw new IllegalArgumentException("style is null");
 129  
         }
 130  0
     }
 131  
 
 132  
     private boolean isCaptionColorDifferToBarColor() {
 133  0
         return (showValues || showPercentage) && (fontColors != null);
 134  
     }
 135  
 }