com.davisor.graphics.chart
Class BarFactory

java.lang.Object
  extended bycom.davisor.graphics.chart.ChartFactory
      extended bycom.davisor.graphics.chart.AxisFactory
          extended bycom.davisor.graphics.chart.BarFactory
All Implemented Interfaces:
com.davisor.core.Dupable, com.davisor.core.MIMETypes, com.davisor.core.Public
Direct Known Subclasses:
ColumnBarFactory, RowBarFactory

public abstract class BarFactory
extends AxisFactory

BarFactory is a base class for chart producers that can make bar charts out of one- or multidimensional data. Bar charts support the 3D look and a wealth of chart attributes.

Bar charts visualize data as bar groups. A bar group is made out of one or more bars, where each bar represents a single value from one or more channels. A single bar is made out of one or more bar segments, where the segments represent the values from one base channel and optionally some additional cumulative channels. Bars in a bar group reside next to each other, while the bar groups are separated by symmetric gaps.

       _             _
      | |_          | |_
      |b| |         |b| | <- segment
     _|a|_|        _|a|_|
    | |r| |       | |r| | <- segment
 ___|_|_|_|___ ___|_|_|_|___
     0 1 2         1 2 3  <- sequence number
 gap       gap gap       gap
     group         group
 

Bar charts utilize the services of the AxisFactory base class, in order to prepare the chart data and attributes for rendering. This class then converts the chart data values, expressed originally in arbitrary user value data types, to the chart device coordinates, expressed in scalar pixel values. The values are then rendered using the various draw methods that this class provides.

The BarFactory subclasses implement the details of how exactly the chart bars are rendered. The subclasses do this by implementing the abstract interface that this class and it's superclass define. Please see the appropriate subclass documentation for more information.

Since:
JDK1.2
See Also:
AxisFactory.createChart(com.davisor.graphics.chart.ChartFactory.ChartContext, com.davisor.graphics.chart.ChartFactory.ChartMetrics, com.davisor.graphics.chart.ChartAttributes, com.davisor.graphics.chart.Chart), drawBar(java.awt.Graphics2D, java.awt.Paint, java.awt.Paint[], int, int, float, float, float, float, float, float, float, float, float), drawValue(java.awt.Graphics2D, java.awt.Paint, java.awt.Paint, java.awt.Font, java.lang.String, com.davisor.graphics.chart.AxisFactory.AxisMetrics, int, int, float, float, float, float, float, int, float), AxisFactory.createChart(com.davisor.graphics.chart.ChartFactory.ChartContext, com.davisor.graphics.chart.ChartFactory.ChartMetrics, com.davisor.graphics.chart.ChartAttributes, com.davisor.graphics.chart.Chart), ChartAttributes, ColumnBarFactory, PaintParameters, RowBarFactory, ShapeFactory

Nested Class Summary
protected  class BarFactory.BarEntry
          BarEntry stores the data of one bar block needed in rendering.
protected  class BarFactory.BarLabel
          BarLabel stores value label rendering information for later use.
 class BarFactory.BarMetrics
          BarMetrics implements bar chart spesific axis metrics.
 
Nested classes inherited from class com.davisor.graphics.chart.AxisFactory
AxisFactory.AxisContext, AxisFactory.AxisMetrics
 
Nested classes inherited from class com.davisor.graphics.chart.ChartFactory
ChartFactory.ChartContext, ChartFactory.ChartMetrics
 
Field Summary
protected static int NEG
           
protected static int POS
           
 
Fields inherited from class com.davisor.graphics.chart.AxisFactory
DEFAULTLABELTYPE, FLIPX, FLIPY, MAJORMARGIN, MINORMARGIN, MINSIZE
 
Fields inherited from class com.davisor.graphics.chart.ChartFactory
ALL, BRIGHT, CHANNEL, COS, DARK, DOTSEQUENCE, DOTSTROKE, DOTSTROKEWIDTH, DUMPFACTORYNAME, ENCODERINFO, FONT, FRC, HAS_3D, I, LABEL, LABELFIELDNAMES, LABELFIELDS, MIME_DEFAULT, NONE, NORMAL, NULLSTROKE, PERCENT, PI2, SHAPE, SIN, STROKE, STROKEWIDTH, TIC, VALUE, X, Y, Z
 
