def _to_primitives(self): r = 0.04 primitives = [] pos = nx.kamada_kawai_layout(self.graph) for edge in self.graph.edges: node1, node2 = edge[0], edge[1] pos1, pos2 = pos[node1], pos[node2] line = plot_data.LineSegment2D([pos1[0], pos1[1]], [pos2[0], pos2[1]], edge_style=plot_data.EdgeStyle()) primitives.append(line) for node, data in self.graph.nodes(data=True): position = pos[node] color, shape, name = data['color'], data['shape'], data['name'] x, y = position[0], position[1] edge_style = plot_data.EdgeStyle(color_stroke=color) surface_style = plot_data.SurfaceStyle(color_fill=color) if shape == '.': point_style = plot_data.PointStyle(color_fill=color, color_stroke=color, size=4) prim = plot_data.Point2D(x, y, point_style=point_style) elif shape == 'o': prim = plot_data.Circle2D(x, y, r, edge_style=edge_style, surface_style=surface_style) elif shape == 's': x1, x2, y1, y2 = x - r, x + r, y - r, y + r l1 = plot_data.LineSegment2D([x1, y1], [x2, y1]) l2 = plot_data.LineSegment2D([x2, y1], [x2, y2]) l3 = plot_data.LineSegment2D([x2, y2], [x1, y2]) l4 = plot_data.LineSegment2D([x1, y2], [x1, y1]) prim = plot_data.Contour2D([l1, l2, l3, l4], edge_style=edge_style, surface_style=surface_style) else: raise NotImplementedError primitives.append(prim) text_style = plot_data.TextStyle(text_color='rgb(0,0,0)', text_align_x='center', text_align_y='middle') text = plot_data.Text(name, x, y, text_style=text_style) primitives.append(text) return primitives
def plot_data(self, edge_style: plot_data.EdgeStyle = None, surface_style: plot_data.SurfaceStyle = None): """ Dessia plot_data method return a plotdata.Circle2D object """ if edge_style is None: edge_style = plot_data.EdgeStyle(line_width=1, color_stroke=BLACK, dashline=[]) if surface_style is None: surface_style = plot_data.SurfaceStyle(color_fill=CYAN) return plot_data.Circle2D(cx=self.position.x, cy=self.position.y, r=self.diameter / 2, edge_style=edge_style, surface_style=surface_style)
# In the same way, primitive_groups contain primitives (ie: Arc2D, Circle2D, Contour2D, # LineSegment and Text) import plot_data import plot_data.colors as colors contour = plot_data.Contour2D(plot_data_primitives=[ plot_data.LineSegment2D([1, 1], [1, 2]), plot_data.LineSegment2D([1, 2], [2, 2]), plot_data.LineSegment2D([2, 2], [2, 1]), plot_data.LineSegment2D([2, 1], [1, 1]) ], surface_style=plot_data.SurfaceStyle( colors.LIGHTORANGE)) circle1 = plot_data.Circle2D(cx=0, cy=0, r=10) circle2 = plot_data.Circle2D(cx=1, cy=1, r=5, surface_style=plot_data.SurfaceStyle(colors.RED)) circle3 = plot_data.Circle2D(cx=1, cy=1, r=5, surface_style=plot_data.SurfaceStyle( colors.LIGHTBROWN)) primitive_group1 = plot_data.PrimitiveGroup(primitives=[circle1]) primitive_group2 = plot_data.PrimitiveGroup(primitives=[contour]) primitive_group3 = plot_data.PrimitiveGroup(primitives=[circle2]) primitive_group4 = plot_data.PrimitiveGroup(primitives=[circle3]) primitive_groups = [
surface_style=surface_style) # LineSegment2D line = plot_data.LineSegment2D(point1=[4, 0], point2=[6, 2], edge_style=edge_style) # Circle circle_edge_style = plot_data.EdgeStyle(1, colors.RED) circle_surface_style = plot_data.SurfaceStyle(color_fill=colors.YELLOW, opacity=0.5, hatching=plot_data.HatchingSet()) circle = plot_data.Circle2D(cx=5, cy=10, r=5, edge_style=circle_edge_style, surface_style=circle_surface_style) # Text text = plot_data.Text(comment='Hello', position_x=6, position_y=9, text_style=plot_data.TextStyle(text_color=colors.RED, font_size=12, font_style='sans-serif')) # Label # This label is created with minimum information label1 = plot_data.Label(title='label1')