/// <summary> /// Initializes a new instance of the Visifire.Charts.AxisLabels class /// </summary> public AxisLabels() { // Apply default style from generic #if WPF if (!_defaultStyleKeyApplied) { DefaultStyleKeyProperty.OverrideMetadata(typeof(AxisLabels), new FrameworkPropertyMetadata(typeof(AxisLabels))); _defaultStyleKeyApplied = true; } #else DefaultStyleKey = typeof(AxisLabels); #endif WidthOfACharacter = Double.NaN; InternalAngle = Double.NaN; _tag = new ElementData() { Element = this }; }
/// <summary> /// Initializes a new instance of the Visifire.Charts.CustomAxisLabels class /// </summary> public CustomAxisLabels() { // Apply default style from generic #if WPF if (!_defaultStyleKeyApplied) { DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomAxisLabels), new FrameworkPropertyMetadata(typeof(CustomAxisLabels))); _defaultStyleKeyApplied = true; } #else DefaultStyleKey = typeof(CustomAxisLabels); #endif WidthOfACharacter = Double.NaN; InternalAngle = Double.NaN; _tag = new ElementData() { Element = this }; // Initialize CustomAxisLabels list Labels = new CustomAxisLabelCollection(); Labels.CollectionChanged += new NotifyCollectionChangedEventHandler(Labels_CollectionChanged); }
/// <summary> /// Create visual for AxisLabel /// </summary> internal void CreateVisualObject(Boolean positioningAllowed, ElementData tag) { Visual = new Canvas() { Tag = tag }; TextElement = new TextBlock() { Tag = tag }; Rotation = new RotateTransform(); TextElement.RenderTransform = Rotation; Visual.Children.Add(TextElement); ApplyProperties(this); CalculateTextElementSize(); if (positioningAllowed) SetPosition(); // calculate the actual size of the AxisLabel element CalculateSize(GetRadians(Angle)); }
/// <summary> /// Create visual for AxisLabel /// </summary> internal void CreateVisualObject(ElementData tag) { TextElement = new TextBlock() { Tag = tag }; Rotation = new RotateTransform(); TextElement.RenderTransform = Rotation; Visual = TextElement; ApplyProperties(this); CalculateTextElementSize(); //if (positioningAllowed) // SetPosition(); // calculate the actual size of the AxisLabel element CalculateSize(GetRadians(Angle)); }
/// <summary> /// Create visual object of the Legend /// </summary> internal void CreateVisualObject() { if (!(Boolean)Enabled) { Visual = null; return; } ElementData tag = new ElementData { Element = this, VisualElementName = "Legend" }; Visual = new Border() { Tag = tag }; Grid innerGrid = new Grid() { Tag = tag }; (Visual as Border).Child = innerGrid; LegendContainer = new StackPanel() { Tag = tag }; if (!String.IsNullOrEmpty(Title)) { Title legendTitle = new Title(); ApplyFontProperty(legendTitle); if (TitleBackground != null) legendTitle.InternalBackground = TitleBackground; legendTitle.InternalHorizontalAlignment = TitleAlignmentX; legendTitle.InternalVerticalAlignment = VerticalAlignment.Top; legendTitle.TextAlignment = TitleTextAlignment; legendTitle.CreateVisualObject(tag); legendTitle.Measure(new Size(Double.MaxValue, Double.MaxValue)); if (legendTitle.DesiredSize.Width > InternalMaxWidth) legendTitle.Visual.Width = InternalMaxWidth; LegendContainer.Children.Add(legendTitle.Visual); } Grid legendContent = CreateLegendContent(); legendContent.Tag = tag; LegendContainer.Children.Add(legendContent); LegendContainer.VerticalAlignment = VerticalAlignment.Center; LegendContainer.HorizontalAlignment = HorizontalAlignment.Stretch; ApplyVisualProperty(); innerGrid.Children.Add(LegendContainer); Visual.Cursor = this.Cursor; Visual.Measure(new Size(Double.MaxValue, Double.MaxValue)); if (!Double.IsPositiveInfinity(InternalMaxHeight) && InternalMaxHeight < Visual.DesiredSize.Height) Visual.Height = InternalMaxHeight; else Visual.Height = Visual.DesiredSize.Height; if (!Double.IsPositiveInfinity(InternalMaxWidth) && InternalMaxWidth < Visual.DesiredSize.Width + InternalPadding.Left) Visual.Width = InternalMaxWidth; else if (Layout == Layouts.GridLayout) Visual.Width = Visual.DesiredSize.Width + InternalPadding.Left; else Visual.Width = Visual.DesiredSize.Width; PlotArea plotArea = (Chart as Chart).PlotArea; RectangleGeometry rectGeo = new RectangleGeometry(); rectGeo.Rect = new Rect(InternalBorderThickness.Left, InternalBorderThickness.Top, Visual.Width - InternalBorderThickness.Left - InternalBorderThickness.Right, Visual.Height - InternalBorderThickness.Top - InternalBorderThickness.Bottom); rectGeo.RadiusX = CornerRadius.TopLeft; rectGeo.RadiusY = CornerRadius.TopRight; LegendContainer.Clip = rectGeo; ApplyShadow(innerGrid); if (VerticalAlignment == System.Windows.VerticalAlignment.Bottom && (HorizontalAlignment == System.Windows.HorizontalAlignment.Center || HorizontalAlignment == System.Windows.HorizontalAlignment.Left || HorizontalAlignment == System.Windows.HorizontalAlignment.Right || HorizontalAlignment == System.Windows.HorizontalAlignment.Stretch)) Visual.Margin = new Thickness(0, DEFAULT_MARGIN, 0, 0); else if (VerticalAlignment == System.Windows.VerticalAlignment.Top && (HorizontalAlignment == System.Windows.HorizontalAlignment.Center || HorizontalAlignment == System.Windows.HorizontalAlignment.Left || HorizontalAlignment == System.Windows.HorizontalAlignment.Right || HorizontalAlignment == System.Windows.HorizontalAlignment.Stretch)) Visual.Margin = new Thickness(0, 0, 0, DEFAULT_MARGIN); else if (HorizontalAlignment == System.Windows.HorizontalAlignment.Left && (VerticalAlignment == System.Windows.VerticalAlignment.Center || VerticalAlignment == System.Windows.VerticalAlignment.Stretch)) Visual.Margin = new Thickness(0, 0, DEFAULT_MARGIN, 0); else if (HorizontalAlignment == System.Windows.HorizontalAlignment.Right && (VerticalAlignment == System.Windows.VerticalAlignment.Center || VerticalAlignment == System.Windows.VerticalAlignment.Stretch)) Visual.Margin = new Thickness(DEFAULT_MARGIN, 0, 0, 0); }
/// <summary> /// Create or update a CandleStick /// </summary> /// <param name="dataPoint"></param> /// <param name="seriesCanvas"></param> /// <param name="labelCanvas"></param> /// <param name="canvasWidth"></param> /// <param name="canvasHeight"></param> /// <param name="dataPointWidth"></param> internal static void CreateOrUpdateACandleStick(DataPoint dataPoint, Canvas candleStickCanvas, Canvas labelCanvas, Double canvasWidth, Double canvasHeight, Double dataPointWidth) { Faces dpFaces = dataPoint.Faces; // Remove preexisting dataPoint visual and label visual if (dpFaces != null && dpFaces.Visual != null && candleStickCanvas == dpFaces.Visual.Parent) { candleStickCanvas.Children.Remove(dataPoint.Faces.Visual); //dpFaces = null; } // Remove preexisting label visual if(dataPoint.LabelVisual != null && dataPoint.LabelVisual.Parent == labelCanvas) { labelCanvas.Children.Remove(dataPoint.LabelVisual); //dataPoint.LabelVisual = null; } dataPoint.Faces = null; if (dataPoint.YValues == null || dataPoint.Enabled == false) return; // Creating ElementData for Tag ElementData tagElement = new ElementData() { Element = dataPoint }; // Initialize DataPoint faces dataPoint.Faces = new Faces(); // Create DataPoint Visual Canvas dataPointVisual = new Canvas(); dataPoint.Faces.Visual = dataPointVisual; // Create High and Low Line Line highLowLine = new Line() { Tag = tagElement }; dataPoint.Faces.Parts.Add(highLowLine); dataPoint.Faces.VisualComponents.Add(highLowLine); dataPointVisual.Children.Add(highLowLine); /* Create Open-Close Rectangle * Math.Max is used to make sure that the rectangle is visible * even when the difference between high and low is 0 */ Rectangle openCloseRect = new Rectangle() { Tag = tagElement }; dataPoint.Faces.VisualComponents.Add(openCloseRect); dataPoint.Faces.BorderElements.Add(openCloseRect); dataPointVisual.Children.Add(openCloseRect); UpdateYValueAndXValuePosition(dataPoint, canvasWidth, canvasHeight, dataPointWidth); // Add dataPointVisual to seriesCanvas candleStickCanvas.Children.Add(dataPointVisual); CreateAndPositionLabel(labelCanvas, dataPoint); dataPointVisual.Opacity = dataPoint.Parent.Opacity * dataPoint.Opacity; Chart chart = dataPoint.Chart as Chart; dataPoint.SetCursor2DataPointVisualFaces(); dataPoint.AttachEvent2DataPointVisualFaces(dataPoint); dataPoint.AttachEvent2DataPointVisualFaces(dataPoint.Parent); dataPoint._parsedToolTipText = dataPoint.TextParser(dataPoint.ToolTipText); dataPoint.AttachToolTip(chart, dataPoint, dataPoint.Faces.VisualComponents); dataPoint.AttachHref(chart, dataPoint.Faces.VisualComponents, dataPoint.Href, (HrefTargets)dataPoint.HrefTarget); }
internal static void CreateOrUpdateAStockDataPoint(DataPoint dataPoint, Canvas stockChartCanvas, Canvas labelCanvas, Double canvasWidth, Double canvasHeight, Double dataPointWidth) { Faces dpFaces = dataPoint.Faces; // Remove preexisting dataPoint visual and label visual if (dpFaces != null && dpFaces.Visual != null && stockChartCanvas == dpFaces.Visual.Parent) { stockChartCanvas.Children.Remove(dataPoint.Faces.Visual); } // Remove preexisting label visual if (dataPoint.LabelVisual != null && dataPoint.LabelVisual.Parent == labelCanvas) { labelCanvas.Children.Remove(dataPoint.LabelVisual); } dataPoint.Faces = null; if (dataPoint.YValues == null || dataPoint.Enabled == false) { return; } // Initialize DataPoint faces dataPoint.Faces = new Faces(); // Creating ElementData for Tag ElementData tagElement = new ElementData() { Element = dataPoint }; // Create DataPoint Visual Canvas dataPointVisual = new Canvas(); // Create DataPoint Visual Line highLow = new Line() { Tag = tagElement }; // Create High and Low Line Line closeLine = new Line() { Tag = tagElement }; // Create Close Line Line openLine = new Line() { Tag = tagElement }; // Create Close Line dataPoint.Faces.Visual = dataPointVisual; // Add VisualComponents dataPoint.Faces.VisualComponents.Add(highLow); dataPoint.Faces.VisualComponents.Add(openLine); dataPoint.Faces.VisualComponents.Add(closeLine); // Add Border elements dataPoint.Faces.BorderElements.Add(highLow); dataPoint.Faces.BorderElements.Add(openLine); dataPoint.Faces.BorderElements.Add(closeLine); dataPoint.Faces.Visual = dataPointVisual; stockChartCanvas.Children.Add(dataPointVisual); UpdateYValueAndXValuePosition(dataPoint, canvasWidth, canvasHeight, dataPointWidth); ApplyBorderProperties(dataPoint, highLow, openLine, closeLine, dataPointWidth); ApplyOrUpdateColorForAStockDp(dataPoint, highLow, openLine, closeLine); // Add VisualComponents to visual dataPointVisual.Children.Add(highLow); dataPointVisual.Children.Add(openLine); dataPointVisual.Children.Add(closeLine); // Attach tooltip, events, href etc dataPointVisual.Opacity = dataPoint.Parent.Opacity * dataPoint.Opacity; Chart chart = dataPoint.Chart as Chart; dataPoint.SetCursor2DataPointVisualFaces(); dataPoint.AttachEvent2DataPointVisualFaces(dataPoint); dataPoint.AttachEvent2DataPointVisualFaces(dataPoint.Parent); dataPoint._parsedToolTipText = dataPoint.TextParser(dataPoint.ToolTipText); dataPoint.AttachToolTip(chart, dataPoint, dataPoint.Faces.VisualComponents); dataPoint.AttachHref(chart, dataPoint.Faces.VisualComponents, dataPoint.Href, (HrefTargets)dataPoint.HrefTarget); }
internal static void CreateOrUpdateAStockDataPoint(DataPoint dataPoint, Canvas stockChartCanvas, Canvas labelCanvas, Double canvasWidth, Double canvasHeight, Double dataPointWidth) { Faces dpFaces = dataPoint.Faces; // Remove preexisting dataPoint visual and label visual if (dpFaces != null && dpFaces.Visual != null && stockChartCanvas == dpFaces.Visual.Parent) { stockChartCanvas.Children.Remove(dataPoint.Faces.Visual); } // Remove preexisting label visual if (dataPoint.LabelVisual != null && dataPoint.LabelVisual.Parent == labelCanvas) { labelCanvas.Children.Remove(dataPoint.LabelVisual); } dataPoint.Faces = null; if (dataPoint.YValues == null || dataPoint.Enabled == false) return; // Initialize DataPoint faces dataPoint.Faces = new Faces(); // Creating ElementData for Tag ElementData tagElement = new ElementData() { Element = dataPoint }; // Create DataPoint Visual Canvas dataPointVisual = new Canvas(); // Create DataPoint Visual Line highLow = new Line(){ Tag = tagElement }; // Create High and Low Line Line closeLine = new Line(){ Tag = tagElement }; // Create Close Line Line openLine = new Line() { Tag = tagElement }; // Create Close Line dataPoint.Faces.Visual = dataPointVisual; // Add VisualComponents dataPoint.Faces.VisualComponents.Add(highLow); dataPoint.Faces.VisualComponents.Add(openLine); dataPoint.Faces.VisualComponents.Add(closeLine); // Add Border elements dataPoint.Faces.BorderElements.Add(highLow); dataPoint.Faces.BorderElements.Add(openLine); dataPoint.Faces.BorderElements.Add(closeLine); dataPoint.Faces.Visual = dataPointVisual; stockChartCanvas.Children.Add(dataPointVisual); UpdateYValueAndXValuePosition(dataPoint, canvasWidth, canvasHeight, dataPointWidth); ApplyBorderProperties(dataPoint, highLow, openLine, closeLine, dataPointWidth); ApplyOrUpdateColorForAStockDp(dataPoint, highLow, openLine, closeLine); // Add VisualComponents to visual dataPointVisual.Children.Add(highLow); dataPointVisual.Children.Add(openLine); dataPointVisual.Children.Add(closeLine); // Attach tooltip, events, href etc dataPointVisual.Opacity = dataPoint.Parent.Opacity * dataPoint.Opacity; Chart chart = dataPoint.Chart as Chart; dataPoint.SetCursor2DataPointVisualFaces(); dataPoint.AttachEvent2DataPointVisualFaces(dataPoint); dataPoint.AttachEvent2DataPointVisualFaces(dataPoint.Parent); dataPoint._parsedToolTipText = dataPoint.TextParser(dataPoint.ToolTipText); dataPoint.AttachToolTip(chart, dataPoint, dataPoint.Faces.VisualComponents); dataPoint.AttachHref(chart, dataPoint.Faces.VisualComponents, dataPoint.Href, (HrefTargets)dataPoint.HrefTarget); }
/// <summary> /// Create or update a CandleStick /// </summary> /// <param name="dataPoint"></param> /// <param name="seriesCanvas"></param> /// <param name="labelCanvas"></param> /// <param name="canvasWidth"></param> /// <param name="canvasHeight"></param> /// <param name="dataPointWidth"></param> internal static void CreateOrUpdateACandleStick(DataPoint dataPoint, Canvas candleStickCanvas, Canvas labelCanvas, Double canvasWidth, Double canvasHeight, Double dataPointWidth) { Faces dpFaces = dataPoint.Faces; // Remove preexisting dataPoint visual and label visual if (dpFaces != null && dpFaces.Visual != null && candleStickCanvas == dpFaces.Visual.Parent) { candleStickCanvas.Children.Remove(dataPoint.Faces.Visual); //dpFaces = null; } // Remove preexisting label visual if (dataPoint.LabelVisual != null && dataPoint.LabelVisual.Parent == labelCanvas) { labelCanvas.Children.Remove(dataPoint.LabelVisual); //dataPoint.LabelVisual = null; } dataPoint.Faces = null; if (dataPoint.InternalYValues == null || dataPoint.Enabled == false) { return; } // Creating ElementData for Tag ElementData tagElement = new ElementData() { Element = dataPoint }; // Initialize DataPoint faces dataPoint.Faces = new Faces(); // Create DataPoint Visual Canvas dataPointVisual = new Canvas(); dataPoint.Faces.Visual = dataPointVisual; // Create High and Low Line Line highLowLine = new Line() { Tag = tagElement }; dataPoint.Faces.Parts.Add(highLowLine); dataPoint.Faces.VisualComponents.Add(highLowLine); dataPointVisual.Children.Add(highLowLine); /* Create Open-Close Rectangle * Math.Max is used to make sure that the rectangle is visible * even when the difference between high and low is 0 */ Rectangle openCloseRect = new Rectangle() { Tag = tagElement }; dataPoint.Faces.VisualComponents.Add(openCloseRect); dataPoint.Faces.BorderElements.Add(openCloseRect); dataPointVisual.Children.Add(openCloseRect); UpdateYValueAndXValuePosition(dataPoint, canvasWidth, canvasHeight, dataPointWidth); // Add dataPointVisual to seriesCanvas candleStickCanvas.Children.Add(dataPointVisual); CreateAndPositionLabel(labelCanvas, dataPoint); dataPointVisual.Opacity = (Double)dataPoint.Parent.Opacity * (Double)dataPoint.Opacity; Chart chart = dataPoint.Chart as Chart; dataPoint.SetCursor2DataPointVisualFaces(); dataPoint.AttachEvent2DataPointVisualFaces(dataPoint); dataPoint.AttachEvent2DataPointVisualFaces(dataPoint.Parent); dataPoint._parsedToolTipText = dataPoint.TextParser(dataPoint.ToolTipText); if (!chart.IndicatorEnabled) { dataPoint.AttachToolTip(chart, dataPoint, dataPoint.Faces.VisualComponents); if (dataPoint.LabelVisual != null) { dataPoint.AttachToolTip(chart, dataPoint, dataPoint.LabelVisual); } } dataPoint.AttachHref(chart, dataPoint.Faces.VisualComponents, dataPoint.Href, (HrefTargets)dataPoint.HrefTarget); }
/// <summary> /// Create visual object of the Legend /// </summary> internal void CreateVisualObject() { if (!(Boolean)Enabled) { Visual = null; return; } ElementData tag = new ElementData { Element = this, VisualElementName = "Legend" }; Visual = new Border() { Tag = tag }; Grid innerGrid = new Grid() { Tag = tag }; (Visual as Border).Child = innerGrid; LegendContainer = new StackPanel() { Tag = tag }; if (!String.IsNullOrEmpty(Title)) { Title legendTitle = new Title(); ApplyFontProperty(legendTitle); if (TitleBackground != null) legendTitle.InternalBackground = TitleBackground; legendTitle.InternalHorizontalAlignment = TitleAlignmentX; legendTitle.InternalVerticalAlignment = VerticalAlignment.Top; legendTitle.TextAlignment = TitleTextAlignment; legendTitle.CreateVisualObject(tag); legendTitle.Measure(new Size(Double.MaxValue, Double.MaxValue)); if (legendTitle.DesiredSize.Width > InternalMaxWidth) legendTitle.Visual.Width = InternalMaxWidth; LegendContainer.Children.Add(legendTitle.Visual); } Grid legendContent = CreateLegendContent(); legendContent.Tag = tag; LegendContainer.Children.Add(legendContent); LegendContainer.VerticalAlignment = VerticalAlignment.Center; LegendContainer.HorizontalAlignment = HorizontalAlignment.Center; ApplyVisualProperty(); innerGrid.Children.Add(LegendContainer); Visual.Cursor = this.Cursor; Visual.Measure(new Size(Double.MaxValue, Double.MaxValue)); if (!Double.IsPositiveInfinity(InternalMaxHeight) && InternalMaxHeight < Visual.DesiredSize.Height) Visual.Height = InternalMaxHeight; else Visual.Height = Visual.DesiredSize.Height; if (!Double.IsPositiveInfinity(InternalMaxWidth) && InternalMaxWidth < Visual.DesiredSize.Width + InternalPadding.Left) Visual.Width = InternalMaxWidth; else Visual.Width = Visual.DesiredSize.Width + InternalPadding.Left; }