Fields inherited from interface com.davisor.core.MIMETypes
FILETYPE_BMP, FILETYPE_CSS, FILETYPE_DOC, FILETYPE_ECMA, FILETYPE_GIF, FILETYPE_HTML, FILETYPE_HTML_CSS, FILETYPE_INDEX, FILETYPE_INDEX_DOC, FILETYPE_INDEX_HTML, FILETYPE_INDEX_HTML_CSS, FILETYPE_INDEX_PDF, FILETYPE_INDEX_PPT, FILETYPE_INDEX_SVG, FILETYPE_INDEX_XHTML, FILETYPE_INDEX_XLS, FILETYPE_INDEX_XMSE, FILETYPE_INDEX_XMSP, FILETYPE_INDEX_XMSW, FILETYPE_INDEX_XSLFO, FILETYPE_JPEG, FILETYPE_PDF, FILETYPE_PNG, FILETYPE_PNG_WBMP, FILETYPE_PPM, FILETYPE_PPT, FILETYPE_SVG, FILETYPE_TEXT, FILETYPE_WBMP, FILETYPE_XHTML, FILETYPE_XLS, FILETYPE_XML, FILETYPE_XMSE, FILETYPE_XMSP, FILETYPE_XMSW, FILETYPE_XSLFO, FILETYPE_XSLFO_CSS, MIME_BMP, MIME_CSS, MIME_DOC, MIME_ECMA, MIME_GIF, MIME_HTML, MIME_HTML_CSS, MIME_INDEX, MIME_INDEX_DOC, MIME_INDEX_HTML, MIME_INDEX_HTML_CSS, MIME_INDEX_PDF, MIME_INDEX_PPT, MIME_INDEX_SVG, MIME_INDEX_XHTML, MIME_INDEX_XLS, MIME_INDEX_XMSE, MIME_INDEX_XMSP, MIME_INDEX_XMSW, MIME_INDEX_XSLFO, MIME_JPEG, MIME_OTHER, MIME_PDF, MIME_PNG, MIME_PNG_WBMP, MIME_PPM, MIME_PPT, MIME_SVG, MIME_TEXT, MIME_WBMP, MIME_XHTML, MIME_XLS, MIME_XML, MIME_XMSE, MIME_XMSP, MIME_XMSW, MIME_XSLFO, MIME_XSLFO_CSS
 
Constructor Summary
BarFactory()
          Default constructor.
BarFactory(BarFactory factory)
          Copy constructor.
 
Method Summary
protected  float computeMinorMargin(int dim, float[][] labelSizes)
          Computes label minor margin size in bar factory spesific way.
protected  AxisFactory.AxisContext createContext(ChartData data, ChartAttributes attr, ChartAxes axes, short index)
          Creates and initializes a bar chart context.
protected  AxisFactory.AxisMetrics createMetrics(ChartAxes axes, float chartWidth, float chartHeight, float[] titleSize, float[] labelSize, float[] markerSize, float[] axisOffset, float[] labelOffset, float[] markerOffset, float[] symbolOffset, float[] majorEdge, float[] minorEdge)
          Defines metrics for two-dimensional bar chart.
protected  float drawBar(java.awt.Graphics2D g, boolean tupleMode, java.awt.Paint color, java.awt.Paint[] paints, java.awt.Stroke stroke, int group, int bar, float zero, float groupWidth, float barSize, float gapSize, float borderWidth, float beginValue, float size, float rotWidth, float rotHeight, DataValue dataValue, DataValue minValue, DataValue maxValue, boolean hidden)
          Passes drawing to subclasses.
protected  void drawBar(java.awt.Graphics2D g, java.awt.Paint[] paint, float x1, float y1, float x2, float y2, float dx, float dy)
          Draws a filled rectangular bar shape, optionally with 3D shearing.
protected abstract  void drawBar(java.awt.Graphics2D g, java.awt.Paint color, java.awt.Paint[] paint, int group, int bar, float zero, float groupWidth, float barSize, float gapSize, float borderWidth, float beginValue, float endValue, float rotWidth, float rotHeight)
          Draws a bar segment in a bar group.
