NTP Analyzer  0.8.2
Analyze the operation of time servers
Ntp.Analyzer.Graph.GraphBase Class Referenceabstract
Inheritance diagram for Ntp.Analyzer.Graph.GraphBase:
Collaboration diagram for Ntp.Analyzer.Graph.GraphBase:

Public Member Functions

Stream Generate ()
 
Stream Render ()
 

Public Attributes

IEnumerable< StreamDestinationDestinations => destinations
 
string ImageFileExtension => "png"
 

Protected Member Functions

 GraphBase (IGraphBaseConfiguration baseConfig)
 
abstract void AddPlots ()
 
abstract void LoadData ()
 
virtual void PreRender ()
 
LinePlot SetupPlot (string name, Color color, IList time, IList data)
 

Protected Attributes

TimeSpan GraphTimeSpan => new TimeSpan(baseConfig.Timespan, 0, 0, 0)
 

Properties

PlotSurface2D Surface [get, private set]
 
abstract string YLabel [get]
 
- Properties inherited from Ntp.Analyzer.Export.IStreamGenerator
IEnumerable< StreamDestinationDestinations [get]
 

Private Attributes

readonly IGraphBaseConfiguration baseConfig
 
readonly List< StreamDestinationdestinations
 

Static Private Attributes

static readonly object Locker = new object()
 

Detailed Description

Definition at line 36 of file GraphBase.cs.

Constructor & Destructor Documentation

Ntp.Analyzer.Graph.GraphBase.GraphBase ( IGraphBaseConfiguration  baseConfig)
inlineprotected

Definition at line 38 of file GraphBase.cs.

References Ntp.Analyzer.Interface.IGraphBaseConfiguration.Locations.

39  {
40  this.baseConfig = baseConfig;
41  destinations = new List<StreamDestination>(baseConfig.Locations);
42  }
readonly List< StreamDestination > destinations
Definition: GraphBase.cs:46
readonly IGraphBaseConfiguration baseConfig
Definition: GraphBase.cs:45

Member Function Documentation

abstract void Ntp.Analyzer.Graph.GraphBase.AddPlots ( )
protectedpure virtual
Stream Ntp.Analyzer.Graph.GraphBase.Generate ( )
inline

Implements Ntp.Analyzer.Export.IStreamGenerator.

Definition at line 58 of file GraphBase.cs.

59  {
61 
62  // Only one loader at the time
63  lock (Locker)
64  {
65  LoadData();
66  }
67 
68  var titleFont = new Font("Arial", 12);
69  var axisFont = new Font("Arial", 10);
70  var legendFont = new Font("Arial", 10);
71  var tickFont = new Font("Arial", 8);
72 
73  // Prepare PlotSurface:
74  Surface.Clear();
75  Surface.Title = baseConfig.Title;
76  Surface.TitleFont = titleFont;
77  Surface.SmoothingMode = SmoothingMode.HighQuality;
78  Surface.BackColor = Color.White;
79  Surface.Add(new Grid(), NPlot.PlotSurface2D.XAxisPosition.Bottom, NPlot.PlotSurface2D.YAxisPosition.Left);
80 
81  AddPlots();
82 
83  // Prepare axis
84  Surface.XAxis1.Label = string.Empty;
85  Surface.XAxis1.LabelFont = axisFont;
86  Surface.XAxis1.TickTextFont = tickFont;
87  Surface.XAxis1.TicksLabelAngle = 0;
88  Surface.XAxis1.TickTextNextToAxis = true;
89  Surface.XAxis1.FlipTicksLabel = true;
90  Surface.XAxis1.LabelOffset = 95;
91  Surface.XAxis1.LabelOffsetAbsolute = true;
92  Surface.XAxis1.NumberFormat = baseConfig.Timespan <= 2 ? "HH" : "MMMM d";
93  Surface.YAxis1.Label = YLabel;
94  Surface.YAxis1.LabelFont = axisFont;
95  Surface.YAxis1.LabelOffsetScaled = true;
96  Surface.YAxis1.TickTextFont = tickFont;
97  Surface.YAxis1.NumberFormat = "{0:####0.00}";
98 
99  if (Surface.YAxis2 != null)
100  {
101  Surface.YAxis2.Label = "Value";
102  Surface.YAxis2.LabelFont = axisFont;
103  Surface.YAxis2.TickTextFont = tickFont;
104  Surface.YAxis2.NumberFormat = "{0:####0.00}";
105  }
106 
107  // Add legend
108  var legend = new Legend {Font = legendFont};
109  legend.AttachTo(NPlot.PlotSurface2D.XAxisPosition.Top, NPlot.PlotSurface2D.YAxisPosition.Left);
110  legend.VerticalEdgePlacement = Legend.Placement.Inside;
111  legend.HorizontalEdgePlacement = Legend.Placement.Inside;
112  legend.BorderStyle = LegendBase.BorderType.Line;
113  legend.BackgroundColor = Color.White;
114  legend.XOffset = 20;
115  legend.YOffset = 15;
116  Surface.Legend = legend;
117  Surface.LegendZOrder = 10;
118 
119  PreRender();
120 
121  return Render();
122  }
NPlot.Bitmap.PlotSurface2D PlotSurface2D
Definition: GraphBase.cs:32
abstract string YLabel
Definition: GraphBase.cs:48
virtual void PreRender()
Definition: GraphBase.cs:154
static readonly object Locker
Definition: GraphBase.cs:44
readonly IGraphBaseConfiguration baseConfig
Definition: GraphBase.cs:45
abstract void Ntp.Analyzer.Graph.GraphBase.LoadData ( )
protectedpure virtual
virtual void Ntp.Analyzer.Graph.GraphBase.PreRender ( )
inlineprotectedvirtual

Reimplemented in Ntp.Analyzer.Graph.TrafficGraph, and Ntp.Analyzer.Graph.PeerGraph.

Definition at line 154 of file GraphBase.cs.

155  {
156  }
Stream Ntp.Analyzer.Graph.GraphBase.Render ( )
inline

Definition at line 124 of file GraphBase.cs.

References b.

125  {
126  var stream = new MemoryStream();
127 
128  if (Surface == null)
129  return stream;
130 
131  // Only one rendering at the time
132  lock (Locker)
133  {
134  using (var b = new Bitmap(baseConfig.Width, baseConfig.Height))
135  using (var g = Graphics.FromImage(b))
136  {
137  g.FillRectangle(new Pen(Color.White).Brush, 0, 0, b.Width, b.Height);
138  Surface.Draw(Graphics.FromImage(b), new Rectangle(0, 0, b.Width, b.Height));
139 
140  b.Save(stream, ImageFormat.Png);
141  }
142 
143  // Force garbage collection
144  GC.Collect();
145  }
146 
147  return stream;
148  }
static readonly object Locker
Definition: GraphBase.cs:44
var b
Definition: bootstrap.min.js:6
readonly IGraphBaseConfiguration baseConfig
Definition: GraphBase.cs:45
LinePlot Ntp.Analyzer.Graph.GraphBase.SetupPlot ( string  name,
Color  color,
IList  time,
IList  data 
)
inlineprotected

Definition at line 158 of file GraphBase.cs.

159  {
160  var plot = new LinePlot
161  {
162  AbscissaData = time,
163  DataSource = data,
164  Color = color,
165  Shadow = false,
166  Label = name
167  };
168 
169  return plot;
170  }

Member Data Documentation

readonly IGraphBaseConfiguration Ntp.Analyzer.Graph.GraphBase.baseConfig
private

Definition at line 45 of file GraphBase.cs.

readonly List<StreamDestination> Ntp.Analyzer.Graph.GraphBase.destinations
private

Definition at line 46 of file GraphBase.cs.

IEnumerable<StreamDestination> Ntp.Analyzer.Graph.GraphBase.Destinations => destinations

Definition at line 56 of file GraphBase.cs.

TimeSpan Ntp.Analyzer.Graph.GraphBase.GraphTimeSpan => new TimeSpan(baseConfig.Timespan, 0, 0, 0)
protected

Definition at line 52 of file GraphBase.cs.

string Ntp.Analyzer.Graph.GraphBase.ImageFileExtension => "png"

Definition at line 54 of file GraphBase.cs.

readonly object Ntp.Analyzer.Graph.GraphBase.Locker = new object()
staticprivate

Definition at line 44 of file GraphBase.cs.

Property Documentation

PlotSurface2D Ntp.Analyzer.Graph.GraphBase.Surface
getprivate setprotected

Definition at line 50 of file GraphBase.cs.

abstract string Ntp.Analyzer.Graph.GraphBase.YLabel
getprotected

Definition at line 48 of file GraphBase.cs.


The documentation for this class was generated from the following file: