public void RedrawGraphs() { if (!Graphs.Any()) { return; } MinDate = Graphs.Min(g => g.Plots.Min(p => p.DataSeries.Elements.ToArray().First().Timestamp)); MaxDate = Graphs.Max(g => g.Plots.Max(p => p.DataSeries.Elements.ToArray().Last().Timestamp)); if (Period == PeriodType.OneDay) { TotalSlots = CalcTotalSlots(out _Timestamps); } else { throw new Exception("didn't expect " + Period); } SlotPxWidth = Math.Max(MinSlotPxWidth, AvailableWidth / TotalSlots); SlotsInView = (int)Math.Floor(AvailableWidth / SlotPxWidth); if (SlotsInView == 0) { return; } foreach (var g in Graphs) { g.Redraw(); } Parent.TimeAxisGraph.Redraw(); Update(); }
/// <summary> /// Generates a new color of the same tone as the basecolor of the given type /// </summary> public System.Windows.Media.Color NewColor(IGraphType type) { System.Drawing.Color newColor; // Get basecolor of the type var baseColorWpf = typeColors[Types.IndexOf(Types.Single(t => t.Model.GetType() == type.GetType()))]; var baseColor = System.Drawing.Color.FromArgb(baseColorWpf.R, baseColorWpf.G, baseColorWpf.B); var h = baseColor.GetHue(); var random = new Random(); do { // Generate new color by using the hue of the basecolor and getting a random brightness and saturation. newColor = HslHelper.HslToRgb(h, random.NextDouble(), random.NextDouble()); } while (!IsInInterval(0.5, newColor.GetSaturation(), 0.3) || !IsInInterval(0.5, newColor.GetBrightness(), 0.3) || Graphs.Any(g => SimilarColor(Color.FromArgb(g.LineColor.R, g.LineColor.G, g.LineColor.B), newColor))); return(System.Windows.Media.Color.FromRgb(newColor.R, newColor.G, newColor.B)); }