Alignment of vertical axes of dynamic plots.

TeeChart for ActiveX, COM and ASP
Post Reply
BARMatt
Newbie
Newbie
Posts: 5
Joined: Wed Jan 12, 2011 12:00 am

Alignment of vertical axes of dynamic plots.

Post by BARMatt » Wed Apr 20, 2011 12:17 am

I've searched for how to align the vertical axes of a column of plots and found this link but it doesn't work for my purposes. The example in the thread seems to presume that the alignment will only happen once, as the plots are initialized, and that once every property is given the same value that all will be well. This won't work for me because my users have the ability to change various settings like label format, tick length, the font size of the labels and title (if they choose to have a title at all) as well as legend position. The vertical axis alignment must be maintained no matter what else the user configures.

I've tried various versions of the following using custom rectangles, margins, etc. with no success.

Code: Select all

for(i = 0; i < m_nCols; i++)
{
    left = 0;
    right = 99999;
    for(j = 0; j < m_nRows; j++)
    {
        m_Plots[i][j]->SetCustomChartRect(FALSE);
        m_Plots[i][j]->GetEnvironment().InternalRepaint();
        tr = m_Plots[i][j]->GetGetChartRect();
        if(tr.GetLeft() > left) left = tr.GetLeft();
        if(tr.GetRight() < right) right = tr.GetRight();
    }

    for(j = 0; j < m_nRows; j++)
    {
        tr = m_Plots[i][j]->GetGetChartRect();
        m_Plots[i][j]->SetCustomChartRect(TRUE);
        m_Plots[i][j]->ChartRect(left, tr.GetTop(), right, tr.GetBottom());
        m_Plots[i][j]->GetEnvironment().InternalRepaint();
    }
}
The idea is to revert back to allowing TeeChart to determine the plot boundaries based on all of the various components then manually setting each plot in the column to common values based on the defaults. How can I do this? What is the best way to align the vertical axes of a column of plots, on-demand, where the only graphical setting that I can count on is that all of the plots will be two dimensional line series and where I cannot override things like axis settings that the user has already configured?

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Alignment of vertical axes of dynamic plots.

Post by Yeray » Wed Apr 20, 2011 10:05 am

Hello Matt,

Your code snipped looks fine to me. Could you please attach your testing application so we can reproduce the complete situation here?
Thanks in advance.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

BARMatt
Newbie
Newbie
Posts: 5
Joined: Wed Jan 12, 2011 12:00 am

Re: Alignment of vertical axes of dynamic plots.

Post by BARMatt » Thu Apr 21, 2011 12:05 am

Can do. I adapted something I was using to play with the legend (and related to an older post I made that I hope to eventually get back to) before I got pulled away from this whole thing for a little while. So ignore the legend-y looking controls at the bottom. I also removed all that code to just focus on this. Anyway, I was looking at this and noticed that the left and right sides are aligning but that they are doing so in a way other than what I'm looking for. The ChartRect I set bounds the entire image, labels, legend and all, and I want to only specify the actual plot bounds and let TeeChart put the axis labels and legend where it wants to relative to that. This also effects the top and bottom as you can see. Even though I specifically set the ChartRect top and bottom to the values given by GetChartRect, the plot shrinks. It's weird because GetChartRect returns the plot boundaries as expected but setting that property includes the other elements. I can mock up screenshots of the before and after that I'm looking for, if that will help.

Another issue can be seen by:

1) Start the program.
2) Check "Align Plots."
3) They resize somewhat correctly in the manner I described above.
4) Uncheck "Align Plots."
5) Resize the window again.
6) Check "Align Plots" again.
7) They resize to the rectangles that were calculated the first time and NOT relative to the default positions set after step 5. I'm not using any static members or variables and TRACE statements show that ChartRect is being called with the correct values.
Attachments
TCLegendTest.zip
(22.31 KiB) Downloaded 544 times

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Alignment of vertical axes of dynamic plots.

Post by Narcís » Tue Apr 26, 2011 9:53 am

Hi BARMatt,

Thanks for the example project but I'm not able to run it because TChartHeaders.h is missing from your project. Could you please attach it?

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

BARMatt
Newbie
Newbie
Posts: 5
Joined: Wed Jan 12, 2011 12:00 am

Re: Alignment of vertical axes of dynamic plots.

Post by BARMatt » Tue Apr 26, 2011 1:39 pm

Crap. Sorry about that. I also included the actual TeeChart files that I'm using to build.
Attachments
TCLegendTest2.zip
(506.01 KiB) Downloaded 606 times

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Alignment of vertical axes of dynamic plots.

Post by Yeray » Wed Apr 27, 2011 3:26 pm

Hello Matt,

Note that the GetGetChartRect returns the rectangle formed by the axes, so it doesn't include the labels widths, the space occupied by the legend,... However, when you set a rectangle to be used by the ChartRect function, this rectangle includes those extra "margins".
So you should calculate the these extra pixels needed and accommodate the calculated rectangle with them. Here is how you could do it:

Code: Select all

void CTCLegendTestDlg::CalcChartRectMargins(CTChart& AChart, int& ALeft, int& ARight, int& ATop, int& ABottom)
{
	ALeft = ARight = ATop = ABottom = 0;

	if(AChart.GetAxis().GetLeft().GetVisible())
	{
		ALeft = ALeft + AChart.GetAxis().GetLeft().GetLabels().MaxWidth() + AChart.GetAxis().GetLeft().GetTickLength() + 7;
	}

	if(AChart.GetAxis().GetRight().GetVisible())
	{
		ARight = ARight + AChart.GetAxis().GetRight().GetLabels().MaxWidth() + AChart.GetAxis().GetRight().GetTickLength() + 7;
	}

	if(AChart.GetAxis().GetBottom().GetVisible())
	{
		ABottom = ABottom + AChart.GetAxis().GetBottom().GetLabels().Height(0) + AChart.GetAxis().GetBottom().GetTickLength() + 3;
	}

	if(AChart.GetLegend().GetVisible())
	{
		if(AChart.GetLegend().GetAlignment() == laRight)
		{
			ARight = ARight + AChart.GetLegend().GetWidth() + 23;
		}
		else if(AChart.GetLegend().GetAlignment() == laLeft)
		{
			ALeft = ALeft + AChart.GetLegend().GetWidth() + 23;
		}
		else if(AChart.GetLegend().GetAlignment() == laTop)
		{
			ATop = ATop + AChart.GetLegend().GetHeight() + 20;
		}
		else if(AChart.GetLegend().GetAlignment() == laBottom)
		{
			ABottom = ABottom + AChart.GetLegend().GetHeight() + 20;
		}
	}

	if(AChart.GetHeader().GetVisible())
	{
		ATop = ATop + AChart.GetHeader().GetHeight() + 5;
	}
}

//...
void CTCLegendTestDlg::AlignPlots(void)
{
//...
    if(m_alignEnabled)
    {
		int tmpL, tmpR, tmpT, tmpB;

		CalcChartRectMargins(m_topPlot, tmpL, tmpR, tmpT, tmpB);
        m_topPlot.SetCustomChartRect(TRUE);
        m_topPlot.ChartRect(left-tmpL, tr.GetTop()-tmpT, right+tmpR, tr.GetBottom()+tmpB);
        m_topPlot.Repaint();

		CalcChartRectMargins(m_midPlot, tmpL, tmpR, tmpT, tmpB);
        m_midPlot.SetCustomChartRect(TRUE);
        m_midPlot.ChartRect(left-tmpL, mr.GetTop()-tmpT, right+tmpR, mr.GetBottom()+tmpB);
        m_midPlot.Repaint();

        CalcChartRectMargins(m_btmPlot, tmpL, tmpR, tmpT, tmpB);
		m_btmPlot.SetCustomChartRect(TRUE);
        m_btmPlot.ChartRect(left-tmpL, br.GetTop()-tmpT, right+tmpR, br.GetBottom()+tmpB);
        m_btmPlot.Repaint();
    }
}
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

BARMatt
Newbie
Newbie
Posts: 5
Joined: Wed Jan 12, 2011 12:00 am

Re: Alignment of vertical axes of dynamic plots.

Post by BARMatt » Wed Apr 27, 2011 5:45 pm

Okay, I've finally stopped dancing long enough to reply. Yeray, you are my hero. I've been fiddling with this off and on for ages, trying to find the right combination of function calls, metrics, and math to do exactly what your snippet does. Thanks a million! I still get the other problem I described though; setting the ChartRect once results in those values being used every time.

Image 1 is what happened when I aligned the plots the first time. Perfect. Image 2 is what happened after I turned off the alignment, resized the window, then aligned again. As you can see, the "After" part of Image 2 put the plots in the same position as the "After" part of Image 1. However, the ChartRect calls in both cases look correct:

Image 1:
m_topPlot.ChartRect(65, 8, 702, 187);
m_midPlot.ChartRect(23, 8, 617, 187);
m_btmPlot.ChartRect(23, 8, 716, 187);

Image 2:
m_topPlot.ChartRect(73, 7, 942, 156);
m_midPlot.ChartRect(31, 7, 857, 156);
m_btmPlot.ChartRect(31, 7, 956, 156);
Attachments
1.gif
1.gif (76.05 KiB) Viewed 9719 times
2.gif
2.gif (82.41 KiB) Viewed 9715 times

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Alignment of vertical axes of dynamic plots.

Post by Yeray » Fri Apr 29, 2011 2:57 pm

Hello Matt,
BARMatt wrote:Okay, I've finally stopped dancing long enough to reply. Yeray, you are my hero. I've been fiddling with this off and on for ages, trying to find the right combination of function calls, metrics, and math to do exactly what your snippet does. Thanks a million!
What can I say... I'm really thankful to hear I helped you. :D
BARMatt wrote:I still get the other problem I described though; setting the ChartRect once results in those values being used every time.Image 1 is what happened when I aligned the plots the first time. Perfect. Image 2 is what happened after I turned off the alignment, resized the window, then aligned again. As you can see, the "After" part of Image 2 put the plots in the same position as the "After" part of Image 1. However, the ChartRect calls in both cases look correct:Image 1:m_topPlot.ChartRect(65, 8, 702, 187);m_midPlot.ChartRect(23, 8, 617, 187);m_btmPlot.ChartRect(23, 8, 716, 187);Image 2:m_topPlot.ChartRect(73, 7, 942, 156);m_midPlot.ChartRect(31, 7, 857, 156);m_btmPlot.ChartRect(31, 7, 956, 156);
I'm afraid I haven't been able to find a solution for this so I've added it to the wish list to be investigated further (TV52015549).
I've seen in TeeProcs, line 1582, there is:

Code: Select all

  if CustomChartRect and IsRectEmpty(ICachedChartRect) then
    ICachedChartRect:=ChartRect;
If you change the above for the following the initial problem seems fixed:

Code: Select all

  if CustomChartRect and (IsRectEmpty(ICachedChartRect) or (not EqualRect(ICachedChartRect, ChartRect))) then
     ICachedChartRect:=ChartRect;
However, resizing a chart with a modified ChartRect makes the chart to become smaller and smaller. So they don't seem to be good fixes enough.

Note that the references to TeeProcs.pas make reference to TeeChart VCL sources. As TeeChart ActiveX is a wrapper from the VCL version, as soon as this will be modified in the VCL sources the modification will be inherited in the next ActiveX build.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply