Draw full full graph
This commit is contained in:
parent
f4030e7595
commit
74aa48b446
@ -213,12 +213,12 @@ namespace NanoBrain.Unity {
|
|||||||
#region Full Graph
|
#region Full Graph
|
||||||
|
|
||||||
protected void DrawFullGraph() {
|
protected void DrawFullGraph() {
|
||||||
if (this.currentNucleus == null) {
|
// if (this.currentNucleus == null) {
|
||||||
Vector3 position = new(150, 210, 0);
|
// Vector3 position = new(150, 210, 0);
|
||||||
DrawAllOutputs(position);
|
// DrawAllOutputs(position);
|
||||||
DrawOutputs(position);
|
// DrawOutputs(position);
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
Dag dag = GenerateGraph(this.selectedOutput);
|
Dag dag = GenerateGraph(this.selectedOutput);
|
||||||
Dag.ComputeLayout(dag);
|
Dag.ComputeLayout(dag);
|
||||||
@ -271,8 +271,8 @@ namespace NanoBrain.Unity {
|
|||||||
|
|
||||||
public Dag GenerateGraph(Nucleus rootNucleus) {
|
public Dag GenerateGraph(Nucleus rootNucleus) {
|
||||||
Dag dag = new();
|
Dag dag = new();
|
||||||
if (rootNucleus == null)
|
// if (rootNucleus == null)
|
||||||
return dag;
|
// return dag;
|
||||||
|
|
||||||
int ix = 0;
|
int ix = 0;
|
||||||
Dag.Node receiver = new() {
|
Dag.Node receiver = new() {
|
||||||
@ -281,18 +281,41 @@ namespace NanoBrain.Unity {
|
|||||||
};
|
};
|
||||||
dag.nodes.Add(receiver);
|
dag.nodes.Add(receiver);
|
||||||
ix++;
|
ix++;
|
||||||
|
if (rootNucleus == null)
|
||||||
|
DescendGraphFromRoot(ref ix, dag);
|
||||||
|
else
|
||||||
DescendGraph(receiver, ref ix, dag);
|
DescendGraph(receiver, ref ix, dag);
|
||||||
return dag;
|
return dag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void DescendGraphFromRoot(ref int ix, Dag dag) {
|
||||||
|
foreach (Nucleus nucleus in this.currentCluster.outputs) {
|
||||||
|
string nucleusName = nucleus.name;
|
||||||
|
Dag.Node node = dag.FindNode(nucleusName);
|
||||||
|
if (node == null) {
|
||||||
|
node = new() {
|
||||||
|
id = ix,
|
||||||
|
nucleus = nucleus
|
||||||
|
};
|
||||||
|
dag.nodes.Add(node);
|
||||||
|
}
|
||||||
|
Dag.Edge edge = new() {
|
||||||
|
fromId = node.id,
|
||||||
|
toId = 0
|
||||||
|
};
|
||||||
|
dag.edges.Add(edge);
|
||||||
|
ix++;
|
||||||
|
DescendGraph(node, ref ix, dag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void DescendGraph(Dag.Node receiver, ref int ix, Dag dag) {
|
private void DescendGraph(Dag.Node receiver, ref int ix, Dag dag) {
|
||||||
Neuron receiverNeuron = receiver.nucleus as Neuron;
|
if (receiver.nucleus is not Neuron receiverNeuron)
|
||||||
if (receiverNeuron == null)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (Synapse synapse in receiverNeuron.synapses) {
|
foreach (Synapse synapse in receiverNeuron.synapses) {
|
||||||
Nucleus nucleus = synapse.neuron;
|
Nucleus nucleus = synapse.neuron;
|
||||||
if (nucleus.parent != null && nucleus.parent != currentNucleus.parent) {
|
if (nucleus.parent != null && currentNucleus != null && nucleus.parent != currentNucleus.parent) {
|
||||||
nucleus = nucleus.parent;
|
nucleus = nucleus.parent;
|
||||||
}
|
}
|
||||||
string nucleusName = nucleus.name;
|
string nucleusName = nucleus.name;
|
||||||
|
|||||||
@ -18,13 +18,12 @@ namespace NanoBrain.Unity {
|
|||||||
currentClusterView.initialized = false;
|
currentClusterView.initialized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private const float padding = 0f;//4f;
|
|
||||||
private const float graphHeight = 500f; // height reserved for the VisualElement
|
private const float graphHeight = 500f; // height reserved for the VisualElement
|
||||||
private static ClusterView currentClusterView;
|
private static ClusterView currentClusterView;
|
||||||
private static UnityEngine.Object selectedTarget;
|
private static UnityEngine.Object selectedTarget;
|
||||||
|
|
||||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
|
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
|
||||||
float height = EditorGUIUtility.singleLineHeight + padding;
|
float height = EditorGUIUtility.singleLineHeight;
|
||||||
if (Cluster_Drawer.currentClusterView == null)
|
if (Cluster_Drawer.currentClusterView == null)
|
||||||
// When no cluster is viewed
|
// When no cluster is viewed
|
||||||
return height;
|
return height;
|
||||||
@ -32,6 +31,10 @@ namespace NanoBrain.Unity {
|
|||||||
SerializedProperty prefabProp = property.FindPropertyRelative(nameof(Cluster.prefab));
|
SerializedProperty prefabProp = property.FindPropertyRelative(nameof(Cluster.prefab));
|
||||||
if (prefabProp.objectReferenceValue != null && Cluster_Drawer.currentClusterView.isOpen) {
|
if (prefabProp.objectReferenceValue != null && Cluster_Drawer.currentClusterView.isOpen) {
|
||||||
height = graphHeight;
|
height = graphHeight;
|
||||||
|
} else {
|
||||||
|
// Unclear why this is necessary,
|
||||||
|
// but without this, expanding the graph foldout is not possible
|
||||||
|
height += EditorGUIUtility.singleLineHeight;
|
||||||
}
|
}
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
@ -73,7 +76,7 @@ namespace NanoBrain.Unity {
|
|||||||
SerializedProperty prefabProp = property.FindPropertyRelative(nameof(Cluster.prefab));
|
SerializedProperty prefabProp = property.FindPropertyRelative(nameof(Cluster.prefab));
|
||||||
|
|
||||||
// Draw the object field on the top line
|
// Draw the object field on the top line
|
||||||
Rect fieldRect = new(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight + padding);
|
Rect fieldRect = new(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);
|
||||||
EditorGUI.BeginChangeCheck();
|
EditorGUI.BeginChangeCheck();
|
||||||
EditorGUI.PropertyField(fieldRect, prefabProp, label);
|
EditorGUI.PropertyField(fieldRect, prefabProp, label);
|
||||||
// If a new prefab has been selected
|
// If a new prefab has been selected
|
||||||
|
|||||||
@ -28,6 +28,9 @@ namespace NanoBrain.Unity {
|
|||||||
name = name[..colonPos];
|
name = name[..colonPos];
|
||||||
}
|
}
|
||||||
foreach (Node node in this.nodes) {
|
foreach (Node node in this.nodes) {
|
||||||
|
if (node.nucleus == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
string nodeName = node.nucleus.name;
|
string nodeName = node.nucleus.name;
|
||||||
if (justBaseName) {
|
if (justBaseName) {
|
||||||
int colonPos = nodeName.IndexOf(":");
|
int colonPos = nodeName.IndexOf(":");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user