B
    d9                 @   sx  d Z ddddddddd	d
dgZddlZddlZddlZddlZyddlmZ W n  ek
rn   ddlmZ Y nX ddl	m
Z
 dd Zdd Zdd ZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd
 d
eZG dd deZG dd	 d	eZG dd deZG d d! d!eZG d"d# d#eZG d$d% d%eZe e e gZdS )&a6  
Plugins to add behavior to mpld3 charts
=======================================

Plugins are means of adding additional javascript features to D3-rendered
matplotlib plots.  A number of plugins are defined here; it is also possible
to create nearly any imaginable behavior by defining your own custom plugin.
connectclearget_plugins
PluginBaseResetZoomBoxZoomPointLabelTooltipPointHTMLTooltipLineLabelTooltipMousePosition    N)Iterable   )get_idc             C   s   t |  | jS )z%Get the list of plugins in the figure)r   mpld3_plugins)fig r   Z/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/mpld3/plugins.pyr      s    c             G   sL   t | tjjstdt| ds.tdd | _x|D ]}| j| q4W dS )a  Connect one or more plugins to a figure

    Parameters
    ----------
    fig : matplotlib Figure instance
        The figure to which the plugins will be connected

    *plugins :
        Additional arguments should be plugins which will be connected
        to the figure.

    Examples
    --------
    >>> import matplotlib.pyplot as plt
    >>> from mpld3 import plugins
    >>> fig, ax = plt.subplots()
    >>> lines = ax.plot(range(10), '-k')
    >>> plugins.connect(fig, plugins.LineLabelTooltip(lines[0]))
    z0plugins.connect: first argument must be a figurer   N)	
isinstance
matplotlibZfigureZFigure
ValueErrorhasattrDEFAULT_PLUGINSr   append)r   pluginspluginr   r   r   r   !   s    

c             C   s
   g | _ dS )z5Clear all plugins from the figure, including defaultsN)r   )r   r   r   r   r   =   s    c               @   s$   e Zd Zdd Zdd Zdd ZdS )r   c             C   s   | j S )N)dict_)selfr   r   r   get_dictC   s    zPluginBase.get_dictc             C   s2   t | dr*t | dr"| j| jS | jS ndS d S )N
JAVASCRIPTjs_args_ )r   r   renderr    )r   r   r   r   
javascriptF   s
    

zPluginBase.javascriptc             C   s   t | dr| jS dS d S )Ncss_r!   )r   r$   )r   r   r   r   cssO   s    
zPluginBase.cssN)__name__
__module____qualname__r   r#   r%   r   r   r   r   r   B   s   	c               @   s   e Zd ZdZddiZdS )r   zA Plugin to add a reset buttontyperesetN)r&   r'   r(   __doc__r   r   r   r   r   r   V   s   c               @   s   e Zd ZdZdddZdS )r   aL  A Plugin to display coordinates for the current mouse position

    Example
    -------
    >>> import matplotlib.pyplot as plt
    >>> from mpld3 import fig_to_html, plugins
    >>> fig, ax = plt.subplots()
    >>> points = ax.plot(range(10), 'o')
    >>> plugins.connect(fig, plugins.MousePosition())
    >>> fig_to_html(fig)
       .3gc             C   s   d||d| _ d S )NZmouseposition)r)   fontsizefmt)r   )r   r.   r/   r   r   r   __init__h   s    zMousePosition.__init__N)r,   r-   )r&   r'   r(   r+   r0   r   r   r   r   r   [   s   c               @   s   e Zd ZdZdddZdS )r   a  A Plugin to add zoom behavior to the plot

    Parameters
    ----------
    button : boolean, optional
        if True (default), then add a button to enable/disable zoom behavior
    enabled : boolean, optional
        specify whether the zoom should be enabled by default. By default,
        zoom is enabled if button == False, and disabled if button == True.

    Notes
    -----
    Even if ``enabled`` is specified, other plugins may modify this state.
    TNc             C   s    |d kr| }d||d| _ d S )NZzoom)r)   buttonenabled)r   )r   r1   r2   r   r   r   r0   }   s
    zZoom.__init__)TN)r&   r'   r(   r+   r0   r   r   r   r   r   n   s   c               @   s   e Zd ZdZdddZdS )r   a  A Plugin to add box-zoom behavior to the plot

    Parameters
    ----------
    button : boolean, optional
        if True (default), then add a button to enable/disable zoom behavior
    enabled : boolean, optional
        specify whether the zoom should be enabled by default. By default,
        zoom is enabled if button == False, and disabled if button == True.

    Notes
    -----
    Even if ``enabled`` is specified, other plugins may modify this state.
    TNc             C   s    |d kr| }d||d| _ d S )NZboxzoom)r)   r1   r2   )r   )r   r1   r2   r   r   r   r0      s
    zBoxZoom.__init__)TN)r&   r'   r(   r+   r0   r   r   r   r   r      s   c               @   s   e Zd ZdZdddZdS )	r   a  A Plugin to enable a tooltip: text which hovers over points.

    Parameters
    ----------
    points : matplotlib Collection or Line2D object
        The figure element to apply the tooltip to
    labels : array or None
        If supplied, specify the labels for each point in points.  If not
        supplied, the (x, y) values will be used.
    hoffset, voffset : integer
        The number of pixels to offset the tooltip text.  Default is
        hoffset = 0, voffset = 10

    Examples
    --------
    >>> import matplotlib.pyplot as plt
    >>> from mpld3 import fig_to_html, plugins
    >>> fig, ax = plt.subplots()
    >>> points = ax.plot(range(10), 'o')
    >>> plugins.connect(fig, PointLabelTooltip(points[0]))
    >>> fig_to_html(fig)
    Nr   
   mousec             C   sL   |dkrt d|t|tjjr*d}nd }dt||||||d| _d S )N)zbottom leftztop leftzbottom rightz	top rightr4   zinvalid location: {0}ptstooltip)r)   idlabelshoffsetvoffsetlocation)r   formatr   r   linesLine2Dr   r   )r   pointsr8   r9   r:   r;   suffixr   r   r   r0      s    zPointLabelTooltip.__init__)Nr   r3   r4   )r&   r'   r(   r+   r0   r   r   r   r   r      s    c               @   s   e Zd ZdZdddZdS )	r
   a  A Plugin to enable a tooltip: text which hovers over a line.

    Parameters
    ----------
    line : matplotlib Line2D object
        The figure element to apply the tooltip to
    label : string
        If supplied, specify the labels for each point in points.  If not
        supplied, the (x, y) values will be used.
    hoffset, voffset : integer
        The number of pixels to offset the tooltip text.  Default is
        hoffset = 0, voffset = 10

    Examples
    --------
    >>> import matplotlib.pyplot as plt
    >>> from mpld3 import fig_to_html, plugins
    >>> fig, ax = plt.subplots()
    >>> lines = ax.plot(range(10), 'o')
    >>> plugins.connect(fig, LineLabelTooltip(lines[0]))
    >>> fig_to_html(fig)
    Nr   r3   r4   c             C   s@   |dkrt d|dt||d kr*|n|g|||d| _d S )N)zbottom leftztop leftzbottom rightz	top rightr4   zinvalid location: {0}r6   )r)   r7   r8   r9   r:   r;   )r   r<   r   r   )r   r?   labelr9   r:   r;   r   r   r   r0      s    zLineLabelTooltip.__init__)Nr   r3   r4   )r&   r'   r(   r+   r0   r   r   r   r   r
      s    c               @   s   e Zd ZdZdddZdS )LinkedBrusha'  A Plugin to enable linked brushing between plots

    Parameters
    ----------
    points : matplotlib Collection or Line2D object
        A representative of the scatter plot elements to brush.
    button : boolean, optional
        if True (default), then add a button to enable/disable zoom behavior
    enabled : boolean, optional
        specify whether the zoom should be enabled by default. default=True.

    Examples
    --------
    >>> import matplotlib.pyplot as plt
    >>> import numpy as np
    >>> from mpld3 import fig_to_html, plugins
    >>> X = np.random.random((3, 100))
    >>> fig, ax = plt.subplots(3, 3)
    >>> for i in range(2):
    ...     for j in range(2):
    ...         points = ax[i, j].scatter(X[i], X[j])
    >>> plugins.connect(fig, LinkedBrush(points))
    >>> fig_to_html(fig)

    Notes
    -----
    Notice that in the above example, only one of the four sets of points is
    passed to the plugin. This is all that is needed: for the sake of efficient
    data storage, mpld3 keeps track of which plot objects draw from the same
    data.

    Also note that for the linked brushing to work correctly, the data must
    not contain any NaNs. The presence of NaNs makes the different data views
    have different sizes, so that mpld3 is unable to link the related points.
    Tc             C   s2   t |tjjrd}nd }d||t||d| _d S )Nr5   Zlinkedbrush)r)   r1   r2   r7   )r   r   r=   r>   r   r   )r   r?   r1   r2   r@   r   r   r   r0     s    zLinkedBrush.__init__N)TT)r&   r'   r(   r+   r0   r   r   r   r   rB      s   #rB   c               @   s   e Zd ZdZdZdddZdS )	r	   a  A Plugin to enable an HTML tooltip:
    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.
    targets : list
        The urls that each point will open when clicked.
    hoffset, voffset : integer, optional
        The number of pixels to offset the tooltip text.  Default is
        hoffset = 0, voffset = 10
    css : str, optional
        css to be included, for styling the label html if desired
    Examples
    --------
    >>> import matplotlib.pyplot as plt
    >>> from mpld3 import fig_to_html, plugins
    >>> fig, ax = plt.subplots()
    >>> points = ax.plot(range(10), 'o')
    >>> labels = ['<h1>{title}</h1>'.format(title=i) for i in range(10)]
    >>> plugins.connect(fig, PointHTMLTooltip(points[0], labels))
    >>> fig_to_html(fig)
    a  
    mpld3.register_plugin("htmltooltip", HtmlTooltipPlugin);
    HtmlTooltipPlugin.prototype = Object.create(mpld3.Plugin.prototype);
    HtmlTooltipPlugin.prototype.constructor = HtmlTooltipPlugin;
    HtmlTooltipPlugin.prototype.requiredProps = ["id"];
    HtmlTooltipPlugin.prototype.defaultProps = {labels:null,
                                                target:null,
                                                hoffset:0,
                                                voffset:10,
                                                targets:null};
    function HtmlTooltipPlugin(fig, props){
        mpld3.Plugin.call(this, fig, props);
    };

    HtmlTooltipPlugin.prototype.draw = function(){
        var obj = mpld3.get_element(this.props.id);
        var labels = this.props.labels;
        var targets = this.props.targets;
        var tooltip = d3.select("body").append("div")
            .attr("class", "mpld3-tooltip")
            .style("position", "absolute")
            .style("z-index", "10")
            .style("visibility", "hidden");

        obj.elements()
            .on("mouseover", function(d, i){
                tooltip.html(labels[i])
                    .style("visibility", "visible");
            })
            .on("mousemove", function(d, i){
                tooltip
                .style("top", d3.event.pageY + this.props.voffset + "px")
                .style("left",d3.event.pageX + this.props.hoffset + "px");
            }.bind(this))
            .on("mousedown.callout", function(d, i){
                window.open(targets[i],"_blank");
            })
            .on("mouseout", function(d, i){
                tooltip.style("visibility", "hidden");
            });
    };
    Nr   r3   c             C   s^   || _ || _|| _|| _|| _|p$d| _t|tjj	r<d}nd }dt
||||||d| _d S )Nr!   r5   Zhtmltooltip)r)   r7   r8   targetsr9   r:   )r?   r8   rC   r:   r9   r$   r   r   r=   r>   r   r   )r   r?   r8   rC   r9   r:   r%   r@   r   r   r   r0   `  s    
zPointHTMLTooltip.__init__)NNr   r3   N)r&   r'   r(   r+   r   r0   r   r   r   r   r	     s   + c               @   s   e Zd ZdZdZdddZdS )	LineHTMLTooltipaN  A Plugin to enable an HTML tooltip:
    formated text which hovers over points.

    Parameters
    ----------
    points : matplotlib Line2D object
        The figure element to apply the tooltip to
    label : string
        The label for the line, as strings of unescaped HTML.
    hoffset, voffset : integer, optional
        The number of pixels to offset the tooltip text.  Default is
        hoffset = 0, voffset = 10
    css : str, optional
        css to be included, for styling the label html if desired
    Examples
    --------
    >>> import matplotlib.pyplot as plt
    >>> from mpld3 import fig_to_html, plugins
    >>> fig, ax = plt.subplots()
    >>> lines = ax.plot(range(10))
    >>> label = '<h1>line {title}</h1>'.format(title='A')
    >>> plugins.connect(fig, LineHTMLTooltip(lines[0], label))
    >>> fig_to_html(fig)
    a  
    mpld3.register_plugin("linehtmltooltip", LineHTMLTooltip);
    LineHTMLTooltip.prototype = Object.create(mpld3.Plugin.prototype);
    LineHTMLTooltip.prototype.constructor = LineHTMLTooltip;
    LineHTMLTooltip.prototype.requiredProps = ["id"];
    LineHTMLTooltip.prototype.defaultProps = {label:null,
                                              hoffset:0,
                                              voffset:10};
    function LineHTMLTooltip(fig, props){
        mpld3.Plugin.call(this, fig, props);
    };

    LineHTMLTooltip.prototype.draw = function(){
        var obj = mpld3.get_element(this.props.id, this.fig);
        var label = this.props.label
        var tooltip = d3.select("body").append("div")
                    .attr("class", "mpld3-tooltip")
                    .style("position", "absolute")
                    .style("z-index", "10")
                    .style("visibility", "hidden");

        obj.elements()
           .on("mouseover", function(d, i){
                               tooltip.html(label)
                                      .style("visibility", "visible");
                                     })
            .on("mousemove", function(d, i){
                  tooltip
                    .style("top", d3.event.pageY + this.props.voffset + "px")
                    .style("left",d3.event.pageX + this.props.hoffset + "px");
                 }.bind(this))
           .on("mouseout",  function(d, i){
                           tooltip.style("visibility", "hidden");})
    };
    Nr   r3   c             C   s<   || _ || _|| _|| _|pd| _dt||||d| _d S )Nr!   Zlinehtmltooltip)r)   r7   rA   r9   r:   )linerA   r:   r9   r$   r   r   )r   rE   rA   r9   r:   r%   r   r   r   r0     s    
zLineHTMLTooltip.__init__)Nr   r3   N)r&   r'   r(   r+   r   r0   r   r   r   r   rD   t  s
   $  rD   c               @   s*   e Zd ZdZdZdZdd
dZdd ZdS )InteractiveLegendPlugina 	  A plugin for an interactive legends.

    Inspired by http://bl.ocks.org/simzou/6439398

    Parameters
    ----------
    plot_elements : iterable of matplotlib elements
        the elements to associate with a given legend items
    labels : iterable of strings
        The labels for each legend element
    ax :  matplotlib axes instance, optional
        the ax to which the legend belongs. Default is the first
        axes. The legend will be plotted to the right of the specified
        axes
    alpha_unsel : float, optional
        the alpha value to multiply the plot_element(s) associated alpha
        with the legend item when the legend item is unselected.
        Default is 0.2
    alpha_over : float, optional
        the alpha value to multiply the plot_element(s) associated alpha
        with the legend item when the legend item is overlaid.
        Default is 1 (no effect), 1.5 works nicely !
    start_visible : boolean, optional (could be a list of booleans)
        defines if objects should start selected on not.
    font_size : int, optional
        defines legend font-size.
        Default is 10.
    legend_offset : list of int (length: 2)
        defines horizontal offset and vertical offset of legend.
        Default is (0, 0).

    Examples
    --------
    >>> import matplotlib.pyplot as plt
    >>> from mpld3 import fig_to_html, plugins
    >>> N_paths = 5
    >>> N_steps = 100
    >>> x = np.linspace(0, 10, 100)
    >>> y = 0.1 * (np.random.random((N_paths, N_steps)) - 0.5)
    >>> y = y.cumsum(1)
    >>> fig, ax = plt.subplots()
    >>> labels = ["a", "b", "c", "d", "e"]
    >>> line_collections = ax.plot(x, y.T, lw=4, alpha=0.6)
    >>> interactive_legend = plugins.InteractiveLegendPlugin(line_collections,
    ...                                                      labels,
    ...                                                      alpha_unsel=0.2,
    ...                                                      alpha_over=1.5,
    ...                                                      start_visible=True,
    ...                                                      font_size=14,
    ...                                                      legend_offset=(-100,20))
    >>> plugins.connect(fig, interactive_legend)
    >>> fig_to_html(fig)
    a  
    mpld3.register_plugin("interactive_legend", InteractiveLegend);
    InteractiveLegend.prototype = Object.create(mpld3.Plugin.prototype);
    InteractiveLegend.prototype.constructor = InteractiveLegend;
    InteractiveLegend.prototype.requiredProps = ["element_ids", "labels"];
    InteractiveLegend.prototype.defaultProps = {"ax":null,
                                                "alpha_unsel":0.2,
                                                "alpha_over":1.0,
                                                "start_visible":true,
                                                "font_size": 10,
                                                "legend_offset": [0,0]}
    function InteractiveLegend(fig, props){
        mpld3.Plugin.call(this, fig, props);
    };

    InteractiveLegend.prototype.draw = function(){
        var alpha_unsel = this.props.alpha_unsel;
        var alpha_over = this.props.alpha_over;
        var font_size = this.props.font_size;
        var legend_offset = this.props.legend_offset;

        var legendItems = new Array();
        for(var i=0; i<this.props.labels.length; i++){
            var obj = {};
            obj.label = this.props.labels[i];

            var element_id = this.props.element_ids[i];
            mpld3_elements = [];
            for(var j=0; j<element_id.length; j++){
                var mpld3_element = mpld3.get_element(element_id[j], this.fig);

                // mpld3_element might be null in case of Line2D instances
                // for we pass the id for both the line and the markers. Either
                // one might not exist on the D3 side
                if(mpld3_element){
                    mpld3_elements.push(mpld3_element);
                }
            }

            obj.mpld3_elements = mpld3_elements;
            obj.visible = this.props.start_visible[i]; // should become be setable from python side
            legendItems.push(obj);
            set_alphas(obj, false);
        }

        // determine the axes with which this legend is associated
        var ax = this.props.ax
        if(!ax){
            ax = this.fig.axes[0];
        } else{
            ax = mpld3.get_element(ax, this.fig);
        }

        // add a legend group to the canvas of the figure
        var legend = this.fig.canvas.append("svg:g")
                               .attr("class", "legend");

        // add the rectangles
        legend.selectAll("rect")
                .data(legendItems)
                .enter().append("rect")
                .attr("height", 0.7*font_size)
                .attr("width", 1.6*font_size)
                .attr("x", ax.width + ax.position[0] + 15 + legend_offset[0])
                .attr("y",function(d,i) {
                           return ax.position[1] + i * (font_size+5) + 10 + legend_offset[1];})
                .attr("stroke", get_color)
                .attr("class", "legend-box")
                .style("fill", function(d, i) {
                           return d.visible ? get_color(d) : "white";})
                .on("click", click).on('mouseover', over).on('mouseout', out);

        // add the labels
        legend.selectAll("text")
              .data(legendItems)
              .enter().append("text")
              .attr("font-size", font_size)
              .attr("x", function (d) {
                           return ax.width + ax.position[0] + (1.9*font_size+15) + legend_offset[0];})
              .attr("y", function(d,i) {
                           return ax.position[1] + i * (font_size+5) + 10 + (0.72*font_size-1) + legend_offset[1];})
              .text(function(d) { return d.label })
              .on('mouseover', over).on('mouseout', out);


        // specify the action on click
        function click(d,i){
            d.visible = !d.visible;
            d3.select(this)
              .style("fill",function(d, i) {
                return d.visible ? get_color(d) : "white";
              })
            set_alphas(d, false);

        };

        // specify the action on legend overlay 
        function over(d,i){
             set_alphas(d, true);
        };

        // specify the action on legend overlay 
        function out(d,i){
             set_alphas(d, false);
        };

        // helper function for setting alphas
        function set_alphas(d, is_over){
            for(var i=0; i<d.mpld3_elements.length; i++){
                var type = d.mpld3_elements[i].constructor.name;

                if(type =="mpld3_Line"){
                    var current_alpha = d.mpld3_elements[i].props.alpha;
                    var current_alpha_unsel = current_alpha * alpha_unsel;
                    var current_alpha_over = current_alpha * alpha_over;
                    d3.select(d.mpld3_elements[i].path.nodes()[0])
                        .style("stroke-opacity", is_over ? current_alpha_over :
                                                (d.visible ? current_alpha : current_alpha_unsel))
                        .style("stroke-width", is_over ?
                                alpha_over * d.mpld3_elements[i].props.edgewidth : d.mpld3_elements[i].props.edgewidth);
                } else if((type=="mpld3_PathCollection")||
                         (type=="mpld3_Markers")){
                    var current_alpha = d.mpld3_elements[i].props.alphas[0];
                    var current_alpha_unsel = current_alpha * alpha_unsel;
                    var current_alpha_over = current_alpha * alpha_over;
                    d.mpld3_elements[i].pathsobj
                        .style("stroke-opacity", is_over ? current_alpha_over :
                                                (d.visible ? current_alpha : current_alpha_unsel))
                        .style("fill-opacity", is_over ? current_alpha_over :
                                                (d.visible ? current_alpha : current_alpha_unsel));
                } else{
                    console.log(type + " not yet supported");
                }
            }
        };


        // helper function for determining the color of the rectangles
        function get_color(d){
            var type = d.mpld3_elements[0].constructor.name;
            var color = "black";
            if(type =="mpld3_Line"){
                color = d.mpld3_elements[0].props.edgecolor;
            } else if((type=="mpld3_PathCollection")||
                      (type=="mpld3_Markers")){
                color = d.mpld3_elements[0].props.facecolors[0];
            } else{
                console.log(type + " not yet supported");
            }
            return color;
        };
    };
    z4
    .legend-box {
      cursor: pointer;
    }
    N皙?      ?Tr3   r   r   c	       
   
   C   s   || _ |rt|}t|tr,|gt| }n(t|t|ksTtdt|t|| |}	|	| _d|	|||||||d	| _	d S )Nz({} out of {} visible params has been setZinteractive_legend)	r)   Zelement_idsr8   axalpha_unsel
alpha_overstart_visible	font_sizelegend_offset)
rJ   r   r   boollenr   r<   _determine_mpld3idsmpld3_element_idsr   )
r   plot_elementsr8   rJ   rK   rL   rM   rN   rO   rS   r   r   r   r0     s&    

z InteractiveLegendPlugin.__init__c             C   s   g }x|D ]}g }t |tr`xr|D ]8}t|}|| t |tjjr"t|d}|| q"W n0|t| t |tjjrt|d}|| || q
W |S )za
        Helper function to get the mpld3_id for each
        of the specified elements.
        r5   )r   r   r   r   r   r=   r>   )r   rT   rS   entryZidselementZmpld3_idr   r   r   rR     s     







z+InteractiveLegendPlugin._determine_mpld3ids)NrG   rH   Tr3   rI   )r&   r'   r(   r+   r   r$   r0   rR   r   r   r   r   rF     s   5  
rF   c               @   s   e Zd ZdZdZdddZdS )	PointClickableHTMLTooltipa  A plugin for pop-up windows with data with rich HTML

    Parameters
    ----------
    points : matplotlib Collection object
        The figure element to apply the tooltip to
    labels : list
        The labels for each point in points, as strings of unescaped HTML.
    targets : list
        The target data or rich HTML to be displayed when each collection element is clicked
    hoffset, voffset : integer, optional
        The number of pixels to offset the tooltip text.  Default is
        hoffset = 0, voffset = 10
    css : str, optional
        css to be included, for styling the label html and target data/tables, if desired
    Examples
    --------
    >>> import matplotlib.pyplot as plt
    >>> from mpld3 import plugins
    >>> fig, ax = plt.subplots(1,1)
    >>> xx = yy = range(10)
    >>> scat = ax.scatter(xx, range(10))
    >>> targets = map(lambda (x, y): "<marquee>It works!<br><h1>{}, {}</h1></marquee>".format(x, y),
    >>>               zip(xx, yy))
    >>> labels = map(lambda (x, y): "{}, {}".format(x,y), zip(xx, yy))
    >>> from mpld3.plugins import PointClickableHTMLTooltip
    >>> plugins.connect(fig, PointClickableHTMLTooltip(scat, labels=labels, targets=targets))

    a  
    mpld3.register_plugin("clickablehtmltooltip", PointClickableHTMLTooltip);
    PointClickableHTMLTooltip.prototype = Object.create(mpld3.Plugin.prototype);
    PointClickableHTMLTooltip.prototype.constructor = PointClickableHTMLTooltip;
    PointClickableHTMLTooltip.prototype.requiredProps = ["id"];
    PointClickableHTMLTooltip.prototype.defaultProps = {labels:null,
                                                 targets:null,
                                                 hoffset:0,
                                                 voffset:10};
    function PointClickableHTMLTooltip(fig, props){
        mpld3.Plugin.call(this, fig, props);
    };

    PointClickableHTMLTooltip.prototype.draw = function(){
       var obj = mpld3.get_element(this.props.id);
       var labels = this.props.labels;
       var targets = this.props.targets;

       var tooltip = d3.select("body").append("div")
                    .attr("class", "mpld3-tooltip")
                    .style("position", "absolute")
                    .style("z-index", "10")
                    .style("visibility", "hidden");

       obj.elements()
           .on("mouseover", function(d, i){
                  if ($(obj.elements()[0][0]).css( "fill-opacity" ) > 0 || $(obj.elements()[0][0]).css( "stroke-opacity" ) > 0) {
                              tooltip.html(labels[i])
                                     .style("visibility", "visible");
                              } })

           .on("mousedown", function(d, i){
                              window.open().document.write(targets[i]);
                               })
           .on("mousemove", function(d, i){
                  tooltip
                    .style("top", d3.event.pageY + this.props.voffset + "px")
                    .style("left",d3.event.pageX + this.props.hoffset + "px");
                 }.bind(this))
           .on("mouseout",  function(d, i){
                           tooltip.style("visibility", "hidden");});
    };
    N   c       	         s~   | _ | _| _| _| _|p$d _|d k	rDt fdd|}nd }t|tj	j
r\d}nd }dt||||||d _d S )Nr!   c                s
    j |  S )N)r$   )x)r   r   r   <lambda>(      z4PointClickableHTMLTooltip.__init__.<locals>.<lambda>r5   Zclickablehtmltooltip)r)   r7   r8   rC   r9   r:   )r?   r8   rC   r:   r9   r$   mapr   r   r=   r>   r   r   )	r   r?   r8   rC   r9   r:   r%   Zstyled_targetsr@   r   )r   r   r0     s$    
z"PointClickableHTMLTooltip.__init__)NNrX   rY   N)r&   r'   r(   r+   r   r0   r   r   r   r   rW     s   , rW   c               @   s   e Zd ZdZdZdddZdS )	MouseXPositionz2Like MousePosition, but only show the X coordinatea  
  mpld3.register_plugin("mousexposition", MouseXPositionPlugin);
  MouseXPositionPlugin.prototype = Object.create(mpld3.Plugin.prototype);
  MouseXPositionPlugin.prototype.constructor = MouseXPositionPlugin;
  MouseXPositionPlugin.prototype.requiredProps = [];
  MouseXPositionPlugin.prototype.defaultProps = {
    fontsize: 12,
    fmt: "0d"
  };
  function MouseXPositionPlugin(fig, props) {
    mpld3.Plugin.call(this, fig, props);
  }
  MouseXPositionPlugin.prototype.draw = function() {
    var fig = this.fig;
    var fmt = d3.format(this.props.fmt);
    var coords = fig.canvas.append("text").attr("class", "mpld3-coordinates").style("text-anchor", "end").style("font-size", this.props.fontsize).attr("x", this.fig.width - 5).attr("y", this.fig.height - 5);
    for (var i = 0; i < this.fig.axes.length; i++) {
      var update_coords = function() {
        var ax = fig.axes[i];
        return function() {
          var pos = d3.mouse(this), x = ax.x.invert(pos[0]), y = ax.y.invert(pos[1]);
          coords.text(fmt(x));
        };
      }();
      fig.axes[i].baseaxes.on("mousemove", update_coords).on("mouseout", function() {
        coords.text("");
      });
    }
  };r,   8.0fc             C   s   d||d| _ d S )NZmousexposition)r)   r.   r/   )r   )r   r.   r/   r   r   r   r0   e  s    zMouseXPosition.__init__N)r,   r_   )r&   r'   r(   r+   r   r0   r   r   r   r   r^   9  s   r^   )r+   __all__collectionsjsonuuidr   collections.abcr   ImportErrorutilsr   r   r   r   objectr   r   r   r   r   r   r
   rB   r	   rD   rF   rW   r^   r   r   r   r   r   <module>   s@   ($1[M  d1