Description:
Get rudimentary custom graph plot working.
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r612:1735a628e097 -

@@ -39,8 +39,48
39 .Select(e => (e, false))
39 .Select(e => (e, false))
40 .ToDictionary(t => t.Item1, t=> t.Item2);
40 .ToDictionary(t => t.Item1, t=> t.Item2);
41
41
42 public static void DrawLine(ImDrawListPtr draw_list, Num.Vector2[] points) {
42
43
43 public static void Render(ImFontPtr font, Simulation sim, ImGuiWindowBridgeEngine engine)
44 var p = Num.Vector2.Zero;// ImGui.GetCursorScreenPos();
45
46 // var points = new Num.Vector2[] { new Num.Vector2(0, 0), new Num.Vector2(25, 25), new Num.Vector2(50, 500) };
47
48 for (int i = 0; i < points.Length; i++)
49 {
50 var c = ImGui.GetCursorScreenPos();
51 points[i] = Num.Vector2.Add(points[i], c);
52 }
53
54 // uint col = 0b_1111_1111_1111_0000;
55 uint col = 0xFF000000;
56
57 draw_list.AddPolyline(ref points[0], points.Length, col, ImDrawFlags.RoundCornersDefault, 1.0f);
58
59 }
60
61 public static int Scale(Num.Vector2 domain, Num.Vector2 range, int num) {
62 //https://stats.stackexchange.com/a/281164
63
64 var domain_span = Math.Max(1, (domain.Y - domain.X));
65 var range_span = range.Y - range.X;
66
67 var start = range.X - domain.X;
68
69
70 // return (int)((domain_span / range_span) * (num + start));
71
72 checked
73 {
74
75 return (int) (((num - domain.X) / domain_span) * range_span + range.X);
76 }
77
78
79
80 }
81
82
83 public static async void Render(ImFontPtr font, Simulation sim, ImGuiWindowBridgeEngine engine)
44 {
84 {
45 bool newShow = true;
85 bool newShow = true;
46
86
@@ -99,8 +139,6
99
139
100 ImPlot.PushStyleVar(ImPlotStyleVar.LineWeight, 2.0f);
140 ImPlot.PushStyleVar(ImPlotStyleVar.LineWeight, 2.0f);
101 ImPlot.PushStyleVar(ImPlotStyleVar.MinorAlpha, 0.0f);
141 ImPlot.PushStyleVar(ImPlotStyleVar.MinorAlpha, 0.0f);
102 // ImPlot.PushStyleVar(ImPlotStyleVar.MajorGridSize, new Num.Vector2(0.0f, 0.0f));
103 // ImPlot.PushStyleVar(ImPlotStyleVar.MinorGridSize, new Num.Vector2(0.0f, 0.0f));
104
142
105 ImPlot.SetNextPlotLimits(totals.Count()-periods, totals.Count(), min, max, ImGuiCond.Always);
143 ImPlot.SetNextPlotLimits(totals.Count()-periods, totals.Count(), min, max, ImGuiCond.Always);
106 if( ImPlot.BeginPlot("My Plot", null, null, new Num.Vector2(-1,0), ImPlotFlags.NoLegend | ImPlotFlags.NoMousePos )) {
144 if( ImPlot.BeginPlot("My Plot", null, null, new Num.Vector2(-1,0), ImPlotFlags.NoLegend | ImPlotFlags.NoMousePos )) {
@@ -114,6 +152,8
114 ImPlot.PlotLine(key, ref data_array[0], data_array.Length);
152 ImPlot.PlotLine(key, ref data_array[0], data_array.Length);
115 ImPlot.AnnotateClamped(data_array.Length-1, data_array[data_array.Length-1],
153 ImPlot.AnnotateClamped(data_array.Length-1, data_array[data_array.Length-1],
116 new Num.Vector2(5, -10), StyleSets.grey, key);
154 new Num.Vector2(5, -10), StyleSets.grey, key);
155
156
117 }
157 }
118 }
158 }
119
159
@@ -122,6 +162,7
122
162
123 ImPlot.PopStyleVar(2);
163 ImPlot.PopStyleVar(2);
124
164
165
125 ImGui.RadioButton("1 year", ref GraphWindow.year, 1);
166 ImGui.RadioButton("1 year", ref GraphWindow.year, 1);
126 ImGui.SameLine();
167 ImGui.SameLine();
127 ImGui.RadioButton("5 years", ref GraphWindow.year, 5);
168 ImGui.RadioButton("5 years", ref GraphWindow.year, 5);
@@ -161,8 +202,28
161 }
202 }
162
203
163
204
205 var draw_list = ImGui.GetWindowDrawList();
164
206
165
207
208 var range = new Num.Vector2(200, 0);
209
210 foreach (var key in keys) {
211 var show = data_sets_show[key];
212 var data = data_sets[key];
213 var domain = new Num.Vector2((int)data.Min(), (int)data.Max());
214 // var data_array = datasets[key].Select((p) => Scale(domain, range, (int)p) ).Select((p,i) => new Num.Vector2(i*10, (int)p)).ToArray();
215 if (data.Count() > 0 && show)
216 {
217 // Logging.Spy(range);
218 // Logging.Spy(domain);
219 IEnumerable<int> data_array = data_sets[key].Select((p) => Scale(domain, range, (int)p));
220 var data_array2 = data_array.Select((p, i) => new Num.Vector2(i * 10, p)).ToArray();
221 DrawLine(draw_list, data_array2);
222 }
223 }
224
225 ImGui.Dummy(new Num.Vector2(200, 200));
226
166 ImGui.End();
227 ImGui.End();
167 ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.Left;
228 ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.Left;
168 StyleSets.defaultSet.pop();
229 StyleSets.defaultSet.pop();
You need to be logged in to leave comments. Login now