{**********************************************}
{  TeeChart Pro - TTagCloudSeries              }
{  Copyright (c) 2011-2020 by Steema Software  }
{**********************************************}
unit TeeTagCloudEditor;
{$I TeeDefs.inc}

interface

uses
  {$IFNDEF LINUX}
  Windows,
  {$ENDIF}
  Classes, SysUtils,

  Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls, Menus, Grids,

  TeCanvas, TeeProcs, TeEngine, Chart, TeeGriEd, TeeSurfa, TeeChartGrid,
  TeePenDlg, TeeBrushDlg, TeeEdiGrad, TeeTagCloud;

type
  TTagCloudEditor = class(TForm)
    PageControl1: TPageControl;
    TabFont: TTabSheet;
    TabOptions: TTabSheet;
    Label1: TLabel;
    EFilter: TEdit;
    CBClip: TCheckBox;
    Label2: TLabel;
    ESep: TEdit;
    UDSep: TUpDown;
    TabSheet1: TTabSheet;
    Button2: TButton;
    ComboFlat1: TComboFlat;
    ComboFlat2: TComboFlat;
    TabBorder: TTabSheet;
    TabPattern: TTabSheet;
    Label3: TLabel;
    TBTransp: TTrackBar;
    procedure FormShow(Sender: TObject);
    procedure EFilterChange(Sender: TObject);
    procedure CBClipClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ESepChange(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure TBTranspChange(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }

    IGrid3D  : TGrid3DSeriesEditor;
    TagCloud : TTagCloudSeries;
  public
    { Public declarations }
  end;

implementation

{$IFNDEF LCL}
{$R *.DFM}
{$ELSE}
{$R *.lfm}
{$ENDIF}

uses
  Math, TeeEdiFont, TeeProCo;

// TTagCloudEditor

procedure TTagCloudEditor.FormShow(Sender: TObject);
begin
  TagCloud:=TTagCloudSeries(Tag);

  if Assigned(TagCloud) then
  begin
    if not Assigned(IGrid3D) then
       IGrid3D:=TeeInsertGrid3DForm(Self,TagCloud) as TGrid3DSeriesEditor;

    EFilter.Text:=TagCloud.Filter;

    if TagCloud.ParentChart<>nil then
       CBClip.Checked:=TagCloud.ParentChart.ClipPoints;
       
    UDSep.Position:=TagCloud.TagSeparation;

    TBTransp.Position:=TagCloud.Transparency;
  end;
end;

procedure TTagCloudEditor.EFilterChange(Sender: TObject);
begin
  TagCloud.Filter:=EFilter.Text;
end;

procedure TTagCloudEditor.CBClipClick(Sender: TObject);
begin
  TagCloud.ParentChart.ClipPoints:=CBClip.Checked;
end;

procedure TTagCloudEditor.FormCreate(Sender: TObject);
begin
  PageControl1.ActivePage:=TabOptions;
end;

procedure TTagCloudEditor.ESepChange(Sender: TObject);
begin
  if Showing then
     TagCloud.TagSeparation:=UDSep.Position;
end;

procedure TTagCloudEditor.Button2Click(Sender: TObject);
begin
  TagCloud.Sort(TTagCloudOrder(ComboFlat1.ItemIndex),
                TChartListOrder(1+ComboFlat2.ItemIndex));
end;

procedure TTagCloudEditor.PageControl1Change(Sender: TObject);
begin
  if (PageControl1.ActivePage=TabFont) and (TabFont.ControlCount=0) then
     InsertTeeFontEditor(TabFont).RefreshControls(TagCloud.Font)
  else
  if (PageControl1.ActivePage=TabBorder) and (TabBorder.ControlCount=0) then
     TPenDialog.InsertForm(TagCloud.Pen,TabBorder)
  else
  if (PageControl1.ActivePage=TabPattern) and (TabPattern.ControlCount=0) then
     TBrushDialog.AddDialog(TagCloud.Brush,TabPattern);
end;

procedure TTagCloudEditor.TBTranspChange(Sender: TObject);
begin
  if Showing then
     TagCloud.Transparency:=TBTransp.Position;
end;

procedure TTagCloudEditor.FormDestroy(Sender: TObject);
begin
  IGrid3D.Free;
end;

initialization
  RegisterClass(TTagCloudEditor);
end.
