{**********************************************}
{   TTreeMapSeries TreeMap Charts              }
{   Copyright (c) 2009-2020 by Steema Software }
{**********************************************}
unit TeeTreeMapSeriesEditor;
{$I TeeDefs.inc}

interface

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

  StdCtrls, Controls, Buttons, ExtCtrls, ComCtrls, Forms, Graphics,

  TeCanvas, TeEngine, Chart, TeeTools, TeeConst, TeePenDlg, TeeComma, TeeProcs,
  TeeCustomShapeEditor, TeeStringsEditor, TeeMargins, TeeOrgSeries,
  TeeOrgSeriesEditor, TeeSurfa, TeeGriEd, TeeTreeMapSeries;

type
  TTreeMapSeriesEditor = class(TOrgSeriesEditor)
    Options: TTabSheet;
    Panel1: TPanel;
    LTiling: TLabel;
    LTextAlign: TLabel;
    CBTilingStyle: TComboFlat;
    ComboFlat2: TComboFlat;
    CBoxColorEach: TCheckBox;
    Label6: TLabel;
    CBColorStyle: TComboFlat;
    Label7: TLabel;
    EValue: TEdit;
    TabPalette: TTabSheet;
    procedure FormShow(Sender: TObject);
    procedure CBTilingStyleChange(Sender: TObject);
    procedure CBoxColorEachClick(Sender: TObject);
    procedure ComboFlat2Change(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure CBColorStyleChange(Sender: TObject);
    procedure EValueChange(Sender: TObject);
  private
    { Private declarations }
    I3DEditor : TGrid3DSeriesEditor;
  protected
    procedure SetItemProperties(Index:Integer); override;
  public
    { Public declarations }
  end;

implementation

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

uses
  TeeProCo;

{ TTreeMapSeriesEditor }

procedure TTreeMapSeriesEditor.FormShow(Sender: TObject);
begin
  inherited;

  if Assigned(Series) then
  begin
    CBTilingStyle.ItemIndex:=Ord(TTreeMapSeries(Series).MapStyle);
    CBoxColorEach.Checked:=Series.ColorEachPoint;
    CBColorStyle.ItemIndex:=Ord(TTreeMapSeries(Series).ColorStyle);

    ComboFlat2.ItemIndex:=Integer(TAlignment(Series.Format.TextAlignment));

    I3DEditor:=TGrid3DSeriesEditor.Create(nil);
    I3DEditor.Align:=alClient;
    TeeTranslateControl(I3DEditor);
    
    AddFormTo(I3DEditor,TabPalette,TTreeMapSeries(Series).Palette.Series);
  end;
end;

procedure TTreeMapSeriesEditor.CBTilingStyleChange(Sender: TObject);
begin
  TTreeMapSeries(Series).MapStyle:=TTreeMapTiling(CBTilingStyle.ItemIndex);
end;

procedure TTreeMapSeriesEditor.CBoxColorEachClick(Sender: TObject);
begin
  Series.ColorEachPoint:=CBoxColorEach.Checked;
end;

procedure TTreeMapSeriesEditor.ComboFlat2Change(Sender: TObject);
begin
  Series.Format.TextAlignment:=TAlignment(ComboFlat2.ItemIndex);
end;

procedure TTreeMapSeriesEditor.FormDestroy(Sender: TObject);
begin
  I3DEditor.Free;
  inherited;
end;

procedure TTreeMapSeriesEditor.CBColorStyleChange(Sender: TObject);
begin
  TTreeMapSeries(Series).ColorStyle:=TTreeMapColorStyle(CBColorStyle.ItemIndex);
end;

procedure TTreeMapSeriesEditor.EValueChange(Sender: TObject);
begin
  if not IChanging then
  with Series do
  begin
    MandatoryValueList[CurrentIndex]:=StrToFloatDef(EValue.Text,MandatoryValueList[CurrentIndex]);
    Repaint;
  end;
end;

procedure TTreeMapSeriesEditor.SetItemProperties(Index: Integer);
begin
  inherited;
  EValue.Text:=FormatFloat(Series.ValueFormat,Series.MandatoryValueList[CurrentIndex]);
end;

initialization
  RegisterClass(TTreeMapSeriesEditor);
end.
