Example #1
0
    def _init_html(self):
        """Initialize HTML for the plot"""
        div_js = """
        <script>
            var req = require.config( {

                paths: {

                    "EventPlot": '""" + IPythonConf.add_web_base("plotter_scripts/EventPlot/EventPlot") + """',
                    "d3-tip": '""" + IPythonConf.add_web_base("plotter_scripts/EventPlot/d3.tip.v0.6.3") + """',
                    "d3-plotter": '""" + IPythonConf.add_web_base("plotter_scripts/EventPlot/d3.min") + """'
                },
                shim: {
                    "d3-plotter" : {
                        "exports" : "d3"
                    },
                    "d3-tip": ["d3-plotter"],
                    "EventPlot": {

                        "deps": ["d3-tip", "d3-plotter" ],
                        "exports":  "EventPlot"
                    }
                }
            });
            req(["require", "EventPlot"], function() {
               EventPlot.generate('""" + self._fig_name + """', '""" + IPythonConf.add_web_base("") + """');
            });
        </script>
        """

        self._html.append(
            '<div id="{}" class="eventplot">{}</div>'.format(self._fig_name,
                                                             div_js))
Example #2
0
    def view(self, max_datapoints=75000, test=False):
        """Displays the graph

        :param max_datapoints: Maximum number of datapoints to plot.
        Dygraph can make the browser unresponsive if it tries to plot
        too many datapoints.  Chrome 50 chokes at around 75000 on an
        i7-4770 @ 3.4GHz, Firefox 47 can handle up to 200000 before
        becoming too slow in the same machine.  You can increase this
        number if you know what you're doing and are happy to wait for
        the plot to render.  :type max_datapoints: int

        :param test: For testing purposes.  Only set to true if run
        from the testsuite.
        :type test: boolean
        """

        # Defer installation of IPython components
        # to the .view call to avoid any errors at
        # when importing the module. This facilitates
        # the importing of the module from outside
        # an IPython notebook
        if not test:
            IPythonConf.iplot_install("ILinePlot")

        self._attr["max_datapoints"] = max_datapoints

        if self._attr["concat"]:
            self._plot_concat()
        else:
            self._plot(self._attr["permute"], test)
Example #3
0
    def view(self, max_datapoints=75000, test=False):
        """Displays the graph

        :param max_datapoints: Maximum number of datapoints to plot.
        Dygraph can make the browser unresponsive if it tries to plot
        too many datapoints.  Chrome 50 chokes at around 75000 on an
        i7-4770 @ 3.4GHz, Firefox 47 can handle up to 200000 before
        becoming too slow in the same machine.  You can increase this
        number if you know what you're doing and are happy to wait for
        the plot to render.  :type max_datapoints: int

        :param test: For testing purposes.  Only set to true if run
        from the testsuite.
        :type test: boolean
        """

        # Defer installation of IPython components
        # to the .view call to avoid any errors at
        # when importing the module. This facilitates
        # the importing of the module from outside
        # an IPython notebook
        if not test:
            IPythonConf.iplot_install("ILinePlot")

        self._attr["max_datapoints"] = max_datapoints

        if self._attr["concat"]:
            self._plot_concat()
        else:
            self._plot(self._attr["permute"], test)
Example #4
0
    def _add_graph_cell(self, fig_name):
        """Add a HTML table cell to hold the plot"""

        div_js = """
            <script>
            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"
                    }
                }
            });
                ilp_req(["require", "ILinePlot"], function() {
                ILinePlot.generate('""" + fig_name + """', '""" + IPythonConf.add_web_base("") + """');
            });
            </script>
        """

        cell = '<td style="border-style: hidden;"><div class="ilineplot" id="{}">{}</div></td>'.format(fig_name, div_js)

        self._html.append(cell)
Example #5
0
    def view(self):
        """Views the Graph Object"""

        # Defer installation of IPython components
        # to the .view call to avoid any errors at
        # when importing the module. This facilitates
        # the importing of the module from outside
        # an IPython notebook
        IPythonConf.iplot_install("EventPlot")
        display(HTML(self.html()))
