Commit b22a2fab authored by Marcus D. Hanwell's avatar Marcus D. Hanwell

ENH: Use the gutter and border in chart matrix.

Enhanced the vtkChartMatrix to support gutters (space between charts)
and borders (space around the entire matrix).

Change-Id: I4c4e54823766a449357e3fdab80f32dbcd57a373
parent adb0857f
......@@ -20,6 +20,7 @@
#include "vtkSmartPointer.h"
#include "vtkContext2D.h"
#include "vtkContextScene.h"
#include "vtkAxis.h"
#include "vtkObjectFactory.h"
#include <vector>
......@@ -36,9 +37,13 @@ public:
vtkStandardNewMacro(vtkChartMatrix)
vtkChartMatrix::vtkChartMatrix()
vtkChartMatrix::vtkChartMatrix() : Gutter(15.0, 15.0)
{
this->Private = new PIMPL;
this->Borders[vtkAxis::LEFT] = 50;
this->Borders[vtkAxis::BOTTOM] = 40;
this->Borders[vtkAxis::RIGHT] = 20;
this->Borders[vtkAxis::TOP] = 40;
}
vtkChartMatrix::~vtkChartMatrix()
......@@ -61,18 +66,40 @@ bool vtkChartMatrix::Paint(vtkContext2D *painter)
this->GetScene()->GetSceneHeight());
if (this->Size.X() > 0 && this->Size.Y() > 0)
{
vtkVector2f increments(this->Private->Geometry.X() / this->Size.X(),
this->Private->Geometry.Y() / this->Size.Y());
// Calculate the increments without the gutters/borders that must be left
vtkVector2f increments;
increments.SetX((this->Private->Geometry.X() - (this->Size.X() - 1) *
this->Gutter.X() - this->Borders[vtkAxis::LEFT] -
this->Borders[vtkAxis::RIGHT]) /
this->Size.X());
increments.SetY((this->Private->Geometry.Y() - (this->Size.Y() - 1) *
this->Gutter.Y() - this->Borders[vtkAxis::TOP] -
this->Borders[vtkAxis::BOTTOM]) /
this->Size.Y());
float x = this->Borders[vtkAxis::LEFT];
float y = this->Borders[vtkAxis::BOTTOM];
for (int i = 0; i < this->Size.X(); ++i)
{
if (i > 0)
{
x += increments.X() + this->Gutter.X();
}
for (int j = 0; j < this->Size.Y(); ++j)
{
if (j > 0)
{
y += increments.Y() + this->Gutter.Y();
}
else
{
y = this->Borders[vtkAxis::BOTTOM];
}
size_t index = j * this->Size.X() + i;
if (this->Private->Charts[index])
{
vtkChart *chart = this->Private->Charts[index];
chart->SetSize(vtkRectf(i * increments.X(),
j * increments.Y(),
chart->SetSize(vtkRectf(x, y,
increments.X(),
increments.Y()));
}
......@@ -100,6 +127,11 @@ void vtkChartMatrix::SetSize(const vtkVector2i &size)
}
}
void vtkChartMatrix::SetGutter(const vtkVector2f &gutter)
{
this->Gutter = gutter;
}
void vtkChartMatrix::Allocate()
{
// Force allocation of all objects as vtkChartXY.
......
......@@ -56,6 +56,14 @@ public:
// Get the width and height of the chart matrix.
virtual vtkVector2i GetSize() const { return this->Size; }
// Description:
// Set the gutter that should be left between the charts in the matrix.
virtual void SetGutter(const vtkVector2f& gutter);
// Description:
// Get the gutter that should be left between the charts in the matrix.
virtual vtkVector2f GetGutter() const { return this->Gutter; }
// Description:
// Allocate the charts, this will cause any null chart to be allocated.
virtual void Allocate();
......@@ -80,8 +88,13 @@ protected:
class PIMPL;
PIMPL *Private;
// The number of charts in x and y.
vtkVector2i Size;
// The gutter between each chart.
vtkVector2f Gutter;
int Borders[4];
private:
vtkChartMatrix(const vtkChartMatrix &); // Not implemented.
void operator=(const vtkChartMatrix &); // Not implemented.
......
......@@ -743,6 +743,10 @@ bool vtkChartXY::UpdateLayout(vtkContext2D* painter)
if (this->LayoutStrategy == vtkChart::AXES_TO_RECT)
{
this->SetBorders(0, 0, 0, 0);
this->ChartPrivate->axes[0]->GetBoundingRect(painter);
this->ChartPrivate->axes[1]->GetBoundingRect(painter);
this->ChartPrivate->axes[2]->GetBoundingRect(painter);
this->ChartPrivate->axes[3]->GetBoundingRect(painter);
}
else
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment