Description:
Handle multiple series scalably.
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r508:fcb79fc7fb1d -

@@ -3,6 +3,7
3 3 using Num = System.Numerics;
4 4 using System.Linq;
5 5 using System.Runtime.InteropServices;
6 using System.Collections.Generic;
6 7
7 8 using ImGuiNET;
8 9 using ImPlotNET;
@@ -25,6 +26,14
25 26 public static bool show_subsidies = false;
26 27 public static bool show_upkeep = false;
27 28
29
30 public static Dictionary<string, IEnumerable<double>> data_sets = new Dictionary<string, IEnumerable<double>>();
31
32 public static Dictionary<String, bool> data_sets_show = new Dictionary<string,bool> {
33 {"Total Funds", false},
34 {"Subsidies", false},
35 {"Upkeep", false}};
36
28 37 public static void Render(ImFontPtr font, Simulation sim, ImGuiWindowBridgeEngine engine)
29 38 {
30 39 bool newShow = true;
@@ -48,38 +57,38
48 57 }
49 58 GraphWindow.hadFocus = ImGui.IsWindowFocused();
50 59
51 // ImGui.Text("Lorem Ipsum");
52
53 var totals = sim.allBudgets().Select(b => (double)b.money);
54 var subsidies = sim.allBudgets().Select(b => (double)b.subsidy);
55 var upkeep = sim.allBudgets().Select(b => (double)b.upkeep);
56
57 var totals_array = totals.ToArray();
58 var subsidies_array = subsidies.ToArray();
59 var upkeep_array = upkeep.ToArray();
60 data_sets["Total Funds"] = sim.allBudgets().Select(b => (double)b.money);
61 data_sets["Subsidies"] = sim.allBudgets().Select(b => (double)b.subsidy);
62 data_sets["Upkeep"] = sim.allBudgets().Select(b => (double)b.upkeep);
60 63
61 64 var periods = 12.0d * GraphWindow.year;
65 var keys = data_sets_show.Keys.ToList();
62 66
63 // totals.Max() * 1.10d;
64 ImPlot.SetNextPlotLimits(totals.Count()-periods, totals.Count(), 0.0d, (totals.Count() > 0 )? totals.Max() * 1.05 : 115_000d , ImGuiCond.Always);
67 var totals = data_sets["Total Funds"];
68
69 var max = 0.0d;
65 70
71 foreach( var key in keys) {
72 if (data_sets_show[key] && totals.Count() > 0) {
73 var series_max = data_sets[key].Max() * 1.10f;
74 max = Math.Max(series_max, max);
75 }
76 }
77
78 ImPlot.SetNextPlotLimits(totals.Count()-periods, totals.Count(), 0.0d, max , ImGuiCond.Always);
66 79 if( ImPlot.BeginPlot("My Plot")) {
67 80 // Span<double> totals = new Span<double>(new double[]{0.0, 1.0, 2.0, 9.0});
68 if (totals_array.Length > 0 && show_totals)
69 {
70 ImPlot.PlotLine("Total Funds", ref totals_array[0], totals_array.Length);
71 }
72 if (subsidies_array.Length > 0 && show_subsidies)
73 {
74 ImPlot.PlotLine("Subsidies", ref subsidies_array[0], subsidies_array.Length);
75 }
76 if (upkeep_array.Length > 0 && show_upkeep)
77 {
78 ImPlot.PlotLine("Upkeep", ref upkeep_array[0], upkeep_array.Length);
81 foreach (var key in keys) {
82 var show = data_sets_show[key];
83 var data = data_sets[key];
84 var data_array = data_sets[key].ToArray();
85 if (data_array.Length > 0 && show)
86 {
87 ImPlot.PlotLine(key, ref data_array[0], data_array.Length);
88 }
79 89 }
80 90
81 91 ImPlot.EndPlot();
82
83 92 }
84 93
85 94 ImGui.RadioButton("1 year", ref GraphWindow.year, 1);
@@ -90,13 +99,18
90 99 ImGui.SameLine();
91 100 ImGui.RadioButton("100 years", ref GraphWindow.year, 100);
92 101
93 if (Menu.activeButton("Totals", show_totals, StyleSets.selected, StyleSets.white))
102 foreach (var key in keys)
94 103 {
95 GraphWindow.show_totals = !GraphWindow.show_totals;
104 if (Menu.activeButton(key, data_sets_show[key], StyleSets.selected, StyleSets.white))
105 {
106 data_sets_show[key] = !data_sets_show[key];
107 }
108
96 109 }
97 110
98 111
99 112
113
100 114 ImGui.End();
101 115 ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.Left;
102 116 StyleSets.defaultSet.pop();
You need to be logged in to leave comments. Login now