fpspreadsheet: Fix rotated axis titles.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9239 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2024-02-14 00:32:33 +00:00
parent 42a8f179d2
commit 9c8682ff8b
4 changed files with 64 additions and 33 deletions

View File

@ -302,6 +302,7 @@ type
FAutomaticMinorSteps: Boolean; FAutomaticMinorSteps: Boolean;
FAxisLine: TsChartLine; FAxisLine: TsChartLine;
FCategoryRange: TsChartRange; FCategoryRange: TsChartRange;
FDefaultTitleRotation: Boolean;
FMajorGridLines: TsChartLine; FMajorGridLines: TsChartLine;
FMinorGridLines: TsChartline; FMinorGridLines: TsChartline;
FInverted: Boolean; FInverted: Boolean;
@ -325,6 +326,7 @@ type
FPositionValue: Double; FPositionValue: Double;
FShowLabels: Boolean; FShowLabels: Boolean;
FDateTime: Boolean; FDateTime: Boolean;
function GetTitleRotationAngle: Single;
procedure SetMax(AValue: Double); procedure SetMax(AValue: Double);
procedure SetMin(AValue: Double); procedure SetMin(AValue: Double);
procedure SetMinorCount(AValue: Integer); procedure SetMinorCount(AValue: Integer);
@ -347,6 +349,7 @@ type
property AxisLine: TsChartLine read FAxisLine write FAxisLine; property AxisLine: TsChartLine read FAxisLine write FAxisLine;
property CategoryRange: TsChartRange read FCategoryRange write FCategoryRange; property CategoryRange: TsChartRange read FCategoryRange write FCategoryRange;
property DateTime: Boolean read FDateTime write FDateTime; property DateTime: Boolean read FDateTime write FDateTime;
property DefaultTitleRotation: Boolean read FDefaultTitleRotation write FDefaultTitleRotation;
property Inverted: Boolean read FInverted write FInverted; property Inverted: Boolean read FInverted write FInverted;
property LabelFont: TsFont read FLabelFont write FLabelFont; property LabelFont: TsFont read FLabelFont write FLabelFont;
property LabelFormat: String read FLabelFormat write FLabelFormat; property LabelFormat: String read FLabelFormat write FLabelFormat;
@ -369,6 +372,7 @@ type
property PositionValue: Double read FPositionValue write FPositionValue; property PositionValue: Double read FPositionValue write FPositionValue;
property ShowLabels: Boolean read FShowLabels write FShowLabels; property ShowLabels: Boolean read FShowLabels write FShowLabels;
property Title: TsChartText read FTitle write FTitle; property Title: TsChartText read FTitle write FTitle;
property TitleRotationAngle: Single read GetTitleRotationAngle;
property Visible; property Visible;
end; end;
@ -798,7 +802,6 @@ type
FImages: TsChartImageList; FImages: TsChartImageList;
function GetCategoryLabelRange: TsChartRange; function GetCategoryLabelRange: TsChartRange;
procedure SetRotatedAxes(AValue: Boolean);
protected protected
function AddSeries(ASeries: TsChartSeries): Integer; virtual; function AddSeries(ASeries: TsChartSeries): Integer; virtual;
@ -873,7 +876,7 @@ type
{ Connecting line between data points (for line and scatter series) } { Connecting line between data points (for line and scatter series) }
property Interpolation: TsChartInterpolation read FInterpolation write FInterpolation; property Interpolation: TsChartInterpolation read FInterpolation write FInterpolation;
{ x and y axes exchanged (mainly for bar series, but works also for scatter and bubble series) } { x and y axes exchanged (mainly for bar series, but works also for scatter and bubble series) }
property RotatedAxes: Boolean read FRotatedAxes write SetRotatedAxes; property RotatedAxes: Boolean read FRotatedAxes write FRotatedAxes;
{ Stacking of series (for bar and area series ) } { Stacking of series (for bar and area series ) }
property StackMode: TsChartStackMode read FStackMode write FStackMode; property StackMode: TsChartStackMode read FStackMode write FStackMode;
@ -1727,6 +1730,7 @@ begin
FCategoryRange := TsChartRange.Create(AChart); FCategoryRange := TsChartRange.Create(AChart);
FTitle := TsChartText.Create(AChart); FTitle := TsChartText.Create(AChart);
FDefaultTitleRotation := true;
FLabelFont := TsFont.Create; FLabelFont := TsFont.Create;
FLabelFont.Size := 9; FLabelFont.Size := 9;
@ -1842,6 +1846,26 @@ begin
Result := Chart.X2Axis; Result := Chart.X2Axis;
end; end;
{@@ ----------------------------------------------------------------------------
Returns the text rotation angle of the axis title.
When DefaultTitleRotation is true this is either 0 or 90, depending on the
axis direction. Otherwise it is the title's RotationAngle.
-------------------------------------------------------------------------------}
function TsChartAxis.GetTitleRotationAngle: Single;
var
rotated: Boolean;
begin
if FDefaultTitleRotation then
begin
rotated := FChart.RotatedAxes;
case FAlignment of
caaLeft, caaRight: if rotated then Result := 0 else Result := 90;
caaBottom, caaTop: if rotated then Result := 90 else Result := 0;
end;
end else
Result := FTitle.RotationAngle;
end;
procedure TsChartAxis.SetCategoryRange(ARow1, ACol1, ARow2, ACol2: Cardinal); procedure TsChartAxis.SetCategoryRange(ARow1, ACol1, ARow2, ACol2: Cardinal);
begin begin
SetCategoryRange('', ARow1, ACol1, '', ARow2, ACol2); SetCategoryRange('', ARow1, ACol1, '', ARow2, ACol2);
@ -2927,25 +2951,6 @@ begin
Result := FLineStyles.Count; Result := FLineStyles.Count;
end; end;
procedure TsChart.SetRotatedAxes(AValue: Boolean);
begin
if FRotatedAxes = AValue then
exit;
FRotatedAxes := AValue;
if FRotatedAxes then
begin
FXAxis.Title.RotationAngle := FXAxis.Title.RotationAngle + 90;
FX2Axis.Title.RotationAngle := FX2Axis.Title.RotationAngle + 90;
FYAxis.Title.RotationAngle := FYAxis.Title.RotationAngle - 90;
FY2Axis.Title.RotationAngle := FY2Axis.Title.RotationAngle - 90;
end else
begin
FXAxis.Title.RotationAngle := FXAxis.Title.RotationAngle - 90;
FX2Axis.Title.RotationAngle := FX2Axis.Title.RotationAngle - 90;
FYAxis.Title.RotationAngle := FYAxis.Title.RotationAngle + 90;
FY2Axis.Title.RotationAngle := FY2Axis.Title.RotationAngle + 90;
end;
end;
{ TsChartList } { TsChartList }

