Commit 53be7324 authored by T.J. Corona's avatar T.J. Corona

vtkChartXY: Add an option to auto rescale axis range for log plots.

This commit is in reference to ParaView issue # 0014895. It introduces a
toggle to vtkChartXY that corrects the lower axis bound to be greater than 0
when the axis is displaying in log mode. It is disabled by default.
parent 03e3d1c5
......@@ -183,6 +183,7 @@ vtkChartXY::vtkChartXY()
this->ForceAxesToBounds = false;
this->ZoomWithMouseWheel = true;
this->AdjustLowerBoundForLogPlot = false;
}
//-----------------------------------------------------------------------------
......@@ -812,6 +813,19 @@ void vtkChartXY::RecalculatePlotBounds()
return;
}
if (this->AdjustLowerBoundForLogPlot && axis->GetLogScale() &&
range[0] <= 0.)
{
if (range[1] <= 0.)
{
// All of the data is negative, so we arbitrarily set the axis range to
// be positive and show no data
range[1] = 1.;
}
// The minimum value is set to either 4 decades below the max or to 1,
// regardless of the true minimum value (which is less than 0)
range[0] = (range[1] < 1.e4 ? range[1] / 1.e4 : 1.);
}
if (this->ForceAxesToBounds)
{
axis->SetMinimumLimit(range[0]);
......
......@@ -204,6 +204,14 @@ public:
vtkGetMacro(ZoomWithMouseWheel, bool);
vtkBooleanMacro(ZoomWithMouseWheel, bool);
// Description:
// Adjust the minimum of a logarithmic axis to be greater than 0, regardless
// of the minimum data value.
// False by default.
vtkSetMacro(AdjustLowerBoundForLogPlot, bool);
vtkGetMacro(AdjustLowerBoundForLogPlot, bool);
vtkBooleanMacro(AdjustLowerBoundForLogPlot, bool);
// Description:
// Set the information passed to the tooltip.
virtual void SetTooltipInfo(const vtkContextMouseEvent &,
......@@ -336,11 +344,16 @@ protected:
// False by default.
bool ForceAxesToBounds;
// Desription:
// Description:
// Property to enable zooming the chart with the mouse wheel.
// True by default.
bool ZoomWithMouseWheel;
// Description:
// Property to adjust the minimum of a logarithmic axis to be greater than 0,
// regardless of the minimum data value.
bool AdjustLowerBoundForLogPlot;
private:
vtkChartXY(const vtkChartXY &) VTK_DELETE_FUNCTION;
void operator=(const vtkChartXY &) VTK_DELETE_FUNCTION;
......
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