Esempio n. 1
0
    void Awake()
    {
        mGraph = gameObject.GetComponent <NGraph>();
        if (mGraph == null)
        {
            Debug.LogWarning("NGraph component not found.  Aborting.");
            return;
        }
        mGraph.setRanges(-10, 10, -8, 8);

        List <Vector2> data = new List <Vector2>();

        data.Add(new Vector2(-10, -3));
        data.Add(new Vector2(-8, 6));
        data.Add(new Vector2(-6, 2));
        data.Add(new Vector2(-4, -1));
        data.Add(new Vector2(-3, -7));
        data.Add(new Vector2(-2, -4));
        data.Add(new Vector2(-0, 3));

        mSeries1               = mGraph.addDataSeries <NGraphDataSeriesXy>("Simple Plot 1", Color.green);
        mSeries1.PlotStyle     = NGraphDataSeriesXy.Style.Line;
        mSeries1.PlotThickness = 3f;
        mSeries1.Data          = data;

        mSeries1               = mGraph.addDataSeries <NGraphDataSeriesXy>("Simple Plot 2", Color.red);
        mSeries1.PlotStyle     = NGraphDataSeriesXy.Style.Bar;
        mSeries1.PlotThickness = 10f;
        mSeries1.Data          = data;
    }
Esempio n. 2
0
    public static GameObject AddGameObject(GameObject pParentGo, GameObject pWillBeChildGo, float zValue, bool setRectTransformToFullStrech = true)
    {
        pWillBeChildGo.layer = pParentGo.layer;
        pWillBeChildGo.transform.SetParent(pParentGo.transform);
        pWillBeChildGo.transform.localScale    = Vector3.one;
        pWillBeChildGo.transform.localPosition = new Vector3(0, 0, zValue);

        NGraph ng = pParentGo.GetComponentInParent <NGraph>();

        if (ng == null)
        {
            ng = pParentGo.GetComponent <NGraph>();
        }

        if (ng.UnityGui)
        {
            RectTransform rt = pWillBeChildGo.AddComponent <RectTransform>();
            if (setRectTransformToFullStrech)
            {
                rt.anchorMin = new Vector2(0, 0);
                rt.anchorMax = new Vector2(1, 1);
                rt.pivot     = new Vector2(0.5f, 0.5f);
                rt.offsetMin = Vector2.zero;
                rt.offsetMax = Vector2.zero;
            }
        }
        return(pWillBeChildGo);
    }
Esempio n. 3
0
    // Use this for initialization
    void Start()
    {
        mGraph = gameObject.GetComponent <NGraph>();
        if (mGraph == null)
        {
            Debug.LogWarning("NGraph component not found.  Aborting.");
            return;
        }

        // Setup the graph
        mGraph.setRangeX(-5, 5);
        mGraph.setRangeY(-15, 15);

        mEquationPlot1            = mGraph.addDataSeries <NGraphDataSeriesXyEquation>("Simple Equation", Color.blue);
        mEquationPlot1.Resolution = 0.05f;
        mEquationPlot1.Equation   = "(x + 3) * (x + 1) * (x - 2)";

        ErrorLabel.text = "";

        Equation.text         = mEquationPlot1.Equation;
        InputResolution.text  = mEquationPlot1.Resolution.ToString();
        XMin.text             = mGraph.XRange.x.ToString();
        XMax.text             = mGraph.XRange.y.ToString();
        YMin.text             = mGraph.YRange.x.ToString();
        YMax.text             = mGraph.YRange.y.ToString();
        mEquationPlot1.Reveal = 2.0f;
    }
Esempio n. 4
0
 public virtual void teardown(NGraph pGraph, GameObject pGameObject)
 {
     Destroy(mDataLabelContainerGo);
     mDataLabelContainerGo = null;
     mGraph      = null;
     mGameObject = null;
 }
Esempio n. 5
0
    public override List <GameObject> setup(NGraph pGraph, GameObject pGameObject, NGraph.DataSeriesDataLabelCallback pDataLabelCallback, GameObject pDataLabelContainer)
    {
        List <GameObject> pChildGos = base.setup(pGraph, pGameObject, pDataLabelCallback, pDataLabelContainer);

        mMarkerColor = PlotColor;

        return(pChildGos);
    }
 static public void SetupGraph(NGraph pGraph)
 {
     pGraph.PlotBackgroundColor   = sPlotBackgroundColor;
     pGraph.MarginBackgroundColor = sMarginColor;
     pGraph.AxisColor             = sAxesColor;
     pGraph.GridLinesColorMajor   = Color.white;
     pGraph.GridLinesColorMinor   = Color.white;
     pGraph.GetComponent <RectTransform>().sizeDelta = new Vector2(sWidth, sHeight);
 }
Esempio n. 7
0
        private void UpdateHighlights()
        {
            ClearHighlights();

            // get the selected shape
            NShape shape = (view.Selection.AnchorNode as NShape);

            if (shape == null)
            {
                document.SmartRefreshAllViews();
                return;
            }

            // get the graph in which the shape resides
            NGraphBuilder graphBuilder = new NGraphBuilder(new NShapeGraphAdapter(), new NGraphPartFactory());

            NObjectGraphPartMap map;
            NGraph graph = graphBuilder.BuildGraph(shape, out map);

            if (graph == null)
            {
                document.SmartRefreshAllViews();
                return;
            }

            // get the vertex which represents the shape in the graph
            NGraphVertex vertex = (map.GetPartFromObject(shape) as NGraphVertex);

            if (vertex == null)
            {
                return;
            }

            // create a visitor which will visit and highlight the graph parts
            NHighlightingVisitor visitor = new NHighlightingVisitor(this);

            visitor.objectMap = map;
            GraphType graphType = (undirectedGraphRadioButton.Checked ? GraphType.Undirected : GraphType.Directed);

            switch (traversalMethodComboBox.SelectedIndex)
            {
            case 0:     // Depth First Traversal
                graph.DepthFirstTraversal(graphType, visitor, vertex);
                break;

            case 1:     // Breadth First Traversal
                graph.BreadthFirstTraversal(graphType, visitor, vertex);
                break;

            case 2:     // Topological Order Traversal (applicable for directed graphs only)
                graph.TopologicalOrderTraversal(visitor);
                break;
            }

            // smart refresh all views
            document.SmartRefreshAllViews();
        }
Esempio n. 8
0
    public virtual List <GameObject> setup(NGraph pGraph, GameObject pGameObject, NGraph.DataSeriesDataLabelCallback pDataLabelCallback, GameObject pDataLabelContainer)
    {
        if (mGameObject != null)
        {
            return(null);
        }

        mGraph             = pGraph;
        mGameObject        = pGameObject;
        mDataLabelCallback = pDataLabelCallback;

        List <GameObject> pGoList = new List <GameObject>();

        mDataLabelContainerGo = pDataLabelContainer;
        return(pGoList);
    }
Esempio n. 9
0
    void Awake()
    {
        mGraph = gameObject.GetComponent <NGraph>();
        if (mGraph == null)
        {
            Debug.LogWarning("NGraph component not found.  Aborting.");
            return;
        }
        mGraph.setRanges(-10, 0, -8, 8);

        List <Vector2> data = new List <Vector2>();

        mSeries1            = mGraph.addDataSeries <NGraphDataSeriesXyLiveTransient>("Transient", Color.green);
        mSeries1.Data       = data;
        mSeries1.UpdateRate = 0.005f;

        //testing
        ubdRigidbody   = UBD.GetComponent <Rigidbody>();
        ubdTransform   = UBD.GetComponent <Transform>();
        VelocityVector = ubdTransform.position;
    }
