Пример #1
0
        private void GetAreaPosition(ChartArea area)
        {
            if (_host == null ||
                _host.Child == null)
            {
                return;
            }

            ChartAreaPosition position = _areaPositions.Find(pos => pos.Area.Name == area.Name);

            if (position == null)
            {
                position = new ChartAreaPosition();
                _areaPositions.Add(position);
                position.Area = area;
            }

            position.LeftPoint = _host.Child.Left + _host.Child.Width * (area.InnerPlotPosition.X / 100);

            position.RightPoint = position.LeftPoint + _host.Child.Width * (area.InnerPlotPosition.Width / 100);

            position.UpPoint = _chart.Height - _chart.Height * ((100 - area.Position.Y) / 100);

            position.DownPoint = position.UpPoint + _host.Child.Height * (area.Position.Height / 100);
        }
Пример #2
0
        private void _chart_MouseMove2(object sender, MouseEventArgs e)
        {
            if (_chart.Cursor == Cursors.SizeAll)
            {
                return;
            }
            if (_chart.ChartAreas.Count < 1)
            {
                return;
            }

            if (e.Button == MouseButtons.Left &&
                _chart.Cursor == Cursors.Arrow)
            {
                return;
            }

            if (_volume.VolumeClusters == null ||
                _volume.VolumeClusters.Count < 3)
            {
                return;
            }

            if (_areaPositions.Count != _chart.ChartAreas.Count ||
                _areaPositions.Find(posi => posi.RightPoint == 0) != null)
            {
                _areaPositions = new List <ChartAreaPosition>();
                ReloadChartAreasSize();
            }

            if (_chart.Cursor == Cursors.Hand ||
                _chart.Cursor == Cursors.SizeNS ||
                _areaPositions == null)
            {
                return;
            }

            ChartAreaPosition myPosition = null;

            MouseEventArgs mouse = (MouseEventArgs)e;

            ChartAreaPosition pos = _areaPositions[0];

            if ((pos.LeftPoint < e.X &&
                 pos.RightPoint > e.X &&
                 pos.DownPoint - 30 < e.Y &&
                 pos.DownPoint - 10 > e.Y)
                ||
                (mouse.Button == MouseButtons.Left && _chart.Cursor == Cursors.SizeWE && pos.LeftPoint < e.X &&
                 pos.RightPoint > e.X &&
                 pos.DownPoint - 200 < e.Y &&
                 pos.DownPoint + 100 > e.Y))
            {
                myPosition    = pos;
                _chart.Cursor = Cursors.SizeWE;
            }
            else
            {
                pos.ValueYMouseOnClickStart = 0;
                pos.HeightAreaOnClick       = 0;
                pos.ValueYChartOnClick      = 0;
            }


            if (myPosition == null)
            {
                _chart.Cursor = Cursors.Arrow;
                return;
            }

            if (mouse.Button != MouseButtons.Left)
            {
                myPosition.ValueXMouseOnClickStart       = 0;
                myPosition.CountXValuesChartOnClickStart = 0;
                return;
            }

            if (myPosition.ValueXMouseOnClickStart == 0)
            {
                myPosition.ValueXMouseOnClickStart = e.X;

                if (double.IsNaN(_chart.ChartAreas[0].AxisY.ScaleView.Size))
                {
                    int max = _volume.VolumeClusters.Count;

                    myPosition.CountXValuesChartOnClickStart = max;
                }
                else
                {
                    myPosition.CountXValuesChartOnClickStart = (int)_chart.ChartAreas[0].AxisY.ScaleView.Size;
                }
                return;
            }


            double persentMove = Math.Abs(myPosition.ValueXMouseOnClickStart - e.X) / _host.Child.Width;

            if (double.IsInfinity(persentMove) ||
                persentMove == 0)
            {
                return;
            }

            //double concateValue = 100*persentMove*5;


            int maxSize = _volume.VolumeClusters.Count;


            if (myPosition.ValueXMouseOnClickStart < e.X)
            {
                if (myPosition.Area.Position.Height < 10)
                {
                    return;
                }

                double newVal = myPosition.CountXValuesChartOnClickStart +
                                myPosition.CountXValuesChartOnClickStart * persentMove * 3;


                if (newVal > maxSize)
                {
                    _chart.ChartAreas[0].AxisY.ScaleView.Size = Double.NaN;
                }
                else
                {
                    if (newVal + _chart.ChartAreas[0].AxisY.ScaleView.Position > maxSize)
                    {
                        _chart.ChartAreas[0].AxisY.ScaleView.Position = maxSize - newVal;
                    }

                    _chart.ChartAreas[0].AxisY.ScaleView.Size = newVal;
                    //RePaintRightLebels();

                    if (_chart.ChartAreas[0].AxisY.ScaleView.Position + newVal > maxSize)
                    {
                        _chart.ChartAreas[0].AxisY.ScaleView.Position = maxSize - newVal;
                    }
                }
            }
            else if (myPosition.ValueXMouseOnClickStart > e.X)
            {
                double newVal = myPosition.CountXValuesChartOnClickStart -
                                myPosition.CountXValuesChartOnClickStart * persentMove * 3;


                if (newVal < 5)
                {
                    _chart.ChartAreas[0].AxisY.ScaleView.Size = 5;
                }
                else
                {
                    if (!double.IsNaN(_chart.ChartAreas[0].AxisY.ScaleView.Size))
                    {
                        _chart.ChartAreas[0].AxisY.ScaleView.Position = _chart.ChartAreas[0].AxisY.ScaleView.Position + _chart.ChartAreas[0].AxisY.ScaleView.Size - newVal;
                    }

                    _chart.ChartAreas[0].AxisY.ScaleView.Size = newVal;
                    if (_chart.ChartAreas[0].AxisY.ScaleView.Position + newVal > maxSize)
                    {
                        double newStartPos = maxSize - newVal;
                        if (newStartPos < 0)
                        {
                            newStartPos = 0;
                        }
                        _chart.ChartAreas[0].AxisY.ScaleView.Position = newStartPos;
                    }
                }
            }

            ResizeXAxis();
            ResizeYAxis();
        }