fpspreadsheet: More on date/time formats for axis labels.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9074 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2023-12-06 14:11:04 +00:00
parent 9cf4d83c2d
commit e8a24a0cf0
4 changed files with 50 additions and 28 deletions

View File

@ -64,8 +64,11 @@ end;
procedure TForm1.ComboBox1CloseUp(Sender: TObject);
begin
Combobox1.Text := Combobox1.Items[Combobox1.ItemIndex];
LoadFile(Combobox1.Text);
if ComboBox1.ItemIndex > -1 then
begin
Combobox1.Text := Combobox1.Items[Combobox1.ItemIndex];
LoadFile(Combobox1.Text);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);

View File

@ -247,6 +247,8 @@ type
FInverted: Boolean;
FLabelFont: TsFont;
FLabelFormat: String;
FLabelFormatFromSource: Boolean;
FLabelFormatDateTime: String;
FLabelFormatPercent: String;
FLabelRotation: Integer;
FLogarithmic: Boolean;
@ -274,6 +276,8 @@ type
property Inverted: Boolean read FInverted write FInverted;
property LabelFont: TsFont read FLabelFont write FLabelFont;
property LabelFormat: String read FLabelFormat write FLabelFormat;
property LabelFormatDateTime: String read FLabelFormatDateTime write FLabelFormatDateTime;
property LabelFormatFromSource: Boolean read FLabelFormatFromSource write FLabelFormatFromSource;
property LabelFormatPercent: String read FLabelFormatPercent write FLabelFormatPercent;
property LabelRotation: Integer read FLabelRotation write FLabelRotation;
property Logarithmic: Boolean read FLogarithmic write FLogarithmic;
@ -1190,6 +1194,8 @@ begin
FLabelFont.Style := [];
FLabelFont.Color := scBlack;
FLabelFormatFromSource := true;
FLabelFormatDateTime := '';
FLabelFormatPercent := '0%';
FLabelRotation := 0;
FShowLabels := true;

View File

@ -12,7 +12,8 @@ uses
fpszipper,
{$ENDIF}
laz2_xmlread, laz2_DOM,
fpsTypes, fpSpreadsheet, fpsChart, fpsUtils, fpsReaderWriter, fpsXMLCommon;
fpsTypes, fpSpreadsheet, fpsChart, fpsUtils, fpsNumFormat,
fpsReaderWriter, fpsXMLCommon;
type
@ -693,9 +694,15 @@ var
ticks: TsChartAxisTicks = [];
begin
nodeName := AStyleNode.NodeName;
s := GetAttrValue(AStyleNode, 'style:data-style-name');
if s <> '' then
s := TsChartNumberFormatList(FNumberFormatList).FindFormatByName(s);
if IsDateTimeFormat(s) then
begin
Axis.DateTime := true;
Axis.LabelFormatDateTime := s;
end else
if (AChart.StackMode = csmStackedPercentage) and ((Axis = AChart.YAxis) or (Axis = AChart.Y2Axis)) then
Axis.LabelFormatPercent := s
else

View File

@ -27,7 +27,7 @@ uses
TASeries, TARadialSeries, TAFitUtils, TAFuncSeries, TAMultiSeries,
TATransformations, TAChartAxisUtils, TAChartAxis, TAStyles, TATools, TAGraph,
// FPSpreadsheet
fpsTypes, fpSpreadsheet, fpsUtils, fpsChart,
fpsTypes, fpSpreadsheet, fpsUtils, fpsNumFormat, fpsChart,
// FPSpreadsheet Visual
fpSpreadsheetCtrls, fpSpreadsheetGrid, fpsVisualUtils;
@ -1141,7 +1141,7 @@ begin
Result.Title := src.Title;
end;
// Assign series to axis for primary and secondary axes support
// Assign series index to axis for primary and secondary axes support
case ASeries.XAxis of
alPrimary:
Result.AxisIndexX := FChart.AxisList.GetAxisByAlign(calBottom).Index;
@ -1785,6 +1785,9 @@ begin
// Labels
Convert_sFont_to_Font(AWorkbookAxis.LabelFont, axis.Marks.LabelFont);
axis.Marks.LabelFont.Orientation := round(AWorkbookAxis.LabelRotation * 10);
if (AWorkbookAxis.LabelFormat <> '') and not IsDateTimeFormat(AWorkbookAxis.LabelFormat) then
axis.Marks.Format := Convert_NumFormatStr_to_FormatStr(AWorkbookAxis.LabelFormat);
// Axis line
UpdateChartPen(AWorkbookAxis.Chart, AWorkbookAxis.AxisLine, axis.AxisPen);
@ -1839,9 +1842,34 @@ begin
axis.Intervals.MinLength := 20;
axis.Intervals.Tolerance := 0;
end;
end;
procedure TsWorkbookChartLink.UpdateChartAxisLabels(AWorkbookChart: TsChart);
var
axis: TChartAxis;
begin
if FChart.SeriesCount = 0 then
exit;
axis := FChart.BottomAxis;
case AWorkbookChart.GetChartType of
ctScatter, ctBubble:
begin
axis.Marks.Source := nil;
axis.Marks.Style := smsValue;
end;
ctBar, ctLine, ctArea:
begin
axis.Marks.Source := TChartSeries(FChart.Series[0]).Source;
if not AWorkbookChart.Series[0].LabelRange.IsEmpty then
axis.Marks.Style := smsLabel
else
axis.Marks.Style := smsXValue;
end;
end;
// Date/time?
if AWorkbookAxis.DateTime then
if AWorkbookChart.XAxis.DateTime then
begin
axis.Marks.Source := TDateTimeIntervalChartsource.Create(FChart);
axis.Marks.Style := smsLabel;
@ -1853,28 +1881,6 @@ begin
end;
end;
procedure TsWorkbookChartLink.UpdateChartAxisLabels(AWorkbookChart: TsChart);
begin
if FChart.SeriesCount = 0 then
exit;
case AWorkbookChart.GetChartType of
ctScatter, ctBubble:
begin
FChart.BottomAxis.Marks.Source := nil;
FChart.BottomAxis.Marks.Style := smsValue;
end;
ctBar, ctLine, ctArea:
begin
FChart.BottomAxis.Marks.Source := TChartSeries(FChart.Series[0]).Source;
if not AWorkbookChart.Series[0].LabelRange.IsEmpty then
FChart.BottomAxis.Marks.Style := smsLabel
else
FChart.BottomAxis.Marks.Style := smsXValue;
end;
end;
end;
procedure TsWorkbookChartLink.UpdateChartBackground(AWorkbookChart: TsChart);
begin
FChart.Color := Convert_sColor_to_Color(AWorkbookChart.Background.Color);