TCVis/public/chartjs-plugin-zoom.min.js

10 lines
8.2 KiB
JavaScript

/*!
* chartjs-plugin-zoom
* http://chartjs.org/
* Version: 0.6.6
*
* Copyright 2016 Evert Timberg
* Released under the MIT license
* https://github.com/chartjs/chartjs-plugin-zoom/blob/master/LICENSE.md
*/
!function(){function e(o,t,n){function a(r,l){if(!t[r]){if(!o[r]){var m="function"==typeof require&&require;if(!l&&m)return m(r,!0);if(i)return i(r,!0);var s=new Error("Cannot find module '"+r+"'");throw s.code="MODULE_NOT_FOUND",s}var u=t[r]={exports:{}};o[r][0].call(u.exports,function(e){var t=o[r][1][e];return a(t||e)},u,u.exports,e,o,t,n)}return t[r].exports}for(var i="function"==typeof require&&require,r=0;r<n.length;r++)a(n[r]);return a}return e}()({1:[function(e,o,t){},{}],2:[function(e,o,t){function n(e,o){return void 0===e||"string"==typeof e&&e.indexOf(o)!==-1}function a(e,o){if(e.scaleAxes&&e.rangeMax&&!z.isNullOrUndef(e.rangeMax[e.scaleAxes])){var t=e.rangeMax[e.scaleAxes];o>t&&(o=t)}return o}function i(e,o){if(e.scaleAxes&&e.rangeMin&&!z.isNullOrUndef(e.rangeMin[e.scaleAxes])){var t=e.rangeMin[e.scaleAxes];o<t&&(o=t)}return o}function r(e,o,t,n){var r=e.chart.data.labels,l=e.minIndex,m=r.length-1,s=e.maxIndex,u=n.sensitivity,c=e.isHorizontal()?e.left+e.width/2:e.top+e.height/2,d=e.isHorizontal()?t.x:t.y;y.zoomCumulativeDelta=o>1?y.zoomCumulativeDelta+1:y.zoomCumulativeDelta-1,Math.abs(y.zoomCumulativeDelta)>u&&(y.zoomCumulativeDelta<0?(d>=c?l<=0?s=Math.min(m,s+1):l=Math.max(0,l-1):d<c&&(s>=m?l=Math.max(0,l-1):s=Math.min(m,s+1)),y.zoomCumulativeDelta=0):y.zoomCumulativeDelta>0&&(d>=c?l=l<s?l=Math.min(s,l+1):l:d<c&&(s=s>l?s=Math.max(l,s-1):s),y.zoomCumulativeDelta=0),e.options.ticks.min=i(n,r[l]),e.options.ticks.max=a(n,r[s]))}function l(e,o,t,n){var r,l,m=e.options;e.isHorizontal()?(r=e.right-e.left,l=(t.x-e.left)/r):(r=e.bottom-e.top,l=(t.y-e.top)/r);var s=1-l,u=r*(o-1),c=u*l,d=u*s,p=e.getValueForPixel(e.getPixelForValue(e.min)+c),f=e.getValueForPixel(e.getPixelForValue(e.max)-d),v=f.diff(p),x=i(n,v)!=v,g=a(n,v)!=v;x||g||(m.time.min=p,m.time.max=f)}function m(e,o,t,n){var r=e.max-e.min,l=r*(o-1),m=e.isHorizontal()?t.x:t.y,s=(e.getValueForPixel(m)-e.min)/r,u=1-s,c=l*s,d=l*u;e.options.ticks.min=i(n,e.min+c),e.options.ticks.max=a(n,e.max-d)}function s(e,o,t,n){var a=D[e.options.type];a&&a(e,o,t,n)}function u(e,o,t,a){var i=e.chartArea;t||(t={x:(i.left+i.right)/2,y:(i.top+i.bottom)/2});var r=e.options.zoom;if(r&&z.getValueOrDefault(r.enabled,_.zoom.enabled)){var l=z.getValueOrDefault(e.options.zoom.mode,_.zoom.mode);r.sensitivity=z.getValueOrDefault(e.options.zoom.sensitivity,_.zoom.sensitivity);var m;m="xy"==l&&void 0!==a?a:"xy",z.each(e.scales,function(e,a){e.isHorizontal()&&n(l,"x")&&n(m,"x")?(r.scaleAxes="x",s(e,o,t,r)):!e.isHorizontal()&&n(l,"y")&&n(m,"y")&&(r.scaleAxes="y",s(e,o,t,r))}),e.update(0),"function"==typeof r.onZoom&&r.onZoom()}}function c(e,o,t){var n,r=e.chart.data.labels,l=r.length-1,m=Math.max(e.ticks.length-(e.options.gridLines.offsetGridLines?0:1),1),s=t.speed,u=e.minIndex,c=Math.round(e.width/(m*s));y.panCumulativeDelta+=o,u=y.panCumulativeDelta>c?Math.max(0,u-1):y.panCumulativeDelta<-c?Math.min(l-m+1,u+1):u,y.panCumulativeDelta=u!==e.minIndex?0:y.panCumulativeDelta,n=Math.min(l,u+m-1),e.options.ticks.min=i(t,r[u]),e.options.ticks.max=a(t,r[n])}function d(e,o,t){var n=e.options,r=a(t,e.getValueForPixel(e.getPixelForValue(e.max)-o)),l=i(t,e.getValueForPixel(e.getPixelForValue(e.min)-o)),m=o<0?r-e.max:l-e.min;n.time.max=e.max+m,n.time.min=e.min+m}function p(e,o,t){var n=e.options.ticks,r=e.start,l=e.end;n.reverse?(n.max=e.getValueForPixel(e.getPixelForValue(r)-o),n.min=e.getValueForPixel(e.getPixelForValue(l)-o)):(n.min=e.getValueForPixel(e.getPixelForValue(r)-o),n.max=e.getValueForPixel(e.getPixelForValue(l)-o)),n.min=i(t,n.min),n.max=a(t,n.max)}function f(e,o,t){var n=F[e.options.type];n&&n(e,o,t)}function v(e,o,t){var a=e.options.pan;if(a&&z.getValueOrDefault(a.enabled,_.pan.enabled)){var i=z.getValueOrDefault(e.options.pan.mode,_.pan.mode);a.speed=z.getValueOrDefault(e.options.pan.speed,_.pan.speed),z.each(e.scales,function(e,r){e.isHorizontal()&&n(i,"x")&&0!==o?(a.scaleAxes="x",f(e,o,a)):!e.isHorizontal()&&n(i,"y")&&0!==t&&(a.scaleAxes="y",f(e,t,a))}),e.update(0),"function"==typeof a.onPan&&a.onPan()}}function x(e){var o=e.scales;for(var t in o){var n=o[t];if(!n.isHorizontal())return n}}var g=e("hammerjs");g="function"==typeof g?g:window.Hammer;var h=e("chart.js");h="function"==typeof h?h:window.Chart;var z=h.helpers,y=h.Zoom=h.Zoom||{},D=y.zoomFunctions=y.zoomFunctions||{},F=y.panFunctions=y.panFunctions||{},_=y.defaults={pan:{enabled:!0,mode:"xy",speed:20,threshold:10},zoom:{enabled:!0,mode:"xy",sensitivity:3}};y.zoomFunctions.category=r,y.zoomFunctions.time=l,y.zoomFunctions.linear=m,y.zoomFunctions.logarithmic=m,y.panFunctions.category=c,y.panFunctions.time=d,y.panFunctions.linear=p,y.panFunctions.logarithmic=p,y.panCumulativeDelta=0,y.zoomCumulativeDelta=0;var M={id:"zoom",afterInit:function(e){z.each(e.scales,function(e){e.originalOptions=z.clone(e.options)}),e.resetZoom=function(){z.each(e.scales,function(e,o){var t=e.options.time,n=e.options.ticks;t&&(t.min=e.originalOptions.time.min,t.max=e.originalOptions.time.max),n&&(n.min=e.originalOptions.ticks.min,n.max=e.originalOptions.ticks.max)}),z.each(e.data.datasets,function(e,o){e._meta=null}),e.update()}},beforeInit:function(e){e.zoom={};var o=e.zoom.node=e.chart.ctx.canvas,t=e.options,n=z.getValueOrDefault(t.pan?t.pan.threshold:void 0,y.defaults.pan.threshold);if(t.zoom&&t.zoom.enabled&&(t.zoom.drag?(t.zoom.mode="x",e.zoom._mouseDownHandler=function(o){e.zoom._dragZoomStart=o},o.addEventListener("mousedown",e.zoom._mouseDownHandler),e.zoom._mouseMoveHandler=function(o){e.zoom._dragZoomStart&&(e.zoom._dragZoomEnd=o,e.update(0))},o.addEventListener("mousemove",e.zoom._mouseMoveHandler),e.zoom._mouseUpHandler=function(o){if(e.zoom._dragZoomStart){var t=e.chartArea,n=x(e),a=e.zoom._dragZoomStart,i=a.target.getBoundingClientRect().left,r=Math.min(a.clientX,o.clientX)-i,l=Math.max(a.clientX,o.clientX)-i,m=l-r,s=t.right-t.left,c=1+(s-m)/s;e.zoom._dragZoomStart=null,e.zoom._dragZoomEnd=null,m>0&&u(e,c,{x:m/2+r,y:(n.bottom-n.top)/2})}},o.addEventListener("mouseup",e.zoom._mouseUpHandler)):(e.zoom._wheelHandler=function(o){var t=o.target.getBoundingClientRect(),n=o.clientX-t.left,a=o.clientY-t.top,i={x:n,y:a};o.deltaY<0?u(e,1.1,i):u(e,.909,i),o.preventDefault()},o.addEventListener("wheel",e.zoom._wheelHandler)),g)){var a=new g.Manager(o);a.add(new g.Pinch),a.add(new g.Pan({threshold:n}));var i,r=function(o){var t,n=1/i*o.scale,a=o.target.getBoundingClientRect(),r=o.center.x-a.left,l=o.center.y-a.top,m={x:r,y:l},s=Math.abs(o.pointers[0].clientX-o.pointers[1].clientX),c=Math.abs(o.pointers[0].clientY-o.pointers[1].clientY),d=s/c;t=d>.3&&d<1.7?"xy":s>c?"x":"y",u(e,n,m,t),i=o.scale};a.on("pinchstart",function(e){i=1}),a.on("pinch",r),a.on("pinchend",function(e){r(e),i=null,y.zoomCumulativeDelta=0});var l=null,m=null,s=!1,c=function(o){if(null!==l&&null!==m){s=!0;var t=o.deltaX-l,n=o.deltaY-m;l=o.deltaX,m=o.deltaY,v(e,t,n)}};a.on("panstart",function(e){l=0,m=0,c(e)}),a.on("panmove",c),a.on("panend",function(e){l=null,m=null,y.panCumulativeDelta=0,setTimeout(function(){s=!1},500)}),e.zoom._ghostClickHandler=function(e){s&&(e.stopImmediatePropagation(),e.preventDefault())},o.addEventListener("click",e.zoom._ghostClickHandler),e._mc=a}},beforeDatasetsDraw:function(e){var o=e.chart.ctx,t=e.chartArea;if(o.save(),o.beginPath(),e.zoom._dragZoomEnd){var n=x(e),a=e.zoom._dragZoomStart,i=e.zoom._dragZoomEnd,r=a.target.getBoundingClientRect().left,l=Math.min(a.clientX,i.clientX)-r,m=Math.max(a.clientX,i.clientX)-r,s=m-l;o.fillStyle="rgba(225,225,225,0.3)",o.lineWidth=5,o.fillRect(l,n.top,s,n.bottom-n.top)}o.rect(t.left,t.top,t.right-t.left,t.bottom-t.top),o.clip()},afterDatasetsDraw:function(e){e.chart.ctx.restore()},destroy:function(e){if(e.zoom){var o=e.options,t=e.zoom.node;o.zoom&&o.zoom.drag?(t.removeEventListener("mousedown",e.zoom._mouseDownHandler),t.removeEventListener("mousemove",e.zoom._mouseMoveHandler),t.removeEventListener("mouseup",e.zoom._mouseUpHandler)):t.removeEventListener("wheel",e.zoom._wheelHandler),g&&t.removeEventListener("click",e.zoom._ghostClickHandler),delete e.zoom;var n=e._mc;n&&(n.remove("pinchstart"),n.remove("pinch"),n.remove("pinchend"),n.remove("panstart"),n.remove("pan"),n.remove("panend"))}}};o.exports=M,h.pluginService.register(M)},{"chart.js":1,hammerjs:1}]},{},[2]);