fpspreadsheet: ods chart writer supports legend overlapping with plot area.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8982 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2023-10-26 11:30:36 +00:00
parent 16944df46e
commit eded936053
4 changed files with 14 additions and 3 deletions

View File

@ -100,6 +100,7 @@ begin
ch.Legend.Border.Color := scGray;
ch.Legend.Background.FgColor := scSilver;
ch.Legend.Background.Style := fsSolidFill;
ch.Legend.CanOverlapPlotArea := true;
// 2nd sheet
sh2 := b.AddWorksheet('test2');

View File

@ -171,9 +171,11 @@ type
TsChartLegend = class(TsChartFillElement)
private
FFont: TsFont;
FCanOverlapPlotArea: Boolean;
public
constructor Create(AChart: TsChart);
destructor Destroy; override;
property CanOverlapPlotArea: Boolean read FCanOverlapPlotArea write FCanOverlapPlotArea;
property Font: TsFont read FFont write FFont;
end;

View File

@ -93,6 +93,7 @@ type
end;
TsChartLegendRec = record
CanOverlapPlotArea: Boolean;
Font: TsChartFontRec;
Border: TsChartLineRec;
Fill: TsChartFillRec;
@ -599,6 +600,7 @@ end;
{ TsChartLegendRec }
procedure TsChartLegendRec.FromChart(AChart: TsChart; AElement: TsChartStyleElement);
begin
CanOverlapPlotArea := AChart.Legend.CanOverlapPlotArea;
Font.FromChart(AChart, ceLegend);
Border.FromChart(AChart, ceLegend, 0);
Fill.FromChart(AChart, ceLegend, 0);
@ -607,6 +609,7 @@ end;
procedure TsChartLegendRec.ToChart(AChart: TsChart; AElement: TsChartStyleElement);
begin
AChart.Legend.CanOverlapPlotArea := CanOverlapPlotArea;
Font.ToChart(AChart, ceLegend);
Border.ToChart(AChart, ceLegend, 0);
Fill.ToChart(AChart, ceLegend, 0);
@ -616,7 +619,7 @@ end;
class operator TsChartLegendRec.= (A, B: TsChartLegendRec): Boolean;
begin
Result := (A.Font = B.Font) and (A.Border = B.Border) and (A.Fill = B.Fill) and
(A.Visible = B.Visible);
(A.Visible = B.Visible) and (A.CanOverlapPlotArea = B.CanOverlapPlotArea);
end;
{ TsChartPlotAreaRec }

View File

@ -7005,18 +7005,23 @@ procedure TsSpreadOpenDocWriter.WriteChartLegend(AStream: TStream; AChart: TsCha
var
ind: String;
styles: TsChartStyleList;
style: TsChartStyle_Legend;
idx: Integer = 400;
canOverlap: String = '';
begin
if (not AChart.Legend.Visible) then
exit;
styles := TsChartStyleList(FChartStyleList);
idx := styles.AddChartStyle('Legend', AChart, TsChartstyle_Legend, ceLegend);
style := TsChartStyle_Legend(styles[idx]);
if style.Legend.CanOverlapPlotArea then
canOverlap := 'loext:overlay="true" ';
ind := DupeString(' ', AIndent);
AppendToStream(AStream, Format(
ind + '<chart:legend chart:style-name="ch%d" chart:legend-position="end" style:legend-expansion="high" />' + LE,
[ idx + 1 ]
ind + '<chart:legend chart:style-name="ch%d" chart:legend-position="end" style:legend-expansion="high" %s/>' + LE,
[ idx + 1, canOverlap ]
));
{$ifdef DEBUG_CHART_STYLES}