{**********************************************}
{   TeeChart Tools Gallery Demos               }
{   Copyright (c) 2006-2020 by Steema Software }
{**********************************************}
unit TeeToolsGalleryDemos;
{$I TeeDefs.inc}

interface

uses
  Classes, SysUtils,

  {$IFDEF FMX}
  FMX.Types, 
  {$IFDEF D16}
  System.UIConsts,
  {$ENDIF}
  {$IFDEF D19}
  FMX.Graphics,
  {$ENDIF}
  
  {$ELSE}
  Controls, Graphics, StdCtrls, Buttons, Dialogs, Grids,
  {$ENDIF}

  {$IFDEF D16}
  System.UITypes,
  {$ENDIF}

  {$IFDEF FMX}
  FMXTee.Engine, FMXTee.Chart, FMXTee.Tools.Gallery, FMXTee.Animations.Tools,
  {$IFDEF D18}
  FMX.StdCtrls,
  {$ENDIF}
  FMX.Controls
  {$ELSE}
  TeEngine, Chart, TeeToolsGallery
  {$ENDIF};

const
  TeeMsg_Animate='&Animate !';
  TeeMsg_Stop='&Stop';

type
  {$IFDEF FMX}
  TBitBtn=TButton;
  TControlClass=class of TControl;
  {$ENDIF}

  TToolDemosBase=class {$IFDEF D11}abstract{$ENDIF} 
  private
    procedure ChartDblClick(Sender: TObject);
  protected
    Gallery : {$IFDEF FMX}TToolsGallery{$ELSE}TTeeToolsGallery{$ENDIF};

    function AddBitButton(const Chart:TCustomChart; const Element:TCustomChartElement;
                          const AText:String; AEvent:TNotifyEvent;
                          const AObject:TObject):TBitBtn;
    function AddButton(const Chart:TCustomChart;
                       const AText:String; AEvent:TNotifyEvent;
                       const AObject:TObject):TButton;
    function AddCheck(const Chart:TCustomChart;
                      const AText:String; AEvent:TNotifyEvent;
                      const AObject:TObject):TCheckBox;
    function AddControl(const AClass:TControlClass; const Chart:TCustomChart;
                        const AText:String;
                        const AObject:TObject):TControl;

    function CreateChart(const ATool:TTeeCustomToolClass;
                         const ATitle:String='';
                         const ASeries:TChartSeriesClass=nil):TChart;

    procedure CreateGallery; virtual; abstract;

    function NewChart(const ATitle:String='';
                      const ASeries:TChartSeriesClass=nil):TChart;

    function Prepare(AClass:TClass):TCustomChart; virtual;
  public
    Constructor Create(const AGallery:{$IFDEF FMX}TToolsGallery{$ELSE}TTeeToolsGallery{$ENDIF});
  end;

implementation

uses
  {$IFDEF D6}
  Types, Variants,
  {$ENDIF}

  Math,

  {$IFDEF FMX}
  FMX.Grid,
  
  FMXTee.Canvas, FMXTee.Procs, FMXTee.Constants, FMXTee.ProConstants,
  FMXTee.Series, FMXTee.Tools, FMXTee.Themes, FMXTee.Tools.Gantt,
  FMXTee.Series.Gantt, FMXTee.Tools.Pie, FMXTee.Editor.Brush,
  FMXTee.Tools.ExtraLegend, FMXTee.Tools.Surface, FMXTee.Series.Surface,
  FMXTee.Tools.DragPoint, FMXTee.Tools.SeriesStats, FMXTee.Tools.SeriesBand,
  FMXTee.Tools.Selector,
  FMXTee.Tools.Clustering,
  FMXTee.Tools.PageNumber,
  FMXTee.Tools.DataTable, FMXTee.Tools.Transpose,
  FMXTee.Tools.TransposeSeries,
  FMXTee.Tools.LegendScrollBar,
  //FMXTee.Tools.Frame,
  FMXTee.Tools.LegendPalette,
  FMXTee.Tools.SeriesRegion,
  FMXTee.Tools.Banner,
  //FMXTee.Tools.Text3D,
  FMXTee.Tools.CustomLegend,
  //FMXTee.Tools.Magnify, FMXTee.Tools.Fades,
  FMXTee.Tools.SubChart,
  FMXTee.Tools.Link,
  FMXTee.Tools.Fibonacci,
  FMXTee.Tools.Arrow,
  FMXTee.Tools.AxisBreaks,
  FMXTee.Tools.ScrollPager,
  FMXTee.Series.Candle

  {$ELSE}
  TeCanvas, TeeTools, TeeProcs, TeeClusteringTool, TeeAnimations, TeeAnimate,
  TeeScrollPagerTool, TeeConst, TeeProCo, Series,

  TeeThemes, TeeGanttTool, GanttCh, TeePieTool,
  TeeBrushDlg, TeeExtraLegendTool, TeeSurfaceTool, TeeSurfa, TeeDragPoint,
  TeeAntiAlias, TeeSeriesStats, TeeSeriesBandTool, TeeSelectorTool,
  TeeLighting, TeeIsoSurface, TeePageNumTool, TeeDataTableTool,
  TeeTransposeTool, TeeTransposeSeries, TeeLegendScrollBar, TeeFrameTool,
  TeeLegendPalette, TeeSeriesRegion, TeeBannerTool,

  {$IFDEF MSWINDOWS}
  TeeText3D,
  {$ENDIF}

  TeeCustomLegendTool,

  {$IFNDEF LCL}
  TeeVideo, TeeVideoPlayer,
  {$ENDIF}

  TeeMagnifyTool, TeeFaderTool, TeeSubChart, TeeLinkTool, TeeFibonacci,
  CandleCh, TeeArrowTool, TeeAxisBreaks
  {$ENDIF};

{$IFDEF FMX}
const
  clBlack=claBlack;
  clGreen=claGreen;
  clBlue=claBlue;
  clCream=claBlanchedalmond;
  clRed=claRed;
  clSilver=claSilver;
  clYellow=claYellow;
{$ENDIF}

