def create(x, y): initial_state = np.random.randint(0, 2, size=[x, y]) nx_graph = graph_algs.get_periodic_two_dim_square_lattice(initial_state) data = graph_algs.nx_to_d3(nx_graph) data_json = json.dumps(data) network = ought_ext.Network(data_json) _set_network(network) return 'Network created successfully'
def describe_prelaid(): d3_json = _get_network().to_json() d3_dict = json.loads(d3_json) nx_graph = graph_algs.d3_to_nx(d3_dict) layout = graph_algs.get_layout(nx_graph) for name, position in layout.items(): # Scale position to lie in [0, 1] p = 0.5 * (position + 1.0) nx_graph.node[name]['x'] = p[0] nx_graph.node[name]['y'] = p[1] json_str = json.dumps(graph_algs.nx_to_d3(nx_graph)) return json_str