aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/SideChains/RealTimeGraphX/Renderers/GraphScrollingRenderer.cs
blob: 3d127c4480e30ed7bc58ad461a42e42b607f4be5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold }
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RealTimeGraphX.Renderers
{
    /// <summary>
    /// Represents a scrolling style graph renderer.
    /// </summary>
    /// <typeparam name="TDataSeries">The type of the graph data series.</typeparam>
    /// <typeparam name="XDataPoint">The type of the x-axis data point.</typeparam>
    /// <typeparam name="YDataPoint">The type of the y-axis data point.</typeparam>
    /// <seealso cref="RealTimeGraphX.GraphRendererBase{XDataPoint, YDataPoint}" />
    public class GraphScrollingRenderer<TDataSeries, XDataPoint, YDataPoint> : GraphRendererBase<TDataSeries, XDataPoint, YDataPoint> where XDataPoint : GraphDataPointBase where YDataPoint : GraphDataPointBase where TDataSeries : IGraphDataSeries
    {
        /// <summary>
        /// Returns an array of absolute graph data points to render.
        /// This method is called per data series.
        /// </summary>
        /// <param name="seriesCollection">A collection of all data series that is currently in the rendering pass.</param>
        /// <param name="series">The current data series to render.</param>
        /// <param name="toRender">Pending data series object to render.</param>
        /// <returns></returns>
        protected override List<GraphPoint> OnRender(IEnumerable<PendingSeries> seriesCollection, TDataSeries series, PendingSeries toRender)
        {
            List<GraphPoint> points = new List<GraphPoint>();

            if (toRender.XX.Count > 0 && toRender.YY.Count > 0)
            {
                XDataPoint min_x = toRender.XX.First();
                XDataPoint max_x = toRender.XX.Last();

                YDataPoint min_y = Input.Range.MinimumY;
                YDataPoint max_y = Input.Range.MaximumY;

                if (Input.Range.AutoY)
                {
                    min_y = _current_min_y;
                    max_y = _current_max_y;
                }

                OnEffectiveRangeXChanged(min_x, max_x);
                OnEffectiveRangeYChanged(min_y, max_y);

                var dxList = toRender.XX.Select(x => x.ComputeRelativePosition(min_x, max_x)).ToList();
                var dyList = toRender.YY.Select(x => x.ComputeRelativePosition(min_y, max_y)).ToList();

                if (max_x - min_x > Input.Range.MaximumX)
                {
                    var offset = ((max_x - min_x) - Input.Range.MaximumX) + min_x;

                    for (int i = 0; i < toRender.XX.Count; i++)
                    {
                        if (toRender.XX[i] < offset)
                        {
                            toRender.XX.RemoveAt(i);
                            toRender.YY.RemoveAt(i);
                            i--;
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                for (int i = 0; i < dxList.Count; i++)
                {
                    float image_x = ConvertXValueToRendererValue(dxList[i]);
                    float image_y = (float)Math.Min(ConvertYValueToRendererValue(dyList[i]), Output.SurfaceHeight - 2);

                    GraphPoint point = new GraphPoint(image_x, image_y);
                    points.Add(point);
                }
            }

            return points;
        }
    }
}