Exemplo n.º 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)
    add_glyph(glyph, global_source)

    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))
    plot.data_sources.append(source)

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

    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))
    plot.data_sources.append(source)

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

    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))
    plot.data_sources.append(source)

    glyph = Text(x="x", y="y", angle="angle", text="text", text_align="center", text_baseline="middle")
    add_glyph(glyph, source)
Exemplo n.º 2
0
class TestRay(unittest.TestCase):
    def setUp(self):
        from bokeh.glyphs import Ray
        self.test_ray = Ray()

    def test_expected_properties(self):
        expected_properties = set(['x', 'y', 'angle', 'length'])
        actual_properties = get_prop_set(type(self.test_ray))
        self.assertTrue(expected_properties.issubset(actual_properties))

    def test_expected_values(self):
        self.assertEqual(self.test_ray.x, 'x')
        self.assertEqual(self.test_ray.y, 'y')
        self.assertEqual(self.test_ray.angle, 'angle')
        self.assertEqual(self.test_ray.length, 'length')
        self.assertEqual(self.test_ray.__view_model__, 'ray')

    def test_to_glyphspec(self):
        expected = dict(GENERIC_GLYPH_DICT)
        del expected['fill_color']  # only line props
        del expected['fill_alpha']  # only line props
        expected['type'] = 'ray'
        expected.update({
            'angle': {
                'units': 'data',
                'field': 'angle'
            },
            'length': {
                'units': 'data',
                'field': 'length'
            },
        })
        self.assertEqual(self.test_ray.to_glyphspec(), expected)
        self.test_ray.x = 50
        self.test_ray.y = 51
        self.test_ray.angle = 90
        self.test_ray.length = 100
        expected.update({
            'x': {
                'units': 'data',
                'value': 50
            },
            'y': {
                'units': 'data',
                'value': 51
            },
            'angle': {
                'units': 'data',
                'value': 90
            },
            'length': {
                'units': 'data',
                'value': 100
            },
        })
        self.assertEqual(self.test_ray.to_glyphspec(), expected)
Exemplo n.º 3
0
def add_needle(speed, units):
    angle = speed_to_angle(speed, units)
    add_glyph(
        Ray(x=0,
            y=0,
            length=0.75,
            angle=angle,
            line_color="black",
            line_width=3))
    add_glyph(
        Ray(x=0,
            y=0,
            length=0.10,
            angle=angle - pi,
            line_color="black",
            line_width=3))
Exemplo n.º 4
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
Exemplo n.º 5
0
def add_needle(speed, units):
    angle = speed_to_angle(speed, units)
    plot.add_glyph(
        ds,
        Ray(x=0,
            y=0,
            length=data(0.75),
            angle=angle,
            line_color="black",
            line_width=3))
    plot.add_glyph(
        ds,
        Ray(x=0,
            y=0,
            length=data(0.10),
            angle=angle - pi,
            line_color="black",
            line_width=3))
Exemplo n.º 6
0
class TestRay(unittest.TestCase):

    def setUp(self):
        from bokeh.glyphs import Ray
        self.test_ray = Ray()

    def test_expected_properties(self):
        expected_properties = set(['x', 'y', 'angle', 'length'])
        actual_properties = get_prop_set(type(self.test_ray))
        self.assertTrue(expected_properties.issubset(actual_properties))

    def test_expected_values(self):
        self.assertEqual(self.test_ray.x, 'x')
        self.assertEqual(self.test_ray.y, 'y')
        self.assertEqual(self.test_ray.angle, 'angle')
        self.assertEqual(self.test_ray.length, 'length')
        self.assertEqual(self.test_ray.__view_model__, 'ray')

    def test_to_glyphspec(self):
        expected = dict(GENERIC_GLYPH_DICT)
        del expected['fill_color']  # only line props
        del expected['fill_alpha']  # only line props
        expected['type'] = 'ray'
        expected.update({
            'angle':  {'units': 'data', 'field': 'angle'},
            'length': {'units': 'data', 'field': 'length'},
        })
        self.assertEqual(self.test_ray.to_glyphspec(), expected)
        self.test_ray.x = 50
        self.test_ray.y = 51
        self.test_ray.angle = 90
        self.test_ray.length = 100
        expected.update({
            'x':      {'units': 'data', 'value': 50},
            'y':      {'units': 'data', 'value': 51},
            'angle':  {'units': 'data', 'value': 90},
            'length':  {'units': 'data', 'value': 100},
        })
        self.assertEqual(self.test_ray.to_glyphspec(), expected)
Exemplo n.º 7
0
class TestRay(unittest.TestCase):
    def setUp(self):
        from bokeh.glyphs import Ray

        self.test_ray = Ray()

    def test_expected_properties(self):
        expected_properties = set(["x", "y", "angle", "length"])
        actual_properties = get_prop_set(type(self.test_ray))
        self.assertTrue(expected_properties.issubset(actual_properties))

    def test_expected_values(self):
        self.assertEqual(self.test_ray.x, "x")
        self.assertEqual(self.test_ray.y, "y")
        self.assertEqual(self.test_ray.angle, "angle")
        self.assertEqual(self.test_ray.length, "length")
        self.assertEqual(self.test_ray.__view_model__, "ray")

    def test_to_glyphspec(self):
        expected = dict(GENERIC_GLYPH_DICT)
        del expected["fill_color"]  # only line props
        del expected["fill_alpha"]  # only line props
        expected["type"] = "ray"
        expected.update({"angle": {"units": "data", "field": "angle"}, "length": {"units": "data", "field": "length"}})
        self.assertEqual(self.test_ray.to_glyphspec(), expected)
        self.test_ray.x = 50
        self.test_ray.y = 51
        self.test_ray.angle = 90
        self.test_ray.length = 100
        expected.update(
            {
                "x": {"units": "data", "value": 50},
                "y": {"units": "data", "value": 51},
                "angle": {"units": "data", "value": 90},
                "length": {"units": "data", "value": 100},
            }
        )
        self.assertEqual(self.test_ray.to_glyphspec(), expected)
Exemplo n.º 8
0
class TestRay(unittest.TestCase):
    def setUp(self):
        from bokeh.glyphs import Ray
        self.test_ray = Ray()

    def test_expected_properties(self):
        expected_properties = set(['x','y','angle','length'])
        actual_properties = get_prop_set(type(self.test_ray))
        self.assertTrue(expected_properties.issubset(actual_properties))

    def test_expected_values(self):
        self.assertEqual(self.test_ray.x,'x')
        self.assertEqual(self.test_ray.y,'y')
        self.assertEqual(self.test_ray.angle,'angle')
        self.assertEqual(self.test_ray.length,'length')
        self.assertEqual(self.test_ray.__view_model__,'ray')

    def test_to_glyphspec(self):
        self.assertEqual(self.test_ray.to_glyphspec(), {'line_color': {'value': 'black'}, 'angle': {'units': 'data', 'field': 'angle'}, 'length': {'units': 'data', 'field': 'length'}, 'y': {'units': 'data', 'field': 'y'}, 'x': {'units': 'data', 'field': 'x'}, 'type': 'ray'})
        self.test_ray.x = 50
        self.test_ray.y = 51
        self.test_ray.angle = 90
        self.test_ray.length = 100
        self.assertEqual(self.test_ray.to_glyphspec(), {'line_color': {'value': 'black'}, 'angle': {'units': 'data', 'value': 90}, 'length': {'units': 'data', 'value': 100}, 'y': {'units': 'data', 'value': 51}, 'x': {'units': 'data', 'value': 50}, 'type': 'ray'})
Exemplo n.º 9
0
 def setUp(self):
     from bokeh.glyphs import Ray
     self.test_ray = Ray()
Exemplo n.º 10
0
 ("quad",
  Quad(left="x", right="xm01", 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",
Exemplo n.º 11
0
 def setUp(self):
     from bokeh.glyphs import Ray
     self.test_ray = Ray()