{*********************************************}
{  TeeChart Charting Library for FireMonkey   }
{  Copyright (c) 2012-2020 by Steema Software }
{  All Rights Reserved                        }
{*********************************************}
unit FMXTee.Editor.Series.Histogram;
{$I TeeDefs.inc}

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.Edit, FMX.Colors,
  FMX.StdCtrls,
  {$IFDEF D21}
  FMX.SpinBox,
  {$ENDIF}
  FMX.TabControl, FMXTee.Functions.Stats, FMXTee.Editor.Stroke,
  FMXTee.Editor.Brush;

type
  THistogramSeriesEditor = class(TForm)
    TabControl1: TTabControl;
    TabOptions: TTabItem;
    CBColorEach: TCheckBox;
    TabBorder: TTabItem;
    TabLines: TTabItem;
    TabPattern: TTabItem;
    GroupBox1: TGroupBox;
    BAreaColor: TColorButton;
    Label6: TLabel;
    UDTransp: TSpinBox;
    Label7: TLabel;
    GroupBox2: TGroupBox;
    CBUseOrigin: TCheckBox;
    UDOrigin: TSpinBox;
    Label8: TLabel;
    procedure FormActivate(Sender: TObject);
    procedure CBColorEachChange(Sender: TObject);
    procedure UDTranspChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure CBUseOriginChange(Sender: TObject);
    procedure UDOriginChange(Sender: TObject);
    procedure TabControl1Change(Sender: TObject);
  private
    { Private declarations }
    CreatingForm : Boolean;
    FBorder : TStrokeEditor;
    FLines : TStrokeEditor;
    FPattern : TBrushEditor;
    TheSeries    : THistogramSeries;
    Procedure EnableOrigin;
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

procedure THistogramSeriesEditor.CBColorEachChange(Sender: TObject);
begin
  TheSeries.ColorEachPoint:=CBColorEach.IsChecked;
  BAreaColor.Enabled:=not TheSeries.ColorEachPoint;
end;

procedure THistogramSeriesEditor.CBUseOriginChange(Sender: TObject);
begin
  TheSeries.UseYOrigin:=CBUseOrigin.IsChecked;
  EnableOrigin;
end;

procedure THistogramSeriesEditor.FormActivate(Sender: TObject);
begin
  TheSeries:=THistogramSeries(TagObject);

  if Assigned(TheSeries) then
  begin
    With TheSeries do
    begin
      CBColorEach.IsChecked   :=ColorEachPoint;
      UDTransp.Value:=Transparency;
      CBUseOrigin.IsChecked   :=UseYOrigin;
      UDOrigin.Value     :=Round(YOrigin);
    end;

    With BAreaColor do
    begin
      Color := TheSeries.SeriesColor;
      Enabled:=not TheSeries.ColorEachPoint;
    end;
  end;

  EnableOrigin;

  CreatingForm:=False;

end;

procedure THistogramSeriesEditor.FormCreate(Sender: TObject);
begin
  CreatingForm:=True;
end;

procedure THistogramSeriesEditor.TabControl1Change(Sender: TObject);
begin
  if (TabControl1.ActiveTab=TabBorder) and (not Assigned(FBorder)) then
     FBorder:=TStrokeEditor.InsertForm(TheSeries.Pen,TabBorder)
  else
  if (TabControl1.ActiveTab=TabLines) and (not Assigned(FLines)) then
     FLines:=TStrokeEditor.InsertForm(TheSeries.LinesPen,TabLines)
  else
  if (TabControl1.ActiveTab=TabPattern) and (not Assigned(FPattern)) then
     FPattern:=TBrushEditor.InsertForm(TheSeries.Brush,TabPattern);
end;

procedure THistogramSeriesEditor.UDOriginChange(Sender: TObject);
begin
  if Assigned(TheSeries) then
     TheSeries.YOrigin:=UDOrigin.Value;
end;

procedure THistogramSeriesEditor.UDTranspChange(Sender: TObject);
begin
  if Assigned(TheSeries) then
     TheSeries.Transparency:=Round(UDTransp.Value);
end;

procedure THistogramSeriesEditor.EnableOrigin;
begin
  UDOrigin.Enabled:=CBUseOrigin.IsChecked;
end;

initialization
  RegisterClass(THistogramSeriesEditor);
end.
