Pie Chart Improvements

This commit is contained in:
Mark Watkins 2011-07-29 00:56:14 +10:00
parent 9b93c8f6ea
commit 2e4eb2f3f2
5 changed files with 28 additions and 5 deletions

View File

@ -51,6 +51,13 @@ void gCandleStick::Plot(gGraphWindow & w,float scrx,float scry)
int width=scrx-(w.GetLeftMargin()+w.GetRightMargin())-1;
int height=scry-(w.GetTopMargin()+w.GetBottomMargin())-1;
for (map<MachineCode,int>::iterator m=m_counts.begin();m!=m_counts.end();m++) {
if (!m->second) continue;
int j=float(m->second)/float(m_total); // ratio of this pie slice
//QColor & col1 = m_colors[m->first];
//QColor & col2 = m_gradient_color;
}
/* float sum=0;
for (int i=0;i<data->np[0];i++)
sum+=data->point[0][i].y();

View File

@ -19,11 +19,15 @@ class gCandleStick:public gLayer
virtual void Plot(gGraphWindow & w,float scrx,float scry);
void AddSlice(MachineCode code,QColor color,QString name="");
void setGradientColor(QColor & color) { m_gradient_color=color; }
void setOutlineColor(QColor & color) { m_outline_color=color; }
protected:
Qt::Orientation m_orientation;
map<MachineCode,int> m_counts;
map<MachineCode,QString> m_names;
map<MachineCode,QColor> m_colors;
QColor m_gradient_color;
QColor m_outline_color;
int m_total;
};

View File

@ -4,6 +4,7 @@
gPieChart::gPieChart(QColor outline_color)
:gLayer(MC_UNKNOWN),m_outline_color(outline_color)
{
m_gradient_color=QColor(200,200,200);
}
gPieChart::~gPieChart()
{
@ -57,10 +58,12 @@ void gPieChart::Plot(gGraphWindow & w,float scrx,float scry)
for (map<MachineCode,int>::iterator m=m_counts.begin();m!=m_counts.end();m++) {
if (!m->second) continue;
j=float(m->second)/float(m_total); // ratio of this pie slice
w.qglColor(m_colors[m->first]);
glPolygonMode(GL_BACK,GL_FILL);
glBegin(GL_POLYGON);
bool first_col;
w.qglColor(m_gradient_color);
glVertex2f(start_px+radius+4, start_py+radius+4);
w.qglColor(m_colors[m->first]);
double q;
for (q=sum;q<sum+j;q+=step) {
px=start_px+radius+4+sin(q*2*M_PI)*radius;
@ -75,8 +78,12 @@ void gPieChart::Plot(gGraphWindow & w,float scrx,float scry)
glPolygonMode(GL_BACK,GL_LINE);
w.qglColor(m_outline_color);
glBegin(GL_POLYGON);
glVertex2f(start_px+radius+4, start_py+radius+4);
if (m_total>m->second) { // Draw the center point first
glBegin(GL_POLYGON);
glVertex2f(start_px+radius+4, start_py+radius+4);
} else { // Only one entry, so just draw the circle
glBegin(GL_LINE_LOOP);
}
for (q=sum;q<sum+j;q+=step) {
px=start_px+radius+4+sin(q*2*M_PI)*radius;
py=start_py+radius+4+cos(q*2*M_PI)*radius;

View File

@ -12,6 +12,8 @@ public:
virtual void SetDay(Day *d);
void AddSlice(MachineCode code,QColor col,QString name="");
void setGradientColor(QColor & color) { m_gradient_color=color; }
void setOutlineColor(QColor & color) { m_outline_color=color; }
protected:
map <MachineCode,QString> m_names;
@ -19,6 +21,8 @@ protected:
map <MachineCode,QColor> m_colors;
int m_total;
QColor m_outline_color;
QColor m_gradient_color;
};
#endif // GPIECHART_H

View File

@ -271,9 +271,10 @@ Daily::Daily(QWidget *parent,QGLWidget * shared) :
//gSplitter->setCollapsible(gSplitter->indexOf(SF),false);
//gSplitter->setStretchFactor(gSplitter->indexOf(SF),0);
gSplitter->layout();
splitter_sizes=gSplitter->sizes();
gSplitter->layout();
gSplitter->update();
QTextCharFormat format = ui->calendar->weekdayTextFormat(Qt::Saturday);
format.setForeground(QBrush(Qt::black, Qt::SolidPattern));