Decompiled source of LwfEconomyGraph v1.0.1

BepInEx/plugins/LwfEconomyGraph.dll

Decompiled 4 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using BaseSystem;
using BepInEx;
using BepInEx.Configuration;
using GameState;
using HarmonyLib;
using Items;
using Items.Craft;
using Items.Delivery;
using Items.Tag;
using Map.MapObjects.Mono;
using Map.Ownership;
using R3;
using Stats;
using TMPro;
using UI;
using UI.Cursor;
using UI.SelectableWindow.Managers;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.UI;
using Utility.Localization;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace LwfEconomyGraph;

internal sealed class SourceSeries
{
	internal readonly string Key;

	internal readonly int Reason;

	internal readonly bool HasSource;

	internal long Total;

	internal long Held;

	internal readonly List<long> ByPeriod = new List<long>();

	internal readonly List<long> RepaidByPeriod = new List<long>();

	internal SourceSeries(string key, int reason, bool hasSource)
	{
		Key = key;
		Reason = reason;
		HasSource = hasSource;
	}

	internal long At(int period)
	{
		if (period < 0 || period >= ByPeriod.Count)
		{
			return 0L;
		}
		return ByPeriod[period];
	}

	internal long RepaidAt(int period)
	{
		if (period < 0 || period >= RepaidByPeriod.Count)
		{
			return 0L;
		}
		return RepaidByPeriod[period];
	}

	internal void AddRepaid(int period, long value)
	{
		while (RepaidByPeriod.Count <= period)
		{
			RepaidByPeriod.Add(0L);
		}
		RepaidByPeriod[period] += value;
	}

	internal void Add(int period, long value)
	{
		while (ByPeriod.Count <= period)
		{
			ByPeriod.Add(0L);
		}
		ByPeriod[period] += value;
		Total += value;
	}
}
internal sealed class TagSeries
{
	internal readonly string TagID;

	internal readonly int Index;

	internal string DisplayName;

	internal long Balance;

	internal long InitialBalance;

	internal long PeakBalance;

	internal double PeakAt;

	internal long IncomeTotal;

	internal long ExpenseTotal;

	internal long RecordCount;

	internal readonly long[] IncomeByReason;

	internal readonly long[] ExpenseByReason;

	internal readonly Dictionary<string, long> IncomeBySource = new Dictionary<string, long>(StringComparer.Ordinal);

	internal readonly Dictionary<string, long> ExpenseBySource = new Dictionary<string, long>(StringComparer.Ordinal);

	internal List<long> Balances = new List<long>();

	internal readonly List<long> Flows = new List<long>();

	internal readonly List<long> PeriodFlows = new List<long>();

	internal long HeldUnattributed;

	internal readonly List<SourceSeries> IncomeSources = new List<SourceSeries>();

	internal readonly List<SourceSeries> ExpenseSources = new List<SourceSeries>();

	private readonly Dictionary<string, SourceSeries> _incomeIndex = new Dictionary<string, SourceSeries>(StringComparer.Ordinal);

	private readonly Dictionary<string, SourceSeries> _expenseIndex = new Dictionary<string, SourceSeries>(StringComparer.Ordinal);

	private readonly List<SourceSeries> _lotSource = new List<SourceSeries>();

	private readonly List<long> _lotAmount = new List<long>();

	internal TagSeries(string tagID, int index, int reasonCount)
	{
		TagID = tagID;
		Index = index;
		DisplayName = tagID;
		IncomeByReason = new long[reasonCount];
		ExpenseByReason = new long[reasonCount];
	}

	internal SourceSeries GetOrCreateSource(bool income, string key, int reason, bool hasSource)
	{
		Dictionary<string, SourceSeries> dictionary = (income ? _incomeIndex : _expenseIndex);
		if (dictionary.TryGetValue(key, out var value))
		{
			return value;
		}
		value = new SourceSeries(key, reason, hasSource);
		dictionary.Add(key, value);
		(income ? IncomeSources : ExpenseSources).Add(value);
		return value;
	}

	internal long HeldTotal()
	{
		long num = HeldUnattributed;
		for (int i = 0; i < IncomeSources.Count; i++)
		{
			num += IncomeSources[i].Held;
		}
		return num;
	}

	internal void AddHolding(SourceSeries src, long amount)
	{
		if (src != null && amount > 0)
		{
			src.Held += amount;
			int num = _lotSource.Count - 1;
			if (num >= 0 && object.ReferenceEquals(_lotSource[num], src))
			{
				_lotAmount[num] += amount;
				return;
			}
			_lotSource.Add(src);
			_lotAmount.Add(amount);
		}
	}

	internal void TakeFromHolding(long amount, List<SourceSeries> srcOut, List<long> amtOut)
	{
		if (amount <= 0)
		{
			return;
		}
		long num = amount;
		int num2 = _lotSource.Count - 1;
		while (num2 >= 0 && num > 0)
		{
			long num3 = ((_lotAmount[num2] < num) ? _lotAmount[num2] : num);
			if (num3 > 0)
			{
				_lotAmount[num2] -= num3;
				_lotSource[num2].Held -= num3;
				num -= num3;
				if (srcOut != null)
				{
					srcOut.Add(_lotSource[num2]);
					amtOut.Add(num3);
				}
			}
			num2--;
		}
		while (_lotAmount.Count > 0 && _lotAmount[_lotAmount.Count - 1] <= 0)
		{
			_lotAmount.RemoveAt(_lotAmount.Count - 1);
			_lotSource.RemoveAt(_lotSource.Count - 1);
		}
		if (num > 0 && HeldUnattributed > 0)
		{
			long num4 = ((HeldUnattributed < num) ? HeldUnattributed : num);
			HeldUnattributed -= num4;
			num -= num4;
			if (srcOut != null)
			{
				srcOut.Add(null);
				amtOut.Add(num4);
			}
		}
	}

	internal void SpendFromHolding(long amount)
	{
		TakeFromHolding(amount, null, null);
	}

	internal long BalanceAt(int bucket)
	{
		int count = Balances.Count;
		if (count == 0)
		{
			return InitialBalance;
		}
		if (bucket < 0)
		{
			return Balances[0];
		}
		if (bucket >= count)
		{
			return Balances[count - 1];
		}
		return Balances[bucket];
	}

	internal long FlowAt(int bucket, int slot)
	{
		int num = bucket * (IncomeByReason.Length * 2) + slot;
		if (bucket < 0 || num < 0 || num >= Flows.Count)
		{
			return 0L;
		}
		return Flows[num];
	}

	internal long PeriodFlowAt(int period, int slot)
	{
		int num = period * (IncomeByReason.Length * 2) + slot;
		if (period < 0 || num < 0 || num >= PeriodFlows.Count)
		{
			return 0L;
		}
		return PeriodFlows[num];
	}
}
internal interface IChartPainter
{
	float FontSize { get; }

	float LineHeight { get; }

	void SetScale(float scale);

	float Measure(string text);

	float MeasureTitle(string text);

	void Fill(Rect r, Color color);

	void Text(float x, float y, string text, Color color);

	void Title(float x, float y, string text, Color color);

	bool Icon(Rect r, string sourceKey, string tagID, Color tint, Color outline);

	string ReasonLabel(int reason);
}
internal sealed class ChartData
{
	internal List<TagSeries> Ordered = new List<TagSeries>();

	internal TagSeries Selected;

	internal float BucketSeconds = 1f;

	internal int BucketCount;

	internal int MaxColumns = 480;

	internal int PeriodIndex;

	internal List<int> PeriodRepaid = new List<int>();

	internal int RepaidTotal;

	internal int TargetProgress;

	internal string RequiredTagID;

	internal int RequiredCount;

	internal long RequiredCurrent;

	internal List<double> PeriodEnds = new List<double>();

	internal HashSet<string> HiddenTags = new HashSet<string>(StringComparer.Ordinal);

	internal int Mode;

	internal bool LastMinute;

	internal bool ExpenseSide;

	internal Vector2 Mouse;

	internal bool MouseValid;

	internal readonly List<Rect> IconRects = new List<Rect>();

	internal readonly List<string> IconTagIDs = new List<string>();

	internal readonly List<Rect> ModeRects = new List<Rect>();

	internal readonly List<int> ModeIDs = new List<int>();

	internal readonly List<Rect> ToggleRects = new List<Rect>();

	internal readonly List<int> ToggleIDs = new List<int>();

	internal readonly List<SourceSeries> RateSources = new List<SourceSeries>();

	internal readonly List<float[]> RateValues = new List<float[]>();

	internal readonly List<long> RateTotals = new List<long>();

	internal float RateSlotSeconds = 1f;

	internal long RateTotal;
}
internal sealed class ChartRenderer
{
	internal const int ReasonCount = 16;

	internal const int SlotsPerBucket = 32;

	internal const float DesignWidth = 494f;

	internal const int ModeNetFlow = 0;

	internal const int ModeBalanceAll = 1;

	internal const int ModeComposition = 2;

	internal const int ModeCount = 3;

	internal const int ToggleRange = 0;

	internal const int ToggleSide = 1;

	internal const string CraftIconKey = "#craft";

	private const float MinShare = 0.03f;

	private const int HoverRows = 10;

	internal static readonly string[] KnownTagIDs = new string[8] { "Cash", "Construction", "Grocery", "Luxury", "Fertilizer", "Chemical", "Magic", "Fuel" };

	internal static readonly string[] KnownTagNamesJa = new string[8] { "現金", "建材", "食品", "高級品", "肥料", "薬品", "魔力", "燃料" };

	private static readonly Color[] TagColors = (Color[])(object)new Color[9]
	{
		new Color(1f, 0.82f, 0.25f),
		new Color(0.72f, 0.72f, 0.76f),
		new Color(0.55f, 0.85f, 0.45f),
		new Color(0.95f, 0.55f, 0.85f),
		new Color(0.78f, 0.6f, 0.32f),
		new Color(0.45f, 0.85f, 0.8f),
		new Color(0.65f, 0.55f, 0.98f),
		new Color(0.98f, 0.55f, 0.3f),
		new Color(0.6f, 0.6f, 0.62f)
	};

	private static readonly Color[] SourcePalette = (Color[])(object)new Color[8]
	{
		new Color(1f, 0.62f, 0.2f),
		new Color(0.42f, 0.8f, 0.45f),
		new Color(0.4f, 0.68f, 0.98f),
		new Color(0.95f, 0.45f, 0.55f),
		new Color(0.75f, 0.55f, 0.95f),
		new Color(0.35f, 0.85f, 0.82f),
		new Color(0.95f, 0.85f, 0.35f),
		new Color(0.9f, 0.55f, 0.85f)
	};

	private static readonly Color OthersColor = new Color(0.55f, 0.55f, 0.58f);

	private static readonly Color IconOutline = new Color(1f, 1f, 1f, 0.95f);

	private static readonly Color Faint = new Color(1f, 1f, 1f, 0.14f);

	private static readonly Color Fainter = new Color(1f, 1f, 1f, 0.1f);

	private static readonly Color Ink = Color.white;

	private static readonly Color Accent = new Color(1f, 0.68f, 0.25f, 1f);

	private static readonly Color DeficitColor = new Color(0.95f, 0.32f, 0.34f, 1f);

	private static readonly Color ZeroColor = new Color(0.66f, 0.63f, 0.6f, 0.9f);

	private static readonly Color NetLineUp = new Color(0.55f, 0.95f, 0.6f, 1f);

	private static readonly Color NetLineDown = new Color(0.98f, 0.55f, 0.55f, 1f);

	private static readonly Color NetFillUp = new Color(0.35f, 0.85f, 0.45f, 0.26f);

	private static readonly Color NetFillDown = new Color(0.95f, 0.35f, 0.38f, 0.26f);

	private readonly List<SourceSeries> _rank = new List<SourceSeries>();

	private readonly List<SourceSeries> _hover = new List<SourceSeries>();

	private readonly List<long> _rankTotals = new List<long>();

	private readonly List<float[]> _rateLines = new List<float[]>();

	private readonly List<int> _rateOrder = new List<int>();

	private bool _hoverByRepaid;

	private bool _hoverHeld;

	private int _hoverPeriod;

	private readonly List<Color> _rankColors = new List<Color>();

	private readonly List<Color> _lineColors = new List<Color>();

	private readonly List<TagSeries> _capOrder = new List<TagSeries>();

	private readonly List<float> _capY = new List<float>();

	private static readonly float[] RisingLevels = new float[4] { 0.16f, 0.4f, 0.28f, 0.72f };

	private static readonly float[] NetLevels = new float[4] { 0.2f, 0.72f, 0.34f, 0.78f };

	private static readonly float[] FallingLevels = new float[4] { 0.82f, 0.6f, 0.66f, 0.34f };

	private long[] _net;

	private long[] _bucketNet;

	private string _netTag;

	private int _netCount;

	private int _netWindow;

	private long _netLast;

	private static bool UsesNorm(ChartData d)
	{
		if (!d.ExpenseSide && d.RequiredCount > 0 && d.Selected != null)
		{
			return string.Equals(d.RequiredTagID, d.Selected.TagID, StringComparison.Ordinal);
		}
		return false;
	}

