1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
unit TASeriesPropEditors;
{$H+}
interface
procedure Register;
implementation
uses
Graphics, Classes, Math, PropEdits, SysUtils, LCLIntf, typinfo,
TATypes, TADrawerCanvas, TACustomSeries, TASeries, TALegend,
TAGraph, TAChartCombos;
type
TAxisIndexPropertyEditor = class(TOrdinalPropertyEditor)
public
function GetAttributes: TPropertyAttributes; override;
function OrdValueToVisualValue(AOrdValue: Longint): String; override;
procedure GetValues(AProc: TGetStrProc); override;
procedure SetValue(const ANewValue: String); override;
end;
TSeriesPointerStylePropertyEditor = class(TEnumPropertyEditor)
private
procedure DrawPointer(ACanvas: TCanvas; ARect: TRect;
AStyle: TSeriesPointerStyle; APenColor, ABrushColor: TColor);
public
function GetAttributes: TPropertyAttributes; override;
procedure ListMeasureWidth(const {%H-}CurValue: ansistring; {%H-}AIndex:integer;
{%H-}ACanvas: TCanvas; var AWidth: Integer); override;
procedure ListDrawValue(const CurValue: ansistring; {%H-}AIndex:integer;
ACanvas: TCanvas; const ARect: TRect; AState: TPropEditDrawState); override;
procedure PropDrawValue(ACanvas: TCanvas; const ARect: TRect;
AState:TPropEditDrawState); override;
end;
procedure Register;
begin
RegisterPropertyEditor(
TypeInfo(TChartAxisIndex), TCustomChartSeries, '', TAxisIndexPropertyEditor);
RegisterPropertyEditor(
TypeInfo(TSeriesPointerStyle), TSeriesPointer, '', TSeriesPointerStylePropertyEditor);
RegisterPropertyEditor(
TypeInfo(TSeriesPointerStyle), TChartComboBox, '', TSeriespointerStylePropertyEditor);
end;
{ TAxisIndexPropertyEditor }
function TAxisIndexPropertyEditor.GetAttributes: TPropertyAttributes;
begin
Result := [paMultiSelect, paValueList, paRevertable];
end;
procedure TAxisIndexPropertyEditor.GetValues(AProc: TGetStrProc);
var
s: TCustomChartSeries;
ch: TChart;
i: Integer;
begin
s := GetComponent(0) as TCustomChartSeries;
ch := s.ParentChart;
AProc('-1 None');
if ch <> nil then
for i := 0 to ch.AxisList.Count - 1 do
AProc(IntToStr(i) + ' ' + ch.AxisList[i].DisplayName);
end;
function TAxisIndexPropertyEditor.OrdValueToVisualValue(
AOrdValue: Longint): String;
var
s: TCustomChartSeries;
ch: TChart;
begin
s := GetComponent(0) as TCustomChartSeries;
ch := s.ParentChart;
Result := IntToStr(AOrdValue) + ' ';
if Assigned(ch) and InRange(AOrdValue, 0, ch.AxisList.Count - 1) then
Result += ch.AxisList[AOrdValue].DisplayName
else
Result += 'None';
end;
procedure TAxisIndexPropertyEditor.SetValue(const ANewValue: String);
var
v: Integer;
code: Word;
begin
Val(ANewValue, v, code);
if code > 0 then
Val(Copy(ANewValue, 1, code - 1), v, code);
SetOrdValue(Max(v, Low(TChartAxisIndex)));
end;
{ TSeriesPointerStylePropertyEditor }
procedure TSeriesPointerStylePropertyEditor.DrawPointer(ACanvas: TCanvas;
ARect: TRect; AStyle: TSeriesPointerStyle; APenColor, ABrushColor: TColor);
var
pointer: TSeriesPointer;
c: TPoint;
begin
pointer := TSeriesPointer.Create(nil);
try
pointer.Style := AStyle;
Pointer.HorizSize := (ARect.Right - ARect.Left) div 2 - 1;
Pointer.VertSize := (ARect.Bottom - ARect.Top) div 2 - 1;
Pointer.Brush.Color := ABrushColor;
Pointer.Pen.Color := APenColor;
c := Point((ARect.Left + ARect.Right) div 2, (ARect.Top + ARect.Bottom) div 2);
pointer.Draw(TCanvasDrawer.Create(ACanvas), c, ABrushColor);
finally
pointer.Free;
end;
end;
function TSeriesPointerStylePropertyEditor.GetAttributes: TPropertyAttributes;
begin
Result := (inherited GetAttributes) + [paCustomDrawn];
end;
procedure TSeriesPointerStylePropertyEditor.ListMeasureWidth(
const CurValue: ansistring; AIndex:integer; ACanvas: TCanvas;
var AWidth: Integer);
begin
AWidth := 130;
end;
procedure TSeriesPointerStylePropertyEditor.ListDrawValue(const CurValue: ansistring;
AIndex:integer; ACanvas: TCanvas; const ARect: TRect; AState: TPropEditDrawState);
const
MARGIN = 2;
var
lRect: TRect;
oldPenColor, oldBrushColor: TColor;
oldPenStyle: TPenStyle;
i: Integer;
begin
lRect := ARect;
lRect.Right := lRect.Left + (lRect.Bottom - lRect.Top); // * 3 div 2;
InflateRect(lRect, -MARGIN, -MARGIN);
with ACanvas do
try
// save off things
oldPenColor := Pen.Color;
oldBrushColor := Brush.Color;
oldPenStyle := Pen.Style;
try
{
// white out the background
Brush.Color := clWindow;
FillRect(ARect);
}
// set things up and do work
i := GetEnumValue(GetPropInfo^.PropType, CurValue);
DrawPointer(ACanvas, lRect, TSeriesPointerStyle(i), clWindowText, clWindowText);
finally
// restore the things we twiddled with
Brush.Color := oldBrushColor;
Pen.Style := oldPenStyle;
Pen.Color := oldPenColor;
end;
finally
lRect := Rect(lRect.Right + 2*MARGIN, ARect.Top, ARect.Right, ARect.Bottom);
inherited ListDrawValue(CurValue, -1, ACanvas, lRect, AState);
end;
end;
procedure TSeriesPointerStylePropertyEditor.PropDrawValue(ACanvas: TCanvas;
const ARect: TRect; AState:TPropEditDrawState);
begin
if GetVisualValue <> '' then
ListDrawValue(GetVisualValue, -1, ACanvas, ARect, [pedsInEdit])
else
inherited PropDrawValue(ACanvas, ARect, AState);
end;
end.
|