From 51c89b10caf8ead4d3b11c05eea03dd98600a6ed Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Sun, 15 Sep 2024 21:28:40 +0000 Subject: [PATCH] FPSpreadsheet: Change signature of AddChart() methods. Adapt all sample projects. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9442 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../other/chart/areachart_write_demo.lpr | 4 ++-- .../other/chart/barchart_2axes_write_demo.lpr | 4 ++-- .../chart/barchart_stacked_write_demo.lpr | 2 +- .../other/chart/barchart_write_demo.lpr | 2 +- .../other/chart/bubblechart_write_demo.lpr | 2 +- .../other/chart/errorbars_write_demo.lpr | 2 +- .../other/chart/linechart_write_demo.lpr | 4 ++-- .../other/chart/piechart_write_demo.lpr | 2 +- .../other/chart/radarchart_write_demo.lpr | 2 +- .../examples/other/chart/read_chart_demo.lpr | 8 +++++--- .../other/chart/regressionchart_write_demo.lpr | 2 +- .../other/chart/scatter_write_demo.lpr | 2 +- .../other/chart/stock_volume_write_demo.lpr | 2 +- .../examples/other/chart/stock_write_demo.lpr | 2 +- .../examples/other/chart/write_chart_demo.lpr | 2 +- .../source/common/fpsopendocument.pas | 2 +- .../source/common/fpspreadsheet.pas | 8 ++++---- .../source/common/fpspreadsheet_chart.inc | 18 +++++++++--------- .../fpspreadsheet/source/common/xlsxooxml.pas | 2 +- 19 files changed, 37 insertions(+), 35 deletions(-) diff --git a/components/fpspreadsheet/examples/other/chart/areachart_write_demo.lpr b/components/fpspreadsheet/examples/other/chart/areachart_write_demo.lpr index 7da98b3da..4e1d469eb 100644 --- a/components/fpspreadsheet/examples/other/chart/areachart_write_demo.lpr +++ b/components/fpspreadsheet/examples/other/chart/areachart_write_demo.lpr @@ -74,8 +74,8 @@ begin sheet.WriteText( 9, 0, 'Physics'); sheet.WriteNumber( 9, 1, 12); sheet.WriteNumber( 9, 2, 19); sheet.WriteText(10, 0, 'Computer'); sheet.WriteNumber(10, 1, 16); sheet.WriteNumber(10, 2, 18); - // Create chart: left/top in cell D4, 160 mm x 100 mm - ch := book.AddChart(sheet, 2, 3, 160, 100); + // Create chart: left/top in cell D4 of worksheet "area_series", 160 mm x 100 mm + ch := sheet.AddChart(160, 100, 2, 3); // Chart properties ch.Border.Style := clsNoLine; diff --git a/components/fpspreadsheet/examples/other/chart/barchart_2axes_write_demo.lpr b/components/fpspreadsheet/examples/other/chart/barchart_2axes_write_demo.lpr index 9f4e8d9d0..1fb10bdab 100644 --- a/components/fpspreadsheet/examples/other/chart/barchart_2axes_write_demo.lpr +++ b/components/fpspreadsheet/examples/other/chart/barchart_2axes_write_demo.lpr @@ -51,8 +51,8 @@ begin sheet.WriteText( 7, 0, 'Case 5'); sheet.WriteNumber( 7, 1, 9); sheet.WriteNumber( 7, 2, 304); sheet.WriteText( 8, 0, 'Case 6'); sheet.WriteNumber( 8, 1, 5); sheet.WriteNumber( 8, 2, 1285); - // Create chart: left/top in cell D4, 160 mm x 100 mm - ch := book.AddChart(sheet, 2, 3, 120, 100); + // Create chart: left/top in cell D4 of sheet "bar_series", 160 mm x 100 mm + ch := sheet.AddChart(120, 100, 2, 3); // Chart properties ch.Border.Style := clsNoLine; diff --git a/components/fpspreadsheet/examples/other/chart/barchart_stacked_write_demo.lpr b/components/fpspreadsheet/examples/other/chart/barchart_stacked_write_demo.lpr index 71bfb6671..14485644e 100644 --- a/components/fpspreadsheet/examples/other/chart/barchart_stacked_write_demo.lpr +++ b/components/fpspreadsheet/examples/other/chart/barchart_stacked_write_demo.lpr @@ -59,7 +59,7 @@ begin sheet.WriteText( 6, 0, 'Q4/2022'); sheet.WriteNumber( 6, 1, 311); sheet.WriteNumber( 6, 2, 183); // Create chart: left/top in cell D4, 160 mm x 100 mm - ch := book.AddChart(sheet, 2, 3, 120, 100); + ch := sheet.AddChart(120, 100, 2, 3); // Chart properties if stackedPercentage then diff --git a/components/fpspreadsheet/examples/other/chart/barchart_write_demo.lpr b/components/fpspreadsheet/examples/other/chart/barchart_write_demo.lpr index f4b26f294..d20457a18 100644 --- a/components/fpspreadsheet/examples/other/chart/barchart_write_demo.lpr +++ b/components/fpspreadsheet/examples/other/chart/barchart_write_demo.lpr @@ -80,7 +80,7 @@ begin sheet.WriteText(10, 0, 'Computer'); sheet.WriteNumber(10, 1, 16); sheet.WriteNumber(10, 2, 18); // Create chart: left/top in cell D4, 160 mm x 100 mm - ch := book.AddChart(sheet, 2, 3, 160, 100); + ch := sheet.AddChart(160, 100, 2, 3); // Chart properties ch.Border.Style := clsNoLine; diff --git a/components/fpspreadsheet/examples/other/chart/bubblechart_write_demo.lpr b/components/fpspreadsheet/examples/other/chart/bubblechart_write_demo.lpr index 6a35e0788..d97c845aa 100644 --- a/components/fpspreadsheet/examples/other/chart/bubblechart_write_demo.lpr +++ b/components/fpspreadsheet/examples/other/chart/bubblechart_write_demo.lpr @@ -51,7 +51,7 @@ begin sheet.WriteColWidth(2, 40.0, suMillimeters); // Create chart: left/top in cell D4, 150 mm x 150 mm - ch := book.AddChart(sheet, 2, 4, 150, 150); + ch := sheet.AddChart(150, 150, 2, 4); // Chart properties ch.Border.Style := clsNoLine; diff --git a/components/fpspreadsheet/examples/other/chart/errorbars_write_demo.lpr b/components/fpspreadsheet/examples/other/chart/errorbars_write_demo.lpr index 1883d7fd3..1b6255fa6 100644 --- a/components/fpspreadsheet/examples/other/chart/errorbars_write_demo.lpr +++ b/components/fpspreadsheet/examples/other/chart/errorbars_write_demo.lpr @@ -46,7 +46,7 @@ begin sheet.WriteNumber(8, 0, 6.8); sheet.WriteNumber(8, 1, 71.3); sheet.WriteNumber(8, 2, 3.5); // Create chart: left/top in cell D4, 150 mm x 100 mm - ch := book.AddChart(sheet, 2, 3, 150, 100); + ch := sheet.AddChart(150, 100, 2, 3); // Chart properties ch.Border.Style := clsNoLine; diff --git a/components/fpspreadsheet/examples/other/chart/linechart_write_demo.lpr b/components/fpspreadsheet/examples/other/chart/linechart_write_demo.lpr index 87544e230..1a155e46f 100644 --- a/components/fpspreadsheet/examples/other/chart/linechart_write_demo.lpr +++ b/components/fpspreadsheet/examples/other/chart/linechart_write_demo.lpr @@ -75,7 +75,7 @@ begin sheet.WriteText(10, 0, 'Computer'); sheet.WriteNumber(10, 1, 16); sheet.WriteNumber(10, 2, 18); // Create chart: left/top in cell D4, 160 mm x 100 mm - ch := book.AddChart(sheet, 2, 3, 160, 100); + ch := sheet.AddChart(160, 100, 2, 3); // Chart properties ch.Border.Style := clsNoLine; @@ -100,7 +100,7 @@ begin ser.SymbolFill.Color := ChartColor(scRed, 0.5); ser.SymbolFill.Style := cfsSolid; ser.SymbolBorder.Color := ChartColor(scBlack); - ser.Smooth := true; + ser.Interpolation := ciCubicSpline; // ser.GroupIndex := -1; // Add 2nd line series ("Student 2") diff --git a/components/fpspreadsheet/examples/other/chart/piechart_write_demo.lpr b/components/fpspreadsheet/examples/other/chart/piechart_write_demo.lpr index 062c330bd..bf73b365b 100644 --- a/components/fpspreadsheet/examples/other/chart/piechart_write_demo.lpr +++ b/components/fpspreadsheet/examples/other/chart/piechart_write_demo.lpr @@ -47,7 +47,7 @@ begin sheet.WriteText(8, 0, 'Oceania'); sheet.WriteNumber(8, 1, 42); // sheet.WriteChartColor(8, 2, $FF8080); // Create chart: left/top in cell D4, 150 mm x 150 mm - ch := book.AddChart(sheet, 2, 3, 150, 150); + ch := sheet.AddChart(150, 150, 2, 3); // Chart properties ch.Border.Style := clsNoLine; diff --git a/components/fpspreadsheet/examples/other/chart/radarchart_write_demo.lpr b/components/fpspreadsheet/examples/other/chart/radarchart_write_demo.lpr index 480f94fdf..4a4355d7e 100644 --- a/components/fpspreadsheet/examples/other/chart/radarchart_write_demo.lpr +++ b/components/fpspreadsheet/examples/other/chart/radarchart_write_demo.lpr @@ -38,7 +38,7 @@ begin sheet.WriteText(10, 0, 'Computer'); sheet.WriteNumber(10, 1, 16); sheet.WriteNumber(10, 2, 18); // Create chart: left/top in cell D4, 160 mm x 100 mm - ch := book.AddChart(sheet, 2, 3, 120, 100); + ch := sheet.AddChart(120, 100, 2, 3); // Chart properties ch.Border.Style := clsNoLine; diff --git a/components/fpspreadsheet/examples/other/chart/read_chart_demo.lpr b/components/fpspreadsheet/examples/other/chart/read_chart_demo.lpr index 25b2f0526..14039a638 100644 --- a/components/fpspreadsheet/examples/other/chart/read_chart_demo.lpr +++ b/components/fpspreadsheet/examples/other/chart/read_chart_demo.lpr @@ -68,6 +68,10 @@ begin end; const + FOLDER = 'files/'; + +// Uncomment one of the following FILE_NAMEs + // FILE_NAME = 'test.ods'; // FILE_NAME = 'area.ods'; // FILE_NAME = 'bars.ods'; @@ -81,14 +85,12 @@ var series: TsChartSeries; trendline: TsChartTrendline; i, j: Integer; - isODS: Boolean; begin FormatSettings.DecimalSeparator := '.'; - isODS := ExtractFileExt(FILE_NAME) = '.ods'; book := TsWorkbook.Create; try - book.ReadFromFile(FILE_NAME); + book.ReadFromFile(FOLDER + FILE_NAME); for i := 0 to book.GetChartCount-1 do begin chart := book.GetChartByIndex(i); diff --git a/components/fpspreadsheet/examples/other/chart/regressionchart_write_demo.lpr b/components/fpspreadsheet/examples/other/chart/regressionchart_write_demo.lpr index 0fabf33f1..850f78f65 100644 --- a/components/fpspreadsheet/examples/other/chart/regressionchart_write_demo.lpr +++ b/components/fpspreadsheet/examples/other/chart/regressionchart_write_demo.lpr @@ -42,7 +42,7 @@ begin sheet.WriteNumber(8, 0, 6.8); sheet.WriteNumber(8, 1, 71.3); // Create chart: left/top in cell D4, 150 mm x 100 mm - ch := book.AddChart(sheet, 2, 3, 150, 100); + ch := book.AddChart(sheet, 150, 100, 2, 3); // Chart properties ch.Border.Style := clsNoLine; diff --git a/components/fpspreadsheet/examples/other/chart/scatter_write_demo.lpr b/components/fpspreadsheet/examples/other/chart/scatter_write_demo.lpr index eb13313fa..5e1611a1d 100644 --- a/components/fpspreadsheet/examples/other/chart/scatter_write_demo.lpr +++ b/components/fpspreadsheet/examples/other/chart/scatter_write_demo.lpr @@ -97,7 +97,7 @@ begin end; // Create chart: left/top in cell D4, 160 mm x 100 mm - ch := book.AddChart(sheet, 2, 2, 160, 100); + ch := sheet.AddChart(160, 100, 2, 2); // Chart properties ch.Border.Style := clsNoLine; diff --git a/components/fpspreadsheet/examples/other/chart/stock_volume_write_demo.lpr b/components/fpspreadsheet/examples/other/chart/stock_volume_write_demo.lpr index e3891bd4a..327a54eca 100644 --- a/components/fpspreadsheet/examples/other/chart/stock_volume_write_demo.lpr +++ b/components/fpspreadsheet/examples/other/chart/stock_volume_write_demo.lpr @@ -113,7 +113,7 @@ begin WriteData(r, d, 95000, 110, 119, 103, 115); // Create chart: left/top in cell D4, 160 mm x 100 mm - ch := book.AddChart(sheet, 2, 6, 160, 100); + ch := sheet.AddChart(160, 100, 2, 6); // Chart properties ch.RotatedAxes := rotated; diff --git a/components/fpspreadsheet/examples/other/chart/stock_write_demo.lpr b/components/fpspreadsheet/examples/other/chart/stock_write_demo.lpr index ece761f04..aea928765 100644 --- a/components/fpspreadsheet/examples/other/chart/stock_write_demo.lpr +++ b/components/fpspreadsheet/examples/other/chart/stock_write_demo.lpr @@ -87,7 +87,7 @@ begin WriteData(r, d, 110, 119, 103, 115); // Create chart: left/top in cell D4, 160 mm x 100 mm - ch := book.AddChart(sheet, 2, 5, 160, 100); + ch := book.AddChart(sheet, 160, 100, 2, 5); // Chart properties ch.Border.Style := clsNoLine; diff --git a/components/fpspreadsheet/examples/other/chart/write_chart_demo.lpr b/components/fpspreadsheet/examples/other/chart/write_chart_demo.lpr index 8c0461c7b..0b42dcd88 100644 --- a/components/fpspreadsheet/examples/other/chart/write_chart_demo.lpr +++ b/components/fpspreadsheet/examples/other/chart/write_chart_demo.lpr @@ -56,7 +56,7 @@ begin sheet1.WriteNumber(r2, 3, r2*r2); // Create chart - ch := book.AddChart(sheet1, 4, 6, 160, 100); + ch := book.AddChart(sheet1, 160, 100, 4, 6); // Add first series (type depending on SERIES_CLASS) ser := SERIES_CLASS.Create(ch); diff --git a/components/fpspreadsheet/source/common/fpsopendocument.pas b/components/fpspreadsheet/source/common/fpsopendocument.pas index ad2384d20..4bdc4d890 100644 --- a/components/fpspreadsheet/source/common/fpsopendocument.pas +++ b/components/fpspreadsheet/source/common/fpsopendocument.pas @@ -5154,7 +5154,7 @@ procedure TsSpreadOpenDocReader.ReadShape(ANode: TDOMNode; if entry.IsChartRoot and ((entry.FileName = href) or ('./' + entry.FileName = href)) then begin (FWorksheet as TsWorksheet).CalcObjectCell(x, y, w, h, r, c, dy, dx); - chart := (FWorkbook as TsWorkbook).AddChart(FWorksheet, r, c, w, h, dx, dy); + chart := (FWorksheet as TsWorksheet).AddChart(w, h, r, c, dx, dy); chart.Name := entry.FileName; handled := true; break; diff --git a/components/fpspreadsheet/source/common/fpspreadsheet.pas b/components/fpspreadsheet/source/common/fpspreadsheet.pas index 94130e821..0011aa8a5 100644 --- a/components/fpspreadsheet/source/common/fpspreadsheet.pas +++ b/components/fpspreadsheet/source/common/fpspreadsheet.pas @@ -644,8 +644,8 @@ type {$ifdef FPS_CHARTS} { Chart support } - function AddChart(ARow, ACol: Cardinal; - AWidth, AHeight: Double; AOffsetX: Double = 0.0; AOffsetY: Double = 0.0): TsChart; + function AddChart(AWidth, AHeight: Double; ARow, ACol: Cardinal; + AOffsetX: Double = 0.0; AOffsetY: Double = 0.0): TsChart; function GetChartCount: Integer; procedure RemoveAllCharts; procedure RemoveChart(AChart: TsChart); @@ -945,8 +945,8 @@ type {$ifdef FPS_CHARTS} { Charts } - function AddChart(ASheet: TsBasicWorksheet; ARow, ACol: Cardinal; - AWidth, AHeight: Double; AOffsetX: Double = 0.0; AOffsetY: Double = 0.0): TsChart; + function AddChart(ASheet: TsBasicWorksheet; AWidth, AHeight: Double; + ARow, ACol: Cardinal; AOffsetX: Double = 0.0; AOffsetY: Double = 0.0): TsChart; function GetChartByIndex(AIndex: Integer): TsChart; function GetChartCount: Integer; {$endif} diff --git a/components/fpspreadsheet/source/common/fpspreadsheet_chart.inc b/components/fpspreadsheet/source/common/fpspreadsheet_chart.inc index c9f3d80b4..00e6b952b 100644 --- a/components/fpspreadsheet/source/common/fpspreadsheet_chart.inc +++ b/components/fpspreadsheet/source/common/fpspreadsheet_chart.inc @@ -8,18 +8,18 @@ {@@ ---------------------------------------------------------------------------- Adds a chart to the worksheet. - @param ARow Index of the row in which the top of the chart should be positioned. - @param ACol Index of the column in which the left side of the chart should be positioned. @param AWidth Width of the chart, in workbook units @param AHeight Height of the chart, in workbook units + @param ARow Index of the row in which the top of the chart should be positioned. + @param ACol Index of the column in which the left side of the chart should be positioned. @param AOffsetX Distance of the chart's left side from the left side of column ACol, in workbook units @param AOffsetY Distance of the chart's top side from the top side of row ARow, in workbook units @returns The instance of the created chart -------------------------------------------------------------------------------} -function TsWorksheet.AddChart(ARow, ACol: Cardinal; AWidth, AHeight: Double; +function TsWorksheet.AddChart(AWidth, AHeight: Double; ARow, ACol: Cardinal; AOffsetX: Double = 0.0; AOffsetY: Double = 0.0): TsChart; begin - Result := Workbook.AddChart(self, ARow, ACol, AWidth, AHeight, AOffsetX, AOffsetY); + Result := Workbook.AddChart(self, AWidth, AHeight, ARow, ACol, AOffsetX, AOffsetY); end; {@@ ---------------------------------------------------------------------------- @@ -76,21 +76,21 @@ end; {@@ ---------------------------------------------------------------------------- Creates a chart object with its top/left corner in the specified row/colum and - having the specified width (in workbook units). + having the specified width and height (in workbook units). Inserts the chart in the internal FCharts list of the workbook and returns the chart instance. @param ASheet Worksheet into which the chart will be inserted. - @param ARow Index of the row in which the top of the chart should be positioned. - @param ACol Index of the column in which the left side of the chart should be positioned. @param AWidth Width of the chart, in workbook units (usually millimeters) @param AHeight Height of the chart, in workbook units + @param ARow Index of the row in which the top of the chart should be positioned. + @param ACol Index of the column in which the left side of the chart should be positioned. @param AOffsetX Distance of the chart's left side from the left side of column ACol, in workbook units @param AOffsetY Distance of the chart's top side from the top side of row ARow, in workbook units @returns The instance of the created chart -------------------------------------------------------------------------------} -function TsWorkbook.AddChart(ASheet: TsBasicWorksheet; ARow, ACol: Cardinal; - AWidth, AHeight: Double; AOffsetX: Double = 0.0; AOffsetY: Double = 0.0): TsChart; +function TsWorkbook.AddChart(ASheet: TsBasicWorksheet; AWidth, AHeight: Double; + ARow, ACol: Cardinal; AOffsetX: Double = 0.0; AOffsetY: Double = 0.0): TsChart; begin Result := TsChart.Create; if (ASheet = nil) then diff --git a/components/fpspreadsheet/source/common/xlsxooxml.pas b/components/fpspreadsheet/source/common/xlsxooxml.pas index 1847ec7c0..95a58be1f 100644 --- a/components/fpspreadsheet/source/common/xlsxooxml.pas +++ b/components/fpspreadsheet/source/common/xlsxooxml.pas @@ -3044,7 +3044,7 @@ begin w := w + sheet.GetColWidth(j, suMillimeters); for j := data.FromRow to data.ToRow-1 do h := h + sheet.GetRowHeight(j, suMillimeters); - chart := TsWorkbook(FWorkbook).AddChart(sheet, data.FromRow, data.FromCol, w, h, data.FromRowOffs, data.FromColOffs); + chart := sheet.AddChart(w, h, data.FromRow, data.FromCol, data.FromRowOffs, data.FromColOffs); TsSpreadOOXMLChartReader(FChartReader).ReadChartXML(AStream, chart, data.MediaName); end else {$endif}