-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathentityRelationship.html
More file actions
253 lines (228 loc) · 10.1 KB
/
entityRelationship.html
File metadata and controls
253 lines (228 loc) · 10.1 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Entity Relationship</title>
<meta name="description" content="Interactive entity-relationship diagram or data model diagram implemented by GoJS in JavaScript for HTML." />
<!-- Copyright 1998-2018 by Northwoods Software Corporation. -->
<meta charset="UTF-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/gojs/1.8.32/go.js"></script>
<script src="./lib/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", // must name or refer to the DIV HTML element
{
initialContentAlignment: go.Spot.Center,
allowDelete: false,
allowCopy: false,
layout: $(go.ForceDirectedLayout),
"undoManager.isEnabled": true
});
// define several shared Brushes
var bluegrad = $(go.Brush, "Linear", { 0: "rgb(150, 150, 250)", 0.5: "rgb(86, 86, 186)", 1: "rgb(86, 86, 186)" });
var greengrad = $(go.Brush, "Linear", { 0: "rgb(158, 209, 159)", 1: "rgb(67, 101, 56)" });
var redgrad = $(go.Brush, "Linear", { 0: "rgb(206, 106, 100)", 1: "rgb(180, 56, 50)" });
var yellowgrad = $(go.Brush, "Linear", { 0: "rgb(254, 221, 50)", 1: "rgb(254, 182, 50)" });
var lightgrad = $(go.Brush, "Linear", { 1: "#E6E6FA", 0: "#FFFAF0" });
// the template for each attribute in a node's array of item data
var itemTempl =
$(go.Panel, "Horizontal",
$(go.Shape,
{ desiredSize: new go.Size(10, 10) },
new go.Binding("figure", "figure"),
new go.Binding("fill", "color")),
$(go.TextBlock,
{ stroke: "#333333",
font: "bold 14px sans-serif" },
new go.Binding("text", "name"))
);
// define the Node template, representing an entity
myDiagram.nodeTemplate =
$(go.Node, "Auto", // the whole node panel
{ selectionAdorned: true,
resizable: true,
layoutConditions: go.Part.LayoutStandard & ~go.Part.LayoutNodeSized,
fromSpot: go.Spot.AllSides,
toSpot: go.Spot.AllSides,
isShadowed: true,
shadowColor: "#C5C1AA" },
new go.Binding("location", "location").makeTwoWay(),
// whenever the PanelExpanderButton changes the visible property of the "LIST" panel,
// clear out any desiredSize set by the ResizingTool.
new go.Binding("desiredSize", "visible", function(v) { return new go.Size(NaN, NaN); }).ofObject("LIST"),
// define the node's outer shape, which will surround the Table
$(go.Shape, "Rectangle",
{ fill: lightgrad, stroke: "#756875", strokeWidth: 3 }),
$(go.Panel, "Table",
{ margin: 8, stretch: go.GraphObject.Fill },
$(go.RowColumnDefinition, { row: 0, sizing: go.RowColumnDefinition.None }),
// the table header
$(go.TextBlock,
{
row: 0, alignment: go.Spot.Center,
margin: new go.Margin(0, 14, 0, 2), // leave room for Button
font: "bold 16px sans-serif"
},
new go.Binding("text", "key")),
// the collapse/expand button
$("PanelExpanderButton", "LIST", // the name of the element whose visibility this button toggles
{ row: 0, alignment: go.Spot.TopRight }),
// the list of Panels, each showing an attribute
$(go.Panel, "Vertical",
{
name: "LIST",
row: 1,
padding: 3,
alignment: go.Spot.TopLeft,
defaultAlignment: go.Spot.Left,
stretch: go.GraphObject.Horizontal,
itemTemplate: itemTempl
},
new go.Binding("itemArray", "items"))
) // end Table Panel
); // end Node
// define the Link template, representing a relationship
myDiagram.linkTemplate =
$(go.Link, // the whole link panel
{
selectionAdorned: true,
layerName: "Foreground",
reshapable: true,
routing: go.Link.AvoidsNodes,
corner: 5,
curve: go.Link.JumpOver
},
$(go.Shape, // the link shape
{ stroke: "#303B45", strokeWidth: 2.5 }),
$(go.TextBlock, // the "from" label
{
textAlign: "center",
font: "bold 14px sans-serif",
stroke: "#1967B3",
segmentIndex: 0,
segmentOffset: new go.Point(NaN, NaN),
segmentOrientation: go.Link.OrientUpright
},
new go.Binding("text", "text")),
$(go.TextBlock, // the "to" label
{
textAlign: "center",
font: "bold 14px sans-serif",
stroke: "#1967B3",
segmentIndex: -1,
segmentOffset: new go.Point(NaN, NaN),
segmentOrientation: go.Link.OrientUpright
},
new go.Binding("text", "toText"))
);
// create the model for the E-R diagram
// var nodeDataArray = [
// { key: "Products",
// items: [ { name: "ProductID", iskey: true, figure: "Decision", color: yellowgrad },
// { name: "ProductName", iskey: false, figure: "Cube1", color: bluegrad },
// { name: "SupplierID", iskey: false, figure: "Decision", color: "purple" },
// { name: "CategoryID", iskey: false, figure: "Decision", color: "purple" } ] },
// { key: "Suppliers",
// items: [ { name: "SupplierID", iskey: true, figure: "Decision", color: yellowgrad },
// { name: "CompanyName", iskey: false, figure: "Cube1", color: bluegrad },
// { name: "ContactName", iskey: false, figure: "Cube1", color: bluegrad },
// { name: "Address", iskey: false, figure: "Cube1", color: bluegrad } ] },
// { key: "Categories",
// items: [ { name: "CategoryID", iskey: true, figure: "Decision", color: yellowgrad },
// { name: "CategoryName", iskey: false, figure: "Cube1", color: bluegrad },
// { name: "Description", iskey: false, figure: "Cube1", color: bluegrad },
// { name: "Picture", iskey: false, figure: "TriangleUp", color: redgrad } ] },
// { key: "Order Details",
// items: [ { name: "OrderID", iskey: true, figure: "Decision", color: yellowgrad },
// { name: "ProductID", iskey: true, figure: "Decision", color: yellowgrad },
// { name: "UnitPrice", iskey: false, figure: "MagneticData", color: greengrad },
// { name: "Quantity", iskey: false, figure: "MagneticData", color: greengrad },
// { name: "Discount", iskey: false, figure: "MagneticData", color: greengrad } ] },
// ];
// var linkDataArray = [
// { from: "Products", to: "Suppliers", text: "0..N", toText: "1" },
// { from: "Products", to: "Categories", text: "0..N", toText: "1" },
// { from: "Order Details", to: "Products", text: "0..N", toText: "1" }
// ];
const handleFileSelect = (evt) => {
const file = evt.target.files[0]; // FileList object
console.log(file);
const nodeDataArray = [];
const linkDataArray = [];
const fileReader = new FileReader();
let regras;
fileReader.addEventListener('load', (evt) => {
// console.log(event.target.result);
regras = JSON.parse(evt.target.result);
console.log(regras);
for(const chave in regras.rules){
if(regras.rules.hasOwnProperty(chave)){
const colecao = {
key: chave,
items: []
};
let chave_objeto;
let chave_objeto_id;
let chave_associacao_id;
const chaves_propria = Object.keys(regras.rules[chave]);
for(let i = 0; i < chaves_propria.length; i++){
if(chaves_propria[i].startsWith('$')){
chave_objeto = chaves_propria[i];
console.log('CH ', chave_objeto);
chave_objeto_id = chave_objeto.split('_id')[0].split('$')[1];
console.log('CO ', chave_objeto_id);
break;
}
}
const items_obj = regras.rules[chave][chave_objeto];
for(const item in items_obj){
if(items_obj.hasOwnProperty(item) && !item.startsWith('.') && !item.startsWith('$')){
colecao.items.push({
name: item,
iskey: false,
figure: "Decision",
color: yellowgrad
});
} else if(item.startsWith('$') && item.endsWith('_id')) {
chave_associacao_id = item.split('_id')[0].split('$')[1];;
}
}
if (chave !== chave_objeto_id){
console.log('EX CHAVE 1 ', chave, ' CHAVE 2 ', chave_objeto_id);
linkDataArray.push({
from: chave,
to: chave_objeto_id,
//text: "0..N",
//toText: "1"
});
}
if (chave_associacao_id !== undefined) {
console.log('AS CHAVE 1 ', chave, ' CHAVE 2 ', chave_associacao_id);
linkDataArray.push({
from: chave,
to: chave_associacao_id,
//text: "0..N",
//toText: "1"
});
}
nodeDataArray.push(colecao);
}
}
myDiagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
});
fileReader.readAsText(file);
}
document.getElementById('file').addEventListener('change', handleFileSelect, false);
}
</script>
</head>
<body onload="init()">
<div id="sample">
<input type="file" id="file" name="files[]" />
<div id="myDiagramDiv" style="background-color: white; border: solid 1px black; width: 100%; height: 700px"></div>
</div>
</body>
</html>