You've already forked lazarus-ccr
fpspreadsheet: Improved user interface for adding datapoint styles in workbook charts.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9064 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -57,11 +57,11 @@ begin
|
|||||||
|
|
||||||
// Individual sector colors
|
// Individual sector colors
|
||||||
// Must be complete, otherwise will be ignored by Calc and replaced by default colors
|
// Must be complete, otherwise will be ignored by Calc and replaced by default colors
|
||||||
ser.AddDataPointStyle(scYellow);
|
ser.DataPointStyles.AddSolidFill($C47244);
|
||||||
ser.AddDataPointStyle(scMaroon);
|
ser.DataPointStyles.AddSolidFill($317DED);
|
||||||
ser.AddDataPointStyle(scRed);
|
ser.DataPointStyles.AddSolidFill($A5A5A5);
|
||||||
ser.AddDataPointStyle(scWhite);
|
ser.DataPointStyles.AddSolidFill($00C0FF);
|
||||||
ser.AddDatapointStyle(scBlue);
|
ser.DataPointStyles.AddSolidFill($D69B5B);
|
||||||
|
|
||||||
//ser.SetFillColorRange(4, 2, 8, 2);
|
//ser.SetFillColorRange(4, 2, 8, 2);
|
||||||
|
|
||||||
|
@ -316,6 +316,18 @@ type
|
|||||||
|
|
||||||
TsChartDataPointStyle = class(TsChartFillElement);
|
TsChartDataPointStyle = class(TsChartFillElement);
|
||||||
|
|
||||||
|
TsChartDataPointStyleList = class(TFPObjectList)
|
||||||
|
private
|
||||||
|
FChart: TsChart;
|
||||||
|
function GetItem(AIndex: Integer): TsChartDataPointStyle;
|
||||||
|
procedure SetItem(AIndex: Integer; AValue: TsChartDataPointStyle);
|
||||||
|
public
|
||||||
|
constructor Create(AChart: TsChart);
|
||||||
|
function AddFillAndLine(AFill: TsChartFill; ALine: TsChartline; ACount: Integer = 1): Integer;
|
||||||
|
function AddSolidFill(AColor: TsColor; ACount: Integer = 1): Integer;
|
||||||
|
property Items[AIndex: Integer]: TsChartDataPointStyle read GetItem write SetItem; default;
|
||||||
|
end;
|
||||||
|
|
||||||
TsChartSeries = class(TsChartElement)
|
TsChartSeries = class(TsChartElement)
|
||||||
private
|
private
|
||||||
FChartType: TsChartType;
|
FChartType: TsChartType;
|
||||||
@ -335,14 +347,12 @@ type
|
|||||||
FLine: TsChartLine;
|
FLine: TsChartLine;
|
||||||
FFill: TsChartFill;
|
FFill: TsChartFill;
|
||||||
FDataLabels: TsChartDataLabels;
|
FDataLabels: TsChartDataLabels;
|
||||||
FDataPointStyles: TFPObjectList;
|
FDataPointStyles: TsChartDataPointStyleList;
|
||||||
protected
|
protected
|
||||||
function GetChartType: TsChartType; virtual;
|
function GetChartType: TsChartType; virtual;
|
||||||
public
|
public
|
||||||
constructor Create(AChart: TsChart); virtual;
|
constructor Create(AChart: TsChart); virtual;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
procedure AddDataPointStyle(AFill: TsChartFill; ALine: TsChartLine; ACount: Integer = 1);
|
|
||||||
procedure AddDataPointStyle(AColor: TsColor; ACount: Integer = 1);
|
|
||||||
function GetCount: Integer;
|
function GetCount: Integer;
|
||||||
function GetXCount: Integer;
|
function GetXCount: Integer;
|
||||||
function GetYCount: Integer;
|
function GetYCount: Integer;
|
||||||
@ -368,7 +378,7 @@ type
|
|||||||
property ChartType: TsChartType read GetChartType;
|
property ChartType: TsChartType read GetChartType;
|
||||||
property Count: Integer read GetCount;
|
property Count: Integer read GetCount;
|
||||||
property DataLabels: TsChartDataLabels read FDataLabels write FDataLabels;
|
property DataLabels: TsChartDataLabels read FDataLabels write FDataLabels;
|
||||||
property DataPointStyles: TFPObjectList read FDataPointStyles;
|
property DataPointStyles: TsChartDatapointStyleList read FDataPointStyles;
|
||||||
property FillColorRange: TsChartRange read FFillColorRange write FFillColorRange;
|
property FillColorRange: TsChartRange read FFillColorRange write FFillColorRange;
|
||||||
property LabelBackground: TsChartFill read FLabelBackground write FLabelBackground;
|
property LabelBackground: TsChartFill read FLabelBackground write FLabelBackground;
|
||||||
property LabelBorder: TsChartLine read FLabelBorder write FLabelBorder;
|
property LabelBorder: TsChartLine read FLabelBorder write FLabelBorder;
|
||||||
@ -1203,6 +1213,70 @@ begin
|
|||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TsChartDataPointStyleList }
|
||||||
|
|
||||||
|
constructor TsChartDataPointStyleList.Create(AChart: TsChart);
|
||||||
|
begin
|
||||||
|
inherited Create;
|
||||||
|
FChart := AChart;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TsChartDataPointStyleList.AddFillAndLine(AFill: TsChartFill; ALine: TsChartLine;
|
||||||
|
ACount: Integer = 1): Integer;
|
||||||
|
var
|
||||||
|
dataPointStyle: TsChartDataPointStyle;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
if (AFill = nil) and (ALine = nil) then
|
||||||
|
for i := 1 to ACount do
|
||||||
|
Result := inherited Add(nil)
|
||||||
|
else
|
||||||
|
for i := 1 to ACount do
|
||||||
|
begin
|
||||||
|
dataPointStyle := TsChartDataPointStyle.Create(FChart);
|
||||||
|
if AFill <> nil then
|
||||||
|
dataPointStyle.Background.CopyFrom(AFill)
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
dataPointStyle.Background.Free;
|
||||||
|
dataPointStyle.Background := nil;
|
||||||
|
end;
|
||||||
|
if ALine <> nil then
|
||||||
|
dataPointStyle.Border.CopyFrom(ALine)
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
dataPointStyle.Border.Free;
|
||||||
|
dataPointStyle.Border := nil;
|
||||||
|
end;
|
||||||
|
Result := inherited Add(dataPointStyle);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TsChartDataPointStyleList.AddSolidFill(AColor: TsColor; ACount: Integer = 1): Integer;
|
||||||
|
var
|
||||||
|
fill: TsChartFill;
|
||||||
|
begin
|
||||||
|
fill := TsChartFill.Create;
|
||||||
|
try
|
||||||
|
fill.Style := cfsSolid;
|
||||||
|
fill.Color := AColor;
|
||||||
|
Result := AddFillAndLine(fill, nil, ACount);
|
||||||
|
finally
|
||||||
|
fill.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TsChartDataPointStyleList.GetItem(AIndex: Integer): TsChartDataPointStyle;
|
||||||
|
begin
|
||||||
|
Result := TsChartDataPointStyle(inherited Items[AIndex]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TsChartDataPointStyleList.SetItem(AIndex: Integer;
|
||||||
|
AValue: TsChartDataPointStyle);
|
||||||
|
begin
|
||||||
|
inherited Items[AIndex] := AValue;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
{ TsChartSeries }
|
{ TsChartSeries }
|
||||||
|
|
||||||
@ -1232,7 +1306,7 @@ begin
|
|||||||
FLine.Width := PtsToMM(DEFAULT_CHART_LINEWIDTH);
|
FLine.Width := PtsToMM(DEFAULT_CHART_LINEWIDTH);
|
||||||
FLine.Color := DEFAULT_SERIES_COLORS[idx mod Length(DEFAULT_SERIES_COLORS)];
|
FLine.Color := DEFAULT_SERIES_COLORS[idx mod Length(DEFAULT_SERIES_COLORS)];
|
||||||
|
|
||||||
FDataPointStyles := TFPObjectList.Create;
|
FDataPointStyles := TsChartDataPointStyleList.Create(AChart);
|
||||||
|
|
||||||
FLabelFont := TsFont.Create;
|
FLabelFont := TsFont.Create;
|
||||||
FLabelFont.Size := 9;
|
FLabelFont.Size := 9;
|
||||||
@ -1265,39 +1339,6 @@ begin
|
|||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TsChartSeries.AddDataPointStyle(AFill: TsChartFill; ALine: TsChartLine;
|
|
||||||
ACount: Integer = 1);
|
|
||||||
var
|
|
||||||
i: Integer;
|
|
||||||
dataPointStyle: TsChartDataPointStyle;
|
|
||||||
begin
|
|
||||||
if (AFill = nil) and (ALine = nil) then
|
|
||||||
for i := 1 to ACount do
|
|
||||||
FDataPointStyles.Add(nil)
|
|
||||||
else
|
|
||||||
for i := 1 to ACount do
|
|
||||||
begin
|
|
||||||
dataPointStyle := TsChartDataPointStyle.Create(FChart);
|
|
||||||
dataPointStyle.Background.CopyFrom(AFill);
|
|
||||||
dataPointStyle.Border.CopyFrom(ALine);
|
|
||||||
FDataPointStyles.Add(dataPointStyle);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TsChartSeries.AddDataPointStyle(AColor: TsColor; ACount: Integer = 1);
|
|
||||||
var
|
|
||||||
i: Integer;
|
|
||||||
datapointStyle: TsChartDataPointStyle;
|
|
||||||
begin
|
|
||||||
for i := 1 to ACount do
|
|
||||||
begin
|
|
||||||
datapointStyle := TsChartDatapointStyle.Create(FChart);
|
|
||||||
dataPointStyle.Background.Style:= cfsSolid;
|
|
||||||
dataPointStyle.Background.Color := AColor;
|
|
||||||
FDataPointStyles.Add(datapointStyle);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TsChartSeries.GetChartType: TsChartType;
|
function TsChartSeries.GetChartType: TsChartType;
|
||||||
begin
|
begin
|
||||||
Result := FChartType;
|
Result := FChartType;
|
||||||
|
@ -1310,7 +1310,7 @@ begin
|
|||||||
s := GetAttrValue(subnode, 'chart:repeated');
|
s := GetAttrValue(subnode, 'chart:repeated');
|
||||||
if (s <> '') then
|
if (s <> '') then
|
||||||
n := StrToIntDef(s, 1);
|
n := StrToIntDef(s, 1);
|
||||||
series.AddDataPointStyle(fill, line, n);
|
series.DataPointStyles.AddFillAndLine(fill, line, n);
|
||||||
fill.Free; // the styles have been copied to the series datapoint list and are not needed any more.
|
fill.Free; // the styles have been copied to the series datapoint list and are not needed any more.
|
||||||
line.Free;
|
line.Free;
|
||||||
end;
|
end;
|
||||||
@ -2309,6 +2309,10 @@ begin
|
|||||||
);
|
);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{@@ ----------------------------------------------------------------------------
|
||||||
|
Creates an xml string which contains the individual style of the
|
||||||
|
datapoint with index APointIndex of the series with index ASeriesIndex.
|
||||||
|
-------------------------------------------------------------------------------}
|
||||||
function TsSpreadOpenDocChartWriter.GetChartSeriesDataPointStyleAsXML(AChart: TsChart;
|
function TsSpreadOpenDocChartWriter.GetChartSeriesDataPointStyleAsXML(AChart: TsChart;
|
||||||
ASeriesIndex, APointIndex, AIndent, AStyleID: Integer): String;
|
ASeriesIndex, APointIndex, AIndent, AStyleID: Integer): String;
|
||||||
var
|
var
|
||||||
@ -2322,7 +2326,7 @@ begin
|
|||||||
indent := DupeString(' ', AIndent);
|
indent := DupeString(' ', AIndent);
|
||||||
|
|
||||||
series := AChart.Series[ASeriesIndex];
|
series := AChart.Series[ASeriesIndex];
|
||||||
dataPointStyle := TsChartDataPointStyle(series.DataPointStyles[APointIndex]);
|
dataPointStyle := series.DataPointStyles[APointIndex];
|
||||||
|
|
||||||
chartProps := 'chart:solid-type="cuboid" ';
|
chartProps := 'chart:solid-type="cuboid" ';
|
||||||
|
|
||||||
|
@ -896,10 +896,16 @@ begin
|
|||||||
SetRangeFromChart(rngY, YIndex, ARange);
|
SetRangeFromChart(rngY, YIndex, ARange);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{@@ ----------------------------------------------------------------------------
|
||||||
|
Extracts the fill color from the DataPointStyle items of the series. All the
|
||||||
|
other elements are ignored because TAChart does not support them.
|
||||||
|
-------------------------------------------------------------------------------}
|
||||||
procedure TsWorkbookChartSource.UseDataPointColors(ASeries: TsChartSeries);
|
procedure TsWorkbookChartSource.UseDataPointColors(ASeries: TsChartSeries);
|
||||||
var
|
var
|
||||||
datapointStyle: TsChartDataPointStyle;
|
datapointStyle: TsChartDataPointStyle;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
|
c: TsColor;
|
||||||
|
g: TsChartGradient;
|
||||||
begin
|
begin
|
||||||
if ASeries = nil then
|
if ASeries = nil then
|
||||||
begin
|
begin
|
||||||
@ -910,13 +916,27 @@ begin
|
|||||||
SetLength(FDataPointColors, ASeries.DataPointStyles.Count);
|
SetLength(FDataPointColors, ASeries.DataPointStyles.Count);
|
||||||
for i := 0 to High(FDataPointColors) do
|
for i := 0 to High(FDataPointColors) do
|
||||||
begin
|
begin
|
||||||
datapointStyle := TsChartDataPointStyle(ASeries.DatapointStyles[i]);
|
datapointStyle := ASeries.DatapointStyles[i];
|
||||||
FDataPointColors[i] := clTAColor;
|
FDataPointColors[i] := clTAColor;
|
||||||
if (dataPointStyle <> nil) and (datapointStyle.Background.Style = cfsSolid) then
|
if (dataPointStyle <> nil) and (dataPointStyle.Background <> nil) then
|
||||||
FDataPointColors[i] := Convert_sColor_to_Color(dataPointStyle.Background.Color);
|
begin
|
||||||
|
if (datapointStyle.Background.Style in [cfsSolid, cfsSolidHatched]) then
|
||||||
|
c := dataPointStyle.Background.Color
|
||||||
|
else
|
||||||
|
if (dataPointStyle.Background.Style = cfsGradient) then
|
||||||
|
begin
|
||||||
|
// TAChart does not support gradient fills. Let's use the start color
|
||||||
|
// of the gradient for a solid fill.
|
||||||
|
g := ASeries.Chart.Gradients[datapointStyle.Background.Gradient];
|
||||||
|
c := g.StartColor;
|
||||||
|
end else
|
||||||
|
Continue;
|
||||||
|
FDataPointColors[i] := Convert_sColor_to_Color(c);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
Setter method for the WorkbookSource
|
Setter method for the WorkbookSource
|
||||||
-------------------------------------------------------------------------------}
|
-------------------------------------------------------------------------------}
|
||||||
@ -1866,6 +1886,7 @@ end;
|
|||||||
procedure TsWorkbookChartLink.UpdatePieSeries(AWorkbookSeries: TsPieSeries;
|
procedure TsWorkbookChartLink.UpdatePieSeries(AWorkbookSeries: TsPieSeries;
|
||||||
AChartSeries: TPieSeries);
|
AChartSeries: TPieSeries);
|
||||||
begin
|
begin
|
||||||
|
UpdateChartPen(AWorkbookSeries.Chart, AWorkbookSeries.Line, AChartSeries.EdgePen);
|
||||||
AChartSeries.StartAngle := AWorkbookSeries.StartAngle;
|
AChartSeries.StartAngle := AWorkbookSeries.StartAngle;
|
||||||
AChartSeries.Legend.Multiplicity := lmPoint;
|
AChartSeries.Legend.Multiplicity := lmPoint;
|
||||||
AChartSeries.Legend.Format := '%2:s';
|
AChartSeries.Legend.Format := '%2:s';
|
||||||
|
Reference in New Issue
Block a user