Annotation goes off right side of chart
Posted: Thu Nov 20, 2014 12:08 am
In the attached demo, I have a couple chart tools--one a TColorLineTool that I place at a specific location on the X (bottom) axis, and a annotation tool that I try to place right over the line to note the lines purpose.
If the line appears on the right side of the chart, I try to position the annotation so that it shifts right as not to cut off the text in the annotation--I even add margin for this. Here is my code for it:
But this can still put the annotation too far right. See here:
I cannot figure out how to get this so it does not go off the right side of the chart. How can I achieve that?
A demo of this is attached.
Thank you,
Ed Dressel
If the line appears on the right side of the chart, I try to position the annotation so that it shifts right as not to cut off the text in the annotation--I even add margin for this. Here is my code for it:
Code: Select all
procedure SetLeftPos(aMiddle: double; aAnnTool: TAnnotationTool);
const
H_MARGIN = 50;
var
lLeft: Integer;
lR: TRect;
lAnnWidth: Integer;
begin
if not aAnnTool.Active then
exit;
lLeft := aChart.BottomAxis.CalcXPosValue(aMiddle);
lR := aAnnTool.Bounds;
lAnnWidth := lR.Right- lR.Left + 1;
aAnnTool.Shape.Left := lLeft - (Max(0, lAnnWidth) div 2);
if aAnnTool.Shape.Left + aAnnTool.Shape.Width > (aChart.Width - H_MARGIN) then
aAnnTool.Shape.Left := aChart.Width - H_MARGIN - aAnnTool.Shape.Width;
aAnnTool.Shape.Top := 30;
end;
I cannot figure out how to get this so it does not go off the right side of the chart. How can I achieve that?
A demo of this is attached.
Thank you,
Ed Dressel