56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
/*
** Flags that can be passed into the pie-chart generator
*/
#if INTERFACE
#define PIE_OTHER 0x0001 /* No wedge less than 1/60th of the circle */
#define PIE_CHROMATIC 0x0002 /* Wedge colors are in chromatic order */
#endif
/*
** Output HTML that will render a pie chart using data from
** the PIECHART temporary table.
**
** The schema for the PIECHART table should be:
|
>
|
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
/*
** Flags that can be passed into the pie-chart generator
*/
#if INTERFACE
#define PIE_OTHER 0x0001 /* No wedge less than 1/60th of the circle */
#define PIE_CHROMATIC 0x0002 /* Wedge colors are in chromatic order */
#define PIE_PERCENT 0x0004 /* Add "(XX%)" marks on each label */
#endif
/*
** Output HTML that will render a pie chart using data from
** the PIECHART temporary table.
**
** The schema for the PIECHART table should be:
|
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
const char *zClr; /* Color */
int l; /* Large arc flag */
int j; /* Wedge number */
double rTotal; /* Total piechart.amt */
double rTooSmall; /* Sum of pieChart.amt entries less than 1/60th */
int nTotal; /* Total number of entries in piechart */
int nTooSmall; /* Number of pieChart.amt entries less than 1/60th */
# define SATURATION 128
# define VALUE 192
# define OTHER_CUTOFF 90.0
cx = 0.5*width;
cy = 0.5*height;
r2 = cx<cy ? cx : cy;
r = r2 - 80.0;
if( r<0.33333*r2 ) r = 0.33333*r2;
h = 0;
db_prepare(&q, "SELECT sum(amt), count(*) FROM piechart");
if( db_step(&q)!=SQLITE_ROW ) return;
rTotal = db_column_double(&q, 0);
nTotal = db_column_int(&q, 1);
db_finalize(&q);
rTooSmall = 0.0;
nTooSmall = 0;
if( (pieFlags & PIE_OTHER)!=0 && nTotal>1 ){
db_prepare(&q, "SELECT sum(amt), count(*) FROM piechart WHERE amt<:amt");
db_bind_double(&q, ":amt", rTotal/OTHER_CUTOFF);
if( db_step(&q)==SQLITE_ROW ){
rTooSmall = db_column_double(&q, 0);
nTooSmall = db_column_double(&q, 1);
}
db_finalize(&q);
}
if( nTooSmall>1 ){
db_prepare(&q, "SELECT amt, label FROM piechart WHERE amt>=:limit"
" UNION ALL SELECT %.17g, '(%d others)';",
rTooSmall, nTooSmall);
db_bind_double(&q, ":limit", rTotal/OTHER_CUTOFF);
nTotal += 1 - nTooSmall;
}else{
db_prepare(&q, "SELECT amt, label FROM piechart");
}
if( nTotal<=10 ) pieFlags |= PIE_CHROMATIC;
|
>
>
|
|
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
const char *zClr; /* Color */
int l; /* Large arc flag */
int j; /* Wedge number */
double rTotal; /* Total piechart.amt */
double rTooSmall; /* Sum of pieChart.amt entries less than 1/60th */
int nTotal; /* Total number of entries in piechart */
int nTooSmall; /* Number of pieChart.amt entries less than 1/60th */
const char *zFg; /* foreground color for lines and text */
# define SATURATION 128
# define VALUE 192
# define OTHER_CUTOFF 90.0
cx = 0.5*width;
cy = 0.5*height;
r2 = cx<cy ? cx : cy;
r = r2 - 80.0;
if( r<0.33333*r2 ) r = 0.33333*r2;
h = 0;
zFg = skin_detail_boolean("white-foreground") ? "white" : "black";
db_prepare(&q, "SELECT sum(amt), count(*) FROM piechart");
if( db_step(&q)!=SQLITE_ROW ) return;
rTotal = db_column_double(&q, 0);
nTotal = db_column_int(&q, 1);
db_finalize(&q);
rTooSmall = 0.0;
nTooSmall = 0;
if( (pieFlags & PIE_OTHER)!=0 && nTotal>1 ){
db_prepare(&q, "SELECT sum(amt), count(*) FROM piechart WHERE amt<:amt");
db_bind_double(&q, ":amt", rTotal/OTHER_CUTOFF);
if( db_step(&q)==SQLITE_ROW ){
rTooSmall = db_column_double(&q, 0);
nTooSmall = db_column_double(&q, 1);
}
db_finalize(&q);
}
if( nTooSmall>1 ){
db_prepare(&q, "SELECT amt, label FROM piechart WHERE amt>=:limit"
" UNION ALL SELECT %.17g, '%d others';",
rTooSmall, nTooSmall);
db_bind_double(&q, ":limit", rTotal/OTHER_CUTOFF);
nTotal += 1 - nTooSmall;
}else{
db_prepare(&q, "SELECT amt, label FROM piechart");
}
if( nTotal<=10 ) pieFlags |= PIE_CHROMATIC;
|
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
h = 256*(j+2)/nTotal;
}else{
h = 256*((j+2+(nTotal&1))%nTotal)/nTotal;
}
zClr = rgbName(h,SATURATION,VALUE);
l = x>=0.5;
a1 = a2;
@ <path stroke="black" stroke-width="1" fill="%s(zClr)"
@ d='M%g(cx),%g(cy)L%g(x1),%g(y1)A%g(r),%g(r) 0 %d(l),1 %g(x2),%g(y2)z'/>
@ <line stroke='black' stroke-width='1'
@ x1='%g(x3)' y1='%g(y3)' x2='%g(x4)' y2='%g(y4)''/>
if( rot!=0 ){
@ <text text-anchor="%s(zAnc)" transform='rotate(%d(rot),%g(x5),%g(y5))'
}else{
@ <text text-anchor="%s(zAnc)" transform='rotate(%d(rot),%g(x5),%g(y5))'
}
@ x='%g(x5)' y='%g(y5)'>%h(zLbl)</text>
}
db_finalize(&q);
}
/*
** WEBPAGE: test-piechart
|
|
|
>
>
>
>
|
>
|
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
h = 256*(j+2)/nTotal;
}else{
h = 256*((j+2+(nTotal&1))%nTotal)/nTotal;
}
zClr = rgbName(h,SATURATION,VALUE);
l = x>=0.5;
a1 = a2;
@ <path stroke="%s(zFg)" stroke-width="1" fill="%s(zClr)"
@ d='M%g(cx),%g(cy)L%g(x1),%g(y1)A%g(r),%g(r) 0 %d(l),1 %g(x2),%g(y2)z'/>
@ <line stroke='%s(zFg)' stroke-width='1'
@ x1='%g(x3)' y1='%g(y3)' x2='%g(x4)' y2='%g(y4)''/>
if( rot!=0 ){
@ <text text-anchor="%s(zAnc)" transform='rotate(%d(rot),%g(x5),%g(y5))'
}else{
@ <text text-anchor="%s(zAnc)" transform='rotate(%d(rot),%g(x5),%g(y5))'
}
if( pieFlags & PIE_PERCENT ){
int p = (int)(x*100.0 + 0.5);
@ x='%g(x5)' y='%g(y5)' fill='%s(zFg)'>%h(zLbl) (%d(p)%%)</text>
}else{
@ x='%g(x5)' y='%g(y5)' fill='%s(zFg)'>%h(zLbl)</text>
}
}
db_finalize(&q);
}
/*
** WEBPAGE: test-piechart
|