Commit 9ffb9792 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

BUG #14809: Use title size when placing title in vtkChartXY.

vtkChartXY did not use the space used by the title text and top-axes to
determine where to place the title text. That resulted in cases where
the title overlapped the top-axes labels or for larger font sizes,
simply didn't have enough room. Fixed that by ensuring that the title
placement/border determination code uses the title text's size.

Updated TestLinePlotAxisFonts test to test this new functionality.

Change-Id: Idac42b970eb27ebbaee95adf43748d79747cd1dc
parent e18424bc
......@@ -34,6 +34,8 @@ int TestLinePlotAxisFonts(int, char * [])
view->GetRenderWindow()->SetSize(400, 300);
vtkNew<vtkChartXY> chart;
view->GetScene()->AddItem(chart.GetPointer());
chart->SetTitle("Chart Title");
chart->GetTitleProperties()->SetFontSize(32);
// Create a table with some points in it...
vtkNew<vtkTable> table;
......
86df322d3946113deba850188aab2272
071b95ec444cef08e1de149331e0500f
......@@ -394,8 +394,15 @@ bool vtkChartXY::Paint(vtkContext2D *painter)
if (this->Title)
{
int offset = 0; // title margin.
vtkAxis* topAxis = this->ChartPrivate->axes[vtkAxis::TOP];
if (topAxis->GetVisible())
{
vtkRectf bounds = topAxis->GetBoundingRect(painter);
offset += static_cast<int>(bounds.GetHeight());
}
vtkPoints2D *rect = vtkPoints2D::New();
rect->InsertNextPoint(this->Point1[0], this->Point2[1]);
rect->InsertNextPoint(this->Point1[0], this->Point2[1] + offset);
rect->InsertNextPoint(this->Point2[0]-this->Point1[0], 10);
painter->ApplyTextProp(this->TitleProperties);
painter->DrawStringRect(rect, this->Title);
......@@ -763,7 +770,7 @@ bool vtkChartXY::UpdateLayout(vtkContext2D* painter)
if (axis->GetVisible())
{
vtkRectf bounds = axis->GetBoundingRect(painter);
if (i == 1 || i == 3)
if (i == vtkAxis::TOP || i == vtkAxis::BOTTOM)
{// Horizontal axes
border = int(bounds.GetHeight());
}
......@@ -773,6 +780,18 @@ bool vtkChartXY::UpdateLayout(vtkContext2D* painter)
}
}
border += this->GetLegendBorder(painter, i);
if (i == vtkAxis::TOP && this->Title)
{
painter->ApplyTextProp(this->TitleProperties);
float bounds[4];
painter->ComputeStringBounds(this->Title, bounds);
if (bounds[3] > 0)
{
border += 5 /* title margin */
+ bounds[3]; // add the title text height to the border.
}
}
border = border < this->HiddenAxisBorder ? this->HiddenAxisBorder :
border;
if (this->ChartPrivate->Borders[i] != border)
......
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