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.19 to 0.1.20

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){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")}()}function e(t){for(;t.firstChild;)t.removeChild(t.firstChild)}function n(t,e,n){var i=n&&Math.pow(10,n);i&&(t*=i);var a=Math.floor(t/e);return a=function(t){var e=(i=t,1+(0|Math.log10((i^i>>31)-(i>>31)))),n=1;var i;e>2&&(n=Math.pow(10,e-2),t=Math.floor(t/Math.pow(10,e-2)));if(t>5){var a=t%10;a/t<.2?t-=a:t%2&&t--}return t*n}(a),i&&(a/=i),a*e}function i(t,e){var n,i=0,a=function(){n=void 0,i=Date.now(),t()};return function(){var r=Date.now(),o=e-(r-i);o<=0?(n&&(clearTimeout(n),n=void 0),i=r,t()):n||(n=setTimeout(a,o))}}function a(t,e,n){function i(t){n(t.changedTouches[0].clientX,t.changedTouches[0].clientY)}function a(t){n(t.clientX,t.clientY)}function r(){window.removeEventListener("pointermove",a),window.removeEventListener("touchmove",i),window.removeEventListener("pointerup",r),window.removeEventListener("pointercancel",r),window.removeEventListener("touchend",r),window.removeEventListener("touchcancel",r)}function o(t){if(t.touches.length>1)return r();e(t.changedTouches[0].clientX,t.changedTouches[0].clientY),window.addEventListener("touchmove",i),window.addEventListener("touchend",r),window.addEventListener("touchcancel",r)}function s(t){e(t.clientX,t.clientY),window.addEventListener("pointermove",a),window.addEventListener("pointerup",r),window.addEventListener("pointercancel",r)}return t.addEventListener("touchstart",o),t.addEventListener("pointerdown",s),function(){r(),t.removeEventListener(s),t.removeEventListener(o)}}function r(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function o(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var s=function(){function t(e){var n=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),o(this,"setUpListener",function(){!function(t,e,n,i){var a;function r(t,e){n(t,e,a)}function o(){a=t.getBoundingClientRect(),e()}function s(e){if(e.touches.length>1)return u();o(),t.addEventListener("touchend",u),t.addEventListener("touchmove",h),t.addEventListener("touchend",u),t.addEventListener("touchcancel",u),h(e)}function h(t){var e=t.changedTouches[0].clientX,n=t.changedTouches[0].clientY;e<a.left||e>a.left+a.width||n<a.top||n>a.top+a.height?u():r(e,n)}function c(t){r(t.clientX,t.clientY)}function u(){t.removeEventListener("pointermove",c),t.removeEventListener("pointerleave",u),t.removeEventListener("pointercancel",u),t.removeEventListener("touchmove",h),t.removeEventListener("touchend",u),t.removeEventListener("touchcancel",u),i()}function l(){o(),t.addEventListener("pointermove",c),t.addEventListener("pointerleave",u),t.addEventListener("pointercancel",u)}t.addEventListener("touchstart",s),t.addEventListener("pointerenter",l)}(n.props.canvas,function(){},n.onTrack,function(){return n.unmount()})}),o(this,"onTrack",function(t,e,i){var a,r=n.props,o=r.minX,s=r.maxX,h=r.xPoints,c=o+(t-i.left)/i.width*(s-o),u=h.findIndex(function(t){return t>=c}),l=u-1;if((u<0||u>=h.length)&&(u=-1),(l<0||l>=h.length)&&(l=-1),u<0){if(l<0)return n.unmount();a=l}else if(l<0)a=u;else{var p=h[l],d=h[u];a=c-p>d-c?u:l}var m=h[a];m!==n.tooltipForX&&(n.tooltipForX=m,n.tooltip||n.mount(),n.updateTooltip(m,a,i.width))}),o(this,"unmountLine",function(){n.props.canvas.removeChild(n.line),n.line=void 0}),o(this,"mountPoints",function(){var t=n.props.pointsContainer;n.points=n.renderPoints();var e=n.points,i=Array.isArray(e),a=0;for(e=i?e:e[Symbol.iterator]();;){var r;if(i){if(a>=e.length)break;r=e[a++]}else{if((a=e.next()).done)break;r=a.value}var o=r;t.appendChild(o)}}),o(this,"unmountPoints",function(){var t=n.props.pointsContainer,e=n.points,i=Array.isArray(e),a=0;for(e=i?e:e[Symbol.iterator]();;){var r;if(i){if(a>=e.length)break;r=e[a++]}else{if((a=e.next()).done)break;r=a.value}var o=r;t.removeChild(o)}n.points=void 0}),o(this,"updateLinePosition",function(t){n.isLineRendered()||n.mountLine();var e=n.props,i=e.canvasWidth,a=e.aspectRatio,r=e.fixSvgCoordinate,o=e.mapX;n.line.setAttributeNS(null,"x1",r(o(t))),n.line.setAttributeNS(null,"x2",r(o(t))),n.line.setAttributeNS(null,"y1",0),n.line.setAttributeNS(null,"y2",r(i/a))}),o(this,"updatePointPositions",function(t,e){for(var i=n.props,a=i.maxY,r=i.y,o=0,s=0;o<r.length;){if(r[o].isShown){var h=n.points[s],c=r[o].points[t]/a;h.style.left="".concat(100*e,"%"),h.style.bottom="".concat(100*c,"%"),s++}o++}}),this.props=e}var e,n,i;return e=t,(n=[{key:"componentDidMount",value:function(){this.unlisten=this.setUpListener()}},{key:"componentWillUnmount",value:function(){this.unlisten(),this.unmount()}},{key:"componentDidUpdate",value:function(){}},{key:"mount",value:function(){var t=this.props.container;this.tooltip=this.renderTooltip(),t.appendChild(this.tooltip),this.mountPoints(),this.isLineRendered()||this.mountLine()}},{key:"unmount",value:function(){if(this.tooltip){var t=this.props.container;this.tooltipForX=void 0,t.removeChild(this.tooltip),this.tooltip=void 0,this.unmountPoints(),this.isLineRendered()&&this.unmountLine()}}},{key:"mountLine",value:function(){var t=this.props.canvas;this.line=this.renderLine(),t.insertBefore(this.line,t.querySelector("polyline"))}},{key:"renderTooltip",value:function(){var t=this.props.y,e=document.createElement("div");e.setAttribute("class","chartogram__tooltip");var n=document.createElement("h1");n.setAttribute("class","chartogram__tooltip-header"),e.appendChild(n);var i=document.createElement("ul");i.setAttribute("class","chartogram__tooltip-values"),e.appendChild(i);var a=t,r=Array.isArray(a),o=0;for(a=r?a:a[Symbol.iterator]();;){var s;if(r){if(o>=a.length)break;s=a[o++]}else{if((o=a.next()).done)break;s=o.value}var h=s,c=h.isShown,u=h.color;if(c){var l=document.createElement("li");l.style.color=u,i.appendChild(l);var p=document.createElement("div");l.appendChild(p);var d=document.createElement("div");l.appendChild(d)}}return e}},{key:"renderLine",value:function(){var t=document.createElementNS("http://www.w3.org/2000/svg","line");return t.setAttribute("class","chartogram__tooltip-line"),t}},{key:"isLineRendered",value:function(){var t=this.props.canvas;return this.line&&this.line.parentNode===t}},{key:"renderPoints",value:function(){var t=[],e=this.props,n=e.pointsContainer,i=e.y,a=Array.isArray(i),r=0;for(i=a?i:i[Symbol.iterator]();;){var o;if(a){if(r>=i.length)break;o=i[r++]}else{if((r=i.next()).done)break;o=r.value}var s=o;if(s.isShown){var h=document.createElement("div");h.setAttribute("class","chartogram__tooltip-point"),h.style.color=s.color,t.push(h),n.appendChild(h)}}return t}},{key:"updateTooltip",value:function(t,e,n){var i=this.props,a=i.minX,r=(t-a)/(i.maxX-a);this.updateTooltipXValue(t),this.updateTooltipYValues(e),this.updateTooltipPosition(r,n),this.updatePointPositions(e,r),this.updateLinePosition(t)}},{key:"updateTooltipPosition",value:function(t,e){var n=this.props,i=n.tooltipShift,a=n.maxOverflow,r=Math.round(t*e);r-=void 0===i?40:i,this.tooltip.style.left=0,this.tooltip.parentNode.style.marginRight=0;var o=this.tooltip.getBoundingClientRect().width,s=void 0===a?5:a,h=0;r<0?(h=-1*Math.min(-1*r,s),r=0):r>e-o&&(h=Math.min(r-(e-o),s),r=e-o),this.tooltip.style.left=r+h+"px",this.tooltip.style.marginRight=-h+"px"}},{key:"updateTooltipXValue",value:function(t){var e=this.props.formatX;this.tooltip.childNodes[0].textContent=e(t,{long:!0})}},{key:"updateTooltipYValues",value:function(t){var e=this.props,n=e.y,i=e.formatY,a=this.tooltip.childNodes[1],r=0,o=n,s=Array.isArray(o),h=0;for(o=s?o:o[Symbol.iterator]();;){var c;if(s){if(h>=o.length)break;c=o[h++]}else{if((h=o.next()).done)break;c=h.value}var u=c,l=u.isShown,p=u.points,d=u.name;l&&(a.childNodes[r].childNodes[0].textContent=i(p[t]),a.childNodes[r].childNodes[1].textContent=d,r++)}}}])&&r(e.prototype,n),i&&r(e,i),t}();function h(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function c(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var u=function(){function t(e){var n=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),c(this,"onResize",function(t){n.setState({aspectRatio:n.getCanvasAspectRatio(),canvasWidthPx:n.canvas.getBoundingClientRect().width})}),c(this,"onResizeThrottled",i(this.onResize,33)),c(this,"mapX",function(t){var e=n.props,i=e.canvasWidth,a=e.minX;return(t-a)/(e.maxX-a)*i}),c(this,"mapY",function(t){var e=n.props,i=e.canvasWidth,a=e.minY;return(t-a)/(e.maxY-a)*i/n.state.aspectRatio}),this.props=e}var n,a,r;return n=t,(a=[{key:"componentDidMount",value:function(t){this.canvasWrapper=t.querySelector(".chartogram__canvas-wrapper"),this.canvas=t.querySelector(".chartogram__canvas"),this.xAxis=t.querySelector(".chartogram__x"),this.yAxis=t.querySelector(".chartogram__y"),this.tooltipContainer=t.querySelector(".chartogram__plan"),this.state={aspectRatio:this.getCanvasAspectRatio(),canvasWidthPx:this.canvas.getBoundingClientRect().width},this.updateAspectRatio(),this.mountGridLines(),this.mountXAxis(),this.mountYAxis(),this.mountGraphs(),this.tooltip=new s(this.getTooltipProps()),this.tooltip.componentDidMount(t),this.render(),window.addEventListener("resize",this.onResizeThrottled)}},{key:"componentWillUnmount",value:function(){window.removeEventListener("resize",this.onResizeThrottled)}},{key:"setState",value:function(t){var e=this.state;this.state=function(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{},i=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(n).filter(function(t){return Object.getOwnPropertyDescriptor(n,t).enumerable}))),i.forEach(function(e){c(t,e,n[e])})}return t}({},this.state,t),this.componentDidUpdate(this.props,e)}},{key:"componentDidUpdate",value:function(t,n){n&&(this.state.aspectRatio!==n.aspectRatio&&this.updateAspectRatio(this.state.aspectRatio),this.state.canvasWidthPx!==n.canvasWidthPx&&(e(this.xAxis),this.mountXAxis())),this.render(),this.tooltip.props=this.getTooltipProps(),this.tooltip.componentDidUpdate()}},{key:"getTooltipProps",value:function(){return{canvas:this.canvas,container:this.tooltipContainer,pointsContainer:this.canvasWrapper,formatX:this.props.formatX,formatY:this.props.formatY,canvasWidth:this.props.canvasWidth,aspectRatio:this.state.aspectRatio,mapX:this.mapX,fixSvgCoordinate:this.props.fixSvgCoordinate,minX:this.props.minX,maxX:this.props.maxX,maxY:this.props.maxY,xPoints:this.props.xPoints,y:this.props.y}}},{key:"updateAspectRatio",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.state.aspectRatio,e=this.props,n=e.canvasWidth,i=e.fixSvgCoordinate;this.canvas.setAttribute("viewBox","0 0 ".concat(n," ").concat(i(n/t)))}},{key:"getCanvasAspectRatio",value:function(){var t=this.canvas.getBoundingClientRect();return t.width/t.height}},{key:"render",value:function(){var t=this,e=this.props,n=e.yAxisTickMarksCount,i=e.y,a=e.minX,r=e.maxX,o=e.minY,s=e.maxY,h=e.maxYGaugeMark,c=e.graphOpacity,u=o,l=h,p=(s-o)/(l-u);(function(t,e,n){for(var i=new Array(n),a=0;a<n;)i[a]=t+a*(e-t)/(n-1),a++;return i})(u,l,n).forEach(function(e,n){return t.updateGridLine(n,e)});for(var d=0;d<i.length;){var m=i[d],f=m.isShown,v=m.graphPoints,g=m.color,y=c[d];f||y>0?this.graphs[d]?this.updateGraph(d,v,y):this.mountGraph(d,v,g,y):this.graphs[d]&&this.unmountGraph(d),d++}this.updateAxes(a,r,u,l,p)}},{key:"renderGraph",value:function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,i=document.createElementNS("http://www.w3.org/2000/svg","polyline");return i.setAttribute("stroke",e),i.setAttribute("fill","none"),i.setAttribute("class","chartogram__graph"),this.updateGraph(i,t,n),i}},{key:"renderGridLine",value:function(t){var e=this.props,n=e.fixSvgCoordinate,i=e.minX,a=e.maxX,r=(e.minY,e.maxY),o=document.createElementNS("http://www.w3.org/2000/svg","line");return o.setAttribute("class","chartogram__grid-line"),o.setAttribute("x1",n(this.mapX(i))),o.setAttribute("x2",n(this.mapX(a))),o.setAttribute("y1",n(this.mapY(r-t))),o.setAttribute("y2",n(this.mapY(r-t))),o}},{key:"mountGridLines",value:function(){var t=this.props.yAxisTickMarksCount;this.gridLines=[];for(var e=0;e<t;){var n=this.renderGridLine(0);this.gridLines.push(n),this.canvas.appendChild(n),e++}}},{key:"mountXAxis",value:function(){for(var t=this.getXGaugeTickMarksCount(),e=0;e<t;)this.xAxis.appendChild(document.createElement("div")),e++}},{key:"getXGaugeTickMarksCount",value:function(){var t=this.props.xAxisTickMarkWidth,e=this.state.canvasWidthPx/t;return e=e>2?Math.pow(e-2,.75):0,2+Math.floor(e)}},{key:"mountYAxis",value:function(){for(var t=this.props.yAxisTickMarksCount,e=0;e<t;){var n=document.createElement("div");this.yAxis.appendChild(n);var i=document.createElement("span");i.setAttribute("class","chartogram__y__label"),n.appendChild(i),e++}}},{key:"mountGraphs",value:function(){var t=this;this.graphs=[],this.props.y.forEach(function(e,n){var i=e.graphPoints,a=e.color;t.mountGraph(n,i,a)})}},{key:"mountGraph",value:function(t,e,n,i){var a=this.renderGraph(e,n,i);this.graphs[t]=a,this.canvas.appendChild(a)}},{key:"unmountGraph",value:function(t){this.canvas.removeChild(this.graphs[t]),this.graphs[t]=void 0}},{key:"updateGraph",value:function(t,e,n){var i=this,a=this.props,r=a.createPolylinePoints,o=a.xGraphPoints,s=a.maxY;"number"==typeof t&&(t=this.graphs[t]),t.setAttribute("points",r(o.map(this.mapX),e.map(function(t){return i.mapY(s-t)})).join(" ")),1!==n&&(t.style.opacity=n)}},{key:"updateGridLine",value:function(t,e){var n=this.props,i=n.fixSvgCoordinate,a=n.maxY,r=this.gridLines[t];r.setAttribute("y1",i(this.mapY(a-e))),r.setAttribute("y2",i(this.mapY(a-e)))}},{key:"updateAxes",value:function(t,e,n,i,a){var r=this.props,o=r.formatX,s=r.formatY;this.updateAxis(this.xAxis,t,e,o),this.updateAxis(this.yAxis,n,i,s),this.yAxis.style.height="".concat(100/a,"%")}},{key:"updateAxis",value:function(t,e,n,i){for(var a=t.childNodes.length,r=0;r<a;){var o=t.childNodes[r],s=e+r*(n-e)/(a-1);i&&(s=i(s)),o.firstChild?o.firstChild.textContent=s:o.textContent=s,r++}}}])&&h(n.prototype,a),r&&h(n,r),t}();function l(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=[],i=!0,a=!1,r=void 0;try{for(var o,s=t[Symbol.iterator]();!(i=(o=s.next()).done)&&(n.push(o.value),!e||n.length!==e);i=!0);}catch(t){a=!0,r=t}finally{try{i||null==s.return||s.return()}finally{if(a)throw r}}return n}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function p(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function d(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}u.INITIAL_MARKUP='\n\t<div class="chartogram__plan-with-axes">\n\t\t<div class="chartogram__plan">\n\t\t\t<div class="chartogram__top-border"></div>\n\t\t\t<div class="chartogram__canvas-wrapper">\n\t\t\t\t<svg class="chartogram__canvas"></svg>\n\t\t\t\t<div class="chartogram__x"></div>\n\t\t\t\t<div class="chartogram__y-wrapper">\n\t\t\t\t\t<div class="chartogram__y"></div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>\n\t</div>\n';var m=function(){function e(t){var n=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),d(this,"onResize",function(t){n.setState({aspectRatio:n.getCanvasAspectRatio()})}),d(this,"onResizeThrottled",i(this.onResize,33)),d(this,"setState",function(t){t.aspectRatio!==n.state.aspectRatio&&n.updateAspectRatio(t.aspectRatio),n.state=function(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{},i=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(n).filter(function(t){return Object.getOwnPropertyDescriptor(n,t).enumerable}))),i.forEach(function(e){d(t,e,n[e])})}return t}({},n.state,t),n.render()}),d(this,"mapX",function(t){var e=n.props,i=e.canvasWidth,a=e.data,r=a.minX;return(t-r)/(a.maxX-r)*i}),d(this,"mapY",function(t){var e=n.props,i=e.canvasWidth,a=e.minY;return(t-a)/(e.maxY-a)*i/n.state.aspectRatio}),d(this,"setUpTimelineWindowHandle",function(t){var e,i,r,o,s="left"===t?n.timelineWindowLeftHandle:n.timelineWindowRightHandle,h=parseFloat(getComputedStyle(n.timelineWindow).borderLeftWidth);return a(s,function(a){e=n.timeline.getBoundingClientRect();var s=n.timelineWindow.getBoundingClientRect();"left"===t?(i=e.left,r=s.left+s.width-2*h,o=a-s.left):(i=s.left+2*h,r=e.left+e.width,o=a-(s.left+s.width))},function(a){a-=o;var s=((a=Math.max(Math.min(a,r),i))-e.left)/e.width;s=Math.min(Math.max(s,0),1),"left"===t?n.updateBounds(s,n.props.toRatio):n.updateBounds(n.props.fromRatio,s)})}),d(this,"setUpTimelineWindow",function(){var t,e,i,r,o;return a(n.timelineWindowDrag,function(a){t=n.timeline.getBoundingClientRect(),e=n.timelineWindow.getBoundingClientRect(),o=a-e.left,i=t.left,r=t.left+(t.width-e.width)},function(a){a-=o;var s=((a=Math.max(Math.min(a,r),i))-t.left)/t.width;n.updateBounds(s,s+e.width/t.width)})}),d(this,"setTimelineWindowLeft",function(t){n.timelineOverlayLeft.style.right="".concat(100*(1-t),"%"),n.timelineWindow.style.left="".concat(100*t,"%")}),d(this,"setTimelineWindowRight",function(t){n.timelineOverlayRight.style.left="".concat(100*t,"%"),n.timelineWindow.style.right="".concat(100*(1-t),"%")}),this.props=t}var n,r,o;return n=e,(r=[{key:"componentDidUpdate",value:function(){this.state={aspectRatio:this.getCanvasAspectRatio()},this.onChangeBounds(this.props.fromRatio,this.props.toRatio),this.render()}},{key:"componentDidMount",value:function(t){this.timeline=t.querySelector(".chartogram__timeline"),this.timelineOverlayLeft=t.querySelector(".chartogram__timeline-overlay-left"),this.timelineWindowLeftHandle=t.querySelector(".chartogram__timeline-window__left-handle"),this.timelineWindow=t.querySelector(".chartogram__timeline-window"),this.timelineWindowDrag=t.querySelector(".chartogram__timeline-window__drag"),this.timelineWindowRightHandle=t.querySelector(".chartogram__timeline-window__right-handle"),this.timelineOverlayRight=t.querySelector(".chartogram__timeline-overlay-right"),this.timelineCanvas=t.querySelector(".chartogram__timeline-canvas"),this.state={aspectRatio:this.getCanvasAspectRatio()},this.updateAspectRatio(),this.setUpTimelineWindowHandle("left"),this.setUpTimelineWindowHandle("right"),this.setUpTimelineWindow(),window.addEventListener("resize",this.onResizeThrottled),this.onChangeBounds(this.props.fromRatio,this.props.toRatio),this.mountGraphs(),this.render()}},{key:"componentWillUnmount",value:function(){window.removeEventListener("resize",this.onResizeThrottled)}},{key:"updateAspectRatio",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.state.aspectRatio,e=this.props,n=e.canvasWidth,i=e.fixSvgCoordinate;this.timelineCanvas.setAttribute("viewBox","0 0 ".concat(n," ").concat(i(n/t)))}},{key:"getCanvasAspectRatio",value:function(){var t=this.timelineCanvas.getBoundingClientRect();return t.width/t.height}},{key:"render",value:function(){for(var e=this,n=this.props,i=n.y,a=n.data,r=n.graphOpacity,o=0,s=function(){var n=a.y[o],s=n.id,h=n.points,c=n.color,u=i.find(function(t){return t.id===s}).isShown,p=r[o];if(u||p>0){var d=l(function e(n,i,a){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:Math.max.apply(Math,t(i)),o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:.025,s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0,h=arguments.length>6&&void 0!==arguments[6]?arguments[6]:new Array(n.length),c=arguments.length>7&&void 0!==arguments[7]?arguments[7]:new Array(n.length),u=arguments.length>8&&void 0!==arguments[8]?arguments[8]:0;if(s+2>n.length-1){for(;s<i.length;)h[u]=n[s],c[u]=i[s],u++,s++;return h=h.slice(0,u),c=c.slice(0,u),h.length<=a?[h,c]:(n.length/h.length<1.1&&(o=Math.min(o+.025,1)),e(h,c,a,r,o))}var l=(i[s+2]+i[s])/2;return Math.abs(l-i[s+1])/r<o?(h[u]=n[s],h[u+1]=n[s+2],c[u]=i[s],c[u+1]=i[s+2],e(n,i,a,r,o,s+2,h,c,u+1)):(h[u]=n[s],h[u+1]=n[s+1],h[u+2]=n[s+2],c[u]=i[s],c[u+1]=i[s+1],c[u+2]=i[s+2],e(n,i,a,r,o,s+2,h,c,u+2))}(a.x.points,h,80),2),m=d[0],f=d[1];e.graphs[o]?e.updateGraph(o,m,f,p):e.mountGraph(o,m,f,c,p)}else e.graphs[o]&&e.unmountGraph(o);o++};o<a.y.length;)s()}},{key:"renderGraph",value:function(t,e,n){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,a=document.createElementNS("http://www.w3.org/2000/svg","polyline");return a.setAttribute("stroke",n),a.setAttribute("fill","none"),this.updateGraph(a,t,e,i),a.setAttribute("class","chartogram__graph"),a}},{key:"mountGraphs",value:function(){var t=this;this.graphs=[];var e=this.props.data;e.y.forEach(function(n,i){var a=n.points,r=n.color;t.mountGraph(i,e.x.points,a,r)})}},{key:"mountGraph",value:function(t,e,n,i,a){var r=this.renderGraph(e,n,i,a);this.graphs[t]=r,this.timelineCanvas.appendChild(r)}},{key:"unmountGraph",value:function(t){this.timelineCanvas.removeChild(this.graphs[t]),this.graphs[t]=void 0}},{key:"updateGraph",value:function(t,e,n,i){var a=this,r=this.props,o=r.maxY,s=r.createPolylinePoints;"number"==typeof t&&(t=this.graphs[t]),t.setAttribute("points",s(e.map(this.mapX),n.map(function(t){return a.mapY(o-t)})).join(" ")),1!==i&&(t.style.opacity=i)}},{key:"onChangeBounds",value:function(t,e){this.setTimelineWindowLeft(t),this.setTimelineWindowRight(e)}},{key:"updateBounds",value:function(t,e){this.props.onChangeBounds(t,e),this.props.fromRatio=t,this.props.toRatio=e,this.onChangeBounds(t,e)}}])&&p(n.prototype,r),o&&p(n,o),e}();function f(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function v(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}m.INITIAL_MARKUP='\n\t<div class="chartogram__timeline">\n\t\t<div class="chartogram__timeline-canvas-padding">\n\t\t\t<svg class="chartogram__timeline-canvas"></svg>\n\t\t</div>\n\t\t<div class="chartogram__timeline-overlay-left"></div>\n\t\t<div class="chartogram__timeline-overlay-right"></div>\n\t\t<div class="chartogram__timeline-window">\n\t\t\t<button type="button" class="chartogram__reset-button chartogram__timeline-window__drag"></button>\n\t\t\t<button type="button" class="chartogram__reset-button chartogram__timeline-window__left-handle"></button>\n\t\t\t<button type="button" class="chartogram__reset-button chartogram__timeline-window__right-handle"></button>\n\t\t</div>\n\t</div>\n';var g=function(){function t(e){var n=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),v(this,"renderToggler",function(t){var e=t.id,i=t.name,a=t.color,r=document.createElement("button");r.setAttribute("type","button"),r.setAttribute("class","chartogram__chart-toggler chartogram__reset-button");var o="http://www.w3.org/2000/svg",s=document.createElementNS(o,"svg");s.setAttribute("viewBox","0 0 19 19"),s.setAttribute("class","chartogram__chart-toggler-check");var h=document.createElementNS(o,"circle");h.setAttribute("cx","9.5"),h.setAttribute("cy","9.5"),h.setAttribute("r","9.5"),h.setAttribute("fill",a),s.appendChild(h);var c=document.createElementNS(o,"circle");c.setAttribute("cx","9.5"),c.setAttribute("cy","9.5"),c.setAttribute("r","8"),c.setAttribute("class","chartogram__chart-toggler-check-circle"),c.setAttribute("transform","scale(0)"),s.appendChild(c);var u=document.createElementNS(o,"path");return u.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"),u.setAttribute("fill","white"),u.setAttribute("class","chartogram__chart-toggler-check-mark"),u.setAttribute("transform","scale(1)"),s.appendChild(u),r.appendChild(s),r.appendChild(document.createTextNode(i)),r.addEventListener("click",function(){return n.onToggle(e,r,u,c)}),r}),v(this,"onToggle",function(t,e,i,a){var r=(0,n.props.onToggle)(t);void 0!==r&&(r?(a.setAttribute("transform","scale(0)"),i.setAttribute("transform","scale(1)")):(a.setAttribute("transform","scale(1)"),i.setAttribute("transform","scale(0)")))}),this.props=e}var e,n,i;return e=t,(n=[{key:"componentDidMount",value:function(t){this.togglers=t.querySelector(".chartogram__chart-togglers"),this.mount()}},{key:"mount",value:function(){var t=this.props.data.y,e=Array.isArray(t),n=0;for(t=e?t:t[Symbol.iterator]();;){var i;if(e){if(n>=t.length)break;i=t[n++]}else{if((n=t.next()).done)break;i=n.value}var a=i;this.togglers.appendChild(this.renderToggler(a))}}}])&&f(e.prototype,n),i&&f(e,i),t}();function y(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{},i=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(n).filter(function(t){return Object.getOwnPropertyDescriptor(n,t).enumerable}))),i.forEach(function(e){w(t,e,n[e])})}return t}function b(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function w(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}g.INITIAL_MARKUP='\n\t<div class="chartogram__chart-togglers"></div>\n';var x=function(){function t(e,n,i){var a=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),w(this,"transitions",[]),w(this,"tick",function(){var t,e=y({},a.getState()),n=a.transitions,i=Array.isArray(n),r=0;for(n=i?n:n[Symbol.iterator]();;){var o;if(i){if(r>=n.length)break;o=n[r++]}else{if((r=n.next()).done)break;o=r.value}var s=o;s.tick(e)&&(t=t||[]).push(s)}a.setState(e),t&&(a.transitions=a.transitions.filter(function(e){return t.indexOf(e)<0})),a.transitions.length>0?a.timer=requestAnimationFrame(a.tick):a.timer=void 0}),this.getState=e,this.setState=n,this.props=i}var e,n,i;return e=t,(n=[{key:"cleanUp",value:function(){this.timer&&(cancelAnimationFrame(this.timer),this.timer=void 0)}},{key:"batch",value:function(){this.pendingTransitions=[]}},{key:"run",value:function(){var t=this,e=this.transitions.filter(function(e){var n=t.pendingTransitions,i=Array.isArray(n),a=0;for(n=i?n:n[Symbol.iterator]();;){var r;if(i){if(a>=n.length)break;r=n[a++]}else{if((a=n.next()).done)break;r=a.value}var o=r;if(e.owner===o.owner&&e.property===o.property)return!0}});if(e.length>0){var n=y({},this.getState()),i=e,a=Array.isArray(i),r=0;for(i=a?i:i[Symbol.iterator]();;){var o;if(a){if(r>=i.length)break;o=i[r++]}else{if((r=i.next()).done)break;o=r.value}o.tick(n)}this.setState(n),this.transitions=this.transitions.filter(function(t){return e.indexOf(t)<0})}var s=this.getTransitionDuration(this.pendingTransitions);this.transitions=this.transitions.concat(this.pendingTransitions.map(function(e){return y({},e,{startedAt:Date.now(),duration:s,easing:t.props.transitionEasing,fromValue:e.getter?e.getter(t.getState()):t.getState()[e.property],tick:function(t){var e,n=Date.now()-this.startedAt,i=Math.min(n/this.duration,1);return i=A[this.easing](i),e=this.getNewValue?this.getNewValue(this.fromValue,this.toValue,i):this.fromValue+(this.toValue-this.fromValue)*i,this.setter?this.setter(t,e):t[this.property]=e,1===i}})})),this.pendingTransitions=void 0,this.timer||(this.timer=requestAnimationFrame(this.tick))}},{key:"add",value:function(t,e,n,i){var a,r;"string"!=typeof e&&(a=e,r=n,n=i,e=void 0),this.pendingTransitions.push({owner:t,property:e,getter:a,setter:r,toValue:n})}},{key:"getTransitionDuration",value:function(t){var e=this.props.transitionDuration,n=e,i=t.find(function(t){return"charts"===t.owner&&"minY"===t.property}),a=t.find(function(t){return"charts"===t.owner&&"maxY"===t.property});if(i&&a){var r=this.getState().minY,o=this.getState().maxY,s=i.toValue,h=a.toValue,c=o-r,u=Math.abs(h-o)/c,l=Math.abs(s-r)/c,p=Math.max(l,u);n=e*Math.max(.2,2*Math.min(p,.5))}return n}}])&&b(e.prototype,n),i&&b(e,i),t}(),A={linear:function(t){return t},easeInOutSin:function(t){return(1+Math.sin(Math.PI*t-Math.PI/2))/2},easeInOutQuad:function(t){return t<.5?2*t*t:(4-2*t)*t-1},easeInOutCubic:function(t){return t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1},easeOutCubic:function(t){return--t*t*t+1},easeOutQuad:function(t){return t*(2-t)}};function k(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")}()}function _(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{},i=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(n).filter(function(t){return Object.getOwnPropertyDescriptor(n,t).enumerable}))),i.forEach(function(e){C(t,e,n[e])})}return t}function S(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function C(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var T=function(){function t(e,n){var i=this,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"Title",r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),C(this,"setState",function(t){var e=i.state;i.state=_({},i.state,t),i.componentDidUpdate(i.props,e)}),C(this,"onToggle",function(t){var e=i.state.y.findIndex(function(e){return e.id===t}),n=i.state.y[e];if(n.isShown&&1===i.state.y.filter(function(t){return t.isShown}).length)return;n.isShown=!n.isShown;var a=i.calculateMinMaxY(i.state.y),r=a.minY,o=a.maxY,s=a.minYGlobal,h=a.maxYGlobal,c=a.maxYGaugeMark;return i.transition.batch(),i.transition.add("charts","minY",r),i.transition.add("charts","maxY",o),i.transition.add("charts","maxYGaugeMark",c),i.transition.add("timeline","minYGlobal",s),i.transition.add("timeline","maxYGlobal",h),i.transition.add("graph#".concat(t,"/opacity"),function(t){return t.graphOpacity[e]},function(t,n){t.graphOpacity=t.graphOpacity.slice(),t.graphOpacity[e]=n},n.isShown?1:0),i.transition.run(),n.isShown}),C(this,"onChangeBounds",function(t,e){var n=i.createState(t,e),a=n.minY,r=n.maxY,o=n.maxYGaugeMark;delete n.minY,delete n.maxY,delete n.maxYGaugeMark,i.setState(n),i.transition.batch(),i.transition.add("charts","minY",a),i.transition.add("charts","maxY",r),i.transition.add("charts","maxYGaugeMark",o),i.transition.run()}),C(this,"createPolylinePoints",function(t,e){return n=t.map(i.fixSvgCoordinate),a=e.map(i.fixSvgCoordinate),n.map(function(t,e){return"".concat(t,",").concat(a[e])});var n,a}),C(this,"fixSvgCoordinate",function(t){var e=i.props.precisionFactor;return Math.round(t*e)/e}),C(this,"formatX",function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=i.props,a=n.locale,r=n.formatX;if(r)return r(t,e);i.dateTimeFormatShort||(i.dateTimeFormatShort=new Intl.DateTimeFormat(a,{month:"short",day:"numeric"}),i.dateTimeFormatLong=new Intl.DateTimeFormat(a,{weekday:"short",month:"short",day:"numeric"}),i.dateTimeFormatLongWithYear=new Intl.DateTimeFormat(a,{weekday:"short",year:"numeric",month:"short",day:"numeric"}));var o=new Date(t);return e.long?i.dateTimeFormatLong.format(o):i.dateTimeFormatShort.format(o)}),C(this,"formatY",function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=i.props,a=n.locale,r=n.formatY,o=n.yAxisPrecision;if(r)return r(t,e);i.numberFormat||(i.numberFormat=new Intl.NumberFormat(a,{minimumFractionDigits:o,maximumFractionDigits:o}));var s=o&&Math.pow(10,o);return s&&(t*=s),t=Math.round(t),s&&(t/=s),i.numberFormat.format(t)}),this.props=_({title:a,transitionDuration:250,transitionEasing:"easeOutQuad",xAxisTickMarkWidth:60,yAxisTickMarksCount:6,yAxisPrecision:0,timelineWindowSize:40,canvasWidth:512,precisionFactor:Math.pow(10,r.precision||3)},r),this.rootNode=e,this.data=_({},n,{minX:Math.min.apply(Math,k(n.x.points)),maxX:Math.max.apply(Math,k(n.x.points)),y:n.y.map(function(t){return _({},t,{min:Math.min.apply(Math,k(t.points)),max:Math.max.apply(Math,k(t.points))})})}),this.transition=new x(function(){return i.state},this.setState,this.props)}var i,a,r;return i=t,(a=[{key:"componentDidMount",value:function(){this.rootNode.classList.add("chartogram"),this.rootNode.innerHTML='\n\t\t\t<header class="chartogram__header">\n\t\t\t\t<h1 class="chartogram__title">'.concat(this.props.title,"</h1>\n\t\t\t</header>\n\t\t\t").concat(u.INITIAL_MARKUP,"\n\t\t\t").concat(m.INITIAL_MARKUP,"\n\t\t\t").concat(g.INITIAL_MARKUP,"\n\t\t"),this.state=this.getInitialState(),this.charts=new u(this.getChartsProps()),this.charts.componentDidMount(this.rootNode),this.timeline=new m(this.getTimelineProps()),this.timeline.componentDidMount(this.rootNode),this.togglers=new g(this.getTogglersProps()),this.togglers.componentDidMount(this.rootNode)}},{key:"componentWillUnmount",value:function(){this.charts.componentWillUnmount(),this.timeline.componentWillUnmount(),this.transition.cleanUp(),this.rootNode.classList.remove("chartogram"),e(this.rootNode)}},{key:"componentDidUpdate",value:function(t,e){this.charts.props=this.getChartsProps(),this.charts.componentDidUpdate(),this.shouldUpdateTimeline(e)&&(this.timeline.props=this.getTimelineProps(),this.timeline.componentDidUpdate())}},{key:"shouldUpdateTimeline",value:function(t){return this.state.graphOpacity!==t.graphOpacity||this.state.minYGlobal!==t.minYGlobal||this.state.maxYGlobal!==t.maxYGlobal}},{key:"getChartsProps",value:function(){return _({},this.props,this.state,{createPolylinePoints:this.createPolylinePoints,fixSvgCoordinate:this.fixSvgCoordinate,formatX:this.formatX,formatY:this.formatY})}},{key:"getTimelineProps",value:function(){return{data:this.data,canvasWidth:this.props.canvasWidth,fixSvgCoordinate:this.fixSvgCoordinate,createPolylinePoints:this.createPolylinePoints,fromRatio:this.state.fromRatio,toRatio:this.state.toRatio,minY:this.state.minYGlobal,maxY:this.state.maxYGlobal,y:this.state.y,graphOpacity:this.state.graphOpacity,onChangeBounds:this.onChangeBounds}}},{key:"getTogglersProps",value:function(){return{data:this.data,onToggle:this.onToggle}}},{key:"getInitialState",value:function(){var t,e=this.props.timelineWindowSize,n=this.data,i=n.minX,a=n.maxX;t=this.data.x.points.length>e?this.data.x.points.length-e:0;var r=(this.data.x.points[t]-i)/(a-i);return _({},this.createState(r,1),{graphOpacity:this.data.y.map(function(t){return 1})})}},{key:"createState",value:function(t,e){var n,i,a=this,r=this.data.x,o=this.data.minX+t*(this.data.maxX-this.data.minX),s=this.data.minX+e*(this.data.maxX-this.data.minX);n=o===this.data.minX?0:r.points.findIndex(function(t){return t>o})-1,i=s===this.data.maxX?r.points.length-1:r.points.findIndex(function(t){return t>s});var h=r.points.slice(n,i+1),c=h.slice();h.length>=2&&(r.points[n]!==o&&(c[0]=o),r.points[i]!==s&&(c[c.length-1]=s));var u=this.data.y.map(function(t,e){var c=a.data.y[e].points.slice(n,i+1),u=c.slice();if(h.length>=2){if(r.points[n]!==o){var l=a.data.y[e].points[n],p=l+(a.data.y[e].points[n+1]-l)*((o-a.data.x.points[n])/(a.data.x.points[n+1]-a.data.x.points[n]));u[0]=p}if(r.points[i]!==s){var d=a.data.y[e].points[i],m=a.data.y[e].points[i-1],f=m+(d-m)*((s-a.data.x.points[i-1])/(a.data.x.points[i]-a.data.x.points[i-1]));u[u.length-1]=f}}return _({},a.data.y[e],a.state?a.state.y[e]:{isShown:!0},{points:c,graphPoints:u,min:0,max:Math.max.apply(Math,k(u))})});return _({minX:o,maxX:s,fromIndex:n,toIndex:i,fromRatio:t,toRatio:e,xPoints:h,xGraphPoints:c},this.calculateMinMaxY(u),{y:u})}},{key:"calculateMinMaxY",value:function(t){var e=this.props,i=e.yAxisTickMarksCount,a=e.yAxisPrecision,r=1/0,o=-1/0,s=t,h=Array.isArray(s),c=0;for(s=h?s:s[Symbol.iterator]();;){var u;if(h){if(c>=s.length)break;u=s[c++]}else{if((c=s.next()).done)break;u=c.value}var l=u;l.isShown&&(r=Math.min(r,l.min),o=Math.max(o,l.max))}var p=1/0,d=-1/0,m=function(){if(v){if(g>=f.length)return"break";y=f[g++]}else{if((g=f.next()).done)return"break";y=g.value}var e=y;t.find(function(t){return t.id===e.id}).isShown&&(p=Math.min(p,e.min),d=Math.max(d,e.max))},f=this.data.y,v=Array.isArray(f),g=0;for(f=v?f:f[Symbol.iterator]();;){var y;if("break"===m())break}return{minY:r,maxY:o,minYGlobal:p=0,maxYGlobal:d,maxYGaugeMark:n(.985*o,i-1,a)}}}])&&S(i.prototype,a),r&&S(i,r),t}();return function(t,e,n,i){var a=new T(t,e,n,i);return a.componentDidMount(),function(){a.componentWillUnmount()}}});
!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){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")}()}function e(t){for(;t.firstChild;)t.removeChild(t.firstChild)}function n(t,e,n){var i=n&&Math.pow(10,n);i&&(t*=i);var a=Math.floor(t/e);return a=function(t){var e=(i=t,1+(0|Math.log10((i^i>>31)-(i>>31)))),n=1;var i;e>2&&(n=Math.pow(10,e-2),t=Math.floor(t/Math.pow(10,e-2)));if(t>5){var a=t%10;a/t<.2?t-=a:t%2&&t--}return t*n}(a),i&&(a/=i),a*e}function i(t,e){var n,i=0,a=function(){n=void 0,i=Date.now(),t()};return function(){var r=Date.now(),o=e-(r-i);o<=0?(n&&(clearTimeout(n),n=void 0),i=r,t()):n||(n=setTimeout(a,o))}}function a(t,e,n){function i(t){n(t.changedTouches[0].clientX,t.changedTouches[0].clientY)}function a(t){n(t.clientX,t.clientY)}function r(){window.removeEventListener("pointermove",a),window.removeEventListener("touchmove",i),window.removeEventListener("pointerup",r),window.removeEventListener("pointercancel",r),window.removeEventListener("touchend",r),window.removeEventListener("touchcancel",r)}function o(t){if(t.touches.length>1)return r();e(t.changedTouches[0].clientX,t.changedTouches[0].clientY),window.addEventListener("touchmove",i),window.addEventListener("touchend",r),window.addEventListener("touchcancel",r)}function s(t){e(t.clientX,t.clientY),window.addEventListener("pointermove",a),window.addEventListener("pointerup",r),window.addEventListener("pointercancel",r)}return t.addEventListener("touchstart",o),t.addEventListener("pointerdown",s),function(){r(),t.removeEventListener(s),t.removeEventListener(o)}}function r(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function o(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var s=function(){function t(e){var n=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),o(this,"setUpListener",function(){!function(t,e,n,i){var a;function r(t,e){n(t,e,a)}function o(){a=t.getBoundingClientRect(),e()}function s(e){if(e.touches.length>1)return c();o(),t.addEventListener("touchend",c),t.addEventListener("touchmove",u),t.addEventListener("touchend",c),t.addEventListener("touchcancel",c),u(e)}function u(t){var e=t.changedTouches[0].clientX,n=t.changedTouches[0].clientY;e<a.left||e>a.left+a.width||n<a.top||n>a.top+a.height?c():r(e,n)}function h(t){r(t.clientX,t.clientY)}function c(){t.removeEventListener("pointermove",h),t.removeEventListener("pointerleave",c),t.removeEventListener("pointercancel",c),t.removeEventListener("touchmove",u),t.removeEventListener("touchend",c),t.removeEventListener("touchcancel",c),i()}function l(){o(),t.addEventListener("pointermove",h),t.addEventListener("pointerleave",c),t.addEventListener("pointercancel",c)}t.addEventListener("touchstart",s),t.addEventListener("pointerenter",l)}(n.props.canvas,function(){},n.onTrack,function(){return n.unmount()})}),o(this,"onTrack",function(t,e,i){var a,r=n.props,o=r.minX,s=r.maxX,u=r.xPoints,h=o+(t-i.left)/i.width*(s-o),c=u.findIndex(function(t){return t>=h}),l=c-1;if((c<0||c>=u.length)&&(c=-1),(l<0||l>=u.length)&&(l=-1),c<0){if(l<0)return n.unmount();a=l}else if(l<0)a=c;else{var p=u[l],d=u[c];a=h-p>d-h?c:l}var m=u[a];m!==n.tooltipForX&&(n.tooltipForX=m,n.tooltip||n.mount(),n.updateTooltip(m,a,i.width))}),o(this,"unmountLine",function(){n.props.canvas.removeChild(n.line),n.line=void 0}),o(this,"mountPoints",function(){var t=n.props.pointsContainer;n.points=n.renderPoints();var e=n.points,i=Array.isArray(e),a=0;for(e=i?e:e[Symbol.iterator]();;){var r;if(i){if(a>=e.length)break;r=e[a++]}else{if((a=e.next()).done)break;r=a.value}var o=r;t.appendChild(o)}}),o(this,"unmountPoints",function(){var t=n.props.pointsContainer,e=n.points,i=Array.isArray(e),a=0;for(e=i?e:e[Symbol.iterator]();;){var r;if(i){if(a>=e.length)break;r=e[a++]}else{if((a=e.next()).done)break;r=a.value}var o=r;t.removeChild(o)}n.points=void 0}),o(this,"updateLinePosition",function(t){n.isLineRendered()||n.mountLine();var e=n.props,i=e.canvasWidth,a=e.aspectRatio,r=e.fixSvgCoordinate,o=e.mapX;n.line.setAttributeNS(null,"x1",r(o(t))),n.line.setAttributeNS(null,"x2",r(o(t))),n.line.setAttributeNS(null,"y1",0),n.line.setAttributeNS(null,"y2",r(i/a))}),o(this,"updatePointPositions",function(t,e){for(var i=n.props,a=i.maxY,r=i.y,o=0,s=0;o<r.length;){if(r[o].isShown){var u=n.points[s],h=r[o].points[t]/a;u.style.left="".concat(100*e,"%"),u.style.bottom="".concat(100*h,"%"),s++}o++}}),this.props=e}var e,n,i;return e=t,(n=[{key:"componentDidMount",value:function(){this.unlisten=this.setUpListener()}},{key:"componentWillUnmount",value:function(){this.unlisten(),this.unmount()}},{key:"componentDidUpdate",value:function(){}},{key:"mount",value:function(){var t=this.props.container;this.tooltip=this.renderTooltip(),t.appendChild(this.tooltip),this.mountPoints(),this.isLineRendered()||this.mountLine()}},{key:"unmount",value:function(){if(this.tooltip){var t=this.props.container;this.tooltipForX=void 0,t.removeChild(this.tooltip),this.tooltip=void 0,this.unmountPoints(),this.isLineRendered()&&this.unmountLine()}}},{key:"mountLine",value:function(){var t=this.props.canvas;this.line=this.renderLine(),t.insertBefore(this.line,t.querySelector("polyline"))}},{key:"renderTooltip",value:function(){var t=this.props.y,e=document.createElement("div");e.setAttribute("class","chartogram__tooltip");var n=document.createElement("h1");n.setAttribute("class","chartogram__tooltip-header"),e.appendChild(n);var i=document.createElement("ul");i.setAttribute("class","chartogram__tooltip-values"),e.appendChild(i);var a=t,r=Array.isArray(a),o=0;for(a=r?a:a[Symbol.iterator]();;){var s;if(r){if(o>=a.length)break;s=a[o++]}else{if((o=a.next()).done)break;s=o.value}var u=s,h=u.isShown,c=u.color;if(h){var l=document.createElement("li");l.style.color=c,i.appendChild(l);var p=document.createElement("div");l.appendChild(p);var d=document.createElement("div");l.appendChild(d)}}return e}},{key:"renderLine",value:function(){var t=document.createElementNS("http://www.w3.org/2000/svg","line");return t.setAttribute("class","chartogram__tooltip-line"),t}},{key:"isLineRendered",value:function(){var t=this.props.canvas;return this.line&&this.line.parentNode===t}},{key:"renderPoints",value:function(){var t=[],e=this.props,n=e.pointsContainer,i=e.y,a=Array.isArray(i),r=0;for(i=a?i:i[Symbol.iterator]();;){var o;if(a){if(r>=i.length)break;o=i[r++]}else{if((r=i.next()).done)break;o=r.value}var s=o;if(s.isShown){var u=document.createElement("div");u.setAttribute("class","chartogram__tooltip-point"),u.style.color=s.color,t.push(u),n.appendChild(u)}}return t}},{key:"updateTooltip",value:function(t,e,n){var i=this.props,a=i.minX,r=(t-a)/(i.maxX-a);this.updateTooltipXValue(t),this.updateTooltipYValues(e),this.updateTooltipPosition(r,n),this.updatePointPositions(e,r),this.updateLinePosition(t)}},{key:"updateTooltipPosition",value:function(t,e){var n=this.props,i=n.tooltipShift,a=n.maxOverflow,r=Math.round(t*e);r-=void 0===i?40:i,this.tooltip.style.left=0,this.tooltip.parentNode.style.marginRight=0;var o=this.tooltip.getBoundingClientRect().width,s=void 0===a?5:a,u=0;r<0?(u=-1*Math.min(-1*r,s),r=0):r>e-o&&(u=Math.min(r-(e-o),s),r=e-o),this.tooltip.style.left=r+u+"px",this.tooltip.style.marginRight=-u+"px"}},{key:"updateTooltipXValue",value:function(t){var e=this.props.formatX;this.tooltip.childNodes[0].textContent=e(t,{long:!0})}},{key:"updateTooltipYValues",value:function(t){var e=this.props,n=e.y,i=e.formatY,a=this.tooltip.childNodes[1],r=0,o=n,s=Array.isArray(o),u=0;for(o=s?o:o[Symbol.iterator]();;){var h;if(s){if(u>=o.length)break;h=o[u++]}else{if((u=o.next()).done)break;h=u.value}var c=h,l=c.isShown,p=c.points,d=c.name;l&&(a.childNodes[r].childNodes[0].textContent=i(p[t]),a.childNodes[r].childNodes[1].textContent=d,r++)}}}])&&r(e.prototype,n),i&&r(e,i),t}();function u(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function h(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var c=function(){function t(e){var n=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),h(this,"onResize",function(t){n.setState({aspectRatio:n.getCanvasAspectRatio(),canvasWidthPx:n.canvas.getBoundingClientRect().width})}),h(this,"onResizeThrottled",i(this.onResize,33)),h(this,"mapX",function(t){var e=n.props,i=e.canvasWidth,a=e.minX;return(t-a)/(e.maxX-a)*i}),h(this,"mapY",function(t){var e=n.props,i=e.canvasWidth,a=e.minY;return(t-a)/(e.maxY-a)*i/n.state.aspectRatio}),this.props=e}var n,a,r;return n=t,(a=[{key:"componentDidMount",value:function(t){this.canvasWrapper=t.querySelector(".chartogram__canvas-wrapper"),this.canvas=t.querySelector(".chartogram__canvas"),this.xAxis=t.querySelector(".chartogram__x"),this.yAxis=t.querySelector(".chartogram__y"),this.tooltipContainer=t.querySelector(".chartogram__plan"),this.state={aspectRatio:this.getCanvasAspectRatio(),canvasWidthPx:this.canvas.getBoundingClientRect().width},this.updateAspectRatio(),this.mountGridLines(),this.mountXAxis(),this.mountYAxis(),this.mountGraphs(),this.tooltip=new s(this.getTooltipProps()),this.tooltip.componentDidMount(t),this.render(),window.addEventListener("resize",this.onResizeThrottled)}},{key:"componentWillUnmount",value:function(){window.removeEventListener("resize",this.onResizeThrottled)}},{key:"setState",value:function(t){var e=this.state;this.state=function(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{},i=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(n).filter(function(t){return Object.getOwnPropertyDescriptor(n,t).enumerable}))),i.forEach(function(e){h(t,e,n[e])})}return t}({},this.state,t),this.componentDidUpdate(this.props,e)}},{key:"componentDidUpdate",value:function(t,n){n&&(this.state.aspectRatio!==n.aspectRatio&&this.updateAspectRatio(this.state.aspectRatio),this.state.canvasWidthPx!==n.canvasWidthPx&&(e(this.xAxis),this.mountXAxis())),this.render(),this.tooltip.props=this.getTooltipProps(),this.tooltip.componentDidUpdate()}},{key:"getTooltipProps",value:function(){return{canvas:this.canvas,container:this.tooltipContainer,pointsContainer:this.canvasWrapper,formatX:this.props.formatX,formatY:this.props.formatY,canvasWidth:this.props.canvasWidth,aspectRatio:this.state.aspectRatio,mapX:this.mapX,fixSvgCoordinate:this.props.fixSvgCoordinate,minX:this.props.minX,maxX:this.props.maxX,maxY:this.props.maxY,xPoints:this.props.xPoints,y:this.props.y}}},{key:"updateAspectRatio",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.state.aspectRatio,e=this.props,n=e.canvasWidth,i=e.fixSvgCoordinate;this.canvas.setAttribute("viewBox","0 0 ".concat(n," ").concat(i(n/t)))}},{key:"getCanvasAspectRatio",value:function(){var t=this.canvas.getBoundingClientRect();return t.width/t.height}},{key:"render",value:function(){var t=this,e=this.props,n=e.yAxisTickMarksCount,i=e.y,a=e.minX,r=e.maxX,o=e.minY,s=e.maxY,u=e.maxYGaugeMark,h=e.graphOpacity,c=o,l=u,p=(s-o)/(l-c);(function(t,e,n){for(var i=new Array(n),a=0;a<n;)i[a]=t+a*(e-t)/(n-1),a++;return i})(c,l,n).forEach(function(e,n){return t.updateGridLine(n,e)});for(var d=0;d<i.length;){var m=i[d],f=m.isShown,v=m.graphPoints,g=m.color,y=h[d];f||y>0?this.graphs[d]?this.updateGraph(d,v,y):this.mountGraph(d,v,g,y):this.graphs[d]&&this.unmountGraph(d),d++}this.updateAxes(a,r,c,l,p)}},{key:"renderGraph",value:function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,i=document.createElementNS("http://www.w3.org/2000/svg","polyline");return i.setAttribute("stroke",e),i.setAttribute("fill","none"),i.setAttribute("class","chartogram__graph"),this.updateGraph(i,t,n),i}},{key:"renderGridLine",value:function(t){var e=this.props,n=e.fixSvgCoordinate,i=e.minX,a=e.maxX,r=(e.minY,e.maxY),o=document.createElementNS("http://www.w3.org/2000/svg","line");return o.setAttribute("class","chartogram__grid-line"),o.setAttribute("x1",n(this.mapX(i))),o.setAttribute("x2",n(this.mapX(a))),o.setAttribute("y1",n(this.mapY(r-t))),o.setAttribute("y2",n(this.mapY(r-t))),o}},{key:"mountGridLines",value:function(){var t=this.props.yAxisTickMarksCount;this.gridLines=[];for(var e=0;e<t;){var n=this.renderGridLine(0);this.gridLines.push(n),this.canvas.appendChild(n),e++}}},{key:"mountXAxis",value:function(){for(var t=this.getXGaugeTickMarksCount(),e=0;e<t;)this.xAxis.appendChild(document.createElement("div")),e++}},{key:"getXGaugeTickMarksCount",value:function(){var t=this.props.xAxisTickMarkWidth,e=this.state.canvasWidthPx/t;return e=e>2?Math.pow(e-2,.75):0,2+Math.floor(e)}},{key:"mountYAxis",value:function(){for(var t=this.props.yAxisTickMarksCount,e=0;e<t;){var n=document.createElement("div");this.yAxis.appendChild(n);var i=document.createElement("span");i.setAttribute("class","chartogram__y__label"),n.appendChild(i),e++}}},{key:"mountGraphs",value:function(){var t=this;this.graphs=[],this.props.y.forEach(function(e,n){var i=e.graphPoints,a=e.color;t.mountGraph(n,i,a)})}},{key:"mountGraph",value:function(t,e,n,i){var a=this.renderGraph(e,n,i);this.graphs[t]=a,this.canvas.appendChild(a)}},{key:"unmountGraph",value:function(t){this.canvas.removeChild(this.graphs[t]),this.graphs[t]=void 0}},{key:"updateGraph",value:function(t,e,n){var i=this,a=this.props,r=a.createPolylinePoints,o=a.xGraphPoints,s=a.maxY;"number"==typeof t&&(t=this.graphs[t]),t.setAttribute("points",r(o.map(this.mapX),e.map(function(t){return i.mapY(s-t)})).join(" ")),1!==n&&(t.style.opacity=n)}},{key:"updateGridLine",value:function(t,e){var n=this.props,i=n.fixSvgCoordinate,a=n.maxY,r=this.gridLines[t];r.setAttribute("y1",i(this.mapY(a-e))),r.setAttribute("y2",i(this.mapY(a-e)))}},{key:"updateAxes",value:function(t,e,n,i,a){var r=this.props,o=r.formatX,s=r.formatY;this.updateAxis(this.xAxis,t,e,o),this.updateAxis(this.yAxis,n,i,s),this.yAxis.style.height="".concat(100/a,"%")}},{key:"updateAxis",value:function(t,e,n,i){for(var a=t.childNodes.length,r=0;r<a;){var o=t.childNodes[r],s=e+r*(n-e)/(a-1);i&&(s=i(s)),o.firstChild?o.firstChild.textContent=s:o.textContent=s,r++}}}])&&u(n.prototype,a),r&&u(n,r),t}();function l(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=[],i=!0,a=!1,r=void 0;try{for(var o,s=t[Symbol.iterator]();!(i=(o=s.next()).done)&&(n.push(o.value),!e||n.length!==e);i=!0);}catch(t){a=!0,r=t}finally{try{i||null==s.return||s.return()}finally{if(a)throw r}}return n}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function p(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function d(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}c.INITIAL_MARKUP='\n\t<div class="chartogram__plan-with-axes">\n\t\t<div class="chartogram__plan">\n\t\t\t<div class="chartogram__top-border"></div>\n\t\t\t<div class="chartogram__canvas-wrapper">\n\t\t\t\t<svg class="chartogram__canvas"></svg>\n\t\t\t\t<div class="chartogram__x"></div>\n\t\t\t\t<div class="chartogram__y-wrapper">\n\t\t\t\t\t<div class="chartogram__y"></div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>\n\t</div>\n';var m=function(){function e(t){var n=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),d(this,"onResize",function(t){n.setState({aspectRatio:n.getCanvasAspectRatio()})}),d(this,"onResizeThrottled",i(this.onResize,33)),d(this,"setState",function(t){t.aspectRatio!==n.state.aspectRatio&&n.updateAspectRatio(t.aspectRatio),n.state=function(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{},i=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(n).filter(function(t){return Object.getOwnPropertyDescriptor(n,t).enumerable}))),i.forEach(function(e){d(t,e,n[e])})}return t}({},n.state,t),n.render()}),d(this,"_updateBounds",function(){n.updateBoundsTimeout=void 0;var t=n.updateBoundsFrom,e=n.updateBoundsTo;n.updateBoundsFrom=void 0,n.updateBoundsTo=void 0,n.props.onChangeBounds(t,e),n.props.fromRatio=t,n.props.toRatio=e,n.onChangeBounds(t,e)}),d(this,"mapX",function(t){var e=n.props,i=e.canvasWidth,a=e.data,r=a.minX;return(t-r)/(a.maxX-r)*i}),d(this,"mapY",function(t){var e=n.props,i=e.canvasWidth,a=e.minY;return(t-a)/(e.maxY-a)*i/n.state.aspectRatio}),d(this,"setUpTimelineWindowHandle",function(t){var e,i,r,o,s="left"===t?n.timelineWindowLeftHandle:n.timelineWindowRightHandle,u=parseFloat(getComputedStyle(n.timelineWindow).borderLeftWidth);return a(s,function(a){e=n.timeline.getBoundingClientRect();var s=n.timelineWindow.getBoundingClientRect();"left"===t?(i=e.left,r=s.left+s.width-2*u,o=a-s.left):(i=s.left+2*u,r=e.left+e.width,o=a-(s.left+s.width))},function(a){a-=o;var s=((a=Math.max(Math.min(a,r),i))-e.left)/e.width;s=Math.min(Math.max(s,0),1),"left"===t?n.updateBounds(s,n.props.toRatio):n.updateBounds(n.props.fromRatio,s)})}),d(this,"setUpTimelineWindow",function(){var t,e,i,r,o;return a(n.timelineWindowDrag,function(a){t=n.timeline.getBoundingClientRect(),e=n.timelineWindow.getBoundingClientRect(),o=a-e.left,i=t.left,r=t.left+(t.width-e.width)},function(a){a-=o;var s=((a=Math.max(Math.min(a,r),i))-t.left)/t.width;n.updateBounds(s,s+e.width/t.width)})}),d(this,"setTimelineWindowLeft",function(t){n.timelineOverlayLeft.style.right="".concat(100*(1-t),"%"),n.timelineWindow.style.left="".concat(100*t,"%")}),d(this,"setTimelineWindowRight",function(t){n.timelineOverlayRight.style.left="".concat(100*t,"%"),n.timelineWindow.style.right="".concat(100*(1-t),"%")}),this.props=t}var n,r,o;return n=e,(r=[{key:"componentDidUpdate",value:function(){this.state={aspectRatio:this.getCanvasAspectRatio()},this.onChangeBounds(this.props.fromRatio,this.props.toRatio),this.render()}},{key:"componentDidMount",value:function(t){this.timeline=t.querySelector(".chartogram__timeline"),this.timelineOverlayLeft=t.querySelector(".chartogram__timeline-overlay-left"),this.timelineWindowLeftHandle=t.querySelector(".chartogram__timeline-window__left-handle"),this.timelineWindow=t.querySelector(".chartogram__timeline-window"),this.timelineWindowDrag=t.querySelector(".chartogram__timeline-window__drag"),this.timelineWindowRightHandle=t.querySelector(".chartogram__timeline-window__right-handle"),this.timelineOverlayRight=t.querySelector(".chartogram__timeline-overlay-right"),this.timelineCanvas=t.querySelector(".chartogram__timeline-canvas"),this.state={aspectRatio:this.getCanvasAspectRatio()},this.updateAspectRatio(),this.setUpTimelineWindowHandle("left"),this.setUpTimelineWindowHandle("right"),this.setUpTimelineWindow(),window.addEventListener("resize",this.onResizeThrottled),this.onChangeBounds(this.props.fromRatio,this.props.toRatio),this.mountGraphs(),this.render()}},{key:"componentWillUnmount",value:function(){window.removeEventListener("resize",this.onResizeThrottled),this.updateBoundsTimeout&&cancelAnimationFrame(this.updateBoundsTimeout)}},{key:"updateAspectRatio",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.state.aspectRatio,e=this.props,n=e.canvasWidth,i=e.fixSvgCoordinate;this.timelineCanvas.setAttribute("viewBox","0 0 ".concat(n," ").concat(i(n/t)))}},{key:"getCanvasAspectRatio",value:function(){var t=this.timelineCanvas.getBoundingClientRect();return t.width/t.height}},{key:"render",value:function(){for(var e=this,n=this.props,i=n.y,a=n.data,r=n.graphOpacity,o=0,s=function(){var n=a.y[o],s=n.id,u=n.points,h=n.color,c=i.find(function(t){return t.id===s}).isShown,p=r[o];if(c||p>0){var d=l(function e(n,i,a){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:Math.max.apply(Math,t(i)),o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:.025,s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0,u=arguments.length>6&&void 0!==arguments[6]?arguments[6]:new Array(n.length),h=arguments.length>7&&void 0!==arguments[7]?arguments[7]:new Array(n.length),c=arguments.length>8&&void 0!==arguments[8]?arguments[8]:0;if(s+2>n.length-1){for(;s<i.length;)u[c]=n[s],h[c]=i[s],c++,s++;return u=u.slice(0,c),h=h.slice(0,c),u.length<=a?[u,h]:(n.length/u.length<1.1&&(o=Math.min(o+.025,1)),e(u,h,a,r,o))}var l=(i[s+2]+i[s])/2;return Math.abs(l-i[s+1])/r<o?(u[c]=n[s],u[c+1]=n[s+2],h[c]=i[s],h[c+1]=i[s+2],e(n,i,a,r,o,s+2,u,h,c+1)):(u[c]=n[s],u[c+1]=n[s+1],u[c+2]=n[s+2],h[c]=i[s],h[c+1]=i[s+1],h[c+2]=i[s+2],e(n,i,a,r,o,s+2,u,h,c+2))}(a.x.points,u,80),2),m=d[0],f=d[1];e.graphs[o]?e.updateGraph(o,m,f,p):e.mountGraph(o,m,f,h,p)}else e.graphs[o]&&e.unmountGraph(o);o++};o<a.y.length;)s()}},{key:"renderGraph",value:function(t,e,n){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,a=document.createElementNS("http://www.w3.org/2000/svg","polyline");return a.setAttribute("stroke",n),a.setAttribute("fill","none"),this.updateGraph(a,t,e,i),a.setAttribute("class","chartogram__graph"),a}},{key:"mountGraphs",value:function(){var t=this;this.graphs=[];var e=this.props.data;e.y.forEach(function(n,i){var a=n.points,r=n.color;t.mountGraph(i,e.x.points,a,r)})}},{key:"mountGraph",value:function(t,e,n,i,a){var r=this.renderGraph(e,n,i,a);this.graphs[t]=r,this.timelineCanvas.appendChild(r)}},{key:"unmountGraph",value:function(t){this.timelineCanvas.removeChild(this.graphs[t]),this.graphs[t]=void 0}},{key:"updateGraph",value:function(t,e,n,i){var a=this,r=this.props,o=r.maxY,s=r.createPolylinePoints;"number"==typeof t&&(t=this.graphs[t]),t.setAttribute("points",s(e.map(this.mapX),n.map(function(t){return a.mapY(o-t)})).join(" ")),1!==i&&(t.style.opacity=i)}},{key:"onChangeBounds",value:function(t,e){this.setTimelineWindowLeft(t),this.setTimelineWindowRight(e)}},{key:"updateBounds",value:function(t,e){this.updateBoundsFrom=t,this.updateBoundsTo=e,this.updateBoundsTimeout||(this.updateBoundsTimeout=requestAnimationFrame(this._updateBounds))}}])&&p(n.prototype,r),o&&p(n,o),e}();function f(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function v(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}m.INITIAL_MARKUP='\n\t<div class="chartogram__timeline">\n\t\t<div class="chartogram__timeline-canvas-padding">\n\t\t\t<svg class="chartogram__timeline-canvas"></svg>\n\t\t</div>\n\t\t<div class="chartogram__timeline-overlay-left"></div>\n\t\t<div class="chartogram__timeline-overlay-right"></div>\n\t\t<div class="chartogram__timeline-window">\n\t\t\t<button type="button" class="chartogram__reset-button chartogram__timeline-window__drag"></button>\n\t\t\t<button type="button" class="chartogram__reset-button chartogram__timeline-window__left-handle"></button>\n\t\t\t<button type="button" class="chartogram__reset-button chartogram__timeline-window__right-handle"></button>\n\t\t</div>\n\t</div>\n';var g=function(){function t(e){var n=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),v(this,"renderToggler",function(t){var e=t.id,i=t.name,a=t.color,r=document.createElement("button");r.setAttribute("type","button"),r.setAttribute("class","chartogram__chart-toggler chartogram__reset-button");var o="http://www.w3.org/2000/svg",s=document.createElementNS(o,"svg");s.setAttribute("viewBox","0 0 19 19"),s.setAttribute("class","chartogram__chart-toggler-check");var u=document.createElementNS(o,"circle");u.setAttribute("cx","9.5"),u.setAttribute("cy","9.5"),u.setAttribute("r","9.5"),u.setAttribute("fill",a),s.appendChild(u);var h=document.createElementNS(o,"circle");h.setAttribute("cx","9.5"),h.setAttribute("cy","9.5"),h.setAttribute("r","8"),h.setAttribute("class","chartogram__chart-toggler-check-circle"),h.setAttribute("transform","scale(0)"),s.appendChild(h);var c=document.createElementNS(o,"path");return c.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"),c.setAttribute("fill","white"),c.setAttribute("class","chartogram__chart-toggler-check-mark"),c.setAttribute("transform","scale(1)"),s.appendChild(c),r.appendChild(s),r.appendChild(document.createTextNode(i)),r.addEventListener("click",function(){return n.onToggle(e,r,c,h)}),r}),v(this,"onToggle",function(t,e,i,a){var r=(0,n.props.onToggle)(t);void 0!==r&&(r?(a.setAttribute("transform","scale(0)"),i.setAttribute("transform","scale(1)")):(a.setAttribute("transform","scale(1)"),i.setAttribute("transform","scale(0)")))}),this.props=e}var e,n,i;return e=t,(n=[{key:"componentDidMount",value:function(t){this.togglers=t.querySelector(".chartogram__chart-togglers"),this.mount()}},{key:"mount",value:function(){var t=this.props.data.y,e=Array.isArray(t),n=0;for(t=e?t:t[Symbol.iterator]();;){var i;if(e){if(n>=t.length)break;i=t[n++]}else{if((n=t.next()).done)break;i=n.value}var a=i;this.togglers.appendChild(this.renderToggler(a))}}}])&&f(e.prototype,n),i&&f(e,i),t}();function y(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{},i=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(n).filter(function(t){return Object.getOwnPropertyDescriptor(n,t).enumerable}))),i.forEach(function(e){w(t,e,n[e])})}return t}function b(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function w(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}g.INITIAL_MARKUP='\n\t<div class="chartogram__chart-togglers"></div>\n';var x=function(){function t(e,n,i){var a=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),w(this,"transitions",[]),w(this,"tick",function(){var t,e=y({},a.getState()),n=a.transitions,i=Array.isArray(n),r=0;for(n=i?n:n[Symbol.iterator]();;){var o;if(i){if(r>=n.length)break;o=n[r++]}else{if((r=n.next()).done)break;o=r.value}var s=o;s.tick(e)&&(t=t||[]).push(s)}a.setState(e),t&&(a.transitions=a.transitions.filter(function(e){return t.indexOf(e)<0})),a.transitions.length>0?a.timer=requestAnimationFrame(a.tick):a.timer=void 0}),this.getState=e,this.setState=n,this.props=i}var e,n,i;return e=t,(n=[{key:"cleanUp",value:function(){this.timer&&(cancelAnimationFrame(this.timer),this.timer=void 0)}},{key:"batch",value:function(){this.pendingTransitions=[]}},{key:"run",value:function(){var t=this,e=this.transitions.filter(function(e){var n=t.pendingTransitions,i=Array.isArray(n),a=0;for(n=i?n:n[Symbol.iterator]();;){var r;if(i){if(a>=n.length)break;r=n[a++]}else{if((a=n.next()).done)break;r=a.value}var o=r;if(e.owner===o.owner&&e.property===o.property)return!0}});if(e.length>0){var n=y({},this.getState()),i=e,a=Array.isArray(i),r=0;for(i=a?i:i[Symbol.iterator]();;){var o;if(a){if(r>=i.length)break;o=i[r++]}else{if((r=i.next()).done)break;o=r.value}o.tick(n)}this.setState(n),this.transitions=this.transitions.filter(function(t){return e.indexOf(t)<0})}var s=this.getTransitionDuration(this.pendingTransitions);this.transitions=this.transitions.concat(this.pendingTransitions.map(function(e){return y({},e,{startedAt:Date.now(),duration:s,easing:t.props.transitionEasing,fromValue:e.getter?e.getter(t.getState()):t.getState()[e.property],tick:function(t){var e,n=Date.now()-this.startedAt,i=Math.min(n/this.duration,1);return i=A[this.easing](i),e=this.getNewValue?this.getNewValue(this.fromValue,this.toValue,i):this.fromValue+(this.toValue-this.fromValue)*i,this.setter?this.setter(t,e):t[this.property]=e,1===i}})})),this.pendingTransitions=void 0,this.timer||(this.timer=requestAnimationFrame(this.tick))}},{key:"add",value:function(t,e,n,i){var a,r;"string"!=typeof e&&(a=e,r=n,n=i,e=void 0),this.pendingTransitions.push({owner:t,property:e,getter:a,setter:r,toValue:n})}},{key:"getTransitionDuration",value:function(t){var e=this.props.transitionDuration,n=e,i=t.find(function(t){return"charts"===t.owner&&"minY"===t.property}),a=t.find(function(t){return"charts"===t.owner&&"maxY"===t.property});if(i&&a){var r=this.getState().minY,o=this.getState().maxY,s=i.toValue,u=a.toValue,h=o-r,c=Math.abs(u-o)/h,l=Math.abs(s-r)/h,p=Math.max(l,c);n=e*Math.max(.2,2*Math.min(p,.5))}return n}}])&&b(e.prototype,n),i&&b(e,i),t}(),A={linear:function(t){return t},easeInOutSin:function(t){return(1+Math.sin(Math.PI*t-Math.PI/2))/2},easeInOutQuad:function(t){return t<.5?2*t*t:(4-2*t)*t-1},easeInOutCubic:function(t){return t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1},easeOutCubic:function(t){return--t*t*t+1},easeOutQuad:function(t){return t*(2-t)}};function k(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")}()}function _(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{},i=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(n).filter(function(t){return Object.getOwnPropertyDescriptor(n,t).enumerable}))),i.forEach(function(e){T(t,e,n[e])})}return t}function S(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function T(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var C=function(){function t(e,n){var i=this,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"Title",r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),T(this,"setState",function(t){var e=i.state;i.state=_({},i.state,t),i.componentDidUpdate(i.props,e)}),T(this,"onToggle",function(t){var e=i.state.y.findIndex(function(e){return e.id===t}),n=i.state.y[e];if(n.isShown&&1===i.state.y.filter(function(t){return t.isShown}).length)return;n.isShown=!n.isShown;var a=i.calculateMinMaxY(i.state.y),r=a.minY,o=a.maxY,s=a.minYGlobal,u=a.maxYGlobal,h=a.maxYGaugeMark;return i.transition.batch(),i.transition.add("charts","minY",r),i.transition.add("charts","maxY",o),i.transition.add("charts","maxYGaugeMark",h),i.transition.add("timeline","minYGlobal",s),i.transition.add("timeline","maxYGlobal",u),i.transition.add("graph#".concat(t,"/opacity"),function(t){return t.graphOpacity[e]},function(t,n){t.graphOpacity=t.graphOpacity.slice(),t.graphOpacity[e]=n},n.isShown?1:0),i.transition.run(),n.isShown}),T(this,"onChangeBounds",function(t,e){var n=i.createState(t,e),a=n.minY,r=n.maxY,o=n.maxYGaugeMark;delete n.minY,delete n.maxY,delete n.maxYGaugeMark,i.setState(n),i.transition.batch(),i.transition.add("charts","minY",a),i.transition.add("charts","maxY",r),i.transition.add("charts","maxYGaugeMark",o),i.transition.run()}),T(this,"createPolylinePoints",function(t,e){return n=t.map(i.fixSvgCoordinate),a=e.map(i.fixSvgCoordinate),n.map(function(t,e){return"".concat(t,",").concat(a[e])});var n,a}),T(this,"fixSvgCoordinate",function(t){var e=i.props.precisionFactor;return Math.round(t*e)/e}),T(this,"formatX",function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=i.props,a=n.locale,r=n.formatX;if(r)return r(t,e);i.dateTimeFormatShort||(i.dateTimeFormatShort=new Intl.DateTimeFormat(a,{month:"short",day:"numeric"}),i.dateTimeFormatLong=new Intl.DateTimeFormat(a,{weekday:"short",month:"short",day:"numeric"}),i.dateTimeFormatLongWithYear=new Intl.DateTimeFormat(a,{weekday:"short",year:"numeric",month:"short",day:"numeric"}));var o=new Date(t);return e.long?i.dateTimeFormatLong.format(o):i.dateTimeFormatShort.format(o)}),T(this,"formatY",function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=i.props,a=n.locale,r=n.formatY,o=n.yAxisPrecision;if(r)return r(t,e);i.numberFormat||(i.numberFormat=new Intl.NumberFormat(a,{minimumFractionDigits:o,maximumFractionDigits:o}));var s=o&&Math.pow(10,o);return s&&(t*=s),t=Math.round(t),s&&(t/=s),i.numberFormat.format(t)}),this.props=_({title:a,transitionDuration:250,transitionEasing:"easeOutQuad",xAxisTickMarkWidth:60,yAxisTickMarksCount:6,yAxisPrecision:0,timelineWindowSize:40,canvasWidth:512,precisionFactor:Math.pow(10,r.precision||3)},r),this.rootNode=e,this.data=_({},n,{minX:Math.min.apply(Math,k(n.x.points)),maxX:Math.max.apply(Math,k(n.x.points)),y:n.y.map(function(t){return _({},t,{min:Math.min.apply(Math,k(t.points)),max:Math.max.apply(Math,k(t.points))})})}),this.transition=new x(function(){return i.state},this.setState,this.props)}var i,a,r;return i=t,(a=[{key:"componentDidMount",value:function(){this.rootNode.classList.add("chartogram"),this.rootNode.innerHTML='\n\t\t\t<header class="chartogram__header">\n\t\t\t\t<h1 class="chartogram__title">'.concat(this.props.title,"</h1>\n\t\t\t</header>\n\t\t\t").concat(c.INITIAL_MARKUP,"\n\t\t\t").concat(m.INITIAL_MARKUP,"\n\t\t\t").concat(g.INITIAL_MARKUP,"\n\t\t"),this.state=this.getInitialState(),this.charts=new c(this.getChartsProps()),this.charts.componentDidMount(this.rootNode),this.timeline=new m(this.getTimelineProps()),this.timeline.componentDidMount(this.rootNode),this.togglers=new g(this.getTogglersProps()),this.togglers.componentDidMount(this.rootNode)}},{key:"componentWillUnmount",value:function(){this.charts.componentWillUnmount(),this.timeline.componentWillUnmount(),this.transition.cleanUp(),this.rootNode.classList.remove("chartogram"),e(this.rootNode)}},{key:"componentDidUpdate",value:function(t,e){this.charts.props=this.getChartsProps(),this.charts.componentDidUpdate(),this.shouldUpdateTimeline(e)&&(this.timeline.props=this.getTimelineProps(),this.timeline.componentDidUpdate())}},{key:"shouldUpdateTimeline",value:function(t){return this.state.graphOpacity!==t.graphOpacity||this.state.minYGlobal!==t.minYGlobal||this.state.maxYGlobal!==t.maxYGlobal}},{key:"getChartsProps",value:function(){return _({},this.props,this.state,{createPolylinePoints:this.createPolylinePoints,fixSvgCoordinate:this.fixSvgCoordinate,formatX:this.formatX,formatY:this.formatY})}},{key:"getTimelineProps",value:function(){return{data:this.data,canvasWidth:this.props.canvasWidth,fixSvgCoordinate:this.fixSvgCoordinate,createPolylinePoints:this.createPolylinePoints,fromRatio:this.state.fromRatio,toRatio:this.state.toRatio,minY:this.state.minYGlobal,maxY:this.state.maxYGlobal,y:this.state.y,graphOpacity:this.state.graphOpacity,onChangeBounds:this.onChangeBounds}}},{key:"getTogglersProps",value:function(){return{data:this.data,onToggle:this.onToggle}}},{key:"getInitialState",value:function(){var t,e=this.props.timelineWindowSize,n=this.data,i=n.minX,a=n.maxX;t=this.data.x.points.length>e?this.data.x.points.length-e:0;var r=(this.data.x.points[t]-i)/(a-i);return _({},this.createState(r,1),{graphOpacity:this.data.y.map(function(t){return 1})})}},{key:"createState",value:function(t,e){var n,i,a=this,r=this.data.x,o=this.data.minX+t*(this.data.maxX-this.data.minX),s=this.data.minX+e*(this.data.maxX-this.data.minX);n=o===this.data.minX?0:r.points.findIndex(function(t){return t>o})-1,i=s===this.data.maxX?r.points.length-1:r.points.findIndex(function(t){return t>s});var u=r.points.slice(n,i+1),h=u.slice();u.length>=2&&(r.points[n]!==o&&(h[0]=o),r.points[i]!==s&&(h[h.length-1]=s));var c=this.data.y.map(function(t,e){var h=a.data.y[e].points.slice(n,i+1),c=h.slice();if(u.length>=2){if(r.points[n]!==o){var l=a.data.y[e].points[n],p=l+(a.data.y[e].points[n+1]-l)*((o-a.data.x.points[n])/(a.data.x.points[n+1]-a.data.x.points[n]));c[0]=p}if(r.points[i]!==s){var d=a.data.y[e].points[i],m=a.data.y[e].points[i-1],f=m+(d-m)*((s-a.data.x.points[i-1])/(a.data.x.points[i]-a.data.x.points[i-1]));c[c.length-1]=f}}return _({},a.data.y[e],a.state?a.state.y[e]:{isShown:!0},{points:h,graphPoints:c,min:0,max:Math.max.apply(Math,k(c))})});return _({minX:o,maxX:s,fromIndex:n,toIndex:i,fromRatio:t,toRatio:e,xPoints:u,xGraphPoints:h},this.calculateMinMaxY(c),{y:c})}},{key:"calculateMinMaxY",value:function(t){var e=this.props,i=e.yAxisTickMarksCount,a=e.yAxisPrecision,r=1/0,o=-1/0,s=t,u=Array.isArray(s),h=0;for(s=u?s:s[Symbol.iterator]();;){var c;if(u){if(h>=s.length)break;c=s[h++]}else{if((h=s.next()).done)break;c=h.value}var l=c;l.isShown&&(r=Math.min(r,l.min),o=Math.max(o,l.max))}var p=1/0,d=-1/0,m=function(){if(v){if(g>=f.length)return"break";y=f[g++]}else{if((g=f.next()).done)return"break";y=g.value}var e=y;t.find(function(t){return t.id===e.id}).isShown&&(p=Math.min(p,e.min),d=Math.max(d,e.max))},f=this.data.y,v=Array.isArray(f),g=0;for(f=v?f:f[Symbol.iterator]();;){var y;if("break"===m())break}return{minY:r,maxY:o,minYGlobal:p=0,maxYGlobal:d,maxYGaugeMark:n(.985*o,i-1,a)}}}])&&S(i.prototype,a),r&&S(i,r),t}();return function(t,e,n,i){var a=new C(t,e,n,i);return a.componentDidMount(),function(){a.componentWillUnmount()}}});
//# sourceMappingURL=chartogram.js.map

@@ -57,2 +57,17 @@ "use strict";

_defineProperty(this, "_updateBounds", function () {
_this.updateBoundsTimeout = undefined;
var from = _this.updateBoundsFrom;
var to = _this.updateBoundsTo;
_this.updateBoundsFrom = undefined;
_this.updateBoundsTo = undefined; // Update bounds.
_this.props.onChangeBounds(from, to);
_this.props.fromRatio = from;
_this.props.toRatio = to;
_this.onChangeBounds(from, to);
});
_defineProperty(this, "mapX", function (x) {

@@ -198,2 +213,6 @@ var _this$props = _this.props,

window.removeEventListener('resize', this.onResizeThrottled);
if (this.updateBoundsTimeout) {
cancelAnimationFrame(this.updateBoundsTimeout);
}
}

@@ -328,6 +347,9 @@ }, {

value: function updateBounds(from, to) {
this.props.onChangeBounds(from, to);
this.props.fromRatio = from;
this.props.toRatio = to;
this.onChangeBounds(from, to);
this.updateBoundsFrom = from;
this.updateBoundsTo = to;
if (!this.updateBoundsTimeout) {
// Schedule bounds update.
this.updateBoundsTimeout = requestAnimationFrame(this._updateBounds);
}
}

@@ -334,0 +356,0 @@ }]);

