Adding a TColorBandTool, resizing immediately

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Test Always
Newbie
Newbie
Posts: 14
Joined: Mon Jan 18, 2016 12:00 am

Adding a TColorBandTool, resizing immediately

Post by Test Always » Mon Sep 19, 2016 11:13 pm

I am adding a band to a chart as soon as the user clicks on the chart--and I want to start resizing the band as soon as it is added. Can that be done?

Thanks
Ed Dressel

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Adding a TColorBandTool, resizing immediately

Post by Yeray » Tue Sep 20, 2016 8:01 am

Hello Ed,

Yes, you can use the mouse events to do so.
I'm not sure how do you want to determine what TColorLineTool (StartLine/EndLine) should be dragged (note dragging one of the two TColorLineTools in the TColorBandTool is a TColorBandTool resizing) when you just created the tool.
Here you have an example that creates the TColorBandTool and starts dragging it at OnMouseDown event:

Code: Select all

uses Series, TeeTools;

type TMyColorBandTool=class(TColorBandTool)
  private
    Dragging : Boolean;
    Old      : Double;
end;

var myColorBand: TMyColorBandTool;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=false;

  Chart1.AddSeries(TBarSeries).FillSampleValues();
end;

procedure TForm1.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if not Assigned(myColorBand) then
  begin
    myColorBand:=Chart1.Tools.Add(TMyColorBandTool) as TMyColorBandTool;

    with myColorBand do
    begin
      Axis:=Chart1.Axes.Bottom;
      StartValue:=2;
      EndValue:=4;

      if not ParentChart.CancelMouse then
      begin
        Dragging:=True;

        if Axis.Horizontal then
           Old:=Axis.CalcPosPoint(X)-StartValue
        else
           Old:=Axis.CalcPosPoint(Y)-StartValue;

        ParentChart.CancelMouse:=True;
      end;
    end;
  end;
end;

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var tmpValue,
    tmpStartValue,
    tmpDiff  : Double;
begin
  if Assigned(myColorBand) and myColorBand.Dragging then
  begin
    with myColorBand do
    begin
      tmpDiff:=EndValue-StartValue;

      if Axis.Horizontal then
         tmpValue:=Axis.CalcPosPoint(X)-Old
      else
         tmpValue:=Axis.CalcPosPoint(Y)-Old;

      if NoLimitDrag then
         tmpStartValue:=tmpValue
      else
         tmpStartValue:=StartLine.LimitValue(tmpValue);

      tmpValue:=EndLine.LimitValue(tmpStartValue+tmpDiff);

      if (not NoLimitDrag) and (tmpValue<(tmpStartValue+tmpDiff)) then
         StartValue:=tmpValue-tmpDiff
      else
         StartValue:=tmpStartValue;

      EndValue:=StartValue+tmpDiff;
    end;
  end;
end;

procedure TForm1.Chart1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if Assigned(myColorBand) then
     myColorBand.Dragging:=False;
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply