首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >mpld3:如何使用插件更改工具栏的位置?

mpld3:如何使用插件更改工具栏的位置?
EN

Stack Overflow用户
提问于 2014-10-27 17:53:37
回答 1查看 406关注 0票数 3

mpld3显示工具栏通常位于屏幕右下角。我希望它在屏幕的右上角。似乎控制工具栏位置的代码可以定位为这里

我想知道如何使用Javascript选择工具栏对象,以便更改它的位置。理想情况下,Javascript代码是一些自定义mpld3插件的属性。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-27 18:45:06

下面是一个简单的mpld3插件,可以将工具栏移动到图形的顶部:

代码语言:javascript
复制
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"}

您可以在这里有本笔记本中看到它的作用。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26593759

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档