fpspreadsheet: Implement axis position for xlsx writer. Fix its transfer to TAChart.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9261 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2024-02-29 18:31:48 +00:00
parent 8d065c3c40
commit 67802d571d
3 changed files with 57 additions and 10 deletions

View File

@ -372,6 +372,7 @@ type
property MinorCount: Integer read FMinorCount write SetMinorCount;
property MinorInterval: Double read FMinorInterval write SetMinorInterval;
property MinorTicks: TsChartAxisTicks read FMinorTicks write FMinorTicks;
// Position and PositionValue define where the axis is crossed by the other axis
property Position: TsChartAxisPosition read FPosition write FPosition;
property PositionValue: Double read FPositionValue write FPositionValue;
property ShowLabels: Boolean read FShowLabels write FShowLabels;

View File

@ -427,6 +427,20 @@ begin
x := DEFAULT_TEXT_DIR[AChart.RotatedAxes, AChartAxis.Alignment]; // not sure, but maybe 1000 means: default
AChartAxis.LabelRotation := x;
end;
'c:crossAx':
;
'c:crosses':
case s of
'min': AChartAxis.Position := capStart;
'max': AChartAxis.Position := capEnd;
'autoZero': AChartAxis.Position := capStart;
end;
'c:crossesAt':
if TryStrToFloat(s, x, FPointSeparatorSettings) then
begin
AChartAxis.Position := capValue;
AChartAxis.PositionValue := x;
end;
end;
ANode := ANode.NextSibling;
end;
@ -3768,21 +3782,17 @@ var
indent: String;
chart: TsChart;
axID: DWord;
rotAxID: DWord;
crosses: String = 'autoZero';
crosses: String;
delete: Integer = 0;
axAlign: TsChartAxisAlignment;
rotAxID: DWord;
rotAxis: TsChartAxis;
begin
indent := DupeString(' ', AIndent);
chart := Axis.Chart;
axID := FAxisID[Axis.Alignment];
rotAxID := FAxisID[Axis.GetRotatedAxis.Alignment];
if (Axis = chart.Y2Axis) then
crosses := 'max'
else
if (Axis = chart.YAxis) and (chart.GetChartType in [ctBar]) then
crosses := 'min';
if Axis = chart.X2Axis then
delete := 1;
@ -3818,20 +3828,33 @@ begin
if Axis.ShowLabels then
WriteChartLabels(AStream, AIndent + 2, Axis.LabelFont);
// Axis position
case Axis.Position of
capStart:
crosses := ' <c:crosses val="min"/>';
capEnd:
crosses := ' <c:crosses val="max"/>';
capValue:
crosses := Format(' <c:crossesAt val="%g"/>', [Axis.PositionValue], FPointSeparatorSettings);
else
raise Exception.Create('Unsupported value of Axis.Position');
// not used here: "autoZero"
end;
if crosses <> '' then crosses := indent + crosses + LE;
AppendToStream(AStream, Format(
indent + ' <c:numFmt formatCode="General" sourceLinked="1"/>' + LE +
indent + ' <c:majorTickMark val="%s"/>' + LE +
indent + ' <c:minorTickMark val="%s"/>' + LE +
indent + ' <c:tickLblPos val="nextTo"/>' + LE +
indent + ' <c:crossAx val="%d" />' + LE +
indent + ' <c:crosses val="%s"/>' + LE +
indent + ' <c:crossAx val="%d"/>' + LE +
crosses +
// indent + ' <c:auto val="1"/>' + LE +
indent + '</%s>' + LE,
[
GetTickMarkStr(Axis.MajorTicks), // <c:majorTickMark>
GetTickMarkStr(Axis.MinorTicks), // <c:minorTickMark>
rotAxID, // <c:crossAx>
crosses, // <c:crosses>
ANodeName // </c:catAx> or </c:valAx>
]
));

View File

@ -2228,6 +2228,29 @@ begin
axis.Intervals.MinLength := 20;
axis.Intervals.Tolerance := 0;
end;
// Axis position
case AWorkbookAxis.Position of
capStart:
begin
axis.Position := 0;
axis.PositionUnits := cuPercent;
end;
capEnd:
begin
axis.Position := 100;
axis.PositionUnits := cuPercent;
// To do: Move TAChart axis labels and title to the other side
end;
capValue:
begin
if AWorkbookAxis.GetRotatedAxis.Logarithmic then
axis.Position := log10(AWorkbookAxis.PositionValue)
else
axis.Position := AWorkbookAxis.PositionValue;
axis.PositionUnits := cuGraph; // To do: cuAxis not yet implemented in TAChart...
end;
end;
end;
procedure TsWorkbookChartLink.UpdateChartAxisLabels(AWorkbookChart: TsChart);