diff --git a/components/tachart/tachartutils.pas b/components/tachart/tachartutils.pas index 6417d26d94..3e7ca1d1d2 100644 --- a/components/tachart/tachartutils.pas +++ b/components/tachart/tachartutils.pas @@ -129,6 +129,16 @@ type TCaseOfTwo = (cotNone, cotFirst, cotSecond, cotBoth); + { TIndexedComponent } + + TIndexedComponent = class (TComponent) + protected + function GetIndex: Integer; virtual; abstract; + procedure SetIndex(AValue: Integer); virtual; abstract; + public + property Index: Integer read GetIndex write SetIndex; + end; + const // 0-value, 1-percent, 2-label, 3-total, 4-xvalue SERIES_MARK_FORMATS: array [TSeriesMarksStyle] of String = ( diff --git a/components/tachart/tacustomseries.pas b/components/tachart/tacustomseries.pas index 098ed95834..5e417d299b 100644 --- a/components/tachart/tacustomseries.pas +++ b/components/tachart/tacustomseries.pas @@ -52,6 +52,10 @@ type procedure ReadState(Reader: TReader); override; procedure SetParentComponent(AParent: TComponent); override; + protected + function GetIndex: Integer; override; + procedure SetIndex(AValue: Integer); override; + protected function AxisToGraphX(AX: Double): Double; override; function AxisToGraphY(AY: Double): Double; override; @@ -224,6 +228,11 @@ begin end; end; +function TCustomChartSeries.GetIndex: Integer; +begin + Result := FChart.Series.List.IndexOf(Self); +end; + function TCustomChartSeries.GetParentComponent: TComponent; begin Result := FChart; @@ -286,6 +295,12 @@ begin UpdateParentChart; end; +procedure TCustomChartSeries.SetIndex(AValue: Integer); +begin + with FChart.Series.List do + Move(Index, EnsureRange(AValue, 0, Count - 1)); +end; + procedure TCustomChartSeries.SetParentComponent(AParent: TComponent); begin if not (csLoading in ComponentState) then diff --git a/components/tachart/tagraph.pas b/components/tachart/tagraph.pas index 7c9c263c7b..f42118aa91 100644 --- a/components/tachart/tagraph.pas +++ b/components/tachart/tagraph.pas @@ -43,7 +43,7 @@ type { TBasicChartSeries } - TBasicChartSeries = class(TComponent) + TBasicChartSeries = class(TIndexedComponent) protected FActive: Boolean; FChart: TChart; @@ -96,7 +96,7 @@ type { TBasicСhartTool } - TBasicChartTool = class(TComponent) + TBasicChartTool = class(TIndexedComponent) strict protected FChart: TChart; diff --git a/components/tachart/tatools.pas b/components/tachart/tatools.pas index ecac0a549c..9765ca0e0e 100644 --- a/components/tachart/tatools.pas +++ b/components/tachart/tatools.pas @@ -51,11 +51,13 @@ type procedure Deactivate; override; procedure Dispatch( AChart: TChart; AEventId: TChartToolEventId; APoint: TPoint); + function GetIndex: Integer; override; function Index: Integer; override; function IsActive: Boolean; procedure MouseDown(APoint: TPoint); virtual; procedure MouseMove(APoint: TPoint); virtual; procedure MouseUp(APoint: TPoint); virtual; + procedure SetIndex(AValue: Integer); override; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; @@ -352,6 +354,11 @@ begin end; end; +function TChartTool.GetIndex: Integer; +begin + Result := Toolset.Tools.IndexOf(Self); +end; + function TChartTool.GetParentComponent: TComponent; begin Result := FToolset; @@ -420,6 +427,11 @@ begin FChart.Cursor := ActiveCursor; end; +procedure TChartTool.SetIndex(AValue: Integer); +begin + Toolset.Tools.Move(Index, EnsureRange(AValue, 0, Toolset.Tools.Count - 1)); +end; + procedure TChartTool.SetParentComponent(AParent: TComponent); begin if not (csLoading in ComponentState) then