Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
VerticalBarsPainter.cs
1using SkiaSharp;
2
4{
9 {
19 public void DrawGraph(SKCanvas Canvas, SKPoint[] Points, object[] Parameters, SKPoint[] PrevPoints, object[] PrevParameters,
21 {
22 SKPaint Brush = null;
23 SKPath Path = null;
24
25 try
26 {
27 Brush = new SKPaint()
28 {
29 Color = Graph.ToColor(Parameters[0]),
30 Style = SKPaintStyle.Fill
31 };
32 Path = new SKPath();
33
34 int Count = DrawingArea.XLabelPositions?.Count ?? Points.Length;
35 float HalfBarWidth = (DrawingArea.Width - Count) * 0.45f / Count;
36 float x0, y0, x1, y1;
37 int i, c;
38
39 if (!(PrevPoints is null))
40 {
41 if ((c = PrevPoints.Length) != Points.Length)
42 PrevPoints = null;
43 else
44 {
45 for (i = 0; i < c; i++)
46 {
47 if (PrevPoints[i].X != Points[i].X)
48 {
49 PrevPoints = null;
50 break;
51 }
52 }
53 }
54 }
55
56 int MinX = DrawingArea.OffsetX;
57 int MaxX = DrawingArea.OffsetX + DrawingArea.Width;
58
59 i = 0;
60 foreach (SKPoint Point in Points)
61 {
62 x0 = Point.X - HalfBarWidth + 1;
63 y0 = Point.Y;
64 x1 = Point.X + HalfBarWidth - 1;
65 y1 = !(PrevPoints is null) ? PrevPoints[i++].Y : DrawingArea.OrigoY;
66
67 if (x0 < MinX)
68 x0 = MinX;
69
70 if (x1 > MaxX)
71 x1 = MaxX;
72
73 Canvas.DrawRect(new SKRect(x0, y0, x1, y1), Brush);
74 }
75
76 Canvas.DrawPath(Path, Brush);
77 }
78 finally
79 {
80 Brush?.Dispose();
81 Path?.Dispose();
82 }
83 }
84
85 }
86}
Contains information about the current drawing area.
Definition: DrawingArea.cs:12
float OrigoY
Y-coordinate for the origo.
Definition: DrawingArea.cs:105
Dictionary< string, double > XLabelPositions
Optional fixed X-Label positions.
Definition: DrawingArea.cs:116
int Width
Width of drawing area.
Definition: DrawingArea.cs:90
int OffsetX
X-offset of drawing area, relative to the canvas origin.
Definition: DrawingArea.cs:80
Plots a two-dimensional vertical-bar chart.
void DrawGraph(SKCanvas Canvas, SKPoint[] Points, object[] Parameters, SKPoint[] PrevPoints, object[] PrevParameters, DrawingArea DrawingArea)
Draws the graph on a canvas.
Base class for graphs.
Definition: Graph.cs:79
static SKColor ToColor(object Object)
Converts an object to a color.
Definition: Graph.cs:828
Interface for 2D graph drawing functions.
Definition: IPainter2D.cs:10