fpspreadsheet: Add writing of series labels to ods.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9001 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2023-10-30 14:37:53 +00:00
parent ceec0a7159
commit 2f80394b32
3 changed files with 32 additions and 6 deletions

View File

@@ -61,6 +61,7 @@ begin
ser.Line.Color := scBlue;
ser.Fill.FgColor := scBlue;
ser.SetFillColorRange(r1, 4, r2, 4);
ser.DataLabels := [cdlPercentage, cdlSymbol];
if (ser is TsLineSeries) then
begin
TsLineSeries(ser).ShowSymbols := true;

View File

@@ -185,9 +185,12 @@ type
property CanOverlapPlotArea: Boolean read FCanOverlapPlotArea write FCanOverlapPlotArea;
property Font: TsFont read FFont write FFont;
property Position: TsChartLegendPosition read FPosition write FPosition;
// There is also a "legend-expansion" but this does not seem to have a visual effect in Calc.
end;
TsChartAxisLink = (alPrimary, alSecondary);
TsChartDataLabel = (cdlValue, cdlPercentage, cdlValueAndPercentage, cdlCategory, cdlSeriesName, cdlSymbol);
TsChartDataLabels = set of TsChartDataLabel;
TsChartSeries = class(TsChartElement)
private
@@ -195,12 +198,14 @@ type
FXRange: TsCellRange; // cell range containing the x data
FYRange: TsCellRange;
FLabelRange: TsCellRange;
FLabelFont: TsFont;
FFillColorRange: TsCellRange;
FYAxis: TsChartAxisLink;
FTitleAddr: TsCellCoord;
FLabelFormat: String;
FLine: TsChartLine;
FFill: TsChartFill;
FDataLabels: TsChartDataLabels;
public
constructor Create(AChart: TsChart); virtual;
destructor Destroy; override;
@@ -221,7 +226,9 @@ type
property ChartType: TsChartType read FChartType;
property Count: Integer read GetCount;
property DataLabels: TsChartDataLabels read FDataLabels write FDataLabels;
property FillColorRange: TsCellRange read FFillColorRange;
property LabelFont: TsFont read FLabelFont write FLabelFont;
property LabelFormat: String read FLabelFormat write FLabelFormat; // Number format in Excel notation, e.g. '0.00'
property LabelRange: TsCellRange read FLabelRange;
property TitleAddr: TsCellCoord read FTitleAddr write FTitleAddr;
@@ -593,10 +600,15 @@ begin
FLine.Style := clsSolid;
FLine.Width := PtsToMM(DEFAULT_CHART_LINEWIDTH);
FLine.Color := DEFAULT_SERIES_COLORS[idx mod Length(DEFAULT_SERIES_COLORS)];
FLabelFont := TsFont.Create;
FLabelFont := TsFont.Create;
FLabelFont.Size := 9;
end;
destructor TsChartSeries.Destroy;
begin
FLabelFont.Free;
FLine.Free;
FFill.Free;
inherited;

View File

@@ -527,6 +527,20 @@ begin
);
end;
chartProps := chartProps + 'chart:link-data-style-to-source="true" ';
if ([cdlValue, cdlPercentage] * series.DataLabels = [cdlValue]) then
chartProps := chartProps + 'chart:data-label-number="value" '
else
if ([cdlValue, cdlPercentage] * series.DataLabels = [cdlPercentage]) then
chartProps := chartProps + 'chart:data-label-number="percentage" '
else
if ([cdlValue, cdlPercentage] * series.DataLabels = [cdlValue, cdlPercentage]) then
chartProps := chartProps + 'chart:data-label-number="value-and-percentage" ';
if (cdlCategory in series.DataLabels) then
chartProps := chartProps + 'chart:data-label-text="true" ';
if (cdlSeriesName in series.DataLabels) then
chartProps := chartProps + 'chart:data-label-series="true" ';
if (cdlSymbol in series.DataLabels) then
chartProps := chartProps + 'chart:data-label-symbol="true" ';
// Graphic properties
lineProps := GetChartLineStyleGraphicPropsAsXML(AChart, series.Line);
@@ -541,8 +555,7 @@ begin
graphProps := fillProps + lineProps;
// Text properties
textProps := 'fo:font-size="10pt" style:font-size-asian="10pt" style:font-size-complex="10pt" ';
// textProps := WriteFontStyleXMLAsString(font); // <--- to be completed. this is for the series labels.
textProps := TsSpreadOpenDocWriter(Writer).WriteFontStyleXMLAsString(series.LabelFont);
Result := Format(
indent + '<style:style style:name="ch%d" style:family="chart" style:data-style-name="N0">' + LE +
@@ -1018,7 +1031,7 @@ begin
// Write legend properties
indent := DupeString(' ', AChartIndent);
AppendToStream(AChartStream, Format(
indent + '<chart:legend chart:style-name="ch%d" chart:legend-position="%s" style:legend-expansion="high" %s/>' + LE,
indent + '<chart:legend chart:style-name="ch%d" chart:legend-position="%s" style:legend-expansion="wide" %s/>' + LE,
[ AStyleID, LEGEND_POSITION[AChart.Legend.Position], canOverlap ]
));
@@ -1218,12 +1231,10 @@ var
indent: String;
sheet: TsWorksheet;
series: TsChartSeries;
valuesRange: String;
valuesRange: String = '';
domainRangeX: String = '';
domainRangeY: String = '';
fillColorRange: String = '';
borderColorRange: String = '';
rangeStr: String = '';
titleAddr: String;
count: Integer;
begin
@@ -1287,6 +1298,8 @@ begin
);
count := series.YRange.Row2 - series.YRange.Row1 + 1;
// Store the series properties
AppendToStream(AChartStream, Format(
indent + '<chart:series chart:style-name="ch%d" ' +