Page 1 of 1

Aligning of vertical marks does not work properly

Posted: Sun Feb 19, 2012 7:56 am
by 16555900
Hello,

I would like to show vertical marks with their bottom edge aligned to some level.
I have set marks angle to 90 degrees and text align to left. Unfortunately, these options cause separation of marks’ text and background. Further tests showed that text aligning works properly only for horizontal orientation of marks.

The simplest test application compiled in Delphi 2009 and TeeChart 2011 is attached. Double click the chart to open chart editor and change the "text align" option. The erroneous behavior can be observed also on design stage.

Could someone propose a method for aligning vertical marks to required level?

Thanks in advance

Stanislaw Sosnowski

Re: Aligning of vertical marks does not work properly

Posted: Mon Feb 20, 2012 10:49 am
by 16555900
Sorry for missed attachment.

below is source code of application and content of the frm file (the simplest form with a chart and a chart editor with default options, apart of marks orientation). Under Delphi XE2 and TeeChart 2011 the error also exists.

Stanislaw Sosnowski



unit UnitXE2;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, VCLTee.TeeEdit, VCLTee.TeEngine,
Vcl.ExtCtrls, VCLTee.TeeProcs, VCLTee.Chart, VCLTee.Series;

type
TForm1 = class(TForm)
Chart1: TChart;
ChartEditor1: TChartEditor;
Series1: TFastLineSeries;
procedure Chart1DblClick(Sender: TObject);
private
public
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Chart1DblClick(Sender: TObject);
begin
ChartEditor1.Execute;
end;

end.



object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 348
ClientWidth = 643
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Chart1: TChart
Left = 0
Top = 0
Width = 643
Height = 348
BackWall.Brush.Gradient.Direction = gdBottomTop
BackWall.Brush.Gradient.EndColor = clWhite
BackWall.Brush.Gradient.MidColor = clNone
BackWall.Brush.Gradient.StartColor = 15395562
BackWall.Brush.Gradient.Visible = True
BackWall.Transparent = False
Foot.Font.Name = 'Verdana'
Gradient.Direction = gdBottomTop
Gradient.EndColor = clWhite
Gradient.MidColor = 15395562
Gradient.StartColor = 15395562
Gradient.Visible = True
LeftWall.Color = 14745599
Legend.Font.Name = 'Verdana'
RightWall.Color = 14745599
SubFoot.Font.Name = 'Verdana'
SubTitle.Font.Name = 'Verdana'
Title.Font.Name = 'Verdana'
Title.Text.Strings = (
'TChart')
BottomAxis.Axis.Color = 4210752
BottomAxis.Grid.Color = 11119017
BottomAxis.LabelsFont.Name = 'Verdana'
BottomAxis.TicksInner.Color = 11119017
BottomAxis.Title.Font.Name = 'Verdana'
DepthAxis.Axis.Color = 4210752
DepthAxis.Grid.Color = 11119017
DepthAxis.LabelsFont.Name = 'Verdana'
DepthAxis.TicksInner.Color = 11119017
DepthAxis.Title.Font.Name = 'Verdana'
DepthTopAxis.Axis.Color = 4210752
DepthTopAxis.Grid.Color = 11119017
DepthTopAxis.LabelsFont.Name = 'Verdana'
DepthTopAxis.TicksInner.Color = 11119017
DepthTopAxis.Title.Font.Name = 'Verdana'
LeftAxis.Axis.Color = 4210752
LeftAxis.Grid.Color = 11119017
LeftAxis.LabelsFont.Name = 'Verdana'
LeftAxis.TicksInner.Color = 11119017
LeftAxis.Title.Font.Name = 'Verdana'
RightAxis.Axis.Color = 4210752
RightAxis.Grid.Color = 11119017
RightAxis.LabelsFont.Name = 'Verdana'
RightAxis.TicksInner.Color = 11119017
RightAxis.Title.Font.Name = 'Verdana'
TopAxis.Axis.Color = 4210752
TopAxis.Grid.Color = 11119017
TopAxis.LabelsFont.Name = 'Verdana'
TopAxis.TicksInner.Color = 11119017
TopAxis.Title.Font.Name = 'Verdana'
Align = alClient
TabOrder = 0
OnDblClick = Chart1DblClick
ExplicitLeft = 280
ExplicitTop = 192
ExplicitWidth = 400
ExplicitHeight = 250
ColorPaletteIndex = 13
object Series1: TFastLineSeries
Marks.Angle = 90
Marks.Arrow.Visible = True
Marks.Callout.Brush.Color = clBlack
Marks.Callout.Arrow.Visible = True
Marks.Visible = True
LinePen.Color = 10708548
XValues.Name = 'X'
XValues.Order = loAscending
YValues.Name = 'Y'
YValues.Order = loNone
Data = {
00190000000000000000808B400000000000D48C4000000000003C8E40000000
0000188F4000000000003A9140000000000008914000000000004A9040000000
0000B48E400000000000048F400000000000988C400000000000B48940000000
0000988C4000000000004C8D400000000000CC8A4000000000004C8D40000000
000036904000000000009A904000000000002C90400000000000748D40000000
0000F48A400000000000FC8C400000000000F48F400000000000EA9040000000
00000C92400000000000CE9340}
end
end
object ChartEditor1: TChartEditor
Chart = Chart1
TreeView = True
GalleryHeight = 0
GalleryWidth = 0
Height = 0
Width = 0
Left = 328
Top = 208
end
end

Re: Aligning of vertical marks does not work properly

Posted: Mon Feb 20, 2012 11:58 am
by narcis
Hi Stanislaw,

I'm not sure about how would you like to align the marks. I recommend you to have a look at this thread about the options for custom marks positioning available. If this doesn't fit your needs please post some more detailed information about your requirement.

BTW: I attach a sample project with the code you posted.

Re: Aligning of vertical marks does not work properly

Posted: Mon Feb 20, 2012 6:36 pm
by 16555900
Hi Narcis,

Thank you for the fast advice. I have read the topics, unfortunately proposed advices was not helpful. Moreover, it seems to be possible that there is a more serious error in procedures of marks repositioning. I attache test application with modified code. Please observe marks behavior during resizing of the main form. They loss links to respective data and seems to be positioned respectively to their centers, independently on applied calculation. The problem indicated also in the earlier post suggests that marks and mark texts are positioned (aligned) independently. So I would like to turn your attention on the strange (not intuitive) behavior.

My problem is not serious and I can temporarily go without a proper solution. I wanted to position marks aligned with their lower edges to the bottom axis of a chart. To be more precise I have two characteristic points which should be marked by vertical lines with marks "glued" to the bottom axis. I used a separate series containing two points. It is all. Please see attached bitmap.
However marks positioning cannot be done by a simple aligning of marks.

Stanislaw
Marks repositioning.zip
(24.27 KiB) Downloaded 785 times

Re: Aligning of vertical marks does not work properly

Posted: Tue Feb 21, 2012 11:47 am
by yeray
Hi Stanislaw,

Note the following line actually does nothing:

Code: Select all

    LeftTop.X:= LeftTop.X;
Changing it for the following works as expected for me here:

Code: Select all

    LeftTop.X:= Series1.CalcXPos(i) - (Width div 2);

Re: Aligning of vertical marks does not work properly

Posted: Tue Feb 21, 2012 5:53 pm
by 16555900
Hi Yeray,

Thank you for advice. Commands
LeftTop.X:= Series1.CalcXPos(i) - (Height div 2);
LeftTop.Y:= 100 - (Width div 2);
align marks as I want, however resizing of main form works improperly.
Especially when size of form is changed significantly, marks appears far from expected positions.

Any suggestions ?

Stanislaw

Re: Aligning of vertical marks does not work properly

Posted: Wed Feb 22, 2012 8:29 am
by yeray
Hi Stanislaw,

I'm not sure to understand what are you obtaining or what are you exactly trying to achieve. Could you please attach an snapshot of the result you are getting and drawing or somehow indicating where would you expect the marks to be?
Thanks in advance.

Re: Aligning of vertical marks does not work properly

Posted: Wed Feb 22, 2012 6:48 pm
by 16555900
Hi Yeray,

Please see the attached project. It contains one fast series with marks oriented vertically (two points only). I need to show only these marks; each one should display value of X coordinate of a given point. The marks should be aligned horizontally (centered) at position of a given point. The vertical position should be arranged on such manner so that bottom edges of marks should be placed at level of the bottom axis. It should be noted that Y values of the points will be be set to 0.
The above arrangement appeared very easy by setting marks' text aligning to left. However, in case of non horizontal orientation of marks, changing of text aligning causes unexpected effects. This is visible also at design step - please check it. In my opinion it is a bug or an unintentional behavior.

In the the attached project the aligning of marks seems to be proper, unfortunately marks are arranged relatively to main form (or the chart panel?) coordinates, thus resizing the form causes separation of marks and appropriate points.

Is it possible to meet my expectation?

With the best wishes

Stanislaw
Marks Arrangement.zip
(1.71 KiB) Downloaded 841 times

Re: Aligning of vertical marks does not work properly

Posted: Mon Feb 27, 2012 4:36 pm
by yeray
Hi Stanislaw,

First of all note you haven't set a minimum/maximum to the left axis, and there are just two values with the same YValue in a unique series. That's why the left axis only shows "0"s as labels. To correct it in your example:

Code: Select all

Chart1.Axes.Left.SetMinMax(-5, 10);
Then, if I modify the following two lines in your example:

Code: Select all

    LeftTop.X:= Series1.CalcXPos(i) - (Height div 2);
    LeftTop.Y:= Series1.CalcYPos(i) - (Width div 2);
For the following:

Code: Select all

    LeftTop.X:=Series1.CalcXPos(i) - Width div 2;
    LeftTop.Y:=Series1.CalcYPos(i) - Width div 2 - 8;
Then it seem to work as you would like to.
Just force a Chart repaint at the end of the FormCreate to see it without needing to scroll or unzoom the chart to force a chart repaint and thus aall to the OnAfterDraw event:

Code: Select all

Chart1.Draw;

Re: Aligning of vertical marks does not work properly

Posted: Tue Feb 28, 2012 5:18 pm
by 16555900
Hi Yeray,

Thank you very much for advices. After tiny changes the chart looks as I want. The code is shown below:

Code: Select all

procedure TForm1.Chart1AfterDraw(Sender: TObject);
var
  i: Integer;
begin
  for i:= 0 to Series1.Count-1 do
  with Series1.Marks.Positions.Position[i] do begin
    Custom:= True;
    LeftTop.X:= Series1.CalcXPos(i) - Width div 2;
    LeftTop.Y:= Series1.CalcYPos(i) - Width div 2 - 8;
    end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Series1.Clear;
  Series1.AddXY(Random(100), 0);
  Series1.AddXY(Random(100), 0);
  Series1.OnGetMarkText:= SeriesGetMarkText;
  Chart1.Axes.Left.SetMinMax(0, 10);
  Chart1.Draw;
end;
However there is still serious problem: I need to resize or to zoom the plot. Unfortunately zooming or resizing cause moving the marks to unpredictable positions (even out of the chart when resizing is large). Next resizing (but only very small) brings the marks closely to proper positions. How to avoid this?

And additional question: what does mean digit 8 in your code? I guess that it is related to font size and it should be modified when font size is changed. But could you to explain this more precisely?

with best wishes

Stanislaw

Re: Aligning of vertical marks does not work properly

Posted: Fri Mar 02, 2012 10:23 am
by yeray
Hi,
Stanislaw wrote:However there is still serious problem: I need to resize or to zoom the plot. Unfortunately zooming or resizing cause moving the marks to unpredictable positions (even out of the chart when resizing is large). Next resizing (but only very small) brings the marks closely to proper positions. How to avoid this?
It would probably be more logical (and it solves this) to create a method (ie AlignMarks) to calculate the new marks position and call it at OnScroll, OnZoom, OnUndoZoom and OnResize events:

Code: Select all

procedure TForm1.AlignMarks;
var
  i: Integer;
begin
  Chart1.Draw;

  for i:= 0 to Series1.Count-1 do
  with Series1.Marks.Positions.Position[i] do begin
    Custom:= True;
    LeftTop.X:=Series1.CalcXPos(i) - Width div 2;
    LeftTop.Y:=Series1.CalcYPos(i) - Width div 2 - 8;
    end;
  Series1.Repaint;
end;

procedure TForm1.Chart1Scroll(Sender: TObject);
begin
  AlignMarks;
end;

procedure TForm1.Chart1Resize(Sender: TObject);
begin
  AlignMarks;
end;

procedure TForm1.Chart1Zoom(Sender: TObject);
begin
  AlignMarks;
end;

procedure TForm1.Chart1UndoZoom(Sender: TObject);
begin
  AlignMarks;
end;
Stanislaw wrote:And additional question: what does mean digit 8 in your code? I guess that it is related to font size and it should be modified when font size is changed. But could you to explain this more precisely?
The calculations made to rotate the marks are not so easy to extrapolate and inverse to find the horizontal and vertical exact displacements to be applied. I haven't find a simple way to calculate them, but if you find the font size approximation gives you a good enough result, of course, use it.

Re: Aligning of vertical marks does not work properly

Posted: Sun Mar 04, 2012 4:30 pm
by 16555900
Dear Yeray,
All works excellently.

Best wishes
Stanislaw