ILinePlotGen.py revision 7c1bbd549ab76cff58409d91bcb4749cc06d4d15
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
537c1bbd549ab76cff58409d91bcb4749cc06d4d15Javi Merino        graph_js = ''
54215d9fffd7b77a10c8106c539bb1235847cafdf6Javi Merino        lib_urls =  [IPythonConf.DYGRAPH_COMBINED_URL, IPythonConf.DYGRAPH_SYNC_URL,
55215d9fffd7b77a10c8106c539bb1235847cafdf6Javi Merino                     IPythonConf.UNDERSCORE_URL]
56215d9fffd7b77a10c8106c539bb1235847cafdf6Javi Merino        for url in lib_urls:
577c1bbd549ab76cff58409d91bcb4749cc06d4d15Javi Merino            graph_js += '<!-- TRAPPY_PUBLISH_SOURCE_LIB = "{}" -->\n'.format(url)
58215d9fffd7b77a10c8106c539bb1235847cafdf6Javi Merino
597c1bbd549ab76cff58409d91bcb4749cc06d4d15Javi Merino        graph_js += """
604aa15c0de680a339ba3e7acf300aaa089f3eb4caKapileshwar Singh            <script>
61215d9fffd7b77a10c8106c539bb1235847cafdf6Javi Merino            /* TRAPPY_PUBLISH_IMPORT = "plotter/js/ILinePlot.js" */
62215d9fffd7b77a10c8106c539bb1235847cafdf6Javi Merino            /* TRAPPY_PUBLISH_REMOVE_START */
634aa15c0de680a339ba3e7acf300aaa089f3eb4caKapileshwar Singh            var ilp_req = require.config( {
644aa15c0de680a339ba3e7acf300aaa089f3eb4caKapileshwar Singh
6507ac8dd8c8093d432390078dab4dce61906e421dKapileshwar Singh                paths: {
6653de9b352977814c37608788cc1df83fc6485371Kapileshwar Singh                    "dygraph-sync": '""" + IPythonConf.add_web_base("plotter_scripts/ILinePlot/synchronizer") + """',
6753de9b352977814c37608788cc1df83fc6485371Kapileshwar Singh                    "dygraph": '""" + IPythonConf.add_web_base("plotter_scripts/ILinePlot/dygraph-combined") + """',
6853de9b352977814c37608788cc1df83fc6485371Kapileshwar Singh                    "ILinePlot": '""" + IPythonConf.add_web_base("plotter_scripts/ILinePlot/ILinePlot") + """',
69324d33688bde12601302cbad42e3487c37364817Kapileshwar Singh                    "underscore": '""" + IPythonConf.add_web_base("plotter_scripts/ILinePlot/underscore-min") + """',
7007ac8dd8c8093d432390078dab4dce61906e421dKapileshwar Singh                },
7107ac8dd8c8093d432390078dab4dce61906e421dKapileshwar Singh
724aa15c0de680a339ba3e7acf300aaa089f3eb4caKapileshwar Singh                shim: {
7307ac8dd8c8093d432390078dab4dce61906e421dKapileshwar Singh                    "dygraph-sync": ["dygraph"],
7407ac8dd8c8093d432390078dab4dce61906e421dKapileshwar Singh                    "ILinePlot": {
754aa15c0de680a339ba3e7acf300aaa089f3eb4caKapileshwar Singh
76324d33688bde12601302cbad42e3487c37364817Kapileshwar Singh                        "deps": ["dygraph-sync", "dygraph", "underscore"],
774aa15c0de680a339ba3e7acf300aaa089f3eb4caKapileshwar Singh                        "exports":  "ILinePlot"
784aa15c0de680a339ba3e7acf300aaa089f3eb4caKapileshwar Singh                    }
794aa15c0de680a339ba3e7acf300aaa089f3eb4caKapileshwar Singh                }
804aa15c0de680a339ba3e7acf300aaa089f3eb4caKapileshwar Singh            });
81215d9fffd7b77a10c8106c539bb1235847cafdf6Javi Merino                /* TRAPPY_PUBLISH_REMOVE_STOP */
82215d9fffd7b77a10c8106c539bb1235847cafdf6Javi Merino                ilp_req(["require", "ILinePlot"], function() { /* TRAPPY_PUBLISH_REMOVE_LINE */
8353de9b352977814c37608788cc1df83fc6485371Kapileshwar Singh                ILinePlot.generate('""" + fig_name + """', '""" + IPythonConf.add_web_base("") + """');
84215d9fffd7b77a10c8106c539bb1235847cafdf6Javi Merino            }); /* TRAPPY_PUBLISH_REMOVE_LINE */
85211860fe53efaa299db6ff6c9b28816bcb5902d4Kapileshwar Singh            </script>
86211860fe53efaa299db6ff6c9b28816bcb5902d4Kapileshwar Singh        """
87211860fe53efaa299db6ff6c9b28816bcb5902d4Kapileshwar Singh
887c1bbd549ab76cff58409d91bcb4749cc06d4d15Javi Merino        cell = '<td style="border-style: hidden;"><div class="ilineplot" id="{}"></div></td>'.format(fig_name)
898741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
908741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        self._html.append(cell)
917c1bbd549ab76cff58409d91bcb4749cc06d4d15Javi Merino        self._js.append(graph_js)
928741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
938741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh    def _add_legend_cell(self, fig_name):
948741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        """Add HTML table cell for the legend"""
958741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
968741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        legend_div_name = fig_name + "_legend"
979b4898aa3ea40f2af85157af65ab491e8aaa9b4cMichele Di Giorgio        cell = '<td style="border-style: hidden;"><div style="text-align:center" id="{}"></div></td>'.format(legend_div_name)
988741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
998741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        self._html.append(cell)
1008741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1018741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh    def _begin_row(self):
1028741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        """Add the opening tag for HTML row"""
1038741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1048741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        self._html.append("<tr>")
1058741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1068741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh    def _end_row(self):
1078741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        """Add the closing tag for the HTML row"""
1088741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1098741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        self._html.append("</tr>")
1108741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1117c32bc41bcd9e96c06bb70339334489cb93c663cKapileshwar Singh    def _end_table(self):
1127c32bc41bcd9e96c06bb70339334489cb93c663cKapileshwar Singh        """Add the closing tag for the HTML table"""
1137c32bc41bcd9e96c06bb70339334489cb93c663cKapileshwar Singh
1147c32bc41bcd9e96c06bb70339334489cb93c663cKapileshwar Singh        self._html.append("</table>")
1157c32bc41bcd9e96c06bb70339334489cb93c663cKapileshwar Singh
1168741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh    def _generate_fig_name(self):
1178741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        """Generate a unique figure name"""
1188741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1198741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        fig_name = "fig_" + uuid.uuid4().hex
1208741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        self._fig_map[self._fig_index] = fig_name
1218741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        self._fig_index += 1
1228741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        return fig_name
1238741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1248741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh    def _init_html(self):
1258741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        """Initialize HTML code for the plots"""
1268741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
127b9e8f11cfd24c71e4634a3b23ba3704841e636d9Kapileshwar Singh        table = '<table style="border-style: hidden;">'
1288741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        self._html.append(table)
129b24eed7a902022c014c61f7c8c3061adf53f4eacMichele Di Giorgio        if self._attr["title"]:
130b24eed7a902022c014c61f7c8c3061adf53f4eacMichele Di Giorgio            cell = '<caption style="text-align:center; font: 24px sans-serif bold; color: black">{}</caption>'.format(self._attr["title"])
131b24eed7a902022c014c61f7c8c3061adf53f4eacMichele Di Giorgio            self._html.append(cell)
1328741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1338741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        for _ in range(self._rows):
1348741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh            self._begin_row()
1358741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh            legend_figs = []
1368377bdc6856e004ecc6554008a9e0f556a05b579Michele Di Giorgio            for _ in range(self._attr["per_line"]):
1378741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh                fig_name = self._generate_fig_name()
1388741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh                legend_figs.append(fig_name)
1398741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh                self._add_graph_cell(fig_name)
1408741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1418741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh            self._end_row()
1428741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh            self._begin_row()
1438741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1448741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh            for l_fig in legend_figs:
1458741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh                self._add_legend_cell(l_fig)
1468741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1478741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh            self._end_row()
1488741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1497c32bc41bcd9e96c06bb70339334489cb93c663cKapileshwar Singh        self._end_table()
1507c32bc41bcd9e96c06bb70339334489cb93c663cKapileshwar Singh
1518377bdc6856e004ecc6554008a9e0f556a05b579Michele Di Giorgio    def __init__(self, num_plots, **kwargs):
1528741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
153bd75d5c3abd977e41ce8c9f7e4740a552a239932Kapileshwar Singh        self._attr = kwargs
1548741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        self._html = []
1557c1bbd549ab76cff58409d91bcb4749cc06d4d15Javi Merino        self._js = []
1568741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        self.num_plots = num_plots
1578741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        self._fig_map = {}
1588741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        self._fig_index = 0
1598741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1608741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        self._single_plot = False
1618741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        if self.num_plots == 0:
1628741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh            raise RuntimeError("No plots for the given constraints")
1638741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1648377bdc6856e004ecc6554008a9e0f556a05b579Michele Di Giorgio        if self.num_plots < self._attr["per_line"]:
1658377bdc6856e004ecc6554008a9e0f556a05b579Michele Di Giorgio            self._attr["per_line"] = self.num_plots
1668377bdc6856e004ecc6554008a9e0f556a05b579Michele Di Giorgio        self._rows = (self.num_plots / self._attr["per_line"])
1678741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1688377bdc6856e004ecc6554008a9e0f556a05b579Michele Di Giorgio        if self.num_plots % self._attr["per_line"] != 0:
1698741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh            self._rows += 1
1708741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1718741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        self._attr["height"] = AttrConf.HTML_HEIGHT
1728741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        self._init_html()
1738741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
1747ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh    def _check_add_scatter(self, fig_params):
1757ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh        """Check if a scatter plot is needed
1767ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh        and augment the fig_params accordingly"""
1777ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh
1787ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh        if self._attr["scatter"]:
1797ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh            fig_params["drawPoints"] = True
1807ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh            fig_params["strokeWidth"] = 0.0
1817ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh        else:
1827ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh            fig_params["drawPoints"] = False
1837ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh            fig_params["strokeWidth"] = AttrConf.LINE_WIDTH
1847ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh
1857ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh        fig_params["pointSize"] = self._attr["point_size"]
1867ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh
187aa4bece3adc7f37b8121c84f2515ab2300c132f9Javi Merino    def add_plot(self, plot_num, data_dict, title="", test=False):
18866451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh        """Add a plot for the corresponding index
18966451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh
19066451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh        :param plot_num: The linear index of the plot
19166451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh        :type plot_num: int
19266451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh
193aa4bece3adc7f37b8121c84f2515ab2300c132f9Javi Merino        :param data_dict: The data for the plot
194aa4bece3adc7f37b8121c84f2515ab2300c132f9Javi Merino        :type data_dict: dict
19566451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh
19666451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh        :param title: The title for the plot
19766451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh        :type title: str
19866451b48f106e10658bdce2bd49c852f844db6faKapileshwar Singh        """
1998741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
2008741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        fig_name = self._fig_map[plot_num]
2018741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        fig_params = {}
202aa4bece3adc7f37b8121c84f2515ab2300c132f9Javi Merino        fig_params["data"] = dict((k, v.T.to_dict()) for k, v in data_dict.iteritems())
2038741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        fig_params["name"] = fig_name
2048741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        fig_params["rangesel"] = False
2058741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        fig_params["logscale"] = False
2068741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        fig_params["title"] = title
2078741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        fig_params["step_plot"] = self._attr["step_plot"]
208bd75d5c3abd977e41ce8c9f7e4740a552a239932Kapileshwar Singh        fig_params["fill_graph"] = self._attr["fill"]
209b9e8f11cfd24c71e4634a3b23ba3704841e636d9Kapileshwar Singh        fig_params["per_line"] = self._attr["per_line"]
210b9e8f11cfd24c71e4634a3b23ba3704841e636d9Kapileshwar Singh        fig_params["height"] = self._attr["height"]
2118741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
2127ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh        self._check_add_scatter(fig_params)
2137ab82627f892036d7eeb04af3d282a329f8d04cdKapileshwar Singh
21467527ddea39e858c957997356a16bd8e3819f359Kapileshwar Singh        if "group" in self._attr:
21567527ddea39e858c957997356a16bd8e3819f359Kapileshwar Singh            fig_params["syncGroup"] = self._attr["group"]
21667527ddea39e858c957997356a16bd8e3819f359Kapileshwar Singh            if "sync_zoom" in self._attr:
21767527ddea39e858c957997356a16bd8e3819f359Kapileshwar Singh                fig_params["syncZoom"] = self._attr["sync_zoom"]
21867527ddea39e858c957997356a16bd8e3819f359Kapileshwar Singh            else:
21967527ddea39e858c957997356a16bd8e3819f359Kapileshwar Singh                fig_params["syncZoom"] = AttrConf.DEFAULT_SYNC_ZOOM
22067527ddea39e858c957997356a16bd8e3819f359Kapileshwar Singh
2214462468766dabe30a7c58c655807c4c2ede0fdccKapileshwar Singh        if "ylim" in self._attr:
2224462468766dabe30a7c58c655807c4c2ede0fdccKapileshwar Singh            fig_params["valueRange"] = self._attr["ylim"]
2234462468766dabe30a7c58c655807c4c2ede0fdccKapileshwar Singh
224c972b86eac3c41c14b4063f0a4c79b371ebe739cKapileshwar Singh        if "xlim" in self._attr:
225c972b86eac3c41c14b4063f0a4c79b371ebe739cKapileshwar Singh            fig_params["dateWindow"] = self._attr["xlim"]
226c972b86eac3c41c14b4063f0a4c79b371ebe739cKapileshwar Singh
227f2666cb3e55dfc7812d6c170f992190e795602cfJavi Merino        if not test:
228f2666cb3e55dfc7812d6c170f992190e795602cfJavi Merino            json_file = os.path.join(IPythonConf.get_data_path(), fig_name + ".json")
229f2666cb3e55dfc7812d6c170f992190e795602cfJavi Merino            fh = open(json_file, "w")
230f2666cb3e55dfc7812d6c170f992190e795602cfJavi Merino            json.dump(fig_params, fh)
231f2666cb3e55dfc7812d6c170f992190e795602cfJavi Merino            fh.close()
2328741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
2338741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh    def finish(self):
2348741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        """Called when the Plotting is finished"""
2358741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
236211860fe53efaa299db6ff6c9b28816bcb5902d4Kapileshwar Singh        display(HTML(self.html()))
2378741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
2388741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh    def html(self):
2398741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh        """Return the raw HTML text"""
2408741ef170bc7fcc772837fd2db3df2f8d74b6c10Kapileshwar Singh
2417c1bbd549ab76cff58409d91bcb4749cc06d4d15Javi Merino        return "\n".join(self._html + self._js)
242