Commit Description:
Scale graph.
Commit Description:
Scale graph.
File last commit:
Show/Diff file:
Action:
isometric-park-fna/UI/Graph.cs
89 lines | 3.1 KiB | text/x-csharp | CSharpLexer
using System;
using Num = System.Numerics;
using System.Linq;
using System.Runtime.InteropServices;
using ImGuiNET;
using ImPlotNET;
using JM.LinqFaster;
using isometricparkfna.Messages;
using isometricparkfna.Components;
using isometricparkfna.Engines;
namespace isometricparkfna.UI
{
public static class GraphWindow
{
public static bool hadFocus = false;
public static int year = 1;
public static void Render(ImFontPtr font, Simulation sim, ImGuiWindowBridgeEngine engine)
{
bool newShow = true;
ImGui.PushFont(font);
ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.None;
StyleSets.defaultSet.push();
if(GraphWindow.hadFocus)
{
ImGui.PushStyleColor(ImGuiCol.Text, StyleSets.white);
}
ImGui.SetNextWindowSize(new Num.Vector2(400, 400));
ImGui.Begin("Graph", ref newShow, ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoSavedSettings);
if (GraphWindow.hadFocus)
{
ImGui.PopStyleColor();
}
GraphWindow.hadFocus = ImGui.IsWindowFocused();
// ImGui.Text("Lorem Ipsum");
var totals = sim.allBudgets().Select(b => (double)b.money);
var totals_array = totals.ToArray();
var periods = 12.0d * GraphWindow.year;
// totals.Max() * 1.10d;
ImPlot.SetNextPlotLimits(totals.Count()-periods, totals.Count(), 0.0d, (totals.Count() > 0 )? totals.Max() * 1.05 : 115_000d , ImGuiCond.Always);
if( ImPlot.BeginPlot("My Plot")) {
// Span<double> totals = new Span<double>(new double[]{0.0, 1.0, 2.0, 9.0});
if (totals_array.Length > 0)
{
// ImGui.PlotLines("MainGraph", ref totals[0], totals.Length, 0, null, float.MaxValue, float.MaxValue, new Num.Vector2(350, 200));
// ImPlot.PlotLine("My Line", ref MemoryMarshal.GetReference(totals), ref MemoryMarshal.GetReference(totals), totals.Length);
// Logging.Info(String.Format("Max: {0}", max.ToString()));
ImPlot.PlotLine("Total Funds", ref totals_array[0], totals_array.Length);
}
ImPlot.EndPlot();
}
ImGui.RadioButton("1 year", ref GraphWindow.year, 1);
ImGui.SameLine();
ImGui.RadioButton("5 years", ref GraphWindow.year, 5);
ImGui.SameLine();
ImGui.RadioButton("25 years", ref GraphWindow.year, 25);
ImGui.SameLine();
ImGui.RadioButton("100 years", ref GraphWindow.year, 100);
ImGui.End();
ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.Left;
StyleSets.defaultSet.pop();
ImGui.PopFont();
}
}
}