View File

@ -1071,6 +1071,10 @@ begin
AChart.YAxis.Visible := false; AChart.YAxis.Visible := false;
AChart.X2Axis.Visible := false; AChart.X2Axis.Visible := false;
AChart.Y2Axis.Visible := false; AChart.Y2Axis.Visible := false;
AChart.XAxis.DefaultTitleRotation := true;
AChart.YAxis.DefaultTitleRotation := true;
AChart.X2Axis.DefaultTitleRotation := true;
AChart.Y2Axis.DefaultTitleRotation := true;
AChart.PlotArea.Border.Style := clsNoLine; AChart.PlotArea.Border.Style := clsNoLine;
AChart.Floor.Border.Style := clsNoLine; AChart.Floor.Border.Style := clsNoLine;
@ -2346,6 +2350,7 @@ var
font: TsFont; font: TsFont;
indent: String; indent: String;
rotAngle: Single; rotAngle: Single;
rotAngleStr: String = '';
chartProps: String = ''; chartProps: String = '';
textProps: String = ''; textProps: String = '';
begin begin
@ -2368,13 +2373,22 @@ begin
end; end;
font := axis.Title.Font; font := axis.Title.Font;
rotAngle := axis.Title.RotationAngle; rotAngle := axis.Title.RotationAngle;
if not axis.DefaultTitleRotation then
begin
if AChart.RotatedAxes then
begin
if rotAngle = 0 then rotAngle := 90 else if rotAngle = 90 then rotAngle := 0;
end;
rotAngleStr := Format('%.1f', [rotangle], FPointSeparatorSettings);
end;
end; end;
else else
raise Exception.Create('[GetChartCaptionStyleAsXML] Unknown caption.'); raise Exception.Create('[GetChartCaptionStyleAsXML] Unknown caption.');
end; end;
chartProps := 'chart:auto-position="true" '; chartProps := 'chart:auto-position="true" ';
chartProps := chartProps + Format('style:rotation-angle="%.1f" ', [rotAngle], FPointSeparatorSettings); if rotAngleStr <> '' then
chartProps := chartProps + Format('style:rotation-angle="%s" ', [rotAngleStr]);
textProps := TsSpreadOpenDocWriter(Writer).WriteFontStyleXMLAsString(font); textProps := TsSpreadOpenDocWriter(Writer).WriteFontStyleXMLAsString(font);

View File

