Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/7579_plot_using_selected_x'
Browse files Browse the repository at this point in the history
  • Loading branch information
Anders-Markvardsen committed Sep 25, 2013
2 parents f841040 + ae1be2a commit 7aac045
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 42 deletions.
5 changes: 4 additions & 1 deletion Code/Mantid/MantidPlot/src/ApplicationWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16448,6 +16448,9 @@ bool ApplicationWindow::validFor2DPlot(Table *table)
if (!table->selectedYColumns().count()){
QMessageBox::warning(this, tr("MantidPlot - Error"), tr("Please select a Y column to plot!"));//Mantid
return false;
} else if (table->selectedXColumns().count() > 1){
QMessageBox::warning(this, tr("MantidPlot - Error"), tr("Can't plot using multiple X columns!"));//Mantid
return false;
} else if (table->numCols()<2) {
QMessageBox::critical(this, tr("MantidPlot - Error"),tr("You need at least two columns for this operation!"));//Mantid
return false;
Expand All @@ -16470,7 +16473,7 @@ MultiLayer* ApplicationWindow::generate2DGraph(Graph::CurveType type)
return 0;

Q3TableSelection sel = table->getSelection();
return multilayerPlot(table, table->drawableColumnSelection(), type, sel.topRow(), sel.bottomRow());
return multilayerPlot(table, table->selectedColumns(), type, sel.topRow(), sel.bottomRow());
} else if (w->isA("Matrix")){
Matrix *m = static_cast<Matrix *>(w);
return plotHistogram(m);
Expand Down
113 changes: 72 additions & 41 deletions Code/Mantid/MantidPlot/src/Graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3145,53 +3145,84 @@ bool Graph::addCurves(Table* w, const QStringList& names, int style, double lWid
else if (style == VectXYXY || style == VectXYAM)
plotVectorCurve(w, names, style, startRow, endRow);
else {
int curves = (int)names.count();
int errCurves = 0;
QStringList lst = QStringList();
for (int i=0; i<curves; i++)
{//We rearrange the list so that the error bars are placed at the end
int j = w->colIndex(names[i]);
if (w->colPlotDesignation(j) == Table::xErr || w->colPlotDesignation(j) == Table::yErr ||
w->colPlotDesignation(j) == Table::Label){
errCurves++;
lst << names[i];
} else
lst.prepend(names[i]);
}
QStringList drawableNames;
int noOfErrorCols = 0;
QString xColNameGiven;

for (int i=0; i<curves; i++){
int j = w->colIndex(names[i]);
PlotCurve *c = NULL;
if (w->colPlotDesignation(j) == Table::xErr || w->colPlotDesignation(j) == Table::yErr){
int ycol = w->colY(w->colIndex(names[i]));
if (ycol < 0)
return false;
// Select only those column names which we can draw and search for any X columns specified
for (int i = 0; i < names.count(); i++)
{
int d = w->colPlotDesignation(w->colIndex(names[i]));

if (w->colPlotDesignation(j) == Table::xErr)
c = dynamic_cast<PlotCurve *>(addErrorBars(w->colName(ycol), w, names[i], static_cast<int>(QwtErrorPlotCurve::Horizontal)));
else
c = dynamic_cast<PlotCurve *>(addErrorBars(w->colName(ycol), w, names[i]));
} else if (w->colPlotDesignation(j) == Table::Label){
QString labelsCol = names[i];
int xcol = w->colX(w->colIndex(labelsCol));
int ycol = w->colY(w->colIndex(labelsCol));
if (xcol < 0 || ycol < 0)
if (d == Table::Y || d == Table::xErr || d == Table::yErr || d == Table::Label)
{
drawableNames << names[i];

// Count error columns
if(d == Table::xErr || d == Table::yErr)
noOfErrorCols++;
} else if(d == Table::X)
{
// If multiple X columns are specified, it's an error, as we don't know which one to use
if(!xColNameGiven.isEmpty())
return false;

DataCurve* mc = masterCurve(w->colName(xcol), w->colName(ycol));
if (mc){
d_plot->replot();
mc->setLabelsColumnName(labelsCol);
} else
xColNameGiven = names[i];
}
}

// Layout we will use to draw curves
CurveLayout cl = initCurveLayout(style, drawableNames.count() - noOfErrorCols);
cl.sSize = sSize;
cl.lWidth = float(lWidth);

for (int i = 0; i < drawableNames.count(); i++){
QString colName = drawableNames[i];
int colIndex = w->colIndex(colName);
int colType = w->colPlotDesignation(colIndex);

QString yColName;
if(colType == Table::Y)
// For Y columns we use the column itself as Y
yColName = colName;
else
// For other column types, we find associated Y column
yColName = w->colName(w->colY(colIndex));

QString xColName;
if(!xColNameGiven.isEmpty())
// If X column is given - use it
xColName = xColNameGiven;
else
// Otherise, use associated one
xColName = w->colName(w->colX(colIndex));

if (xColName.isEmpty() || yColName.isEmpty())
return false;

// --- Drawing error columns -----------------------------
if (colType == Table::xErr || colType == Table::yErr){
int dir;
if(colType == Table::xErr)
dir = QwtErrorPlotCurve::Horizontal;
else
dir = QwtErrorPlotCurve::Vertical;

PlotCurve* c = addErrorBars(xColName, yColName, w, colName, dir);
updateCurveLayout(c, &cl);
// --- Drawing label columns -----------------------------
} else if (colType == Table::Label){
DataCurve* mc = masterCurve(xColName, yColName);
if (!mc)
return false;
} else
c = dynamic_cast<PlotCurve *>(insertCurve(w, names[i], style, startRow, endRow));

if (c){
CurveLayout cl = initCurveLayout(style, curves - errCurves);
cl.sSize = sSize;
cl.lWidth = float(lWidth);
updateCurveLayout(c, &cl);
d_plot->replot();
mc->setLabelsColumnName(colName);
// --- Drawing Y columns -----------------------------
} else if (colType == Table::Y)
{
PlotCurve* c = insertCurve(w, xColName, yColName, style, startRow, endRow);
updateCurveLayout(c, &cl);
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions Code/Mantid/MantidPlot/src/Table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,17 @@ QStringList Table::selectedYColumns()
return names;
}

QStringList Table::selectedXColumns()
{
QStringList names;
for (int i=0;i<d_table->numCols();i++)
{
if(d_table->isColumnSelected (i) && col_plot_type[i] == X)
names<<QString(name())+"_"+col_label[i];
}
return names;
}

QStringList Table::selectedErrColumns()
{
QStringList names;
Expand Down
1 change: 1 addition & 0 deletions Code/Mantid/MantidPlot/src/Table.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ public slots:
void init(int rows, int cols);
QStringList selectedColumns();
QStringList selectedYColumns();
QStringList selectedXColumns();
QStringList selectedErrColumns();
QStringList selectedYLabels();
QStringList drawableColumnSelection();
Expand Down

0 comments on commit 7aac045

Please sign in to comment.