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