Displays a pie chart by means of the <svg> tag and associated javascript. Returns: None
| Return Type | Function name | Arguments |
|---|---|---|
| void | hdsChartPie::Generate | (hzChain&,hzHttpEvent*,uint32_t&,) |
Declared in file: hzDissemino.h
Defined in file : hdsGenerate.cpp
Function Logic:
Function body:
void hdsChartPie::Generate (hzChain& Z)hzHttpEvent* pE, uint32_t& nLine,
{
// Category: HTML Generation
//
// Displays a pie chart by means of the <svg> tag and associated javascript.
//
// Arguments: 1) Z The HTML output chain
// 2) pE The HTTP event being responded to
// 3) nLine Line number tracker (controls NL printing)
//
// Returns: None
_hzfunc("hdsChartPie::Generate") ;
_pie* pSlice ; // Pie value
double val ; // Current segment value
double sofar ; // Total value of all segments so far processed
double deg ; // Angle from top
double ang ; // Angle in radians
uint32_t X ; // Destination horizontal coord
uint32_t Y ; // Destination vertical coord
uint32_t last_y = 0; // y-coord
uint32_t last_x = 0; // x-coord
uint32_t n ; // Parts iterator
uint32_t bSmall ; // Short arc indicator
// char buf[200] ;
// Open svg tag
Z.Printf("\n<svg id=\"%s\" height=\"%d\" width=\"%d\" style=\"background:#%06x;\">", *m_Id, m_Height, m_Width, m_BgColor) ;
// Draw header and footer if applicable
if (m_Header)
_hds_svg_drawText(Z, m_Header, m_Width/2,20,m_FgColor,1);
// Work out what percentage of the total, each part represents
last_x = m_ccX ;
last_y = m_ccY - m_Rad ;
sofar = val = 0.0;
for (n = 0; n < m_nSlices ; n++)
{
pSlice = m_pSlices + n ;
bSmall = pSlice->m_nValue/m_Total >&eq; 0.5?1:0;
Z << "\t<path d=\"" ;
if ((n+1)== m_nSlices)
{
X = m_ccX ;
Y = m_ccY - m_Rad ;
Z.Printf("M %u %u L %u %u A %u %u 0 %d 1 %u %u Z\" fill=\"#%06x\"/>\n", m_ccX, m_ccY, last_x, last_y, m_Rad, m_Rad, bSmall, X, Y, pSlice->color) ;
}
else
{
sofar += pSlice->m_nValue ;
deg = (360*sofar)/m_Total;
ang = (deg * M_PI)/180;
X = m_ccX + (m_Rad * sin(ang)) ;
Y = m_ccY - (m_Rad * cos(ang)) ;
Z.Printf("M %u %u L %u %u A %u %u 0 %d 1 %u %u Z\" fill=\"#%06x\"/>\n", m_ccX, m_ccY, last_x, last_y, m_Rad, m_Rad, bSmall, X, Y, pSlice->color) ;
last_x = X ;
last_y = Y ;
}
}
// Write index
X = m_ccX + m_Rad + 40;
Y = m_ccY - m_Rad ;
for (n = 0; n < m_nSlices ; n++)
{
pSlice = m_pSlices + n ;
Z.Printf("<rect x=\"%u\" y=\"%u\" width=\"%u\" height=\"%u\" style=\"fill:#%06x;stroke:#%06x;stroke-width:1\"/>\n",
X, Y, 12,12,pSlice->color,m_FgColor,1);
_hds_svg_drawText(Z, pSlice->header, X+15,Y+12,m_FgColor,0);
Y += 20;
}
if (m_Footer)
_hds_svg_drawText(Z, m_Footer, m_Width/2,m_Height - 20,m_FgColor,1);
Z << "</svg>\n" ;
}