def d3(self, line, cell):
src = line if len(line) > 0 else "3.5.17"
s = """
<script>
requirejs.config({
paths: {
d3: "//cdnjs.cloudflare.com/ajax/libs/d3/""" + src + """/d3"
}
});
require(['d3'], function(d3) {
window.d3 = d3;
});
</script>
<script>
_select = d3.select;
d3.select""" + str(self.max_id) + """ = function(selection) {
return _select("#d3-cell-""" + str(self.max_id) + """").select(selection);
}
d3.selectAll""" + str(self.max_id) + """ = function(selection) {
return _select("#d3-cell-""" + str(self.max_id) + """").selectAll(selection);
}
</script>
<g id="d3-cell-""" + str(self.max_id) + """">
"""
cell = re.sub('d3.select\((?!this)', "d3.select" + str(self.max_id) + "(", cell)
cell = re.sub('d3.selectAll\((?!this)', "d3.selectAll" + str(self.max_id) + "(", cell)
s += cell + "\n</g>"
# print(s) # Useful for debugging.
h = HTML(s)
self.max_id += 1
display(h)
评论列表
文章目录