Esempio n. 10
0
    private void Awake()
    {
        droneGraph = gameObject.GetComponent <NGraph>();
        if (droneGraph == null)
        {
            Debug.LogWarning("NGraph component not found.  Aborting.");
            return;
        }

        //(-x, x, -y , y)
        droneGraph.setRanges(-2, 3, -2, 2);

        List <Vector2> velData = new List <Vector2>();

        linearVelocity            = droneGraph.addDataSeries <NGraphDataSeriesXyLiveTransient>("Transient", Color.cyan);
        linearVelocity.Data       = velData;
        linearVelocity.UpdateRate = 0.005f;

        droneRigidbody = drone.GetComponent <Rigidbody>();
        droneTransform = drone.GetComponent <Transform>();
        velocityVector = droneTransform.position;
    }
    void Awake()
    {
        mGraph = gameObject.GetComponent <NGraph>();
        if (mGraph == null)
        {
            Debug.LogWarning("NGraph component not found.  Aborting.");
            return;
        }
        mGraph.setRanges(-10, 0, -8, 8);

        List <Vector2> data1 = new List <Vector2>();
        List <Vector2> data2 = new List <Vector2>();

        mSeries1 = mGraph.addDataSeries <NGraphDataSeriesXyLiveTransient>("Transient", Color.yellow);
        mSeries1.PlotThickness = 0.5f;
        mSeries1.Data          = data1;
        mSeries1.UpdateRate    = 0.05f;

        mSeries2            = mGraph.addDataSeries <NGraphDataSeriesXyLiveTransient>("Transient", Color.green);
        mSeries2.Data       = data2;
        mSeries2.UpdateRate = 0.05f;
    }
Esempio n. 12
0
 public override void teardown(NGraph pGraph, GameObject pGameObject)
 {
     base.teardown(pGraph, pGameObject);
     clearMeshes(0);
     clearCanvasRenderers(0);
 }
Esempio n. 13
0
        private void UpdateHighlights()
        {
            ClearHighlights();

            // get the selected shape
            NShape shape = (view.Selection.AnchorNode as NShape);

            if (shape == null)
            {
                document.SmartRefreshAllViews();
                return;
            }

            // build the graph in which the shape resides
            NGraphBuilder graphBuilder = new NGraphBuilder(new NShapeGraphAdapter(), new NGraphPartFactory());

            NObjectGraphPartMap map;
            NGraph graph = graphBuilder.BuildGraph(shape, out map);

            if (graph == null)
            {
                document.SmartRefreshAllViews();
                return;
            }

            NNodeList shapesToHighlight = new NNodeList();

            switch (shape.ShapeType)
            {
            case ShapeType.Shape2D:

                // 2D shapes are treated as graph vertices, so we must find the vertex in the graph, which
                // represents the shape
                NGraphVertex vertex = (map.GetPartFromObject(shape) as NGraphVertex);
                if (vertex != null)
                {
                    // add edges
                    if (allEdgesCheck.Checked)
                    {
                        shapesToHighlight.AddRangeNoDuplicates(GetShapesList(vertex.Edges, map));
                    }
                    else
                    {
                        if (incommingEdgesCheck.Checked)
                        {
                            shapesToHighlight.AddRangeNoDuplicates(GetShapesList(vertex.IncomingEdges, map));
                        }

                        if (outgoingEdgesCheck.Checked)
                        {
                            shapesToHighlight.AddRangeNoDuplicates(GetShapesList(vertex.OutgoingEdges, map));
                        }
                    }

                    // add neighbour vertices
                    if (neighbourVerticesCheck.Checked)
                    {
                        shapesToHighlight.AddRangeNoDuplicates(GetShapesList(vertex.NeighbourVertices, map));
                    }
                    else
                    {
                        if (sourceVerticesCheck.Checked)
                        {
                            shapesToHighlight.AddRangeNoDuplicates(GetShapesList(vertex.SourceVertices, map));
                        }

                        if (destinationVerticesCheck.Checked)
                        {
                            shapesToHighlight.AddRangeNoDuplicates(GetShapesList(vertex.DestinationVertices, map));
                        }
                    }

                    // add accessible vertices
                    if (accessibleVerticesCheck.Checked)
                    {
                        shapesToHighlight.AddRangeNoDuplicates(GetShapesList(vertex.AccessibleVertices, map));
                    }
                    else
                    {
                        if (predecessorVerticesCheck.Checked)
                        {
                            shapesToHighlight.AddRangeNoDuplicates(GetShapesList(vertex.PredecessorVertices, map));
                        }

                        if (successorVerticesCheck.Checked)
                        {
                            shapesToHighlight.AddRangeNoDuplicates(GetShapesList(vertex.SuccessorVertices, map));
                        }
                    }
                }
                break;

            case ShapeType.Shape1D:

                // 1D shapes are treated as graph edges, so we must find the edge in the graph, which
                // represents the shape
                NGraphEdge edge = (map.GetPartFromObject(shape) as NGraphEdge);
                if (edge != null)
                {
                    if (fromVertexCheck.Checked)
                    {
                        shapesToHighlight.AddNoDuplicates((NShape)map.GetObjectFromPart(edge.FromVertex));
                    }

                    if (toVertexCheck.Checked)
                    {
                        shapesToHighlight.AddNoDuplicates((NShape)map.GetObjectFromPart(edge.ToVertex));
                    }
                }
                break;
            }

            // highlight the shapes
            foreach (NShape cur in shapesToHighlight)
            {
                cur.Style.FillStyle   = (highlightFillStyle.Clone() as NFillStyle);
                cur.Style.StrokeStyle = (highlightStrokeStyle.Clone() as NStrokeStyle);
            }

            // smart refresh all views
            document.SmartRefreshAllViews();
        }
Esempio n. 14
0
    public override void OnInspectorGUI()
    {
        bool   b      = false;
        float  f      = 0.0f;
        NGraph pGraph = (NGraph)target;

        NGraphUtils.DrawSeparator();

        // Colors
        Color c = EditorGUILayout.ColorField("Plot Background Color", pGraph.PlotBackgroundColor);

        if (c != pGraph.PlotBackgroundColor)
        {
            UndoableAction <NGraph>(gr => gr.PlotBackgroundColor = c);
        }
        c = EditorGUILayout.ColorField("Margin Background Color", pGraph.MarginBackgroundColor);
        if (c != pGraph.MarginBackgroundColor)
        {
            UndoableAction <NGraph>(gr => gr.MarginBackgroundColor = c);
        }
        c = EditorGUILayout.ColorField("Axis Line Color", pGraph.AxisColor);
        if (c != pGraph.AxisColor)
        {
            UndoableAction <NGraph>(gr => gr.AxisColor = c);
        }
        c = EditorGUILayout.ColorField("Axis Label Color", pGraph.AxisLabelColor);
        if (c != pGraph.AxisLabelColor)
        {
            UndoableAction <NGraph>(gr => gr.AxisLabelColor = c);
        }

        NGraphUtils.DrawSeparator();

        // Axis
        Vector2 vec2;
        Vector4 vec4;
        int     i = 0;

        NGraph.TickStyle tickStyle;
        f = EditorGUILayout.FloatField("Axis Thickness", pGraph.AxesThickness);
        if (f != pGraph.AxesThickness)
        {
            UndoableAction <NGraph>(gr => gr.AxesThickness = f);
        }
        tickStyle = (NGraph.TickStyle)EditorGUILayout.EnumPopup("X Axis Tick Style", pGraph.XTickStyle);
        if (tickStyle != pGraph.XTickStyle)
        {
            UndoableAction <NGraph>(gr => gr.XTickStyle = tickStyle);
        }
        tickStyle = (NGraph.TickStyle)EditorGUILayout.EnumPopup("Y Axis Tick Style", pGraph.YTickStyle);
        if (tickStyle != pGraph.YTickStyle)
        {
            UndoableAction <NGraph>(gr => gr.YTickStyle = tickStyle);
        }
        i = EditorGUILayout.IntField("X Axis Tick Count", pGraph.XNumberOfTicks);
        if (i != pGraph.XNumberOfTicks)
        {
            UndoableAction <NGraph>(gr => gr.XNumberOfTicks = i);
        }
        i = EditorGUILayout.IntField("Y Axis Tick Count", pGraph.YNumberOfTicks);
        if (i != pGraph.YNumberOfTicks)
        {
            UndoableAction <NGraph>(gr => gr.YNumberOfTicks = i);
        }

        b = EditorGUILayout.Toggle("Draw X Axis Labels", pGraph.DrawXLabel);
        if (b != pGraph.DrawXLabel)
        {
            UndoableAction <NGraph>(gr => gr.DrawXLabel = b);
        }
        b = EditorGUILayout.Toggle("Draw Y Axis Labels", pGraph.DrawYLabel);
        if (b != pGraph.DrawYLabel)
        {
            UndoableAction <NGraph>(gr => gr.DrawYLabel = b);
        }
        vec2 = EditorGUILayout.Vector2Field("Axis Draw At", pGraph.AxesDrawAt);
        if (vec2 != pGraph.AxesDrawAt)
        {
            UndoableAction <NGraph>(gr => gr.AxesDrawAt = vec2);
        }
        vec4 = EditorGUILayout.Vector4Field("Margins", pGraph.Margin);
        if (vec4 != pGraph.Margin)
        {
            UndoableAction <NGraph>(gr => gr.Margin = vec4);
        }

        NGraphUtils.DrawSeparator();

        // Grid
        vec2 = EditorGUILayout.Vector2Field("Major Grid Separation (0 for no grid)", pGraph.GridLinesSeparationMajor);
        if (vec2 != pGraph.GridLinesSeparationMajor)
        {
            UndoableAction <NGraph>(gr => gr.GridLinesSeparationMajor = vec2);
        }
        c = EditorGUILayout.ColorField("Major Grid Color", pGraph.GridLinesColorMajor);
        if (c != pGraph.GridLinesColorMajor)
        {
            UndoableAction <NGraph>(gr => gr.GridLinesColorMajor = c);
        }
        f = EditorGUILayout.FloatField("Major Grid Thickness", pGraph.GridLinesThicknesMajor);
        if (f != pGraph.GridLinesThicknesMajor)
        {
            UndoableAction <NGraph>(gr => gr.GridLinesThicknesMajor = f);
        }

        /*
         * vec2 = EditorGUILayout.Vector2Field("Minor Grid Separation (0 for no grid)", pGraph.GridLinesSeparationMinor);
         * if (vec2 != pGraph.GridLinesSeparationMinor)
         * UndoableAction<NGraph>( gr => gr.GridLinesSeparationMinor = vec2 );
         * c = EditorGUILayout.ColorField("Minor Grid Color", pGraph.GridLinesColorMinor);
         * if (c != pGraph.GridLinesColorMinor)
         * UndoableAction<NGraph>( gr => gr.GridLinesColorMinor = c );
         * f = EditorGUILayout.FloatField("Minor Grid Thickness", pGraph.GridLinesThicknesMinor);
         * if (f != pGraph.GridLinesThicknesMinor)
         * UndoableAction<NGraph>( gr => gr.GridLinesThicknesMinor = f );
         */
        NGraphUtils.DrawSeparator();

        // Materials
        Material mat = null;

        mat = (Material)EditorGUILayout.ObjectField("Plot Material", pGraph.DefaultPlotMaterial, typeof(Material), false);
        if (mat != pGraph.DefaultPlotMaterial)
        {
            UndoableAction <NGraph>(gr => gr.DefaultPlotMaterial = mat);
        }
        mat = (Material)EditorGUILayout.ObjectField("Plot Background Material", pGraph.PlotBackgroundMaterial, typeof(Material), false);
        if (mat != pGraph.PlotBackgroundMaterial)
        {
            UndoableAction <NGraph>(gr => gr.PlotBackgroundMaterial = mat);
        }
        mat = (Material)EditorGUILayout.ObjectField("Axis Line And Tick Material", pGraph.AxisMaterial, typeof(Material), false);
        if (mat != pGraph.AxisMaterial)
        {
            UndoableAction <NGraph>(gr => gr.AxisMaterial = mat);
        }
    }