You've already forked lazarus-ccr
fpspreadsheet: Chart link supports 100%-stacking for bar, area and line series.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9050 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -18,6 +18,7 @@ object Form1: TForm1
|
|||||||
PageBreakPen.Color = clBlue
|
PageBreakPen.Color = clBlue
|
||||||
PageBreakPen.Style = psDash
|
PageBreakPen.Style = psDash
|
||||||
ReadFormulas = False
|
ReadFormulas = False
|
||||||
|
TextOverflow = True
|
||||||
WorkbookSource = sWorkbookSource1
|
WorkbookSource = sWorkbookSource1
|
||||||
Align = alLeft
|
Align = alLeft
|
||||||
AutoAdvance = aaDown
|
AutoAdvance = aaDown
|
||||||
|
@ -35,8 +35,8 @@ implementation
|
|||||||
{$R *.lfm}
|
{$R *.lfm}
|
||||||
|
|
||||||
const
|
const
|
||||||
// FILE_NAME = '../../../other/chart/bars.ods';
|
FILE_NAME = '../../../other/chart/bars.ods';
|
||||||
FILE_NAME = '../../../other/chart/area.ods';
|
// FILE_NAME = '../../../other/chart/area.ods';
|
||||||
// FILE_NAME = '../../../other/chart/area-sameImg.ods';
|
// FILE_NAME = '../../../other/chart/area-sameImg.ods';
|
||||||
// FILE_NAME = '../../../other/chart/pie.ods';
|
// FILE_NAME = '../../../other/chart/pie.ods';
|
||||||
// FILE_NAME = '../../../other/chart/scatter.ods';
|
// FILE_NAME = '../../../other/chart/scatter.ods';
|
||||||
|
@ -22,7 +22,7 @@ uses
|
|||||||
// LCL
|
// LCL
|
||||||
LCLVersion, Forms, Controls, Graphics, GraphUtil, Dialogs,
|
LCLVersion, Forms, Controls, Graphics, GraphUtil, Dialogs,
|
||||||
// TAChart
|
// TAChart
|
||||||
TATypes, TATextElements, TAChartUtils, TALegend, TACustomSource,
|
TATypes, TATextElements, TAChartUtils, TALegend, TACustomSource, TASources,
|
||||||
TACustomSeries, TASeries, TARadialSeries, TAFitUtils, TAFuncSeries,
|
TACustomSeries, TASeries, TARadialSeries, TAFitUtils, TAFuncSeries,
|
||||||
TAChartAxisUtils, TAChartAxis, TAStyles, TAGraph,
|
TAChartAxisUtils, TAChartAxis, TAStyles, TAGraph,
|
||||||
// FPSpreadsheet
|
// FPSpreadsheet
|
||||||
@ -888,6 +888,7 @@ var
|
|||||||
stackable: Boolean;
|
stackable: Boolean;
|
||||||
firstSeries: TChartSeries;
|
firstSeries: TChartSeries;
|
||||||
src: TsWorkbookChartSource;
|
src: TsWorkbookChartSource;
|
||||||
|
calcSrc: TCalculatedChartSource;
|
||||||
style: TChartStyle;
|
style: TChartStyle;
|
||||||
begin
|
begin
|
||||||
if FChart.Series.Count > 0 then
|
if FChart.Series.Count > 0 then
|
||||||
@ -901,8 +902,23 @@ begin
|
|||||||
begin
|
begin
|
||||||
// A stackable series in TAChart must use multiple y values.
|
// A stackable series in TAChart must use multiple y values.
|
||||||
Result := firstSeries;
|
Result := firstSeries;
|
||||||
|
// For percent-stacking we need an additional chart source, a TCalculatedChartSource
|
||||||
|
// which gets its data from the workbook chart source.
|
||||||
|
if (firstSeries.Source is TCalculatedChartSource) then
|
||||||
|
begin
|
||||||
|
calcSrc := TCalculatedChartSource(firstSeries.Source);
|
||||||
|
if (calcSrc.Origin is TsWorkbookChartSource) then
|
||||||
|
src := TsWorkbookChartSource(calcSrc.Origin);
|
||||||
|
end else
|
||||||
|
// ... otherwise we use the workbook chartsource directly.
|
||||||
|
if (firstSeries.Source is TsWorkbookChartSource) then
|
||||||
|
begin
|
||||||
src := (firstSeries.Source as TsWorkbookChartSource);
|
src := (firstSeries.Source as TsWorkbookChartSource);
|
||||||
src.SetYRange(src.YCount, ASeries.YRange);
|
calcSrc := nil;
|
||||||
|
end else
|
||||||
|
raise Exception.Create('Unexpected chart source type.');
|
||||||
|
|
||||||
|
src.SetYRange(src.YCount, ASeries.YRange); // <--- This updates also the YCount
|
||||||
src.FRangeStr[rngY] := src.BuildRangeStr(rngY);
|
src.FRangeStr[rngY] := src.BuildRangeStr(rngY);
|
||||||
if Result is TBarSeries then
|
if Result is TBarSeries then
|
||||||
TBarSeries(Result).Styles := FChartStyles
|
TBarSeries(Result).Styles := FChartStyles
|
||||||
@ -912,9 +928,17 @@ begin
|
|||||||
TAreaSeries(Result).Styles := FChartStyles;
|
TAreaSeries(Result).Styles := FChartStyles;
|
||||||
Result.Legend.Multiplicity := lmStyle;
|
Result.Legend.Multiplicity := lmStyle;
|
||||||
src.SetTitleAddr(ASeries.TitleAddr);
|
src.SetTitleAddr(ASeries.TitleAddr);
|
||||||
|
|
||||||
|
// Trigger recalculation of YCount of the calculated chart source.
|
||||||
|
if calcSrc <> nil then
|
||||||
|
begin
|
||||||
|
calcSrc.Origin := nil;
|
||||||
|
calcSrc.Origin := src;
|
||||||
|
end;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
|
// This is either for a non-stackable or the first stackable series.
|
||||||
case ASeries.ChartType of
|
case ASeries.ChartType of
|
||||||
ctBar:
|
ctBar:
|
||||||
Result := TBarSeries.Create(FChart);
|
Result := TBarSeries.Create(FChart);
|
||||||
@ -933,6 +957,13 @@ begin
|
|||||||
if not ASeries.YRange.IsEmpty then src.SetYRange(0, ASeries.YRange);
|
if not ASeries.YRange.IsEmpty then src.SetYRange(0, ASeries.YRange);
|
||||||
if not ASeries.FillColorRange.IsEmpty then src.SetColorRange(ASeries.FillColorRange);
|
if not ASeries.FillColorRange.IsEmpty then src.SetColorRange(ASeries.FillColorRange);
|
||||||
src.SetTitleAddr(ASeries.TitleAddr);
|
src.SetTitleAddr(ASeries.TitleAddr);
|
||||||
|
|
||||||
|
if stackable then begin
|
||||||
|
calcSrc := TCalculatedChartSource.Create(self);
|
||||||
|
calcSrc.Origin := src;
|
||||||
|
Result.Source := calcSrc;
|
||||||
|
src.Reset;
|
||||||
|
end else
|
||||||
Result.Source := src;
|
Result.Source := src;
|
||||||
Result.Title := src.Title;
|
Result.Title := src.Title;
|
||||||
end;
|
end;
|
||||||
@ -980,7 +1011,7 @@ procedure TsWorkbookChartLink.ClearChart;
|
|||||||
var
|
var
|
||||||
i, j: Integer;
|
i, j: Integer;
|
||||||
ser: TChartSeries;
|
ser: TChartSeries;
|
||||||
src: TCustomChartSource;
|
src, src1: TCustomChartSource;
|
||||||
begin
|
begin
|
||||||
// Clear the styles
|
// Clear the styles
|
||||||
FChartStyles.Styles.Clear;
|
FChartStyles.Styles.Clear;
|
||||||
@ -995,6 +1026,13 @@ begin
|
|||||||
begin
|
begin
|
||||||
ser := TChartSeries(FChart.Series[i]);
|
ser := TChartSeries(FChart.Series[i]);
|
||||||
src := ser.Source;
|
src := ser.Source;
|
||||||
|
if src is TCalculatedChartSource then
|
||||||
|
begin
|
||||||
|
src1 := TCalculatedChartSource(src).Origin;
|
||||||
|
if src1 is TsWorkbookChartSource then
|
||||||
|
src1.Free;
|
||||||
|
src.Free;
|
||||||
|
end else
|
||||||
if src is TsWorkbookChartSource then
|
if src is TsWorkbookChartSource then
|
||||||
src.Free;
|
src.Free;
|
||||||
end;
|
end;
|
||||||
@ -1287,11 +1325,9 @@ begin
|
|||||||
UpdateChartBrush(AWorkbookSeries.Chart, AWorkbookSeries.Fill, AChartSeries.AreaBrush);
|
UpdateChartBrush(AWorkbookSeries.Chart, AWorkbookSeries.Fill, AChartSeries.AreaBrush);
|
||||||
UpdateChartPen(AWorkbookSeries.Chart, AWorkbookSeries.Line, AChartSeries.AreaContourPen);
|
UpdateChartPen(AWorkbookSeries.Chart, AWorkbookSeries.Line, AChartSeries.AreaContourPen);
|
||||||
AChartSeries.AreaLinesPen.Style := psClear;
|
AChartSeries.AreaLinesPen.Style := psClear;
|
||||||
case AWorkbookSeries.Chart.StackMode of
|
AChartSeries.Stacked := AWorkbookSeries.Chart.StackMode <> csmSideBySide;
|
||||||
csmSideBySide: AChartSeries.Stacked := false;
|
if AChartSeries.Source is TCalculatedChartSource then
|
||||||
csmStacked: AChartSeries.Stacked := true;
|
TCalculatedChartSource(AChartSeries.Source).Percentage := (AWorkbookSeries.Chart.StackMode = csmStackedPercentage);
|
||||||
csmStackedPercentage: AChartSeries.Stacked := true;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TsWorkbookChartLink.UpdateBarSeries(AWorkbookSeries: TsBarSeries;
|
procedure TsWorkbookChartLink.UpdateBarSeries(AWorkbookSeries: TsBarSeries;
|
||||||
@ -1299,11 +1335,9 @@ procedure TsWorkbookChartLink.UpdateBarSeries(AWorkbookSeries: TsBarSeries;
|
|||||||
begin
|
begin
|
||||||
UpdateChartBrush(AWorkbookSeries.Chart, AWorkbookSeries.Fill, AChartSeries.BarBrush);
|
UpdateChartBrush(AWorkbookSeries.Chart, AWorkbookSeries.Fill, AChartSeries.BarBrush);
|
||||||
UpdateChartPen(AWorkbookSeries.Chart, AWorkbookSeries.Line, AChartSeries.BarPen);
|
UpdateChartPen(AWorkbookSeries.Chart, AWorkbookSeries.Line, AChartSeries.BarPen);
|
||||||
case AWorkbookSeries.Chart.StackMode of
|
AChartSeries.Stacked := AWorkbookSeries.Chart.StackMode <> csmSideBySide;
|
||||||
csmSideBySide: AChartSeries.Stacked := false;
|
if AChartSeries.Source is TCalculatedChartSource then
|
||||||
csmStacked: AChartSeries.Stacked := true;
|
TCalculatedChartSource(AChartSeries.Source).Percentage := (AWorkbookSeries.Chart.StackMode = csmStackedPercentage);
|
||||||
csmStackedPercentage: AChartSeries.Stacked := true;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TsWorkbookChartLink.UpdateChart;
|
procedure TsWorkbookChartLink.UpdateChart;
|
||||||
@ -1672,11 +1706,9 @@ begin
|
|||||||
AChartSeries.Pointer.HorizSize := mmToPx(AWorkbookSeries.SymbolWidth, ppi);
|
AChartSeries.Pointer.HorizSize := mmToPx(AWorkbookSeries.SymbolWidth, ppi);
|
||||||
AChartSeries.Pointer.VertSize := mmToPx(AWorkbookSeries.SymbolHeight, ppi);
|
AChartSeries.Pointer.VertSize := mmToPx(AWorkbookSeries.SymbolHeight, ppi);
|
||||||
end;
|
end;
|
||||||
case AWorkbookSeries.Chart.StackMode of
|
AChartSeries.Stacked := AWorkbookSeries.Chart.StackMode <> csmSideBySide;
|
||||||
csmSideBySide: AChartSeries.Stacked := false;
|
if AChartSeries.Source is TCalculatedChartSource then
|
||||||
csmStacked: AChartSeries.Stacked := true;
|
TCalculatedChartSource(AChartSeries.Source).Percentage := (AWorkbookSeries.Chart.StackMode = csmStackedPercentage);
|
||||||
csmStackedPercentage: AChartSeries.Stacked := true;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TsWorkbookChartLink.UpdatePieSeries(AWorkbookSeries: TsPieSeries;
|
procedure TsWorkbookChartLink.UpdatePieSeries(AWorkbookSeries: TsPieSeries;
|
||||||
|
Reference in New Issue
Block a user