ILinePlotGen.py revision f2666cb3e55dfc7812d6c170f992190e795602cf
14ec4aee55dbd4045cfb6a2fe099615a569ce7ff7Javi Merino#    Copyright 2015-2016 ARM Limited
28741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh#
3aace7c0732cac769f1ffe95a89591b6217fa9447Javi Merino# Licensed under the Apache License, Version 2.0 (the "License");
4aace7c0732cac769f1ffe95a89591b6217fa9447Javi Merino# you may not use this file except in compliance with the License.
5aace7c0732cac769f1ffe95a89591b6217fa9447Javi Merino# You may obtain a copy of the License at
6aace7c0732cac769f1ffe95a89591b6217fa9447Javi Merino#
7aace7c0732cac769f1ffe95a89591b6217fa9447Javi Merino#     http://www.apache.org/licenses/LICENSE-2.0
8aace7c0732cac769f1ffe95a89591b6217fa9447Javi Merino#
9aace7c0732cac769f1ffe95a89591b6217fa9447Javi Merino# Unless required by applicable law or agreed to in writing, software
10aace7c0732cac769f1ffe95a89591b6217fa9447Javi Merino# distributed under the License is distributed on an "AS IS" BASIS,
11aace7c0732cac769f1ffe95a89591b6217fa9447Javi Merino# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12aace7c0732cac769f1ffe95a89591b6217fa9447Javi Merino# See the License for the specific language governing permissions and
13aace7c0732cac769f1ffe95a89591b6217fa9447Javi Merino# limitations under the License.
14aace7c0732cac769f1ffe95a89591b6217fa9447Javi Merino#
15aace7c0732cac769f1ffe95a89591b6217fa9447Javi Merino
1666451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh"""This is helper module for :mod:`trappy.plotter.ILinePlot`
1766451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singhfor adding HTML and javascript necessary for interactive
1866451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singhplotting. The Linear to 2-D co-ordination transformations
1966451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singhare done by using the functionality in
2066451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh:mod:`trappy.plotter.PlotLayout`
218741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh"""
228741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
23435457c8af9d69383ba45e0bd7da022d967a8deaJavi Merinofrom trappy.plotter import AttrConf
248741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singhimport uuid
258741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singhimport json
268741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singhimport os
2753de9b352977814c37608788cc1df83fc6485371Kapileshwar Singhfrom trappy.plotter import IPythonConf
288741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
29e1a703051d7cf345003f0ed4cfa7c25a76b0105cKapileshwar Singh
3053de9b352977814c37608788cc1df83fc6485371Kapileshwar Singhif not IPythonConf.check_ipython():
318741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh    raise ImportError("No Ipython Environment found")
328741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
33fd5fe5f7938465e38af92f33287e7ad6549951eaKapileshwar Singhfrom IPython.display import display, HTML
34fd5fe5f7938465e38af92f33287e7ad6549951eaKapileshwar Singh
358741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
368741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singhclass ILinePlotGen(object):
3766451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh    """
3866451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh    :param num_plots: The total number of plots
3966451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh    :type num_plots: int
4066451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh
4166451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh    The linear co-ordinate system :math:`[0, N_{plots}]` is
4266451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh    mapped to a 2-D coordinate system with :math:`N_{rows}`
4366451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh    and :math:`N_{cols}` such that:
448741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
4566451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh    .. math::
4666451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh
4766451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh        N_{rows} = \\frac{N_{cols}}{N_{plots}}
488741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh    """
498741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
508741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh    def _add_graph_cell(self, fig_name):
518741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        """Add a HTML table cell to hold the plot"""
528741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
53211860fe53efaa299db6ff6c9b28816bcb5902d4Kapileshwar Singh        div_js = """
544aa15c0de680a339ba3e7acf300aaa089f3eb4caKapileshwar Singh            <script>
554aa15c0de680a339ba3e7acf300aaa089f3eb4caKapileshwar Singh            var ilp_req = require.config( {
564aa15c0de680a339ba3e7acf300aaa089f3eb4caKapileshwar Singh
5707ac8dd8c8093d432390078dab4dce61906e421dKapileshwar Singh                paths: {
5853de9b352977814c37608788cc1df83fc6485371Kapileshwar Singh                    "dygraph-sync": '""" + IPythonConf.add_web_base("plotter_scripts/ILinePlot/synchronizer") + """',
5953de9b352977814c37608788cc1df83fc6485371Kapileshwar Singh                    "dygraph": '""" + IPythonConf.add_web_base("plotter_scripts/ILinePlot/dygraph-combined") + """',
6053de9b352977814c37608788cc1df83fc6485371Kapileshwar Singh                    "ILinePlot": '""" + IPythonConf.add_web_base("plotter_scripts/ILinePlot/ILinePlot") + """',
61324d33688bde12601302cbad42e3487c37364817Kapileshwar Singh                    "underscore": '""" + IPythonConf.add_web_base("plotter_scripts/ILinePlot/underscore-min") + """',
6207ac8dd8c8093d432390078dab4dce61906e421dKapileshwar Singh                },
6307ac8dd8c8093d432390078dab4dce61906e421dKapileshwar Singh
644aa15c0de680a339ba3e7acf300aaa089f3eb4caKapileshwar Singh                shim: {
6507ac8dd8c8093d432390078dab4dce61906e421dKapileshwar Singh                    "dygraph-sync": ["dygraph"],
6607ac8dd8c8093d432390078dab4dce61906e421dKapileshwar Singh                    "ILinePlot": {
674aa15c0de680a339ba3e7acf300aaa089f3eb4caKapileshwar Singh
68324d33688bde12601302cbad42e3487c37364817Kapileshwar Singh                        "deps": ["dygraph-sync", "dygraph", "underscore"],
694aa15c0de680a339ba3e7acf300aaa089f3eb4caKapileshwar Singh                        "exports":  "ILinePlot"
704aa15c0de680a339ba3e7acf300aaa089f3eb4caKapileshwar Singh                    }
714aa15c0de680a339ba3e7acf300aaa089f3eb4caKapileshwar Singh                }
724aa15c0de680a339ba3e7acf300aaa089f3eb4caKapileshwar Singh            });
7307ac8dd8c8093d432390078dab4dce61906e421dKapileshwar Singh                ilp_req(["require", "ILinePlot"], function() {
7453de9b352977814c37608788cc1df83fc6485371Kapileshwar Singh                ILinePlot.generate('""" + fig_name + """', '""" + IPythonConf.add_web_base("") + """');
75211860fe53efaa299db6ff6c9b28816bcb5902d4Kapileshwar Singh            });
76211860fe53efaa299db6ff6c9b28816bcb5902d4Kapileshwar Singh            </script>
77211860fe53efaa299db6ff6c9b28816bcb5902d4Kapileshwar Singh        """
78211860fe53efaa299db6ff6c9b28816bcb5902d4Kapileshwar Singh
79b9e8f11cfd24c71e4634a3b23ba3704841e636d9Kapileshwar Singh        cell = '<td style="border-style: hidden;"><div class="ilineplot" id="{}">{}</div></td>'.format(fig_name, div_js)
808741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
818741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        self._html.append(cell)
828741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
838741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh    def _add_legend_cell(self, fig_name):
848741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        """Add HTML table cell for the legend"""
858741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
868741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        legend_div_name = fig_name + "_legend"
879b4898aa3ea40f2af85157af65ab491e8aaa9b4cMichele Di Giorgio        cell = '<td style="border-style: hidden;"><div style="text-align:center" id="{}"></div></td>'.format(legend_div_name)
888741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
898741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        self._html.append(cell)
908741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
918741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh    def _begin_row(self):
928741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        """Add the opening tag for HTML row"""
938741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
948741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        self._html.append("<tr>")
958741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
968741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh    def _end_row(self):
978741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        """Add the closing tag for the HTML row"""
988741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
998741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        self._html.append("</tr>")
1008741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1017c32bc41bcd9e96c06bb70339334489cb93c663cKapileshwar Singh    def _end_table(self):
1027c32bc41bcd9e96c06bb70339334489cb93c663cKapileshwar Singh        """Add the closing tag for the HTML table"""
1037c32bc41bcd9e96c06bb70339334489cb93c663cKapileshwar Singh
1047c32bc41bcd9e96c06bb70339334489cb93c663cKapileshwar Singh        self._html.append("</table>")
1057c32bc41bcd9e96c06bb70339334489cb93c663cKapileshwar Singh
1068741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh    def _generate_fig_name(self):
1078741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        """Generate a unique figure name"""
1088741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1098741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        fig_name = "fig_" + uuid.uuid4().hex
1108741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        self._fig_map[self._fig_index] = fig_name
1118741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        self._fig_index += 1
1128741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        return fig_name
1138741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1148741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh    def _init_html(self):
1158741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        """Initialize HTML code for the plots"""
1168741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
117b9e8f11cfd24c71e4634a3b23ba3704841e636d9Kapileshwar Singh        table = '<table style="border-style: hidden;">'
1188741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        self._html.append(table)
119b24eed7a902022c014c61f7c8c3061adf53f4eacMichele Di Giorgio        if self._attr["title"]:
120b24eed7a902022c014c61f7c8c3061adf53f4eacMichele Di Giorgio            cell = '<caption style="text-align:center; font: 24px sans-serif bold; color: black">{}</caption>'.format(self._attr["title"])
121b24eed7a902022c014c61f7c8c3061adf53f4eacMichele Di Giorgio            self._html.append(cell)
1228741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1238741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        for _ in range(self._rows):
1248741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh            self._begin_row()
1258741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh            legend_figs = []
1268377bdc6856e004ecc6554008a9e0f556a05b579Michele Di Giorgio            for _ in range(self._attr["per_line"]):
1278741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh                fig_name = self._generate_fig_name()
1288741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh                legend_figs.append(fig_name)
1298741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh                self._add_graph_cell(fig_name)
1308741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1318741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh            self._end_row()
1328741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh            self._begin_row()
1338741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1348741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh            for l_fig in legend_figs:
1358741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh                self._add_legend_cell(l_fig)
1368741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1378741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh            self._end_row()
1388741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1397c32bc41bcd9e96c06bb70339334489cb93c663cKapileshwar Singh        self._end_table()
1407c32bc41bcd9e96c06bb70339334489cb93c663cKapileshwar Singh
1418377bdc6856e004ecc6554008a9e0f556a05b579Michele Di Giorgio    def __init__(self, num_plots, **kwargs):
1428741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
143bd75d5c3abd977e41ce8c9f7e4740a552a239932Kapileshwar Singh        self._attr = kwargs
1448741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        self._html = []
1458741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        self.num_plots = num_plots
1468741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        self._fig_map = {}
1478741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        self._fig_index = 0
1488741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1498741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        self._single_plot = False
1508741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        if self.num_plots == 0:
1518741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh            raise RuntimeError("No plots for the given constraints")
1528741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1538377bdc6856e004ecc6554008a9e0f556a05b579Michele Di Giorgio        if self.num_plots < self._attr["per_line"]:
1548377bdc6856e004ecc6554008a9e0f556a05b579Michele Di Giorgio            self._attr["per_line"] = self.num_plots
1558377bdc6856e004ecc6554008a9e0f556a05b579Michele Di Giorgio        self._rows = (self.num_plots / self._attr["per_line"])
1568741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1578377bdc6856e004ecc6554008a9e0f556a05b579Michele Di Giorgio        if self.num_plots % self._attr["per_line"] != 0:
1588741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh            self._rows += 1
1598741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1608741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        self._attr["height"] = AttrConf.HTML_HEIGHT
1618741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        self._init_html()
1628741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1637ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh    def _check_add_scatter(self, fig_params):
1647ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh        """Check if a scatter plot is needed
1657ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh        and augment the fig_params accordingly"""
1667ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh
1677ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh        if self._attr["scatter"]:
1687ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh            fig_params["drawPoints"] = True
1697ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh            fig_params["strokeWidth"] = 0.0
1707ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh        else:
1717ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh            fig_params["drawPoints"] = False
1727ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh            fig_params["strokeWidth"] = AttrConf.LINE_WIDTH
1737ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh
1747ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh        fig_params["pointSize"] = self._attr["point_size"]
1757ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh
176f2666cb3e55dfc7812d6c170f992190e795602cfJavi Merino    def add_plot(self, plot_num, data_frame, title="", test=False):
17766451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh        """Add a plot for the corresponding index
17866451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh
17966451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh        :param plot_num: The linear index of the plot
18066451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh        :type plot_num: int
18166451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh
18266451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh        :param data_frame: The data for the plot
18366451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh        :type data_frame: :mod:`pandas.DataFrame`
18466451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh
18566451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh        :param title: The title for the plot
18666451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh        :type title: str
18766451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh        """
1888741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1898741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        fig_name = self._fig_map[plot_num]
1908741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        fig_params = {}
1918741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        fig_params["data"] = json.loads(data_frame.to_json())
1928741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        fig_params["name"] = fig_name
1938741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        fig_params["rangesel"] = False
1948741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        fig_params["logscale"] = False
1958741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        fig_params["title"] = title
1968741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        fig_params["step_plot"] = self._attr["step_plot"]
197bd75d5c3abd977e41ce8c9f7e4740a552a239932Kapileshwar Singh        fig_params["fill_graph"] = self._attr["fill"]
198b9e8f11cfd24c71e4634a3b23ba3704841e636d9Kapileshwar Singh        fig_params["per_line"] = self._attr["per_line"]
199b9e8f11cfd24c71e4634a3b23ba3704841e636d9Kapileshwar Singh        fig_params["height"] = self._attr["height"]
2008741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
2017ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh        self._check_add_scatter(fig_params)
2027ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh
20367527ddea39e858c957997356a16bd8e3819f359Kapileshwar Singh        if "group" in self._attr:
20467527ddea39e858c957997356a16bd8e3819f359Kapileshwar Singh            fig_params["syncGroup"] = self._attr["group"]
20567527ddea39e858c957997356a16bd8e3819f359Kapileshwar Singh            if "sync_zoom" in self._attr:
20667527ddea39e858c957997356a16bd8e3819f359Kapileshwar Singh                fig_params["syncZoom"] = self._attr["sync_zoom"]
20767527ddea39e858c957997356a16bd8e3819f359Kapileshwar Singh            else:
20867527ddea39e858c957997356a16bd8e3819f359Kapileshwar Singh                fig_params["syncZoom"] = AttrConf.DEFAULT_SYNC_ZOOM
20967527ddea39e858c957997356a16bd8e3819f359Kapileshwar Singh
2104462468766dabe30a7c58c655807c4c2ede0fdccKapileshwar Singh        if "ylim" in self._attr:
2114462468766dabe30a7c58c655807c4c2ede0fdccKapileshwar Singh            fig_params["valueRange"] = self._attr["ylim"]
2124462468766dabe30a7c58c655807c4c2ede0fdccKapileshwar Singh
213c972b86eac3c41c14b4063f0a4c79b371ebe739cKapileshwar Singh        if "xlim" in self._attr:
214c972b86eac3c41c14b4063f0a4c79b371ebe739cKapileshwar Singh            fig_params["dateWindow"] = self._attr["xlim"]
215c972b86eac3c41c14b4063f0a4c79b371ebe739cKapileshwar Singh
216f2666cb3e55dfc7812d6c170f992190e795602cfJavi Merino        if not test:
217f2666cb3e55dfc7812d6c170f992190e795602cfJavi Merino            json_file = os.path.join(IPythonConf.get_data_path(), fig_name + ".json")
218f2666cb3e55dfc7812d6c170f992190e795602cfJavi Merino            fh = open(json_file, "w")
219f2666cb3e55dfc7812d6c170f992190e795602cfJavi Merino            json.dump(fig_params, fh)
220f2666cb3e55dfc7812d6c170f992190e795602cfJavi Merino            fh.close()
2218741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
2228741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh    def finish(self):
2238741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        """Called when the Plotting is finished"""
2248741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
225211860fe53efaa299db6ff6c9b28816bcb5902d4Kapileshwar Singh        display(HTML(self.html()))
2268741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
2278741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh    def html(self):
2288741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        """Return the raw HTML text"""
2298741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
2308741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        return "\n".join(self._html)
231