10 changes: 9 additions & 1 deletion src/Charts/GenericPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,18 @@ class GenericPlot : public QWidget {
};
typedef enum annotationType AnnotationType;

double scale() const { return scale_; }

public slots:

void configChanged(qint32);

// background color
QColor backgroundColor() { return bgcolor_; }
void setBackgroundColor(QColor bgcolor);

// set chart settings
bool initialiseChart(QString title, int type, bool animate, int legendpos);
bool initialiseChart(QString title, int type, bool animate, int legendpos, double scale=1.0f);

// add a curve, associating an axis
bool addCurve(QString name, QVector<double> xseries, QVector<double> yseries, QVector<QString> fseries, QString xname, QString yname,
Expand Down Expand Up @@ -166,5 +172,7 @@ class GenericPlot : public QWidget {
// axis placement (before user interacts)
// alternates as axis added
bool left, bottom;
double scale_;
QColor bgcolor_;
};
#endif
10 changes: 5 additions & 5 deletions src/Charts/GenericSelectTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void GenericSelectTool::paint(QPainter*painter, const QStyleOptionGraphicsItem *
// min max texts
QFont stGiles; // hoho - Chart Font St. Giles ... ok you have to be British to get this joke
stGiles.fromString(appsettings->value(NULL, GC_FONT_CHARTLABELS, QFont().toString()).toString());
stGiles.setPointSize(appsettings->value(NULL, GC_FONT_CHARTLABELS_SIZE, 8).toInt());
stGiles.setPointSizeF(appsettings->value(NULL, GC_FONT_CHARTLABELS_SIZE, 8).toInt()*host->scale_);
QFontMetrics fm(stGiles); // adjust position to align centre

//
Expand Down Expand Up @@ -88,7 +88,7 @@ void GenericSelectTool::paint(QPainter*painter, const QStyleOptionGraphicsItem *
QColor invert = GCColor::invertColor(GColor(CPLOTBACKGROUND));
painter->setBrush(invert);
painter->setPen(invert);
QRectF circle(0,0,gl_linemarker*dpiXFactor,gl_linemarker*dpiYFactor);
QRectF circle(0,0,gl_linemarker*dpiXFactor*host->scale_,gl_linemarker*dpiYFactor*host->scale_);
circle.moveCenter(pos);
painter->drawEllipse(circle);
painter->setBrush(Qt::NoBrush);
Expand Down Expand Up @@ -116,7 +116,7 @@ void GenericSelectTool::paint(QPainter*painter, const QStyleOptionGraphicsItem *
QColor invert = GCColor::invertColor(GColor(CPLOTBACKGROUND));
painter->setBrush(invert);
painter->setPen(invert);
QRectF circle(0,0,gl_scattermarker*dpiXFactor,gl_scattermarker*dpiYFactor);
QRectF circle(0,0,gl_scattermarker*dpiXFactor*host->scale_,gl_scattermarker*dpiYFactor*host->scale_);
circle.moveCenter(hoverpoint);
painter->drawEllipse(circle);
painter->setBrush(Qt::NoBrush);
Expand Down Expand Up @@ -264,7 +264,7 @@ void GenericSelectTool::paint(QPainter*painter, const QStyleOptionGraphicsItem *
col.setAlphaF(1);
QPen line(col);
line.setStyle(Qt::SolidLine);
line.setWidthF(0.5 * dpiXFactor);
line.setWidthF(0.5 * dpiXFactor*host->scale_);
painter->setPen(line);
if (host->charttype == GC_CHART_LINE) painter->setClipRect(r); // too jarring on a line plot
else painter->setClipRect(mapRectFromScene(host->qchart->plotArea())); // need context for a scatter plot
Expand Down Expand Up @@ -300,7 +300,7 @@ void GenericSelectTool::paint(QPainter*painter, const QStyleOptionGraphicsItem *
// min max texts
QFont stGiles; // hoho - Chart Font St. Giles ... ok you have to be British to get this joke
stGiles.fromString(appsettings->value(NULL, GC_FONT_CHARTLABELS, QFont().toString()).toString());
stGiles.setPointSize(appsettings->value(NULL, GC_FONT_CHARTLABELS_SIZE, 8).toInt());
stGiles.setPointSizeF(appsettings->value(NULL, GC_FONT_CHARTLABELS_SIZE, 8).toInt()*host->scale_);
painter->setFont(stGiles);

QPen markerpen(GColor(CPLOTMARKER));
Expand Down
7 changes: 5 additions & 2 deletions src/Charts/PythonChart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,9 @@ PythonChart::eventFilter(QObject *, QEvent *e)
void
PythonChart::configChanged(qint32)
{
if (!ridesummary) setProperty("color", GColor(CTRENDPLOTBACKGROUND));
else setProperty("color", GColor(CPLOTBACKGROUND));
QColor bgcolor = !ridesummary ? GColor(CTRENDPLOTBACKGROUND) : GColor(CPLOTBACKGROUND);
setProperty("color", bgcolor);
if (plot) plot->setBackgroundColor(bgcolor);

// tinted palette for headings etc
QPalette palette;
Expand All @@ -520,6 +521,8 @@ PythonChart::configChanged(qint32)
palette.setColor(QPalette::Base, GCColor::alternateColor(GColor(CPLOTBACKGROUND)));
setPalette(palette);

// refresh
runScript();
}

void
Expand Down
8 changes: 6 additions & 2 deletions src/Charts/RChart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,10 @@ RChart::eventFilter(QObject *, QEvent *e)
void
RChart::configChanged(qint32)
{
if (!ridesummary) setProperty("color", GColor(CTRENDPLOTBACKGROUND));
else setProperty("color", GColor(CPLOTBACKGROUND));
QColor bgcolor = !ridesummary ? GColor(CTRENDPLOTBACKGROUND) : GColor(CPLOTBACKGROUND);
setProperty("color", bgcolor);
chart->setBackgroundColor(bgcolor);


// tinted palette for headings etc
QPalette palette;
Expand All @@ -477,6 +479,8 @@ RChart::configChanged(qint32)
palette.setColor(QPalette::Text, GColor(CPLOTMARKER));
palette.setColor(QPalette::Base, GCColor::alternateColor(GColor(CPLOTBACKGROUND)));
setPalette(palette);

runScript(); // to update
}

void
Expand Down
46 changes: 38 additions & 8 deletions src/Charts/UserChart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ UserChart::UserChart(QWidget *parent, Context *context, bool rangemode)
connect(settingsTool_, SIGNAL(chartConfigChanged()), this, SLOT(chartConfigChanged()));
connect(context, SIGNAL(configChanged(qint32)), this, SLOT(configChanged(qint32)));

// defaults, can be overriden via setBackgroundColor()
if (rangemode) bgcolor = GColor(CTRENDPLOTBACKGROUND);
else bgcolor = GColor(CPLOTBACKGROUND);

// set default background color
configChanged(0);
}

Expand All @@ -70,23 +75,32 @@ UserChart::configChanged(qint32)
{
setUpdatesEnabled(false);

if (rangemode) setProperty("color", GColor(CTRENDPLOTBACKGROUND));
else setProperty("color", GColor(CPLOTBACKGROUND));

// tinted palette for headings etc
QPalette palette;
palette.setBrush(QPalette::Window, QBrush(GColor(CPLOTBACKGROUND)));
palette.setBrush(QPalette::Window, bgcolor);
palette.setBrush(QPalette::Background, bgcolor);
palette.setColor(QPalette::WindowText, GColor(CPLOTMARKER));
palette.setColor(QPalette::Text, GColor(CPLOTMARKER));
palette.setColor(QPalette::Base, GCColor::alternateColor(GColor(CPLOTBACKGROUND)));
palette.setColor(QPalette::Base, bgcolor /*GCColor::alternateColor(bgcolor)*/);
setPalette(palette);

setAutoFillBackground(true);

// redraw
chartConfigChanged();

setUpdatesEnabled(true);
}

void
UserChart::setBackgroundColor(QColor bgcolor)
{
if (this->bgcolor != bgcolor) {
this->bgcolor = bgcolor;
configChanged(0);
}
}

void
UserChart::chartConfigChanged()
{
Expand Down Expand Up @@ -144,7 +158,8 @@ UserChart::setRide(const RideItem *item)
if (!isVisible()) { stale=true; return; }

// ok, we've run out of excuses, looks like we need to plot
chart->initialiseChart(chartinfo.title, chartinfo.type, chartinfo.animate, chartinfo.legendpos, chartinfo.stack, chartinfo.orientation);
chart->setBackgroundColor(bgcolor);
chart->initialiseChart(chartinfo.title, chartinfo.type, chartinfo.animate, chartinfo.legendpos, chartinfo.stack, chartinfo.orientation, chartinfo.scale);

// now generate the series data
for (int ii=0; ii<seriesinfo.count(); ii++) {
Expand Down Expand Up @@ -308,7 +323,9 @@ UserChart::settings() const
out << "\"animate\": " << (chartinfo.animate ? "true" : "false") << ",\n";
out << "\"legendpos\": " << chartinfo.legendpos << ",\n";
out << "\"stack\": " << (chartinfo.stack ? "true" : "false") << ",\n";
out << "\"orientation\": " << chartinfo.orientation; // note no trailing comma
out << "\"orientation\": " << chartinfo.orientation << ",\n";
out << "\"scale\": " << QString("%1").arg(chartinfo.scale); // note no trailing comma
// bgcolor not saved, it is set based upon context

// seriesinfos
if (seriesinfo.count()) out << ",\n\"SERIES\": [\n"; // that trailing comma
Expand Down Expand Up @@ -394,6 +411,8 @@ UserChart::applySettings(QString x)
chartinfo.legendpos = obj["legendpos"].toInt();
chartinfo.stack = obj["stack"].toBool();
chartinfo.orientation = obj["orientation"].toInt();
if (obj.contains("scale")) chartinfo.scale = obj["scale"].toDouble();
else chartinfo.scale = 1.0f;

// array of series, but userchartdata needs to be deleted
foreach(GenericSeriesInfo series, seriesinfo)
Expand Down Expand Up @@ -531,6 +550,15 @@ UserChartSettings::UserChartSettings(Context *context, bool rangemode, GenericCh
zz->addStretch();
cf->addRow(tr("Legend"), zz);

scale = new QSlider(Qt::Horizontal, this);
scale->setTickInterval(1);
scale->setMinimum(1);
scale->setMaximum(9);
scale->setSingleStep(1);
scale->setValue(1 + ((chart.scale-1)*2)); // 1-5 mapped to 1-7, where scale is 1,1.5,2,2.5,3,3.5,4,4.5,5
cf->addRow(tr("Scale"), scale);


cf->addRow(" ", (QWidget*)NULL);
animate = new QCheckBox(tr("Animate"));
cf->addRow(" ", animate);
Expand Down Expand Up @@ -658,6 +686,7 @@ UserChartSettings::UserChartSettings(Context *context, bool rangemode, GenericCh
connect(legpos, SIGNAL(currentIndexChanged(QString)), this, SLOT(updateChartInfo()));
connect(stack, SIGNAL(stateChanged(int)), this, SLOT(updateChartInfo()));
connect(orientation, SIGNAL(currentIndexChanged(int)), this, SLOT(updateChartInfo()));
connect(scale, SIGNAL(valueChanged(int)), this, SLOT(updateChartInfo()));
}

void
Expand Down Expand Up @@ -686,7 +715,7 @@ UserChartSettings::refreshChartInfo()
index=orientation->findData(chartinfo.orientation);
if (index >= 0) orientation->setCurrentIndex(index);
else orientation->setCurrentIndex(0);

scale->setValue(1 + ((chartinfo.scale-1)*2)); // 1-5 mapped to 1-7, where scale is 1,1.5,2,2.5,3,3.5,4,4.5,5
updating=false;
}

Expand All @@ -707,6 +736,7 @@ UserChartSettings::updateChartInfo()
chartinfo.legendpos = legpos->itemData(legpos->currentIndex()).toInt();
chartinfo.stack = stack->isChecked();
chartinfo.orientation = orientation->itemData(orientation->currentIndex()).toInt();
chartinfo.scale = 1 + ((scale->value() - 1) * 0.5);

// we need to refresh whenever stuff changes....
if (refresh) emit chartConfigChanged();
Expand Down
5 changes: 5 additions & 0 deletions src/Charts/UserChart.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class UserChart : public QWidget {
QString settings() const;
void applySettings(QString);

// set background for all charts, legends etc
void setBackgroundColor(QColor bgcolor);

public slots:

// runtime - ride item changed
Expand Down Expand Up @@ -88,6 +91,7 @@ class UserChart : public QWidget {
Context *context;
bool rangemode;
bool stale;
QColor bgcolor;

const RideItem *last; // the last ride we plotted
const RideItem *ride;
Expand Down Expand Up @@ -174,6 +178,7 @@ class UserChartSettings : public QWidget {
QComboBox *legpos;
QCheckBox *stack;
QComboBox *orientation;
QSlider *scale;
};

class EditUserSeriesDialog : public QDialog
Expand Down
8 changes: 8 additions & 0 deletions src/Charts/UserChartOverviewItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ UserChartOverviewItem::UserChartOverviewItem(ChartSpace *parent, QString name, Q

// create the chart and place on scene
chart = new UserChart(NULL, parent->context, parent->scope == OverviewScope::TRENDS ? true : false);
chart->setBackgroundColor(GColor(CCARDBACKGROUND));
chart->hide();
proxy = parent->getScene()->addWidget(chart);
proxy->setParent(this);
Expand All @@ -47,10 +48,17 @@ UserChartOverviewItem::UserChartOverviewItem(ChartSpace *parent, QString name, Q
setConfig(settings);

connect(nameEdit, SIGNAL(textEdited(QString)), this, SLOT(nameChanged()));
connect(parent->context, SIGNAL(configChanged(qint32)), this, SLOT(configChanged()));
}

UserChartOverviewItem::~UserChartOverviewItem() { }

void
UserChartOverviewItem::configChanged()
{
chart->setBackgroundColor(GColor(CCARDBACKGROUND));
}

void
UserChartOverviewItem::nameChanged()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Charts/UserChartOverviewItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class UserChartOverviewItem : public ChartSpaceItem

// create a blank one
static ChartSpaceItem *create(ChartSpace *parent) { return new UserChartOverviewItem(parent, "User Chart",
"{ \"title\": \" \",\n\"description\": \"A description of the chart, mostly useful when the chart is uploaded to the cloud to let others know what this chart is useful for etc. \",\n\"type\": 2,\n\"animate\": false,\n\"legendpos\": 2,\n\"stack\": false,\n\"orientation\": 1,\n\"SERIES\": [\n{ \"name\": \"Power \", \"group\": \" \", \"xname\": \"Cadence \", \"yname\": \"watts \", \"program\": \"{\\n finalise {\\n # we just fetch samples at end\\n xx <- samples(CADENCE);\\n yy <- samples(POWER);\\n }\\n\\n x { xx; }\\n y { yy; }\\n}\\n \", \"line\": 0, \"symbol\": 1, \"size\": 14, \"color\": \"#010112\", \"opacity\": 100, \"legend\": true, \"opengl\": false, \"datalabels\": false, \"fill\": false},\n{ \"name\": \"LR \", \"group\": \" \", \"xname\": \"Cadence \", \"yname\": \"watts \", \"program\": \"{\\n finalise {\\n # we just fetch samples at end\\n xx <- samples(CADENCE);\\n yy <- samples(POWER);\\n fit <- lr(xx,yy);\\n ex <- c(10,120);\\n wy <- c((ex[0]*fit[0])+fit[1],\\n (ex[1]*fit[0])+fit[1]);\\n \\n }\\n\\n x { ex; }\\n y { wy; }\\n}\\n \", \"line\": 2, \"symbol\": 1, \"size\": 3, \"color\": \"#01010b\", \"opacity\": 100, \"legend\": false, \"opengl\": false, \"datalabels\": false, \"fill\": false} ]\n,\n\"AXES\": [\n{ \"name\": \"Cadence \", \"type\": 0, \"orientation\": 1, \"align\": 1, \"minx\": 0, \"maxx\": 160, \"miny\": 0, \"maxy\": 0, \"visible\": true, \"fixed\": true, \"log\": false, \"minorgrid\": false, \"majorgrid\": true, \"labelcolor\": \"#6569a5\", \"axiscolor\": \"#6569a5\"},\n{ \"name\": \"watts \", \"type\": 0, \"orientation\": 2, \"align\": 1, \"minx\": 0, \"maxx\": 0, \"miny\": 0, \"maxy\": 1000, \"visible\": true, \"fixed\": false, \"log\": false, \"minorgrid\": false, \"majorgrid\": true, \"labelcolor\": \"#010112\", \"axiscolor\": \"#010112\"} ]\n} "); }
"{ \"title\": \" \",\n\"description\": \"A description of the chart, mostly useful when the chart is uploaded to the cloud to let others know what this chart is useful for etc. \",\n\"type\": 2,\n\"animate\": false,\n\"legendpos\": 2,\n\"stack\": false,\n\"orientation\": 1,\"scale\": 2.5, \n\"SERIES\": [\n{ \"name\": \"Power \", \"group\": \" \", \"xname\": \"Cadence \", \"yname\": \"watts \", \"program\": \"{\\n finalise {\\n # we just fetch samples at end\\n xx <- samples(CADENCE);\\n yy <- samples(POWER);\\n }\\n\\n x { xx; }\\n y { yy; }\\n}\\n \", \"line\": 0, \"symbol\": 1, \"size\": 14, \"color\": \"#010112\", \"opacity\": 100, \"legend\": true, \"opengl\": false, \"datalabels\": false, \"fill\": false},\n{ \"name\": \"LR \", \"group\": \" \", \"xname\": \"Cadence \", \"yname\": \"watts \", \"program\": \"{\\n finalise {\\n # we just fetch samples at end\\n xx <- samples(CADENCE);\\n yy <- samples(POWER);\\n fit <- lr(xx,yy);\\n ex <- c(10,120);\\n wy <- c((ex[0]*fit[0])+fit[1],\\n (ex[1]*fit[0])+fit[1]);\\n \\n }\\n\\n x { ex; }\\n y { wy; }\\n}\\n \", \"line\": 2, \"symbol\": 1, \"size\": 3, \"color\": \"#01010b\", \"opacity\": 100, \"legend\": false, \"opengl\": false, \"datalabels\": false, \"fill\": false} ]\n,\n\"AXES\": [\n{ \"name\": \"Cadence \", \"type\": 0, \"orientation\": 1, \"align\": 1, \"minx\": 0, \"maxx\": 160, \"miny\": 0, \"maxy\": 0, \"visible\": true, \"fixed\": true, \"log\": false, \"minorgrid\": false, \"majorgrid\": true, \"labelcolor\": \"#6569a5\", \"axiscolor\": \"#6569a5\"},\n{ \"name\": \"watts \", \"type\": 0, \"orientation\": 2, \"align\": 1, \"minx\": 0, \"maxx\": 0, \"miny\": 0, \"maxy\": 1000, \"visible\": true, \"fixed\": false, \"log\": false, \"minorgrid\": false, \"majorgrid\": true, \"labelcolor\": \"#010112\", \"axiscolor\": \"#010112\"} ]\n} "); }

// settings get and set
QString getConfig() const { return chart->settings(); }
Expand All @@ -55,6 +55,7 @@ class UserChartOverviewItem : public ChartSpaceItem
public slots:

void nameChanged();
void configChanged();

private:
// embedding
Expand Down
12 changes: 12 additions & 0 deletions src/Charts/UserChartWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ UserChartWindow::UserChartWindow(Context *context, bool rangemode) : GcChartWind

// need to refresh when perspective selected
connect(this, SIGNAL(perspectiveChanged(Perspective*)), this, SLOT(refresh()));
connect(context, SIGNAL(configChanged(qint32)), this, SLOT(configChanged()));
}

void
UserChartWindow::configChanged()
{
QColor bgcolor = rangemode ? GColor(CTRENDPLOTBACKGROUND) : GColor(CPLOTBACKGROUND);

setProperty("color", bgcolor);
chart->setBackgroundColor(bgcolor);

update();
}

//
Expand Down
3 changes: 3 additions & 0 deletions src/Charts/UserChartWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class UserChartWindow : public GcChartWindow {
// runtime - date range was selected
void setDateRange(DateRange);

// watch color changes
void configChanged();

// redraw
void refresh();

Expand Down
12 changes: 11 additions & 1 deletion src/Gui/AddChartWizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <QPixmap>
#include <QRegExp>

#include "OverviewItems.h"

// WIZARD FLOW
//
// 01. select chart type
Expand Down Expand Up @@ -195,7 +197,15 @@ AddChartFinal::validatePage()
{
// add to the top left
if (wizard->item) {
wizard->item->parent->addItem(0,0,1,7, wizard->item);
if (wizard->item->type == OverviewItemType::USERCHART) {

// we add user charts but make them a bit bigger
wizard->item->parent->addItem(0,0,2,21, wizard->item);
} else {

// everthing else is a bit smaller
wizard->item->parent->addItem(0,0,1,7, wizard->item);
}
wizard->item->parent->updateGeometry();
}
return true;
Expand Down
1 change: 1 addition & 0 deletions src/Gui/Colors.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ extern double dpiXFactor, dpiYFactor;
extern QFont baseFont;

// turn color to rgb, checks if a named color
#define StandardColor(x) (QColor(1,1,x))
#define NamedColor(x) (x.red()==1 && x.green()==1)
#define RGBColor(x) (NamedColor(x) ? GColor(x.blue()) : x)

Expand Down