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

ENH: Added code for axes to rectangle in charts.

This now allows the user to specify a rectangle and have the chart axes
touch each corner of that rectangle, facilitating views like a scatter
plot matrix where it is important that all axes are exactly aligned.

Change-Id: Ibcc30b9be085187f49984ea726d75eed56d3a51c
parent 59a7f179
......@@ -177,7 +177,7 @@ public:
enum {
FILL_SCENE, // Attempt to fill the entire scene.
FILL_RECT, // Attempt to supply the supplied vtkRectf in Size.
AXIS_TO_RECT // Put the corners of the axes on the vtkRectf in Size.
AXES_TO_RECT // Put the corners of the axes on the vtkRectf in Size.
};
// Description:
......
......@@ -116,7 +116,7 @@ bool vtkChartMatrix::SetChart(const vtkVector2i &position, vtkChart *chart)
}
this->Private->Charts[index] = chart;
this->AddItem(chart);
chart->SetAutoSize(false);
chart->SetLayoutStrategy(vtkChart::AXES_TO_RECT);
return true;
}
else
......@@ -135,7 +135,7 @@ vtkChart* vtkChartMatrix::GetChart(const vtkVector2i &position)
vtkNew<vtkChartXY> chart;
this->Private->Charts[index] = chart.GetPointer();
this->AddItem(chart.GetPointer());
chart->SetAutoSize(false);
chart->SetLayoutStrategy(vtkChart::AXES_TO_RECT);
}
return this->Private->Charts[index];
}
......
......@@ -667,30 +667,35 @@ bool vtkChartXY::UpdateLayout(vtkContext2D* painter)
bool changed = false;
// Axes
for (int i = 0; i < 4; ++i)
if (this->LayoutStrategy == vtkChart::FILL_SCENE ||
this->LayoutStrategy == vtkChart::FILL_RECT)
{
int border = 0;
vtkAxis* axis = this->ChartPrivate->axes[i];
axis->Update();
if (axis->GetVisible())
for (int i = 0; i < 4; ++i)
{
vtkRectf bounds = axis->GetBoundingRect(painter);
if (i == 1 || i == 3)
{// Horizontal axes
border = int(bounds.GetHeight());
int border = 0;
vtkAxis* axis = this->ChartPrivate->axes[i];
axis->Update();
if (axis->GetVisible())
{
vtkRectf bounds = axis->GetBoundingRect(painter);
if (i == 1 || i == 3)
{// Horizontal axes
border = int(bounds.GetHeight());
}
else
{// Vertical axes
border = int(bounds.GetWidth());
}
}
else
{// Vertical axes
border = int(bounds.GetWidth());
border += this->GetLegendBorder(painter, i);
border = border < this->HiddenAxisBorder ? this->HiddenAxisBorder :
border;
if (this->ChartPrivate->Borders[i] != border)
{
this->ChartPrivate->Borders[i] = border;
changed = true;
}
}
border += this->GetLegendBorder(painter, i);
border = border < this->HiddenAxisBorder ? this->HiddenAxisBorder : border;
if (this->ChartPrivate->Borders[i] != border)
{
this->ChartPrivate->Borders[i] = border;
changed = true;
}
}
if (this->LayoutChanged || changed)
......@@ -735,10 +740,17 @@ bool vtkChartXY::UpdateLayout(vtkContext2D* painter)
}
else
{
this->SetBorders(this->ChartPrivate->Borders[0],
this->ChartPrivate->Borders[1],
this->ChartPrivate->Borders[2],
this->ChartPrivate->Borders[3]);
if (this->LayoutStrategy == vtkChart::AXES_TO_RECT)
{
this->SetBorders(0, 0, 0, 0);
}
else
{
this->SetBorders(this->ChartPrivate->Borders[0],
this->ChartPrivate->Borders[1],
this->ChartPrivate->Borders[2],
this->ChartPrivate->Borders[3]);
}
// This is where we set the axes up too
// Y axis (left)
this->ChartPrivate->axes[0]->SetPoint1(this->Point1[0], this->Point1[1]);
......
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