def test_dygraph_colors(self): """Check that to_dygraph_colors() constructs a valid dygraph colors argument""" from trappy.plotter.ColorMap import to_dygraph_colors color_map = [[86, 58, 206]] expected = '["rgb(86, 58, 206)"]' self.assertEquals(to_dygraph_colors(color_map), expected) color_map = [[0, 0, 0], [123, 23, 45]] expected = '["rgb(0, 0, 0)", "rgb(123, 23, 45)"]' self.assertEquals(to_dygraph_colors(color_map), expected)
def _add_graph_cell(self, fig_name, color_map): """Add a HTML table cell to hold the plot""" colors_opt_arg = ", " + to_dygraph_colors( color_map) if color_map else "" graph_js = '' lib_urls = [ IPythonConf.DYGRAPH_COMBINED_URL, IPythonConf.DYGRAPH_SYNC_URL, IPythonConf.UNDERSCORE_URL ] for url in lib_urls: graph_js += '<!-- TRAPPY_PUBLISH_SOURCE_LIB = "{}" -->\n'.format( url) graph_js += """ <script> /* TRAPPY_PUBLISH_IMPORT = "plotter/js/ILinePlot.js" */ /* TRAPPY_PUBLISH_REMOVE_START */ var ilp_req = require.config( { paths: { "dygraph-sync": '""" + IPythonConf.add_web_base( "plotter_scripts/ILinePlot/synchronizer") + """', "dygraph": '""" + IPythonConf.add_web_base( "plotter_scripts/ILinePlot/dygraph-combined") + """', "ILinePlot": '""" + IPythonConf.add_web_base( "plotter_scripts/ILinePlot/ILinePlot") + """', "underscore": '""" + IPythonConf.add_web_base( "plotter_scripts/ILinePlot/underscore-min") + """', }, shim: { "dygraph-sync": ["dygraph"], "ILinePlot": { "deps": ["dygraph-sync", "dygraph", "underscore"], "exports": "ILinePlot" } } }); /* TRAPPY_PUBLISH_REMOVE_STOP */ ilp_req(["require", "ILinePlot"], function() { /* TRAPPY_PUBLISH_REMOVE_LINE */ ILinePlot.generate(""" + fig_name + "_data" + colors_opt_arg + """); }); /* TRAPPY_PUBLISH_REMOVE_LINE */ </script> """ cell = '<td style="border-style: hidden;"><div class="ilineplot" id="{}"></div></td>'.format( fig_name) self._html.append(cell) self._js.append(graph_js)
def _add_graph_cell(self, fig_name, color_map): """Add a HTML table cell to hold the plot""" colors_opt_arg = ", " + to_dygraph_colors(color_map) if color_map else "" graph_js = '' lib_urls = [IPythonConf.DYGRAPH_COMBINED_URL, IPythonConf.DYGRAPH_SYNC_URL, IPythonConf.UNDERSCORE_URL] for url in lib_urls: graph_js += '<!-- TRAPPY_PUBLISH_SOURCE_LIB = "{}" -->\n'.format(url) graph_js += """ <script> /* TRAPPY_PUBLISH_IMPORT = "plotter/js/ILinePlot.js" */ /* TRAPPY_PUBLISH_REMOVE_START */ var ilp_req = require.config( { paths: { "dygraph-sync": '""" + IPythonConf.add_web_base("plotter_scripts/ILinePlot/synchronizer") + """', "dygraph": '""" + IPythonConf.add_web_base("plotter_scripts/ILinePlot/dygraph-combined") + """', "ILinePlot": '""" + IPythonConf.add_web_base("plotter_scripts/ILinePlot/ILinePlot") + """', "underscore": '""" + IPythonConf.add_web_base("plotter_scripts/ILinePlot/underscore-min") + """', }, shim: { "dygraph-sync": ["dygraph"], "ILinePlot": { "deps": ["dygraph-sync", "dygraph", "underscore"], "exports": "ILinePlot" } } }); /* TRAPPY_PUBLISH_REMOVE_STOP */ ilp_req(["require", "ILinePlot"], function() { /* TRAPPY_PUBLISH_REMOVE_LINE */ ILinePlot.generate(""" + fig_name + "_data" + colors_opt_arg + """); }); /* TRAPPY_PUBLISH_REMOVE_LINE */ </script> """ cell = '<td style="border-style: hidden;"><div class="ilineplot" id="{}"></div></td>'.format(fig_name) self._html.append(cell) self._js.append(graph_js)