Ejemplo n.º 1
0
        /// <summary>
        /// Creates PlotAreaMouseEventArgs
        /// </summary>
        /// <param name="e">MouseButtonEventArgs</param>
        /// <returns>PlotAreaMouseButtonEventArgs</returns>
        internal PlotAreaMouseEventArgs CreatePlotAreaMouseEventArgs(MouseEventArgs e)
        {
            Chart chart = Chart as Chart;
            PlotAreaMouseEventArgs eventArgs = new PlotAreaMouseEventArgs(e);

            if (chart.ChartArea.AxisX != null)
            {
                Double xValue;
                Orientation axisOrientation = chart.ChartArea.AxisX.AxisOrientation;
                Double pixelPosition = (axisOrientation == Orientation.Horizontal) ? e.GetPosition(chart.ChartArea.PlottingCanvas).X : e.GetPosition(chart.ChartArea.PlottingCanvas).Y;
                Double lengthInPixel = ((axisOrientation == Orientation.Horizontal) ? chart.ChartArea.ChartVisualCanvas.Width : chart.ChartArea.ChartVisualCanvas.Height);

                xValue = chart.ChartArea.AxisX.PixelPositionToXValue(lengthInPixel, (axisOrientation == Orientation.Horizontal) ? pixelPosition : lengthInPixel - pixelPosition);

                if (chart.ChartArea.AxisX.IsDateTimeAxis)
                    eventArgs.XValue = DateTimeHelper.XValueToDateTime(chart.ChartArea.AxisX.MinDate, xValue, chart.ChartArea.AxisX.InternalIntervalType);
                else
                    eventArgs.XValue = xValue;
            }

            if (chart.ChartArea.AxisY != null)
            {
                Double yValue;
                Orientation axisOrientation = chart.ChartArea.AxisY.AxisOrientation;
                Double pixelPosition = (axisOrientation == Orientation.Vertical) ? e.GetPosition(chart.ChartArea.PlottingCanvas).Y : e.GetPosition(chart.ChartArea.PlottingCanvas).X;
                Double lengthInPixel = ((axisOrientation == Orientation.Vertical) ? chart.ChartArea.ChartVisualCanvas.Height : chart.ChartArea.ChartVisualCanvas.Width);

                yValue = chart.ChartArea.AxisY.PixelPositionToYValue(lengthInPixel, (axisOrientation == Orientation.Vertical) ? pixelPosition : lengthInPixel - pixelPosition);

                eventArgs.YValue = yValue;
            }

            if (chart.ChartArea.AxisY2 != null)
            {
                Double yValue;
                Orientation axisOrientation = chart.ChartArea.AxisY2.AxisOrientation;
                Double pixelPosition = (axisOrientation == Orientation.Vertical) ? e.GetPosition(chart.ChartArea.PlottingCanvas).Y : e.GetPosition(chart.ChartArea.PlottingCanvas).X;
                Double lengthInPixel = ((axisOrientation == Orientation.Vertical) ? chart.ChartArea.ChartVisualCanvas.Height : chart.ChartArea.ChartVisualCanvas.Width);

                yValue = chart.ChartArea.AxisY2.PixelPositionToYValue(lengthInPixel, (axisOrientation == Orientation.Vertical) ? pixelPosition : lengthInPixel - pixelPosition);

                eventArgs.YValue = yValue;
            }

            return eventArgs;
        }
Ejemplo n.º 2
0
        private void SetPlotAreaMouseEventArgs4AxesX(Chart chart, Axis axis, MouseEventArgs e, PlotAreaMouseEventArgs eventArgs)
        {
            Double xValue;
            AxisOrientation axisOrientation = chart.ChartArea.AxisX.AxisOrientation;
            Double pixelPosition = (axisOrientation == AxisOrientation.Horizontal) ? e.GetPosition(chart.ChartArea.PlottingCanvas).X : e.GetPosition(chart.ChartArea.PlottingCanvas).Y;
            Double lenthInPixel = ((axisOrientation == AxisOrientation.Horizontal) ? chart.ChartArea.ChartVisualCanvas.Width : chart.ChartArea.ChartVisualCanvas.Height);

            xValue = chart.ChartArea.AxisX.PixelPositionToXValue(lenthInPixel, (axisOrientation == AxisOrientation.Horizontal) ? pixelPosition : lenthInPixel - pixelPosition);

            if (chart.ChartArea.AxisX.IsDateTimeAxis)
            {
                /* The statement below can throw exception while calculating date corresponding XValue 
                 * if there is not DataPoints MinDate will be 1/1/1 */

                try
                {
                    eventArgs.XValue = DateTimeHelper.XValueToDateTime(chart.ChartArea.AxisX.MinDate, xValue, chart.ChartArea.AxisX.InternalIntervalType);
                }
                catch 
                {
                    eventArgs.XValue = chart.ChartArea.AxisX.MinDate;
                }
            }
            else
                eventArgs.XValue = xValue;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates PlotAreaMouseEventArgs
        /// </summary>
        /// <param name="e">MouseButtonEventArgs</param>
        /// <returns>PlotAreaMouseButtonEventArgs</returns>
        internal PlotAreaMouseEventArgs CreatePlotAreaMouseEventArgs(MouseEventArgs e)
        {   
            Chart chart = Chart as Chart;
            PlotAreaMouseEventArgs eventArgs = new PlotAreaMouseEventArgs(e);

            if (chart.ChartArea.AxisX != null)
                SetPlotAreaMouseEventArgs4AxesX(chart, chart.ChartArea.AxisX, e, eventArgs);

            if (chart.ChartArea.AxisY != null)
                SetPlotAreaMouseEventArgs4AxesY(chart, chart.ChartArea.AxisY, e, eventArgs);
            else if (chart.ChartArea.AxisY2 != null)
                SetPlotAreaMouseEventArgs4AxesY(chart, chart.ChartArea.AxisY2, e, eventArgs);

            return eventArgs;
        }
Ejemplo n.º 4
0
        private void SetPlotAreaMouseEventArgs4AxesY(Chart chart, Axis axis, MouseEventArgs e, PlotAreaMouseEventArgs eventArgs)
        {
            Double yValue;
            AxisOrientation axisOrientation = axis.AxisOrientation;
            Double pixelPosition = (axisOrientation == AxisOrientation.Vertical) ? e.GetPosition(chart.ChartArea.PlottingCanvas).Y : e.GetPosition(chart.ChartArea.PlottingCanvas).X;
            Double lenthInPixel = ((axisOrientation == AxisOrientation.Vertical) ? chart.ChartArea.ChartVisualCanvas.Height : chart.ChartArea.ChartVisualCanvas.Width);

            yValue = axis.PixelPositionToYValue(lenthInPixel, (axisOrientation == AxisOrientation.Vertical) ? pixelPosition : lenthInPixel - pixelPosition);

            if (axis.Logarithmic)
                eventArgs.YValue = DataPoint.ConvertLogarithmicValue2ActualValue(chart, yValue, axis.AxisType);
            else
                eventArgs.YValue = yValue;
        }