unit UFrameCyclesDailyWeightsHistory;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, ExtCtrls, TAGraph, TASeries, TASources, TACustomSource, TAIntervalSources, TATransformations,
TATools, TAChartAxisUtils;
type
{ TFrameCyclesDailyWeightsHistory }
TFrameCyclesDailyWeightsHistory = class(TFrame)
Chart: TChart;
ChartAxisWeightTransformationsLeft: TChartAxisTransformations;
ChartAxisWeightTransformationsLeftAutoScaleAxisTransform: TAutoScaleAxisTransform;
ChartBarSeriesWeights: TBarSeries;
DateTimeIntervalChartSource: TDateTimeIntervalChartSource;
PanelChartControls: TPanel;
PanelMain: TPanel;
UserDefinedChartSourceActualWeights: TUserDefinedChartSource;
procedure ChartAxisList1MarkToText(var AText: String; AMark: Double);
procedure UserDefinedChartSourceGetChartDataItem(ASource: TUserDefinedChartSource; AIndex: Integer; var AItem: TChartDataItem);
private
fLastStartTime, fLastEndTime: TDateTime;
fHistory: TList;
fAverage: Pointer;
public
procedure SetSource(lastStartTime: TDateTime; lastEndTime: TDateTime; history: TList; average: Pointer);
procedure Translate();
procedure ShowContent();
constructor Create(TheOwner: TComponent); override;
end;
implementation
{$R *.lfm}
uses
Graphics
, DateUtils
, Math
,ProdLogQueries
;
////////////////////////////////////////////////////////////////////////////////
// TFrameCyclesDailyWeightsHistory
////////////////////////////////////////////////////////////////////////////////
constructor TFrameCyclesDailyWeightsHistory.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
fHistory := nil;
fAverage := nil;
end;
procedure TFrameCyclesDailyWeightsHistory.UserDefinedChartSourceGetChartDataItem(ASource: TUserDefinedChartSource; AIndex: Integer;
var AItem: TChartDataItem);
var
weightT: Single;
begin
if (fHistory <> nil)
and (fHistory.Count > 1)
and (0 <= AIndex)
and (AIndex < fHistory.Count - 1)
then
begin
AItem.X := PPoweronCycle(fHistory[AIndex + 1])^.ReferenceTime;
if (ASource = UserDefinedChartSourceActualWeights) then
begin
weightT := PPoweronCycle(fHistory[AIndex + 1])^.ActualWeight / 1000;
AItem.Y := weightT;
AItem.Text := Format('%0.2f t', [weightT]);
Exit;
end;
end;
end;
procedure TFrameCyclesDailyWeightsHistory.ChartAxisList1MarkToText(var AText: String; AMark: Double);
begin
AText := SysUtils.FormatDateTime('mmm', AMark) + System.LineEnding + SysUtils.FormatDateTime('dd', AMark);
end;
procedure TFrameCyclesDailyWeightsHistory.SetSource(lastStartTime: TDateTime; lastEndTime: TDateTime; history: TList; average: Pointer);
begin
fLastStartTime := lastStartTime;
fLastEndTime := lastEndTime;
fHistory := history;
fAverage := average;
end;
////////////////////////////////////////////////////////////////////////////////
// Translate/ShowContent
////////////////////////////////////////////////////////////////////////////////
procedure TFrameCyclesDailyWeightsHistory.Translate();
begin
end;
procedure TFrameCyclesDailyWeightsHistory.ShowContent();
begin
if (fHistory <> nil)
and (fHistory.Count > 0) then
begin
Chart.BottomAxis.Range.Min := fLastStartTime - 1;
Chart.BottomAxis.Range.UseMin := True;
Chart.BottomAxis.Range.Max := fLastEndTime + 1;
Chart.BottomAxis.Range.UseMax := True;
DateTimeIntervalChartSource.Params.Count :=
Math.Min(
System.Trunc(2.0 + System.Trunc((Chart.BottomAxis.Range.Max - Chart.BottomAxis.Range.Min) / 2.0) * 2.0 - 1)
, 41);
UserDefinedChartSourceActualWeights.BeginUpdate();
UserDefinedChartSourceActualWeights.Reset();
UserDefinedChartSourceActualWeights.PointsNumber := fHistory.Count - 1;
UserDefinedChartSourceActualWeights.EndUpdate();
end;
end;
end.