public void Update(float?val, SimpleGraph other = null, float?otherVal = null)
        {
            if (!val.HasValue)
            {
                return;
            }

            _history.RemoveAt(0);
            _history.Add(val.Value);

            if (AutoScale(other, otherVal))
            {
                UpdateAxis();
                UpdateGridLines();
            }

            _figure.Segments.Clear();

            UpdatePath();
        }
        private bool AutoScale(SimpleGraph other, float?otherVal)
        {
            if (Primary != null)
            {
                Max = Primary.Max;
                Min = Primary.Min;
                return(false);
            }

            if (NoScale)
            {
                return(false);
            }

            var historyWithValues = _history.Where(h => h >= 0).ToList();

            if (historyWithValues.Count == 0)
            {
                return(false);
            }

            var changed = false;

            var histMax = _history.Where(h => h >= 0).Max();

            if (other != null)
            {
                var otherHistMax = other._history.Where(h => h >= 0).DefaultIfEmpty(0).Max();
                if (otherHistMax > histMax)
                {
                    histMax = otherHistMax;
                }
                if (otherVal.HasValue && otherVal.Value > histMax)
                {
                    histMax = otherVal.Value;
                }
            }
            var histMin = _history.Where(h => h >= 0).Min();

            while (histMax > Max)
            {
                changed = true;
                Max    += 10;
            }

            while (histMax < Max - 10 && Max > _defaultMax)
            {
                changed = true;
                Max    -= 10;
                if (Max < _defaultMax)
                {
                    Max = _defaultMax;
                    break;
                }
            }

            while (histMin < Min)
            {
                changed = true;
                Min    -= 10;
            }

            while (histMin > Min + 10 && Min < _defaultMin)
            {
                changed = true;
                Min    += 10;
                if (Min > _defaultMin)
                {
                    Min = _defaultMin;
                    break;
                }
            }

            return(changed);
        }