Пример #1
0
        public override void Draw(Canvas canvas)
        {
            base.Draw(canvas);

            if (this.BubbleData == null)
            {
                return;
            }

            if (this.Data == null)
            {
                return;
            }

            if (this.xAxis == null)
            {
                return;
            }

            for (int i = 0; i < this.xAxis.Count; i++)
            {
                double x = this.xAxis[i];

                double y = this.Data[i];

                double v = this.BubbleData[i];

                //  Do :显示标记
                EllipseMarker m = Activator.CreateInstance(this.MarkStyle?.TargetType) as EllipseMarker;

                if (m != null)
                {
                    m.Style = this.MarkStyle;

                    m.Rect = new Rect(0, 0, v, v);

                    Canvas.SetLeft(m, this.GetX(x, this.ActualWidth));
                    Canvas.SetTop(m, this.GetY(y, this.ActualHeight));
                    this.Children.Add(m);

                    m.Tag = $"({x.ToString("G4")},{y.ToString("G4")})";
                }
            }

            //var items = this.GetChildren<FrameworkElement>().Where(l => l.RenderTransform is TransformGroup);

            //items = items.Where(l => (l.RenderTransform as TransformGroup).Children.Count == 4);

            //Storyboard storyboard = this.FindResource("sss") as Storyboard;

            //foreach (var item in items)
            //{
            //    storyboard?.Begin(item);
            //}
        }
Пример #2
0
        public override void Draw(Canvas canvas)
        {
            base.Draw(canvas);

            Point center = new Point(0, 0);

            for (int i = 0; i < this.Data.Count; i++)
            {
                double x = this.yAxis[i];

                double d = this.Data[i];

                double v = this.BubbleData[i];

                double angle = x;

                Point start = new Point(this.GetX(d, this.Len), center.Y);

                Matrix matrix = new Matrix();

                matrix.RotateAt(angle, center.X, center.Y);

                Point end = matrix.Transform(start);

                //  Do :显示标记
                EllipseMarker m = Activator.CreateInstance(this.MarkStyle.TargetType) as EllipseMarker;

                if (m != null)
                {
                    m.Style = this.MarkStyle;

                    m.Rect = new Rect(0, 0, v, v);

                    Canvas.SetLeft(m, end.X);
                    Canvas.SetTop(m, end.Y);

                    this.Children.Add(m);

                    m.Tag = $"( {x.ToString("G4")} , {d.ToString("G4")} )";
                }
            }
        }
Пример #3
0
        public override void Draw(Canvas canvas)
        {
            base.Draw(canvas);

            var data = this.GetData();

            var names = this.GetDisplayName();

            for (int i = 0; i < data.Count; i++)
            {
                double value = data[i];

                Point start;

                Point end;

                if (this.MarkLineType == MarkLineType.Custom)
                {
                    start = this.Start;
                    end   = this.End;
                }

                else
                {
                    start = this.Orientation == Orientation.Horizontal ? new Point(this.minX, value) : new Point(value, this.minY);
                    end   = this.Orientation == Orientation.Horizontal ? new Point(this.maxX, value) : new Point(value, this.maxY);
                }

                {
                    //  Do :添加标定线
                    Path path = new Path();

                    path.Style = this.PathStyle;

                    if (this.MarkBrushes.Count > i)
                    {
                        path.Stroke = new SolidColorBrush(this.MarkBrushes[i]);
                    }
                    else
                    {
                        path.Stroke = this.Foreground;
                    }

                    PolyLineSegment pls = new PolyLineSegment();

                    pls.Points.Add(new Point(this.GetX(start.X), this.GetY(start.Y)));
                    pls.Points.Add(new Point(this.GetX(end.X), this.GetY(end.Y)));

                    PathFigure pf = new PathFigure();
                    pf.StartPoint = pls.Points.FirstOrDefault();
                    pf.Segments.Add(pls);

                    PathGeometry pg = new PathGeometry(new List <PathFigure>()
                    {
                        pf
                    });

                    pg.Figures.Add(pf);

                    path.Data = pg;

                    this.Children.Add(path);
                }

                //  Do :增加箭头
                {
                    //  Do :添加标定线
                    Path path = new Path();
                    path.Style = this.TrangleStyle;

                    if (this.MarkBrushes.Count > i)
                    {
                        path.Stroke = new SolidColorBrush(this.MarkBrushes[i]);
                    }
                    else
                    {
                        path.Stroke = this.Foreground;
                    }

                    path.Fill = path.Stroke;

                    PolyLineSegment pls = new PolyLineSegment();

                    pls.Points.Add(new Point(25, 0));
                    pls.Points.Add(new Point(50, 5));
                    pls.Points.Add(new Point(25, 10));
                    pls.Points.Add(new Point(20, 5));
                    pls.Points.Add(new Point(25, 0));

                    PathFigure pf = new PathFigure();
                    pf.StartPoint = pls.Points.FirstOrDefault();
                    pf.Segments.Add(pls);

                    PathGeometry pg = new PathGeometry(new List <PathFigure>()
                    {
                        pf
                    });

                    path.Data = pg;

                    if (path.RenderTransform is TransformGroup group)
                    {
                        TransformGroup ng = group.Clone();

                        if (ng.Children[2] is RotateTransform rotate)
                        {
                            double angle = Math.Atan2((end.Y - start.Y), (end.X - start.X)) * 180 / Math.PI;
                            rotate.Angle = -angle;
                        }

                        path.RenderTransform = ng;
                    }

                    path.Loaded += (l, k) =>
                    {
                        Canvas.SetBottom(path, this.ActualHeight - this.GetY(end.Y) - path.ActualHeight / 2);
                        Canvas.SetLeft(path, this.GetX(end.X) - path.ActualWidth / 2);
                    };

                    this.Children.Add(path);
                }


                {
                    //  Do :绘制文本
                    Label text = new Label();
                    text.Content = names.Count > i ? names[i] : names.FirstOrDefault();
                    text.Style   = this.LabelStyle;

                    if (this.MarkBrushes.Count > i)
                    {
                        text.Foreground = new SolidColorBrush(this.MarkBrushes[i]);
                    }
                    else
                    {
                        text.Foreground = this.Foreground;
                    }

                    text.Loaded += (l, k) =>
                    {
                        Canvas.SetTop(text, this.GetY(end.Y) - text.ActualHeight / 2);
                        Canvas.SetLeft(text, this.GetX(end.X) + text.ActualWidth / 2);
                    };



                    this.Children.Add(text);
                }

                {
                    //  Do :绘制文本
                    Label text = new Label();

                    if (this.MarkBrushes.Count > i)
                    {
                        text.Foreground = new SolidColorBrush(this.MarkBrushes[i]);
                    }
                    else
                    {
                        text.Foreground = this.Foreground;
                    }
                    text.Content = value.ToString("G4");

                    text.Style = this.LabelStyle;

                    if (this.MarkBrushes.Count > i)
                    {
                        text.Foreground = new SolidColorBrush(this.MarkBrushes[i]);
                    }
                    else
                    {
                        text.Foreground = this.Foreground;
                    }
                    text.Loaded += (l, k) =>
                    {
                        Canvas.SetTop(text, this.GetY(start.Y) - text.ActualHeight / 2);
                        Canvas.SetLeft(text, this.GetX(start.X) - text.ActualWidth * 1.5);
                    };

                    this.Children.Add(text);
                }

                //  Do :显示标记
                if (this.MarkStyle == null)
                {
                    return;
                }

                EllipseMarker m = Activator.CreateInstance(this.MarkStyle.TargetType) as EllipseMarker;

                if (m != null)
                {
                    m.Style = this.MarkStyle;

                    if (this.MarkBrushes.Count > i)
                    {
                        m.Stroke = new SolidColorBrush(this.MarkBrushes[i]);
                    }
                    else
                    {
                        m.Stroke = this.Foreground;
                    }

                    Canvas.SetLeft(m, this.GetX(start.X));
                    Canvas.SetTop(m, this.GetY(start.Y));
                    this.Children.Add(m);
                }
            }
        }