Example #1
0
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)
Example #2
0
def add_needle(speed, units):
    angle = speed_to_angle(speed, units)
    plot.add_glyph(
        Ray(x=0,
            y=0,
            length=data(0.75),
            angle=angle,
            line_color="black",
            line_width=3))
    plot.add_glyph(
        Ray(x=0,
            y=0,
            length=data(0.10),
            angle=angle - pi,
            line_color="black",
            line_width=3))
Example #3
0
def test_Ray():
    glyph = Ray()
    assert glyph.x == "x"
    assert glyph.y == "y"
    assert glyph.angle == "angle"
    assert glyph.length == None
    yield check_line, glyph
    yield check_props, glyph, ["x", "y", "angle", "length"], LINE
Example #4
0
def test_Ray():
    glyph = Ray()
    assert glyph.x == "x"
    assert glyph.y == "y"
    assert glyph.angle == "angle"
    assert glyph.length == "length"
    yield check_line, glyph
    yield (check_props, glyph, [
        "x",
        "y",
        "angle",
        "angle_units",
        "length",
        "length_units",
    ], LINE)
Example #5
0
def test_Ray() -> None:
    glyph = Ray()
    assert glyph.x == field("x")
    assert glyph.y == field("y")
    assert glyph.angle is None
    assert glyph.length is None
    check_line_properties(glyph)
    check_properties_existence(glyph, [
        "x",
        "y",
        "angle",
        "angle_units",
        "length",
        "length_units",
    ], LINE, GLYPH)
Example #6
0
def test_Ray():
    glyph = Ray()
    assert glyph.x is None
    assert glyph.y is None
    assert glyph.angle is None
    assert glyph.length is None
    yield check_line_properties, glyph
    yield (check_properties_existence, glyph, [
        "x",
        "y",
        "angle",
        "angle_units",
        "length",
        "length_units",
    ], LINE, GLYPH)
Example #7
0
 ("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",
Example #8
0
File: Ray.py Project: ogrisel/bokeh
xdr = DataRange1d(sources=[source.columns("x")])
ydr = DataRange1d(sources=[source.columns("y")])

plot = Plot(title=None,
            x_range=xdr,
            y_range=ydr,
            plot_width=300,
            plot_height=300,
            h_symmetry=False,
            v_symmetry=False,
            min_border=0,
            toolbar_location=None)

glyph = Ray(x="x",
            y="y",
            length="l",
            angle=-2.0,
            line_color="#fb8072",
            line_width=3)
plot.add_glyph(source, glyph)

xaxis = LinearAxis()
plot.add_layout(xaxis, 'below')

yaxis = LinearAxis()
plot.add_layout(yaxis, 'left')

plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker))
plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))

doc = Document()
doc.add(plot)
Example #9
0
 def add_needle(speed, units, color_choice, line_weight):
     angle = speed_to_angle(speed, units)
     plot.add_glyph(Ray(x=0, y=0, length=data(0.75), angle=angle,    line_color=color_choice, line_width=line_weight))
     plot.add_glyph(Ray(x=0, y=0, length=data(0.10), angle=angle-pi, line_color=color_choice, line_width=line_weight))
Example #10
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