@ -119,7 +119,7 @@ type
procedure WriteScatterSeries(AStream: TStream; AIndent: Integer; ASeries: TsScatterSeries; ASeriesIndex, APosInAxisGroup: Integer); procedure WriteScatterSeries(AStream: TStream; AIndent: Integer; ASeries: TsScatterSeries; ASeriesIndex, APosInAxisGroup: Integer);
procedure WriteChartLabels(AStream: TStream; AIndent: Integer; AFont: TsFont); procedure WriteChartLabels(AStream: TStream; AIndent: Integer; AFont: TsFont);
procedure WriteChartText(AStream: TStream; AIndent: Integer; AText: TsChartText); procedure WriteChartText(AStream: TStream; AIndent: Integer; AText: TsChartText; ARotationAngle: Single);
public public
constructor Create(AWriter: TsBasicSpreadWriter); override; constructor Create(AWriter: TsBasicSpreadWriter); override;
@ -2301,14 +2301,25 @@ begin
s := GetAttrValue(child2, 'rot'); s := GetAttrValue(child2, 'rot');
if (s <> '') and TryStrToInt(s, n) then if (s <> '') and TryStrToInt(s, n) then
begin begin
if n = 1000 then if axis <> nil then
begin begin
if axis <> nil then if n = 1000 then
n := DEFAULT_TEXT_DIR[axis.Chart.RotatedAxes, axis.Alignment] // not sure, but maybe 1000 means: default axis.DefaultTitleRotation := true
else else
n := 0; begin
if n = 0 then
ATitle.RotationAngle := 0
else
ATitle.RotationAngle := -n / ANGLE_MULTIPLIER;
axis.DefaultTitleRotation := false;
end;
end else
begin
if (n = 1000) or (n = 0) then
ATitle.RotationAngle := 0
else
Atitle.RotationAngle := -n/ANGLE_MULTIPLIER;
end; end;
ATitle.RotationAngle := -n / ANGLE_MULTIPLIER;
end; end;
end; end;
'a:lstStyle': 'a:lstStyle':
@ -2453,6 +2464,7 @@ end;
procedure TsSpreadOOXMLChartReader.SetAxisDefaults(AWorkbookAxis: TsChartAxis); procedure TsSpreadOOXMLChartReader.SetAxisDefaults(AWorkbookAxis: TsChartAxis);
begin begin
AWorkbookAxis.Title.Caption := ''; AWorkbookAxis.Title.Caption := '';
AWorkbookAxis.DefaultTitleRotation := true;
AWorkbookAxis.LabelRotation := 0; AWorkbookAxis.LabelRotation := 0;
AWorkbookAxis.Visible := false; AWorkbookAxis.Visible := false;
AWorkbookAxis.MajorGridLines.Style := clsNoLine; AWorkbookAxis.MajorGridLines.Style := clsNoLine;
@ -3842,7 +3854,7 @@ begin
indent + '<c:title>' + LE indent + '<c:title>' + LE
); );
WriteChartText(AStream, AIndent + 4, Axis.Title); WriteChartText(AStream, AIndent + 4, Axis.Title, Axis.TitleRotationAngle);
AppendToStream(AStream, AppendToStream(AStream,
indent + ' <c:overlay val="0"/>' + LE + indent + ' <c:overlay val="0"/>' + LE +
@ -4636,7 +4648,7 @@ end;
Writes a <c:tx> node containing either the chart title or axis title. Writes a <c:tx> node containing either the chart title or axis title.
-------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsSpreadOOXMLChartWriter.WriteChartText(AStream: TStream; procedure TsSpreadOOXMLChartWriter.WriteChartText(AStream: TStream;
AIndent: Integer; AText: TsChartText); AIndent: Integer; AText: TsChartText; ARotationAngle: Single);
var var
indent: String; indent: String;
rotStr: String; rotStr: String;
@ -4644,7 +4656,7 @@ begin
if not AText.Visible then if not AText.Visible then
exit; exit;
str(-AText.RotationAngle * ANGLE_MULTIPLIER:0:0, rotStr); str(-ARotationAngle * ANGLE_MULTIPLIER:0:0, rotStr);
indent := DupeString(' ', AIndent); indent := DupeString(' ', AIndent);
AppendToStream(AStream, AppendToStream(AStream,
@ -4685,7 +4697,7 @@ begin
indent + '<c:title>' + LE indent + '<c:title>' + LE
); );
WriteChartText(AStream, AIndent + 2, ATitle); WriteChartText(AStream, AIndent + 2, ATitle, ATitle.RotationAngle);
AppendToStream(AStream, AppendToStream(AStream,
indent + ' <c:overlay val="0"/>' + LE + indent + ' <c:overlay val="0"/>' + LE +

View File

@ -2150,7 +2150,7 @@ begin
axis.Title.Caption := AWorkbookAxis.Title.Caption; axis.Title.Caption := AWorkbookAxis.Title.Caption;
axis.Title.Visible := true; axis.Title.Visible := true;
Convert_sFont_to_Font(AWorkbookAxis.Title.Font, axis.Title.LabelFont); Convert_sFont_to_Font(AWorkbookAxis.Title.Font, axis.Title.LabelFont);
axis.Title.LabelFont.Orientation := round(AWorkbookAxis.Title.RotationAngle * 10); axis.Title.LabelFont.Orientation := round(AWorkbookAxis.TitleRotationAngle * 10);
// Labels // Labels
Convert_sFont_to_Font(AWorkbookAxis.LabelFont, axis.Marks.LabelFont); Convert_sFont_to_Font(AWorkbookAxis.LabelFont, axis.Marks.LabelFont);