Example #6
0
    def view(self):
        """Views the Graph Object"""

        # Defer installation of IPython components
        # to the .view call to avoid any errors at
        # when importing the module. This facilitates
        # the importing of the module from outside
        # an IPython notebook
        IPythonConf.iplot_install("EventPlot")
        display(HTML(self.html()))
Example #7
0
    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)
Example #8
0
    def view(self, test=False):
        """Displays the graph"""

        # Defer installation of IPython components
        # to the .view call to avoid any errors at
        # when importing the module. This facilitates
        # the importing of the module from outside
        # an IPython notebook
        IPythonConf.iplot_install("ILinePlot")

        if self._attr["concat"]:
            self._plot_concat()
        else:
            self._plot(self._attr["permute"])
Example #9
0
    def view(self, test=False):
        """Displays the graph"""

        # Defer installation of IPython components
        # to the .view call to avoid any errors at
        # when importing the module. This facilitates
        # the importing of the module from outside
        # an IPython notebook
        IPythonConf.iplot_install("ILinePlot")

        if self._attr["concat"]:
            self._plot_concat()
        else:
            self._plot(self._attr["permute"])
Example #10
0
    def __init__(self,
                 data,
                 keys,
                 domain,
                 lane_prefix="Lane: ",
                 num_lanes=0,
                 summary=True,
                 stride=False,
                 lanes=None):

        self._html = []
        self._fig_name = self._generate_fig_name()
        avgFunc = lambda x: sum([(evt[1] - evt[0]) for evt in x]) / len(x)
        avg = {k: avgFunc(v) for k, v in data.iteritems()}
        graph = {}
        graph["data"] = data
        graph["lanes"] = self._get_lanes(lanes, lane_prefix, num_lanes, data)
        graph["xDomain"] = domain
        graph["keys"] = sorted(avg, key=lambda x: avg[x], reverse=True)
        graph["showSummary"] = summary
        graph["stride"] = AttrConf.EVENT_PLOT_STRIDE

        json_file = os.path.join(IPythonConf.get_data_path(),
                                 self._fig_name + ".json")

        with open(json_file, "w") as json_fh:
            json.dump(graph, json_fh)

        # Initialize the HTML, CSS and JS Components
        self._add_css()
        self._init_html()
Example #11
0
    def __init__(
            self,
            data,
            keys,
            domain,
            lane_prefix="Lane: ",
            num_lanes=0,
            summary=True,
            stride=False,
            lanes=None):

        self._html = []
        self._fig_name = self._generate_fig_name()
        avgFunc = lambda x: sum([(evt[1] - evt[0]) for evt in x]) / len(x)
        avg = {k: avgFunc(v) for k, v in data.iteritems()}
        graph = {}
        graph["data"] = data
        graph["lanes"] = self._get_lanes(lanes, lane_prefix, num_lanes, data)
        graph["xDomain"] = domain
        graph["keys"] = sorted(avg, key=lambda x: avg[x], reverse=True)
        graph["showSummary"] = summary
        graph["stride"] = AttrConf.EVENT_PLOT_STRIDE

        json_file = os.path.join(
            IPythonConf.get_data_path(),
            self._fig_name +
            ".json")

        with open(json_file, "w") as json_fh:
            json.dump(graph, json_fh)

        # Initialize the HTML, CSS and JS Components
        self._add_css()
        self._init_html()
Example #12
0
    def _init_html(self):
        """Initialize HTML for the plot"""
        div_js = ''
        for url in [IPythonConf.D3_PLOTTER_URL, IPythonConf.D3_TIP_URL]:
            div_js += '<!-- TRAPPY_PUBLISH_SOURCE_LIB = "{}" -->\n'.format(url)

        div_js += """
        <script>
            /* TRAPPY_PUBLISH_IMPORT = "plotter/js/EventPlot.js" */
            /* TRAPPY_PUBLISH_REMOVE_START */
            var req = require.config( {

                paths: {

                    "EventPlot": '""" + IPythonConf.add_web_base(
            "plotter_scripts/EventPlot/EventPlot") + """',
                    "d3-tip": '""" + IPythonConf.add_web_base(
                "plotter_scripts/EventPlot/d3.tip.v0.6.3") + """',
                    "d3-plotter": '""" + IPythonConf.add_web_base(
                    "plotter_scripts/EventPlot/d3.min") + """'
                },
                shim: {
                    "d3-plotter" : {
                        "exports" : "d3"
                    },
                    "d3-tip": ["d3-plotter"],
                    "EventPlot": {

                        "deps": ["d3-tip", "d3-plotter" ],
                        "exports":  "EventPlot"
                    }
                }
            });
            /* TRAPPY_PUBLISH_REMOVE_STOP */
            """

        div_js += "var data = {};\n".format(self._data)
        div_js += """
        req(["require", "EventPlot"], function() { /* TRAPPY_PUBLISH_REMOVE_LINE */
            EventPlot.generate('""" + self._fig_name + """', '""" + IPythonConf.add_web_base(
            "") + """', data);
        }); /* TRAPPY_PUBLISH_REMOVE_LINE */
        </script>
        """

        self._html.append('<div id="{}" class="eventplot">\n{}</div>'.format(
            self._fig_name, div_js))
def change_resource_paths(txt):
    """Change the resource paths from local to
       Web URLs
    """

    # Replace the path for d3-tip
    txt = txt.replace(
        IPythonConf.add_web_base("plotter_scripts/EventPlot/d3.tip.v0.6.3"),
        IPythonConf.D3_TIP_URL)
    txt = txt.replace(
        IPythonConf.add_web_base("plotter_scripts/EventPlot/d3.v3.min"),
        IPythonConf.D3_PLOTTER_URL)
    txt = txt.replace(
        IPythonConf.add_web_base("plotter_scripts/EventPlot/EventPlot"),
        "https://rawgit.com/sinkap/7f89de3e558856b81f10/raw/46144f8f8c5da670c54f826f0c634762107afc66/EventPlot")
    txt = txt.replace(
        IPythonConf.add_web_base("plotter_scripts/ILinePlot/synchronizer"),
        IPythonConf.DYGRAPH_SYNC_URL)
    txt = txt.replace(
        IPythonConf.add_web_base("plotter_scripts/ILinePlot/dygraph-combined"),
        IPythonConf.DYGRAPH_COMBINED_URL)
    txt = txt.replace(
        IPythonConf.add_web_base("plotter_scripts/ILinePlot/ILinePlot"),
        "https://rawgit.com/sinkap/648927dfd6985d4540a9/raw/69d6f1f9031ae3624c15707315ce04be1a9d1ac3/ILinePlot")
    txt = txt.replace(
        IPythonConf.add_web_base("plotter_scripts/ILinePlot/underscore-min"),
        IPythonConf.UNDERSCORE_URL)

    logging.info("Updated Library Paths...")
    return txt
Example #14
0
def change_resource_paths(txt):
    """Change the resource paths from local to
       Web URLs
    """

    # Replace the path for d3-tip
    txt = txt.replace(
        IPythonConf.add_web_base("plotter_scripts/EventPlot/d3.tip.v0.6.3"),
        "http://labratrevenge.com/d3-tip/javascripts/d3.tip.v0.6.3")
    txt = txt.replace(
        IPythonConf.add_web_base("plotter_scripts/EventPlot/d3.v3.min"),
        "http://d3js.org/d3.v3.min")
    txt = txt.replace(
        IPythonConf.add_web_base("plotter_scripts/EventPlot/EventPlot"),
        "https://rawgit.com/sinkap/7f89de3e558856b81f10/raw/46144f8f8c5da670c54f826f0c634762107afc66/EventPlot"
    )
    txt = txt.replace(
        IPythonConf.add_web_base("plotter_scripts/ILinePlot/synchronizer"),
        "http://dygraphs.com/extras/synchronizer")
    txt = txt.replace(
        IPythonConf.add_web_base("plotter_scripts/ILinePlot/dygraph-combined"),
        "http://cdnjs.cloudflare.com/ajax/libs/dygraph/1.1.1/dygraph-combined")
    txt = txt.replace(
        IPythonConf.add_web_base("plotter_scripts/ILinePlot/ILinePlot"),
        "https://rawgit.com/sinkap/648927dfd6985d4540a9/raw/69d6f1f9031ae3624c15707315ce04be1a9d1ac3/ILinePlot"
    )
    txt = txt.replace(
        IPythonConf.add_web_base("plotter_scripts/ILinePlot/underscore-min"),
        "https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min"
    )

    logging.info("Updated Library Paths...")
    return txt
