Commit 5e4acfdf authored by Marcus D. Hanwell's avatar Marcus D. Hanwell
Browse files

ENH: Inherit vtkColorLegend from vtkChartLegend.

Set sane defaults for vtkColorLegend for normal 2D histograms.
parent 67151701
......@@ -141,7 +141,7 @@ public:
// vtkRect4f, with the corner being the offset from Point, and the width/
// height being the total width/height required by the axis. In order to
// ensure the numbers are correct, Update() should be called first.
vtkRectf GetBoundingRect(vtkContext2D* painter);
virtual vtkRectf GetBoundingRect(vtkContext2D* painter);
protected:
vtkChartLegend();
......
......@@ -37,6 +37,9 @@ vtkColorLegend::vtkColorLegend()
this->Interpolate = true;
this->Axis = vtkSmartPointer<vtkAxis>::New();
this->Axis->SetPosition(vtkAxis::RIGHT);
this->SetInline(false);
this->SetHorizontalAlignment(vtkChartLegend::RIGHT);
this->SetVerticalAlignment(vtkChartLegend::BOTTOM);
this->Callback = vtkSmartPointer<vtkCallbackCommand>::New();
this->Callback->SetClientData(this);
......@@ -117,6 +120,28 @@ vtkRectf vtkColorLegend::GetPosition()
return this->Position;
}
//-----------------------------------------------------------------------------
vtkRectf vtkColorLegend::GetBoundingRect(vtkContext2D *painter)
{
if (this->RectTime > this->GetMTime() && this->RectTime > this->PlotTime &&
this->RectTime > this->Axis->GetMTime())
{
return this->Rect;
}
this->Axis->Update();
vtkRectf axisRect = this->Axis->GetBoundingRect(painter);
// Default point placement is bottom left.
this->Rect = vtkRectf(0.0, 0.0,
this->SymbolWidth + axisRect.Width(),
this->Position.Height() + axisRect.Height());
this->RectTime.Modified();
return this->Rect;
}
//-----------------------------------------------------------------------------
void vtkColorLegend::ComputeTexture()
{
......
......@@ -21,7 +21,7 @@
#ifndef __vtkColorLegend_h
#define __vtkColorLegend_h
#include "vtkContextItem.h"
#include "vtkChartLegend.h"
#include "vtkSmartPointer.h" // For SP ivars
#include "vtkVector.h" // For vtkRectf
......@@ -30,10 +30,10 @@ class vtkImageData;
class vtkScalarsToColors;
class vtkCallbackCommand;
class VTK_CHARTS_EXPORT vtkColorLegend: public vtkContextItem
class VTK_CHARTS_EXPORT vtkColorLegend: public vtkChartLegend
{
public:
vtkTypeMacro(vtkColorLegend, vtkContextItem);
vtkTypeMacro(vtkColorLegend, vtkChartLegend);
virtual void PrintSelf(ostream &os, vtkIndent indent);
static vtkColorLegend* New();
......@@ -60,6 +60,13 @@ public:
virtual void SetPosition(const vtkRectf& pos);
virtual vtkRectf GetPosition();
// Description:
// Request the space the legend requires to be drawn. This is returned as a
// vtkRect4f, with the corner being the offset from Point, and the width/
// height being the total width/height required by the axis. In order to
// ensure the numbers are correct, Update() should be called first.
vtkRectf GetBoundingRect(vtkContext2D* painter);
protected:
vtkColorLegend();
virtual ~vtkColorLegend();
......
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