mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-05 18:50:44 +00:00
minor barchart gradient optimisation
This commit is contained in:
parent
d1341787ba
commit
83a6038a70
@ -17,7 +17,8 @@
|
||||
#include "gYAxis.h"
|
||||
|
||||
extern MainWindow * mainwin;
|
||||
QColor brighten(QColor color, float mult = 2.0);
|
||||
|
||||
short SummaryCalcItem::midcalc;
|
||||
|
||||
gSummaryChart::gSummaryChart(QString label, MachineType machtype)
|
||||
:Layer(NoChannel), m_label(label), m_machtype(machtype)
|
||||
@ -152,6 +153,8 @@ QList<Day *> gSummaryChart::daylist;
|
||||
|
||||
void gSummaryChart::preCalc()
|
||||
{
|
||||
midcalc = p_profile->general->prefCalcMiddle();
|
||||
|
||||
for (int i=0; i<calcitems.size(); ++i) {
|
||||
SummaryCalcItem & calc = calcitems[i];
|
||||
calc.reset(idx_end - idx_start);
|
||||
@ -503,7 +506,7 @@ void gSummaryChart::paint(QPainter &painter, gGraph &graph, const QRegion ®io
|
||||
do {
|
||||
Day * day = daylist.at(idx);
|
||||
|
||||
if ((lastx1 + barw) > (rect.left()+rect.width()+1))
|
||||
if ((lastx1 + barw) > (rect.left() + rect.width() + 1))
|
||||
break;
|
||||
|
||||
totaldays++;
|
||||
@ -552,6 +555,7 @@ void gSummaryChart::paint(QPainter &painter, gGraph &graph, const QRegion ®io
|
||||
customCalc(day, list);
|
||||
|
||||
int listsize = list.size();
|
||||
QLinearGradient gradient(lastx1, 0, lastx1 + barw, 0); //rect.bottom(), barw, rect.bottom());
|
||||
|
||||
for (int i=0; i < listsize; ++i) {
|
||||
SummaryChartSlice & slice = list[i];
|
||||
@ -560,9 +564,8 @@ void gSummaryChart::paint(QPainter &painter, gGraph &graph, const QRegion ®io
|
||||
y1 = ((lastval-miny) * ymult);
|
||||
y2 = (val * ymult);
|
||||
QColor color = slice.color;
|
||||
QRectF rec(lastx1, rect.bottom() - y1, barw, -y2);
|
||||
|
||||
rec = rec.intersected(rect);
|
||||
QRectF rec = QRectF(lastx1, rect.bottom() - y1, barw, -y2).intersected(rect);
|
||||
|
||||
if (hlday) {
|
||||
if (rec.contains(mouse.x(), mouse.y())) {
|
||||
@ -571,19 +574,17 @@ void gSummaryChart::paint(QPainter &painter, gGraph &graph, const QRegion ®io
|
||||
}
|
||||
}
|
||||
|
||||
QColor col2 = brighten(color,2.5);
|
||||
|
||||
if (barw > 8) {
|
||||
QLinearGradient gradient(lastx1, rect.bottom(), lastx1+barw, rect.bottom());
|
||||
if (barw <= 3) {
|
||||
painter.fillRect(rec, QBrush(color));
|
||||
} else if (barw > 8) {
|
||||
gradient.setColorAt(0,color);
|
||||
gradient.setColorAt(1,col2);
|
||||
gradient.setColorAt(1,brighten(color, 2.0));
|
||||
painter.fillRect(rec, QBrush(gradient));
|
||||
outlines.append(rec);
|
||||
} else if (barw > 3) {
|
||||
painter.fillRect(rec, QBrush(brighten(color,1.25)));
|
||||
// painter.fillRect(rec, slice.brush);
|
||||
outlines.append(rec);
|
||||
} else {
|
||||
painter.fillRect(rec, QBrush(color));
|
||||
painter.fillRect(rec, QBrush(brighten(color,1.25)));
|
||||
outlines.append(rec);
|
||||
}
|
||||
|
||||
lastval += val;
|
||||
@ -617,7 +618,11 @@ void gSummaryChart::paint(QPainter &painter, gGraph &graph, const QRegion ®io
|
||||
|
||||
graph.ToolTip(txt, mouse.x()-15, mouse.y()+5, TT_AlignRight);
|
||||
}
|
||||
afterDraw(painter, graph, rect);
|
||||
try {
|
||||
afterDraw(painter, graph, rect);
|
||||
} catch(...) {
|
||||
qDebug() << "Bad median call in" << m_label;
|
||||
}
|
||||
|
||||
|
||||
// This could be turning off graphs prematurely..
|
||||
@ -651,6 +656,8 @@ void gUsageChart::populate(Day *day, int idx)
|
||||
|
||||
void gUsageChart::preCalc()
|
||||
{
|
||||
midcalc = p_profile->general->prefCalcMiddle();
|
||||
|
||||
compliance_threshold = p_profile->cpap->complianceHours();
|
||||
incompdays = 0;
|
||||
|
||||
@ -703,6 +710,9 @@ void gUsageChart::afterDraw(QPainter &, gGraph &graph, QRect rect)
|
||||
|
||||
|
||||
void gSessionTimesChart::preCalc() {
|
||||
|
||||
midcalc = p_profile->general->prefCalcMiddle();
|
||||
|
||||
num_slices = 0;
|
||||
num_days = 0;
|
||||
total_length = 0;
|
||||
@ -965,6 +975,8 @@ void gSessionTimesChart::paint(QPainter &painter, gGraph &graph, const QRegion &
|
||||
customCalc(day, slices);
|
||||
int size = slices.size();
|
||||
|
||||
QLinearGradient gradient(lastx1, rect.bottom(), lastx1+barw, rect.bottom());
|
||||
|
||||
for (int i=0; i < size; ++i) {
|
||||
const SummaryChartSlice & slice = slices.at(i);
|
||||
float s1 = slice.value - miny;
|
||||
@ -978,18 +990,18 @@ void gSessionTimesChart::paint(QPainter &painter, gGraph &graph, const QRegion &
|
||||
QRect rec(lastx1, rect.bottom() - y1 - y2, barw, y2);
|
||||
rec = rec.intersected(rect);
|
||||
|
||||
// QBrush brush = slice.brush;
|
||||
if (rec.contains(mouse)) {
|
||||
col = Qt::yellow;
|
||||
graph.ToolTip(slice.name, mouse.x() - 15,mouse.y() + 15, TT_AlignRight);
|
||||
|
||||
}
|
||||
QColor col2 = brighten(col,2.5);
|
||||
|
||||
if (barw > 8) {
|
||||
QLinearGradient gradient(lastx1, rect.bottom(), lastx1+barw, rect.bottom());
|
||||
gradient.setColorAt(0,col);
|
||||
gradient.setColorAt(1,col2);
|
||||
gradient.setColorAt(1,brighten(col, 2.0));
|
||||
painter.fillRect(rec, QBrush(gradient));
|
||||
// painter.fillRect(rec, brush);
|
||||
outlines.append(rec);
|
||||
} else if (barw > 3) {
|
||||
painter.fillRect(rec, QBrush(brighten(col,1.25)));
|
||||
@ -1035,16 +1047,22 @@ void gAHIChart::customCalc(Day *day, QList<SummaryChartSlice> &list)
|
||||
SummaryCalcItem * calc = slice.calc;
|
||||
|
||||
EventDataType value = slice.value;
|
||||
|
||||
calc->wavg_sum += value;
|
||||
calc->divisor += hours;
|
||||
|
||||
calc->avg_sum += value;
|
||||
calc->cnt++;
|
||||
|
||||
float valh = value/ hours;
|
||||
|
||||
calc->median_data.append(valh);
|
||||
switch (midcalc) {
|
||||
case 0:
|
||||
calc->median_data.append(valh);
|
||||
break;
|
||||
case 1:
|
||||
calc->wavg_sum += value;
|
||||
calc->divisor += hours;
|
||||
default:
|
||||
calc->avg_sum += value;
|
||||
calc->cnt++;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
calc->min = qMin(valh, calc->min);
|
||||
calc->max = qMax(valh, calc->max);
|
||||
@ -1065,17 +1083,21 @@ void gAHIChart::afterDraw(QPainter & /*painter */, gGraph &graph, QRect rect)
|
||||
{
|
||||
if (totaldays == nousedays) return;
|
||||
|
||||
int size = idx_end - idx_start;
|
||||
|
||||
int midcalc = p_profile->general->prefCalcMiddle();
|
||||
|
||||
int mpos = size /2 ;
|
||||
//int size = idx_end - idx_start;
|
||||
|
||||
float med = 0;
|
||||
if (size > 0) {
|
||||
|
||||
//nth_element(ahi_data.begin(), ahi_data.begin()+ mpos, ahi_data.end());
|
||||
med = median(ahi_data.begin(), ahi_data.end());
|
||||
switch (midcalc) {
|
||||
case 0:
|
||||
if (ahi_data.size() > 0) {
|
||||
med = median(ahi_data.begin(), ahi_data.end());
|
||||
}
|
||||
break;
|
||||
case 1: // wavg
|
||||
med = ahi_wavg / total_hours;
|
||||
break;
|
||||
case 2: // avg
|
||||
med = ahi_avg / calc_cnt;
|
||||
break;
|
||||
}
|
||||
|
||||
QStringList txtlist;
|
||||
|
@ -51,6 +51,8 @@ struct SummaryCalcItem {
|
||||
divisor = 0;
|
||||
min = 0;
|
||||
max = 0;
|
||||
midcalc = p_profile->general->prefCalcMiddle();
|
||||
|
||||
}
|
||||
|
||||
SummaryCalcItem(ChannelID code, SummaryType type, QColor color)
|
||||
@ -58,16 +60,25 @@ struct SummaryCalcItem {
|
||||
}
|
||||
|
||||
inline void update(float value, float weight) {
|
||||
wavg_sum += value * weight;
|
||||
divisor += weight;
|
||||
avg_sum += value;
|
||||
cnt++;
|
||||
median_data.append(value);
|
||||
switch (midcalc) {
|
||||
case 0:
|
||||
median_data.append(value);
|
||||
break;
|
||||
case 1:
|
||||
wavg_sum += value * weight;
|
||||
divisor += weight;
|
||||
break;
|
||||
default:
|
||||
avg_sum += value;
|
||||
cnt++;
|
||||
}
|
||||
min = qMin(min, value);
|
||||
max = qMax(max, value);
|
||||
}
|
||||
|
||||
void reset(int reserve) {
|
||||
midcalc = p_profile->general->prefCalcMiddle();
|
||||
|
||||
wavg_sum = 0;
|
||||
avg_sum = 0;
|
||||
divisor = 0;
|
||||
@ -75,7 +86,9 @@ struct SummaryCalcItem {
|
||||
min = 99999;
|
||||
max = -99999;
|
||||
median_data.clear();
|
||||
median_data.reserve(reserve);
|
||||
if (midcalc == 0) {
|
||||
median_data.reserve(reserve);
|
||||
}
|
||||
}
|
||||
ChannelID code;
|
||||
SummaryType type;
|
||||
@ -87,6 +100,7 @@ struct SummaryCalcItem {
|
||||
int cnt;
|
||||
EventDataType min;
|
||||
EventDataType max;
|
||||
static short midcalc;
|
||||
|
||||
QList<float> median_data;
|
||||
|
||||
@ -106,15 +120,23 @@ struct SummaryChartSlice {
|
||||
height = copy.height;
|
||||
name = copy.name;
|
||||
color = copy.color;
|
||||
// brush = copy.brush;
|
||||
}
|
||||
|
||||
SummaryChartSlice(SummaryCalcItem * calc, EventDataType value, EventDataType height, QString name, QColor color)
|
||||
:calc(calc), value(value), height(height), name(name), color(color) {}
|
||||
:calc(calc), value(value), height(height), name(name), color(color) {
|
||||
// QLinearGradient gradient(0, 0, 1, 0);
|
||||
// gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
|
||||
// gradient.setColorAt(0,color);
|
||||
// gradient.setColorAt(1,brighten(color));
|
||||
// brush = QBrush(gradient);
|
||||
}
|
||||
SummaryCalcItem * calc;
|
||||
EventDataType value;
|
||||
EventDataType height;
|
||||
QString name;
|
||||
QColor color;
|
||||
// QBrush brush;
|
||||
};
|
||||
|
||||
class gSummaryChart : public Layer
|
||||
@ -218,6 +240,8 @@ protected:
|
||||
|
||||
int idx_start;
|
||||
int idx_end;
|
||||
|
||||
short midcalc;
|
||||
};
|
||||
|
||||
|
||||
@ -249,6 +273,7 @@ public:
|
||||
|
||||
//! \brief Renders the graph to the QPainter object
|
||||
virtual void paint(QPainter &painter, gGraph &graph, const QRegion ®ion);
|
||||
|
||||
virtual Layer * Clone() {
|
||||
gSessionTimesChart * sc = new gSessionTimesChart();
|
||||
gSummaryChart::CloneInto(sc);
|
||||
@ -332,7 +357,7 @@ public:
|
||||
return sc;
|
||||
}
|
||||
|
||||
void CloneInto(gAHIChart * layer) {
|
||||
void CloneInto(gAHIChart * /* layer */) {
|
||||
// layer->ahicalc = ahicalc;
|
||||
// layer->ahi_wavg = ahi_wavg;
|
||||
// layer->ahi_avg = ahi_avg;
|
||||
|
@ -382,34 +382,6 @@ void SummaryChart::SetDay(Day * nullday)
|
||||
m_physminy = m_miny;
|
||||
}
|
||||
|
||||
QColor brighten(QColor color, float mult = 2.0)
|
||||
{
|
||||
int cr, cg, cb;
|
||||
|
||||
cr = color.red();
|
||||
cg = color.green();
|
||||
cb = color.blue();
|
||||
|
||||
if (cr < 64) { cr = 64; }
|
||||
|
||||
if (cg < 64) { cg = 64; }
|
||||
|
||||
if (cb < 64) { cb = 64; }
|
||||
|
||||
cr *= mult;
|
||||
cg *= mult;
|
||||
cb *= mult;
|
||||
|
||||
if (cr > 255) { cr = 255; }
|
||||
|
||||
if (cg > 255) { cg = 255; }
|
||||
|
||||
if (cb > 255) { cb = 255; }
|
||||
|
||||
return QColor(cr, cg, cb, 255);
|
||||
|
||||
}
|
||||
|
||||
void SummaryChart::paint(QPainter &painter, gGraph &w, const QRegion ®ion)
|
||||
{
|
||||
int left = region.boundingRect().left();
|
||||
|
@ -20,6 +20,7 @@
|
||||
*/
|
||||
enum GraphType { GT_BAR, GT_LINE, GT_POINTS, GT_SESSIONS };
|
||||
|
||||
|
||||
/*! \class SummaryChart
|
||||
\brief The main overall chart type layer used in Overview page
|
||||
*/
|
||||
|
@ -14,6 +14,34 @@ float brightness(QColor color) {
|
||||
}
|
||||
|
||||
|
||||
QColor brighten(QColor color, float mult)
|
||||
{
|
||||
int cr, cg, cb;
|
||||
|
||||
cr = color.red();
|
||||
cg = color.green();
|
||||
cb = color.blue();
|
||||
|
||||
if (cr < 64) { cr = 64; }
|
||||
|
||||
if (cg < 64) { cg = 64; }
|
||||
|
||||
if (cb < 64) { cb = 64; }
|
||||
|
||||
cr *= mult;
|
||||
cg *= mult;
|
||||
cb *= mult;
|
||||
|
||||
if (cr > 255) { cr = 255; }
|
||||
|
||||
if (cg > 255) { cg = 255; }
|
||||
|
||||
if (cb > 255) { cb = 255; }
|
||||
|
||||
return QColor(cr, cg, cb, 255);
|
||||
|
||||
}
|
||||
|
||||
#ifdef BUILD_WITH_MSVC
|
||||
|
||||
#if (_MSC_VER < 1800)
|
||||
@ -24,3 +52,4 @@ double round(double number)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -50,12 +50,12 @@ const QColor COLOR_Brown = QColor("brown");
|
||||
const QColor COLOR_Text = Qt::black;
|
||||
const QColor COLOR_Outline = Qt::black;
|
||||
|
||||
const QColor COLOR_ALT_BG1 = QColor(0xd8, 0xff, 0xd8,
|
||||
0xff); // Alternating Background Color 1 (Event Flags)
|
||||
const QColor COLOR_ALT_BG2 =
|
||||
COLOR_White; // Alternating Background Color 2 (Event Flags)
|
||||
const QColor COLOR_ALT_BG1 = QColor(0xd8, 0xff, 0xd8, 0xff); // Alternating Background Color 1 (Event Flags)
|
||||
const QColor COLOR_ALT_BG2 = COLOR_White; // Alternating Background Color 2 (Event Flags)
|
||||
|
||||
|
||||
QColor brighten(QColor color, float mult = 2.0);
|
||||
|
||||
const int max_history = 50;
|
||||
|
||||
#ifndef M_PI
|
||||
|
@ -1 +1 @@
|
||||
const int build_number = 11;
|
||||
const int build_number = 0;
|
||||
|
@ -51,7 +51,7 @@
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>6</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="importTab">
|
||||
<attribute name="title">
|
||||
|
Loading…
Reference in New Issue
Block a user