コード例 #1
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var graph = value as IGraph;

            if (graph == null)
            {
                return(null);
            }

            graphControl.Graph = graph;
            graphControl.FitGraphBounds();
            var size = graphControl.ContentRect;
            var cc   = new ContextConfigurator(graphControl.ContentRect);

            cc.Scale = Math.Min(cc.CalculateScaleForWidth(size.Width), cc.CalculateScaleForHeight(size.Height));

            var       renderContext = cc.CreateRenderContext(graphControl);
            Transform transform     = cc.CreateWorldToIntermediateTransform();
            Geometry  clip          = cc.CreateClip();

            var visualContent = graphControl.ExportContent(renderContext);
            var container     = new VisualGroup {
                Transform = transform,
                Clip      = clip,
                Children  = { visualContent }
            };
            var brush = new VisualBrush(container);

            return(new DrawingImage(new GeometryDrawing(brush, null, new RectangleGeometry(new Rect(0, 0, size.Width, size.Height)))));
        }
コード例 #2
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            INode listBoxNode = value as INode;

            if (listBoxNode != null)
            {
                graphControl.Graph.Clear();

                var    size        = FlowChartNodeStyle.GetNodeTypeSize(listBoxNode);
                var    node        = graphControl.Graph.CreateNode(new RectD(0, 0, size.Width, size.Height), listBoxNode.Style, listBoxNode.Tag);
                double labelHeight = 0;
                foreach (var label in listBoxNode.Labels)
                {
                    graphControl.Graph.AddLabel(node, label.Text, label.LayoutParameter, label.Style, label.PreferredSize, label.Tag);
                    labelHeight = Math.Max(labelHeight, label.GetLayout().Height);
                }
                graphControl.FitGraphBounds(new InsetsD(5));
                ContextConfigurator cc             = new ContextConfigurator(graphControl.ContentRect);
                var       renderContext            = cc.CreateRenderContext(graphControl);
                Transform transform                = cc.CreateWorldToIntermediateTransform();
                System.Windows.Media.Geometry clip = cc.CreateClip();
                var visualContent = graphControl.ExportContent(renderContext);

                VisualGroup container = new VisualGroup()
                {
                    Transform = transform, Clip = clip, Children = { visualContent }
                };
                VisualBrush brush = new VisualBrush(container);
                return(new DrawingImage(new GeometryDrawing(brush, null, new RectangleGeometry(new Rect(0, 0, size.Width, size.Height + labelHeight)))));
            }
            else
            {
                return(null);
            }
        }
コード例 #3
0
        protected VisualGroup CreateVisual(GraphControl canvas)
        {
            RectD rect = canvas.ContentRect;
            ContextConfigurator configurator = new ContextConfigurator(rect);

            configurator.Margins = new InsetsD(0, 0, 0, 0);
            // scale down if necessary
            if (ActualHeight > 0 && ActualHeight > 0)
            {
                if (ActualHeight < rect.Height || ActualWidth < rect.Width)
                {
                    configurator.Scale = Math.Min(this.ActualWidth / rect.Width, this.ActualHeight / rect.Height);
                }
                RectD bounds = RectD.FromCenter(rect.Center,
                                                new SizeD(this.ActualWidth, this.ActualHeight) * (1 / configurator.Scale));
                configurator.WorldBounds = bounds;
            }

            IRenderContext vc        = configurator.CreateRenderContext(canvas);
            Transform      transform = configurator.CreateWorldToIntermediateTransform();
            Visual         visual    = canvas.ExportContent(vc);

            return(new VisualGroup()
            {
                Children = { visual }, Clip = Clip, Transform = transform
            });
        }
コード例 #4
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            INode listBoxNode = value as INode;

            if (listBoxNode == null)
            {
                return(null);
            }
            graphControl.Graph.Clear();

            var node = graphControl.Graph.CreateNode(listBoxNode.Layout.ToRectD(), listBoxNode.Style, listBoxNode.Tag);

            foreach (var label in listBoxNode.Labels)
            {
                graphControl.Graph.AddLabel(node, label.Text, label.LayoutParameter,
                                            label.Style, label.PreferredSize, label.Tag);
            }
            graphControl.FitGraphBounds();
            ContextConfigurator cc = new ContextConfigurator(graphControl.ContentRect);

            cc.Scale = Math.Min(cc.CalculateScaleForWidth(size.Width), cc.CalculateScaleForHeight(size.Height));

            var       renderContext = cc.CreateRenderContext(graphControl);
            Transform transform     = cc.CreateWorldToIntermediateTransform();

            System.Windows.Media.Geometry clip = cc.CreateClip();

            var         visualContent = graphControl.ExportContent(renderContext);
            VisualGroup container     = new VisualGroup
            {
                Transform = transform,
                Clip      = clip,
                Children  = { visualContent }
            };
            VisualBrush brush = new VisualBrush(container);

            return
                (new DrawingImage(new GeometryDrawing(brush, null,
                                                      new RectangleGeometry(new Rect(0, 0, size.Width, size.Height)))));
        }