@fnando/sparkline
Advanced tools
Comparing version 0.3.2 to 0.3.3
@@ -78,2 +78,5 @@ var sparkline = | ||
exports.sparkline = sparkline; | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
function getY(max, height, diff, value) { | ||
@@ -165,3 +168,3 @@ return parseFloat((height - value * height / max + diff).toFixed(2)); | ||
// each sparkline datapoint. | ||
var max = Math.max.apply(Math, values); | ||
var max = Math.max.apply(Math, _toConsumableArray(values)); | ||
@@ -172,10 +175,7 @@ // Some arbitrary value to remove the cursor and spot out of | ||
// Cache the values size. | ||
var entriesCount = values.length; | ||
// Cache the last item index. | ||
var lastItemIndex = entriesCount - 1; | ||
var lastItemIndex = values.length - 1; | ||
// Calculate the X coord base step. | ||
var offset = width / entriesCount; | ||
var offset = width / lastItemIndex; | ||
@@ -182,0 +182,0 @@ // Hold all datapoints, which is whatever we got as the entry plus |
@@ -1,2 +0,2 @@ | ||
var sparkline=function(t){function e(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,e),i.l=!0,i.exports}var r={};return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,r){"use strict";function n(t,e,r,n){return parseFloat((e-n*e/t+r).toFixed(2))}function i(t,e){var r=document.createElementNS("http://www.w3.org/2000/svg",t);for(var n in e)r.setAttribute(n,e[n]);return r}function u(t,e,r){if(function(t){t.querySelectorAll("*").forEach(function(e){return t.removeChild(e)})}(t),!(e.length<=1)){r=r||{},"number"==typeof e[0]&&(e=e.map(function(t){return{value:t}}));var u=r.onmousemove,o=r.onmouseout,a="interactive"in r?r.interactive:!!u,s=r.spotRadius||2,c=2*s,l=r.cursorWidth||2,f=parseFloat(t.attributes["stroke-width"].value),p=r.fetch||function(t){return t.value},d=e.map(function(t){return p(t)}),v=parseFloat(t.attributes.width.value)-c,x=parseFloat(t.attributes.height.value),h=x-2*f-c,b=Math.max.apply(Math,d),m=d.length,y=m-1,A=v/m,g=[],w=n(b,h,f+s,d[0]),k="M"+c+" "+w;d.forEach(function(t,r){var i=r*A+c,u=n(b,h,f+s,t);g.push(Object.assign({},e[r],{index:r,x:i,y:u})),k+=" L "+i+" "+u});var O=i("path",{d:k,fill:"none"}),C=i("path",{d:k+" V "+x+" L "+c+" "+x+" Z",stroke:"none"});if(t.appendChild(O),t.appendChild(C),a){var E=i("line",{class:"sparkline--cursor",x1:-1e3,x2:-1e3,y1:0,y2:x,"stroke-width":l}),F=i("circle",{class:"sparkline--spot",cx:-1e3,cy:-1e3,r:s});t.appendChild(E),t.appendChild(F),t.addEventListener("mouseout",function(t){E.setAttribute("x1",-1e3),E.setAttribute("x2",-1e3),F.setAttribute("cx",-1e3),o&&o(t)}),t.addEventListener("mousemove",function(t){var e=t.offsetX,r=g.find(function(t){return t.x>=e});r||(r=g[y]);var n=g[g.indexOf(r)-1],i=void 0,o=void 0;n?(o=n.x+(r.x-n.x)/2,i=e>=o?r:n):i=r;var a=i.x,s=i.y;F.setAttribute("cx",a),F.setAttribute("cy",s),E.setAttribute("x1",a),E.setAttribute("x2",a),u&&u(t,i)})}}}Object.defineProperty(e,"__esModule",{value:!0}),e.sparkline=u,e.default=u}]); | ||
var sparkline=function(t){function e(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,e),i.l=!0,i.exports}var r={};return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,r){"use strict";function n(t,e,r,n){return parseFloat((e-n*e/t+r).toFixed(2))}function i(t,e){var r=document.createElementNS("http://www.w3.org/2000/svg",t);for(var n in e)r.setAttribute(n,e[n]);return r}function u(t,e,r){if(function(t){t.querySelectorAll("*").forEach(function(e){return t.removeChild(e)})}(t),!(e.length<=1)){r=r||{},"number"==typeof e[0]&&(e=e.map(function(t){return{value:t}}));var u=r.onmousemove,o=r.onmouseout,a="interactive"in r?r.interactive:!!u,s=r.spotRadius||2,c=2*s,l=r.cursorWidth||2,f=parseFloat(t.attributes["stroke-width"].value),p=r.fetch||function(t){return t.value},d=e.map(function(t){return p(t)}),v=parseFloat(t.attributes.width.value)-c,h=parseFloat(t.attributes.height.value),x=h-2*f-c,b=Math.max.apply(Math,function(t){if(Array.isArray(t)){for(var e=0,r=Array(t.length);e<t.length;e++)r[e]=t[e];return r}return Array.from(t)}(d)),y=d.length-1,m=v/y,A=[],g=n(b,x,f+s,d[0]),w="M"+c+" "+g;d.forEach(function(t,r){var i=r*m+c,u=n(b,x,f+s,t);A.push(Object.assign({},e[r],{index:r,x:i,y:u})),w+=" L "+i+" "+u});var k=i("path",{d:w,fill:"none"}),O=i("path",{d:w+" V "+h+" L "+c+" "+h+" Z",stroke:"none"});if(t.appendChild(k),t.appendChild(O),a){var C=i("line",{class:"sparkline--cursor",x1:-1e3,x2:-1e3,y1:0,y2:h,"stroke-width":l}),E=i("circle",{class:"sparkline--spot",cx:-1e3,cy:-1e3,r:s});t.appendChild(C),t.appendChild(E),t.addEventListener("mouseout",function(t){C.setAttribute("x1",-1e3),C.setAttribute("x2",-1e3),E.setAttribute("cx",-1e3),o&&o(t)}),t.addEventListener("mousemove",function(t){var e=t.offsetX,r=A.find(function(t){return t.x>=e});r||(r=A[y]);var n=A[A.indexOf(r)-1],i=void 0,o=void 0;n?(o=n.x+(r.x-n.x)/2,i=e>=o?r:n):i=r;var a=i.x,s=i.y;E.setAttribute("cx",a),E.setAttribute("cy",s),C.setAttribute("x1",a),C.setAttribute("x2",a),u&&u(t,i)})}}}Object.defineProperty(e,"__esModule",{value:!0}),e.sparkline=u,e.default=u}]); | ||
//# sourceMappingURL=sparkline.min.js.map |
{ | ||
"name": "@fnando/sparkline", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"files": [ | ||
"src/sparkline.js", | ||
"dist/**/*", | ||
"README.md" | ||
], | ||
"main": "dist/sparkline.js", | ||
@@ -10,3 +15,3 @@ "module": "src/sparkline.js", | ||
"js:dist:minified": "NODE_ENV=production webpack", | ||
"dist": "yarn js:dist:expanded && yarn js:dist:minified" | ||
"dist": "yarn test && yarn js:dist:expanded && yarn js:dist:minified" | ||
}, | ||
@@ -13,0 +18,0 @@ "description": "Generate SVG sparklines with JavaScript without any external dependency.", |
@@ -83,3 +83,3 @@ function getY(max, height, diff, value) { | ||
// each sparkline datapoint. | ||
const max = Math.max.apply(Math, values); | ||
const max = Math.max(...values); | ||
@@ -90,10 +90,7 @@ // Some arbitrary value to remove the cursor and spot out of | ||
// Cache the values size. | ||
const entriesCount = values.length; | ||
// Cache the last item index. | ||
const lastItemIndex = entriesCount - 1; | ||
const lastItemIndex = values.length - 1; | ||
// Calculate the X coord base step. | ||
const offset = width / entriesCount; | ||
const offset = width / lastItemIndex; | ||
@@ -100,0 +97,0 @@ // Hold all datapoints, which is whatever we got as the entry plus |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
1
45905
7
395