Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
PlotLine.cs
1using System;
2using System.Text;
4
6{
10 public class PlotLine : Plot
11 {
12 private readonly string color;
13 private Series x = null;
14 private Series y = null;
15 private int index = 1;
16 private bool first = true;
17
21 protected readonly StringBuilder graph = new StringBuilder();
22
28 : this(Model, "Red")
29 {
30 }
31
37 public PlotLine(Model Model, string Color)
38 : base(Model)
39 {
40 this.color = Color;
41 }
42
46 public int Index => this.index;
47
51 public string Color => this.color;
52
56 public override bool HasGraph
57 {
58 get
59 {
60 this.Break();
61 return this.index > 1;
62 }
63 }
64
69 public override void Add(Statistic Record)
70 {
71 if (Record.Mean.HasValue)
72 this.AddPoint(this.GetMeanTime(Record), Record.Mean.Value);
73 else if (Record.Count > 0)
74 this.AddPoint(this.GetMeanTime(Record), Record.Count);
75 else
76 this.Break();
77 }
78
84 public void AddPoint(double X, double Y)
85 {
86 if (this.first)
87 {
88 this.first = false;
89
90 this.x = new Series("x" + this.index.ToString());
91 this.y = new Series("y" + this.index.ToString());
92 }
93
94 this.x.Add(X);
95 this.y.Add(Y);
96 }
97
101 public override void Break()
102 {
103 if (!this.first)
104 {
105 this.graph.AppendLine(this.x.EndSeries());
106 this.graph.AppendLine(this.y.EndSeries());
107
108 this.index++;
109 this.first = true;
110 this.x = null;
111 this.y = null;
112 }
113 }
114
119 public override string GetPlotScript()
120 {
121 this.Break();
122
123 int i;
124
125 for (i = 1; i < this.index; i++)
126 {
127 if (i > 1)
128 this.graph.Append('+');
129
130 this.graph.Append("plot2dline(x");
131 this.graph.Append(i.ToString());
132 this.graph.Append(",y");
133 this.graph.Append(i.ToString());
134 this.graph.Append(",\"");
135 this.graph.Append(this.color);
136 this.graph.Append("\",5)");
137 }
138
139 return this.graph.ToString();
140 }
141
142 }
143}
Root node of a simulation model
Definition: Model.cs:49
Abstract base class for plots
Definition: Plot.cs:10
double GetMeanTime(Statistic Record)
Gets the mean time of a statistic.
Definition: Plot.cs:47
PlotLine(Model Model)
Plots a line graph
Definition: PlotLine.cs:27
void AddPoint(double X, double Y)
Adds a point to the graph.
Definition: PlotLine.cs:84
PlotLine(Model Model, string Color)
Plots a line graph
Definition: PlotLine.cs:37
override void Break()
Breaks the graph.
Definition: PlotLine.cs:101
override bool HasGraph
If there is a plot to display.
Definition: PlotLine.cs:57
readonly StringBuilder graph
Graph being built.
Definition: PlotLine.cs:21
override void Add(Statistic Record)
Adds a statistic to the plot.
Definition: PlotLine.cs:69
override string GetPlotScript()
Gets the plot script
Definition: PlotLine.cs:119
string EndSeries()
Ends the series.
Definition: Series.cs:43
void Add(double Value)
Adds a value to the series.
Definition: Series.cs:29
Represents collected statistical information from a small portion of time.
Definition: Statistic.cs:12
long Count
Number of events
Definition: Statistic.cs:97