Ejemplo n.º 1
0
glyphs = [
    ("annular_wedge", AnnularWedge(x="x", y="y", inner_radius=screen(10), outer_radius=screen(20), start_angle=0.6, end_angle=4.1, fill_color="#8888ee")),
    ("annulus", Annulus(x="x", y="y", inner_radius=screen(10), outer_radius=screen(20), fill_color="#7FC97F")),
    ("arc", Arc(x="x", y="y", radius=screen(20), start_angle=0.6, end_angle=4.1, line_color="#BEAED4", line_width=3)),
    ("bezier", Bezier(x0="x", y0="y", x1="xp02", y1="y", cx0="xp01", cy0="yp01", cx1="xm01", cy1="ym01", line_color="#D95F02", line_width=2)),
    ("gear", Gear(x="x", y="y", module=0.1, teeth=8, angle=0, shaft_size=0.02, fill_color="#FDF6E3", line_color="D95F02")),
    ("image_url",  ImageURL(x="x", y="y", w=0.4, h=0.4, url=dict(value="http://bokeh.pydata.org/en/latest/_static/images/logo.png"), anchor="center")),
    ("line", Line(x="x", y="y", line_color="#F46D43")),
    ("multi_line", MultiLine(xs="xs", ys="ys", line_color="#8073AC", line_width=2)),
    ("oval", Oval(x="x", y="y", width=screen(15), height=screen(25), angle=-0.7, fill_color="#1D91C0")),
    ("patch", Patch(x="x", y="y", fill_color="#A6CEE3")),
    ("patches", Patches(xs="xs", ys="ys", fill_color="#FB9A99")),
    ("quad", Quad(left="x", right="xp01", top="y", bottom="ym01", fill_color="#B3DE69")),
    ("quadratic", Quadratic(x0="x", y0="y", x1="xp02", y1="y", cx="xp01", cy="yp01", line_color="#4DAF4A", line_width=3)),
    ("ray", Ray(x="x", y="y", length=45, angle=-0.7, line_color="#FB8072", line_width=2)),
    ("rect", Rect(x="x", y="y", width=screen(10), height=screen(20), angle=-0.7, fill_color="#CAB2D6")),
    ("segment", Segment(x0="x", y0="y", x1="xm01", y1="ym01", line_color="#F4A582", line_width=3)),
    ("text", Text(x="x", y="y", text=["hello"])),
    ("wedge", Wedge(x="x", y="y", radius=screen(15), start_angle=0.6, end_angle=4.1, fill_color="#B3DE69")),
]