def change_resource_paths(txt):
    """Change the resource paths from local to
       Web URLs
    """

    # Replace the path for d3-tip
    txt = txt.replace(
        IPythonConf.add_web_base("plotter_scripts/EventPlot/d3.tip.v0.6.3"),
        "http://labratrevenge.com/d3-tip/javascripts/d3.tip.v0.6.3")
    txt = txt.replace(
        IPythonConf.add_web_base("plotter_scripts/EventPlot/d3.v3.min"),
        "http://d3js.org/d3.v3.min")
    txt = txt.replace(
        IPythonConf.add_web_base("plotter_scripts/EventPlot/EventPlot"),
        "https://rawgit.com/sinkap/7f89de3e558856b81f10/raw/46144f8f8c5da670c54f826f0c634762107afc66/EventPlot")
    txt = txt.replace(
        IPythonConf.add_web_base("plotter_scripts/ILinePlot/synchronizer"),
        "http://dygraphs.com/extras/synchronizer")
    txt = txt.replace(
        IPythonConf.add_web_base("plotter_scripts/ILinePlot/dygraph-combined"),
        "http://cdnjs.cloudflare.com/ajax/libs/dygraph/1.1.1/dygraph-combined")
    txt = txt.replace(
        IPythonConf.add_web_base("plotter_scripts/ILinePlot/ILinePlot"),
        "https://rawgit.com/sinkap/648927dfd6985d4540a9/raw/69d6f1f9031ae3624c15707315ce04be1a9d1ac3/ILinePlot")
    txt = txt.replace(
        IPythonConf.add_web_base("plotter_scripts/ILinePlot/underscore-min"),
        "https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min")

    logging.info("Updated Library Paths...")
    return txt
Example #16
0
def change_resource_paths(txt):
    """Change the resource paths from local to
       Web URLs
    """

    # Replace the path for d3-tip
    txt = txt.replace(
        IPythonConf.add_web_base("plotter_scripts/EventPlot/d3.tip.v0.6.3"),
        IPythonConf.D3_TIP_URL)
    txt = txt.replace(
        IPythonConf.add_web_base("plotter_scripts/EventPlot/d3.v3.min"),
        IPythonConf.D3_PLOTTER_URL)
    txt = txt.replace(
        IPythonConf.add_web_base("plotter_scripts/EventPlot/EventPlot"),
        "https://rawgit.com/sinkap/7f89de3e558856b81f10/raw/46144f8f8c5da670c54f826f0c634762107afc66/EventPlot"
    )
    txt = txt.replace(
        IPythonConf.add_web_base("plotter_scripts/ILinePlot/synchronizer"),
        IPythonConf.DYGRAPH_SYNC_URL)
    txt = txt.replace(
        IPythonConf.add_web_base("plotter_scripts/ILinePlot/dygraph-combined"),
        IPythonConf.DYGRAPH_COMBINED_URL)
    txt = txt.replace(
        IPythonConf.add_web_base("plotter_scripts/ILinePlot/ILinePlot"),
        "https://rawgit.com/sinkap/648927dfd6985d4540a9/raw/69d6f1f9031ae3624c15707315ce04be1a9d1ac3/ILinePlot"
    )
    txt = txt.replace(
        IPythonConf.add_web_base("plotter_scripts/ILinePlot/underscore-min"),
        IPythonConf.UNDERSCORE_URL)

    logging.info("Updated Library Paths...")
    return txt
