Commit 36614d77 authored by Marcus D. Hanwell's avatar Marcus D. Hanwell

Make the bottom-left charts non-interactive

Added a new convenience method to vtkChartMatrix to get the index of a
chart at a supplied position, use this with chart interactivity in the
scatter plot matrix to prevent any interaction with all but the large
chart.

Change-Id: Ic240a3ea7f262efe6d2f7617cb084725dc330b45
parent 04bdc951
......@@ -227,6 +227,58 @@ vtkVector2i vtkChartMatrix::GetChartSpan(const vtkVector2i& position)
}
}
vtkVector2i vtkChartMatrix::GetChartIndex(const vtkVector2f &position)
{
if (this->Size.X() > 0 && this->Size.Y() > 0)
{
// 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])
{
vtkVector2i &span = this->Private->Spans[index];
// Check if the supplied location is within this charts area.
if (position.X() > x &&
position.X() < (x + increments.X() * span.X()
+ (span.X() - 1) * this->Gutter.X()) &&
position.Y() > y &&
position.Y() < (y + increments.Y() * span.Y()
+ (span.Y() - 1) * this->Gutter.Y()))
return vtkVector2i(i, j);
}
}
}
}
return vtkVector2i(-1, -1);
}
void vtkChartMatrix::PrintSelf(ostream &os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
......
......@@ -57,10 +57,6 @@ 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:
// Set/get the borders of the chart matrix (space in pixels around each chart).
virtual void SetBorders(int left, int bottom, int right, int top);
......@@ -72,6 +68,10 @@ public:
}
}
// 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; }
......@@ -104,6 +104,11 @@ public:
// Get the span of the specified chart.
virtual vtkVector2i GetChartSpan(const vtkVector2i& position);
// Description:
// Get the position of the chart in the matrix at the specified location.
// The position should be specified in scene coordinates.
virtual vtkVector2i GetChartIndex(const vtkVector2f& position);
protected:
vtkChartMatrix();
~vtkChartMatrix();
......
......@@ -1098,22 +1098,11 @@ bool vtkScatterPlotMatrix::MouseButtonReleaseEvent(
const vtkContextMouseEvent &mouse)
{
// Work out which scatter plot was clicked - make that one the active plot.
int n = this->GetSize().X();
vtkVector2i pos(-1, -1);
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
if (i + j + 1 < n && this->GetChart(vtkVector2i(i, j))->Hit(mouse))
{
pos = vtkVector2i(i, j);
}
}
}
vtkVector2i pos = this->GetChartIndex(mouse.GetPos());
if(pos[0] == -1)
if(pos.X() == -1 || pos.X() + pos.Y() + 1 >= this->Size.X())
{
// no plot was clicked, so just return
// We didn't click a chart in the bottom-left triangle of the matrix.
return true;
}
......@@ -1341,6 +1330,7 @@ void vtkScatterPlotMatrix::UpdateLayout()
vtkChart* chart = this->GetChart(pos);
this->ApplyAxisSetting(chart, column, row);
chart->ClearPlots();
chart->SetInteractive(false);
chart->SetAnnotationLink(this->Private->Link.GetPointer());
// Lower-left triangle - scatter plots.
chart->SetActionToButton(vtkChart::PAN, -1);
......@@ -1361,6 +1351,7 @@ void vtkScatterPlotMatrix::UpdateLayout()
{
// We are on the diagonal - need a histogram plot.
vtkChart* chart = this->GetChart(pos);
chart->SetInteractive(false);
this->ApplyAxisSetting(chart, column, row);
chart->ClearPlots();
vtkPlot *plot = chart->AddPlot(vtkChart::BAR);
......
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