	private static float NormRatio(ChartData d)
	{
		if (d.RequiredCount <= 0)
		{
			return 1f;
		}
		return (float)((double)d.RequiredCurrent / (double)d.RequiredCount);
	}

	internal void Draw(Rect area, ChartData d, IChartPainter p)
	{
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_03de: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_027d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0267: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0351: Unknown result type (might be due to invalid IL or missing references)
		//IL_034a: Unknown result type (might be due to invalid IL or missing references)
		p.SetScale(Mathf.Clamp(((Rect)(ref area)).width / 494f, 0.8f, 2.2f));
		d.IconRects.Clear();
		d.IconTagIDs.Clear();
		d.ModeRects.Clear();
		d.ModeIDs.Clear();
		d.ToggleRects.Clear();
		d.ToggleIDs.Clear();
		float lineHeight = p.LineHeight;
		float num = lineHeight + 4f;
		float x = ((Rect)(ref area)).x;
		float num2 = ((Rect)(ref area)).y;
		if (d.Mode == 0 && d.Selected != null)
		{
			BuildNet(d, d.Selected);
		}
		float num3 = Mathf.Max(16f, lineHeight) + 8f;
		Rect r = default(Rect);
		((Rect)(ref r))..ctor(((Rect)(ref area)).x, ((Rect)(ref area)).yMax - num3, ((Rect)(ref area)).width, num3);
		if (((Rect)(ref area)).height > num3 + 40f)
		{
			DrawToolbar(r, d, p);
			((Rect)(ref area))..ctor(((Rect)(ref area)).x, ((Rect)(ref area)).y, ((Rect)(ref area)).width, ((Rect)(ref r)).y - ((Rect)(ref area)).y - 2f);
		}
		if (d.Ordered.Count == 0)
		{
			DrawZeroLine(area, p);
			return;
		}
		if (d.Mode != 1 && d.Selected != null)
		{
			p.Icon(new Rect(x, num2, num, num), null, d.Selected.TagID, Ink, IconOutline);
			x += num + 6f;
			if (d.Mode == 0)
			{
				long netLast = _netLast;
				string text = ((netLast >= 0) ? "+" : "-") + N(Math.Abs(netLast)) + "/min";
				p.Title(x, num2 + 2f, text, (netLast >= 0) ? NetLineUp : NetLineDown);
			}
			else
			{
				bool lastMinute = d.LastMinute;
				long v = (lastMinute ? d.RateTotal : (d.ExpenseSide ? d.Selected.ExpenseTotal : d.Selected.IncomeTotal));
				string text2 = (d.ExpenseSide ? "-" : "+") + N(v) + (lastMinute ? "/min" : "");
				p.Title(x, num2 + 2f, text2, d.ExpenseSide ? new Color(0.98f, 0.55f, 0.55f) : new Color(0.55f, 0.95f, 0.6f));
				float num4 = x + p.MeasureTitle(text2) + 8f;
				if (d.TargetProgress > 0)
				{
					string text3 = d.RepaidTotal.ToString(CultureInfo.InvariantCulture) + "/" + d.TargetProgress.ToString(CultureInfo.InvariantCulture);
					p.Text(num4, num2 + 6f, text3, new Color(0.75f, 0.72f, 0.68f));
					num4 += p.Measure(text3) + 8f;
				}
				if (UsesNorm(d))
				{
					int num5 = Mathf.RoundToInt(NormRatio(d) * 100f);
					string text4 = num5.ToString(CultureInfo.InvariantCulture) + "%";
					p.Text(num4, num2 + 6f, text4, (num5 < 0) ? DeficitColor : Accent);
				}
			}
		}
		if (d.Mode != 1)
		{
			num2 += num + 4f;
		}
		Rect r2 = default(Rect);
		((Rect)(ref r2))..ctor(((Rect)(ref area)).x, num2, ((Rect)(ref area)).width, ((Rect)(ref area)).yMax - num2);
		if (((Rect)(ref r2)).height < 40f)
		{
			return;
		}
		if (d.Mode == 2)
		{
			if (d.Selected == null)
			{
				DrawZeroLine(r2, p);
			}
			else if (d.LastMinute)
			{
				DrawRates(r2, d, p);
			}
			else
			{
				DrawComposition(r2, d, p);
			}
		}
		else if (d.Mode == 1)
		{
			DrawBalanceChart(r2, d, null, p);
		}
		else if (d.Selected == null)
		{
			DrawZeroLine(r2, p);
		}
		else
		{
			DrawNetChart(r2, d, p);
		}
	}

	private void DrawToolbar(Rect r, ChartData d, IChartPainter p)
	{
		float num = Mathf.Max(14f, p.LineHeight);
		float num2 = num * 1.9f;
		float num3 = 4f;
		float num4 = 10f;
		int count = d.Ordered.Count;
		float num5 = num2 * 4f + num * (float)count + num3 * (float)(count + 1) + num4 * 7.5f;
		if (num5 > ((Rect)(ref r)).width && num5 > 0f)
		{
			float num6 = ((Rect)(ref r)).width / num5;
			num = Mathf.Max(11f, num * num6);
			num2 = Mathf.Max(13f, num2 * num6);
			num3 = Mathf.Max(2f, num3 * num6);
			num4 = Mathf.Max(4f, num4 * num6);
		}
		float y = ((Rect)(ref r)).y + (((Rect)(ref r)).height - num) * 0.5f - 1f;
		float num7 = num4;
		float x = ((Rect)(ref r)).x + num7;
		x = DrawModeButton(x, y, num2, num, 1, d, p) + num4;
		x = DrawTagRow(x, y, num, num3, d, p) + num4;
		x = DrawModeButton(x, y, num2, num, 0, d, p) + num4 * 2.5f;
		x = DrawToggleButton(x, y, num2, num, 1, d, p) + num3;
		DrawToggleButton(x, y, num2, num, 0, d, p);
		DrawModeButton(((Rect)(ref r)).xMax - num7 - num2, y, num2, num, 2, d, p);
	}

	private float DrawTagRow(float x, float y, float icon, float gap, ChartData d, IChartPainter p)
	{
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		bool flag = d.Mode == 1;
		Rect val = default(Rect);
		for (int i = 0; i < d.Ordered.Count; i++)
		{
			string tagID = d.Ordered[i].TagID;
			bool flag2 = (flag ? (!d.HiddenTags.Contains(tagID)) : (d.Selected != null && d.Selected.TagID == tagID));
			((Rect)(ref val))..ctor(x, y, icon, icon);
			p.Icon(val, null, tagID, (Color)(flag2 ? Ink : new Color(1f, 1f, 1f, 0.3f)), (Color)(flag2 ? IconOutline : new Color(0f, 0f, 0f, 0f)));
			p.Fill(new Rect(x, y + icon + 1f, icon, 2f), flag2 ? TagColor(tagID) : Fainter);
			d.IconRects.Add(val);
			d.IconTagIDs.Add(tagID);
			x += icon + gap;
		}
		return x - gap;
	}

