Skip to content

Commit

Permalink
MantidCurves now take notice of error bar settings. Re #2657.
Browse files Browse the repository at this point in the history
Though they can only be customised from python at the moment,
and are not retained on saving a project.
  • Loading branch information
RussellTaylor committed Jan 8, 2012
1 parent b1ca7c5 commit 20b8bc4
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Code/Mantid/MantidPlot/mantidplotpy/proxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def addCurve(self, table, columnName, style=0, lineWidth=1, symbolSize=3, startR
"""
return self._getHeldObject().addCurves(table._getHeldObject(),columnName,style,lineWidth,symbolSize,startRow,endRow)

def addErrorBars(self, yColName, errTable, errColName, type=1, width=1, cap=8, color=Qt.black, through=True, minus=True, plus=True):
def addErrorBars(self, yColName, errTable, errColName, type=1, width=1, cap=8, color=Qt.black, through=False, minus=True, plus=True):
"""Add error bars to a plot that was created from a table column.
Args:
Expand All @@ -209,7 +209,7 @@ def addErrorBars(self, yColName, errTable, errColName, type=1, width=1, cap=8, c
width: The line width of the error bars (default: 1).
cap: The length of the cap on the error bars (default: 8).
color: The color of error bars (default: black).
through: Whether the error bars are drawn through the symbol (default: yes).
through: Whether the error bars are drawn through the symbol (default: no).
minus: Whether these errors should be shown as negative errors (default: yes).
plus: Whether these errors should be shown as positive errors (default: yes).
"""
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/MantidPlot/src/Graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,11 @@ public slots:
//@{
QwtErrorPlotCurve* addErrorBars(const QString& xColName, const QString& yColName, Table *errTable,
const QString& errColName, int type = 1, double width = 1, int cap = 8, const QColor& color = QColor(Qt::black),
bool through = true, bool minus = true, bool plus = true);
bool through = false, bool minus = true, bool plus = true);

QwtErrorPlotCurve* addErrorBars(const QString& yColName, Table *errTable, const QString& errColName,
int type = 1, double width = 1, int cap = 8, const QColor& color = QColor(Qt::black),
bool through = true, bool minus = true, bool plus = true);
bool through = false, bool minus = true, bool plus = true);

/// Adds the errors to an existing MantidCurve
void addMantidErrorBars(const QString& curveName,bool drawAll);
Expand Down
6 changes: 3 additions & 3 deletions Code/Mantid/MantidPlot/src/Mantid/ErrorBarSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* Sets defaults of black lines having width 1.0 and caps of length 6,
* that show on both sides of the symbol but don't draw through it.
*/
ErrorBarSettings::ErrorBarSettings()
: m_cap(6), m_plus(true), m_minus(true), m_through(false),
m_width(1.0), m_color(Qt::black)
ErrorBarSettings::ErrorBarSettings(QObject * parent)
: QObject(parent), m_cap(6), m_plus(true), m_minus(true),
m_through(false), m_width(1.0), m_color(Qt::black)
{}

/// Return the length of the cap decoration on the error bars
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/MantidPlot/src/Mantid/ErrorBarSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ErrorBarSettings : public QObject
{
Q_OBJECT
public:
ErrorBarSettings();
ErrorBarSettings(QObject * parent = 0);

int capLength() const;
void setCapLength(int t);
Expand Down
58 changes: 43 additions & 15 deletions Code/Mantid/MantidPlot/src/Mantid/MantidCurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Constructor
*/
MantidCurve::MantidCurve(const QString& wsName, bool err, bool allError)
: PlotCurve(wsName), WorkspaceObserver(),
m_drawErrorBars(err), m_drawAllErrorBars(allError), m_errorSettings(new ErrorBarSettings)
m_drawErrorBars(err), m_drawAllErrorBars(allError), m_errorSettings(new ErrorBarSettings(this))
{
}

Expand All @@ -28,7 +28,7 @@ Constructor
*/
MantidCurve::MantidCurve(bool err)
: PlotCurve(), WorkspaceObserver(),
m_drawErrorBars(err), m_drawAllErrorBars(false), m_errorSettings(new ErrorBarSettings)
m_drawErrorBars(err), m_drawAllErrorBars(false), m_errorSettings(new ErrorBarSettings(this))
{
}

Expand Down Expand Up @@ -116,7 +116,6 @@ void MantidCurve::axisScaleChanged(int axis, bool toLog)
/// Destructor
MantidCurve::~MantidCurve()
{
delete m_errorSettings;
}


Expand Down Expand Up @@ -151,28 +150,57 @@ void MantidCurve::doDraw(QPainter *p,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
const QRect&, MantidQwtWorkspaceData const * const d) const
{
int sh = 0;
const QwtSymbol symbol(symbol());
if (symbol.style() != QwtSymbol::NoSymbol)
{
sh = symbol.size().height() / 2;
}

int xi0 = 0;
p->setPen(pen());
const int dx = 3;
QPen pen(pen());
pen.setColor(m_errorSettings->color());
pen.setWidth(m_errorSettings->width());
p->setPen(pen);
const int dx = m_errorSettings->capLength()/2;
const int dx2 = 2*dx;
int x1 = static_cast<int>(floor(xMap.p1()));
int x2 = static_cast<int>(floor(xMap.p2()));
for (int i = 0; i < static_cast<int>(d->esize()); i++)
const int x1 = static_cast<int>(floor(xMap.p1()));
const int x2 = static_cast<int>(floor(xMap.p2()));

const int skipPoints = skipSymbolsCount();
for (int i = 0; i < static_cast<int>(d->esize()); i += skipPoints)
{
const int xi = xMap.transform(d->ex(i));
if (m_drawAllErrorBars || (xi > x1 && xi < x2 && (i == 0 || abs(xi - xi0) > dx2)))
{
const double Y = y(i);
const double E = d->e(i);
const int yi = yMap.transform(Y);
const int ei1 = yMap.transform(Y - E);
const int ei2 = yMap.transform(Y + E);

// This call can crash MantidPlot if the error is zero,
// so protect against this (line of zero length anyway)
if (E) p->drawLine(xi,ei1,xi,ei2);
p->drawLine(xi-dx,ei1,xi+dx,ei1);
p->drawLine(xi-dx,ei2,xi+dx,ei2);

const int yhl = yi - sh;
const int ylh = yi + sh;


if ( m_errorSettings->minusSide() )
{
// This call can crash MantidPlot if the error is zero,
// so protect against this (line of zero length anyway)
if (E) p->drawLine(xi,ei1,xi,ylh);
p->drawLine(xi-dx,ei1,xi+dx,ei1);
}
if ( m_errorSettings->plusSide() )
{
// This call can crash MantidPlot if the error is zero,
// so protect against this (line of zero length anyway)
if (E) p->drawLine(xi,yhl,xi,ei2);
p->drawLine(xi-dx,ei2,xi+dx,ei2);
}
if ( m_errorSettings->throughSymbol() )
{
if (E) p->drawLine(xi,yhl,xi,ylh);
}

xi0 = xi;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/MantidPlot/src/PlotCurve.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Q_OBJECT
//! Set the number of symbols not to be drawn: useful for large data sets
void setSkipSymbolsCount(int count);
//! Returns the number of symbols not to be drawn
int skipSymbolsCount() {return d_skip_symbols;}
int skipSymbolsCount() const {return d_skip_symbols;}

/// Returns a list of error bar settings for each set of error bars associated to this curve
virtual QList<ErrorBarSettings*> errorBarSettingsList() const = 0;
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/MantidPlot/src/qti.sip
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,8 @@ public:
%End

void addErrorBars(const QString&, Table *, const QString&,
int type = 1, double width = 1, int cap = 8, const QColor& color = QColor(Qt::black),
bool through = true, bool minus = true, bool plus = true);
int type = 1, double width = 1, int cap = 8, const QColor& color = QColor(Qt::black),
bool through = false, bool minus = true, bool plus = true);

ErrorBarSettings* errorBarSettings(int curveIndex, int errorBarIndex = 0);

Expand Down

0 comments on commit 20b8bc4

Please sign in to comment.