Merge lp:~elof-bigestans/lenasys/elofsbranch into lp:lenasys

Proposed by Elof Bigestans
Status: Rejected
Rejected by: Gustav Hartvigsson
Proposed branch: lp:~elof-bigestans/lenasys/elofsbranch
Merge into: lp:lenasys
Diff against target: 1900 lines (+634/-1224)
5 files modified
CodeViewer/Lindex.html (+11/-11)
ErModeller/canvas.css (+13/-3)
ErModeller/canvas.js (+609/-601)
ErModeller/canvas_ER_demo_duggajs.html (+1/-1)
ErModeller/dugga.js (+0/-608)
To merge this branch: bzr merge lp:~elof-bigestans/lenasys/elofsbranch
Reviewer Review Type Date Requested Status
lenasysmaint Pending
Review via email: mp+157293@code.launchpad.net

Description of the change

Fixed bugs pertaining to ErModeller

To post a comment you must log in.
21. By Elof Bigestans <email address hidden>

 * Fixed bug #1164524 (in LIndex.html)

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CodeViewer/Lindex.html'
2--- CodeViewer/Lindex.html 2013-04-03 08:20:14 +0000
3+++ CodeViewer/Lindex.html 2013-04-05 07:55:26 +0000
4@@ -76,17 +76,17 @@
5
6 <h2 id="DOMExamples">DOM Examples</h2>
7 <div class="container">
8- <a href='DOMExample1/DOMExample1.php'>DOM Example 1: Initiation and simple navigation</a><br>
9- <a href='DOMExample1b/DOMExample1b.php'>DOM Example 2: Attribute navigation</a><br>
10- <a href='DOMExample1c/DOMExample1c.php'>DOM Example 3: Advanced navigation</a><br>
11- <a href='DOMExample1d/DOMExample1d.php'>DOM Example 4: Advanced navigation</a><br>
12- <a href='DOMExample2/DOMExample2.php'>DOM Example 5: Validation #1</a><br>
13- <a href='DOMExample2b/DOMExample2b.php'>DOM Example 6: Validation #2</a><br>
14- <a href='DOMExample2c/DOMExample2c.php'>DOM Example 7: Validation #3</a><br>
15- <a href='DOMExample2d/DOMExample2d.php'>DOM Example 8: Validation #4</a><br>
16- <a href='DOMExample2e/DOMExample2e.php'>DOM Example 9: Validation #5 </a><br>
17- <a href='DOMExample3/DOMExample3.php'>DOM Example 10: XPATH #1</a><br>
18- <a href='DOMExample3b/DOMExample3b.php'>DOM Example 11: XPATH #2 Context Nodes</a><br>
19+ <a href='DomExample1/DomExample1.php'>DOM Example 1: Initiation and simple navigation</a><br>
20+ <a href='DomExample1b/DomExample1b.php'>DOM Example 2: Attribute navigation</a><br>
21+ <a href='DomExample1c/DomExample1c.php'>DOM Example 3: Advanced navigation</a><br>
22+ <a href='DomExample1d/DomExample1d.php'>DOM Example 4: Advanced navigation</a><br>
23+ <a href='DomExample2/DomExample2.php'>DOM Example 5: Validation #1</a><br>
24+ <a href='DomExample2b/DomExample2b.php'>DOM Example 6: Validation #2</a><br>
25+ <a href='DomExample2c/DomExample2c.php'>DOM Example 7: Validation #3</a><br>
26+ <a href='DomExample2d/DomExample2d.php'>DOM Example 8: Validation #4</a><br>
27+ <a href='DomExample2e/DomExample2e.php'>DOM Example 9: Validation #5 </a><br>
28+ <a href='DomExample3/DomExample3.php'>DOM Example 10: XPATH #1</a><br>
29+ <a href='DomExample3b/DomExample3b.php'>DOM Example 11: XPATH #2 Context Nodes</a><br>
30 </div>
31
32 <h2 id="XSLTExamples">XSLT Examples</h2>
33
34=== modified file 'ErModeller/canvas.css'
35--- ErModeller/canvas.css 2013-04-04 08:48:09 +0000
36+++ ErModeller/canvas.css 2013-04-05 07:55:26 +0000
37@@ -1,3 +1,13 @@
38-#a {border:2px solid black;}
39-#infobox {padding:4px;}
40-#background {border:2px solid black;background-color:#fed; width:300px;height:450px;}
41+#a {
42+ border:2px solid black;
43+}
44+
45+#infobox {
46+ padding:4px;
47+}
48+
49+#background {
50+ border:2px solid black;
51+ background-color:#fed;
52+ width:300px;height:450px;
53+}
54\ No newline at end of file
55
56=== modified file 'ErModeller/canvas.js'
57--- ErModeller/canvas.js 2013-04-03 09:15:09 +0000
58+++ ErModeller/canvas.js 2013-04-05 07:55:26 +0000
59@@ -1,604 +1,612 @@
60- var startx = 0;
61- var starty = 0;
62- var deltax = 0;
63- var deltay = 0;
64- var gridsize = 20;
65-
66- // Multi-select move offset
67- var offsx = 0;
68- var offsy = 0;
69- // Drawing Globals -- For while in transit drawing
70- var drawlinesx;
71- var drawlinesy;
72- var drawlinedx;
73- var drawlinedy;
74- var drawlinekind = 0;
75- // List of objects
76- // List of identifiers
77- // List of selected object identifiers
78- // The context object
79- var Objects = new Array();
80- var Selected = new Array();
81- var Identifiers = new Array();
82- var ContextObj;
83- // Mouse Down Result
84- var downRes;
85- // User Interface Mode Variables
86- var multiselect = 0;
87- var dragsensitivity = 12;
88- var sidetol = 12;
89- var printstr;
90-
91- /*
92- User interface callbacks
93- */
94- function handler_mouseup()
95- {
96- if(clickstate == 1) {
97- // Either select on/off for multi or single select
98- if(multiselect) {
99- if(Selected[downRes.objid]) {
100- Selected[downRes.objid] = false;
101- } else {
102- Selected[downRes.objid] = true;
103- }
104- } else {
105- if(ContextObj == downRes.objid) {
106- ContextObj = "";
107- } else {
108- ContextObj = downRes.objid;
109- }
110- }
111- } else if(clickstate == 8) {
112- // Draw Attribute Line
113- upRes=mouseover(gridx,gridy);
114- if(upRes.code != "None") {
115- obj = Objects[downRes.objid];
116- if(upRes.typ == "ERAttribute" || upRes.typ == "Entity" || upRes.typ == "ERRel") {
117- obj.DrawtoID = upRes.objid;
118- obj.DrawfromSide = downRes.side;
119- if(upRes.side != "None") {
120- obj.DrawtoSide = upRes.side;
121- obj.DrawtoPerc = upRes.sideperc;
122- } else {
123- upobj = Objects[downRes.objid];
124- var sid = 1;
125- var perco = 0.5;
126- var x1g = Math.abs(upRes.x1 - gridx);
127- var x2g = Math.abs(upRes.x2 - gridx);
128- var y1g = Math.abs(upRes.y1 - gridy);
129- var y2g = Math.abs(upRes.y2 - gridy);
130- if(x1g <= x2g && x1g <= y1g && x1g <= y2g){
131- sid = 1;
132- perco = makesideperc(gridy, upRes.y1, upRes.y2);
133- } else if(x2g <= x1g && x2g <= y1g && x2g <= y2g){
134- sid = 3;
135- perco = makesideperc(gridy, upRes.y1, upRes.y2);
136- } else if(y1g <= x1g && y1g <= x2g && y1g <= y2g){
137- sid = 4;
138- perco = makesideperc(gridx, upRes.x1, upRes.x2);
139- } else if(y2g <= x1g && y2g <= x2g && y2g <= y1g){
140- sid = 2;
141- perco = makesideperc(gridx, upRes.x1, upRes.x2);
142- }
143- obj.DrawtoSide = sid;
144- obj.DrawtoPerc = perco;
145- }
146- if(upRes.typ == "ERAttribute" || upRes.typ == "ERRel") obj.DrawtoPerc = 0.5;
147- }
148- }
149- } else if(clickstate == 9) {
150- // Draw Relationship line
151- upRes = mouseover(gridx, gridy);
152- if(upRes.code != "None") {
153- obj = Objects[downRes.objid];
154- if(upRes.side != "None") {
155- if(obj.DrawtoID == "None") {
156- obj.DrawtoID = upRes.objid;
157- obj.DrawtoSide = upRes.side;
158- obj.DrawtoPerc = upRes.sideperc;
159- obj.DrawfromSide = downRes.side;
160- } else {
161- obj.DrawtoIDDest = upRes.objid;
162- obj.DrawtoSideDest = upRes.side;
163- obj.DrawtoPercDest = upRes.sideperc;
164- obj.DrawfromSideDest = downRes.side;
165- }
166- } else {
167- upobj = Objects[downRes.objid];
168- var sid = 1;
169- var perco = 0.5;
170- var x1g = Math.abs(upRes.x1-gridx);
171- var x2g = Math.abs(upRes.x2-gridx);
172- var y1g = Math.abs(upRes.y1-gridy);
173- var y2g = Math.abs(upRes.y2-gridy);
174- if(x1g <= x2g && x1g <= y1g && x1g <= y2g) {
175- sid = 1;
176- perco = makesideperc(gridy, upRes.y1, upRes.y2);
177- } else if(x2g <= x1g && x2g <= y1g && x2g <= y2g) {
178- sid = 3;
179- perco = makesideperc(gridy, upRes.y1, upRes.y2);
180- } else if(y1g <= x1g && y1g <= x2g && y1g <= y2g) {
181- sid = 4;
182- perco = makesideperc(gridx, upRes.x1, upRes.x2);
183- } else if(y2g <= x1g && y2g <= x2g && y2g <= y1g){
184- sid = 2;
185- perco = makesideperc(gridx, upRes.x1, upRes.x2);
186- }
187- if(obj.DrawtoID == "None") {
188- obj.DrawtoID = upRes.objid;
189- obj.DrawtoSide = sid;
190- obj.DrawtoPerc = perco;
191- obj.DrawfromSide = downRes.side;
192- } else {
193- obj.DrawtoIDDest = upRes.objid;
194- obj.DrawtoSideDest = sid;
195- obj.DrawtoPercDest = perco;
196- obj.DrawfromSideDest = downRes.side;
197- }
198- }
199- }
200- }
201- clickstate = 0;
202- cpsel = 0;
203- drawlinekind = 0;
204- }
205- /*
206- * Mouse down state
207- */
208- function handler_mousedown() {
209- clickstate = 1;
210- downRes = mouseover(gridx, gridy);
211- startx = gridx;
212- starty = gridy;
213- }
214-
215- /*
216- * Mouse move
217- */
218- function handler_mousemove(cx, cy) {
219+var startx = 0;
220+var starty = 0;
221+var deltax = 0;
222+var deltay = 0;
223+var gridsize = 20;
224+
225+// Multi-select move offset
226+var offsx = 0;
227+var offsy = 0;
228+
229+// Drawing Globals -- For while in transit drawing
230+var drawlinesx;
231+var drawlinesy;
232+var drawlinedx;
233+var drawlinedy;
234+var drawlinekind = 0;
235+
236+// List of objects
237+var Objects = new Array();
238+
239+// List of identifiers
240+var Selected = new Array();
241+
242+// List of selected object identifiers
243+var Identifiers = new Array();
244+
245+// The context object
246+var ContextObj;
247+
248+// Mouse Down Result
249+var downRes;
250+// User Interface Mode Variables
251+var multiselect = 0;
252+var dragsensitivity = 12;
253+var sidetol = 12;
254+var printstr;
255+
256+/*
257+ * User interface callbacks
258+ */
259+function handler_mouseup() {
260+ if(clickstate == 1) {
261+
262+ // Either select on/off for multi or single select
263+ if(multiselect) {
264+ if(Selected[downRes.objid]) {
265+ Selected[downRes.objid] = false;
266+ } else {
267+ Selected[downRes.objid] = true;
268+ }
269+ } else {
270+ if(ContextObj == downRes.objid) {
271+ ContextObj = "";
272+ } else {
273+ ContextObj = downRes.objid;
274+ }
275+ }
276+ } else if(clickstate == 8) {
277+
278+ // Draw Attribute Line
279+ upRes=mouseover(gridx,gridy);
280+ if(upRes.code != "None") {
281+ obj = Objects[downRes.objid];
282+ if(upRes.typ == "ERAttribute" || upRes.typ == "Entity" || upRes.typ == "ERRel") {
283+ obj.DrawtoID = upRes.objid;
284+ obj.DrawfromSide = downRes.side;
285+ if(upRes.side != "None") {
286+ obj.DrawtoSide = upRes.side;
287+ obj.DrawtoPerc = upRes.sideperc;
288+ } else {
289+ upobj = Objects[downRes.objid];
290+ var sid = 1;
291+ var perco = 0.5;
292+ var x1g = Math.abs(upRes.x1 - gridx);
293+ var x2g = Math.abs(upRes.x2 - gridx);
294+ var y1g = Math.abs(upRes.y1 - gridy);
295+ var y2g = Math.abs(upRes.y2 - gridy);
296+ if(x1g <= x2g && x1g <= y1g && x1g <= y2g){
297+ sid = 1;
298+ perco = makesideperc(gridy, upRes.y1, upRes.y2);
299+ } else if(x2g <= x1g && x2g <= y1g && x2g <= y2g){
300+ sid = 3;
301+ perco = makesideperc(gridy, upRes.y1, upRes.y2);
302+ } else if(y1g <= x1g && y1g <= x2g && y1g <= y2g){
303+ sid = 4;
304+ perco = makesideperc(gridx, upRes.x1, upRes.x2);
305+ } else if(y2g <= x1g && y2g <= x2g && y2g <= y1g){
306+ sid = 2;
307+ perco = makesideperc(gridx, upRes.x1, upRes.x2);
308+ }
309+ obj.DrawtoSide = sid;
310+ obj.DrawtoPerc = perco;
311+ }
312+ if(upRes.typ == "ERAttribute" || upRes.typ == "ERRel") obj.DrawtoPerc = 0.5;
313+ }
314+ }
315+ } else if(clickstate == 9) {
316+
317+ // Draw Relationship line
318+ upRes = mouseover(gridx, gridy);
319+ if(upRes.code != "None") {
320+ obj = Objects[downRes.objid];
321+ if(upRes.side != "None") {
322+ if(obj.DrawtoID == "None") {
323+ obj.DrawtoID = upRes.objid;
324+ obj.DrawtoSide = upRes.side;
325+ obj.DrawtoPerc = upRes.sideperc;
326+ obj.DrawfromSide = downRes.side;
327+ } else {
328+ obj.DrawtoIDDest = upRes.objid;
329+ obj.DrawtoSideDest = upRes.side;
330+ obj.DrawtoPercDest = upRes.sideperc;
331+ obj.DrawfromSideDest = downRes.side;
332+ }
333+ } else {
334+ upobj = Objects[downRes.objid];
335+ var sid = 1;
336+ var perco = 0.5;
337+ var x1g = Math.abs(upRes.x1-gridx);
338+ var x2g = Math.abs(upRes.x2-gridx);
339+ var y1g = Math.abs(upRes.y1-gridy);
340+ var y2g = Math.abs(upRes.y2-gridy);
341+ if(x1g <= x2g && x1g <= y1g && x1g <= y2g) {
342+ sid = 1;
343+ perco = makesideperc(gridy, upRes.y1, upRes.y2);
344+ } else if(x2g <= x1g && x2g <= y1g && x2g <= y2g) {
345+ sid = 3;
346+ perco = makesideperc(gridy, upRes.y1, upRes.y2);
347+ } else if(y1g <= x1g && y1g <= x2g && y1g <= y2g) {
348+ sid = 4;
349+ perco = makesideperc(gridx, upRes.x1, upRes.x2);
350+ } else if(y2g <= x1g && y2g <= x2g && y2g <= y1g){
351+ sid = 2;
352+ perco = makesideperc(gridx, upRes.x1, upRes.x2);
353+ }
354+ if(obj.DrawtoID == "None") {
355+ obj.DrawtoID = upRes.objid;
356+ obj.DrawtoSide = sid;
357+ obj.DrawtoPerc = perco;
358+ obj.DrawfromSide = downRes.side;
359+ } else {
360+ obj.DrawtoIDDest = upRes.objid;
361+ obj.DrawtoSideDest = sid;
362+ obj.DrawtoPercDest = perco;
363+ obj.DrawfromSideDest = downRes.side;
364+ }
365+ }
366+ }
367+ }
368+ clickstate = 0;
369+ cpsel = 0;
370+ drawlinekind = 0;
371+}
372+/*
373+ * Mouse down state
374+ */
375+function handler_mousedown() {
376+ clickstate = 1;
377+ downRes = mouseover(gridx, gridy);
378+ startx = gridx;
379+ starty = gridy;
380+}
381+
382+/*
383+ * Mouse move
384+ */
385+function handler_mousemove(cx, cy) {
386 // gridx=Math.round((cx-(gridsize/2.0))/gridsize)*gridsize;
387 // gridy=Math.round((cy-(gridsize/2.0))/gridsize)*gridsize;
388- gridx = cx;
389- gridy = cy;
390- deltax = startx - gridx;
391- deltay = starty - gridy;
392- // We start drag mode
393- if((distance(gridx, gridy, startx, starty) > dragsensitivity) && clickstate == 1) {
394- clickstate = 2;
395- }
396- // We are in drag mode
397- if(clickstate == 2) {
398- // Single Object Move - If Not Selected, Or if Selected and Center Area Is Dragged
399- if((downRes.typ == "Entity" || downRes.typ == "ERAttribute" || downRes.typ == "ERRel") && (downRes.code == "NonSel" || (downRes.code == "Cont" && downRes.side == "None") || (downRes.code == "ContDraw" && downRes.side == "None"))) {
400- clickstate = 3;
401- }
402- // Single Object Scale Left
403- if((downRes.typ == "Entity" || downRes.typ == "ERAttribute") && (downRes.code == "Cont" && downRes.side == "1")) {
404- clickstate=4;
405- }
406- // Single Object Scale Bottom
407- if((downRes.typ == "Entity" || downRes.typ == "ERAttribute") && (downRes.code == "Cont" && downRes.side == "2")) {
408- clickstate=5;
409- }
410- // Single Object Scale Right
411- if((downRes.typ == "Entity" || downRes.typ == "ERAttribute") && (downRes.code == "Cont" && downRes.side == "3")) {
412- clickstate=6;
413- }
414- // Single Object Scale Top
415- if((downRes.typ == "Entity" || downRes.typ == "ERAttribute") && (downRes.code == "Cont" && downRes.side == "4")) {
416- clickstate=7;
417- }
418- if(downRes.typ == "ERAttribute" && downRes.code == "ContDraw" && downRes.side != "None") {
419- clickstate=8; // Attribute Connection Draw
420- drawlinekind=1; // Tell drawing engine to draw attribute line symbol
421- if(downRes.side == "1") {
422- drawlinesx = downRes.x1; // Initiate start parameters for line drawing left side
423- drawlinesy = downRes.y1 + ((downRes.y2 - downRes.y1) * 0.5);
424- } else if(downRes.side == "2") {
425- drawlinesx = downRes.x1 + ((downRes.x2 - downRes.x1) * 0.5); // Initiate start parameters for line drawing bottom side
426- drawlinesy = downRes.y2;
427- } else if(downRes.side == "3") {
428- drawlinesx = downRes.x2; // Initiate start parameters for line drawing left side
429- drawlinesy = downRes.y1 + ((downRes.y2 - downRes.y1) * 0.5);
430- } else if(downRes.side == "4") {
431- drawlinesx = downRes.x1 + ((downRes.x2 - downRes.x1) * 0.5); // Initiate start parameters for line drawing bottom side
432- drawlinesy = downRes.y1;
433- }
434- drawlinedx = drawlinesx;
435- drawlinedy = drawlinesy;
436- }
437- if(downRes.typ == "ERRel" && downRes.code == "ContDraw" && downRes.side != "None") {
438- var obj=Objects[downRes.objid];
439- if(downRes.side != obj.DrawfromSide && downRes.side != obj.DrawfromSideDest) {
440- clickstate = 9; // Attribute Connection Draw
441- drawlinekind = 1; // Tell drawing engine to draw relation line symbol
442- if(downRes.side == "1") {
443- drawlinesx = downRes.x1; // Initiate start parameters for line drawing left side
444- drawlinesy = downRes.y1 + ((downRes.y2 - downRes.y1) * 0.5);
445- } else if(downRes.side == "2") {
446- drawlinesx = downRes.x1 + ((downRes.x2 - downRes.x1) * 0.5); // Initiate start parameters for line drawing bottom side
447- drawlinesy = downRes.y2;
448- } else if(downRes.side == "3") {
449- drawlinesx = downRes.x2; // Initiate start parameters for line drawing left side
450- drawlinesy = downRes.y1 + ((downRes.y2 - downRes.y1) * 0.5);
451- } else if(downRes.side == "4") {
452- drawlinesx = downRes.x1 + ((downRes.x2 - downRes.x1) * 0.5); // Initiate start parameters for line drawing bottom side
453- drawlinesy = downRes.y1;
454- }
455- drawlinedx = drawlinesx;
456- drawlinedy = drawlinesy;
457- }
458- }
459- }
460- if(clickstate > 2) {
461- var obj = Objects[downRes.objid];
462- }
463- if(clickstate == 3) { // We are in single rectangular object move
464- obj.x1 = downRes.x1 - deltax;
465- obj.y1 = downRes.y1 - deltay;
466- obj.x2 = downRes.x2 - deltax;
467- obj.y2 = downRes.y2 - deltay;
468- } else if(clickstate == 4) { // We are in single rectangular object scale left
469- if((obj.x2 - downRes.x1 + deltax) > 60) obj.x1 = downRes.x1 - deltax;
470- } else if(clickstate == 5) { // We are in single rectangular object scale bottom
471- if((downRes.y2 - obj.y1 - deltay) > 40) obj.y2 = downRes.y2 - deltay;
472- } else if(clickstate==6) { // We are in single rectangular object scale right
473- if((downRes.x2 - obj.x1 - deltax) > 60) obj.x2 = downRes.x2 - deltax;
474- } else if(clickstate == 7) { // We are in single rectangular object scale top
475- if((obj.y2 - downRes.y1 + deltay) > 40) obj.y1 = downRes.y1 - deltay;
476- } else if(clickstate == 8 || clickstate == 9) { // We are in straight connective line drawing mode
477- drawlinedx = gridx;
478- drawlinedy = gridy;
479- }
480- }
481-
482- /*
483- * Call-forward for mouse-over event
484- */
485- function mouseover(x, y) {
486- // Code of touch, and if available object id and id of side of object that was touched
487- // Tolerances included as constant
488- var obj_code = "None";
489- var obj_id = "None";
490- var obj_sidentifier =" None";
491- var obj_sideperc = 0;
492- var obj_centerdist = 0;
493- var obj_type = "None";
494- var obj_x1 = 0;
495- var obj_y1 = 0;
496- var obj_x2 = 0;
497- var obj_y2 = 0;
498- var Cont;
499- var found = 0;
500- var side;
501- for(j = 0; j < Identifiers.length; j++) {
502- var objid = Identifiers[j];
503- var obj = Objects[objid];
504- var Sel = Selected[objid];
505- if(ContextObj == objid) {
506- Cont = 1;
507- } else {
508- Cont = 0;
509- }
510- // Compute coordinates including offset
511- if(obj.type == "Entity" || obj.type == "ERAttribute" || obj.type == "ERRel") {
512- x1 = obj.x1 + offsx;
513- y1 = obj.y1 + offsy;
514- x2 = obj.x2 + offsx;
515- y2 = obj.y2 + offsy;
516- rx = (x2 - x1) * 0.5;
517- ry = (y2 - y1) * 0.5;
518- }
519- found = 0;
520- // For each kind of clickable object, check if we are inside object and if so assign variables
521- // Any general properties for all object types are set when "found" is true
522- if(obj.type == "Entity") {
523- if(x > (x1 - sidetol) && y > (y1 - sidetol ) && x < (x2 + sidetol) && y < (y2 + sidetol)) {
524- obj_code = "NonSel";
525- if(Sel) {
526- obj_code = "Sel";
527- }
528- if(Cont) {
529- obj_code = "Cont";
530- }
531- side = computeside(x, y, x1, y1, x2, y2, sidetol);
532- obj_sidentifier = side.side;
533- obj_sideperc = side.perc;
534- obj_centerdist = side.dist;
535- found = 1;
536- }
537- } else if(obj.type=="ERAttribute") {
538- if(x > (x1 - sidetol) && y > (y1 - sidetol) && x < (x2 + sidetol) && y < (y2 + sidetol)) {
539- obj_code = "NonSel";
540- if(Sel) {
541- obj_code="Sel";
542- }
543- if(Cont) {
544- if(obj.DrawtoID == "None") {
545- obj_code = "ContDraw";
546- } else {
547- obj_code = "Cont";
548- }
549- }
550- side = computeside(x, y, x1, y1, x2, y2, sidetol);
551- obj_sidentifier = side.side;
552- obj_sideperc = side.perc;
553- obj_centerdist = side.dist;
554- found = 1;
555- }
556- } else if(obj.type == "ERRel") {
557- if(x > (x1 - sidetol) && y > (y1 - sidetol) && x < (x2 + sidetol) && y < (y2 + sidetol)) {
558- xk = x - x1;
559- // Colision detection against diamond
560- var inside = 0;
561- if(xk <= rx) {
562- if(y > (y1 + ry - xk - sidetol) && y < (y1 + ry + xk + sidetol)) {
563- inside = 1;
564- }
565- } else {
566- if(y > (y1 - rx + xk - sidetol) && y < ( y2 + rx - xk + sidetol)) {
567- inside = 1;
568- }
569- }
570- if(inside) {
571- if((x > (x1 - sidetol)) && (x < (x1 + sidetol)) && (y > (y1 + ry - sidetol)) && (y < (y1 + ry + sidetol))) {
572- obj_sidentifier = 1;
573- }
574- if((x > (x1 + rx - sidetol)) && (x < (x1 + rx + sidetol)) && (y > (y2 - sidetol)) && (y < (y2 + sidetol))) {
575- obj_sidentifier = 2;
576- }
577- if((x > (x2 - sidetol)) && (x < (x2 + sidetol)) && (y > (y1 + ry - sidetol)) && (y < (y1 + ry + sidetol))) {
578- obj_sidentifier = 3;
579- }
580- if((x > (x1 + rx - sidetol)) && (x < (x1 + rx + sidetol)) && (y > (y1 - sidetol)) && (y < (y1 + sidetol))) {
581- obj_sidentifier = 4;
582- }
583- obj_code = "NonSel";
584- if(Sel) {
585- obj_code = "Sel";
586- }
587- if(Cont) {
588- if(obj.DrawtoID == "None"){
589- obj_code = "ContDraw";
590- } else if(obj.DrawtoIDDest == "None") {
591- obj_code = "ContDraw";
592- } else {
593- obj_code = "Cont";
594- }
595- }
596- obj_sideperc = 0.5;
597- found = 1;
598- }
599- }
600- }
601- if(found == 1) {
602- // Save coordinates at time of click
603- obj_x1 = x1;
604- obj_y1 = y1;
605- obj_x2 = x2;
606- obj_y2 = y2;
607- obj_id = objid;
608- obj_type = obj.type;
609- printstr=obj_id + " " + obj_sidentifier + " " + obj_sideperc;
610- }
611- }
612- return {
613- objid:obj_id,
614- code:obj_code,
615- side:obj_sidentifier,
616- sideperc:obj_sideperc,
617- centerdist:obj_centerdist,
618- typ:obj_type,
619- x1:obj_x1,
620- y1:obj_y1,
621- x2:obj_x2,
622- y2:obj_y2
623- }
624- }
625-
626- /*
627- *
628- */
629- function importdata() {
630- for(i = 0; i < 7; i++) {
631- if(i == 0) {
632- obj = jQuery.parseJSON('{"type":"ERAttribute","id":"ATT1","kind":"Multiple","name":"Addressfosoppooo","x1":220,"y1":100,"x2":300,"y2":140, "DrawtoID":"None", "DrawfromSide":"None","DrawtoSide":"None", "DrawtoPerc":"None", "DrawX1":"", "DrawY1":"", "DrawX2":"","DrawY2":""}');
633- }
634- if(i == 1) {
635- obj = jQuery.parseJSON('{"type":"Entity","id":"ENT2","kind":"Weak","name":"Carsmashoepppoloo","x1":100,"y1":160,"x2":220,"y2":220}');
636- }
637- if(i == 2) {
638- obj = jQuery.parseJSON('{"type":"ERAttribute","id":"ATT3","kind":"Key","name":"SSNFooomesPoo","x1":160,"y1":260,"x2":260,"y2":300, "DrawtoID":"None", "DrawfromSide":"None","DrawtoSide":"None", "DrawtoPerc":"None", "DrawX1":"", "DrawY1":"", "DrawX2":"","DrawY2":""}');
639- }
640- if(i == 3) {
641- obj = jQuery.parseJSON('{"type":"Entity","id":"ENT4","kind":"Strong","name":"Trailerfpdddpeoooooe","x1":320,"y1":260,"x2":420,"y2":320}');
642- }
643- if(i == 4) {
644- obj = jQuery.parseJSON('{"type":"Entity","id":"ENT5","kind":"Strong","name":"Grail","x1":120,"y1":440,"x2":220,"y2":480}');
645- }
646- if(i == 5) {
647- obj = jQuery.parseJSON('{"type":"ERRel","id":"REL6","kind":"Strong","name":"FGFool","x1":460,"y1":160,"x2":520,"y2":220, "DrawtoID":"None", "DrawfromSide":"None","DrawtoSide":"None", "DrawtoPerc":"0", "DrawtoCard":"N", "DrawtoRole":"Fumo", "DrawtoXoffs":"20", "DrawtoYoffs":"50", "DrawtoIDDest":"None", "DrawfromSideDest":"None","DrawtoSideDest":"None", "DrawtoPercDest":"0", "DrawtoDestCard":"N", "DrawtoDestRole":"Luma", "DrawtoDestXoffs":"0", "DrawtoDestYoffs":"-50", "DrawX1":"", "DrawY1":"", "DrawX2":"","DrawY2":"","DrawX3":"", "DrawY3":"", "DrawX4":"","DrawY4":""}');
648- }
649- if(i == 6) {
650- obj = jQuery.parseJSON('{"type":"ERRel","id":"REL7","kind":"Weak","name":"PODrool","x1":360,"y1":360,"x2":420,"y2":420, "DrawtoID":"None", "DrawfromSide":"None","DrawtoSide":"None", "DrawtoPerc":"0", "DrawtoCard":"N", "DrawtoRole":"Kumo", "DrawtoXoffs":"60", "DrawtoYoffs":"70", "DrawtoIDDest":"None", "DrawfromSideDest":"None","DrawtoSideDest":"None", "DrawtoPercDest":"0", "DrawtoDestCard":"N", "DrawtoDestRole":"Zuuma", "DrawtoDestXoffs":"40", "DrawtoDestYoffs":"50", "DrawX1":"", "DrawY1":"", "DrawX2":"","DrawY2":"","DrawX3":"", "DrawY3":"", "DrawX4":"","DrawY4":""}');
651- }
652- objid = obj.id;
653- Objects[objid] = obj;
654- Identifiers.push(objid);
655- }
656- }
657-
658- /*
659- * prepareobj
660- * Prepares all kinds of objects, with local movement-offset (scrolling offset is handled with transforms??)
661- * Ofss in prepare are not finished.
662- */
663- function prepareobj(obji) {
664- var fromobj = Objects[obji];
665- // Attributes are prepared by re-pointing the DrawX1, DrawY1, DrawX2 and DrawY2 variables and Relationships are prepared by re-pointing DrawX1-DrawX4 and DrawY1-DrawY4
666- if((fromobj.type == "ERAttribute" || fromobj.type == "ERRel") && fromobj.DrawtoID != "None") {
667- var toid = fromobj.DrawtoID;
668- var toobj = Objects[toid];
669- var sidek;
670- if(fromobj.DrawtoIDDest != "None" && fromobj.DrawtoIDDest != undefined) {
671- var toiddest = fromobj.DrawtoIDDest;
672- var toobjdest = Objects[toiddest];
673- sidek = makeside(fromobj.DrawfromSideDest, fromobj.x1, fromobj.y1, fromobj.x2, fromobj.y2, 0.5);
674- fromobj.DrawX3 = sidek.x;
675- fromobj.DrawY3 = sidek.y;
676- sidek = makeside(fromobj.DrawtoSideDest, toobjdest.x1, toobjdest.y1, toobjdest.x2, toobjdest.y2, fromobj.DrawtoPercDest);
677- fromobj.DrawX4 = sidek.x;
678- fromobj.DrawY4 = sidek.y;
679- }
680- //printstr=fromobj.DrawfromSide+" "+fromobj.x1+" "+fromobj.y1+" "+fromobj.x2+" "+fromobj.y2+" :: "+fromobj.DrawtoSide+" "+toobj.x1+" "+toobj.y1+" "+toobj.x2+" "+toobj.y2+" "+fromobj.DrawtoPerc;
681- sidek = makeside(fromobj.DrawfromSide, fromobj.x1, fromobj.y1, fromobj.x2, fromobj.y2, 0.5);
682- fromobj.DrawX1 = sidek.x;
683- fromobj.DrawY1 = sidek.y;
684- sidek = makeside(fromobj.DrawtoSide, toobj.x1, toobj.y1, toobj.x2, toobj.y2, fromobj.DrawtoPerc);
685- fromobj.DrawX2 = sidek.x;
686- fromobj.DrawY2 = sidek.y;
687- }
688- }
689-
690- /*
691- * Drawobj
692- * Draws all kinds of objects, with local movement-offset (scrolling offset is handled with transforms??)
693- */
694- function drawobj(obji) {
695- var obj = Objects[obji];
696- var Sel = Selected[obji];
697- if(ContextObj == obji) {
698- Cont = 1;
699- } else {
700- Cont = 0;
701- }
702- context.strokeStyle = '#000';
703- context.lineWidth = 2.0;
704- // Compute coordinates including offset
705- if(obj.type == "Entity" || obj.type == "ERAttribute" || obj.type == "ERRel") {
706- x1 = obj.x1 + offsx;
707- y1 = obj.y1 + offsy;
708- x2 = obj.x2 + offsx;
709- y2 = obj.y2 + offsy;
710- rx = (x2 - x1) * 0.5;
711- ry = (y2 - y1) * 0.5;
712- }
713- if(obj.type == "Entity") {
714- //Draw Local Graphic
715- drawrect(x1, y1, x2, y2, "#000");
716- if(obj.kind == "Weak") {
717- drawrect(x1 + 5, y1 + 5, x2 - 5, y2 - 5, "#000");
718- cliptext(x1 + 5, y1 + 5, x2 - 5, y2 - 5, obj.name, "20px Calibri", "center", 8, 6, "#000", 1, 0);
719-
720- } else {
721- cliptext(x1, y1, x2, y2, obj.name, "20px Calibri", "center", 8, 6, "#000", 1, 0);
722- }
723- // Draw Select Marker
724- if(Sel || Cont) {
725- fourpoints(x1, y1 + ry, x2, y1 + ry, x1 + rx, y1, x1 + rx, y2, "#5f8");
726- }
727- } else if(obj.type == "ERAttribute") {
728- drawellipse(x1, y1, x2, y2);
729- if(obj.kind == "Key") {
730- cliptext(x1, y1, x2, y2, obj.name, "20px Calibri", "center", 8, 6, "#000", 2, 1);
731- } else {
732- cliptext(x1, y1, x2, y2, obj.name, "20px Calibri", "center", 8, 6, "#000", 2, 0);
733- }
734- if(obj.DrawtoID != "None") {
735- drawline(obj.DrawX1, obj.DrawY1, obj.DrawX2, obj.DrawY2, "#000", 2.0);
736- }
737- // Draw Select Marker
738- if(Cont && obj.DrawtoID == "None") {
739- fourpoints(x1, y1 + ry, x2, y1 + ry, x1 + rx, y1, x1 + rx, y2, "#fa2");
740- } else if(Sel || (Cont && obj.DrawtoID != "None")) {
741- fourpoints(x1, y1 + ry, x2, y1 + ry, x1 + rx, y1, x1 + rx, y2, "#5f8");
742- }
743- } else if(obj.type == "ERRel") {
744- if(obj.DrawtoID != "None") {
745- drawline(obj.DrawX1, obj.DrawY1, obj.DrawX2, obj.DrawY2, "#000", 2.0);
746- drawcardinality(obj.DrawX2, obj.DrawY2, obj.DrawtoSide, obj.DrawtoCard, obj.DrawtoXoffsCard, obj.DrawtoYoffsCard, "20px Calibri", 20, 1, "#0a0");
747- drawcardinality(obj.DrawX2, obj.DrawY2, obj.DrawtoSide, obj.DrawtoRole, obj.DrawtoXoffsRole, obj.DrawtoYoffsRole, "20px Calibri", 20, 2, "#0a0");
748-// function drawcardinality(x,y,side,tex,xoffs,yoffs,font,baseline,sign,color)
749-// if(i==5) obj = jQuery.parseJSON('{"type":"ERRel","id":"REL6","kind":"Strong","name":"FGFool","x1":460,"y1":160,"x2":520,"y2":220, "DrawtoID":"None", "DrawfromSide":"None","DrawtoSide":"None", "DrawtoPerc":"0", "DrawtoCard":"N", "DrawtoRole":"Fumo", "DrawtoXoffsCard":"20", "DrawtoYoffsCard":"50","DrawtoXoffsRole":"20", "DrawtoYoffsRole":"-50", "DrawtoIDDest":"None", "DrawfromSideDest":"None","DrawtoSideDest":"None", "DrawtoPercDest":"0", "DrawtoDestCard":"1", "DrawtoDestRole":"Luma", "DrawtoDestXoffsCard":"0", "DrawtoDestYoffsCard":"-50","DrawtoDestXoffsRole":"0", "DrawtoDestYoffsRole":"-50", "DrawX1":"", "DrawY1":"", "DrawX2":"","DrawY2":"","DrawX3":"", "DrawY3":"", "DrawX4":"","DrawY4":""}');
750-// if(i==6) obj = jQuery.parseJSON('{"type":"ERRel","id":"REL7","kind":"Weak","name":"PODrool","x1":360,"y1":360,"x2":420,"y2":420, "DrawtoID":"None", "DrawfromSide":"None","DrawtoSide":"None", "DrawtoPerc":"0", "DrawtoCard":"1", "DrawtoRole":"Kumo", "DrawtoXoffsCard":"60", "DrawtoYoffsCard":"70", "DrawtoXoffsCard":"80", "DrawtoYoffsCard":"-70", "DrawtoIDDest":"None", "DrawfromSideDest":"None","DrawtoSideDest":"None", "DrawtoPercDest":"0", "DrawtoDestCard":"N", "DrawtoDestRole":"Zuuma", "DrawtoDestXoffsCard":"40", "DrawtoDestYoffsCard":"50", "DrawtoDestXoffsRole":"40", "DrawtoDestYoffsRole":"50", "DrawX1":"", "DrawY1":"", "DrawX2":"","DrawY2":"","DrawX3":"", "DrawY3":"", "DrawX4":"","DrawY4":""}');
751- }
752- if(obj.DrawtoIDDest != "None") {
753- drawline(obj.DrawX3, obj.DrawY3, obj.DrawX4, obj.DrawY4, "#000", 2.0);
754- }
755- if(obj.kind == "Weak") {
756- drawdiamond(x1 - 4, y1 - 4, x2 + 4, y2 + 4);
757- drawdiamond(x1 + 4, y1 + 4, x2 - 4, y2 - 4);
758- cliptext(x1 + 8, y1 + 8, x2 - 8, y2 - 8, obj.name, "20px Calibri", "center", 8, 6, "#000", 3, 0);
759- } else {
760- drawdiamond(x1, y1, x2, y2, 0);
761- cliptext(x1, y1, x2, y2, obj.name, "20px Calibri", "center", 8, 6, "#000", 3, 0);
762- }
763- // Draw Select Markers
764- if(Sel || (Cont && obj.DrawtoID != "None" && obj.DrawtoIDDest != "None")) {
765- fourpoints(x1, y1 + ry, x2, y1 + ry, x1 + rx, y1, x1 + rx, y2, "#5f8");
766- } else if(Cont) {
767- if(obj.DrawfromSide != 1 && obj.DrawfromSideDest != 1) {
768- point(x1, y1 + ry, "#fa2");
769- }
770- if(obj.DrawfromSide != 2 && obj.DrawfromSideDest != 2) {
771- point(x1 + rx, y2, "#fa2");
772- }
773- if(obj.DrawfromSide != 3 && obj.DrawfromSideDest != 3) {
774- point(x2, y1 + ry, "#fa2");
775- }
776- if(obj.DrawfromSide != 4 && obj.DrawfromSideDest != 4) {
777- point(x1 + rx, y1, "#fa2");
778- }
779- }
780- }
781- }
782- importdata();
783-
784- /*
785- *
786- */
787- function foo() {
788- context.clearRect(0, 0, 600, 600);
789+ gridx = cx;
790+ gridy = cy;
791+ deltax = startx - gridx;
792+ deltay = starty - gridy;
793+ // We start drag mode
794+ if((distance(gridx, gridy, startx, starty) > dragsensitivity) && clickstate == 1) {
795+ clickstate = 2;
796+ }
797+ // We are in drag mode
798+ if(clickstate == 2) {
799+ // Single Object Move - If Not Selected, Or if Selected and Center Area Is Dragged
800+ if((downRes.typ == "Entity" || downRes.typ == "ERAttribute" || downRes.typ == "ERRel") && (downRes.code == "NonSel" || (downRes.code == "Cont" && downRes.side == "None") || (downRes.code == "ContDraw" && downRes.side == "None"))) {
801+ clickstate = 3;
802+ }
803+ // Single Object Scale Left
804+ if((downRes.typ == "Entity" || downRes.typ == "ERAttribute") && (downRes.code == "Cont" && downRes.side == "1")) {
805+ clickstate=4;
806+ }
807+ // Single Object Scale Bottom
808+ if((downRes.typ == "Entity" || downRes.typ == "ERAttribute") && (downRes.code == "Cont" && downRes.side == "2")) {
809+ clickstate=5;
810+ }
811+ // Single Object Scale Right
812+ if((downRes.typ == "Entity" || downRes.typ == "ERAttribute") && (downRes.code == "Cont" && downRes.side == "3")) {
813+ clickstate=6;
814+ }
815+ // Single Object Scale Top
816+ if((downRes.typ == "Entity" || downRes.typ == "ERAttribute") && (downRes.code == "Cont" && downRes.side == "4")) {
817+ clickstate=7;
818+ }
819+ if(downRes.typ == "ERAttribute" && downRes.code == "ContDraw" && downRes.side != "None") {
820+ clickstate=8; // Attribute Connection Draw
821+ drawlinekind=1; // Tell drawing engine to draw attribute line symbol
822+ if(downRes.side == "1") {
823+ drawlinesx = downRes.x1; // Initiate start parameters for line drawing left side
824+ drawlinesy = downRes.y1 + ((downRes.y2 - downRes.y1) * 0.5);
825+ } else if(downRes.side == "2") {
826+ drawlinesx = downRes.x1 + ((downRes.x2 - downRes.x1) * 0.5); // Initiate start parameters for line drawing bottom side
827+ drawlinesy = downRes.y2;
828+ } else if(downRes.side == "3") {
829+ drawlinesx = downRes.x2; // Initiate start parameters for line drawing left side
830+ drawlinesy = downRes.y1 + ((downRes.y2 - downRes.y1) * 0.5);
831+ } else if(downRes.side == "4") {
832+ drawlinesx = downRes.x1 + ((downRes.x2 - downRes.x1) * 0.5); // Initiate start parameters for line drawing bottom side
833+ drawlinesy = downRes.y1;
834+ }
835+ drawlinedx = drawlinesx;
836+ drawlinedy = drawlinesy;
837+ }
838+ if(downRes.typ == "ERRel" && downRes.code == "ContDraw" && downRes.side != "None") {
839+ var obj=Objects[downRes.objid];
840+ if(downRes.side != obj.DrawfromSide && downRes.side != obj.DrawfromSideDest) {
841+ clickstate = 9; // Attribute Connection Draw
842+ drawlinekind = 1; // Tell drawing engine to draw relation line symbol
843+ if(downRes.side == "1") {
844+ drawlinesx = downRes.x1; // Initiate start parameters for line drawing left side
845+ drawlinesy = downRes.y1 + ((downRes.y2 - downRes.y1) * 0.5);
846+ } else if(downRes.side == "2") {
847+ drawlinesx = downRes.x1 + ((downRes.x2 - downRes.x1) * 0.5); // Initiate start parameters for line drawing bottom side
848+ drawlinesy = downRes.y2;
849+ } else if(downRes.side == "3") {
850+ drawlinesx = downRes.x2; // Initiate start parameters for line drawing left side
851+ drawlinesy = downRes.y1 + ((downRes.y2 - downRes.y1) * 0.5);
852+ } else if(downRes.side == "4") {
853+ drawlinesx = downRes.x1 + ((downRes.x2 - downRes.x1) * 0.5); // Initiate start parameters for line drawing bottom side
854+ drawlinesy = downRes.y1;
855+ }
856+ drawlinedx = drawlinesx;
857+ drawlinedy = drawlinesy;
858+ }
859+ }
860+ }
861+ if(clickstate > 2) {
862+ var obj = Objects[downRes.objid];
863+ }
864+ if(clickstate == 3) { // We are in single rectangular object move
865+ obj.x1 = downRes.x1 - deltax;
866+ obj.y1 = downRes.y1 - deltay;
867+ obj.x2 = downRes.x2 - deltax;
868+ obj.y2 = downRes.y2 - deltay;
869+ } else if(clickstate == 4) { // We are in single rectangular object scale left
870+ if((obj.x2 - downRes.x1 + deltax) > 60) obj.x1 = downRes.x1 - deltax;
871+ } else if(clickstate == 5) { // We are in single rectangular object scale bottom
872+ if((downRes.y2 - obj.y1 - deltay) > 40) obj.y2 = downRes.y2 - deltay;
873+ } else if(clickstate==6) { // We are in single rectangular object scale right
874+ if((downRes.x2 - obj.x1 - deltax) > 60) obj.x2 = downRes.x2 - deltax;
875+ } else if(clickstate == 7) { // We are in single rectangular object scale top
876+ if((obj.y2 - downRes.y1 + deltay) > 40) obj.y1 = downRes.y1 - deltay;
877+ } else if(clickstate == 8 || clickstate == 9) { // We are in straight connective line drawing mode
878+ drawlinedx = gridx;
879+ drawlinedy = gridy;
880+ }
881+}
882+
883+/*
884+ * Call-forward for mouse-over event
885+ */
886+function mouseover(x, y) {
887+ // Code of touch, and if available object id and id of side of object that was touched
888+ // Tolerances included as constant
889+ var obj_code = "None";
890+ var obj_id = "None";
891+ var obj_sidentifier =" None";
892+ var obj_sideperc = 0;
893+ var obj_centerdist = 0;
894+ var obj_type = "None";
895+ var obj_x1 = 0;
896+ var obj_y1 = 0;
897+ var obj_x2 = 0;
898+ var obj_y2 = 0;
899+ var Cont;
900+ var found = 0;
901+ var side;
902+ for(j = 0; j < Identifiers.length; j++) {
903+ var objid = Identifiers[j];
904+ var obj = Objects[objid];
905+ var Sel = Selected[objid];
906+ if(ContextObj == objid) {
907+ Cont = 1;
908+ } else {
909+ Cont = 0;
910+ }
911+ // Compute coordinates including offset
912+ if(obj.type == "Entity" || obj.type == "ERAttribute" || obj.type == "ERRel") {
913+ x1 = obj.x1 + offsx;
914+ y1 = obj.y1 + offsy;
915+ x2 = obj.x2 + offsx;
916+ y2 = obj.y2 + offsy;
917+ rx = (x2 - x1) * 0.5;
918+ ry = (y2 - y1) * 0.5;
919+ }
920+ found = 0;
921+ // For each kind of clickable object, check if we are inside object and if so assign variables
922+ // Any general properties for all object types are set when "found" is true
923+ if(obj.type == "Entity") {
924+ if(x > (x1 - sidetol) && y > (y1 - sidetol ) && x < (x2 + sidetol) && y < (y2 + sidetol)) {
925+ obj_code = "NonSel";
926+ if(Sel) {
927+ obj_code = "Sel";
928+ }
929+ if(Cont) {
930+ obj_code = "Cont";
931+ }
932+ side = computeside(x, y, x1, y1, x2, y2, sidetol);
933+ obj_sidentifier = side.side;
934+ obj_sideperc = side.perc;
935+ obj_centerdist = side.dist;
936+ found = 1;
937+ }
938+ } else if(obj.type=="ERAttribute") {
939+ if(x > (x1 - sidetol) && y > (y1 - sidetol) && x < (x2 + sidetol) && y < (y2 + sidetol)) {
940+ obj_code = "NonSel";
941+ if(Sel) {
942+ obj_code="Sel";
943+ }
944+ if(Cont) {
945+ if(obj.DrawtoID == "None") {
946+ obj_code = "ContDraw";
947+ } else {
948+ obj_code = "Cont";
949+ }
950+ }
951+ side = computeside(x, y, x1, y1, x2, y2, sidetol);
952+ obj_sidentifier = side.side;
953+ obj_sideperc = side.perc;
954+ obj_centerdist = side.dist;
955+ found = 1;
956+ }
957+ } else if(obj.type == "ERRel") {
958+ if(x > (x1 - sidetol) && y > (y1 - sidetol) && x < (x2 + sidetol) && y < (y2 + sidetol)) {
959+ xk = x - x1;
960+ // Colision detection against diamond
961+ var inside = 0;
962+ if(xk <= rx) {
963+ if(y > (y1 + ry - xk - sidetol) && y < (y1 + ry + xk + sidetol)) {
964+ inside = 1;
965+ }
966+ } else {
967+ if(y > (y1 - rx + xk - sidetol) && y < ( y2 + rx - xk + sidetol)) {
968+ inside = 1;
969+ }
970+ }
971+ if(inside) {
972+ if((x > (x1 - sidetol)) && (x < (x1 + sidetol)) && (y > (y1 + ry - sidetol)) && (y < (y1 + ry + sidetol))) {
973+ obj_sidentifier = 1;
974+ }
975+ if((x > (x1 + rx - sidetol)) && (x < (x1 + rx + sidetol)) && (y > (y2 - sidetol)) && (y < (y2 + sidetol))) {
976+ obj_sidentifier = 2;
977+ }
978+ if((x > (x2 - sidetol)) && (x < (x2 + sidetol)) && (y > (y1 + ry - sidetol)) && (y < (y1 + ry + sidetol))) {
979+ obj_sidentifier = 3;
980+ }
981+ if((x > (x1 + rx - sidetol)) && (x < (x1 + rx + sidetol)) && (y > (y1 - sidetol)) && (y < (y1 + sidetol))) {
982+ obj_sidentifier = 4;
983+ }
984+ obj_code = "NonSel";
985+ if(Sel) {
986+ obj_code = "Sel";
987+ }
988+ if(Cont) {
989+ if(obj.DrawtoID == "None"){
990+ obj_code = "ContDraw";
991+ } else if(obj.DrawtoIDDest == "None") {
992+ obj_code = "ContDraw";
993+ } else {
994+ obj_code = "Cont";
995+ }
996+ }
997+ obj_sideperc = 0.5;
998+ found = 1;
999+ }
1000+ }
1001+ }
1002+ if(found == 1) {
1003+ // Save coordinates at time of click
1004+ obj_x1 = x1;
1005+ obj_y1 = y1;
1006+ obj_x2 = x2;
1007+ obj_y2 = y2;
1008+ obj_id = objid;
1009+ obj_type = obj.type;
1010+ printstr=obj_id + " " + obj_sidentifier + " " + obj_sideperc;
1011+ }
1012+ }
1013+ return {
1014+ objid:obj_id,
1015+ code:obj_code,
1016+ side:obj_sidentifier,
1017+ sideperc:obj_sideperc,
1018+ centerdist:obj_centerdist,
1019+ typ:obj_type,
1020+ x1:obj_x1,
1021+ y1:obj_y1,
1022+ x2:obj_x2,
1023+ y2:obj_y2
1024+ }
1025+}
1026+
1027+/*
1028+ * Turns JSON data into jQuery objects
1029+ */
1030+function importdata() {
1031+ for(i = 0; i < 7; i++) {
1032+ if(i == 0) {
1033+ obj = jQuery.parseJSON('{"type":"ERAttribute","id":"ATT1","kind":"Multiple","name":"Addressfosoppooo","x1":220,"y1":100,"x2":300,"y2":140, "DrawtoID":"None", "DrawfromSide":"None","DrawtoSide":"None", "DrawtoPerc":"None", "DrawX1":"", "DrawY1":"", "DrawX2":"","DrawY2":""}');
1034+ }
1035+ if(i == 1) {
1036+ obj = jQuery.parseJSON('{"type":"Entity","id":"ENT2","kind":"Weak","name":"Carsmashoepppoloo","x1":100,"y1":160,"x2":220,"y2":220}');
1037+ }
1038+ if(i == 2) {
1039+ obj = jQuery.parseJSON('{"type":"ERAttribute","id":"ATT3","kind":"Key","name":"SSNFooomesPoo","x1":160,"y1":260,"x2":260,"y2":300, "DrawtoID":"None", "DrawfromSide":"None","DrawtoSide":"None", "DrawtoPerc":"None", "DrawX1":"", "DrawY1":"", "DrawX2":"","DrawY2":""}');
1040+ }
1041+ if(i == 3) {
1042+ obj = jQuery.parseJSON('{"type":"Entity","id":"ENT4","kind":"Strong","name":"Trailerfpdddpeoooooe","x1":320,"y1":260,"x2":420,"y2":320}');
1043+ }
1044+ if(i == 4) {
1045+ obj = jQuery.parseJSON('{"type":"Entity","id":"ENT5","kind":"Strong","name":"Grail","x1":120,"y1":440,"x2":220,"y2":480}');
1046+ }
1047+ if(i == 5) {
1048+ obj = jQuery.parseJSON('{"type":"ERRel","id":"REL6","kind":"Strong","name":"FGFool","x1":460,"y1":160,"x2":520,"y2":220, "DrawtoID":"None", "DrawfromSide":"None","DrawtoSide":"None", "DrawtoPerc":"0", "DrawtoCard":"N", "DrawtoRole":"Fumo", "DrawtoXoffs":"20", "DrawtoYoffs":"50", "DrawtoIDDest":"None", "DrawfromSideDest":"None","DrawtoSideDest":"None", "DrawtoPercDest":"0", "DrawtoDestCard":"N", "DrawtoDestRole":"Luma", "DrawtoDestXoffs":"0", "DrawtoDestYoffs":"-50", "DrawX1":"", "DrawY1":"", "DrawX2":"","DrawY2":"","DrawX3":"", "DrawY3":"", "DrawX4":"","DrawY4":""}');
1049+ }
1050+ if(i == 6) {
1051+ obj = jQuery.parseJSON('{"type":"ERRel","id":"REL7","kind":"Weak","name":"PODrool","x1":360,"y1":360,"x2":420,"y2":420, "DrawtoID":"None", "DrawfromSide":"None","DrawtoSide":"None", "DrawtoPerc":"0", "DrawtoCard":"N", "DrawtoRole":"Kumo", "DrawtoXoffs":"60", "DrawtoYoffs":"70", "DrawtoIDDest":"None", "DrawfromSideDest":"None","DrawtoSideDest":"None", "DrawtoPercDest":"0", "DrawtoDestCard":"N", "DrawtoDestRole":"Zuuma", "DrawtoDestXoffs":"40", "DrawtoDestYoffs":"50", "DrawX1":"", "DrawY1":"", "DrawX2":"","DrawY2":"","DrawX3":"", "DrawY3":"", "DrawX4":"","DrawY4":""}');
1052+ }
1053+ objid = obj.id;
1054+ Objects[objid] = obj;
1055+ Identifiers.push(objid);
1056+ }
1057+}
1058+
1059+/*
1060+ * prepareobj
1061+ * Prepares all kinds of objects, with local movement-offset (scrolling offset is handled with transforms??)
1062+ * Ofss in prepare are not finished.
1063+ */
1064+function prepareobj(obji) {
1065+ var fromobj = Objects[obji];
1066+ // Attributes are prepared by re-pointing the DrawX1, DrawY1, DrawX2 and DrawY2 variables and Relationships are prepared by re-pointing DrawX1-DrawX4 and DrawY1-DrawY4
1067+ if((fromobj.type == "ERAttribute" || fromobj.type == "ERRel") && fromobj.DrawtoID != "None") {
1068+ var toid = fromobj.DrawtoID;
1069+ var toobj = Objects[toid];
1070+ var sidek;
1071+ if(fromobj.DrawtoIDDest != "None" && fromobj.DrawtoIDDest != undefined) {
1072+ var toiddest = fromobj.DrawtoIDDest;
1073+ var toobjdest = Objects[toiddest];
1074+ sidek = makeside(fromobj.DrawfromSideDest, fromobj.x1, fromobj.y1, fromobj.x2, fromobj.y2, 0.5);
1075+ fromobj.DrawX3 = sidek.x;
1076+ fromobj.DrawY3 = sidek.y;
1077+ sidek = makeside(fromobj.DrawtoSideDest, toobjdest.x1, toobjdest.y1, toobjdest.x2, toobjdest.y2, fromobj.DrawtoPercDest);
1078+ fromobj.DrawX4 = sidek.x;
1079+ fromobj.DrawY4 = sidek.y;
1080+ }
1081+ //printstr=fromobj.DrawfromSide+" "+fromobj.x1+" "+fromobj.y1+" "+fromobj.x2+" "+fromobj.y2+" :: "+fromobj.DrawtoSide+" "+toobj.x1+" "+toobj.y1+" "+toobj.x2+" "+toobj.y2+" "+fromobj.DrawtoPerc;
1082+ sidek = makeside(fromobj.DrawfromSide, fromobj.x1, fromobj.y1, fromobj.x2, fromobj.y2, 0.5);
1083+ fromobj.DrawX1 = sidek.x;
1084+ fromobj.DrawY1 = sidek.y;
1085+ sidek = makeside(fromobj.DrawtoSide, toobj.x1, toobj.y1, toobj.x2, toobj.y2, fromobj.DrawtoPerc);
1086+ fromobj.DrawX2 = sidek.x;
1087+ fromobj.DrawY2 = sidek.y;
1088+ }
1089+}
1090+
1091+/*
1092+ * Drawobj
1093+ * Draws all kinds of objects, with local movement-offset (scrolling offset is handled with transforms??)
1094+ */
1095+function drawobj(obji) {
1096+ var obj = Objects[obji];
1097+ var Sel = Selected[obji];
1098+ if(ContextObj == obji) {
1099+ Cont = 1;
1100+ } else {
1101+ Cont = 0;
1102+ }
1103+ context.strokeStyle = '#000';
1104+ context.lineWidth = 2.0;
1105+ // Compute coordinates including offset
1106+ if(obj.type == "Entity" || obj.type == "ERAttribute" || obj.type == "ERRel") {
1107+ x1 = obj.x1 + offsx;
1108+ y1 = obj.y1 + offsy;
1109+ x2 = obj.x2 + offsx;
1110+ y2 = obj.y2 + offsy;
1111+ rx = (x2 - x1) * 0.5;
1112+ ry = (y2 - y1) * 0.5;
1113+ }
1114+ if(obj.type == "Entity") {
1115+ //Draw Local Graphic
1116+ drawrect(x1, y1, x2, y2, "#000");
1117+ if(obj.kind == "Weak") {
1118+ drawrect(x1 + 5, y1 + 5, x2 - 5, y2 - 5, "#000");
1119+ cliptext(x1 + 5, y1 + 5, x2 - 5, y2 - 5, obj.name, "20px Calibri", "center", 8, 6, "#000", 1, 0);
1120+
1121+ } else {
1122+ cliptext(x1, y1, x2, y2, obj.name, "20px Calibri", "center", 8, 6, "#000", 1, 0);
1123+ }
1124+ // Draw Select Marker
1125+ if(Sel || Cont) {
1126+ fourpoints(x1, y1 + ry, x2, y1 + ry, x1 + rx, y1, x1 + rx, y2, "#5f8");
1127+ }
1128+ } else if(obj.type == "ERAttribute") {
1129+ drawellipse(x1, y1, x2, y2);
1130+ if(obj.kind == "Key") {
1131+ cliptext(x1, y1, x2, y2, obj.name, "20px Calibri", "center", 8, 6, "#000", 2, 1);
1132+ } else {
1133+ cliptext(x1, y1, x2, y2, obj.name, "20px Calibri", "center", 8, 6, "#000", 2, 0);
1134+ }
1135+ if(obj.DrawtoID != "None") {
1136+ drawline(obj.DrawX1, obj.DrawY1, obj.DrawX2, obj.DrawY2, "#000", 2.0);
1137+ }
1138+ // Draw Select Marker
1139+ if(Cont && obj.DrawtoID == "None") {
1140+ fourpoints(x1, y1 + ry, x2, y1 + ry, x1 + rx, y1, x1 + rx, y2, "#fa2");
1141+ } else if(Sel || (Cont && obj.DrawtoID != "None")) {
1142+ fourpoints(x1, y1 + ry, x2, y1 + ry, x1 + rx, y1, x1 + rx, y2, "#5f8");
1143+ }
1144+ } else if(obj.type == "ERRel") {
1145+ if(obj.DrawtoID != "None") {
1146+ drawline(obj.DrawX1, obj.DrawY1, obj.DrawX2, obj.DrawY2, "#000", 2.0);
1147+ drawcardinality(obj.DrawX2, obj.DrawY2, obj.DrawtoSide, obj.DrawtoCard, obj.DrawtoXoffsCard, obj.DrawtoYoffsCard, "20px Calibri", 20, 1, "#0a0");
1148+ drawcardinality(obj.DrawX2, obj.DrawY2, obj.DrawtoSide, obj.DrawtoRole, obj.DrawtoXoffsRole, obj.DrawtoYoffsRole, "20px Calibri", 20, 2, "#0a0");
1149+ //function drawcardinality(x,y,side,tex,xoffs,yoffs,font,baseline,sign,color)
1150+ //if(i==5) obj = jQuery.parseJSON('{"type":"ERRel","id":"REL6","kind":"Strong","name":"FGFool","x1":460,"y1":160,"x2":520,"y2":220, "DrawtoID":"None", "DrawfromSide":"None","DrawtoSide":"None", "DrawtoPerc":"0", "DrawtoCard":"N", "DrawtoRole":"Fumo", "DrawtoXoffsCard":"20", "DrawtoYoffsCard":"50","DrawtoXoffsRole":"20", "DrawtoYoffsRole":"-50", "DrawtoIDDest":"None", "DrawfromSideDest":"None","DrawtoSideDest":"None", "DrawtoPercDest":"0", "DrawtoDestCard":"1", "DrawtoDestRole":"Luma", "DrawtoDestXoffsCard":"0", "DrawtoDestYoffsCard":"-50","DrawtoDestXoffsRole":"0", "DrawtoDestYoffsRole":"-50", "DrawX1":"", "DrawY1":"", "DrawX2":"","DrawY2":"","DrawX3":"", "DrawY3":"", "DrawX4":"","DrawY4":""}');
1151+ //if(i==6) obj = jQuery.parseJSON('{"type":"ERRel","id":"REL7","kind":"Weak","name":"PODrool","x1":360,"y1":360,"x2":420,"y2":420, "DrawtoID":"None", "DrawfromSide":"None","DrawtoSide":"None", "DrawtoPerc":"0", "DrawtoCard":"1", "DrawtoRole":"Kumo", "DrawtoXoffsCard":"60", "DrawtoYoffsCard":"70", "DrawtoXoffsCard":"80", "DrawtoYoffsCard":"-70", "DrawtoIDDest":"None", "DrawfromSideDest":"None","DrawtoSideDest":"None", "DrawtoPercDest":"0", "DrawtoDestCard":"N", "DrawtoDestRole":"Zuuma", "DrawtoDestXoffsCard":"40", "DrawtoDestYoffsCard":"50", "DrawtoDestXoffsRole":"40", "DrawtoDestYoffsRole":"50", "DrawX1":"", "DrawY1":"", "DrawX2":"","DrawY2":"","DrawX3":"", "DrawY3":"", "DrawX4":"","DrawY4":""}');
1152+ }
1153+ if(obj.DrawtoIDDest != "None") {
1154+ drawline(obj.DrawX3, obj.DrawY3, obj.DrawX4, obj.DrawY4, "#000", 2.0);
1155+ }
1156+ if(obj.kind == "Weak") {
1157+ drawdiamond(x1 - 4, y1 - 4, x2 + 4, y2 + 4);
1158+ drawdiamond(x1 + 4, y1 + 4, x2 - 4, y2 - 4);
1159+ cliptext(x1 + 8, y1 + 8, x2 - 8, y2 - 8, obj.name, "20px Calibri", "center", 8, 6, "#000", 3, 0);
1160+ } else {
1161+ drawdiamond(x1, y1, x2, y2, 0);
1162+ cliptext(x1, y1, x2, y2, obj.name, "20px Calibri", "center", 8, 6, "#000", 3, 0);
1163+ }
1164+ // Draw Select Markers
1165+ if(Sel || (Cont && obj.DrawtoID != "None" && obj.DrawtoIDDest != "None")) {
1166+ fourpoints(x1, y1 + ry, x2, y1 + ry, x1 + rx, y1, x1 + rx, y2, "#5f8");
1167+ } else if(Cont) {
1168+ if(obj.DrawfromSide != 1 && obj.DrawfromSideDest != 1) {
1169+ point(x1, y1 + ry, "#fa2");
1170+ }
1171+ if(obj.DrawfromSide != 2 && obj.DrawfromSideDest != 2) {
1172+ point(x1 + rx, y2, "#fa2");
1173+ }
1174+ if(obj.DrawfromSide != 3 && obj.DrawfromSideDest != 3) {
1175+ point(x2, y1 + ry, "#fa2");
1176+ }
1177+ if(obj.DrawfromSide != 4 && obj.DrawfromSideDest != 4) {
1178+ point(x1 + rx, y1, "#fa2");
1179+ }
1180+ }
1181+ }
1182+}
1183+importdata();
1184+
1185+/*
1186+ *
1187+ */
1188+function foo() {
1189+ context.clearRect(0, 0, 600, 600);
1190 // overline(gridx,gridy,150,550,550,300,8.0);
1191- // Draw grid lines
1192- context.strokeStyle = '#ddd';
1193- context.lineWidth = 0.5;
1194- context.beginPath();
1195- for(i = 0; i < 600; i += 20) {
1196- context.moveTo(i, 0);
1197- context.lineTo(i, 600);
1198- context.moveTo(0, i);
1199- context.lineTo(600, i);
1200- }
1201- context.stroke();
1202- // Draw drawing line
1203- if(drawlinekind == 1) {
1204- drawline(drawlinesx, drawlinesy, drawlinedx, drawlinedy, "#000", 1.0);
1205- }
1206- // Prepare model objects
1207- for(i = 0; i < Identifiers.length; i++){
1208- var objid = Identifiers[i];
1209- prepareobj(objid);
1210- }
1211- // Draw model objects
1212- for(i = 0; i < Identifiers.length; i++){
1213- var objid = Identifiers[i];
1214- drawobj(objid);
1215- }
1216- // Draw Crosshair
1217- context.beginPath();
1218- context.strokeStyle = '#444';
1219- context.lineWidth = 1.0;
1220- context.moveTo(gridx - gridsize, gridy);
1221- context.lineTo(gridx + gridsize, gridy);
1222- context.moveTo(gridx, gridy - gridsize);
1223- context.lineTo(gridx, gridy + gridsize);
1224- context.stroke();
1225- context.strokeStyle = '#ddd';
1226- context.fillStyle = '#000';
1227- context.font = "bold 16px Arial";
1228- context.textAlign = "left";
1229- context.fillText("currop: " + printstr, 20, 576);
1230- setTimeout("foo();", 100);
1231- }
1232\ No newline at end of file
1233+ // Draw grid lines
1234+ context.strokeStyle = '#ddd';
1235+ context.lineWidth = 0.5;
1236+ context.beginPath();
1237+ for(i = 0; i < 600; i += 20) {
1238+ context.moveTo(i, 0);
1239+ context.lineTo(i, 600);
1240+ context.moveTo(0, i);
1241+ context.lineTo(600, i);
1242+ }
1243+ context.stroke();
1244+ // Draw drawing line
1245+ if(drawlinekind == 1) {
1246+ drawline(drawlinesx, drawlinesy, drawlinedx, drawlinedy, "#000", 1.0);
1247+ }
1248+ // Prepare model objects
1249+ for(i = 0; i < Identifiers.length; i++){
1250+ var objid = Identifiers[i];
1251+ prepareobj(objid);
1252+ }
1253+ // Draw model objects
1254+ for(i = 0; i < Identifiers.length; i++){
1255+ var objid = Identifiers[i];
1256+ drawobj(objid);
1257+ }
1258+ // Draw Crosshair
1259+ context.beginPath();
1260+ context.strokeStyle = '#444';
1261+ context.lineWidth = 1.0;
1262+ context.moveTo(gridx - gridsize, gridy);
1263+ context.lineTo(gridx + gridsize, gridy);
1264+ context.moveTo(gridx, gridy - gridsize);
1265+ context.lineTo(gridx, gridy + gridsize);
1266+ context.stroke();
1267+ context.strokeStyle = '#ddd';
1268+ context.fillStyle = '#000';
1269+ context.font = "bold 16px Arial";
1270+ context.textAlign = "left";
1271+ context.fillText("currop: " + printstr, 20, 576);
1272+ setTimeout("foo();", 100);
1273+}
1274\ No newline at end of file
1275
1276=== modified file 'ErModeller/canvas_ER_demo_duggajs.html'
1277--- ErModeller/canvas_ER_demo_duggajs.html 2013-04-03 09:20:17 +0000
1278+++ ErModeller/canvas_ER_demo_duggajs.html 2013-04-05 07:55:26 +0000
1279@@ -4,7 +4,7 @@
1280 <link rel="stylesheet" type="text/css" href="canvas.css">
1281 <script type="text/javascript" src="../js/jquery.js"></script>
1282 <script type="text/javascript" src="canvas.js"></script>
1283- <script type="text/javascript" src="dugga.js"></script>
1284+ <script type="text/javascript" src="../js/dugga.js"></script>
1285 </head>
1286 <body onload="setupcanvas();">
1287 <table>
1288
1289=== removed file 'ErModeller/dugga.js'
1290--- ErModeller/dugga.js 2013-03-28 16:01:26 +0000
1291+++ ErModeller/dugga.js 1970-01-01 00:00:00 +0000
1292@@ -1,608 +0,0 @@
1293-/********************************************************************************
1294- Mouse coordinate and canvas globals
1295- Handles both Touch and Mouse/Keyboard input at the same time
1296- *********************************************************************************/
1297-
1298-// Mouse coordinate globals
1299-var gridx, gridy;
1300-var clickstate = 0;
1301-var acanvas;
1302-var context;
1303-
1304-/********************************************************************************
1305- Canvas Setup and Click Handling Code
1306-
1307- Handles both Touch and Mouse/Keyboard input at the same time and executes
1308- handler callbacks.
1309- Also declares canvas globals
1310- *********************************************************************************/
1311-
1312-function setupcanvas() {
1313- acanvas = document.getElementById('a');
1314- context = acanvas.getContext("2d");
1315- setTimeout("foo();",50);
1316- setupClickHandling();
1317-}
1318-
1319-function setupClickHandling() {
1320- // Mouse and Keyboard Events
1321- acanvas.addEventListener('mousemove', ev_mousemove, false);
1322- acanvas.addEventListener('mouseup', ev_mouseup, false);
1323- acanvas.addEventListener('mousedown', ev_mousedown, false);
1324-
1325- // Touch Events
1326- acanvas.addEventListener('touchstart', ev_touchstart, false);
1327- acanvas.addEventListener('touchend', ev_touchend, false);
1328- acanvas.addEventListener('touchmove', ev_touchmove, false);
1329-}
1330-
1331-// Keyboard/Mouse Mouse Up Handler
1332-function ev_mouseup(ev) {
1333- handler_mouseup();
1334-}
1335-
1336-// Keyboard/Mouse Mouse Down Handler
1337-function ev_mousedown(ev) {
1338- handler_mousedown();
1339-}
1340-
1341-// Keyboard/Mouse Mouse Move Handler
1342-function ev_mousemove (ev) {
1343- var cx, cy = 0;
1344- if (ev.layerX || ev.layerX == 0) { // Firefox
1345- cx = ev.layerX - acanvas.offsetLeft;
1346- cy = ev.layerY - acanvas.offsetTop;
1347- } else if (ev.offsetX || ev.offsetX == 0) { // Opera
1348- cx = ev.offsetX - acanvas.offsetLeft;
1349- cy = ev.offsetY - acanvas.offsetTop;
1350- }
1351- coord = findPos(acanvas);
1352- cx = cx - coord.x;
1353- cy = cy - coord.y;
1354- handler_mousemove(cx, cy);
1355-}
1356-
1357-// Touch start event
1358-function ev_touchstart(event) {
1359- event.preventDefault();
1360- var numtouch = event.touches.length;
1361- targetEvent = event.touches.item(0);
1362- var cx = targetEvent.pageX;
1363- var cy = targetEvent.pageY;
1364- gridx = cx;
1365- gridy = cy;
1366- handler_mousedown();
1367-};
1368-
1369-// Touch end event
1370-function ev_touchend(event) {
1371- event.preventDefault();
1372- var numtouch = event.touches.length;
1373- handler_mouseup();
1374-};
1375-
1376-// Touch move event
1377-function ev_touchmove(event) {
1378- event.preventDefault();
1379- var numtouch = event.touches.length;
1380- targetEvent = event.touches.item(0);
1381- var cx = targetEvent.pageX;
1382- var cy = targetEvent.pageY;
1383- handler_mousemove(cx, cy);
1384-};
1385-
1386-// Fix scrolling on touch devices
1387-var ScrollFix = function(elem) {
1388- // Variables to track inputs
1389- var startY, startTopScroll;
1390- elem = elem || document.querySelector(elem);
1391-
1392- // If there is no element, then do nothing
1393- if(!elem) {
1394- return;
1395- }
1396-
1397- // Handle the start of interactions
1398- elem.addEventListener('touchstart', function(event) {
1399- startY = event.touches[0].pageY;
1400- startTopScroll = elem.scrollTop;
1401-
1402- if(startTopScroll <= 0) {
1403- elem.scrollTop = 1;
1404- }
1405-
1406- if(startTopScroll + elem.offsetHeight >= elem.scrollHeight) {
1407- elem.scrollTop = elem.scrollHeight - elem.offsetHeight - 1;
1408- }
1409- }, false);
1410-};
1411-
1412-/********************************************************************************
1413- Canvas Diagram Drawing Code
1414- *********************************************************************************/
1415-
1416-// Draws a stroked rectangle of certain thicknes and color
1417-function drawrect(x1, y1, x2, y2, color) {
1418- context.lineWidth = 1.5;
1419- context.strokeStyle = color;
1420- context.strokeRect(x1, y1, x2 - x1, y2 - y1);
1421-}
1422-
1423-// Draws a perfect round circle
1424-function drawcircle(radius, color) {
1425- context.lineWidth = 1.5;
1426- context.strokeStyle = color;
1427- context.arc(0, 0, radius, 0 , 2 * Math.PI, false);
1428-}
1429-
1430-// Draws 90 degree arc
1431-function drawellipse(x1, y1, x2, y2) {
1432- var rx = (x2 - x1) * 0.5;
1433- var ry = (y2 - y1) * 0.5;
1434- context.beginPath();
1435- context.moveTo(x1, y1 + ry);
1436- context.quadraticCurveTo(x1, y1, x1 + rx, y1);
1437- context.quadraticCurveTo(x2, y1, x2, y1 + ry);
1438- context.quadraticCurveTo(x2, y2, x2 - rx, y2);
1439- context.quadraticCurveTo(x1, y2, x1, y1 + ry);
1440- context.stroke();
1441-}
1442-
1443-// Draw a point
1444-function point(x, y, col) {
1445- context.strokeStyle = "#000";
1446- context.lineWidth = 1;
1447- context.fillStyle = col;
1448- context.fillRect(x - 4, y - 4, 8, 8);
1449- context.strokeRect(x - 4, y - 4, 8, 8);
1450-}
1451-
1452-// Draw a box around a point to indicate highlight
1453-function highlight(px, py) {
1454- context.strokeStyle = "#aaa";
1455- context.lineWidth = 1;
1456- context.strokeRect(px - 8, py - 8, 16, 16);
1457-}
1458-
1459-// Draw a line using current context
1460-function drawline(x1, y1, x2, y2, strokestyle, linewidth) {
1461- context.strokeStyle = strokestyle;
1462- context.lineWidth = linewidth;
1463- context.beginPath();
1464- context.moveTo(x1, y1);
1465- context.lineTo(x2, y2);
1466- context.stroke();
1467-}
1468-
1469-function fourpoints(x1, y1, x2, y2, x3, y3, x4, y4, col) {
1470- point(x1, y1, col);
1471- point(x2, y2, col);
1472- point(x3, y3, col);
1473- point(x4, y4, col);
1474-}
1475-
1476-function drawdiamond(x1, y1, x2, y2) {
1477- var rx = (x2 - x1) * 0.5;
1478- var ry = (y2 - y1) * 0.5;
1479- context.beginPath();
1480- context.moveTo(x1, y1 + ry);
1481- context.lineTo(x1 + rx, y2);
1482- context.lineTo(x2, y1 + ry);
1483- context.lineTo(x1 + rx, y1);
1484- context.lineTo(x1, y1 + ry);
1485- context.stroke();
1486-}
1487-
1488-// Dashed Line in Segments of given size
1489-function dashedline(sx, sy, ex, ey, dashlen, linewidth, col) {
1490- var dx = ex - sx;
1491- var dy = ey - sy;
1492- len = Math.sqrt((dx * dx) + (dy * dy));
1493- notimes = Math.round(len / dashlen);
1494- dx = dx / notimes;
1495- dy = dy / notimes;
1496- context.lineWidth = linewidth;
1497- context.strokeStyle = col;
1498- context.beginPath();
1499- var xk, yk;
1500- xk = sx;
1501- yk = sy;
1502- xh = dx / 2.0;
1503- yh = dy / 2.0;
1504- for(var i = 0; i < notimes; i++) {
1505- context.moveTo(xk, yk);
1506- context.lineTo(xk + xh, yk + yh);
1507- xk += dx;
1508- yk += dy;
1509- }
1510- context.stroke();
1511-}
1512-
1513-// Arcto only works if both x1 and y2 are on circle border
1514-function arcto(x0, y0, x1, y1, x2, y2) {
1515- var r = Math.sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
1516- var x = x0 - r;
1517- var y = y0 - r;
1518- var startAngle = (180 / Math.PI * Math.atan2(y1 - y0, x1 - x0));
1519- var endAngle = (180 / Math.PI * Math.atan2(y2 - y0, x2 - x0));
1520- context.arc(x0, y0, r, 0, Math.PI * 2.0, 1.0);
1521-}
1522-
1523-// Draws 90 degree arc
1524-function arcdeg(x1, y1, x2, y2, x3, y3) {
1525- // First quadrant positive positive
1526- dashedline(x1, y1, x2, y2, 8, 1.0, "#999");
1527- dashedline(x3, y3, x2, y2, 8, 1.0, "#999");
1528- point(x1, y1, "#ff5");
1529- point(x2, y2, "#f55");
1530- point(x3, y3, "#f55");
1531-
1532- k = (y3 - y1) / (x3 - x1);
1533- yk = y1 + ((x2 - x1) * k);
1534- rx = x3 - x1;
1535- ry = y3 - y1;
1536- point(x2, yk, "#f5f");
1537-
1538- context.strokeStyle = '#49f';
1539- context.lineWidth = 1.0;
1540- context.beginPath();
1541- context.moveTo(x1, y1);
1542- for(i = 0; i < 48; i++) {
1543- if(y3 >= y1) {
1544- if(yk >= y2) {
1545- context.lineTo(x1 + (Math.sin(((Math.PI / 96.0) * -i) + (Math.PI * 1.0)) * rx), y3 + (Math.cos(((Math.PI / 96.0) * -i) + (Math.PI * 1.0)) * ry));
1546- } else {
1547- context.lineTo(x3 + (Math.sin(((Math.PI / 96.0) * i) + (Math.PI * 1.5)) * rx), y1 + (Math.cos(((Math.PI / 96.0) * i) + (Math.PI * 1.5)) * ry));
1548- }
1549- } else {
1550- if(yk <= y2) {
1551- context.lineTo(x1 + (Math.sin(((Math.PI / 96.0) * -i) + (Math.PI * 1.0)) * rx), y3 + (Math.cos(((Math.PI / 96.0) * -i) + (Math.PI * 1.0)) * ry));
1552- } else {
1553- context.lineTo(x3 + (Math.sin(((Math.PI / 96.0) * i) + (Math.PI * 1.5)) * rx), y1 + (Math.cos(((Math.PI / 96.0) * i) + (Math.PI * 1.5)) * ry));
1554- }
1555- }
1556- }
1557- context.stroke();
1558-}
1559-
1560-// function that draws one part of the sun
1561-function sundial(radius, angle, scale) {
1562- cosv = Math.cos(angle);
1563- sinv = Math.sin(angle);
1564- yaddx = scale * cosv;
1565- yaddy = scale * sinv;
1566- xaddx = -scale * sinv;
1567- xaddy = scale * cosv;
1568- xk = cosv * radius;
1569- yk = sinv * radius;
1570-
1571- context.bezierCurveTo((-1.5 * xaddx) + (yaddx * 1.5) + xk, (-1.5 * xaddy) + (yaddy * 1.5) + yk, xaddx + (yaddx * 2.0) + xk, xaddy + (yaddy * 2.0) + yk, xaddx + (yaddx * 3.0) + xk, xaddy + (yaddy * 3.0) + yk);
1572- context.bezierCurveTo(xaddx + yaddx + xk, xaddy + yaddy + yk, (1.5 * xaddx) + yaddx + xk, (1.5 * xaddy) + yaddy + yk, (3.0 * xaddx) + xk, (3.0 * xaddy) + yk);
1573-}
1574-
1575-// function that daws the sun
1576-function drawsun() {
1577- context.fillStyle = "#fe9";
1578- context.strokeStyle = "#d82";
1579- context.lineWidth = 1.5;
1580- context.beginPath();
1581- context.moveTo(30, 0);
1582- for(i = 0.0; i < 360.0; i += 22.5) {
1583- angle = (i / 360.0) * 2 * Math.PI;
1584- sundial(30, angle, 3);
1585- }
1586- context.stroke();
1587- context.fill();
1588-}
1589-
1590-// Draws the ball (used in various examples)
1591-function drawball(cx, cy, radie, innerradie, ballradie, col1, inangle, inangleadd) {
1592-
1593- angleadd = (inangleadd / 360.0) * 2 * Math.PI;
1594- context.fillStyle = col1;
1595- for(i = 0; i < 360; i += inangle) {
1596- angle = (i / 360.0) * 2 * Math.PI;
1597- angle2 = angle + angleadd;
1598- angle3 = angle + (angleadd * 2.0);
1599- angle4 = angle - angleadd;
1600-
1601- cosv = Math.cos(angle);
1602- sinv = Math.sin(angle);
1603-
1604- cosv2 = Math.cos(angle2);
1605- sinv2 = Math.sin(angle2);
1606-
1607- cosv4 = Math.cos(angle4);
1608- sinv4 = Math.sin(angle4);
1609-
1610- context.beginPath();
1611-
1612- context.moveTo(cx, cy);
1613- context.quadraticCurveTo(cx + (cosv * innerradie), cy + (sinv * innerradie), cx + (cosv2 * radie), cy + (sinv2 * radie));
1614- context.arc(cx, cy, radie, angle2, angle, 1.0);
1615- context.quadraticCurveTo(cx + (cosv4 * innerradie), cy + (sinv4 * innerradie), cx, cy);
1616- context.fill();
1617- }
1618-
1619- context.beginPath();
1620- context.arc(cx, cy, radie, 0, Math.PI * 2.0, 1.0);
1621- context.stroke();
1622-}
1623-
1624-// Draws underlined/dashed underlined text clipped inside a rectangle, a quadratic curve ellipsis or a diamond
1625-function cliptext(x1, y1, x2, y2, tex, font, align, edgeoffs, baseline, color, clipkind, underlinekind) {
1626- var rx = (x2 - x1) * 0.5;
1627- var ry = (y2 - y1) * 0.5;
1628- var tx = x1;
1629-
1630- if(clipkind != 0) {
1631- context.save();
1632- context.beginPath();
1633- }
1634-
1635- // Make Rectangle / Ellipse / Diamond Clipping Paths
1636- if(clipkind == 1) {
1637- context.moveTo(x1, y1);
1638- context.lineTo(x1, y2);
1639- context.lineTo(x2 - edgeoffs, y2);
1640- context.lineTo(x2 - edgeoffs, y1);
1641- context.lineTo(x1, y1);
1642- } else if(clipkind == 2) {
1643- context.moveTo(x1, y1 + ry);
1644- context.quadraticCurveTo(x1 + edgeoffs, y1 + edgeoffs, x1 + edgeoffs + rx, y1 + edgeoffs);
1645- context.quadraticCurveTo(x2 - edgeoffs, y1 + edgeoffs, x2 - edgeoffs , y1 + ry + edgeoffs);
1646- context.quadraticCurveTo(x2 - edgeoffs, y2 - edgeoffs, x2 - rx - edgeoffs, y2 - edgeoffs);
1647- context.quadraticCurveTo(x1 + edgeoffs, y2 - edgeoffs, x1 + edgeoffs, y1 + ry + edgeoffs);
1648- } else if(clipkind == 3) {
1649- context.moveTo(x1, y1 + ry);
1650- context.lineTo(x1 + rx, y2);
1651- context.lineTo(x2, y1 + ry);
1652- context.lineTo(x1 + rx, y1);
1653- context.lineTo(x1, y1 + ry);
1654- }
1655-
1656- if(clipkind != 0) {
1657- context.clip();
1658- }
1659-
1660- context.font = font;
1661- context.textAlign = "left";
1662- context.fillStyle = color;
1663-
1664- var metrics = context.measureText(tex);
1665- var hwidth = metrics.width * 0.5;
1666-
1667- // Compute left-justified centered coordinate
1668- if((rx - hwidth - edgeoffs) < 0) {
1669- tx = x1 + edgeoffs;
1670- } else {
1671- tx = x1 + rx - hwidth;
1672- }
1673-
1674- context.fillText(tex, tx, y2 - ry + baseline);
1675-
1676- // Draw underlining - can handle dashed underline!
1677- if(underlinekind == 1) {
1678- drawline(tx, y2 - ry + baseline + 5.0, tx + (hwidth*2), y2 - ry + baseline + 5.0, "#000", 2.0);
1679- }
1680-
1681- if(clipkind != 0) context.restore();
1682-
1683-}
1684-
1685-// Draws cardinality at a certain offset from a coordinate
1686-function drawcardinality(x, y, side, tex, xoffs, yoffs, font, baseline, sign, color)
1687-{
1688- // Xoffs is along line
1689- xoffs = 0;
1690- // Yoffs is distance from line
1691- yoffs = 10;
1692-
1693- var metrics = context.measureText(tex);
1694- var twidth = metrics.width;
1695- var theight = 12;
1696-
1697- point(x, y, "#f8f");
1698-
1699- context.font = font;
1700- context.textAlign = "left";
1701- context.fillStyle = color;
1702-
1703- if(side == 1 && sign == 1){
1704- context.fillText(tex, x - twidth - xoffs, y - yoffs);
1705- drawrect(x - twidth - xoffs, y - yoffs,x - xoffs, y - yoffs - theight);
1706- }else if(side == 2 && sign == 1){
1707- context.fillText(tex, x + yoffs, y + xoffs + theight);
1708- drawrect(x + yoffs, y + xoffs + theight,x + yoffs + twidth, y + xoffs);
1709- }else if(side == 3 && sign == 1){
1710- context.fillText(tex, x + xoffs, y - yoffs);
1711- }else if(side == 4 && sign == 1){
1712- context.fillText(tex, x + yoffs, y - xoffs);
1713- }else if(side == 1 && sign == 2){
1714- context.fillText(tex, x - twidth - xoffs, y + theight + yoffs);
1715- drawrect(x - twidth - xoffs, y + yoffs,x - xoffs, y + theight + yoffs);
1716- }else if(side == 2 && sign == 2){
1717- context.fillText(tex, x - yoffs - twidth, y + xoffs + theight);
1718- drawrect(x - yoffs - twidth, y + xoffs,x - yoffs, y + xoffs + theight);
1719- }else if(side == 3 && sign == 2){
1720- context.fillText(tex, x + xoffs, y + theight + yoffs);
1721- }else if(side == 4 && sign == 2){
1722- context.fillText(tex, x - yoffs - twidth, y - xoffs);
1723- }
1724-}
1725-
1726-/********************************************************************************
1727- Canvas and Diagram Measuring Functions
1728-
1729- These functions allow us to measure pixels in diagram and other apps
1730- *********************************************************************************/
1731-
1732-// Recursive Pos of div in document - should work in most browsers
1733-function findPos(obj) {
1734- var curleft = curtop = 0;
1735- if(obj.offsetParent) {
1736- curleft = obj.offsetLeft;
1737- curtop = obj.offsetTop;
1738- while (obj = obj.offsetParent) {
1739- curleft += obj.offsetLeft;
1740- curtop += obj.offsetTop;
1741- }
1742- }
1743- return {
1744- x:curleft,
1745- y:curtop
1746- };
1747-}
1748-
1749-// Make side coordinates for drawing Model
1750-function makeside(side, x1, y1, x2, y2, perc) {
1751- var xk = 0;
1752- var yk = 0;
1753-
1754- if(side == 1) {
1755- xk = x1;
1756- yk = y1 + ((y2 - y1) * perc);
1757- } else if(side == 2) {
1758- xk = x1 + ((x2 - x1) * perc);
1759- yk = y2;
1760- } else if(side == 3){
1761- xk = x2;
1762- yk = y1 + ((y2 - y1) * perc);
1763- } else if(side == 4){
1764- xk = x1 + ((x2 - x1) * perc)
1765- yk = y1;
1766- }
1767-
1768- return {
1769- x:xk,
1770- y:yk
1771- };
1772-}
1773-
1774-// Computes side identifier for a mouse coordinate and object coordinates
1775-function computeside(x, y, x1, y1, x2, y2, sidetol) {
1776- var obj_sidentifier = "None";
1777- var obj_sideperc = 0;
1778- var obj_centerdist = 0;
1779-
1780- // Left Side
1781- if(x > x1 - sidetol && x < x1 + sidetol && y > y1 - sidetol && y < y2 + sidetol) {
1782- obj_sidentifier = 1;
1783- obj_sideperc = makesideperc(y, y1, y2);
1784- obj_centerdist = centerdist(y, y1, y2);
1785- }
1786-
1787- // Bottom Not Including Left Side or Right Side
1788- if(x > x1 + sidetol && x < x2 - sidetol && y > y2 - sidetol && y < y2 + sidetol) {
1789- obj_sidentifier = 2;
1790- obj_sideperc = makesideperc(x, x1, x2);
1791- obj_centerdist = centerdist(x, x1, x2);
1792- }
1793-
1794- // Right Side
1795- if(x > x2 - sidetol && x < x2 + sidetol && y > y1 - sidetol && y < y2 + sidetol) {
1796- obj_sidentifier = 3;
1797- obj_sideperc = makesideperc(y, y1, y2);
1798- obj_centerdist=centerdist(y, y1, y2);
1799- }
1800-
1801- // Top Not Including Left Side or Right Side
1802- if(x > x1 + sidetol && x < x2 - sidetol && y > y1 - sidetol && y < y1 + sidetol) {
1803- obj_sidentifier = 4;
1804- obj_sideperc = makesideperc(x, x1, x2);
1805- obj_centerdist=centerdist(x, x1, x2);
1806- }
1807-
1808- return {
1809- side:obj_sidentifier,
1810- perc:obj_sideperc,
1811- dist:obj_centerdist
1812- };
1813-}
1814-
1815-// Make side perc for ER model
1816-function makesideperc(x, x1, x2) {
1817- r = x2 - x1;
1818- perc = (x - x1) / r;
1819-
1820- if(perc > 1.0) perc = 1.0;
1821- if(perc < 0.0) perc = 0.0;
1822-
1823- return perc;
1824-}
1825-
1826-function centerdist(x, x1, x2){
1827- r = x1 + ((x2 - x1) * 0.5);
1828-
1829- return (x - r);
1830-}
1831-
1832-// Euclidian distance - Yo!
1833-function distance(x1, y1, x2, y2) {
1834- var dist = Math.sqrt(((y2 - y1) * (y2 - y1)) + ((x2 - x1) * (x2 - x1)));
1835-
1836- return dist;
1837-}
1838-
1839-// Are we over a line or not.
1840-function overline(x, y, x1, y1, x2, y2, tolerance) {
1841- var distance = 10000;
1842- dx = x2 - x1;
1843- dy = y2- y1;
1844-
1845- straighttolerance = 2.0;
1846-
1847- var box1, boy1, box2, boy2;
1848-
1849- if(x1 > x2) {
1850- box1 = x2;
1851- box2 = x1;
1852- } else {
1853- box1 = x1;
1854- box2 = x2;
1855- }
1856-
1857- if(y1 > y2) {
1858- boy1 = y2;
1859- boy2 = y1;
1860- } else {
1861- boy1 = y1;
1862- boy2 = y2;
1863- }
1864-
1865- //drawrect(box1-tolerance,boy1-tolerance,box2+tolerance,boy2+tolerance,"#aaa");
1866- if((x > (box1 - tolerance)) && (x < (box2 + tolerance)) && (y > (boy1 - tolerance)) && (y < (boy2 + tolerance))) {
1867- // Straight X, Straight Y or Positive or Negative Incline
1868- if(Math.abs(dx) < straighttolerance) {
1869- if(y1 < y2) {
1870- if(y > y1 - tolerance && y < y2 + tolerance) {
1871- distance = Math.abs(x1 - x);
1872- }
1873- } else {
1874- if(y > y2 - tolerance && y < y1 + tolerance) {
1875- distance = Math.abs(x1 - x);
1876- }
1877- }
1878- } else if(Math.abs(dy) < straighttolerance) {
1879- if(x1 < x2){
1880- if(x > x1 - tolerance && x < x2 + tolerance) {
1881- distance = Math.abs(y1 - y);
1882- }
1883- } else {
1884- if(x > x2 - tolerance && x < x1 + tolerance) {
1885- distance = Math.abs(y1 - y);
1886- }
1887- }
1888- } else if(Math.abs(dx) >= Math.abs(dy)) {
1889- k = dy / dx;
1890- yk = y1 + ((x - x1) * k);
1891- distance = Math.abs(yk - y);
1892- } else {
1893- k = dx / dy;
1894- xk = x1 + ((y - y1) * k);
1895- distance = Math.abs(xk - x);
1896- }
1897- }
1898-
1899- return distance;
1900-}

Subscribers

People subscribed via source and target branches

to all changes: