react-line-graph
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -1,1 +0,1 @@ | ||
module.exports=function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=4)}([function(t,e){t.exports=require("react")},function(t,e,r){t.exports=r(2)()},function(t,e,r){"use strict";var n=r(3);function o(){}function i(){}i.resetWarningCache=o,t.exports=function(){function t(t,e,r,o,i,a){if(a!==n){var c=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw c.name="Invariant Violation",c}}function e(){return t}t.isRequired=t;var r={array:t,bool:t,func:t,number:t,object:t,string:t,symbol:t,any:t,arrayOf:e,element:t,elementType:t,instanceOf:e,node:t,objectOf:e,oneOf:e,oneOfType:e,shape:e,exact:e,checkPropTypes:i,resetWarningCache:o};return r.PropTypes=r,r}},function(t,e,r){"use strict";t.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},function(t,e,r){"use strict";r.r(e);var n=r(0),o=r.n(n),i=function(t){return"L".concat(t.join(","))};function a(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=[],n=!0,o=!1,i=void 0;try{for(var a,c=t[Symbol.iterator]();!(n=(a=c.next()).done)&&(r.push(a.value),!e||r.length!==e);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==c.return||c.return()}finally{if(o)throw i}}return r}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var c=function(t){return"string"==typeof t?t.trim().split(",").map(function(t){return parseInt(t,10)}):t},u=function(t,e){var r=a(c(t),2),n=r[0],o=r[1],i=a(c(e),2),u=i[0],l=(i[1]-o)/(u-n);return[l,o-l*n]},l=function(t,e){var r=a(c(e),2),n=r[0];return r[1]-t*n},f=function(t,e,r){var n=a(t,1)[0];return(n+(r[e+1]?r[e+1][0]:n))/2};function s(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=[],n=!0,o=!1,i=void 0;try{for(var a,c=t[Symbol.iterator]();!(n=(a=c.next()).done)&&(r.push(a.value),!e||r.length!==e);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==c.return||c.return()}finally{if(o)throw i}}return r}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var h=function(t,e,r){var n=t.nativeEvent,o=n.offsetX,i=n.offsetY,a=s(function(t){var e=t.target.getBoundingClientRect();return[e.width,e.height]}(t),2);return[o/a[0]*e,i/a[1]*r]};function d(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=[],n=!0,o=!1,i=void 0;try{for(var a,c=t[Symbol.iterator]();!(n=(a=c.next()).done)&&(r.push(a.value),!e||r.length!==e);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==c.return||c.return()}finally{if(o)throw i}}return r}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function p(t){return(p="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var y=function(t){if(!Array.isArray(t))throw new Error("Data must be of type array!");return t.map(function(t,e){return Array.isArray(t)&&t.length>=2?t.slice(0,2):"object"===p(t)?[t.x,t.y]:(r=t,Object(r)!==r?[t,e]:null);var r})};function v(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=[],n=!0,o=!1,i=void 0;try{for(var a,c=t[Symbol.iterator]();!(n=(a=c.next()).done)&&(r.push(a.value),!e||r.length!==e);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==c.return||c.return()}finally{if(o)throw i}}return r}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var b=function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length,r=new Array(e>1?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];var o=r.filter(function(t){return t}).map(function(t){return c(t)}),i=o[0],a=o[Math.floor(o.length/2)],f=o[o.length-1],s=u(i,f),h=v(s,1),d=h[0],p=l(d,a),y=c(a),b=v(y,1),g=b[0],m=c(i),O=v(m,1),w=O[0],j=.5*(g-w),x=d*(g-=Math.min(Math.abs(t),1)*j)+p;return[g||0,x||0]},g=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[0,0],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;return"S".concat(b(n,r[e-1],t,r[e+1]).join(",")," ").concat(t.join(","))},m=r(1),O={data:Object(m.oneOfType)([Object(m.arrayOf)(Object(m.arrayOf)(m.number)),Object(m.arrayOf)(m.number),Object(m.shape)({x:m.number,y:m.number})]),smoothing:m.number,width:Object(m.oneOfType)([m.string,m.number]),height:Object(m.oneOfType)([m.string,m.number]),hover:m.bool,fillBelow:m.string,accent:m.string,strokeWidth:Object(m.oneOfType)([m.string,m.number]),onHover:m.func,compression:m.number,calcWidth:Object(m.oneOfType)([m.string,m.number]),calcHeight:Object(m.oneOfType)([m.string,m.number]),adjData:Object(m.arrayOf)(Object(m.arrayOf)(m.number)),sortedData:Object(m.arrayOf)(Object(m.arrayOf)(m.number)),children:m.node,path:Object(m.oneOfType)([m.string,Object(m.arrayOf)(m.string)]),x:m.number,y:m.number},w=function(t){var e=t.x,r=t.y,n=t.accent,i=t.strokeWidth;return o.a.createElement("circle",{cx:e,cy:r,r:"5",fill:"white",stroke:n,strokeWidth:i/2})};w.propTypes={x:O.x,y:O.y,accent:O.accent.isRequired,strokeWidth:O.strokeWidth.isRequired},w.defaultProps={x:-100,y:-100};var j=w,x=function(t){var e=t.x,r=t.accent,n=t.strokeWidth,i=t.calcHeight;return o.a.createElement("line",{x1:e,x2:e,y1:0,y2:i,strokeWidth:n/2,stroke:r})};x.propTypes={x:O.x,accent:O.accent.isRequired,strokeWidth:O.strokeWidth.isRequired,calcHeight:O.calcHeight.isRequired},x.defaultProps={x:-100};var W=x;function k(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=[],n=!0,o=!1,i=void 0;try{for(var a,c=t[Symbol.iterator]();!(n=(a=c.next()).done)&&(r.push(a.value),!e||r.length!==e);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==c.return||c.return()}finally{if(o)throw i}}return r}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var T=function(t){var e=t.calcWidth,r=t.calcHeight,i=t.adjData,a=t.sortedData,c=t.accent,u=t.strokeWidth,l=t.onHover,s=k(function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[0,0],e=arguments.length>1?arguments[1]:void 0,r=arguments.length>2?arguments[2]:void 0,o=Object(n.useState)(t),i=d(o,2),a=i[0],c=i[1],u=Object(n.useCallback)(function(t){var n=d(h(t,e,r),2),o=n[0],i=n[1];c(o<=e&&i<=r?[o,i]:[-1*e,-1*r])});return[a,u]}([0,0],e,r),2),p=k(s[0],2),y=p[0],v=p[1],b=s[1],g=k(Object(n.useState)([-e,-r]),2),m=k(g[0],2),O=m[0],w=m[1],x=g[1],T=i.map(f);return Object(n.useEffect)(function(){var t=T.findIndex(function(t){return y<=t});i[t]&&x(i[t]),a[t]&&l(a[t])},[y,v]),o.a.createElement("g",null,o.a.createElement(j,{x:O,y:w,accent:c,strokeWidth:u}),o.a.createElement(W,{x:O,accent:c,strokeWidth:u,calcHeight:r}),o.a.createElement("rect",{onMouseLeave:function(){return x([-e,-r])},onMouseMove:b,width:e,height:r,style:{fill:"transparent",stroke:"transparent"}}))};T.propTypes={calcWidth:O.calcWidth.isRequired,calcHeight:O.calcHeight.isRequired,adjData:O.adjData.isRequired,sortedData:O.sortedData.isRequired,accent:O.accent.isRequired,strokeWidth:O.strokeWidth.isRequired,onHover:O.onHover.isRequired};var R=T,H=Object(n.forwardRef)(function(t,e){var r=t.width,n=t.height,i=t.calcWidth,a=t.calcHeight,c=t.children;return o.a.createElement("svg",{style:{width:r,height:n},viewBox:"0 0 ".concat(i," ").concat(a),preserveAspectRatio:"none",ref:e},c)});H.propTypes={width:O.width.isRequired,height:O.height.isRequired,calcWidth:O.calcWidth.isRequired,calcHeight:O.calcHeight.isRequired,children:O.children},H.defaultProps={children:null};var E=H,q=function(t){var e=t.accent,r=t.strokeWidth,n=t.path;return o.a.createElement("path",{fill:"none",stroke:e,strokeWidth:r,d:n})};q.propTypes={accent:O.accent.isRequired,strokeWidth:O.strokeWidth.isRequired,path:O.path.isRequired};var S=q,A=function(t){var e=t.fillBelow,r=t.path,n=t.calcHeight;return r&&o.a.createElement("path",{stroke:"none",fill:e,d:"M0,0".concat(r," V").concat(n," H0 Z")})};A.propTypes={fillBelow:O.fillBelow.isRequired,calcHeight:O.calcHeight.isRequired,path:O.path.isRequired};var M=A;function P(){return(P=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function _(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=[],n=!0,o=!1,i=void 0;try{for(var a,c=t[Symbol.iterator]();!(n=(a=c.next()).done)&&(r.push(a.value),!e||r.length!==e);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==c.return||c.return()}finally{if(o)throw i}}return r}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var D=function(t){var e=t.data,r=t.smoothing,c=t.width,u=t.height,l=t.hover,f=t.fillBelow,s=t.accent,h=t.strokeWidth,d=t.onHover,p=t.compression,v=_(Object(n.useState)([0,0]),2),b=_(v[0],2),m=b[0],O=b[1],w=v[1],j=Object(n.useRef)(),x=y(e).sort(function(t,e){return t[0]-e[0]}),W=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100;return t.map(function(t){var r=a(t,2),n=r[0],o=r[1];return void 0!==n&&void 0!==o?[n,e-o]:[]})}(function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,o=t.reduce(function(t,e){return[Math.max(e[0],t[0]),Math.max(e[1],t[1]),Math.min(e[0],t[2]),Math.min(e[1],t[3])]},[-1/0,-1/0,1/0,1/0]),i=a(o,4),c=i[0],u=i[1],l=i[2],f=i[3],s=1-Math.min(Math.abs(e),1),h=c-l||1,d=u-f||1,p=r/h,y=n*s/d*s,v=r-p*c,b=n*s-y*u;return t.map(function(t){var e=a(t,2),r=e[0],n=e[1];return[Number((r*p+v).toFixed(2)),Number((n*y+b).toFixed(2))]})}(x,p,m,O),O),k=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:i,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return t.sort(function(t,e){return t[0]-e[0]}).reduce(function(n,o,i){return i?"".concat(n," ").concat(e(o,i,t,r)):"M".concat(o.join(","))},"")}(W,g,r);return Object(n.useEffect)(function(){var t=j.current,e=t.clientWidth,r=t.clientHeight;w([e,r])},[]),o.a.createElement(E,P({ref:j},{width:c,height:u,calcWidth:m,calcHeight:O}),o.a.createElement(S,{accent:s,strokeWidth:h,path:k}),o.a.createElement(M,{calcHeight:O,fillBelow:f,path:k}),l&&o.a.createElement(R,{calcWidth:m,calcHeight:O,adjData:W,sortedData:x,accent:s,strokeWidth:h,onHover:d}))};D.propTypes={data:O.data,smoothing:O.smoothing,width:O.width,height:O.height,hover:O.hover,fillBelow:O.fillBelow,accent:O.accent,strokeWidth:O.strokeWidth,onHover:O.onHover,compression:O.compression},D.defaultProps={data:[],smoothing:0,width:"100%",height:"100%",hover:!1,fillBelow:"none",accent:"black",strokeWidth:"0.5",onHover:function(){},compression:.1};var B=D;e.default=B}]); | ||
module.exports=function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=4)}([function(t,e,r){t.exports=r(2)()},function(t,e){t.exports=require("react")},function(t,e,r){"use strict";var n=r(3);function o(){}function i(){}i.resetWarningCache=o,t.exports=function(){function t(t,e,r,o,i,a){if(a!==n){var c=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw c.name="Invariant Violation",c}}function e(){return t}t.isRequired=t;var r={array:t,bool:t,func:t,number:t,object:t,string:t,symbol:t,any:t,arrayOf:e,element:t,elementType:t,instanceOf:e,node:t,objectOf:e,oneOf:e,oneOfType:e,shape:e,exact:e,checkPropTypes:i,resetWarningCache:o};return r.PropTypes=r,r}},function(t,e,r){"use strict";t.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},function(t,e,r){"use strict";r.r(e);var n=r(1),o=r.n(n),i=function(t){return"L".concat(t.join(","))};function a(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=[],n=!0,o=!1,i=void 0;try{for(var a,c=t[Symbol.iterator]();!(n=(a=c.next()).done)&&(r.push(a.value),!e||r.length!==e);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==c.return||c.return()}finally{if(o)throw i}}return r}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var c=function(t){return"string"==typeof t?t.trim().split(",").map(function(t){return parseInt(t,10)}):t},u=function(t,e){var r=a(c(t),2),n=r[0],o=r[1],i=a(c(e),2),u=i[0],l=(i[1]-o)/(u-n);return[l,o-l*n]},l=function(t,e){var r=a(c(e),2),n=r[0];return r[1]-t*n},f=function(t,e,r){var n=a(t,1)[0];return(n+(r[e+1]?r[e+1][0]:n))/2};function s(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=[],n=!0,o=!1,i=void 0;try{for(var a,c=t[Symbol.iterator]();!(n=(a=c.next()).done)&&(r.push(a.value),!e||r.length!==e);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==c.return||c.return()}finally{if(o)throw i}}return r}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var h=function(t,e,r){var n=t.nativeEvent,o=n.offsetX,i=n.offsetY,a=s(function(t){var e=t.target.getBoundingClientRect();return[e.width,e.height]}(t),2);return[o/a[0]*e,i/a[1]*r]};function d(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=[],n=!0,o=!1,i=void 0;try{for(var a,c=t[Symbol.iterator]();!(n=(a=c.next()).done)&&(r.push(a.value),!e||r.length!==e);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==c.return||c.return()}finally{if(o)throw i}}return r}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function p(t){return(p="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var y=function(t){if(!Array.isArray(t))throw new Error("Data must be of type array!");return t.map(function(t,e){return Array.isArray(t)&&t.length>=2?t.slice(0,2):"object"===p(t)?[t.x,t.y]:(r=t,Object(r)!==r?[e,t]:null);var r})};function v(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=[],n=!0,o=!1,i=void 0;try{for(var a,c=t[Symbol.iterator]();!(n=(a=c.next()).done)&&(r.push(a.value),!e||r.length!==e);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==c.return||c.return()}finally{if(o)throw i}}return r}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var g=function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length,r=new Array(e>1?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];var o=r.filter(function(t){return t}).map(function(t){return c(t)}),i=o[0],a=o[Math.floor(o.length/2)],f=o[o.length-1],s=u(i,f),h=v(s,1),d=h[0],p=l(d,a),y=c(a),g=v(y,1),b=g[0],m=c(i),O=v(m,1),w=O[0],j=.5*(b-w),x=d*(b-=Math.min(Math.abs(t),1)*j)+p;return[b||0,x||0]},b=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[0,0],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;return"S".concat(g(n,r[e-1],t,r[e+1]).join(",")," ").concat(t.join(","))},m=r(0),O={data:Object(m.oneOfType)([Object(m.arrayOf)(Object(m.arrayOf)(m.number)),Object(m.arrayOf)(m.number),Object(m.shape)({x:m.number,y:m.number})]),smoothing:m.number,width:Object(m.oneOfType)([m.string,m.number]),height:Object(m.oneOfType)([m.string,m.number]),hover:m.bool,fillBelow:m.string,accent:m.string,strokeWidth:Object(m.oneOfType)([m.string,m.number]),onHover:m.func,compression:m.number,calcWidth:Object(m.oneOfType)([m.string,m.number]),calcHeight:Object(m.oneOfType)([m.string,m.number]),adjData:Object(m.arrayOf)(Object(m.arrayOf)(m.number)),sortedData:Object(m.arrayOf)(Object(m.arrayOf)(m.number)),children:m.node,path:Object(m.oneOfType)([m.string,Object(m.arrayOf)(m.string)]),x:m.number,y:m.number},w=function(t){var e=t.x,r=t.y,n=t.accent,i=t.strokeWidth;return o.a.createElement("circle",{cx:e,cy:r,r:"5",fill:"white",stroke:n,strokeWidth:i/2})};w.propTypes={x:O.x,y:O.y,accent:O.accent.isRequired,strokeWidth:O.strokeWidth.isRequired},w.defaultProps={x:-100,y:-100};var j=w,x=function(t){var e=t.x,r=t.accent,n=t.strokeWidth,i=t.calcHeight;return o.a.createElement("line",{x1:e,x2:e,y1:0,y2:i,strokeWidth:n/2,stroke:r})};x.propTypes={x:O.x,accent:O.accent.isRequired,strokeWidth:O.strokeWidth.isRequired,calcHeight:O.calcHeight.isRequired},x.defaultProps={x:-100};var W=x;function k(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=[],n=!0,o=!1,i=void 0;try{for(var a,c=t[Symbol.iterator]();!(n=(a=c.next()).done)&&(r.push(a.value),!e||r.length!==e);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==c.return||c.return()}finally{if(o)throw i}}return r}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var T=function(t){var e=t.calcWidth,r=t.calcHeight,i=t.adjData,a=t.sortedData,c=t.accent,u=t.strokeWidth,l=t.onHover,s=k(function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[0,0],e=arguments.length>1?arguments[1]:void 0,r=arguments.length>2?arguments[2]:void 0,o=Object(n.useState)(t),i=d(o,2),a=i[0],c=i[1],u=function(t){var n=d(h(t,e,r),2),o=n[0],i=n[1];c(o<=e&&i<=r?[o,i]:[-1*e,-1*r])};return[a,u]}([0,0],e,r),2),p=k(s[0],2),y=p[0],v=p[1],g=s[1],b=k(Object(n.useState)([-e,-r]),2),m=k(b[0],2),O=m[0],w=m[1],x=b[1],T=i.map(f);return Object(n.useEffect)(function(){var t=T.findIndex(function(t){return y<=t});i[t]&&x(i[t]),a[t]&&l(a[t])},[y,v]),o.a.createElement("g",null,o.a.createElement(j,{x:O,y:w,accent:c,strokeWidth:u}),o.a.createElement(W,{x:O,accent:c,strokeWidth:u,calcHeight:r}),o.a.createElement("rect",{onMouseLeave:function(){return x([-e,-r])},onMouseMove:g,width:e,height:r,style:{fill:"transparent",stroke:"transparent"}}))};T.propTypes={calcWidth:O.calcWidth.isRequired,calcHeight:O.calcHeight.isRequired,adjData:O.adjData.isRequired,sortedData:O.sortedData.isRequired,accent:O.accent.isRequired,strokeWidth:O.strokeWidth.isRequired,onHover:O.onHover.isRequired};var R=T,H=Object(n.forwardRef)(function(t,e){var r=t.width,n=t.height,i=t.calcWidth,a=t.calcHeight,c=t.children;return o.a.createElement("svg",{style:{width:r,height:n},viewBox:"0 0 ".concat(i," ").concat(a),preserveAspectRatio:"none",ref:e},c)});H.propTypes={width:O.width.isRequired,height:O.height.isRequired,calcWidth:O.calcWidth.isRequired,calcHeight:O.calcHeight.isRequired,children:O.children},H.defaultProps={children:null};var E=H,q=function(t){var e=t.accent,r=t.strokeWidth,n=t.path;return o.a.createElement("path",{fill:"none",stroke:e,strokeWidth:r,d:n})};q.propTypes={accent:O.accent.isRequired,strokeWidth:O.strokeWidth.isRequired,path:O.path.isRequired};var S=q,A=function(t){var e=t.fillBelow,r=t.path,n=t.calcHeight;return r&&o.a.createElement("path",{stroke:"none",fill:e,d:"M0,0".concat(r," V").concat(n," H0 Z")})};A.propTypes={fillBelow:O.fillBelow.isRequired,calcHeight:O.calcHeight.isRequired,path:O.path.isRequired};var M=A;function P(){return(P=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function _(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=[],n=!0,o=!1,i=void 0;try{for(var a,c=t[Symbol.iterator]();!(n=(a=c.next()).done)&&(r.push(a.value),!e||r.length!==e);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==c.return||c.return()}finally{if(o)throw i}}return r}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var D=function(t){var e=t.data,r=t.smoothing,c=t.width,u=t.height,l=t.hover,f=t.fillBelow,s=t.accent,h=t.strokeWidth,d=t.onHover,p=t.compression,v=_(Object(n.useState)([0,0]),2),g=_(v[0],2),m=g[0],O=g[1],w=v[1],j=Object(n.useRef)(),x=y(e).sort(function(t,e){return t[0]-e[0]}),W=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100;return t.map(function(t){var r=a(t,2),n=r[0],o=r[1];return void 0!==n&&void 0!==o?[n,e-o]:[]})}(function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,o=t.reduce(function(t,e){return[Math.max(e[0],t[0]),Math.max(e[1],t[1]),Math.min(e[0],t[2]),Math.min(e[1],t[3])]},[-1/0,-1/0,1/0,1/0]),i=a(o,4),c=i[0],u=i[1],l=i[2],f=i[3],s=1-Math.min(Math.abs(e),1),h=c-l||1,d=u-f||1,p=r/h,y=n*s/d*s,v=r-p*c,g=n*s-y*u;return t.map(function(t){var e=a(t,2),r=e[0],n=e[1];return[Number((r*p+v).toFixed(2)),Number((n*y+g).toFixed(2))]})}(x,p,m,O),O),k=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:i,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return t.sort(function(t,e){return t[0]-e[0]}).reduce(function(n,o,i){return i?"".concat(n," ").concat(e(o,i,t,r)):"M".concat(o.join(","))},"")}(W,b,r);return Object(n.useEffect)(function(){var t=j.current,e=t.clientWidth,r=t.clientHeight;w([e,r])},[]),o.a.createElement(E,P({ref:j},{width:c,height:u,calcWidth:m,calcHeight:O}),o.a.createElement(S,{accent:s,strokeWidth:h,path:k}),o.a.createElement(M,{calcHeight:O,fillBelow:f,path:k}),l&&o.a.createElement(R,{calcWidth:m,calcHeight:O,adjData:W,sortedData:x,accent:s,strokeWidth:h,onHover:d}))};D.propTypes={data:O.data,smoothing:O.smoothing,width:O.width,height:O.height,hover:O.hover,fillBelow:O.fillBelow,accent:O.accent,strokeWidth:O.strokeWidth,onHover:O.onHover,compression:O.compression},D.defaultProps={data:[],smoothing:0,width:"100%",height:"100%",hover:!1,fillBelow:"none",accent:"black",strokeWidth:"0.5",onHover:function(){},compression:.1};var B=D;e.default=B}]); |
{ | ||
"name": "react-line-graph", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "A simple and lightweight line graph", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
605331