Socket
Socket
Sign inDemoInstall

d3kit

Package Overview
Dependencies
2
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.1.0 to 3.1.1

5

CHANGELOG.md

@@ -5,2 +5,7 @@ # Change logs

### 3.1.1
- Use existing `fitOptions` when calling `.fit()` with no argument.
- Fix issue with fit watching when it does not resize as expected.
### 3.1.0

@@ -7,0 +12,0 @@

11

dist/d3kit-es.js

@@ -899,3 +899,3 @@ import { select } from 'd3-selection';

var _ref$interval = _ref.interval;
var interval = _ref$interval === undefined ? 500 : _ref$interval;
var interval = _ref$interval === undefined ? 200 : _ref$interval;

@@ -1294,3 +1294,3 @@

// Fit once
var fitter = new Fitter(fitOptions);
var fitter = new Fitter(this._state.fitOptions);

@@ -1313,3 +1313,8 @@ var _fitter$fit = fitter.fit(this.dimension(), this.container.node());

}
this.fitWatcher = new FitWatcher(this.dimension(), this.container.node(), this._state.fitOptions, isObject(watchOptions) ? watchOptions : null).on('change', function (dim) {
this.fitWatcher = new FitWatcher(
// pass getter instead of value
// because the value may change when time the watcher checks
function () {
return _this.dimension();
}, this.container.node(), this._state.fitOptions, isObject(watchOptions) ? watchOptions : null).on('change', function (dim) {
return _this.dimension([dim.width, dim.height]);

@@ -1316,0 +1321,0 @@ }).start();

@@ -902,3 +902,3 @@ (function (global, factory) {

var _ref$interval = _ref.interval;
var interval = _ref$interval === undefined ? 500 : _ref$interval;
var interval = _ref$interval === undefined ? 200 : _ref$interval;

@@ -1297,3 +1297,3 @@

// Fit once
var fitter = new Fitter(fitOptions);
var fitter = new Fitter(this._state.fitOptions);

@@ -1316,3 +1316,8 @@ var _fitter$fit = fitter.fit(this.dimension(), this.container.node());

}
this.fitWatcher = new FitWatcher(this.dimension(), this.container.node(), this._state.fitOptions, isObject(watchOptions) ? watchOptions : null).on('change', function (dim) {
this.fitWatcher = new FitWatcher(
// pass getter instead of value
// because the value may change when time the watcher checks
function () {
return _this.dimension();
}, this.container.node(), this._state.fitOptions, isObject(watchOptions) ? watchOptions : null).on('change', function (dim) {
return _this.dimension([dim.width, dim.height]);

@@ -1319,0 +1324,0 @@ }).start();

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("d3-selection"),require("d3-dispatch")):"function"==typeof define&&define.amd?define(["exports","d3-selection","d3-dispatch"],e):e(t.d3Kit=t.d3Kit||{},t.d3,t.d3)}(this,function(t,e,n){"use strict";function i(t){var e="undefined"==typeof t?"undefined":E(t);return null!=t&&("object"==e||"function"==e)}function r(t){var e=i(t)?S.call(t):"";return e==M||e==P||e==I}function s(t){return null!=t&&"object"==("undefined"==typeof t?"undefined":E(t))}function a(t){return"symbol"==("undefined"==typeof t?"undefined":E(t))||s(t)&&$.call(t)==H}function o(t){if("number"==typeof t)return t;if(a(t))return q;if(i(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=i(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(U,"");var n=K.test(t);return n||V.test(t)?Z(t.slice(2),n?2:8):B.test(t)?q:+t}function h(t,e,n){function r(e){var n=g,i=v;return g=v=void 0,_=e,m=t.apply(i,n)}function s(t){return _=t,y=setTimeout(u,e),b?r(t):m}function a(t){var n=t-w,i=t-_,r=e-n;return O?X(r,p-i):r}function h(t){var n=t-w,i=t-_;return void 0===w||n>=e||0>n||O&&i>=p}function u(){var t=z();return h(t)?c(t):void(y=setTimeout(u,a(t)))}function c(t){return y=void 0,k&&g?r(t):(g=v=void 0,m)}function f(){void 0!==y&&clearTimeout(y),_=0,g=w=v=y=void 0}function l(){return void 0===y?m:c(z())}function d(){var t=z(),n=h(t);if(g=arguments,v=this,w=t,n){if(void 0===y)return s(w);if(O)return y=setTimeout(u,e),r(w)}return void 0===y&&(y=setTimeout(u,e)),m}var g,v,p,m,y,w,_=0,b=!1,O=!1,k=!0;if("function"!=typeof t)throw new TypeError(J);return e=o(e)||0,i(n)&&(b=!!n.leading,O="maxWait"in n,p=O?Q(o(n.maxWait)||0,e):p,k="trailing"in n?!!n.trailing:k),d.cancel=f,d.flush=l,d}function u(t,e,n){var r=!0,s=!0;if("function"!=typeof t)throw new TypeError(Y);return i(n)&&(r="leading"in n?!!n.leading:r,s="trailing"in n?!!n.trailing:s),h(t,e,{leading:r,maxWait:e,trailing:s})}function c(t){return null==t?"":String(t).replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function f(t){return null==t?"\\s":t.source?t.source:"["+c(t)+"]"}function l(t,e){if(null==t)return"";if(!e&&tt)return tt.call(t);var n=f(e),i=new RegExp("^"+n+"+|"+n+"+$","g");return String(t).replace(i,"")}function d(t){return l(t).replace(/([A-Z])/g,"-$1").replace(/[-_\s]+/g,"-").toLowerCase()}function g(t){t=t||{};for(var e=1;e<arguments.length;e++){var n=arguments[e];if(n)for(var s in n)if(n.hasOwnProperty(s)){var a=n[s];t[s]=!i(a)||Array.isArray(a)||r(a)?a:g(t[s],a)}}return t}function v(t){t=t||{};for(var e=1;e<arguments.length;e++)if(arguments[e])for(var n in arguments[e])arguments[e].hasOwnProperty(n)&&(t[n]=arguments[e][n]);return t}function p(t,e,n){return function(){var i=n.apply(e,arguments);return i===e?t:i}}function m(t,e){for(var n=1,i=arguments.length,r=void 0;++n<i;)t[r=arguments[n]]=p(t,e,e[r]);return t}function y(t){return r(t)?t:function(){return t}}function w(t){throw new Error("Missing parameter "+t)}function _(t){return null!==t&&void 0!==t}function b(t){return null===t||void 0===t}function O(t){return!(!t||1!==t.nodeType)}function k(t){if(b(t))return function(t,e){return Math.min(t,e)};var e=(""+t).trim().toLowerCase();if(e.indexOf("%")>-1){var n=function(){var t=+e.replace("%","")/100;return{v:function(e,n){return n*t}}}();if("object"===("undefined"==typeof n?"undefined":E(n)))return n.v}return function(){return+e.replace("px","")}}function D(t){function e(t,e){var n=arguments.length<=2||void 0===arguments[2]?"":arguments[2],i=e.split("."),r=void 0,s=void 0;i.length>1?(s=i[0].length>0?i[0]:h,r=i[1]):(s=h,r=i[0]);var a=""+n+r;if(u.hasOwnProperty(a))throw new Error("invalid or duplicate layer id: "+a);var o=d(r)+"-layer",c=t.append(s).classed(o,!0);return u[a]=c,c}function n(t,r){var s=arguments.length<=2||void 0===arguments[2]?"":arguments[2];if(Array.isArray(r))return r.map(function(e){return n(t,e,s)});if(i(r)){var a=Object.keys(r),o=C(a,1),h=o[0],u=e(t,h,s);return n(u,r[h],""+s+h+"/"),u}return e(t,r,s)}function r(e){return n(t,e)}function s(t){return Array.isArray(t)?t.map(r):r(t)}function a(t){return u[t]}function o(t){return!!u[t]}var h=arguments.length<=1||void 0===arguments[1]?"g":arguments[1],u={};return{create:s,get:a,has:o}}var E="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},j=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},x=function(){function t(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)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),W=function ut(t,e,n){null===t&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,e);if(void 0===i){var r=Object.getPrototypeOf(t);return null===r?void 0:ut(r,e,n)}if("value"in i)return i.value;var s=i.get;return void 0===s?void 0:s.call(n)},A=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},T=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},C=function(){function t(t,e){var n=[],i=!0,r=!1,s=void 0;try{for(var a,o=t[Symbol.iterator]();!(i=(a=o.next()).done)&&(n.push(a.value),!e||n.length!==e);i=!0);}catch(h){r=!0,s=h}finally{try{!i&&o["return"]&&o["return"]()}finally{if(r)throw s}}return n}return function(e,n){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),M="[object Function]",P="[object GeneratorFunction]",I="[object Proxy]",N=Object.prototype,S=N.toString,R="object"==("undefined"==typeof global?"undefined":E(global))&&global&&global.Object===Object&&global,F="object"==("undefined"==typeof self?"undefined":E(self))&&self&&self.Object===Object&&self,L=R||F||Function("return this")(),z=function(){return L.Date.now()},H="[object Symbol]",G=Object.prototype,$=G.toString,q=0/0,U=/^\s+|\s+$/g,B=/^[-+]0x[0-9a-f]+$/i,K=/^0b[01]+$/i,V=/^0o[0-7]+$/i,Z=parseInt,J="Expected a function",Q=Math.max,X=Math.min,Y="Expected a function",tt=String.prototype.trim,et=Object.freeze({isObject:i,isFunction:r,kebabCase:d,deepExtend:g,extend:v,rebind:m,functor:y,debounce:h,throttle:u}),nt=function(){function t(){j(this,t);for(var e=arguments.length,n=Array(e),i=0;e>i;i++)n[i]=arguments[i];if(1===n.length){var s=n[0],a=r(s)?s():s;if(a instanceof t)this.width=a.width,this.height=a.height;else if(O(a))this.width=a.clientWidth,this.height=a.clientHeight;else if(Array.isArray(a))this.width=a[0],this.height=a[1];else{if(!(_(a)&&_(a.width)&&_(a.height))){var o=new Error("Unsupported input. Must be either\n DOMNode, Array or Object with field width and height,\n or a function that returns any of the above.");throw o.value=s,o}this.width=a.width,this.height=a.height}}else{var h=n[0],u=n[1];this.width=h,this.height=u}}return x(t,[{key:"isEqual",value:function(e){if(e instanceof t)return this.width===e.width&&this.height===e.height;var n=new t(e);return this.width===n.width&&this.height===n.height}},{key:"toArray",value:function(){return[this.width,this.height]}},{key:"toObject",value:function(){return{width:this.width,height:this.height}}}]),t}(),it=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];j(this,t);var n=e||{},i=n.mode,r=void 0===i?t.MODE_BASIC:i,s=n.width,a=void 0===s?"100%":s,o=n.height,h=void 0===o?null:o,u=n.ratio,c=void 0===u?1:u,f=n.maxWidth,l=void 0===f?null:f,d=n.maxHeight,g=void 0===d?null:d;r===t.MODE_ASPECT_RATIO?(this.wFn=k(l),this.hFn=k(g),this.options={mode:r,ratio:c,maxWidth:l,maxHeight:g}):(this.wFn=k(a),this.hFn=k(h),this.options={mode:r,width:a,height:h})}return x(t,[{key:"fit",value:function(){var e=arguments.length<=0||void 0===arguments[0]?w("box"):arguments[0],n=arguments.length<=1||void 0===arguments[1]?w("container"):arguments[1],i=new nt(e),r=i.width,s=i.height,a=new nt(n),o=a.width,h=a.height,u=void 0;if(this.options.mode===t.MODE_ASPECT_RATIO){var c=this.options.ratio,f=this.wFn(o,o),l=this.hFn(h,h),d=Math.floor(c*l);u=f>=d?new nt(d,l):new nt(f,Math.floor(f/c))}else u=new nt(this.wFn(r,o),this.hFn(s,h));return{dimension:u,changed:!u.isEqual(i)}}}]),t}();it.MODE_BASIC="basic",it.MODE_ASPECT_RATIO="aspectRatio";var rt=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];j(this,t);var n=e||{},i=n.mode,r=void 0===i?t.MODE_WINDOW:i,s=n.target,a=void 0===s?null:s,o=n.interval,h=void 0===o?500:o;r!==t.MODE_POLLING||a||w("options.target"),this.mode=r,this.target=a,this.interval=h,this.check=this.check.bind(this),this.throttledCheck=u(this.check,this.interval),this.isWatching=!1,this.listeners={change:[]}}return x(t,[{key:"hasTargetChanged",value:function(){if(!this.target)return!0;var t=new nt(this.target);return this.currentDim&&t.isEqual(this.currentDim)?!1:(this.currentDim=t,!0)}},{key:"check",value:function(){return this.hasTargetChanged()&&this.dispatch("change",this.currentDim),this}},{key:"dispatch",value:function(t){for(var e=this,n=arguments.length,i=Array(n>1?n-1:0),r=1;n>r;r++)i[r-1]=arguments[r];return this.listeners[t].forEach(function(t){return t.apply(e,i)}),this}},{key:"on",value:function(t,e){return-1===this.listeners[t].indexOf(e)&&this.listeners[t].push(e),this}},{key:"off",value:function(t,e){return this.listeners[t]=this.listeners[t].filter(function(t){return t!==e}),this}},{key:"start",value:function(){return this.isWatching||(this.target&&(this.currentDim=new nt(this.target)),this.mode===t.MODE_WINDOW?window.addEventListener("resize",this.throttledCheck):this.mode===t.MODE_POLLING&&(this.intervalId=window.setInterval(this.check,this.interval)),this.isWatching=!0),this}},{key:"stop",value:function(){return this.isWatching&&(this.mode===t.MODE_WINDOW?window.removeEventListener("resize",this.throttledCheck):this.mode===t.MODE_POLLING&&this.intervalId&&(window.clearInterval(this.intervalId),this.intervalId=null),this.isWatching=!1),this}},{key:"destroy",value:function(){return this.stop(),this.listeners.change=[],this}}]),t}();rt.MODE_WINDOW="window",rt.MODE_POLLING="polling";var st=function(t){function e(){var t=arguments.length<=0||void 0===arguments[0]?w("box"):arguments[0],n=arguments.length<=1||void 0===arguments[1]?w("container"):arguments[1],i=arguments[2],r=arguments[3];j(this,e);var s=T(this,Object.getPrototypeOf(e).call(this,r)),a=new it(i);return s.fit=function(){return a.fit(t,n)},s}return A(e,t),x(e,[{key:"check",value:function(){if(this.hasTargetChanged()){var t=this.fit(),e=t.changed,n=t.dimension;e&&this.dispatch("change",n)}return this}}]),e}(rt),at=function(){function t(n){j(this,t);for(var i=arguments.length,r=Array(i>1?i-1:0),s=1;i>s;s++)r[s-1]=arguments[s];var a=g.apply(void 0,[this.constructor.getDefaultOptions()].concat(r));this._state={width:a.initialWidth,height:a.initialHeight,innerWidth:0,innerHeight:0,fitOptions:null,options:a,data:null},this.container=e.select(n),this.container.style("line-height",0);var o=this.constructor.getCustomEventNames();this.setupDispatcher(o),this._dispatchData=h(this._dispatchData.bind(this),1),this._dispatchOptions=h(this._dispatchOptions.bind(this),1),this._dispatchResize=h(this._dispatchResize.bind(this),1),this._updateDimension=h(this._updateDimension.bind(this),1)}return x(t,null,[{key:"getDefaultOptions",value:function(){return{initialWidth:720,initialHeight:500,margin:{top:30,right:30,bottom:30,left:30},offset:{x:.5,y:.5}}}},{key:"getCustomEventNames",value:function(){return[]}}]),x(t,[{key:"setupDispatcher",value:function(){var e=arguments.length<=0||void 0===arguments[0]?[]:arguments[0];this._customEventNames=e,this._eventNames=t.DEFAULT_EVENTS.concat(e),this.dispatcher=n.dispatch.apply(this,this._eventNames)}},{key:"getCustomEventNames",value:function(){return this._customEventNames}},{key:"getInnerWidth",value:function(){return this._state.innerWidth}},{key:"getInnerHeight",value:function(){return this._state.innerHeight}},{key:"width",value:function(){if(0===arguments.length)return this._state.width;var t=Math.floor(+(arguments.length<=0?void 0:arguments[0]));return t!==this._state.width&&(this._state.width=t,this._updateDimension(),this._dispatchResize()),this}},{key:"height",value:function(){if(0===arguments.length)return this._state.height;var t=Math.floor(+(arguments.length<=0?void 0:arguments[0]));return t!==this._state.height&&(this._state.height=t,this._updateDimension(),this._dispatchResize()),this}},{key:"dimension",value:function(){if(0===arguments.length)return[this._state.width,this._state.height];var t=arguments.length<=0?void 0:arguments[0],e=C(t,2),n=e[0],i=e[1];return this.width(n).height(i),this}},{key:"data",value:function(){for(var t=arguments.length,e=Array(t),n=0;t>n;n++)e[n]=arguments[n];if(0===e.length)return this._state.data;var i=e[0];return this._state.data=i,this._dispatchData(),this}},{key:"margin",value:function(){if(0===arguments.length)return this._state.options.margin;var t=this._state.options.margin,e=v({},this._state.options.margin,arguments.length<=0?void 0:arguments[0]),n=Object.keys(t).some(function(n){return t[n]!==e[n]});return n&&(this._state.options.margin=e,this._updateDimension(),this._dispatchResize()),this}},{key:"offset",value:function(){if(0===arguments.length)return this._state.options.offset;var t=this._state.options.offset,e=v({},this._state.offset,arguments.length<=0?void 0:arguments[0]),n=Object.keys(t).some(function(n){return t[n]!==e[n]});return n&&(this._state.options.offset=e,this._updateDimension(),this._dispatchResize()),this}},{key:"options",value:function(){for(var t=arguments.length,e=Array(t),n=0;t>n;n++)e[n]=arguments[n];if(0===e.length)return this._state.options;var i=e[0];return i.margin&&this.margin(i.margin),i.offset&&this.offset(i.offset),this._state.options=g(this._state.options,i),this._dispatchOptions(),this}},{key:"_updateDimension",value:function(){var t=this._state,e=t.width,n=t.height,i=this._state.options.margin,r=i.top,s=i.right,a=i.bottom,o=i.left;return this._state.innerWidth=e-o-s,this._state.innerHeight=n-r-a,this}},{key:"updateDimensionNow",value:function(){return this._updateDimension(),this._updateDimension.flush(),this}},{key:"hasData",value:function(){var t=this._state.data;return null!==t&&void 0!==t}},{key:"hasNonZeroArea",value:function(){var t=this._state,e=t.innerWidth,n=t.innerHeight;return e>0&&n>0}},{key:"fit",value:function(t){var e=this,n=arguments.length<=1||void 0===arguments[1]?!1:arguments[1];t&&(this._state.fitOptions=t);var r=new it(t),s=r.fit(this.dimension(),this.container.node()),a=s.changed,o=s.dimension;a&&this.dimension([o.width,o.height]);var h=!!n;return h&&(this.fitWatcher&&this.fitWatcher.destroy(),this.fitWatcher=new st(this.dimension(),this.container.node(),this._state.fitOptions,i(n)?n:null).on("change",function(t){return e.dimension([t.width,t.height])}).start()),this}},{key:"stopFitWatcher",value:function(){return this.fitWatcher&&(this.fitWatcher.destroy(),this.fitWatcher=null),this}},{key:"_dispatchData",value:function(){return this.dispatcher.call("data",this,this._state.data),this}},{key:"_dispatchOptions",value:function(){return this.dispatcher.call("options",this,this._state.options),this}},{key:"_dispatchResize",value:function(){var t=this._state,e=t.width,n=t.height,i=t.innerWidth,r=t.innerHeight;return this.dispatcher.apply("resize",this,[e,n,i,r]),this}},{key:"on",value:function(t,e){return this.dispatcher.on(t,e),this}},{key:"off",value:function(t){return this.dispatcher.on(t,null),this}},{key:"destroy",value:function(){var t=this;this._eventNames.forEach(function(e){t.off(e)}),this.stopFitWatcher()}}]),t}();at.DEFAULT_EVENTS=["data","options","resize"];var ot=function(t){function e(t){var n;j(this,e);for(var i=arguments.length,r=Array(i>1?i-1:0),s=1;i>s;s++)r[s-1]=arguments[s];var a=T(this,(n=Object.getPrototypeOf(e)).call.apply(n,[this,t].concat(r)));return a.canvas=a.container.append("canvas"),a.updateDimensionNow(),a}return A(e,t),x(e,null,[{key:"getDefaultOptions",value:function(){return g(W(Object.getPrototypeOf(e),"getDefaultOptions",this).call(this),{pixelRatio:window.devicePixelRatio})}}]),x(e,[{key:"getContext2d",value:function(){var t=this.options(),e=t.pixelRatio,n=t.margin,i=t.offset,r=this.canvas.node().getContext("2d");return r.setTransform(1,0,0,1,0,0),r.scale(e,e),r.translate(n.left+i.x,n.top+i.y),r}},{key:"clear",value:function(){var t=this.options(),e=t.pixelRatio,n=this.canvas.node().getContext("2d");return n.setTransform(1,0,0,1,0,0),n.scale(e,e),n.clearRect(0,0,this.width(),this.height()),this}},{key:"_updateDimension",value:function(){W(Object.getPrototypeOf(e.prototype),"_updateDimension",this).call(this);var t=this._state,n=t.width,i=t.height,r=this._state.options.pixelRatio;return this.canvas.style("width",n).style("height",i).attr("width",n*r).attr("height",i*r),this}}]),e}(at),ht=function(t){function e(t){var n;j(this,e);for(var i=arguments.length,r=Array(i>1?i-1:0),s=1;i>s;s++)r[s-1]=arguments[s];var a=T(this,(n=Object.getPrototypeOf(e)).call.apply(n,[this,t].concat(r)));return a.svg=a.container.append("svg"),a.rootG=a.svg.append("g"),a.layers=new D(a.rootG),a.updateDimensionNow(),a}return A(e,t),x(e,[{key:"_updateDimension",value:function(){W(Object.getPrototypeOf(e.prototype),"_updateDimension",this).call(this);var t=this._state,n=t.width,i=t.height,r=this._state.options,s=r.offset,a=r.margin,o=a.top,h=a.left;return this.svg.attr("width",n).attr("height",i),this.rootG.attr("transform","translate("+(h+s.x)+","+(o+s.y)+")"),this}}]),e}(at);t.helper=et,t.AbstractChart=at,t.CanvasChart=ot,t.SvgChart=ht,t.LayerOrganizer=D,Object.defineProperty(t,"__esModule",{value:!0})});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("d3-selection"),require("d3-dispatch")):"function"==typeof define&&define.amd?define(["exports","d3-selection","d3-dispatch"],e):e(t.d3Kit=t.d3Kit||{},t.d3,t.d3)}(this,function(t,e,n){"use strict";function i(t){var e="undefined"==typeof t?"undefined":E(t);return null!=t&&("object"==e||"function"==e)}function r(t){var e=i(t)?S.call(t):"";return e==M||e==P||e==I}function s(t){return null!=t&&"object"==("undefined"==typeof t?"undefined":E(t))}function a(t){return"symbol"==("undefined"==typeof t?"undefined":E(t))||s(t)&&$.call(t)==H}function o(t){if("number"==typeof t)return t;if(a(t))return q;if(i(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=i(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(U,"");var n=K.test(t);return n||V.test(t)?Z(t.slice(2),n?2:8):B.test(t)?q:+t}function h(t,e,n){function r(e){var n=g,i=v;return g=v=void 0,_=e,m=t.apply(i,n)}function s(t){return _=t,y=setTimeout(u,e),b?r(t):m}function a(t){var n=t-w,i=t-_,r=e-n;return O?X(r,p-i):r}function h(t){var n=t-w,i=t-_;return void 0===w||n>=e||0>n||O&&i>=p}function u(){var t=z();return h(t)?c(t):void(y=setTimeout(u,a(t)))}function c(t){return y=void 0,k&&g?r(t):(g=v=void 0,m)}function f(){void 0!==y&&clearTimeout(y),_=0,g=w=v=y=void 0}function l(){return void 0===y?m:c(z())}function d(){var t=z(),n=h(t);if(g=arguments,v=this,w=t,n){if(void 0===y)return s(w);if(O)return y=setTimeout(u,e),r(w)}return void 0===y&&(y=setTimeout(u,e)),m}var g,v,p,m,y,w,_=0,b=!1,O=!1,k=!0;if("function"!=typeof t)throw new TypeError(J);return e=o(e)||0,i(n)&&(b=!!n.leading,O="maxWait"in n,p=O?Q(o(n.maxWait)||0,e):p,k="trailing"in n?!!n.trailing:k),d.cancel=f,d.flush=l,d}function u(t,e,n){var r=!0,s=!0;if("function"!=typeof t)throw new TypeError(Y);return i(n)&&(r="leading"in n?!!n.leading:r,s="trailing"in n?!!n.trailing:s),h(t,e,{leading:r,maxWait:e,trailing:s})}function c(t){return null==t?"":String(t).replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function f(t){return null==t?"\\s":t.source?t.source:"["+c(t)+"]"}function l(t,e){if(null==t)return"";if(!e&&tt)return tt.call(t);var n=f(e),i=new RegExp("^"+n+"+|"+n+"+$","g");return String(t).replace(i,"")}function d(t){return l(t).replace(/([A-Z])/g,"-$1").replace(/[-_\s]+/g,"-").toLowerCase()}function g(t){t=t||{};for(var e=1;e<arguments.length;e++){var n=arguments[e];if(n)for(var s in n)if(n.hasOwnProperty(s)){var a=n[s];t[s]=!i(a)||Array.isArray(a)||r(a)?a:g(t[s],a)}}return t}function v(t){t=t||{};for(var e=1;e<arguments.length;e++)if(arguments[e])for(var n in arguments[e])arguments[e].hasOwnProperty(n)&&(t[n]=arguments[e][n]);return t}function p(t,e,n){return function(){var i=n.apply(e,arguments);return i===e?t:i}}function m(t,e){for(var n=1,i=arguments.length,r=void 0;++n<i;)t[r=arguments[n]]=p(t,e,e[r]);return t}function y(t){return r(t)?t:function(){return t}}function w(t){throw new Error("Missing parameter "+t)}function _(t){return null!==t&&void 0!==t}function b(t){return null===t||void 0===t}function O(t){return!(!t||1!==t.nodeType)}function k(t){if(b(t))return function(t,e){return Math.min(t,e)};var e=(""+t).trim().toLowerCase();if(e.indexOf("%")>-1){var n=function(){var t=+e.replace("%","")/100;return{v:function(e,n){return n*t}}}();if("object"===("undefined"==typeof n?"undefined":E(n)))return n.v}return function(){return+e.replace("px","")}}function D(t){function e(t,e){var n=arguments.length<=2||void 0===arguments[2]?"":arguments[2],i=e.split("."),r=void 0,s=void 0;i.length>1?(s=i[0].length>0?i[0]:h,r=i[1]):(s=h,r=i[0]);var a=""+n+r;if(u.hasOwnProperty(a))throw new Error("invalid or duplicate layer id: "+a);var o=d(r)+"-layer",c=t.append(s).classed(o,!0);return u[a]=c,c}function n(t,r){var s=arguments.length<=2||void 0===arguments[2]?"":arguments[2];if(Array.isArray(r))return r.map(function(e){return n(t,e,s)});if(i(r)){var a=Object.keys(r),o=C(a,1),h=o[0],u=e(t,h,s);return n(u,r[h],""+s+h+"/"),u}return e(t,r,s)}function r(e){return n(t,e)}function s(t){return Array.isArray(t)?t.map(r):r(t)}function a(t){return u[t]}function o(t){return!!u[t]}var h=arguments.length<=1||void 0===arguments[1]?"g":arguments[1],u={};return{create:s,get:a,has:o}}var E="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},j=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},x=function(){function t(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)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),W=function ut(t,e,n){null===t&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,e);if(void 0===i){var r=Object.getPrototypeOf(t);return null===r?void 0:ut(r,e,n)}if("value"in i)return i.value;var s=i.get;return void 0===s?void 0:s.call(n)},A=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},T=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},C=function(){function t(t,e){var n=[],i=!0,r=!1,s=void 0;try{for(var a,o=t[Symbol.iterator]();!(i=(a=o.next()).done)&&(n.push(a.value),!e||n.length!==e);i=!0);}catch(h){r=!0,s=h}finally{try{!i&&o["return"]&&o["return"]()}finally{if(r)throw s}}return n}return function(e,n){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),M="[object Function]",P="[object GeneratorFunction]",I="[object Proxy]",N=Object.prototype,S=N.toString,R="object"==("undefined"==typeof global?"undefined":E(global))&&global&&global.Object===Object&&global,F="object"==("undefined"==typeof self?"undefined":E(self))&&self&&self.Object===Object&&self,L=R||F||Function("return this")(),z=function(){return L.Date.now()},H="[object Symbol]",G=Object.prototype,$=G.toString,q=0/0,U=/^\s+|\s+$/g,B=/^[-+]0x[0-9a-f]+$/i,K=/^0b[01]+$/i,V=/^0o[0-7]+$/i,Z=parseInt,J="Expected a function",Q=Math.max,X=Math.min,Y="Expected a function",tt=String.prototype.trim,et=Object.freeze({isObject:i,isFunction:r,kebabCase:d,deepExtend:g,extend:v,rebind:m,functor:y,debounce:h,throttle:u}),nt=function(){function t(){j(this,t);for(var e=arguments.length,n=Array(e),i=0;e>i;i++)n[i]=arguments[i];if(1===n.length){var s=n[0],a=r(s)?s():s;if(a instanceof t)this.width=a.width,this.height=a.height;else if(O(a))this.width=a.clientWidth,this.height=a.clientHeight;else if(Array.isArray(a))this.width=a[0],this.height=a[1];else{if(!(_(a)&&_(a.width)&&_(a.height))){var o=new Error("Unsupported input. Must be either\n DOMNode, Array or Object with field width and height,\n or a function that returns any of the above.");throw o.value=s,o}this.width=a.width,this.height=a.height}}else{var h=n[0],u=n[1];this.width=h,this.height=u}}return x(t,[{key:"isEqual",value:function(e){if(e instanceof t)return this.width===e.width&&this.height===e.height;var n=new t(e);return this.width===n.width&&this.height===n.height}},{key:"toArray",value:function(){return[this.width,this.height]}},{key:"toObject",value:function(){return{width:this.width,height:this.height}}}]),t}(),it=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];j(this,t);var n=e||{},i=n.mode,r=void 0===i?t.MODE_BASIC:i,s=n.width,a=void 0===s?"100%":s,o=n.height,h=void 0===o?null:o,u=n.ratio,c=void 0===u?1:u,f=n.maxWidth,l=void 0===f?null:f,d=n.maxHeight,g=void 0===d?null:d;r===t.MODE_ASPECT_RATIO?(this.wFn=k(l),this.hFn=k(g),this.options={mode:r,ratio:c,maxWidth:l,maxHeight:g}):(this.wFn=k(a),this.hFn=k(h),this.options={mode:r,width:a,height:h})}return x(t,[{key:"fit",value:function(){var e=arguments.length<=0||void 0===arguments[0]?w("box"):arguments[0],n=arguments.length<=1||void 0===arguments[1]?w("container"):arguments[1],i=new nt(e),r=i.width,s=i.height,a=new nt(n),o=a.width,h=a.height,u=void 0;if(this.options.mode===t.MODE_ASPECT_RATIO){var c=this.options.ratio,f=this.wFn(o,o),l=this.hFn(h,h),d=Math.floor(c*l);u=f>=d?new nt(d,l):new nt(f,Math.floor(f/c))}else u=new nt(this.wFn(r,o),this.hFn(s,h));return{dimension:u,changed:!u.isEqual(i)}}}]),t}();it.MODE_BASIC="basic",it.MODE_ASPECT_RATIO="aspectRatio";var rt=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];j(this,t);var n=e||{},i=n.mode,r=void 0===i?t.MODE_WINDOW:i,s=n.target,a=void 0===s?null:s,o=n.interval,h=void 0===o?200:o;r!==t.MODE_POLLING||a||w("options.target"),this.mode=r,this.target=a,this.interval=h,this.check=this.check.bind(this),this.throttledCheck=u(this.check,this.interval),this.isWatching=!1,this.listeners={change:[]}}return x(t,[{key:"hasTargetChanged",value:function(){if(!this.target)return!0;var t=new nt(this.target);return this.currentDim&&t.isEqual(this.currentDim)?!1:(this.currentDim=t,!0)}},{key:"check",value:function(){return this.hasTargetChanged()&&this.dispatch("change",this.currentDim),this}},{key:"dispatch",value:function(t){for(var e=this,n=arguments.length,i=Array(n>1?n-1:0),r=1;n>r;r++)i[r-1]=arguments[r];return this.listeners[t].forEach(function(t){return t.apply(e,i)}),this}},{key:"on",value:function(t,e){return-1===this.listeners[t].indexOf(e)&&this.listeners[t].push(e),this}},{key:"off",value:function(t,e){return this.listeners[t]=this.listeners[t].filter(function(t){return t!==e}),this}},{key:"start",value:function(){return this.isWatching||(this.target&&(this.currentDim=new nt(this.target)),this.mode===t.MODE_WINDOW?window.addEventListener("resize",this.throttledCheck):this.mode===t.MODE_POLLING&&(this.intervalId=window.setInterval(this.check,this.interval)),this.isWatching=!0),this}},{key:"stop",value:function(){return this.isWatching&&(this.mode===t.MODE_WINDOW?window.removeEventListener("resize",this.throttledCheck):this.mode===t.MODE_POLLING&&this.intervalId&&(window.clearInterval(this.intervalId),this.intervalId=null),this.isWatching=!1),this}},{key:"destroy",value:function(){return this.stop(),this.listeners.change=[],this}}]),t}();rt.MODE_WINDOW="window",rt.MODE_POLLING="polling";var st=function(t){function e(){var t=arguments.length<=0||void 0===arguments[0]?w("box"):arguments[0],n=arguments.length<=1||void 0===arguments[1]?w("container"):arguments[1],i=arguments[2],r=arguments[3];j(this,e);var s=T(this,Object.getPrototypeOf(e).call(this,r)),a=new it(i);return s.fit=function(){return a.fit(t,n)},s}return A(e,t),x(e,[{key:"check",value:function(){if(this.hasTargetChanged()){var t=this.fit(),e=t.changed,n=t.dimension;e&&this.dispatch("change",n)}return this}}]),e}(rt),at=function(){function t(n){j(this,t);for(var i=arguments.length,r=Array(i>1?i-1:0),s=1;i>s;s++)r[s-1]=arguments[s];var a=g.apply(void 0,[this.constructor.getDefaultOptions()].concat(r));this._state={width:a.initialWidth,height:a.initialHeight,innerWidth:0,innerHeight:0,fitOptions:null,options:a,data:null},this.container=e.select(n),this.container.style("line-height",0);var o=this.constructor.getCustomEventNames();this.setupDispatcher(o),this._dispatchData=h(this._dispatchData.bind(this),1),this._dispatchOptions=h(this._dispatchOptions.bind(this),1),this._dispatchResize=h(this._dispatchResize.bind(this),1),this._updateDimension=h(this._updateDimension.bind(this),1)}return x(t,null,[{key:"getDefaultOptions",value:function(){return{initialWidth:720,initialHeight:500,margin:{top:30,right:30,bottom:30,left:30},offset:{x:.5,y:.5}}}},{key:"getCustomEventNames",value:function(){return[]}}]),x(t,[{key:"setupDispatcher",value:function(){var e=arguments.length<=0||void 0===arguments[0]?[]:arguments[0];this._customEventNames=e,this._eventNames=t.DEFAULT_EVENTS.concat(e),this.dispatcher=n.dispatch.apply(this,this._eventNames)}},{key:"getCustomEventNames",value:function(){return this._customEventNames}},{key:"getInnerWidth",value:function(){return this._state.innerWidth}},{key:"getInnerHeight",value:function(){return this._state.innerHeight}},{key:"width",value:function(){if(0===arguments.length)return this._state.width;var t=Math.floor(+(arguments.length<=0?void 0:arguments[0]));return t!==this._state.width&&(this._state.width=t,this._updateDimension(),this._dispatchResize()),this}},{key:"height",value:function(){if(0===arguments.length)return this._state.height;var t=Math.floor(+(arguments.length<=0?void 0:arguments[0]));return t!==this._state.height&&(this._state.height=t,this._updateDimension(),this._dispatchResize()),this}},{key:"dimension",value:function(){if(0===arguments.length)return[this._state.width,this._state.height];var t=arguments.length<=0?void 0:arguments[0],e=C(t,2),n=e[0],i=e[1];return this.width(n).height(i),this}},{key:"data",value:function(){for(var t=arguments.length,e=Array(t),n=0;t>n;n++)e[n]=arguments[n];if(0===e.length)return this._state.data;var i=e[0];return this._state.data=i,this._dispatchData(),this}},{key:"margin",value:function(){if(0===arguments.length)return this._state.options.margin;var t=this._state.options.margin,e=v({},this._state.options.margin,arguments.length<=0?void 0:arguments[0]),n=Object.keys(t).some(function(n){return t[n]!==e[n]});return n&&(this._state.options.margin=e,this._updateDimension(),this._dispatchResize()),this}},{key:"offset",value:function(){if(0===arguments.length)return this._state.options.offset;var t=this._state.options.offset,e=v({},this._state.offset,arguments.length<=0?void 0:arguments[0]),n=Object.keys(t).some(function(n){return t[n]!==e[n]});return n&&(this._state.options.offset=e,this._updateDimension(),this._dispatchResize()),this}},{key:"options",value:function(){for(var t=arguments.length,e=Array(t),n=0;t>n;n++)e[n]=arguments[n];if(0===e.length)return this._state.options;var i=e[0];return i.margin&&this.margin(i.margin),i.offset&&this.offset(i.offset),this._state.options=g(this._state.options,i),this._dispatchOptions(),this}},{key:"_updateDimension",value:function(){var t=this._state,e=t.width,n=t.height,i=this._state.options.margin,r=i.top,s=i.right,a=i.bottom,o=i.left;return this._state.innerWidth=e-o-s,this._state.innerHeight=n-r-a,this}},{key:"updateDimensionNow",value:function(){return this._updateDimension(),this._updateDimension.flush(),this}},{key:"hasData",value:function(){var t=this._state.data;return null!==t&&void 0!==t}},{key:"hasNonZeroArea",value:function(){var t=this._state,e=t.innerWidth,n=t.innerHeight;return e>0&&n>0}},{key:"fit",value:function(t){var e=this,n=arguments.length<=1||void 0===arguments[1]?!1:arguments[1];t&&(this._state.fitOptions=t);var r=new it(this._state.fitOptions),s=r.fit(this.dimension(),this.container.node()),a=s.changed,o=s.dimension;a&&this.dimension([o.width,o.height]);var h=!!n;return h&&(this.fitWatcher&&this.fitWatcher.destroy(),this.fitWatcher=new st(function(){return e.dimension()},this.container.node(),this._state.fitOptions,i(n)?n:null).on("change",function(t){return e.dimension([t.width,t.height])}).start()),this}},{key:"stopFitWatcher",value:function(){return this.fitWatcher&&(this.fitWatcher.destroy(),this.fitWatcher=null),this}},{key:"_dispatchData",value:function(){return this.dispatcher.call("data",this,this._state.data),this}},{key:"_dispatchOptions",value:function(){return this.dispatcher.call("options",this,this._state.options),this}},{key:"_dispatchResize",value:function(){var t=this._state,e=t.width,n=t.height,i=t.innerWidth,r=t.innerHeight;return this.dispatcher.apply("resize",this,[e,n,i,r]),this}},{key:"on",value:function(t,e){return this.dispatcher.on(t,e),this}},{key:"off",value:function(t){return this.dispatcher.on(t,null),this}},{key:"destroy",value:function(){var t=this;this._eventNames.forEach(function(e){t.off(e)}),this.stopFitWatcher()}}]),t}();at.DEFAULT_EVENTS=["data","options","resize"];var ot=function(t){function e(t){var n;j(this,e);for(var i=arguments.length,r=Array(i>1?i-1:0),s=1;i>s;s++)r[s-1]=arguments[s];var a=T(this,(n=Object.getPrototypeOf(e)).call.apply(n,[this,t].concat(r)));return a.canvas=a.container.append("canvas"),a.updateDimensionNow(),a}return A(e,t),x(e,null,[{key:"getDefaultOptions",value:function(){return g(W(Object.getPrototypeOf(e),"getDefaultOptions",this).call(this),{pixelRatio:window.devicePixelRatio})}}]),x(e,[{key:"getContext2d",value:function(){var t=this.options(),e=t.pixelRatio,n=t.margin,i=t.offset,r=this.canvas.node().getContext("2d");return r.setTransform(1,0,0,1,0,0),r.scale(e,e),r.translate(n.left+i.x,n.top+i.y),r}},{key:"clear",value:function(){var t=this.options(),e=t.pixelRatio,n=this.canvas.node().getContext("2d");return n.setTransform(1,0,0,1,0,0),n.scale(e,e),n.clearRect(0,0,this.width(),this.height()),this}},{key:"_updateDimension",value:function(){W(Object.getPrototypeOf(e.prototype),"_updateDimension",this).call(this);var t=this._state,n=t.width,i=t.height,r=this._state.options.pixelRatio;return this.canvas.style("width",n).style("height",i).attr("width",n*r).attr("height",i*r),this}}]),e}(at),ht=function(t){function e(t){var n;j(this,e);for(var i=arguments.length,r=Array(i>1?i-1:0),s=1;i>s;s++)r[s-1]=arguments[s];var a=T(this,(n=Object.getPrototypeOf(e)).call.apply(n,[this,t].concat(r)));return a.svg=a.container.append("svg"),a.rootG=a.svg.append("g"),a.layers=new D(a.rootG),a.updateDimensionNow(),a}return A(e,t),x(e,[{key:"_updateDimension",value:function(){W(Object.getPrototypeOf(e.prototype),"_updateDimension",this).call(this);var t=this._state,n=t.width,i=t.height,r=this._state.options,s=r.offset,a=r.margin,o=a.top,h=a.left;return this.svg.attr("width",n).attr("height",i),this.rootG.attr("transform","translate("+(h+s.x)+","+(o+s.y)+")"),this}}]),e}(at);t.helper=et,t.AbstractChart=at,t.CanvasChart=ot,t.SvgChart=ht,t.LayerOrganizer=D,Object.defineProperty(t,"__esModule",{value:!0})});
{
"name": "d3kit",
"version": "3.1.0",
"version": "3.1.1",
"description": "A kit of tools to speed D3 related project development.",

@@ -58,7 +58,8 @@ "repository": {

"rollup-plugin-node-resolve": "^2.0.0",
"slimfit": "^0.4.1",
"slimfit": "^0.4.2",
"uglifyjs": "^2.4.10"
},
"scripts": {
"gh-pages": "npm run build && gh-pages -d dist",
"rollup": "rollup -c",
"build": "npm run rollup && uglifyjs dist/d3kit.js -m -c > dist/d3kit.min.js",
"test": "NODE_ENV=test karma start --single-run",

@@ -72,5 +73,4 @@ "tdd": "NODE_ENV=test karma start",

"prepublish": "pkgfiles",
"rollup": "rollup -c",
"build": "npm run rollup && uglifyjs dist/d3kit.js -m -c > dist/d3kit.min.js"
"gh-pages": "npm run build && gh-pages -d dist"
}
}

@@ -191,3 +191,3 @@ import { select } from 'd3-selection';

// Fit once
const fitter = new Fitter(fitOptions);
const fitter = new Fitter(this._state.fitOptions);
const { changed, dimension } = fitter.fit(

@@ -209,3 +209,5 @@ this.dimension(),

this.fitWatcher = new FitWatcher(
this.dimension(),
// pass getter instead of value
// because the value may change when time the watcher checks
() => this.dimension(),
this.container.node(),

@@ -212,0 +214,0 @@ this._state.fitOptions,

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc