Shape bounds are not always available
Posted: Wed Jul 05, 2006 4:31 pm
I have tried to get the label shape bounds and if I make the label visible and try to get its bounds right away in C++ it shows up as a NULL rect. Is there a way of forcing TChart to update this right away?
Here is the sample code:
You'll note that the ASSERT(!rect.IsRectNull()); fails.
Thanks for your help,
Adrian
Here is the sample code:
Code: Select all
CRect ConvertTeeRect(CTeeRect & teeRect)
{
return CRect(teeRect.GetLeft(), teeRect.GetTop(), teeRect.GetRight(), teeRect.GetBottom());
}
void testFunction()
{
CTChart& tchart = *(CTChart*)GetDlgItem(IDC_TCHART1);
enum { eAllTraces = 10 };
long AxisIds[eAllTraces];
long LabelIds[eAllTraces];
long TraceIds[eAllTraces];
for (int index = 0
; index < eAllTraces
; ++index) {
//------------------------------------------------------------------
// Adding custom axis
AxisIds[index] = tchart.GetAxis().AddCustom(false);
CAxis& axis = tchart.GetAxis().GetCustom(AxisIds[index]);
axis.SetMaximumOffset(axis.GetMaximumOffset()+10*index);
axis.SetMinimumOffset(axis.GetMinimumOffset()-10*index);
//------------------------------------------------------------------
// Adding Label
CAxisLabels& labels = axis.GetLabels();
LabelIds[index] = labels.Add(0.0, "");
// Setup label properties
CAxisLabelsItem& label = labels.GetItem(LabelIds[index]);
label.SetShapeStyle(fosRoundRectangle);
label.GetFont().SetSize(10);
label.GetFont().SetBold(true);
label.SetTransparent(false);
ASSERT(label.GetVisible());
CRect rect = ConvertTeeRect(label.GetShapeBounds());
ASSERT(!rect.IsRectNull());
//------------------------------------------------------------------
// Adding series (trace)
TraceIds[index] = tchart.AddSeries(scLine);
CSeries& series = tchart.Series(TraceIds[index]);
// Attach the series to the custom axis
series.SetVerticalAxisCustom(AxisIds[index]);
for (double x = 0; x < 1; x += .01) {
double y = (((double)rand()) / RAND_MAX) * 0.2 - 0.1;
series.AddXY(x, y, "", RGB(0xff, 0, 0));
}
}
}
Thanks for your help,
Adrian