com.davisor.graphics.chart
Class ChartFactory.ChartMetrics

java.lang.Object
  extended bycom.davisor.graphics.chart.ChartFactory.ChartMetrics
Direct Known Subclasses:
AxisFactory.AxisMetrics, ComboFactory.ComboMetrics, LabelLegendFactory.LabelLegendMetrics, LayoutFactory.LayoutMetrics, PieFactory.PieMetrics, ScaleLegendFactory.ScaleLegendMetrics
Enclosing class:
ChartFactory

public class ChartFactory.ChartMetrics
extends java.lang.Object

ChartMetrics provides common interface for all chart factories to store chart and chart component size information, and to resize charts. The minimum information metrics required from all chart types is the physical size of the chart rendering.

All charts must use a metrics object derived from this class, as ChartMetrics is the principal interface through which different combination charts like LayoutFactory and ComboFactory interact and organize their children. A failure to implement a chart type specific metrics object and in particular propert implementations for scale(int, float) and scaleToSize(java.lang.Number, java.lang.Number) methods will make those chart types incompatible with combination charts.

Chart metrics stores chart size in two separate member variables and provides corresponding separate accessor methods for both of them. This is the typical arrangement in traditional API design. Many chart factory operations are however identical to both horizontal (X) and vertical (Y) dimensions. In these cases, it is important to be able to parmetrise the dimension that is being accessed. For this reason, chart metrics provides also indexable accessor methods like getSize(int) for chart size variables.

See Also:
getWidth(), getHeight(), getSize(int), ChartFactory.ChartContext

Field Summary
protected  float M_height
          Chart height, stricly within chart boundary line.
protected  float M_width
          Chart width, stricly within chart boundary line.
 
Constructor Summary
ChartFactory.ChartMetrics(float width, float height)
          Creates new chart metrics.
 
Method Summary
 void add(int dim, float term)
          Adds term to given size component.
 float getHeight()
          Gets the chart height.
 float getSize(int dim)
          Gets the chart size component.
 float getWidth()
          Gets the chart width.
 void scale(float xFactor, float yFactor)
          Scales all metrics components.
 void scale(int dim, float factor)
          Scales given size component.
 void scaleToSize(java.lang.Number width, java.lang.Number height)
          Scales the metrics to make the chart meet given new size.
 void setHeight(float height)
          Sets the chart height.
 void setSize(int dim, float size)
          Sets the chart size component.
 void setWidth(float width)
          Sets the chart width.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

M_width

protected float M_width
Chart width, stricly within chart boundary line.


M_height

protected float M_height
Chart height, stricly within chart boundary line.

Constructor Detail

ChartFactory.ChartMetrics

public ChartFactory.ChartMetrics(float width,
                                 float height)
Creates new chart metrics.

Parameters:
width - chart width, in millimeters
height - chart height, in millimeters
Method Detail

add

public void add(int dim,
                float term)
Adds term to given size component. This method provides an indexable view to the chart size component values.

Parameters:
dim - dimension index (X or Y)
term - sum term
See Also:
scale(int,float)

getHeight

public float getHeight()
Gets the chart height.

See Also:
setHeight(float)

getSize

public float getSize(int dim)
Gets the chart size component. This method provides an indexable view to the chart size component values.

Parameters:
dim - dimension index (X or Y)
See Also:
getWidth(), getHeight(), setSize(int,float)

getWidth

public float getWidth()
Gets the chart width.

See Also:
setWidth(float)

scale

public void scale(int dim,
                  float factor)
Scales given size component. This method provides an indexable view to the chart size component values.

Parameters:
dim - dimension index (X or Y)
factor - scaling factor
See Also:
add(int,float)

scale

public void scale(float xFactor,
                  float yFactor)
Scales all metrics components.

This default implementation scales current chart size with the given scalar factors. Sub-classes are expected to override this method with implementations that scale all sub-class specific metrics components, too.

Parameters:
xFactor - horizontal scaling factor
yFactor - vertical scaling factor

scaleToSize

public void scaleToSize(java.lang.Number width,
                        java.lang.Number height)
Scales the metrics to make the chart meet given new size. The old width or height is kept if a coresponding new value is not given.

This method is used is particular when charts are laid out with LayoutFactory and other similar tools. For this reason, the implementations of this method are expected to rescale the chart in some intelligent, optimal way, better that the following equivivalent but propably non-optimal linear scaling:

scale(width.floatValue()/getWidth(), height.floatValue()/getHeight());

Optimal chart scaling does not need to be linear with respect of chart internal components. Instead, areas that hold text should not become overly large or small. If neccessary, charts should recompute their entire metrics information if they can't otherwise produce optimal results.

This default implementation replaces current size components with not null given components. Sub-classes are expected to override this method with implementations that scale all sub-class specific metrics components, too.

Parameters:
width - new chart width (may be null = keep the old width)
height - new chart height (may be null = keep the old height)
See Also:
getSize(int)

setHeight

public void setHeight(float height)
Sets the chart height.

Parameters:
height - new chart height
See Also:
getHeight()

setSize

public void setSize(int dim,
                    float size)
Sets the chart size component. This method provides an indexable view to the chart size component values.

Parameters:
dim - dimension index (X or Y)
See Also:
getSize(int)

setWidth

public void setWidth(float width)
Sets the chart width.

Parameters:
width - new chart width
See Also:
getWidth()


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