protected  Chart drawChart(AxisFactory.AxisContext context, AxisFactory.AxisMetrics metrics, ChartAxes axes, boolean fillGrid, boolean drawAxes, boolean drawLabel, boolean drawGrid, Chart chart)
          Renders a bar sub-chart out of the given chart data.
protected abstract  void drawValue(java.awt.Graphics2D g, java.awt.Paint color, java.awt.Paint paint, java.awt.Font font, java.lang.String label, AxisFactory.AxisMetrics info, int group, int bar, float groupWidth, float barSize, float gapSize, float beginValue, float endValue, int alignment, float padding)
          Draws a bar value at the top of a bar.
protected abstract  int getCategoryAxis()
          Gets the index of the axis along which the indexes grow.
protected static float getGap(ChartAxis axis)
          Gets the relative width of the gap between two bars.
protected  float[] getIdealSize(ChartAxes axes, int elements, int channels, float[] labelOffsets, float[][] titleSizes, float[][] labelSizes, float[][] markerSizes, float[] markerOffsets)
          Gets the ideal suggested size for this chart.
protected abstract  int getValueAxis()
          Gets the index of the axis along which the values grow.
protected  boolean hasGridLines(ChartAxis axis)
          Tests if axis has grid lines in chart factory spesific way.
protected  boolean isSilent(ChartAxis axis)
          Tests axis silency in chart factory spesific way.
protected  void renderChart(AxisFactory.AxisContext context, AxisFactory.AxisMetrics metrics, ChartAxes axes, Chart chart)
          Default code for bar chart rendering.
protected  DataValue[] resolveDataLimits(ChartData data, ChartAttributes attr, PlotRenderAttributes plot, int[] channels, boolean isometric, boolean[] cumulative)
          Determines global minimum and maximum data values.
protected  DataValue[][] resolveLimits(ChartDataSummary summary)
          Computes chart factory specific limit values for axes.
 
Methods inherited from class com.davisor.graphics.chart.AxisFactory
createChart, createChart, createContext, createContext, createContext, createMetrics, createMetrics, createMetrics, drawAxis, drawMarkers, drawTics, drawXYAxes, drawXYZAxes, fillGrid, fillMarkers, formatDouble, getIdealSize, labelAxis, labelMarkers, resolveLabels, resolveLabels, resolveMarkerSizes, resolveOverlap, titleAxis, transpose
 
Methods inherited from class com.davisor.graphics.chart.ChartFactory
annotate, combineProperties, createChannelType, createChannelType, createChart, createChart, createChart, createChart, createChart, createFormat, createPaintChannelType, createPaintChannelType, createShapeChannelType, createShapeChannelType, createSummary, drawLabel, getContentType, getDefaultPaint, getFactory, getFactory, getGroup, getIsometricCoefficients, getLegendShape, getName, has3D, hasSVG, isClassAvailable, isMultiSeriesMode, main, mayHaveLegend, registerFactory, resolveDataLimits, rotateSize, shade, unregisterFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.davisor.core.Dupable
dup
 

Field Detail

NEG

protected static final int NEG
See Also:
Constant Field Values

POS

protected static final int POS
See Also:
Constant Field Values
Constructor Detail

BarFactory

public BarFactory()
Default constructor.


BarFactory

public BarFactory(BarFactory factory)
Copy constructor.

Method Detail

getCategoryAxis

protected abstract int getCategoryAxis()
Gets the index of the axis along which the indexes grow.


getValueAxis

protected abstract int getValueAxis()
Gets the index of the axis along which the values grow.


drawBar

protected abstract void drawBar(java.awt.Graphics2D g,
                                java.awt.Paint color,
                                java.awt.Paint[] paint,
                                int group,
                                int bar,
                                float zero,
                                float groupWidth,
                                float barSize,
                                float gapSize,
                                float borderWidth,
                                float beginValue,
                                float endValue,
                                float rotWidth,
                                float rotHeight)
Draws a bar segment in a bar group. If the shearing arguments are zero, the bar is to be rendered as a two-dimensional flat rectangle, otherwise as a isometric three-dimensional bar.

Parameters:
g - the graphic's context to draw into
color - bar segment border color
paint - bar segment fill paint shades
group - the number of this bar group
bar - bar sequence number within this group
groupWidth - bar group width
barSize - bar group width
gapSize - bar group gap width
borderWidth - bar border width
beginValue - bar begin value
endValue - bar end value
rotWidth - shearing X-offset
rotHeight - shearing Y-offset
See Also:
drawBar(java.awt.Graphics2D, java.awt.Paint, java.awt.Paint[], int, int, float, float, float, float, float, float, float, float, float), ChartFactory.shade(java.awt.Paint), ColumnBarFactory.drawBar(java.awt.Graphics2D, java.awt.Paint, java.awt.Paint[], int, int, float, float, float, float, float, float, float, float, float), RowBarFactory.drawBar(java.awt.Graphics2D, java.awt.Paint, java.awt.Paint[], int, int, float, float, float, float, float, float, float, float, float)

drawValue

protected abstract void drawValue(java.awt.Graphics2D g,
                                  java.awt.Paint color,
                                  java.awt.Paint paint,
                                  java.awt.Font font,
                                  java.lang.String label,
                                  AxisFactory.AxisMetrics info,
                                  int group,
                                  int bar,
                                  float groupWidth,
                                  float barSize,
                                  float gapSize,
                                  float beginValue,
                                  float endValue,
                                  int alignment,
                                  float padding)
Draws a bar value at the top of a bar.

Parameters:
g - the graphics' context to draw into
color - label color
font - label font
label - value text
info - chart axis into
group - the number of this bar group
bar - bar sequence number within this group
groupWidth - bar group width
barSize - bar group width
gapSize - bar group width
beginValue - bar begin value
endValue - bar end value
alignment - label alignment
padding - padding around the label

resolveDataLimits

protected DataValue[] resolveDataLimits(ChartData data,
                                        ChartAttributes attr,
                                        PlotRenderAttributes plot,
                                        int[] channels,
                                        boolean isometric,
                                        boolean[] cumulative)
                                 throws InvalidDataException
Determines global minimum and maximum data values.

Bar factories group positive and negative value bars above and below the zero line, respectively. In particular, cumulative positive and negative values are summed separately.

Warning! Do not modify the returned values since they may be references to the original data points.

Overrides:
resolveDataLimits in class ChartFactory
Parameters:
data - chart data to be inspected
attr - chart rendering attributes
plot - local plot area attributes
channels - indexes of the channels to be inspected
isometric - isometric rendering may affect how data is understood
cumulative - precomputed channel cumulativenes values
Returns:
global minimum and maximum values, taken over all value channels
Throws:
InvalidDataException - if data limit resolvation fails
See Also:
ChartFactory.resolveDataLimits(DataValue[][],boolean[])

computeMinorMargin

protected float computeMinorMargin(int dim,
                                   float[][] labelSizes)
Computes label minor margin size in bar factory spesific way. In particular, bar char category axis provides always wide enough plot margins so that no minor margin space is needed at all.
                    
    |            X |           XX = edgemost label text
    |            X |
    |            X |
    +------      X +------
    XX   XX         
 

Overrides:
computeMinorMargin in class AxisFactory
Parameters:
dim - dimension index
labelSizes - label width and height ([x,y][w,h])
Returns:
chart type spesific minor margin value
See Also:
AxisFactory.resolveLabels(com.davisor.graphics.chart.ChartAxes, com.davisor.graphics.chart.AxisFactory.AxisContext), AxisFactory.computeMinorMargin(int, float[][])

createContext

protected AxisFactory.AxisContext createContext(ChartData data,
                                                ChartAttributes attr,
                                                ChartAxes axes,
                                                short index)
                                         throws ChartException
Creates and initializes a bar chart context. In addition to standard axis factor context initialization, this method changes the bar chart category axis default position to AxisAttributes.BEFORE_VALUE, because otherwise the default default value would place the crossing value axis at the middle of the first bar.

Overrides:
createContext in class AxisFactory
Parameters:
data - chart data
attr - chart attributes
axes - chart axes
index - context index among other contexts
Returns:
axis chart context, containing axis chart sizing information
Throws:
ChartException - if chart generation fails
See Also:
createMetrics(com.davisor.graphics.chart.ChartAxes, float, float, float[], float[], float[], float[], float[], float[], float[], float[], float[]), getCategoryAxis(), ChartAxes.getAxis(int), ChartAxis.setDefaultPosition(float)

