Skip to content
/ VTK Public
forked from Kitware/VTK

Commit c8cfd91

Browse files
scottwittenburgjcfr
authored andcommitted
[Backport] rendering: Add ForceVerticalTitle option to vtkScalarBarActor
This new option is off by default, but when turned on, renders the scalar bar title vertically rather than horizontally. Merge-request: vtk/vtk!10306 (cherry picked from commit Kitware/VTK@fa6552e)
1 parent 92021a6 commit c8cfd91

File tree

2 files changed

+99
-34
lines changed

2 files changed

+99
-34
lines changed

Rendering/Annotation/vtkScalarBarActor.cxx

Lines changed: 90 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ vtkScalarBarActor::vtkScalarBarActor()
267267
this->DrawColorBar = 1;
268268
this->DrawTickLabels = 1;
269269
this->UnconstrainedFontSize = false;
270+
271+
this->ForceVerticalTitle = false;
270272
}
271273

272274
//------------------------------------------------------------------------------
@@ -1121,22 +1123,40 @@ void vtkScalarBarActor::LayoutTitle()
11211123
}
11221124

11231125
int targetWidth, targetHeight;
1124-
// Title spans entire width of frame at top, regardless of orientation.
1125-
targetWidth = static_cast<int>(this->P->Frame.Size[this->P->TL[0]]) - 2 * this->TextPad;
1126-
// Height is either: at most half the frame height or
1127-
// a fixed portion of the frame remaining after subtracting the
1128-
// scalar bar's thickness.
1129-
//
1130-
// When laid out horizontally, ticks share vertical space with title.
1131-
// We want the title to be larger (18pt vs 14pt).
1132-
targetHeight = static_cast<int>(
1133-
(this->Orientation == VTK_ORIENT_VERTICAL || this->LookupTable->GetIndexedLookup())
1134-
? ceil(this->P->Frame.Size[this->P->TL[1]] / 2. - this->TextPad)
1135-
: (this->P->Frame.Size[0] - this->P->ScalarBarBox.Size[0] -
1136-
(this->TextPosition == SucceedScalarBar ? this->P->ScalarBarBox.Posn[this->P->TL[0]]
1137-
: 0) -
1138-
this->TextPad) *
1139-
this->TitleRatio);
1126+
if (!this->ForceVerticalTitle)
1127+
{
1128+
// Title spans entire width of frame at top, regardless of orientation.
1129+
targetWidth = static_cast<int>(this->P->Frame.Size[this->P->TL[0]]) - 2 * this->TextPad;
1130+
}
1131+
else
1132+
{
1133+
targetWidth = static_cast<int>(
1134+
(this->P->Frame.Size[0] - this->P->ScalarBarBox.Size[0] - this->TextPad) * this->TitleRatio);
1135+
}
1136+
1137+
if (!this->ForceVerticalTitle)
1138+
{
1139+
// Height is either: at most half the frame height or
1140+
// a fixed portion of the frame remaining after subtracting the
1141+
// scalar bar's thickness.
1142+
//
1143+
// When laid out horizontally, ticks share vertical space with title.
1144+
// We want the title to be larger (18pt vs 14pt).
1145+
targetHeight = static_cast<int>(
1146+
(this->Orientation == VTK_ORIENT_VERTICAL || this->LookupTable->GetIndexedLookup())
1147+
? ceil(this->P->Frame.Size[this->P->TL[1]] / 2. - this->TextPad)
1148+
: (this->P->Frame.Size[0] - this->P->ScalarBarBox.Size[0] -
1149+
(this->TextPosition == SucceedScalarBar ? this->P->ScalarBarBox.Posn[this->P->TL[0]]
1150+
: 0) -
1151+
this->TextPad) *
1152+
this->TitleRatio);
1153+
}
1154+
else
1155+
{
1156+
targetHeight = static_cast<int>(this->P->Frame.Size[1] / 3.0);
1157+
}
1158+
1159+
this->TitleActor->SetOrientation(this->ForceVerticalTitle ? 90 : 0);
11401160

11411161
if (this->UnconstrainedFontSize)
11421162
{
@@ -1157,29 +1177,48 @@ void vtkScalarBarActor::LayoutTitle()
11571177
this->P->TitleBox.Size[this->P->TL[i]] = static_cast<int>(ceil(titleSize[i]));
11581178
}
11591179

1160-
this->P->TitleBox.Posn[0] =
1161-
this->P->Frame.Posn[0] + (this->P->Frame.Size[this->P->TL[0]] - titleSize[0]) / 2;
1162-
this->P->TitleBox.Posn[1] =
1163-
static_cast<int>(this->P->Frame.Posn[1] + this->P->Frame.Size[this->P->TL[1]]);
1164-
if (this->Orientation == VTK_ORIENT_VERTICAL ||
1165-
this->TextPosition == vtkScalarBarActor::SucceedScalarBar)
1180+
if (this->ForceVerticalTitle)
11661181
{
1167-
this->P->TitleBox.Posn[1] -= this->P->TitleBox.Size[this->P->TL[1]] + this->TextPad +
1168-
static_cast<int>(this->FrameProperty->GetLineWidth());
1182+
this->P->TitleBox.Posn[0] = this->TextPosition == vtkScalarBarActor::PrecedeScalarBar
1183+
? this->P->Frame.Posn[0]
1184+
: this->P->Frame.Posn[0] + this->P->Frame.Size[this->P->TL[0]] -
1185+
(this->P->TitleBox.Size[this->P->TL[0]] + this->TextPad);
1186+
this->P->TitleBox.Posn[1] = this->P->Frame.Posn[1] +
1187+
(this->P->Frame.Size[this->P->TL[1]] - this->P->TitleBox.Size[this->P->TL[1]]) / 2;
11691188
}
11701189
else
11711190
{
1172-
this->P->TitleBox.Posn[1] = this->P->Frame.Posn[1] + this->TextPad -
1173-
static_cast<int>(this->FrameProperty->GetLineWidth());
1191+
this->P->TitleBox.Posn[0] =
1192+
this->P->Frame.Posn[0] + (this->P->Frame.Size[this->P->TL[0]] - titleSize[0]) / 2;
1193+
this->P->TitleBox.Posn[1] =
1194+
static_cast<int>(this->P->Frame.Posn[1] + this->P->Frame.Size[this->P->TL[1]]);
1195+
if (this->Orientation == VTK_ORIENT_VERTICAL ||
1196+
this->TextPosition == vtkScalarBarActor::SucceedScalarBar)
1197+
{
1198+
this->P->TitleBox.Posn[1] -= this->P->TitleBox.Size[this->P->TL[1]] + this->TextPad +
1199+
static_cast<int>(this->FrameProperty->GetLineWidth());
1200+
}
1201+
else
1202+
{
1203+
this->P->TitleBox.Posn[1] = this->P->Frame.Posn[1] + this->TextPad -
1204+
static_cast<int>(this->FrameProperty->GetLineWidth());
1205+
}
11741206
}
11751207
}
11761208

