Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
GraphSettings.cs
1using System;
2using System.Xml;
3using SkiaSharp;
5
7{
11 public class GraphSettings
12 {
13 private SKColor backgroundColor = SKColors.White;
14 private SKColor axisColor = SKColors.Black;
15 private SKColor gridColor = SKColors.LightGray;
16 private string fontName = SKTypeface.Default.FamilyName;
17 private double labelFontSize = 12;
18 private int axisWidth = 2;
19 private int gridWidth = 1;
20 private int approxNrLabelsX = 5;
21 private int approxNrLabelsY = 10;
22 private int width = 640;
23 private int height = 480;
24 private int marginTop = 10;
25 private int marginBottom = 10;
26 private int marginLeft = 15;
27 private int marginRight = 15;
28 private int marginLabel = 5;
29
34 {
35 }
36
42 {
43 return new GraphSettings()
44 {
45 backgroundColor = this.backgroundColor,
46 axisColor = this.axisColor,
47 gridColor = this.gridColor,
48 fontName = this.fontName,
49 labelFontSize = this.labelFontSize,
50 axisWidth = this.axisWidth,
51 gridWidth = this.gridWidth,
52 approxNrLabelsX = this.approxNrLabelsX,
53 approxNrLabelsY = this.approxNrLabelsY,
54 width = this.width,
55 height = this.height,
56 marginTop = this.marginTop,
57 marginBottom = this.marginBottom,
58 marginLeft = this.marginLeft,
59 marginRight = this.marginRight,
60 marginLabel = this.marginLabel
61 };
62 }
63
67 public int Width
68 {
69 get => this.width;
70 set
71 {
72 if (value < 1)
73 throw new ArgumentOutOfRangeException("Value must be positive.", nameof(this.Width));
74
75 this.width = value;
76 }
77 }
78
82 public int Height
83 {
84 get => this.height;
85 set
86 {
87 if (value < 1)
88 throw new ArgumentOutOfRangeException("Value must be positive.", nameof(this.Height));
89
90 this.height = value;
91 }
92 }
93
97 public SKColor BackgroundColor
98 {
99 get => this.backgroundColor;
100 set => this.backgroundColor = value;
101 }
102
106 public SKColor AxisColor
107 {
108 get => this.axisColor;
109 set => this.axisColor = value;
110 }
111
115 public int AxisWidth
116 {
117 get => this.axisWidth;
118 set
119 {
120 if (value < 0)
121 throw new ArgumentOutOfRangeException("Value must be non-negative.", nameof(this.AxisWidth));
122
123 this.axisWidth = value;
124 }
125 }
126
130 public SKColor GridColor
131 {
132 get => this.gridColor;
133 set => this.gridColor = value;
134 }
135
139 public int GridWidth
140 {
141 get => this.gridWidth;
142 set
143 {
144 if (value < 0)
145 throw new ArgumentOutOfRangeException("Value must be non-negative.", nameof(this.GridWidth));
146
147 this.gridWidth = value;
148 }
149 }
150
154 public int MarginTop
155 {
156 get => this.marginTop;
157 set
158 {
159 if (value < 0)
160 throw new ArgumentOutOfRangeException("Value must be non-negative.", nameof(this.MarginTop));
161
162 this.marginTop = value;
163 }
164 }
165
169 public int MarginBottom
170 {
171 get => this.marginBottom;
172 set
173 {
174 if (value < 0)
175 throw new ArgumentOutOfRangeException("Value must be non-negative.", nameof(this.MarginBottom));
176
177 this.marginBottom = value;
178 }
179 }
180
184 public int MarginLeft
185 {
186 get => this.marginLeft;
187 set
188 {
189 if (value < 0)
190 throw new ArgumentOutOfRangeException("Value must be non-negative.", nameof(this.MarginLeft));
191
192 this.marginLeft = value;
193 }
194 }
195
199 public int MarginRight
200 {
201 get => this.marginRight;
202 set
203 {
204 if (value < 0)
205 throw new ArgumentOutOfRangeException("Value must be non-negative.", nameof(this.MarginRight));
206
207 this.marginRight = value;
208 }
209 }
210
214 public int MarginLabel
215 {
216 get => this.marginLabel;
217 set
218 {
219 if (value < 0)
220 throw new ArgumentOutOfRangeException("Value must be non-negative.", nameof(this.MarginLabel));
221
222 this.marginLabel = value;
223 }
224 }
225
229 public string FontName
230 {
231 get => this.fontName;
232 set
233 {
234 if (string.IsNullOrEmpty(value))
235 throw new ArgumentException("Value cannot be empty.", nameof(this.FontName));
236
237 this.fontName = value;
238 }
239 }
240
244 public double LabelFontSize
245 {
246 get => this.labelFontSize;
247 set
248 {
249 if (value < 0)
250 throw new ArgumentOutOfRangeException("Value must be positive.", nameof(this.LabelFontSize));
251
252 this.labelFontSize = value;
253 }
254 }
255
260 {
261 get => this.approxNrLabelsX;
262 set
263 {
264 if (value < 0)
265 throw new ArgumentOutOfRangeException("Value must be non-negative.", nameof(this.ApproxNrLabelsX));
266
267 this.approxNrLabelsX = value;
268 }
269 }
270
275 {
276 get => this.approxNrLabelsY;
277 set
278 {
279 if (value < 0)
280 throw new ArgumentOutOfRangeException("Value must be non-negative.", nameof(this.ApproxNrLabelsY));
281
282 this.approxNrLabelsY = value;
283 }
284 }
285
290 public void ExportSettings(XmlWriter Output)
291 {
292 Output.WriteStartElement("Settings");
293 Output.WriteAttributeString("backgroundColor", Graph.ToRGBAStyle(this.backgroundColor));
294 Output.WriteAttributeString("axisColor", Graph.ToRGBAStyle(this.axisColor));
295 Output.WriteAttributeString("gridColor", Graph.ToRGBAStyle(this.gridColor));
296 Output.WriteAttributeString("fontName", this.fontName);
297 Output.WriteAttributeString("labelFontSize", Expression.ToString(this.labelFontSize));
298 Output.WriteAttributeString("axisWidth", this.axisWidth.ToString());
299 Output.WriteAttributeString("gridWidth", this.gridWidth.ToString());
300 Output.WriteAttributeString("approxNrLabelsX", this.approxNrLabelsX.ToString());
301 Output.WriteAttributeString("approxNrLabelsY", this.approxNrLabelsY.ToString());
302 Output.WriteAttributeString("width", this.width.ToString());
303 Output.WriteAttributeString("height", this.height.ToString());
304 Output.WriteAttributeString("marginTop", this.marginTop.ToString());
305 Output.WriteAttributeString("marginBottom", this.marginBottom.ToString());
306 Output.WriteAttributeString("marginLeft", this.marginLeft.ToString());
307 Output.WriteAttributeString("marginRight", this.marginRight.ToString());
308 Output.WriteAttributeString("marginLabel", this.marginLabel.ToString());
309 Output.WriteEndElement();
310 }
311
317 public static GraphSettings Import(XmlElement Xml)
318 {
319 GraphSettings Result = new GraphSettings();
320 string s;
321
322 if (!string.IsNullOrEmpty(s = Xml.GetAttribute("backgroundColor")) && Color.TryParse(s, out SKColor cl))
323 Result.backgroundColor = cl;
324
325 if (!string.IsNullOrEmpty(s = Xml.GetAttribute("axisColor")) && Color.TryParse(s, out cl))
326 Result.axisColor = cl;
327
328 if (!string.IsNullOrEmpty(s = Xml.GetAttribute("gridColor")) && Color.TryParse(s, out cl))
329 Result.gridColor = cl;
330
331 if (!string.IsNullOrEmpty(s = Xml.GetAttribute("fontName")))
332 Result.fontName = s;
333
334 if (!string.IsNullOrEmpty(s = Xml.GetAttribute("labelFontSize")) && Expression.TryParse(s, out double d))
335 Result.labelFontSize = d;
336
337 if (!string.IsNullOrEmpty(s = Xml.GetAttribute("axisWidth")) && int.TryParse(s, out int i))
338 Result.axisWidth = i;
339
340 if (!string.IsNullOrEmpty(s = Xml.GetAttribute("gridWidth")) && int.TryParse(s, out i))
341 Result.gridWidth = i;
342
343 if (!string.IsNullOrEmpty(s = Xml.GetAttribute("approxNrLabelsX")) && int.TryParse(s, out i))
344 Result.approxNrLabelsX = i;
345
346 if (!string.IsNullOrEmpty(s = Xml.GetAttribute("approxNrLabelsY")) && int.TryParse(s, out i))
347 Result.approxNrLabelsY = i;
348
349 if (!string.IsNullOrEmpty(s = Xml.GetAttribute("width")) && int.TryParse(s, out i))
350 Result.width = i;
351
352 if (!string.IsNullOrEmpty(s = Xml.GetAttribute("height")) && int.TryParse(s, out i))
353 Result.height = i;
354
355 if (!string.IsNullOrEmpty(s = Xml.GetAttribute("marginTop")) && int.TryParse(s, out i))
356 Result.marginTop = i;
357
358 if (!string.IsNullOrEmpty(s = Xml.GetAttribute("marginBottom")) && int.TryParse(s, out i))
359 Result.marginBottom = i;
360
361 if (!string.IsNullOrEmpty(s = Xml.GetAttribute("marginLeft")) && int.TryParse(s, out i))
362 Result.marginLeft = i;
363
364 if (!string.IsNullOrEmpty(s = Xml.GetAttribute("marginRight")) && int.TryParse(s, out i))
365 Result.marginRight = i;
366
367 if (!string.IsNullOrEmpty(s = Xml.GetAttribute("marginLabel")) && int.TryParse(s, out i))
368 Result.marginLabel = i;
369
370 return Result;
371 }
372
373 }
374}
Class managing a script expression.
Definition: Expression.cs:41
static bool TryParse(string s, out double Value)
Tries to parse a double-precision floating-point value.
Definition: Expression.cs:4781
static string ToString(double Value)
Converts a value to a string, that can be parsed as part of an expression.
Definition: Expression.cs:4760
Returns a color value from a string.
Definition: Color.cs:14
static bool TryParse(string s, out SKColor Color)
Tries to parse a string containing a color name.
Definition: Color.cs:69
Base class for graphs.
Definition: Graph.cs:88
static string ToRGBAStyle(SKColor Color)
Converts a color to an RGB(A) style string.
Definition: Graph.cs:919
void ExportSettings(XmlWriter Output)
Exports the settings to an XML writer.
SKColor BackgroundColor
Background color.
int ApproxNrLabelsY
Approximate number of labels along the Y-axis.
int ApproxNrLabelsX
Approximate number of labels along the X-axis.
static GraphSettings Import(XmlElement Xml)
Imports graph settings from an XML element.
double LabelFontSize
Label font size
int Width
Width of graph, in pixels. (Default=640 pixels.)
int Height
Height of graph, in pixels. (Default=480 pixels.)
GraphSettings Copy()
Copies the graph settings.