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.9 to 0.3.10

dist/sparkline.commonjs2.js

297

dist/sparkline.js

@@ -1,297 +0,2 @@

var sparkline =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = "./src/sparkline.js");
/******/ })
/************************************************************************/
/******/ ({
/***/ "./src/sparkline.js":
/*!**************************!*\
!*** ./src/sparkline.js ***!
\**************************/
/*! exports provided: sparkline, default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "sparkline", function() { return sparkline; });
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
function getY(max, height, diff, value) {
return parseFloat((height - value * height / max + diff).toFixed(2));
}
function removeChildren(svg) {
_toConsumableArray(svg.querySelectorAll("*")).forEach(function (element) {
return svg.removeChild(element);
});
}
function defaultFetch(entry) {
return entry.value;
}
function buildElement(tag, attrs) {
var element = document.createElementNS("http://www.w3.org/2000/svg", tag);
for (var name in attrs) {
element.setAttribute(name, attrs[name]);
}
return element;
}
function sparkline(svg, entries, options) {
removeChildren(svg);
if (entries.length <= 1) {
return;
}
options = options || {};
if (typeof entries[0] === "number") {
entries = entries.map(function (entry) {
return {
value: entry
};
});
} // This function will be called whenever the mouse moves
// over the SVG. You can use it to render something like a
// tooltip.
var onmousemove = options.onmousemove; // This function will be called whenever the mouse leaves
// the SVG area. You can use it to hide the tooltip.
var onmouseout = options.onmouseout; // Should we run in interactive mode? If yes, this will handle the
// cursor and spot position when moving the mouse.
var interactive = "interactive" in options ? options.interactive : !!onmousemove; // Define how big should be the spot area.
var spotRadius = options.spotRadius || 2;
var spotDiameter = spotRadius * 2; // Define how wide should be the cursor area.
var cursorWidth = options.cursorWidth || 2; // Get the stroke width; this is used to compute the
// rendering offset.
var strokeWidth = parseFloat(svg.attributes["stroke-width"].value); // By default, data must be formatted as an array of numbers or
// an array of objects with the value key (like `[{value: 1}]`).
// You can set a custom function to return data for a different
// data structure.
var fetch = options.fetch || defaultFetch; // Retrieve only values, easing the find for the maximum value.
var values = entries.map(function (entry) {
return fetch(entry);
}); // The rendering width will account for the spot size.
var width = parseFloat(svg.attributes.width.value) - spotDiameter * 2; // Get the SVG element's full height.
// This is used
var fullHeight = parseFloat(svg.attributes.height.value); // The rendering height accounts for stroke width and spot size.
var height = fullHeight - strokeWidth * 2 - spotDiameter; // The maximum value. This is used to calculate the Y coord of
// each sparkline datapoint.
var max = Math.max.apply(Math, _toConsumableArray(values)); // Some arbitrary value to remove the cursor and spot out of
// the viewing canvas.
var offscreen = -1000; // Cache the last item index.
var lastItemIndex = values.length - 1; // Calculate the X coord base step.
var offset = width / lastItemIndex; // Hold all datapoints, which is whatever we got as the entry plus
// x/y coords and the index.
var datapoints = []; // Hold the line coordinates.
var pathY = getY(max, height, strokeWidth + spotRadius, values[0]);
var pathCoords = "M".concat(spotDiameter, " ").concat(pathY);
values.forEach(function (value, index) {
var x = index * offset + spotDiameter;
var y = getY(max, height, strokeWidth + spotRadius, value);
datapoints.push(Object.assign({}, entries[index], {
index: index,
x: x,
y: y
}));
pathCoords += " L ".concat(x, " ").concat(y);
});
var path = buildElement("path", {
class: "sparkline--line",
d: pathCoords,
fill: "none"
});
var fillCoords = "".concat(pathCoords, " V ").concat(fullHeight, " L ").concat(spotDiameter, " ").concat(fullHeight, " Z");
var fill = buildElement("path", {
class: "sparkline--fill",
d: fillCoords,
stroke: "none"
});
svg.appendChild(fill);
svg.appendChild(path);
if (!interactive) {
return;
}
var cursor = buildElement("line", {
class: "sparkline--cursor",
x1: offscreen,
x2: offscreen,
y1: 0,
y2: fullHeight,
"stroke-width": cursorWidth
});
var spot = buildElement("circle", {
class: "sparkline--spot",
cx: offscreen,
cy: offscreen,
r: spotRadius
});
svg.appendChild(cursor);
svg.appendChild(spot);
var interactionLayer = buildElement("rect", {
width: svg.attributes.width.value,
height: svg.attributes.height.value,
style: "fill: transparent; stroke: transparent",
class: "sparkline--interaction-layer"
});
svg.appendChild(interactionLayer);
interactionLayer.addEventListener("mouseout", function (event) {
cursor.setAttribute("x1", offscreen);
cursor.setAttribute("x2", offscreen);
spot.setAttribute("cx", offscreen);
if (onmouseout) {
onmouseout(event);
}
});
interactionLayer.addEventListener("mousemove", function (event) {
var mouseX = event.offsetX;
var nextDataPoint = datapoints.find(function (entry) {
return entry.x >= mouseX;
});
if (!nextDataPoint) {
nextDataPoint = datapoints[lastItemIndex];
}
var previousDataPoint = datapoints[datapoints.indexOf(nextDataPoint) - 1];
var currentDataPoint;
var halfway;
if (previousDataPoint) {
halfway = previousDataPoint.x + (nextDataPoint.x - previousDataPoint.x) / 2;
currentDataPoint = mouseX >= halfway ? nextDataPoint : previousDataPoint;
} else {
currentDataPoint = nextDataPoint;
}
var x = currentDataPoint.x;
var y = currentDataPoint.y;
spot.setAttribute("cx", x);
spot.setAttribute("cy", y);
cursor.setAttribute("x1", x);
cursor.setAttribute("x2", x);
if (onmousemove) {
onmousemove(event, currentDataPoint);
}
});
}
/* harmony default export */ __webpack_exports__["default"] = (sparkline);
/***/ })
/******/ });
var sparkline=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=1)}([function(t,e,r){var n=r(2),o=r(3),i=r(4);t.exports=function(t){return n(t)||o(t)||i()}},function(t,e,r){"use strict";r.r(e),r.d(e,"sparkline",function(){return c});var n=r(0),o=r.n(n);function i(t,e,r,n){return parseFloat((e-n*e/t+r).toFixed(2))}function a(t){return t.value}function u(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 c(t,e,r){var n;if(n=t,o()(n.querySelectorAll("*")).forEach(function(t){return n.removeChild(t)}),!(e.length<=1)){r=r||{},"number"==typeof e[0]&&(e=e.map(function(t){return{value:t}}));var c=r.onmousemove,l=r.onmouseout,s="interactive"in r?r.interactive:!!c,f=r.spotRadius||2,p=2*f,d=r.cursorWidth||2,v=parseFloat(t.attributes["stroke-width"].value),b=r.fetch||a,h=e.map(function(t){return b(t)}),y=parseFloat(t.attributes.width.value)-2*p,x=parseFloat(t.attributes.height.value),m=x-2*v-p,g=Math.max.apply(Math,o()(h)),A=-1e3,w=h.length-1,j=y/w,k=[],O=i(g,m,v+f,h[0]),S="M".concat(p," ").concat(O);h.forEach(function(t,r){var n=r*j+p,o=i(g,m,v+f,t);k.push(Object.assign({},e[r],{index:r,x:n,y:o})),S+=" L ".concat(n," ").concat(o)});var M=u("path",{class:"sparkline--line",d:S,fill:"none"}),C=u("path",{class:"sparkline--fill",d:"".concat(S," V ").concat(x," L ").concat(p," ").concat(x," Z"),stroke:"none"});if(t.appendChild(C),t.appendChild(M),s){var E=u("line",{class:"sparkline--cursor",x1:A,x2:A,y1:0,y2:x,"stroke-width":d}),_=u("circle",{class:"sparkline--spot",cx:A,cy:A,r:f});t.appendChild(E),t.appendChild(_);var F=u("rect",{width:t.attributes.width.value,height:t.attributes.height.value,style:"fill: transparent; stroke: transparent",class:"sparkline--interaction-layer"});t.appendChild(F),F.addEventListener("mouseout",function(t){E.setAttribute("x1",A),E.setAttribute("x2",A),_.setAttribute("cx",A),l&&l(t)}),F.addEventListener("mousemove",function(t){var e=t.offsetX,r=k.find(function(t){return t.x>=e});r||(r=k[w]);var n,o=k[k.indexOf(r)-1],i=(n=o?o.x+(r.x-o.x)/2<=e?r:o:r).x,a=n.y;_.setAttribute("cx",i),_.setAttribute("cy",a),E.setAttribute("x1",i),E.setAttribute("x2",i),c&&c(t,n)})}}}e.default=c},function(t,e){t.exports=function(t){if(Array.isArray(t)){for(var e=0,r=new Array(t.length);e<t.length;e++)r[e]=t[e];return r}}},function(t,e){t.exports=function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}},function(t,e){t.exports=function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}}]);
//# sourceMappingURL=sparkline.js.map
{
"name": "@fnando/sparkline",
"version": "0.3.9",
"version": "0.3.10",
"files": [

@@ -10,9 +10,8 @@ "src/sparkline.js",

"main": "dist/sparkline.js",
"module": "src/sparkline.js",
"browser": "dist/sparkline.js",
"module": "dist/sparkline.commonjs2.js",
"scripts": {
"test": "mocha --require @babel/register \"test/**/*_test.js\"",
"js:dist:expanded": "webpack",
"js:dist:minified": "env NODE_ENV=production webpack",
"dist": "yarn test && yarn js:dist:expanded && yarn js:dist:minified"
"js:dist:commonjs2": "LIBRARY_TARGET=commonjs2 webpack",
"js:dist:browser": "LIBRARY_TARGET=var webpack",
"dist": "rm -rf dist/* && yarn test && yarn js:dist:browser && yarn js:dist:commonjs2"
},

@@ -25,4 +24,8 @@ "description": "Generate SVG sparklines with JavaScript without any external dependency.",

"@babel/core": "7.0.x",
"@babel/plugin-proposal-function-bind": "7.0.x",
"@babel/plugin-proposal-object-rest-spread": "x",
"@babel/plugin-transform-runtime": "7.1.x",
"@babel/preset-env": "7.0.x",
"@babel/register": "7.0.x",
"@babel/preset-env": "7.0.x",
"@babel/runtime": "7.0.x",
"babel-loader": "8.0.x",

@@ -29,0 +32,0 @@ "jsdom": "11.7.x",

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