TAChart: Extend TListChartSource.DataPoints to support separator ('|') as well as line breaks in the Text field.

git-svn-id: trunk@60501 -
This commit is contained in:
wp 2019-02-25 18:44:13 +00:00
parent bfaf53d166
commit 2361649666
4 changed files with 58 additions and 7 deletions

View File

@ -33,6 +33,7 @@ object DataPointsEditorForm: TDataPointsEditorForm
Width = 63
end
item
ButtonStyle = cbsEllipsis
Title.Alignment = taCenter
Title.Font.Style = [fsBold]
Title.Caption = 'Text'

View File

@ -59,11 +59,41 @@ type
implementation
uses
LCLIntf, LCLType, Math,
LCLIntf, LCLType, Math, StdCtrls,
TAChartStrConsts, TAChartUtils, TASources;
{$R *.lfm}
function EditText(var AText: String): Boolean;
var
F: TForm;
memo: TMemo;
begin
F := TForm.CreateNew(Application);
try
F.Caption := 'Data point text';
F.Position := poScreenCenter;
memo := TMemo.Create(F);
with memo do begin
Parent := F;
Align := alClient;
BorderSpacing.Around := 6;
Lines.Text := AText;
end;
with TButtonPanel.Create(F) do begin
Parent := F;
Align := alBottom;
BorderSpacing.Around := 6;
ShowButtons := [pbOK, pbCancel];
end;
Result := F.ShowModal = mrOK;
if Result then AText := memo.Lines.Text;
finally
F.Free;
end;
end;
{ TDataPointsEditorForm }
procedure TDataPointsEditorForm.ExtractData(out AModified: Boolean);
@ -200,12 +230,21 @@ end;
procedure TDataPointsEditorForm.sgDataButtonClick(
ASender: TObject; ACol, ARow: Integer);
var
s: String;
begin
Unused(ASender);
if (ARow < 1) or (ACol <> FXCount + FYCount + 1) then exit;
cdItemColor.Color := StrToIntDef(sgData.Cells[ACol, ARow], clRed);
if not cdItemColor.Execute then exit;
sgData.Cells[ACol, ARow] := IntToColorHex(cdItemColor.Color);
if (ARow < 1) then exit;
if (ACol = FXCount + FYCount + 1) then begin
cdItemColor.Color := StrToIntDef(sgData.Cells[ACol, ARow], clRed);
if cdItemColor.Execute then
sgData.Cells[ACol, ARow] := IntToColorHex(cdItemColor.Color);
end else
if (ACol = FXCount + FYCount + 2) then begin
s := sgData.Cells[ACol, ARow];
if EditText(s) then sgData.Cells[ACol, ARow] := s;
end;
end;
procedure TDataPointsEditorForm.sgDataDrawCell(

View File

@ -313,6 +313,8 @@ begin
end;
function TListChartSourceStrings.Get(Index: Integer): String;
const
COLOR_TEXT_MASK: array[boolean] of string = ('%s|%s', '%s|"%s"');
function NumberStr(AValue: Double): String;
begin
@ -335,7 +337,7 @@ begin
Result += NumberStr(Y);
for i := 0 to High(YList) do
Result += NumberStr(YList[i]);
Result += Format('%s|%s', [IntToColorHex(Color), Text]);
Result += Format(COLOR_TEXT_MASK[pos('|', Text) > 0], [IntToColorHex(Color), Text]);
end;
end;
@ -423,6 +425,7 @@ begin
parts := Split(AString);
try
// There must be XCount + YCount + 2 parts of the string (+2 for Color and Text)
// Text must be quoted if it contains '|'.
if (Cardinal(parts.Count) <> FSource.XCount + FSource.YCount + 2) then
raise EListSourceStringError.CreateFmt(
rsListSourceStringFormatError, [SourceClassString, ChopString(AString, 20)]);

View File

@ -563,7 +563,15 @@ begin
FSource.DataPoints.Add('1|2|3||t');
AssertEquals(clTAColor, FSource[6]^.Color);
// check multiple x and y values
// Check Text part containing '|' character(s)
FSource.DataPoints.Add('1|2|3|?|"a|b|c"');
AssertEquals('a|b|c', FSource[7]^.Text);
// Check Text part containing line ending
FSource.DataPoints.Add('1|2|3|?|"a'+LineEnding+'b"');
AssertEquals('a'+LineEnding+'b', FSource[8]^.Text);
// Check multiple x and y values
FSource.Clear;
FSource.XCount := 2;
FSource.YCount := 3;