Skip to content

Commit

Permalink
Add methods to create X/Y axis labels to WorkspaceData classes
Browse files Browse the repository at this point in the history
All of the data should have meaningful units so it makes sense to
tie them together.
Refs #9252
  • Loading branch information
martyngigg committed Apr 3, 2014
1 parent fffb57e commit 030ee4f
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 6 deletions.
Expand Up @@ -48,8 +48,8 @@ class EXPORT_OPT_MANTIDQT_API MantidQwtIMDWorkspaceData : public MantidQwtWorksp
void setPlotAxisChoice(int choice);
void setNormalization(Mantid::API::MDNormalization choice);

std::string getXAxisLabel() const;
std::string getYAxisLabel() const;
QString getXAxisLabel() const;
QString getYAxisLabel() const;
int currentPlotXAxis() const;


Expand Down
Expand Up @@ -51,6 +51,10 @@ class EXPORT_OPT_MANTIDQT_API MantidQwtMatrixWorkspaceData : public MantidQwtWor

double getYMin() const;
double getYMax() const;
/// Return the label to use for the X axis
QString getXAxisLabel() const;
/// Return the label to use for the Y axis
QString getYAxisLabel() const;

bool isHistogram()const{return m_isHistogram;}

Expand Down
Expand Up @@ -16,6 +16,9 @@ class EXPORT_OPT_MANTIDQT_API MantidQwtWorkspaceData:public QwtData
virtual double ex(size_t i)const = 0;
virtual double getYMin() const = 0;
virtual double getYMax() const = 0;
virtual QString getXAxisLabel() const = 0;
virtual QString getYAxisLabel() const = 0;

protected:
// Assignment operator (virtualized).
MantidQwtWorkspaceData& operator=(const MantidQwtWorkspaceData&);
Expand Down
9 changes: 5 additions & 4 deletions Code/Mantid/MantidQt/API/src/MantidQwtIMDWorkspaceData.cpp
Expand Up @@ -7,6 +7,7 @@
#include "MantidAPI/NullCoordTransform.h"
#include "MantidGeometry/MDGeometry/IMDDimension.h"
#include "MantidGeometry/MDGeometry/MDTypes.h"
#include <QStringBuilder>

using namespace Mantid::Kernel;
using namespace Mantid::Geometry;
Expand Down Expand Up @@ -443,16 +444,16 @@ int MantidQwtIMDWorkspaceData::currentPlotXAxis() const

//-----------------------------------------------------------------------------
/// @return the label for the X axis
std::string MantidQwtIMDWorkspaceData::getXAxisLabel() const
QString MantidQwtIMDWorkspaceData::getXAxisLabel() const
{
std::string xLabel;
QString xLabel;
if ( m_originalWorkspace.expired() )
return xLabel; // Empty string
if (m_currentPlotAxis >= 0)
{
// One of the dimensions of the original
IMDDimension_const_sptr dim = m_originalWorkspace.lock()->getDimension(m_currentPlotAxis);
xLabel = dim->getName() + " (" + dim->getUnits() + ")";
xLabel = QString::fromStdString(dim->getName() + " (" + dim->getUnits() + ")");
}
else
{
Expand All @@ -471,7 +472,7 @@ std::string MantidQwtIMDWorkspaceData::getXAxisLabel() const

//-----------------------------------------------------------------------------
/// @return the label for the Y axis, based on the selected normalization
std::string MantidQwtIMDWorkspaceData::getYAxisLabel() const
QString MantidQwtIMDWorkspaceData::getYAxisLabel() const
{
switch (m_normalization)
{
Expand Down
46 changes: 46 additions & 0 deletions Code/Mantid/MantidQt/API/src/MantidQwtMatrixWorkspaceData.cpp
@@ -1,4 +1,5 @@
#include "MantidQtAPI/MantidQwtMatrixWorkspaceData.h"
#include <QStringBuilder> // provides % operator for QString

/// Constructor
MantidQwtMatrixWorkspaceData::MantidQwtMatrixWorkspaceData(Mantid::API::MatrixWorkspace_const_sptr workspace,int specIndex, const bool logScale, bool distr)
Expand Down Expand Up @@ -140,6 +141,51 @@ double MantidQwtMatrixWorkspaceData::getYMax() const
return temp;
}

/**
* @return A string containin the text to use as an X axis label
*/
QString MantidQwtMatrixWorkspaceData::getXAxisLabel() const
{
// Deal with axis names
Mantid::API::Axis* ax = m_workspace->getAxis(0);
QString xTitle;
if (ax->unit() && ax->unit()->unitID() != "Empty" )
{
xTitle = QString::fromStdString(ax->unit()->caption());
if ( !ax->unit()->label().empty() )
{
xTitle += " (" + QString::fromStdWString(ax->unit()->utf8Label()) + ")";
}
}
else if (!ax->title().empty())
{
xTitle = QString::fromStdString(ax->title());
}
else
{
xTitle = "X axis";
}
return xTitle;
}

/**
* @return A string containin the text to use as an Y axis label
*/
QString MantidQwtMatrixWorkspaceData::getYAxisLabel() const
{
QString yTitle = QString::fromStdString(m_workspace->YUnitLabel());
Mantid::API::Axis* ax = m_workspace->getAxis(0);
if (m_isDistribution && ax->unit())
{
const std::string unitID = ax->unit()->unitID();
if (unitID != "" || unitID != "Empty")
{
yTitle = yTitle % " / " % ax->unit()->label().c_str();
}
}
return yTitle;
}

void MantidQwtMatrixWorkspaceData::setLogScale(bool on)
{
m_logScale = on;
Expand Down

0 comments on commit 030ee4f

Please sign in to comment.