	private float DrawModeButton(float x, float y, float bw, float icon, int mode, ChartData d, IChartPainter p)
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		Rect val = default(Rect);
		((Rect)(ref val))..ctor(x, y - 2f, bw, icon + 4f);
		bool flag = mode == d.Mode;
		p.Fill(val, flag ? new Color(1f, 1f, 1f, 0.15f) : new Color(1f, 1f, 1f, 0.05f));
		DrawModeGlyph(val, mode, (Color)(flag ? Accent : new Color(1f, 1f, 1f, 0.45f)), p);
		d.ModeRects.Add(val);
		d.ModeIDs.Add(mode);
		return ((Rect)(ref val)).xMax;
	}

	private float DrawToggleButton(float x, float y, float bw, float icon, int id, ChartData d, IChartPainter p)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		Rect box = default(Rect);
		((Rect)(ref box))..ctor(x, y - 2f, bw, icon + 4f);
		AddToggle(box, id, d, p);
		return ((Rect)(ref box)).xMax;
	}

	private static void DrawModeGlyph(Rect box, int mode, Color c, IChartPainter p)
	{
		//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0222: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.Max(2f, ((Rect)(ref box)).height * 0.24f);
		Rect g = default(Rect);
		((Rect)(ref g))..ctor(((Rect)(ref box)).x + num, ((Rect)(ref box)).y + num, ((Rect)(ref box)).width - num * 2f, ((Rect)(ref box)).height - num * 2f);
		if (((Rect)(ref g)).width < 4f || ((Rect)(ref g)).height < 4f)
		{
			return;
		}
		if (mode == 2)
		{
			float num2 = ((Rect)(ref g)).width / 3f;
			for (int i = 0; i < 3; i++)
			{
				float num3 = Mathf.Max(1f, num2 - 1.5f);
				float num4 = ((Rect)(ref g)).height * (0.34f + (float)i * 0.13f);
				p.Fill(new Rect(((Rect)(ref g)).x + (float)i * num2, ((Rect)(ref g)).yMax - num4, num3, num4), c);
				p.Fill(new Rect(((Rect)(ref g)).x + (float)i * num2, ((Rect)(ref g)).y, num3, ((Rect)(ref g)).height - num4 - 1f), new Color(c.r, c.g, c.b, c.a * 0.38f));
			}
			return;
		}
		float thick = Mathf.Max(1f, ((Rect)(ref g)).height * 0.16f);
		if (mode == 0)
		{
			float num5 = Mathf.Min(((Rect)(ref box)).width, ((Rect)(ref box)).height) - 2f;
			Rect r = default(Rect);
			((Rect)(ref r))..ctor(((Rect)(ref box)).x + (((Rect)(ref box)).width - num5) * 0.5f, ((Rect)(ref box)).y + (((Rect)(ref box)).height - num5) * 0.5f, num5, num5);
			if (!p.Icon(r, "#craft", null, c, new Color(0f, 0f, 0f, 0f)))
			{
				DrawFactoryGlyph(g, c, p);
			}
		}
		else
		{
			DrawGlyphLine(g, RisingLevels, thick, c, p);
			if (mode == 1)
			{
				DrawGlyphLine(g, FallingLevels, thick, new Color(c.r, c.g, c.b, c.a * 0.5f), p);
			}
		}
	}

	private static void AddToggle(Rect box, int id, ChartData d, IChartPainter p)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		p.Fill(box, new Color(1f, 1f, 1f, 0.08f));
		if (id == 1)
		{
			DrawSideGlyph(box, d.ExpenseSide, p);
		}
		else
		{
			DrawRangeGlyph(box, d.LastMinute, p);
		}
		d.ToggleRects.Add(box);
		d.ToggleIDs.Add(id);
	}

	private static void DrawSideGlyph(Rect box, bool expense, IChartPainter p)
	{
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.Max(2f, ((Rect)(ref box)).height * 0.24f);
		Rect val = default(Rect);
		((Rect)(ref val))..ctor(((Rect)(ref box)).x + num, ((Rect)(ref box)).y + num, ((Rect)(ref box)).width - num * 2f, ((Rect)(ref box)).height - num * 2f);
		if (!(((Rect)(ref val)).width < 4f) && !(((Rect)(ref val)).height < 4f))
		{
			Color color = (expense ? new Color(0.98f, 0.55f, 0.55f) : new Color(0.55f, 0.95f, 0.6f));
			int num2 = Mathf.Max(3, Mathf.RoundToInt(((Rect)(ref val)).height / 2f));
			float num3 = ((Rect)(ref val)).height / (float)num2;
			for (int i = 0; i < num2; i++)
			{
				float num4 = (float)i / (float)(num2 - 1);
				float num5 = (expense ? (1f - num4) : num4);
				float num6 = Mathf.Max(1f, ((Rect)(ref val)).width * (0.12f + 0.88f * num5));
				p.Fill(new Rect(((Rect)(ref val)).x + (((Rect)(ref val)).width - num6) * 0.5f, ((Rect)(ref val)).y + (float)i * num3, num6, Mathf.Max(1f, num3)), color);
			}
		}
	}

	private static void DrawRangeGlyph(Rect box, bool lastMinute, IChartPainter p)
	{
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.Max(2f, ((Rect)(ref box)).height * 0.28f);
		Rect val = default(Rect);
		((Rect)(ref val))..ctor(((Rect)(ref box)).x + num, ((Rect)(ref box)).y + num, ((Rect)(ref box)).width - num * 2f, ((Rect)(ref box)).height - num * 2f);
		if (!(((Rect)(ref val)).width < 4f) && !(((Rect)(ref val)).height < 4f))
		{
			float num2 = Mathf.Max(2f, ((Rect)(ref val)).height * 0.36f);
			float num3 = ((Rect)(ref val)).y + (((Rect)(ref val)).height - num2) * 0.5f;
			p.Fill(new Rect(((Rect)(ref val)).x, num3, ((Rect)(ref val)).width, num2), new Color(1f, 1f, 1f, 0.22f));
			float num4 = (lastMinute ? (((Rect)(ref val)).width * 0.3f) : ((Rect)(ref val)).width);
			p.Fill(new Rect(((Rect)(ref val)).xMax - num4, num3, num4, num2), Accent);
		}
	}

	private static void DrawFactoryGlyph(Rect g, Color c, IChartPainter p)
	{
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		float width = ((Rect)(ref g)).width;
		float height = ((Rect)(ref g)).height;
		float num = Mathf.Max(1f, height * 0.14f);
		Color color = default(Color);
		((Color)(ref color))..ctor(c.r, c.g, c.b, c.a * 0.45f);
		float num2 = Mathf.Max(2f, width * 0.16f);
		float num3 = ((Rect)(ref g)).x + width * 0.12f;
		p.Fill(new Rect(num3, ((Rect)(ref g)).y + height * 0.34f, num2, height * 0.66f), c);
		float num4 = Mathf.Max(2f, width * 0.11f);
		p.Fill(new Rect(num3 + num2 * 0.15f, ((Rect)(ref g)).y + height * 0.14f, num4, num4 * 0.8f), color);
		p.Fill(new Rect(num3 + num2 * 0.9f, ((Rect)(ref g)).y, num4 * 0.9f, num4 * 0.7f), color);
		float num5 = ((Rect)(ref g)).x + width * 0.4f;
		float num6 = ((Rect)(ref g)).xMax - num5;
		p.Fill(new Rect(num5, ((Rect)(ref g)).y + height * 0.5f, num6 * 0.5f, height * 0.5f), c);
		p.Fill(new Rect(num5 + num6 * 0.5f, ((Rect)(ref g)).y + height * 0.66f, num6 * 0.5f, height * 0.34f), c);
		p.Fill(new Rect(((Rect)(ref g)).x, ((Rect)(ref g)).yMax - num, width, num), c);
	}

	private static void DrawGlyphLine(Rect g, float[] levels, float thick, Color c, IChartPainter p)
	{
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		float num = ((Rect)(ref g)).width / (float)levels.Length;
		float num2 = 0f;
		for (int i = 0; i < levels.Length; i++)
		{
			float num3 = ((Rect)(ref g)).yMax - ((Rect)(ref g)).height * levels[i] - thick;
			p.Fill(new Rect(((Rect)(ref g)).x + (float)i * num, num3, Mathf.Max(1f, num), thick), c);
			if (i > 0)
			{
				float num4 = Mathf.Min(num2, num3);
				p.Fill(new Rect(((Rect)(ref g)).x + (float)i * num, num4, thick, Mathf.Abs(num2 - num3) + thick), c);
			}
			num2 = num3;
		}
	}

	private void DrawNetChart(Rect r, ChartData d, IChartPainter p)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_029a: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_030e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0350: Unknown result type (might be due to invalid IL or missing references)
		//IL_038f: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0346: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_0203: Unknown result type (might be due to invalid IL or missing references)
		//IL_0255: Unknown result type (might be due to invalid IL or missing references)
		//IL_0215: Unknown result type (might be due to invalid IL or missing references)
		//IL_020e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0267: Unknown result type (might be due to invalid IL or missing references)
		//IL_0260: Unknown result type (might be due to invalid IL or missing references)
		TagSeries selected = d.Selected;
		int num = TotalBuckets(d);
		if (selected == null || num <= 0)
		{
			DrawZeroLine(r, p);
			return;
		}
		BuildNet(d, selected);
		int num2 = 0;
		if (d.LastMinute)
		{
			int num3 = Mathf.Max(2, Mathf.CeilToInt(60f / d.BucketSeconds));
			num2 = Mathf.Max(0, num - num3);
		}
		if (num - num2 < 2)
		{
			num2 = Mathf.Max(0, num - 2);
		}
		long num4 = 0L;
		long num5 = 0L;
		for (int i = num2; i < num && i < _netCount; i++)
		{
			if (_net[i] > num4)
			{
				num4 = _net[i];
			}
			if (_net[i] < num5)
			{
				num5 = _net[i];
			}
		}
		if (num4 == num5)
		{
			num4 = num5 + 1;
		}
		float num6 = p.FontSize + 4f;
		float num7 = Mathf.Max(p.Measure(N(num4)), p.Measure("-" + N(-num5))) + 10f;
		Rect plot = default(Rect);
		((Rect)(ref plot))..ctor(((Rect)(ref r)).x + num7, ((Rect)(ref r)).y + 2f, ((Rect)(ref r)).width - num7 - 6f, ((Rect)(ref r)).height - num6 - 6f);
		if (((Rect)(ref plot)).width < 20f || ((Rect)(ref plot)).height < 20f)
		{
			return;
		}
		float num8 = ValueToY(plot, num5, num4, 0L);
		int num9 = num - num2;
		int num10 = Mathf.Max(2, Mathf.CeilToInt(((Rect)(ref plot)).width));
		float num11 = 0f;
		for (int j = 0; j < num10; j++)
		{
			int num12 = num2 + (int)((long)j * (long)(num9 - 1) / (num10 - 1));
			long num13 = ((num12 < _netCount) ? _net[num12] : 0);
			float num14 = ValueToY(plot, num5, num4, num13);
			float num15 = Mathf.Min(num14, num8);
			float num16 = Mathf.Abs(num14 - num8);
			if (num16 >= 1f)
			{
				p.Fill(new Rect(((Rect)(ref plot)).x + (float)j, num15, 1f, num16), (num13 >= 0) ? NetFillUp : NetFillDown);
			}
			if (j == 0)
			{
				num11 = num14;
			}
			float num17 = Mathf.Min(num11, num14);
			p.Fill(new Rect(((Rect)(ref plot)).x + (float)j, num17, 1.6f, Mathf.Abs(num11 - num14) + 1.6f), (num13 >= 0) ? NetLineUp : NetLineDown);
			num11 = num14;
		}
		p.Fill(new Rect(((Rect)(ref plot)).x, num8, ((Rect)(ref plot)).width, 1f), new Color(1f, 1f, 1f, 0.35f));
		p.Text(((Rect)(ref r)).x, ((Rect)(ref plot)).y - 2f, N(num4), Ink);
		p.Text(((Rect)(ref r)).x, num8 - p.FontSize * 0.6f, "0", new Color(0.75f, 0.72f, 0.68f));
		if (num5 < 0)
		{
			p.Text(((Rect)(ref r)).x, ((Rect)(ref plot)).yMax - p.FontSize, "-" + N(-num5), Ink);
		}
		DrawRepaymentMarks(plot, d, num2, num, p);
		double seconds = (double)num2 * (double)d.BucketSeconds;
		double seconds2 = (double)num * (double)d.BucketSeconds;
		p.Text(((Rect)(ref plot)).x, ((Rect)(ref plot)).yMax + 2f, FormatTime(seconds), Ink);
		string text = FormatTime(seconds2);
		p.Text(((Rect)(ref plot)).xMax - p.Measure(text), ((Rect)(ref plot)).yMax + 2f, text, Ink);
	}

	private static bool IsSteadyFlow(int reason)
	{
		if (reason != 2 && reason != 13)
		{
			return reason == 14;
		}
		return true;
	}

	private void BuildNet(ChartData d, TagSeries s)
	{
		int num = TotalBuckets(d);
		if (num <= 0)
		{
			_netCount = 0;
			_netLast = 0L;
			return;
		}
		int num2 = Mathf.Max(1, Mathf.CeilToInt(60f / d.BucketSeconds));
		if (_net == null || _net.Length < num)
		{
			int num3 = Mathf.Max(num, 256);
			_net = new long[num3];
			_bucketNet = new long[num3];
			_netTag = null;
		}
		bool flag = _netTag != s.TagID || _netCount != num || _netWindow != num2;
		int num4 = ((!flag) ? (num - 1) : 0);
		for (int i = num4; i < num; i++)
		{
			long num5 = 0L;
			for (int j = 0; j < 16; j++)
			{
				if (IsSteadyFlow(j))
				{
					num5 += s.FlowAt(i, j);
					num5 -= s.FlowAt(i, 16 + j);
				}
			}
			_bucketNet[i] = num5;
			long num6 = 0L;
			int num7 = i - num2 + 1;
			if (num7 < 0)
			{
				num7 = 0;
			}
			if (flag && i > 0 && num7 > 0)
			{
				num6 = _net[i - 1] + num5 - _bucketNet[num7 - 1];
			}
			else if (flag && i > 0)
			{
				num6 = _net[i - 1] + num5;
			}
			else
			{
				for (int k = num7; k <= i; k++)
				{
					num6 += _bucketNet[k];
				}
			}
			_net[i] = num6;
		}
		_netTag = s.TagID;
		_netCount = num;
		_netWindow = num2;
		_netLast = _net[num - 1];
	}

	private void DrawRates(Rect r, ChartData d, IChartPainter p)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0258: Unknown result type (might be due to invalid IL or missing references)
		//IL_0302: Unknown result type (might be due to invalid IL or missing references)
		//IL_0307: Unknown result type (might be due to invalid IL or missing references)
		//IL_033a: Unknown result type (might be due to invalid IL or missing references)
		//IL_033f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0366: Unknown result type (might be due to invalid IL or missing references)
		//IL_0391: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_057d: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_048a: Unknown result type (might be due to invalid IL or missing references)
		//IL_048f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0503: Unknown result type (might be due to invalid IL or missing references)
		//IL_051d: Unknown result type (might be due to invalid IL or missing references)
		//IL_066f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0688: Unknown result type (might be due to invalid IL or missing references)
		//IL_0708: Unknown result type (might be due to invalid IL or missing references)
		//IL_06db: Unknown result type (might be due to invalid IL or missing references)
		//IL_06e8: Unknown result type (might be due to invalid IL or missing references)
		if (d.RateSources.Count == 0 || d.Selected == null)
		{
			DrawZeroLine(r, p);
			return;
		}
		float lineHeight = p.LineHeight;
		float iconSize = Mathf.Max(12f, lineHeight);
		_rank.Clear();
		_rankTotals.Clear();
		_rateLines.Clear();
		long num = 0L;
		for (int i = 0; i < d.RateSources.Count && i < d.RateValues.Count; i++)
		{
			_rank.Add(d.RateSources[i]);
			_rankTotals.Add(d.RateTotals[i]);
			_rateLines.Add(d.RateValues[i]);
			num += d.RateTotals[i];
		}
		if (num <= 0)
		{
			DrawZeroLine(r, p);
			return;
		}
		AssignRankColors(d.Selected.TagID);
		while (_rank.Count > 1 && LegendWidth(p, iconSize, num) > ((Rect)(ref r)).width)
		{
			_rank.RemoveAt(_rank.Count - 1);
			_rankColors.RemoveAt(_rankColors.Count - 1);
			_rankTotals.RemoveAt(_rankTotals.Count - 1);
			_rateLines.RemoveAt(_rateLines.Count - 1);
		}
		long num2 = 0L;
		for (int j = 0; j < _rankTotals.Count; j++)
		{
			num2 += _rankTotals[j];
		}
		float num3 = DrawSourceLegend(((Rect)(ref r)).x, ((Rect)(ref r)).y, ((Rect)(ref r)).width, lineHeight, iconSize, d.Selected.TagID, num, num - num2, p);
		float num4 = 0f;
		int num5 = 0;
		for (int k = 0; k < _rateLines.Count; k++)
		{
			float[] array = _rateLines[k];
			if (array.Length > num5)
			{
				num5 = array.Length;
			}
			for (int l = 0; l < array.Length; l++)
			{
				if (array[l] > num4)
				{
					num4 = array[l];
				}
			}
		}
		if (num4 <= 0f || num5 < 2)
		{
			DrawZeroLine(new Rect(((Rect)(ref r)).x, num3, ((Rect)(ref r)).width, ((Rect)(ref r)).yMax - num3), p);
			return;
		}
		float num6 = p.FontSize + 4f;
		float num7 = p.Measure(N((long)num4)) + 10f;
		float num8 = lineHeight + 4f;
		Rect plot = default(Rect);
		((Rect)(ref plot))..ctor(((Rect)(ref r)).x + num7, num3 + 2f, ((Rect)(ref r)).width - num7 - num8, ((Rect)(ref r)).yMax - num3 - num6 - 6f);
		if (((Rect)(ref plot)).width < 20f || ((Rect)(ref plot)).height < 20f)
		{
			return;
		}
		p.Fill(new Rect(((Rect)(ref plot)).x, ((Rect)(ref plot)).yMax, ((Rect)(ref plot)).width, 1f), Faint);
		p.Fill(new Rect(((Rect)(ref plot)).x, ((Rect)(ref plot)).y + ((Rect)(ref plot)).height * 0.5f, ((Rect)(ref plot)).width, 1f), Fainter);
		p.Text(((Rect)(ref r)).x, ((Rect)(ref plot)).y - 2f, N((long)num4), Ink);
		p.Text(((Rect)(ref r)).x, ((Rect)(ref plot)).yMax - p.FontSize * 0.6f, "0", Ink);
		float num9 = num5 - 1;
		_ = ((Rect)(ref plot)).width / num9;
		float num10 = ((Rect)(ref plot)).height / num4;
		Rect r2 = default(Rect);
		for (int m = 0; m < _rateLines.Count; m++)
		{
			float[] array2 = _rateLines[m];
			Color val = _rankColors[m];
			int num11 = Mathf.Max(2, Mathf.CeilToInt(((Rect)(ref plot)).width));
			float num12 = 0f;
			for (int n = 0; n < num11; n++)
			{
				float num13 = (float)n / (float)(num11 - 1) * num9;
				int num14 = Mathf.Clamp((int)num13, 0, array2.Length - 1);
				int num15 = Mathf.Min(num14 + 1, array2.Length - 1);
				float num16 = ((Rect)(ref plot)).yMax - Mathf.Lerp(array2[num14], array2[num15], num13 - (float)num14) * num10;
				if (n == 0)
				{
					num12 = num16;
				}
				float num17 = Mathf.Min(num12, num16);
				p.Fill(new Rect(((Rect)(ref plot)).x + (float)n, num17, 1.6f, Mathf.Abs(num12 - num16) + 1.6f), val);
				num12 = num16;
			}
			float num18 = Mathf.Min(num8, lineHeight);
			if (num18 >= 10f)
			{
				((Rect)(ref r2))..ctor(((Rect)(ref plot)).xMax + 2f, num12 - num18 * 0.5f, num18, num18);
				((Rect)(ref r2)).y = Mathf.Clamp(((Rect)(ref r2)).y, ((Rect)(ref plot)).y, ((Rect)(ref plot)).yMax - num18);
				DrawSourceIcon(r2, _rank[m], d.Selected.TagID, val, p);
			}
		}
		string text = "-" + ((int)(num9 * d.RateSlotSeconds)).ToString(CultureInfo.InvariantCulture) + "s";
		p.Text(((Rect)(ref plot)).x, ((Rect)(ref plot)).yMax + 2f, text, Ink);
		p.Text(((Rect)(ref plot)).xMax - p.Measure("0"), ((Rect)(ref plot)).yMax + 2f, "0", Ink);
		if (!d.MouseValid || d.Mouse.x < ((Rect)(ref plot)).x || d.Mouse.x > ((Rect)(ref plot)).xMax || d.Mouse.y < ((Rect)(ref plot)).y || d.Mouse.y > ((Rect)(ref plot)).yMax)
		{
			return;
		}
		int num19 = Mathf.Clamp(Mathf.RoundToInt((d.Mouse.x - ((Rect)(ref plot)).x) / ((Rect)(ref plot)).width * num9), 0, num5 - 1);
		float num20 = ((Rect)(ref plot)).x + (float)num19 / num9 * ((Rect)(ref plot)).width;
		p.Fill(new Rect(num20, ((Rect)(ref plot)).y, 1f, ((Rect)(ref plot)).height), new Color(1f, 1f, 1f, 0.35f));
		for (int num21 = 0; num21 < _rateLines.Count; num21++)
		{
			float[] array3 = _rateLines[num21];
			if (num19 < array3.Length)
			{
				float num22 = ((Rect)(ref plot)).yMax - array3[num19] * num10;
				p.Fill(new Rect(num20 - 2f, num22 - 2f, 5f, 5f), _rankColors[num21]);
			}
		}
		DrawRateHover(plot, d, num19, num5, p);
	}

	private void DrawRateHover(Rect plot, ChartData d, int at, int slots, IChartPainter p)
	{
		//IL_031c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0335: Unknown result type (might be due to invalid IL or missing references)
		//IL_034c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0365: Unknown result type (might be due to invalid IL or missing references)
		//IL_0385: Unknown result type (might be due to invalid IL or missing references)
		//IL_039e: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_0407: Unknown result type (might be due to invalid IL or missing references)
		//IL_043b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0461: Unknown result type (might be due to invalid IL or missing references)
		//IL_0472: Unknown result type (might be due to invalid IL or missing references)
		//IL_0477: Unknown result type (might be due to invalid IL or missing references)
		//IL_0499: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_050b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0597: Unknown result type (might be due to invalid IL or missing references)
		//IL_05d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_063f: Unknown result type (might be due to invalid IL or missing references)
		//IL_055e: Unknown result type (might be due to invalid IL or missing references)
		_rateOrder.Clear();
		long num = 0L;
		for (int i = 0; i < _rateLines.Count; i++)
		{
			if (at < _rateLines[i].Length && !(_rateLines[i][at] <= 0f))
			{
				_rateOrder.Add(i);
				num += (long)_rateLines[i][at];
			}
		}
		if (_rateOrder.Count == 0)
		{
			return;
		}
		float[][] lines = _rateLines.ToArray();
		_rateOrder.Sort((int a, int b) => lines[b][at].CompareTo(lines[a][at]));
		float num2 = Mathf.Max(12f, p.LineHeight);
		int num3 = Mathf.Min(_rateOrder.Count, 10);
		float num4 = Mathf.Max(num2, p.LineHeight) + 2f;
		float num5 = 6f;
		float num6 = 0f;
		float num7 = 0f;
		float num8 = 0f;
		for (int num9 = 0; num9 < num3; num9++)
		{
			SourceSeries sourceSeries = _rank[_rateOrder[num9]];
			long num10 = (long)_rateLines[_rateOrder[num9]][at];
			num6 = Mathf.Max(num6, p.Measure(N(num10)));
			num7 = Mathf.Max(num7, p.Measure(Percent(num10, num)));
			if (!sourceSeries.HasSource)
			{
				num8 = Mathf.Max(num8, p.Measure(p.ReasonLabel(sourceSeries.Reason)) + 8f);
			}
		}
		int num11 = (int)((float)(slots - 1 - at) * d.RateSlotSeconds);
		string text = ((num11 > 0) ? ("-" + num11.ToString(CultureInfo.InvariantCulture) + "s") : "0");
		string text2 = N(num);
		float num12 = p.Measure(text) + 6f + num2 + 4f + p.Measure(text2);
		float num13 = Mathf.Max(num12, num2 + 6f + num8 + num6 + 6f + num7) + num5 * 2f;
		float num14 = num5 * 2f + num4 + (float)num3 * num4;
		if (_rateOrder.Count > num3)
		{
			num14 += p.LineHeight;
		}
		float num15 = d.Mouse.x + 14f;
		float num16 = d.Mouse.y + 10f;
		if (num15 + num13 > ((Rect)(ref plot)).xMax)
		{
			num15 = d.Mouse.x - 14f - num13;
		}
		if (num16 + num14 > ((Rect)(ref plot)).yMax)
		{
			num16 = ((Rect)(ref plot)).yMax - num14;
		}
		if (num15 < ((Rect)(ref plot)).x)
		{
			num15 = ((Rect)(ref plot)).x;
		}
		if (num16 < ((Rect)(ref plot)).y)
		{
			num16 = ((Rect)(ref plot)).y;
		}
		p.Fill(new Rect(num15, num16, num13, num14), new Color(0.04f, 0.04f, 0.05f, 0.94f));
		p.Fill(new Rect(num15, num16, num13, 1f), new Color(1f, 1f, 1f, 0.25f));
		p.Fill(new Rect(num15, num16 + num14 - 1f, num13, 1f), new Color(1f, 1f, 1f, 0.25f));
		p.Fill(new Rect(num15, num16, 1f, num14), new Color(1f, 1f, 1f, 0.25f));
		p.Fill(new Rect(num15 + num13 - 1f, num16, 1f, num14), new Color(1f, 1f, 1f, 0.25f));
		float num17 = (num2 - p.FontSize) * 0.5f;
		float num18 = num16 + num5;
		float num19 = num15 + num5;
		p.Text(num19, num18 + num17, text, Accent);
		num19 += p.Measure(text) + 6f;
		p.Icon(new Rect(num19, num18, num2, num2), null, d.Selected.TagID, Ink, IconOutline);
		num19 += num2 + 4f;
		p.Text(num19, num18 + num17, text2, Ink);
		num18 += num4;
		for (int num20 = 0; num20 < num3; num20++)
		{
			int index = _rateOrder[num20];
			SourceSeries sourceSeries2 = _rank[index];
			long num21 = (long)_rateLines[index][at];
			DrawSourceIcon(new Rect(num15 + num5, num18, num2, num2), sourceSeries2, d.Selected.TagID, _rankColors[index], p);
			if (!sourceSeries2.HasSource)
			{
				string text3 = p.ReasonLabel(sourceSeries2.Reason);
				if (!string.IsNullOrEmpty(text3))
				{
					p.Text(num15 + num5 + num2 + 6f, num18 + num17, text3, new Color(0.78f, 0.75f, 0.7f));
				}
			}
			string text4 = N(num21);
			p.Text(num15 + num5 + num2 + 6f + num8 + (num6 - p.Measure(text4)), num18 + num17, text4, Ink);
			string text5 = Percent(num21, num);
			p.Text(num15 + num13 - num5 - p.Measure(text5), num18 + num17, text5, new Color(0.75f, 0.72f, 0.68f));
			num18 += num4;
		}
		if (_rateOrder.Count > num3)
		{
			p.Text(num15 + num5, num18, "+" + (_rateOrder.Count - num3).ToString(CultureInfo.InvariantCulture), new Color(0.65f, 0.62f, 0.58f));
		}
	}

	private static void DrawZeroLine(Rect r, IChartPainter p)
	{
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		float num = p.FontSize + 4f;
		float num2 = p.Measure("0") + 10f;
		Rect val = default(Rect);
		((Rect)(ref val))..ctor(((Rect)(ref r)).x + num2, ((Rect)(ref r)).y + 2f, ((Rect)(ref r)).width - num2 - 4f, ((Rect)(ref r)).height - num - 6f);
		if (!(((Rect)(ref val)).width < 8f) && !(((Rect)(ref val)).height < 8f))
		{
			p.Fill(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y, 1f, ((Rect)(ref val)).height), Fainter);
			p.Fill(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).yMax, ((Rect)(ref val)).width, 2f), ZeroColor);
			p.Text(((Rect)(ref r)).x, ((Rect)(ref val)).yMax - p.FontSize * 0.6f, "0", Ink);
		}
	}

	private static void DrawZeroColumn(float cx, float bw, float baseline, float fullHeight, IChartPainter p)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		Rect val = default(Rect);
		((Rect)(ref val))..ctor(cx + 1f, baseline - fullHeight, bw, fullHeight);
		p.Fill(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y, ((Rect)(ref val)).width, 1f), Fainter);
		p.Fill(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y, 1f, ((Rect)(ref val)).height), Fainter);
		p.Fill(new Rect(((Rect)(ref val)).xMax - 1f, ((Rect)(ref val)).y, 1f, ((Rect)(ref val)).height), Fainter);
		float num = Mathf.Max(4f, fullHeight * 0.018f);
		p.Fill(new Rect(((Rect)(ref val)).x, baseline - num, ((Rect)(ref val)).width, num), ZeroColor);
	}

	private void DrawBalanceChart(Rect r, ChartData d, TagSeries single, IChartPainter p)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0214: Unknown result type (might be due to invalid IL or missing references)
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_0268: Unknown result type (might be due to invalid IL or missing references)
		//IL_02af: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_031c: Unknown result type (might be due to invalid IL or missing references)
		//IL_032f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0465: Unknown result type (might be due to invalid IL or missing references)
		//IL_049a: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0521: Unknown result type (might be due to invalid IL or missing references)
		//IL_0387: Unknown result type (might be due to invalid IL or missing references)
		//IL_0392: Unknown result type (might be due to invalid IL or missing references)
		//IL_0421: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
		int num = TotalBuckets(d);
		if (num <= 0)
		{
			DrawZeroLine(r, p);
			return;
		}
		int num2 = 0;
		if (d.LastMinute)
		{
			int num3 = Mathf.Max(2, Mathf.CeilToInt(60f / d.BucketSeconds));
			num2 = Mathf.Max(0, num - num3);
		}
		if (num - num2 < 2)
		{
			num2 = Mathf.Max(0, num - 2);
		}
		float num4 = p.Measure("00,000") + 10f;
		float num5 = p.FontSize + 4f;
		float num6 = ((single == null) ? (p.LineHeight + 4f) : 4f);
		Rect plot = default(Rect);
		((Rect)(ref plot))..ctor(((Rect)(ref r)).x + num4, ((Rect)(ref r)).y + 2f, ((Rect)(ref r)).width - num4 - num6, ((Rect)(ref r)).height - num5 - 6f);
		if (((Rect)(ref plot)).width < 20f || ((Rect)(ref plot)).height < 20f)
		{
			return;
		}
		long min = long.MaxValue;
		long max = long.MinValue;
		if (single != null)
		{
			ScanRange(single, num2, num, ref min, ref max);
		}
		else
		{
			for (int i = 0; i < d.Ordered.Count; i++)
			{
				if (!d.HiddenTags.Contains(d.Ordered[i].TagID))
				{
					ScanRange(d.Ordered[i], num2, num, ref min, ref max);
				}
			}
		}
		if (min == long.MaxValue)
		{
			min = 0L;
			max = 1L;
		}
		if (max <= min)
		{
			max = min + 1;
		}
		long num7 = (long)Math.Max(1.0, (double)(max - min) * 0.06);
		max += num7;
		min -= num7;
		if (min < 0 && !HasNegative(d, single, num2, num))
		{
			min = 0L;
		}
		p.Fill(new Rect(((Rect)(ref plot)).x, ((Rect)(ref plot)).yMax, ((Rect)(ref plot)).width, 1f), Faint);
		p.Fill(new Rect(((Rect)(ref plot)).x, ((Rect)(ref plot)).y + ((Rect)(ref plot)).height * 0.5f, ((Rect)(ref plot)).width, 1f), Fainter);
		float num8 = ((Rect)(ref r)).x + num4 - 6f;
		long v = min + (max - min) / 2;
		p.Text(num8 - p.Measure(N(max)), ((Rect)(ref plot)).y - 2f, N(max), Ink);
		p.Text(num8 - p.Measure(N(v)), ((Rect)(ref plot)).y + ((Rect)(ref plot)).height * 0.5f - p.FontSize * 0.5f, N(v), Ink);
		p.Text(num8 - p.Measure(N(min)), ((Rect)(ref plot)).yMax - p.FontSize, N(min), Ink);
		DrawRepaymentMarks(plot, d, num2, num, p);
		int num9 = ColumnCount(((Rect)(ref plot)).width, d.MaxColumns);
		float colW = ((Rect)(ref plot)).width / (float)num9;
		if (single != null)
		{
			DrawBalanceLine(plot, single, num2, num, num9, colW, min, max, TagColor(single.TagID), p);
		}
		else
		{
			_lineColors.Clear();
			for (int j = 0; j < d.Ordered.Count; j++)
			{
				if (!d.HiddenTags.Contains(d.Ordered[j].TagID))
				{
					_lineColors.Add(Separate(TagColor(d.Ordered[j].TagID), _lineColors));
				}
			}
			int num10 = 0;
			for (int k = 0; k < d.Ordered.Count; k++)
			{
				if (!d.HiddenTags.Contains(d.Ordered[k].TagID))
				{
					DrawBalanceLine(plot, d.Ordered[k], num2, num, num9, colW, min, max, _lineColors[num10], p);
					num10++;
				}
			}
			DrawLineEndCaps(plot, d, num, min, max, p);
		}
		double num11 = (double)num2 * (double)d.BucketSeconds;
		double num12 = (double)num * (double)d.BucketSeconds;
		p.Text(((Rect)(ref plot)).x, ((Rect)(ref plot)).yMax + 2f, FormatTime(num11), Ink);
		string text = FormatTime(num12);
		p.Text(((Rect)(ref plot)).xMax - p.Measure(text), ((Rect)(ref plot)).yMax + 2f, text, Ink);
		string text2 = FormatTime((num11 + num12) * 0.5);
		p.Fill(new Rect(((Rect)(ref plot)).x + ((Rect)(ref plot)).width * 0.5f, ((Rect)(ref plot)).yMax, 1f, 4f), Faint);
		p.Text(((Rect)(ref plot)).x + (((Rect)(ref plot)).width - p.Measure(text2)) * 0.5f, ((Rect)(ref plot)).yMax + 2f, text2, Ink);
	}

	private static bool HasNegative(ChartData d, TagSeries single, int from, int count)
	{
		if (single != null)
		{
			return HasNegative(single, from, count);
		}
		for (int i = 0; i < d.Ordered.Count; i++)
		{
			if (!d.HiddenTags.Contains(d.Ordered[i].TagID) && HasNegative(d.Ordered[i], from, count))
			{
				return true;
			}
		}
		return false;
	}

	private static bool HasNegative(TagSeries s, int from, int count)
	{
		for (int i = from; i < count; i++)
		{
			if (s.BalanceAt(i) < 0)
			{
				return true;
			}
		}
		return false;
	}

	private void DrawLineEndCaps(Rect plot, ChartData d, int count, long min, long max, IChartPainter p)
	{
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		float lineHeight = p.LineHeight;
		if (((Rect)(ref plot)).height < lineHeight * 2f)
		{
			return;
		}
		_capOrder.Clear();
		_capY.Clear();
		for (int i = 0; i < d.Ordered.Count; i++)
		{
			if (!d.HiddenTags.Contains(d.Ordered[i].TagID))
			{
				_capOrder.Add(d.Ordered[i]);
				_capY.Add(ValueToY(plot, min, max, d.Ordered[i].BalanceAt(count - 1)));
			}
		}
		if (_capOrder.Count != 0)
		{
			SortCapsByY();
			float num = float.MinValue;
			for (int j = 0; j < _capY.Count; j++)
			{
				float num2 = Mathf.Max(_capY[j], num + lineHeight + 1f);
				_capY[j] = Mathf.Min(num2, ((Rect)(ref plot)).yMax - lineHeight);
				num = _capY[j];
			}
			float num3 = ((Rect)(ref plot)).xMax - lineHeight;
			Rect val = default(Rect);
			for (int k = 0; k < _capOrder.Count; k++)
			{
				((Rect)(ref val))..ctor(num3, _capY[k] - lineHeight * 0.5f, lineHeight, lineHeight);
				p.Icon(val, null, _capOrder[k].TagID, Ink, IconOutline);
				d.IconRects.Add(val);
				d.IconTagIDs.Add(_capOrder[k].TagID);
			}
		}
	}

	private void SortCapsByY()
	{
		for (int i = 1; i < _capY.Count; i++)
		{
			float num = _capY[i];
			TagSeries value = _capOrder[i];
			int num2 = i - 1;
			while (num2 >= 0 && _capY[num2] > num)
			{
				_capY[num2 + 1] = _capY[num2];
				_capOrder[num2 + 1] = _capOrder[num2];
				num2--;
			}
			_capY[num2 + 1] = num;
			_capOrder[num2 + 1] = value;
		}
	}

	private static void ScanRange(TagSeries s, int from, int count, ref long min, ref long max)
	{
		for (int i = from; i < count; i++)
		{
			long num = s.BalanceAt(i);
			if (num < min)
			{
				min = num;
			}
			if (num > max)
			{
				max = num;
			}
		}
	}

	private static void DrawBalanceLine(Rect plot, TagSeries s, int from, int count, int cols, float colW, long min, long max, Color stroke, IChartPainter p)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		int num = count - from;
		if (num <= 0)
		{
			return;
		}
		if (num < cols)
		{
			DrawInterpolatedLine(plot, s, from, count, cols, colW, min, max, stroke, p);
			return;
		}
		float num2 = float.NaN;
		for (int i = 0; i < cols; i++)
		{
			int num3 = from + (int)((long)i * (long)num / cols);
			int num4 = from + (int)((long)(i + 1) * (long)num / cols);
			if (num4 <= num3)
			{
				num4 = num3 + 1;
			}
			long num5 = long.MaxValue;
			long num6 = long.MinValue;
			long value = 0L;
			for (int j = num3; j < num4 && j < count; j++)
			{
				long num7 = s.BalanceAt(j);
				if (num7 < num5)
				{
					num5 = num7;
				}
				if (num7 > num6)
				{
					num6 = num7;
				}
				value = num7;
			}
			if (num5 != long.MaxValue)
			{
				float num8 = ValueToY(plot, min, max, num6);
				float num9 = ValueToY(plot, min, max, num5);
				if (!float.IsNaN(num2))
				{
					num8 = Mathf.Min(num8, num2);
					num9 = Mathf.Max(num9, num2);
				}
				float num10 = ((Rect)(ref plot)).x + (float)i * colW;
				p.Fill(new Rect(num10, num8, colW, Mathf.Max(2f, num9 - num8 + 2f)), stroke);
				num2 = ValueToY(plot, min, max, value);
			}
		}
	}

	private static void DrawInterpolatedLine(Rect plot, TagSeries s, int from, int count, int cols, float colW, long min, long max, Color stroke, IChartPainter p)
	{
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		int num = count - from;
		float num2 = float.NaN;
		for (int i = 0; i < cols; i++)
		{
			float num3 = (float)from + (float)i * (float)(num - 1) / (float)(cols - 1);
			int num4 = (int)num3;
			int bucket = Mathf.Min(num4 + 1, count - 1);
			float num5 = num3 - (float)num4;
			float value = (float)s.BalanceAt(num4) * (1f - num5) + (float)s.BalanceAt(bucket) * num5;
			float num6 = ValueToYFloat(plot, min, max, value);
			float num7 = ((Rect)(ref plot)).x + (float)i * colW;
			float num8 = (float.IsNaN(num2) ? num6 : Mathf.Min(num2, num6));
			float num9 = (float.IsNaN(num2) ? num6 : Mathf.Max(num2, num6));
			p.Fill(new Rect(num7, num8, colW, Mathf.Max(2f, num9 - num8 + 2f)), stroke);
			num2 = num6;
		}
	}

	private static float ValueToYFloat(Rect plot, long min, long max, float value)
	{
		double num = ((double)value - (double)min) / (double)(max - min);
		if (num < 0.0)
		{
			num = 0.0;
		}
		if (num > 1.0)
		{
			num = 1.0;
		}
		return ((Rect)(ref plot)).yMax - (float)(num * (double)((Rect)(ref plot)).height);
	}

	private static void DrawRepaymentMarks(Rect plot, ChartData d, int from, int count, IChartPainter p)
	{
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		double num = (double)from * (double)d.BucketSeconds;
		double num2 = (double)count * (double)d.BucketSeconds;
		double num3 = num2 - num;
		if (num3 <= 0.0)
		{
			return;
		}
		float num4 = float.MinValue;
		Color val = default(Color);
		((Color)(ref val))..ctor(0.92f, 0.34f, 0.36f, 0.28f);
		Color val2 = default(Color);
		((Color)(ref val2))..ctor(0.95f, 0.38f, 0.4f, 0.85f);
		for (int i = 0; i < d.PeriodEnds.Count; i++)
		{
			double num5 = d.PeriodEnds[i];
			if (num5 < num || num5 > num2)
			{
				continue;
			}
			int num6 = ((i < d.PeriodRepaid.Count) ? d.PeriodRepaid[i] : (i + 1));
			int num7 = ((i > 0 && i - 1 < d.PeriodRepaid.Count) ? d.PeriodRepaid[i - 1] : 0);
			bool flag = num6 / 5 != num7 / 5;
			float num8 = ((Rect)(ref plot)).x + (float)((num5 - num) / num3) * ((Rect)(ref plot)).width;
			p.Fill(new Rect(num8, ((Rect)(ref plot)).y, flag ? 2f : 1f, ((Rect)(ref plot)).height), flag ? val2 : val);
			if (flag)
			{
				string text = num6.ToString(CultureInfo.InvariantCulture);
				if (!(num8 + 3f < num4))
				{
					p.Text(num8 + 3f, ((Rect)(ref plot)).y, text, new Color(0.98f, 0.62f, 0.62f));
					num4 = num8 + 3f + p.Measure(text) + 3f;
				}
			}
		}
	}

	private void DrawComposition(Rect r, ChartData d, IChartPainter p)
	{
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0200: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_0276: Unknown result type (might be due to invalid IL or missing references)
		TagSeries selected = d.Selected;
		List<SourceSeries> list = (d.ExpenseSide ? selected.ExpenseSources : selected.IncomeSources);
		float lineHeight = p.LineHeight;
		float num = Mathf.Max(10f, lineHeight * 0.7f);
		float iconSize = Mathf.Max(16f, lineHeight * 1.6f);
		float iconSize2 = Mathf.Max(12f, lineHeight);
		long num2 = 0L;
		for (int i = 0; i < list.Count; i++)
		{
			if (list[i].Total > 0)
			{
				num2 += list[i].Total;
			}
		}
		if (num2 <= 0)
		{
			num2 = 1L;
		}
		RankSources(list, selected.TagID, SourcePalette.Length);
		while (_rank.Count > 1 && LegendWidth(p, iconSize2, num2) > ((Rect)(ref r)).width)
		{
			_rank.RemoveAt(_rank.Count - 1);
			_rankColors.RemoveAt(_rankColors.Count - 1);
		}
		if (_rank.Count == 0)
		{
			DrawPeriodColumns(r, d, list, iconSize, p);
			return;
		}
		long num3 = 0L;
		for (int j = 0; j < _rank.Count; j++)
		{
			num3 += _rank[j].Total;
		}
		long num4 = num2 - num3;
		float num5 = ((Rect)(ref r)).x;
		for (int k = 0; k < _rank.Count; k++)
		{
			float num6 = ((Rect)(ref r)).width * (float)((double)_rank[k].Total / (double)num2);
			p.Fill(new Rect(num5, ((Rect)(ref r)).y, Mathf.Max(1f, num6 - 1f), num), _rankColors[k]);
			num5 += num6;
		}
		if (num4 > 0)
		{
			p.Fill(new Rect(num5, ((Rect)(ref r)).y, Mathf.Max(1f, ((Rect)(ref r)).xMax - num5), num), OthersColor);
		}
		float y = ((Rect)(ref r)).y + num + 4f;
		y = DrawSourceLegend(((Rect)(ref r)).x, y, ((Rect)(ref r)).width, lineHeight, iconSize2, selected.TagID, num2, num4, p);
		Rect r2 = default(Rect);
		((Rect)(ref r2))..ctor(((Rect)(ref r)).x, y, ((Rect)(ref r)).width, ((Rect)(ref r)).yMax - y);
		if (((Rect)(ref r2)).height > 40f)
		{
			DrawPeriodColumns(r2, d, list, iconSize, p);
		}
	}

	private static long ColumnRepaidSum(List<SourceSeries> all, int period)
	{
		long num = 0L;
		for (int i = 0; i < all.Count; i++)
		{
			num += all[i].RepaidAt(period);
		}
		return num;
	}

	private static long Value(SourceSeries src, int period, bool byRepaid)
	{
		if (!byRepaid)
		{
			return src.At(period);
		}
		return src.RepaidAt(period);
	}

	private float LegendWidth(IChartPainter p, float iconSize, long grand)
	{
		float num = 0f;
		long num2 = 0L;
		for (int i = 0; i < _rank.Count; i++)
		{
			num2 += _rankTotals[i];
			num += iconSize + 2f + p.Measure(Percent(_rankTotals[i], grand)) + 10f;
		}
		long num3 = grand - num2;
		if (num3 > 0)
		{
			num += iconSize + 2f + p.Measure(Percent(num3, grand)) + 10f;
		}
		return num;
	}

	private float DrawSourceLegend(float x, float y, float w, float line, float iconSize, string tagID, long grand, long others, IChartPainter p)
	{
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		float num = x;
		float num2 = y;
		int num3 = 1;
		Rect r = default(Rect);
		for (int i = 0; i <= _rank.Count; i++)
		{
			bool flag = i == _rank.Count;
			if (flag && others <= 0)
			{
				break;
			}
			long num4 = (flag ? others : _rankTotals[i]);
			string text = ((int)Math.Round((double)num4 * 100.0 / (double)grand)).ToString(CultureInfo.InvariantCulture) + "%";
			float num5 = iconSize + 2f + p.Measure(text) + 10f;
			if (num + num5 > x + w)
			{
				if (num3 >= 2)
				{
					break;
				}
				num3++;
				num = x;
				num2 += line + 2f;
			}
			Color val = (flag ? OthersColor : _rankColors[i]);
			((Rect)(ref r))..ctor(num, num2, iconSize, iconSize);
			if (flag)
			{
				p.Fill(r, val);
			}
			else
			{
				DrawSourceIcon(r, _rank[i], tagID, val, p);
			}
			p.Fill(new Rect(num, num2 + iconSize, iconSize, 2f), val);
			p.Text(num + iconSize + 2f, num2 + (iconSize - p.FontSize) * 0.5f, text, Ink);
			num += num5;
		}
		return num2 + iconSize + 6f;
	}

	private void DrawPeriodColumns(Rect r, ChartData d, List<SourceSeries> all, float iconSize, IChartPainter p)
	{
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0428: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_040f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0342: Unknown result type (might be due to invalid IL or missing references)
		//IL_0347: Unknown result type (might be due to invalid IL or missing references)
		//IL_0269: Unknown result type (might be due to invalid IL or missing references)
		//IL_0276: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
		int num = Mathf.Max(1, d.PeriodIndex + 1);
		float num2 = p.FontSize + 4f;
		float num3 = 2f;
		Rect plot = default(Rect);
		((Rect)(ref plot))..ctor(((Rect)(ref r)).x + num3, ((Rect)(ref r)).y, ((Rect)(ref r)).width - num3 - 2f, ((Rect)(ref r)).height - num2 - 2f);
		if (((Rect)(ref plot)).width < 20f || ((Rect)(ref plot)).height < 20f)
		{
			return;
		}
		bool flag = UsesNorm(d);
		if (flag)
		{
			NormRatio(d);
		}
		float yMax = ((Rect)(ref plot)).yMax;
		float height = ((Rect)(ref plot)).height;
		p.Fill(new Rect(((Rect)(ref plot)).x, yMax - height * 0.5f, ((Rect)(ref plot)).width, 1f), Faint);
		p.Fill(new Rect(((Rect)(ref plot)).x, yMax, ((Rect)(ref plot)).width, 1f), Faint);
		float num4 = ((Rect)(ref plot)).width / (float)num;
		float num5 = Mathf.Max(1f, num4 - 2f);
		int num6 = num - 1;
		float num7 = Mathf.Min(iconSize, num5);
		Rect r2 = default(Rect);
		for (int i = 0; i < num; i++)
		{
			bool byRepaid = ColumnRepaidSum(all, i) > 0;
			long num8 = 0L;
			for (int j = 0; j < all.Count; j++)
			{
				num8 += Value(all[j], i, byRepaid);
			}
			float num9 = ((Rect)(ref plot)).x + (float)i * num4;
			bool flag2 = i == num6;
			if (flag2)
			{
				DrawCurrentFrame(new Rect(num9, ((Rect)(ref plot)).y, num4, yMax - ((Rect)(ref plot)).y), p);
			}
			if (flag2 && flag)
			{
				DrawHoldingColumn(num9, num5, yMax, height, num7, d, all, p);
				continue;
			}
			if (num8 <= 0)
			{
				DrawZeroColumn(num9, num5, yMax, height, p);
				continue;
			}
			float num10 = height;
			float num11 = ((num8 > 0) ? (num10 / (float)num8) : 0f);
			float num12 = yMax;
			long num13 = 0L;
			for (int k = 0; k < _rank.Count; k++)
			{
				long num14 = Value(_rank[k], i, byRepaid);
				if (num14 <= 0)
				{
					continue;
				}
				num13 += num14;
				float num15 = (float)num14 * num11;
				if (!(num15 <= 0f))
				{
					num12 -= num15;
					p.Fill(new Rect(num9 + 1f, num12, num5, Mathf.Max(1f, num15)), _rankColors[k]);
					if (num7 >= 16f && num15 >= num7 + 4f)
					{
						float num16 = num7;
						((Rect)(ref r2))..ctor(num9 + 1f + (num5 - num16) * 0.5f, num12 + (num15 - num16) * 0.5f, num16, num16);
						DrawSourceIcon(r2, _rank[k], d.Selected.TagID, _rankColors[k], p);
					}
				}
			}
			long num17 = num8 - num13;
			if (num17 > 0)
			{
				float num18 = (float)num17 * num11;
				num12 -= num18;
				p.Fill(new Rect(num9 + 1f, num12, num5, Mathf.Max(1f, num18)), OthersColor);
			}
		}
		bool flag3 = num <= 12;
		for (int l = 0; l < num; l++)
		{
			if (l < d.PeriodRepaid.Count)
			{
				int num19 = d.PeriodRepaid[l];
				int num20 = ((l > 0) ? d.PeriodRepaid[l - 1] : 0);
				if (flag3 || l == 0 || num19 / 5 != num20 / 5)
				{
					string text = num19.ToString(CultureInfo.InvariantCulture);
					p.Text(((Rect)(ref plot)).x + (float)l * num4 + num4 * 0.5f - p.Measure(text) * 0.5f, ((Rect)(ref plot)).yMax + 2f, text, Ink);
				}
			}
		}
		DrawHover(plot, d, all, num, num4, iconSize, flag, p);
	}

	private void DrawHover(Rect plot, ChartData d, List<SourceSeries> all, int total, float cw, float iconSize, bool useNorm, IChartPainter p)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		if (!d.MouseValid || !((Rect)(ref plot)).Contains(d.Mouse))
		{
			return;
		}
		int num = (int)((d.Mouse.x - ((Rect)(ref plot)).x) / cw);
		if (num < 0 || num >= total)
		{
			return;
		}
		_hoverHeld = useNorm && num == total - 1;
		_hoverByRepaid = ColumnRepaidSum(all, num) > 0;
		_hoverPeriod = num;
		_hover.Clear();
		long num2 = 0L;
		for (int i = 0; i < all.Count; i++)
		{
			long num3 = HoverValue(all[i]);
			if (num3 > 0)
			{
				_hover.Add(all[i]);
				num2 += num3;
			}
		}
		if (_hover.Count != 0 && num2 > 0)
		{
			_hover.Sort(CompareHover);
			float num4 = ((Rect)(ref plot)).x + (float)num * cw;
			p.Fill(new Rect(num4, ((Rect)(ref plot)).y, cw, ((Rect)(ref plot)).height), new Color(1f, 1f, 1f, 0.1f));
			long denom = ((_hoverHeld && d.RequiredCount > 0) ? d.RequiredCount : num2);
			DrawHoverBox(plot, d, num, num2, denom, iconSize, p);
		}
	}

	private int CompareHover(SourceSeries a, SourceSeries b)
	{
		return HoverValue(b).CompareTo(HoverValue(a));
	}

	private long HoverValue(SourceSeries src)
	{
		if (_hoverHeld)
		{
			return src.Held;
		}
		return Value(src, _hoverPeriod, _hoverByRepaid);
	}

	private void DrawHoverBox(Rect plot, ChartData d, int period, long sum, long denom, float iconSize, IChartPainter p)
	{
		//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0301: Unknown result type (might be due to invalid IL or missing references)
		//IL_0321: Unknown result type (might be due to invalid IL or missing references)
		//IL_033a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0351: Unknown result type (might be due to invalid IL or missing references)
		//IL_036a: Unknown result type (might be due to invalid IL or missing references)
		//IL_038a: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_040f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0414: Unknown result type (might be due to invalid IL or missing references)
		//IL_0437: Unknown result type (might be due to invalid IL or missing references)
		//IL_0464: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_04bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0579: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_062d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0533: Unknown result type (might be due to invalid IL or missing references)
		int num = Mathf.Min(_hover.Count, 10);
		float num2 = Mathf.Max(iconSize, p.LineHeight) + 2f;
		float num3 = 6f;
		float num4 = 0f;
		float num5 = 0f;
		float num6 = 0f;
		for (int i = 0; i < num; i++)
		{
			long num7 = HoverValue(_hover[i]);
			num4 = Mathf.Max(num4, p.Measure(N(num7)));
			num5 = Mathf.Max(num5, p.Measure(Percent(num7, denom)));
			if (!_hover[i].HasSource)
			{
				num6 = Mathf.Max(num6, p.Measure(p.ReasonLabel(_hover[i].Reason)) + 8f);
			}
		}
		int num8 = ((period < d.PeriodRepaid.Count) ? d.PeriodRepaid[period] : (d.RepaidTotal + 1));
		int num9 = ((period > 0 && period - 1 < d.PeriodRepaid.Count) ? d.PeriodRepaid[period - 1] : 0);
		string text = ((num8 - num9 > 1) ? ((num9 + 1).ToString(CultureInfo.InvariantCulture) + "-" + num8.ToString(CultureInfo.InvariantCulture)) : Math.Max(1, num8).ToString(CultureInfo.InvariantCulture));
		string text2 = N(sum);
		string text3 = ((denom != sum) ? Percent(sum, denom) : null);
		float num10 = p.Measure(text) + 6f + iconSize + 4f + p.Measure(text2) + ((text3 != null) ? (p.Measure(text3) + 6f) : 0f);
		float num11 = Mathf.Max(num10, iconSize + 6f + num6 + num4 + 6f + num5) + num3 * 2f;
		float num12 = num3 * 2f + num2 + (float)num * num2;
		if (_hover.Count > num)
		{
			num12 += p.LineHeight;
		}
		float num13 = d.Mouse.x + 14f;
		float num14 = d.Mouse.y + 10f;
		if (num13 + num11 > ((Rect)(ref plot)).xMax)
		{
			num13 = d.Mouse.x - 14f - num11;
		}
		if (num14 + num12 > ((Rect)(ref plot)).yMax)
		{
			num14 = ((Rect)(ref plot)).yMax - num12;
		}
		if (num13 < ((Rect)(ref plot)).x)
		{
			num13 = ((Rect)(ref plot)).x;
		}
		if (num14 < ((Rect)(ref plot)).y)
		{
			num14 = ((Rect)(ref plot)).y;
		}
		p.Fill(new Rect(num13, num14, num11, num12), new Color(0.04f, 0.04f, 0.05f, 0.94f));
		p.Fill(new Rect(num13, num14, num11, 1f), new Color(1f, 1f, 1f, 0.25f));
		p.Fill(new Rect(num13, num14 + num12 - 1f, num11, 1f), new Color(1f, 1f, 1f, 0.25f));
		p.Fill(new Rect(num13, num14, 1f, num12), new Color(1f, 1f, 1f, 0.25f));
		p.Fill(new Rect(num13 + num11 - 1f, num14, 1f, num12), new Color(1f, 1f, 1f, 0.25f));
		float num15 = num14 + num3;
		float num16 = num13 + num3;
		float num17 = (iconSize - p.FontSize) * 0.5f;
		p.Text(num16, num15 + num17, text, Accent);
		num16 += p.Measure(text) + 6f;
		p.Icon(new Rect(num16, num15, iconSize, iconSize), null, d.Selected.TagID, Ink, IconOutline);
		num16 += iconSize + 4f;
		p.Text(num16, num15 + num17, text2, Ink);
		if (text3 != null)
		{
			num16 += p.Measure(text2) + 6f;
			p.Text(num16, num15 + num17, text3, Accent);
		}
		num15 += num2;
		Rect r = default(Rect);
		for (int j = 0; j < num; j++)
		{
			long num18 = HoverValue(_hover[j]);
			((Rect)(ref r))..ctor(num13 + num3, num15, iconSize, iconSize);
			DrawSourceIcon(r, _hover[j], d.Selected.TagID, OthersColor, p);
			if (!_hover[j].HasSource)
			{
				string text4 = p.ReasonLabel(_hover[j].Reason);
				if (!string.IsNullOrEmpty(text4))
				{
					p.Text(num13 + num3 + iconSize + 6f, num15 + (iconSize - p.FontSize) * 0.5f, text4, new Color(0.78f, 0.75f, 0.7f));
				}
			}
			string text5 = N(num18);
			p.Text(num13 + num3 + iconSize + 6f + num6 + (num4 - p.Measure(text5)), num15 + (iconSize - p.FontSize) * 0.5f, text5, Ink);
			string text6 = Percent(num18, denom);
			p.Text(num13 + num11 - num3 - p.Measure(text6), num15 + (iconSize - p.FontSize) * 0.5f, text6, new Color(0.75f, 0.72f, 0.68f));
			num15 += num2;
		}
		if (_hover.Count > num)
		{
			p.Text(num13 + num3, num15, "+" + (_hover.Count - num).ToString(CultureInfo.InvariantCulture), new Color(0.65f, 0.62f, 0.58f));
		}
	}

	private static string Percent(long value, long sum)
	{
		if (sum <= 0)
		{
			return "0%";
		}
		return Mathf.RoundToInt((float)((double)value * 100.0 / (double)sum)).ToString(CultureInfo.InvariantCulture) + "%";
	}

	private void DrawHoldingColumn(float cx, float bw, float baseline, float fullHeight, float iconFit, ChartData d, List<SourceSeries> all, IChartPainter p)
	{
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		TagSeries selected = d.Selected;
		long num = selected.HeldTotal();
		if (num <= 0 || d.RequiredCount <= 0)
		{
			DrawZeroColumn(cx, bw, baseline, fullHeight, p);
			return;
		}
		double num2 = (double)Math.Max(0L, d.RequiredCurrent) / (double)num;
		float num3 = fullHeight / (float)d.RequiredCount;
		float top = baseline - fullHeight;
		float num4 = (float)((double)num * num2) * num3;
		float num5 = ((num4 > fullHeight) ? (fullHeight / num4) : 1f);
		float yy = baseline;
		long num6 = 0L;
		Rect r = default(Rect);
		for (int i = 0; i < _rank.Count; i++)
		{
			long held = _rank[i].Held;
			if (held <= 0)
			{
				continue;
			}
			num6 += held;
			float num7 = (float)((double)held * num2) * num3 * num5;
			if (!(num7 <= 0f))
			{
				float num8 = StackBand(cx, bw, top, ref yy, num7, _rankColors[i], p);
				if (num8 <= 0f)
				{
					break;
				}
				if (iconFit >= 16f && num8 >= iconFit + 4f)
				{
					((Rect)(ref r))..ctor(cx + 1f + (bw - iconFit) * 0.5f, yy + (num8 - iconFit) * 0.5f, iconFit, iconFit);
					DrawSourceIcon(r, _rank[i], selected.TagID, _rankColors[i], p);
				}
			}
		}
		long num9 = num - num6;
		if (num9 > 0)
		{
			float h = (float)((double)num9 * num2) * num3 * num5;
			StackBand(cx, bw, top, ref yy, h, OthersColor, p);
		}
		float num10 = num4 / fullHeight;
		if (num10 >= 1.05f)
		{
			DrawOverflowCap(cx + 1f, bw, baseline, num10, p);
		}
	}

	private static void DrawOverflowCap(float x, float w, float baseline, float ratio, IChartPainter p)
	{
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		string text = "×" + ratio.ToString("0.#", CultureInfo.InvariantCulture);
		float num = p.Measure(text);
		if (num <= w + 6f)
		{
			p.Text(x + (w - num) * 0.5f, baseline + 2f, text, Accent);
		}
	}

	private static float StackBand(float cx, float bw, float top, ref float yy, float h, Color color, IChartPainter p)
	{
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		float num = yy - top;
		if (num <= 0f)
		{
			return 0f;
		}
		float num2 = Mathf.Min(h, num);
		yy -= num2;
		p.Fill(new Rect(cx + 1f, yy, bw, Mathf.Max(1f, num2)), color);
		return num2;
	}

	private static void DrawCurrentFrame(Rect slot, IChartPainter p)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		Color color = default(Color);
		((Color)(ref color))..ctor(Accent.r, Accent.g, Accent.b, 0.75f);
		p.Fill(new Rect(((Rect)(ref slot)).x, ((Rect)(ref slot)).y, ((Rect)(ref slot)).width, 1f), color);
		p.Fill(new Rect(((Rect)(ref slot)).x, ((Rect)(ref slot)).yMax, ((Rect)(ref slot)).width, 1f), color);
		p.Fill(new Rect(((Rect)(ref slot)).x, ((Rect)(ref slot)).y, 1f, ((Rect)(ref slot)).height), color);
		p.Fill(new Rect(((Rect)(ref slot)).xMax - 1f, ((Rect)(ref slot)).y, 1f, ((Rect)(ref slot)).height), color);
	}

	private void RankSources(List<SourceSeries> all, string tagID, int maxEntries)
	{
		_rank.Clear();
		_rankColors.Clear();
		_rankTotals.Clear();
		long num = 0L;
		for (int i = 0; i < all.Count; i++)
		{
			if (all[i].Total > 0)
			{
				num += all[i].Total;
			}
		}
		if (num <= 0)
		{
			return;
		}
		long num2 = (long)((float)num * 0.03f);
		for (int j = 0; j < all.Count; j++)
		{
			if (all[j].Total > 0 && all[j].Total >= num2)
			{
				_rank.Add(all[j]);
			}
		}
		_rank.Sort((SourceSeries a, SourceSeries b) => b.Total.CompareTo(a.Total));
		int num3 = Mathf.Min(SourcePalette.Length, Mathf.Max(1, maxEntries));
		while (_rank.Count > num3)
		{
			_rank.RemoveAt(_rank.Count - 1);
		}
		for (int num4 = 0; num4 < _rank.Count; num4++)
		{
			_rankTotals.Add(_rank[num4].Total);
		}
		AssignRankColors(tagID);
	}

	private void AssignRankColors(string tagID)
	{
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		_rankColors.Clear();
		for (int i = 0; i < _rank.Count; i++)
		{
			string id = (_rank[i].HasSource ? _rank[i].Key : tagID);
			if (!ChartColors.TryGet(id, out var color))
			{
				color = SourcePalette[i % SourcePalette.Length];
			}
			_rankColors.Add(Separate(color, _rankColors));
		}
	}

	private static Color Separate(Color color, List<Color> used)
	{
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 1; i <= 6; i++)
		{
			bool flag = false;
			for (int j = 0; j < used.Count; j++)
			{
				if (Distance(used[j], color) < 0.2f)
				{
					flag = true;
					break;
				}
			}
			if (!flag)
			{
				return color;
			}
			float num = 0.16f * (float)((i + 1) / 2);
			if (i % 2 == 0)
			{
				num = 0f - num;
			}
			color = ShiftValue(color, num);
		}
		return color;
	}

	private static float Distance(Color a, Color b)
	{
		float num = a.r - b.r;
		float num2 = a.g - b.g;
		float num3 = a.b - b.b;
		return Mathf.Sqrt(num * num + num2 * num2 + num3 * num3);
	}

	private static Color ShiftValue(Color c, float delta)
	{
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.Max(c.r, Mathf.Max(c.g, c.b));
		if (num <= 0.001f)
		{
			return new Color(0.5f, 0.5f, 0.5f, c.a);
		}
		float num2 = Mathf.Clamp(num + delta, 0.22f, 1f);
		float num3 = num2 / num;
		return new Color(Mathf.Clamp01(c.r * num3), Mathf.Clamp01(c.g * num3), Mathf.Clamp01(c.b * num3), c.a);
	}

	private static void DrawSourceIcon(Rect r, SourceSeries src, string tagID, Color fallback, IChartPainter p)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		if (!p.Icon(r, src.Key, tagID, Ink, IconOutline))
		{
			p.Fill(r, fallback);
		}
	}

	internal static int KnownIndex(string tagID)
	{
		for (int i = 0; i < KnownTagIDs.Length; i++)
		{
			if (string.Equals(KnownTagIDs[i], tagID, StringComparison.Ordinal))
			{
				return i;
			}
		}
		return KnownTagIDs.Length;
	}

	internal static Color TagColor(string tagID)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		if (ChartColors.TryGet(tagID, out var color))
		{
			return color;
		}
		int num = KnownIndex(tagID);
		if (num < 0 || num >= TagColors.Length)
		{
			num = TagColors.Length - 1;
		}
		return TagColors[num];
	}

	private static int ColumnCount(float width, int cap)
	{
		int num = (int)width;
		if (cap >= 32 && num > cap)
		{
			num = cap;
		}
		if (num < 2)
		{
			num = 2;
		}
		return num;
	}

	private static float ValueToY(Rect plot, long min, long max, long value)
	{
		double num = (double)(value - min) / (double)(max - min);
		if (num < 0.0)
		{
			num = 0.0;
		}
		if (num > 1.0)
		{
			num = 1.0;
		}
		return ((Rect)(ref plot)).yMax - (float)(num * (double)((Rect)(ref plot)).height);
	}

	private static int TotalBuckets(ChartData d)
	{
		int num = d.BucketCount;
		for (int i = 0; i < d.Ordered.Count; i++)
		{
			if (d.Ordered[i].Balances.Count > num)
			{
				num = d.Ordered[i].Balances.Count;
			}
		}
		return num;
	}

	internal static string N(long v)
	{
		bool flag = v < 0;
		double num = (flag ? (0.0 - (double)v) : ((double)v));
		string text = ((num >= 1000000000000.0) ? ((num / 1000000000000.0).ToString("0.0", CultureInfo.InvariantCulture) + "T") : ((num >= 1000000000.0) ? ((num / 1000000000.0).ToString("0.0", CultureInfo.InvariantCulture) + "B") : ((num >= 1000000.0) ? ((num / 1000000.0).ToString("0.0", CultureInfo.InvariantCulture) + "M") : ((!(num >= 1000.0)) ? num.ToString("0", CultureInfo.InvariantCulture) : ((num / 1000.0).ToString("0.0", CultureInfo.InvariantCulture) + "K")))));
		if (!flag)
		{
			return text;
		}
		return "-" + text;
	}

	internal static string F(double v)
	{
		return v.ToString("0.##", CultureInfo.InvariantCulture);
	}

	internal static string FormatTime(double seconds)
	{
		if (seconds < 0.0)
		{
			seconds = 0.0;
		}
		int num = (int)seconds;
		int num2 = num / 3600;
		int num3 = num % 3600 / 60;
		int num4 = num % 60;
		if (num2 > 0)
		{
			return num2.ToString(CultureInfo.InvariantCulture) + ":" + num3.ToString("00", CultureInfo.InvariantCulture) + ":" + num4.ToString("00", CultureInfo.InvariantCulture);
		}
		return num3.ToString(CultureInfo.InvariantCulture) + ":" + num4.ToString("00", CultureInfo.InvariantCulture);
	}
}
internal static class ChartColors
{
	private static Dictionary<string, Color> _map;

