问题
The toolbar for mpld3 displays is usually located in the bottom right corner of the screen. I would like it to be in the top-right corner of the screen. It appears as though the code controlling the position of the toolbar can be located here.
I would like to know how to select the toolbar object using Javascript so that I may change it's location. The Javascript code would ideally be the attribute of some custom mpld3 plugin.
回答1:
Here is a simple mpld3
plugin to move the toolbar to the top of a figure:
class TopToolbar(plugins.PluginBase):
"""Plugin for moving toolbar to top of figure"""
JAVASCRIPT = """
mpld3.register_plugin("toptoolbar", TopToolbar);
TopToolbar.prototype = Object.create(mpld3.Plugin.prototype);
TopToolbar.prototype.constructor = TopToolbar;
function TopToolbar(fig, props){
mpld3.Plugin.call(this, fig, props);
};
TopToolbar.prototype.draw = function(){
// the toolbar svg doesn't exist
// yet, so first draw it
this.fig.toolbar.draw();
// then change the y position to be
// at the top of the figure
this.fig.toolbar.toolbar.attr("y", 2);
// then remove the draw function,
// so that it is not called again
this.fig.toolbar.draw = function() {}
}
"""
def __init__(self):
self.dict_ = {"type": "toptoolbar"}
You can see it in action in a notebook here.
来源:https://stackoverflow.com/questions/26593759/mpld3-how-to-change-the-location-of-the-toolbar-using-a-plugin