📄 teechartgrid.pas
字号:
Canvas.TextRect(ARect, ARect.Left+18, ARect.Top+4,
SeriesTitleOrName(tmpSeries));
end;
end
else
begin
if (ACol=0) or (ShowFields and (ARow=1)) then // Point number (#) column
FillWithColor(FixedColor);
if FColors and (ACol=ColorsColumn) then // Colors
begin
if ARow=FirstRowNum-1 then
Canvas.TextRect(ARect, ARect.Left+2, ARect.Top+2,
TeeMsg_Colors)
else
if ARow>=FirstRowNum then
begin
tmpSeries:=GetSeries(ACol+1,AList);
if Assigned(tmpSeries) and (tmpSeries.Count>(ARow-FirstRowNum)) then
begin
tmpColor:=tmpSeries.ValueColor[ARow-FirstRowNum];
if tmpColor=clNone then tmpColor:=Self.Color;
end
else tmpColor:=Self.Color;
FillWithColor(tmpColor);
end;
end
else
if FLabels and (ACol=LabelsColumn) then // Labels
Canvas.TextRect(ARect, ARect.Left+2, ARect.Top+2, GetEditText(ACol, ARow))
else
begin
// Values
{$IFNDEF CLX}
{$IFNDEF CLR}Windows.{$ENDIF}SetTextAlign(Canvas.Handle,TA_RIGHT);
{$ENDIF}
{$IFDEF CLX}
QPainter_setBackgroundMode(Canvas.Handle,BGMode_TransparentMode);
{$ENDIF}
tmpSt:=GetEditText(ACol, ARow);
{$IFDEF CLX}
Dec(ARect.Right,3);
{$ENDIF}
Canvas.TextRect(ARect,
{$IFDEF CLX}ARect.Left{$ELSE}ARect.Right-2{$ENDIF},
ARect.Top+2, tmpSt
{$IFDEF CLX},Integer(AlignmentFlags_AlignRight){$ENDIF});
{$IFNDEF CLX}
{$IFNDEF CLR}Windows.{$ENDIF}SetTextAlign(Canvas.Handle,TA_LEFT);
{$ENDIF}
end;
end;
end;
end;
procedure TCustomChartGrid.Notification( AComponent: TComponent;
Operation: TOperation);
begin
inherited;
if Operation=opRemove then
begin
if Assigned(FChart) and (AComponent=FChart) then
Chart:=nil
else
if Assigned(INavigator) and (AComponent=INavigator) then
INavigator:=nil
else
if Assigned(FSeries) and (AComponent=FSeries) then
Series:=nil
end;
end;
// Deletes current row, also deletes series points
Procedure TCustomChartGrid.Delete;
Procedure TryDelete(ASeries:TChartSeries; AIndex:Integer);
begin
With ASeries do
if (Row-FirstRowNum)<Count then
begin
Delete(Row-FirstRowNum);
if not IHasNo[AIndex] then NotMandatoryValueList.FillSequence;
end;
end;
var t : Integer;
begin
if goEditing in Options then // 7.0
begin
if Assigned(FSeries) then
TryDelete(FSeries,0)
else
With FChart do
for t:=0 to SeriesCount-1 do
TryDelete(Series[t],t);
if RowCount>(1+FirstRowNum) then RowCount:=RowCount-1
else
begin
Repaint;
NotifyChange;
end;
end;
end;
// Inserts a new row to the end (appends),
// also inserts (appends) new series points
Procedure TCustomChartGrid.Insert;
var tmpInc : Boolean;
Procedure TryInsert(ASeries:TChartSeries);
begin
With ASeries do
begin
tmpInc:=Count>0;
AddNullXY(Count,0);
end;
end;
Var t : Integer;
begin
if goEditing in Options then // 7.0
begin
tmpInc:=False;
if Assigned(FSeries) then
TryInsert(FSeries)
else
With FChart do
for t:=0 to SeriesCount-1 do
TryInsert(Series[t]);
if tmpInc then RowCount:=RowCount+1;
Row:=RowCount-1; // Go to last row
end;
end;
{$IFNDEF CLR}
type
TTeePanelAccess=class(TCustomAxisPanel);
{$ENDIF}
Procedure TCustomChartGrid.AddListener(AChart:TCustomAxisPanel); // 5.03
begin
if Assigned(AChart) then
begin
AChart.FreeNotification(Self);
{$IFNDEF CLR}TTeePanelAccess{$ENDIF}(AChart).Listeners.Add(Self);
end;
end;
Procedure TCustomChartGrid.RemoveListener(AChart:TCustomAxisPanel); // 5.03
begin
if Assigned(AChart) and (not (csDestroying in AChart.ComponentState)) then
begin
{$IFDEF D5}
AChart.RemoveFreeNotification(Self);
{$ENDIF}
{$IFNDEF CLR}TTeePanelAccess{$ENDIF}(AChart).RemoveListener(Self);
end;
end;
Procedure TCustomChartGrid.SetChart(AChart:TCustomChart);
begin
if FChart<>AChart then
begin
RemoveListener(FChart);
FChart:=AChart;
AddListener(FChart);
end;
Regenerate;
Repaint; { 5.01 }
end;
Procedure TCustomChartGrid.SetNavigator(ANavigator:TChartGridNavigator);
begin
INavigator:=ANavigator;
if Assigned(INavigator) then INavigator.FreeNotification(Self);
end;
// Main procedure to calculate how many rows and columns should the grid have
Procedure TCustomChartGrid.RecalcDimensions;
Function MaxNumPoints:Integer;
var t : Integer;
begin
result:=0;
if Assigned(FSeries) then result:=FSeries.Count
else
for t:=0 to FChart.SeriesCount-1 do
With FChart.Series[t] do
if (t=0) or (Count>result) then result:=Count;
end;
var tmpCol : Integer;
Procedure CalcParams(ASeries:TChartSeries; AIndex:Integer);
begin
if not (csDestroying in ASeries.ComponentState) then
begin
Inc(tmpCol);
if FXValues=cgsAuto then
IHasNo[AIndex]:=HasNoMandatoryValues(ASeries)
else
IHasNo[AIndex]:=FXValues=cgsYes;
if IHasNo[AIndex] then Inc(tmpCol);
Inc(tmpCol,ASeries.ValuesList.Count-2);
end;
end;
Procedure SetXYZDimensions;
var Values : Array of TChartValue;
Function Find(Const Value:TChartValue):Boolean;
var t : Integer;
begin
result:=False;
for t:=0 to Length(Values)-1 do
if Values[t]=Value then
begin
result:=True;
exit;
end;
end;
var tmpSeries : TChartSeries;
t : Integer;
tmp : Double;
begin
tmpSeries:=GetXYZSeries;
if Assigned(tmpSeries) then
begin
for t:=0 to tmpSeries.Count-1 do
begin
tmp:=tmpSeries.ValuesList[2].Value[t];
if not Find(tmp) then
begin
SetLength(Values,Length(Values)+1);
Values[Length(Values)-1]:=tmp;
end;
end;
ColCount:=1+Length(Values);
Values:=nil;
//1+Round(tmpSeries.MaxZValue-tmpSeries.MinZValue+1);
for t:=0 to tmpSeries.Count-1 do
begin
tmp:=tmpSeries.NotMandatoryValueList.Value[t];
if not Find(tmp) then
begin
SetLength(Values,Length(Values)+1);
Values[Length(Values)-1]:=tmp;
end;
end;
RowCount:=2+Length(Values);
// with tmpSeries.NotMandatoryValueList do
// RowCount:=2+Round(MaxValue-MinValue+1);
end;
FLabels:=False;
FColors:=False;
FixedRows:=2;
end;
var t : Integer;
begin
if Grid3DMode then SetXYZDimensions
else
begin
tmpCol:=1;
if Assigned(FChart) or Assigned(FSeries) then
begin
if Assigned(FSeries) then CalcParams(FSeries,0)
else
for t:=0 to FChart.SeriesCount-1 do CalcParams(FChart[t],t);
if FLabels then Inc(tmpCol);
if FColors then Inc(tmpCol);
RowCount:=Math.Max(1+FirstRowNum,MaxNumPoints+FirstRowNum);
end
else RowCount:=1+FirstRowNum;
ColCount:=tmpCol;
ColWidths[0]:=30;
if FColors and (ColCount>1) then
ColWidths[1]:=40; { 5.02 }
if ShowFields then FixedRows:=2
else FixedRows:=1;
end;
if (Col=0) and (ColCount>1) then Col:=1; // 5.02
NotifyChange;
end;
procedure TCustomChartGrid.NotifyChange;
begin
if Assigned(FActiveChanged) then FActiveChanged(Self);
end;
Procedure TCustomChartGrid.SetBooleanProperty(Var Variable:Boolean; Value:Boolean);
begin
if Variable<>Value then
begin
Variable:=Value;
RecalcDimensions;
Repaint;
end;
end;
Procedure TCustomChartGrid.SetShowFields(Value:Boolean);
begin
SetBooleanProperty(FShowFields,Value);
if Row<FirstRowNum then Row:=FirstRowNum;
end;
procedure TCustomChartGrid.SetShowLabels(Value: Boolean);
begin
SetBooleanProperty(FLabels,Value);
end;
Procedure TCustomChartGrid.SetShowColors(Value:Boolean);
begin
SetBooleanProperty(FColors,Value);
end;
Procedure TCustomChartGrid.SetShowXValues(Value:TChartGridShow);
begin
FXValues:=Value;
RecalcDimensions;
Repaint;
end;
procedure TCustomChartGrid.TeeEvent(Event: TTeeEvent);
begin
if not (csDestroying in ComponentState) then
if Event is TTeeSeriesEvent then
Case TTeeSeriesEvent(Event).Event of
seChangeTitle,
seChangeColor,
seChangeActive: Repaint
else RecalcDimensions;
end;
end;
Function TCustomChartGrid.GetSeriesColor(var AColor:TColor):TChartSeries;
var tmpList : TChartValueList;
begin
if FColors and (Col=ColorsColumn) and (Row>=FirstRowNum) then
begin
result:=GetSeries(Col+1,tmpList);
if result.Count>(Row-FirstRowNum) then
AColor:=result.ValueColor[Row-FirstRowNum]
else
result:=nil;
end
else
result:=nil;
end;
Procedure TCustomChartGrid.ChangeColor(AColor:TColor);
var tmpColor : TColor;
tmpSeries : TChartSeries;
begin
tmpSeries:=GetSeriesColor(tmpColor);
if Assigned(tmpSeries) then
ChangeColor(tmpSeries,AColor);
end;
Procedure TCustomChartGrid.ChangeColor(ASeries:TChartSeries; AColor:TColor);
begin
ASeries.ValueColor[Row-FirstRowNum]:=AColor;
SetManualData(ASeries);
DrawCell(Col,Row,CellRect(Col,Row),[gdSelected,gdFocused]);
if Assigned(FOnChangeColor) then FOnChangeColor(Self);
end;
Procedure TCustomChartGrid.ChangeColor;
var tmpSeries : TChartSeries;
tmpColor : TColor;
begin
tmpSeries:=GetSeriesColor(tmpColor);
if Assigned(tmpSeries) then
if EditColorDialog(Self,tmpColor) then
ChangeColor(tmpSeries,tmpColor);
end;
// Use double-click mouse event to show the color editor dialog
// to change a series point color
procedure TCustomChartGrid.DblClick;
begin
if FColors and (Col=ColorsColumn) and (goEditing in Options) then
ChangeColor
else
inherited;
end;
function TCustomChartGrid.CanEditShow: Boolean;
begin
result:=inherited CanEditShow;
if result then
begin
if Assigned(FOnEditing) then // 7.0
FOnEditing(Self,Col,Row,result);
if result then
if FColors and (Col=ColorsColumn) then
result:=False
else
FOldValue:=GetEditText(Col,Row);
end;
end;
procedure TCustomChartGrid.Regenerate;
begin
if not (csDestroying in ComponentState) then
begin
RecalcDimensions;
MoveColRow(Math.Min(ColCount-1,1), FirstRowNum, True, True);
end;
end;
procedure TCustomChartGrid.SetSeries(const Value: TChartSeries);
begin
if FSeries<>Value then
begin
if Assigned(FSeries) then
begin
{$IFDEF D5}
FSeries.RemoveFreeNotification(Self);
{$ENDIF}
if Assigned(FSeries.ParentChart) then
RemoveListener(FSeries.ParentChart)
else
RemoveListener(ISeriesChart); // 6.02
end;
FSeries:=Value;
if Assigned(FSeries) then
begin
FSeries.FreeNotification(Self);
Chart:=nil;
ISeriesChart:=FSeries.ParentChart; // 6.02
AddListener(ISeriesChart);
end;
end;
Regenerate;
Repaint;
end;
// Returns column number for series "Labels"
Function TCustomChartGrid.LabelsColumn:Integer;
begin
if FLabels then
begin
if FColors then result:=2
else result:=1;
end
else result:=-1;
end;
// Returns column number for series "Colors"
Function TCustomChartGrid.ColorsColumn:Integer;
begin
if FColors then result:=1 else result:=-1;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -