public void PlotLine(Point point)
            {
                if (double.IsNaN(point.Y) || double.IsInfinity(point.Y))
                {
                    this.previousPointIsValid = false;
                    return;
                }

                // Insert new point in sorted order based on its x-axis (time) value. Most of the time we
                // will be appending in increasing time order, so start at the end and walk backwards.
                int i = this.lineFigure.Segments.Count - 1;

                while (i >= 0 && ((LineSegment)this.lineFigure.Segments[i]).Point.X > point.X)
                {
                    --i;
                }

                InterpolationStyle interpolationStyle = this.parent.VisualizationObject.InterpolationStyle;

                // If we're doing step interpolation and there are existing points in the segment, then insert a horizontal joiner
                if (i >= 0 && interpolationStyle == InterpolationStyle.Step)
                {
                    this.lineFigure.Segments.Insert(i + 1, new LineSegment(new Point(point.X, ((LineSegment)this.lineFigure.Segments[i]).Point.Y), this.previousPointIsValid));
                    this.previousPointIsValid = true;
                    i++;
                }

                // Insert new point immediately after previous.
                this.lineFigure.Segments.Insert(i + 1, new LineSegment(point, this.previousPointIsValid && interpolationStyle != InterpolationStyle.None));
                this.previousPointIsValid = true;
                this.PointCount++;
            }
Example #2
0
        /// <inheritdoc />
        protected override void InitNew()
        {
            base.InitNew();
            var color = colorChoice[nextColorChoice % colorChoice.Length];

            this.Configuration.LineColor          = color;
            this.Configuration.LineWidth          = 1;
            this.Configuration.InterpolationStyle = InterpolationStyle.Direct;
            this.Configuration.MarkerColor        = color;
            this.Configuration.MarkerSize         = 4;
            this.Configuration.MarkerStyle        = MarkerStyle.None;
            this.Configuration.RangeColor         = color;
            this.Configuration.RangeWidth         = 1;
            this.Configuration.SetYRange(0, 0);
            this.Configuration.YAxisComputeMode = AxisComputeMode.Auto;
            Interlocked.Increment(ref nextColorChoice);
        }
Example #3
0
        /// <summary>
        /// Gets the index id corresponding to a specified time for
        /// a collection of indices that are ordered by time.
        /// </summary>
        /// <param name="currentTime">The time to find the index for.</param>
        /// <param name="count">The number of items in the index collection.</param>
        /// <param name="timeAtIndex">A function that returns the time for a given index id.</param>
        /// <param name="interpolationStyle">The type of interpolation (Direct or Step) to use when resolving indices that don't exactly lie at the specified time.</param>
        /// <returns>The index id closest to the specified time, using the specified interpolation style.</returns>
        public static int GetIndexForTime(DateTime currentTime, int count, Func <int, DateTime> timeAtIndex, InterpolationStyle interpolationStyle)
        {
            // Perform a binary search
            SearchResult result = SearchIndex(currentTime, count, timeAtIndex);

            if (result.ExactMatchFound)
            {
                return(result.ExactIndex);
            }

            // If no exact match, lo and hi indicate ticks that
            // are right before and right after the time we're looking for.
            // If we're using Step interpolation, then we should return
            // lo, otherwise we should return whichever value is closest
            if (interpolationStyle == InterpolationStyle.Step)
            {
                return(result.LowIndex);
            }

            // If the're only one point in the index, then return its index
            if (count == 1)
            {
                return(0);
            }

            // Return the index of whichever point is closest to the current time
            if ((timeAtIndex(result.HighIndex) - currentTime) < (currentTime - timeAtIndex(result.LowIndex)))
            {
                return(result.HighIndex);
            }
            else
            {
                return(result.LowIndex);
            }
        }