MCPcopy Index your code
hub / github.com/clips/pattern / _script

Method _script

pattern/graph/__init__.py:1299–1356  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1297 return "".join(self._script())
1298
1299 def _script(self):
1300 s = [];
1301 s.append("function setup(canvas) {\n")
1302 s.append( "\tcanvas.size(%s, %s);\n" % (self.width, self.height))
1303 s.append( "\tcanvas.fps = %s;\n" % (self.fps))
1304 s.append( "\t" + "".join(self._data()).replace("\n", "\n\t"))
1305 s.append( "\n")
1306 # Apply node weight to node radius.
1307 if self.pack: s.append(
1308 "\tfor (var i=0; i < g.nodes.length; i++) {\n"
1309 "\t\tvar n = g.nodes[i];\n"
1310 "\t\tn.radius = n.radius + n.radius * n.weight;\n"
1311 "\t}\n")
1312 # Apply edge length (leaves get shorter edges).
1313 if self.pack: s.append(
1314 "\tfor (var i=0; i < g.nodes.length; i++) {\n"
1315 "\t\tvar e = g.nodes[i].edges();\n"
1316 "\t\tif (e.length == 1) {\n"
1317 "\t\t\te[0].length *= 0.2;\n"
1318 "\t\t}\n"
1319 "\t}\n")
1320 # Apply eigenvector and betweenness centrality.
1321 if self.weight is True: s.append(
1322 "\tg.eigenvectorCentrality();\n"
1323 "\tg.betweennessCentrality();\n")
1324 if isinstance(self.weight, (list, tuple)):
1325 if WEIGHT in self.weight: s.append(
1326 "\tg.eigenvectorCentrality();\n")
1327 if CENTRALITY in self.weight: s.append(
1328 "\tg.betweennessCentrality();\n")
1329 # Apply pruning.
1330 if self.prune is not None: s.append(
1331 "\tg.prune(%s);\n" % self.prune)
1332 # Apply the layout settings.
1333 s.append( "\tg.layout.k = %s; // Force constant (= edge length).\n"
1334 "\tg.layout.force = %s; // Repulsive strength.\n"
1335 "\tg.layout.repulsion = %s; // Repulsive radius.\n" % (
1336 self.k,
1337 self.force,
1338 self.repulsion))
1339 # Implement <canvas> draw().
1340 s.append("}\n")
1341 s.append("function draw(canvas) {\n"
1342 "\tif (g.layout.iterations <= %s) {\n"
1343 "\t\tcanvas.clear();\n"
1344 "\t\t//shadow();\n"
1345 "\t\tstroke(0);\n"
1346 "\t\tfill(0,0);\n"
1347 "\t\tg.update(%s);\n"
1348 "\t\tg.draw(%s, %s);\n"
1349 "\t}\n"
1350 "\tg.drag(canvas.mouse);\n"
1351 "}" % (
1352 int(self.frames),
1353 int(self.ipf),
1354 str(self.weighted).lower(),
1355 str(self.directed).lower()))
1356 return s

Callers 2

scriptMethod · 0.95
htmlMethod · 0.95

Calls 3

_dataMethod · 0.95
strFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected