chrt-interpolations
Version:
Interpolation functions for Chrt
3 lines (2 loc) • 3.93 kB
JavaScript
// chrt-interpolations v0.0.15 Copyright 2020-2024 chrt chrt.io
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).chrt=n.chrt||{})}(this,(function(n){"use strict";function t(n,t){(null==t||t>n.length)&&(t=n.length);for(var r=0,e=Array(t);r<t;r++)e[r]=n[r];return e}function r(n,t){return function(n){if(Array.isArray(n))return n}(n)||function(n,t){var r=null==n?null:"undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(null!=r){var e,a,o,i,c=[],u=!0,l=!1;try{if(o=(r=r.call(n)).next,0===t);else for(;!(u=(e=o.call(r)).done)&&(c.push(e.value),c.length!==t);u=!0);}catch(n){l=!0,a=n}finally{try{if(!u&&null!=r.return&&(i=r.return(),Object(i)!==i))return}finally{if(l)throw a}}return c}}(n,t)||a(n,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function e(n){return function(n){if(Array.isArray(n))return t(n)}(n)||function(n){if("undefined"!=typeof Symbol&&null!=n[Symbol.iterator]||null!=n["@@iterator"])return Array.from(n)}(n)||a(n)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(n,r){if(n){if("string"==typeof n)return t(n,r);var e={}.toString.call(n).slice(8,-1);return"Object"===e&&n.constructor&&(e=n.constructor.name),"Map"===e||"Set"===e?Array.from(n):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?t(n,r):void 0}}function o(n){return null===n||null==n||void 0===n}function i(n){return"number"==typeof n&&!isFinite(n)}function c(n){var t=this;return null!=this&&this.fields?n.map((function(n){var r=o(n[t.fields.x])||i(n[t.fields.x])?null:t.parentNode.scales.x[t.scales.x](n[t.fields.x]),e=o(n[t.fields.y])||i(n[t.fields.y])?null:t.parentNode.scales.y[t.scales.y](n[t.fields.y]);return[i(r)?0:r,i(e)?0:e]})):[]}var u=function(n,t){var r,a=n.reduce((function(n,t){return o(t[1])?n.push([]):n[n.length-1].push(t),n}),[[]]).map((function(n){return n.reduce((function(n,r,e,a){return n.push(0===e?"M".concat(isNaN(r[0])?0:r[0],",").concat(isNaN(r[1])?0:r[1]):"".concat(t(r,e,a))),n}),[])}));return(r=[]).concat.apply(r,e(a))};var l=function(n){return"L".concat(isNaN(n[0])?0:n[0],",").concat(isNaN(n[1])?0:n[1])};var s=function(n,t,r,e){var a,o,i,c,u=(a=t||n,i=(o=r||n)[0]-a[0],c=o[1]-a[1],{length:Math.sqrt(Math.pow(i,2)+Math.pow(c,2)),angle:Math.atan2(c,i)}),l=u.angle+(e?Math.PI:0),s=.1*u.length;return[n[0]+Math.cos(l)*s,n[1]+Math.sin(l)*s]},f=function(n,t,e){if(isNaN(n[0])||isNaN(n[1]))return"";var a=r(s(e[t-1],e[t-2],n),2),o=a[0],i=a[1],c=r(s(n,e[t-1],e[t+1],!0),2),u=c[0],l=c[1];return"C ".concat(o,",").concat(i," ").concat(u,",").concat(l," ").concat(n[0],",").concat(n[1])};function N(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:h;return u(c.call(this,n),t)}var h=function(n,t,r){var e=((isNaN(n[0])?0:n[0])+(isNaN(r[t-1][0])?0:r[t-1][0]))/2;return"L".concat(isNaN(e)?0:e,",").concat(isNaN(r[t-1][1])?0:r[t-1][1],"\n L").concat(isNaN(e)?0:e,",").concat(isNaN(n[1])?0:n[1],"\n L").concat(isNaN(n[0])?0:n[0],",").concat(isNaN(n[1])?0:n[1])},d=function(n,t,r){return"L".concat(isNaN(n[0])?0:n[0],",").concat(isNaN(r[t-1][1])?0:r[t-1][1],"\n L").concat(isNaN(n[0])?0:n[0],",").concat(isNaN(n[1])?0:n[1])},y=function(n,t,r){return"L".concat(isNaN(r[t-1][0])?0:r[t-1][0],",").concat(isNaN(n[1])?0:n[1],"\n L").concat(isNaN(n[0])?0:n[0],",").concat(isNaN(n[1])?0:n[1])};n.linear=function(n){return u(c.call(this,n),l)},n.spline=function(n){return u(c.call(this,n),f)},n.step=N,n.stepAfter=function(n){return N.call(this,n,d)},n.stepBefore=function(n){return N.call(this,n,y)}}));