mpld3:如何使用插件更改工具栏的位置? [英] mpld3: How to change the location of the toolbar using a plugin?

查看:352
本文介绍了mpld3:如何使用插件更改工具栏的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

mpld3显示的工具栏通常位于屏幕的右下角。我想它在屏幕的右上角。看起来好像控制工具栏位置的代码可以位于此处



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

解决方案

这是一个简单的 mpld3 图的顶部:

  class TopToolbar(plugins.PluginBase):
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(){
//工具栏svg不存在
//但是,首先绘制
this.fig。 toolbar.draw();

//然后将y位置改为
//在图的顶部
this.fig.toolbar.toolbar.attr( y,2);

//然后删除绘制函数
//以便不再调用
this.fig.toolbar.draw = function() {}
}

def __init __(self):
self.dict_ = {type:toptoolbar}



您可以在这里的笔记本


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.

解决方案

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.

这篇关于mpld3:如何使用插件更改工具栏的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