Make Pie chart prettier

This commit is contained in:
Mark Watkins 2014-08-28 01:00:55 +10:00
parent 37e20bf504
commit fb9e26aee3
3 changed files with 22 additions and 6 deletions

View File

@ -357,10 +357,11 @@ gGraphView::gGraphView(QWidget *parent, gGraphView *shared)
snap_action = context_menu->addAction(QString(), this, SLOT(onSnapshotGraphToggle())); snap_action = context_menu->addAction(QString(), this, SLOT(onSnapshotGraphToggle()));
context_menu->addSeparator(); context_menu->addSeparator();
QAction * action = context_menu->addAction(tr("100% zoom level"), this, SLOT(resetZoom()));
action->setToolTip(tr("Restore X-axis zoom too 100% to view entire days data."));
action = context_menu->addAction(tr("Reset Graph Layout"), this, SLOT(resetLayout())); zoom100_action = context_menu->addAction(tr("100% zoom level"), this, SLOT(resetZoom()));
zoom100_action->setToolTip(tr("Restore X-axis zoom too 100% to view entire days data."));
QAction * action = context_menu->addAction(tr("Reset Graph Layout"), this, SLOT(resetLayout()));
action->setToolTip(tr("Resets all graphs to a uniform height and default order.")); action->setToolTip(tr("Resets all graphs to a uniform height and default order."));
context_menu->addSeparator(); context_menu->addSeparator();
@ -1836,12 +1837,15 @@ void gGraphView::populateMenu(gGraph * graph)
{ {
QAction * action; QAction * action;
if (graph->isSnapshot()) { if (graph->isSnapshot()) {
snap_action->setText(tr("Remove Snapshot")); snap_action->setText(tr("Remove Snapshot"));
snap_action->setData(graph->name()+"|remove"); snap_action->setData(graph->name()+"|remove");
// zoom100_action->setVisible(false);
} else { } else {
snap_action->setText(tr("Snapshot Graph")); snap_action->setText(tr("Snapshot Graph"));
snap_action->setData(graph->name()+"|snapshot"); snap_action->setData(graph->name()+"|snapshot");
// zoom100_action->setVisible(true);
} }

View File

@ -644,6 +644,8 @@ class gGraphView
QAction * snap_action; QAction * snap_action;
QAction * zoom100_action;
signals: signals:
void updateCurrentTime(double); void updateCurrentTime(double);
void updateRange(double,double); void updateRange(double,double);

View File

@ -124,7 +124,7 @@ void gSegmentChart::paint(QPainter &painter, gGraph &w, const QRegion &region)
const QColor col = schema::channel[m_codes[m]].defaultColor(); const QColor col = schema::channel[m_codes[m]].defaultColor();
// length of this segment in degrees // length of this segment in degrees
float len = 360.0 / float(m_total) * float(data); float len = 360.0 / m_total * data;
// Setup the shiny radial gradient // Setup the shiny radial gradient
@ -136,16 +136,26 @@ void gSegmentChart::paint(QPainter &painter, gGraph &w, const QRegion &region)
gradient.setColorAt(0, Qt::white); gradient.setColorAt(0, Qt::white);
gradient.setColorAt(1, col); gradient.setColorAt(1, col);
// draw filled pie // draw filled pie
painter.setBrush(gradient); painter.setBrush(gradient);
painter.setBackgroundMode(Qt::OpaqueMode); painter.setBackgroundMode(Qt::OpaqueMode);
painter.drawPie(pierect, -sum * 16.0, -len * 16.0); if (m_total == data) {
painter.drawEllipse(pierect);
} else {
painter.drawPie(pierect, -sum * 16.0, -len * 16.0);
}
// draw outline // draw outline
painter.setBackgroundMode(Qt::TransparentMode); painter.setBackgroundMode(Qt::TransparentMode);
painter.setBrush(QBrush(col,Qt::NoBrush)); painter.setBrush(QBrush(col,Qt::NoBrush));
painter.setPen(QPen(QColor(Qt::black),1.5)); painter.setPen(QPen(QColor(Qt::black),1.5));
painter.drawPie(pierect, -sum * 16.0, -len * 16.0);
if (m_total == data) {
painter.drawEllipse(pierect);
} else {
painter.drawPie(pierect, -sum * 16.0, -len * 16.0);
}
// Draw text labels if they fit // Draw text labels if they fit