From f369cd8288d82f982807fcbab229aa4a390d8350 Mon Sep 17 00:00:00 2001
From: Matthew D Jones <Matthew.D.Jones@tessella.com>
Date: Tue, 11 Aug 2015 14:57:50 +0100
Subject: [PATCH] Re #11422 Try to get the scaled axes working for plots in -ve
 x and y

---
 Code/Mantid/MantidPlot/src/Graph.cpp          | 49 ++++++++++++++++++-
 .../src/plot2D/PowerScaleEngine.cpp           |  1 -
 2 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/Code/Mantid/MantidPlot/src/Graph.cpp b/Code/Mantid/MantidPlot/src/Graph.cpp
index 42d675fd87e..b691ae61f3f 100644
--- a/Code/Mantid/MantidPlot/src/Graph.cpp
+++ b/Code/Mantid/MantidPlot/src/Graph.cpp
@@ -1318,7 +1318,7 @@ void Graph::setAxisScale(int axis, double start, double end, int type, double st
     sc_engine->setType(ScaleTransformation::Linear);
   }
 
-  if (type == GraphOptions::Log10 || type == GraphOptions::Power)
+  if (type == GraphOptions::Log10)
   {
     if (start <= 0)
     {
@@ -1365,6 +1365,53 @@ void Graph::setAxisScale(int axis, double start, double end, int type, double st
     // log scales can't represent zero or negative values, 1e-10 is a low number that I hope will be lower than most of the data but is still sensible for many color plots
     //start = start < 1e-90 ? 1e-10 : start;
   }
+  else if (type == GraphOptions::Power)
+  {
+    g_log.debug() << "Axis type is: " << axis << std::endl;
+    g_log.debug() << "Start is: " << start << std::endl;
+    if (start <= 0)
+    {
+      double s_min = DBL_MAX;
+      // for the y axis rely on the bounding rects
+      for(int i=0;i<curves();++i)
+      {
+        QwtPlotCurve* c = curve(i);
+        if (c)
+        {
+          double s;
+          if (axis == QwtPlot::yRight || axis == QwtPlot::yLeft)
+          {
+            s = c->boundingRect().y();
+          }
+          else
+          {
+            s = c->boundingRect().x();
+          }
+          if (s > 0 && s < s_min)
+          {
+            s_min = s;
+          }
+        }
+      }
+
+      if (s_min != DBL_MAX && s_min > 0)
+      {
+        start = s_min;
+      }
+      else
+      {
+        if (end <= 0)
+        {
+          start = 1;
+          end = 1000;
+        }
+        else
+        {
+          start = 0.01 * end;
+        }
+      }
+    }
+  }
 
   if (axis == QwtPlot::yRight)
   {
diff --git a/Code/Mantid/MantidPlot/src/plot2D/PowerScaleEngine.cpp b/Code/Mantid/MantidPlot/src/plot2D/PowerScaleEngine.cpp
index 36f0bdbc34e..5010681c4a5 100644
--- a/Code/Mantid/MantidPlot/src/plot2D/PowerScaleEngine.cpp
+++ b/Code/Mantid/MantidPlot/src/plot2D/PowerScaleEngine.cpp
@@ -144,7 +144,6 @@ void PowerScaleEngine::buildTicks(
 
         // ticks very close to 0.0 are
         // explicitly set to 0.0
-        // important if nth_power is set to -ve value
 
         for ( int j = 0; j < (int)ticks[i].count(); j++ )
         {
-- 
GitLab