class TestMplChordPlot(TestMPLPlot): def setUp(self): super(TestMplChordPlot, self).setUp() self.edges = [(0, 1, 1), (0, 2, 2), (1, 2, 3)] self.nodes = Dataset([(0, 'A'), (1, 'B'), (2, 'C')], 'index', 'Label') self.chord = Chord((self.edges, self.nodes)) def test_chord_nodes_label_text(self): g = self.chord.opts(plot=dict(label_index='Label')) plot = mpl_renderer.get_plot(g) labels = plot.handles['labels'] self.assertEqual([l.get_text() for l in labels], ['A', 'B', 'C']) def test_chord_nodes_categorically_colormapped(self): g = self.chord.opts(plot=dict(color_index='Label'), style=dict(cmap=['#FFFFFF', '#CCCCCC', '#000000'])) plot = mpl_renderer.get_plot(g) arcs = plot.handles['arcs'] nodes = plot.handles['nodes'] colors = np.array([[ 1., 1., 1., 1. ], [ 0.8, 0.8, 0.8, 1. ], [ 0., 0., 0., 1. ]]) self.assertEqual(arcs.get_colors(), colors) self.assertEqual(nodes.get_facecolors(), colors) def test_chord_edges_categorically_colormapped(self): g = self.chord.opts(plot=dict(edge_color_index='start'), style=dict(edge_cmap=['#FFFFFF', '#000000'])) plot = mpl_renderer.get_plot(g) edges = plot.handles['edges'] colors = np.array([[ 1., 1., 1., 1. ], [ 1., 1., 1., 1. ], [ 0., 0., 0., 1. ]]) self.assertEqual(edges.get_edgecolors(), colors)
class TestBokehChordPlot(TestBokehPlot): def setUp(self): super(TestBokehChordPlot, self).setUp() self.edges = [(0, 1, 1), (0, 2, 2), (1, 2, 3)] self.nodes = Dataset([(0, 'A'), (1, 'B'), (2, 'C')], 'index', 'Label') self.chord = Chord((self.edges, self.nodes)) def test_chord_nodes_label_text(self): g = self.chord.opts(plot=dict(label_index='Label')) plot = bokeh_renderer.get_plot(g) source = plot.handles['text_1_source'] self.assertEqual(source.data['text'], ['A', 'B', 'C']) def test_chord_nodes_categorically_colormapped(self): g = self.chord.opts(plot=dict(color_index='Label', label_index='Label'), style=dict(cmap=['#FFFFFF', '#888888', '#000000'])) plot = bokeh_renderer.get_plot(g) cmapper = plot.handles['color_mapper'] source = plot.handles['scatter_1_source'] arc_source = plot.handles['multi_line_2_source'] glyph = plot.handles['scatter_1_glyph'] self.assertIsInstance(cmapper, CategoricalColorMapper) self.assertEqual(cmapper.factors, ['A', 'B', 'C']) self.assertEqual(cmapper.palette, ['#FFFFFF', '#888888', '#000000']) self.assertEqual(source.data['Label'], np.array(['A', 'B', 'C'])) self.assertEqual(arc_source.data['Label'], np.array(['A', 'B', 'C'])) self.assertEqual(glyph.fill_color, { 'field': 'Label', 'transform': cmapper }) def test_chord_edges_categorically_colormapped(self): g = self.chord.opts(plot=dict(edge_color_index='start'), style=dict(edge_cmap=['#FFFFFF', '#000000'])) plot = bokeh_renderer.get_plot(g) cmapper = plot.handles['edge_colormapper'] edge_source = plot.handles['multi_line_1_source'] glyph = plot.handles['multi_line_1_glyph'] self.assertIsInstance(cmapper, CategoricalColorMapper) self.assertEqual(cmapper.palette, ['#FFFFFF', '#000000', '#FFFFFF']) self.assertEqual(cmapper.factors, ['0', '1', '2']) self.assertEqual(edge_source.data['start_str'], ['0', '0', '1']) self.assertEqual(glyph.line_color, { 'field': 'start_str', 'transform': cmapper })
def setUp(self): super(TestBokehChordPlot, self).setUp() self.edges = [(0, 1, 1), (0, 2, 2), (1, 2, 3)] self.nodes = Dataset([(0, 'A'), (1, 'B'), (2, 'C')], 'index', 'Label') self.chord = Chord((self.edges, self.nodes))
class TestBokehChordPlot(TestBokehPlot): def setUp(self): super(TestBokehChordPlot, self).setUp() self.edges = [(0, 1, 1), (0, 2, 2), (1, 2, 3)] self.nodes = Dataset([(0, 'A'), (1, 'B'), (2, 'C')], 'index', 'Label') self.chord = Chord((self.edges, self.nodes)) def test_chord_draw_order(self): plot = bokeh_renderer.get_plot(self.chord) renderers = plot.state.renderers graph_renderer = plot.handles['glyph_renderer'] arc_renderer = plot.handles['multi_line_2_glyph_renderer'] self.assertTrue(renderers.index(arc_renderer)<renderers.index(graph_renderer)) def test_chord_label_draw_order(self): g = self.chord.options(labels='Label') plot = bokeh_renderer.get_plot(g) renderers = plot.state.renderers graph_renderer = plot.handles['glyph_renderer'] label_renderer = plot.handles['text_1_glyph_renderer'] self.assertTrue(renderers.index(graph_renderer)<renderers.index(label_renderer)) def test_chord_nodes_label_text(self): g = self.chord.opts(plot=dict(label_index='Label')) plot = bokeh_renderer.get_plot(g) source = plot.handles['text_1_source'] self.assertEqual(source.data['text'], ['A', 'B', 'C']) def test_chord_nodes_labels_mapping(self): g = self.chord.opts(plot=dict(labels='Label')) plot = bokeh_renderer.get_plot(g) source = plot.handles['text_1_source'] self.assertEqual(source.data['text'], ['A', 'B', 'C']) def test_chord_nodes_categorically_colormapped(self): g = self.chord.opts(plot=dict(color_index='Label', label_index='Label'), style=dict(cmap=['#FFFFFF', '#888888', '#000000'])) plot = bokeh_renderer.get_plot(g) cmapper = plot.handles['color_mapper'] source = plot.handles['scatter_1_source'] arc_source = plot.handles['multi_line_2_source'] glyph = plot.handles['scatter_1_glyph'] self.assertIsInstance(cmapper, CategoricalColorMapper) self.assertEqual(cmapper.factors, ['A', 'B', 'C']) self.assertEqual(cmapper.palette, ['#FFFFFF', '#888888', '#000000']) self.assertEqual(source.data['Label'], np.array(['A', 'B', 'C'])) self.assertEqual(arc_source.data['Label'], np.array(['A', 'B', 'C'])) self.assertEqual(glyph.fill_color, {'field': 'Label', 'transform': cmapper}) def test_chord_nodes_style_map_node_color_colormapped(self): g = self.chord.opts(plot=dict(labels='Label'), style=dict(node_color='Label', cmap=['#FFFFFF', '#888888', '#000000'])) plot = bokeh_renderer.get_plot(g) cmapper = plot.handles['node_color_color_mapper'] source = plot.handles['scatter_1_source'] arc_source = plot.handles['multi_line_2_source'] glyph = plot.handles['scatter_1_glyph'] arc_glyph = plot.handles['multi_line_2_glyph'] self.assertIsInstance(cmapper, CategoricalColorMapper) self.assertEqual(cmapper.factors, ['A', 'B', 'C']) self.assertEqual(cmapper.palette, ['#FFFFFF', '#888888', '#000000']) self.assertEqual(source.data['Label'], np.array(['A', 'B', 'C'])) self.assertEqual(arc_source.data['Label'], np.array(['A', 'B', 'C'])) self.assertEqual(glyph.fill_color, {'field': 'node_color', 'transform': cmapper}) self.assertEqual(arc_glyph.line_color, {'field': 'node_color', 'transform': cmapper}) def test_chord_edges_categorically_colormapped(self): g = self.chord.opts(plot=dict(edge_color_index='start'), style=dict(edge_cmap=['#FFFFFF', '#000000'])) plot = bokeh_renderer.get_plot(g) cmapper = plot.handles['edge_colormapper'] edge_source = plot.handles['multi_line_1_source'] glyph = plot.handles['multi_line_1_glyph'] self.assertIsInstance(cmapper, CategoricalColorMapper) self.assertEqual(cmapper.palette, ['#FFFFFF', '#000000', '#FFFFFF']) self.assertEqual(cmapper.factors, ['0', '1', '2']) self.assertEqual(edge_source.data['start_str__'], ['0', '0', '1']) self.assertEqual(glyph.line_color, {'field': 'start_str__', 'transform': cmapper}) def test_chord_edge_color_style_mapping(self): g = self.chord.opts(style=dict(edge_color=dim('start').astype(str), edge_cmap=['#FFFFFF', '#000000'])) plot = bokeh_renderer.get_plot(g) cmapper = plot.handles['edge_color_color_mapper'] edge_source = plot.handles['multi_line_1_source'] glyph = plot.handles['multi_line_1_glyph'] self.assertIsInstance(cmapper, CategoricalColorMapper) self.assertEqual(cmapper.palette, ['#FFFFFF', '#000000', '#FFFFFF']) self.assertEqual(cmapper.factors, ['0', '1', '2']) self.assertEqual(edge_source.data['edge_color'], np.array(['0', '0', '1'])) self.assertEqual(glyph.line_color, {'field': 'edge_color', 'transform': cmapper})
def make_chord(self, i): edges = [(0, 1, 1+i), (0, 2, 2+i), (1, 2, 3+i)] nodes = Dataset([(0, 0+i), (1, 1+i), (2, 2+i)], 'index', 'Label') return Chord((edges, nodes), vdims='weight')
class TestMplChordPlot(TestMPLPlot): def setUp(self): super(TestMplChordPlot, self).setUp() self.edges = [(0, 1, 1), (0, 2, 2), (1, 2, 3)] self.nodes = Dataset([(0, 'A'), (1, 'B'), (2, 'C')], 'index', 'Label') self.chord = Chord((self.edges, self.nodes)) def make_chord(self, i): edges = [(0, 1, 1+i), (0, 2, 2+i), (1, 2, 3+i)] nodes = Dataset([(0, 0+i), (1, 1+i), (2, 2+i)], 'index', 'Label') return Chord((edges, nodes), vdims='weight') def test_chord_nodes_label_text(self): g = self.chord.opts(plot=dict(label_index='Label')) plot = mpl_renderer.get_plot(g) labels = plot.handles['labels'] self.assertEqual([l.get_text() for l in labels], ['A', 'B', 'C']) def test_chord_nodes_labels_mapping(self): g = self.chord.opts(plot=dict(labels='Label')) plot = mpl_renderer.get_plot(g) labels = plot.handles['labels'] self.assertEqual([l.get_text() for l in labels], ['A', 'B', 'C']) def test_chord_nodes_categorically_colormapped(self): g = self.chord.opts(plot=dict(color_index='Label'), style=dict(cmap=['#FFFFFF', '#CCCCCC', '#000000'])) plot = mpl_renderer.get_plot(g) arcs = plot.handles['arcs'] nodes = plot.handles['nodes'] colors = np.array([[ 1., 1., 1., 1. ], [ 0.8, 0.8, 0.8, 1. ], [ 0., 0., 0., 1. ]]) self.assertEqual(arcs.get_colors(), colors) self.assertEqual(nodes.get_facecolors(), colors) def test_chord_node_color_style_mapping(self): g = self.chord.opts(style=dict(node_color='Label', cmap=['#FFFFFF', '#CCCCCC', '#000000'])) plot = mpl_renderer.get_plot(g) arcs = plot.handles['arcs'] nodes = plot.handles['nodes'] self.assertEqual(np.asarray(nodes.get_array()), np.array([0, 1, 2])) self.assertEqual(arcs.get_array(), np.array([0, 1, 2])) self.assertEqual(nodes.get_clim(), (0, 2)) self.assertEqual(arcs.get_clim(), (0, 2)) def test_chord_edges_categorically_colormapped(self): g = self.chord.opts(plot=dict(edge_color_index='start'), style=dict(edge_cmap=['#FFFFFF', '#000000'])) plot = mpl_renderer.get_plot(g) edges = plot.handles['edges'] colors = np.array([[ 1., 1., 1., 1. ], [ 1., 1., 1., 1. ], [ 0., 0., 0., 1. ]]) self.assertEqual(edges.get_edgecolors(), colors) def test_chord_edge_color_style_mapping(self): g = self.chord.opts(style=dict(edge_color=dim('start').astype(str), edge_cmap=['#FFFFFF', '#000000'])) plot = mpl_renderer.get_plot(g) edges = plot.handles['edges'] self.assertEqual(edges.get_array(), np.array([0, 0, 1])) self.assertEqual(edges.get_clim(), (0, 2)) def test_chord_edge_color_linear_style_mapping_update(self): hmap = HoloMap({0: self.make_chord(0), 1: self.make_chord(1)}).options(edge_color='weight', framewise=True) plot = mpl_renderer.get_plot(hmap) edges = plot.handles['edges'] self.assertEqual(edges.get_array(), np.array([1, 2, 3])) self.assertEqual(edges.get_clim(), (1, 3)) plot.update((1,)) self.assertEqual(edges.get_array(), np.array([2, 3, 4])) self.assertEqual(edges.get_clim(), (2, 4)) def test_chord_node_color_linear_style_mapping_update(self): hmap = HoloMap({0: self.make_chord(0), 1: self.make_chord(1)}).options(node_color='Label', framewise=True) plot = mpl_renderer.get_plot(hmap) arcs = plot.handles['arcs'] nodes = plot.handles['nodes'] self.assertEqual(nodes.get_array(), np.array([0, 1, 2])) self.assertEqual(arcs.get_array(), np.array([0, 1, 2])) self.assertEqual(nodes.get_clim(), (0, 2)) self.assertEqual(arcs.get_clim(), (0, 2)) plot.update((1,)) self.assertEqual(nodes.get_array(), np.array([1, 2, 3])) self.assertEqual(arcs.get_array(), np.array([1, 2, 3])) self.assertEqual(nodes.get_clim(), (1, 3)) self.assertEqual(arcs.get_clim(), (1, 3)) def test_chord_edge_color_style_mapping_update(self): hmap = HoloMap({0: self.make_chord(0), 1: self.make_chord(1)}).options( edge_color=dim('weight').categorize({1: 'red', 2: 'green', 3: 'blue', 4: 'black'}) ) plot = mpl_renderer.get_plot(hmap) edges = plot.handles['edges'] self.assertEqual(edges.get_edgecolors(), np.array([ [1, 0, 0, 1], [0, 0.501961, 0, 1], [0, 0, 1, 1] ])) plot.update((1,)) self.assertEqual(edges.get_edgecolors(), np.array([ [0, 0.501961, 0, 1], [0, 0, 1, 1], [0, 0, 0, 1] ])) def test_chord_node_color_style_mapping_update(self): hmap = HoloMap({0: self.make_chord(0), 1: self.make_chord(1)}).options( node_color=dim('Label').categorize({0: 'red', 1: 'green', 2: 'blue', 3: 'black'}) ) plot = mpl_renderer.get_plot(hmap) arcs = plot.handles['arcs'] nodes = plot.handles['nodes'] colors = np.array([ [1, 0, 0, 1], [0, 0.501961, 0, 1], [0, 0, 1, 1] ]) self.assertEqual(arcs.get_edgecolors(), colors) self.assertEqual(nodes.get_facecolors(), colors) plot.update((1,)) colors = np.array([ [0, 0.501961, 0, 1], [0, 0, 1, 1], [0, 0, 0, 1] ]) self.assertEqual(arcs.get_edgecolors(), colors) self.assertEqual(nodes.get_facecolors(), colors)
class TestMplChordPlot(TestMPLPlot): def setUp(self): super(TestMplChordPlot, self).setUp() self.edges = [(0, 1, 1), (0, 2, 2), (1, 2, 3)] self.nodes = Dataset([(0, 'A'), (1, 'B'), (2, 'C')], 'index', 'Label') self.chord = Chord((self.edges, self.nodes)) def make_chord(self, i): edges = [(0, 1, 1+i), (0, 2, 2+i), (1, 2, 3+i)] nodes = Dataset([(0, 0+i), (1, 1+i), (2, 2+i)], 'index', 'Label') return Chord((edges, nodes), vdims='weight') def test_chord_nodes_label_text(self): g = self.chord.opts(plot=dict(label_index='Label')) plot = mpl_renderer.get_plot(g) labels = plot.handles['labels'] self.assertEqual([l.get_text() for l in labels], ['A', 'B', 'C']) def test_chord_nodes_labels_mapping(self): g = self.chord.opts(plot=dict(labels='Label')) plot = mpl_renderer.get_plot(g) labels = plot.handles['labels'] self.assertEqual([l.get_text() for l in labels], ['A', 'B', 'C']) def test_chord_nodes_categorically_colormapped(self): g = self.chord.opts(plot=dict(color_index='Label'), style=dict(cmap=['#FFFFFF', '#CCCCCC', '#000000'])) plot = mpl_renderer.get_plot(g) arcs = plot.handles['arcs'] nodes = plot.handles['nodes'] colors = np.array([[ 1., 1., 1., 1. ], [ 0.8, 0.8, 0.8, 1. ], [ 0., 0., 0., 1. ]]) self.assertEqual(arcs.get_colors(), colors) self.assertEqual(nodes.get_facecolors(), colors) def test_chord_node_color_style_mapping(self): g = self.chord.opts(style=dict(node_color='Label', cmap=['#FFFFFF', '#CCCCCC', '#000000'])) plot = mpl_renderer.get_plot(g) arcs = plot.handles['arcs'] nodes = plot.handles['nodes'] self.assertEqual(nodes.get_array(), np.array([0, 1, 2])) self.assertEqual(arcs.get_array(), np.array([0, 1, 2])) self.assertEqual(nodes.get_clim(), (0, 2)) self.assertEqual(arcs.get_clim(), (0, 2)) def test_chord_edges_categorically_colormapped(self): g = self.chord.opts(plot=dict(edge_color_index='start'), style=dict(edge_cmap=['#FFFFFF', '#000000'])) plot = mpl_renderer.get_plot(g) edges = plot.handles['edges'] colors = np.array([[ 1., 1., 1., 1. ], [ 1., 1., 1., 1. ], [ 0., 0., 0., 1. ]]) self.assertEqual(edges.get_edgecolors(), colors) def test_chord_edge_color_style_mapping(self): g = self.chord.opts(style=dict(edge_color=dim('start').astype(str), edge_cmap=['#FFFFFF', '#000000'])) plot = mpl_renderer.get_plot(g) edges = plot.handles['edges'] self.assertEqual(edges.get_array(), np.array([0, 0, 1])) self.assertEqual(edges.get_clim(), (0, 2)) def test_chord_edge_color_linear_style_mapping_update(self): hmap = HoloMap({0: self.make_chord(0), 1: self.make_chord(1)}).options(edge_color='weight', framewise=True) plot = mpl_renderer.get_plot(hmap) edges = plot.handles['edges'] self.assertEqual(edges.get_array(), np.array([1, 2, 3])) self.assertEqual(edges.get_clim(), (1, 3)) plot.update((1,)) self.assertEqual(edges.get_array(), np.array([2, 3, 4])) self.assertEqual(edges.get_clim(), (2, 4)) def test_chord_node_color_linear_style_mapping_update(self): hmap = HoloMap({0: self.make_chord(0), 1: self.make_chord(1)}).options(node_color='Label', framewise=True) plot = mpl_renderer.get_plot(hmap) arcs = plot.handles['arcs'] nodes = plot.handles['nodes'] self.assertEqual(nodes.get_array(), np.array([0, 1, 2])) self.assertEqual(arcs.get_array(), np.array([0, 1, 2])) self.assertEqual(nodes.get_clim(), (0, 2)) self.assertEqual(arcs.get_clim(), (0, 2)) plot.update((1,)) self.assertEqual(nodes.get_array(), np.array([1, 2, 3])) self.assertEqual(arcs.get_array(), np.array([1, 2, 3])) self.assertEqual(nodes.get_clim(), (1, 3)) self.assertEqual(arcs.get_clim(), (1, 3)) def test_chord_edge_color_style_mapping_update(self): hmap = HoloMap({0: self.make_chord(0), 1: self.make_chord(1)}).options( edge_color=dim('weight').categorize({1: 'red', 2: 'green', 3: 'blue', 4: 'black'}) ) plot = mpl_renderer.get_plot(hmap) edges = plot.handles['edges'] self.assertEqual(edges.get_edgecolors(), np.array([ [1, 0, 0, 1], [0, 0.501961, 0, 1], [0, 0, 1, 1] ])) plot.update((1,)) self.assertEqual(edges.get_edgecolors(), np.array([ [0, 0.501961, 0, 1], [0, 0, 1, 1], [0, 0, 0, 1] ])) def test_chord_node_color_style_mapping_update(self): hmap = HoloMap({0: self.make_chord(0), 1: self.make_chord(1)}).options( node_color=dim('Label').categorize({0: 'red', 1: 'green', 2: 'blue', 3: 'black'}) ) plot = mpl_renderer.get_plot(hmap) arcs = plot.handles['arcs'] nodes = plot.handles['nodes'] colors = np.array([ [1, 0, 0, 1], [0, 0.501961, 0, 1], [0, 0, 1, 1] ]) self.assertEqual(arcs.get_edgecolors(), colors) self.assertEqual(nodes.get_facecolors(), colors) plot.update((1,)) colors = np.array([ [0, 0.501961, 0, 1], [0, 0, 1, 1], [0, 0, 0, 1] ]) self.assertEqual(arcs.get_edgecolors(), colors) self.assertEqual(nodes.get_facecolors(), colors)