mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2025-01-31 21:06:10 +01:00
8 lines
12 KiB
JavaScript
8 lines
12 KiB
JavaScript
|
/*!
|
||
|
* chartjs-plugin-zoom v1.2.1
|
||
|
* undefined
|
||
|
* (c) 2016-2022 chartjs-plugin-zoom Contributors
|
||
|
* Released under the MIT License
|
||
|
*/
|
||
|
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n(require("chart.js"),require("hammerjs"),require("chart.js/helpers")):"function"==typeof define&&define.amd?define(["chart.js","hammerjs","chart.js/helpers"],n):(e="undefined"!=typeof globalThis?globalThis:e||self).ChartZoom=n(e.Chart,e.Hammer,e.Chart.helpers)}(this,(function(e,n,t){"use strict";function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=o(n);const i=e=>e&&e.enabled&&e.modifierKey,c=(e,n)=>e&&n[e+"Key"],r=(e,n)=>e&&!n[e+"Key"];function l(e,n,t){return void 0===e||("string"==typeof e?-1!==e.indexOf(n):"function"==typeof e&&-1!==e({chart:t}).indexOf(n))}function s(e,n,o){const a=function({x:e,y:n},t){const o=t.scales,a=Object.keys(o);for(let t=0;t<a.length;t++){const i=o[a[t]];if(n>=i.top&&n<=i.bottom&&e>=i.left&&e<=i.right)return i}return null}(n,o);if(a&&l(e,a.axis,o))return[a];const i=[];return t.each(o.scales,(function(n){l(e,n.axis,o)||i.push(n)})),i}const m=new WeakMap;function u(e){let n=m.get(e);return n||(n={originalScaleLimits:{},updatedScaleLimits:{},handlers:{},panDelta:{}},m.set(e,n)),n}function d(e,n,t){const o=e.max-e.min,a=o*(n-1),i=e.isHorizontal()?t.x:t.y,c=Math.max(0,Math.min(1,(e.getValueForPixel(i)-e.min)/o||0));return{min:a*c,max:a*(1-c)}}function f(e,n,o,a,i){let c=o[a];if("original"===c){const o=e.originalScaleLimits[n.id][a];c=t.valueOrDefault(o.options,o.scale)}return t.valueOrDefault(c,i)}function h(e,{min:n,max:t},o,a=!1){const i=u(e.chart),{id:c,axis:r,options:l}=e,s=o&&(o[c]||o[r])||{},{minRange:m=0}=s,d=f(i,e,s,"min",-1/0),h=f(i,e,s,"max",1/0),p=Math.max(n,d),x=Math.min(t,h),g=a?Math.max(x-p,m):e.max-e.min;if(x-p!==g)if(d>x-g)n=p,t=p+g;else if(h<p+g)t=x,n=x-g;else{const e=(g-x+p)/2;n=p-e,t=x+e}else n=p,t=x;return l.min=n,l.max=t,i.updatedScaleLimits[e.id]={min:n,max:t},e.parse(n)!==e.min||e.parse(t)!==e.max}const p=e=>0===e||isNaN(e)?0:e<0?Math.min(Math.round(e),-1):Math.max(Math.round(e),1);const x={second:500,minute:3e4,hour:18e5,day:432e5,week:3024e5,month:1296e6,quarter:5184e6,year:157248e5};function g(e,n,t,o=!1){const{min:a,max:i,options:c}=e,r=c.time&&c.time.round,l=x[r]||0,s=e.getValueForPixel(e.getPixelForValue(a+l)-n),m=e.getValueForPixel(e.getPixelForValue(i+l)-n),{min:u=-1/0,max:d=1/0}=o&&t&&t[e.axis]||{};return!!(isNaN(s)||isNaN(m)||s<u||m>d)||h(e,{min:s,max:m},t,o)}function b(e,n,t){return g(e,n,t,!0)}const y={category:function(e,n,t,o){const a=d(e,n,t);return e.min===e.max&&n<1&&function(e){const n=e.getLabels().length-1;e.min>0&&(e.min-=1),e.max<n&&(e.max+=1)}(e),h(e,{min:e.min+p(a.min),max:e.max-p(a.max)},o,!0)},default:function(e,n,t,o){const a=d(e,n,t);return h(e,{min:e.min+a.min,max:e.max-a.max},o,!0)}},v={category:function(e,n,t){const o=e.getLabels().length-1;let{min:a,max:i}=e;const c=Math.max(i-a,1),r=Math.round(function(e){return e.isHorizontal()?e.width:e.height}(e)/Math.max(c,10)),l=Math.round(Math.abs(n/r));let s;return n<-r?(i=Math.min(i+l,o),a=1===c?i:i-c,s=i===o):n>r&&(a=Math.max(0,a-l),i=1===c?a:a+c,s=0===a),h(e,{min:a,max:i},t)||s},default:g,logarithmic:b,timeseries:b};function z(e,n){t.each(e,((t,o)=>{n[o]||delete e[o]}))}function M(e,n){const{scales:o}=e,{originalScaleLimits:a,updatedScaleLimits:i}=n;return t.each(o,(function(e){(function(e,n,t){const{id:o,options:{min:a,max:i}}=e;if(!n[o]||!t[o])return!0;const c=t[o];return c.min!==a||c.max!==i})(e,a,i)&&(a[e.id]={min:{scale:e.min,options:e.options.min},max:{scale:e.max,options:e.options.max}})})),z(a,o),z(i,o),a}function k(e,n,o,a){const i=y[e.type]||y.default;t.callback(i,[e,n,o,a])}function w(e){const n=e.chartArea;return{x:(n.left+n.right)/2,y:(n.top+n.bottom)/2}}function S(e,n,o="none"){const{x:a=1,y:i=1,focalPoint:c=w(e)}="number"==typeof n?{x:n,y:n}:n,r=u(e),{options:{limits:m,zoom:d}}=r,{mode:f="xy",overScaleMode:h}=d||{};M(e,r);const p=1!==a&&l(f,"x",e),x=1!==i&&l(f,"y",e),g=h&&s(h,c,e);t.each(g||e.scales,(function(e){e.isHorizontal()&&p?k(e,a,c,m):!e.isHorizontal()&&x&&k(e,i,c,m)})),e.update(o),t.callback(d.onZoom,[{chart:e}])}function P(e,n,t){const o=e.getValueForPixel(n),a=e.g
|