TAChart: Add aipInteger as new TAxisIntervalParamOption to force axis labels only in integer steps.

This commit is contained in:
wp_xyz 2022-11-06 18:28:57 +01:00
parent 3a8bac2cfd
commit 9ac4a95870
2 changed files with 13 additions and 2 deletions

View File

@ -23,7 +23,8 @@ uses
type
TAxisIntervalParamOption = (
aipGraphCoords,
aipUseCount, aipUseMaxLength, aipUseMinLength, aipUseNiceSteps);
aipUseCount, aipUseMaxLength, aipUseMinLength, aipUseNiceSteps,
aipInteger);
const
DEF_INTERVAL_STEPS = '0.2|0.5|1.0';

View File

@ -329,6 +329,13 @@ var
begin
CalcMinMaxCount(minCount, maxCount);
bestCount := 0;
if aipInteger in Params.Options then begin
ABestStart := Int(AParams.FMin);
ABestStep := 1.0;
bestCount := Round(AParams.FMax) - round(ABestStart);
if bestCount <= maxCount then
exit;
end;
if aipUseNiceSteps in Params.Options then begin
s := AParams.CountToStep(minCount) * 10;
while s >= Max(AParams.CountToStep(maxCount), AParams.FMinStep) do begin
@ -339,7 +346,10 @@ begin
s *= 0.1;
end;
end;
if bestCount > 0 then exit;
if (aipInteger in Params.Options) and (bestCount > maxCount) then
bestCount := 0;
if bestCount > 0 then
exit;
// Either nice steps were not required, or we failed to find one.
if aipUseCount in Params.Options then
bestCount := EnsureRange(Params.Count, minCount, maxCount)