type
  TToolDemos=class(TToolDemosBase)
  private
    procedure FullScreen(Sender:TObject);
    procedure OutlineChecked(Sender:TObject);

    {$IFNDEF FMX}
    procedure FadeChart(Sender:TObject);
    {$ENDIF}

    {$IFNDEF LCL}
    {$IFNDEF FMX}
    procedure PlayChartVideo(Sender:TObject);
    procedure RecordChartVideo(Sender:TObject);
    procedure StepAnimation(Sender:TSeriesAnimationTool; Step:Integer);
    procedure StopRecordVideo(Sender:TObject);
    {$ENDIF}
    {$ENDIF}

    procedure ComboColorChanged(Sender:TObject);
    procedure ComboSeriesChanged(Sender:TObject);
    procedure Transpose3DSeries(Sender:TObject);
    procedure TransposeSeries(Sender:TObject);
  protected
    procedure CreateGallery; override;
    function Prepare(AClass:TClass):TCustomChart; override;
  end;

  TControlAccess=class(TControl);

Constructor TToolDemosBase.Create(const AGallery:{$IFDEF FMX}TToolsGallery{$ELSE}TTeeToolsGallery{$ENDIF});
begin
  inherited Create;
  Gallery:=AGallery;
end;

function TToolDemosBase.CreateChart(const ATool:TTeeCustomToolClass;
                     const ATitle:String='';
                     const ASeries:TChartSeriesClass=nil):TChart;
begin
  result:=NewChart(ATitle,ASeries);

  if ATool<>nil then
     result.Tools.Add(ATool);
end;

function TToolDemosBase.NewChart(const ATitle:String='';
                     const ASeries:TChartSeriesClass=nil):TChart;
var c : TChart;
begin
  c:=TChart.Create(Gallery);
  c.Align:={$IFDEF FMX}TAlignLayout.{$IFDEF D20}Client{$ELSE}alClient{$ENDIF}{$ELSE}alClient{$ENDIF};

  if Gallery<>nil then
     c.Parent:=Gallery.PanelDemos;

  if ASeries=nil then
     c.AddSeries(TLineSeries).FillSampleValues
  else
     c.AddSeries(ASeries).FillSampleValues;

  c.Legend.Hide;
  c.Zoom.Allow:=False;
  c.AllowPanning:=pmNone;
  c.Title.Text.Text:=ATitle;

  with c.Title.Font.Shadow do
  begin
    Visible:=True;

    Size:=1;
    Color:={$IFDEF FMX}TAlphaColors.LtGray{$ELSE}clLtGray{$ENDIF};
    SmoothBlur:=2;
  end;

  ApplyChartTheme(TOperaTheme,c);

  // White background
  c.Gradient.StartColor:=clWhite;
  c.Gradient.EndColor:=clWhite;
  c.Color:=clWhite;

  c.Title.Font.Size:=12;

  c.Axes.Left.Grid.Color:={$IFDEF FMX}TTeeCanvas.ColorFrom($DDDDDD,255){$ELSE}$DDDDDD{$ENDIF};
  c.Axes.Bottom.Grid.Color:=c.Axes.Left.Grid.Color;

  c.OnDblClick:=ChartDblClick;

  result:=c;
end;

function TToolDemosBase.Prepare(AClass:TClass):TCustomChart;
begin
  result:=nil;
end;

function TToolDemosBase.AddControl(const AClass:TControlClass; const Chart:TCustomChart;
                                   const AText:String;
                                   const AObject:TObject):TControl;

  function CheckText:String;
  begin
    {$IFDEF FMX}
    result:=StringReplace(AText,'&','',[]);
    {$ELSE}
    result:=AText;
    {$ENDIF}
  end;

begin
  // Use Chart as owner in FMX (to avoid AV at chart destroy)
  result:=AClass.Create(Gallery);

  {$IFDEF FMX}
  result.Position.X:=20;
  result.Position.Y:=Chart.Height-50;
  {$ELSE}
  result.Left:=20;
  result.Top:=Chart.Height-50;
  {$ENDIF}

  result.Parent:=Chart;

  {$IFDEF FMX}
  if result is TButton then
     TButton(result).Text:=CheckText
  else
  if result is TCheckBox then
     TCheckBox(result).Text:=CheckText;

  {$ELSE}
  TControlAccess(result).Caption:=CheckText;
  {$ENDIF}

  result.Width:=Max(result.Width,6*Length(AText));

  result.Tag:=ObjectToTag(AObject);
end;

function TToolDemosBase.AddButton(const Chart:TCustomChart;
                                  const AText:String; AEvent:TNotifyEvent;
                                  const AObject:TObject):TButton;
begin
  result:=AddControl(TButton,Chart,AText,AObject) as TButton;
  result.OnClick:=AEvent;
end;

function TToolDemosBase.AddBitButton(const Chart:TCustomChart; const Element:TCustomChartElement;
                      const AText:String; AEvent:TNotifyEvent;
                      const AObject:TObject):TBitBtn;
var tmpBitmap : TBitmap;
begin
  result:=AddControl(TBitBtn,Chart,AText,AObject) as TBitBtn;
  result.OnClick:=AEvent;

  tmpBitmap:=TBitmap.Create{$IFNDEF D19}{$IFDEF FMX}(0,0){$ENDIF}{$ENDIF};
  try
    TeeGetBitmapEditor(Element,tmpBitmap);

    result.Width:=result.Width+tmpBitmap.Width+2;

    {$IFNDEF FMX}
    result.NumGlyphs:=1;
    result.Glyph:=tmpBitmap;
    {$ENDIF}
  finally
    tmpBitmap.Free;
  end;
end;

function TToolDemosBase.AddCheck(const Chart:TCustomChart;
                                 const AText:String; AEvent:TNotifyEvent;
                                 const AObject:TObject):TCheckBox;
begin
  result:=AddControl(TCheckBox,Chart,'',AObject) as TCheckBox;
  result.OnClick:=AEvent;
  result.Width:=16;

  if Assigned(Gallery) then
  with TLabel.Create(Gallery.PanelDemos) do
  begin
    {$IFDEF FMX}
    Text:=AText;
    {$ELSE}
    Transparent:=True;
    Caption:=AText;
    FocusControl:=result;
    {$ENDIF}

    Font.Style:=[{$IFDEF FMX}TFontStyle.{$ENDIF}fsBold];

    {$IFDEF FMX}
    Position.X:=result.Position.X+2;
    Position.Y:=result.Position.Y+2;
    {$ELSE}
    Left:=result.Left+2;
    Top:=result.Top+2;
    {$ENDIF}

    Parent:=result.Parent;
    AutoSize:=True;
  end;
end;

procedure TToolDemosBase.ChartDblClick(Sender: TObject);
begin
  // EditChartTool(nil,(Sender as TCustomChart).Tools[0]);
  // (Sender as TCustomChart).CancelMouse:=True;
end;

function RandomColor: TColor;
begin
  result:=RGBA(Random(255),Random(255),Random(255),{$IFDEF FMX}$FF{$ELSE}0{$ENDIF});
end;

{ TToolDemos }

function TToolDemos.Prepare(AClass:TClass):TCustomChart;
var
  tmpY : Double;
  tmpRange : Integer;

  function RandomColorLine(const ATool:TTeeCustomTool):TColorLineTool;
  begin
    result:=ATool as TColorLineTool;

    with result do
    begin
      Axis:=ParentChart.Axes.Left;
      Value:=tmpY+Random(tmpRange);
      Pen.Color:=RandomColor;
      Pen.Width:=2;
    end;
  end;

  procedure RandomColorBand(const ATool:TTeeCustomTool);
  begin
    with (ATool as TColorBandTool) do
    begin
      Axis:=ParentChart.Axes.Left;
      StartValue:=tmpY+Random(tmpRange);
      EndValue:=StartValue+Random(tmpRange);
      tmpY:=EndValue;
      Color:=RandomColor;
      ResizeEnd:=True;
      ResizeStart:=True;
    end;
  end;

  procedure ZoomAxis(const Axis:TChartAxis; const AStartPercent,ASizePercent:Single);
  var Range,
      Min, Max: Double;
  begin
    TAxisScrollBarTool.GetAxisLimits(Axis,Range,Min,Max);

    // Recalc Range based on Min Max limits
    Range:=Max-Min;

    Min:=Min+Range*AStartPercent*0.01;
    Axis.SetMinMax(Min,Min+Range*ASizePercent*0.01);
  end;

var tmpS : TStringList;
    c    : TChart;
    b    : TBannerTool;
    t    : Integer;
    tmpAxisArrow : TAxisArrowTool;
    tmp  : TTeeCustomToolClass;
begin
  tmp:=TTeeCustomToolClass(AClass);

  if tmp=TClipSeriesTool then
  begin
    c:=CreateChart(tmp,'Drag chart to scroll Series'+TeeLineSeparator+'that does not display outside axes');

    with c do
    begin
      View3D:=False;
      AllowPanning:=pmBoth;
      AllowZoom:=False;

      ScrollMouseButton:={$IFDEF FMX}TMouseButton.{$ENDIF}mbLeft;

      Axes.Left.StartPosition:=20;
      Axes.Left.EndPosition:=80;
      Axes.Bottom.StartPosition:=25;
      Axes.Bottom.EndPosition:=70;

      (Tools[0] as TClipSeriesTool).Series:=Series[0];
    end;
  end
  else
  if tmp=TCursorTool then
  begin
    c:=CreateChart(tmp,'Click and drag cursor lines');

    with c do
    with (Tools[0] as TCursorTool) do
    begin
      //ScopeStyle:=scsCamera;
      ScopeSize:=20;
      Style:=cssScope;
    end;
  end
  else
  if tmp=TAnnotationTool then
  begin
    c:=CreateChart(tmp);

    with c do
    begin
      (Tools[0] as TAnnotationTool).Text:='This is an Annotation tool';

      Tools.Add(tmp);

      with (Tools[1] as TAnnotationTool) do
      begin
        Text:='Another Annotation'+TeeLineSeparator+'multi-line';

        Left:=150;
        Top:=80;
        Shape.Font.Size:=18;
        Shape.Gradient.Visible:=True;
      end;
    end;
  end
  else
  if tmp=TRotateTool then
  begin
    c:=CreateChart(tmp,'Click and drag to rotate');

    with c do
    begin
      (Tools[0] as TRotateTool).Inertia:=75;

      View3DOptions.Orthogonal:=False;
      View3DOptions.Perspective:=100;
      Chart3DPercent:=75;
    end;

    AddCheck(c,TeeMsg_Outline,OutlineChecked,c.Tools[0]).{$IFDEF FMX}Position.X{$ELSE}Left{$ENDIF}:=4;

  end
  else
  if tmp=TDragMarksTool then
  begin
    c:=CreateChart(tmp,'Click Series Marks to drag');

    with c do
    begin
      Series[0].FillSampleValues(5);
      Series[0].Marks.Show;
      Series[0].Marks.Font.Size:=14;
      Series[0].Marks.Callout.Arrow.Color:=clBlack;
      (Tools[0] as TDragMarksTool).Series:=Series[0];

      Axes.Left.MinimumOffset:=20;
      Axes.Left.MaximumOffset:=20;
      Axes.Bottom.MinimumOffset:=20;
      Axes.Bottom.MaximumOffset:=20;
    end;
  end
  else
  if tmp=TDrawLineTool then
  begin
    c:=CreateChart(tmp,'Click and drag to draw lines');

    with c do
    begin
      with Series[0].MandatoryValueList do
           tmpY:=(MinValue+MaxValue)*0.5;

      with (Tools[0] as TDrawLineTool) do
           Selected:=Lines.AddLine(1.5,tmpY,2.8,tmpY-tmpY*0.25);
    end;
  end
  else
  if tmp=TChartImageTool then
  begin
    c:=CreateChart(tmp,TeeMsg_ChartImageDesc);

    with c do
    begin
      View3D:=False;
      Series[0].Color:=clGreen;
      Series[0].Pen.Width:=4;
      AllowPanning:=pmBoth;
      Zoom.Allow:=True;
      Zoom.Brush.Style:=bsSolid; // ??

      (Tools[0] as TChartImageTool).Series:=Series[0];

      Tools[0].Pen.Show;

      {$IFNDEF FMX}
      with TBrushDialog.Create(nil) do
      try
        (Tools[0] as TChartImageTool).Picture.Graphic:=ImageFire.Picture.Graphic;
      finally
        Free;
      end;
      {$ENDIF}
    end;
  end
  else
  if tmp=TNearestTool then
  begin
    c:=CreateChart(tmp,'Move the mouse over Series points');

    with c do
    begin
      Series[0].FillSampleValues(8);
      (Series[0] as TLineSeries).Pointer.Show;
      (Tools[0] as TNearestTool).Series:=Series[0];

      with (Series[0] as TLineSeries).Pointer.Shadow do
      begin
        Visible:=True;
        Color:=clDkGray;
        HorizSize:=8;
        VertSize:=4;
      end;

      with (Tools[0] as TNearestTool).Pen do
      begin
        Color:=clBlue;
        Width:=2;
      end;
    end;
  end
  else
  if tmp=TMarksTipTool then
  begin
    c:=CreateChart(tmp,'Move mouse over Series points to display hints');

    with c do
    begin
      Series[0].FillSampleValues(5);
      (Series[0] as TLineSeries).Pointer.Show;
      (Tools[0] as TMarksTipTool).Series:=Series[0];
      (Tools[0] as TMarksTipTool).MouseAction:=mtmMove;
      Series[0].Cursor:=crHandPoint;
      Axes.Bottom.MinimumOffset:=20;
      Axes.Bottom.MaximumOffset:=20;
    end;
  end
  else
  if tmp=TColorLineTool then
  begin
    c:=CreateChart(tmp,'Several Color lines displayed'+TeeLineSeparator+'at random positions');

    with c do
    begin
      tmpY:=Series[0].MandatoryValueList.MinValue;
      tmpRange:=Round(Series[0].MandatoryValueList.Range);

      RandomColorLine(Tools[0]).Annotation.Text:='Text';
      RandomColorLine(Tools.Add(tmp)).AnnotationValue:=True;
    end;
  end
  else
  if tmp=TColorBandTool then
  begin
    c:=CreateChart(tmp,'Color bands to fill axes background');

    with c do
    begin
      View3D:=False;

      tmpY:=Series[0].MandatoryValueList.MinValue;
      tmpRange:=Round(Series[0].MandatoryValueList.Range*0.2);

      RandomColorBand(Tools[0]);
      RandomColorBand(Tools.Add(tmp));
      RandomColorBand(Tools.Add(tmp));
    end;
  end
  else
  if tmp=TGridBandTool then
  begin
    c:=CreateChart(tmp,'Two bands fill axes grid lines space');

    with c do
    begin
      (Tools[0] as TGridBandTool).Axis:=Axes.Left;
      (Tools[0] as TGridBandTool).Band1.Color:=RandomColor;
      (Tools[0] as TGridBandTool).Band2.Color:=RandomColor;
    end;
  end
  else
  if tmp=TAxisArrowTool then
  begin
    c:=CreateChart(tmp,'Click axes arrow to scroll');

    with c do
    begin
      View3D:=False;

      tmpAxisArrow:=(Tools[0] as TAxisArrowTool);
      tmpAxisArrow.HeadWidth:=30;
      tmpAxisArrow.Length:=60;
      tmpAxisArrow.Axis:=Axes.Bottom;
      tmpAxisArrow.Brush.BackColor:=TTeeCanvas3D.ColorFrom($0000FF,128);
    end;
  end
  else
  if tmp=TAxisScrollTool then
  begin
    c:=CreateChart(tmp,'Drag axes to scroll');

    with c do
    begin
      View3D:=False;

      (Tools[0] as TAxisScrollTool).Axis:=Axes.Left;
      (Tools.Add(tmp) as TAxisScrollTool).Axis:=Axes.Bottom;

      // 25% <--> 75%  (75=25+50)
      ZoomAxis(Axes.Left,25,50);
      ZoomAxis(Axes.Bottom,25,50);
    end;
  end
  else
  if tmp=TAxisScrollBarTool then
  begin
    c:=CreateChart(tmp,'Drag scrollbar to scroll axes');

    with c do
    begin
      View3D:=False;

      c.AddSeries(TLineSeries);
      c.SeriesList.FillSampleValues(500);

      (Tools[0] as TAxisScrollBarTool).Axis:=Axes.Left;
      (Tools.Add(tmp) as TAxisScrollBarTool).Axis:=Axes.Bottom;

      // 25% <--> 75%  (75=25+50)
      ZoomAxis(Axes.Left,25,50);
      ZoomAxis(Axes.Bottom,25,50);
    end;
  end
  else
  if tmp=TRectangleTool then
  begin
    c:=CreateChart(tmp,'Annotations that can be'+TeeLineSeparator+'dragged and resized');

    with c.Tools[0] as TRectangleTool do
    begin
      AutoSize:=True;
      Text:='Drag and'+TeeLineSeparator+'resize me ';
      Shape.Color:=clRed;
      Shape.Font.Size:=16;
      Shape.Transparency:=30;
      Left:=80;
      Top:=90;
    end;
  end
  else
  if tmp=TSurfaceNearestTool then
  begin
    c:=CreateChart(tmp,'Move mouse over Surface to highlight cells',TSurfaceSeries);

    with c do
    begin
      View3DOptions.Orthogonal:=False;
      View3DOptions.Perspective:=100;
      Chart3DPercent:=75;
      View3DOptions.Zoom:=75;

      (Series[0] as TSurfaceSeries).HideCells:=True;

      Series[0].FillSampleValues(20);
      (Tools[0] as TSurfaceNearestTool).Series:=Series[0];

      tmp:=TRotateTool;
      Tools.Add(tmp);

      Walls.Left.Hide;
      Walls.Back.Hide;
    end;
  end
  else
  if tmp=TDragPointTool then
  begin
    c:=CreateChart(tmp,'Click and drag Series points',TPointSeries);

    with c do
    begin
      Series[0].FillSampleValues(10);
      Series[0].ColorEachPoint:=True;
      Series[0].Cursor:=crHandPoint;
      (Tools[0] as TDragPointTool).Series:=Series[0];

      with (Series[0] as TPointSeries).Pointer.Shadow do
      begin
        Visible:=True;
        Size:=6;
      end;
    end;

  end
  else
  if tmp=TExtraLegendTool then
  begin
    c:=CreateChart(tmp,'Show additional Legend panels',TBarSeries);

    with c do
    begin
      AddSeries(TBarSeries).FillSampleValues;
      Legend.Show;
      Legend.Title.Caption:=TeeMsg_Legend;

      (Tools[0] as TExtraLegendTool).Series:=Series[1];
      (Tools[0] as TExtraLegendTool).Legend.Title.Caption:='Extra Legend';
      (Tools[0] as TExtraLegendTool).Legend.Left:={$IFDEF FMX}Round{$ENDIF}(Width-100);
      (Tools[0] as TExtraLegendTool).Legend.Top:=100;
    end;
  end
  else
  if tmp=TGanttTool then
  begin
    c:=CreateChart(tmp,'Click Gantt bars to drag and resize',TGanttSeries);

    with c do
    begin
      View3D:=False;
      Series[0].FillSampleValues(10);

      with (Series[0] as TGanttSeries).Pointer do
      begin
       VertSize:=10;
       Shadow.Visible:=True;
      end;

      (Tools[0] as TGanttTool).Series:=Series[0];
    end;
  end
  else
  if tmp=TPieTool then
  begin
    c:=CreateChart(tmp,'Move mouse over Pie slices',TPieSeries);

    with c do
    begin
      Chart3DPercent:=70;

      (Tools[0] as TPieTool).Series:=Series[0];

      Series[0].Pen.Color:=clDkGray;
      Series[0].Pen.Width:=3;

      with (Series[0] as TPieSeries).Shadow do
      begin
        Size:=20;
        Visible:=True;
      end;

      //tmp:=TAntiAliasTool;
      //Tools.Add(tmp);
    end;
  end
  else
  if tmp=TSeriesStatsTool then
  begin
    c:=CreateChart(tmp,'Statistics of Series data');

    with c do
    begin
      (Tools[0] as TSeriesStatsTool).Series:=Series[0];

      tmp:=TAnnotationTool;
      Tools.Add(tmp);
      (Tools[1] as TAnnotationTool).Shape.Transparency:=10;
      (Tools[1] as TAnnotationTool).Left:=80;
      (Tools[1] as TAnnotationTool).Top:=30;

      tmpS:=TStringList.Create;
      try
        (Tools[0] as TSeriesStatsTool).Statistics(tmpS);
        (Tools[1] as TAnnotationTool).Text:=tmpS.Text;
      finally
        tmpS.Free;
      end;
    end;
  end
  else
  if tmp=TSeriesBandTool then
  begin
    c:=CreateChart(tmp,'Fill the region between two Series');

    with c do
    begin
      View3D:=False;
      Series[0].FillSampleValues(10);
      AddSeries(TLineSeries).FillSampleValues(10);
      (Tools[0] as TSeriesBandTool).Series:=Series[0];

      Series[0].Pen.Width:=3;
      Series[1].Pen.Width:=3;

      with Series[0].MandatoryValueList do
           tmpY:=(MaxValue+MinValue)*0.5;

      (Tools[0] as TSeriesBandTool).BoundValue:=tmpY;

      (Tools[0] as TSeriesBandTool).Series2:=Series[1];
      (Tools[0] as TSeriesBandTool).Gradient.Visible:=True;
      (Tools[0] as TSeriesBandTool).Gradient.StartColor:=clSilver;
      (Tools[0] as TSeriesBandTool).Pen.Show;
    end;
  end
  else
  {$IFNDEF FMX}
  if tmp=TAntiAliasTool then
  begin
    c:=CreateChart(tmp,'Smooth line edges', TAreaSeries);

    with c do
    begin
      Series[0].Color:=clFuchsia;
      (Series[0] as TAreaSeries).AreaLinesPen.Hide;
    end;
  end
  else
  {$ENDIF}
  if tmp=TSelectorTool then
  begin
    c:=CreateChart(tmp,'Click to select Chart items', TBarSeries);

    with c do
    begin
      Legend.Show;
      Series[0].FillSampleValues(4);
      AddSeries(TBarSeries).FillSampleValues(4);

      tmp:=TAnnotationTool;
      Tools.Add(tmp);
      with (Tools[1] as TAnnotationTool) do
      begin
        Text:='Click me';
        Position:=ppLeftBottom;
      end;

      Title.Transparent:=False;
      Foot.Caption:='Footer text';
      Foot.Transparent:=False;

      (Tools[0] as TSelectorTool).Part.Part:=cpLegend;
    end;
  end
  else
  {$IFNDEF FMX}
  if tmp=TLightTool then
  begin
    c:=CreateChart(tmp,'2D Lighting', TIsoSurfaceSeries);

    with c do
    begin
      View3DOptions.Orthogonal:=False;
      View3DOptions.Perspective:=100;
      Chart3DPercent:=75;
      View3DOptions.Zoom:=75;

      (Tools[0] as TLightTool).FollowMouse:=True;
      (Tools[0] as TLightTool).Style:=lsSpotLight;

      tmp:=TRotateTool;
      Tools.Add(tmp);
    end;
  end
  else
  {$ENDIF}
  if tmp=TPageNumTool then
  begin
    c:=CreateChart(tmp,'Shows Page numbering', TBarSeries);

    with c do
    begin
      Series[0].FillSampleValues(25);
      Pages.MaxPointsPerPage:=5;
      (Tools[0] as TPageNumTool).ShowButtons:=True;
    end;
  end
  else
  if tmp=TDataTableTool then
  begin
    c:=CreateChart(tmp,'Displays a grid with Series data', TBarSeries);

    with c do
    begin
      Series[0].FillSampleValues(4);
      AddSeries(TBarSeries).FillSampleValues(4);

      Series[0].ValueFormat:='#.00';
      Series[1].ValueFormat:=Series[0].ValueFormat;

      (Tools[0] as TDataTableTool).Brush.Color:=clCream;  // Brush not used
    end;
  end
  else
  if tmp=TGridTransposeTool then
  begin
    c:=CreateChart(tmp,'Swaps 3D Series data, rows by columns', TSurfaceSeries);

    with c do
    begin
      (Series[0] as TSurfaceSeries).HideCells:=True;

      (Tools[0] as TGridTransposeTool).Series:=(Series[0] as TCustom3DGridSeries);

      View3DOptions.Orthogonal:=False;
      View3DOptions.Perspective:=100;
      Chart3DPercent:=75;
      View3DOptions.Zoom:=75;

      Axes.Depth.Visible:=True;

      tmp:=TRotateTool;
      Tools.Add(tmp);
    end;

    AddButton(c,'&Transpose !',Transpose3DSeries,c.Tools[0]);
  end
  else
  if tmp=TLegendScrollBar then
  begin
    c:=CreateChart(tmp,'Displays scrollbar at Legend');

    with c do
    begin
      Series[0].FillSampleValues(50);
      Legend.Show;
      (Tools[0] as TLegendScrollBar).Gradient.Visible:=True;

      with (Tools[0] as TLegendScrollBar).Thumb.Gradient do
      begin
        Visible:=True;
        StartColor:=clRed;
        EndColor:=clGreen;
      end;
    end;
  end
  else
  {$IFNDEF FMX}
  if tmp=TFrameTool then
  begin
    c:=CreateChart(tmp,'Displays a frame around Chart');

    with c do
    begin
      (Tools[0] as TFrameTool).ResizeChart:=True;
      (Tools[0] as TFrameTool).Size:=30;
    end;
  end
  else
  {$ENDIF}
  if tmp=TLegendPaletteTool then
  begin
    c:=CreateChart(tmp,'Displays legend of Series color palettes',TIsoSurfaceSeries);

    with c do
    begin
      View3DOptions.Orthogonal:=False;
      View3DOptions.Perspective:=100;
      Chart3DPercent:=75;
      View3DOptions.Zoom:=75;
      MarginLeft:=20;

      with (Series[0] as TIsoSurfaceSeries) do
      begin
        HideCells:=True;
        PaletteStyle:=psRainbow;
      end;

      Series[0].FillSampleValues(20);

      (Tools[0] as TLegendPaletteTool).Chart.Color:=Color;

      with (Tools[0] as TLegendPaletteTool) do
      begin
        Series:=SeriesList[0];
        Top:=100;
        Smooth:=True;
        Chart.Gradient.Visible:=True;

        Chart.Shadow.Size:=5;
        Chart.Shadow.Visible:=True;

        with Chart.Axes do
        begin
          Left.PositionPercent:=-2;
          Left.PositionUnits:=muPixels;
          Right.PositionPercent:=-2;
          Right.PositionUnits:=muPixels;
        end;
      end;
    end;
  end
  else
  if tmp=TSeriesRegionTool then
  begin
    c:=CreateChart(tmp,'Fills region between Series and value');

    with c do
    with (Tools[0] as TSeriesRegionTool) do
    begin
      Series:=SeriesList[0];

      with Series.MandatoryValueList do
           tmpY:=(MinValue+MaxValue)*0.5;

      Origin:=tmpY;
      LowerBound:=Series.NotMandatoryValueList.MinValue;
      UpperBound:=Series.NotMandatoryValueList.MaxValue;
      Gradient.Visible:=True;
      Pen.Color:={$IFDEF FMX}claNavy{$ELSE}clNavy{$ENDIF};
      Pen.Show;
    end;
  end
  else
  if tmp=TTransposeSeriesTool then
  begin
    c:=CreateChart(tmp,'Swaps rows by columns',TBarSeries);

    c.Chart3DPercent:=75;

    c.AddSeries(TBarSeries).FillSampleValues;

    (c[0] as TBarSeries).MultiBar:=mbNone;

    AddButton(c,'&Transpose !',TransposeSeries,c.Tools[0]);
  end
  else
  if tmp=TBannerTool then
  begin
    c:=CreateChart(tmp,'Text scrolling and blinking');

    with c do
    begin
      Series[0].Color:=clSilver;

      (Tools[0] as TBannerTool).Text:='Scrolling text';

      b:=TBannerTool.Create(Owner);
      b.Text:='Blinking Text';
      b.Blink:=True;
      b.Scroll:=False;
      b.BlinkDelayOff:=300;
      b.Position:=ppLeftBottom;
      b.ParentChart:=c;
    end;
  end
  else
  if tmp=TFullScreenTool then
  begin
    c:=CreateChart(tmp,'Maximizes a Chart to full desktop size');
    AddButton(c,'&Full Screen !',FullScreen,c.Tools[0]);
  end
  else
  {$IFNDEF FMX}
  {$IFDEF MSWINDOWS}
  if tmp=TText3DTool then
  begin
    c:=CreateChart(tmp,'Adds 3D text annotations');

    with c do
    begin
      with (Tools[0] as TText3DTool) do
      begin
        Text:='Text with 3D Font';
        Font.OutLine.Color:=clLime;
        Font.Style:=[{$IFDEF FMX}TFontStyle.{$ENDIF}fsBold];
        Font.Size:=36;
      end;

      tmp:=TRotateTool;
      Tools.Add(tmp);
      (Tools[1] as TRotateTool).Inertia:=75;

      Panning.MouseWheel:=pmwNone;
      Zoom.MouseWheel:=pmwNone;
      ZoomWheel:=pmwNormal;

      View3DOptions.Orthogonal:=False;
      View3DOptions.Perspective:=100;
      Chart3DPercent:=75;
      View3DOptions.Zoom:=75;
    end;
  end
  else
  if tmp=TMagnifyTool then
  begin
    c:=CreateChart(tmp,'Magnify a Chart portion under the mouse');

    with c do
    begin
      (Tools[0] as TMagnifyTool).Width:=100;
      (Tools[0] as TMagnifyTool).Height:=100;
      //(Tools[0] as TMagnifyTool).FollowMouse:=True;
    end;
  end
  else
  if tmp=TFaderTool then
  begin
    c:=CreateChart(tmp,'Fade in/out a Chart');

    with (c.Tools[0] as TFaderTool) do
    begin
      if c.Shadow.Visible and Assigned(c.Parent) then
         Color:=TControlAccess(c.Parent).Color
      else
         Color:=c.Color;

      Speed:=2;
      InitialDelay:=750;
    end;

    AddButton(c,'&Fade !',FadeChart,c.Tools[0]);
  end
  else
  {$ENDIF}
  {$ENDIF}
  if tmp=TSubChartTool then
  begin
    c:=CreateChart(tmp,'Multiple Charts inside a Chart');

    with c do
    begin
      Series[0].Clear;
      Axes.Left.Grid.Hide;
      Walls.Visible:=False;

      with Tools[0] as TSubChartTool do
      begin
        with Charts.AddChart do
        begin
          AddSeries(TLineSeries).FillSampleValues;
        end;

        with Charts.AddChart do
        begin
          {$IFDEF FMX}
          Position.X:=200;
          {$ELSE}
          Left:=200;
          {$ENDIF}

          AddSeries(TBarSeries).FillSampleValues;
          Series[0].Color:=clGreen;
        end;

        with Charts.AddChart do
        begin
          {$IFDEF FMX}
          Position.Y:=150;
          {$ELSE}
          Top:=150;
          {$ENDIF}

          AddSeries(TPieSeries).FillSampleValues;
          Series[0].Marks.Hide;
        end;

        with Charts.AddChart do
        begin
          {$IFDEF FMX}
          Position.X:=200;
          Position.Y:=150;
          {$ELSE}
          Left:=200;
          Top:=150;
          {$ENDIF}

          AddSeries(TAreaSeries).FillSampleValues;
          Series[0].Color:=clBlue;
        end;
      end;
    end;
  end
  else

  {$IFNDEF LCL}
  {$IFNDEF FMX}

  if tmp=TVideoTool then
  begin
    c:=CreateChart(tmp,'Create AVI Video with Chart images',TPieSeries);
    (c[0] as TPieSeries).Circled:=True;
    c.Chart3DPercent:=60;

    ColorPalettes.ApplyPalette(c,MacOSPalette);

    tmp:=TSeriesAnimationTool; // <-- Workaround of a D11 dcc32 bug

    with (c.Animations.Add(tmp) as TSeriesAnimationTool) do
    begin
      Series:=c[0];
    end;

    AddBitButton(c,c.Tools[0],TeeMsg_RecordVideo,RecordChartVideo,c.Tools[0]);
  end
  else
  if tmp=TVideoPlayerTool then
  begin
    c:=CreateChart(tmp,'Play AVI videos inside Chart regions');

    tmp:=TRectangleTool;  // <-- Workaround of a D11 dcc32 bug
    c.Tools.Add(tmp);

    with c.Tools[1] as TRectangleTool do
    begin
      AutoSize:=False;
      Shape.Transparency:=10;
      Left:=80;
      Top:=50;
      Width:=120;
      Height:=120;

      (c.Tools[0] as TVideoPlayerTool).Picture:=Shape.Picture;
      (c.Tools[0] as TVideoPlayerTool).Loop:=True;
    end;

    AddBitButton(c,c.Tools[0],TeeMsg_Play,PlayChartVideo,c.Tools[0]);

    tmp:=TRotateTool;
    c.Tools.Add(tmp);
  end
  else
  {$ENDIF}
  {$ENDIF}

  if tmp=TLinkTool then
  begin
    c:=CreateChart(tmp,'Clickable links to navigate to'+TeeLineSeparator+
                         'Internet URLs or local files');

    with c do
    begin
      with TLinkTool(Tools[0]) do
      begin
        Position:=ppCenter;
        URL:='http://www.steema.com';
        Hint:='Visit our web site !';
        Text:='www.Steema.com';
        Shape.Font.Style:=[{$IFDEF FMX}TFontStyle.{$ENDIF}fsBold,
                           {$IFDEF FMX}TFontStyle.{$ENDIF}fsUnderline];
      end;
    end;
  end
  else
  if tmp=TFibonacciTool then
  begin
    c:=CreateChart(tmp,'Fibonnaci financial arcs or fans',TCandleSeries);

    with c do
    with TFibonacciTool(Tools[0]) do
    begin
      Series:=ParentChart.Series[0];
      StartX:=(Series.XValues.Last+Series.XValues.First)*0.5;
      EndX:=StartX+((Series.XValues.Last-Series.XValues.First)*0.3);

      StartY:=(Series.YValues.Last+Series.YValues.First)*0.5;
      EndY:=StartY+((Series.YValues.Last-Series.YValues.First)*0.3);

      Levels[Levels.Count-1].Pen.Color:={$IFDEF FMX}claLime{$ELSE}clLime{$ENDIF};

      LabelsFont.Style:=[{$IFDEF FMX}TFontStyle.{$ENDIF}fsBold];
      LabelsFont.Name:='Verdana';
    end;
  end
  else
  if tmp=TArrowTool then
  begin
    c:=CreateChart(tmp,'Draw Arrows in 2D and 3D');

    with c do
    begin
      with Tools[0] as TArrowTool do
      begin
        FromPoint.Point:=TeePoint(100,100);
        ToPoint.Point:=TeePoint(300,200);
        Gradient.Visible:=True;
        Gradient.EndColor:=clBlue;
      end;

      with Tools.Add(TArrowTool) as TArrowTool do
      begin
        FromPoint.Point:=TeePoint(50,300);
        ToPoint.Point:=TeePoint(200,150);
        Gradient.Visible:=True;
        Gradient.EndColor:=clRed;
      end;

      Tools.Add(TRotateTool);
    end;
  end
  else
  if tmp=TAxisBreaksTool then
  begin
    c:=CreateChart(tmp,'Draws breaks in the axes');

    with c do
    begin
      View3D:=False;

      with Tools[0] as TAxisBreaksTool do
      begin
        Axis := Axes.Bottom;
        Pen.Width:=1;
        Pen.Color := clBlack;
        Brush.Gradient.EndColor := {$IFDEF FMX}claDarkgray{$ELSE}clGrayText{$ENDIF};
        Brush.Gradient.Visible := true;
        GapSize := 100;

        Breaks.Add(5, 20);
        Breaks[0].AxisBreakStyle:=tabSmallZigZag;
      end;
    end;
  end
  else
  if tmp=TCustomLegendTool then
  begin
    c:=CreateChart(tmp,'Customizable legend grid',TBarSeries);

    with c do
    begin
      with Tools[0] as TCustomLegendTool do
      begin
        with Shape do
        begin
          RoundSize := 15;
          Pen.Width:= 2;
          Font.Style := [{$IFDEF FMX}TFontStyle.{$ENDIF}fsItalic];
          ShapeStyle:=fosRoundRectangle
        end;

        with Grid do
        begin
          RowCount := 2;
          
          {$IFNDEF FMX}
          ColCount := 1;
          RowHeights[0] := 20;
          RowHeights[1] := 20;
          ColWidths[0] := 70;
          {$ENDIF}

          Height := 40;
          Width := 70;

          {$IFDEF FMX}
          if ColumnCount=0 then
             TStringColumn.Create(Grid).Parent:=Grid;

          Cells[0,0]:='  Series 1';
          Cells[0,1]:='  Series 2';
          {$ELSE}
          Rows[0].Text := '  Series 1';
          Rows[1].Text := '  Series 2';
          {$ENDIF}
        end;
      end;
    end;
  end
  else
  if tmp=TClusteringTool then
  begin
    c:=CreateChart(tmp,'Points grouped into clusters',TPointSeries);

    with c do
    begin
      SeriesList[0].Clear;
      for t:=0 to 99 do
          SeriesList[0].AddXY(Random(1000),Random(1000));

      (SeriesList[0] as TPointSeries).Pointer.Draw3D:=False;

      with Tools[0] as TClusteringTool do
      begin
        Transparency:=50;
        Centers.Show;
        Centroids.Show;

        Series:=SeriesList[0];
        ShowBounds:=True;
        Execute;
      end;
    end;
  end
  else
  if tmp=TScrollPagerTool then
  begin
    c:=CreateChart(tmp,'Showing portion of total Series',TFastLineSeries);

    with c do
    begin
      SeriesList[0].FillSampleValues(1000);
      (Tools[0] as TScrollPagerTool).Series:=SeriesList[0];
    end;
  end
  else
  if tmp=TRepaintMonitor then
  begin
    c:=CreateChart(tmp,'Chart repaint counter',TBarSeries);
    c[0].FillSampleValues(5);

    with TSeriesAnimationTool.Create(c) do
    begin
      ParentChart:=c;
      Animate.Loop:=True;
      Animate.Play;
    end;
  end
  else
  if tmp=TTeeCombo then
  begin
    c:=CreateChart(tmp,'Combobox',TBarSeries);
    c[0].FillSampleValues(5);

    with c.Tools[0] as TTeeCombo do
    begin
      Items.Add('Red');
      Items.Add('Blue');
      Items.Add('Green');
      Items.Add('Yellow');

      OnChange:=ComboColorChanged;
      ItemIndex:=0;
    end;

    with c.Tools.Add(TTeeCombo) as TTeeCombo do
    begin
      Items.Add(TeeMsg_GalleryBar);
      Items.Add(TeeMsg_GalleryLine);
      Items.Add(TeeMsg_GalleryHorizBar);
      Items.Add(TeeMsg_GalleryArea);

      OnChange:=ComboSeriesChanged;
      ItemIndex:=0;

      Left:=100;
      Top:=10;
    end;
  end
  else
    c:=CreateChart(tmp,'',TFastLineSeries);

  result:=c;
end;

procedure TToolDemos.CreateGallery;
var tmp : TTeeCustomToolClass;
begin
  if Assigned(Gallery) then
     tmp:=Gallery.SelectedTool
  else
     tmp:=nil;

  Prepare(tmp);
end;

procedure TToolDemos.FullScreen(Sender:TObject);
var tmp : TFullScreenTool;
begin
  tmp:=TFullScreenTool((Sender as TButton).Tag);
  tmp.Active:=True;
  (tmp.ParentChart as TCustomChart).Title.Caption:='Press ESC key or Alt + F4 to reset';

  {$IFDEF FMX}
  TControl(tmp.ParentChart.Children[0]).Visible:=False;
  {$ELSE}
  tmp.ParentChart.Controls[0].Hide;
  {$ENDIF}
end;

procedure TToolDemos.OutlineChecked(Sender:TObject);
begin
  TRotateTool((Sender as TCheckBox).Tag).Pen.Visible:=(Sender as TCheckBox).{$IFDEF FMX}IsChecked{$ELSE}Checked{$ENDIF};
end;

{$IFNDEF FMX}
procedure TToolDemos.FadeChart(Sender:TObject);
begin
  TFaderTool((Sender as TButton).Tag).Start;
end;
{$ENDIF}

{$IFNDEF LCL}
{$IFNDEF FMX}

