public void Invalidate()
        {
            if (!Node.IsVisible)
            {
                foreach (var fe in FrameworkElements)
                {
                    fe.Visibility = Visibility.Hidden;
                }
                return;
            }

            if (BoundaryCurveIsDirty)
            {
                BoundaryPath.Data    = CreatePathFromNodeBoundary();
                BoundaryCurveIsDirty = false;
            }

            if (LgNodeInfo != null)
            {
                double scale = 1; // LgNodeInfo != null && LgNodeInfo.Kind == LgNodeInfoKind.Satellite
                                  // ? LgNodeInfo.Scale
                                  // : 1;
                var planeTransform = PlaneTransformation.ScaleAroundCenterTransformation(scale,
                                                                                         node.BoundingBox.Center);
                var transform = new MatrixTransform(planeTransform[0, 0], planeTransform[0, 1],
                                                    planeTransform[1, 0], planeTransform[1, 1],
                                                    planeTransform[0, 2], planeTransform[1, 2]);
                BoundaryPath.RenderTransform = transform;

                if (FrameworkElementOfNodeForLabel != null)
                {
                    Common.PositionFrameworkElement(FrameworkElementOfNodeForLabel, node.GeometryNode.Center,
                                                    scale);
                }
            }
            else
            {
                Common.PositionFrameworkElement(FrameworkElementOfNodeForLabel, Node.BoundingBox.Center, 1);
            }


            SetFillAndStroke();
            if (subgraph == null)
            {
                return;
            }
            PositionTopMarginBorder((Cluster)subgraph.GeometryNode);
            double collapseBorderSize   = GetCollapseBorderSymbolSize();
            var    collapseButtonCenter = GetCollapseButtonCenter(collapseBorderSize);

            Common.PositionFrameworkElement(collapseButtonBorder, collapseButtonCenter, 1);
            double w = collapseBorderSize * 0.4;

            collapseSymbolPath.Data            = CreateCollapseSymbolPath(collapseButtonCenter + new Point(0, -w / 2), w);
            collapseSymbolPath.RenderTransform = ((Cluster)subgraph.GeometryNode).IsCollapsed
                                                     ? new RotateTransform(180, collapseButtonCenter.X,
                                                                           collapseButtonCenter.Y)
                                                     : null;

            topMarginRect.Visibility                =
                collapseSymbolPath.Visibility       =
                    collapseButtonBorder.Visibility = Visibility.Visible;
        }
示例#2
0
        int ProcessDotFile(string inputFile)
        {
            Graph graph;
            int   i = CreateGraphFromDotFile(inputFile, out graph);

            graph.Attr.LayerDirection = GetLayerDirection();

            if (i != 0)
            {
                return(i);
            }
            if (argsParser.OptionIsUsed("-nolayout") && GeometryIsPresent(graph))
            {
                double nodeScale;
                bool   scaling = argsParser.GetDoubleOptionValue("-scaleNodesBy", out nodeScale);
                if (scaling)
                {
                    foreach (var node in graph.GeometryGraph.Nodes)
                    {
                        node.BoundaryCurve = node.BoundaryCurve.Transform(PlaneTransformation.ScaleAroundCenterTransformation(nodeScale,
                                                                                                                              node.Center));
                    }
                    graph.GeometryGraph.UpdateBoundingBox();
                }
                double nodeLineWidth;
                if (argsParser.GetDoubleOptionValue("-nblw", out nodeLineWidth))
                {
                    foreach (var node in graph.Nodes)
                    {
                        node.Attr.LineWidth = nodeLineWidth;
                    }
                    graph.GeometryGraph.UpdateBoundingBox();
                }
            }
            else
            {
                PrepareForOutput(graph);
            }

            var    outputFile = Path.ChangeExtension(inputFile, ".svg");
            string outputDir  = argsParser.GetStringOptionValue(OutputDirOption);

            if (outputDir != null)
            {
                var name = Path.GetFileName(outputFile);
                if (name != null)
                {
                    outputFile = Path.Combine(outputDir, name);
                }
            }


            SetConsolasFontAndSize(graph, 11);
            if (argsParser.OptionIsUsed(NoLabelsOption))
            {
                RemoveLabelsFromGraph(graph);
            }
            using (var stream = File.Create(outputFile)) {
                var svgWriter = new SvgGraphWriter(stream, graph)
                {
                    BlackAndWhite     = argsParser.OptionIsUsed("-bw"),
                    NodeSanitizer     = AntiXss.HtmlAttributeEncode,
                    AttrSanitizer     = AntiXss.HtmlAttributeEncode,
                    Precision         = precision,
                    AllowedToWriteUri = !argsParser.OptionIsUsed(NoUrls),
                    IgnoreEdges       = argsParser.OptionIsUsed("-noedges")
                };
                svgWriter.Write();
                DumpFileToConsole(outputFile);
            }

            if (msaglOutput)
            {
                outputFile = SetMsaglOutputFileName(inputFile);
                var geomGraph = graph.GeometryGraph;
                WriteGeomGraph(outputFile, geomGraph);
            }
            return(0);
        }