Commit 27025ebc authored by Cory Quammen's avatar Cory Quammen Committed by Kitware Robot
Browse files

Merge topic 'color-legend-title-centering'

5fbb5221 Added release documentation for new title orientation option
57ff382d

 Improve positioning of horizontal title when in vertical orientation
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Utkarsh Ayachit's avatarUtkarsh Ayachit <utkarsh.ayachit@kitware.com>
Merge-request: !2076
parents 3975092a 5fbb5221
Pipeline #84148 failed with stage
in 0 seconds
# Horizontal color legend title in vertical orientation mode
As in earlier versions of ParaView, it is now again possible to orient the
color legend title horizontally when the color legend is oriented vertically.
By default, the title is rotated 90 degrees counterclockwise and aligned with
the color legend vertically.
......@@ -905,12 +905,6 @@ void vtkContext2DScalarBarActor::PaintAxis(vtkContext2D* painter, double size[2]
this->Axis->Update();
this->Axis->Paint(painter);
//-----------------------------
// Set up title
// IMPORTANT: this needs to be done *after* this->Axis->Update() is called
// so that we get an accurate axis bounding rectangle.
this->PaintTitle(painter, size);
}
//----------------------------------------------------------------------------
......@@ -940,21 +934,35 @@ void vtkContext2DScalarBarActor::PaintTitle(vtkContext2D* painter, double size[2
float titleHeight = titleBounds[3];
// vtkAxis::GetBoundingRect() is not accurate. Compute it ourselves.
vtkRectf axisRect =
vtkBoundingRectContextDevice2D::GetBoundingRect(this->Axis, this->CurrentViewport);
vtkRectf rect = this->GetColorBarRect(size);
float titleX = rect.GetX() + 0.5 * rect.GetWidth();
float titleY = rect.GetY() + 0.5 * rect.GetHeight();
// All the code in this section is needed to get the actual bounds of
// the axis including any offsets applied in PaintAxis().
vtkNew<vtkBoundingRectContextDevice2D> boundingDevice;
vtkNew<vtkContextDevice2D> contextDevice;
boundingDevice->SetDelegateDevice(contextDevice.Get());
boundingDevice->Begin(this->CurrentViewport);
vtkNew<vtkContext2D> context;
context->Begin(boundingDevice);
this->PaintAxis(context, size);
context->End();
boundingDevice->End();
vtkRectf axisRect = boundingDevice->GetBoundingRect();
vtkRectf barAndAxisRect = axisRect;
vtkRectf colorBarRect = this->GetColorBarRect(size);
barAndAxisRect.AddRect(colorBarRect);
float titleX = barAndAxisRect.GetX() + 0.5 * barAndAxisRect.GetWidth();
float titleY = colorBarRect.GetY() + 0.5 * colorBarRect.GetHeight();
if (this->GetOrientation() == VTK_ORIENT_HORIZONTAL || this->ForceHorizontalTitle)
{
if (this->GetTitleJustification() == VTK_TEXT_LEFT)
{
titleX = 0.0;
titleX = barAndAxisRect.GetX();
}
else if (this->GetTitleJustification() == VTK_TEXT_RIGHT)
{
titleX = rect.GetX() + rect.GetWidth();
titleX = barAndAxisRect.GetX() + barAndAxisRect.GetWidth();
}
if (this->GetTextPosition() == vtkContext2DScalarBarActor::PrecedeScalarBar)
{
......@@ -965,13 +973,13 @@ void vtkContext2DScalarBarActor::PaintTitle(vtkContext2D* painter, double size[2
// Handle zero-height axis.
if (axisRect.GetHeight() < 1.0)
{
axisRect.SetHeight(rect.GetHeight());
axisRect.SetHeight(colorBarRect.GetHeight());
}
titleY = axisRect.GetY() + axisRect.GetHeight() + 0.25 * titleHeight;
}
// Move title to the top if the title is forced horizontal
if (this->ForceHorizontalTitle)
if (this->ForceHorizontalTitle && this->GetOrientation() != VTK_ORIENT_HORIZONTAL)
{
titleY = axisRect.GetY() + axisRect.GetHeight() + 0.25 * titleHeight;
}
......@@ -981,23 +989,23 @@ void vtkContext2DScalarBarActor::PaintTitle(vtkContext2D* painter, double size[2
// Handle zero-width axis.
if (axisRect.GetWidth() < 1.0)
{
axisRect.SetWidth(0.25 * rect.GetWidth());
axisRect.SetWidth(0.25 * colorBarRect.GetWidth());
}
if (this->GetTitleJustification() == VTK_TEXT_LEFT)
{
titleY = 0.0;
titleY = barAndAxisRect.GetY();
}
else if (this->GetTitleJustification() == VTK_TEXT_RIGHT)
{
titleY = rect.GetY() + rect.GetHeight();
titleY = barAndAxisRect.GetY() + barAndAxisRect.GetHeight();
}
if (this->GetTextPosition() == vtkContext2DScalarBarActor::PrecedeScalarBar)
{
titleX = rect.GetX() - axisRect.GetWidth();
titleX = colorBarRect.GetX() - axisRect.GetWidth();
}
else
{
titleX = rect.GetX() + rect.GetWidth() + axisRect.GetWidth() + titleWidth;
titleX = colorBarRect.GetX() + colorBarRect.GetWidth() + axisRect.GetWidth() + titleWidth;
}
}
......@@ -1048,6 +1056,9 @@ bool vtkContext2DScalarBarActor::Paint(vtkContext2D* painter)
this->PaintColorBar(painter, size);
this->PaintAxis(painter, size);
// IMPORTANT: this needs to be done *after* this->Axis->Update() is called
// in PaintAxis() so that we get an accurate axis bounding rectangle.
this->PaintTitle(painter, size);
// Restore settings
pen->DeepCopy(savePen.GetPointer());
......
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