server/python/django/renkanmanager/utils.py
changeset 366 e8327b4e8b8b
parent 334 de35ce18643a
child 367 9a3d5fdbf296
equal deleted inserted replaced
365:a5ff3ac7cb43 366:e8327b4e8b8b
    40             raise Http404
    40             raise Http404
    41         return self.cat_nb_nodes[category].pop(0)
    41         return self.cat_nb_nodes[category].pop(0)
    42 
    42 
    43 
    43 
    44 
    44 
    45 class LineNodePlacer(NodePlacer):
    45 class LineNodePlacer(NodePlacer): #vertical lines
    46     
    46     
    47     max_length = 0
    47     max_length = 0
    48     
    48     
    49     def init(self, cat_nb_nodes_initial):
    49     def init(self, cat_nb_nodes_initial):
    50         for c in cat_nb_nodes_initial:
    50         for c in cat_nb_nodes_initial:
    63                 if c=="northwest":
    63                 if c=="northwest":
    64                     self.cat_nb_nodes[c].append({ "x": order*500, "y": offset })
    64                     self.cat_nb_nodes[c].append({ "x": order*500, "y": offset })
    65                 else:
    65                 else:
    66                     self.cat_nb_nodes[c].append({ "x": order*500, "y": 100*(i+offset) })
    66                     self.cat_nb_nodes[c].append({ "x": order*500, "y": 100*(i+offset) })
    67 
    67 
       
    68 
       
    69 class HorLineNodePlacer(NodePlacer): #horizontal lines
       
    70     
       
    71     max_length = 0
       
    72     
       
    73     def init(self, cat_nb_nodes_initial):
       
    74         for c in cat_nb_nodes_initial:
       
    75             nb = cat_nb_nodes_initial[c]
       
    76             if isinstance(cat_nb_nodes_initial[c], tuple):
       
    77                 _, nb = nb
       
    78             self.max_length = nb if nb > self.max_length else self.max_length
       
    79         for i_cat,c in enumerate(cat_nb_nodes_initial):
       
    80             self.cat_nb_nodes[c] = []
       
    81             order = i_cat
       
    82             nb = cat_nb_nodes_initial[c]
       
    83             if isinstance(cat_nb_nodes_initial[c], tuple):
       
    84                 order, nb = nb
       
    85             offset = float(self.max_length - nb) / 2
       
    86             for i in xrange(nb):
       
    87                 if c=="northwest":
       
    88                     self.cat_nb_nodes[c].append({ "x": offset, "y": order*500 })
       
    89                 else:
       
    90                     self.cat_nb_nodes[c].append({ "x": 100*(i+offset), "y": order*500 })
    68 
    91 
    69 
    92 
    70 class CircleNodePlacer(NodePlacer):
    93 class CircleNodePlacer(NodePlacer):
    71     
    94     
    72     def init(self, cat_nb_nodes_initial):
    95     def init(self, cat_nb_nodes_initial):