Commit 3f0791f2 authored by Giacomo Strangolino's avatar Giacomo Strangolino
Browse files

fixes to curves

parent ec3b8ccc
No preview for this file type
......@@ -164,11 +164,16 @@ void I0mapmon::m_setup_x_list() {
ui->qucbx->setItemData(ui->qucbx->count() - 1, "pos/diagnostics/pico_pos.01/GetId", Qt::UserRole + 1);
}
QList<int> I0mapmon::m_selected_wlens() const {
QList<int> idxs;
for(int i = 0; i < m_cb_model->rowCount(); i++) // i - 1: item 0: "time"
if(m_cb_model->item(i)->data(Qt::CheckStateRole).toBool()) idxs << i - 1;
return idxs;
QMap<int, double> I0mapmon::m_selected_wlens() const {
QMap<int, double> m;
for(int i = 1; i < m_cb_model->rowCount(); i++) {// item 0: "time"
qDebug() << __PRETTY_FUNCTION__ << "model row count" << m_cb_model->rowCount() << "row" << i << "checked" << m_cb_model->item(i)->data(Qt::CheckStateRole).toBool()
<< "text " << m_cb_model->item(i)->data(Qt::DisplayRole).toString() << ui->qucblambda->itemText(i).toDouble();
if(m_cb_model->item(i)->data(Qt::CheckStateRole).toBool()) {
m[i - 1] = ui->qucblambda->itemText(i).toDouble();
}
}
return m;
}
void I0mapmon::m_plot_reconf() {
......
......@@ -49,7 +49,7 @@ private:
// methods
void m_setup_x_list();
QList<int> m_selected_wlens() const;
QMap<int, double> m_selected_wlens() const;
};
#endif // I0mapmon_H
......@@ -18,9 +18,12 @@
#endif
I0MMonPlot::I0MMonPlot(QWidget *parent, CumbiaPool *cup, const CuControlsFactoryPool &fpoo)
: QuPlotBase(parent) {
: QuPlotBase(parent),
m_symstyles (QList<QwtSymbol::Style> () << QwtSymbol::XCross << QwtSymbol::Cross
<< QwtSymbol::Rect << QwtSymbol::Triangle << QwtSymbol::Star1 << QwtSymbol::Diamond << QwtSymbol::Ellipse) {
m_ctrl_fpool = fpoo;
m_cu_poo = cup;
m_time_mode = m_empty = true;
m_numsamples = 1;
CuPluginLoader plo;
QObject *plugin_qob;
......@@ -44,9 +47,10 @@ bool I0MMonPlot::pluginLoaded() const {
void I0MMonPlot::onDataReady(const QList<CuData> &dl) {
qDebug() << __PRETTY_FUNCTION__ << "data szi" << dl.size();
double x;
foreach(QwtPlotCurve *c, curves()) {
if(c->style() != QwtPlotCurve::Dots) {
double x = 0.0;
foreach(QString cn, m_curvesymap.keys()) {
QuPlotCurve *c = curve(cn);
if(c && c->style() != QwtPlotCurve::Dots) {
c->setStyle(QwtPlotCurve::Dots);
QPen p = c->pen();
p.setWidthF(2.0f);
......@@ -55,10 +59,10 @@ void I0MMonPlot::onDataReady(const QList<CuData> &dl) {
#if CUMBIA_QTCONTROLS_VERSION > 0x010202
c->setMaxDataSizeForSymbol(0); // disable first points symbol
#endif
if(!c->symbol() || c->symbol()->style() != QwtSymbol::XCross)
c->setSymbol(new QwtSymbol(QwtSymbol::XCross, c->brush(), c->pen(), QSize(10, 10)));
if(!c->symbol() || c->symbol()->style() != m_curvesymap[cn])
c->setSymbol(new QwtSymbol(m_curvesymap[cn], c->brush(), c->pen(), QSize(10, 10)));
}
if(dl.size() == 2) { // correlate
if(!m_time_mode && dl.size() == 2) { // correlate
QVector<double> yv, xv;
const CuData& xd = dl[0];
const CuData& yd = dl[1];
......@@ -70,30 +74,24 @@ void I0MMonPlot::onDataReady(const QList<CuData> &dl) {
for(size_t i = 0; i < v.size(); i++)
sum += v[i];
x = sum / m_numsamples;
printf("x (%f) averaged across %ld samples\n", v.size());
printf("x (%f) averaged across %ld samples\n", x, v.size());
}
else
x = xd["value"].toDouble();
// y
const std::vector<double> &yt = yd["value"].toDoubleVector();
for(int i = 0; i < m_lambda_idxs.size(); i++) {
if(m_lambda_idxs[i] < static_cast<int>(yt.size()) ) {
yv.push_back(yt[m_lambda_idxs[i]]);
xv.push_back(x);
foreach(int i, m_lambdas.keys()) {
printf("lambda key %d yt size %ld\n", i, yt.size());
if(i < static_cast<int>(yt.size()) ) {
printf("\e[0;35m - appending to curve %f %f %f\e[0m\n", m_lambdas[i], x, yt[i]);
appendData(QString("lambda %1").arg(m_lambdas[i]), x, yt[i]);
yv << yt[i];
xv << x;
}
}
QuPlotCurve * c = curve(m_curvenames.first());
if(c) {
printf("\e[1;32mI0MMonPlot::onDataReady: curve: %s { ", qstoc(c->title().text()));
for(int i = 0; i < xv.size(); i++)
printf("(%.2f, %.2f), ", xv[i], yv[i]);
printf(" }\e[0m\n");
m_set_bounds(xv, yv, c->dataSize());
appendData(m_curvenames.first(), xv.data(), yv.data(), xv.size());
}
m_set_bounds(xv, yv);
}
else if(dl.size() == 1) { // trend
else { // trend in time
const CuData &da = dl[0];
const std::vector<double> &ystdv = da["value"].toDoubleVector();
......@@ -103,49 +101,49 @@ void I0MMonPlot::onDataReady(const QList<CuData> &dl) {
xv << (la);
const QVector<double> yv = QVector<double>::fromStdVector(ystdv);
#else
const QVector<double> xv(m_lambda_idxs.begin(), m_lambda_idxs.end());
QList<double> lambdas = m_lambdas.values();
std::sort(lambdas.begin(), lambdas.end());
const QVector<double> xv = lambdas.toVector();
const QVector<double> yv(ystdv.begin(), ystdv.end());
#endif
// CuVariant ts = da["timestamp_ms"];
// ts.getType() == CuVariant::LongInt ? x = static_cast<qint64>(ts.toLongInt()) : x = ts.toDouble();
printf("\e[0;33mdata %s -- timestamp %f\e[0m\n", datos(da), x);
for(int i = 0; i < m_lambda_idxs.size(); i++) {
const QString curveName = QString("lambda %1").arg(m_lambda_idxs[i]);
if(m_lambda_idxs[i] < static_cast<int>(yv.size()) && curve(curveName) != nullptr ) {
qDebug() << __PRETTY_FUNCTION__ << "APPENDING" << QDateTime::fromMSecsSinceEpoch(x) << yv[m_lambda_idxs[i]];
m_set_bounds(xv, yv, curve(curveName)->dataSize());
appendData(curveName, m_lambda_idxs[i], yv[m_lambda_idxs[i]]);
foreach(int idx, m_lambdas.keys()) {
const QString curveName = QString("lambda %1").arg(m_lambdas[idx]);
if(idx < static_cast<int>(yv.size()) && curve(curveName) != nullptr ) {
m_set_bounds(xv, yv);
appendData(curveName, m_lambdas[idx], yv[idx]);
}
}
refresh();
}
m_empty = false;
}
void I0MMonPlot::setSources(const QString &x, const QString &y, const QList<int> &lambda_idxs, int nsamples)
void I0MMonPlot::setSources(const QString &x, const QString &y, const QMap<int, double> lambdamap, int nsamples)
{
qDebug() << __PRETTY_FUNCTION__ << x << y << lambda_idxs;
qDebug() << __PRETTY_FUNCTION__ << x << y << lambdamap;
QuPlotBase::clearPlot();
m_multiread_plu_i->unsetSources();
m_curvenames.clear();
m_curvesymap.clear();
m_empty = true;
m_numsamples = nsamples;
m_lambda_idxs = lambda_idxs;
m_lambdas = lambdamap;
m_time_mode = (x == "time");
m_reset_scales();
if(x == "time") {
foreach(int l, lambda_idxs) {
QString cuna = QString("lambda %1").arg(l);
QuPlotCurve *crv = curve(cuna);
if(!crv) {
crv = new QuPlotCurve(cuna);
addCurve(cuna, crv);
}
m_curvenames = QStringList() << QString("lambda %1").arg(l);
foreach(double l, lambdamap.values()) {
QString cuna = QString("lambda %1").arg(l);
QuPlotCurve *crv = curve(cuna);
if(!crv) {
crv = new QuPlotCurve(cuna);
addCurve(cuna, crv);
}
m_curvesymap[cuna] = m_symstyles[m_curvesymap.size() % m_symstyles.size()];
}
if(m_time_mode) {
if(m_multiread_plu_i)
m_multiread_plu_i->insertSource(y, 0);
}
else {
addCurve(y);
m_curvenames = QStringList() << y;
if(m_multiread_plu_i ) {
QString xsrc;
x.contains(QRegularExpression("\\(\\d,%\\d\\)")) ? xsrc = QString(x).arg(nsamples) : xsrc = x;
......@@ -155,17 +153,17 @@ void I0MMonPlot::setSources(const QString &x, const QString &y, const QList<int>
}
}
void I0MMonPlot::m_set_bounds(const QVector<double> &xv, const QVector<double> &yv, int curve_datasiz)
void I0MMonPlot::m_set_bounds(const QVector<double> &xv, const QVector<double> &yv)
{
// scales
const auto [xm, xM] = std::minmax_element(begin(xv), end(xv));
const auto [ym, yM] = std::minmax_element(begin(yv), end(yv));
double xlb, xub, ylb, yub;
xlb = (curve_datasiz == 0) ? (*xm) : xLowerBound();
xub = (curve_datasiz == 0) ? (*xM) : xUpperBound();
ylb = (curve_datasiz == 0) ? (*ym) : yLowerBound();
yub = (curve_datasiz == 0) ? (*yM) : yUpperBound();
xlb = m_empty ? (*xm) : xLowerBound();
xub = m_empty ? (*xM) : xUpperBound();
ylb = m_empty ? (*ym) : yLowerBound();
yub = m_empty ? (*yM) : yUpperBound();
if(*xm == *xM) {
if(xlb >= *xm)
......@@ -174,9 +172,9 @@ void I0MMonPlot::m_set_bounds(const QVector<double> &xv, const QVector<double> &
xub = (*xM + 0.5);
} else {
if(xlb >= *xm)
xlb = (*xm - 0.05 * (*xM - *xm));
xlb = (*xm - 0.15 * (*xM - *xm));
if(xub <= *xM)
xub = (*xM + 0.05 * (*xM - *xm));
xub = (*xM + 0.15 * (*xM - *xm));
}
if(*yM == *ym) {
if(ylb >= *ym)
......@@ -185,9 +183,9 @@ void I0MMonPlot::m_set_bounds(const QVector<double> &xv, const QVector<double> &
yub = (*yM + 0.5);
} else {
if(ylb >= *ym)
ylb = (*ym - 0.05 * (*yM - *ym));
ylb = (*ym - 0.15 * (*yM - *ym));
if(yub <= *yM)
yub = (*yM + 0.05 * (*yM - *ym));
yub = (*yM + 0.15 * (*yM - *ym));
}
if(xlb != xLowerBound())
setXLowerBound(xlb);
......
......@@ -4,6 +4,7 @@
#include <cucontrolsfactorypool.h>
#include <quplot_base.h>
#include <cudata.h>
#include <qwt_symbol.h>
#include <QString>
class CumbiaPool;
......@@ -21,11 +22,11 @@ signals:
public slots:
void onDataReady(const QList<CuData> & dl);
void setSources(const QString& x, const QString& y, const QList<int>& lambda_idxs, int nsamples);
void setSources(const QString& x, const QString& y, const QMap<int, double> lambdamap, int nsamples);
private:
void m_set_bounds(const QVector<double> &xv, const QVector<double> &yv, int curve_datasiz);
void m_set_bounds(const QVector<double> &xv, const QVector<double> &yv);
void m_reset_scales();
void m_set_x_trend_scale();
......@@ -34,8 +35,12 @@ private:
QuMultiReaderPluginInterface *m_multiread_plu_i;
int m_numsamples;
QList<int> m_lambda_idxs;
QStringList m_curvenames;
QMap<int, double> m_lambdas;
QMap<QString, QwtSymbol::Style> m_curvesymap;
const QList<QwtSymbol::Style> m_symstyles;
bool m_time_mode, m_empty;
};
#endif // I0MMONPLOT_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment