def test_polygon_roundtrip(self): xs = [1, 2, 3] ys = [2, 0, 7] poly = Polygons([{ 'x': xs, 'y': ys, 'z': 0 }, { 'x': xs[::-1], 'y': ys[::-1], 'z': 1 }], ['x', 'y'], 'z', datatype=[self.datatype]) self.assertIsInstance(poly.data.geometry.dtype, PolygonDtype) roundtrip = poly.clone(datatype=['multitabular']) self.assertEqual(roundtrip.interface.datatype, 'multitabular') expected = Polygons([{ 'x': xs + [1], 'y': ys + [2], 'z': 0 }, { 'x': [3] + xs, 'y': [7] + ys, 'z': 1 }], ['x', 'y'], 'z', datatype=['multitabular']) self.assertEqual(roundtrip, expected)
def test_multi_polygon_roundtrip(self): xs = [1, 2, 3, np.nan, 6, 7, 3] ys = [2, 0, 7, np.nan, 7, 5, 2] holes = [[[(1.5, 2), (2, 3), (1.6, 1.6)], [(2.1, 4.5), (2.5, 5), (2.3, 3.5)]], []] poly = Polygons([{ 'x': xs, 'y': ys, 'holes': holes, 'z': 1 }, { 'x': xs[::-1], 'y': ys[::-1], 'z': 2 }], ['x', 'y'], 'z', datatype=[self.datatype]) self.assertIsInstance(poly.data.geometry.dtype, MultiPolygonDtype) roundtrip = poly.clone(datatype=['multitabular']) self.assertEqual(roundtrip.interface.datatype, 'multitabular') expected = Polygons([{ 'x': [1, 2, 3, 1, np.nan, 6, 3, 7, 6], 'y': [2, 0, 7, 2, np.nan, 7, 2, 5, 7], 'holes': holes, 'z': 1 }, { 'x': [3, 7, 6, 3, np.nan, 3, 1, 2, 3], 'y': [2, 5, 7, 2, np.nan, 7, 2, 0, 7], 'z': 2 }], ['x', 'y'], 'z', datatype=['multitabular']) self.assertEqual(roundtrip, expected)
def test_data_link_poly_table_on_unlinked_clone(self): arr1 = np.random.rand(10, 2) arr2 = np.random.rand(10, 2) polys = Polygons([arr1, arr2]) table = Table([('A', 1), ('B', 2)], 'A', 'B') DataLink(polys, table) layout = polys.clone() + table.clone(link=False) plot = bokeh_renderer.get_plot(layout) cds = list(plot.state.select({'type': ColumnDataSource})) self.assertEqual(len(cds), 2)
def test_data_link_poly_table_on_unlinked_clone(self): arr1 = np.random.rand(10, 2) arr2 = np.random.rand(10, 2) polys = Polygons([arr1, arr2]) table = Table([('A', 1), ('B', 2)], 'A', 'B') DataLink(polys, table) layout = polys.clone() + table.clone(link=False) plot = bokeh_renderer.get_plot(layout) cds = list(plot.state.select({'type': ColumnDataSource})) self.assertEqual(len(cds), 2)