createMetrics

protected AxisFactory.AxisMetrics createMetrics(ChartAxes axes,
                                                float chartWidth,
                                                float chartHeight,
                                                float[] titleSize,
                                                float[] labelSize,
                                                float[] markerSize,
                                                float[] axisOffset,
                                                float[] labelOffset,
                                                float[] markerOffset,
                                                float[] symbolOffset,
                                                float[] majorEdge,
                                                float[] minorEdge)
                                         throws ChartException
Defines metrics for two-dimensional bar chart. This method enlarges plot area margins to make room for bars, and the passes the patched measurements to corresponding super-class method.

Overrides:
createMetrics in class AxisFactory
Parameters:
axes - chart axes
chartWidth - chart width, stricly within chart borders
chartHeight - chart height, stricly within chart borders
titleSize - title size
labelSize - label size
axisOffset - axis line offsets
labelOffset - label offsets
symbolOffset - symbol line offsets
majorEdge - major edge sizes
minorEdge - minor edge sizes
markerSize - marker size
markerOffset - marker offset
Returns:
axis measurements
Throws:
ChartException - if chart generation fails
See Also:
AxisFactory.drawXYAxes(java.awt.Graphics2D, com.davisor.graphics.chart.ChartAxes, com.davisor.graphics.chart.AxisFactory.AxisMetrics, boolean, boolean, boolean, boolean), AxisFactory.AxisMetrics

drawChart

protected Chart drawChart(AxisFactory.AxisContext context,
                          AxisFactory.AxisMetrics metrics,
                          ChartAxes axes,
                          boolean fillGrid,
                          boolean drawAxes,
                          boolean drawLabel,
                          boolean drawGrid,
                          Chart chart)
                   throws InvalidDataException
Renders a bar sub-chart out of the given chart data.

Overrides:
drawChart in class AxisFactory
Parameters:
context - chart context
metrics - chart metrics
axes - chart axes
fillGrid - enables or disables axis background filling
drawAxes - determine which axes may be drawn
drawLabel - determine if default labeling is to be applied
drawGrid - determine if axis grid is to be drawn
chart - chart to draw into
Returns:
bar chart
Throws:
InvalidDataException - if data is invalid for chart drawing
See Also:
createContext(com.davisor.graphics.chart.ChartData, com.davisor.graphics.chart.ChartAttributes, com.davisor.graphics.chart.ChartAxes, short), drawBar(java.awt.Graphics2D, java.awt.Paint, java.awt.Paint[], int, int, float, float, float, float, float, float, float, float, float), drawValue(java.awt.Graphics2D, java.awt.Paint, java.awt.Paint, java.awt.Font, java.lang.String, com.davisor.graphics.chart.AxisFactory.AxisMetrics, int, int, float, float, float, float, float, int, float), createMetrics(com.davisor.graphics.chart.ChartAxes, float, float, float[], float[], float[], float[], float[], float[], float[], float[], float[]), ChartFactory.createSummary(com.davisor.graphics.chart.ChartData, com.davisor.graphics.chart.ChartAttributes, com.davisor.graphics.chart.ChartAxes, com.davisor.graphics.chart.PlotRenderAttributes, com.davisor.data.EnumType, int[], boolean, int[]), ColumnBarFactory, RowBarFactory

renderChart

protected void renderChart(AxisFactory.AxisContext context,
                           AxisFactory.AxisMetrics metrics,
                           ChartAxes axes,
                           Chart chart)
                    throws InvalidDataException
Default code for bar chart rendering. Specialized classes may override this.

Throws:
InvalidDataException - if data is invalid for chart drawing
See Also:
drawChart(com.davisor.graphics.chart.AxisFactory.AxisContext, com.davisor.graphics.chart.AxisFactory.AxisMetrics, com.davisor.graphics.chart.ChartAxes, boolean, boolean, boolean, boolean, com.davisor.graphics.chart.Chart), StockChartFactory

getIdealSize

protected float[] getIdealSize(ChartAxes axes,
                               int elements,
                               int channels,
                               float[] labelOffsets,
                               float[][] titleSizes,
                               float[][] labelSizes,
                               float[][] markerSizes,
                               float[] markerOffsets)
Gets the ideal suggested size for this chart. Size computing will always assume that the chart will be two-dimensional, without any axis rotation. This will keep the chart 3D behaviour consistent with the case when the chart size is explicitly set.

The column bar chart's ideal size is wide and high enough for vertical value labels running along the value-axis, and horizontal text labels running along the category-axis.

Overrides:
getIdealSize in class AxisFactory
Parameters:
axes - axis attributes
elements - the expected number of data element groups
channels - the expected number of data channels
labelOffsets - axis label offsets ([x,y,z])
titleSizes - axis title sizes ([x,y][w,h])
labelSizes - axis label sizes ([x,y][w,h])
Returns:
suggested ideal chart width and height ([w,h])
See Also:
AxisFactory.getIdealSize(ChartAxes,float[],float[], float[][],float[][],float[][],float[])

hasGridLines

protected boolean hasGridLines(ChartAxis axis)
Tests if axis has grid lines in chart factory spesific way.

Bar chart value axes have grid lines by default, while category axes do not. An axis is a value axis if it's dimension equals to value.

Overrides:
hasGridLines in class AxisFactory
Parameters:
axis - axis to check
Returns:
true if given axis has grid lines in this context
See Also:
ChartAxis.getDim(), ChartAxis.hasGridLines()

isSilent

protected boolean isSilent(ChartAxis axis)
Tests axis silency in chart factory spesific way.

Bar factories make category axes that have no labels silent by default. Label precense is detected by checking if axis step data type has an instance of EnumType. If it is, the axis is assumed to have labels.

Overrides:
isSilent in class AxisFactory
Parameters:
axis - axis to check
Returns:
true if given axis is silent in this context
See Also:
ChartAxis.isSilent()

resolveLimits

protected DataValue[][] resolveLimits(ChartDataSummary summary)
Computes chart factory specific limit values for axes.

This implementation places data value limit values on the value axis, and label limit values on the category axis. If the given extreme values are incomplete or have errors, then the value axis limits are left unset. This may happen in particular if no label information is available.

Specified by:
resolveLimits in class AxisFactory
Parameters:
summary - data summary
Returns:
limits values, as descibed by base prototype
See Also:
getValueAxis(), ChartFactory.createSummary(com.davisor.graphics.chart.ChartData, com.davisor.graphics.chart.ChartAttributes, com.davisor.graphics.chart.ChartAxes, com.davisor.graphics.chart.PlotRenderAttributes, com.davisor.data.EnumType, int[], boolean, int[])

drawBar

protected float drawBar(java.awt.Graphics2D g,
                        boolean tupleMode,
                        java.awt.Paint color,
                        java.awt.Paint[] paints,
                        java.awt.Stroke stroke,
                        int group,
                        int bar,
                        float zero,
                        float groupWidth,
                        float barSize,
                        float gapSize,
                        float borderWidth,
                        float beginValue,
                        float size,
                        float rotWidth,
                        float rotHeight,
                        DataValue dataValue,
                        DataValue minValue,
                        DataValue maxValue,
                        boolean hidden)
Passes drawing to subclasses.


drawBar

protected void drawBar(java.awt.Graphics2D g,
                       java.awt.Paint[] paint,
                       float x1,
                       float y1,
                       float x2,
                       float y2,
                       float dx,
                       float dy)
Draws a filled rectangular bar shape, optionally with 3D shearing.

Parameters:
g - graphics context to draw into
paint - face paints
x1 - bar lower left corner X -coordinate
y1 - bar lower left corner Y -coordinate
x2 - bar upper right corner X -coordinate
y2 - bar upper right corner Y -coordinate
dx - X -coordinate shearing offset
dy - Y -coordinate shearing offset

getGap

protected static float getGap(ChartAxis axis)
Gets the relative width of the gap between two bars. Gap values are in within range [0.0,0.5]: '0.0' indicates no gap, '0.5' indicates no bar.
  <---b--->
  :  ___  :
  : |   | :  ___
  : |   | : |   |
 ___|_*_|___|_*_|__    gap = a/b
  : :   : :
  >a<   >a<
 

Parameters:
axis - axis to read gap value
Returns:
relative bar gap width, as described above
See Also:
ChartAxis.getGap()


Copyright © 2001-2004 Davisor Oy. All Rights Reserved.