Commit 5870c66a authored by Marcus D. Hanwell's avatar Marcus D. Hanwell
Browse files

ENH: Fixed legend layout issues for 2D histogram.

Use the parent classes Legend ivar, replace it with our color legend.
parent 508d36d7
......@@ -68,9 +68,6 @@ int Test2DHistogram( int, char * [] )
transferFunction->Build();
chart->SetTransferFunction(transferFunction);
chart->SetAutoSize(false);
chart->SetSize(vtkRectf(0.0, 0.0, size - 40, size));
//Finally render the scene and compare the image to a reference image
view->GetRenderWindow()->SetMultiSamples(0);
view->GetInteractor()->Initialize();
......
......@@ -37,6 +37,7 @@ vtkChart2DHistogram::vtkChart2DHistogram()
this->Histogram = vtkSmartPointer<vtk2DHistogramItem>::New();
this->AddPlot(this->Histogram);
this->RemoveItem(this->Legend);
this->Legend = vtkSmartPointer<vtkColorLegend>::New();
this->AddItem(this->Legend);
}
......@@ -62,15 +63,24 @@ void vtkChart2DHistogram::SetInput(vtkImageData *data, vtkIdType z)
void vtkChart2DHistogram::SetTransferFunction(vtkScalarsToColors *function)
{
this->Histogram->SetTransferFunction(function);
this->Legend->SetTransferFunction(function);
vtkColorLegend *legend = vtkColorLegend::SafeDownCast(this->Legend);
if (legend)
{
legend->SetTransferFunction(function);
}
}
//-----------------------------------------------------------------------------
bool vtkChart2DHistogram::UpdateLayout(vtkContext2D *painter)
{
this->vtkChartXY::UpdateLayout(painter);
this->Legend->SetPosition(vtkRectf(this->Point2[0], this->Point1[1],
10, this->Point2[1] - this->Point1[1]));
vtkColorLegend *legend = vtkColorLegend::SafeDownCast(this->Legend);
if (legend)
{
legend->SetPosition(vtkRectf(this->Point2[0] + 5, this->Point1[1],
this->Legend->GetSymbolWidth(),
this->Point2[1] - this->Point1[1]));
}
this->Legend->Update();
return true;
}
......
......@@ -56,7 +56,6 @@ protected:
vtkChart2DHistogram();
~vtkChart2DHistogram();
vtkSmartPointer<vtkColorLegend> Legend;
vtkSmartPointer<vtk2DHistogramItem> Histogram;
// Description:
......
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