Skip to content
Permalink
Browse files

Curve fill colored zones (AllPlot) 2/2

.. UserData series now have a zone string that
   can be used to define upper values and associated
   colors for shading a curve.

.. the format is: lim,colorname;lim,colorname;

   where lim is an upper value and colorname is
   either a #rgb string or any color name such
   as red,green, blue etc from the list of SVG
   color keyword names provided by the World Wide
   Web Consortium.

   e.g:  200,green;300,yellow;9999,red
   which will shade points <200 green, <300 will be
   yellow and then <9999 will be red.

   The zones must be listed in ascending order.
  • Loading branch information...
liversedge committed Mar 12, 2019
1 parent d2a8951 commit 681f87a4323e3b5b76450465b6f3593b079ce963
Showing with 55 additions and 21 deletions.
  1. +29 −9 src/Charts/AllPlot.cpp
  2. +2 −0 src/Charts/AllPlot.h
  3. +6 −2 src/Charts/AllPlotWindow.cpp
  4. +13 −7 src/Core/UserData.cpp
  5. +5 −3 src/Core/UserData.h
@@ -492,6 +492,31 @@ AllPlotObject::AllPlotObject(AllPlot *plot, QList<UserData*> user) : plot(plot)

}

QVector<QwtZone>
AllPlotObject::parseZoneString(QString zstring)
{
QVector<QwtZone> returning;

// split zstring into ; delimetered tokens
foreach(QString entry, zstring.split(";")) {

// need value, colorname
QStringList toks = entry.split(",");
if (toks.count()!=2) continue;
bool ok;
double lim=toks[0].toDouble(&ok);
if (!ok) continue;
QColor col;
col.setNamedColor(toks[1]);
if (!col.isValid()) continue;

// well that worked!
returning << QwtZone(lim,col);

}
return returning;
}

