Click here to Skip to main content
15,907,183 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Get computer name ? Pin
Surivevoli24-Apr-06 2:22
Surivevoli24-Apr-06 2:22 
GeneralRe: Get computer name ? Pin
Surivevoli24-Apr-06 7:00
Surivevoli24-Apr-06 7:00 
GeneralRe: Get computer name ? Pin
Eytukan24-Apr-06 2:14
Eytukan24-Apr-06 2:14 
GeneralRe: Get computer name ? Pin
Ryan Binns24-Apr-06 4:57
Ryan Binns24-Apr-06 4:57 
GeneralRe: Get computer name ? Pin
Surivevoli24-Apr-06 7:01
Surivevoli24-Apr-06 7:01 
GeneralRe: Get computer name ? Pin
David Crow24-Apr-06 7:16
David Crow24-Apr-06 7:16 
QuestionDiagrams: Axis Resolution Computation Pin
Sebastian Schneider23-Apr-06 22:36
Sebastian Schneider23-Apr-06 22:36 
AnswerRe: Diagrams: Axis Resolution Computation Pin
Cedric Moonen23-Apr-06 22:56
Cedric Moonen23-Apr-06 22:56 
It is difficult to understand your code (you should have explained it a little bit).
Anyway, I developped my own charting control also and of course I developped also a 'clever' way of displaying the ticks (taking anything as min and max values for the axis). The ticks are readable values. Here is the code:

void CGraphAxis::CalculateBestTicks()
{
	//Calculate the appropriate TickSpace (1 tick every 30 pixel +/-)
	if (m_bIsLogarithmic)
	   m_TickIncrement = 10;
    else
    {
    	int PixelSpace;
    	if (m_bIsHorizontal)
    		PixelSpace = 25;
    	else
    		PixelSpace = 20;
    
    	int MaxTickNumber = (int)fabs((m_EndPos-m_StartPos)/PixelSpace);
    
    	//Best Tick Space
    	float TempTickSpace = (m_MaxValue-m_MinValue)/MaxTickNumber;
    
    	//Calculate appropriate tickSpace (not rounded on 'strange values' but 
    	// on something like 1, 2 or 5*10^X  where X is optimalized for showing the most
    	// significant digits)
    	int Zeros = (int)floor(log10(TempTickSpace));
    	float MinTickSpace = pow(10,Zeros);
    
    	int Digits = 0;
    	if (Zeros<0)		//must set digits
    	{
    		Digits = (int)fabs(Zeros);
    	}
    
    	if (MinTickSpace>=TempTickSpace)
    	{
    		m_TickIncrement = MinTickSpace;
    		SetDecimals(Digits);
    	}
    	else if (MinTickSpace*2>=TempTickSpace)
    	{
    		m_TickIncrement = MinTickSpace*2;
    		SetDecimals(Digits);
    	}
    	else if (MinTickSpace*5>=TempTickSpace)
    	{
    		m_TickIncrement = MinTickSpace*5;
    		SetDecimals(Digits);
    	}
    	else if (MinTickSpace*10>=TempTickSpace)
    	{
    		m_TickIncrement = MinTickSpace*10;
    		if (Digits)
    			SetDecimals(Digits-1);
    		else
    			SetDecimals(Digits);
    	}
    }
	
	//Calculate first Tick Value
	if (m_bIsLogarithmic)
	{
        int LogBase = (int)log10(m_MinValue);
        m_FirstTickVal = pow(10,LogBase);
     }
    else
    {
    	m_FirstTickVal = 0;
    	if (m_TickIncrement!=0)
    	{
    		if (m_MinValue == 0)
    			m_FirstTickVal = 0;
    		else if (m_MinValue>0)
    		{
    			m_FirstTickVal = (int)(m_MinValue/m_TickIncrement) * m_TickIncrement;
    			while (m_FirstTickVal<m_MinValue)
    				m_FirstTickVal += m_TickIncrement;
    		}
    		else
    		{
    			m_FirstTickVal = (int)(m_MinValue/m_TickIncrement) * m_TickIncrement;
    			while (m_FirstTickVal>m_MinValue)
    				m_FirstTickVal -= m_TickIncrement;
    			if (!(m_FirstTickVal == m_MinValue))
    				m_FirstTickVal += m_TickIncrement;
    		}
    	}
     }
}


