示例#1
0
class TestImageURL(unittest.TestCase):

    def setUp(self):
        from bokeh.glyphs import ImageURL
        self.test_image_url = ImageURL()

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

    def test_expected_values(self):
        self.assertEqual(self.test_image_url.__view_model__, 'image_url')
        self.assertEqual(self.test_image_url.url, 'url')
        self.assertEqual(self.test_image_url.x, 'x')
        self.assertEqual(self.test_image_url.y, 'y')
        self.assertEqual(self.test_image_url.angle, 'angle')

    def test_to_glyphspec(self):
        self.assertEqual(self.test_image_url.to_glyphspec(), {'url': {'units': 'data', 'field': 'url'}, 'y': {'units': 'data', 'field': 'y'}, 'x': {'units': 'data', 'field': 'x'}, 'angle': {'units': 'data', 'field': 'angle'}, 'type': 'image_url'})
        self.test_image_url.url = ['foo']
        self.test_image_url.x = 50
        self.test_image_url.y = 51
        self.test_image_url.angle = 90
        self.assertEqual(self.test_image_url.to_glyphspec(), {'url': {'units': 'data', 'value': ['foo']}, 'y': {'units': 'data', 'value': 51}, 'x': {'units': 'data', 'value': 50}, 'angle': {'units': 'data', 'value': 90}, 'type': 'image_url'})
示例#2
0
class TestImageURL(unittest.TestCase):
    def setUp(self):
        from bokeh.glyphs import ImageURL

        self.test_image_url = ImageURL()

    def test_expected_properties(self):
        expected_properties = set(["url", "x", "y", "w", "h", "angle"])
        actual_properties = get_prop_set(type(self.test_image_url))
        self.assertTrue(expected_properties.issubset(actual_properties))

    def test_expected_values(self):
        self.assertEqual(self.test_image_url.__view_model__, "image_url")
        self.assertEqual(self.test_image_url.url, "url")
        self.assertEqual(self.test_image_url.x, "x")
        self.assertEqual(self.test_image_url.y, "y")
        self.assertEqual(self.test_image_url.w, "w")
        self.assertEqual(self.test_image_url.h, "h")
        self.assertEqual(self.test_image_url.angle, "angle")

    def test_to_glyphspec(self):
        self.assertEqual(
            self.test_image_url.to_glyphspec(),
            {
                "url": {"units": "data", "field": "url"},
                "x": {"units": "data", "field": "x"},
                "y": {"units": "data", "field": "y"},
                "w": {"units": "data", "field": "w"},
                "h": {"units": "data", "field": "h"},
                "angle": {"units": "data", "field": "angle"},
                "type": "image_url",
            },
        )

        self.test_image_url.url = ["foo"]
        self.test_image_url.x = 50
        self.test_image_url.y = 51
        self.test_image_url.w = 60
        self.test_image_url.h = 61
        self.test_image_url.angle = 90

        self.assertEqual(
            self.test_image_url.to_glyphspec(),
            {
                "url": {"units": "data", "value": ["foo"]},
                "x": {"units": "data", "value": 50},
                "y": {"units": "data", "value": 51},
                "w": {"units": "data", "value": 60},
                "h": {"units": "data", "value": 61},
                "angle": {"units": "data", "value": 90},
                "type": "image_url",
            },
        )
示例#3
0
def test_ImageURL():
    glyph = ImageURL()
    assert glyph.url == "url"
    assert glyph.x == "x"
    assert glyph.y == "y"
    assert glyph.w == "w"
    assert glyph.h == "h"
    assert glyph.angle == "angle"
    assert glyph.dilate == False
    assert glyph.anchor == Anchor.top_left
    yield check_props, glyph, [
        "url", "x", "y", "w", "h", "angle", "dilate", "anchor"
    ]
示例#4
0
 def setUp(self):
     from bokeh.glyphs import ImageURL
     self.test_image_url = ImageURL()
示例#5
0
        y1=np.linspace(0, 150, N),
        w1=np.linspace(10, 50, N),
        h1=np.linspace(10, 50, N),
        x2=np.linspace(-50, 150, N),
        y2=np.linspace(0, 200, N),
    ))

xdr = Range1d(start=-100, end=200)
ydr = Range1d(start=-100, end=200)

plot = Plot(title="ImageURL", x_range=xdr, y_range=ydr)

image1 = ImageURL(url="url",
                  x="x1",
                  y="y1",
                  w="w1",
                  h="h1",
                  angle=0.0,
                  anchor="center")
plot.add_glyph(source, image1)

image2 = ImageURL(url="url",
                  x="x2",
                  y="y2",
                  w=20,
                  h=20,
                  angle=0.0,
                  anchor="top_left")
plot.add_glyph(source, image2)

image3 = ImageURL(url=dict(value=url),
示例#6
0
                 text="text",
                 angle="angle",
                 text_align="center",
                 text_baseline="middle")
    plot.add_glyph(text_source, glyph)


def to_base64(png):
    return "data:image/png;base64," + base64.b64encode(png).decode("utf-8")


urls = [to_base64(icons.get(browser, b"")) for browser in browsers]
x, y = polar_to_cartesian(1.7, start_angles, end_angles)

icons_source = ColumnDataSource(dict(urls=urls, x=x, y=y))
glyph = ImageURL(url="urls", x="x", y="y", angle=0.0, anchor="center")
plot.add_glyph(icons_source, glyph)

text = ["%.02f%%" % value for value in selected.Share]
x, y = polar_to_cartesian(0.7, start_angles, end_angles)

text_source = ColumnDataSource(dict(text=text, x=x, y=y))
glyph = Text(x="x",
             y="y",
             text="text",
             angle=0,
             text_align="center",
             text_baseline="middle")
plot.add_glyph(text_source, glyph)

doc = Document()