2 * Copyright 2016-2017, CMCC Technologies Co., Ltd.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
21 * <Creat topological graph object>
\r
22 * @param id: The id of DIV which display topological graph.
\r
23 * @param settings: Init parameters .
\r
26 this.canvas = function (id, settings)
\r
40 // This works only with the canvas renderer, so the
\r
41 // renderer type set as "canvas" is necessary here.
\r
42 container : document.getElementById(id),
\r
48 CustomShapes.init(topo);
\r
53 * <Refresh topological graph object>
\r
56 this.refresh = function()
\r
63 * <Creat node object>
\r
64 * @param id: The id of node.
\r
67 this.Node = function(id)
\r
72 this.type = "square",/**equilateral,star,square,diamond,circle,cross**/
\r
77 this.color = "transparent",
\r
78 this.borderColor = "#1E90FF",
\r
80 this.setName = function(v)
\r
85 this.setType = function(v)
\r
90 this.setSize = function(v)
\r
95 this.setImg = function(url)
\r
100 // scale/clip are ratio values applied on top of 'size'
\r
104 pr.borderColor = "transparent";
\r
105 pr.color = "transparent";
\r
108 this.setImgScale = function(s)
\r
110 pr.image.scale = s;
\r
113 this.setImgClip = function(c)
\r
118 this.setColor = function(v)
\r
123 this.setBorderColor = function(v)
\r
125 pr.borderColor = v;
\r
128 this.setLocation = function(x,y)
\r
134 this.setProperty = function(k,v)
\r
141 * <Creat link object>
\r
142 * @param id: The id of link.
\r
145 this.Link = function(id)
\r
149 this.type = "arrow",/*'line','curve','arrow','curvedArrow','dashed','dotted','parallel','tapered'*/
\r
152 this.size = Math.random(),
\r
153 this.color = "#1E90FF",
\r
155 this.setType = function(v)
\r
160 this.setSize = function(v)
\r
165 this.setConnect = function(s,t)
\r
171 this.setColor = function(v)
\r
176 this.setProperty = function(k,v)
\r
183 * <Add node to the topological graph>
\r
184 * @param v: Node object.
\r
187 this.addNode = function(v)
\r
189 topo.graph.addNode(v);
\r
193 * <Delete node from the topological graph>
\r
194 * @param id: The id of node.
\r
197 this.dropNode = function(id)
\r
199 topo.graph.dropNode(id);
\r
204 * <Add link to the topological graph>
\r
205 * @param v: Link object.
\r
208 this.addLink = function(v)
\r
210 topo.graph.addEdge(v);
\r
214 * <Delete link from the topological graph>
\r
215 * @param id: The id of link.
\r
218 this.dropLink = function(id)
\r
220 topo.graph.dropEdge(id);
\r
224 * <Returns all of the nodes>
\r
227 this.allNodes = function()
\r
229 return topo.graph.nodes();
\r
233 * Define drag and drop object.
\r
235 var dragListener = null;
\r
238 * <Set the node drag and drop>
\r
239 * @param b: The node can be dragged and dropped when the parameter is TRUE.Set after canvas init.
\r
242 this.setDrag = function(b)
\r
246 dragListener = sigma.plugins.dragNodes(topo, topo.renderers[0]);
\r
251 * <Binding the event of drag and drop>
\r
252 * @param method: The binding method include:startdrag,drag,drop,dragend.
\r
253 * @param e: Callback method.
\r
256 var dragBind = function(method,e)
\r
258 if (null != dragListener)
\r
260 dragListener.bind(method, function(event){
\r
268 * <Binding the event of mouse>
\r
269 * @param method: The binding method include:rightClick,clickStage,doubleClickStage,rightClickStage,clickNode,clickNodes,clickEdge,
\r
270 * clickEdges,doubleClickNode,doubleClickNodes,doubleClickEdge,doubleClickEdges,rightClickNode,
\r
271 * rightClickNodes,rightClickEdge,rightClickEdges,overNode,overNodes,overEdge,overEdges,outNode,
\r
272 * outNodes,outEdge,outEdges,downNode,downNodes,downEdge,downEdges,upNode,upNodes,upEdge,upEdges
\r
273 * @param e Callback method.
\r
276 this.mouseBind = function(method,e)
\r
280 topo.bind(method, function(event){
\r
288 * <Disable the right mouse button for browser>
\r
289 * @param obj: The object to be disabled.
\r
292 this.noright = function(obj) {
\r
294 obj.oncontextmenu = function() {
\r
297 obj.ondragstart = function() {
\r
300 obj.onselectstart = function() {
\r
303 obj.onselect = function() {
\r
304 obj.selection.empty();
\r
306 obj.oncopy = function() {
\r
307 obj.selection.empty();
\r
309 obj.onbeforecopy = function() {
\r