Page 1 of 1

MarkText SeriesPt not scrolling Correct

Posted: Mon Mar 09, 2015 4:15 pm
by 10049920
I have added some MarkText to series marks, and all works well unless the user moves the text boxes and also moves the scroll bar.

If the user moves the MarkText and then scrolls, the MarkText stays in the same screen position, and does not move with the rest of the cart. This happens for all unmoved MarkText items after the one moved, but any unmoved ones before it work fine. Once you scroll to where the item would no longer be visible, then it just disappears.

I was using 8.06 but upgraded to version 8.08 and the problem still exists.
See Attached Pictures.

Re: MarkText SeriesPt not scrolling Correct

Posted: Tue Mar 10, 2015 4:15 pm
by yeray
Hello,

Take a look at this reply.
I've made a simple example using a TBarSeries:

Code: Select all

uses Series, Types;

var XOffset, YOffset: Array of Integer;
    MouseDownPos: TPoint;

procedure TForm1.FormCreate(Sender: TObject);
var s, i: Integer;
begin
  Chart1.Legend.Visible:=false;
  Chart1.View3D:=false;

  with Chart1.AddSeries(TBarSeries) do
  begin
    FillSampleValues;
    Marks.Arrow.Color:=clRed;
  end;

  SetLength(XOffset, Chart1[0].Count);
  SetLength(YOffset, Chart1[0].Count);

  for i:=0 to High(XOffset) do
  begin
    XOffset[i]:=0;
    YOffset[i]:=0;
  end;

  with Chart1.Tools.Add(TDragMarksTool) as TDragMarksTool do
  begin
    Series:=Chart1[0];
    OnDraggedMark:=DragMarksOnDragged;
  end;

end;

procedure TForm1.DragMarksOnDragged(Sender:TDragMarksTool; Index:Integer;
                                    Button:TMouseButton; Shift: TShiftState;
                                    X,Y: Integer);
begin
  if Assigned(Sender.Series) then
  begin
    if (Index>-1) and (Index<Length(XOffset)) then
    begin
      XOffset[Index]:=XOffset[Index]+X-MouseDownPos.X;
      YOffset[Index]:=YOffset[Index]+Y-MouseDownPos.Y;
    end;
  end;
end;

procedure TForm1.PlaceMarks;
var s, i, tmpSize, tmpX, tmpY: Integer;
begin
  Chart1.Draw;

  for s:=0 to Chart1.SeriesCount-1 do
    if Chart1[s] is TBarSeries then
      with Chart1[s] as TBarSeries do
      begin
        for i:=0 to Count-1 do
          with Marks.Positions[i] do
          begin
            tmpX:=CalcXPos(i);
            tmpY:=CalcYPos(i);

            Custom:=true;
            LeftTop.X:=tmpX + BarWidth div 2 - Marks.Item[i].Width div 2 + XOffset[i];

            if MarksOnBar then
              if MarksLocation=mlEnd then
                LeftTop.Y:=tmpY
              else
              begin
                tmpSize:=CalcYSizeValue(YValue[i]);
                if MarksLocation=mlStart then
                  LeftTop.Y:=tmpY+tmpSize-Marks.Height
                else
                  LeftTop.Y:=tmpY+(tmpSize div 2)-(Marks.Height div 2);
              end
            else
              LeftTop.Y:=tmpY-Marks.ArrowLength-Marks.Height;

            LeftTop.Y:=LeftTop.Y+YOffset[i];
            ArrowFrom:=Point(tmpX+BarWidth div 2, tmpY);
            ArrowTo:=Point(LeftTop.X+Marks.Item[i].Width div 2, LeftTop.Y);
          end;
      end;
end;

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

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

procedure TForm1.Chart1UndoZoom(Sender: TObject);
begin
  PlaceMarks;
end;

procedure TForm1.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  MouseDownPos.X:=X;
  MouseDownPos.Y:=Y;
end;

Re: MarkText SeriesPt not scrolling Correct

Posted: Tue Mar 10, 2015 9:23 pm
by 10049920
Thanks, for the help. It has been along time since I had to work with these charts, could you add a bit more.

1. Supply the whole project so i can run the code and watch it work. (unknown items on compile MarksOnBar, MarksLocation, and mlEnd)

Or

2. Add some comments to PlaceMarks so I can figure out how to translate that into what I am doing.

Re: MarkText SeriesPt not scrolling Correct

Posted: Wed Mar 11, 2015 9:10 am
by yeray
Hello,

Sorry, I took part of the code from an example using a newer version.
I've tested this with TeeChart v8:
draggingMarks_TeeChart8.zip
(1.81 KiB) Downloaded 669 times