Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chartogram

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chartogram - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

2

bundle/chartogram.js

@@ -1,2 +0,2 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).chartogram=e()}(this,function(){"use strict";function t(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=[],r=!0,a=!1,o=void 0;try{for(var i,c=t[Symbol.iterator]();!(r=(i=c.next()).done)&&(n.push(i.value),!e||n.length!==e);r=!0);}catch(t){a=!0,o=t}finally{try{r||null==c.return||c.return()}finally{if(a)throw o}}return n}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function e(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{},a=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(a=a.concat(Object.getOwnPropertySymbols(r).filter(function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),a.forEach(function(e){n(t,e,r[e])})}return t}function n(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function r(t){return function(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);e<t.length;e++)n[e]=t[e];return n}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}return function(n,a){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"Title",i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};n.innerHTML='\n\t\t<header class="chartogram__header">\n\t\t\t<h1 class="chartogram__title">'.concat(o,'</h1>\n\t\t</header>\n\t\t<div class="chartogram__plan-with-axes">\n\t\t\t<div class="chartogram__plan">\n\t\t\t\t<div class="chartogram__top-border"></div>\n\t\t\t\t<div class="chartogram__canvas-wrapper">\n\t\t\t\t\t<svg class="chartogram__canvas" preserveAspectRatio="none"></svg>\n\t\t\t\t\t<div class="chartogram__x"></div>\n\t\t\t\t\t<div class="chartogram__y-wrapper">\n\t\t\t\t\t\t<div class="chartogram__y"></div>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>\n\t\t<div class="chartogram__timeline">\n\t\t\t<div class="chartogram__timeline-canvas-padding">\n\t\t\t\t<svg class="chartogram__timeline-canvas" preserveAspectRatio="none"></svg>\n\t\t\t</div>\n\t\t\t<div class="chartogram__timeline-overlay-left"></div>\n\t\t\t<div class="chartogram__timeline-overlay-right"></div>\n\t\t\t<div class="chartogram__timeline-window">\n\t\t\t\t<button type="button" class="chartogram__reset-button chartogram__timeline-window__drag"></button>\n\t\t\t\t<button type="button" class="chartogram__reset-button chartogram__timeline-window__left-handle"></button>\n\t\t\t\t<button type="button" class="chartogram__reset-button chartogram__timeline-window__right-handle"></button>\n\t\t\t</div>\n\t\t</div>\n\t\t<div class="chartogram__chart-togglers"></div>\n\t'),n.classList.add("chartogram");var c,l,d,s,u,h,v,m,g,f,p,_,y,b,w,x,A=i.gaugeMarkTicksCount||6,E=i.timelineWindowSize||40,L=i.timelineChartMaxPoints||80,S=i.months||["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],C=i.weekdays||["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],k=document.querySelector(".chartogram__plan"),M=document.querySelector(".chartogram__canvas"),N=document.querySelector(".chartogram__canvas-wrapper"),T=document.querySelector(".chartogram__x"),q=document.querySelector(".chartogram__y"),O=document.querySelector(".chartogram__timeline"),j=document.querySelector(".chartogram__timeline-overlay-left"),B=document.querySelector(".chartogram__timeline-window__left-handle"),D=document.querySelector(".chartogram__timeline-window"),R=document.querySelector(".chartogram__timeline-window__drag"),X=document.querySelector(".chartogram__timeline-window__right-handle"),Y=document.querySelector(".chartogram__timeline-overlay-right"),I=document.querySelector(".chartogram__timeline-canvas"),P=1;function F(t){for(;t.firstChild;)t.removeChild(t.firstChild)}function H(t,e){return t.map(function(t,n){return"".concat(t,",").concat(e[n])})}function J(t,e,n,r){for(var a=0;a<A;){var o=document.createElement("div"),i=e+a*(n-e)/(A-1);r&&(i=r(i)),o.appendChild(document.createTextNode(i)),t.appendChild(o),a++}}function W(n){var o=a.x.points;g=o[0];var i=o.map(function(t){return(t-g)/1e3});F(M);var p=i[0],_=i[i.length-1],y=_-p,b=p+c*y,w=_-(1-l)*y,x=i.findIndex(function(t){return t>b})-1;x<0&&(x=0);var E=i.findIndex(function(t){return t>w});E<0&&(E=i.length-1);var C=i.slice(x,E+1),k=0,N=0;s=[];var O=[],j=a.lines,B=Array.isArray(j),D=0;for(j=B?j:j[Symbol.iterator]();;){var R;if(B){if(D>=j.length)break;R=j[D++]}else{if((D=j.next()).done)break;R=D.value}var X=R;if(d[X.id]){O.push(X),N=Math.max.apply(Math,[N].concat(r(X.points)));var Y=X.points.slice(x,E+1);s.push(e({},X,{points:Y})),k=Math.max.apply(Math,[k].concat(r(Y)))}}M.setAttribute("viewBox","".concat(b," ").concat(0," ").concat(w-b," ").concat(k-0));var W=function(t,e){for(;;){if(t<e)return e;if(t%e==0)return t;t--}}(k,10),K=(k-0)/(W-0),Q=function(t,e){for(var n=new Array(A),r=0;r<A;)n[r]=t+r*(e-t)/(A-1),r++;return n}(0,W),U=Array.isArray(Q),V=0;for(Q=U?Q:Q[Symbol.iterator]();;){var Z;if(U){if(V>=Q.length)break;Z=Q[V++]}else{if((V=Q.next()).done)break;Z=V.value}var $=Z;M.appendChild(z($,b,w,0,k))}var tt=C.slice(),et=tt[0],nt=tt[tt.length-1],rt=(b-et)/(tt[1]-et),at=(nt-w)/(nt-tt[tt.length-2]);tt[0]=b,tt[tt.length-1]=w;var ot=s,it=Array.isArray(ot),ct=0;for(ot=it?ot:ot[Symbol.iterator]();;){var lt;if(it){if(ct>=ot.length)break;lt=ot[ct++]}else{if((ct=ot.next()).done)break;lt=ct.value}var dt=lt,st=(dt.id,dt.color),ut=dt.points,ht=document.createElement("polyline");ht.setAttribute("stroke",st);var vt=ut.slice(),mt=vt[0],gt=vt[vt.length-1];vt[0]=mt+(vt[1]-mt)*rt,vt[vt.length-1]=gt-(gt-vt[vt.length-2])*at,ht.setAttribute("points",H(tt,vt.map(function(t){return k-P*t})).join(" ")),ht.classList.add("chartogram__graph"),M.appendChild(ht)}M.innerHTML+="",function(t,e,n,r,a){F(T),F(q),J(T,t,e,function(t){var e=new Date(t);return"".concat(S[e.getMonth()]," ").concat(e.getDate())}),J(q,n,r),q.style.height="".concat(100/a,"%")}(o[0],o[o.length-1],0,W,K),v=0,m=k,u=b,h=w,f=C,n&&function(e,n,r,a,o,i){F(I),I.setAttribute("viewBox","".concat(r," ").concat(o," ").concat(a-r," ").concat(i-o));for(var c=e,l=Array.isArray(c),d=0,c=l?c:c[Symbol.iterator]();;){var s;if(l){if(d>=c.length)break;s=c[d++]}else{if((d=c.next()).done)break;s=d.value}var u=s,h=(u.id,u.color),v=u.points,m=G(n,v,L),g=t(m,2),f=g[0],p=g[1],_=document.createElement("polyline");_.setAttribute("stroke",h),_.setAttribute("points",H(f,p.map(function(t){return i-o-t})).join(" ")),_.classList.add("chartogram__graph"),I.appendChild(_)}I.innerHTML+=""}(O,i,p,_,0,N)}function z(t,e,n,r,a){var o=document.createElement("line");return o.classList.add("chartogram__grid-line"),o.setAttribute("x1",e),o.setAttribute("x2",n),o.setAttribute("y1",a-r-t),o.setAttribute("y2",a-r-t),o}function G(t,e,n){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:Math.max.apply(Math,r(e)),o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:.025,i=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0,c=arguments.length>6&&void 0!==arguments[6]?arguments[6]:new Array(t.length),l=arguments.length>7&&void 0!==arguments[7]?arguments[7]:new Array(t.length),d=arguments.length>8&&void 0!==arguments[8]?arguments[8]:0;if(i+2>t.length-1){for(;i<e.length;)c[d]=t[i],l[d]=e[i],d++,i++;return c=c.slice(0,d),l=l.slice(0,d),c.length<=n?[c,l]:(t.length/c.length<1.1&&(o=Math.min(o+.025,1)),G(c,l,n,a,o))}var s=(e[i+2]+e[i])/2;return Math.abs(s-e[i+1])/a<o?(c[d]=t[i],c[d+1]=t[i+2],l[d]=e[i],l[d+1]=e[i+2],G(t,e,n,a,o,i+2,c,l,d+1)):(c[d]=t[i],c[d+1]=t[i+1],c[d+2]=t[i+2],l[d]=e[i],l[d+1]=e[i+1],l[d+2]=e[i+2],G(t,e,n,a,o,i+2,c,l,d+2))}function K(t){var e=t.id,n=t.name,r=t.color,a=document.createElement("button");a.setAttribute("type","button"),a.classList.add("chartogram__chart-toggler"),a.classList.add("chartogram__chart-toggler--on"),a.classList.add("chartogram__reset-button");var o="http://www.w3.org/2000/svg",i=document.createElementNS(o,"svg");i.setAttributeNS(null,"viewBox","0 0 19 19"),i.classList.add("chartogram__chart-toggler-check");var c=document.createElementNS(o,"circle");c.setAttribute("cx","9.5"),c.setAttribute("cy","9.5"),c.setAttribute("r","9.5"),c.setAttribute("fill",r),i.appendChild(c);var l=document.createElementNS(o,"circle");l.setAttribute("cx","9.5"),l.setAttribute("cy","9.5"),l.setAttribute("r","8"),l.classList.add("chartogram__chart-toggler-check-circle"),i.appendChild(l);var s=document.createElementNS(o,"path");return s.setAttribute("d","M13.64 4.94l-6.2 6.34-1.69-1.9c-.73-.63-1.89.1-1.36 1.06l2 3.38c.3.43 1.04.85 1.78 0 .32-.42 6.31-7.93 6.31-7.93.74-.84-.2-1.58-.84-.95z"),s.setAttribute("fill","white"),s.classList.add("chartogram__chart-toggler-check-mark"),i.appendChild(s),a.appendChild(i),a.appendChild(document.createTextNode(n)),a.addEventListener("click",function(){var t=!d[e];(t||1!==Object.keys(d).filter(function(t){return!1!==d[t]}).length)&&(d[e]=t,W(!0),a.classList.toggle("chartogram__chart-toggler--on"))}),a}function Q(t){var e,n,r,a,o="left"===t?B:X,i=parseFloat(getComputedStyle(D).borderLeftWidth);return U(o,function(o){e=O.getBoundingClientRect();var c=D.getBoundingClientRect();"left"===t?(n=e.x,r=c.x+c.width-2*i,a=o-c.x):(n=c.x+2*i,r=e.x+e.width,a=o-(c.x+c.width))},function(o){o-=a,o=((o=Math.max(Math.min(o,r),n))-e.x)/e.width,"left"===t?c=o:l=o,V()})}function U(t,e,n){function r(t){n(t.changedTouches[0].clientX,t.changedTouches[0].clientY)}function a(t){n(t.clientX,t.clientY)}function o(){window.removeEventListener("pointermove",a),window.removeEventListener("touchmove",r),window.removeEventListener("pointerup",o),window.removeEventListener("pointercancel",o),window.removeEventListener("touchend",o),window.removeEventListener("touchcancel",o)}function i(t){if(t.touches.length>1)return o();e(t.changedTouches[0].clientX,t.changedTouches[0].clientY),window.addEventListener("touchmove",r),window.addEventListener("touchend",o),window.addEventListener("touchcancel",o)}function c(t){e(t.clientX,t.clientY),window.addEventListener("pointermove",a),window.addEventListener("pointerup",o),window.addEventListener("pointercancel",o)}return t.addEventListener("touchstart",i),t.addEventListener("pointerdown",c),function(){o(),t.removeEventListener(c),t.removeEventListener(i)}}function V(){var t;t=c,j.style.right="".concat(100*(1-t),"%"),D.style.left="".concat(100*t,"%"),function(t){Y.style.left="".concat(100*t,"%"),D.style.right="".concat(100*(1-t),"%")}(l),W(!1)}function Z(){p&&(b=void 0,k.removeChild(p),p=void 0,function(){for(var t=w,e=Array.isArray(t),n=0,t=e?t:t[Symbol.iterator]();;){var r;if(e){if(n>=t.length)break;r=t[n++]}else{if((n=t.next()).done)break;r=n.value}var a=r;N.removeChild(a)}w=void 0}(),M.removeChild(x),x=void 0)}Q("left"),Q("right"),U(R,function(t){$=O.getBoundingClientRect(),tt=D.getBoundingClientRect(),rt=t-tt.x,et=$.x,nt=$.x+($.width-tt.width)},function(t){t-=rt,t=((t=Math.max(Math.min(t,nt),et))-$.x)/$.width,c=t,l=t+tt.width/$.width,V()}),function(){d={};for(var t=a.lines,e=Array.isArray(t),n=0,t=e?t:t[Symbol.iterator]();;){var r;if(e){if(n>=t.length)break;r=t[n++]}else{if((n=t.next()).done)break;r=n.value}var o=r;d[o.id]=!0}if(a.x.points.length>E){var i=a.x.points[0],s=a.x.points[a.x.points.length-1],u=a.x.points[a.x.points.length-E];c=(u-i)/(s-i)}else c=0;l=1,V(),W(!0),x=void 0;var h=document.querySelector(".chartogram__chart-togglers");F(h);for(var v=a.lines,m=Array.isArray(v),g=0,v=m?v:v[Symbol.iterator]();;){var f;if(m){if(g>=v.length)break;f=v[g++]}else{if((g=v.next()).done)break;f=g.value}var p=f;h.appendChild(K(p))}}(),function(){var t,e;function n(n){var r=(n-t.x)/t.width,o=u+r*(h-u),i=f.findIndex(function(t){return t>=o}),c=i-1;if(e(i)||(i=-1),e(c)||(c=-1),i<0){if(c<0)return Z();o=f[c]}else if(c<0)o=f[i];else{var l=f[c],A=f[i],E=o-l,L=A-o;o=E>L?A:l}if(o!==b){b=o,p||function(){(p=document.createElement("div")).classList.add("chartogram__tooltip"),k.appendChild(p),(_=document.createElement("h1")).classList.add("chartogram__tooltip-header"),p.appendChild(_),(y=document.createElement("dl")).classList.add("chartogram__tooltip-values"),p.appendChild(y);for(var t=a.lines,e=Array.isArray(t),n=0,t=e?t:t[Symbol.iterator]();;){var r;if(e){if(n>=t.length)break;r=t[n++]}else{if((n=t.next()).done)break;r=n.value}var o=r;if(d[o.id]){var i=document.createElement("dt");i.style.color=o.color,y.appendChild(i);var c=document.createElement("dd");c.style.color=o.color,y.appendChild(c)}}}();var T=new Date(1e3*o+g);_.textContent="".concat(C[T.getDay()],", ").concat(S[T.getMonth()]," ").concat(T.getDate());for(var q=f.indexOf(o),O=0;2*O<y.childNodes.length;)y.childNodes[2*O].textContent=s[O].points[q],y.childNodes[2*O+1].textContent=a.lines[O].name,O++;var j=(o-u)/(h-u);p.style.left="".concat(100*j,"%"),function(t,e){w||function(){w=[];for(var t=0;t<s.length;){var e=document.createElement("div");e.classList.add("chartogram__tooltip-point"),e.style.color=s[t].color,w.push(e),N.appendChild(e),t++}}();for(var n=0;n<w.length;){var r=w[n];r.style.left="".concat(100*e,"%");var a=s[n].points[t],o=a/m;r.style.bottom="".concat(100*o,"%"),n++}}(q,j),function(t){x||((x=document.createElementNS("http://www.w3.org/2000/svg","line")).setAttributeNS(null,"class","chartogram__tooltip-line"),M.appendChild(x)),x.setAttributeNS(null,"x1",t),x.setAttributeNS(null,"x2",t),x.setAttributeNS(null,"y1",v),x.setAttributeNS(null,"y2",m)}(o)}}function r(){t=M.getBoundingClientRect(),e=function(t){return!(t<0)&&f[t]>=u&&f[t]<=h}}function o(t){if(t.touches.length>1)return l();r(),M.addEventListener("touchend",l),M.addEventListener("touchmove",i),M.addEventListener("touchend",l),M.addEventListener("touchcancel",l),i(t)}function i(e){var r=e.changedTouches[0].clientX,a=e.changedTouches[0].clientY;r<t.x||r>t.x+t.width||a<t.y||a>t.y+t.height?l():n(r)}function c(t){n(t.clientX,t.clientY)}function l(){M.removeEventListener("pointermove",c),M.removeEventListener("pointerleave",l),M.removeEventListener("pointercancel",l),M.removeEventListener("touchmove",i),M.removeEventListener("touchend",l),M.removeEventListener("touchcancel",l),Z()}function A(){r(),M.addEventListener("pointermove",c),M.addEventListener("pointerleave",l),M.addEventListener("pointercancel",l)}M.addEventListener("touchstart",o),M.addEventListener("pointerenter",A)}();var $,tt,et,nt,rt}});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).chartogram=e()}(this,function(){"use strict";function t(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=[],r=!0,a=!1,o=void 0;try{for(var i,c=t[Symbol.iterator]();!(r=(i=c.next()).done)&&(n.push(i.value),!e||n.length!==e);r=!0);}catch(t){a=!0,o=t}finally{try{r||null==c.return||c.return()}finally{if(a)throw o}}return n}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function e(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{},a=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(a=a.concat(Object.getOwnPropertySymbols(r).filter(function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),a.forEach(function(e){n(t,e,r[e])})}return t}function n(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function r(t){return function(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);e<t.length;e++)n[e]=t[e];return n}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}return function(n,a){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"Title",i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};n.innerHTML='\n\t\t<header class="chartogram__header">\n\t\t\t<h1 class="chartogram__title">'.concat(o,'</h1>\n\t\t</header>\n\t\t<div class="chartogram__plan-with-axes">\n\t\t\t<div class="chartogram__plan">\n\t\t\t\t<div class="chartogram__top-border"></div>\n\t\t\t\t<div class="chartogram__canvas-wrapper">\n\t\t\t\t\t<svg class="chartogram__canvas" preserveAspectRatio="none"></svg>\n\t\t\t\t\t<div class="chartogram__x"></div>\n\t\t\t\t\t<div class="chartogram__y-wrapper">\n\t\t\t\t\t\t<div class="chartogram__y"></div>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>\n\t\t<div class="chartogram__timeline">\n\t\t\t<div class="chartogram__timeline-canvas-padding">\n\t\t\t\t<svg class="chartogram__timeline-canvas" preserveAspectRatio="none"></svg>\n\t\t\t</div>\n\t\t\t<div class="chartogram__timeline-overlay-left"></div>\n\t\t\t<div class="chartogram__timeline-overlay-right"></div>\n\t\t\t<div class="chartogram__timeline-window">\n\t\t\t\t<button type="button" class="chartogram__reset-button chartogram__timeline-window__drag"></button>\n\t\t\t\t<button type="button" class="chartogram__reset-button chartogram__timeline-window__left-handle"></button>\n\t\t\t\t<button type="button" class="chartogram__reset-button chartogram__timeline-window__right-handle"></button>\n\t\t\t</div>\n\t\t</div>\n\t\t<div class="chartogram__chart-togglers"></div>\n\t'),n.classList.add("chartogram");var c,l,d,s,u,h,v,m,g,f,p,_,y,b,w,x,A=i.gaugeMarkTicksCount||6,E=i.timelineWindowSize||40,L=i.timelineChartMaxPoints||80,S=i.months||["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],C=i.weekdays||["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],k=document.querySelector(".chartogram__plan"),M=document.querySelector(".chartogram__canvas"),N=document.querySelector(".chartogram__canvas-wrapper"),T=document.querySelector(".chartogram__x"),q=document.querySelector(".chartogram__y"),O=document.querySelector(".chartogram__timeline"),j=document.querySelector(".chartogram__timeline-overlay-left"),B=document.querySelector(".chartogram__timeline-window__left-handle"),D=document.querySelector(".chartogram__timeline-window"),R=document.querySelector(".chartogram__timeline-window__drag"),X=document.querySelector(".chartogram__timeline-window__right-handle"),Y=document.querySelector(".chartogram__timeline-overlay-right"),I=document.querySelector(".chartogram__timeline-canvas"),P=1;function F(t){for(;t.firstChild;)t.removeChild(t.firstChild)}function H(t,e){return t.map(function(t,n){return"".concat(t,",").concat(e[n])})}function J(t,e,n,r){for(var a=0;a<A;){var o=document.createElement("div"),i=e+a*(n-e)/(A-1);r&&(i=r(i)),o.appendChild(document.createTextNode(i)),t.appendChild(o),a++}}function W(n){var o=a.x.points;g=o[0];var i=o.map(function(t){return(t-g)/1e3});F(M);var p=i[0],_=i[i.length-1],y=_-p,b=p+c*y,w=_-(1-l)*y,x=i.findIndex(function(t){return t>b})-1;x<0&&(x=0);var E=i.findIndex(function(t){return t>w});E<0&&(E=i.length-1);var C=i.slice(x,E+1),k=0,N=0;s=[];var O=[],j=a.lines,B=Array.isArray(j),D=0;for(j=B?j:j[Symbol.iterator]();;){var R;if(B){if(D>=j.length)break;R=j[D++]}else{if((D=j.next()).done)break;R=D.value}var X=R;if(d[X.id]){O.push(X),N=Math.max.apply(Math,[N].concat(r(X.points)));var Y=X.points.slice(x,E+1);s.push(e({},X,{points:Y})),k=Math.max.apply(Math,[k].concat(r(Y)))}}M.setAttribute("viewBox","".concat(b," ").concat(0," ").concat(w-b," ").concat(k-0));var W=function(t,e){for(;;){if(t<e)return e;if(t%e==0)return t;t--}}(k,10),K=(k-0)/(W-0),Q=function(t,e){for(var n=new Array(A),r=0;r<A;)n[r]=t+r*(e-t)/(A-1),r++;return n}(0,W),U=Array.isArray(Q),V=0;for(Q=U?Q:Q[Symbol.iterator]();;){var Z;if(U){if(V>=Q.length)break;Z=Q[V++]}else{if((V=Q.next()).done)break;Z=V.value}var $=Z;M.appendChild(z($,b,w,0,k))}var tt=C.slice(),et=tt[0],nt=tt[tt.length-1],rt=(b-et)/(tt[1]-et),at=(nt-w)/(nt-tt[tt.length-2]);tt[0]=b,tt[tt.length-1]=w;var ot=s,it=Array.isArray(ot),ct=0;for(ot=it?ot:ot[Symbol.iterator]();;){var lt;if(it){if(ct>=ot.length)break;lt=ot[ct++]}else{if((ct=ot.next()).done)break;lt=ct.value}var dt=lt,st=(dt.id,dt.color),ut=dt.points,ht=document.createElement("polyline");ht.setAttribute("stroke",st);var vt=ut.slice(),mt=vt[0],gt=vt[vt.length-1];vt[0]=mt+(vt[1]-mt)*rt,vt[vt.length-1]=gt-(gt-vt[vt.length-2])*at,ht.setAttribute("points",H(tt,vt.map(function(t){return k-P*t})).join(" ")),ht.classList.add("chartogram__graph"),M.appendChild(ht)}M.innerHTML+="",function(t,e,n,r,a){F(T),F(q),J(T,t,e,function(t){var e=new Date(t);return"".concat(S[e.getMonth()]," ").concat(e.getDate())}),J(q,n,r),q.style.height="".concat(100/a,"%")}(o[0],o[o.length-1],0,W,K),v=0,m=k,u=b,h=w,f=C,n&&function(e,n,r,a,o,i){F(I),I.setAttribute("viewBox","".concat(r," ").concat(o," ").concat(a-r," ").concat(i-o));for(var c=e,l=Array.isArray(c),d=0,c=l?c:c[Symbol.iterator]();;){var s;if(l){if(d>=c.length)break;s=c[d++]}else{if((d=c.next()).done)break;s=d.value}var u=s,h=(u.id,u.color),v=u.points,m=G(n,v,L),g=t(m,2),f=g[0],p=g[1],_=document.createElement("polyline");_.setAttribute("stroke",h),_.setAttribute("points",H(f,p.map(function(t){return i-o-t})).join(" ")),_.classList.add("chartogram__graph"),I.appendChild(_)}I.innerHTML+=""}(O,i,p,_,0,N)}function z(t,e,n,r,a){var o=document.createElement("line");return o.classList.add("chartogram__grid-line"),o.setAttribute("x1",e),o.setAttribute("x2",n),o.setAttribute("y1",a-r-t),o.setAttribute("y2",a-r-t),o}function G(t,e,n){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:Math.max.apply(Math,r(e)),o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:.025,i=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0,c=arguments.length>6&&void 0!==arguments[6]?arguments[6]:new Array(t.length),l=arguments.length>7&&void 0!==arguments[7]?arguments[7]:new Array(t.length),d=arguments.length>8&&void 0!==arguments[8]?arguments[8]:0;if(i+2>t.length-1){for(;i<e.length;)c[d]=t[i],l[d]=e[i],d++,i++;return c=c.slice(0,d),l=l.slice(0,d),c.length<=n?[c,l]:(t.length/c.length<1.1&&(o=Math.min(o+.025,1)),G(c,l,n,a,o))}var s=(e[i+2]+e[i])/2;return Math.abs(s-e[i+1])/a<o?(c[d]=t[i],c[d+1]=t[i+2],l[d]=e[i],l[d+1]=e[i+2],G(t,e,n,a,o,i+2,c,l,d+1)):(c[d]=t[i],c[d+1]=t[i+1],c[d+2]=t[i+2],l[d]=e[i],l[d+1]=e[i+1],l[d+2]=e[i+2],G(t,e,n,a,o,i+2,c,l,d+2))}function K(t){var e=t.id,n=t.name,r=t.color,a=document.createElement("button");a.setAttribute("type","button"),a.classList.add("chartogram__chart-toggler"),a.classList.add("chartogram__chart-toggler--on"),a.classList.add("chartogram__reset-button");var o="http://www.w3.org/2000/svg",i=document.createElementNS(o,"svg");i.setAttributeNS(null,"viewBox","0 0 19 19"),i.classList.add("chartogram__chart-toggler-check");var c=document.createElementNS(o,"circle");c.setAttribute("cx","9.5"),c.setAttribute("cy","9.5"),c.setAttribute("r","9.5"),c.setAttribute("fill",r),i.appendChild(c);var l=document.createElementNS(o,"circle");l.setAttribute("cx","9.5"),l.setAttribute("cy","9.5"),l.setAttribute("r","8"),l.classList.add("chartogram__chart-toggler-check-circle"),i.appendChild(l);var s=document.createElementNS(o,"path");return s.setAttribute("d","M13.64 4.94l-6.2 6.34-1.69-1.9c-.73-.63-1.89.1-1.36 1.06l2 3.38c.3.43 1.04.85 1.78 0 .32-.42 6.31-7.93 6.31-7.93.74-.84-.2-1.58-.84-.95z"),s.setAttribute("fill","white"),s.classList.add("chartogram__chart-toggler-check-mark"),i.appendChild(s),a.appendChild(i),a.appendChild(document.createTextNode(n)),a.addEventListener("click",function(){var t=!d[e];(t||1!==Object.keys(d).filter(function(t){return!1!==d[t]}).length)&&(d[e]=t,W(!0),a.classList.toggle("chartogram__chart-toggler--on"))}),a}function Q(t){var e,n,r,a,o="left"===t?B:X,i=parseFloat(getComputedStyle(D).borderLeftWidth);return U(o,function(o){e=O.getBoundingClientRect();var c=D.getBoundingClientRect();"left"===t?(n=e.x,r=c.x+c.width-2*i,a=o-c.x):(n=c.x+2*i,r=e.x+e.width,a=o-(c.x+c.width))},function(o){o-=a,o=((o=Math.max(Math.min(o,r),n))-e.x)/e.width,"left"===t?c=o:l=o,V()})}function U(t,e,n){function r(t){n(t.changedTouches[0].clientX,t.changedTouches[0].clientY)}function a(t){n(t.clientX,t.clientY)}function o(){window.removeEventListener("pointermove",a),window.removeEventListener("touchmove",r),window.removeEventListener("pointerup",o),window.removeEventListener("pointercancel",o),window.removeEventListener("touchend",o),window.removeEventListener("touchcancel",o)}function i(t){if(t.touches.length>1)return o();e(t.changedTouches[0].clientX,t.changedTouches[0].clientY),window.addEventListener("touchmove",r),window.addEventListener("touchend",o),window.addEventListener("touchcancel",o)}function c(t){e(t.clientX,t.clientY),window.addEventListener("pointermove",a),window.addEventListener("pointerup",o),window.addEventListener("pointercancel",o)}return t.addEventListener("touchstart",i),t.addEventListener("pointerdown",c),function(){o(),t.removeEventListener(c),t.removeEventListener(i)}}function V(){var t;t=c,j.style.right="".concat(100*(1-t),"%"),D.style.left="".concat(100*t,"%"),function(t){Y.style.left="".concat(100*t,"%"),D.style.right="".concat(100*(1-t),"%")}(l),W(!1)}function Z(){p&&(b=void 0,k.removeChild(p),p=void 0,function(){for(var t=w,e=Array.isArray(t),n=0,t=e?t:t[Symbol.iterator]();;){var r;if(e){if(n>=t.length)break;r=t[n++]}else{if((n=t.next()).done)break;r=n.value}var a=r;N.removeChild(a)}w=void 0}(),M.removeChild(x),x=void 0)}Q("left"),Q("right"),U(R,function(t){$=O.getBoundingClientRect(),tt=D.getBoundingClientRect(),rt=t-tt.x,et=$.x,nt=$.x+($.width-tt.width)},function(t){t-=rt,t=((t=Math.max(Math.min(t,nt),et))-$.x)/$.width,c=t,l=t+tt.width/$.width,V()}),function(){d={};for(var t=a.lines,e=Array.isArray(t),n=0,t=e?t:t[Symbol.iterator]();;){var r;if(e){if(n>=t.length)break;r=t[n++]}else{if((n=t.next()).done)break;r=n.value}var o=r;d[o.id]=!0}if(a.x.points.length>E){var i=a.x.points[0],s=a.x.points[a.x.points.length-1],u=a.x.points[a.x.points.length-E];c=(u-i)/(s-i)}else c=0;l=1,V(),W(!0),x=void 0;var h=document.querySelector(".chartogram__chart-togglers");F(h);for(var v=a.lines,m=Array.isArray(v),g=0,v=m?v:v[Symbol.iterator]();;){var f;if(m){if(g>=v.length)break;f=v[g++]}else{if((g=v.next()).done)break;f=g.value}var p=f;h.appendChild(K(p))}}(),function(){var t,e;function n(n){var r=(n-t.x)/t.width,o=u+r*(h-u),i=f.findIndex(function(t){return t>=o}),c=i-1;if(e(i)||(i=-1),e(c)||(c=-1),i<0){if(c<0)return Z();o=f[c]}else if(c<0)o=f[i];else{var l=f[c],A=f[i],E=o-l,L=A-o;o=E>L?A:l}if(o!==b){b=o,p||function(){(p=document.createElement("div")).classList.add("chartogram__tooltip"),k.appendChild(p),(_=document.createElement("h1")).classList.add("chartogram__tooltip-header"),p.appendChild(_),(y=document.createElement("dl")).classList.add("chartogram__tooltip-values"),p.appendChild(y);for(var t=a.lines,e=Array.isArray(t),n=0,t=e?t:t[Symbol.iterator]();;){var r;if(e){if(n>=t.length)break;r=t[n++]}else{if((n=t.next()).done)break;r=n.value}var o=r;if(d[o.id]){var i=document.createElement("dt");i.style.color=o.color,y.appendChild(i);var c=document.createElement("dd");c.style.color=o.color,y.appendChild(c)}}}();var T=new Date(1e3*o+g);_.textContent="".concat(C[T.getDay()],", ").concat(S[T.getMonth()]," ").concat(T.getDate());for(var q=f.indexOf(o),O=0;2*O<y.childNodes.length;)y.childNodes[2*O].textContent=s[O].points[q],y.childNodes[2*O+1].textContent=a.lines[O].name,O++;var j=(o-u)/(h-u);p.style.left="".concat(100*j,"%"),function(t,e){w||function(){w=[];for(var t=0;t<s.length;){var e=document.createElement("div");e.classList.add("chartogram__tooltip-point"),e.style.color=s[t].color,w.push(e),N.appendChild(e),t++}}();for(var n=0;n<w.length;){var r=w[n];r.style.left="".concat(100*e,"%");var a=s[n].points[t],o=a/m;r.style.bottom="".concat(100*o,"%"),n++}}(q,j),function(t){x||((x=document.createElementNS("http://www.w3.org/2000/svg","line")).setAttributeNS(null,"class","chartogram__tooltip-line"),M.insertBefore(x,M.querySelector("polyline"))),x.setAttributeNS(null,"x1",t),x.setAttributeNS(null,"x2",t),x.setAttributeNS(null,"y1",v),x.setAttributeNS(null,"y2",m)}(o)}}function r(){t=M.getBoundingClientRect(),e=function(t){return!(t<0)&&f[t]>=u&&f[t]<=h}}function o(t){if(t.touches.length>1)return l();r(),M.addEventListener("touchend",l),M.addEventListener("touchmove",i),M.addEventListener("touchend",l),M.addEventListener("touchcancel",l),i(t)}function i(e){var r=e.changedTouches[0].clientX,a=e.changedTouches[0].clientY;r<t.x||r>t.x+t.width||a<t.y||a>t.y+t.height?l():n(r)}function c(t){n(t.clientX,t.clientY)}function l(){M.removeEventListener("pointermove",c),M.removeEventListener("pointerleave",l),M.removeEventListener("pointercancel",l),M.removeEventListener("touchmove",i),M.removeEventListener("touchend",l),M.removeEventListener("touchcancel",l),Z()}function A(){r(),M.addEventListener("pointermove",c),M.addEventListener("pointerleave",l),M.addEventListener("pointercancel",l)}M.addEventListener("touchstart",o),M.addEventListener("pointerenter",A)}();var $,tt,et,nt,rt}});
//# sourceMappingURL=chartogram.js.map

@@ -882,3 +882,3 @@ "use strict";

tooltipLine.setAttributeNS(null, 'class', 'chartogram__tooltip-line');
canvas.appendChild(tooltipLine);
canvas.insertBefore(tooltipLine, canvas.querySelector('polyline'));
}

@@ -885,0 +885,0 @@

@@ -875,3 +875,3 @@ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

tooltipLine.setAttributeNS(null, 'class', 'chartogram__tooltip-line');
canvas.appendChild(tooltipLine);
canvas.insertBefore(tooltipLine, canvas.querySelector('polyline'));
}

@@ -878,0 +878,0 @@

{
"name": "chartogram",
"version": "0.1.1",
"version": "0.1.2",
"description": "Charts in JS with no dependencies",

@@ -5,0 +5,0 @@ "main": "index.commonjs.js",

@@ -715,3 +715,3 @@ export default function chartogram(rootNode, data, title = 'Title', options = {}) {

tooltipLine.setAttributeNS(null, 'class', 'chartogram__tooltip-line')
canvas.appendChild(tooltipLine)
canvas.insertBefore(tooltipLine, canvas.querySelector('polyline'))
}

@@ -718,0 +718,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc