private Path getPiece() { if ((piece == cross)) { Path lines = new Path(); LineGeometry line1 = new LineGeometry(); LineGeometry line2 = new LineGeometry(); GeometryGroup linegroup = new GeometryGroup(); line1.StartPoint = new Point(0, 0); line1.EndPoint = new Point(60, 60); line2.StartPoint = new Point(60, 0); line2.EndPoint = new Point(0, 60); linegroup.Children.Add(line1); linegroup.Children.Add(line2); lines.Data = linegroup; lines.Stroke = new SolidColorBrush(Colors.Red); lines.StrokeThickness = 5; lines.Margin = new Thickness(10); return lines; } else { EllipseGeometry ellipse = new EllipseGeometry(); Path circle = new Path(); ellipse.Center = new Point(30, 30); ellipse.RadiusX = 30; ellipse.RadiusY = 30; circle.Data = ellipse; circle.Stroke = new SolidColorBrush(Colors.Blue); circle.StrokeThickness = 5; circle.Margin = new Thickness(10); return circle; } }
public static void AddEllipseGeometry( this D2D.GeometrySink sink, Jupiter.Media.EllipseGeometry ellipseGeometry) { // Start the ellipse at 9 o'clock. sink.BeginFigure( new Vector2( (float)(ellipseGeometry.Center.X - ellipseGeometry.RadiusX), (float)(ellipseGeometry.Center.Y)), D2D.FigureBegin.Filled); // Do almost full ellipse in one arc (there is .00001 pixel size missing) sink.AddArc( new D2D.ArcSegment { Point = new Vector2( (float)(ellipseGeometry.Center.X - ellipseGeometry.RadiusX), (float)(ellipseGeometry.Center.Y + 0.00001)), Size = new Size2F( (float)(ellipseGeometry.RadiusX * 2), (float)(ellipseGeometry.RadiusY * 2)), RotationAngle = 0, SweepDirection = D2D.SweepDirection.Clockwise, ArcSize = D2D.ArcSize.Large }); // Close the ellipse sink.EndFigure(D2D.FigureEnd.Closed); }
public static void Write(this StreamGeometryContext ctx, EllipseGeometry ellipseGeometry) { // TODO - for some reason the following code is crashing on iOS. // https://github.com/unoplatform/uno/issues/6849 //var cx = ellipseGeometry.Center.X; //var cy = ellipseGeometry.Center.Y; //var rx = ellipseGeometry.RadiusX; //var ry = ellipseGeometry.RadiusY; //ctx.BeginFigure(new Point(cx, cy - ry), true, true); //ctx.ArcTo(new Point(cx, cy + ry), new Size(rx, ry), 0, false, SweepDirection.Counterclockwise, true, false); //ctx.ArcTo(new Point(cx, cy - ry), new Size(rx, ry), 0, false, SweepDirection.Counterclockwise, true, false); //ctx.SetClosedState(true); }
/// <summary> /// Updates the PieDataPoint's Geometry property. /// </summary> /// <param name="pieDataPoint">PieDataPoint instance.</param> /// <param name="plotAreaWidth">PlotArea width.</param> /// <param name="plotAreaHeight">PlotArea height.</param> internal static void UpdatePieDataPointGeometry(PieDataPoint pieDataPoint, double plotAreaWidth, double plotAreaHeight) { double diameter = (plotAreaWidth < plotAreaHeight) ? plotAreaWidth : plotAreaHeight; diameter *= 0.95; double plotAreaRadius = diameter / 2; double maxDistanceFromCenter = 0.0; double sliceRadius = plotAreaRadius - maxDistanceFromCenter; Point translatePoint = new Point(plotAreaWidth / 2, plotAreaHeight / 2); if (pieDataPoint.ActualRatio == 1) { foreach (DependencyProperty dependencyProperty in new DependencyProperty[] { PieDataPoint.GeometryProperty, PieDataPoint.GeometrySelectionProperty, PieDataPoint.GeometryHighlightProperty }) { Geometry geometry = new EllipseGeometry { Center = translatePoint, RadiusX = sliceRadius, RadiusY = sliceRadius }; pieDataPoint.SetValue(dependencyProperty, geometry); } } else { if (pieDataPoint.ActualRatio == 0.0) { pieDataPoint.Geometry = null; pieDataPoint.GeometryHighlight = null; pieDataPoint.GeometrySelection = null; } else { double ratio = pieDataPoint.ActualRatio; double offsetRatio = pieDataPoint.ActualOffsetRatio; double currentRatio = offsetRatio + ratio; Point offsetRatioPoint = ConvertRatioOfRotationToPoint(offsetRatio, sliceRadius, sliceRadius); Point adjustedOffsetRatioPoint = offsetRatioPoint.Translate(translatePoint); // Calculate the last clockwise point in the pie slice Point currentRatioPoint = ConvertRatioOfRotationToPoint(currentRatio, sliceRadius, sliceRadius); // Adjust point using center of plot area as origin // instead of 0,0 Point adjustedCurrentRatioPoint = currentRatioPoint.Translate(translatePoint); foreach (DependencyProperty dependencyProperty in new DependencyProperty[] { PieDataPoint.GeometryProperty, PieDataPoint.GeometrySelectionProperty, PieDataPoint.GeometryHighlightProperty }) { // Creating the pie slice geometry object PathFigure pathFigure = new PathFigure { IsClosed = true }; pathFigure.StartPoint = translatePoint; pathFigure.Segments.Add(new LineSegment { Point = adjustedOffsetRatioPoint }); bool isLargeArc = (currentRatio - offsetRatio) > 0.5; pathFigure.Segments.Add( new ArcSegment { Point = adjustedCurrentRatioPoint, IsLargeArc = isLargeArc, Size = new Size(sliceRadius, sliceRadius), SweepDirection = SweepDirection.Clockwise }); PathGeometry pathGeometry = new PathGeometry(); pathGeometry.Figures.Add(pathFigure); pieDataPoint.SetValue(dependencyProperty, pathGeometry); } } } }
public static WMedia.Geometry ToWindows(this Geometry geometry) { WMedia.Geometry wGeometry = null; if (geometry is LineGeometry) { LineGeometry lineGeometry = geometry as LineGeometry; wGeometry = new WMedia.LineGeometry { StartPoint = lineGeometry.StartPoint.ToWindows(), EndPoint = lineGeometry.EndPoint.ToWindows() }; } else if (geometry is RectangleGeometry) { var rect = (geometry as RectangleGeometry).Rect; wGeometry = new WMedia.RectangleGeometry { Rect = new WFoundation.Rect(rect.X, rect.Y, rect.Width, rect.Height) }; } else if (geometry is EllipseGeometry) { EllipseGeometry ellipseGeometry = geometry as EllipseGeometry; wGeometry = new WMedia.EllipseGeometry { Center = ellipseGeometry.Center.ToWindows(), RadiusX = ellipseGeometry.RadiusX, RadiusY = ellipseGeometry.RadiusY }; } else if (geometry is GeometryGroup) { GeometryGroup geometryGroup = geometry as GeometryGroup; wGeometry = new WMedia.GeometryGroup { FillRule = ConvertFillRule(geometryGroup.FillRule) }; foreach (Geometry children in geometryGroup.Children) { WMedia.Geometry winChild = children.ToWindows(); (wGeometry as WMedia.GeometryGroup).Children.Add(winChild); } } else if (geometry is PathGeometry) { PathGeometry pathGeometry = geometry as PathGeometry; WMedia.PathGeometry wPathGeometry = new WMedia.PathGeometry { FillRule = ConvertFillRule(pathGeometry.FillRule) }; foreach (PathFigure xamPathFigure in pathGeometry.Figures) { WMedia.PathFigure wPathFigure = new WMedia.PathFigure { StartPoint = xamPathFigure.StartPoint.ToWindows(), IsFilled = xamPathFigure.IsFilled, IsClosed = xamPathFigure.IsClosed }; wPathGeometry.Figures.Add(wPathFigure); foreach (PathSegment pathSegment in xamPathFigure.Segments) { // LineSegment if (pathSegment is LineSegment) { LineSegment lineSegment = pathSegment as LineSegment; WMedia.LineSegment winSegment = new WMedia.LineSegment { Point = lineSegment.Point.ToWindows() }; wPathFigure.Segments.Add(winSegment); } // PolylineSegment if (pathSegment is PolyLineSegment) { PolyLineSegment polyLineSegment = pathSegment as PolyLineSegment; WMedia.PolyLineSegment wSegment = new WMedia.PolyLineSegment(); foreach (var point in polyLineSegment.Points) { wSegment.Points.Add(point.ToWindows()); } wPathFigure.Segments.Add(wSegment); } // BezierSegment if (pathSegment is BezierSegment) { BezierSegment bezierSegment = pathSegment as BezierSegment; WMedia.BezierSegment wSegment = new WMedia.BezierSegment { Point1 = bezierSegment.Point1.ToWindows(), Point2 = bezierSegment.Point2.ToWindows(), Point3 = bezierSegment.Point3.ToWindows() }; wPathFigure.Segments.Add(wSegment); } // PolyBezierSegment else if (pathSegment is PolyBezierSegment) { PolyBezierSegment polyBezierSegment = pathSegment as PolyBezierSegment; WMedia.PolyBezierSegment wSegment = new WMedia.PolyBezierSegment(); foreach (var point in polyBezierSegment.Points) { wSegment.Points.Add(point.ToWindows()); } wPathFigure.Segments.Add(wSegment); } // QuadraticBezierSegment if (pathSegment is QuadraticBezierSegment) { QuadraticBezierSegment quadraticBezierSegment = pathSegment as QuadraticBezierSegment; WMedia.QuadraticBezierSegment wSegment = new WMedia.QuadraticBezierSegment { Point1 = quadraticBezierSegment.Point1.ToWindows(), Point2 = quadraticBezierSegment.Point2.ToWindows() }; wPathFigure.Segments.Add(wSegment); } // PolyQuadraticBezierSegment else if (pathSegment is PolyQuadraticBezierSegment) { PolyQuadraticBezierSegment polyQuadraticBezierSegment = pathSegment as PolyQuadraticBezierSegment; WMedia.PolyQuadraticBezierSegment wSegment = new WMedia.PolyQuadraticBezierSegment(); foreach (var point in polyQuadraticBezierSegment.Points) { wSegment.Points.Add(point.ToWindows()); } wPathFigure.Segments.Add(wSegment); } // ArcSegment else if (pathSegment is ArcSegment) { ArcSegment arcSegment = pathSegment as ArcSegment; WMedia.ArcSegment wSegment = new WMedia.ArcSegment { Size = new WFoundation.Size(arcSegment.Size.Width, arcSegment.Size.Height), RotationAngle = arcSegment.RotationAngle, IsLargeArc = arcSegment.IsLargeArc, SweepDirection = arcSegment.SweepDirection == SweepDirection.Clockwise ? WMedia.SweepDirection.Clockwise : WMedia.SweepDirection.Counterclockwise, Point = arcSegment.Point.ToWindows() }; wPathFigure.Segments.Add(wSegment); } } } wGeometry = wPathGeometry; } return(wGeometry); }
public object ConvertToNative(Geometry geometry) { winMedia.Geometry winGeometry = null; // Determine what type of geometry we're dealing with. if (geometry is LineGeometry) { LineGeometry xamGeometry = geometry as LineGeometry; winGeometry = new winMedia.LineGeometry { StartPoint = ConvertPoint(xamGeometry.StartPoint), EndPoint = ConvertPoint(xamGeometry.EndPoint) }; } else if (geometry is RectangleGeometry) { Rect rect = (geometry as RectangleGeometry).Rect; winGeometry = new winMedia.RectangleGeometry { Rect = new winFound.Rect(rect.X, rect.Y, rect.Width, rect.Height) }; } else if (geometry is EllipseGeometry) { EllipseGeometry xamGeometry = geometry as EllipseGeometry; winGeometry = new winMedia.EllipseGeometry { Center = ConvertPoint(xamGeometry.Center), RadiusX = xamGeometry.RadiusX, RadiusY = xamGeometry.RadiusY }; } else if (geometry is GeometryGroup) { GeometryGroup xamGeometry = geometry as GeometryGroup; winGeometry = new winMedia.GeometryGroup { FillRule = ConvertFillRule(xamGeometry.FillRule) }; foreach (Geometry xamChild in xamGeometry.Children) { winMedia.Geometry winChild = ConvertToNative(xamChild) as winMedia.Geometry; (winGeometry as winMedia.GeometryGroup).Children.Add(winChild); } } else if (geometry is PathGeometry) { PathGeometry xamPathGeometry = geometry as PathGeometry; winMedia.PathGeometry winPathGeometry = new winMedia.PathGeometry { FillRule = ConvertFillRule(xamPathGeometry.FillRule) }; foreach (PathFigure xamPathFigure in xamPathGeometry.Figures) { winMedia.PathFigure winPathFigure = new winMedia.PathFigure { StartPoint = ConvertPoint(xamPathFigure.StartPoint), IsFilled = xamPathFigure.IsFilled, IsClosed = xamPathFigure.IsClosed }; winPathGeometry.Figures.Add(winPathFigure); foreach (PathSegment xamPathSegment in xamPathFigure.Segments) { // LineSegment if (xamPathSegment is LineSegment) { LineSegment xamSegment = xamPathSegment as LineSegment; winMedia.LineSegment winSegment = new winMedia.LineSegment { Point = ConvertPoint(xamSegment.Point) }; winPathFigure.Segments.Add(winSegment); } // PolylineSegment if (xamPathSegment is PolyLineSegment) { PolyLineSegment xamSegment = xamPathSegment as PolyLineSegment; winMedia.PolyLineSegment winSegment = new winMedia.PolyLineSegment(); foreach (Point point in xamSegment.Points) { winSegment.Points.Add(ConvertPoint(point)); } winPathFigure.Segments.Add(winSegment); } // BezierSegment if (xamPathSegment is BezierSegment) { BezierSegment xamSegment = xamPathSegment as BezierSegment; winMedia.BezierSegment winSegment = new winMedia.BezierSegment { Point1 = ConvertPoint(xamSegment.Point1), Point2 = ConvertPoint(xamSegment.Point2), Point3 = ConvertPoint(xamSegment.Point3) }; winPathFigure.Segments.Add(winSegment); } // PolyBezierSegment else if (xamPathSegment is PolyBezierSegment) { PolyBezierSegment xamSegment = xamPathSegment as PolyBezierSegment; winMedia.PolyBezierSegment winSegment = new winMedia.PolyBezierSegment(); foreach (Point point in xamSegment.Points) { winSegment.Points.Add(ConvertPoint(point)); } winPathFigure.Segments.Add(winSegment); } // QuadraticBezierSegment if (xamPathSegment is QuadraticBezierSegment) { QuadraticBezierSegment xamSegment = xamPathSegment as QuadraticBezierSegment; winMedia.QuadraticBezierSegment winSegment = new winMedia.QuadraticBezierSegment { Point1 = ConvertPoint(xamSegment.Point1), Point2 = ConvertPoint(xamSegment.Point2), }; winPathFigure.Segments.Add(winSegment); } // PolyQuadraticBezierSegment else if (xamPathSegment is PolyQuadraticBezierSegment) { PolyQuadraticBezierSegment xamSegment = xamPathSegment as PolyQuadraticBezierSegment; winMedia.PolyQuadraticBezierSegment winSegment = new winMedia.PolyQuadraticBezierSegment(); foreach (Point point in xamSegment.Points) { winSegment.Points.Add(ConvertPoint(point)); } winPathFigure.Segments.Add(winSegment); } // ArcSegment else if (xamPathSegment is ArcSegment) { ArcSegment xamSegment = xamPathSegment as ArcSegment; winMedia.ArcSegment winSegment = new winMedia.ArcSegment(); winSegment.Size = new winFound.Size(xamSegment.Size.Width, xamSegment.Size.Height); winSegment.RotationAngle = xamSegment.RotationAngle; winSegment.IsLargeArc = xamSegment.IsLargeArc; winSegment.SweepDirection = xamSegment.SweepDirection == SweepDirection.Clockwise ? winMedia.SweepDirection.Clockwise : winMedia.SweepDirection.Counterclockwise; winSegment.Point = ConvertPoint(xamSegment.Point); winPathFigure.Segments.Add(winSegment); } } } winGeometry = winPathGeometry; } // Set transform. if (geometry.Transform != null) { winGeometry.Transform = (winMedia.Transform)geometry.Transform.GetNativeObject(); } return(winGeometry); }
/// <summary> /// Generates the pie chart. /// </summary> protected override void GenerateChart() { RootElement.Children.Clear(); var data = ItemsSource; var validData = data == null ? null : data.Where(d => d.Value > 0); if (validData != null && validData.Any()) { if (validData.Count() == 1) { // Only one valid dat ==> draw a circle int colorIndex = validData.Select((k, ind) => ind).FirstOrDefault(); var kvp = data.Where(d => d.Value > 0).First(); EllipseGeometry ellipseGeometry = new EllipseGeometry() { RadiusX = 1, RadiusY = 1 }; Path path = new Path() { Stretch = Stretch.Uniform, Fill = GetColorByIndex(colorIndex), Data = ellipseGeometry }; SetTooltip(path, kvp.Key, string.Format("{0} (100%)", FormattedValue(kvp.Value))); RootElement.Children.Add(path); } else { //We have more than one value to display. Generate pie shapes: var total = validData.Sum(d => d.Value); double current = 0; int colorIndex = 0; const double offset = 0; //Rotational offset (set it to Math.PI * .5 to start first segment upwards, set it to 0 to look like arcgis.com) foreach (var kvp in data) { var val = kvp.Value; if (val <= 0.0) // not valid { colorIndex++; continue; } var fraction = val / total; double angle0 = 2 * Math.PI * current - offset; double angle1 = 2 * Math.PI * (current + fraction) - offset; PathFigure pathFigure = new PathFigure {IsClosed = true, StartPoint = new Point(1, 1)}; pathFigure.Segments.Add(new LineSegment { Point = new Point(Math.Cos(angle0) + 1, Math.Sin(angle0) + 1) }); bool isLargeArc = fraction > .5; pathFigure.Segments.Add( new ArcSegment { Point = new Point(Math.Cos(angle1) + 1, Math.Sin(angle1) + 1), IsLargeArc = isLargeArc, Size = new Size(1, 1), SweepDirection = SweepDirection.Clockwise }); pathFigure.Segments.Add(new LineSegment() { Point = new Point(1, 1) }); //Add these two empty line segments to force the drawing to stretch properly //with 1,1 at the center ( 0,0->2,2 is the bounding box for the figure) PathFigure pathFigure2 = new PathFigure() { StartPoint = new Point(0, 0) }; pathFigure2.Segments.Add(new LineSegment() { Point = new Point(0, 0) }); PathFigure pathFigure3 = new PathFigure() { StartPoint = new Point(2, 2) }; pathFigure3.Segments.Add(new LineSegment() { Point = new Point(2, 2) }); PathGeometry pathGeometry = new PathGeometry(); pathGeometry.Figures.Add(pathFigure2); pathGeometry.Figures.Add(pathFigure3); pathGeometry.Figures.Add(pathFigure); Path path = new Path() { Stretch = Stretch.Uniform, Fill = GetColorByIndex(colorIndex), Data = pathGeometry }; // Add outline separating pie slices PathFigure outLineFigure = new PathFigure { IsClosed = false, StartPoint = new Point(1, 1) }; outLineFigure.Segments.Add(new LineSegment() { Point = new Point(Math.Cos(angle0) + 1, Math.Sin(angle0) + 1) }); //Add these two empty line segments to force the drawing to stretch properly //with 1,1 at the center ( 0,0->2,2 is the bounding box for the figure) PathFigure outLineFigure2 = new PathFigure() { StartPoint = new Point(0, 0) }; outLineFigure2.Segments.Add(new LineSegment() { Point = new Point(0, 0) }); PathFigure outLineFigure3 = new PathFigure() { StartPoint = new Point(2, 2) }; outLineFigure3.Segments.Add(new LineSegment() { Point = new Point(2, 2) }); PathGeometry outLineGeometry = new PathGeometry(); outLineGeometry.Figures.Add(outLineFigure2); outLineGeometry.Figures.Add(outLineFigure3); outLineGeometry.Figures.Add(outLineFigure); Path outLine = new Path() { Fill = null, Stretch = Stretch.Uniform, Stroke = new SolidColorBrush(Colors.White), StrokeThickness = 1.0, Data = outLineGeometry }; SetTooltip(path, kvp.Key, string.Format("{0} ({1:0.##%})", FormattedValue(val), fraction)); RootElement.Children.Add(path); RootElement.Children.Add(outLine); current += fraction; colorIndex++; } } } }
public override Path CreateGrid() { Path _outline = base.CreateGrid(); _outline.Name = "RADIAL_GRID"; if (Dim1 == null || Dim2 == null) return _outline; GeometryGroup gg = new GeometryGroup(); Point origin = new Point(0, 0); double inc = (_dim1.Inc <= 0) ? 5 : _dim1.Inc; for (double r = _dim1.Start; r <= _dim1.End; r += inc) { EllipseGeometry eg = new EllipseGeometry(); eg.Center = origin; eg.RadiusX = eg.RadiusY = r; gg.Children.Add(eg); } inc = (_dim2.Inc <= 0) ? 5 : _dim2.Inc; for (double a = _dim2.Start; a <= _dim2.End; a += _dim2.Inc) { double aa = a * Math.PI / 180; double xs = _dim1.Start * Math.Cos(aa); double ys = _dim1.Start * Math.Sin(aa); Point start = new Point(xs, ys); double xe = _dim1.End * Math.Cos(aa); double ye = _dim1.End * Math.Sin(aa); Point end = new Point(xe, ye); LineGeometry lg = new LineGeometry(); lg.StartPoint = start; lg.EndPoint = end; gg.Children.Add(lg); } _outline.Data = gg; return _outline; }
/// <summary> /// Initializes a new instance of the <see cref="Arc"/> class" /// </summary> public Arc() { this.Stroke = new SolidColorBrush(Colors.White); this.StrokeThickness = 2; this.Fill = new SolidColorBrush(Colors.Red); this.UseLayoutRounding = true; this.pathGeometry = new PathGeometry(); this.pathFigure = new PathFigure(); this.pathFigure.IsClosed = true; this.pathFigure.IsFilled = true; this.arcSegment = new ArcSegment(); this.arcSegment.IsLargeArc = false; this.arcSegment.SweepDirection = SweepDirection.Clockwise; this.lineSegment = new LineSegment(); this.pathFigure.Segments.Add(this.arcSegment); this.pathFigure.Segments.Add(this.lineSegment); this.pathGeometry.Figures.Add(this.pathFigure); this.Data = this.pathGeometry; this.ellipseGeometry = new EllipseGeometry(); this.Tapped += this.OnArcTapped; }
private Geometry buildSingleItemPath(Point centerPoint) { GeometryGroup gg = new GeometryGroup(); EllipseGeometry outerEllipse = new EllipseGeometry(); outerEllipse.Center = centerPoint; outerEllipse.RadiusX = Radius; outerEllipse.RadiusY = Radius; gg.Children.Add(outerEllipse); if (InnerRadius != 0) { EllipseGeometry innerEllipse = new EllipseGeometry(); innerEllipse.Center = centerPoint; innerEllipse.RadiusX = InnerRadius; innerEllipse.RadiusY = InnerRadius; gg.Children.Add(innerEllipse); } return gg; }
private Path getPiece(int player) { if ((player == 1)) // Draw X { Path lines = new Path(); LineGeometry line1 = new LineGeometry(); LineGeometry line2 = new LineGeometry(); GeometryGroup linegroup = new GeometryGroup(); line1.StartPoint = new Point(0, 0); line1.EndPoint = new Point(30, 30); line2.StartPoint = new Point(30, 0); line2.EndPoint = new Point(0, 30); linegroup.Children.Add(line1); linegroup.Children.Add(line2); lines.Data = linegroup; lines.Stroke = new SolidColorBrush(Colors.Red); lines.StrokeThickness = 2; lines.Margin = new Thickness(4); return lines; } else // Draw O { EllipseGeometry ellipse = new EllipseGeometry(); Path circle = new Path(); ellipse.Center = new Point(15, 15); ellipse.RadiusX = 15; ellipse.RadiusY = 15; circle.Data = ellipse; circle.Stroke = new SolidColorBrush(Colors.Blue); circle.StrokeThickness = 2; circle.Margin = new Thickness(4); return circle; } }
public void CreateWorkOutline() { WorkOutline = new Windows.UI.Xaml.Shapes.Path(); GeometryGroup gg = new GeometryGroup(); Point origin = new Point(0, 0); EllipseGeometry eg = new EllipseGeometry(); eg.Center = origin; eg.RadiusX = eg.RadiusY = (_viewmodel.CurrentPathData as LatticeData).Layout.ClipRange.End; gg.Children.Add(eg); if ((_viewmodel.CurrentPathData as LatticeData).Layout.ClipRange.Start > 0) { eg = new EllipseGeometry(); eg.Center = origin; eg.RadiusX = eg.RadiusY = (_viewmodel.CurrentPathData as LatticeData).Layout.ClipRange.Start; gg.Children.Add(eg); } WorkOutline.Data = gg; WorkOutline.StrokeThickness = 1 / ScaleFactor; WorkOutline.Stroke = new SolidColorBrush(Colors.Wheat); WorkOutline.StrokeDashArray = new DoubleCollection() { 5, 5 }; WorkOutline.Name = "WorkOutline"; }
protected override void OnApplyTemplate() { Ellipse innerCircle = this.GetTemplateChild(INNER_CIRCLE_NAME) as Ellipse; if (innerCircle != null) { innerCircle.Width = innerCircle.Height = (Diameter - 2 * RingThickness); } Path fillPath = this.GetTemplateChild(FILL_PATH_NAME) as Path; if (fillPath != null) { double radius = Diameter / 2.0; if (PercentageComplete < 100) { PathGeometry pieSlice = new PathGeometry(); PathFigure path = new PathFigure(); path.StartPoint = new Point(radius, radius); LineSegment startLine = new LineSegment(); startLine.Point = new Point(radius, 0.0d); ArcSegment arc = new ArcSegment(); arc.Size = new Size(radius, radius); arc.SweepDirection = SweepDirection; arc.Point = GetEndPoint(); arc.IsLargeArc = PercentageComplete > 50 ? true : false; path.Segments.Add(startLine); path.Segments.Add(arc); path.IsClosed = true; pieSlice.Figures.Add(path); fillPath.Data = pieSlice; } else { EllipseGeometry fullCircle = new EllipseGeometry(); fullCircle.Center = new Point(radius, radius); fullCircle.RadiusX = fullCircle.RadiusY = radius; fillPath.Data = fullCircle; } fillPath.Fill = GetInterpolatedBrush(); } TextBlock dataText = this.GetTemplateChild(INFO_TEXT_NAME) as TextBlock; if (dataText != null) { dataText.Text = (PercentageComplete / 100).ToString("P0"); } base.OnApplyTemplate(); }