Esempio n. 1
0
def _draw_nucleotide_body(nucleotide, center, subplot: plt_axes.Subplot,
                          radius=10.0):
    nucleotide_color, nucleotide_base_class = _get_nucleotide_color(nucleotide)
    nucleotide_name = nucleotide.name
    if len(nucleotide_name) > 10:
        nucleotide_name = nucleotide_name.replace("_", "_\n")

    nucleotide_body = patches.Circle(
        center, radius=radius, color=nucleotide_color)
    text_object = subplot.text(
        center[0], center[1], nucleotide_name, va="center", ha="center")
    text_object.draw(subplot.figure.canvas.renderer)
    subplot.add_patch(nucleotide_body)
    nucleotide_body.add_callback(
        partial(_nucleotide_name_callback, text_object=text_object))
    nucleotide_body.set_label(":".join([nucleotide_base_class.__name__,
                                        nucleotide.name]))
    nucleotide_body.set_picker(True)
    return nucleotide_body
Esempio n. 2
0
def _add_update_events(subplot: plt_axes.Subplot, dna_helix_graph: nx.DiGraph,
                       nucleotide_plots: Dict[Nucleotide, _NUCLEOTIDE_PLOT]):
    subplot.figure.canvas.mpl_connect(
        'draw_event', lambda x: subplot.pchanged())
    subplot.figure.canvas.mpl_connect(
        'resize_event', lambda x: subplot.pchanged())

    text_initial_position = list(nucleotide_plots.values())[0].body.center
    text_object = subplot.text(
        text_initial_position[0], text_initial_position[1], "",
        ha="right", va="top", ma="left",
        bbox=dict(facecolor='white', edgecolor='blue', pad=5.0))
    text_object.set_visible(False)

    subplot.figure.canvas.mpl_connect(
        'button_press_event',
        partial(_remove_nucleotide_info_text, text_object=text_object))
    subplot.figure.canvas.mpl_connect(
        'pick_event',
        partial(_draw_nucleotide_info, dna_helix_graph=dna_helix_graph,
                text_object=text_object, subplot=subplot))