📄 teedatatabletool.pas
字号:
tmpPos:=tmpPos+Chart.SeriesWidth3D;
tmpOffset:=-Chart.SeriesWidth3D;
end;
Left:=tmpPos;
Top:=0;
end;
end
else
begin
if TableHorizontal then
begin
tmpPos:=Top;
tmpOffset:=Left;
end
else
begin
tmpPos:=Left;
tmpOffset:=Top;
end;
end;
end;
var t,
tt,l,
tmpW,
Old,
x0, x1:Integer;
TicksDown : Boolean;
begin
if VisibleSeriesCount>0 then
with Chart.Canvas do
begin
Axis:=GuessAxis;
TableHorizontal:=Axis.Horizontal;
// Prepare Font
AssignFont(Self.Font);
if TableHorizontal then
tmpItemSize:=FontHeight
else
tmpItemSize:=TextWidth('#.###'); // <-- Improve. Calc based on max of all values
if TableHorizontal then
TextAlign:=TA_CENTER;
BackMode:=cbmTransparent;
// Find Series with maximum number of points
MaxSeriesCount:=CalcMaxSeriesCount;
CalcPositions;
with TAxis(Axis) do
begin
l:=Length(Tick);
if l>=2 then
begin
TicksDown:=Tick[0]<Tick[1];
if not TableHorizontal then TicksDown:=not TicksDown;
if Inverted then TicksDown:=not TicksDown;
end
else TicksDown:=False;
if TableHorizontal then
AssignVisiblePen(Self.ColumnPen)
else
AssignVisiblePen(Self.RowPen);
// Draw 1 row-col to last
for t:=0 to l-2 do
begin
ColDivider((Tick[t+1]+Tick[t]) div 2);
for tt:=0 to Chart.SeriesCount-1 do
if TicksDown then
DoText(Tick[t],MaxSeriesCount-t,tt)
else
DoText(Tick[t],t+1,tt);
end;
// Draw 0 row-col
if l>0 then
begin
for tt:=0 to Chart.SeriesCount-1 do
if TicksDown then
DoText(Tick[l-1],1,tt)
else
DoText(Tick[l-1],l,tt);
if l=1 then
if Horizontal then x0:=IStartPos
else x0:=IEndPos
else
begin
x0:=Tick[l-1]-((Tick[l-2]-Tick[l-1]) div 2);
if Horizontal then x0:=Max(x0,IStartPos)
else x0:=Min(x0,IEndPos);
end;
ColDivider(x0);
if l=1 then
if Horizontal then x1:=IEndPos
else x1:=IStartPos
else
begin
x1:=Tick[0]+((Tick[0]-Tick[1]) div 2);
if Horizontal then x1:=Min(x1,IEndPos)
else x1:=Max(x1,IStartPos);
end;
ColDivider(x1);
end
else
begin
x0:=IStartPos;
x1:=IEndPos;
end;
end;
Inc(x0,tmpOffset);
Inc(x1,tmpOffset);
if FLegend.Visible then
begin
if TicksDown and TableHorizontal then SwapInteger(x0,x1);
if TicksDown and (not TableHorizontal) then SwapInteger(x0,x1);
if Axis.Inverted then SwapInteger(x0,x1);
tmpW:=LegendWidth(tmpW);
if TableHorizontal then
Dec(x0,tmpW)
else
Dec(x1,tmpW);
if Legend.OtherSide then
begin
if TableHorizontal then
begin
Old:=x0;
x0:=x1;
Inc(x1,tmpW);
end
else
begin
Old:=x1;
x1:=x0;
Dec(x0,tmpW);
end;
end
else
Old:=0;
DrawLegend(x0,x1);
if Legend.OtherSide then
begin
if not TableHorizontal then
begin
x0:=x1+tmpW;
x1:=Old+tmpW;
end
else
x0:=Old+tmpW;
end;
end;
// Draw other divider lines
if TableHorizontal then
AssignVisiblePen(Self.RowPen)
else
AssignVisiblePen(Self.ColumnPen);
for t:=-1 to Chart.SeriesCount do
if TableHorizontal then
DoHorizLine(x0,x1,ColRowPos(t))
else
DoVertLine(ColRowPos(t),x0,x1);
end;
end;
{ TDataTableTool }
procedure TDataTableTool.ChartEvent(AEvent: TChartToolEvent);
begin
inherited;
if AEvent=cteAfterDraw then
Draw;
end;
class function TDataTableTool.Description: String;
begin
result:=TeeMsg_DataTableTool;
end;
function TDataTableTool.Chart: TCustomChart;
begin
result:=ParentChart as TCustomChart;
end;
procedure TDataTableTool.SetAutoPos(const Value: Boolean);
begin
SetBooleanProperty(FAutoPos,Value);
end;
procedure TDataTableTool.SetLegend(const Value: TTableLegend);
begin
FLegend := Value;
end;
{$IFNDEF CLR}
type
TAxesAccess=class(TChartAxes);
{$ENDIF}
procedure TDataTableTool.SetParentChart(const Value: TCustomAxisPanel);
begin
if Assigned(ParentChart) and
(not (csDestroying in ParentChart.ComponentState)) then
{$IFNDEF CLR}TAxesAccess{$ENDIF}(ParentChart.Axes).CalcPosLabels:=nil;
inherited;
if not (csDestroying in ComponentState) then
begin
Legend.ParentChart:=ParentChart;
if Assigned(ParentChart) then
{$IFNDEF CLR}TAxesAccess{$ENDIF}(ParentChart.Axes).CalcPosLabels:=CalcPosLabels;
Repaint;
end;
end;
function TDataTableTool.TableSize:Integer;
begin
Chart.Canvas.AssignFont(Font);
if GuessAxis.Horizontal then
result:=10+Chart.Canvas.FontHeight*VisibleSeriesCount
else
result:=16+VisibleSeriesCount*Chart.Canvas.TextWidth('#.###'); // <-- Improve. Calc based on max of all values
end;
// Intercept axis labels position calculation, at TeEngine Axis.CalcRect
function TDataTableTool.CalcPosLabels(Axis:TChartAxis; Value:Integer):Integer;
var tmp : TChartAxis;
tmpL : Integer;
tmpW : Integer;
tmpR : TRect;
begin
result:=Value;
if (not Axis.IsDepthAxis) and AutoPosition then
begin
tmp:=GuessAxis;
if Assigned(tmp) then
begin
if Axis=tmp then
Inc(result,TableSize)
else
if Legend.Visible then
begin
tmpL:=LegendWidth(tmpW);
if tmp.Horizontal then
begin
if not Axis.Horizontal then
if (not Legend.OtherSide) and (not Axis.OtherSide) then
result:=Max(Value,tmpL)
else
if Legend.OtherSide and Axis.OtherSide then
begin
tmpR:=Chart.ChartBounds;
result:=Max(Value,tmpL-(tmpR.Right-Chart.ChartRect.Right));
end;
end
else
if Axis.Horizontal then
if (not Legend.OtherSide) and Axis.OtherSide then
result:=Max(Value,tmpL)
else
if Legend.OtherSide and (not Axis.OtherSide) then
begin
tmpR:=Chart.ChartBounds;
result:=Max(Value,tmpL-(tmpR.Bottom-Chart.ChartRect.Bottom));
end;
end;
end;
end;
end;
procedure TDataTableTool.SetFont(const Value: TTeeFont);
begin
FFont.Assign(Value);
end;
function TDataTableTool.GetRowPen: TChartPen;
begin
result:=Pen;
end;
procedure TDataTableTool.SetColumnPen(const Value: TChartPen);
begin
FColumnPen.Assign(Value);
end;
procedure TDataTableTool.SetRowPen(const Value: TChartPen);
begin
Pen:=Value;
end;
procedure TDataTableTool.SetInverted(const Value: Boolean);
begin
SetBooleanProperty(FInverted,Value);
end;
class function TDataTableTool.GetEditorClass: String;
begin
result:='TDataTableEditor';
end;
procedure TDataTableTool.SetLeft(const Value: Integer);
begin
SetIntegerProperty(FLeft,Value);
end;
procedure TDataTableTool.SetTop(const Value: Integer);
begin
SetIntegerProperty(FTop,Value);
end;
procedure TDataTableTool.SetClipText(const Value: Boolean);
begin
SetBooleanProperty(FClipText,Value);
end;
{ TTableLegend }
Constructor TTableLegend.Create(AOwner: TCustomTeePanel);
begin
inherited;
FSymbol:=TLegendSymbol.Create(AOwner);
TSymbolAccess(FSymbol).CalcItemHeight:=CalcSymbolHeight;
DefaultTransparent:=True;
Transparent:=True;
end;
Destructor TTableLegend.Destroy;
begin
FSymbol.Free;
inherited;
end;
procedure TTableLegend.SetFontColor(const Value: Boolean);
begin
if FFontColor<>Value then
begin
FFontColor:=Value;
Repaint;
end;
end;
function TTableLegend.CalcSymbolHeight:Integer;
begin
result:=FSymbol.Width;
end;
procedure TTableLegend.Assign(Source: TPersistent);
begin
inherited;
if Source is TTableLegend then
begin
FFontColor:=TTableLegend(Source).FFontColor;
Symbol:=TTableLegend(Source).Symbol;
end;
end;
procedure TTableLegend.SetParent(Value: TCustomTeePanel);
begin
inherited;
if Assigned(Symbol) then
Symbol.Parent:=Value;
end;
procedure TTableLegend.SetSymbol(const Value: TLegendSymbol);
begin
FSymbol.Assign(Value);
end;
procedure TTableLegend.SetOtherSide(const Value: Boolean);
begin
if FOtherSide<>Value then
begin
FOtherSide:=Value;
Repaint;
end;
end;
initialization
RegisterTeeTools([TDataTableTool]);
finalization
UnRegisterTeeTools([TDataTableTool]);
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -