📄 jvqchart.pas
字号:
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;
destructor TJvChartOptions.Destroy;
begin
FreeAndNil(FPrimaryYAxis); //memory leak fix SEPT 21, 2004.WAP.
FreeAndNil(FSecondaryYAxis); //memory leak fix SEPT 21, 2004. WAP.
FreeAndNil(FXLegends);
FreeAndNil(FPenLegends);
FreeAndNil(FPenUnit);
FreeAndNil(FHeaderFont);
FreeAndNil(FLegendFont);
FreeAndNil(FAxisFont);
inherited Destroy;
end;
procedure TJvChartOptions.NotifyOptionsChange;
begin
if Assigned(FOwner) then
FOwner.NotifyOptionsChange;
end;
// Each pen can be associated with either the primary or secondary axis,
// this function decides which axis to return depending on the pen configuration:
function TJvChartOptions.GetPenAxis(Index: Integer): TJvChartYAxisOptions;
begin
if (Index < 0) or (Index >= Length(FPenSecondaryAxisFlag)) then
Result := FPrimaryYAxis // default
else
if FPenSecondaryAxisFlag[Index] then
Result := FSecondaryYAxis // alternate!
else
Result := FPrimaryYAxis; // default
end;
procedure TJvChartOptions.SetChartKind(AKind: TJvChartKind);
begin
if AKind <> FChartKind then
FChartKind := AKind;
end;
function TJvChartOptions.GetPenMarkerKind(Index: Integer): TJvChartPenMarkerKind;
begin
if (Index >= 0) and (Index < Length(FPenMarkerKind)) then
Result := FPenMarkerKind[Index]
else
Result := pmkNone;
end;
procedure TJvChartOptions.SetPenMarkerKind(Index: Integer; AMarkKind: TJvChartPenMarkerKind);
begin
if Index >= 0 then
begin
if Index >= Length(FPenMarkerKind) then
SetLength(FPenMarkerKind, Index + 1);
FPenMarkerKind[Index] := AMarkKind;
end;
end;
function TJvChartOptions.GetPenColor(Index: Integer): TColor;
begin
// Don't check for out of range values, since we use that on purpose in this
// function. Okay, ugly, but it works. -WP.
case Index of
jvChartAverageLineColorIndex:
Result := FAverageLineColor;
jvChartDivisionLineColorIndex: // horizontal and vertical division line color
Result := FDivisionLineColor;
jvChartShadowColorIndex: // legend shadow (light gray)
Result := FShadowColor;
jvChartAxisColorIndex:
Result := FAxisLineColor; // get property.
jvChartHintColorIndex:
Result := FHintColor; // Get property.
jvChartPaperColorIndex:
Result := FPaperColor; // Get property.
else
if Index < jvChartAverageLineColorIndex then
Result := clBtnFace
else
if Index >= 0 then
Result := FPenColors[Index]
else
Result := clNone; // I hope clNone is a good unknown value (ahuser). {{Good enough. -WP.}}
end;
end;
procedure TJvChartOptions.SetPenColor(Index: Integer; AColor: TColor);
begin
if (Index < 0) or (Index >= MAX_PEN) then
raise ERangeError.CreateRes(@RsEChartOptionsPenCountPenCountOutOf);
if Index >= Length(FPenColors) then
SetLength(FPenColors, Index + 1);
FPenColors[Index] := AColor;
end;
procedure TJvChartOptions.SetPenStyle(Index: Integer; APenStyle: TPenStyle);
begin
if (Index < 0) or (Index >= MAX_PEN) then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -