UNPKG

8.54 kBJavaScriptView Raw
1/*
2 d3plus-common v0.6.48
3 Common functions and methods used across D3plus modules.
4 Copyright (c) 2019 D3plus - https://d3plus.org
5 @license MIT
6*/
7if(typeof Object.assign!=="function"){Object.defineProperty(Object,"assign",{value:function e(t){"use strict";if(t===null){throw new TypeError("Cannot convert undefined or null to object")}var n=Object(t);for(var r=1;r<arguments.length;r++){var i=arguments[r];if(i!==null){for(var o in i){if(Object.prototype.hasOwnProperty.call(i,o)){n[o]=i[o]}}}}return n},writable:true,configurable:true})}if(!Array.prototype.includes){Object.defineProperty(Array.prototype,"includes",{value:function e(t,n){var r=Object(this);var i=r.length>>>0;if(i===0)return false;var o=n|0;var f=Math.max(o>=0?o:i-Math.abs(o),0);function s(e,t){return e===t||typeof e==="number"&&typeof t==="number"&&isNaN(e)&&isNaN(t)}while(f<i){if(s(r[f],t)){return true}f++}return false}})}if(!String.prototype.includes){Object.defineProperty(String.prototype,"includes",{value:function(e,t){if(typeof t!=="number"){t=0}if(t+e.length>this.length){return false}else{return this.indexOf(e,t)!==-1}}})}if(!Array.prototype.find){Object.defineProperty(Array.prototype,"find",{value:function(e){if(this==null){throw new TypeError('"this" is null or not defined')}var t=Object(this);var n=t.length>>>0;if(typeof e!=="function"){throw new TypeError("predicate must be a function")}var r=arguments[1];var i=0;while(i<n){var o=t[i];if(e.call(r,o,i,t)){return o}i++}return undefined},configurable:true,writable:true})}if(!String.prototype.startsWith){Object.defineProperty(String.prototype,"startsWith",{value:function(e,t){t=!t||t<0?0:+t;return this.substring(t,t+e.length)===e}})}if(typeof window!=="undefined"){(function(){var r=function(e,t){var n=e.nodeType;if(n===3){t.push(e.textContent.replace(/&/,"&amp;").replace(/</,"&lt;").replace(">","&gt;"))}else if(n===1){t.push("<",e.tagName);if(e.hasAttributes()){[].forEach.call(e.attributes,function(e){t.push(" ",e.item.name,"='",e.item.value,"'")})}if(e.hasChildNodes()){t.push(">");[].forEach.call(e.childNodes,function(e){r(e,t)});t.push("</",e.tagName,">")}else{t.push("/>")}}else if(n==8){t.push("\x3c!--",e.nodeValue,"--\x3e")}};Object.defineProperty(SVGElement.prototype,"innerHTML",{get:function(){var e=[];var t=this.firstChild;while(t){r(t,e);t=t.nextSibling}return e.join("")},set:function(e){while(this.firstChild){this.removeChild(this.firstChild)}try{var t=new DOMParser;t.async=false;var n="<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'>"+e+"</svg>";var r=t.parseFromString(n,"text/xml").documentElement;var i=r.firstChild;while(i){this.appendChild(this.ownerDocument.importNode(i,true));i=i.nextSibling}}catch(e){}}});Object.defineProperty(SVGElement.prototype,"innerSVG",{get:function(){return this.innerHTML},set:function(e){this.innerHTML=e}})})()}(function(e,t){typeof exports==="object"&&typeof module!=="undefined"?t(exports,require("d3-selection"),require("d3-transition"),require("d3-array"),require("d3-collection")):typeof define==="function"&&define.amd?define("d3plus-common",["exports","d3-selection","d3-transition","d3-array","d3-collection"],t):t(e.d3plus={},e.d3Selection,e.d3Transition,e.d3Array,e.d3Collection)})(this,function(e,a,u,s,t){"use strict";function n(t,n){if(n===void 0){return function(e){return e[t]}}return function(e){return e[t]===void 0?n:e[t]}}function l(e){return e&&typeof e==="object"&&(typeof window==="undefined"||e!==window&&e!==window.document&&!(e instanceof Element))&&!Array.isArray(e)?true:false}function o(e){if(typeof window==="undefined"){return true}else{return e!==window&&e!==document}}function c(){var t=[],e=arguments.length;while(e--)t[e]=arguments[e];var r=t[0];var n=function(e){var n=t[e];Object.keys(n).forEach(function(e){var t=n[e];if(l(t)&&o(t)){if(r.hasOwnProperty(e)&&l(r[e])){r[e]=c({},r[e],t)}else{r[e]=c({},t)}}else if(Array.isArray(t)){r[e]=t.slice()}else{r[e]=t}})};for(var i=1;i<t.length;i++)n(i);return r}function d(e,t){if(t===void 0)t={};for(var n in t){if({}.hasOwnProperty.call(t,n)){e.attr(n,t[n])}}}function r(){return Math.floor((1+Math.random())*65536).toString(16).substring(1)}function i(){return""+r()+r()+"-"+r()+"-"+r()+"-"+r()+"-"+r()+r()+r()}var h="D3PLUS-COMMON-RESET";function p(e,t){if(l(e)){for(var n in e){if({}.hasOwnProperty.call(e,n)&&!n.startsWith("_")){var r=t&&l(t)?t[n]:undefined;if(e[n]===h){e[n]=r}else if(l(e[n])){p(e[n],r)}}}}}var f=function e(){this._locale="en-US";this._on={};this._uuid=i()};f.prototype.config=function e(t){if(!this._configDefault){var e={};for(var n in this.__proto__){if(n.indexOf("_")!==0&&!["config","constructor","render"].includes(n)){var r=this[n]();e[n]=l(r)?c({},r):r}}this._configDefault=e}if(arguments.length){for(var i in t){if({}.hasOwnProperty.call(t,i)&&i in this){var o=t[i];if(o===h){if(i==="on"){this._on=this._configDefault[i]}else{this[i](this._configDefault[i])}}else{p(o,this._configDefault[i]);this[i](o)}}}return this}else{var f={};for(var s in this.__proto__){if(s.indexOf("_")!==0&&!["config","constructor","render"].includes(s)){f[s]=this[s]()}}return f}};f.prototype.locale=function e(t){return arguments.length?(this._locale=t,this):this._locale};f.prototype.on=function e(t,n){return arguments.length===2?(this._on[t]=n,this):arguments.length?typeof t==="string"?this._on[t]:(this._on=Object.assign({},this._on,t),this):this._on};function y(n,e){if(e===void 0)e=[];if(!e||!(e instanceof Array)||!e.length){return undefined}return e.reduce(function(e,t){return Math.abs(t-n)<Math.abs(e-n)?t:e})}function v(e,r,t){var o=this;if(e===void 0)e=this._shapeConfig;if(r===void 0)r="shape";if(t===void 0)t=false;var n={duration:this._duration,on:{}};var i=function(i){return function(e,t,n){var r;while(e.__d3plus__){if(r){e.__d3plusParent__=r}r=e;t=e.i;e=e.data||e.feature}return i.bind(o)(e,t,n||r)}};var f=function(e,t){for(var n in t){if({}.hasOwnProperty.call(t,n)&&!n.includes(".")||n.includes("."+r)){e.on[n]=i(t[n])}}};var s=function(e,t){for(var n in t){if({}.hasOwnProperty.call(t,n)){if(n==="on"){f(e,t[n])}else if(typeof t[n]==="function"){e[n]=i(t[n])}else if(typeof t[n]==="object"&&!(t instanceof Array)){e[n]={on:{}};s(e[n],t[n])}else{e[n]=t[n]}}}};s(n,e);if(this._on){f(n,this._on)}if(t&&e[t]){s(n,e[t]);if(e[t].on){f(n,e[t].on)}}return n}function g(t){return function e(){return t}}function m(e,t){t=Object.assign({},{condition:true,enter:{},exit:{},parent:a.select("body"),transition:u.transition().duration(0),update:{}},t);var n=/\.([^#]+)/g.exec(e),r=/#([^\.]+)/g.exec(e),i=/^([^.^#]+)/g.exec(e)[1];var o=t.parent.selectAll(e.includes(":")?e.split(":")[1]:e).data(t.condition?[null]:[]);var f=o.enter().append(i).call(d,t.enter);if(r){f.attr("id",r[1])}if(n){f.attr("class",n[1])}o.exit().transition(t.transition).call(d,t.exit).remove();var s=f.merge(o);s.transition(t.transition).call(d,t.update);return s}function b(i,o){if(o===void 0)o={};var e=new Set(s.merge(i.map(function(e){return t.keys(e)}))),f={};e.forEach(function(t){var e=i.map(function(e){return e[t]});var n;if(o[t]){n=o[t](e)}else{var r=e.map(function(e){return e||e===false?e.constructor:e}).filter(function(e){return e!==void 0});if(!r.length){n=undefined}else if(r.indexOf(Array)>=0){n=s.merge(e.map(function(e){return e instanceof Array?e:[e]}));n=Array.from(new Set(n));if(n.length===1){n=n[0]}}else if(r.indexOf(String)>=0){n=Array.from(new Set(e));if(n.length===1){n=n[0]}}else if(r.indexOf(Number)>=0){n=s.sum(e)}else if(r.indexOf(Object)>=0){n=b(e.filter(function(e){return e}))}else{n=Array.from(new Set(e.filter(function(e){return e!==void 0})));if(n.length===1){n=n[0]}}}f[t]=n});return f}function w(e){var i;if(typeof e==="number"){i=[e]}else{i=e.split(/\s+/)}if(i.length===1){i=[i[0],i[0],i[0],i[0]]}else if(i.length===2){i=i.concat(i)}else if(i.length===3){i.push(i[1])}return["top","right","bottom","left"].reduce(function(e,t,n){var r=parseFloat(i[n]);e[t]=r||0;return e},{})}function _(){if("-webkit-transform"in document.body.style){return"-webkit-"}else if("-moz-transform"in document.body.style){return"-moz-"}else if("-ms-transform"in document.body.style){return"-ms-"}else if("-o-transform"in document.body.style){return"-o-"}else{return""}}function O(e,t){if(t===void 0)t={};for(var n in t){if({}.hasOwnProperty.call(t,n)){e.style(n,t[n])}}}e.accessor=n;e.assign=c;e.attrize=d;e.BaseClass=f;e.closest=y;e.configPrep=v;e.constant=g;e.elem=m;e.isObject=l;e.merge=b;e.parseSides=w;e.prefix=_;e.RESET=h;e.stylize=O;e.uuid=i;Object.defineProperty(e,"__esModule",{value:true})});
\No newline at end of file