markers = [
    ("circle", Circle(x="x", y="y", radius=0.1, fill_color="#3288BD")),
    ("circle_x", CircleX(x="x", y="y", size="sizes", line_color="#DD1C77", fill_color=None)),
    ("circle_cross", CircleCross(x="x", y="y", size="sizes", line_color="#FB8072", fill_color=None, line_width=2)),
    ("square", Square(x="x", y="y", size="sizes", fill_color="#74ADD1")),
    ("square_x", SquareX(x="x", y="y", size="sizes", line_color="#FDAE6B", fill_color=None, line_width=2)),
    ("square_cross", SquareCross(x="x", y="y", size="sizes", line_color="#7FC97F", fill_color=None, line_width=2)),
    ("diamond", Diamond(x="x", y="y", size="sizes", line_color="#1C9099", line_width=2)),
    ("diamond_cross", DiamondCross(x="x", y="y", size="sizes", line_color="#386CB0", fill_color=None, line_width=2)),
Ejemplo n.º 2
0
def set_up_simulation(simulation, image, arms):
    '''
    Sets up the simulation screen.

    :param simulation: simulation dictionary
    :param image: image dictionary
    :param arms: arms dictionary
    :returns: bokeh.models.Panel
    '''
    ### behaviour of start and reset button:
    global button
    button = Button(label='Start',
                    button_type='success',
                    width=simulation['sizeX'])
    button.on_click(callback_start)

    logging.info('Intitializing drawing simulator')
    imageFrameX = ([
        image['originX'], image['originX'] + image['width'],
        image['originX'] + image['width'], image['originX'], image['originX']
    ])
    imageFrameY = ([
        image['originY'], image['originY'], image['originY'] + image['height'],
        image['originY'] + image['height'], image['originY']
    ])
    iads = ColumnDataSource(
        dict(x=[0],
             y=[0],
             l=[arms['innerArmLength']],
             a=[0],
             n=["innerArm"],
             c=["midnightblue"],
             w=["6"]))
    oads = ColumnDataSource(
        dict(x=[arms['innerArmLength']],
             y=[0],
             l=[arms['outerArmLength']],
             a=[0],
             n=["outerArm"],
             c=["dodgerblue"],
             w=["6"]))
    sim = bp.figure(width=simulation['sizeX'],
                    height=simulation['sizeY'],
                    x_range=(0, 0.65 * arms['armLength']),
                    y_range=(0, 0.65 * arms['armLength']),
                    name='simulatorPlot')
    # add a line for inner arm without data:
    innerArm = Ray(x="x",
                   y="y",
                   angle="a",
                   length="l",
                   name="n",
                   line_width="w",
                   line_color="c")
    # add a line for outer arm without data
    outerArm = Ray(x="x",
                   y="y",
                   angle="a",
                   length="l",
                   name="n",
                   line_width="w",
                   line_color="c")
    sim.add_glyph(iads, innerArm)
    sim.add_glyph(oads, innerArm)
    sim.circle(0,
               0,
               line_color="deeppink",
               line_width=3,
               radius=arms['armLength'],
               fill_color="deeppink",
               fill_alpha=0.1)
    sim.line(imageFrameX, imageFrameY, line_width=3, color="deeppink")
    simulation['backgroundImageDF'] = ColumnDataSource(dict(url=[]))
    tab = Panel(child=column(button, sim), title="Simulator")
    simulation['innerArmDataStream'] = iads
    simulation['outerArmDataStream'] = oads
    simulation['figure'] = sim
    return tab
Ejemplo n.º 3
0
Archivo: gauges.py Proyecto: xnx/bokeh
def add_gauge(radius, max_value, length, direction, color, major_step,
              minor_step):
    major_angles, minor_angles = [], []
    major_labels, minor_labels = [], []

    total_angle = start_angle - end_angle

    major_angle_step = float(major_step) / max_value * total_angle
    minor_angle_step = float(minor_step) / max_value * total_angle

    major_angle = 0

    while major_angle <= total_angle:
        major_angles.append(start_angle - major_angle)
        major_angle += major_angle_step

    minor_angle = 0

    while minor_angle <= total_angle:
        minor_angles.append(start_angle - minor_angle)
        minor_angle += minor_angle_step

    major_labels = [major_step * i for i, _ in enumerate(major_angles)]
    minor_labels = [minor_step * i for i, _ in enumerate(minor_angles)]

    n = major_step / minor_step
    minor_angles = [x for i, x in enumerate(minor_angles) if i % n != 0]
    minor_labels = [x for i, x in enumerate(minor_labels) if i % n != 0]

    glyph = Arc(x=0,
                y=0,
                radius=radius,
                start_angle=start_angle,
                end_angle=end_angle,
                direction="clock",
                line_color=color,
                line_width=2)
    plot.add_glyph(glyph)

    rotation = 0 if direction == 1 else -pi

    x, y = zip(*[polar_to_cartesian(radius, angle) for angle in major_angles])
    angles = [angle + rotation for angle in major_angles]
    source = ColumnDataSource(dict(x=x, y=y, angle=angles))

    glyph = Ray(x="x",
                y="y",
                length=data(length),
                angle="angle",
                line_color=color,
                line_width=2)
    plot.add_glyph(source, glyph)

    x, y = zip(*[polar_to_cartesian(radius, angle) for angle in minor_angles])
    angles = [angle + rotation for angle in minor_angles]
    source = ColumnDataSource(dict(x=x, y=y, angle=angles))

    glyph = Ray(x="x",
                y="y",
                length=data(length / 2),
                angle="angle",
                line_color=color,
                line_width=1)
    plot.add_glyph(source, glyph)

    x, y = zip(*[
        polar_to_cartesian(radius + 2 * length * direction, angle)
        for angle in major_angles
    ])
    text_angles = [angle - pi / 2 for angle in major_angles]
    source = ColumnDataSource(
        dict(x=x, y=y, angle=text_angles, text=major_labels))

    glyph = Text(x="x",
                 y="y",
                 angle="angle",
                 text="text",
                 text_align="center",
                 text_baseline="middle")
    plot.add_glyph(source, glyph)