/// <summary> /// When a label is clicked, the corresponding PieDataPoint becomes selected. /// This enables master-detail scenario driven by clicking on labels. /// </summary> /// <param name="e"></param> protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { Chart chart = TreeHelper.FindAncestor <Chart>(this); if (chart != null) { PieSeries pieSeries = chart.Series.OfType <PieSeries>().FirstOrDefault(); if (pieSeries != null) { pieSeries.SelectedItem = this.Content; } } }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var currentElement = value as TextBlock; if (currentElement != null) { var label = TreeHelper.FindAncestor <PieChartLabel>(currentElement); if (label != null) { return(label.FormattedRatio); } } return(null); }
/// <summary> /// If at least one arc is small, all labels are displayed connected by a line. Otherwise, they're positioned /// in the arc midpoint. /// </summary> private void PositionAuto() { Chart chart = TreeHelper.FindAncestor <Chart>(this); if (chart != null) { PieChartLabelArea labelArea = chart.Template.FindName("LabelArea_PART", chart) as PieChartLabelArea; if (labelArea != null && labelArea.HasSmallArc) { this.PositionConnected(); } else { this.PositionArcMidpoint(); } } }
private static void IsLabeledPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) { bool isLabeled = (bool)e.NewValue; if (isLabeled == true) { PieDataPoint pieDataPoint = obj as PieDataPoint; if (pieDataPoint != null) { Chart chart = TreeHelper.FindAncestor <Chart>(pieDataPoint.Parent as DependencyObject); if (chart != null) { Canvas labelArea = chart.Template.FindName("LabelArea_PART", chart) as Canvas; if (labelArea != null) { AddLabel(pieDataPoint, labelArea); } } } } }
/// <summary> /// Creates a new PieChartLabel control and adds it to the "LabelArea_PART" canvas. /// </summary> /// <param name="pieDataPoint">PieDataPoint that corresponds to PieChartLabel.</param> /// <param name="labelStyle">The style to be applied to the PieChartLabel.</param> /// <param name="labelArea">The canvas where PieChartLabel will be added.</param> private static void AddLabel(PieDataPoint pieDataPoint, Panel labelArea) { PieChartLabel label = new PieChartLabel(); Style pieChartLabelStyle; DataTemplate pieChartLabelItemTemplate; LabeledPieChart chart = TreeHelper.FindAncestor <LabeledPieChart>(pieDataPoint); if (chart != null) { pieChartLabelStyle = chart.PieChartLabelStyle; if (pieChartLabelStyle != null) { label.Style = pieChartLabelStyle; } pieChartLabelItemTemplate = chart.PieChartLabelItemTemplate; if (pieChartLabelItemTemplate != null) { label.ContentTemplate = pieChartLabelItemTemplate; } } Binding contentBinding = new Binding("DataContext") { Source = pieDataPoint }; label.SetBinding(ContentControl.ContentProperty, contentBinding); Binding dataContextBinding = new Binding("DataContext") { Source = pieDataPoint }; label.SetBinding(ContentControl.DataContextProperty, contentBinding); Binding formattedRatioBinding = new Binding("FormattedRatio") { Source = pieDataPoint }; label.SetBinding(PieChartLabel.FormattedRatioProperty, formattedRatioBinding); Binding visibilityBinding = new Binding("Ratio") { Source = pieDataPoint, Converter = new DoubleToVisibilityConverter() }; label.SetBinding(PieChartLabel.VisibilityProperty, visibilityBinding); Binding geometryBinding = new Binding("Geometry") { Source = pieDataPoint }; label.SetBinding(PieChartLabel.GeometryProperty, geometryBinding); Binding displayModeBinding = new Binding("LabelDisplayMode") { Source = chart }; label.SetBinding(PieChartLabel.DisplayModeProperty, displayModeBinding); labelArea.Children.Add(label); pieDataPoint.Loaded += delegate { if (label.Parent == null) { labelArea.Children.Add(label); } }; pieDataPoint.LayoutUpdated += delegate { if (!pieDataPoint.IsInTree()) { labelArea.Children.Remove(label); } }; //pieDataPoint.Unloaded += delegate //{ // labelArea.Children.Remove(label); //}; }