⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 teechartgrid.pas

📁 BCB第三方组件
💻 PAS
📖 第 1 页 / 共 4 页
字号:

    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) and (not (csDestroying in ComponentState)) then
       result:=FSeries.Count
    else
    for t:=0 to FChart.SeriesCount-1 do
    with FChart[t] do
    if not (csDestroying in ComponentState) then
       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;
    ColWidths[1]:=ColWidths[2]; { 8.0 - TV52012110 }
  end;

var t : Integer;
begin
  if Assigned(FChart) then
     SetLength(IHasNo,FChart.SeriesCount)
  else
  if Assigned(FSeries) then
     SetLength(IHasNo,1);

  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(out AColor:TColor; ACol,ARow:Integer):TChartSeries;
begin
  AColor:=clNone;

  if FColors and (ACol=ColorsColumn) and (ARow>=FirstRowNum) then
  begin
    result:=GetSeries(ACol+1);

    if Assigned(result) then
    begin
      if result.Count>(ARow-FirstRowNum) then
         AColor:=result.ValueColor[ARow-FirstRowNum]
      else
         result:=nil;
    end;
  end
  else
     result:=nil;
end;

Function TCustomChartGrid.GetSeriesColor(out AColor:TColor):TChartSeries;
begin
  result:=GetSeriesColor(AColor,Col,Row);
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
  begin
    if EditColorDialog(Self,tmpColor) then
       ChangeColor(tmpSeries,tmpColor);
  end
  else
  if AllowInsertSeries then
  begin
    if EditColorDialog(Self,tmpColor) then
    begin
      tmpSeries:=Chart.AddSeries(TBarSeries);

      while tmpSeries.Count<=(Row-FirstRowNum) do
            tmpSeries.AddNull;

      ChangeColor(tmpSeries,tmpColor);

      Invalidate;
    end;
  end;
end;

function TCustomChartGrid.AtSeriesColor(var Series:TChartSeries):Boolean;
var tmpCoord : TGridCoord;
    tmpPoint : TPoint;
    tmp      : TChartSeries;
    tmpR     : TRect;
begin
  result:=False;

  tmpPoint:=ScreenToClient(Mouse.CursorPos);
  tmpCoord:=MouseCoord(tmpPoint.X,tmpPoint.Y);

  if tmpCoord.Y=0 then
  begin
    tmp:=GetSeries(tmpCoord.X);

    if Assigned(tmp) then
    begin
      tmpR:=SymbolRect(CellRect(tmpCoord.X,tmpCoord.Y));

      if PtInRect(tmpR,tmpPoint) then
      begin
        Series:=tmp;
        result:=True;
      end;
    end;
  end;
end;

// Use double-click mouse event to show the color editor dialog
// to change a series point color
procedure TCustomChartGrid.DblClick;
var tmpSeries : TChartSeries;
    tmpColor  : TColor;
begin
  if FColors and (Col=ColorsColumn) and (goEditing in Options) then
     ChangeColor
  else
  if (AtSeriesColor(tmpSeries)) and (SeriesSymbolClickable) then
  begin
    tmpColor:=tmpSeries.Color;

    if EditColorDialog(Self,tmpColor) then
       tmpSeries.Color:=tmpColor;
  end
  else
     inherited;
end;

{$IFNDEF LCL}
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;
{$ENDIF}

procedure TCustomChartGrid.Regenerate;
begin
  if not (csDestroying in ComponentState) then
  begin
    RecalcDimensions;
    
    {$IFNDEF LCL} // Same method in LCL does a different thing
    MoveColRow(Math.Min(ColCount-1,1), FirstRowNum, True, True);
    {$ENDIF}
  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 + -