/// <summary> /// Place label for DataPoint /// </summary> /// <param name="visual">Visual</param> /// <param name="labelCanvas">Canvas for label</param> /// <param name="dataPoint">DataPoint</param> internal static void CreateAndPositionLabel(Canvas labelCanvas, DataPoint dataPoint) { if (dataPoint.LabelVisual != null) { Panel parent = dataPoint.LabelVisual.Parent as Panel; if (parent != null) { parent.Children.Remove(dataPoint.LabelVisual); } } if ((Boolean)dataPoint.LabelEnabled && !String.IsNullOrEmpty(dataPoint.LabelText)) { Canvas dataPointVisual = dataPoint.Faces.Visual as Canvas; Title tb = new Title() { Text = dataPoint.TextParser(dataPoint.LabelText), FontFamily = dataPoint.LabelFontFamily, FontSize = dataPoint.LabelFontSize.Value, FontWeight = (FontWeight)dataPoint.LabelFontWeight, FontStyle = (FontStyle)dataPoint.LabelFontStyle, Background = dataPoint.LabelBackground, FontColor = Chart.CalculateDataPointLabelFontColor(dataPoint.Chart as Chart, dataPoint, dataPoint.LabelFontColor, LabelStyles.OutSide) }; tb.CreateVisualObject(new ElementData() { Element = dataPoint }); tb.Visual.Height = tb.Height; tb.Visual.Width = tb.Width; dataPoint.LabelVisual = tb.Visual; // Double labelTop = (Double)dataPointVisual.GetValue(Canvas.TopProperty) - tb.Height; // Double labelLeft = (Double)dataPointVisual.GetValue(Canvas.LeftProperty) + (dataPointVisual.Width - tb.Width) / 2; // if (labelTop < 0) labelTop = (Double)dataPointVisual.GetValue(Canvas.TopProperty); // if (labelLeft < 0) labelLeft = 1; // if (labelLeft + tb.ActualWidth > labelCanvas.Width) // labelLeft = labelCanvas.Width - tb.ActualWidth - 2; // tb.Visual.SetValue(Canvas.LeftProperty, labelLeft); // tb.Visual.SetValue(Canvas.TopProperty, labelTop); SetLabelPosition(dataPoint, labelCanvas.Width, labelCanvas.Height); labelCanvas.Children.Add(tb.Visual); } }
private static void CreateOrUpdateAPointDataPoint(Canvas bubleChartCanvas, DataPoint dataPoint, Double minimumZVal, Double maximumZVal, Double plotWidth, Double plotHeight) { Faces dpFaces = dataPoint.Faces; // Remove preexisting dataPoint visual and label visual if (dpFaces != null && dpFaces.Visual != null && bubleChartCanvas == dpFaces.Visual.Parent) { bubleChartCanvas.Children.Remove(dataPoint.Faces.Visual); // dpFaces = null; } dataPoint.Faces = null; if (Double.IsNaN(dataPoint.InternalYValue) || (dataPoint.Enabled == false)) { return; } Chart chart = dataPoint.Chart as Chart; PlotGroup plotGroup = dataPoint.Parent.PlotGroup; Canvas dataPointVisual = new Canvas(); Faces bubbleFaces = new Faces(); Double xPosition = Graphics.ValueToPixelPosition(0, plotWidth, (Double)plotGroup.AxisX.InternalAxisMinimum, (Double)plotGroup.AxisX.InternalAxisMaximum, dataPoint.InternalXValue); Double yPosition = Graphics.ValueToPixelPosition(plotHeight, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, dataPoint.InternalYValue); Brush markerColor = dataPoint.Color; markerColor = (chart.View3D ? Graphics.Get3DBrushLighting(markerColor, (Boolean)dataPoint.LightingEnabled) : ((Boolean)dataPoint.LightingEnabled ? Graphics.GetLightingEnabledBrush(markerColor, "Linear", null) : markerColor)); String labelText = (Boolean)dataPoint.LabelEnabled ? dataPoint.TextParser(dataPoint.LabelText) : ""; Marker marker = new Marker((MarkerTypes)dataPoint.MarkerType, 1, new Size(6, 6), false, markerColor, labelText); dataPoint.Marker = marker; ApplyZValue(dataPoint, minimumZVal, maximumZVal, plotWidth, plotHeight); marker.ShadowEnabled = (Boolean)dataPoint.ShadowEnabled; if (dataPoint.BorderColor != null) { marker.BorderColor = dataPoint.BorderColor; } marker.TextBackground = dataPoint.LabelBackground; marker.BorderThickness = ((Thickness)dataPoint.MarkerBorderThickness).Left; marker.TextAlignmentX = AlignmentX.Center; marker.TextAlignmentY = AlignmentY.Center; marker.Tag = new ElementData() { Element = dataPoint }; Double gap = ((Double)dataPoint.MarkerScale * (Double)dataPoint.MarkerSize) / 2; if (!String.IsNullOrEmpty(labelText)) { marker.FontColor = Chart.CalculateDataPointLabelFontColor(chart, dataPoint, dataPoint.LabelFontColor, LabelStyles.OutSide); marker.FontSize = (Double)dataPoint.LabelFontSize; marker.FontWeight = (FontWeight)dataPoint.LabelFontWeight; marker.FontFamily = dataPoint.LabelFontFamily; marker.FontStyle = (FontStyle)dataPoint.LabelFontStyle; marker.TextBackground = dataPoint.LabelBackground; marker.TextAlignmentX = AlignmentX.Center; marker.TextAlignmentY = AlignmentY.Center; if (!Double.IsNaN(dataPoint.LabelAngle) && dataPoint.LabelAngle != 0) { marker.LabelAngle = dataPoint.LabelAngle; marker.TextOrientation = Orientation.Vertical; marker.TextAlignmentX = AlignmentX.Center; marker.TextAlignmentY = AlignmentY.Center; marker.LabelStyle = (LabelStyles)dataPoint.LabelStyle; } marker.CreateVisual(); if (Double.IsNaN(dataPoint.LabelAngle) || dataPoint.LabelAngle == 0) { if (yPosition - gap < 0 && (yPosition - marker.TextBlockSize.Height / 2) < 0) { marker.TextAlignmentY = AlignmentY.Bottom; } else if (yPosition + gap > plotHeight && (yPosition + marker.TextBlockSize.Height / 2) > plotHeight) { marker.TextAlignmentY = AlignmentY.Top; } if (xPosition - gap < 0 && (xPosition - marker.TextBlockSize.Width / 2) < 0) { marker.TextAlignmentX = AlignmentX.Right; } else if (xPosition + gap > plotWidth && (xPosition + marker.TextBlockSize.Width / 2) > plotWidth) { marker.TextAlignmentX = AlignmentX.Left; } } } marker.PixelLavelShadow = false; // pixelLavelShadow; marker.CreateVisual(); UpdateBubblePositionAccording2XandYValue(dataPoint, plotWidth, plotHeight, false, 0, 0); bubleChartCanvas.Children.Add(marker.Visual); bubbleFaces.Parts.Add(marker.MarkerShape); bubbleFaces.VisualComponents.Add(marker.Visual); bubbleFaces.BorderElements.Add(marker.MarkerShape); bubbleFaces.Visual = marker.Visual; dataPoint.Faces = bubbleFaces; dataPoint.Faces.Visual.Opacity = dataPoint.Opacity * dataPoint.Parent.Opacity; 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); dataPoint.SetCursor2DataPointVisualFaces(); if (dataPoint.Parent.SelectionEnabled && dataPoint.Selected) { dataPoint.Select(true); } }
// Canvas bubleChartCanvas, DataPoint dataPoint, Double minimumZVal, Double maximumZVal, Double plotWidth, Double plotHeight private static void CreateOrUpdateAPointDataPoint(Canvas pointChartCanvas, DataPoint dataPoint, Double plotAreaWidth, Double plotAreaHeight) { Faces dpFaces = dataPoint.Faces; // Remove preexisting dataPoint visual and label visual if (dpFaces != null && dpFaces.Visual != null && pointChartCanvas == dpFaces.Visual.Parent) { pointChartCanvas.Children.Remove(dataPoint.Faces.Visual); //dpFaces = null; } dataPoint.Faces = null; dpFaces = new Faces(); if (Double.IsNaN(dataPoint.InternalYValue) || (dataPoint.Enabled == false)) { return; } Chart chart = dataPoint.Chart as Chart; PlotGroup plotGroup = dataPoint.Parent.PlotGroup; Double xPosition = Graphics.ValueToPixelPosition(0, plotAreaWidth, (Double)plotGroup.AxisX.InternalAxisMinimum, (Double)plotGroup.AxisX.InternalAxisMaximum, dataPoint.InternalXValue); Double yPosition = Graphics.ValueToPixelPosition(plotAreaHeight, 0, (Double)plotGroup.AxisY.InternalAxisMinimum, (Double)plotGroup.AxisY.InternalAxisMaximum, dataPoint.InternalYValue); Brush markerColor = dataPoint.Color; //markerColor = (chart.View3D ? Graphics.GetLightingEnabledBrush3D(markerColor) : // ((Boolean)dataPoint.LightingEnabled ? Graphics.GetLightingEnabledBrush(markerColor, "Linear", null) : markerColor)); markerColor = (chart.View3D ? Graphics.Get3DBrushLighting(dataPoint.Color, (Boolean)dataPoint.LightingEnabled) : ((Boolean)dataPoint.LightingEnabled ? Graphics.GetLightingEnabledBrush(markerColor, "Linear", null) : markerColor)); Size markerSize = new Size((Double)dataPoint.MarkerSize, (Double)dataPoint.MarkerSize); Boolean markerBevel = false; String labelText = (Boolean)dataPoint.LabelEnabled ? dataPoint.TextParser(dataPoint.LabelText) : ""; Marker marker = new Marker((MarkerTypes)dataPoint.MarkerType, (Double)dataPoint.MarkerScale, markerSize, markerBevel, markerColor, labelText); marker.Tag = new ElementData() { Element = dataPoint }; marker.ShadowEnabled = (Boolean)dataPoint.ShadowEnabled; if (!VisifireControl.IsMediaEffectsEnabled) { marker.PixelLavelShadow = false; } else { marker.PixelLavelShadow = true; } marker.MarkerSize = new Size((Double)dataPoint.MarkerSize, (Double)dataPoint.MarkerSize); if (marker.MarkerType != MarkerTypes.Cross) { if (dataPoint.BorderColor != null) { marker.BorderColor = dataPoint.BorderColor; } } else { marker.BorderColor = markerColor; } marker.BorderThickness = ((Thickness)dataPoint.MarkerBorderThickness).Left; if (!String.IsNullOrEmpty(labelText)) { marker.FontColor = Chart.CalculateDataPointLabelFontColor(chart, dataPoint, dataPoint.LabelFontColor, LabelStyles.OutSide); marker.FontSize = (Double)dataPoint.LabelFontSize; marker.FontWeight = (FontWeight)dataPoint.LabelFontWeight; marker.FontFamily = dataPoint.LabelFontFamily; marker.FontStyle = (FontStyle)dataPoint.LabelFontStyle; marker.TextBackground = dataPoint.LabelBackground; marker.TextAlignmentX = AlignmentX.Center; marker.TextAlignmentY = AlignmentY.Center; if (!Double.IsNaN(dataPoint.LabelAngle) && dataPoint.LabelAngle != 0) { marker.LabelAngle = dataPoint.LabelAngle; marker.TextOrientation = Orientation.Vertical; marker.TextAlignmentX = AlignmentX.Center; marker.TextAlignmentY = AlignmentY.Center; marker.LabelStyle = (LabelStyles)dataPoint.LabelStyle; } marker.CreateVisual(); if (Double.IsNaN(dataPoint.LabelAngle) || dataPoint.LabelAngle == 0) { if ((yPosition - marker.TextBlockSize.Height / 2) < 0) { marker.TextAlignmentY = AlignmentY.Bottom; } else if ((yPosition + marker.TextBlockSize.Height / 2) > plotAreaHeight) { marker.TextAlignmentY = AlignmentY.Top; } if ((xPosition - marker.TextBlockSize.Width / 2) < 0) { marker.TextAlignmentX = AlignmentX.Right; } else if ((xPosition + marker.TextBlockSize.Width / 2) > plotAreaWidth) { marker.TextAlignmentX = AlignmentX.Left; } } } //marker.LabelEnabled =(Boolean) dataPoint.LabelEnabled; //marker.TextBackground = dataPoint.LabelBackground; //marker.FontColor = Chart.CalculateDataPointLabelFontColor(chart, dataPoint, dataPoint.LabelFontColor, LabelStyles.OutSide); //marker.FontSize = (Double)dataPoint.LabelFontSize; //marker.FontWeight = (FontWeight)dataPoint.LabelFontWeight; //marker.FontFamily = dataPoint.LabelFontFamily; //marker.FontStyle = (FontStyle)dataPoint.LabelFontStyle; //marker.TextAlignmentX = AlignmentX.Center; //marker.TextAlignmentY = AlignmentY.Center; marker.CreateVisual(); marker.Visual.Opacity = (Double)dataPoint.Opacity * (Double)dataPoint.Parent.Opacity; marker.AddToParent(pointChartCanvas, xPosition, yPosition, new Point(0.5, 0.5)); dataPoint._visualPosition = new Point(xPosition, yPosition); dpFaces.VisualComponents.Add(marker.Visual); dpFaces.Visual = marker.Visual; dpFaces.BorderElements.Add(marker.MarkerShape); dataPoint.Marker = marker; dataPoint.Faces = dpFaces; dataPoint.Faces.Visual.Opacity = (Double)dataPoint.Opacity * (Double)dataPoint.Parent.Opacity; dataPoint.AttachEvent2DataPointVisualFaces(dataPoint); dataPoint.AttachEvent2DataPointVisualFaces(dataPoint.Parent); dataPoint._parsedToolTipText = dataPoint.TextParser(dataPoint.ToolTipText); if (!chart.IndicatorEnabled) { dataPoint.AttachToolTip(chart, dataPoint, dataPoint.Faces.VisualComponents); } dataPoint.AttachHref(chart, dataPoint.Faces.VisualComponents, dataPoint.Href, (HrefTargets)dataPoint.HrefTarget); dataPoint.SetCursor2DataPointVisualFaces(); if (dataPoint.Parent.SelectionEnabled && dataPoint.Selected) { dataPoint.Select(true); } }