forked from chartjs/chartjs-plugin-zoom
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChart.Zoom.min.js
More file actions
10 lines (10 loc) · 5.74 KB
/
Chart.Zoom.min.js
File metadata and controls
10 lines (10 loc) · 5.74 KB
1
2
3
4
5
6
7
8
9
10
/*!
* Chart.Zoom.js
* http://chartjs.org/
* Version: 0.2.0
*
* Copyright 2016 Evert Timberg
* Released under the MIT license
* https://github.com/chartjs/Chart.Zoom.js/blob/master/LICENSE.md
*/
!function e(t,n,o){function a(r,l){if(!n[r]){if(!t[r]){var u="function"==typeof require&&require;if(!l&&u)return u(r,!0);if(i)return i(r,!0);var s=new Error("Cannot find module '"+r+"'");throw s.code="MODULE_NOT_FOUND",s}var c=n[r]={exports:{}};t[r][0].call(c.exports,function(e){var n=t[r][1][e];return a(n?n:e)},c,c.exports,e,t,n,o)}return n[r].exports}for(var i="function"==typeof require&&require,r=0;r<o.length;r++)a(o[r]);return a}({1:[function(e,t,n){},{}],2:[function(e,t,n){function o(e,t){return void 0===e||"string"==typeof e&&e.indexOf(t)!==-1}function a(e,t,n){}function i(e,t,n){var o,a,i=e.options;e.isHorizontal()?(o=e.right-e.left,a=(n.x-e.left)/o):(o=e.bottom-e.top,a=(n.y-e.top)/o);var r=1-a,l=o*(t-1),u=l*a,s=l*r;i.time.min=e.getValueForPixel(e.getPixelForValue(e.firstTick)+u),i.time.max=e.getValueForPixel(e.getPixelForValue(e.lastTick)-s)}function r(e,t,n){var o=e.max-e.min,a=o*(t-1),i=e.isHorizontal()?n.x:n.y,r=(e.getValueForPixel(i)-e.min)/o,l=1-r,u=a*r,s=a*l;e.options.ticks.min=e.min+u,e.options.ticks.max=e.max-s}function l(e,t,n){var o=F[e.options.type];o&&o(e,t,n)}function u(e,t,n){var a=e.chartArea;n||(n={x:(a.left+a.right)/2,y:(a.top+a.bottom)/2});var i=e.options.zoom;if(i&&h.getValueOrDefault(i.enabled,y.zoom.enabled)){var r=h.getValueOrDefault(e.options.zoom.mode,y.zoom.mode);h.each(e.scales,function(e,a){e.isHorizontal()&&o(r,"x")?l(e,t,n):o(r,"y")&&l(e,t,n)}),e.update(0)}}function s(e,t,n){var o,a=e.chart.data.labels,i=a.length-1,r=Math.max(e.ticks.length-(e.options.gridLines.offsetGridLines?0:1),1),l=n.speed,u=e.minIndex,s=Math.round(e.width/(r*l));x.panCumulativeDelta+=t,u=x.panCumulativeDelta>s?Math.max(0,u-1):x.panCumulativeDelta<-s?Math.min(i-r+1,u+1):u,x.panCumulativeDelta=u!==e.minIndex?0:x.panCumulativeDelta,o=Math.min(i,u+r-1),e.options.ticks.min=a[u],e.options.ticks.max=a[o]}function c(e,t){var n=e.options;n.time.min=e.getValueForPixel(e.getPixelForValue(e.firstTick)-t),n.time.max=e.getValueForPixel(e.getPixelForValue(e.lastTick)-t)}function m(e,t){var n=e.options.ticks,o=e.start,a=e.end;n.reverse?(n.max=e.getValueForPixel(e.getPixelForValue(o)-t),n.min=e.getValueForPixel(e.getPixelForValue(a)-t)):(n.min=e.getValueForPixel(e.getPixelForValue(o)-t),n.max=e.getValueForPixel(e.getPixelForValue(a)-t))}function d(e,t,n){var o=V[e.options.type];o&&o(e,t,n)}function p(e,t,n){var a=e.options.pan;if(a&&h.getValueOrDefault(a.enabled,y.pan.enabled)){var i=h.getValueOrDefault(e.options.pan.mode,y.pan.mode);a.speed=h.getValueOrDefault(e.options.pan.speed,y.pan.speed),h.each(e.scales,function(e,r){e.isHorizontal()&&o(i,"x")&&0!==t?d(e,t,a):!e.isHorizontal()&&o(i,"y")&&0!==n&&d(e,n)}),e.update(0)}}function f(e){var t=e.scales;for(var n in t){var o=t[n];if(!o.isHorizontal())return o}}var v=e("hammerjs");v="function"==typeof v?v:window.Hammer;var g=e("chart.js");g="function"==typeof g?g:window.Chart;var h=g.helpers,x=g.Zoom=g.Zoom||{},F=x.zoomFunctions=x.zoomFunctions||{},V=x.panFunctions=x.panFunctions||{},y=x.defaults={pan:{enabled:!0,mode:"xy",speed:20,threshold:10},zoom:{enabled:!0,mode:"xy"}};x.zoomFunctions.category=a,x.zoomFunctions.time=i,x.zoomFunctions.linear=r,x.zoomFunctions.logarithmic=r,x.panFunctions.category=s,x.panFunctions.time=c,x.panFunctions.linear=m,x.panFunctions.logarithmic=m,x.panCumulativeDelta=0;var P={afterInit:function(e){h.each(e.scales,function(e){e.originalOptions=JSON.parse(JSON.stringify(e.options))}),e.resetZoom=function(){h.each(e.scales,function(e,t){var n=e.options.time,o=e.options.ticks;n&&(delete n.min,delete n.max),o&&(delete o.min,delete o.max),e.options=h.configMerge(e.options,e.originalOptions)}),h.each(e.data.datasets,function(e,t){e._meta=null}),e.update()}},beforeInit:function(e){var t=e.chart.ctx.canvas,n=e.options,o=h.getValueOrDefault(n.pan?n.pan.threshold:void 0,x.defaults.pan.threshold);if(n.zoom.drag)n.zoom.mode="x",t.addEventListener("mousedown",function(t){e._dragZoomStart=t}),t.addEventListener("mousemove",function(t){e._dragZoomStart&&(e._dragZoomEnd=t,e.update(0)),e.update(0)}),t.addEventListener("mouseup",function(t){if(e._dragZoomStart){var n=e.chartArea,o=f(e),a=e._dragZoomStart,i=Math.min(a.x,t.x),r=Math.max(a.x,t.x),l=r-i,s=n.right-n.left,c=1+(s-l)/s;l>0&&u(e,c,{x:l/2+i,y:(o.bottom-o.top)/2}),e._dragZoomStart=null,e._dragZoomEnd=null}});else{var a=function(t){var n=t.target.getBoundingClientRect(),o=t.clientX-n.left,a=t.clientY-n.top,i={x:o,y:a};t.deltaY<0?u(e,1.1,i):u(e,.909,i)};e._wheelHandler=a,t.addEventListener("wheel",a)}if(v){var i=new v.Manager(t);i.add(new v.Pinch),i.add(new v.Pan({threshold:o}));var r,l=function(t){var n=1/r*t.scale;u(e,n,t.center),r=t.scale};i.on("pinchstart",function(e){r=1}),i.on("pinch",l),i.on("pinchend",function(e){l(e),r=null});var s=null,c=null,m=function(t){if(null!==s&&null!==c){var n=t.deltaX-s,o=t.deltaY-c;s=t.deltaX,c=t.deltaY,p(e,n,o)}};i.on("panstart",function(e){s=0,c=0,m(e)}),i.on("panmove",m),i.on("panend",function(e){s=null,c=null,x.panCumulativeDelta=0}),e._mc=i}},beforeDatasetsDraw:function(e){var t=e.chart.ctx,n=e.chartArea;if(t.save(),t.beginPath(),e._dragZoomEnd){var o=f(e),a=e._dragZoomStart,i=e._dragZoomEnd,r=Math.min(a.x,i.x),l=Math.max(a.x,i.x),u=l-r;t.fillStyle="rgba(225,225,225,0.3)",t.lineWidth=5,t.fillRect(r,o.top,u,o.bottom-o.top)}t.rect(n.left,n.top,n.right-n.left,n.bottom-n.top),t.clip()},afterDatasetsDraw:function(e){e.chart.ctx.restore()},destroy:function(e){var t=e.chart.ctx.canvas;t.removeEventListener("wheel",e._wheelHandler);var n=e._mc;n&&(n.remove("pinchstart"),n.remove("pinch"),n.remove("pinchend"),n.remove("panstart"),n.remove("pan"),n.remove("panend"))}};g.pluginService.register(P)},{"chart.js":1,hammerjs:1}]},{},[2]);