Esempio n. 1
0
class TestPatches(unittest.TestCase):

    def setUp(self):
        from bokeh.glyphs import Patches
        self.test_patches = Patches()

    def test_expected_properties(self):
        expected_properties = set(['xs', 'ys'])
        actual_properties = get_prop_set(type(self.test_patches))
        self.assertTrue(expected_properties.issubset(actual_properties))

    def test_expected_values(self):
        self.assertEqual(self.test_patches.xs, 'xs')
        self.assertEqual(self.test_patches.ys, 'ys')
        self.assertEqual(self.test_patches.__view_model__, 'patches')

    def test_to_glyphspec(self):
        expected = dict(GENERIC_FILL_DICT)
        expected.update(GENERIC_LINE_DICT)
        expected['type'] = 'patches'
        expected.update({
            'xs':   {'units': 'data', 'field': 'xs'},
            'ys':  {'units': 'data', 'field': 'ys'},
        })
        self.assertEqual(self.test_patches.to_glyphspec(), expected)
        self.test_patches.xs = [50]
        self.test_patches.ys = [51]
        expected.update({
            'xs':   {'units': 'data', 'value': [50]},
            'ys':  {'units': 'data', 'value': [51]},
        })
        self.assertEqual(self.test_patches.to_glyphspec(), expected)
Esempio n. 2
0
class TestPatches(unittest.TestCase):
    def setUp(self):
        from bokeh.glyphs import Patches

        self.test_patches = Patches()

    def test_expected_properties(self):
        expected_properties = set(["xs", "ys"])
        actual_properties = get_prop_set(type(self.test_patches))
        self.assertTrue(expected_properties.issubset(actual_properties))

    def test_expected_values(self):
        self.assertEqual(self.test_patches.xs, "xs")
        self.assertEqual(self.test_patches.ys, "ys")
        self.assertEqual(self.test_patches.__view_model__, "patches")

    def test_to_glyphspec(self):
        expected = dict(GENERIC_FILL_DICT)
        expected.update(GENERIC_LINE_DICT)
        expected["type"] = "patches"
        expected.update({"xs": {"units": "data", "field": "xs"}, "ys": {"units": "data", "field": "ys"}})
        self.assertEqual(self.test_patches.to_glyphspec(), expected)
        self.test_patches.xs = [50]
        self.test_patches.ys = [51]
        expected.update({"xs": {"units": "data", "value": [50]}, "ys": {"units": "data", "value": [51]}})
        self.assertEqual(self.test_patches.to_glyphspec(), expected)
Esempio n. 3
0
def test_Patches():
    glyph = Patches()
    assert glyph.xs == "xs"
    assert glyph.ys == "ys"
    yield check_fill, glyph
    yield check_line, glyph
    yield check_props, glyph, ["xs", "ys"], FILL, LINE
Esempio n. 4
0
class TestPatches(unittest.TestCase):
    def setUp(self):
        from bokeh.glyphs import Patches
        self.test_patches = Patches()

    def test_expected_properties(self):
        expected_properties = set(['xs', 'ys'])
        actual_properties = get_prop_set(type(self.test_patches))
        self.assertTrue(expected_properties.issubset(actual_properties))

    def test_expected_values(self):
        self.assertEqual(self.test_patches.xs, 'xs')
        self.assertEqual(self.test_patches.ys, 'ys')
        self.assertEqual(self.test_patches.__view_model__, 'patches')

    def test_to_glyphspec(self):
        expected = dict(GENERIC_FILL_DICT)
        expected.update(GENERIC_LINE_DICT)
        expected['type'] = 'patches'
        expected.update({
            'xs': {
                'units': 'data',
                'field': 'xs'
            },
            'ys': {
                'units': 'data',
                'field': 'ys'
            },
        })
        self.assertEqual(self.test_patches.to_glyphspec(), expected)
        self.test_patches.xs = [50]
        self.test_patches.ys = [51]
        expected.update({
            'xs': {
                'units': 'data',
                'value': [50]
            },
            'ys': {
                'units': 'data',
                'value': [51]
            },
        })
        self.assertEqual(self.test_patches.to_glyphspec(), expected)
Esempio n. 5
0
class TestPatches(unittest.TestCase):
    def setUp(self):
        from bokeh.glyphs import Patches
        self.test_patches = Patches()

    def test_expected_properties(self):
        expected_properties = set(['xs','ys'])
        actual_properties = get_prop_set(type(self.test_patches))
        self.assertTrue(expected_properties.issubset(actual_properties))

    def test_expected_values(self):
        self.assertEqual(self.test_patches.xs,'xs')
        self.assertEqual(self.test_patches.ys,'ys')
        self.assertEqual(self.test_patches.__view_model__,'patches')

    def test_to_glyphspec(self):
        self.assertEqual(self.test_patches.to_glyphspec(), {'line_color': {'value': 'black'}, 'xs': {'units': 'data', 'field': 'xs'}, 'ys': {'units': 'data', 'field': 'ys'}, 'type': 'patches', 'fill_color': {'value': 'gray'}})
        self.test_patches.xs = 50
        self.test_patches.ys = 51
        self.assertEqual(self.test_patches.to_glyphspec(), {'line_color': {'value': 'black'}, 'xs': {'units': 'data', 'value': 50}, 'ys': {'units': 'data', 'value': 51}, 'type': 'patches', 'fill_color': {'value': 'gray'}})
Esempio n. 6
0
def altitude_profile(data):
    plot = Plot(title="%s - Altitude Profile" % title,
                plot_width=800,
                plot_height=400)

    xaxis = LinearAxis(axis_label="Distance (km)")
    plot.add_layout(xaxis, 'below')

    yaxis = LinearAxis(axis_label="Altitude (m)")
    plot.add_layout(yaxis, 'left')

    xgrid = Grid(plot=plot, dimension=0, ticker=xaxis.ticker)
    ygrid = Grid(plot=plot, dimension=1, ticker=yaxis.ticker)
    plot.renderers.extend([xgrid, ygrid])

    plot.add_tools(PanTool(), WheelZoomTool(), ResetTool(), BoxSelectTool())

    X, Y = data.dist, data.alt
    y0 = min(Y)

    patches_source = ColumnDataSource(
        dict(xs=[[X[i], X[i + 1], X[i + 1], X[i]] for i in range(len(X[:-1]))],
             ys=[[y0, y0, Y[i + 1], Y[i]] for i in range(len(Y[:-1]))],
             color=data.colors[:-1]))

    patches = Patches(xs="xs", ys="ys", fill_color="color", line_color="color")
    plot.add_glyph(patches_source, patches)

    line_source = ColumnDataSource(dict(
        x=data.dist,
        y=data.alt,
    ))

    line = Line(x='x', y='y', line_color="black", line_width=1)
    plot.add_glyph(line_source, line)

    plot.x_range = DataRange1d(sources=[line_source.columns("x")])
    plot.y_range = DataRange1d(sources=[line_source.columns("y")])

    return plot
Esempio n. 7
0
xdr = DataRange1d(sources=[state_source.columns("state_xs")])
ydr = DataRange1d(sources=[state_source.columns("state_ys")])

plot = Plot(x_range=xdr,
            y_range=ydr,
            min_border=0,
            border_fill="white",
            title="2009 Unemployment Data",
            plot_width=1300,
            plot_height=800,
            toolbar_location="left")

county_patches = Patches(xs="county_xs",
                         ys="county_ys",
                         fill_color="county_colors",
                         fill_alpha=0.7,
                         line_color="white",
                         line_width=0.5)
plot.add_glyph(county_source, county_patches)

state_patches = Patches(xs="state_xs",
                        ys="state_ys",
                        fill_alpha=0.0,
                        line_color="#884444",
                        line_width=2)
plot.add_glyph(state_source, state_patches)

plot.add_tools(ResizeTool())

doc = Document()
doc.add(plot)
Esempio n. 8
0
 def setUp(self):
     from bokeh.glyphs import Patches
     self.test_patches = Patches()
Esempio n. 9
0
         cx1="xm01",
         cy1="ym01",
         line_color="#D95F02",
         line_width=2)),
 ("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="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",
Esempio n. 10
0
 def setUp(self):
     from bokeh.glyphs import Patches
     self.test_patches = Patches()