From f657435b55bdc7255f2457903fa697eb29b66817 Mon Sep 17 00:00:00 2001 From: Evert Timberg Date: Sun, 12 Jun 2016 13:45:02 -0400 Subject: [PATCH] 0.1.3 release --- Chart.Zoom.js | 65 ++++++++++++++++++++++++++++------------------- Chart.Zoom.min.js | 4 +-- package.json | 4 +-- 3 files changed, 43 insertions(+), 30 deletions(-) diff --git a/Chart.Zoom.js b/Chart.Zoom.js index 6a623939..261d0738 100644 --- a/Chart.Zoom.js +++ b/Chart.Zoom.js @@ -1,7 +1,7 @@ /*! * Chart.Zoom.js * http://chartjs.org/ - * Version: 0.1.2 + * Version: 0.1.3 * * Copyright 2016 Evert Timberg * Released under the MIT license @@ -20,14 +20,14 @@ Chart = typeof(Chart) === 'function' ? Chart : window.Chart; var helpers = Chart.helpers; // Take the zoom namespace of Chart -Chart.Zoom = Chart.Zoom || {}; +var zoomNS = Chart.Zoom = Chart.Zoom || {}; // Where we store functions to handle different scale types -var zoomFunctions = Chart.Zoom.zoomFunctions = Chart.Zoom.zoomFunctions || {}; -var panFunctions = Chart.Zoom.panFunctions = Chart.Zoom.panFunctions || {}; +var zoomFunctions = zoomNS.zoomFunctions = zoomNS.zoomFunctions || {}; +var panFunctions = zoomNS.panFunctions = zoomNS.panFunctions || {}; // Default options if none are provided -var defaultOptions = Chart.Zoom.defaults = { +var defaultOptions = zoomNS.defaults = { pan: { enabled: true, mode: 'xy', @@ -93,7 +93,7 @@ function doZoom(chartInstance, zoom, center) { center = { x: (ca.left + ca.right) / 2, y: (ca.top + ca.bottom) / 2, - } + }; } var zoomOptions = chartInstance.options.zoom; @@ -133,16 +133,16 @@ function panTimeScale(scale, delta) { } function panNumericalScale(scale, delta) { - var options = scale.options; + var tickOpts = scale.options.ticks; var start = scale.start, end = scale.end; - if (options.ticks.reverse) { - options.ticks.max = scale.getValueForPixel(scale.getPixelForValue(start) - delta); - options.ticks.min = scale.getValueForPixel(scale.getPixelForValue(end) - delta); + if (tickOpts.reverse) { + tickOpts.max = scale.getValueForPixel(scale.getPixelForValue(start) - delta); + tickOpts.min = scale.getValueForPixel(scale.getPixelForValue(end) - delta); } else { - options.ticks.min = scale.getValueForPixel(scale.getPixelForValue(start) - delta); - options.ticks.max = scale.getValueForPixel(scale.getPixelForValue(end) - delta); + tickOpts.min = scale.getValueForPixel(scale.getPixelForValue(start) - delta); + tickOpts.max = scale.getValueForPixel(scale.getPixelForValue(end) - delta); } } @@ -176,24 +176,24 @@ function positionInChartArea(chartInstance, position) { } // Store these for later -Chart.Zoom.zoomFunctions['category'] = zoomIndexScale; -Chart.Zoom.zoomFunctions['time'] = zoomTimeScale; -Chart.Zoom.zoomFunctions['linear'] = zoomNumericalScale; -Chart.Zoom.zoomFunctions['logarithmic'] = zoomNumericalScale; -Chart.Zoom.panFunctions['category'] = panIndexScale; -Chart.Zoom.panFunctions['time'] = panTimeScale; -Chart.Zoom.panFunctions['linear'] = panNumericalScale; -Chart.Zoom.panFunctions['logarithmic'] = panNumericalScale; +zoomNS.zoomFunctions.category = zoomIndexScale; +zoomNS.zoomFunctions.time = zoomTimeScale; +zoomNS.zoomFunctions.linear = zoomNumericalScale; +zoomNS.zoomFunctions.logarithmic = zoomNumericalScale; +zoomNS.panFunctions.category = panIndexScale; +zoomNS.panFunctions.time = panTimeScale; +zoomNS.panFunctions.linear = panNumericalScale; +zoomNS.panFunctions.logarithmic = panNumericalScale; // Chartjs Zoom Plugin -var ZoomPlugin = Chart.PluginBase.extend({ +var zoomPlugin = { beforeInit: function(chartInstance) { var node = chartInstance.chart.ctx.canvas; var options = chartInstance.options; - var panThreshold = helpers.getValueOrDefault(options.pan ? options.pan.threshold : undefined, Chart.Zoom.defaults.pan.threshold); + var panThreshold = helpers.getValueOrDefault(options.pan ? options.pan.threshold : undefined, zoomNS.defaults.pan.threshold); var wheelHandler = function(e) { - if (e.wheelDelta > 0) { + if (e.deltaY < 0) { doZoom(chartInstance, 1.1); } else { doZoom(chartInstance, 0.909); @@ -201,7 +201,7 @@ var ZoomPlugin = Chart.PluginBase.extend({ }; chartInstance._wheelHandler = wheelHandler; - node.addEventListener('mousewheel', wheelHandler); + node.addEventListener('wheel', wheelHandler); if (Hammer) { var mc = new Hammer.Manager(node); @@ -255,6 +255,19 @@ var ZoomPlugin = Chart.PluginBase.extend({ } }, + beforeDatasetsDraw: function(chartInstance) { + var ctx = chartInstance.chart.ctx; + var chartArea = chartInstance.chartArea; + ctx.save(); + ctx.beginPath(); + ctx.rect(chartArea.left, chartArea.top, chartArea.right - chartArea.left, chartArea.bottom - chartArea.top); + ctx.clip(); + }, + + afterDatasetsDraw: function(chartInstance) { + chartInstance.chart.ctx.restore(); + }, + destroy: function(chartInstance) { var node = chartInstance.chart.ctx.canvas; @@ -268,8 +281,8 @@ var ZoomPlugin = Chart.PluginBase.extend({ mc.remove('panend'); } } -}); +}; -Chart.pluginService.register(new ZoomPlugin()); +Chart.pluginService.register(zoomPlugin); },{"chart.js":1,"hammerjs":1}]},{},[2]); diff --git a/Chart.Zoom.min.js b/Chart.Zoom.min.js index af9810f3..5fc472f6 100644 --- a/Chart.Zoom.min.js +++ b/Chart.Zoom.min.js @@ -1,10 +1,10 @@ /*! * Chart.Zoom.js * http://chartjs.org/ - * Version: 0.1.2 + * Version: 0.1.3 * * Copyright 2016 Evert Timberg * Released under the MIT license * https://github.com/chartjs/Chart.Zoom.js/blob/master/LICENSE.md */ -!function o(e,n,t){function i(r,l){if(!n[r]){if(!e[r]){var u="function"==typeof require&&require;if(!l&&u)return u(r,!0);if(a)return a(r,!0);var c=new Error("Cannot find module '"+r+"'");throw c.code="MODULE_NOT_FOUND",c}var m=n[r]={exports:{}};e[r][0].call(m.exports,function(o){var n=e[r][1][o];return i(n?n:o)},m,m.exports,o,e,n,t)}return n[r].exports}for(var a="function"==typeof require&&require,r=0;r0?u(o,1.1):u(o,.909)};if(o._wheelHandler=i,e.addEventListener("mousewheel",i),d){var a=new d.Manager(e);a.add(new d.Pinch),a.add(new d.Pan({threshold:t}));var r,l=function(e){var n=1/r*e.scale;u(o,n,e.center),r=e.scale};a.on("pinchstart",function(o){r=1}),a.on("pinch",l),a.on("pinchend",function(o){l(o),r=null});var c=null,m=null,s=function(e){if(null!==c&&null!==m){var n=e.deltaX-c,t=e.deltaY-m;c=e.deltaX,m=e.deltaY,p(o,n,t)}};a.on("panstart",function(o){c=0,m=0,s(o)}),a.on("panmove",s),a.on("panend",function(o){c=null,m=null}),o._mc=a}},destroy:function(o){var e=(o.chart.ctx.canvas,o._mc);e&&(e.remove("pinchstart"),e.remove("pinch"),e.remove("pinchend"),e.remove("panstart"),e.remove("pan"),e.remove("panend"))}});v.pluginService.register(new V)},{"chart.js":1,hammerjs:1}]},{},[2]); \ No newline at end of file +!function e(n,t,o){function a(r,l){if(!t[r]){if(!n[r]){var u="function"==typeof require&&require;if(!l&&u)return u(r,!0);if(i)return i(r,!0);var c=new Error("Cannot find module '"+r+"'");throw c.code="MODULE_NOT_FOUND",c}var s=t[r]={exports:{}};n[r][0].call(s.exports,function(e){var t=n[r][1][e];return a(t?t:e)},s,s.exports,e,n,t,o)}return t[r].exports}for(var i="function"==typeof require&&require,r=0;r