4 using System.Collections.Generic;
11 private Dictionary<String, Plotter>
plots =
new Dictionary<String, Plotter>();
38 foreach (KeyValuePair<String, Plotter> p
in plots)
53 public void PlotAdd(String plotName,
float value)
55 if (plots.ContainsKey(plotName)) plots[plotName].
Add(value);
64 public void PlotCreate(String plotName,
float min,
float max, Color plotColor, Vector2 pos)
66 if (!plots.ContainsKey(plotName))
68 plots.Add(plotName,
new Plotter(plotName, grid, min, max, plotColor, pos));
80 public void PlotCreate(String plotName,
float min,
float max, Color plotColor, String parentName)
82 if (!plots.ContainsKey(plotName) && plots.ContainsKey(parentName))
84 plots.Add(plotName,
new Plotter(plotName, grid, min, max, plotColor, plots[parentName]));
88 public void PlotCreate(String plotName, Color plotColor, String parentName)
90 if (!plots.ContainsKey(plotName) && plots.ContainsKey(parentName))
91 plots.Add(plotName,
new Plotter(plotName, grid, plotColor, plots[parentName]));
94 public void PlotCreate(String plotName,
float min,
float max, Color plotColor, ref Texture2D renderTextureReference)
96 if (!plots.ContainsKey(plotName))
98 plots.Add(plotName,
new Plotter(plotName, grid, min, max, plotColor, ref renderTextureReference));
104 if (plots.ContainsKey(plotName)) plots.Remove(plotName);
135 private Dictionary<String, Plotter>
children =
new Dictionary<string, Plotter>();
137 public Plotter(String name, Texture2D blankGraph, Color plotColor,
Plotter parent)
142 public Plotter(String name, Texture2D blankGraph,
float min,
float max, Color plotColor,
Plotter parent)
155 gridHeight = parent.
grid.height;
156 gridWidth = parent.
grid.width;
161 top = gridHeight + Mathf.RoundToInt(gridHeight * 0.17f) +
floor;
163 scale = (max - min) / top;
165 if (max > 0 && min < 0) zeroLine = (int)((-minValue) /
scale) + floor;
168 this.Parent = parent;
173 public Plotter(String name, Texture2D blankGraph,
float min,
float max, Color plotColor, Vector2 pos)
179 grid =
new Texture2D(blankGraph.width, blankGraph.height);
181 gridWidth = grid.width;
182 gridHeight = grid.height;
185 buffer = blankGraph.GetPixels();
189 top = gridHeight + Mathf.RoundToInt(gridHeight * 0.17f) +
floor;
194 scale = (max - min) / top;
196 if (max > 0 && min < 0) zeroLine = (int)((-minValue) /
scale) + floor;
201 public Plotter(String name, Texture2D blankGraph,
float min,
float max, Color plotColor, ref Texture2D renderTextureReference)
207 grid =
new Texture2D(blankGraph.width, blankGraph.height);
208 renderTextureReference =
grid;
209 gridWidth = grid.width;
210 gridHeight = grid.height;
213 buffer = blankGraph.GetPixels();
217 top = gridHeight + Mathf.RoundToInt(gridHeight * 0.17f) +
floor;
222 scale = (max - min) / top;
224 if (max > 0 && min < 0) zeroLine = (int)((-minValue) /
scale) + floor;
239 if (dataIndex == gridWidth) { dataIndex = 0; dataFull =
true; }
242 if (y > maxValue) yPos =
top;
243 else if (y < minValue) yPos =
floor;
244 else yPos = (int)((y - minValue) /
scale) + floor;
248 void DrawLine(Texture2D tex,
int x0,
int y0,
int x1,
int y1, Color col)
250 int dy = (int)(y1-y0);
251 int dx = (int)(x1-x0);
254 if (dy < 0) {dy = -dy; stepy = -1;}
256 if (dx < 0) {dx = -dx; stepx = -1;}
263 tex.SetPixel(x0, y0, col);
265 fraction = dy - (dx >> 1);
266 while (Mathf.Abs(x0 - x1) > 1) {
273 tex.SetPixel(x0, y0, col);
277 fraction = dx - (dy >> 1);
278 while (Mathf.Abs(y0 - y1) > 1) {
285 tex.SetPixel(x0, y0, col);
296 grid.SetPixels(buffer);
310 for (
int i = dataIndex-1; i > 0; i--)
313 DrawLine(grid, previousX, previousY, x, data[i], plotColor);
322 for (
int i = gridWidth - 1; i >=
dataIndex; i--)
325 DrawLine(grid, previousX, previousY, x, data[i], plotColor);
335 for (
int i = 0; i < (gridWidth - 1); i++) grid.SetPixel(i, zeroLine, Color.yellow);
342 if (children.Count > 0)
344 foreach (KeyValuePair<String, Plotter> p
in children)
358 int x = this.Parent.
grid.width;
371 for (
int i = dataIndex-1; i > 0; i--)
374 DrawLine(this.Parent.
grid, previousX, previousY, x, data[i], plotColor);
383 for (
int i = gridWidth - 1; i >=
dataIndex; i--)
386 DrawLine(this.Parent.
grid, previousX, previousY, x, data[i], plotColor);
394 this.Parent.
grid.Apply(
false);
404 if (!children.ContainsKey(child.
name))
405 children.Add(child.
name, child);
static Texture2D totalEnergyPlotTexture
Plotter(String name, Texture2D blankGraph, float min, float max, Color plotColor, Plotter parent)
Plotter(String name, Texture2D blankGraph, float min, float max, Color plotColor, Vector2 pos)
void Draw()
Draw the graph.
void PlotDestroy(String plotName)
void PlotAdd(String plotName, float value)
Add a value to plot graph
void PlotCreate(String plotName, float min, float max, Color plotColor, Vector2 pos)
Instantiate a new new plot graph
void AddChild(Plotter child)
Link a child Plotter to this
static PlotManager Instance
Instance of object
void DrawChild()
Draw Child Graphs
Dictionary< String, Plotter > children
void PlotCreate(String plotName, float min, float max, Color plotColor, ref Texture2D renderTextureReference)
Dictionary< String, Plotter > plots
Plotter(String name, Texture2D blankGraph, float min, float max, Color plotColor, ref Texture2D renderTextureReference)
Plotter(String name, Texture2D blankGraph, Color plotColor, Plotter parent)
void DrawLine(Texture2D tex, int x0, int y0, int x1, int y1, Color col)
void PlotCreate(String plotName, float min, float max, Color plotColor, String parentName)
Create child plotter
void Add(float y)
Add data to buffer
Plotter class for generating graphs
static PlotManager instance
void PlotCreate(String plotName, Color plotColor, String parentName)
void InitPlotterChild(String name, Texture2D blankGraph, float min, float max, Color plotColor, Plotter parent)