/* Copyright (C) 2008 Webyog Softworks Private Limited This file is a part of Visifire Charts. Visifire is a free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. You should have received a copy of the GNU General Public License along with Visifire Charts. If not, see . If GPL is not suitable for your products or company, Webyog provides Visifire under a flexible commercial license designed to meet your specific usage and distribution requirements. If you have already obtained a commercial license from Webyog, you can use this file under those license terms. */ #if WPF using System; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; #else using System; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; using System.Windows.Browser; #endif using Visifire.Commons; using System.ComponentModel; using System.Windows.Data; namespace Visifire.Charts { /// /// Visifire.Charts.PlotArea class /// #if SL [System.Windows.Browser.ScriptableType] #endif public class PlotArea : ObservableObject { #region Public Methods /// /// Initializes a new instance of the Visifire.Charts.PlotArea class /// public PlotArea() { // Apply default style from generic #if WPF if (!_defaultStyleKeyApplied) { DefaultStyleKeyProperty.OverrideMetadata(typeof(PlotArea), new FrameworkPropertyMetadata(typeof(PlotArea))); _defaultStyleKeyApplied = true; } #else DefaultStyleKey = typeof(PlotArea); #endif // Attach event handler with EventChanged event of VisfiireElement EventChanged += delegate { FirePropertyChanged("MouseEvent"); }; } public override void Bind() { #if SL Binding b = new Binding("Background"); b.Source = this; this.SetBinding(InternalBackgroundProperty, b); b = new Binding("BorderThickness"); b.Source = this; this.SetBinding(InternalBorderThicknessProperty, b); b = new Binding("Opacity"); b.Source = this; this.SetBinding(InternalOpacityProperty, b); #endif } #endregion #region Public Properties #if SL /// /// Identifies the Visifire.Charts.PlotArea.Background dependency property. /// /// /// The identifier for the Visifire.Charts.PlotArea.Background dependency property. /// private static readonly DependencyProperty InternalBackgroundProperty = DependencyProperty.Register ("InternalBackground", typeof(Brush), typeof(PlotArea), new PropertyMetadata(OnBackgroundPropertyChanged)); /// /// Identifies the Visifire.Charts.PlotArea.Opacity dependency property. /// /// /// The identifier for the Visifire.Charts.PlotArea.Opacity dependency property. /// private static readonly DependencyProperty InternalOpacityProperty = DependencyProperty.Register ("InternalOpacity", typeof(Double), typeof(PlotArea), new PropertyMetadata(1.0, OnOpacityPropertyChanged)); /// /// Identifies the Visifire.Charts.PlotArea.BorderThickness dependency property. /// /// /// The identifier for the Visifire.Charts.PlotArea.BorderThickness dependency property. /// private static readonly DependencyProperty InternalBorderThicknessProperty = DependencyProperty.Register ("InternalBorderThickness", typeof(Thickness), typeof(PlotArea), new PropertyMetadata(OnBorderThicknessPropertyChanged)); #else /// /// Identifies the Visifire.Charts.PlotArea.Background dependency property. /// /// /// The identifier for the Visifire.Charts.PlotArea.Background dependency property. /// public new static readonly DependencyProperty BackgroundProperty = DependencyProperty.Register ("Background", typeof(Brush), typeof(PlotArea), new PropertyMetadata(OnBackgroundPropertyChanged)); /// /// Identifies the Visifire.Charts.PlotArea.Opacity dependency property. /// /// /// The identifier for the Visifire.Charts.PlotArea.Opacity dependency property. /// public new static readonly DependencyProperty OpacityProperty = DependencyProperty.Register ("Opacity", typeof(Double), typeof(PlotArea), new PropertyMetadata(1.0, OnOpacityPropertyChanged)); /// /// Identifies the Visifire.Charts.PlotArea.BorderThickness dependency property. /// /// /// The identifier for the Visifire.Charts.PlotArea.BorderThickness dependency property. /// public new static readonly DependencyProperty BorderThicknessProperty = DependencyProperty.Register ("BorderThickness", typeof(Thickness), typeof(PlotArea), new PropertyMetadata(OnBorderThicknessPropertyChanged)); #endif /// /// Identifies the Visifire.Charts.PlotArea.HrefTarget dependency property. /// /// /// The identifier for the Visifire.Charts.PlotArea.HrefTarget dependency property. /// public static readonly DependencyProperty HrefTargetProperty = DependencyProperty.Register ("HrefTarget", typeof(HrefTargets), typeof(PlotArea), new PropertyMetadata(OnHrefTargetChanged)); /// /// Identifies the Visifire.Charts.PlotArea.Href dependency property. /// /// /// The identifier for the Visifire.Charts.PlotArea.Href dependency property. /// public static readonly DependencyProperty HrefProperty = DependencyProperty.Register ("Href", typeof(String), typeof(PlotArea), new PropertyMetadata(OnHrefChanged)); /// /// Identifies the Visifire.Charts.PlotArea.Bevel dependency property. /// /// /// The identifier for the Visifire.Charts.PlotArea.Bevel dependency property. /// public static readonly DependencyProperty BevelProperty = DependencyProperty.Register ("Bevel", typeof(Boolean), typeof(PlotArea), new PropertyMetadata(OnBevelPropertyChanged)); /// /// Identifies the Visifire.Charts.PlotArea.BorderColor dependency property. /// /// /// The identifier for the Visifire.Charts.PlotArea.BorderColor dependency property. /// public static readonly DependencyProperty BorderColorProperty = DependencyProperty.Register ("BorderColor", typeof(Brush), typeof(PlotArea), new PropertyMetadata(OnBorderColorPropertyChanged)); #if WPF #endif /// /// Identifies the Visifire.Charts.PlotArea.LightingEnabled dependency property. /// /// /// The identifier for the Visifire.Charts.PlotArea.LightingEnabled dependency property. /// public static readonly DependencyProperty LightingEnabledProperty = DependencyProperty.Register ("LightingEnabled", typeof(Boolean), typeof(PlotArea), new PropertyMetadata(OnLightingEnabledPropertyChanged)); /// /// Identifies the Visifire.Charts.PlotArea.CornerRadius dependency property. /// /// /// The identifier for the Visifire.Charts.PlotArea.CornerRadius dependency property. /// public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register ("CornerRadius", typeof(CornerRadius), typeof(PlotArea), new PropertyMetadata(OnCornerRadiusPropertyChanged)); /// /// Identifies the Visifire.Charts.PlotArea.ShadowEnabled dependency property. /// /// /// The identifier for the Visifire.Charts.PlotArea.ShadowEnabled dependency property. /// public static readonly DependencyProperty ShadowEnabledProperty = DependencyProperty.Register ("ShadowEnabled", typeof(Boolean), typeof(PlotArea), new PropertyMetadata(OnShadowEnabledPropertyChanged)); /// /// Get or set HrefTarget property of PlotArea /// public HrefTargets HrefTarget { get { return (HrefTargets)GetValue(HrefTargetProperty); } set { SetValue(HrefTargetProperty, value); } } /// /// Get or set Href property of PlotArea /// public String Href { get { return (String)GetValue(HrefProperty); } set { SetValue(HrefProperty, value); } } /// /// Get or set the Opacity property /// public new Double Opacity { get { return (Double)GetValue(OpacityProperty); } set { #if SL if (Opacity != value) { InternalOpacity = value; SetValue(OpacityProperty, value); FirePropertyChanged("Opacity"); } #else SetValue(OpacityProperty, value); #endif } } /// /// Get or set the Cursor property /// public new Cursor Cursor { get { return base.Cursor; } set { if (base.Cursor != value) { base.Cursor = value; if(Visual != null) Visual.Cursor = (Cursor == null) ? Cursors.Arrow : Cursor; else FirePropertyChanged("Cursor"); } } } /// /// Get or set Bevel property of PlotArea for Bevel effect /// public Boolean Bevel { get { return (Boolean)GetValue(BevelProperty); } set { SetValue(BevelProperty, value); } } /// /// Get or set BorderColor property of PlotArea /// public Brush BorderColor { get { return (Brush)GetValue(BorderColorProperty); } set { SetValue(BorderColorProperty, value); } } /// /// Get or set ToolTipText property for the Chart /// public override String ToolTipText { get { if (Chart != null && !String.IsNullOrEmpty(Chart.ToolTipText)) return null; else return (String)GetValue(ToolTipTextProperty); } set { SetValue(ToolTipTextProperty, value); } } /// /// Get or set BorderThickness property of PlotArea /// public new Thickness BorderThickness { get { return (Thickness)GetValue(BorderThicknessProperty); } set { #if WPF SetValue(BorderThicknessProperty, value); #else InternalBorderThickness = value; SetValue(BorderThicknessProperty, value); FirePropertyChanged("BorderThickness"); #endif } } /// /// Get or set the BorderThickness of title /// internal Thickness InternalBorderThickness { get { return (Thickness)((_borderThickness == null) ? GetValue(BorderThicknessProperty) : _borderThickness); } set { _borderThickness = value; } } /// /// Get or set LightingEnabled property of PlotArea /// public Boolean LightingEnabled { get { return (Boolean)GetValue(LightingEnabledProperty); } set { SetValue(LightingEnabledProperty, value); } } /// /// Get or set CornerRadius property of PlotArea /// #if WPF [System.ComponentModel.TypeConverter(typeof(System.Windows.CornerRadiusConverter))] #else [System.ComponentModel.TypeConverter(typeof(Converters.CornerRadiusConverter))] #endif public CornerRadius CornerRadius { get { return (CornerRadius)GetValue(CornerRadiusProperty); } set { SetValue(CornerRadiusProperty, value); } } /// /// Get or set ShadowEnabled property of PlotArea /// public Boolean ShadowEnabled { get { return (Boolean)GetValue(ShadowEnabledProperty); } set { SetValue(ShadowEnabledProperty, value); } } /// /// Get or set Background property of PlotArea /// public new Brush Background { get { return (Brush)GetValue(BackgroundProperty); } set { #if SL if (Background != value) { InternalBackground = value; SetValue(BackgroundProperty, value); FirePropertyChanged("Background"); } #else SetValue(BackgroundProperty, value); #endif } } /// /// Get or set the Background property of title /// internal Brush InternalBackground { get { return (Brush)((_internalBackground == null) ? GetValue(BackgroundProperty) : _internalBackground); } set { _internalBackground = value; } } /// /// Get or set the Opacity property /// internal Double InternalOpacity { get { return (Double)(Double.IsNaN(_internalOpacity) ? GetValue(OpacityProperty) : _internalOpacity); } set { _internalOpacity = value; } } #endregion #region Public Events And Delegates /// /// Event handler for the MouseLeftButtonDown event /// #if SL [ScriptableMember] #endif public new event EventHandler MouseLeftButtonDown { remove { _onMouseLeftButtonDown -= value; if (EventChanged != null) EventChanged(this, null); } add { _onMouseLeftButtonDown += value; if (EventChanged != null) EventChanged(this, null); } } /// /// Event handler for the MouseLeftButtonUp event /// #if SL [ScriptableMember] #endif public new event EventHandler MouseLeftButtonUp { remove { _onMouseLeftButtonUp -= value; if (EventChanged != null) EventChanged(this, null); } add { _onMouseLeftButtonUp += value; if (EventChanged != null) EventChanged(this, null); } } #if WPF /// /// Event handler for the MouseLeftButtonDown event /// public new event EventHandler MouseRightButtonDown { remove { _onMouseRightButtonDown -= value; if (EventChanged != null) EventChanged(this, null); } add { _onMouseRightButtonDown += value; if (EventChanged != null) EventChanged(this, null); } } /// /// Event handler for the MouseLeftButtonUp event /// public new event EventHandler MouseRightButtonUp { remove { _onMouseRightButtonUp -= value; if (EventChanged != null) EventChanged(this, null); } add { _onMouseRightButtonUp += value; if (EventChanged != null) EventChanged(this, null); } } #endif /// /// Event handler for the MouseMove event /// #if SL [ScriptableMember] #endif public new event EventHandler MouseMove { remove { _onMouseMove -= value; if (EventChanged != null) EventChanged(this, null); } add { _onMouseMove += value; if (EventChanged != null) EventChanged(this, null); } } #endregion #region Protected Methods #endregion #region Internal Properties /// /// Border used for applying lighting effect over PlotArea /// internal Border LightingBorder { get; set; } /// /// Bevel grid of PlotArea /// internal Grid BevelGrid { get; set; } /// /// Shadow grid of PlotArea /// internal Grid ShadowGrid { get; set; } /// /// Shadow inside ScrollViewer /// internal Grid InnerShadowGrid { get; set; } /// /// PlotArea visual /// internal Canvas Visual { get; set; } /// /// Border element of PlotArea /// internal Border BorderElement { get; set; } #endregion #region Private Properties #endregion #region Private Delegates #endregion #region Private Methods /// /// BackgroundProperty changed call back function /// /// DependencyObject /// DependencyPropertyChangedEventArgs private static void OnBackgroundPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { PlotArea plotArea = d as PlotArea; plotArea.InternalBackground = (Brush)e.NewValue; plotArea.FirePropertyChanged("Background"); } /// /// OpacityProperty changed call back function /// /// DependencyObject /// DependencyPropertyChangedEventArgs private static void OnOpacityPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { PlotArea plotArea = d as PlotArea; plotArea.InternalOpacity = (Double)e.NewValue; plotArea.FirePropertyChanged("Opacity"); } /// /// BorderThicknessProperty changed call back function /// /// DependencyObject /// DependencyPropertyChangedEventArgs private static void OnBorderThicknessPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { PlotArea plotArea = d as PlotArea; plotArea.InternalBorderThickness = (Thickness)e.NewValue; plotArea.FirePropertyChanged("BorderThickness"); } /// /// HrefTargetProperty changed call back function /// /// DependencyObject /// DependencyPropertyChangedEventArgs private static void OnHrefTargetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { (d as PlotArea).FirePropertyChanged("HrefTarget"); } /// /// HrefProperty changed call back function /// /// DependencyObject /// DependencyPropertyChangedEventArgs private static void OnHrefChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { (d as PlotArea).FirePropertyChanged("Href"); } /// /// BevelProperty changed call back function /// /// DependencyObject /// DependencyPropertyChangedEventArgs private static void OnBevelPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { (d as PlotArea).FirePropertyChanged("Bevel"); } /// /// BorderColorProperty changed call back function /// /// DependencyObject /// DependencyPropertyChangedEventArgs private static void OnBorderColorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { (d as PlotArea).FirePropertyChanged("BorderColor"); } /// /// LightingEnabledProperty changed call back function /// /// DependencyObject /// DependencyPropertyChangedEventArgs private static void OnLightingEnabledPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { (d as PlotArea).FirePropertyChanged("LightingEnabled"); } /// /// CornerRadiusProperty changed call back function /// /// DependencyObject /// DependencyPropertyChangedEventArgs private static void OnCornerRadiusPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { (d as PlotArea).FirePropertyChanged("CornerRadius"); } /// /// ShadowEnabledProperty changed call back function /// /// DependencyObject /// DependencyPropertyChangedEventArgs private static void OnShadowEnabledPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { (d as PlotArea).FirePropertyChanged("ShadowEnabled"); } /// /// Returns PathGeometry for clipping Shadow of PlotArea /// /// Size clipSize /// PathGeometry private PathGeometry GetShadowClip(Size clipSize) { PathGeometry pathGeometry = new PathGeometry(); pathGeometry.FillRule = FillRule.EvenOdd; pathGeometry.Figures = new PathFigureCollection(); PathFigure pathFigure = new PathFigure(); pathFigure.StartPoint = new Point(0, clipSize.Height - Charts.Chart.SHADOW_DEPTH); pathFigure.Segments = new PathSegmentCollection(); // Do not change the order of the lines below pathFigure.Segments.Add(Graphics.GetLineSegment(new Point(clipSize.Width - Charts.Chart.SHADOW_DEPTH, clipSize.Height - Charts.Chart.SHADOW_DEPTH))); pathFigure.Segments.Add(Graphics.GetLineSegment(new Point(clipSize.Width - Charts.Chart.SHADOW_DEPTH, 0))); pathFigure.Segments.Add(Graphics.GetLineSegment(new Point(clipSize.Width, 0))); pathFigure.Segments.Add(Graphics.GetLineSegment(new Point(clipSize.Width, clipSize.Height))); pathFigure.Segments.Add(Graphics.GetLineSegment(new Point(0, clipSize.Height))); pathFigure.Segments.Add(Graphics.GetLineSegment(new Point(0, clipSize.Height - Charts.Chart.SHADOW_DEPTH))); pathGeometry.Figures.Add(pathFigure); return pathGeometry; } #endregion #region Internal Methods /// /// Creates visual of PlotArea /// internal void CreateVisualObject() { if (Visual == null) { Visual = new Canvas(); Visual.Children.Add(GetNewBorderElement()); } ApplyProperties(); ApplyLighting(); } /// /// Creates new border element for PlotArea /// /// Border internal Border GetNewBorderElement() { BorderElement = new Border() { Tag = new ElementData() { Element = this } }; LightingBorder = new Border() { Tag = new ElementData() { Element = this } }; BevelGrid = new Grid(); BevelGrid.Children.Add(LightingBorder); BorderElement.Child = BevelGrid; ApplyProperties(); return BorderElement; } /// /// Update PlotArea with new property values /// internal void UpdateProperties() { BorderElement.SetValue(Canvas.TopProperty, (Double)0); BorderElement.SetValue(Canvas.LeftProperty, (Double)0); ApplyProperties(); ApplyLighting(); } /// /// Apply properties to visual and parts of visual /// internal void ApplyProperties() { Visual.Margin = new Thickness(0); Visual.Cursor = (Cursor == null) ? Cursors.Arrow : Cursor; BorderElement.Opacity = this.InternalOpacity; if (InternalBackground != null) BorderElement.Background = InternalBackground; if (BorderColor != null) BorderElement.BorderBrush = BorderColor; if (InternalBorderThickness != null) { BorderElement.BorderThickness = InternalBorderThickness; } if (CornerRadius != null) { BorderElement.CornerRadius = CornerRadius; LightingBorder.CornerRadius = CornerRadius; } } /// /// Apply PlotAreaBevel /// internal void ApplyBevel(Double plankDepth, Double plankThickness) { if (_bevelCanvas != null) { BevelGrid.Children.Remove(_bevelCanvas); _bevelCanvas = null; } if (Bevel) { Chart chart = Chart as Chart; _bevelCanvas = ExtendedGraphics.Get2DRectangleBevel(this, BorderElement.Width - InternalBorderThickness.Left - InternalBorderThickness.Right// - plankDepth , BorderElement.Height - InternalBorderThickness.Top - InternalBorderThickness.Bottom //+ ((chart.PlotDetails.ChartOrientation == ChartOrientationType.Horizontal || chart.PlotDetails.ChartOrientation == ChartOrientationType.NoAxis) ? 0 : (-plankDepth - plankThickness)) , Charts.Chart.BEVEL_DEPTH, Charts.Chart.BEVEL_DEPTH , Graphics.GetBevelTopBrush(BorderElement.Background) , Graphics.GetBevelSideBrush(0, BorderElement.Background) , Graphics.GetBevelSideBrush(180, BorderElement.Background) , Graphics.GetBevelSideBrush(90, BorderElement.Background)); _bevelCanvas.SetValue(Canvas.LeftProperty, InternalBorderThickness.Left); _bevelCanvas.SetValue(Canvas.TopProperty, InternalBorderThickness.Top); _bevelCanvas.IsHitTestVisible = false; BevelGrid.Children.Add(_bevelCanvas); } } /// /// Apply lighting effect to PlotArea /// internal void ApplyLighting() { if (LightingBorder != null) { if (LightingEnabled) { if (Bevel) { LightingBorder.Background = Graphics.GetFrontFaceBrush(InternalBackground); LightingBorder.Background.Opacity = 0.6; } else { LightingBorder.Background = Graphics.LightingBrush(LightingEnabled); } } else LightingBorder.Background = new SolidColorBrush(Colors.Transparent); } } /// /// Apply shadow for PlotArea /// internal void ApplyShadow(Size plotAreaViewPortSize, Double plankOffset, Double plankDepth, Double plankThickness) { Chart._plotAreaShadowCanvas.Children.Clear(); Chart._drawingCanvas.Children.Remove(InnerShadowGrid); Chart chart = Chart as Chart; Size clipSize; if (chart.PlotArea.ShadowEnabled) { if (chart.PlotDetails.ChartOrientation == ChartOrientationType.NoAxis) { ShadowGrid = ExtendedGraphics.Get2DRectangleShadow(this, BorderElement.Width + Visifire.Charts.Chart.SHADOW_DEPTH , BorderElement.Height + Visifire.Charts.Chart.SHADOW_DEPTH , CornerRadius , CornerRadius, 6); clipSize = new Size(ShadowGrid.Width, ShadowGrid.Height); } else { if (chart.View3D) { if (chart.PlotDetails.ChartOrientation == ChartOrientationType.Horizontal) { ShadowGrid = ExtendedGraphics.Get2DRectangleShadow(this, plotAreaViewPortSize.Width + Visifire.Charts.Chart.SHADOW_DEPTH - plankThickness - plankDepth - ChartArea.SCROLLVIEWER_OFFSET4HORIZONTAL_CHART , plotAreaViewPortSize.Height - plankDepth + Visifire.Charts.Chart.SHADOW_DEPTH , CornerRadius , CornerRadius, 6); clipSize = new Size(ShadowGrid.Width, ShadowGrid.Height + Visifire.Charts.Chart.SHADOW_DEPTH); ShadowGrid.SetValue(Canvas.LeftProperty, plankOffset); InnerShadowGrid = ExtendedGraphics.Get2DRectangleShadow(this, plotAreaViewPortSize.Width + Visifire.Charts.Chart.SHADOW_DEPTH - plankThickness - plankDepth - ChartArea.SCROLLVIEWER_OFFSET4HORIZONTAL_CHART , BorderElement.Height + Visifire.Charts.Chart.SHADOW_DEPTH , CornerRadius , CornerRadius, 6); InnerShadowGrid.Clip = GetShadowClip(new Size(InnerShadowGrid.Width + Visifire.Charts.Chart.SHADOW_DEPTH, InnerShadowGrid.Height)); InnerShadowGrid.SetValue(Canvas.LeftProperty, plankOffset); Chart._drawingCanvas.Children.Add(InnerShadowGrid); } else { ShadowGrid = ExtendedGraphics.Get2DRectangleShadow(this, plotAreaViewPortSize.Width + Visifire.Charts.Chart.SHADOW_DEPTH - plankThickness - plankDepth , plotAreaViewPortSize.Height + Visifire.Charts.Chart.SHADOW_DEPTH - plankOffset , CornerRadius , CornerRadius, 6); clipSize = new Size(ShadowGrid.Width, ShadowGrid.Height); ShadowGrid.SetValue(Canvas.LeftProperty, plankOffset); } } else { ShadowGrid = ExtendedGraphics.Get2DRectangleShadow(this, plotAreaViewPortSize.Width + Charts.Chart.SHADOW_DEPTH , plotAreaViewPortSize.Height - plankOffset + Visifire.Charts.Chart.SHADOW_DEPTH, CornerRadius , CornerRadius , 6); clipSize = new Size(ShadowGrid.Width, ShadowGrid.Height); } } ShadowGrid.Clip = GetShadowClip(clipSize); ShadowGrid.IsHitTestVisible = false; Chart._plotAreaShadowCanvas.Children.Add(ShadowGrid); ShadowGrid.UpdateLayout(); } } /// /// Creates PlotAreaMouseButtonEventArgs /// /// MouseButtonEventArgs /// PlotAreaMouseButtonEventArgs 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; } /// /// Creates PlotAreaMouseEventArgs /// /// MouseButtonEventArgs /// PlotAreaMouseButtonEventArgs 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; } /// /// Fire MouseLeftButtonDown event /// /// MouseButtonEventArgs internal void FireMouseLeftButtonDownEvent(MouseButtonEventArgs e) { if(_onMouseLeftButtonDown != null) _onMouseLeftButtonDown(this, CreatePlotAreaMouseButtonEventArgs(e)); } /// /// Fire MouseRightButtonDown event /// /// MouseButtonEventArgs internal void FireMouseRightButtonDownEvent(MouseButtonEventArgs e) { #if WPF if (_onMouseRightButtonDown != null) _onMouseRightButtonDown(this, CreatePlotAreaMouseButtonEventArgs(e)); #endif } /// /// Fire MouseLeftButtonDown event /// /// MouseButtonEventArgs internal void FireMouseLeftButtonUpEvent(MouseButtonEventArgs e) { if (_onMouseLeftButtonUp != null) _onMouseLeftButtonUp(this, CreatePlotAreaMouseButtonEventArgs(e)); } /// /// Fire MouseRightButtonDown event /// /// MouseButtonEventArgs internal void FireMouseRightButtonUpEvent(MouseButtonEventArgs e) { #if WPF if (_onMouseRightButtonUp != null) _onMouseRightButtonUp(this, CreatePlotAreaMouseButtonEventArgs(e)); #endif } /// /// Fire MouseLeftButtonDown event /// /// MouseButtonEventArgs internal void FireMouseMoveEvent(MouseEventArgs e) { if (_onMouseMove != null) _onMouseMove(this, CreatePlotAreaMouseEventArgs(e)); } /// /// Get MouseLeftButtonDown EventHandler /// /// internal EventHandler GetMouseLeftButtonDownEventHandler() { return _onMouseLeftButtonDown; } /// /// Get MouseLeftButtonUp EventHandler /// /// internal EventHandler GetMouseLeftButtonUpEventHandler() { return _onMouseLeftButtonUp; } #if WPF /// /// Get MouseRightButtonDown EventHandler /// /// internal EventHandler GetMouseRightButtonDownEventHandler() { return _onMouseRightButtonDown; } /// /// Get MouseRightButtonUp EventHandler /// /// internal EventHandler GetMouseRightButtonUpEventHandler() { return _onMouseRightButtonUp; } #endif /// /// Get MouseLeftButtonUp EventHandler /// /// internal EventHandler GetMouseMoveEventHandler() { return _onMouseMove; } #endregion #region Internal Events And Delegates /// /// EventChanged event is fired if any event is attached /// internal new event EventHandler EventChanged; #endregion #region Data Brush _internalBackground = null; Nullable _borderThickness = null; Double _internalOpacity = Double.NaN; /// /// Handler for MouseLeftButtonDown event /// private event EventHandler _onMouseLeftButtonDown; /// /// Handler for MouseLeftButtonUp event /// private event EventHandler _onMouseLeftButtonUp; #if WPF /// /// Handler for MouseRightButtonDown event /// private event EventHandler _onMouseRightButtonDown; /// /// Handler for MouseRightButtonUp event /// private event EventHandler _onMouseRightButtonUp; #endif /// /// Handler for MouseMove event /// private event EventHandler _onMouseMove; /// /// Canvas for bevel /// Canvas _bevelCanvas; #if WPF /// /// Whether the default style is applied /// private static Boolean _defaultStyleKeyApplied; #endif #endregion } }