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

@fnando/sparkline

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fnando/sparkline - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

__snapshots__/sparkline_test.js.snap-shot

13

dist/sparkline.js

@@ -131,3 +131,3 @@ var sparkline =

// Define how big should be the spot area.
var spotRadius = options.sportRadius || 2;
var spotRadius = options.spotRadius || 2;
var spotDiameter = spotRadius * 2;

@@ -185,3 +185,4 @@

// Hold the line coordinates.
var pathCoords = "M" + spotDiameter + " " + getY(max, height, strokeWidth + spotRadius, values[0]);
var pathY = getY(max, height, strokeWidth + spotRadius, values[0]);
var pathCoords = "M" + spotDiameter + " " + pathY;

@@ -198,6 +199,3 @@ values.forEach(function (value, index) {

pathCoords += " L ";
pathCoords += x;
pathCoords += " ";
pathCoords += y;
pathCoords += " L " + x + " " + y;
});

@@ -210,4 +208,3 @@

var fillCoords = pathCoords + " V " + fullHeight;
fillCoords += "L " + spotDiameter + " " + fullHeight + " Z";
var fillCoords = pathCoords + " V " + fullHeight + " L " + spotDiameter + " " + fullHeight + " Z";

@@ -214,0 +211,0 @@ var fill = buildElement("path", {

@@ -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.sportRadius||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,d),m=d.length-1,y=Math.round((v-c)/m),A=[],g="M"+c+" "+n(b,x,f+s,d[0]);d.forEach(function(t,r){var i=r===m?v:r*y+c,u=n(b,x,f+s,t);A.push(Object.assign({},e[r],{index:r,x:i,y:u})),g+=" L ",g+=i,g+=" ",g+=u});var w=i("path",{d:g,fill:"none"}),k=g+" V "+h,M=i("path",{d:k+="L "+c+" "+h+" Z",stroke:"none"});if(t.appendChild(w),t.appendChild(M),a){var O=i("line",{class:"sparkline--cursor",x1:-1e3,x2:-1e3,y1:0,y2:h,"stroke-width":l}),C=i("circle",{class:"sparkline--spot",cx:-1e3,cy:-1e3,r:s});t.appendChild(O),t.appendChild(C),t.addEventListener("mouseout",function(t){O.setAttribute("x1",-1e3),O.setAttribute("x2",-1e3),C.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[m]);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;C.setAttribute("cx",a),C.setAttribute("cy",s),O.setAttribute("x1",a),O.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,d),m=d.length-1,y=Math.round((v-c)/m),A=[],g=n(b,x,f+s,d[0]),w="M"+c+" "+g;d.forEach(function(t,r){var i=r===m?v:r*y+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"}),M=i("path",{d:w+" V "+h+" L "+c+" "+h+" Z",stroke:"none"});if(t.appendChild(k),t.appendChild(M),a){var O=i("line",{class:"sparkline--cursor",x1:-1e3,x2:-1e3,y1:0,y2:h,"stroke-width":l}),C=i("circle",{class:"sparkline--spot",cx:-1e3,cy:-1e3,r:s});t.appendChild(O),t.appendChild(C),t.addEventListener("mouseout",function(t){O.setAttribute("x1",-1e3),O.setAttribute("x2",-1e3),C.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[m]);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;C.setAttribute("cx",a),C.setAttribute("cy",s),O.setAttribute("x1",a),O.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.0",
"version": "0.3.1",
"main": "dist/sparkline.js",
"module": "src/sparkline.js",
"scripts": {
"test": "mocha --require babel-core/register 'test/**/*_test.js'",
"js:dist:expanded": "webpack",
"js:dist:minified": "NODE_ENV=production webpack",
"dist": "npm run js:dist:expanded && npm run js:dist:minified"
"dist": "yarn js:dist:expanded && yarn js:dist:minified"
},
"description": "Generate SVG sparklines",
"description": "Generate SVG sparklines with JavaScript without any external dependency.",
"license": "MIT",

@@ -19,2 +20,5 @@ "repository": "https://github.com/fnando/sparkline",

"babel-preset-env": "1.6.1",
"jsdom": "11.4.0",
"mocha": "4.0.1",
"snap-shot": "2.17.0",
"uglifyjs-webpack-plugin": "1.1.0",

@@ -21,0 +25,0 @@ "webpack": "3.8.1"

# sparkline
Generate SVG sparklines.
Generate SVG sparklines with JavaScript without any external dependency.

@@ -25,3 +25,3 @@ ## Instalation

- `svg`: This is a `<svg>` reference that must contain three required attributes (`width`, `height`, and `stroke-width`). This values are used to calculate the drawing area.
- `svg`: This is a `<svg>` reference that must contain three required attributes (`width`, `height`, and `stroke-width`). These attributes are used to calculate the drawing area.
- `values`: You can either provide an array of numbers or an array of objects that respond to `.value`. If you have a different data structure, see `options.fetch`.

@@ -28,0 +28,0 @@ - `options`: This optional argument allows you to further customize the sparkline. The available options are:

@@ -52,3 +52,3 @@ function getY(max, height, diff, value) {

// Define how big should be the spot area.
const spotRadius = options.sportRadius || 2;
const spotRadius = options.spotRadius || 2;
const spotDiameter = spotRadius * 2;

@@ -104,3 +104,4 @@

// Hold the line coordinates.
let pathCoords = "M" + spotDiameter + " " + getY(max, height, strokeWidth + spotRadius, values[0]);
const pathY = getY(max, height, strokeWidth + spotRadius, values[0]);
let pathCoords = `M${spotDiameter} ${pathY}`;

@@ -117,6 +118,3 @@ values.forEach((value, index) => {

pathCoords += " L ";
pathCoords += x;
pathCoords += " "
pathCoords += y;
pathCoords += ` L ${x} ${y}`;
});

@@ -129,4 +127,3 @@

let fillCoords = pathCoords + " V " + fullHeight;
fillCoords += "L " + spotDiameter + " " + fullHeight + " Z";
let fillCoords = `${pathCoords} V ${fullHeight} L ${spotDiameter} ${fullHeight} Z`;

@@ -133,0 +130,0 @@ const fill = buildElement("path", {

@@ -16,2 +16,6 @@ const UglifyJSPlugin = require("uglifyjs-webpack-plugin");

target: "web",
node: {
fs: "empty"
},
output: {

@@ -22,2 +26,3 @@ path: `${__dirname}/dist/`,

},
module: {

@@ -24,0 +29,0 @@ rules: [

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