Skip to content
Snippets Groups Projects
Commit 6d90695f authored by Jaswant Panchumarti (Kitware)'s avatar Jaswant Panchumarti (Kitware)
Browse files

Fix vtkPlotBar::GetBounds logic when log scale is enabled

- address paraview/paraview#22733
- This commit fixes the logic in the
  `vtkPlotBar::GetBounds(double*, bool unscaled)` method
  to scale the bounds only if `unscaled` is false. Previously,
  it returned unscaled bounds even when `unscaled` was false and
  returned scaled bounds when `unscaled` was true.
parent c6c3a83d
No related branches found
No related tags found
No related merge requests found
......@@ -57,6 +57,7 @@ vtk_add_test_cxx(vtkChartsCoreCxxTests tests
TestChartDouble.cxx
TestChartDoubleColors.cxx
TestChartDoubleColorsOpaque.cxx
TestChartLogScaleUpdates.cxx
TestChartMatrix.cxx
TestChartMatrix2.cxx
TestChartMatrix3.cxx
......
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
#include "vtkAxis.h"
#include "vtkChartLegend.h"
#include "vtkChartXY.h"
#include "vtkContextView.h"
#include "vtkFloatArray.h"
#include "vtkPlot.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkTable.h"
//------------------------------------------------------------------------------
// This unit test verifies that log scale can be turned on at a later time and
// also checks that updating other parameters after turning on log scale does
// not reset the bounds of the axis which uses log scale.
int TestChartLogScaleUpdates(int, char*[])
{
// Set up a 2D scene, add an XY chart to it
vtkNew<vtkContextView> view;
view->GetRenderWindow()->SetSize(400, 300);
vtkNew<vtkChartXY> chart;
view->GetScene()->AddItem(chart);
// Create a table with some points in it...
vtkNew<vtkTable> table;
vtkNew<vtkFloatArray> arrX;
arrX->SetName("X Axis");
table->AddColumn(arrX);
vtkNew<vtkFloatArray> arrY1;
arrY1->SetName("y=x");
table->AddColumn(arrY1);
vtkNew<vtkFloatArray> arrY2;
arrY2->SetName("y=-x");
table->AddColumn(arrY2);
// Test charting with a few more points...
int numPoints = 10;
float inc = 7.5 / (numPoints - 1);
table->SetNumberOfRows(numPoints);
for (int i = 0; i < numPoints; ++i)
{
float x = 1.0e-5 + i * inc;
table->SetValue(i, 0, x);
table->SetValue(i, 1, x);
table->SetValue(i, 2, -x);
}
chart->SetShowLegend(true);
chart->GetLegend()->SetHorizontalAlignment(vtkChartLegend::CENTER);
// Add a bar plot
vtkPlot* bar = chart->AddPlot(vtkChart::BAR);
bar->SetInputData(table, 0, 1);
bar->SetColor(255, 0, 0, 255);
// Add a line plot
vtkPlot* line = chart->AddPlot(vtkChart::LINE);
line->SetInputData(table, 0, 2);
line->SetColor(255, 0, 255, 255);
line->SetWidth(4.0);
// Render the scene and compare the image to a reference image
view->GetRenderWindow()->SetMultiSamples(0);
view->GetInteractor()->Initialize();
view->Render();
// turn on log scale.
double xRange[2] = { 1, -1 };
arrX->GetRange(xRange);
// Initialize unscaled min/max to fit x axis data so that LogScaleActive is correctly brought
// up to date.
chart->GetAxis(vtkAxis::BOTTOM)->SetUnscaledMinimum(xRange[0]);
chart->GetAxis(vtkAxis::BOTTOM)->SetUnscaledMaximum(xRange[1]);
chart->GetAxis(vtkAxis::BOTTOM)->LogScaleOn();
chart->GetAxis(vtkAxis::BOTTOM)->Update();
chart->Update();
chart->RecalculateBounds();
view->Render();
// Change the line color to navy blue.
line->SetColor(0, 0, 255, 255);
chart->GetAxis(vtkAxis::BOTTOM)->SetCustomTickPositions(nullptr);
chart->RecalculateBounds();
view->GetInteractor()->Start();
return EXIT_SUCCESS;
}
19a8ce4b51d64feae1faa4cc76d863fe5bb61fcb4ded1b12fb688db50102ee745f813777200163714e9a9c1c0d2b73e79a4d3163c1da96bdf8c654d044da7d08
......@@ -651,7 +651,7 @@ void vtkPlotBar::GetBounds(double bounds[4], bool unscaled)
bounds[valuesHigh] = 0.0;
}
if (unscaled)
if (!unscaled)
{
vtkAxis* axes[2];
axes[seriesLow / 2] = this->GetXAxis();
......@@ -674,13 +674,13 @@ void vtkPlotBar::GetBounds(double bounds[4], bool unscaled)
//------------------------------------------------------------------------------
void vtkPlotBar::GetBounds(double bounds[4])
{
this->GetBounds(bounds, false);
this->GetBounds(bounds, /*unscaled=*/false);
}
//------------------------------------------------------------------------------
void vtkPlotBar::GetUnscaledInputBounds(double bounds[4])
{
this->GetBounds(bounds, true);
this->GetBounds(bounds, /*unscaled=*/true);
}
//------------------------------------------------------------------------------
......
# Fix vtkPlotBar::GetBounds logic when log scale is enabled
The `vtkPlotBar::GetBounds(double*, bool unscaled)` now correctly returns
unscaled bounds when `unscaled` is true and scaled bounds when `unscaled` is false.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment