--- a/server/python/django/renkanmanager/utils.py Tue Aug 26 16:06:55 2014 +0200
+++ b/server/python/django/renkanmanager/utils.py Tue Aug 26 18:03:42 2014 +0200
@@ -10,6 +10,7 @@
from django.shortcuts import get_object_or_404
from django.utils.encoding import smart_str
from renkanmanager.models import Renkan
+import math
import md5
import re
import uuid
@@ -60,21 +61,23 @@
offset = float(self.max_length - nb) / 2
for i in xrange(nb):
self.cat_nb_nodes[c].append({ "x": order*500, "y": 100*(i+offset) })
- #logger.debug(self.cat_nb_nodes)
class CircleNodePlacer(NodePlacer):
- #TODO: Does not work. Meant to be a real circle placer
+
def init(self, cat_nb_nodes_initial):
- for c in cat_nb_nodes_initial:
- self.max_length = cat_nb_nodes_initial[c] if cat_nb_nodes_initial[c] > self.max_length else self.max_length
for i_cat,c in enumerate(cat_nb_nodes_initial):
self.cat_nb_nodes[c] = []
- offset = float(self.max_length - cat_nb_nodes_initial[c]) / 2
- for i in xrange(cat_nb_nodes_initial[c]):
- self.cat_nb_nodes[c].append({ "x": i_cat*400, "y": 200*(i+offset) })
- #logger.debug(self.cat_nb_nodes)
+ order = i_cat
+ nb = cat_nb_nodes_initial[c]
+ if isinstance(cat_nb_nodes_initial[c], tuple):
+ order, nb = nb
+ order -= 1
+ for i in xrange(nb):
+ radius = (order*500) if order>0 else 100
+ angle = 2 * math.pi * i / nb
+ self.cat_nb_nodes[c].append({ "x": radius*math.cos(angle), "y": radius*math.sin(angle) })