Beispiel #1
0
        /// <summary>
        /// This is the rendering loop, called periodically to update the graph.
        /// </summary>
        private void timer_Tick(object sender, EventArgs e)
        {
            var info = GetInfo(Key);

            if (info == null)
            {
                return;
            }

            // Find new maximum values on x and y axes.
            float maxX, maxY;

            Rescale(info, out maxX, out maxY);
            if (maxY == 0.0)
            {
                return;
            }

            // Start scaling animation if necessary.
            _xAxisAnimation.SetTarget(info.GraphPane.XAxis.Scale.Max, maxX, STEPS_FOR_TIME_AXIS_ANIMATION);
            _yAxisAnimation.SetTarget(info.GraphPane.YAxis.Scale.Max, maxY * 1.1, STEPS_FOR_INTENSITY_ANIMATION);

            // Tell Zedgraph if axes are being changed.
            double nextTime      = info.CurrentTime ?? 0;
            double millisElapsed = (DateTime.UtcNow - _lastRender).TotalMilliseconds;

            if (_xAxisAnimation.IsActive || _yAxisAnimation.IsActive)
            {
                info.GraphPane.XAxis.Scale.Max = _xAxisAnimation.Step();
                info.GraphPane.YAxis.Scale.Max = _yAxisAnimation.Step();
                info.GraphPane.AxisChange();
                StartRender();
            }
            else if (millisElapsed < MIN_INCREMENTAL_RENDER)
            {
                return;
            }
            else
            {
                double minTime = Math.Min(_renderMin, _lastTime);
                double maxTime = Math.Max(_renderMax, nextTime);

                // Limit the number of steps for advancing progress
                if (millisElapsed < MAX_INCREMENTAL_RENDER && maxTime - minTime <= info.GraphPane.XAxis.Scale.Max / INCREMENTS_PER_PASS)
                {
                    return;
                }

                IncrementalRender(info, minTime, maxTime);
                _lastRender = DateTime.UtcNow;
            }

            _lastTime  = nextTime;
            _renderMin = double.MaxValue;
            _renderMax = double.MinValue;
        }