Wt::Chart::WChart2DRenderer Class Reference
[Chart library]

Helper class for rendering a cartesian chart. More...

#include <Wt/Chart/WChart2DRenderer>

List of all members.

Public Member Functions

 WChart2DRenderer (const WCartesianChart *chart, WPainter &painter, const WRectF &rectangle)
 Create a renderer.
virtual ~WChart2DRenderer ()
 Destructor.
const WCartesianChartchart () const
 Returns the corresponding chart.
WPainterpainter ()
 Returns a reference to the painter.
WRectF chartArea ()
 Returns the main plotting area rectangle.
virtual void calcChartArea ()
 Calculates the main plotting area rectangle.
virtual void render ()
 Renders the chart.
virtual WPointF map (double xValue, double yValue, Axis axis=OrdinateAxis, int currentXSegment=0, int currentYSegment=0) const
 Map a (X, Y) point to chart coordinates.
void renderLabel (const WString &text, const WPointF &pos, const WColor &color, int flags, double angle, int margin)
 Utility function for rendering text.
WPointF hv (double x, double y) const
 Conversion between chart and painter coordinates.
WPointF hv (const WPointF &f) const
 Conversion between chart and painter coordinates.
WRectF hv (const WRectF &f) const
 Conversion between chart and painter coordinates.
WRectF chartSegmentArea (WAxis yAxis, int xSegment, int ySegment) const
 Returns the segment area for a combination of X and Y segments.

Protected Types

enum  AxisProperty
 Enumeration that specifies a property of the axes.

Protected Member Functions

virtual void prepareAxes ()
 Prepare the axes for rendering.
virtual void renderBackground ()
 Renders the background.
virtual void renderAxes (int properties)
 Renders one or more properties of the axes.
virtual void renderSeries ()
 Renders all series data, including value labels.
virtual void renderLegend ()
 Renders the (default) legend and chart titles.
int width () const
 Returns the width along the X axis (as if orientation is Vertical).
int height () const
 Returns the height along the Y axis (as if orientation is Vertical).
int segmentMargin () const
 Returns the segment margin.
void renderAxis (const WAxis &axis, AxisLocation location, int properties)
 Render properties of one axis.
int calcNumBarGroups ()
 Calculate the total number of bar groups.
void iterateSeries (SeriesIterator *iterator, bool reverseStacked=false)
 Iterate over the series using an iterator.

Protected Attributes

AxisLocation location_ [3]
 The computed axis locations.


Detailed Description

Helper class for rendering a cartesian chart.

This class is used by WCartesianChart during rendering, and normally, you will not need to use this class directly. You may want to specialize this class if you want to override particular aspects of how the chart is renderered. In that case, you will want to instantiate the specialized class in WCartesianChart::createRenderer().

To simplify the simulatenous handling of Horizontal and Vertical charts, the renderer makes abstraction of the orientation of the chart: regardless of the chart orientation, the width() corresponds to the length along the X axis, and height() corresponds to the length along the Y axis. Similarly, calcChartArea() and chartArea() return a rectangle where the bottom side corresponds to the lowest displayed Y values, and the left side corresponds to the lowest displayed X values. To map these "chart coordinates" to painter coordinates, use one of the hv() methods.

Note, this class is part of the internal charting API, and may be subject of changes and refactorings.


Constructor & Destructor Documentation

Wt::Chart::WChart2DRenderer::WChart2DRenderer ( const WCartesianChart chart,
WPainter painter,
const WRectF rectangle 
)

Create a renderer.

Creates a renderer for the cartesian chart chart, for rendering in the specified rectangle of the painter.


Member Function Documentation

WRectF Wt::Chart::WChart2DRenderer::chartArea (  )  [inline]

Returns the main plotting area rectangle.

This area is calculated and cached by calcChartArea().

void Wt::Chart::WChart2DRenderer::calcChartArea (  )  [virtual]

Calculates the main plotting area rectangle.

This method calculates the main plotting area, and stores it in the memeber chartArea_. The default implementation simply removes the plot area padding from the entire painting rectangle.

See also:
WCartesianChart::plotAreaPadding().

void Wt::Chart::WChart2DRenderer::render (  )  [virtual]

Renders the chart.

This method renders the chart. The default implementation does the following:

  calcChartArea();           // sets chartArea_
  prepareAxes();             // provides logical dimensions to the axes

  renderBackground();        // render the background
  renderAxes(Grid);          // render the grid
  renderSeries();            // render the data series
  renderAxes(Line | Labels); // render the axes (lines & labels)
  renderLegend();            // render legend and titles

You may want to reimplement this method to change the sequence of steps for rendering the chart.

WPointF Wt::Chart::WChart2DRenderer::map ( double  xValue,
double  yValue,
Axis  axis = OrdinateAxis,
int  currentXSegment = 0,
int  currentYSegment = 0 
) const [virtual]

Map a (X, Y) point to chart coordinates.

This method maps the point with given (xValue, yValue) to chart coordinates. The y value is mapped by one of the Y axes indicated by axis.

Note that chart coordinates may not be the same as painter coordinates, because of the chart orientation. To map from chart coordinates to painter coordinates, use hv().

The currentXSegment and currentYSegment specify the axis segments in which you wish to map the point.

void Wt::Chart::WChart2DRenderer::renderLabel ( const WString text,
const WPointF pos,
const WColor color,
int  flags,
double  angle,
int  margin 
)

Utility function for rendering text.

This method renders text on the chart position pos, with a particular alignment flags. These are both specified in chart coordinates. The position is converted to painter coordinates using hv(), and the alignment flags are changed accordingly. The rotation, indicated by angle is specified in painter coordinates and thus an angle of 0 always indicates horizontal text, regardless of the chart orientation.

WPointF Wt::Chart::WChart2DRenderer::hv ( double  x,
double  y 
) const

Conversion between chart and painter coordinates.

Converts from chart coordinates to painter coordinates, taking into account the chart orientation.

WPointF Wt::Chart::WChart2DRenderer::hv ( const WPointF f  )  const

Conversion between chart and painter coordinates.

Converts from chart coordinates to painter coordinates, taking into account the chart orientation.

WRectF Wt::Chart::WChart2DRenderer::hv ( const WRectF f  )  const

Conversion between chart and painter coordinates.

Converts from chart coordinates to painter coordinates, taking into account the chart orientation.

WRectF Wt::Chart::WChart2DRenderer::chartSegmentArea ( WAxis  yAxis,
int  xSegment,
int  ySegment 
) const

Returns the segment area for a combination of X and Y segments.

This segment area is used for clipping when rendering in a particular segment.

void Wt::Chart::WChart2DRenderer::prepareAxes (  )  [protected, virtual]

Prepare the axes for rendering.

Computes axis properties such as the range (if not manually specified), label interval (if not manually specified) and axis locations. These properties are stored within the axes (we may want to change that later to allow for reentrant rendering by multiple renderers ?).

int Wt::Chart::WChart2DRenderer::segmentMargin (  )  const [inline, protected]

Returns the segment margin.

This is the separation between segments, and defaults to 40 pixels.

void Wt::Chart::WChart2DRenderer::renderAxis ( const WAxis axis,
AxisLocation  location,
int  properties 
) [protected]

Render properties of one axis.

See also:
renderAxes()


Member Data Documentation

The computed axis locations.

See also:
prepareAxes()


Generated on Mon Nov 3 15:01:05 2008 for Wt by doxygen 1.5.6