示例#1
0
    public void ShowPlot(Global.GraphType gType, float x, float y)
    {
        GraphAttributes gt       = gAttr[gType];
        float           xPos     = (x / gt.xMax) * graphWidth;  // Normalized x position
        float           yPos     = (y / gt.yMax) * graphHeight; // Normalized y position
        GameObject      goCircle = CreateCircle(new Vector2(xPos, yPos), gt.pointColor);

        gt.points.Add(goCircle);
        if (gt.lastCircleGameObject != null)
        {
            GameObject goConn = CreateDotConnection(gt.lastCircleGameObject.GetComponent <RectTransform>().anchoredPosition, goCircle.GetComponent <RectTransform>().anchoredPosition, gt.segmentColor, gt.segmentWidth);
            gt.segments.Add(goConn);
        }
        gt.lastCircleGameObject = goCircle;
        gAttr[gType]            = gt;
    }
示例#2
0
    public void ClearPlot(Global.GraphType gType)
    {
        if (gAttr.ContainsKey(gType) == false)
        {
            return;
        }
        GraphAttributes gt = gAttr[gType];

        foreach (var go in gt.points)
        {
            Destroy(go);
        }
        foreach (var go in gt.segments)
        {
            Destroy(go);
        }
    }
示例#3
0
    public void GraphInit(Global.GraphType gType, Color pointColor, Color segmentColor, float xMax, float yMax, float segmentWidth = 1f)
    {
        GraphAttributes gt = new GraphAttributes();

        gt.lastCircleGameObject = null;
        gt.pointColor           = pointColor;
        gt.segmentColor         = segmentColor;
        gt.xMax         = xMax;
        gt.yMax         = yMax;
        gt.points       = new List <GameObject>();
        gt.segments     = new List <GameObject>();
        gt.segmentWidth = segmentWidth;
        if (gAttr.ContainsKey(gType) == true)
        {
            gAttr[gType] = gt;
        }
        else
        {
            gAttr.Add(gType, gt);
        }
    }
示例#4
0
        private string BuildDot()
        {
            var builder = StringBuilderCache.Acquire();

            builder.Append("// Schematic version ").AppendLine(_fileVersion);
            builder.Append("digraph ").Append(GraphName).AppendLine(" {");

            const uint level = 1U;

            if (GraphAttributes.Any())
            {
                var graphIndent = GetIndentForLevel(level);
                builder.Append(graphIndent).AppendLine("graph [");

                var graphAttrIndent = GetIndentForLevel(level + 1);
                foreach (var graphAttr in GraphAttributes)
                {
                    builder.Append(graphAttrIndent).AppendLine(graphAttr.ToString());
                }

                builder.Append(graphIndent).AppendLine("]");
            }

            if (NodeAttributes.Any())
            {
                var nodeIndent = GetIndentForLevel(level);
                builder.Append(nodeIndent).AppendLine("node [");

                var nodeAttrIndent = GetIndentForLevel(level + 1);
                foreach (var nodeAttr in NodeAttributes)
                {
                    builder.Append(nodeAttrIndent).AppendLine(nodeAttr.ToString());
                }

                builder.Append(nodeIndent).AppendLine("]");
            }

            if (EdgeAttributes.Any())
            {
                var edgeIndent = GetIndentForLevel(level);
                builder.Append(edgeIndent).AppendLine("edge [");

                var edgeAttrIndent = GetIndentForLevel(level + 1);
                foreach (var edgeAttr in EdgeAttributes)
                {
                    builder.Append(edgeAttrIndent).AppendLine(edgeAttr.ToString());
                }

                builder.Append(edgeIndent).AppendLine("]");
            }

            if (Nodes.Any())
            {
                var nodeIndent   = GetIndentForLevel(level);
                var orderedNodes = Nodes.OrderBy(n => n.Identifier.ToString());

                foreach (var node in orderedNodes)
                {
                    var nodeStr = node.ToString();

                    using var reader = new StringReader(nodeStr);
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        builder.Append(nodeIndent).AppendLine(line);
                    }
                }
            }

            if (Edges.Any())
            {
                var edgeIndent = GetIndentForLevel(level);
                foreach (var edge in Edges)
                {
                    var edgeStr = edge.ToString();

                    using var reader = new StringReader(edgeStr);
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        builder.Append(edgeIndent).AppendLine(line);
                    }
                }
            }

            builder.AppendLine("}");
            return(builder.GetStringAndRelease());
        }