Example #17
0
    def _init_html(self):
        """Initialize HTML for the plot"""
        div_js = ''
        for url in [IPythonConf.D3_PLOTTER_URL, IPythonConf.D3_TIP_URL]:
            div_js += '<!-- TRAPPY_PUBLISH_SOURCE_LIB = "{}" -->\n'.format(url)

        div_js += """
        <script>
            /* TRAPPY_PUBLISH_IMPORT = "plotter/js/EventPlot.js" */
            /* TRAPPY_PUBLISH_REMOVE_START */
            var req = require.config( {

                paths: {

                    "EventPlot": '""" + IPythonConf.add_web_base("plotter_scripts/EventPlot/EventPlot") + """',
                    "d3-tip": '""" + IPythonConf.add_web_base("plotter_scripts/EventPlot/d3.tip.v0.6.3") + """',
                    "d3-plotter": '""" + IPythonConf.add_web_base("plotter_scripts/EventPlot/d3.min") + """'
                },
                waitSeconds: 15,
                shim: {
                    "d3-plotter" : {
                        "exports" : "d3"
                    },
                    "d3-tip": ["d3-plotter"],
                    "EventPlot": {

                        "deps": ["d3-tip", "d3-plotter" ],
                        "exports":  "EventPlot"
                    }
                }
            });
            /* TRAPPY_PUBLISH_REMOVE_STOP */
            """

        div_js += """
        req(["require", "EventPlot"], function() { /* TRAPPY_PUBLISH_REMOVE_LINE */
            EventPlot.generate('""" + self._fig_name + "', '" + IPythonConf.add_web_base("") + "', " + self._data + """);
        }); /* TRAPPY_PUBLISH_REMOVE_LINE */
        </script>
        """

        self._html.append(
            '<div id="{}" class="eventplot">\n{}</div>'.format(self._fig_name,
                                                             div_js))
Example #18
0
    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 fig_to_json(fig, profile):
    """Get the underlying data file from figure name"""

    data_dir = IPythonConf.get_data_path(profile)

    return os.path.expanduser(
        os.path.join(
            data_dir,
            fig +
            ".json"))
Example #20
0
    def _add_graph_cell(self, fig_name):
        """Add a HTML table cell to hold the plot"""

        width = int(self._attr["width"] / self._cols)
        div_js = """
            <script>
            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"
                    }
                }
            });
                ilp_req(["require", "ILinePlot"], function() {
                ILinePlot.generate('""" + fig_name + """', '""" + IPythonConf.add_web_base("") + """');
            });
            </script>
        """

        cell = '<td style="border-style: hidden;"><div class="ilineplot" id="{0}" style="width: \
{1}px; height: {2}px;">{3}</div></td>'.format(fig_name,
                                           width,
                                           self._attr["height"], div_js)

        self._html.append(cell)
Example #21
0
    def _init_html(self):
        """Initialize HTML for the plot"""
        div_js = """
        <script>
            var req = require.config( {

                paths: {

                    "EventPlot": '""" + IPythonConf.add_web_base(
            "plotter_scripts/EventPlot/EventPlot") + """',
                    "d3-tip": '""" + IPythonConf.add_web_base(
                "plotter_scripts/EventPlot/d3.tip.v0.6.3") + """',
                    "d3-plotter": '""" + IPythonConf.add_web_base(
                    "plotter_scripts/EventPlot/d3.v3.min") + """'
                },
                shim: {
                    "d3-plotter" : {
                        "exports" : "d3"
                    },
                    "d3-tip": ["d3-plotter"],
                    "EventPlot": {

                        "deps": ["d3-tip", "d3-plotter" ],
                        "exports":  "EventPlot"
                    }
                }
            });
            req(["require", "EventPlot"], function() {
               EventPlot.generate('""" + self._fig_name + """', '""" + IPythonConf.add_web_base(
                        "") + """');
            });
        </script>
        """

        self._html.append('<div id="{}" class="eventplot">{}</div>'.format(
            self._fig_name, div_js))
Example #22
0
    def add_plot(self, plot_num, data_frame, title=""):
        """Add a plot for the corresponding index

        :param plot_num: The linear index of the plot
        :type plot_num: int

        :param data_frame: The data for the plot
        :type data_frame: :mod:`pandas.DataFrame`

        :param title: The title for the plot
        :type title: str
        """

        fig_name = self._fig_map[plot_num]
        fig_params = {}
        fig_params["data"] = json.loads(data_frame.to_json())
        fig_params["name"] = fig_name
        fig_params["rangesel"] = False
        fig_params["logscale"] = False
        fig_params["title"] = title
        fig_params["step_plot"] = self._attr["step_plot"]
        fig_params["fill_graph"] = self._attr["fill"]
        fig_params["per_line"] = self._attr["per_line"]
        fig_params["height"] = self._attr["height"]

        self._check_add_scatter(fig_params)

        if "group" in self._attr:
            fig_params["syncGroup"] = self._attr["group"]
            if "sync_zoom" in self._attr:
                fig_params["syncZoom"] = self._attr["sync_zoom"]
            else:
                fig_params["syncZoom"] = AttrConf.DEFAULT_SYNC_ZOOM

        if "ylim" in self._attr:
            fig_params["valueRange"] = self._attr["ylim"]

        if "xlim" in self._attr:
            fig_params["dateWindow"] = self._attr["xlim"]

        json_file = os.path.join(IPythonConf.get_data_path(), fig_name + ".json")
        fh = open(json_file, "w")
        json.dump(fig_params, fh)
        fh.close()
Example #23
0
    def add_plot(self, plot_num, data_frame, title=""):
        """Add a plot for the corresponding index

        :param plot_num: The linear index of the plot
        :type plot_num: int

        :param data_frame: The data for the plot
        :type data_frame: :mod:`pandas.DataFrame`

        :param title: The title for the plot
        :type title: str
        """

        fig_name = self._fig_map[plot_num]
        fig_params = {}
        fig_params["data"] = json.loads(data_frame.to_json())
        fig_params["name"] = fig_name
        fig_params["rangesel"] = False
        fig_params["logscale"] = False
        fig_params["title"] = title
        fig_params["step_plot"] = self._attr["step_plot"]
        fig_params["fill_graph"] = self._attr["fill"]

        self._check_add_scatter(fig_params)

        if "group" in self._attr:
            fig_params["syncGroup"] = self._attr["group"]
            if "sync_zoom" in self._attr:
                fig_params["syncZoom"] = self._attr["sync_zoom"]
            else:
                fig_params["syncZoom"] = AttrConf.DEFAULT_SYNC_ZOOM

        if "ylim" in self._attr:
            fig_params["valueRange"] = self._attr["ylim"]

        json_file = os.path.join(IPythonConf.get_data_path(), fig_name + ".json")
        fh = open(json_file, "w")
        json.dump(fig_params, fh)
        fh.close()
Example #24
0
customizing Line/Linear Plots with :mod:`trappy.trace.FTrace`
This plot only works when run from an IPython notebook
"""

import matplotlib.pyplot as plt
from trappy.plotter import AttrConf
from trappy.plotter import Utils
from trappy.plotter.Constraint import ConstraintManager
from trappy.plotter.ILinePlotGen import ILinePlotGen
from trappy.plotter.AbstractDataPlotter import AbstractDataPlotter
from trappy.plotter.ColorMap import ColorMap
from trappy.plotter import IPythonConf
from trappy.utils import handle_duplicate_index
import pandas as pd

if not IPythonConf.check_ipython():
    raise ImportError("Ipython Environment not Found")

class ILinePlot(AbstractDataPlotter):
    """
    This class uses :mod:`trappy.plotter.Constraint.Constraint` to
    represent different permutations of input parameters. These
    constraints are generated by creating an instance of
    :mod:`trappy.plotter.Constraint.ConstraintManager`.

    :param traces: The input data
    :type traces: a list of :mod:`trappy.trace.FTrace` or :mod:`pandas.DataFrame` or a single instance of them

    :param column: specifies the name of the column to
           be plotted.
    :type column: (str, list(str))
Example #25
0
def fig_to_json(fig, profile):
    """Get the underlying data file from figure name"""

    data_dir = IPythonConf.get_data_path(profile)

    return os.path.expanduser(os.path.join(data_dir, fig + ".json"))
Example #26
0
from __future__ import division
from __future__ import unicode_literals

from builtins import zip
from builtins import str
from builtins import range
from builtins import object
from trappy.plotter import AttrConf
import uuid
from collections import OrderedDict
import json
import os
from trappy.plotter import IPythonConf
from trappy.plotter.ColorMap import to_dygraph_colors

if not IPythonConf.check_ipython():
    raise ImportError("No Ipython Environment found")

from IPython.display import display, HTML


def df_to_dygraph(data_frame):
    """Helper function to convert a :mod:`pandas.DataFrame` to
    dygraph data

    :param data_frame: The DataFrame to be converted
    :type data_frame: :mod:`pandas.DataFrame`
    """

    values = data_frame.values.tolist()
    data = [[x] for x in data_frame.index.tolist()]