Explanation of how it works:
First, just look at the non logarithmic part. m_StartPos and m_EndPos are the screen position of the axis and m_MinValue and m_MaxValue are the min and max values respectively.
I first know that a 'good' space between the ticks (in screen coordinates) are 25 or 20 pixels (for horiz or vertical axis). Then, knowing that I calculate the number of ticks (knowing the size of the axis) and the space (in value) between the ticks. These are temp values (the resulting values will need to be as close as possible to these values).

Then, I calculate the space (in values) between ticks but no rounded on strange values (like you described) but on something like 1, 2 or 5*10^X where X is optimalized for showing the most significant digits. Then after that I calculate the number of digits that will be displayed on the ticks label (this is used when you have ticks separated by less than 1).

Finally, we need to calculate the first tick value because your axis can start anywhere and not necessarily on a tick.

Hope this helps
GeneralRe: Diagrams: Axis Resolution Computation Pin
Sebastian Schneider23-Apr-06 23:32
Sebastian Schneider23-Apr-06 23:32 
GeneralRe: Diagrams: Axis Resolution Computation Pin
Sebastian Schneider26-Apr-06 2:33
Sebastian Schneider26-Apr-06 2:33 
GeneralRe: Diagrams: Axis Resolution Computation Pin
Cedric Moonen26-Apr-06 2:43
Cedric Moonen26-Apr-06 2:43 
QuestionInstaniating objects of unknown class definitions Pin
christopher.carver23-Apr-06 20:23
christopher.carver23-Apr-06 20:23 
AnswerRe: Instaniating objects of unknown class definitions Pin
Michael Dunn23-Apr-06 20:33
sitebuilderMichael Dunn23-Apr-06 20:33 
AnswerRe: Instaniating objects of unknown class definitions Pin
Cedric Moonen23-Apr-06 20:38
Cedric Moonen23-Apr-06 20:38 
AnswerRe: Instaniating objects of unknown class definitions Pin
Steve Echols23-Apr-06 20:55
Steve Echols23-Apr-06 20:55 
QuestionNative Applicaion Pin
rajeevktripathi23-Apr-06 19:49
rajeevktripathi23-Apr-06 19:49 
AnswerRe: Native Applicaion Pin
includeh1023-Apr-06 20:40
includeh1023-Apr-06 20:40 
GeneralRe: Native Applicaion Pin
Stephen Hewitt23-Apr-06 21:36
Stephen Hewitt23-Apr-06 21:36 
AnswerRe: Native Applicaion Pin
Stephen Hewitt23-Apr-06 21:41
Stephen Hewitt23-Apr-06 21:41 
QuestionHelp me!!! Pin
sieucauthu23-Apr-06 19:21
sieucauthu23-Apr-06 19:21 
AnswerRe: Help me!!! Pin
Manish K. Agarwal23-Apr-06 19:37
Manish K. Agarwal23-Apr-06 19:37 
GeneralRe: Help me!!! Pin
sieucauthu23-Apr-06 19:46
sieucauthu23-Apr-06 19:46 
AnswerRe: Help me!!! Pin
Le Thanh Cong23-Apr-06 20:21
Le Thanh Cong23-Apr-06 20:21 
AnswerRe: Help me!!! Pin
Michael Dunn23-Apr-06 20:39
sitebuilderMichael Dunn23-Apr-06 20:39 
AnswerRe: Help me!!! Pin
Amar Sutar23-Apr-06 20:42
Amar Sutar23-Apr-06 20:42 

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.