py_d3.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:py_d3 作者: ResidentMario 项目源码 文件源码
def __init__(self, **kwargs):
        super(D3Magics, self).__init__(**kwargs)
        self.max_id = 0  # Used to ensure that the current group selection is unique.
        # self.initialized = True  # Used to ensure that d3.js is only imported once.

    # # The necessary substitutions to get a block working are theoretically possible, but too quirky for the moment
    # to consider.
    # @line_magic
    # def block(self, line):
    #     user, gist_id = line.split("/")[-2:]
    #     r = requests.get("https://gist.github.com/{0}/{1}/download".format(user, gist_id))
    #     with zipfile.ZipFile(io.BytesIO(r.content)) as ar:
    #         ar.extractall(".blocks/{0}/".format(user, gist_id))
    #         # This creates e.g. ".blocks/mbostock/3885304-master" in the root directory.
    #         # The appended "-master" is due to the format of the zipped file.
    #         # It's a little unideal, but unsure about whether or not removing it would cause any issues I've kept it
    #         # for the time being (you could easily rename the folder).
    #     with open(".blocks/{0}/{1}-master/index.html".format(user, gist_id), "r") as f:
    #         source = f.read()
    #     # We need to perform a few substutions to make the figure work within a Jupyter Notebook file.
    #     # 1. <body> tags are not allowed within a D3 notebook (one has already been defined and HTML documents only
    #     #    allow one <body> and one <head>), but are probably the most common initial selector of all for defining
    #     #    the initial D3 frame. To fix:
    #     #    >>> <body>                 -->     <g>
    #     #    >>> d3.select("body")      -->     d3.select("g")
    #     #    >>> <body id="foo">        -->     ???
    #     #    >>> <body class="foo">     -->     ???
    #     source = source.replace('<body', '<g')
    #     source = source.replace("select('body", "select(g")
    #     source = source.replace('d3.tsv("', 'd3.tsv("./.blocks/{0}/{1}-master/'.format(user, gist_id))
    #     print(HTML(source).data)
    #     display(HTML(source))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号