2023-01-23 11:03:31 +01:00

5 lines
2.4 KiB
JavaScript

var tokenRegex=/\{([^\}]+)\}/g,objNotationRegex=/(?:(?:^|\.)(.+?)(?=\[|\.|$|\()|\[('|")(.+?)\2\])(\(\))?/g,replacer=function(c,h,g){var a=g;h.replace(objNotationRegex,function(c,b,f,d,g){b=b||d;a&&(b in a&&(a=a[b]),"function"==typeof a&&g&&(a=a()))});return a=(null==a||a==g?c:a)+""},fill=function(c,h){return String(c).replace(tokenRegex,function(c,a){return replacer(c,a,h)})};
Raphael.fn.popup=function(c,h,g,a,k){a=String(a||"top-middle").split("-");a[1]=a[1]||"middle";var b=g.getBBox(),f=Math.round(b.width),d=Math.round(b.height),l=Math.round(b.x)-5,b=Math.round(b.y)-5,e=Math.min(d/2,f/2,10),p=[{x:l+5,y:b,w:f,w4:f/4,h4:d/4,right:0,left:f-2*e,bottom:0,top:d-2*e,r:5,h:d,gap:e},{x:l+5,y:b,w:f,w4:f/4,h4:d/4,left:f/2-e,right:f/2-e,top:d/2-e,bottom:d/2-e,r:5,h:d,gap:e},{x:l+5,y:b,w:f,w4:f/4,h4:d/4,left:0,right:f-2*e,top:0,bottom:d-2*e,r:5,h:d,gap:e}]["middle"==a[1]?1:2*("top"==
a[1]||"left"==a[1])],m=0,n=0,q=this.path(fill({top:"M{x},{y}h{w4},{w4},{w4},{w4}a{r},{r},0,0,1,{r},{r}v{h4},{h4},{h4},{h4}a{r},{r},0,0,1,-{r},{r}l-{right},0-{gap},{gap}-{gap}-{gap}-{left},0a{r},{r},0,0,1-{r}-{r}v-{h4}-{h4}-{h4}-{h4}a{r},{r},0,0,1,{r}-{r}z",bottom:"M{x},{y}l{left},0,{gap}-{gap},{gap},{gap},{right},0a{r},{r},0,0,1,{r},{r}v{h4},{h4},{h4},{h4}a{r},{r},0,0,1,-{r},{r}h-{w4}-{w4}-{w4}-{w4}a{r},{r},0,0,1-{r}-{r}v-{h4}-{h4}-{h4}-{h4}a{r},{r},0,0,1,{r}-{r}z",right:"M{x},{y}h{w4},{w4},{w4},{w4}a{r},{r},0,0,1,{r},{r}v{h4},{h4},{h4},{h4}a{r},{r},0,0,1,-{r},{r}h-{w4}-{w4}-{w4}-{w4}a{r},{r},0,0,1-{r}-{r}l0-{bottom}-{gap}-{gap},{gap}-{gap},0-{top}a{r},{r},0,0,1,{r}-{r}z",
left:"M{x},{y}h{w4},{w4},{w4},{w4}a{r},{r},0,0,1,{r},{r}l0,{top},{gap},{gap}-{gap},{gap},0,{bottom}a{r},{r},0,0,1,-{r},{r}h-{w4}-{w4}-{w4}-{w4}a{r},{r},0,0,1-{r}-{r}v-{h4}-{h4}-{h4}-{h4}a{r},{r},0,0,1,{r}-{r}z"}[a[0]],p)).insertBefore(g);switch(a[0]){case "top":m=c-(l+5+p.left+e);n=h-(b+5+d+5+e);break;case "bottom":m=c-(l+5+p.left+e);n=h-(b-e);break;case "left":m=c-(l+5+f+5+e);n=h-(b+5+p.top+e);break;case "right":m=c-(l-e),n=h-(b+5+p.top+e)}q.translate(m,n);if(k)return k=q.attr("path"),q.remove(),
{path:k,dx:m,dy:n};g.translate(m,n);return q};function getAnchors(c,h,g,a,k,b){var f=(g-c)/2,d=(k-g)/2;c=Math.atan((g-c)/Math.abs(a-h));k=Math.atan((k-g)/Math.abs(a-b));c=h<a?Math.PI-c:c;k=b<a?Math.PI-k:k;b=Math.PI/2-(c+k)%(2*Math.PI)/2;h=f*Math.sin(b+c);f*=Math.cos(b+c);c=d*Math.sin(b+k);d*=Math.cos(b+k);return{x1:g-h,y1:a+f,x2:g+c,y2:a+d}};