/// <summary> /// Creates PlotAreaMouseButtonEventArgs /// </summary> /// <param name="e">MouseButtonEventArgs</param> /// <returns>PlotAreaMouseButtonEventArgs</returns> internal PlotAreaMouseButtonEventArgs CreatePlotAreaMouseButtonEventArgs(MouseButtonEventArgs e) { Chart chart = Chart as Chart; PlotAreaMouseButtonEventArgs eventArgs = new PlotAreaMouseButtonEventArgs(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 lenthInPixel = ((axisOrientation == Orientation.Horizontal) ? chart.ChartArea.ChartVisualCanvas.Width : chart.ChartArea.ChartVisualCanvas.Height); xValue = chart.ChartArea.AxisX.PixelPositionToXValue(lenthInPixel, (axisOrientation == Orientation.Horizontal) ? pixelPosition : lenthInPixel - 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 lenthInPixel = ((axisOrientation == Orientation.Vertical) ? chart.ChartArea.ChartVisualCanvas.Height : chart.ChartArea.ChartVisualCanvas.Width); yValue = chart.ChartArea.AxisY.PixelPositionToYValue(lenthInPixel, (axisOrientation == Orientation.Vertical) ? pixelPosition : lenthInPixel - pixelPosition); eventArgs.YValue = yValue; } return eventArgs; }
private void SetPlotAreaMouseButtonEventArgs4AxesX(Chart chart, Axis axis, MouseButtonEventArgs e, PlotAreaMouseButtonEventArgs 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 (Exception ex) { eventArgs.XValue = chart.ChartArea.AxisX.MinDate; } } else eventArgs.XValue = xValue; }
/// <summary> /// Creates PlotAreaMouseButtonEventArgs /// </summary> /// <param name="e">MouseButtonEventArgs</param> /// <returns>PlotAreaMouseButtonEventArgs</returns> internal PlotAreaMouseButtonEventArgs CreatePlotAreaMouseButtonEventArgs(MouseButtonEventArgs e) { Chart chart = Chart as Chart; PlotAreaMouseButtonEventArgs eventArgs = new PlotAreaMouseButtonEventArgs(e); if (chart.ChartArea.AxisX != null) SetPlotAreaMouseButtonEventArgs4AxesX(chart, chart.ChartArea.AxisX, e, eventArgs); if (chart.ChartArea.AxisY != null) SetPlotAreaMouseButtonEventArgs4AxesY(chart, chart.ChartArea.AxisY, e, eventArgs); else if (chart.ChartArea.AxisY2 != null) SetPlotAreaMouseButtonEventArgs4AxesY(chart, chart.ChartArea.AxisY2, e, eventArgs); return eventArgs; }
private void SetPlotAreaMouseButtonEventArgs4AxesY(Chart chart, Axis axis, MouseButtonEventArgs e, PlotAreaMouseButtonEventArgs 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; }