@@ -49,2 +49,17 @@ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

_defineProperty(this, "_updateBounds", function () {
_this.updateBoundsTimeout = undefined;
var from = _this.updateBoundsFrom;
var to = _this.updateBoundsTo;
_this.updateBoundsFrom = undefined;
_this.updateBoundsTo = undefined; // Update bounds.
_this.props.onChangeBounds(from, to);
_this.props.fromRatio = from;
_this.props.toRatio = to;
_this.onChangeBounds(from, to);
});
_defineProperty(this, "mapX", function (x) {

@@ -190,2 +205,6 @@ var _this$props = _this.props,

window.removeEventListener('resize', this.onResizeThrottled);
if (this.updateBoundsTimeout) {
cancelAnimationFrame(this.updateBoundsTimeout);
}
}

@@ -320,6 +339,9 @@ }, {

value: function updateBounds(from, to) {
this.props.onChangeBounds(from, to);
this.props.fromRatio = from;
this.props.toRatio = to;
this.onChangeBounds(from, to);
this.updateBoundsFrom = from;
this.updateBoundsTo = to;
if (!this.updateBoundsTimeout) {
// Schedule bounds update.
this.updateBoundsTimeout = requestAnimationFrame(this._updateBounds);
}
}

@@ -326,0 +348,0 @@ }]);

{
"name": "chartogram",
"version": "0.1.19",
"version": "0.1.20",
"description": "Charts in JS with no dependencies",

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

@@ -58,2 +58,5 @@ import {

window.removeEventListener('resize', this.onResizeThrottled)
if (this.updateBoundsTimeout) {
cancelAnimationFrame(this.updateBoundsTimeout)
}
}

@@ -162,2 +165,17 @@

updateBounds(from, to) {
this.updateBoundsFrom = from
this.updateBoundsTo = to
if (!this.updateBoundsTimeout) {
// Schedule bounds update.
this.updateBoundsTimeout = requestAnimationFrame(this._updateBounds)
}
}
_updateBounds = () => {
this.updateBoundsTimeout = undefined
const from = this.updateBoundsFrom
const to = this.updateBoundsTo
this.updateBoundsFrom = undefined
this.updateBoundsTo = undefined
// Update bounds.
this.props.onChangeBounds(from, to)

@@ -164,0 +182,0 @@ this.props.fromRatio = from

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