Page 1 of 1

TColorBandTool limits

Posted: Wed Jan 07, 2015 11:29 am
by 16570117
Hi,

I am using TColorBandTool as a special data selector on my chart. It looks like a resizable yellow rectangle (start and end lines are allowed to be dragged). That rectangle can be any size now ( depends upon values StartValue, EndValue) but I would like to limit that.

My question is if it's possible to limit band width in a simple way?

Let's say I would like to limit band width to 10px (10px between StartValue and EndValue). I expect that whenever I drag one side of it, it will stop resizing when it reaches minimum size of 10px and it will continue resizing when size will be greater than that.

I hope I was clear enough. Thank you in advance.

Kind regards,
Aljosa

Re: TColorBandTool limits

Posted: Thu Jan 08, 2015 3:22 pm
by yeray
Hello,

You could use the events to force that. Ie:

Code: Select all

var draggingStart, draggingEnd: boolean;

procedure TForm1.ChartTool1Resizing(Sender: TObject);
var tmp: Double;
begin
  tmp:=Chart1.Axes.Bottom.CalcPosPoint(10)-Chart1.Axes.Bottom.CalcPosPoint(0);

  if (Chart1.Axes.Bottom.CalcSizeValue(ChartTool1.StartValue, ChartTool1.EndValue) > 10) then
  begin
    if draggingStart then
      ChartTool1.StartValue:=ChartTool1.EndValue-tmp;
    if draggingEnd then
      ChartTool1.EndValue:=ChartTool1.StartValue+tmp;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  draggingStart:=false;
  draggingEnd:=false;

  ChartTool1.StartLine.OnBeginDragLine:=StartLineBeginDragging;
  ChartTool1.StartLine.OnEndDragLine:=StartLineEndDragging;
  ChartTool1.EndLine.OnBeginDragLine:=EndLineBeginDragging;
  ChartTool1.EndLine.OnEndDragLine:=EndLineEndDragging;
end;

procedure TForm1.StartLineBeginDragging(Sender: TColorLineTool);
begin
  draggingStart:=true;
end;

procedure TForm1.StartLineEndDragging(Sender: TColorLineTool);
begin
  draggingStart:=false;
end;

procedure TForm1.EndLineBeginDragging(Sender: TColorLineTool);
begin
  draggingEnd:=true;
end;

procedure TForm1.EndLineEndDragging(Sender: TColorLineTool);
begin
  draggingEnd:=false;
end;

Re: TColorBandTool limits

Posted: Fri Jan 09, 2015 7:50 am
by 16570117
Hi,

thanks for fast response. Your solution helped me a lot. It's still not exactly what I was looking for but the idea and approach helped me to develop my solution.

Thank you again.
Aljosa

Re: TColorBandTool limits

Posted: Mon Jan 12, 2015 8:25 am
by yeray
Hi Aljosa,

I'm glad to hear it helped you! :)