Commit 747ec01c authored by Robert Applin's avatar Robert Applin
Browse files

Refs #31571. Fix plot axis scale crash.

parent c967ad68
......@@ -137,6 +137,9 @@ private:
boost::optional<char const *> overrideAxisLabel(AxisID const &axisID);
void setAxisLabel(AxisID const &axisID, char const *const label);
bool tickLabelFormatX(char *axis, char *style, bool useOffset);
bool tickLabelFormatY(char *axis, char *style, bool useOffset);
// Block redrawing from taking place
bool m_allowRedraws = true;
......
......@@ -30,6 +30,7 @@ using MantidQt::Widgets::MplCpp::FigureCanvasQt;
using MantidQt::Widgets::MplCpp::Line2D;
using MantidQt::Widgets::MplCpp::MantidAxes;
namespace Python = MantidQt::Widgets::Common::Python;
using Mantid::PythonInterface::PythonException;
namespace {
Mantid::Kernel::Logger g_log("PreviewPlot");
......@@ -743,12 +744,37 @@ void PreviewPlot::toggleLegend(const bool checked) {
* calculated as needed, False no offset will be used
*/
void PreviewPlot::tickLabelFormat(char *axis, char *style, bool useOffset) {
m_canvas->gca().tickLabelFormat(axis, style, useOffset);
const auto xTickLabelFormatChanged = tickLabelFormatX(axis, style, useOffset);
const auto yTickLabelFormatChanged = tickLabelFormatY(axis, style, useOffset);
if (xTickLabelFormatChanged || yTickLabelFormatChanged) {
// Need to save parameters to re-format on scale change
m_axis = axis;
m_style = style;
m_useOffset = useOffset;
}
}
bool PreviewPlot::tickLabelFormatX(char *axis, char *style, bool useOffset) {
auto axes = m_canvas->gca();
const auto isXLinear = (*axis == 'x' || *axis == 'both') && axes.getXScale().toStdString() == "linear";
if (isXLinear) {
char *axisType;
axisType = "x";
axes.tickLabelFormat(axisType, style, useOffset);
}
return isXLinear;
}
// Need to save parameters to re-format on scale change
m_axis = axis;
m_style = style;
m_useOffset = useOffset;
bool PreviewPlot::tickLabelFormatY(char *axis, char *style, bool useOffset) {
auto axes = m_canvas->gca();
const auto isYLinear = (*axis == 'y' || *axis == 'both') && axes.getYScale().toStdString() == "linear";
if (isYLinear) {
char *axisType;
axisType = "y";
axes.tickLabelFormat(axisType, style, useOffset);
}
return isYLinear;
}
} // namespace MantidWidgets
......
Supports Markdown
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