Skip to content

Commit 1efed16

Browse files
author
HQ\chacha
committed
Improving the Graph Visualiser for new API
- PlayableGraph API (Timeline 5.6 alpha) - Bug fixing and robustness improvements - Workflow simplification - Based on the work of Catherine Proulx
0 parents  commit 1efed16

25 files changed

+1415
-0
lines changed

Assets/Editor/GraphVisualizer.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Editor/GraphVisualizer/Graph.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
4+
5+
namespace GraphVisualizer
6+
{
7+
public abstract class Graph : IEnumerable<Node>
8+
{
9+
private readonly List<Node> m_Nodes = new List<Node>();
10+
11+
public ReadOnlyCollection<Node> nodes
12+
{
13+
get { return m_Nodes.AsReadOnly(); }
14+
}
15+
16+
protected class NodeWeight
17+
{
18+
public object node { get; set; }
19+
public float weight { get; set; }
20+
}
21+
22+
// Derived class should specify the children of a given node.
23+
protected abstract IEnumerable<Node> GetChildren(Node node);
24+
25+
// Derived class should implement how to populate this graph (usually by calling AddNodeHierarchy()).
26+
protected abstract void Populate();
27+
28+
public void AddNodeHierarchy(Node root)
29+
{
30+
AddNode(root);
31+
32+
IEnumerable<Node> children = GetChildren(root);
33+
if (children == null)
34+
return;
35+
36+
foreach (Node child in children)
37+
{
38+
root.AddChild(child);
39+
AddNodeHierarchy(child);
40+
}
41+
}
42+
43+
public void AddNode(Node node)
44+
{
45+
m_Nodes.Add(node);
46+
}
47+
48+
public void Clear()
49+
{
50+
m_Nodes.Clear();
51+
}
52+
53+
public void Refresh()
54+
{
55+
// TODO optimize?
56+
Clear();
57+
Populate();
58+
}
59+
60+
public IEnumerator<Node> GetEnumerator()
61+
{
62+
return m_Nodes.GetEnumerator();
63+
}
64+
65+
IEnumerator IEnumerable.GetEnumerator()
66+
{
67+
return m_Nodes.GetEnumerator();
68+
}
69+
}
70+
}

Assets/Editor/GraphVisualizer/Graph/Graph.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Editor/GraphVisualizer/Graph/Layouts.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System.Collections.Generic;
2+
using UnityEngine;
3+
4+
namespace GraphVisualizer
5+
{
6+
// Interface for a generic graph layout.
7+
public interface IGraphLayout
8+
{
9+
IEnumerable<Vertex> vertices { get; }
10+
IEnumerable<Edge> edges { get; }
11+
12+
bool leftToRight { get; }
13+
14+
void CalculateLayout(Graph graph);
15+
}
16+
17+
public class Edge
18+
{
19+
// Indices in the vertex array of the layout algorithm.
20+
public Edge(Vertex src, Vertex dest)
21+
{
22+
source = src;
23+
destination = dest;
24+
}
25+
26+
public Vertex source { get; private set; }
27+
28+
public Vertex destination { get; private set; }
29+
}
30+
31+
// One vertex is associated to each node in the graph.
32+
public class Vertex
33+
{
34+
// Center of the node in the graph layout.
35+
public Vector2 position { get; set; }
36+
37+
// The Node represented by the vertex.
38+
public Node node { get; private set; }
39+
40+
public Vertex(Node node)
41+
{
42+
this.node = node;
43+
}
44+
}
45+
}

Assets/Editor/GraphVisualizer/Graph/Layouts/IGraphLayout.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)