Click here to Skip to main content
15,867,330 members
Articles / Desktop Programming / MFC
Article

2D Multi-Parameter Pie Control

Rate me:
Please Sign up or sign in to vote.
4.25/5 (4 votes)
7 Jan 20032 min read 62.9K   2.4K   22   2
A simple 2D Pie Control

Image 1

Introduction

The Code Project is an exciting site with impressive teaching and professional exchange capabilities. I have learned much from it and also decided to submit my contribution. Occasionally I was involved in a project to check experimental data for consistency. The data were collected in several binary files, which also contain "holes", i.e. missing data segments. The main idea to simplify the fast check report was to embed this report inside the progress control. So first of all I had found :

I thank these authors for inspiration. It was a starting point, because I needed a more complex structure of the progress control to show report data.

Resolving the problem

Considering 2D pie chart you can easily reveal that it contains 4 parameters, which are potentially able to display 4 independent variables. These are width of angular sectors, their radius, initial offset from the horizontal line (an initial phase), and the color of each angular segment. A small restriction in conversion to the geometrical representation is that the radius and width of angular sectors require positive determined input data, what is sometimes automatically met (for instance, counting number of iterations or loop passing). You may think about the example represented by the figure as a report of processed files, which have their own length (width), the "holes" total length relative to the file length (%) (radius), maximal "hole" length relative to the file length (%) (color), and possibly deviation of the processing time from the mean value (%) (phase). (I have never used the last option, always assuming it as zero, but I believe it can be used in other tasks).

Programming issues

All necessary operations are included in the Cpcontrol class derived from CStatic, which converts processed data into their geometrical representation and displays them in an appropriate window frame. Cpcontrol class is embedded in the standard dialog application, which is responsible for the general data processing and collecting data for the Pie Progress Control. The internal labels of the control can be customized during the process of the dialog initialization.

BOOL CPieProgressCtrlDlg::OnInitDialog()
{    
    CDialog::OnInitDialog();
    
    // some useful code here    
    //setting for progress pie control
    
    m_pWnd=GetDlgItem(IDC_PROGRESS);    
    m_control.m_pWnd=m_pWnd;
    
    CRect rect;    
    m_pWnd->GetClientRect(&rect);    
    m_control.m_rect=rect;    
    int lenx=rect.right-rect.left;    
    int leny=rect.bottom-rect.top;    
    m_control.m_w=lenx;    
    m_control.m_h=leny;
    
    // keep ratio 2/3 for the control
    
    if(2*lenx>3*leny) 
        m_control.m_w=(int)floor(1.5*leny);    
    else 
        if(2*lenx<3*leny) 
            m_control.m_h=(int)floor(2.0*lenx/3);
    
    m_control.m_top=rect.top;    
    m_control.m_left=rect.left;    
    strcpy(m_control.m_bottom,"total");    
    strcpy(m_control.m_color,"Max bad segments");    
    strcpy(m_control.m_ctitle,"Current processing info");    
    int fsize=8;
    
    if(m_control.m_h>80 && m_control.m_h<150) 
        fsize=10;
    else 
        if(m_control.m_h>=150) 
            fsize=12;
    
    LOGFONT lf; // Used to create the CFont.    
    memset(&lf, 0, sizeof(LOGFONT)); // Clear out structure.    
    lf.lfHeight = fsize; // Request a 12-pixel-high font    
    strcpy(lf.lfFaceName, "Arial"); // with face name "Arial".    
    m_control.m_SmallFont.CreateFontIndirect(&lf); // Create the small font.
    
    lf.lfHeight = fsize+2;    
    m_control.m_MiddleFont.CreateFontIndirect(&lf);    
    lf.lfHeight = fsize+4;    
    lf.lfWeight=FW_BOLD;    
    m_control.m_BigFont.CreateFontIndirect(&lf);    
    m_control.m_cur=-1;
    
    // some other code     
}

The process of geometrical conversion in the pie progress control is pretty fast and not time consuming as compared with the general data processing. In the above mentioned example an additional delaying function Sleep(500) is used to make an impression this example is visually running.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Researcher
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralCool Pin
NormDroid8-Jan-03 22:54
professionalNormDroid8-Jan-03 22:54 
GeneralBroken link Pin
Ali Khanlarkhani8-Jan-03 19:24
Ali Khanlarkhani8-Jan-03 19:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.