void
AllPlotObject::setUserData(QList<UserData*>user)
{
@@ -525,21 +550,16 @@ AllPlotObject::setUserData(QList<UserData*>user)
add.color = userdata->color;
add.color.setAlpha(200);

#if 0 // just for testing zones, will be deleted shortly XXX
// set zones - just for testing during development of zone curve
QVector<QwtZone> zones;
zones << QwtZone(210, Qt::green);
zones << QwtZone(300, Qt::yellow);
zones << QwtZone(9999, Qt::red);
add.curve->setZones(zones);
#endif
// set zones
QVector<QwtZone> zones = parseZoneString(userdata->zstring);
if (zones.count()>0) add.curve->setZones(zones);

QPen pen;
pen.setWidth(1.0);
pen.setColor(userdata->color);
add.curve->setPen(pen);

if (plot->fill) {
if (plot->fill || zones.count()>0) {
QColor p = add.color;
p.setAlpha(64);
add.curve->setBrush(QBrush(p));
@@ -348,6 +348,7 @@ struct UserObject {
QVector<double> array;
QVector<double> smooth;
QwtPlotGappedCurve *curve;
QVector<QwtZone> zones;
QColor color;
};

@@ -370,6 +371,7 @@ class AllPlotObject : public QObject
void setColor(QColor color); // set ALL curves the same color
void hideUnwanted(); // hide curves we are not interested in
// using setVisible ...
QVector<QwtZone> parseZoneString(QString zstring);

QwtPlotGrid *grid;
QVector<QwtPlotMarker*> d_mrk;
@@ -1062,6 +1062,7 @@ AllPlotWindow::editUserData()
UserData edit(userDataSeries[index]->name,
userDataSeries[index]->units,
userDataSeries[index]->formula,
userDataSeries[index]->zstring,
userDataSeries[index]->color);

EditUserDataDialog dialog(context, &edit);
@@ -1070,6 +1071,7 @@ AllPlotWindow::editUserData()

// apply!
userDataSeries[index]->formula = edit.formula;
userDataSeries[index]->zstring = edit.zstring;
userDataSeries[index]->name = edit.name;
userDataSeries[index]->units = edit.units;
userDataSeries[index]->color = edit.color;
@@ -1093,6 +1095,7 @@ AllPlotWindow::doubleClicked( int row, int )
UserData edit(userDataSeries[row]->name,
userDataSeries[row]->units,
userDataSeries[row]->formula,
userDataSeries[row]->zstring,
userDataSeries[row]->color);

EditUserDataDialog dialog(context, &edit);
@@ -1101,6 +1104,7 @@ AllPlotWindow::doubleClicked( int row, int )

// apply!
userDataSeries[row]->formula = edit.formula;
userDataSeries[row]->zstring = edit.zstring;
userDataSeries[row]->name = edit.name;
userDataSeries[row]->units = edit.units;
userDataSeries[row]->color = edit.color;
@@ -1149,7 +1153,7 @@ AllPlotWindow::addUserData()

if (dialog.exec()) {
// apply
userDataSeries.append(new UserData(add.name, add.units, add.formula, add.color));
userDataSeries.append(new UserData(add.name, add.units, add.formula, add.zstring, add.color));

// refresh
refreshCustomTable();
@@ -1263,7 +1267,7 @@ AllPlotWindow::compareChanged()
foreach(CompareInterval ci, context->compareIntervals) {
QList<UserData*> list;
foreach(UserData *u, userDataSeries) {
UserData *p = new UserData(u->name, u->units, u->formula, ci.color); // use context for interval
UserData *p = new UserData(u->name, u->units, u->formula, u->zstring, ci.color); // use context for interval
p->setRideItem(ci.rideItem);
list << p;
}
@@ -26,19 +26,19 @@
#include <QTextEdit> // for parsing trademark symbols (!)

UserData::UserData()
: name(""), units(""), formula(""), color(QColor(0,0,0)), rideItem(NULL)
: name(""), units(""), formula(""), zstring(""), color(QColor(0,0,0)), rideItem(NULL)
{
}

UserData::UserData(QString settings)
: name(""), units(""), formula(""), color(QColor(0,0,0)), rideItem(NULL)
: name(""), units(""), formula(""), zstring(""), color(QColor(0,0,0)), rideItem(NULL)
{
// and apply settings
setSettings(settings);
}

UserData::UserData(QString name, QString units, QString formula, QColor color)
: name(name), units(units), formula(formula), color(color), rideItem(NULL)
UserData::UserData(QString name, QString units, QString formula, QString zstring, QColor color)
: name(name), units(units), formula(formula), zstring(zstring), color(color), rideItem(NULL)
{
}

@@ -86,6 +86,8 @@ EditUserDataDialog::EditUserDataDialog(Context *context, UserData *here) :
nameEdit->setText(here->name);
unitsEdit = new QLineEdit(this);
unitsEdit->setText(here->units);
zstringEdit = new QLineEdit(this);
zstringEdit->setText(here->zstring);

// formula editor
formulaEdit = new DataFilterEdit(this, context);
@@ -194,8 +196,10 @@ EditUserDataDialog::EditUserDataDialog(Context *context, UserData *here) :
widgets->addWidget(unitsEdit, 1, 1);
widgets->addWidget(new QLabel(tr("Formula")), 2, 0, Qt::AlignLeft|Qt::AlignTop);
widgets->addWidget(formulaEdit, 2, 1);
widgets->addWidget(new QLabel(tr("Color")), 3, 0);
widgets->addWidget(seriesColor, 3, 1);
widgets->addWidget(new QLabel(tr("Zone string")), 3, 0, Qt::AlignLeft|Qt::AlignTop);
widgets->addWidget(zstringEdit, 3, 1);
widgets->addWidget(new QLabel(tr("Color")), 4, 0);
widgets->addWidget(seriesColor, 4, 1);
mainLayout->addLayout(widgets);
widgets->setColumnStretch(1,100);
widgets->setRowStretch(2,100);
@@ -222,6 +226,7 @@ EditUserDataDialog::applyClicked()
here->units = unitsEdit->text();
here->name = nameEdit->text();
here->formula = formulaEdit->toPlainText();
here->zstring = zstringEdit->text();
accept();
}

@@ -271,7 +276,7 @@ UserData::settings() const
{
QString returning;
returning = "<userdata name=\"" + Utils::xmlprotect(name) + "\" units=\"" + Utils::xmlprotect(units)+ "\"";
returning += " color=\""+ color.name() + "\">";
returning += " color=\""+ color.name() + "\" zstring=\"" + Utils::xmlprotect(zstring) + "\">";
returning += Utils::xmlprotect(formula);
returning += "</userdata>";

@@ -313,6 +318,7 @@ bool UserDataParser::startElement( const QString&, const QString&, const QString
// only 3 attributes for now
if (attrs.qName(i) == "color") here->color = QColor(attrs.value(i));
if (attrs.qName(i) == "name") here->name = Utils::unprotect(attrs.value(i));
if (attrs.qName(i) == "zstring") here->zstring = Utils::unprotect(attrs.value(i));
if (attrs.qName(i) == "units") here->units = Utils::unprotect(attrs.value(i));
}
return true;
@@ -52,7 +52,7 @@ class UserData : public QObject {

UserData();
UserData(QString settings);
UserData(QString name, QString units, QString formula, QColor color);
UserData(QString name, QString units, QString formula, QString zstring, QColor color);
~UserData();

// does it have values other than NA?
@@ -62,7 +62,8 @@ class UserData : public QObject {
// as get/set is tedious for these kinds of attrs
QString name,
units,
formula;
formula,
zstring;
QColor color;

QVector<double> vector; // the actuall data series !
@@ -107,7 +108,8 @@ class EditUserDataDialog : public QDialog

// name, units
QLineEdit *nameEdit,
*unitsEdit;
*unitsEdit,
*zstringEdit;
QPushButton *seriesColor;
QColor color; // remember what we edited
void setButtonIcon(QColor);

0 comments on commit 681f87a

Please sign in to comment.
You can’t perform that action at this time.