Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
HorizontalBarPainter.cs
1using System;
2using SkiaSharp;
3
5{
10 {
20 public void DrawGraph(SKCanvas Canvas, SKPoint[] Points, object[] Parameters, SKPoint[] PrevPoints, object[] PrevParameters,
22 {
23 SKPaint Brush = null;
24 SKPath Path = null;
25
26 try
27 {
28 Brush = new SKPaint()
29 {
30 Color = Graph.ToColor(Parameters[0]),
31 Style = SKPaintStyle.Fill
32 };
33 Path = new SKPath();
34
35 int Count = DrawingArea.YLabelPositions?.Count ?? Points.Length;
36 float HalfBarHeight = (-DrawingArea.Height - Count) * 0.45f / Count;
37 float x0, y0, x1, y1;
38 int i, c;
39
40 if (!(PrevPoints is null))
41 {
42 if ((c = PrevPoints.Length) != Points.Length)
43 PrevPoints = null;
44 else
45 {
46 for (i = 0; i < c; i++)
47 {
48 if (PrevPoints[i].Y != Points[i].Y)
49 {
50 PrevPoints = null;
51 break;
52 }
53 }
54 }
55 }
56
57 int MinY = DrawingArea.OffsetY;
58 int MaxY = DrawingArea.OffsetY + DrawingArea.Height;
59
60 i = 0;
61 foreach (SKPoint Point in Points)
62 {
63 y0 = Point.Y - HalfBarHeight + 1;
64 x0 = Point.X;
65 y1 = Point.Y + HalfBarHeight - 1;
66 x1 = !(PrevPoints is null) ? PrevPoints[i++].X : DrawingArea.OrigoX;
67
68 if (y0 < MaxY)
69 y0 = MaxY;
70
71 if (y1 > MinY)
72 y1 = MinY;
73
74 Canvas.DrawRect(new SKRect(x0, y0, x1, y1), Brush);
75 }
76
77 Canvas.DrawPath(Path, Brush);
78 }
79 finally
80 {
81 Brush?.Dispose();
82 Path?.Dispose();
83 }
84 }
85 }
86}
Contains information about the current drawing area.
Definition: DrawingArea.cs:12
Dictionary< string, double > YLabelPositions
Optional fixed Y-Label positions.
Definition: DrawingArea.cs:125
int Height
Height of drawing area.
Definition: DrawingArea.cs:95
int OffsetY
Y-offset of drawing area, relative to the canvas origin.
Definition: DrawingArea.cs:85
float OrigoX
X-coordinate for the origo.
Definition: DrawingArea.cs:100
Plots a two-dimensional horizontal-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