def make_widget(self, debug=False):
     width = self.width
     self.info = widgets.HTML("<div>Ranker of rankings explorer.</div>")
     self.n_k_slider = n_k_slider(self.set_n_k,
                                  n=self.n,
                                  k=self.k,
                                  max_n=self.max_n)
     stat_abbrevs = sorted(st.ABBREVIATION_TO_STATISTIC.keys())
     self.primary_dropdown = widgets.Dropdown(
         options=stat_abbrevs,
         value=self.primary_stat.abbreviation,
         description='primary stat')
     self.secondary_dropdown = widgets.Dropdown(
         options=stat_abbrevs,
         value=self.secondary_stat.abbreviation,
         description='secondary stat')
     self.reset_button = widgets.Button(description="reset stats")
     self.reset_button.on_click(self.reset_stats)
     self.stats_box = widgets.HBox([
         self.primary_dropdown,
         self.secondary_dropdown,
         self.reset_button,
         self.check_change_array,
     ])
     hwidth = width * 0.5
     self.scatter = dual_canvas.DualCanvasWidget(width=hwidth,
                                                 height=hwidth)
     self.curves = dual_canvas.DualCanvasWidget(width=hwidth, height=hwidth)
     if debug:
         self.plots_box = widgets.HBox([
             self.scatter.debugging_display(),
             self.curves.debugging_display(),
         ])
     else:
         self.plots_box = widgets.HBox([
             self.scatter,
             self.curves,
         ])
     self.rebuild()
     if debug:
         self.assembly = widgets.VBox([
             self.info,
             self.n_k_slider,
             self.stats_box,
             self.rank_of_rankings.debugging_display(),
             self.plots_box,
             self.selected_rank.debugging_display(),
         ])
     else:
         self.assembly = widgets.VBox([
             self.info,
             self.n_k_slider,
             self.stats_box,
             self.rank_of_rankings,
             self.plots_box,
             self.selected_rank,
         ])
     return self.assembly
예제 #2
0
def get_usual_screen(width=WIDTH, height=HEIGHT):
    global USUAL_SCREEN
    if USUAL_SCREEN is not None:
        return USUAL_SCREEN
    screen = dual_canvas.DualCanvasWidget(width=width, height=height)
    # use a counter to distinguish turtles
    screen.turtle_count = 0
    # store info about turtles in the javascript element container
    screen.js_init("""
        element.turtle_info = { };

        element.get_turtle_info = function(id) {
            return element.turtle_info[id];
        };
    """)
    if not debugging:
        display(screen)
        screen.in_dialog()
        screen.element.dialog(dict(width=width + 100, height=height + 100))
    else:
        display(screen.debugging_display())
    screen.rect(0, 0, WIDTH, HEIGHT, "#eea", name='Screen')
    screen.fit()
    USUAL_SCREEN = screen
    return screen
예제 #3
0
 def execute_widget(self, widget):
     from jp_doodle import dual_canvas
     from IPython.display import display
     if widget is None:
         widget = dual_canvas.DualCanvasWidget(width=self.width,
                                               height=self.height)
     display(widget)
     self.exec_code(widget)
예제 #4
0
 def __init__(self, color="blue", slots=10, width=200, height=None):
     if height is None:
         height = width
     self.slots = slots
     self.color = color
     self.width = width
     self.height = height
     self.widget = dual_canvas.DualCanvasWidget(width=width, height=height)
예제 #5
0
 def embed_widget(self, embed=True):
     from jp_doodle import auto_capture, dual_canvas
     self.widget = dual_canvas.DualCanvasWidget(width=self.width,
                                                height=self.height)
     if embed and self.embeddable:
         with auto_capture.SaveAndEmbed(self.widget, self.image_filename,
                                        self.prefix, self.hide_after):
             self.execute_widget(self.widget)
     else:
         self.execute_widget(self.widget)
예제 #6
0
def swatch3d(
    pixels=500,
    model_height=2.0,
    cx=0,
    cy=0,
    auto_show=True,
):
    pixel_height = pixels
    dc_config = {
        "width": pixel_height,
        "height": pixel_height,
    }
    canvas = dual_canvas.DualCanvasWidget(width=pixel_height,
                                          height=pixel_height,
                                          config=dc_config)
    radius = model_height * 0.5
    frame = canvas.frame_region(0, 0, pixel_height, pixel_height, cx - radius,
                                cy - radius, cx + radius, cy + radius)
    result = ND_Frame(canvas, frame)
    if auto_show:
        result.show()
    return result
