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.18 to 0.1.19

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 a=n&&Math.pow(10,n);a&&(t*=a);var r=Math.floor(t/e);return r=function(t){var e,n=(r=t,1+(0|Math.log10((r^r>>31)-(r>>31)))),a=1;var r;n>2&&(a=Math.pow(10,n-2),t=Math.floor(t/Math.pow(10,n-2)));for(var o=i,s=0;s<o.length;s++){var h=o[s];if(!(t>h.threshold))break;e=h}if(e){var u=t%e.adjustment;u&&(t-=u)}return t*a}(r),a&&(r/=a),r*e}var i=[{threshold:5,adjustment:2},{threshold:40,adjustment:10}];function a(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 r(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 o(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 s(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var h=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),s(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",h),t.addEventListener("touchend",c),t.addEventListener("touchcancel",c),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?c():r(e,n)}function u(t){r(t.clientX,t.clientY)}function c(){t.removeEventListener("pointermove",u),t.removeEventListener("pointerleave",c),t.removeEventListener("pointercancel",c),t.removeEventListener("touchmove",h),t.removeEventListener("touchend",c),t.removeEventListener("touchcancel",c),i()}function l(){o(),t.addEventListener("pointermove",u),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()})}),s(this,"onTrack",function(t,e,i){var a,r=n.props,o=r.minX,s=r.maxX,h=r.xPoints,u=o+(t-i.left)/i.width*(s-o),c=h.findIndex(function(t){return t>=u}),l=c-1;if((c<0||c>=h.length)&&(c=-1),(l<0||l>=h.length)&&(l=-1),c<0){if(l<0)return n.unmount();a=l}else if(l<0)a=c;else{var p=h[l],d=h[c];a=u-p>d-u?c:l}var m=h[a];m!==n.tooltipForX&&(n.tooltipForX=m,n.tooltip||n.mount(),n.updateTooltip(m,a,i.width))}),s(this,"unmountLine",function(){n.props.canvas.removeChild(n.line),n.line=void 0}),s(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)}}),s(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}),s(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))}),s(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],u=r[o].points[t]/a;h.style.left="".concat(100*e,"%"),h.style.bottom="".concat(100*u,"%"),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,u=h.isShown,c=h.color;if(u){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 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.y,n=this.tooltip.childNodes[1],i=0,a=e,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,u=h.isShown,c=h.points,l=h.name;u&&(n.childNodes[i].childNodes[0].textContent=c[t],n.childNodes[i].childNodes[1].textContent=l,i++)}}}])&&o(e.prototype,n),i&&o(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 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 l=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",a(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,i,r;return n=t,(i=[{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 h(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,u=e.graphOpacity,c=o,l=h,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=u[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,i),r&&u(n,r),t}();function p(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 d(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 m(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}l.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 f=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),m(this,"onResize",function(t){n.setState({aspectRatio:n.getCanvasAspectRatio()})}),m(this,"onResizeThrottled",a(this.onResize,33)),m(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){m(t,e,n[e])})}return t}({},n.state,t),n.render()}),m(this,"mapX",function(t){var e=n.props,i=e.canvasWidth,a=e.data,r=a.minX;return(t-r)/(a.maxX-r)*i}),m(this,"mapY",function(t){var e=n.props,i=e.canvasWidth,a=e.minY;return(t-a)/(e.maxY-a)*i/n.state.aspectRatio}),m(this,"setUpTimelineWindowHandle",function(t){var e,i,a,o,s="left"===t?n.timelineWindowLeftHandle:n.timelineWindowRightHandle,h=parseFloat(getComputedStyle(n.timelineWindow).borderLeftWidth);return r(s,function(r){e=n.timeline.getBoundingClientRect();var s=n.timelineWindow.getBoundingClientRect();"left"===t?(i=e.left,a=s.left+s.width-2*h,o=r-s.left):(i=s.left+2*h,a=e.left+e.width,o=r-(s.left+s.width))},function(r){r-=o;var s=((r=Math.max(Math.min(r,a),i))-e.left)/e.width;"left"===t?n.updateBounds(s,n.props.toRatio):n.updateBounds(n.props.fromRatio,s)})}),m(this,"setUpTimelineWindow",function(){var t,e,i,a,o;return r(n.timelineWindowDrag,function(r){t=n.timeline.getBoundingClientRect(),e=n.timelineWindow.getBoundingClientRect(),o=r-e.left,i=t.left,a=t.left+(t.width-e.width)},function(r){r-=o;var s=((r=Math.max(Math.min(r,a),i))-t.left)/t.width;n.updateBounds(s,s+e.width/t.width)})}),m(this,"setTimelineWindowLeft",function(t){n.timelineOverlayLeft.style.right="".concat(100*(1-t),"%"),n.timelineWindow.style.left="".concat(100*t,"%")}),m(this,"setTimelineWindowRight",function(t){n.timelineOverlayRight.style.left="".concat(100*t,"%"),n.timelineWindow.style.right="".concat(100*(1-t),"%")}),this.props=t}var n,i,o;return n=e,(i=[{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,u=n.color,c=i.find(function(t){return t.id===s}).isShown,l=r[o];if(c||l>0){var d=p(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),u=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;)h[c]=n[s],u[c]=i[s],c++,s++;return h=h.slice(0,c),u=u.slice(0,c),h.length<=a?[h,u]:(n.length/h.length<1.1&&(o=Math.min(o+.025,1)),e(h,u,a,r,o))}var l=(i[s+2]+i[s])/2;return Math.abs(l-i[s+1])/r<o?(h[c]=n[s],h[c+1]=n[s+2],u[c]=i[s],u[c+1]=i[s+2],e(n,i,a,r,o,s+2,h,u,c+1)):(h[c]=n[s],h[c+1]=n[s+1],h[c+2]=n[s+2],u[c]=i[s],u[c+1]=i[s+1],u[c+2]=i[s+2],e(n,i,a,r,o,s+2,h,u,c+2))}(a.x.points,h,80),2),m=d[0],f=d[1];e.graphs[o]?e.updateGraph(o,m,f,l):e.mountGraph(o,m,f,u,l)}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)}}])&&d(n.prototype,i),o&&d(n,o),e}();function v(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 g(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}f.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 y=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),g(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 u=document.createElementNS(o,"circle");u.setAttribute("cx","9.5"),u.setAttribute("cy","9.5"),u.setAttribute("r","8"),u.setAttribute("class","chartogram__chart-toggler-check-circle"),u.setAttribute("transform","scale(0)"),s.appendChild(u);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,u)}),r}),g(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))}}}])&&v(e.prototype,n),i&&v(e,i),t}();function b(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){x(t,e,n[e])})}return t}function w(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 x(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}y.INITIAL_MARKUP='\n\t<div class="chartogram__chart-togglers"></div>\n';var A=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),x(this,"transitions",[]),x(this,"tick",function(){var t,e=b({},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=b({},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 b({},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=k[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,u=o-r,c=Math.abs(h-o)/u,l=Math.abs(s-r)/u,p=Math.max(l,c);n=e*Math.max(.2,2*Math.min(p,.5))}return n}}])&&w(e.prototype,n),i&&w(e,i),t}(),k={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 _(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 S(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 C(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 P=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=S({},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,h=a.maxYGlobal,u=a.maxYGaugeMark;return i.transition.batch(),i.transition.add("charts","minY",r),i.transition.add("charts","maxY",o),i.transition.add("charts","maxYGaugeMark",u),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}),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=S({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=S({},n,{minX:Math.min.apply(Math,_(n.x.points)),maxX:Math.max.apply(Math,_(n.x.points)),y:n.y.map(function(t){return S({},t,{min:Math.min.apply(Math,_(t.points)),max:Math.max.apply(Math,_(t.points))})})}),this.transition=new A(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(l.INITIAL_MARKUP,"\n\t\t\t").concat(f.INITIAL_MARKUP,"\n\t\t\t").concat(y.INITIAL_MARKUP,"\n\t\t"),this.state=this.getInitialState(),this.charts=new l(this.getChartsProps()),this.charts.componentDidMount(this.rootNode),this.timeline=new f(this.getTimelineProps()),this.timeline.componentDidMount(this.rootNode),this.togglers=new y(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 S({},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 S({},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),u=h.slice();h.length>=2&&(r.points[n]!==o&&(u[0]=o),r.points[i]!==s&&(u[u.length-1]=s));var c=this.data.y.map(function(t,e){var u=a.data.y[e].points.slice(n,i+1),c=u.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]));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 S({},a.data.y[e],a.state?a.state.y[e]:{isShown:!0},{points:u,graphPoints:c,min:0,max:Math.max.apply(Math,_(c))})});return S({minX:o,maxX:s,fromIndex:n,toIndex:i,fromRatio:t,toRatio:e,xPoints:h,xGraphPoints:u},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,h=Array.isArray(s),u=0;for(s=h?s:s[Symbol.iterator]();;){var c;if(h){if(u>=s.length)break;c=s[u++]}else{if((u=s.next()).done)break;c=u.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)}}}])&&C(i.prototype,a),r&&C(i,r),t}();return function(t,e,n,i){var a=new P(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 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()}}});
//# sourceMappingURL=chartogram.js.map

@@ -87,4 +87,10 @@ "use strict";

x = Math.max(Math.min(x, maxX), minX);
var ratio = (x - timelineCoordinates.left) / timelineCoordinates.width;
var ratio = (x - timelineCoordinates.left) / timelineCoordinates.width; // Due to CSS em -> px rounding precision `ratio` may
// sometimes be out of bounds on the edges of the timeline.
// For example, for the right timeline window handle
// its width may be "6.39844" but the collapsed timeline window
// width may be "12.796875" which is "6.3984375" x2.
ratio = Math.min(Math.max(ratio, 0), 1);
if (side === 'left') {

@@ -91,0 +97,0 @@ _this.updateBounds(ratio, _this.props.toRatio);

@@ -383,3 +383,5 @@ "use strict";

value: function updateTooltipYValues(xIndex) {
var y = this.props.y;
var _this$props7 = this.props,
y = _this$props7.y,
formatY = _this$props7.formatY;
var tooltipValues = this.tooltip.childNodes[1];

@@ -406,3 +408,3 @@ var i = 0;

if (isShown) {
tooltipValues.childNodes[i].childNodes[0].textContent = points[xIndex];
tooltipValues.childNodes[i].childNodes[0].textContent = formatY(points[xIndex]);
tooltipValues.childNodes[i].childNodes[1].textContent = name;

@@ -409,0 +411,0 @@ i++;

@@ -52,10 +52,2 @@ "use strict";

var ROUND_POINTS = [{
threshold: 5,
adjustment: 2
}, {
threshold: 40,
adjustment: 10
}];
function round(n) {

@@ -70,23 +62,14 @@ var digitCount = getDigitCount(n);

var roundPoint;
var _arr = ROUND_POINTS;
if (n > 5) {
var remainder = n % 10;
for (var _i2 = 0; _i2 < _arr.length; _i2++) {
var point = _arr[_i2];
if (n > point.threshold) {
roundPoint = point;
if (remainder / n < 0.2) {
n -= remainder;
} else {
break;
if (n % 2) {
n--;
}
}
}
if (roundPoint) {
var remainder = n % roundPoint.adjustment;
if (remainder) {
n -= remainder;
}
}
return n * factor;

@@ -93,0 +76,0 @@ }

@@ -79,4 +79,10 @@ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

x = Math.max(Math.min(x, maxX), minX);
var ratio = (x - timelineCoordinates.left) / timelineCoordinates.width;
var ratio = (x - timelineCoordinates.left) / timelineCoordinates.width; // Due to CSS em -> px rounding precision `ratio` may
// sometimes be out of bounds on the edges of the timeline.
// For example, for the right timeline window handle
// its width may be "6.39844" but the collapsed timeline window
// width may be "12.796875" which is "6.3984375" x2.
ratio = Math.min(Math.max(ratio, 0), 1);
if (side === 'left') {

@@ -83,0 +89,0 @@ _this.updateBounds(ratio, _this.props.toRatio);

@@ -375,3 +375,5 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

value: function updateTooltipYValues(xIndex) {
var y = this.props.y;
var _this$props7 = this.props,
y = _this$props7.y,
formatY = _this$props7.formatY;
var tooltipValues = this.tooltip.childNodes[1];

@@ -398,3 +400,3 @@ var i = 0;

if (isShown) {
tooltipValues.childNodes[i].childNodes[0].textContent = points[xIndex];
tooltipValues.childNodes[i].childNodes[0].textContent = formatY(points[xIndex]);
tooltipValues.childNodes[i].childNodes[1].textContent = name;

@@ -401,0 +403,0 @@ i++;

@@ -35,9 +35,2 @@ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }

}
var ROUND_POINTS = [{
threshold: 5,
adjustment: 2
}, {
threshold: 40,
adjustment: 10
}];

@@ -53,23 +46,14 @@ function round(n) {

var roundPoint;
var _arr = ROUND_POINTS;
if (n > 5) {
var remainder = n % 10;
for (var _i2 = 0; _i2 < _arr.length; _i2++) {
var point = _arr[_i2];
if (n > point.threshold) {
roundPoint = point;
if (remainder / n < 0.2) {
n -= remainder;
} else {
break;
if (n % 2) {
n--;
}
}
}
if (roundPoint) {
var remainder = n % roundPoint.adjustment;
if (remainder) {
n -= remainder;
}
}
return n * factor;

@@ -76,0 +60,0 @@ }

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

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

@@ -190,3 +190,9 @@ import {

x = Math.max(Math.min(x, maxX), minX)
const ratio = (x - timelineCoordinates.left) / timelineCoordinates.width
let ratio = (x - timelineCoordinates.left) / timelineCoordinates.width
// Due to CSS em -> px rounding precision `ratio` may
// sometimes be out of bounds on the edges of the timeline.
// For example, for the right timeline window handle
// its width may be "6.39844" but the collapsed timeline window
// width may be "12.796875" which is "6.3984375" x2.
ratio = Math.min(Math.max(ratio, 0), 1)
if (side === 'left') {

@@ -193,0 +199,0 @@ this.updateBounds(ratio, this.props.toRatio)

@@ -226,3 +226,3 @@ import { setUpTouchMove } from './utility'

updateTooltipYValues(xIndex) {
const { y } = this.props
const { y, formatY } = this.props
const tooltipValues = this.tooltip.childNodes[1]

@@ -232,3 +232,3 @@ let i = 0

if (isShown) {
tooltipValues.childNodes[i].childNodes[0].textContent = points[xIndex]
tooltipValues.childNodes[i].childNodes[0].textContent = formatY(points[xIndex])
tooltipValues.childNodes[i].childNodes[1].textContent = name

@@ -235,0 +235,0 @@ i++

@@ -24,13 +24,2 @@ export function clearElement(element) {

const ROUND_POINTS = [
{
threshold: 5,
adjustment: 2
},
{
threshold: 40,
adjustment: 10
}
]
function round(n) {

@@ -43,16 +32,12 @@ const digitCount = getDigitCount(n)

}
let roundPoint
for (const point of ROUND_POINTS) {
if (n > point.threshold) {
roundPoint = point
if (n > 5) {
const remainder = n % 10
if (remainder / n < 0.2) {
n -= remainder
} else {
break
if (n % 2) {
n--
}
}
}
if (roundPoint) {
const remainder = n % roundPoint.adjustment
if (remainder) {
n -= remainder
}
}
return n * factor

@@ -59,0 +44,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

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

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