sk.baka.webvm.misc
Class DivGraph

java.lang.Object
  extended by sk.baka.webvm.misc.DivGraph

public final class DivGraph
extends Object

Draws stacked bars.

Author:
Martin Vysny

Field Summary
static int MEMSTAT_BAR_HEIGHT
          The height of a memory status bar.
 
Method Summary
static String drawMemoryStatus(MemoryUsage usage, int width)
          Converts a memory usage to a horizontal bar graph.
static String drawStackedBar(GraphStyle style, int[] values, int max, boolean floatLeft)
          Draws a stacked bar graph.
static void drawStackedBar(GraphStyle style, int[] values, int max, boolean floatLeft, StringBuilder sb)
          Draws a stacked bar graph.
(package private) static int[] toPixels(int[] values, int max, int maxPixels)
          Converts given value array into pixel dimensions for each value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MEMSTAT_BAR_HEIGHT

public static final int MEMSTAT_BAR_HEIGHT
The height of a memory status bar.

See Also:
Constant Field Values
Method Detail

drawStackedBar

public static String drawStackedBar(GraphStyle style,
                                    int[] values,
                                    int max,
                                    boolean floatLeft)
Draws a stacked bar graph.

Parameters:
style - the graph style, must be valid.
values - the values to draw. The array must be sorted from least to highest. Negative values are not permitted.
max - the maximum value. A transparent div will be added at the end if necessary.
floatLeft - if true then a float:left style is added to ensure that next HTML content is positioned to the right of this bar.
Returns:
a html source

drawStackedBar

public static void drawStackedBar(GraphStyle style,
                                  int[] values,
                                  int max,
                                  boolean floatLeft,
                                  StringBuilder sb)
Draws a stacked bar graph.

Parameters:
style - the graph style, must be valid.
values - the values to draw. The array must be sorted from least to highest. Negative values are not permitted.
max - the maximum value. A transparent div will be added at the end if necessary.
floatLeft - if true then a float:left style is added to ensure that next HTML content is positioned to the right of this bar.
sb - puts the HTML code here.

toPixels

static int[] toPixels(int[] values,
                      int max,
                      int maxPixels)
Converts given value array into pixel dimensions for each value.

Parameters:
values - the values to convert. The array must be sorted from least to highest. Negative values are not permitted.
max - the maximum value to draw.
maxPixels - the desired pixel dimension.
Returns:
a sorted list of pixel dimensions. Contains one additional value for the max value.
Throws:
IllegalArgumentException - if the values is empty, max is not a positive number or maxPixels is not a positive number
NullPointerException - if the values array is null

drawMemoryStatus

public static String drawMemoryStatus(MemoryUsage usage,
                                      int width)
Converts a memory usage to a horizontal bar graph.

Parameters:
usage - the memory usage. Should be converted to megabytes as longs will be converted to integers.
width - width of result in pixels.
Returns:
a string representation of a horizontal bar line.


Copyright © 2010 Baka. All Rights Reserved.