Example #1
0
        /// <summary>
        /// Moves chart around depending on
        /// </summary>
        /// <param name="e"></param>
        private void MoveX(MouseEventArgs e)
        {
            if (MouseVector.Start.IsInvalid)
            {
                return;
            }

            MouseVector.End = (Point2D)e.Location;

            if (MouseVector.IsInvalid ||
                MouseVector.Min < 0 ||
                MouseVector.MaxX >= ChartMain.Width ||
                MouseVector.MaxY >= ChartMain.Height ||
                MouseVector.Width < 1
                )
            {
                return;
            }


            double position = ChartMain.ChartAreas[0].AxisX.ScaleView.Position;
            double size     = ChartMain.ChartAreas[0].AxisX.ScaleView.Size;

            double x1   = AxisX.PixelPositionToValue(MouseVector.Start.X);
            double x2   = AxisX.PixelPositionToValue(MouseVector.End.X);
            double move = x2 - x1;

            double pXStart = position - move;
            double pXEnd   = position + size;


            if (MinX == null || MaxX == null)
            {
                return;
            }

            if ((pXStart < MinX.XValue && move > 0) || (pXEnd > MaxX.XValue && move < 0))
            {
                MouseVector.Reset();
                return;
            }


            //ScaleX.Zoom(pXStart, pXEnd);

            ChartMain.ChartAreas[0].AxisX.ScaleView.Position = pXStart;
            //ChartMain.ChartAreas[0].AxisX.ScaleView.Size = pXEnd - pXStart;



            this.RescaleY();
            MouseVector.Start = MouseVector.End;
        }
Example #2
0
        void ChartMain_MouseWheel(object sender, MouseEventArgs e)
        {
            Area.RecalculateAxesScale();
            double position = ChartMain.ChartAreas[0].AxisX.ScaleView.Position;
            double xMin     = ScaleX.ViewMinimum;
            double xMax     = ScaleX.ViewMaximum;
            double size     = xMax - xMin;// ChartMain.ChartAreas[0].AxisX.ScaleView.Size;

            //if (e.Location.X < 0 || e.Location.Y < 0)// || e.Location.X > 100 || e.Location.Y > 100)
            //   return;

            double cursor = 0;

            try
            {
                cursor = AxisX.PixelPositionToValue(e.Location.X);
            }
            catch { return; }

            double change = size / 3;

            double pXStart = double.NaN;
            double pXEnd   = double.NaN;

            if (e.Delta < 0 && RescaledPointsCount < ChartMain.Series[0].Points.Count)
            {
                pXStart = AxisX.PixelPositionToValue(e.Location.X) - change * 3;
                pXEnd   = AxisX.PixelPositionToValue(e.Location.X) + change * 3;

                ScaleX.Zoom(pXStart, pXEnd);
            }
            else if (e.Delta > 0 && RescaledPointsCount > 30)
            {
                pXStart = AxisX.PixelPositionToValue(e.Location.X) - change;
                pXEnd   = AxisX.PixelPositionToValue(e.Location.X) + change;
            }

            if (!Doubles.IsNaN(pXEnd, pXStart))
            {
                if (pXStart < MinX.XValue)
                {
                    pXStart = MinX.XValue;
                }
                if (pXEnd > MaxX.XValue)
                {
                    pXEnd = MaxX.XValue;
                }


                ScaleX.Zoom(pXStart, pXEnd);
                this.RescaleY();
            }
        }
Example #3
0
        private void OnChartMouseUp(object sender, MouseEventArgs e)
        {
            if (SelectButton == MouseButtons.None)
            {
                return;
            }

            HitTestResult htr = chart.HitTest(e.X, e.Y);

            if (htr.ChartElementType == ChartElementType.Nothing)
            {
                return;
            }

            var mousedx = e.X - StartSelect.X;
            var mousedy = e.Y - StartSelect.Y;
            var x       = AxisX.PixelPositionToValue(StartSelect.X);
            var y       = AxisY.PixelPositionToValue(e.Y);
            var dx      = AxisX.PixelPositionToValue(e.X) - x;
            var dy      = AxisY.PixelPositionToValue(StartSelect.Y) - y;

            if (SelectButton == MouseButtons.Left)
            {
                if (mousedx > 0 && mousedy > 0)
                {
                    AxisX.ScaleView.Zoom(x, x + dx);
                    AxisY.ScaleView.Zoom(y, y + dy);
                }
                else if (mousedx < 0 && mousedy < 0)
                {
                    var szx = AxisX.ScaleView.ViewMaximum - AxisX.ScaleView.ViewMinimum;
                    var szy = AxisY.ScaleView.ViewMaximum - AxisY.ScaleView.ViewMinimum;
                    dx = szx * szx / -dx;
                    dy = szy * szy / -dy;
                    x  = AxisX.ScaleView.Position + szx / 2 - dx / 2;
                    y  = AxisY.ScaleView.Position + szy / 2 - dy / 2;
                    AxisX.ScaleView.Zoom(x, x + dx);
                    AxisY.ScaleView.Zoom(y, y + dy);
                }
                else
                {
                    AxisX.ScaleView.ZoomReset();
                    AxisY.ScaleView.ZoomReset();
                }
            }
            if (SelectButton == MouseButtons.Right)
            {
                AxisX.ScaleView.Scroll(AxisX.ScaleView.Position - dx);
                AxisY.ScaleView.Scroll(AxisY.ScaleView.Position + dy);
            }
            SelectButton = MouseButtons.None;
        }
Example #4
0
 private void ChartOnMouseDown(object sender, MouseEventArgs e)
 {
     if (e.Button != MouseButtons.Right)
     {
         return;
     }
     try
     {
         StartMousePosition = new PointD(
             AxisX.PixelPositionToValue(e.X),
             AxisY.PixelPositionToValue(e.Y));
         IsChartScroll = true;
     }
     catch (ArgumentException)
     {
         IsChartScroll = false;
     }
 }
Example #5
0
 private void ChartOnMouseMove(object sender, MouseEventArgs e)
 {
     if (IsChartScroll && e.Button == MouseButtons.Right)
     {
         try
         {
             var x = AxisX.ScaleView.Position + StartMousePosition.X - AxisX.PixelPositionToValue(e.X);
             var y = AxisY.ScaleView.Position + StartMousePosition.Y - AxisY.PixelPositionToValue(e.Y);
             x = Math.Round(x, DigitsX); //0..15
             y = Math.Round(y, DigitsY);
             AxisX.ScaleView.Scroll(x);
             AxisY.ScaleView.Scroll(y);
         }
         catch (ArgumentException)
         {
         }
     }
     else
     {
         IsChartScroll = false;
     }
 }
Example #6
0
        public override void ChangeDrawArea()
        {
            if (autoYToolStripMenuItem.Checked)
            {
                double ymax = -1;
                double xmin = AxisX.PixelPositionToValue(Math.Min(SelArea.X0, SelArea.X1));
                double xmax = AxisX.PixelPositionToValue(Math.Max(SelArea.X0, SelArea.X1));
                foreach (var s in chart.Series)
                {
                    for (int i = 0; i < s.Points.Count; i++)
                    {
                        //範囲内での絶対値最大の値を探す
                        if (ymax < 0)
                        {
                            ymax = Math.Abs(s.Points[i].YValues[0]);
                        }
                        else
                        {
                            ymax = Math.Max(ymax, s.Points.Max(
                                                t => (t.XValue >= xmin && t.XValue <= xmax) ? Math.Abs(t.YValues[0]) : 0
                                                ));
                        }
                    }
                }
                if (ymax < 0)
                {
                    return;
                }


                SelArea.SetChartDrawAreaLimitedY(AxisX, AxisY, ymax);
            }
            else
            {
                base.ChangeDrawArea();
            }
        }
Example #7
0
        void ChartMain_MouseWheel(object sender, MouseEventArgs e)
        {
            if (ChartMain.Series.IsNullOrEmpty())
            {
                return;
            }

            ZoomPointNow = (Point2D)MousePosition;


            Area.RecalculateAxesScale();
            double position = ChartMain.ChartAreas[0].AxisX.ScaleView.Position;
            double xMin     = ScaleX.ViewMinimum;
            double xMax     = ScaleX.ViewMaximum;
            double size     = xMax - xMin;// ChartMain.ChartAreas[0].AxisX.ScaleView.Size;

            //if (e.Location.X < 0 || e.Location.Y < 0)// || e.Location.X > 100 || e.Location.Y > 100)
            //   return;

            double cursor = 0;

            try
            {
                cursor = AxisX.PixelPositionToValue(e.Location.X);
            }
            catch { return; }

            double change = size / 3;

            double pXStart = double.NaN;
            double pXEnd   = double.NaN;

            int    locationX     = e.Location.X;
            double positionValue = AxisX.PixelPositionToValue(locationX);

            //If mouse is not moved zoom toward origin cursor
            if (ZoomPointOrigin == ZoomPointNow)
            {
                positionValue = CursorPosition.X;
            }



            if (e.Delta < 0 && RescaledPointsCount < ChartMain.Series[0].Points.Count)
            {
                pXStart = positionValue - change * 3;
                pXEnd   = positionValue + change * 3;

                ScaleX.Zoom(pXStart, pXEnd);
            }
            else if (e.Delta > 0 && RescaledPointsCount > 30)
            {
                pXStart = positionValue - change;
                pXEnd   = positionValue + change;
            }

            if (!Doubles.IsNaN(pXEnd, pXStart))
            {
                if (pXStart < MinX.XValue)
                {
                    pXStart = MinX.XValue;
                }
                if (pXEnd > MaxX.XValue)
                {
                    pXEnd = MaxX.XValue;
                }


                ScaleX.Zoom(pXStart, pXEnd);
                this.RescaleY();
            }

            ZoomPointOrigin = (Point2D)MousePosition;
        }