Exemplo n.º 1
0
        private void TrimToLiveScroll()
        {
            double scaleX = this.liveScrollingXScale;

            this.visibleEndIndex   = series.Values.Count;
            this.visibleStartIndex = this.visibleEndIndex;
            var width = this.ActualWidth;

            // find the data value that starts the chart on the left side of the scrolling window
            // and make this the visibleStartIndex from which smooth scrolling will resume.
            if (series.Values.Count > 0)
            {
                // walk back until the scaled values fill one screen width.
                this.visibleStartIndex = this.visibleEndIndex - 1;
                var    dv   = series.Values[this.visibleStartIndex];
                double endX = dv.X * scaleX;

                while (--this.visibleStartIndex > 0)
                {
                    dv = series.Values[this.visibleStartIndex];
                    double startX = dv.X * scaleX;

                    if (endX - startX > width)
                    {
                        break;
                    }
                }
            }

            this.scaleSelf = null;
            this.dirty     = true;
        }
Exemplo n.º 2
0
 public void Combine(ChartScaleInfo info)
 {
     minX = Math.Min(minX, info.minX);
     maxX = Math.Max(maxX, info.maxX);
     minY = Math.Min(minY, info.minY);
     maxY = Math.Max(maxY, info.maxY);
 }
Exemplo n.º 3
0
        internal bool ComputeScale(SimpleLineChart trigger)
        {
            bool           changed  = false;
            ChartScaleInfo combined = null;

            int index = this.scaleIndex;

            // make sure they are all up to date.
            foreach (var ptr in FindCharts())
            {
                ChartScaleInfo info = ptr.ComputeScaleSelf(index);
                if (combined == null)
                {
                    combined = info;
                }
                else
                {
                    combined.Combine(info);
                }
            }

            foreach (var ptr in FindCharts())
            {
                if (ptr.ApplyScale(combined))
                {
                    if (ptr != trigger)
                    {
                        ptr.DelayedUpdate();
                    }
                    changed = true;
                }
            }
            return(changed);
        }
Exemplo n.º 4
0
        public ChartScaleInfo ComputeScaleSelf()
        {
            int startIndex = this.visibleStartIndex;
            int endIndex   = this.visibleEndIndex;

            if (!dirty && scaleSelf != null && !this.liveScrolling)
            {
                return(scaleSelf);
            }

            if (scaleSelf != null && this.liveScrolling)
            {
                // try and do incremental update of the scale for added efficiency!
                startIndex = this.smoothScrollScaleIndex;
            }
            else
            {
                scaleSelf = new ChartScaleInfo();
                this.smoothScrollScaleIndex = 0;
            }
            if (series == null)
            {
                return(scaleSelf);
            }

            int len = series.Values.Count;

            if (startIndex < 0)
            {
                startIndex = 0;
            }
            if (endIndex < 0 || endIndex > len)
            {
                endIndex = len;
            }

            if (this.ActualHeight == 0)
            {
                return(scaleSelf);
            }

            for (int i = startIndex; i < endIndex; i++)
            {
                DataValue d = series.Values[i];
                double    x = d.X;
                double    y = d.Y;
                scaleSelf.Add(x, y);
            }
            this.smoothScrollScaleIndex = endIndex;

            return(scaleSelf);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Returns true if the scale just changed.
        /// </summary>
        bool ComputeScale()
        {
            bool changed = false;

            if (this.Group != null && !scaleIndependently)
            {
                changed = this.Group.ComputeScale(this);
            }
            else
            {
                ChartScaleInfo info = ComputeScaleSelf(this.scaleIndex);
                changed = ApplyScale(info);
            }
            return(changed);
        }
Exemplo n.º 6
0
        public ChartScaleInfo ComputeScaleSelf(int index)
        {
            if (scaleSelf == null)
            {
                scaleSelf = new ChartScaleInfo();
            }

            if (!dirty)
            {
                return(scaleSelf);
            }

            if (index > 0)
            {
                // this is an incremental update then so we pick up where we left off.
            }
            else
            {
                // start over
                scaleSelf = new ChartScaleInfo();
            }

            if (series == null)
            {
                return(scaleSelf);
            }

            int len = series.Values.Count;

            if (index < 0)
            {
                index = 0;
            }

            for (int i = index; i < len; i++)
            {
                DataValue d = series.Values[i];
                double    x = d.X;
                double    y = d.Y;
                scaleSelf.Add(x, y);
            }

            scaleIndex = len;

            return(scaleSelf);
        }
        /// <summary>
        /// Returns true if the scale just changed.
        /// </summary>
        bool ComputeScale()
        {
            bool changed = false;

            if (this.Next != null)
            {
                ChartScaleInfo combined = null;

                int index = this.scaleIndex;

                // make sure they are all up to date.
                foreach (var ptr in GroupItems)
                {
                    ChartScaleInfo info = ptr.ComputeScaleSelf(index);
                    if (combined == null)
                    {
                        combined = info;
                    }
                    else
                    {
                        combined.Combine(info);
                    }
                }

                //Debug.WriteLine("Combined scale: minx={0}, maxx={1}, miny={2}, maxy={3}", combined.minX, combined.maxX, combined.minY, combined.maxY);

                foreach (var ptr in GroupItems)
                {
                    if (ptr.ApplyScale(combined))
                    {
                        if (ptr != this)
                        {
                            ptr.DelayedUpdate();
                        }
                        changed = true;
                    }
                }
            }
            else
            {
                ChartScaleInfo info = ComputeScaleSelf(this.scaleIndex);
                changed = ApplyScale(info);
            }
            return(changed);
        }
Exemplo n.º 8
0
        internal bool ApplyScale(ChartScaleInfo info)
        {
            if (info == null)
            {
                return(false);
            }

            double actualHeight = this.ActualHeight - 1;
            double actualWidth  = this.ActualWidth;

            bool changed = false;

            this.minX = info.minX;
            this.maxX = info.maxX;
            this.minY = info.minY;
            this.maxY = info.maxY;

            double yRange = maxY - minY;

            if (yRange == 0)
            {
                yRange = 1;
            }
            double newyScale = actualHeight / yRange;

            if (newyScale == 0)
            {
                newyScale = 1;
            }
            if (newyScale != yScale)
            {
                yScale  = newyScale;
                changed = true;
            }

            // overrides for automatic X-Scaling.
            if (fixedMaximumX.HasValue)
            {
                this.maxX = fixedMaximumX.Value;
            }

            if (fixedMinimumX.HasValue)
            {
                this.minX = fixedMinimumX.Value;
            }

            double newxScale = LiveScrollingXScale;

            if (!LiveScrolling)
            {
                double xRange = maxX - minX;
                if (xRange == 0)
                {
                    xRange = 1;
                }
                newxScale = actualWidth / xRange;
                if (newxScale == 0)
                {
                    newxScale = 1;
                }
            }

            if (newxScale != xScale)
            {
                xScale  = newxScale;
                changed = true;
            }

            if (changed || scaleTransform == null)
            {
                Matrix m = new Matrix();
                m.Scale(xScale, yScale);
                m.OffsetX      = -minX * xScale;
                m.OffsetY      = -minY * yScale;
                scaleTransform = new MatrixTransform(m);
            }

            return(changed);
        }