Skip to content

Commit

Permalink
Only use distribution flag for histogram data.
Browse files Browse the repository at this point in the history
Refs #10639
  • Loading branch information
martyngigg committed Nov 28, 2014
1 parent 5734e7e commit 73956a6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Code/Mantid/MantidPlot/src/Graph.cpp
Expand Up @@ -203,6 +203,8 @@ Graph::Graph(int x, int y, int width, int height, QWidget* parent, Qt::WFlags f)

connect (d_zoomer[0],SIGNAL(zoomed (const QwtDoubleRect &)),this,SLOT(zoomed (const QwtDoubleRect &)));

m_isDistribution = false;
m_normalizable = false;
}

void Graph::notifyChanges()
Expand Down
8 changes: 6 additions & 2 deletions Code/Mantid/MantidPlot/src/Graph.h
Expand Up @@ -201,7 +201,9 @@ public slots:

void noNormalization();
void binWidthNormalization();


bool normalizable() const { return m_normalizable; }
void setNormalizable(const bool on) { m_normalizable = on; }
// Are MantidCurves plotted as distributions in this Graph
bool isDistribution() const { return m_isDistribution; }
void setDistribution(const bool on) { m_isDistribution = on; }
Expand Down Expand Up @@ -885,8 +887,10 @@ private slots:
bool d_synchronize_scales;
int d_waterfall_offset_x, d_waterfall_offset_y;

// True if MantidCurves are plotted as distributions
// True if MantidCurves are plotted as distribution
bool m_isDistribution;
// True, if the graph can be plotted as distribution
bool m_normalizable;
// x and y units of MantidCurves
boost::shared_ptr<Mantid::Kernel::Unit> m_xUnits;
boost::shared_ptr<Mantid::Kernel::Unit> m_yUnits;
Expand Down
9 changes: 9 additions & 0 deletions Code/Mantid/MantidPlot/src/Mantid/MantidMatrixCurve.cpp
Expand Up @@ -359,3 +359,12 @@ bool MantidMatrixCurve::isDistribution() const
}
else return false;
}

bool MantidMatrixCurve::isHistogramData() const
{
if( auto *d = dynamic_cast<const QwtWorkspaceSpectrumData*>(&data()))
{
return d->m_isHistogram;
}
else return false;
}
3 changes: 3 additions & 0 deletions Code/Mantid/MantidPlot/src/Mantid/MantidMatrixCurve.h
Expand Up @@ -89,6 +89,9 @@ class MantidMatrixCurve:public MantidCurve
/// Returns whether the curve is plotted as a distribution
bool isDistribution() const;

/// Returns true if the curve data comes for a histgoram workspace
bool isHistogramData() const;

virtual void draw(QPainter *p,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
const QRect &) const;
Expand Down
13 changes: 9 additions & 4 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp
Expand Up @@ -3123,7 +3123,7 @@ MultiLayer* MantidUI::plot1D(const QMultiMap<QString,int>& toPlot, bool spectrum
ml->setName(appWindow()->generateUniqueName(plotTitle + "-"));
m_lastShown1DPlotWin = ml;

// Do we plot a distribution or not
// Do we plot try to plot as distribution
bool plotAsDistribution(false);
if(distr == MantidQt::DistributionDefault)
{
Expand All @@ -3136,15 +3136,20 @@ MultiLayer* MantidUI::plot1D(const QMultiMap<QString,int>& toPlot, bool spectrum

// Try to add curves to the plot
Graph *g = ml->activeGraph();
g->setDistribution(plotAsDistribution);
MantidMatrixCurve::IndexDir indexType = (spectrumPlot) ? MantidMatrixCurve::Spectrum : MantidMatrixCurve::Bin;
MantidMatrixCurve* firstCurve(NULL);
for(QMultiMap<QString,int>::const_iterator it=toPlot.begin();it!=toPlot.end();++it)
{
try
{
auto * wsCurve = new MantidMatrixCurve(it.key(),g,it.value(),indexType,errs,plotAsDistribution,style);
if(!firstCurve) firstCurve = wsCurve;
auto * wsCurve = new MantidMatrixCurve(it.key(), g, it.value(), indexType,
errs, plotAsDistribution, style);
if(!firstCurve)
{
firstCurve = wsCurve;
g->setNormalizable(firstCurve->isHistogramData());
g->setDistribution(firstCurve->isDistribution());
}
}
catch (Mantid::Kernel::Exception::NotFoundError&)
{
Expand Down
6 changes: 4 additions & 2 deletions Code/Mantid/MantidQt/API/src/QwtWorkspaceSpectrumData.cpp
Expand Up @@ -8,7 +8,7 @@
* @param workspace The workspace containing the data
* @param specIndex Index of the spectrum to plot
* @param logScale If true, plot a log scale
* @param distr If true, plot the Y values/X bin-width
* @param distr If true and the data is histogram then plot the Y values/X bin-width
*/
QwtWorkspaceSpectrumData::QwtWorkspaceSpectrumData(const Mantid::API::MatrixWorkspace & workspace,
int specIndex, const bool logScale, const bool distr)
Expand All @@ -21,8 +21,10 @@ QwtWorkspaceSpectrumData::QwtWorkspaceSpectrumData(const Mantid::API::MatrixWork
m_binCentres(false),
m_logScale(logScale),
m_minPositive(0),
m_isDistribution(distr)
m_isDistribution(false)
{
setAsDistribution(distr); // takes into account if this is a histogram or not

m_xTitle = MantidQt::API::PlotAxis(workspace, 0).title();
m_yTitle = MantidQt::API::PlotAxis(workspace).title();
}
Expand Down

0 comments on commit 73956a6

Please sign in to comment.