简体   繁体   中英

Unhide toolbar in MPLD3

Is there an existing plugin for mpld3 that stops the toolbar from autohiding? In general, I am trying to make the toolbar more visible, so any existing plugins modifying the toolbar (making it larger, more opaque, etc) would be helpful. I saw this answer but unfortunately I don't think I know enough javascript to know how to generalize it to modify other parts of the toolbar.

It is possible to adapt the TopToolbar example to make a persistent toolbar. This javascript stuff is a bit fiddly, so here is the code, and if you want more details on why, let me know.

class TweakToolbar(plugins.PluginBase):
    """Plugin for changing toolbar"""

    JAVASCRIPT = """
    mpld3.register_plugin("tweaktoolbar", TweakToolbar);
    TweakToolbar.prototype = Object.create(mpld3.Plugin.prototype);
    TweakToolbar.prototype.constructor = TweakToolbar;
    function TweakToolbar(fig, props){
        mpld3.Plugin.call(this, fig, props);
    };

    TweakToolbar.prototype.draw = function(){
      // the toolbar svg doesn't exist
      // yet, so first draw it
      this.fig.toolbar.draw();

      // then change the toolbar as desired

      // show toolbar
      this.fig.toolbar.buttonsobj.transition(750).attr("y", 0);

      // remove event triggers
      this.fig.canvas
        .on("mouseenter", null)
        .on("mouseleave", null)
        .on("touchenter", null)
        .on("touchstart", null);


      // then remove the draw function,
      // so that it is not called again
      this.fig.toolbar.draw = function() {}
    }
    """
    def __init__(self):
        self.dict_ = {"type": "tweaktoolbar"}

Here is a notebook that shows it in context .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM