-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
308 lines (276 loc) ยท 11.7 KB
/
index.html
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>Ember ERD</title>
<meta name='description' content=''>
<meta name='viewport' content='width=device-width', initial-scale='1'>
<style>
body,
html {
width: 100%;
height: 100%;
}
.models {
/*display: flex;
flex-direction: row;
overflow-x: scroll;
flex-wrap: wrap;*/
display: block;
}
.model {
display: inline-block;
border: 1px solid black;
width: 400px;
// height: 200px;
margin: 20px;
/*display: flex;*/
align-items: center;
justify-content: center;
z-index: 100;
}
.model .name,
.model .attrs,
.model .relations {
width: 30%;
display: inline-block;
padding: 2px;
z-index: 100;
height: 100%;
}
.model .attrs {
border-left: 1px solid black;
border-right: 1px solid black;
min-height: 150px;
}
.model .name {
font-weight: 900;
}
.model .attrs .attr-val {
color: lightgrey;
display: inline-block;
}
.arrow {
position: absolute;
background: black;
width: 40px;
height: 3px;
transform-origin: 0% 50%;
transition: all 100ms cubic-bezier(.8,.5,1,.8);
/*border-radius: 50%/100px 100px 0 0;*/
/*background-image: url("http://www.iconsdb.com/icons/preview/black/arrow-18-xxl.png");
background-size: cover;
background-position: center;*/
z-index: -1000;
}
.arrow:after {
display: block;
content:'';
border-top: 7px solid transparent;
border-bottom: 8px solid transparent;
border-left: 20px solid red;
transform: translate(40px, -5px);
}
.row {
text-align: center;
}
.row.offset .model {
width: 400px;
}
</style>
</head>
<body>
<h1> Ember ERD Model Visualizer</h1>
<div class="models">
<div class='row'><div class="model" data-model="user"
data-belongsTo=""
data-hasMany="pets battles gameStats">
<div class="name">
user
</div>
<div class="attrs">
currency <span class='attr-val'>string')</span><br /> email <span class='attr-val'>string')</span><br /> uid <span class='attr-val'>string')</span><br /> nickname <span class='attr-val'>string')</span><br /> image <span class='attr-val'>string')</span><br /> online <span class='attr-val'>boolean')</span><br /> avatar <span class='attr-val'>string')</span><br />
</div>
<div class="relations">
belongsTo:
<br />
hasMany: pets, battles, gameStats
</div>
</div><div class="model" data-model="pet"
data-belongsTo="user"
data-hasMany="stats battles petStates">
<div class="name">
pet
</div>
<div class="attrs">
name <span class='attr-val'>string')</span><br /> level <span class='attr-val'>number')</span><br /> vertices <span class='attr-val'>number')</span><br /> colour <span class='attr-val'>string')</span><br />
</div>
<div class="relations">
belongsTo: user
<br />
hasMany: stats, battles, petStates
</div>
</div></div><div class='row offset'><div class="model" data-model="battle"
data-belongsTo="state"
data-hasMany="users pets">
<div class="name">
battle
</div>
<div class="attrs">
winnerId <span class='attr-val'>number')</span><br /> loserId <span class='attr-val'>number')</span><br /> winnerEmail <span class='attr-val'>string')</span><br /> loserEmail <span class='attr-val'>string')</span><br /> name <span class='attr-val'>string')</span><br /> challengedEmail <span class='attr-val'>string')</span><br /> challengerEmail <span class='attr-val'>string')</span><br /> status <span class='attr-val'>string')</span><br /> challengerPetId <span class='attr-val'>string')</span><br /> challengedPetId <span class='attr-val'>string')</span><br /> challengerPet <span class='attr-val'>)</span><br /> challengedPet <span class='attr-val'>)</span><br /> currentTurn <span class='attr-val'>number')</span><br /> currentTurnEmail <span class='attr-val'>string')</span><br /> createdAt <span class='attr-val'>string')</span><br />
</div>
<div class="relations">
belongsTo: state
<br />
hasMany: users, pets
</div>
</div></div><div class='row '><div class="model" data-model="state"
data-belongsTo="battle"
data-hasMany="petStates">
<div class="name">
state
</div>
<div class="attrs">
name <span class='attr-val'>string')</span><br /> currentTurn <span class='attr-val'>integer')</span><br />
</div>
<div class="relations">
belongsTo: battle
<br />
hasMany: petStates
</div>
</div></div><div class='row offset'><div class="model" data-model="stat"
data-belongsTo="pet"
data-hasMany="">
<div class="name">
stat
</div>
<div class="attrs">
statType <span class='attr-val'>string')</span><br /> value <span class='attr-val'>number')</span><br />
</div>
<div class="relations">
belongsTo: pet
<br />
hasMany:
</div>
</div><div class="model" data-model="petState"
data-belongsTo="state pet"
data-hasMany="">
<div class="name">
petState
</div>
<div class="attrs">
currentHealth <span class='attr-val'>number')</span><br /> currentAttack <span class='attr-val'>number')</span><br /> currentDefence <span class='attr-val'>number')</span><br /> shield <span class='attr-val'>boolean')</span><br />
</div>
<div class="relations">
belongsTo: state, pet
<br />
hasMany:
</div>
</div><div class="model" data-model="gameStat"
data-belongsTo="user"
data-hasMany="">
<div class="name">
gameStat
</div>
<div class="attrs">
name <span class='attr-val'>string')</span><br /> value <span class='attr-val'>number')</span><br />
</div>
<div class="relations">
belongsTo: user
<br />
hasMany:
</div>
</div><div class="model" data-model="balanceChange"
data-belongsTo=""
data-hasMany="">
<div class="name">
balanceChange
</div>
<div class="attrs">
changeType <span class='attr-val'>string')</span><br /> entryDate <span class='attr-val'>string')</span><br /> value <span class='attr-val'>number')</span><br />
</div>
<div class="relations">
belongsTo:
<br />
hasMany:
</div>
</div>
</div>
<script>
function angle(p1,p2) {
var dx=p2.x-p1.x,
dy=p2.y-p1.y,
c=Math.sqrt(dx*dx+dy*dy),
deg;
deg=(c>0) ? Math.asin(dy/c)/(Math.PI/180) : 0;
deg=(dx>0) ? deg : 180-deg;
return (deg).toFixed(2);
}
function pythagoras(point1, point2) {
return (Math.sqrt(Math.pow(Math.abs(point1.x-point2.x), 2) + Math.pow(Math.abs(point1.y-point2.y), 2)))
}
init = function() {
var arrows = document.getElementsByClassName('arrow');
for (var i = 0; i < arrows.length; i++) {
(function() {
arrows[i].remove();
})()
};
var models = document.getElementsByClassName('model');
var belongsTo, hasMany, modelName;
for (var i =0; i < models.length; i++) {
belongsTo = models[i].dataset.belongsto
hasMany = models[i].dataset.hasmany
modelName = models[i].dataset.model
var divFrom = models[i]
if (hasMany.length !== 0) {
// name is pluralized so remove s to search
var rels = hasMany.split(" ")
for (var j = 0; j < rels.length; j++) {
var toName = rels[j].slice(0, -1);
var divTo = document.querySelectorAll("[data-model='"+toName+"']")[0]
var divFromCoords = divFrom.getBoundingClientRect()
var divToCoords = divTo.getBoundingClientRect()
var divFromCenter = {
"x": divFromCoords.left + divFromCoords.width/2,
"y": divFromCoords.top + divFromCoords.height/2,
}
var divToCenter = {
"x": divToCoords.left + divToCoords.width/2,
"y": divToCoords.top + divToCoords.height/2,
}
// need to figure out where to put arrow,
// if the model from is above model to, then we aim for top of container
// if model from is below to (via top in coords), aim for the bottom of the model container
var newArrow = document.createElement("div");
newArrow.className += "arrow"
newArrow.className += " " + modelName + "_to_" + toName
newArrow.style.top = divFromCenter.y + "px";
newArrow.style.left = (divFromCenter.x) + "px"
// newArrow.style.bottom = divFromCoords.bottom + "px"
// newArrow.style.right = divFromCoords.right + "px";
var deg = angle({"x": divFromCenter.x,
"y": divFromCenter.y
},
{"x": divToCenter.x,
"y": divToCenter.y
});
var distanceForArrow = pythagoras(divFromCenter, divToCenter) + "px"
var prefixTransform = "transform";
newArrow.style[prefixTransform]="rotate(" + deg + "deg)";
newArrow.style.width = distanceForArrow;
document.body.appendChild(newArrow);
if (divFromCoords.top > divToCoords.top) {
// arrow needs to point down
} else {
// arrow needs to point up
}
}
}
}
}
window.onresize = init
init()
</script>
</body></html>