Changeset 7949:633ce1a8418a in orange
 Timestamp:
 05/27/11 14:25:01 (3 years ago)
 Branch:
 default
 Convert:
 f4bfeddb4fac2c061fd1023243960e32f6f987fb
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

orange/Orange/network/network.py
r7858 r7949 2 2 import readwrite 3 3 import Orange 4 import orangeom 4 5 5 6 from networkx import algorithms … … 13 14 14 15 def items(self): 15 if len(self._items) != self.number_of_nodes(): 16 if self._items is not None and \ 17 len(self._items) != self.number_of_nodes(): 16 18 print "Warning: items length does not match the number of nodes." 17 19 … … 19 21 20 22 def set_items(self, items=None): 21 if items :23 if items is not None: 22 24 if not isinstance(items, Orange.data.Table): 23 25 raise TypeError('items must be of type \'Orange.data.Table\'') … … 28 30 29 31 def links(self): 30 if len(self._links) != self.number_of_edges(): 32 if self._links is not None \ 33 and len(self._links) != self.number_of_edges(): 31 34 print "Warning: links length does not match the number of edges." 32 35 33 36 return self._links 34 37 35 def set_links(self, links ):36 if links :38 def set_links(self, links=None): 39 if links is not None: 37 40 if not isinstance(links, Orange.data.Table): 38 41 raise TypeError('links must be of type \'Orange.data.Table\'') … … 43 46 44 47 ### TODO: OVERRIDE METHODS THAT CHANGE GRAPH STRUCTURE, add warning prints 48 49 def items_vars(self): 50 """Return a list of features in network items.""" 51 vars = [] 52 if (self._items is not None): 53 if isinstance(self._items, Orange.data.Table): 54 vars = list(self._items.domain.variables) 55 56 metas = self._items.domain.getmetas(0) 57 vars.extend(var for i, var in metas.iteritems()) 58 return vars 59 60 def links_vars(self): 61 """Return a list of features in network links.""" 62 vars = [] 63 if (self._links is not None): 64 if isinstance(self._links, Orange.data.Table): 65 vars = list(self._links.domain.variables) 66 67 metas = self._links.domain.getmetas(0) 68 vars.extend(var for i, var in metas.iteritems()) 69 return [x for x in vars if str(x.name) != 'u' and str(x.name) != 'v'] 45 70 46 71 class Graph(BaseGraph, nx.Graph): … … 75 100 76 101 __init__.__doc__ = nx.MultiDiGraph.__init__.__doc__ 102 103 class GraphLayout(orangeom.GraphLayout): 104 105 """A graph layout optimization class.""" 106 107 def __init__(self): 108 pass 109 110 def set_graph(self, graph=None, positions=None): 111 """Initialize graph structure 112 113 :param graph: NetworkX graph 114 115 """ 116 if positions is not None and len(positions) == graph.number_of_nodes(): 117 orangeom.GraphLayout.set_graph(self, graph, positions) 118 else: 119 orangeom.GraphLayout.set_graph(self, graph) 120 121 def random(self): 122 orangeom.GraphLayout.random(self) 123 124 def fr(self, steps, temperature, coolFactor=0, weighted=False): 125 return orangeom.GraphLayout.fr(self, steps, temperature, coolFactor, weighted) 126 127 def fr_radial(self, center, steps, temperature): 128 return orangeom.GraphLayout.fr_radial(self, center, steps, temperature) 129 130 def circular_original(self): 131 orangeom.GraphLayout.circular_original(self) 132 133 def circular_random(self): 134 orangeom.GraphLayout.circular_random(self) 135 136 def circular_crossing_reduction(self): 137 orangeom.GraphLayout.circular_crossing_reduction(self) 138 139 def get_vertices_in_rect(self, x1, y1, x2, y2): 140 return orangeom.GraphLayout.get_vertices_in_rect(self, x1, y1, x2, y2) 141 142 def closest_vertex(self, x, y): 143 return orangeom.GraphLayout.closest_vertex(self, x, y) 144 145 def vertex_distances(self, x, y): 146 return orangeom.GraphLayout.vertex_distances(self, x, y) 147 148 def rotate_vertices(self, components, phi): 149 """Rotate network components for a given angle. 150 151 :param components: list of network components 152 :type components: list of lists of vertex indices 153 :param phi: list of component rotation angles (unit: radians) 154 """ 155 #print phi 156 for i in range(len(components)): 157 if phi[i] == 0: 158 continue 159 160 component = components[i] 161 162 x = self.coors[0][component] 163 y = self.coors[1][component] 164 165 x_center = x.mean() 166 y_center = y.mean() 167 168 x = x  x_center 169 y = y  y_center 170 171 r = numpy.sqrt(x ** 2 + y ** 2) 172 fi = numpy.arctan2(y, x) 173 174 fi += phi[i] 175 #fi += factor * M[i] * numpy.pi / 180 176 177 x = r * numpy.cos(fi) 178 y = r * numpy.sin(fi) 179 180 self.coors[0][component] = x + x_center 181 self.coors[1][component] = y + y_center 182
Note: See TracChangeset
for help on using the changeset viewer.