procedure TToolDemos.StepAnimation(Sender:TSeriesAnimationTool; Step:Integer);
begin
  with Sender.Series as TPieSeries do
       RotationAngle:=RotationAngle+5;
end;

procedure TToolDemos.StopRecordVideo(Sender:TObject);
var a : TSeriesAnimationTool;
begin
  a:=TSeriesAnimationTool(Sender);
 // a.Stop;
  TVideoTool(a.Tag).StopRecording;
  TButton(TVideoTool(a.Tag).Tag).Caption:=TeeMsg_RecordVideo;
end;

procedure TToolDemos.RecordChartVideo(Sender:TObject);
var b       : TButton;
    tmpName : String;
    v       : TVideoTool;
    a       : TSeriesAnimationTool;
begin
  b:=Sender as TButton;
  v:=TVideoTool(b.Tag);
  a:=TSeriesAnimationTool(v.ParentChart.Animations[0]);
  a.Tag:=ObjectToTag(v);
  v.Tag:=ObjectToTag(b);

  if b.Caption=TeeMsg_Stop then
  begin
    StopRecordVideo(a);
  end
  else
  begin
    tmpName:='';

    with TSaveDialog.Create(nil) do
    try
      Filter:='Avi Video files (*.avi)|*.avi';
      DefaultExt:='avi';

      if Execute then
         tmpName:=FileName;
    finally
      Free;
    end;

    if tmpName<>'' then
    begin
      b.Caption:=TeeMsg_Stop;
      v.StartRecording(tmpName);
      a.OnStep:=StepAnimation;
      a.OnStop:=StopRecordVideo;
      a.Execute;
    end;
  end;
end;

procedure TToolDemos.PlayChartVideo(Sender:TObject);
var tmpName : String;
begin
  tmpName:='';

  with TOpenDialog.Create(nil) do
  try
    Filter:='Avi Video files (*.avi)|*.avi';
    DefaultExt:='avi';

    if Execute then
       tmpName:=FileName;
  finally
    Free;
  end;

  if tmpName<>'' then
  begin
    (Sender as TButton).Enabled:=False;

    with TVideoPlayerTool((Sender as TButton).Tag) do
    begin
      FileName:=tmpName;
      Play;
    end;
  end;
end;
{$ENDIF}
{$ENDIF}

procedure TToolDemos.ComboColorChanged(Sender:TObject);
var c : TTeeCombo;
    tmpColor : TColor;
begin
  c:=TTeeCombo(Sender);

  case c.ItemIndex of
    0: tmpColor:=clRed;
    1: tmpColor:=clBlue;
    2: tmpColor:=clGreen;
  else
    tmpColor:=clYellow;
  end;

  c.ParentChart[0].Color:=tmpColor;
end;

procedure TToolDemos.ComboSeriesChanged(Sender:TObject);
var c : TTeeCombo;
    tmp : TCustomChart;
begin
  c:=TTeeCombo(Sender);
  tmp:=c.ParentChart as TCustomChart;

  case c.ItemIndex of
    0: ChangeAllSeriesType(tmp,TBarSeries);
    1: ChangeAllSeriesType(tmp,TLineSeries);
    2: ChangeAllSeriesType(tmp,THorizBarSeries);
  else
    ChangeAllSeriesType(tmp,TAreaSeries);
  end;
end;

procedure TToolDemos.Transpose3DSeries(Sender:TObject);
begin
  TGridTransposeTool((Sender as TButton).Tag).Transpose;
end;

procedure TToolDemos.TransposeSeries(Sender:TObject);
begin
  TTransposeSeriesTool((Sender as TButton).Tag).Transpose;
end;

function GalleryHook(const Gallery:{$IFDEF FMX}TToolsGallery{$ELSE}TTeeToolsGallery{$ENDIF}):TObject;
begin
  result:=TToolDemos.Create(Gallery);
  TToolDemos(result).CreateGallery;
end;

initialization
  ToolsGalleryHook:=GalleryHook;
finalization
  ToolsGalleryHook:=nil;
end.