	private static readonly string[] Ids = new string[238]
	{
		"Adamantite", "All", "AllCritByTime", "Amethyst", "BuffGemMagic", "CancelGetFam", "Cash", "CashByLandTime", "Chemical", "Cinnabar",
		"Cobalt", "Coin", "Compost", "Construction", "ConvertOnRAllFuel", "Conveyor2Supplies", "ConveyorSpeedByTime", "ConveyorSupplies", "Crafter", "CrimeCoin",
		"CrimeContract", "CrimeLand", "Debug1", "Debug2", "Debug3", "Debug4", "Debug5", "FakeCoin", "FakeStamp", "FamExpense",
		"FamIncome", "FasterOrder", "Fertilizer", "FreeLand", "FreeLandSupplies", "Fuel", "GemPowder", "Gold", "GoldOre", "Grocery",
		"Gunpowder", "HDAStamp", "Honey", "Hourglass", "IntervalChemical", "IntervalCrafter", "IntervalFuel", "IntervalGrocery", "IntervalMagic", "IntervalSmelter",
		"IntervalSummoner", "IntervalTransporter", "IntervalWorker", "Iron", "IronOre", "Jade", "Lemon", "Lemonade", "LoseTransportSpeed", "Luxury",
		"Lye", "Magic", "MagicChunk", "MagicToCash", "Mercury", "Monitoring", "Mushroom", "Mythril", "Nitro", "Oil",
		"Olive", "OnDeliveryPatronResources", "OnPurchaseTag1", "OnPurchaseTag6", "OrderTag6ByAll", "Orichalcum", "Pickaxe", "ReduceSkillCost", "RelicAllSmelter", "RelicAmethyst",
		"RelicCobalt", "RelicCritCash", "RelicJade", "RelicLye", "RelicOrderTag1", "RelicOrderTag6", "RelicRepaymentTag4", "RelicRuby", "RelicTag2X10", "RelicTag6X10",
		"RepaymentLoseCash", "RoyalStraightFlush", "Ruby", "Salt", "Smelter", "SmelterSpeedByTime", "Smuggling", "Soda", "Splitter", "Stamp",
		"Sulfur", "Summon-Caretaker", "Summon-Conveyor", "Summon-Conveyor2", "Summon-Crafter", "Summon-Farmer", "Summon-Smelter", "Summon-Splitter", "Summon-Splitter2", "Summon-Summoner",
		"Summon-Transporter", "Summon-TransporterExit", "Summon-Worker", "Summoner", "SummonerSpeed", "SusPowder", "TradeCrafterAmethystCoin", "TradeCrafterAmethystFuelGold", "TradeCrafterAmethystWoodGold", "TradeCrafterCinnabarFuelSoda",
		"TradeCrafterCinnabarGold", "TradeCrafterCobaltFuelMercury", "TradeCrafterCobaltSoda", "TradeCrafterCobaltWoodMercury", "TradeCrafterCoinFuelGold", "TradeCrafterCoinWoodGold", "TradeCrafterComplexCoin", "TradeCrafterComplexNitro", "TradeCrafterComplexPickaxe", "TradeCrafterComplexSoda",
		"TradeCrafterConstructionSplitter2", "TradeCrafterFuelCoin", "TradeCrafterFuelSplitter2", "TradeCrafterGoldOreCoin", "TradeCrafterIronCoin", "TradeCrafterIronOreFuelPickaxe", "TradeCrafterIronOreGold", "TradeCrafterJadeFuelIron", "TradeCrafterJadePickaxe", "TradeCrafterJadeWoodIron",
		"TradeCrafterLuxurySplitter2", "TradeCrafterMagicSplitter2", "TradeCrafterOliveFuelGunpowder", "TradeCrafterOliveWoodGunpowder", "TradeCrafterRubyFuelGunpowder", "TradeCrafterRubyNitro", "TradeCrafterRubyWoodGunpowder", "TradeCrafterSaltMercury", "TradeCrafterSulfurFuelGunpowder", "TradeCrafterSulfurNitro",
		"TradeCrafterSulfurWoodGunpowder", "TradeCrafterWaxFuelGunpowder", "TradeCrafterWaxWoodGunpowder", "TradeCrafterWoodCoin", "TradeCrafterWoodIron", "TradeSmelterBlueSoda", "TradeSmelterChemicalCinnabar", "TradeSmelterChemicalCompost", "TradeSmelterChemicalConveyor", "TradeSmelterChemicalGemPowder",
		"TradeSmelterChemicalLemonade", "TradeSmelterChemicalLye", "TradeSmelterChemicalSalt", "TradeSmelterChemicalSulfur", "TradeSmelterConstructionCompost", "TradeSmelterConstructionConveyor", "TradeSmelterConstructionGemPowder", "TradeSmelterConstructionLemonade", "TradeSmelterConstructionLye", "TradeSmelterConstructionSoda",
		"TradeSmelterConveyorLye", "TradeSmelterFertilizerCompost", "TradeSmelterFertilizerConveyor", "TradeSmelterFertilizerGemPowder", "TradeSmelterFertilizerLemonade", "TradeSmelterFertilizerLye", "TradeSmelterFertilizerSoda", "TradeSmelterFromTransporter", "TradeSmelterFromWorker", "TradeSmelterFuelCompost",
		"TradeSmelterFuelConveyor", "TradeSmelterFuelGemPowder", "TradeSmelterFuelLemonade", "TradeSmelterFuelLye", "TradeSmelterFuelSoda", "TradeSmelterGoldSulfur", "TradeSmelterGroceryCompost", "TradeSmelterGroceryConveyor", "TradeSmelterGroceryGemPowder", "TradeSmelterGroceryLemonade",
		"TradeSmelterGroceryLye", "TradeSmelterGrocerySoda", "TradeSmelterIronOreCinnabar", "TradeSmelterIronOreSalt", "TradeSmelterLuxuryCompost", "TradeSmelterLuxuryConveyor", "TradeSmelterLuxuryGemPowder", "TradeSmelterLuxuryLemonade", "TradeSmelterLuxuryLye", "TradeSmelterLuxurySoda",
		"TradeSmelterMagicCompost", "TradeSmelterMagicConveyor", "TradeSmelterMagicGemPowder", "TradeSmelterMagicLemonade", "TradeSmelterMagicLye", "TradeSmelterMagicSoda", "TradeSmelterNoneMushroom", "TradeSmelterWoodMushroom", "TradeSummoneCreateFam2", "TradeSummoneCreateFam4",
		"TradeSummoneCreateFam6", "TradeSummoneCreateFam8", "TradeSummonerAdamantite", "TradeSummonerAmethystFromBuff", "TradeSummonerAmethystIncrease", "TradeSummonerAmethystRock", "TradeSummonerAmethystTag", "TradeSummonerCobaltFromBuff", "TradeSummonerCobaltIncrease", "TradeSummonerCobaltRock",
		"TradeSummonerCobaltTag", "TradeSummonerJadeFromBuff", "TradeSummonerJadeIncrease", "TradeSummonerJadeRock", "TradeSummonerJadeTag", "TradeSummonerMythril", "TradeSummonerRubyFromBuff", "TradeSummonerRubyIncrease", "TradeSummonerRubyRock", "TradeSummonerRubyTag",
		"Transporter", "Wand", "Wax", "WingPen", "Wood", "Worker", "WorkerIncome", "WorkerSpeedByTime"
	};

	private static readonly uint[] Rgb = new uint[238]
	{
		14899763u, 13073999u, 13075489u, 8869063u, 13060953u, 13049134u, 13081948u, 13082989u, 3568071u, 13056887u,
		2382288u, 15053878u, 13074797u, 6997849u, 13388338u, 51047u, 367303u, 104135u, 13791605u, 13054777u,
		13054777u, 13082733u, 7265251u, 13076333u, 6532575u, 15053878u, 7194546u, 16102695u, 9059575u, 13062216u,
		13082477u, 13058871u, 13055417u, 13082733u, 13148526u, 13257009u, 5487815u, 16703090u, 13075232u, 13082165u,
		7184839u, 14639976u, 16110197u, 14299192u, 5277650u, 7182023u, 15965718u, 13072973u, 13062491u, 7191495u,
		13085538u, 8416711u, 15843666u, 8767341u, 8636269u, 5359432u, 15916893u, 14859601u, 8701805u, 8808391u,
		6532575u, 2869191u, 7194546u, 15053878u, 7185351u, 13069701u, 6457799u, 12879608u, 13061440u, 16110198u,
		11519818u, 825799u, 8809927u, 6589127u, 7192775u, 7265251u, 13076333u, 2803655u, 7192519u, 8934855u,
		2316236u, 13067607u, 5359432u, 1265395u, 13078065u, 7192519u, 9642695u, 13782107u, 8046445u, 15692130u,
		13061188u, 12879608u, 14306396u, 14777493u, 7193031u, 8374117u, 12959687u, 6476281u, 52207u, 13070937u,
		16366865u, 13089389u, 38087u, 51046u, 13791605u, 16446967u, 7193031u, 52207u, 116583u, 7174087u,
		12283592u, 13071469u, 13081425u, 7174087u, 2603975u, 5846471u, 15053878u, 16703090u, 16703090u, 6476281u,
		16703090u, 7185351u, 6476281u, 7185351u, 16703090u, 16703090u, 15053878u, 13061440u, 13076333u, 6476281u,
		116583u, 15053878u, 116583u, 15053878u, 15053878u, 13076333u, 16703090u, 8767341u, 13076333u, 8767341u,
		116583u, 116583u, 7184839u, 7184839u, 7184839u, 13061440u, 7184839u, 7185351u, 7184839u, 13061440u,
		7184839u, 7184839u, 7184839u, 15053878u, 8767341u, 6476281u, 13056887u, 13074797u, 38087u, 5487815u,
		14859601u, 6532575u, 14777493u, 16366865u, 13074797u, 38087u, 5487815u, 14859601u, 6532575u, 6476281u,
		6532575u, 13074797u, 38087u, 5487815u, 14859601u, 6532575u, 6476281u, 7193031u, 7193031u, 13074797u,
		38087u, 5487815u, 14859601u, 6532575u, 6476281u, 16366865u, 13074797u, 38087u, 5487815u, 14859601u,
		6532575u, 6476281u, 13056887u, 14777493u, 13074797u, 38087u, 5487815u, 14859601u, 6532575u, 6476281u,
		13074797u, 38087u, 5487815u, 14859601u, 6532575u, 6476281u, 6457799u, 6457799u, 13081425u, 12283592u,
		7193031u, 13791605u, 14899763u, 8869063u, 8869063u, 8869063u, 8869063u, 2382288u, 2382288u, 2382288u,
		2382288u, 5359432u, 5359432u, 5359432u, 5359432u, 12879608u, 14306396u, 14306396u, 14306396u, 14306396u,
		12283592u, 13937525u, 15648598u, 7176903u, 13731409u, 13081425u, 13354096u, 13545036u
	};

	internal static bool TryGet(string id, out Color color)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		color = Color.white;
		if (string.IsNullOrEmpty(id))
		{
			return false;
		}
		if (_map == null)
		{
			Build();
		}
		return _map.TryGetValue(id, out color);
	}

	private static void Build()
	{
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		_map = new Dictionary<string, Color>(Ids.Length, StringComparer.Ordinal);
		for (int i = 0; i < Ids.Length; i++)
		{
			uint num = Rgb[i];
			_map[Ids[i]] = new Color((float)((num >> 16) & 0xFF) / 255f, (float)((num >> 8) & 0xFF) / 255f, (float)(num & 0xFF) / 255f, 1f);
		}
	}
}
internal sealed class Hotkey
{
	private readonly bool _ctrl;

	private readonly bool _alt;

	private readonly bool _shift;

	private readonly Key _key;

	private readonly string _text;

	private Hotkey(bool ctrl, bool alt, bool shift, Key key, string text)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		_ctrl = ctrl;
		_alt = alt;
		_shift = shift;
		_key = key;
		_text = text;
	}

	public override string ToString()
	{
		return _text;
	}

	internal static Hotkey Parse(string spec)
	{
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		if (string.IsNullOrEmpty(spec))
		{
			return null;
		}
		bool ctrl = false;
		bool alt = false;
		bool shift = false;
		string text = null;
		string[] array = spec.Split('+');
		for (int i = 0; i < array.Length; i++)
		{
			string text2 = array[i].Trim();
			if (text2.Length != 0)
			{
				switch (text2.ToLowerInvariant())
				{
				case "ctrl":
				case "control":
					ctrl = true;
					break;
				case "alt":
					alt = true;
					break;
				case "shift":
					shift = true;
					break;
				default:
					text = text2;
					break;
				}
			}
		}
		if (text == null)
		{
			return null;
		}
		try
		{
			Key key = (Key)Enum.Parse(typeof(Key), text, ignoreCase: true);
			return new Hotkey(ctrl, alt, shift, key, spec.Trim());
		}
		catch (Exception)
		{
			return null;
		}
	}

	internal bool WasPressedThisFrame(Keyboard kb)
	{
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Invalid comparison between Unknown and I4
		if (kb == null)
		{
			return false;
		}
		bool flag = ((ButtonControl)kb.leftCtrlKey).isPressed || ((ButtonControl)kb.rightCtrlKey).isPressed;
		bool flag2 = ((ButtonControl)kb.leftAltKey).isPressed || ((ButtonControl)kb.rightAltKey).isPressed;
		bool flag3 = ((ButtonControl)kb.leftShiftKey).isPressed || ((ButtonControl)kb.rightShiftKey).isPressed;
		if (flag != _ctrl || flag2 != _alt || flag3 != _shift)
		{
			return false;
		}
		if (((ButtonControl)kb[_key]).wasPressedThisFrame)
		{
			return true;
		}
		if ((int)_key == 2 && ((ButtonControl)kb[(Key)77]).wasPressedThisFrame)
		{
			return true;
		}
		return false;
	}
}
[BepInPlugin("kiyonakanata.lwfeconomygraph", "LWF Economy Graph", "1.0.1")]
public sealed class EconomyGraphPlugin : BaseUnityPlugin
{
	private sealed class ImguiPainter : IChartPainter
	{
		private readonly EconomyGraphPlugin _owner;

		private int _baseSize;

		public float FontSize => _owner._text.fontSize;

		public float LineHeight => _owner._text.fontSize + 6;

		internal ImguiPainter(EconomyGraphPlugin owner)
		{
			_owner = owner;
		}

		internal void Begin(int baseSize)
		{
			_baseSize = baseSize;
			SetScale(1f);
		}

		public void SetScale(float scale)
		{
			_owner._text.fontSize = Mathf.RoundToInt((float)_baseSize * scale);
			_owner._title.fontSize = _owner._text.fontSize + 3;
		}

		public float Measure(string text)
		{
			return _owner.W(text, _owner._text);
		}

		public float MeasureTitle(string text)
		{
			return _owner.W(text, _owner._title);
		}

		public void Fill(Rect r, Color color)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			EconomyGraphPlugin.Fill(r, color);
		}

		public void Text(float x, float y, string text, Color color)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			_owner.DrawText(x, y, text, _owner._text, color);
		}

		public void Title(float x, float y, string text, Color color)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			_owner.DrawText(x, y, text, _owner._title, color);