(self)
| 1206 | return "".join(self._data()) |
| 1207 | |
| 1208 | def _data(self): |
| 1209 | if self.graph.nodes and isinstance(self.weight, (list, tuple)): |
| 1210 | if WEIGHT in self.weight and self.graph.nodes[-1]._weight is None: |
| 1211 | self.graph.eigenvector_centrality() |
| 1212 | if CENTRALITY in self.weight and self.graph.nodes[-1]._centrality is None: |
| 1213 | self.graph.betweenness_centrality() |
| 1214 | s = [] |
| 1215 | s.append("g = new Graph(%s, %s);\n" % (self.ctx, self.distance)) |
| 1216 | s.append("var n = {") |
| 1217 | if len(self.graph.nodes) > 0: |
| 1218 | s.append("\n") |
| 1219 | # Translate node properties to Javascript dictionary (var n). |
| 1220 | for n in self.graph.nodes: |
| 1221 | p = [] |
| 1222 | if n._x != 0: |
| 1223 | p.append("x:%i" % n._x) # 0 |
| 1224 | if n._y != 0: |
| 1225 | p.append("y:%i" % n._y) # 0 |
| 1226 | if n.radius != self.default["radius"]: |
| 1227 | p.append("radius:%.1f" % n.radius) # 5.0 |
| 1228 | if n._weight is not None: |
| 1229 | p.append("weight:%.2f" % n.weight) # 0.00 |
| 1230 | if n._centrality is not None: |
| 1231 | p.append("centrality:%.2f" % n.centrality) # 0.00 |
| 1232 | if n.fixed != self.default["fixed"]: |
| 1233 | p.append("fixed:%s" % repr(n.fixed).lower()) # false |
| 1234 | if n.fill != self.default["fill"]: |
| 1235 | p.append("fill:%s" % self._rgba(n.fill)) # [0,0,0,1.0] |
| 1236 | if n.stroke != self.default["stroke"]: |
| 1237 | p.append("stroke:%s" % self._rgba(n.stroke)) # [0,0,0,1.0] |
| 1238 | if n.strokewidth != self.default["strokewidth"]: |
| 1239 | p.append("strokewidth:%.1f" % n.strokewidth) # 0.5 |
| 1240 | if n.text is None: |
| 1241 | p.append("text:false") |
| 1242 | if n.text and n.text.fill != self.default["text"]: |
| 1243 | p.append("text:%s" % self._rgba(n.text.fill)) # [0,0,0,1.0] |
| 1244 | if n.text and "font" in n.text.__dict__: |
| 1245 | p.append("font:\"%s\"" % n.text.__dict__["font"]) # "sans-serif" |
| 1246 | if n.text and n.text.__dict__.get("fontsize", self.default["fontsize"]) != self.default["fontsize"]: |
| 1247 | p.append("fontsize:%i" % int(max(1, n.text.fontsize))) |
| 1248 | if n.text and "fontweight" in n.text.__dict__: # "bold" |
| 1249 | p.append("fontweight:\"%s\"" % n.text.__dict__["fontweight"]) |
| 1250 | if n.text and n.text.string != n.id: |
| 1251 | p.append("label:\"%s\"" % n.text.string) |
| 1252 | if n.id in self.href: |
| 1253 | p.append("href:\"%s\"" % self.href[n.id]) |
| 1254 | if n.id in self.css: |
| 1255 | p.append("css:\"%s\"" % self.css[n.id]) |
| 1256 | s.append("\t%s: {%s},\n" % (self._escape(n.id), ", ".join(p))) |
| 1257 | s[-1] = s[-1].rstrip(",\n") # Trailing comma breaks in IE. |
| 1258 | s.append("\n};\n") |
| 1259 | s.append("var e = [") |
| 1260 | if len(self.graph.edges) > 0: |
| 1261 | s.append("\n") |
| 1262 | # Translate edge properties to Javascript dictionary (var e). |
| 1263 | for e in self.graph.edges: |
| 1264 | id1, id2 = self._escape(e.node1.id), self._escape(e.node2.id) |
| 1265 | p = [] |
no test coverage detected