mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-13 09:29:10 +02:00
TAChart: display labels on bar series. Initial crude implementation.
git-svn-id: trunk@18859 -
This commit is contained in:
parent
7e91120fe5
commit
0aa059ecff
@ -99,6 +99,7 @@ var
|
|||||||
i: integer;
|
i: integer;
|
||||||
begin
|
begin
|
||||||
if FBar = nil then InitBar;
|
if FBar = nil then InitBar;
|
||||||
|
FBar.MarksStyle := TSeriesMarksStyle(cbMarkStyle.ItemIndex);
|
||||||
for i := 1 to edAddCount.Value do begin
|
for i := 1 to edAddCount.Value do begin
|
||||||
FBar.AddXY(x, y, '', clRed);
|
FBar.AddXY(x, y, '', clRed);
|
||||||
X := X + 1;
|
X := X + 1;
|
||||||
|
@ -1208,29 +1208,54 @@ end;
|
|||||||
|
|
||||||
procedure TBarSeries.Draw(ACanvas: TCanvas);
|
procedure TBarSeries.Draw(ACanvas: TCanvas);
|
||||||
var
|
var
|
||||||
i: Integer;
|
|
||||||
barX, barTopY, barBottomY: Double;
|
barX, barTopY, barBottomY: Double;
|
||||||
barWidth, totalbarWidth, totalBarSeries, myPos: Integer;
|
i, barWidth, totalbarWidth, totalBarSeries, myPos: Integer;
|
||||||
r: TRect;
|
r: TRect;
|
||||||
begin
|
prevLabelRect: TRect = (Left: 0; Top: 0; Right: 0; Bottom: 0);
|
||||||
if FCoordList.Count = 0 then exit;
|
|
||||||
|
|
||||||
// Calculate the single bar width.
|
procedure DrawLabel;
|
||||||
totalbarWidth :=
|
const
|
||||||
Round(FBarWidthPercent * 0.01 * ParentChart.ChartWidth / FCoordList.Count);
|
DIST = 10;
|
||||||
ExamineAllBarSeries(totalBarSeries, myPos);
|
var
|
||||||
barWidth := totalbarWidth div totalBarSeries;
|
labelRect: TRect;
|
||||||
|
dummy: TRect = (Left: 0; Top: 0; Right: 0; Bottom: 0);
|
||||||
|
labelText: String;
|
||||||
|
labelSize: TSize;
|
||||||
|
xc: Integer;
|
||||||
|
labelPos: TPoint;
|
||||||
|
begin
|
||||||
|
labelText := FormattedMark(i);
|
||||||
|
if labelText = '' then exit;
|
||||||
|
|
||||||
ACanvas.Brush.Assign(BarBrush);
|
labelSize := ACanvas.TextExtent(labelText);
|
||||||
if barWidth > 2 then
|
xc := (r.Left + r.Right) div 2;
|
||||||
ACanvas.Pen.Assign(BarPen)
|
labelPos.X := xc - labelSize.cx div 2;
|
||||||
else begin
|
labelPos.Y :=
|
||||||
// Bars are too narrow to distinguish border from interior.
|
ifthen(barTopY = 0, r.Bottom + DIST, r.Top - DIST - labelSize.cy);
|
||||||
ACanvas.Pen.Color := BarBrush.Color;
|
labelRect := Bounds(labelPos.X, labelPos.Y, labelSize.cx, labelSize.cy);
|
||||||
ACanvas.Pen.Style := psSolid;
|
InflateRect(labelRect, 4, 2);
|
||||||
|
if
|
||||||
|
not IsRectEmpty(prevLabelRect) and
|
||||||
|
IntersectRect(dummy, labelRect, prevLabelRect)
|
||||||
|
then
|
||||||
|
exit;
|
||||||
|
prevLabelRect := labelRect;
|
||||||
|
|
||||||
|
// Link between the label and the bar.
|
||||||
|
ACanvas.Pen.Color := clWhite;
|
||||||
|
if barTopY = 0 then
|
||||||
|
ACanvas.Line(xc, r.Bottom, xc, labelRect.Top)
|
||||||
|
else
|
||||||
|
ACanvas.Line(xc, r.Top - 1, xc, labelRect.Bottom - 1);
|
||||||
|
|
||||||
|
ACanvas.Pen.Color := clBlack;
|
||||||
|
ACanvas.Brush.Color := clYellow;
|
||||||
|
ACanvas.Rectangle(labelRect);
|
||||||
|
ACanvas.TextOut(labelPos.X, labelPos.Y, labelText);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
for i := 0 to FCoordList.Count - 1 do begin
|
function PrepareBar: Boolean;
|
||||||
|
begin
|
||||||
with PChartCoord(FCoordList.Items[i])^ do begin
|
with PChartCoord(FCoordList.Items[i])^ do begin
|
||||||
barX := x;
|
barX := x;
|
||||||
barTopY := y;
|
barTopY := y;
|
||||||
@ -1241,11 +1266,10 @@ begin
|
|||||||
|
|
||||||
with ParentChart do begin
|
with ParentChart do begin
|
||||||
// Check if bar is in view port.
|
// Check if bar is in view port.
|
||||||
if
|
Result :=
|
||||||
not InRange(barX, XGraphMin, XGraphMax) or
|
InRange(barX, XGraphMin, XGraphMax) and
|
||||||
not FloatRangesOverlap(barBottomY, barTopY, YGraphMin, YGraphMax)
|
FloatRangesOverlap(barBottomY, barTopY, YGraphMin, YGraphMax);
|
||||||
then
|
if not Result then exit;
|
||||||
continue;
|
|
||||||
|
|
||||||
// Only draw to the limits.
|
// Only draw to the limits.
|
||||||
if barTopY > YGraphMax then barTopY := YGraphMax;
|
if barTopY > YGraphMax then barTopY := YGraphMax;
|
||||||
@ -1259,12 +1283,38 @@ begin
|
|||||||
// Adjust for multiple bar series.
|
// Adjust for multiple bar series.
|
||||||
r.Left += myPos * barWidth - totalbarWidth div 2;
|
r.Left += myPos * barWidth - totalbarWidth div 2;
|
||||||
r.Right := r.Left + barWidth;
|
r.Right := r.Left + barWidth;
|
||||||
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
if FCoordList.Count = 0 then exit;
|
||||||
|
|
||||||
|
totalbarWidth :=
|
||||||
|
Round(FBarWidthPercent * 0.01 * ParentChart.ChartWidth / FCoordList.Count);
|
||||||
|
ExamineAllBarSeries(totalBarSeries, myPos);
|
||||||
|
barWidth := totalbarWidth div totalBarSeries;
|
||||||
|
|
||||||
|
ACanvas.Brush.Assign(BarBrush);
|
||||||
|
for i := 0 to FCoordList.Count - 1 do begin
|
||||||
|
if not PrepareBar then continue;
|
||||||
// Draw a line instead of an empty rectangle.
|
// Draw a line instead of an empty rectangle.
|
||||||
if r.Bottom = r.Top then Inc(r.Bottom);
|
if r.Bottom = r.Top then Inc(r.Bottom);
|
||||||
if r.Left = r.Right then Inc(r.Right);
|
if r.Left = r.Right then Inc(r.Right);
|
||||||
|
|
||||||
|
if (barWidth > 2) and (r.Bottom - r.Top > 2) then
|
||||||
|
ACanvas.Pen.Assign(BarPen)
|
||||||
|
else begin
|
||||||
|
// Bars are too small to distinguish border from interior.
|
||||||
|
ACanvas.Pen.Color := BarBrush.Color;
|
||||||
|
ACanvas.Pen.Style := psSolid;
|
||||||
|
end;
|
||||||
|
|
||||||
ACanvas.Rectangle(r);
|
ACanvas.Rectangle(r);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
if MarksStyle = smsNone then exit;
|
||||||
|
for i := 0 to FCoordList.Count - 1 do
|
||||||
|
if PrepareBar then
|
||||||
|
DrawLabel;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TBarSeries.DrawLegend(ACanvas: TCanvas; const ARect: TRect);
|
procedure TBarSeries.DrawLegend(ACanvas: TCanvas; const ARect: TRect);
|
||||||
|
Loading…
Reference in New Issue
Block a user