Newer
Older
}
/** Return which coordinates to use as the X axis to plot in the line view.
*
* @return PlotAxisChoice, either Auto, X, Y or Distance.
*/
int LineViewer::getPlotAxis() const
return m_lineOptions->getPlotAxis();
// ==============================================================================================
// ================================== Rendering =================================================
// ==============================================================================================
//-----------------------------------------------------------------------------
/** Calculate and show the preview (non-integrated) line,
* using the current parameters. */
void LineViewer::showPreview()
{
MantidQwtIMDWorkspaceData curveData(m_ws, isLogScaledY(),
m_start, m_end, m_lineOptions->getNormalization());
curveData.setPreviewMode(true);
curveData.setPlotAxisChoice(m_lineOptions->getPlotAxis());
m_previewCurve->setData(curveData);
if (m_fullCurve->isVisible())
{
m_fullCurve->setVisible(false);
m_fullCurve->detach();
m_previewCurve->attach(m_plot);
}
m_previewCurve->setVisible(true);
m_plot->replot();
m_plot->setTitle("Preview Plot");
m_plot->setAxisTitle( QwtPlot::xBottom, QString::fromStdString( curveData.getXAxisLabel() ));;
m_plot->setAxisTitle( QwtPlot::yLeft, QString::fromStdString( curveData.getYAxisLabel() ));;
/**
Gets the dimension index corresponding to the lineviewers preview plot x axis.
@return the index.
*/
int LineViewer::getXAxisDimensionIndex() const
{
MantidQwtIMDWorkspaceData curveData(m_ws, isLogScaledY(),
m_start, m_end, m_lineOptions->getNormalization());
curveData.setPreviewMode(true);
curveData.setPlotAxisChoice(m_lineOptions->getPlotAxis());
return curveData.currentPlotXAxis();
}
/**
* Getter for the log scaled status.
* @return True if and only if the y-axis is log scaled.
*/
bool LineViewer::isLogScaledY() const
{
return m_lineOptions->isLogScaledY();
}
//-----------------------------------------------------------------------------
/** Calculate and show the full (integrated) line, using the latest
* integrated workspace. The apply() method must have been called
* before calling this. */
void LineViewer::showFull()
{
if (!m_sliceWS) return;
MatrixWorkspace_const_sptr sliceMatrix = boost::dynamic_pointer_cast<const MatrixWorkspace>(m_sliceWS);
if (sliceMatrix)
{
MantidQwtMatrixWorkspaceData curveData(sliceMatrix, 0, isLogScaledY());
m_fullCurve->setData(curveData);
Unit_const_sptr unit = sliceMatrix->getAxis(0)->unit();
std::string title = unit->caption() + " (" + unit->label() + ")";
m_plot->setAxisTitle( QwtPlot::xBottom, QString::fromStdString(title));;
title = sliceMatrix->YUnit() + " (" + sliceMatrix->YUnitLabel() + ")";
m_plot->setAxisTitle( QwtPlot::yLeft, QString::fromStdString(title));;
MantidQwtIMDWorkspaceData curveData(m_sliceWS, isLogScaledY(),
VMD(), VMD(), m_lineOptions->getNormalization());
curveData.setPreviewMode(false);
curveData.setPlotAxisChoice(m_lineOptions->getPlotAxis());
m_fullCurve->setData(curveData);
m_plot->setAxisTitle( QwtPlot::xBottom, QString::fromStdString( curveData.getXAxisLabel() ));;
m_plot->setAxisTitle( QwtPlot::yLeft, QString::fromStdString( curveData.getYAxisLabel() ));;
}
if (m_previewCurve->isVisible())
{
m_previewCurve->setVisible(false);
m_previewCurve->detach();
m_fullCurve->attach(m_plot);
}
m_fullCurve->setVisible(true);
m_plot->replot();
m_plot->setTitle("Integrated Line Plot");
//-----------------------------------------------------------------------------
/** Slot called when the options of the plot display change (normalization
* or plot axis.
* Refreshes the preview or full plot, whichever is visible.
*/
void LineViewer::refreshPlot()
{
if (m_previewCurve->isVisible())
showPreview();
else
showFull();
}
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
/**
* Helper method to get the positive min value.
* @param curve : Curve to look through the data of.
* @param to : Start value
* @return : Positive min value.
*/
double getPositiveMin(LineViewerCurve* curve, const double to)
{
double yPositiveMin = to;
int n = curve->dataSize();
for (int i = 0; i < n; ++i)
{
double y = curve->y(i);
if (y > 0 && y < yPositiveMin)
{
yPositiveMin = y;
}
}
return yPositiveMin;
}
/**
* Handler for the log10 toggle axis event.
*/
void LineViewer::onToggleLogYAxis()
{
const QwtScaleDiv *div = m_plot->axisScaleDiv(QwtPlot::yLeft);
auto interval = div->interval();
double from = interval.minValue();
double to = interval.maxValue();
const bool logScaled = m_lineOptions->isLogScaledY();
QwtScaleEngine* engine = NULL;
double yPositiveMin = 0;
LineViewerCurve* curve = m_previewCurve;
if (m_fullCurve->isVisible())
{
curve = m_fullCurve;
}
if (logScaled)
{
engine = new QwtLog10ScaleEngine();
yPositiveMin = getPositiveMin(curve, to);
}
else
{
engine = new QwtLinearScaleEngine();
yPositiveMin = from;
}
curve->setLogScale(logScaled);
m_plot->setAxisScaleEngine(QwtPlot::yLeft, engine);
m_plot->setAxisScale(QwtPlot::yLeft, yPositiveMin, to);
refreshPlot(); // Data should now be log scale.
m_plot->replot();
}