示例#1
0
class TestArc(unittest.TestCase):
    def setUp(self):
        from bokeh.glyphs import Arc
        self.test_arc = Arc()

    def test_expected_properties(self):
        expected_properties = set(['x','y','radius','start_angle','end_angle','direction'])
        actual_properties = get_prop_set(type(self.test_arc))
        self.assertTrue(expected_properties.issubset(actual_properties))

    def test_expected_values(self):
        self.assertEqual(self.test_arc.__view_model__,'arc')
        self.assertEqual(self.test_arc.x,'x')
        self.assertEqual(self.test_arc.y,'y')
        self.assertEqual(self.test_arc.radius,None)
        self.assertEqual(self.test_arc.start_angle,'start_angle')
        self.assertEqual(self.test_arc.end_angle,'end_angle')
        self.assertEqual(self.test_arc.direction,'clock')
        self.test_arc.direction = 'anticlock'

    def test_to_glyphspec(self):
        self.assertEqual(self.test_arc.to_glyphspec(), {'line_color': {'value': 'black'}, 'start_angle': {'units': 'data', 'field': 'start_angle'}, 'end_angle': {'units': 'data', 'field': 'end_angle'}, 'radius': {'units': 'data', 'field': None}, 'y': {'units': 'data', 'field': 'y'}, 'x': {'units': 'data', 'field': 'x'}, 'type': 'arc'})
        self.test_arc.x = 50
        self.test_arc.y = 100
        self.test_arc.radius = 51
        self.test_arc.start_angle = 52
        self.test_arc.end_angle = 53
        self.test_arc.direction = 'anticlock'
        self.assertEqual(self.test_arc.to_glyphspec(), {'line_color': {'value': 'black'}, 'direction': 'anticlock', 'start_angle': {'units': 'data', 'value': 52}, 'end_angle': {'units': 'data', 'value': 53}, 'radius': {'units': 'data', 'value': 51}, 'y': {'units': 'data', 'value': 100}, 'x': {'units': 'data', 'value': 50}, 'type': 'arc'})
示例#2
0
class TestArc(unittest.TestCase):
    def setUp(self):
        from bokeh.glyphs import Arc

        self.test_arc = Arc()

    def test_expected_properties(self):
        expected_properties = set(["x", "y", "radius", "start_angle", "end_angle", "direction"])
        actual_properties = get_prop_set(type(self.test_arc))
        self.assertTrue(expected_properties.issubset(actual_properties))

    def test_expected_values(self):
        self.assertEqual(self.test_arc.__view_model__, "arc")
        self.assertEqual(self.test_arc.x, "x")
        self.assertEqual(self.test_arc.y, "y")
        self.assertEqual(self.test_arc.radius, None)
        self.assertEqual(self.test_arc.start_angle, "start_angle")
        self.assertEqual(self.test_arc.end_angle, "end_angle")
        self.assertEqual(self.test_arc.direction, "clock")
        self.test_arc.direction = "anticlock"

    def test_to_glyphspec(self):
        expected = dict(GENERIC_GLYPH_DICT)
        del expected["fill_color"]  # only has line props
        del expected["fill_alpha"]  # only has line pros:ps
        expected["type"] = "arc"
        expected.update(
            {
                "radius": {"units": "data", "field": None},
                "start_angle": {"units": "data", "field": "start_angle"},
                "end_angle": {"units": "data", "field": "end_angle"},
            }
        )
        self.assertEqual(self.test_arc.to_glyphspec(), expected)
        self.test_arc.x = 50
        self.test_arc.y = 100
        self.test_arc.radius = 51
        self.test_arc.start_angle = 52
        self.test_arc.end_angle = 53
        self.test_arc.direction = "anticlock"
        expected.update(
            {
                "x": {"units": "data", "value": 50},
                "y": {"units": "data", "value": 100},
                "radius": {"units": "data", "value": 51},
                "start_angle": {"units": "data", "value": 52},
                "end_angle": {"units": "data", "value": 53},
                "direction": "anticlock",
            }
        )
        self.assertEqual(self.test_arc.to_glyphspec(), expected)
示例#3
0
class TestArc(unittest.TestCase):

    def setUp(self):
        from bokeh.glyphs import Arc
        self.test_arc = Arc()

    def test_expected_properties(self):
        expected_properties = set(['x', 'y', 'radius', 'start_angle', 'end_angle', 'direction'])
        actual_properties = get_prop_set(type(self.test_arc))
        self.assertTrue(expected_properties.issubset(actual_properties))

    def test_expected_values(self):
        self.assertEqual(self.test_arc.__view_model__, 'arc')
        self.assertEqual(self.test_arc.x, 'x')
        self.assertEqual(self.test_arc.y, 'y')
        self.assertEqual(self.test_arc.radius, None)
        self.assertEqual(self.test_arc.start_angle, 'start_angle')
        self.assertEqual(self.test_arc.end_angle, 'end_angle')
        self.assertEqual(self.test_arc.direction, 'clock')
        self.test_arc.direction = 'anticlock'

    def test_to_glyphspec(self):
        expected = dict(GENERIC_GLYPH_DICT)
        del expected['fill_color']  # only has line props
        del expected['fill_alpha']  # only has line pros:ps
        expected['type'] = 'arc'
        expected.update({
            'radius': {'units': 'data', 'field': None},
            'start_angle':  {'units': 'data', 'field': 'start_angle'},
            'end_angle':    {'units': 'data', 'field': 'end_angle'},
        })
        self.assertEqual(self.test_arc.to_glyphspec(), expected)
        self.test_arc.x = 50
        self.test_arc.y = 100
        self.test_arc.radius = 51
        self.test_arc.start_angle = 52
        self.test_arc.end_angle = 53
        self.test_arc.direction = 'anticlock'
        expected.update({
            'x':            {'units': 'data', 'value': 50},
            'y':            {'units': 'data', 'value': 100},
            'radius': {'units': 'data', 'value': 51},
            'start_angle':  {'units': 'data', 'value': 52},
            'end_angle':    {'units': 'data', 'value': 53},
            'direction':    'anticlock',
        })
        self.assertEqual(self.test_arc.to_glyphspec(), expected)
示例#4
0
文件: gauges.py 项目: tarzzz/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)
    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)
示例#5
0
def test_Arc():
    glyph = Arc()
    assert glyph.x == "x"
    assert glyph.y == "y"
    assert glyph.radius == None
    assert glyph.start_angle == "start_angle"
    assert glyph.end_angle == "end_angle"
    assert glyph.direction == "clock"
    yield check_line, glyph
    yield check_props, glyph, [
        "x", "y", "radius", "start_angle", "end_angle", "direction"
    ], LINE
示例#6
0
 def setUp(self):
     from bokeh.glyphs import Arc
     self.test_arc = Arc()
示例#7
0
               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)),
 ("line", Line(x="x", y="y", line_color="#F46D43")),
示例#8
0
 def setUp(self):
     from bokeh.glyphs import Arc
     self.test_arc = Arc()
示例#9
0
class TestArc(unittest.TestCase):
    def setUp(self):
        from bokeh.glyphs import Arc
        self.test_arc = Arc()

    def test_expected_properties(self):
        expected_properties = set(
            ['x', 'y', 'radius', 'start_angle', 'end_angle', 'direction'])
        actual_properties = get_prop_set(type(self.test_arc))
        self.assertTrue(expected_properties.issubset(actual_properties))

    def test_expected_values(self):
        self.assertEqual(self.test_arc.__view_model__, 'arc')
        self.assertEqual(self.test_arc.x, 'x')
        self.assertEqual(self.test_arc.y, 'y')
        self.assertEqual(self.test_arc.radius, None)
        self.assertEqual(self.test_arc.start_angle, 'start_angle')
        self.assertEqual(self.test_arc.end_angle, 'end_angle')
        self.assertEqual(self.test_arc.direction, 'clock')
        self.test_arc.direction = 'anticlock'

    def test_to_glyphspec(self):
        expected = dict(GENERIC_GLYPH_DICT)
        del expected['fill_color']  # only has line props
        del expected['fill_alpha']  # only has line pros:ps
        expected['type'] = 'arc'
        expected.update({
            'radius': {
                'units': 'data',
                'field': None
            },
            'start_angle': {
                'units': 'data',
                'field': 'start_angle'
            },
            'end_angle': {
                'units': 'data',
                'field': 'end_angle'
            },
        })
        self.assertEqual(self.test_arc.to_glyphspec(), expected)
        self.test_arc.x = 50
        self.test_arc.y = 100
        self.test_arc.radius = 51
        self.test_arc.start_angle = 52
        self.test_arc.end_angle = 53
        self.test_arc.direction = 'anticlock'
        expected.update({
            'x': {
                'units': 'data',
                'value': 50
            },
            'y': {
                'units': 'data',
                'value': 100
            },
            'radius': {
                'units': 'data',
                'value': 51
            },
            'start_angle': {
                'units': 'data',
                'value': 52
            },
            'end_angle': {
                'units': 'data',
                'value': 53
            },
            'direction': 'anticlock',
        })
        self.assertEqual(self.test_arc.to_glyphspec(), expected)