Revision | 8afedfb913f32e536b0cc14526f7f8f518d25e70 (tree) |
---|---|
Time | 2020-01-26 05:37:06 |
Author | Capsia Tech <cmsuser3754@zoho...> |
Commiter | Capsia Tech |
Code Decluttering
@@ -7,9 +7,8 @@ | ||
7 | 7 | svg_block.style.width = width + "px"; |
8 | 8 | svg_block.style.height = height + "px"; |
9 | 9 | } |
10 | - var posArr = [[0.08, 0.5],[0.16, 0.5], [0.24, 0.5], [0.32, 0.5], [0.40, 0.5], [0.48, 0.5], [0.56, 0.5]]; | |
11 | 10 | sizing(); |
12 | - res = initSVG(posArr); | |
11 | + res = initSVG(); | |
13 | 12 | function runRes() { |
14 | 13 | res(window.innerWidth, window.innerHeight); |
15 | 14 | sizing(); |
@@ -0,0 +1,18 @@ | ||
1 | +window.onload = setSizes; | |
2 | +function setSizes() { | |
3 | + function sizing() { | |
4 | + var height = window.innerHeight, | |
5 | + width = window.innerWidth, | |
6 | + svg_block = document.getElementById("svg"); | |
7 | + svg_block.style.width = width + "px"; | |
8 | + svg_block.style.height = height + "px"; | |
9 | + } | |
10 | + var posArr = [[0.08, 0.5],[0.16, 0.5], [0.24, 0.5], [0.32, 0.5], [0.40, 0.5], [0.48, 0.5], [0.56, 0.5]]; | |
11 | + sizing(); | |
12 | + res = initSVG(posArr); | |
13 | + function runRes() { | |
14 | + res(window.innerWidth, window.innerHeight); | |
15 | + sizing(); | |
16 | + } | |
17 | + $(window).resize(runRes); | |
18 | +} |
@@ -6,46 +6,41 @@ | ||
6 | 6 | Riccardo Riccio |
7 | 7 | Simon Tomsič*/ |
8 | 8 | |
9 | -function initSVG(posArr) { // Snap.SVG.JS needs to be started on load | |
9 | +function initSVG() { // Snap.SVG.JS needs to be started on load | |
10 | 10 | // Starting Snap SVG, basic objects and variables. To change discs positions use posArr. |
11 | 11 | // Global setup |
12 | 12 | document.getElementById("overlay").style.visibility = "hidden"; |
13 | + window.nowFull = -1; | |
13 | 14 | var height = window.innerHeight, |
14 | 15 | width = window.innerWidth, |
16 | + fontSize = parseFloat(getComputedStyle(document.body).fontSize)*0.6, | |
17 | + dates = [2012, 2015, 2016, 2018, 2019], | |
18 | + posArr = [], | |
19 | + | |
15 | 20 | s = Snap("#svg"), // set element to draw in |
16 | 21 | // Start drawing |
22 | + dateLine = s.line(0, height/2, width, height/2), | |
17 | 23 | discs = s.group(), // group of all circles |
18 | - nums = s.group(), | |
19 | - rect = s.rect(0,0,width,height); | |
20 | - if (width/height > 1.05) { | |
21 | - var bigCircle = s.circle(0, height/2, height/2); | |
22 | - } else { | |
23 | - var bigCircle = s.circle(0, width/3, width/3); | |
24 | + nums = s.group(); | |
25 | + | |
26 | + for (i = 1; i <= dates.length; i++ ) { | |
27 | + posArr.push([0.08*i, 0.5]); | |
24 | 28 | } |
29 | + | |
25 | 30 | function SVGsizes(width, height) { |
26 | - if (width/height > 1.05) { | |
27 | - bigCircle.attr({ | |
28 | - r: height/2, | |
29 | - cy: height/2 | |
30 | - }); | |
31 | - } else { | |
32 | - bigCircle.attr({ | |
33 | - r: width/3, | |
34 | - cy: width/3 | |
35 | - }); | |
36 | - } | |
37 | - rect.attr({ | |
38 | - width: width, | |
39 | - height: height | |
31 | + dateLine.attr({ | |
32 | + x2: width, | |
33 | + y1: height / 2, | |
34 | + y2: height / 2 | |
40 | 35 | }); |
41 | 36 | for (i = 0; i < posArr.length; i++) { |
42 | - discs.select("circle:nth-child(" + (i+1) + ")").attr({ | |
37 | + discs[i].attr({ | |
43 | 38 | cx: width*posArr[i][0], |
44 | 39 | cy: height*posArr[i][1] |
45 | 40 | }); |
46 | - nums.select("text:nth-child(" + (i+1) + ")").attr({ | |
47 | - x: (width*posArr[i][0])-7, | |
48 | - y: (height*posArr[i][1])+5 | |
41 | + nums[i].attr({ | |
42 | + x: (width*posArr[i][0])-32, | |
43 | + y: (height*posArr[i][1])+50 | |
49 | 44 | }); |
50 | 45 | } |
51 | 46 | } |
@@ -58,62 +53,45 @@ | ||
58 | 53 | } |
59 | 54 | //console.log(initSVG.SVGsizes); |
60 | 55 | // Setting default styles for rectangle and discs |
61 | - rect.attr({ | |
62 | - fill: " #383c4a", | |
63 | - visibility: "hidden", | |
64 | - opacity: 0 | |
65 | - }); | |
66 | - bigCircle.attr({ | |
67 | - fill: "#4e9a06", | |
68 | - stroke: "#ca64ff", | |
69 | - strokeWidth: 20, | |
70 | - visibility: "hidden" | |
71 | - }); | |
72 | 56 | discs.attr({ |
73 | 57 | fill: "#4e9a06", |
74 | 58 | stroke: "#ca64ff", |
75 | 59 | strokeWidth: 5 |
76 | 60 | }); |
61 | + dateLine.attr({ | |
62 | + stroke: "#333", | |
63 | + strokeWidth: 30 | |
64 | + }); | |
77 | 65 | nums.attr({ |
78 | - pointerEvents: "none" | |
66 | + fontSize: "1.8em", | |
67 | + fontWeight: "bold" | |
68 | +// pointerEvents: "none" | |
79 | 69 | }); |
80 | 70 | // Initialize circles |
81 | 71 | for (i = 0; i < posArr.length; i++) { |
82 | 72 | discs.add(s.circle(width*posArr[i][0], height*posArr[i][1], 20)); // Create and add circles to discs. |
83 | - nums.add(s.text((width*posArr[i][0])-7, (height*posArr[i][1])+5, addZyro(i))); | |
84 | - discs.select("circle:nth-child(" + (i+1) + ")").click( function() { | |
85 | -// console.log(this); //Enable this for debug | |
86 | - var save = [this.node.attributes.r.nodeValue, this.node.attributes.cx.nodeValue, this.node.attributes.cy.nodeValue], | |
87 | - reback = this; // Save elements for later | |
88 | -// displayInfo(posArr, save); | |
89 | - nums.attr({visibility: "hidden"}); | |
90 | - this.animate({r: window.innerWidth, cy: (window.innerHeight / 2) , cx: (window.innerWidth / 2), strokeWidth: 50}, 1000); //Move circle | |
91 | - setTimeout(function(){ // Wait 1s function | |
73 | + nums.add(s.text((width*posArr[i][0])-32, (height*posArr[i][1])+50, dates[i])); | |
74 | + discs[i].click( function() { | |
75 | + if (window.nowFull == -1) { | |
76 | + for ( i = 0; i < posArr.length; i++ ) { | |
77 | + if (discs[i].id == this.id) { | |
78 | + window.nowFull = i; | |
79 | + } | |
80 | + } | |
81 | + nums.attr({visibility: "hidden"}); | |
92 | 82 | discs.attr({visibility: "hidden"}); // Hide discs to prevent ovelay viewing |
93 | - bigCircle.attr({visibility: ""}); // Show big circle | |
94 | - rect.attr({visibility: ""}); //Show rectangle | |
95 | - rect.animate({opacity: 0.8}, 500); // Animate opacity | |
96 | - reback.animate({r: 20, cy: save[2], cx: save[1], strokeWidth: 5}, 1000); //Return circle to original position | |
97 | - document.getElementById("overlay").style.visibility = ""; | |
98 | - }, 1000); | |
83 | + this.attr({visibility: "visible"}); // Hide discs to prevent ovelay viewing | |
84 | + this.animate({r: window.innerWidth, cy: (window.innerHeight / 2) , cx: (window.innerWidth / 2), strokeWidth: 50}, 1000); //Move circle | |
85 | + document.getElementById("overlay").style.visibility = ""; | |
86 | + } else { | |
87 | + discs[window.nowFull].animate({r: 20, cy: height*posArr[window.nowFull][1], cx: width*posArr[window.nowFull][0], strokeWidth: 5}, 1000); //Return circle to original position | |
88 | + discs[window.nowFull].attr({visibility: ""}); | |
89 | + nums.attr({visibility: ""}); | |
90 | + discs.attr({visibility: ""}); // Unhide circles | |
91 | + document.getElementById("overlay").style.visibility = "hidden"; | |
92 | + window.nowFull = -1; | |
93 | + } | |
99 | 94 | }); |
100 | 95 | } |
101 | -// Return function on bigCircle (click to return) | |
102 | - bigCircle.click(bConClick); | |
103 | - rect.click(bConClick); | |
104 | - function bConClick() { | |
105 | - nums.attr({visibility: ""}); | |
106 | - discs.attr({visibility: ""}); // Unhide circles | |
107 | - bigCircle.attr({visibility: "hidden"}); // Hide big side circle | |
108 | - rect.attr({visibility: "hidden", opacity: "0"}); // Hide rectangle and set animation | |
109 | - document.getElementById("overlay").style.visibility = "hidden"; | |
110 | - } | |
111 | - function addZyro(num) { | |
112 | - if (num < 9) { | |
113 | - return "0" + (num+1); | |
114 | - } else { | |
115 | - return (num+1); | |
116 | - } | |
117 | - } | |
118 | 96 | return SVGsizes; |
119 | 97 | } |
@@ -0,0 +1,100 @@ | ||
1 | +// Welcome to SVG Virtual Map Animator by Capsia Tech | |
2 | + | |
3 | +/* Written by: | |
4 | +Desirée Schembri | |
5 | +Niccolò Celoro | |
6 | +Riccardo Riccio | |
7 | +Simon Tomsič*/ | |
8 | + | |
9 | +function initSVG() { // Snap.SVG.JS needs to be started on load | |
10 | +// Starting Snap SVG, basic objects and variables. To change discs positions use posArr. | |
11 | +// Global setup | |
12 | + document.getElementById("overlay").style.visibility = "hidden"; | |
13 | + window.nowFull = -1; | |
14 | + var height = window.innerHeight, | |
15 | + width = window.innerWidth, | |
16 | + fontSize = parseFloat(getComputedStyle(document.body).fontSize)*0.6, | |
17 | + dates = [2012, 2015, 2016, 2018, 2019], | |
18 | + posArr = [], | |
19 | + | |
20 | + s = Snap("#svg"), // set element to draw in | |
21 | +// Start drawing | |
22 | + dateLine = s.line(0, height/2, width, height/2), | |
23 | + discs = s.group(), // group of all circles | |
24 | + nums = s.group(); | |
25 | + | |
26 | + for (i = 1; i <= dates.length; i++ ) { | |
27 | + posArr.push([0.08*i, 0.5]); | |
28 | + } | |
29 | + | |
30 | + function SVGsizes(width, height) { | |
31 | + dateLine.attr({ | |
32 | + x2: width, | |
33 | + y1: height / 2, | |
34 | + y2: height / 2 | |
35 | + }); | |
36 | + for (i = 0; i < posArr.length; i++) { | |
37 | + discs[i].attr({ | |
38 | + cx: width*posArr[i][0], | |
39 | + cy: height*posArr[i][1] | |
40 | + }); | |
41 | + nums[i].attr({ | |
42 | + x: (width*posArr[i][0])-32, | |
43 | + y: (height*posArr[i][1])+50 | |
44 | + }); | |
45 | + } | |
46 | + } | |
47 | + function WHforDiscs(width, height) { | |
48 | + if (width/height > 1.05) { | |
49 | + return height/2; | |
50 | + } else { | |
51 | + return width/3; | |
52 | + } | |
53 | + } | |
54 | + //console.log(initSVG.SVGsizes); | |
55 | +// Setting default styles for rectangle and discs | |
56 | + discs.attr({ | |
57 | + fill: "#4e9a06", | |
58 | + stroke: "#ca64ff", | |
59 | + strokeWidth: 5 | |
60 | + }); | |
61 | + dateLine.attr({ | |
62 | + stroke: "#333", | |
63 | + strokeWidth: 30 | |
64 | + }); | |
65 | + nums.attr({ | |
66 | + fontSize: "1.8em", | |
67 | + fontWeight: "bold" | |
68 | +// pointerEvents: "none" | |
69 | + }); | |
70 | +// Initialize circles | |
71 | + for (i = 0; i < posArr.length; i++) { | |
72 | + discs.add(s.circle(width*posArr[i][0], height*posArr[i][1], 20)); // Create and add circles to discs. | |
73 | + nums.add(s.text((width*posArr[i][0])-32, (height*posArr[i][1])+50, dates[i])); | |
74 | + discs[i].click( function() { | |
75 | + if (window.nowFull == -1) { | |
76 | + for ( i = 0; i < posArr.length; i++ ) { | |
77 | + if (discs[i].id == this.id) { | |
78 | + window.nowFull = i; | |
79 | + } | |
80 | + } | |
81 | + nums.attr({visibility: "hidden"}); | |
82 | + discs.attr({visibility: "hidden"}); // Hide discs to prevent ovelay viewing | |
83 | + this.attr({visibility: "visible"}); // Hide discs to prevent ovelay viewing | |
84 | + this.animate({r: window.innerWidth, cy: (window.innerHeight / 2) , cx: (window.innerWidth / 2), strokeWidth: 50}, 1000); //Move circle | |
85 | + rect.attr({visibility: ""}); //Show rectangle | |
86 | + rect.animate({opacity: 0.8}, 500); // Animate opacity | |
87 | + document.getElementById("overlay").style.visibility = ""; | |
88 | + } else { | |
89 | + discs[window.nowFull].animate({r: 20, cy: height*posArr[window.nowFull][1], cx: width*posArr[window.nowFull][0], strokeWidth: 5}, 1000); //Return circle to original position | |
90 | + discs[window.nowFull].attr({visibility: ""}); | |
91 | + nums.attr({visibility: ""}); | |
92 | + discs.attr({visibility: ""}); // Unhide circles | |
93 | + rect.attr({visibility: "hidden", opacity: "0"}); // Hide rectangle and set animation | |
94 | + document.getElementById("overlay").style.visibility = "hidden"; | |
95 | + window.nowFull = -1; | |
96 | + } | |
97 | + }); | |
98 | + } | |
99 | + return SVGsizes; | |
100 | +} |