예제 #7
0
def show_array(
        array,
        width=None,
        height=None,
        #axes=True,   # axes have problems...
        background=None,
        scale=True,
        shift_min=True,
        margin=50,
        textcolor="red",
        textbackground="yellow",
        font="normal 15px Courier",
        hover_text_callback=default_hover_callback,
        hover_color="rgba(200,100,50,0.5)",
        epsilon=1e-10,
        widget=None):
    """
    Display the array as an image with the specified width and height.
    """
    # xxxx refactor this eventually to a more conventional structure.
    array = np.array(array)
    source_array = array
    if scale:
        M = array.max()
        m = array.min()
        if m > 0 and not shift_min:
            m = 0.0
        diff = M - m
        grey_max = 255
        if diff < epsilon:
            diff = 1.0
        array = (array - m) * (grey_max / diff)
    (iheight, iwidth) = array.shape[:2]
    if width is None:
        width = iwidth
    if height is None:
        height = iheight
    if widget is None:
        widget = dual_canvas.DualCanvasWidget(width=width + 2 * margin,
                                              height=height + 2 * margin)
    widget.reset_canvas()
    if background:
        widget.rect(0,
                    0,
                    w=width + 2 * margin,
                    h=height + 2 * margin,
                    color=background)
    name = "array image"
    widget.current_array = None

    def set_image(array):
        if widget.current_array is not None:
            assert widget.current_array.shape[:
                                              2] == array.shape[:
                                                                2], "Shape change not supported"
        widget.current_array = array
        if scale:
            M = array.max()
            m = array.min()
            if m > 0 and not shift_min:
                m = 0.0
            diff = M - m
            grey_max = 255
            if diff < epsilon:
                diff = 1.0
            array = (array - m) * (grey_max / diff)
        widget.name_image_array(name, array)
        widget.request_redraw()

    widget.set_image = set_image
    widget.set_image(array)
    frame = widget.frame_region(minx=margin,
                                miny=margin,
                                maxx=width + margin,
                                maxy=height + margin,
                                frame_minx=0,
                                frame_miny=iheight,
                                frame_maxx=iwidth,
                                frame_maxy=0)
    full = frame.named_image("array image",
                             0,
                             iheight,
                             width,
                             height,
                             name=True)
    widget.text(width + margin,
                height + margin + 5,
                str(iwidth),
                align="right",
                color=textcolor,
                font=font,
                background=textbackground)
    widget.text(margin - 5,
                margin,
                str(iheight),
                degrees=90,
                color=textcolor,
                font=font,
                background=textbackground)
    if hover_text_callback:
        hover_info = widget.text(margin,
                                 height + margin + 5,
                                 str(array.shape),
                                 color=textcolor,
                                 font=font,
                                 background=textbackground,
                                 name=True)
        widget.hover_info = hover_info
        upline = frame.frame_rect(x=0,
                                  y=0,
                                  w=1,
                                  h=0,
                                  color=hover_color,
                                  name=True,
                                  events=False)
        downline = frame.frame_rect(x=0,
                                    y=0,
                                    w=1,
                                    h=0,
                                    color=hover_color,
                                    name=True,
                                    events=False)
        leftline = frame.frame_rect(x=0,
                                    y=0,
                                    w=0,
                                    h=1,
                                    color=hover_color,
                                    name=True,
                                    events=False)
        rightline = frame.frame_rect(x=0,
                                     y=0,
                                     w=0,
                                     h=1,
                                     color=hover_color,
                                     name=True,
                                     events=False)

        def on_hover(event):
            position = event['model_location']
            x = int(position["x"])
            y = int(position["y"])
            upline.change(x=x, h=y)
            downline.change(x=x, y=y + 1, h=iheight - y - 1)
            leftline.change(y=y, w=x)
            rightline.change(y=y, x=x + 1, w=iwidth - x - 1)
            try:
                cb_text = hover_text_callback(x, y, widget.current_array)
            except Exception as e:
                e_text = repr(e)
                hover_info.change(text=e_text)
                raise
            else:
                hover_info.change(text=cb_text)

        full.on("mousemove", on_hover)

        def on_out(event):
            upline.change(h=0)
            downline.change(h=0)
            leftline.change(w=0)
            rightline.change(w=0)

        full.on("mouseout", on_out)
    widget.image_display = full
    return widget
예제 #8
0
def showVolume(array, width, height, draw_delay=0.01, di=1, dj=1, dk=1):
    c = dual_canvas.DualCanvasWidget(width, height)
    S = VolumeImageViewer(array, c, draw_delay=draw_delay, di=di, dj=dj, dk=dk)
    c.fit()
    return c