How to use the mpld3.plugins.PluginBase function in mpld3

To help you get started, we’ve selected a few mpld3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Patent2net / P2N / Patent2Net / P2N-Cluster.py View on Github external
// then change the y position to be
      // at the top of the figure
      this.fig.toolbar.toolbar.attr("x", 1200);
      this.fig.toolbar.toolbar.attr("y", 310);

      // then remove the draw function,
      // so that it is not called again
      this.fig.toolbar.draw = function() {}
    }
    
    """
    def __init__(self):
        self.dict_ = {"type": "toptoolbar"}
        
class ClickInfo(mpld3.plugins.PluginBase):
    """Hack of mpld3 Plugin for getting info on click adding "on mouse over" tooltip function   """

    JAVASCRIPT = """
    mpld3.register_plugin("ClickInfo", ClickInfo);
    ClickInfo.prototype = Object.create(mpld3.Plugin.prototype);
    ClickInfo.prototype.constructor = ClickInfo;
    ClickInfo.prototype.requiredProps = ["id", "urls", "labels"];
    ClickInfo.prototype.defaultProps = {hoffset:10,
                                                voffset:10};
        
    function ClickInfo(fig, props){
        mpld3.Plugin.call(this, fig, props);
    };

    ClickInfo.prototype.draw = function(){
        var obj = mpld3.get_element(this.props.id);
github thunder-project / thunder / python / thunder / viz / plugins.py View on Github external
};
    """

    def __init__(self, points, line, linedata):
        if isinstance(points, matplotlib.lines.Line2D):
            suffix = "pts"
        else:
            suffix = None

        self.dict_ = {"type": "linkedview",
                      "idpts": utils.get_id(points, suffix),
                      "idline": utils.get_id(line),
                      "data": linedata}


class HiddenAxes(plugins.PluginBase):

    def __init__(self):
        self.dict_ = {"type": "hiddenaxes"}
        self.css_ = """
            g.mpld3-xaxis, g.mpld3-yaxis {
github dparks1134 / RefineM / refinem / plots / mpld3_plugins.py View on Github external
# Additional script to add at global scope.
    script_global = ('var selected_points = []\n'
                        'function clear_selection_list() {\n'
                            'selected_points = []\n'
                            'var div = document.getElementById("selected_points");\n'
                            'div.innerHTML = "";\n'
                        '};\n')

    # Additional HTML to add to body
    html_body = ('<hr>\n'
                    '<div id="selected_points"></div>\n'
                    '<br>\n'
                    '<button>Clear</button>\n')
            
            
class LinkedBrushSave(mpld3.plugins.PluginBase):
    JAVASCRIPT="""
      mpld3.LinkedBrushSavePlugin = mpld3_LinkedBrushSavePlugin;
      mpld3.register_plugin("linkedbrushsave", mpld3_LinkedBrushSavePlugin);
      mpld3_LinkedBrushSavePlugin.prototype = Object.create(mpld3.Plugin.prototype);
      mpld3_LinkedBrushSavePlugin.prototype.constructor = mpld3_LinkedBrushSavePlugin;
      mpld3_LinkedBrushSavePlugin.prototype.requiredProps = [ "id" ];
      mpld3_LinkedBrushSavePlugin.prototype.defaultProps = {
        labels:null,
        button: true,
        enabled: null
      };
      function mpld3_LinkedBrushSavePlugin(fig, props) {
        mpld3.Plugin.call(this, fig, props);
        if (this.props.enabled === null) {
          this.props.enabled = !this.props.button;
        }
github dparks1134 / RefineM / refinem / plots / mpld3_plugins.py View on Github external
this.disable();
        };
    """

    def __init__(self, points, button=True, enabled=True):
        if isinstance(points, matplotlib.lines.Line2D):
            suffix = "pts"
        else:
            suffix = None
        self.dict_ = {"type": "refinem_linkedbrush",
                      "button": button,
                      "enabled": False,
                      "id": mpld3.utils.get_id(points, suffix)}


class Tooltip(mpld3.plugins.PluginBase):
    """A Plugin to enable an HTML tooltip.

    This extends the PointHTMLTooltip class in mpld3. It adds
    a mousedown() event which writes the label of clicked
    points to an HTML element with the id 'selected_points'.

    formated text which hovers over points.
    Parameters
    ----------
    points : matplotlib Collection or Line2D object
        The figure element to apply the tooltip to
    labels : list
        The labels for each point in points, as strings of unescaped HTML.
    hoffset, voffset : integer, optional
        The number of pixels to offset the tooltip text.  Default is
        hoffset = 0, voffset = 10
github hugadams / scikit-spectra / skspec / interact / ipynbs / line_plugin.py View on Github external
# CREDIT TO JAKE VANDERPLAUS MPLD3 FOR THIS EXAMPLE

import mpld3
from mpld3 import plugins, utils

# for color.  "stroke", "red" instead of "stroke-opacity", alpha-fg

#http://www.d3noob.org/2014/02/styles-in-d3js.html
class HighlightLines(plugins.PluginBase):
    """A plugin to highlight lines on hover"""

    JAVASCRIPT = """
    mpld3.register_plugin("linehighlight", LineHighlightPlugin);
    LineHighlightPlugin.prototype = Object.create(mpld3.Plugin.prototype);
    LineHighlightPlugin.prototype.constructor = LineHighlightPlugin;
    LineHighlightPlugin.prototype.requiredProps = ["line_ids"];
    LineHighlightPlugin.prototype.defaultProps = {alpha_bg:1.0, alpha_fg:0.1}
    function LineHighlightPlugin(fig, props){
        mpld3.Plugin.call(this, fig, props);
    };

    LineHighlightPlugin.prototype.draw = function(){
      for(var i=0; i
github jcornford / pyecog / pyecog / visualisation / javascript.py View on Github external
}
      pts.elements().on("mouseover", mouseover);
    };
    """

    def __init__(self, points, line, linedata):
        if isinstance(points, matplotlib.lines.Line2D):
            suffix = "pts"
        else:
            suffix = None

        self.dict_ = {"type": "linkedview",
                      "idpts": utils.get_id(points, suffix),
                      "idline": utils.get_id(line),
                      "data": linedata}
class ClickInfo(plugins.PluginBase):
    """Plugin for getting info on click"""
    
    JAVASCRIPT = """
    mpld3.register_plugin("clickinfo", ClickInfo);
    ClickInfo.prototype = Object.create(mpld3.Plugin.prototype);
    ClickInfo.prototype.constructor = ClickInfo;
    ClickInfo.prototype.requiredProps = ["id"];
    function ClickInfo(fig, props){
        mpld3.Plugin.call(this, fig, props);
    };
    
    ClickInfo.prototype.draw = function(){
        var obj = mpld3.get_element(this.props.id);
        obj.elements().on("mousedown",
                          function(d, i){alert("clicked on points[" + i + "]");});
    }
github gwastro / pycbc / pycbc / results / mpld3_utils.py View on Github external
var links = this.props.links;

        obj.elements().on("mousedown",
                          function(d, i){
                                           window.open(links[i]);
                                        }
                          );
    }
    """
    def __init__(self, points, links):
        self.dict_ = {"type": "clicklink",
                      "id": mpld3.utils.get_id(points),
                      "links": links,
                      }

class MPLSlide(mpld3.plugins.PluginBase):
    JAVASCRIPT = """
         mpld3.Axes.prototype.zoomed = function(propagate) {
            propagate = typeof propagate == "undefined" ? true : propagate;
            if (propagate) {
              var dt0 = this.zoom.translate()[0] - this.zoom.last_t[0];
              var dt1 = this.zoom.translate()[1] - this.zoom.last_t[1];
              var ds = this.zoom.scale() / this.zoom.last_s;
              this.zoom_x.translate([ this.zoom_x.translate()[0] + dt0, 0 ]);
              this.zoom_x.scale(this.zoom_x.scale() * ds);

              this.zoom.last_t = this.zoom.translate();
              this.zoom.last_s = this.zoom.scale();
              this.sharex.forEach(function(ax) {
                ax.zoom_x.translate(this.zoom_x.translate()).scale(this.zoom_x.scale());
              }.bind(this));
github tim-fiola / network_traffic_modeler_py3 / examples / graph_network / graph_network_interactive.py View on Github external
import networkx as nx
from networkx.readwrite import json_graph
import threading
import time


#######################################
# These 2 lines are needed to avoid the user interface crashing due to some
# problem with Tkinter interaction with matplotlib when importing Model
# into the ui code
import matplotlib as mpl
mpl.use("TkAgg")
########################################


class LinkedDragPlugin(plugins.PluginBase):
    JAVASCRIPT = r"""
    mpld3.register_plugin("drag", DragPlugin);
    DragPlugin.prototype = Object.create(mpld3.Plugin.prototype);
    DragPlugin.prototype.constructor = DragPlugin;
    DragPlugin.prototype.requiredProps = ["idpts", "idline"];
    DragPlugin.prototype.defaultProps = {}
    function DragPlugin(fig, props){
        mpld3.Plugin.call(this, fig, props);
    };

    DragPlugin.prototype.draw = function(){
        var ptsobj = mpld3.get_element(this.props.idpts, this.fig);
        var lineobj = mpld3.get_element(this.props.idline, this.fig);

        var drag = d3.behavior.drag()
            .origin(function(d) { return {x:ptsobj.ax.x(d[0]),
github sglebs / srccheck / utilities / utils.py View on Github external
from matplotlib import pyplot as plt
plt.ioff()  # fixes #32 - no need for an interactive backend
import mpld3
from utilities.complex_radar import ComplexRadar
import sys

def insert_understand_in_path(dllDir):
    sys.path.insert(0, dllDir)  # add the dir with the DLLs - Qt etc
    os.environ["PATH"] = dllDir + os.pathsep + os.environ["PATH"]  # prepend
    sys.path.insert(0, os.path.join(dllDir, "Python"))  # also needed, For interop
    sys.path.insert(0, os.path.join(dllDir,
                                    "python"))  # also needed, For interop with older versions of Understand (which used lowercase)
    # hangs!!!!! os.environ["PYTHONPATH"] = os.path.join(dllDir,"python") + os.pathsep + os.environ.get("PYTHONPATH", "") # prepend


class ClickSendToBack(mpld3.plugins.PluginBase):
    """Plugin for sending element to the back. Combined https://mpld3.github.io/notebooks/custom_plugins.html and http://bl.ocks.org/eesur/4e0a69d57d3bfc8a82c2"""

    JAVASCRIPT = """
    d3.selection.prototype.moveToBack = function() {
        return this.each(function() {
            var firstChild = this.parentNode.firstChild;
            if (firstChild) {
                this.parentNode.insertBefore(this, firstChild);
            }
        });
    };
    mpld3.register_plugin("clicksendtoback", ClickSendToBackPlugin);
    ClickSendToBackPlugin.prototype = Object.create(mpld3.Plugin.prototype);
    ClickSendToBackPlugin.prototype.constructor = ClickSendToBackPlugin;
    ClickSendToBackPlugin.prototype.requiredProps = ["id"];
    function ClickSendToBackPlugin(fig, props){
github thunder-project / thunder / python / thunder / viz / plugins.py View on Github external
import matplotlib
from mpld3 import plugins, utils


class LinkedView(plugins.PluginBase):
    """A plugin """

    JAVASCRIPT = """
    mpld3.register_plugin("linkedview", LinkedViewPlugin);
    LinkedViewPlugin.prototype = Object.create(mpld3.Plugin.prototype);
    LinkedViewPlugin.prototype.constructor = LinkedViewPlugin;
    LinkedViewPlugin.prototype.requiredProps = ["idpts", "idline", "data"];
    LinkedViewPlugin.prototype.defaultProps = {}
    function LinkedViewPlugin(fig, props){
        mpld3.Plugin.call(this, fig, props);
    };

    LinkedViewPlugin.prototype.draw = function(){
      var pts = mpld3.get_element(this.props.idpts);
      var line = mpld3.get_element(this.props.idline);
      var data = this.props.data;