11771209
//------------------------------------------------------------------------------
11781210
void vtkScalarBarActor::ComputeScalarBarLength()
11791211
{
1180-
this->P->ScalarBarBox.Size[1] = this->Orientation == VTK_ORIENT_VERTICAL
1181-
? this->P->Frame.Size[1] - this->P->TitleBox.Size[1] - this->VerticalTitleSeparation
1182-
: this->P->Frame.Size[1];
1212+
if (!this->ForceVerticalTitle)
1213+
{
1214+
this->P->ScalarBarBox.Size[1] = this->Orientation == VTK_ORIENT_VERTICAL
1215+
? this->P->Frame.Size[1] - this->P->TitleBox.Size[1] - this->VerticalTitleSeparation
1216+
: this->P->Frame.Size[1];
1217+
}
1218+
else
1219+
{
1220+
this->P->ScalarBarBox.Size[1] = this->P->Frame.Size[1];
1221+
}
11831222

11841223
// The scalar bar does not include the Nan Swatch, the Below Range Swatch and
11851224
// the Above Range Swatch.
@@ -1333,6 +1372,11 @@ void vtkScalarBarActor::LayoutTicks()
13331372
// lowered by box constraints, but we won't bother:
13341373
this->P->TickBox.Size[1] = this->P->Frame.Size[1] - this->P->TitleBox.Size[1] -
13351374
3 * this->TextPad - this->VerticalTitleSeparation;
1375+
if (this->ForceVerticalTitle)
1376+
{
1377+
this->P->TickBox.Size[0] -= this->P->TitleBox.Size[0];
1378+
this->P->TickBox.Size[1] += this->P->TitleBox.Size[1];
1379+
}
13361380
// Tick box height also reduced by NaN swatch size, if present:
13371381
if (this->DrawNanAnnotation)
13381382
{
@@ -1353,6 +1397,10 @@ void vtkScalarBarActor::LayoutTicks()
13531397
if (this->TextPosition == vtkScalarBarActor::PrecedeScalarBar)
13541398
{
13551399
this->P->TickBox.Posn[0] = this->TextPad;
1400+
if (this->ForceVerticalTitle)
1401+
{
1402+
this->P->TickBox.Posn[0] += this->P->TitleBox.Size[0];
1403+
}
13561404
}
13571405
else
13581406
{
@@ -1643,11 +1691,19 @@ void vtkScalarBarActor::ConfigureScalarBar()
16431691
//------------------------------------------------------------------------------
16441692
void vtkScalarBarActor::ConfigureTitle()
16451693
{
1646-
this->TitleActor->SetPosition(
1647-
this->P->TitleBox.Posn[0] + this->P->TitleBox.Size[this->P->TL[0]] / 2,
1648-
this->TitleActor->GetTextProperty()->GetVerticalJustification() == VTK_TEXT_BOTTOM
1649-
? this->P->TitleBox.Posn[1]
1650-
: this->P->TitleBox.Posn[1] + this->P->TitleBox.Size[this->P->TL[1]]);
1694+
if (!this->ForceVerticalTitle)
1695+
{
1696+
this->TitleActor->SetPosition(
1697+
this->P->TitleBox.Posn[0] + this->P->TitleBox.Size[this->P->TL[0]] / 2,
1698+
this->TitleActor->GetTextProperty()->GetVerticalJustification() == VTK_TEXT_BOTTOM
1699+
? this->P->TitleBox.Posn[1]
1700+
: this->P->TitleBox.Posn[1] + this->P->TitleBox.Size[this->P->TL[1]]);
1701+
}
1702+
else
1703+
{
1704+
this->TitleActor->SetPosition(this->P->TitleBox.Posn[0],
1705+
this->P->TitleBox.Posn[1] + this->P->TitleBox.Size[this->P->TL[1]] / 2);
1706+
}
16511707
}
16521708

16531709
//------------------------------------------------------------------------------

Rendering/Annotation/vtkScalarBarActor.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,14 @@ class VTKRENDERINGANNOTATION_EXPORT vtkScalarBarActor : public vtkActor2D
187187
void SetOrientationToVertical() { this->SetOrientation(VTK_ORIENT_VERTICAL); }
188188
///@}
189189

190+
///@{
191+
/**
192+
* Force the scalar bar title to be vertical.
193+
*/
194+
vtkGetMacro(ForceVerticalTitle, bool);
195+
vtkSetMacro(ForceVerticalTitle, bool);
196+
///@}
197+
190198
///@{
191199
/**
192200
* Set/Get the title text property.
@@ -773,6 +781,7 @@ class VTKRENDERINGANNOTATION_EXPORT vtkScalarBarActor : public vtkActor2D
773781
double BarRatio;
774782
double TitleRatio;
775783
bool UnconstrainedFontSize; // off by default
784+
bool ForceVerticalTitle; // off by default
776785

777786
bool DrawBelowRangeSwatch;
778787
bool DrawAboveRangeSwatch;

0 commit comments

Comments
 (0)