📄 jvchart.pas
字号:
FDataAlloc := (ValueIndex * 2) // Double in size
else
FDataAlloc := ValueIndex + 64000;
oldLength := Length(FData);
SetLength(FData, FDataAlloc);
// new: If we set FClearToValue to NaN, special handling in growing arrays:
if IsNaN(FClearToValue) then
for I := oldLength to FDataAlloc - 1 do
for J := 0 to Length(FData[I]) - 1 do
FData[I][J] := FClearToValue; // XXX Debug me!
end;
if Pen >= Length(FData[ValueIndex]) then
begin
oldLength := Length(FData[ValueIndex]);
SetLength(FData[ValueIndex], Pen + 1);
if IsNaN(FClearToValue) then
begin
for I := oldLength to FDataAlloc - 1 do
begin
Assert(Length(FData) > ValueIndex);
if (Length(FData[ValueIndex]) < FDataAlloc) then
SetLength(FData[ValueIndex], FDataAlloc); // Safety code!
FData[ValueIndex][I] := FClearToValue; // XXX Debug me!
end;
end;
end;
end;
function TJvChartData.DebugStr(ValueIndex: Integer): string; // dump all pens for particular valueindex, as string.
var
S: string;
I, IMax: Integer;
begin
if (ValueIndex < 0) or (ValueIndex >= FDataAlloc) then
Exit;
IMax := Length(FData[ValueIndex]) - 1;
if Timestamp[ValueIndex] > 0.0 then
S := FormatDateTime('hh:nn:ss ', Timestamp[ValueIndex]);
for I := 0 to IMax do
begin
if IsNaN(FData[ValueIndex, I]) then
S := S + '-'
else
S := S + Format('%5.2f', [FData[ValueIndex, I]]);
if I < IMax then
S := S + ', '
end;
Result := S;
end;
procedure TJvChartData.Clear; // Resets FValuesCount/FPenCount to zero. Zeroes everything too, just for good luck.
var
I, J: Integer;
begin
for I := 0 to FDataAlloc - 1 do
for J := 0 to Length(FData[I]) - 1 do
FData[I, J] := FClearToValue;
FValueCount := 0;
end;
procedure TJvChartData.ClearPenValues; // Clears all pen values to NaN but does not reset pen definitions etc.
var
I, J: Integer;
begin
for I := 0 to FDataAlloc - 1 do
for J := 0 to Length(FData[I]) - 1 do
FData[I, J] := 0.0;
end;
//=== { TJvChartYAxisOptions } ===============================================
constructor TJvChartYAxisOptions.Create(Owner: TJvChartOptions);
begin
inherited Create;
FOwner := Owner;
FMarkerValueDecimals := -1; // -1 = default (automatic decimals)
FYLegends := TStringList.Create;
FMaxYDivisions := 20;
FMinYDivisions := 5;
FYDivisions := 10;
FDefaultYLegends := JvDefaultYLegends;
end;
destructor TJvChartYAxisOptions.Destroy;
begin
FYLegends.Free;
inherited Destroy;
end;
procedure TJvChartYAxisOptions.Clear;
begin
YDivisions := DefaultYLegends;
YLegends.Clear;
Normalize;
end;
procedure TJvChartYAxisOptions.Normalize;
var
// CheckYDivisions: Integer;
VC: Integer;
begin
if (FYMax - FYMin) < 0.00001 then // make sure that there is some difference here!
FYMax := FYMin + 10;
if (DefaultYLegends > 0) and (YDivisions = 0) then
YDivisions := DefaultYLegends;
// DON'T KNOW WHY WE NEEDED THIS. REMOVED IT.
(*
if (YGap>0.0) then
begin
CheckYDivisions := Round((YMax + (YGap - 1)) / YGap);
if CheckYDivisions<>YDivisions then
YDivisions :=CheckYDivisions;
end;*)
VC := YDivisions;
if VC < 1 then
VC := 1;
FYGap := ((YMax - YMin) / VC);
FYGap1 := (((YMax - YMin) + 1) / VC);
YPixelGap := ((FOwner.YEnd - 1) / VC); // Vertical Pixels Per Value Division counter.
(*CheckYDivisions := Round(((YMax-YMin) + (YGap - 1)) / YGap);
if CheckYDivisions<>YDivisions then
YDivisions :=CheckYDivisions; *)
//---------------------------------------------------------------------
// Here's the normalization section:
// !!!The 10 and 20 here should be properties settable by the user!!!
//---------------------------------------------------------------------
if YDivisions < MinYDivisions then
begin
YDivisions := MinYDivisions;
FYGap := (YMax - YMin) / YDivisions;
end
else
begin
if YDivisions > MaxYDivisions then
begin
YDivisions := MaxYDivisions;
FYGap := (YMax - YMin) / YDivisions;
end;
end;
end;
procedure TJvChartYAxisOptions.SetYMin(NewYMin: Double);
begin
if NewYMin = FYMin then
Exit;
FYMin := NewYMin;
if not Assigned(FOwner) then
Exit;
if not Assigned(FOwner.FOwner) then
Exit;
if csLoading in FOwner.FOwner.ComponentState then
Exit;
// Rework other values around new YMin:
Normalize;
FOwner.NotifyOptionsChange;
{NEW: Auto-Regenerate Y Axis Labels}
if Assigned(FYLegends) then
begin
if FYLegends.Count > 0 then
begin
FYLegends.Clear;
FOwner.FOwner.PrimaryYAxisLabels;
end;
end;
end;
procedure TJvChartYAxisOptions.SetYMax(NewYMax: Double);
begin
if NewYMax = FYMax then
Exit;
FYMax := NewYMax;
if not Assigned(FOwner) then
Exit;
if not Assigned(FOwner.FOwner) then
Exit;
if csLoading in FOwner.FOwner.ComponentState then
Exit;
// Rework other values around new YMax:
Normalize;
FOwner.NotifyOptionsChange;
{NEW: Auto-Regenerate Y Axis Labels}
if Assigned(FYLegends) then
begin
if FYLegends.Count > 0 then
begin
FYLegends.Clear;
FOwner.FOwner.PrimaryYAxisLabels;
end;
end;
end;
(*procedure TJvChartYAxisOptions.SetYGap(newYgap: Double);
begin
if (FYGap < 5.0) and (YMax>100) then
begin
OutputDebugString('Bug');
end;
FYGap := newYGap;
// TODO: Fire event, and cause a refresh, recalculate other
// dependant fields that are calculated from the YGap.
FOwner.NotifyOptionsChange; // Fire event before we auto-format graph. Allows some customization to occur here.
end;
*)
function TJvChartYAxisOptions.GetYLegends: TStrings;
begin
Result := FYLegends as TStrings;
end;
procedure TJvChartYAxisOptions.SetYLegends(Value: TStrings);
begin
FYLegends.Assign(Value);
if Assigned(FOwner) then
FOwner.NotifyOptionsChange; // Fire event before we auto-format graph. Allows some customization to occur here.
end;
procedure TJvChartYAxisOptions.SetYDivisions(AValue: Integer);
begin
FYDivisions := AValue;
if not Assigned(FOwner) then
Exit;
if not Assigned(FOwner.FOwner) then
Exit;
if csLoading in FOwner.FOwner.ComponentState then
Exit;
// Rework other values around new YMax:
Normalize;
FOwner.NotifyOptionsChange;
end;
//=== { TJvChartOptions } ====================================================
constructor TJvChartOptions.Create(Owner: TJvChart);
begin
inherited Create;
FOwner := Owner;
FAutoUpdateGraph := True;
FPrimaryYAxis := TJvChartYAxisOptions.Create(Self);
FSecondaryYAxis := TJvChartYAxisOptions.Create(Self);
FXAxisDivisionMarkers := True; //default property.
FYAxisDivisionMarkers := True; //default property.
SetLength(FPenColors, 12);
FPenColors[0] := clLime;
FPenColors[1] := clRed;
FPenColors[2] := clBlue;
FPenColors[3] := clYellow;
FPenColors[4] := clMaroon;
FPenColors[5] := clGreen;
FPenColors[6] := clOlive;
FPenColors[7] := clNavy;
FPenColors[8] := clPurple;
FPenColors[9] := clTeal;
FPenColors[10] := clFuchsia;
FPenColors[11] := clAqua;
FChartKind := ckChartLine;
FPenCount := 1;
FLegend := clChartLegendNone; //default Legend is None.
// Create TStringList property objects
FXLegends := TStringList.Create;
FPenLegends := TStringList.Create;
FPenUnit := TStringList.Create;
// dynamic array setup
SetLength(FAverageValue, DEFAULT_VALUE_COUNT);
// Defaults for Graph Options:
FMarkerSize := JvChartDefaultMarkerSize;
FXStartOffset := 45; {DEFAULT}
FYStartOffset := 10;
FTitle := '';
// FXAxisHeader := 'X';
// FYAxisHeader := 'Y';
FPaperColor := clWhite;
FAxisLineColor := clBlack;
FAverageLineColor := JvDefaultAvgLineColor;
FDivisionLineColor := JvDefaultDivisionLineColor; // NEW!
FShadowColor := JvDefaultShadowColor; //NEW!
FHeaderFont := TFont.Create;
FLegendFont := TFont.Create;
FAxisFont := TFont.Create;
//FShowLegend := True;
FMouseEdit := True;
FMouseInfo := True;
FLegendWidth := 150;
FPenLineWidth := 1;
FAxisLineWidth := 3;
FXValueCount := 10;
FXAxisLegendSkipBy := 1;
FXLegendHoriz := 0;
FHintColor := JvDefaultHintColor;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -