UNPKG

flot-thumb-plugin

Version:

Thumb for flot-cursor-plugin and flot-axishandle-plugin

3 lines (2 loc) 9.82 kB
"use strict";var _slicedToArray=function(){function t(t,e){var n=[],r=!0,i=!1,o=void 0;try{for(var s,l=t[Symbol.iterator]();!(r=(s=l.next()).done)&&(n.push(s.value),!e||n.length!==e);r=!0);}catch(t){i=!0,o=t}finally{try{!r&&l.return&&l.return()}finally{if(i)throw o}}return n}return function(e,n){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();!function(t){function e(t){t.addEventListener("mousemove",n,!1),t.addEventListener("touchmove",n,!1),t.addEventListener("mouseup",r,!1),t.addEventListener("touchend",r,!1)}function n(t){if(f){if(0===t.buttons)return void r(t);var e=h(t),n=o(t),i=s(n),l=i.eventHolder;if(f.selectedElement.constraintFunction){var u=f.selectedElement.constraintFunction(e.X,e.Y,f.x,f.y),c=_slicedToArray(u,2);e.X=c[0],e.Y=c[1]}var m=f.selectedElement.getCTM(),b=e.X-f.x,p=e.Y-f.y;m.e+=b,m.f+=p,f.selectedElement.transform.baseVal.getItem(0).setMatrix(m),f.x=e.X,f.y=e.Y,a(f.selectedElement),t.preventDefault(),t.stopPropagation(),d("thumbmove",t,l)}}function r(t){var e=o(t),n=s(e),r=n.eventHolder;f&&(f=null,n.style.pointerEvents="none",r.dispatchEvent(new CustomEvent("thumbmoveend",{detail:t})))}function i(t){var e=o(t),n=s(e),r=n.eventHolder;if(f=null,e&&-1!==e.getAttribute("class").indexOf("draggable")){var i=h(t),l=e.getBoundingClientRect(),a=document.documentElement,u=(window.pageXOffset||a.scrollLeft)-(a.clientLeft||0),c=(window.pageYOffset||a.scrollTop)-(a.clientTop||0);f={selectedElement:e,x:i.X,y:i.Y,deltaHandlingX:i.X-(l.left+l.right)/2-u,deltaHandlingY:i.Y-(l.top+l.bottom)/2-c},n.style.pointerEvents="all"}f&&d("thumbmovestart",t,r)}function o(t){var e=t.target,n=e.getAttribute("class");return n&&n.includes("interactionLayer")?e.parentNode:e}function s(t){return"svg"===t.tagName?t:"g"===t.tagName?t.parentNode:null}function l(t){var e=o(t),n=[];e&&-1!==e.getAttribute("class").indexOf("thumb")&&(n=u(e),n.length>0&&a(n[0]))}function a(t){t.parentNode.appendChild(t)}function u(t){var e=t.getBoundingClientRect(),n=e.left,r=e.right,i=e.top,o=e.bottom,s=t.parentNode;return Array.prototype.slice.call(s.childNodes,0).filter(function(t){var e=t.getBoundingClientRect(),s=e.left,l=e.right,a=e.top,u=e.bottom;return e.width>0&&e.height>0&&(n<l&&r>s&&i<u&&o>a)})}function d(t,e,n){var r=h(e),i=new CustomEvent(t,{detail:e});i.pageX=r.X-f.deltaHandlingX,i.pageY=r.Y-f.deltaHandlingY,i.selectedThumb=f.selectedElement,n.dispatchEvent(i)}function c(t){var e=document.documentElement;return{X:t.clientX+(window.pageXOffset||e.scrollLeft)-(e.clientLeft||0),Y:t.clientY+(window.pageYOffset||e.scrollTop)-(e.clientTop||0)}}function h(t){return t.touches?{X:t.touches[0].pageX,Y:t.touches[0].pageY}:c(t)}function m(t){Array.prototype.forEach.call(t.childNodes,function(t){t.classList.contains("thumb")&&(t.removeEventListener("mousedown",i),t.removeEventListener("touchstart",i))}),t.removeEventListener("mousemove",n),t.removeEventListener("touchmove",n),t.removeEventListener("mouseup",r),t.removeEventListener("touchend",r)}function b(t,e){var n=e-8,r=window.getComputedStyle(t).fontSize.replace("px",""),i=t.textContent,o=i.trim().split(/\s+/);if(o.length>1){t.textContent="";var s=document.createElementNS("http://www.w3.org/2000/svg","tspan");s.setAttribute("x",t.getAttribute("x")),s.setAttribute("y",t.getAttribute("y")),s.setAttribute("pointer-events","none"),s.setAttribute("font-size",r),s.textContent=o[0],t.appendChild(s);for(var l=1;l<o.length;l++){var a=s.firstChild.textContent.length;s.firstChild.textContent+=" "+o[l],s.getComputedTextLength()>n&&(s.firstChild.textContent=s.firstChild.textContent.slice(0,a),s=s.cloneNode(!0),t.appendChild(s),s.textContent=o[l])}for(var u=0;u<t.children.length;u++){var d=-(r*(t.children.length/2-u)-r/2);t.children[u].setAttribute("dy",d)}}}t.thumb={};var f;t.thumb.createSVGLayer=function(t,n){if(t&&t.find(".flot-thumbs")[0])return t.find(".flot-thumbs")[0].firstChild;var r=document.createElement("div");r.className="flot-thumbs",r.style.position="absolute",r.style.top="0px",r.style.left="0px",r.style.width="100%",r.style.height="100%",r.style.pointerEvents="none",t?t.append(r):document.body.appendChild(r);var i=document.createElementNS("http://www.w3.org/2000/svg","svg");i.setAttributeNS(null,"width","100%"),i.setAttributeNS(null,"height","100%");var o=window.getComputedStyle(r).getPropertyValue("--customIcon");o=(o||"").trim();var s=window.getComputedStyle(r).getPropertyValue("--customIconTextBoundary");s=(s||"").trim();var l=o||'<symbol id="round" viewBox="0 0 50 50"><polyline points="25,0 40,20 10,20 25,0"></polyline><circle cx="25" cy="25" r="20"/></symbol>',a=s;""===s&&""===o&&(a='<symbol id="round" viewBox="0 0 50 50"><circle cx="25" cy="25" r="20"/></symbol>'),""===a&&(a=l);var u='<defs xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">'+l+a+'<symbol id="l_round" viewBox="0 0 50 50"><use xlink:href="#round" x="0" y="0" width="50" height="50" transform="rotate(90 25 25)"/></symbol><symbol id="r_round" viewBox="0 0 50 50"><use xlink:href="#round" x="0" y="0" width="50" height="50" transform="rotate(270 25 25)"/></symbol><symbol id="b_round" viewBox="0 0 50 50"><use xlink:href="#round" x="0" y="0" width="50" height="50" transform="rotate(0 25 25)"/></symbol><symbol id="t_round" viewBox="0 0 50 50"><use xlink:href="#round" x="0" y="0" width="50" height="50" transform="rotate(180 25 25)"/></symbol><symbol id="l_tb" viewBox="0 0 50 50"><use xlink:href="#tb" x="0" y="0" width="50" height="50" transform="rotate(90 25 25)" /></symbol><symbol id="r_tb" viewBox="0 0 50 50"><use xlink:href="#tb" x="0" y="0" width="50" height="50" transform="rotate(270 25 25)" /></symbol><symbol id="b_tb" viewBox="0 0 50 50"><use xlink:href="#tb" x="0" y="0" width="50" height="50" transform="rotate(0 25 25)" /></symbol><symbol id="t_tb" viewBox="0 0 50 50"><use xlink:href="#tb" x="0" y="0" width="50" height="50" transform="rotate(180 25 25)" /></symbol></defs>',d=(new DOMParser).parseFromString(u,"image/svg+xml"),c=document.importNode(d.documentElement,!0);return c.children[0].setAttribute("id","round"),c.children[1].setAttribute("id","tb"),i.appendChild(c),r.appendChild(i),i.eventHolder=n||document,e(i),i},t.thumb.createThumb=function(e){function n(t,e){t.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",e),t.setAttributeNS("http://www.w3.org/1999/xlink","href",e)}var r={size:e.size||20,x:e.x||0,y:e.y||0,svgRoot:e.svgRoot,shape:e.shape||"bottom",abbreviation:e.abbreviation||"",constraintFunction:e.constraintFunction,classList:e.classList?e.classList.slice():["draggable"],offset:e.offset||"0",fill:e.fill},o=document.createElementNS("http://www.w3.org/2000/svg","use"),s=document.createElementNS("http://www.w3.org/2000/svg","text"),a=document.createElementNS("http://www.w3.org/2000/svg","use"),u=document.createElementNS("http://www.w3.org/2000/svg","g"),d=document.createElementNS("http://www.w3.org/2000/svg","rect"),c=r.svgRoot,h=r.size,m=r.x,f=r.y,p="",g=0,v=0;switch(r.shape){case"left":p="y",r.classList.push("left"),u.shape="left",n(o,"#l_round"),n(a,"#l_tb"),g="-"===r.offset[0]?r.offset.substr(1):"-"+r.offset;break;case"right":p="y",r.classList.push("right"),u.shape="right",n(o,"#r_round"),n(a,"#r_tb"),g=r.offset;break;case"bottom":p="x",r.classList.push("bottom"),u.shape="bottom",n(o,"#b_round"),n(a,"#b_tb"),v=r.offset;break;case"top":p="x",r.classList.push("top"),u.shape="top",n(o,"#t_round"),n(a,"#t_tb"),v="-"===r.offset[0]?r.offset.substr(1):"-"+r.offset}if(o.setAttributeNS(null,"width",2*h),o.setAttributeNS(null,"height",2*h),o.setAttributeNS(null,"transform","translate("+-h+" "+-h+")"),o.setAttributeNS(null,"x",g),o.setAttributeNS(null,"y",v),o.setAttribute("class","thumbIcon"),o.style.fill=r.fill,a.setAttributeNS(null,"width",2*h),a.setAttributeNS(null,"height",2*h),a.setAttributeNS(null,"transform","translate("+-h+" "+-h+")"),a.setAttributeNS(null,"x",g),a.setAttributeNS(null,"y",v),s.setAttributeNS(null,"text-anchor","middle"),s.setAttributeNS(null,"dominant-baseline","middle"),s.setAttributeNS(null,"lengthAdjust","spacingAndGlyphs"),s.setAttribute("class","thumbLabel"),s.textContent=r.abbreviation,s.style.pointerEvents="none",u.appendChild(o),u.appendChild(a),u.appendChild(s),u.setAttributeNS(null,"transform","translate("+m+" "+f+")"),u.setAttribute("class","thumb"),u.classList.add(p),r.classList)for(var w=0;w<r.classList.length;w++)""!==r.classList[w]&&u.classList.add(r.classList[w]);u.style.pointerEvents="all",u.addEventListener("mousedown",i,!1),u.addEventListener("touchstart",i,!1),t(u).click(l),u.constraintFunction=r.constraintFunction,c.appendChild(u);var y=o.getBBox();d.setAttributeNS(null,"width",y.width),d.setAttributeNS(null,"height",y.height),d.setAttributeNS(null,"x",y.x),d.setAttributeNS(null,"y",y.y),d.setAttributeNS(null,"transform","translate("+-h+" "+-h+")"),d.setAttribute("pointer-events","all"),d.classList.add("interactionLayer"),d.style.fill="transparent",d.style.stroke="transparent",u.appendChild(d);var x=a.getBBox(),A=x.x+x.width/2,N=x.y+x.height/2;return u.removeChild(a),s.setAttributeNS(null,"x",A),s.setAttributeNS(null,"y",N),s.setAttributeNS(null,"transform","translate("+-h+" "+-h+")"),/word/.test(window.getComputedStyle(s).getPropertyValue("--wrap"))?b(s,2*h):s.setAttributeNS(null,"textLength",h),u},t.thumb.updateComputedXPosition=function(t,e){var n=t.getCTM(),r="matrix("+n.a+" "+n.b+" "+n.c+" "+n.d+" "+e+" "+n.f+")";t.setAttribute("transform",r)},t.thumb.updateComputedYPosition=function(t,e){var n=t.getCTM(),r="matrix("+n.a+" "+n.b+" "+n.c+" "+n.d+" "+n.e+" "+e+")";t.setAttribute("transform",r)},t.thumb.setHidden=function(t,e){t.style.display=e?"none":"inline"},t.thumb.shutdown=function(t){f=null,m(t)}}(jQuery); //# sourceMappingURL=jquery.thumb.js.map