forked from NorthwoodsSoftware/GoJS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparseTree.html
More file actions
172 lines (166 loc) · 6.18 KB
/
parseTree.html
File metadata and controls
172 lines (166 loc) · 6.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!DOCTYPE html>
<html>
<head>
<title>Parse Tree</title>
<meta name="description" content="A collapsible tree layout with all of the leaf nodes at the same layer." />
<!-- Copyright 1998-2016 by Northwoods Software Corporation. -->
<meta charset="UTF-8">
<script src="go.js"></script>
<link href="../assets/css/goSamples.css" rel="stylesheet" type="text/css" /> <!-- you don't need to use this -->
<script src="goSamples.js"></script> <!-- this is only for the GoJS Samples framework -->
<script id="code">
function init() {
if (window.goSamples) goSamples(); // init for these samples -- you don't need to call this
var $ = go.GraphObject.make; // for conciseness in defining templates
myDiagram =
$(go.Diagram, "myDiagramDiv",
{
allowCopy: false,
allowDelete: false,
allowMove: false,
initialContentAlignment: go.Spot.Center,
initialAutoScale: go.Diagram.Uniform,
layout:
$(FlatTreeLayout, // custom Layout, defined below
{ angle: 90,
compaction: go.TreeLayout.CompactionNone }),
"undoManager.isEnabled": true
});
myDiagram.nodeTemplate =
$(go.Node, "Vertical",
{ selectionObjectName: "BODY" },
$(go.Panel, "Auto", { name: "BODY" },
$(go.Shape, "RoundedRectangle",
new go.Binding("fill"),
new go.Binding("stroke")),
$(go.TextBlock,
{ font: "bold 12pt Arial", margin: new go.Margin(4, 2, 2, 2) },
new go.Binding("text"))
),
$(go.Panel, // this is underneath the "BODY"
{ height: 15 }, // always this height, even if the TreeExpanderButton is not visible
$("TreeExpanderButton")
)
);
myDiagram.linkTemplate =
$(go.Link,
$(go.Shape, { strokeWidth: 1.5 }));
load();
}
function load() {
myDiagram.model = go.Model.fromJson(document.getElementById("mySavedModel").value);
}
// Customize the TreeLayout to position all of the leaf nodes at the same vertical Y position.
function FlatTreeLayout() {
go.TreeLayout.call(this); // call base constructor
}
go.Diagram.inherit(FlatTreeLayout, go.TreeLayout);
// This assumes the TreeLayout.angle is 90 -- growing downward
/** @override */
FlatTreeLayout.prototype.commitLayout = function() {
go.TreeLayout.prototype.commitLayout.call(this); // call base method first
// find maximum Y position of all Nodes
var y = -Infinity;
this.network.vertexes.each(function(v) {
y = Math.max(y, v.node.position.y);
});
// move down all leaf nodes to that Y position, but keeping their X position
this.network.vertexes.each(function(v) {
var node = v.node;
if (node.isTreeLeaf) {
node.position = new go.Point(node.position.x, y);
}
});
};
// end FlatTreeLayout
</script>
</head>
<body onload="init()">
<div id="sample">
Parse Tree
<div id="myDiagramDiv" style="border: solid 1px black; width:100%; height:500px"></div>
<button onclick="load()">Load</button>
<br />
<textarea id="mySavedModel" style="width:100%;height:300px">
{
"class": "go.GraphLinksModel",
"nodeDataArray":[
{"key":1,"text":"Sentence","fill":"#f68c06","stroke":"#4d90fe"},
{"key":2,"text":"NP","fill":"#f68c06","stroke":"#4d90fe"},
{"key":3,"text":"DT","fill":"#ccc","stroke":"#4d90fe"},
{"key":4,"text":"A","fill":"#f8f8f8","stroke":"#4d90fe"},
{"key":5,"text":"JJ","fill":"#ccc","stroke":"#4d90fe"},
{"key":6,"text":"rare","fill":"#f8f8f8","stroke":"#4d90fe"},
{"key":7,"text":"JJ","fill":"#ccc","stroke":"#4d90fe"},
{"key":8,"text":"black","fill":"#f8f8f8","stroke":"#4d90fe"},
{"key":9,"text":"NN","fill":"#ccc","stroke":"#4d90fe"},
{"key":10,"text":"squirrel","fill":"#f8f8f8","stroke":"#4d90fe"},
{"key":11,"text":"VP","fill":"#f68c06","stroke":"#4d90fe"},
{"key":12,"text":"VBZ","fill":"#ccc","stroke":"#4d90fe"},
{"key":13,"text":"has","fill":"#f8f8f8","stroke":"#4d90fe"},
{"key":14,"text":"VP","fill":"#f68c06","stroke":"#4d90fe"},
{"key":15,"text":"VBN","fill":"#ccc","stroke":"#4d90fe"},
{"key":16,"text":"become","fill":"#f8f8f8","stroke":"#4d90fe"},
{"key":17,"text":"NP","fill":"#f68c06","stroke":"#4d90fe"},
{"key":18,"text":"NP","fill":"#f68c06","stroke":"#4d90fe"},
{"key":19,"text":"DT","fill":"#ccc","stroke":"#4d90fe"},
{"key":20,"text":"a","fill":"#f8f8f8","stroke":"#4d90fe"},
{"key":21,"text":"JJ","fill":"#ccc","stroke":"#4d90fe"},
{"key":22,"text":"regular","fill":"#f8f8f8","stroke":"#4d90fe"},
{"key":23,"text":"NN","fill":"#ccc","stroke":"#4d90fe"},
{"key":24,"text":"visitor","fill":"#f8f8f8","stroke":"#4d90fe"},
{"key":25,"text":"PP","fill":"#f68c06","stroke":"#4d90fe"},
{"key":26,"text":"TO","fill":"#ccc","stroke":"#4d90fe"},
{"key":27,"text":"to","fill":"#f8f8f8","stroke":"#4d90fe"},
{"key":28,"text":"NP","fill":"#f68c06","stroke":"#4d90fe"},
{"key":29,"text":"DT","fill":"#ccc","stroke":"#4d90fe"},
{"key":30,"text":"a","fill":"#f8f8f8","stroke":"#4d90fe"},
{"key":31,"text":"JJ","fill":"#ccc","stroke":"#4d90fe"},
{"key":32,"text":"suburban","fill":"#f8f8f8","stroke":"#4d90fe"},
{"key":33,"text":"NN","fill":"#ccc","stroke":"#4d90fe"},
{"key":34,"text":"garden","fill":"#f8f8f8","stroke":"#4d90fe"},
{"key":35,"text":".","fill":"#ccc","stroke":"#4d90fe"},
{"key":36,"text":".","fill":"#f8f8f8","stroke":"#4d90fe"}
],
"linkDataArray":[
{"from":1,"to":2},
{"from":2,"to":3},
{"from":3,"to":4},
{"from":2,"to":5},
{"from":5,"to":6},
{"from":2,"to":7},
{"from":7,"to":8},
{"from":2,"to":9},
{"from":9,"to":10},
{"from":1,"to":11},
{"from":11,"to":12},
{"from":12,"to":13},
{"from":11,"to":14},
{"from":14,"to":15},
{"from":15,"to":16},
{"from":14,"to":17},
{"from":17,"to":18},
{"from":18,"to":19},
{"from":19,"to":20},
{"from":18,"to":21},
{"from":21,"to":22},
{"from":18,"to":23},
{"from":23,"to":24},
{"from":17,"to":25},
{"from":25,"to":26},
{"from":26,"to":27},
{"from":25,"to":28},
{"from":28,"to":29},
{"from":29,"to":30},
{"from":28,"to":31},
{"from":31,"to":32},
{"from":28,"to":33},
{"from":33,"to":34},
{"from":1,"to":35},
{"from":35,"to":36}
]
}
</textarea>
</div>
</body>
</html>