You've already forked lazarus-ccr
fpspreadsheet: Logarithmic axis support in chart link.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9070 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -341,6 +341,7 @@ type
|
|||||||
FLabelFont: TsFont;
|
FLabelFont: TsFont;
|
||||||
FLabelPosition: TsChartLabelPosition;
|
FLabelPosition: TsChartLabelPosition;
|
||||||
FLabelSeparator: string;
|
FLabelSeparator: string;
|
||||||
|
FXAxis: TsChartAxisLink;
|
||||||
FYAxis: TsChartAxisLink;
|
FYAxis: TsChartAxisLink;
|
||||||
FTitleAddr: TsChartCellAddr;
|
FTitleAddr: TsChartCellAddr;
|
||||||
FLabelFormat: String;
|
FLabelFormat: String;
|
||||||
@@ -389,9 +390,10 @@ type
|
|||||||
property LabelSeparator: string read FLabelSeparator write FLabelSeparator;
|
property LabelSeparator: string read FLabelSeparator write FLabelSeparator;
|
||||||
property LineColorRange: TsChartRange read FLineColorRange write FLineColorRange;
|
property LineColorRange: TsChartRange read FLineColorRange write FLineColorRange;
|
||||||
property TitleAddr: TsChartCellAddr read FTitleAddr write FTitleAddr; // use '\n' for line-break
|
property TitleAddr: TsChartCellAddr read FTitleAddr write FTitleAddr; // use '\n' for line-break
|
||||||
|
property XAxis: TsChartAxisLink read FXAxis write FXAxis;
|
||||||
property XRange: TsChartRange read FXRange write FXRange;
|
property XRange: TsChartRange read FXRange write FXRange;
|
||||||
property YRange: TsChartRange read FYRange write FYRange;
|
|
||||||
property YAxis: TsChartAxisLink read FYAxis write FYAxis;
|
property YAxis: TsChartAxisLink read FYAxis write FYAxis;
|
||||||
|
property YRange: TsChartRange read FYRange write FYRange;
|
||||||
|
|
||||||
property Fill: TsChartFill read FFill write FFill;
|
property Fill: TsChartFill read FFill write FFill;
|
||||||
property Line: TsChartLine read FLine write FLine;
|
property Line: TsChartLine read FLine write FLine;
|
||||||
|
@@ -132,7 +132,11 @@ type
|
|||||||
procedure ConstructHatchPattern(AWorkbookChart: TsChart; AFill: TsChartFill; ABrush: TBrush);
|
procedure ConstructHatchPattern(AWorkbookChart: TsChart; AFill: TsChartFill; ABrush: TBrush);
|
||||||
procedure ConstructHatchPatternSolid(AWorkbookChart: TsChart; AFill: TsChartFill; ABrush: TBrush);
|
procedure ConstructHatchPatternSolid(AWorkbookChart: TsChart; AFill: TsChartFill; ABrush: TBrush);
|
||||||
procedure ConstructSeriesMarks(AWorkbookSeries: TsChartSeries; AChartSeries: TChartSeries);
|
procedure ConstructSeriesMarks(AWorkbookSeries: TsChartSeries; AChartSeries: TChartSeries);
|
||||||
|
function GetAutoscaleAxisTransform(AChartAxis: TChartAxis): TAutoScaleAxisTransform;
|
||||||
|
function GetAxisTransform(AChartAxis: TChartAxis; AClass: TAxisTransformClass): TAxisTransform;
|
||||||
|
function GetLogAxisTransform(AChartAxis: TChartAxis): TLogarithmAxisTransform;
|
||||||
function GetWorkbookChart: TsChart;
|
function GetWorkbookChart: TsChart;
|
||||||
|
function IsLogarithmic(Axis: TChartAxis): Boolean;
|
||||||
function IsSecondaryAxis(Axis: TsChartAxis): boolean;
|
function IsSecondaryAxis(Axis: TsChartAxis): boolean;
|
||||||
function IsStackable(ASeries: TsChartSeries): Boolean;
|
function IsStackable(ASeries: TsChartSeries): Boolean;
|
||||||
|
|
||||||
@@ -1099,7 +1103,13 @@ begin
|
|||||||
Result.Title := src.Title;
|
Result.Title := src.Title;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Assign series to axis for primary and secondary y axes support
|
// Assign series to axis for primary and secondary axes support
|
||||||
|
case ASeries.XAxis of
|
||||||
|
alPrimary:
|
||||||
|
Result.AxisIndexX := FChart.AxisList.GetAxisByAlign(calBottom).Index;
|
||||||
|
alSecondary:
|
||||||
|
Result.AxisIndexX := FChart.AxisList.GetAxisByAlign(calTop).Index;
|
||||||
|
end;
|
||||||
case ASeries.YAxis of
|
case ASeries.YAxis of
|
||||||
alPrimary:
|
alPrimary:
|
||||||
Result.AxisIndexY := FChart.AxisList.GetAxisByAlign(calLeft).Index;
|
Result.AxisIndexY := FChart.AxisList.GetAxisByAlign(calLeft).Index;
|
||||||
@@ -1459,6 +1469,30 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TsWorkbookChartLink.GetAutoScaleAxisTransform(AChartAxis: TChartAxis): TAutoScaleAxisTransform;
|
||||||
|
begin
|
||||||
|
Result := TAutoScaleAxisTransform(GetAxisTransform(AChartAxis, TAutoScaleAxisTransform));
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TsWorkbookChartLink.GetAxisTransform(AChartAxis: TChartAxis;
|
||||||
|
AClass: TAxisTransformClass): TAxisTransform;
|
||||||
|
var
|
||||||
|
T: TAxisTransform;
|
||||||
|
begin
|
||||||
|
for T in AChartAxis.Transformations.List do
|
||||||
|
if T is AClass then
|
||||||
|
begin
|
||||||
|
Result := T;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
Result := nil;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TsWorkbookChartLink.GetLogAxisTransform(AChartAxis: TChartAxis): TLogarithmAxisTransform;
|
||||||
|
begin
|
||||||
|
Result := TLogarithmAxisTransform(GetAxisTransform(AChartAxis, TLogarithmAxisTransform));
|
||||||
|
end;
|
||||||
|
|
||||||
function TsWorkbookChartLink.GetWorkbookChart: TsChart;
|
function TsWorkbookChartLink.GetWorkbookChart: TsChart;
|
||||||
begin
|
begin
|
||||||
if (FWorkbook <> nil) and (FWorkbookChartIndex > -1) then
|
if (FWorkbook <> nil) and (FWorkbookChartIndex > -1) then
|
||||||
@@ -1467,6 +1501,14 @@ begin
|
|||||||
Result := nil;
|
Result := nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TsWorkbookChartLink.IsLogarithmic(Axis: TChartAxis): Boolean;
|
||||||
|
var
|
||||||
|
T: TLogarithmAxisTransform;
|
||||||
|
begin
|
||||||
|
T := GetLogAxisTransform(Axis);
|
||||||
|
Result := (T <> nil) and T.Enabled;
|
||||||
|
end;
|
||||||
|
|
||||||
function TsWorkbookChartLink.IsSecondaryAxis(Axis: TsChartAxis): Boolean;
|
function TsWorkbookChartLink.IsSecondaryAxis(Axis: TsChartAxis): Boolean;
|
||||||
begin
|
begin
|
||||||
Result := (Axis = Axis.Chart.Y2Axis) or (Axis = Axis.Chart.X2Axis);
|
Result := (Axis = Axis.Chart.Y2Axis) or (Axis = Axis.Chart.X2Axis);
|
||||||
@@ -1669,6 +1711,25 @@ begin
|
|||||||
// Entire axis visible?
|
// Entire axis visible?
|
||||||
axis.Visible := AWorkbookAxis.Visible;
|
axis.Visible := AWorkbookAxis.Visible;
|
||||||
|
|
||||||
|
// Usually not needed, but axis handling is simplified when there is
|
||||||
|
// an axis transformations object at each axis with all transforms prepared.
|
||||||
|
if axis.Transformations = nil then
|
||||||
|
begin
|
||||||
|
axis.Transformations := TChartAxisTransformations.Create(FChart);
|
||||||
|
|
||||||
|
// Logarithmic
|
||||||
|
T := TLogarithmAxisTransform.Create(axis.Transformations);
|
||||||
|
T.Transformations := axis.Transformations;
|
||||||
|
TLogarithmAxisTransform(T).Base := 10;
|
||||||
|
TLogarithmAxisTransform(T).Enabled := AWorkbookAxis.Logarithmic;
|
||||||
|
|
||||||
|
// Autoscale transformation for primary and secondary axes
|
||||||
|
T := TAutoScaleAxisTransform.Create(axis.Transformations);
|
||||||
|
T.Transformations := axis.Transformations;
|
||||||
|
if AWorkbookAxis.Logarithmic or (AWorkbookAxis.Chart.GetChartType in [ctRadar, ctFilledRadar]) then
|
||||||
|
T.Enabled := false;
|
||||||
|
end;
|
||||||
|
|
||||||
// Axis title
|
// Axis title
|
||||||
axis.Title.Caption := AWorkbookAxis.Title.Caption;
|
axis.Title.Caption := AWorkbookAxis.Title.Caption;
|
||||||
axis.Title.Visible := true;
|
axis.Title.Visible := true;
|
||||||
@@ -1697,7 +1758,10 @@ begin
|
|||||||
minorAxis := axis.Minors.Add;
|
minorAxis := axis.Minors.Add;
|
||||||
UpdateChartPen(AWorkbookAxis.Chart, AWorkbookAxis.MinorGridLines, minorAxis.Grid);
|
UpdateChartPen(AWorkbookAxis.Chart, AWorkbookAxis.MinorGridLines, minorAxis.Grid);
|
||||||
minorAxis.Grid.Visible := not IsSecondaryAxis(AWorkbookAxis);
|
minorAxis.Grid.Visible := not IsSecondaryAxis(AWorkbookAxis);
|
||||||
minorAxis.Intervals.Count := AWorkbookAxis.MinorCount;
|
if AWorkbookAxis.Logarithmic then
|
||||||
|
minorAxis.Intervals.Count := 9
|
||||||
|
else
|
||||||
|
minorAxis.Intervals.Count := AWorkbookAxis.MinorCount;
|
||||||
minorAxis.TickLength := IfThen(catOutside in AWorkbookAxis.MinorTicks, 2, 0);
|
minorAxis.TickLength := IfThen(catOutside in AWorkbookAxis.MinorTicks, 2, 0);
|
||||||
minorAxis.TickInnerLength := IfThen(catInside in AWorkbookAxis.MinorTicks, 2, 0);
|
minorAxis.TickInnerLength := IfThen(catInside in AWorkbookAxis.MinorTicks, 2, 0);
|
||||||
minorAxis.TickColor := axis.AxisPen.Color;
|
minorAxis.TickColor := axis.AxisPen.Color;
|
||||||
@@ -1707,23 +1771,6 @@ begin
|
|||||||
// Inverted?
|
// Inverted?
|
||||||
axis.Inverted := AWorkbookAxis.Inverted;
|
axis.Inverted := AWorkbookAxis.Inverted;
|
||||||
|
|
||||||
// Usually not needed, but axis handling is simplified when there is
|
|
||||||
// an axis transformation at each axis.
|
|
||||||
if axis.Transformations = nil then
|
|
||||||
begin
|
|
||||||
axis.Transformations := TChartAxisTransformations.Create(FChart);
|
|
||||||
// Autoscale transformation for primary and secondary axes
|
|
||||||
T := TAutoScaleAxisTransform.Create(axis.Transformations);
|
|
||||||
T.Transformations := axis.Transformations;
|
|
||||||
if AWorkbookAxis.Chart.GetChartType in [ctRadar, ctFilledRadar] then
|
|
||||||
T.Enabled := false;
|
|
||||||
// Logarithmic
|
|
||||||
T := TLogarithmAxisTransform.Create(axis.Transformations);
|
|
||||||
T.Transformations := axis.Transformations;
|
|
||||||
TLogarithmAxisTransform(T).Base := 10;
|
|
||||||
TLogarithmAxisTransform(T).Enabled := AWorkbookAxis.Logarithmic;
|
|
||||||
end;
|
|
||||||
|
|
||||||
// Scaling
|
// Scaling
|
||||||
axis.Range.UseMin := not AWorkbookAxis.AutomaticMin;
|
axis.Range.UseMin := not AWorkbookAxis.AutomaticMin;
|
||||||
axis.Range.UseMax := not AWorkbookAxis.AutomaticMax;
|
axis.Range.UseMax := not AWorkbookAxis.AutomaticMax;
|
||||||
@@ -1731,16 +1778,17 @@ begin
|
|||||||
axis.Range.Max := AWorkbookAxis.Max;
|
axis.Range.Max := AWorkbookAxis.Max;
|
||||||
|
|
||||||
// Logarithmic
|
// Logarithmic
|
||||||
logTransf := TLogarithmAxisTransform(axis.Transformations.List[1]);
|
logTransf := GetLogAxisTransform(axis);
|
||||||
logTransf.Enabled := AWorkbookAxis.Logarithmic;
|
logTransf.Enabled := AWorkbookAxis.Logarithmic;
|
||||||
if AWorkbookAxis.Logarithmic then
|
if AWorkbookAxis.Logarithmic then
|
||||||
begin
|
begin
|
||||||
// axis.Intervals.Options := axis.Intervals.Options + [aipInteger];;
|
axis.Intervals.Options := axis.Intervals.Options + [aipGraphCoords];
|
||||||
axis.Intervals.MaxLength := 150;
|
axis.Intervals.MaxLength := 150;
|
||||||
axis.Intervals.MinLength := 30;
|
axis.Intervals.MinLength := 30;
|
||||||
axis.Intervals.Tolerance := 30;
|
axis.Intervals.Tolerance := 30;
|
||||||
end else
|
end else
|
||||||
begin
|
begin
|
||||||
|
axis.Intervals.Options := axis.Intervals.Options - [aipGraphCoords];
|
||||||
axis.Intervals.MaxLength := 100;
|
axis.Intervals.MaxLength := 100;
|
||||||
axis.Intervals.MinLength := 20;
|
axis.Intervals.MinLength := 20;
|
||||||
axis.Intervals.Tolerance := 0;
|
axis.Intervals.Tolerance := 0;
|
||||||
|
Reference in New Issue
Block a user