├── LICENSE
├── README.md
├── samples
├── 3d.html
├── about.html
├── animation.html
├── contact.html
├── container.html
├── container2.html
├── css
│ ├── bootstrap-responsive.css
│ ├── bootstrap.min.css
│ └── jquery.snippet.min.css
├── cutFruit.html
├── dev.html
├── device.html
├── diy.html
├── gravitate.html
├── img
│ ├── OS_Apple.png
│ ├── OS_Ubuntu.png
│ ├── OS_Windows_8.png
│ ├── acer-samll.jpg
│ ├── bg.jpg
│ ├── building.png
│ ├── cloud.png
│ ├── cutfruit.jpg
│ ├── cutfruit_bg.jpg
│ ├── delivery.png
│ ├── email.png
│ ├── fruit
│ │ ├── apple.png
│ │ ├── background.jpg
│ │ ├── banana.png
│ │ ├── basaha.png
│ │ ├── boom.png
│ │ ├── developing.png
│ │ ├── dojo.png
│ │ ├── flash.png
│ │ ├── flash_bak.png
│ │ ├── game-over.png
│ │ ├── home-desc.png
│ │ ├── home-mask.png
│ │ ├── logo.png
│ │ ├── lose.png
│ │ ├── new-game.png
│ │ ├── new.png
│ │ ├── ninja.png
│ │ ├── peach.png
│ │ ├── quit.png
│ │ ├── sandia.png
│ │ ├── score.png
│ │ └── xxxf.png
│ ├── harddisk.png
│ ├── helpdesk.png
│ ├── home.png
│ ├── host.png
│ ├── laptop.png
│ ├── memory.png
│ ├── ne.png
│ ├── new-game.png
│ ├── ok.png
│ ├── person.png
│ ├── phone
│ │ ├── IE.png
│ │ ├── Karate.png
│ │ ├── SMS.png
│ │ ├── Setup.png
│ │ ├── bullets.png
│ │ ├── power.png
│ │ ├── signal.png
│ │ ├── usb.png
│ │ └── writing.png
│ ├── print.png
│ ├── qq.png
│ ├── room.jpg
│ ├── telephone.png
│ ├── vm.png
│ ├── vm_inner.jpg
│ └── zone.png
├── index.html
├── js
│ ├── animation.js
│ ├── dev.js
│ ├── excanvas.js
│ ├── jquery.js
│ ├── jtopo-0.3.0-min.js
│ ├── menu.js
│ └── snippet
│ │ └── jquery.snippet.min.js
├── keyboard.html
├── link.html
├── mix.html
├── mix2.html
├── mix3.html
├── mix4.html
├── mouse.html
├── node.html
├── nodeDown.html
├── phoneNode.html
├── real.html
├── rotate.html
├── sound
│ ├── boom.mp3
│ ├── boom.ogg
│ ├── menu.mp3
│ ├── menu.ogg
│ ├── over.mp3
│ ├── over.ogg
│ ├── splatter.mp3
│ ├── splatter.ogg
│ ├── start.mp3
│ ├── start.ogg
│ ├── throw.mp3
│ └── throw.ogg
├── star.html
├── star2.html
├── star3.html
├── star4.html
├── tree.html
├── tree2.html
├── tree3.html
└── umlNode.html
└── src
├── jtopo.abstractnode.js
├── jtopo.animation.js
├── jtopo.container.js
├── jtopo.databox.js
├── jtopo.element.js
├── jtopo.js
├── jtopo.layout.js
├── jtopo.link.js
├── jtopo.node.js
└── jtopo.util.js
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
131 |
').appendTo($('#canvas').parent().css('width', '800px')) 73 | .html(code).snippet("javascript",{style:"acid",collapse:true}); 74 | }); 75 | 76 | 77 | -------------------------------------------------------------------------------- /samples/keyboard.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 61 | 67 | 68 | 69 | 70 | 71 |93 | 94 |95 |115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /samples/link.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 119 | 125 | 126 | 127 | 128 | 129 | 151 | 152 |96 |107 | 108 |97 |103 | 102 |104 | 105 |106 |
109 | 110 | 113 | 114 |153 |172 | 173 | 174 | 175 | -------------------------------------------------------------------------------- /samples/mix.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 101 | 107 | 108 | 109 | 110 | 111 | 133 | 134 |154 |164 | 165 |155 |160 | 159 |161 | 162 |163 |
166 | 167 | 170 | 171 |135 |154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /samples/mix2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 70 | 76 | 77 | 78 | 79 | 80 | 102 | 103 |136 |146 | 147 |137 |142 | 141 |143 | 144 |145 |
148 | 149 | 152 | 153 |104 |124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /samples/mix3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 70 | 76 | 77 | 78 | 79 | 80 | 102 | 103 |105 |116 | 117 |106 |112 | 111 |113 | 114 |115 |
118 | 119 | 122 | 123 |104 |124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /samples/mix4.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 75 | 81 | 82 | 83 | 84 | 85 | 107 | 108 |105 |116 | 117 |106 |112 | 111 |113 | 114 |115 |
118 | 119 | 122 | 123 |109 |129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /samples/mouse.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 73 | 79 | 80 | 81 | 82 | 83 | 105 | 106 |110 |121 | 122 |111 |117 | 116 |118 | 119 |120 |
123 | 124 | 127 | 128 |107 |127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /samples/node.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 85 | 91 | 92 | 93 | 94 | 95 | 117 | 118 |108 |119 | 120 |109 |115 | 114 |116 | 117 |118 |
121 | 122 | 125 | 126 |119 |138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /samples/nodeDown.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 104 | 110 | 111 | 112 | 113 | 114 | 136 | 137 |120 |130 | 131 |121 |126 | 125 |127 | 128 |129 |
132 | 133 | 136 | 137 |138 |157 | 158 | 159 | 160 | -------------------------------------------------------------------------------- /samples/phoneNode.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 62 | 68 | 69 | 70 | 71 | 72 | 94 | 95 |139 |149 | 150 |140 |145 | 144 |146 | 147 |148 |
151 | 152 | 155 | 156 |96 |115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /samples/real.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 61 | 67 | 68 | 69 | 70 | 71 | 93 | 94 |97 |107 | 108 |98 |103 | 102 |104 | 105 |106 |
109 | 110 | 113 | 114 |95 |114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /samples/rotate.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 60 | 66 | 67 | 68 | 69 | 70 | 92 | 93 |96 |106 | 107 |97 |102 | 101 |103 | 104 |105 |
108 | 109 | 112 | 113 |94 |114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /samples/sound/boom.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tuanjie54188/jtopo/3247af33618b9f94eb6f54a2f930b062bb53730c/samples/sound/boom.mp3 -------------------------------------------------------------------------------- /samples/sound/boom.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tuanjie54188/jtopo/3247af33618b9f94eb6f54a2f930b062bb53730c/samples/sound/boom.ogg -------------------------------------------------------------------------------- /samples/sound/menu.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tuanjie54188/jtopo/3247af33618b9f94eb6f54a2f930b062bb53730c/samples/sound/menu.mp3 -------------------------------------------------------------------------------- /samples/sound/menu.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tuanjie54188/jtopo/3247af33618b9f94eb6f54a2f930b062bb53730c/samples/sound/menu.ogg -------------------------------------------------------------------------------- /samples/sound/over.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tuanjie54188/jtopo/3247af33618b9f94eb6f54a2f930b062bb53730c/samples/sound/over.mp3 -------------------------------------------------------------------------------- /samples/sound/over.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tuanjie54188/jtopo/3247af33618b9f94eb6f54a2f930b062bb53730c/samples/sound/over.ogg -------------------------------------------------------------------------------- /samples/sound/splatter.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tuanjie54188/jtopo/3247af33618b9f94eb6f54a2f930b062bb53730c/samples/sound/splatter.mp3 -------------------------------------------------------------------------------- /samples/sound/splatter.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tuanjie54188/jtopo/3247af33618b9f94eb6f54a2f930b062bb53730c/samples/sound/splatter.ogg -------------------------------------------------------------------------------- /samples/sound/start.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tuanjie54188/jtopo/3247af33618b9f94eb6f54a2f930b062bb53730c/samples/sound/start.mp3 -------------------------------------------------------------------------------- /samples/sound/start.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tuanjie54188/jtopo/3247af33618b9f94eb6f54a2f930b062bb53730c/samples/sound/start.ogg -------------------------------------------------------------------------------- /samples/sound/throw.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tuanjie54188/jtopo/3247af33618b9f94eb6f54a2f930b062bb53730c/samples/sound/throw.mp3 -------------------------------------------------------------------------------- /samples/sound/throw.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tuanjie54188/jtopo/3247af33618b9f94eb6f54a2f930b062bb53730c/samples/sound/throw.ogg -------------------------------------------------------------------------------- /samples/star.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 65 | 71 | 72 | 73 | 74 | 75 | 97 | 98 |95 |106 | 107 |96 |102 | 101 |103 | 104 |105 |
108 | 109 | 112 | 113 |99 |119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /samples/star2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 67 | 73 | 74 | 75 | 76 | 77 | 99 | 100 |100 |111 | 112 |101 |107 | 106 |108 | 109 |110 |
113 | 114 | 117 | 118 |101 |121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /samples/star3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 62 | 68 | 69 | 70 | 71 | 72 | 94 | 95 |102 |113 | 114 |103 |109 | 108 |110 | 111 |112 |
115 | 116 | 119 | 120 |96 |115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /samples/star4.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 80 | 86 | 87 | 88 | 89 | 90 | 112 | 113 |97 |107 | 108 |98 |103 | 102 |104 | 105 |106 |
109 | 110 | 113 | 114 |114 |149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /samples/tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 60 | 66 | 67 | 68 | 69 | 70 | 92 | 93 |115 |141 | 142 |116 |137 | 136 |138 | 139 |140 |
143 | 144 | 147 | 148 |94 |114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /samples/tree2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 61 | 67 | 68 | 69 | 70 | 71 | 93 | 94 |95 |106 | 107 |96 |102 | 101 |103 | 104 |105 |
108 | 109 | 112 | 113 |95 |115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /samples/tree3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 61 | 67 | 68 | 69 | 70 | 71 | 93 | 94 |96 |107 | 108 |97 |103 | 102 |104 | 105 |106 |
109 | 110 | 113 | 114 |95 |115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /samples/umlNode.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 73 | 79 | 80 | 81 | 82 | 83 | 105 | 106 |96 |107 | 108 |97 |103 | 102 |104 | 105 |106 |
109 | 110 | 113 | 114 |107 |126 | 127 | 128 | 129 | -------------------------------------------------------------------------------- /src/jtopo.abstractnode.js: -------------------------------------------------------------------------------- 1 | /* 2 | * JTopo (Javascript topology libraries) 0.2.0 3 | * https://github.com/wondery/jtopo 4 | * 5 | * Copyright (c) 2013 wondery 6 | * Released under the LGPL license, Version 3.0 7 | * http://www.gnu.org/licenses/lgpl.html 8 | * 9 | * Author: wondery 10 | * Email: jtopology@163.com 11 | */ 12 | 13 | (function(JTopo){ 14 | /** 15 | * Abstract node object 16 | * @param {int} id 17 | * @param {String} name 18 | */ 19 | function AbstractNode(name) { 20 | this.id = null; 21 | this.x = 0; 22 | this.y = 0; 23 | this.width = 0; 24 | this.height = 0; 25 | this.visible = true; 26 | this.dragable = true; 27 | 28 | this.name = name; 29 | this.image = null; 30 | this.color = null; 31 | this.layout = null; 32 | this.gravitate = null;//function(){}; 33 | this.parentContainer = null; 34 | this.inContainer = null; 35 | this.outContainer = null; 36 | this.fixed = false; 37 | }; 38 | 39 | AbstractNode.prototype = new JTopo.Element(); 40 | 41 | AbstractNode.prototype.getName = function(){ 42 | return this.name; 43 | }; 44 | 45 | AbstractNode.prototype.setName = function(n){ 46 | this.name = n; 47 | return this; 48 | }; 49 | 50 | AbstractNode.prototype.getImage = function(){ 51 | return this.image; 52 | }; 53 | 54 | AbstractNode.prototype.setImage = function(i){ 55 | var node = this; 56 | if(typeof i == 'string'){ 57 | var img = this.image = new Image(); 58 | this.image.onload = function(){ 59 | node.setSize(img.width, img.height); 60 | }; 61 | this.image.src = i; 62 | }else{ 63 | this.image = i; 64 | } 65 | }; 66 | 67 | var ImageCache = {}; 68 | AbstractNode.prototype.getTypeImage = function(type){ 69 | var typeImages = { 70 | 'zone' : './img/zone.png', 71 | 'host' : './img/host.png', 72 | 'vm' : './img/vm.png' 73 | }; 74 | if(ImageCache[type]){ 75 | return ImageCache[type]; 76 | } 77 | var src = typeImages[type]; 78 | if(src == null) return null; 79 | 80 | var image = new Image(); 81 | image.src = src; 82 | return ImageCache[type] = image; 83 | }; 84 | 85 | AbstractNode.prototype.getType = function(){ 86 | return this.type; 87 | }; 88 | 89 | AbstractNode.prototype.setType = function(type){ 90 | this.type = type; 91 | this.setImage(this.getTypeImage(type)); 92 | }; 93 | 94 | JTopo.AbstractNode = AbstractNode; 95 | 96 | })(JTopo); 97 | -------------------------------------------------------------------------------- /src/jtopo.animation.js: -------------------------------------------------------------------------------- 1 | /* 2 | * JTopo (Javascript topology libraries) 0.2.0 3 | * https://github.com/wondery/jtopo 4 | * 5 | * Copyright (c) 2013 wondery 6 | * Released under the LGPL license, Version 3.0 7 | * http://www.gnu.org/licenses/lgpl.html 8 | * 9 | * Author: wondery 10 | * Email: jtopology@163.com 11 | */ 12 | 13 | (function(JTopo){ 14 | var isStopAll = false; 15 | 16 | //gravity 17 | function gravity(node, option){ 18 | var box = option.context; 19 | var gravity = option.gravity || 0.1; 20 | 21 | var t = null; 22 | var effect = {}; 23 | 24 | function stop(){ 25 | window.clearInterval(t); 26 | if(effect.onStop){ 27 | effect.onStop(node); 28 | } 29 | return effect; 30 | } 31 | 32 | function run(){ 33 | var dx = option.dx || 0, dy = option.dy || 2; 34 | t = setInterval(function(){ 35 | if(isStopAll){ 36 | effect.stop(); 37 | return; 38 | } 39 | dy += gravity; 40 | if(node.y + node.height < box.canvas.height){ 41 | node.setLocation(node.x + dx, node.y + dy); 42 | box.updateView(); 43 | }else{ 44 | dy = 0; 45 | stop(); 46 | } 47 | }, 20); 48 | return effect; 49 | } 50 | 51 | effect.run = run; 52 | effect.stop = stop; 53 | effect.onStop = function(f){ effect.onStop = f; return effect;}; 54 | return effect; 55 | } 56 | 57 | // 58 | function rotate(node, option){ 59 | var box = option.context; 60 | var t = null; 61 | var effect = {}; 62 | var v = option.v; 63 | 64 | function run(){ 65 | t = setInterval(function(){ 66 | if(isStopAll){ 67 | effect.stop(); 68 | return; 69 | } 70 | node.rotate += v || 0.2; 71 | if(node.rotate>2*Math.PI){ 72 | node.rotate = 0; 73 | } 74 | box.updateView(); 75 | }, 100); 76 | return effect; 77 | } 78 | function stop(){ 79 | window.clearInterval(t); 80 | if(effect.onStop){ 81 | effect.onStop(node); 82 | } 83 | return effect; 84 | } 85 | 86 | effect.run = run; 87 | effect.stop = stop; 88 | effect.onStop = function(f){ effect.onStop = f; return effect;}; 89 | return effect; 90 | } 91 | 92 | // 93 | function dividedTwoPiece(node, option){ 94 | var box = option.context; 95 | var style = node.style; 96 | var effect = {}; 97 | 98 | function genNode(x, y, r, beginDegree, endDegree){ 99 | var newNode = new JTopo.Node(); 100 | newNode.setImage(node.image); 101 | newNode.setSize(node.width, node.height); 102 | newNode.setLocation(x, y); 103 | newNode.draw = function(ctx){ 104 | ctx.save(); 105 | ctx.arc(this.x+this.width/2, this.y+this.height/2, r, beginDegree, endDegree); 106 | ctx.clip(); 107 | ctx.beginPath(); 108 | if(this.image != null){ 109 | ctx.drawImage(this.image, this.x, this.y); 110 | }else{ 111 | ctx.fillStyle = 'rgba(' + this.style.fillStyle + ',' + this.alpha + ')'; 112 | ctx.rect(this.x, this.y, this.width, this.height); 113 | ctx.fill(); 114 | } 115 | ctx.closePath(); 116 | ctx.restore(); 117 | }; 118 | return newNode; 119 | }; 120 | 121 | function split(angle, box){ 122 | var beginDegree = angle; 123 | var endDegree = angle + Math.PI; 124 | 125 | var node1 = genNode(node.x, node.y , node.width, beginDegree, endDegree); 126 | var node2 = genNode(node.x- 2 + Math.random()*4, node.y , node.width, beginDegree + Math.PI, beginDegree); 127 | 128 | node.setVisible(false); 129 | 130 | box.add(node1); 131 | box.add(node2); 132 | box.updateView(); 133 | 134 | JTopo.Animation.gravity(node1, {context:box, dx:0.3}).run().onStop(function(n){ 135 | box.remove(node1); 136 | box.remove(node2); 137 | box.updateView(); 138 | effect.stop(); 139 | }); 140 | JTopo.Animation.gravity(node2, {context:box, dx:-0.2}).run(); 141 | } 142 | 143 | function run(){ 144 | split(option.angle, box); 145 | return effect; 146 | } 147 | function stop(){ 148 | if(effect.onStop){ 149 | effect.onStop(node); 150 | } 151 | return effect; 152 | } 153 | 154 | effect.onStop = function(f){ effect.onStop = f; return effect;}; 155 | effect.run = run; 156 | effect.stop = stop; 157 | return effect; 158 | } 159 | 160 | function repeatThrow(node, option){ 161 | var gravity = 0.8; 162 | var wind = 2; 163 | var angle = 0; 164 | var box = option.context; 165 | node.isSelected = function(){ return false; }; 166 | node.isFocus = function(){return false; }; 167 | node.setDragable(false); 168 | 169 | function initNode(node){ 170 | node.setVisible(true); 171 | node.rotate = Math.random(); 172 | var w = box.canvas.width/2; 173 | node.x = w + Math.random() * (w - 100) - Math.random() * (w - 100); 174 | node.y = box.canvas.height; 175 | node.vx = Math.random() * 5 - Math.random() * 5; 176 | node.vy = -25; 177 | } 178 | 179 | var t = null; 180 | var effect = {}; 181 | function run(){ 182 | initNode(node); 183 | t = setInterval(function(){ 184 | if(isStopAll){ 185 | effect.stop(); 186 | return; 187 | } 188 | node.vy += gravity; 189 | node.x += node.vx; 190 | node.y += node.vy; 191 | if(node.x < 0 || node.x >box.canvas.width || node.y>box.canvas.height){ 192 | if(effect.onStop){ 193 | effect.onStop(node); 194 | } 195 | initNode(node); 196 | } 197 | box.updateView(); 198 | }, 50); 199 | return effect; 200 | } 201 | function stop(){ 202 | window.clearInterval(t); 203 | } 204 | 205 | effect.onStop = function(f){ effect.onStop = f; return effect;}; 206 | effect.run = run; 207 | effect.stop = stop; 208 | return effect; 209 | } 210 | 211 | function stopAll(){ 212 | isStopAll = true; 213 | } 214 | 215 | function startAll(){ 216 | isStopAll = false; 217 | } 218 | 219 | 220 | //cycle 221 | function cycle(node, option){ 222 | var p1 = option.p1; 223 | var p2 = option.p2; 224 | var box = option.context; 225 | 226 | var midX = p1.x + (p2.x - p1.x)/2; 227 | var midY = p1.y + (p2.y - p1.y)/2; 228 | var r = JTopo.util.getDistance(p1, p2)/2; 229 | 230 | var angle = Math.atan2(midY, midX); 231 | var speed = option.speed || 0.2; 232 | var effect = {}; 233 | var t = null; 234 | function run(){ 235 | t = setInterval(function(){ 236 | if(isStopAll){ 237 | effect.stop(); 238 | return; 239 | } 240 | //var newx = p1.x + midX + Math.cos(angle) * r; 241 | var newy = p1.y + midX + Math.sin(angle) * r; 242 | node.setLocation(node.x,newy); 243 | box.updateView(); 244 | angle += speed; 245 | }, 100); 246 | return effect; 247 | } 248 | function stop(){ 249 | window.clearInterval(t); 250 | } 251 | 252 | effect.run = run; 253 | effect.stop = stop; 254 | return effect; 255 | } 256 | 257 | //move 258 | function move(node, option){ 259 | var p = option.position; 260 | var box = option.context; 261 | var easing = option.easing || 0.2; 262 | 263 | var effect = {}; 264 | var t = null; 265 | function run(){ 266 | t = setInterval(function(){ 267 | if(isStopAll){ 268 | effect.stop(); 269 | return; 270 | } 271 | var dx = p.x - node.x; 272 | var dy = p.y - node.y; 273 | var vx = dx * easing; 274 | var vy = dy * easing; 275 | 276 | node.x += vx; 277 | node.y += vy; 278 | box.updateView(); 279 | if(vx < 0.01 && vy<0.1){ 280 | stop(); 281 | } 282 | }, 100); 283 | return effect; 284 | } 285 | function stop(){ 286 | window.clearInterval(t); 287 | } 288 | effect.onStop = function(f){ effect.onStop = f; return effect;}; 289 | effect.run = run; 290 | effect.stop = stop; 291 | return effect; 292 | } 293 | 294 | //scala 295 | function scala(node, option){ 296 | var p = option.position; 297 | var box = option.context; 298 | var scala = option.scala || 1; 299 | var v = 0.06; 300 | var oldScala = node.scala; 301 | 302 | var effect = {}; 303 | var t = null; 304 | function run(){ 305 | t = setInterval(function(){ 306 | node.scala += v; 307 | 308 | if(node.scala >= scala){ 309 | stop(); 310 | } 311 | box.updateView(); 312 | }, 100); 313 | return effect; 314 | } 315 | function stop(){ 316 | if(effect.onStop){ 317 | effect.onStop(node); 318 | } 319 | node.scala = oldScala; 320 | window.clearInterval(t); 321 | } 322 | effect.onStop = function(f){ effect.onStop = f; return effect;}; 323 | effect.run = run; 324 | effect.stop = stop; 325 | return effect; 326 | } 327 | 328 | JTopo.Animation = { 329 | gravity : gravity, 330 | dividedTwoPiece : dividedTwoPiece, 331 | repeatThrow: repeatThrow, 332 | rotate: rotate, 333 | cycle: cycle, 334 | move: move, 335 | scala: scala, 336 | stopAll: stopAll, 337 | startAll: startAll 338 | }; 339 | })(JTopo); 340 | -------------------------------------------------------------------------------- /src/jtopo.container.js: -------------------------------------------------------------------------------- 1 | /* 2 | * JTopo (Javascript topology libraries) 0.2.0 3 | * https://github.com/wondery/jtopo 4 | * 5 | * Copyright (c) 2013 wondery 6 | * Released under the LGPL license, Version 3.0 7 | * http://www.gnu.org/licenses/lgpl.html 8 | * 9 | * Author: wondery 10 | * Email: jtopology@163.com 11 | */ 12 | 13 | (function(JTopo){ 14 | 15 | function Container(name) { 16 | this.name = name; 17 | this.x = 0; 18 | this.y = 0; 19 | this.width = 40; 20 | this.height = 40; 21 | this.items = []; 22 | this.style = {fillStyle: '193, 200, 254'}; 23 | this.alpha = 0.3; 24 | this.dragable = true; 25 | }; 26 | 27 | Container.prototype = new JTopo.Element(); 28 | 29 | Container.prototype.add = function (e) { 30 | this.items.push(e); 31 | e.parentContainer = this; 32 | }; 33 | 34 | Container.prototype.remove = function (e) { 35 | for(var i=0; i108 |118 | 119 |109 |114 | 113 |115 | 116 |117 |
120 | 121 | 124 | 125 |0){ 66 | var minX = 10000000; 67 | var maxX = -10000000; 68 | var minY = 10000000; 69 | var maxY = -10000000; 70 | var width = maxX - minX; 71 | var height = maxY - minY; 72 | for (var i = 0; i < this.items.length; i++) { 73 | var item = this.items[i]; 74 | if (item.x <= minX) { 75 | minX = item.x; 76 | } 77 | if (item.x >= maxX) { 78 | maxX = item.x; 79 | } 80 | if (item.y <= minY) { 81 | minY = item.y; 82 | } 83 | if (item.y >= maxY) { 84 | maxY = item.y; 85 | } 86 | width = maxX - minX + item.width; 87 | height = maxY - minY + item.height; 88 | } 89 | 90 | this.x = minX - 5; 91 | this.y = minY - 5; 92 | this.width = width + 5; 93 | this.height = height + 5; 94 | } 95 | }; 96 | 97 | Container.prototype.draw = function (ctx) { 98 | this.updateBound(); 99 | ctx.save(); 100 | ctx.beginPath(); 101 | ctx.shadowBlur = 9; 102 | ctx.shadowColor = 'rgba(0,0,0,0.5)'; 103 | ctx.shadowOffsetX = 3; 104 | ctx.shadowOffsetY = 3; 105 | ctx.fillStyle = 'rgba(' + this.style.fillStyle + ',' + this.alpha + ')'; 106 | ctx.fillRect(this.x, this.y, this.width, this.height); 107 | ctx.closePath(); 108 | ctx.restore(); 109 | }; 110 | 111 | function GhomboidContainer(){ 112 | var container = new JTopo.Container(); 113 | container.offset = 50; 114 | container.draw = function(ctx){ 115 | this.updateBound(); 116 | ctx.save(); 117 | ctx.beginPath(); 118 | ctx.shadowBlur = 9; 119 | ctx.shadowColor = 'rgba(0,0,0,0.9)'; 120 | ctx.shadowOffsetX = 6; 121 | ctx.shadowOffsetY = 6; 122 | ctx.fillStyle = 'rgba(' + this.style.fillStyle + ',' + this.alpha + ')'; 123 | ctx.moveTo(this.x+this.offset, this.y); 124 | ctx.lineTo(this.x+this.offset+this.width, this.y); 125 | ctx.lineTo(this.x+this.width, this.y+this.height); 126 | ctx.lineTo(this.x, this.y+this.height); 127 | ctx.lineTo(this.x+this.offset, this.y); 128 | ctx.fill(); 129 | ctx.stroke(); 130 | ctx.closePath(); 131 | ctx.restore(); 132 | }; 133 | return container; 134 | } 135 | 136 | 137 | function GridContainer(){ 138 | var container = new JTopo.Container(); 139 | container.rows = 3; 140 | container.cols = 2; 141 | container.cellWidth = 60; 142 | container.cellHeight = 60; 143 | container.offset = 3; 144 | //container.padding = {left:0, right:0, top:0, bottom:0}; 145 | 146 | container.adjustLayout = function(){ 147 | for(var i=0; i c.x+c.width || this.y+this.height < c.y || this.y>c.y + c.height){ 221 | this.parentContainer.remove(this); 222 | break; 223 | } 224 | } 225 | } 226 | 227 | if(this.inContainer && this.isOnMousedrag){ 228 | for (var j = 0; j < box.containers.length; j++) { 229 | var group = box.containers[j]; 230 | if(! this.inContainer(group)) continue; 231 | if (x > group.x && x < group.x+group.width && y>group.y && y group.x && x < group.x+group.width && y>group.y && y