Пример #1
0
        protected Range GetRangeFromChildren(Axis2D axis)
        {
            Range range = new Range(0, 0);
            Plot2DItem child;
            bool rangeUpdated = false;
            for (int i = 0; i < plotItems.Count; ++i)
            {
                child = plotItems[i];
                
                if ((child.XAxis != axis) && (child.YAxis != axis)) 
                    continue;
                
                Rect bounds = child.PaddedBounds;

                if (bounds == Rect.Empty)
                    continue;

                if (rangeUpdated == false)
                {
                    range = (axis is XAxis) ? new Range(bounds.Left, bounds.Right) : new Range(bounds.Top, bounds.Bottom);
                    rangeUpdated = true;
                }
                else range = range.Union((axis is XAxis) ? new Range(bounds.Left, bounds.Right) : new Range(bounds.Top, bounds.Bottom));
            }
            return range;
        }
Пример #2
0
        private void IntervalFromRange(Range range, double minInterval, out DecomposedNumber interval, out DecomposedNumber firstTick) 
        {
            // Exponent of the least significant figure of the interval.
            int intervalExponent = (int)Math.Floor(Math.Log10(minInterval));
            int intervalIntCoefficient = (int)Math.Floor(minInterval / Math.Pow(10, intervalExponent) + fractionalTolerance);

            // LSF must be either 1, 2, 5 or 10, whichever is directly above the current value.      
            if (intervalIntCoefficient > 5) { intervalIntCoefficient = 1; intervalExponent++; }
            else if (intervalIntCoefficient > 2) { intervalIntCoefficient = 5; }
            else if (intervalIntCoefficient > 1) { intervalIntCoefficient = 2; }
            else { intervalIntCoefficient = 1; }
            //
            interval = new DecomposedNumber(intervalIntCoefficient * Math.Pow(10, intervalExponent), (double)intervalIntCoefficient, intervalExponent);
            //
            // Now get the first tick
            double firstTickValue;
            double absoluteTolerance = fractionalTolerance * interval.Value;
            if ((range.Min - absoluteTolerance) < 0)
            {
                firstTickValue = (range.Min - absoluteTolerance) - ((range.Min - absoluteTolerance) % interval.Value);
            }
            else
            {
                firstTickValue = interval.Value - ((range.Min - absoluteTolerance) % interval.Value) + (range.Min - absoluteTolerance);
            }
            int firstTickExp = (firstTickValue == 0) ? interval.Exponent : (int)Math.Floor(Math.Log10(Math.Abs(firstTickValue)));
            firstTick = new DecomposedNumber(firstTickValue, firstTickValue / Math.Pow(10, firstTickExp), firstTickExp);
        }
Пример #3
0
 public Range Union(Range otherRange)
 {
     return new Range(Math.Min(this.Min, otherRange.Min), Math.Max(this.Max, otherRange.Max));
 }
Пример #4
0
        protected void LeftClickStart(object sender, MouseButtonEventArgs e)
        {
            foreach (Plot2DItem item in plotItems)
            {
                if (item is Plot2DCurve && !Double.IsNaN((item as Plot2DCurve).AnnotationPosition.X))
                {
                    (item as Plot2DCurve).AnnotationPosition = new Point(Double.NaN, Double.NaN);
                }
            }

            bool ctrlOrShift = Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl) ||
                               Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.LeftShift);

            if (ctrlOrShift)
            {
                canvas_RightClickStart(sender, e);
                return;
            }

            // either whole canvas or single axis
            bool isSingleAxis = (sender is Axis2D);

            if (e.ClickCount > 1)
            {
                dragging    = false;
                this.Cursor = Cursors.Arrow;
                List <Axis2D> allAxes;
                if (isSingleAxis)
                {
                    allAxes = new List <Axis2D> {
                        sender as Axis2D
                    }
                }
                ;
                else
                {
                    allAxes = Axes.XAxes.Concat(Axes.YAxes).ToList();
                }
                foreach (Axis2D axis in allAxes)
                {
                    Range axisRange = GetRangeFromChildren(axis);
                    if (axisRange.Length != 0)
                    {
                        axis.SetValue(Axis2D.RangeProperty, axisRange);
                    }
                }
            }
            else
            {
                if (isSingleAxis)
                {
                    axesBeingDragged = new List <Axis2D> {
                        sender as Axis2D
                    }
                }
                ;
                else
                {
                    axesBeingDragged = Axes.XAxes.Concat(Axes.YAxes).ToList();
                }
                StartDrag(e);
            }
            Canvas.CaptureMouse();
        }