private double LayoutSection(PieSection section, int sectionNumber, double sectionStartAngle) { // calculate section area based on its weight double sectionsAngle = (360d * section.SectionWeight) / TotalWeight; double sectionEndAngle = sectionStartAngle + sectionsAngle; // draw section Color sectionColor = SectionColors[sectionNumber % SectionColors.Length]; sectionColor.A = 0x20; DrawPieSection(sectionStartAngle, sectionEndAngle, sectionColor, true); // draw matching double matchingEndAngle = sectionStartAngle + ((sectionsAngle * section.MatchingPercentage) / 100d); sectionColor.A = 0xFF; DrawPieSection(sectionStartAngle, matchingEndAngle, sectionColor, false); // labels double topProperty = TopLabelsSection + ((LabelsFontSize + LabelsGap) * sectionNumber); RectangleGeometry labelRect = new RectangleGeometry { Rect = new Rect(0d, 0d, LabelsRectangleRadius, LabelsRectangleRadius) }; Path pathLabelRect = new Path { Fill = new SolidColorBrush(sectionColor), Data = labelRect, Stroke = PieStroke, StrokeThickness = StrokeThickness, }; Canvas.SetTop(pathLabelRect, topProperty); Canvas.SetLeft(pathLabelRect, LeftLabelsSection); this.Children.Add(pathLabelRect); double leftProperty = LeftLabelsSection + (LabelsRectangleRadius + LabelsGap); TextBlock label = new TextBlock { Text = string.Format(CultureInfo.CurrentUICulture, "{0} ({1} %)", section.Description, section.MatchingPercentage), FontSize = LabelsFontSize }; Canvas.SetTop(label, topProperty); Canvas.SetLeft(label, leftProperty); this.Children.Add(label); return(sectionEndAngle); }
private double LayoutSection(PieSection section, int sectionNumber, double sectionStartAngle) { // calculate section area based on its weight double sectionsAngle = (360d * section.SectionWeight) / TotalWeight; double sectionEndAngle = sectionStartAngle + sectionsAngle; // draw section Color sectionColor = SectionColors[sectionNumber % SectionColors.Length]; sectionColor.A = 0x20; DrawPieSection(sectionStartAngle, sectionEndAngle, sectionColor, true); // draw matching double matchingEndAngle = sectionStartAngle + ((sectionsAngle * section.MatchingPercentage) / 100d); sectionColor.A = 0xFF; DrawPieSection(sectionStartAngle, matchingEndAngle, sectionColor, false); // labels double topProperty = TopLabelsSection + ((LabelsFontSize + LabelsGap) * sectionNumber); RectangleGeometry labelRect = new RectangleGeometry { Rect = new Rect(0d, 0d, LabelsRectangleRadius, LabelsRectangleRadius) }; Path pathLabelRect = new Path { Fill = new SolidColorBrush(sectionColor), Data = labelRect, Stroke = PieStroke, StrokeThickness = StrokeThickness, }; Canvas.SetTop(pathLabelRect, topProperty); Canvas.SetLeft(pathLabelRect, LeftLabelsSection); this.Children.Add(pathLabelRect); double leftProperty = LeftLabelsSection + (LabelsRectangleRadius + LabelsGap); TextBlock label = new TextBlock { Text = string.Format(CultureInfo.CurrentUICulture, "{0} ({1} %)", section.Description, section.MatchingPercentage), FontSize = LabelsFontSize }; Canvas.SetTop(label, topProperty); Canvas.SetLeft(label, leftProperty); this.Children.Add(label); return sectionEndAngle; }