From 48a521c5863a9bb44bf9392a793016b69838e483 Mon Sep 17 00:00:00 2001 From: hansmaad Date: Mon, 3 Apr 2017 08:27:30 +0200 Subject: [PATCH] Version bump to v0.4.0 --- dist/chartist-plugin-zoom.js | 454 ++++++++++++++------------- dist/chartist-plugin-zoom.min.js | 2 +- dist/chartist-plugin-zoom.min.js.map | 2 +- package.json | 2 +- 4 files changed, 240 insertions(+), 220 deletions(-) diff --git a/dist/chartist-plugin-zoom.js b/dist/chartist-plugin-zoom.js index ee83fe8..920071b 100644 --- a/dist/chartist-plugin-zoom.js +++ b/dist/chartist-plugin-zoom.js @@ -14,278 +14,298 @@ } }(this, function () { - /** - * Chartist.js zoom plugin. - * - */ - (function (window, document, Chartist) { + (function (root, factory) { 'use strict'; - var defaultOptions = { - // onZoom - // resetOnRightMouseBtn - pointClipOffset: 5 - }; + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['chartist'], function (Chartist) { + return (root.returnExportsGlobal = factory(Chartist)); + }); + } else if (typeof exports === 'object') { + // Node. Does not work with strict CommonJS, but + // only CommonJS-like enviroments that support module.exports, + // like Node. + module.exports = factory(require('chartist')); + } else { + root['Chartist.plugins.zoom'] = factory(Chartist); + } + }(this, function (Chartist) { + 'use strict'; + /** + * Chartist.js zoom plugin. + * + */ + (function (window, document, Chartist) { + + var defaultOptions = { + // onZoom + // resetOnRightMouseBtn + pointClipOffset: 5 + }; + Chartist.plugins = Chartist.plugins || {}; + Chartist.plugins.zoom = function (options) { - Chartist.plugins = Chartist.plugins || {}; - Chartist.plugins.zoom = function (options) { + options = Chartist.extend({}, defaultOptions, options); - options = Chartist.extend({}, defaultOptions, options); + return function zoom(chart) { - return function zoom(chart) { + if (!(chart instanceof Chartist.Line)) { + return; + } - if (!(chart instanceof Chartist.Line)) { - return; - } + var rect, svg, axisX, axisY, chartRect; + var downPosition; + var onZoom = options.onZoom; + var ongoingTouches = []; - var rect, svg, axisX, axisY, chartRect; - var downPosition; - var onZoom = options.onZoom; - var ongoingTouches = []; + chart.on('draw', function (data) { + var type = data.type; + var mask = type === 'point' ? 'point-mask' : 'line-mask'; + if (type === 'line' || type === 'bar' || type === 'area' || type === 'point') { + data.element.attr({ 'clip-path': 'url(#' + mask + ')' }); + } + }); + + chart.on('created', function (data) { + axisX = data.axisX; + axisY = data.axisY; + chartRect = data.chartRect; + svg = data.svg._node; + rect = data.svg.elem('rect', { + x: 10, + y: 10, + width: 100, + height: 100, + }, 'ct-zoom-rect'); + hide(rect); - chart.on('draw', function (data) { - var type = data.type; - var mask = type === 'point' ? 'point-mask' : 'line-mask'; - if (type === 'line' || type === 'bar' || type === 'area' || type === 'point') { - data.element.attr({ 'clip-path': 'url(#' + mask + ')' }); - } - }); - - chart.on('created', function (data) { - axisX = data.axisX; - axisY = data.axisY; - chartRect = data.chartRect; - svg = data.svg._node; - rect = data.svg.elem('rect', { - x: 10, - y: 10, - width: 100, - height: 100, - }, 'ct-zoom-rect'); - hide(rect); - - var defs = data.svg.querySelector('defs') || data.svg.elem('defs'); - var width = chartRect.width(); - var height = chartRect.height(); - - function addMask(id, offset) { - defs - .elem('clipPath', { - id: id - }) - .elem('rect', { - x: chartRect.x1 - offset, - y: chartRect.y2 - offset, - width: width + offset + offset, - height: height + offset + offset, - fill: 'white' - }); - } - addMask('line-mask', 0); - addMask('point-mask', options.pointClipOffset); + var defs = data.svg.querySelector('defs') || data.svg.elem('defs'); + var width = chartRect.width(); + var height = chartRect.height(); + + function addMask(id, offset) { + defs + .elem('clipPath', { + id: id + }) + .elem('rect', { + x: chartRect.x1 - offset, + y: chartRect.y2 - offset, + width: width + offset + offset, + height: height + offset + offset, + fill: 'white' + }); + } + addMask('line-mask', 0); + addMask('point-mask', options.pointClipOffset); - function on(event, handler) { - svg.addEventListener(event, handler); - } + function on(event, handler) { + svg.addEventListener(event, handler); + } - on('mousedown', onMouseDown); - on('mouseup', onMouseUp); - on('mousemove', onMouseMove); - on('touchstart', onTouchStart); - on('touchmove', onTouchMove); - on('touchend', onTouchEnd); - on('touchcancel', onTouchCancel); - }); + on('mousedown', onMouseDown); + on('mouseup', onMouseUp); + on('mousemove', onMouseMove); + on('touchstart', onTouchStart); + on('touchmove', onTouchMove); + on('touchend', onTouchEnd); + on('touchcancel', onTouchCancel); + }); - function copyTouch(touch) { - var p = position(touch, svg); - p.id = touch.identifier; - return p; - } + function copyTouch(touch) { + var p = position(touch, svg); + p.id = touch.identifier; + return p; + } - function ongoingTouchIndexById(idToFind) { - for (var i = 0; i < ongoingTouches.length; i++) { - var id = ongoingTouches[i].id; - if (id === idToFind) { - return i; + function ongoingTouchIndexById(idToFind) { + for (var i = 0; i < ongoingTouches.length; i++) { + var id = ongoingTouches[i].id; + if (id === idToFind) { + return i; + } } + return -1; } - return -1; - } - function onTouchStart(event) { - var touches = event.changedTouches; - for (var i = 0; i < touches.length; i++) { - ongoingTouches.push(copyTouch(touches[i])); + function onTouchStart(event) { + var touches = event.changedTouches; + for (var i = 0; i < touches.length; i++) { + ongoingTouches.push(copyTouch(touches[i])); + } + + if (ongoingTouches.length > 1) { + rect.attr(getRect(ongoingTouches[0], ongoingTouches[1])); + show(rect); + } } - if (ongoingTouches.length > 1) { - rect.attr(getRect(ongoingTouches[0], ongoingTouches[1])); - show(rect); + function onTouchMove(event) { + var touches = event.changedTouches; + for (var i = 0; i < touches.length; i++) { + var idx = ongoingTouchIndexById(touches[i].identifier); + ongoingTouches.splice(idx, 1, copyTouch(touches[i])); + } + + if (ongoingTouches.length > 1) { + rect.attr(getRect(ongoingTouches[0], ongoingTouches[1])); + show(rect); + event.preventDefault(); + } } - } - function onTouchMove(event) { - var touches = event.changedTouches; - for (var i = 0; i < touches.length; i++) { - var idx = ongoingTouchIndexById(touches[i].identifier); - ongoingTouches.splice(idx, 1, copyTouch(touches[i])); + function onTouchCancel(event) { + removeTouches(event.changedTouches); } - if (ongoingTouches.length > 1) { - rect.attr(getRect(ongoingTouches[0], ongoingTouches[1])); - show(rect); - event.preventDefault(); + function removeTouches(touches) { + for (var i = 0; i < touches.length; i++) { + var idx = ongoingTouchIndexById(touches[i].identifier); + if (idx >= 0) { + ongoingTouches.splice(idx, 1); + } + } } - } - function onTouchCancel(event) { - removeTouches(event.changedTouches); - } + function onTouchEnd(event) { + if (ongoingTouches.length > 1) { + zoomIn(getRect(ongoingTouches[0], ongoingTouches[1])); + } + removeTouches(event.changedTouches); + hide(rect); + } - function removeTouches(touches) { - for (var i = 0; i < touches.length; i++) { - var idx = ongoingTouchIndexById(touches[i].identifier); - if (idx >= 0) { - ongoingTouches.splice(idx, 1); + function onMouseDown(event) { + if (event.button === 0) { + var point = position(event, svg); + if (isInRect(point, chartRect)) { + downPosition = point; + rect.attr(getRect(downPosition, downPosition)); + show(rect); + event.preventDefault(); + } } } - } - function onTouchEnd(event) { - if (ongoingTouches.length > 1) { - zoomIn(getRect(ongoingTouches[0], ongoingTouches[1])); + function isInRect(point, rect) { + return point.x >= rect.x1 && point.x <= rect.x2 && point.y >= rect.y2 && point.y <= rect.y1; } - removeTouches(event.changedTouches); - hide(rect); - } - function onMouseDown(event) { - if (event.button === 0) { - var point = position(event, svg); - if (isInRect(point, chartRect)) { - downPosition = point; - rect.attr(getRect(downPosition, downPosition)); - show(rect); + var reset = function () { + chart.options.axisX.highLow = null; + chart.options.axisY.highLow = null; + chart.update(chart.data, chart.options); + }; + + function onMouseUp(event) { + if (event.button === 0 && downPosition) { + var box = getRect(downPosition, position(event, svg)); + zoomIn(box); + downPosition = null; + hide(rect); + } + else if (options.resetOnRightMouseBtn && event.button === 2) { + reset(); event.preventDefault(); } } - } - function isInRect(point, rect) { - return point.x >= rect.x1 && point.x <= rect.x2 && point.y >= rect.y2 && point.y <= rect.y1; - } + function zoomIn(rect) { + if (rect.width > 5 && rect.height > 5) { + var x1 = Math.max(0, rect.x - chartRect.x1); + var x2 = Math.min(chartRect.width(), x1 + rect.width); + var y2 = Math.min(chartRect.height(), chartRect.y1 - rect.y); + var y1 = Math.max(0, y2 - rect.height); - var reset = function () { - chart.options.axisX.highLow = null; - chart.options.axisY.highLow = null; - chart.update(chart.data, chart.options); - }; + chart.options.axisX.highLow = { low: project(x1, axisX), high: project(x2, axisX) }; + chart.options.axisY.highLow = { low: project(y1, axisY), high: project(y2, axisY) }; - function onMouseUp(event) { - if (event.button === 0 && downPosition) { - var box = getRect(downPosition, position(event, svg)); - zoomIn(box); - downPosition = null; - hide(rect); - } - else if (options.resetOnRightMouseBtn && event.button === 2) { - reset(); - event.preventDefault(); + chart.update(chart.data, chart.options); + onZoom && onZoom(chart, reset); + } } - } - - function zoomIn(rect) { - if (rect.width > 5 && rect.height > 5) { - var x1 = Math.max(0, rect.x - chartRect.x1); - var x2 = Math.min(chartRect.width(), x1 + rect.width); - var y2 = Math.min(chartRect.height(), chartRect.y1 - rect.y); - var y1 = Math.max(0, y2 - rect.height); - chart.options.axisX.highLow = { low: project(x1, axisX), high: project(x2, axisX) }; - chart.options.axisY.highLow = { low: project(y1, axisY), high: project(y2, axisY) }; - - chart.update(chart.data, chart.options); - onZoom && onZoom(chart, reset); - } - } - - function onMouseMove(event) { - if (downPosition) { - var point = position(event, svg); - if (isInRect(point, chartRect)) { - rect.attr(getRect(downPosition, point)); - event.preventDefault(); + function onMouseMove(event) { + if (downPosition) { + var point = position(event, svg); + if (isInRect(point, chartRect)) { + rect.attr(getRect(downPosition, point)); + event.preventDefault(); + } } } - } - }; + }; - }; + }; - function hide(rect) { - rect.attr({ style: 'display:none' }); - } + function hide(rect) { + rect.attr({ style: 'display:none' }); + } - function show(rect) { - rect.attr({ style: 'display:block' }); - } + function show(rect) { + rect.attr({ style: 'display:block' }); + } - function getRect(firstPoint, secondPoint) { - var x = firstPoint.x; - var y = firstPoint.y; - var width = secondPoint.x - x; - var height = secondPoint.y - y; - if (width < 0) { - width = -width; - x = secondPoint.x; + function getRect(firstPoint, secondPoint) { + var x = firstPoint.x; + var y = firstPoint.y; + var width = secondPoint.x - x; + var height = secondPoint.y - y; + if (width < 0) { + width = -width; + x = secondPoint.x; + } + if (height < 0) { + height = -height; + y = secondPoint.y; + } + return { + x: x, + y: y, + width: width, + height: height + }; } - if (height < 0) { - height = -height; - y = secondPoint.y; + + function position(event, svg) { + return transform(event.clientX, event.clientY, svg); } - return { - x: x, - y: y, - width: width, - height: height - }; - } - function position(event, svg) { - return transform(event.clientX, event.clientY, svg); - } + function transform(x, y, svgElement) { + var svg = svgElement.tagName === 'svg' ? svgElement : svgElement.ownerSVGElement; + var matrix = svg.getScreenCTM(); + var point = svg.createSVGPoint(); + point.x = x; + point.y = y; + point = point.matrixTransform(matrix.inverse()); + return point || { x: 0, y: 0 }; + } - function transform(x, y, svgElement) { - var svg = svgElement.tagName === 'svg' ? svgElement : svgElement.ownerSVGElement; - var matrix = svg.getScreenCTM(); - var point = svg.createSVGPoint(); - point.x = x; - point.y = y; - point = point.matrixTransform(matrix.inverse()); - return point || { x: 0, y: 0 }; - } + function project(value, axis) { + var max = axis.bounds.max; + var min = axis.bounds.min; + if (axis.scale && axis.scale.type === 'log') { + var base = axis.scale.base; + return Math.pow(base, + value * baseLog(max / min, base) / axis.axisLength) * min; + } + return (value * axis.bounds.range / axis.axisLength) + min; + } - function project(value, axis) { - var max = axis.bounds.max; - var min = axis.bounds.min; - if (axis.scale && axis.scale.type === 'log') { - var base = axis.scale.base; - return Math.pow(base, - value * baseLog(max / min, base) / axis.axisLength) * min; + function baseLog(val, base) { + return Math.log(val) / Math.log(base); } - return (value * axis.bounds.range / axis.axisLength) + min; - } - function baseLog(val, base) { - return Math.log(val) / Math.log(base); - } + } (window, document, Chartist)); + - } (window, document, Chartist)); + return Chartist.plugins.tooltips; + })); return Chartist.plugins.zoom; })); diff --git a/dist/chartist-plugin-zoom.min.js b/dist/chartist-plugin-zoom.min.js index 8b4e95c..daac400 100644 --- a/dist/chartist-plugin-zoom.min.js +++ b/dist/chartist-plugin-zoom.min.js @@ -1,2 +1,2 @@ -!function(a,b){"function"==typeof define&&define.amd?define([],function(){return a.returnExportsGlobal=b()}):"object"==typeof exports?module.exports=b():a["Chartist.plugins.zoom"]=b()}(this,function(){return function(a,b,c){"use strict";function d(a){a.attr({style:"display:none"})}function e(a){a.attr({style:"display:block"})}function f(a,b){var c=a.x,d=a.y,e=b.x-c,f=b.y-d;return 0>e&&(e=-e,c=b.x),0>f&&(f=-f,d=b.y),{x:c,y:d,width:e,height:f}}function g(a,b){return h(a.clientX,a.clientY,b)}function h(a,b,c){var d="svg"===c.tagName?c:c.ownerSVGElement,e=d.getScreenCTM(),f=d.createSVGPoint();return f.x=a,f.y=b,f=f.matrixTransform(e.inverse()),f||{x:0,y:0}}function i(a,b){var c=b.bounds.max,d=b.bounds.min;if(b.scale&&"log"===b.scale.type){var e=b.scale.base;return Math.pow(e,a*j(c/d,e)/b.axisLength)*d}return a*b.bounds.range/b.axisLength+d}function j(a,b){return Math.log(a)/Math.log(b)}var k={pointClipOffset:5};c.plugins=c.plugins||{},c.plugins.zoom=function(a){return a=c.extend({},k,a),function(b){function h(a){var b=g(a,v);return b.id=a.identifier,b}function j(a){for(var b=0;b1&&(u.attr(f(B[0],B[1])),e(u))}function l(a){for(var b=a.changedTouches,c=0;c1&&(u.attr(f(B[0],B[1])),e(u),a.preventDefault())}function m(a){n(a.changedTouches)}function n(a){for(var b=0;b=0&&B.splice(c,1)}}function o(a){B.length>1&&s(f(B[0],B[1])),n(a.changedTouches),d(u)}function p(a){if(0===a.button){var b=g(a,v);q(b,y)&&(z=b,u.attr(f(z,z)),e(u),a.preventDefault())}}function q(a,b){return a.x>=b.x1&&a.x<=b.x2&&a.y>=b.y2&&a.y<=b.y1}function r(b){if(0===b.button&&z){var c=f(z,g(b,v));s(c),z=null,d(u)}else a.resetOnRightMouseBtn&&2===b.button&&(C(),b.preventDefault())}function s(a){if(a.width>5&&a.height>5){var c=Math.max(0,a.x-y.x1),d=Math.min(y.width(),c+a.width),e=Math.min(y.height(),y.y1-a.y),f=Math.max(0,e-a.height);b.options.axisX.highLow={low:i(c,w),high:i(d,w)},b.options.axisY.highLow={low:i(f,x),high:i(e,x)},b.update(b.data,b.options),A&&A(b,C)}}function t(a){if(z){var b=g(a,v);q(b,y)&&(u.attr(f(z,b)),a.preventDefault())}}if(b instanceof c.Line){var u,v,w,x,y,z,A=a.onZoom,B=[];b.on("draw",function(a){var b=a.type,c="point"===b?"point-mask":"line-mask";("line"===b||"bar"===b||"area"===b||"point"===b)&&a.element.attr({"clip-path":"url(#"+c+")"})}),b.on("created",function(b){function c(a,b){f.elem("clipPath",{id:a}).elem("rect",{x:y.x1-b,y:y.y2-b,width:g+b+b,height:h+b+b,fill:"white"})}function e(a,b){v.addEventListener(a,b)}w=b.axisX,x=b.axisY,y=b.chartRect,v=b.svg._node,u=b.svg.elem("rect",{x:10,y:10,width:100,height:100},"ct-zoom-rect"),d(u);var f=b.svg.querySelector("defs")||b.svg.elem("defs"),g=y.width(),h=y.height();c("line-mask",0),c("point-mask",a.pointClipOffset),e("mousedown",p),e("mouseup",r),e("mousemove",t),e("touchstart",k),e("touchmove",l),e("touchend",o),e("touchcancel",m)});var C=function(){b.options.axisX.highLow=null,b.options.axisY.highLow=null,b.update(b.data,b.options)}}}}}(window,document,Chartist),Chartist.plugins.zoom}); +!function(a,b){"function"==typeof define&&define.amd?define([],function(){return a.returnExportsGlobal=b()}):"object"==typeof exports?module.exports=b():a["Chartist.plugins.zoom"]=b()}(this,function(){return function(a,b){"use strict";"function"==typeof define&&define.amd?define(["chartist"],function(c){return a.returnExportsGlobal=b(c)}):"object"==typeof exports?module.exports=b(require("chartist")):a["Chartist.plugins.zoom"]=b(Chartist)}(this,function(a){"use strict";return function(a,b,c){function d(a){a.attr({style:"display:none"})}function e(a){a.attr({style:"display:block"})}function f(a,b){var c=a.x,d=a.y,e=b.x-c,f=b.y-d;return 0>e&&(e=-e,c=b.x),0>f&&(f=-f,d=b.y),{x:c,y:d,width:e,height:f}}function g(a,b){return h(a.clientX,a.clientY,b)}function h(a,b,c){var d="svg"===c.tagName?c:c.ownerSVGElement,e=d.getScreenCTM(),f=d.createSVGPoint();return f.x=a,f.y=b,f=f.matrixTransform(e.inverse()),f||{x:0,y:0}}function i(a,b){var c=b.bounds.max,d=b.bounds.min;if(b.scale&&"log"===b.scale.type){var e=b.scale.base;return Math.pow(e,a*j(c/d,e)/b.axisLength)*d}return a*b.bounds.range/b.axisLength+d}function j(a,b){return Math.log(a)/Math.log(b)}var k={pointClipOffset:5};c.plugins=c.plugins||{},c.plugins.zoom=function(a){return a=c.extend({},k,a),function(b){function h(a){var b=g(a,v);return b.id=a.identifier,b}function j(a){for(var b=0;b1&&(u.attr(f(B[0],B[1])),e(u))}function l(a){for(var b=a.changedTouches,c=0;c1&&(u.attr(f(B[0],B[1])),e(u),a.preventDefault())}function m(a){n(a.changedTouches)}function n(a){for(var b=0;b=0&&B.splice(c,1)}}function o(a){B.length>1&&s(f(B[0],B[1])),n(a.changedTouches),d(u)}function p(a){if(0===a.button){var b=g(a,v);q(b,y)&&(z=b,u.attr(f(z,z)),e(u),a.preventDefault())}}function q(a,b){return a.x>=b.x1&&a.x<=b.x2&&a.y>=b.y2&&a.y<=b.y1}function r(b){if(0===b.button&&z){var c=f(z,g(b,v));s(c),z=null,d(u)}else a.resetOnRightMouseBtn&&2===b.button&&(C(),b.preventDefault())}function s(a){if(a.width>5&&a.height>5){var c=Math.max(0,a.x-y.x1),d=Math.min(y.width(),c+a.width),e=Math.min(y.height(),y.y1-a.y),f=Math.max(0,e-a.height);b.options.axisX.highLow={low:i(c,w),high:i(d,w)},b.options.axisY.highLow={low:i(f,x),high:i(e,x)},b.update(b.data,b.options),A&&A(b,C)}}function t(a){if(z){var b=g(a,v);q(b,y)&&(u.attr(f(z,b)),a.preventDefault())}}if(b instanceof c.Line){var u,v,w,x,y,z,A=a.onZoom,B=[];b.on("draw",function(a){var b=a.type,c="point"===b?"point-mask":"line-mask";("line"===b||"bar"===b||"area"===b||"point"===b)&&a.element.attr({"clip-path":"url(#"+c+")"})}),b.on("created",function(b){function c(a,b){f.elem("clipPath",{id:a}).elem("rect",{x:y.x1-b,y:y.y2-b,width:g+b+b,height:h+b+b,fill:"white"})}function e(a,b){v.addEventListener(a,b)}w=b.axisX,x=b.axisY,y=b.chartRect,v=b.svg._node,u=b.svg.elem("rect",{x:10,y:10,width:100,height:100},"ct-zoom-rect"),d(u);var f=b.svg.querySelector("defs")||b.svg.elem("defs"),g=y.width(),h=y.height();c("line-mask",0),c("point-mask",a.pointClipOffset),e("mousedown",p),e("mouseup",r),e("mousemove",t),e("touchstart",k),e("touchmove",l),e("touchend",o),e("touchcancel",m)});var C=function(){b.options.axisX.highLow=null,b.options.axisY.highLow=null,b.update(b.data,b.options)}}}}}(window,document,a),a.plugins.tooltips}),Chartist.plugins.zoom}); //# sourceMappingURL=chartist-plugin-zoom.min.js.map \ No newline at end of file diff --git a/dist/chartist-plugin-zoom.min.js.map b/dist/chartist-plugin-zoom.min.js.map index d76f895..694e821 100644 --- a/dist/chartist-plugin-zoom.min.js.map +++ b/dist/chartist-plugin-zoom.min.js.map @@ -1 +1 @@ -{"version":3,"file":"chartist-plugin-zoom.min.js","sources":["chartist-plugin-zoom.js"],"names":["root","factory","define","amd","returnExportsGlobal","exports","module","this","window","document","Chartist","hide","rect","attr","style","show","getRect","firstPoint","secondPoint","x","y","width","height","position","event","svg","transform","clientX","clientY","svgElement","tagName","ownerSVGElement","matrix","getScreenCTM","point","createSVGPoint","matrixTransform","inverse","project","value","axis","max","bounds","min","scale","type","base","Math","pow","baseLog","axisLength","range","val","log","defaultOptions","pointClipOffset","plugins","zoom","options","extend","chart","copyTouch","touch","p","id","identifier","ongoingTouchIndexById","idToFind","i","ongoingTouches","length","onTouchStart","touches","changedTouches","push","onTouchMove","idx","splice","preventDefault","onTouchCancel","removeTouches","onTouchEnd","zoomIn","onMouseDown","button","isInRect","chartRect","downPosition","x1","x2","y2","y1","onMouseUp","box","resetOnRightMouseBtn","reset","axisX","highLow","low","high","axisY","update","data","onZoom","onMouseMove","Line","on","mask","element","clip-path","addMask","offset","defs","elem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AI6F,cAAc,SAAWhB,EAAK7E,IAAIwF,KAAK,QACvD5F,EAAQiE,EAAUjE,QAClBC,EAASgE,EAAUhE,QAevBwF,GAAQ,YAAa,GACrBA,EAAQ,aAAcpD,EAAQH,iBAM9BmD,EAAG,YAAavB,GAChBuB,EAAG,UAAWd,GACdc,EAAG,YAAaF,GAChBE,EAAG,aAAcnC,GACjBmC,EAAG,YAAa/B,GAChB+B,EAAG,WAAYzB,GACfyB,EAAG,cAAe3B,IAoFpB,IAAIgB,GAAQ,WACVnC,EAAMF,QAAQsC,MAAMC,QAAU,KAC9BrC,EAAMF,QAAQ0C,MAAMH,QAAU,KAC9BrC,EAAMyC,OAAOzC,EAAM0C,KAAM1C,EAAMF,cAsGpClD,OAAQC,SAAUC,UAEdA,SAAS8C,QAAQC","sourcesContent":["(function (root, factory) {\n if (typeof define === 'function' && define.amd) {\n // AMD. Register as an anonymous module.\n define([], function () {\n return (root.returnExportsGlobal = factory());\n });\n } else if (typeof exports === 'object') {\n // Node. Does not work with strict CommonJS, but\n // only CommonJS-like enviroments that support module.exports,\n // like Node.\n module.exports = factory();\n } else {\n root['Chartist.plugins.zoom'] = factory();\n }\n}(this, function () {\n\n /**\r\n * Chartist.js zoom plugin.\r\n *\r\n */\r\n (function (window, document, Chartist) {\r\n 'use strict';\r\n\r\n var defaultOptions = {\r\n // onZoom\r\n // resetOnRightMouseBtn\r\n pointClipOffset: 5\r\n };\r\n\r\n\r\n Chartist.plugins = Chartist.plugins || {};\r\n Chartist.plugins.zoom = function (options) {\r\n\r\n options = Chartist.extend({}, defaultOptions, options);\r\n\r\n return function zoom(chart) {\r\n\r\n if (!(chart instanceof Chartist.Line)) {\r\n return;\r\n }\r\n\r\n var rect, svg, axisX, axisY, chartRect;\r\n var downPosition;\r\n var onZoom = options.onZoom;\r\n var ongoingTouches = [];\r\n\r\n chart.on('draw', function (data) {\r\n var type = data.type;\r\n var mask = type === 'point' ? 'point-mask' : 'line-mask';\r\n if (type === 'line' || type === 'bar' || type === 'area' || type === 'point') {\r\n data.element.attr({ 'clip-path': 'url(#' + mask + ')' });\r\n }\r\n });\r\n\r\n chart.on('created', function (data) {\r\n axisX = data.axisX;\r\n axisY = data.axisY;\r\n chartRect = data.chartRect;\r\n svg = data.svg._node;\r\n rect = data.svg.elem('rect', {\r\n x: 10,\r\n y: 10,\r\n width: 100,\r\n height: 100,\r\n }, 'ct-zoom-rect');\r\n hide(rect);\r\n\r\n var defs = data.svg.querySelector('defs') || data.svg.elem('defs');\r\n var width = chartRect.width();\r\n var height = chartRect.height();\r\n\r\n function addMask(id, offset) {\r\n defs\r\n .elem('clipPath', {\r\n id: id\r\n })\r\n .elem('rect', {\r\n x: chartRect.x1 - offset,\r\n y: chartRect.y2 - offset,\r\n width: width + offset + offset,\r\n height: height + offset + offset,\r\n fill: 'white'\r\n });\r\n }\r\n addMask('line-mask', 0);\r\n addMask('point-mask', options.pointClipOffset);\r\n\r\n function on(event, handler) {\r\n svg.addEventListener(event, handler);\r\n }\r\n\r\n on('mousedown', onMouseDown);\r\n on('mouseup', onMouseUp);\r\n on('mousemove', onMouseMove);\r\n on('touchstart', onTouchStart);\r\n on('touchmove', onTouchMove);\r\n on('touchend', onTouchEnd);\r\n on('touchcancel', onTouchCancel);\r\n });\r\n\r\n\r\n\r\n function copyTouch(touch) {\r\n var p = position(touch, svg);\r\n p.id = touch.identifier;\r\n return p;\r\n }\r\n\r\n function ongoingTouchIndexById(idToFind) {\r\n for (var i = 0; i < ongoingTouches.length; i++) {\r\n var id = ongoingTouches[i].id;\r\n if (id === idToFind) {\r\n return i;\r\n }\r\n }\r\n return -1;\r\n }\r\n\r\n function onTouchStart(event) {\r\n var touches = event.changedTouches;\r\n for (var i = 0; i < touches.length; i++) {\r\n ongoingTouches.push(copyTouch(touches[i]));\r\n }\r\n\r\n if (ongoingTouches.length > 1) {\r\n rect.attr(getRect(ongoingTouches[0], ongoingTouches[1]));\r\n show(rect);\r\n }\r\n }\r\n\r\n function onTouchMove(event) {\r\n var touches = event.changedTouches;\r\n for (var i = 0; i < touches.length; i++) {\r\n var idx = ongoingTouchIndexById(touches[i].identifier);\r\n ongoingTouches.splice(idx, 1, copyTouch(touches[i]));\r\n }\r\n\r\n if (ongoingTouches.length > 1) {\r\n rect.attr(getRect(ongoingTouches[0], ongoingTouches[1]));\r\n show(rect);\r\n event.preventDefault();\r\n }\r\n }\r\n\r\n function onTouchCancel(event) {\r\n removeTouches(event.changedTouches);\r\n }\r\n\r\n function removeTouches(touches) {\r\n for (var i = 0; i < touches.length; i++) {\r\n var idx = ongoingTouchIndexById(touches[i].identifier);\r\n if (idx >= 0) {\r\n ongoingTouches.splice(idx, 1);\r\n }\r\n }\r\n }\r\n\r\n function onTouchEnd(event) {\r\n if (ongoingTouches.length > 1) {\r\n zoomIn(getRect(ongoingTouches[0], ongoingTouches[1]));\r\n }\r\n removeTouches(event.changedTouches);\r\n hide(rect);\r\n }\r\n\r\n function onMouseDown(event) {\r\n if (event.button === 0) {\r\n var point = position(event, svg);\r\n if (isInRect(point, chartRect)) {\r\n downPosition = point;\r\n rect.attr(getRect(downPosition, downPosition));\r\n show(rect);\r\n event.preventDefault();\r\n }\r\n }\r\n }\r\n\r\n function isInRect(point, rect) {\r\n return point.x >= rect.x1 && point.x <= rect.x2 && point.y >= rect.y2 && point.y <= rect.y1;\r\n }\r\n\r\n var reset = function () {\r\n chart.options.axisX.highLow = null;\r\n chart.options.axisY.highLow = null;\r\n chart.update(chart.data, chart.options);\r\n };\r\n\r\n function onMouseUp(event) {\r\n if (event.button === 0 && downPosition) {\r\n var box = getRect(downPosition, position(event, svg));\r\n zoomIn(box);\r\n downPosition = null;\r\n hide(rect);\r\n }\r\n else if (options.resetOnRightMouseBtn && event.button === 2) {\r\n reset();\r\n event.preventDefault();\r\n }\r\n }\r\n\r\n function zoomIn(rect) {\r\n if (rect.width > 5 && rect.height > 5) {\r\n var x1 = Math.max(0, rect.x - chartRect.x1);\r\n var x2 = Math.min(chartRect.width(), x1 + rect.width);\r\n var y2 = Math.min(chartRect.height(), chartRect.y1 - rect.y);\r\n var y1 = Math.max(0, y2 - rect.height);\r\n\r\n chart.options.axisX.highLow = { low: project(x1, axisX), high: project(x2, axisX) };\r\n chart.options.axisY.highLow = { low: project(y1, axisY), high: project(y2, axisY) };\r\n\r\n chart.update(chart.data, chart.options);\r\n onZoom && onZoom(chart, reset);\r\n }\r\n }\r\n\r\n function onMouseMove(event) {\r\n if (downPosition) {\r\n var point = position(event, svg);\r\n if (isInRect(point, chartRect)) {\r\n rect.attr(getRect(downPosition, point));\r\n event.preventDefault();\r\n }\r\n }\r\n }\r\n };\r\n\r\n };\r\n\r\n function hide(rect) {\r\n rect.attr({ style: 'display:none' });\r\n }\r\n\r\n function show(rect) {\r\n rect.attr({ style: 'display:block' });\r\n }\r\n\r\n function getRect(firstPoint, secondPoint) {\r\n var x = firstPoint.x;\r\n var y = firstPoint.y;\r\n var width = secondPoint.x - x;\r\n var height = secondPoint.y - y;\r\n if (width < 0) {\r\n width = -width;\r\n x = secondPoint.x;\r\n }\r\n if (height < 0) {\r\n height = -height;\r\n y = secondPoint.y;\r\n }\r\n return {\r\n x: x,\r\n y: y,\r\n width: width,\r\n height: height\r\n };\r\n }\r\n\r\n function position(event, svg) {\r\n return transform(event.clientX, event.clientY, svg);\r\n }\r\n\r\n function transform(x, y, svgElement) {\r\n var svg = svgElement.tagName === 'svg' ? svgElement : svgElement.ownerSVGElement;\r\n var matrix = svg.getScreenCTM();\r\n var point = svg.createSVGPoint();\r\n point.x = x;\r\n point.y = y;\r\n point = point.matrixTransform(matrix.inverse());\r\n return point || { x: 0, y: 0 };\r\n }\r\n\r\n function project(value, axis) {\r\n var max = axis.bounds.max;\r\n var min = axis.bounds.min;\r\n if (axis.scale && axis.scale.type === 'log') {\r\n var base = axis.scale.base;\r\n return Math.pow(base,\r\n value * baseLog(max / min, base) / axis.axisLength) * min;\r\n }\r\n return (value * axis.bounds.range / axis.axisLength) + min;\r\n }\r\n\r\n function baseLog(val, base) {\r\n return Math.log(val) / Math.log(base);\r\n }\r\n\r\n } (window, document, Chartist));\r\n\n return Chartist.plugins.zoom;\n\n}));\n"]} \ No newline at end of file +{"version":3,"file":"chartist-plugin-zoom.min.js","sources":["chartist-plugin-zoom.js"],"names":["root","factory","define","amd","returnExportsGlobal","exports","module","this","Chartist","require","window","document","hide","rect","attr","style","show","getRect","firstPoint","secondPoint","x","y","width","height","position","event","svg","transform","clientX","clientY","svgElement","tagName","ownerSVGElement","matrix","getScreenCTM","point","createSVGPoint","matrixTransform","inverse","project","value","axis","max","bounds","min","scale","type","base","Math","pow","baseLog","axisLength","range","val","log","defaultOptions","pointClipOffset","plugins","zoom","options","extend","chart","copyTouch","touch","p","id","identifier","ongoingTouchIndexById","idToFind","i","ongoingTouches","length","onTouchStart","touches","changedTouches","push","onTouchMove","idx","splice","preventDefault","onTouchCancel","removeTouches","onTouchEnd","zoomIn","onMouseDown","button","isInRect","chartRect","downPosition","x1","x2","y2","y1","onMouseUp","box","resetOnRightMouseBtn","reset","axisX","highLow","low","high","axisY","update","data","onZoom","onMouseMove","Line","on","mask","element","clip-path","addMask","offset","defs","elem","fill","handler","addEventListener","_node","querySelector","tooltips"],"mappings":"CAAC,SAAUA,EAAMC,GACO,kBAAXC,SAAyBA,OAAOC,IAEzCD,UAAW,WACT,MAAQF,GAAKI,oBAAsBH,MAET,gBAAZI,SAIhBC,OAAOD,QAAUJ,IAEjBD,EAAK,yBAA2BC,KAElCM,KAAM,WAsSN,MApSC,UAAUP,EAAMC,GACf,YAEsB,mBAAXC,SAAyBA,OAAOC,IAEzCD,QAAQ,YAAa,SAAUM,GAC7B,MAAQR,GAAKI,oBAAsBH,EAAQO,KAEjB,gBAAZH,SAIhBC,OAAOD,QAAUJ,EAAQQ,QAAQ,aAEjCT,EAAK,yBAA2BC,EAAQO,WAE1CD,KAAM,SAAUC,GAChB,YAgRA,OA3QC,UAAUE,EAAQC,EAAUH,GA8M3B,QAASI,GAAKC,GACZA,EAAKC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yB,EAAG,cAAe3B,IAoFpB,IAAIgB,GAAQ,WACVnC,EAAMF,QAAQsC,MAAMC,QAAU,KAC9BrC,EAAMF,QAAQ0C,MAAMH,QAAU,KAC9BrC,EAAMyC,OAAOzC,EAAM0C,KAAM1C,EAAMF,cAsGpCjD,OAAQC,SAAUH,GAGdA,EAASiD,QAAQ+D,WAGnBhH,SAASiD,QAAQC","sourcesContent":["(function (root, factory) {\n if (typeof define === 'function' && define.amd) {\n // AMD. Register as an anonymous module.\n define([], function () {\n return (root.returnExportsGlobal = factory());\n });\n } else if (typeof exports === 'object') {\n // Node. Does not work with strict CommonJS, but\n // only CommonJS-like enviroments that support module.exports,\n // like Node.\n module.exports = factory();\n } else {\n root['Chartist.plugins.zoom'] = factory();\n }\n}(this, function () {\n\n (function (root, factory) {\r\n 'use strict';\r\n\r\n if (typeof define === 'function' && define.amd) {\r\n // AMD. Register as an anonymous module.\r\n define(['chartist'], function (Chartist) {\r\n return (root.returnExportsGlobal = factory(Chartist));\r\n });\r\n } else if (typeof exports === 'object') {\r\n // Node. Does not work with strict CommonJS, but\r\n // only CommonJS-like enviroments that support module.exports,\r\n // like Node.\r\n module.exports = factory(require('chartist'));\r\n } else {\r\n root['Chartist.plugins.zoom'] = factory(Chartist);\r\n }\r\n }(this, function (Chartist) {\r\n 'use strict';\r\n /**\r\n * Chartist.js zoom plugin.\r\n *\r\n */\r\n (function (window, document, Chartist) {\r\n\r\n var defaultOptions = {\r\n // onZoom\r\n // resetOnRightMouseBtn\r\n pointClipOffset: 5\r\n };\r\n\r\n Chartist.plugins = Chartist.plugins || {};\r\n Chartist.plugins.zoom = function (options) {\r\n\r\n options = Chartist.extend({}, defaultOptions, options);\r\n\r\n return function zoom(chart) {\r\n\r\n if (!(chart instanceof Chartist.Line)) {\r\n return;\r\n }\r\n\r\n var rect, svg, axisX, axisY, chartRect;\r\n var downPosition;\r\n var onZoom = options.onZoom;\r\n var ongoingTouches = [];\r\n\r\n chart.on('draw', function (data) {\r\n var type = data.type;\r\n var mask = type === 'point' ? 'point-mask' : 'line-mask';\r\n if (type === 'line' || type === 'bar' || type === 'area' || type === 'point') {\r\n data.element.attr({ 'clip-path': 'url(#' + mask + ')' });\r\n }\r\n });\r\n\r\n chart.on('created', function (data) {\r\n axisX = data.axisX;\r\n axisY = data.axisY;\r\n chartRect = data.chartRect;\r\n svg = data.svg._node;\r\n rect = data.svg.elem('rect', {\r\n x: 10,\r\n y: 10,\r\n width: 100,\r\n height: 100,\r\n }, 'ct-zoom-rect');\r\n hide(rect);\r\n\r\n var defs = data.svg.querySelector('defs') || data.svg.elem('defs');\r\n var width = chartRect.width();\r\n var height = chartRect.height();\r\n\r\n function addMask(id, offset) {\r\n defs\r\n .elem('clipPath', {\r\n id: id\r\n })\r\n .elem('rect', {\r\n x: chartRect.x1 - offset,\r\n y: chartRect.y2 - offset,\r\n width: width + offset + offset,\r\n height: height + offset + offset,\r\n fill: 'white'\r\n });\r\n }\r\n addMask('line-mask', 0);\r\n addMask('point-mask', options.pointClipOffset);\r\n\r\n function on(event, handler) {\r\n svg.addEventListener(event, handler);\r\n }\r\n\r\n on('mousedown', onMouseDown);\r\n on('mouseup', onMouseUp);\r\n on('mousemove', onMouseMove);\r\n on('touchstart', onTouchStart);\r\n on('touchmove', onTouchMove);\r\n on('touchend', onTouchEnd);\r\n on('touchcancel', onTouchCancel);\r\n });\r\n\r\n\r\n\r\n function copyTouch(touch) {\r\n var p = position(touch, svg);\r\n p.id = touch.identifier;\r\n return p;\r\n }\r\n\r\n function ongoingTouchIndexById(idToFind) {\r\n for (var i = 0; i < ongoingTouches.length; i++) {\r\n var id = ongoingTouches[i].id;\r\n if (id === idToFind) {\r\n return i;\r\n }\r\n }\r\n return -1;\r\n }\r\n\r\n function onTouchStart(event) {\r\n var touches = event.changedTouches;\r\n for (var i = 0; i < touches.length; i++) {\r\n ongoingTouches.push(copyTouch(touches[i]));\r\n }\r\n\r\n if (ongoingTouches.length > 1) {\r\n rect.attr(getRect(ongoingTouches[0], ongoingTouches[1]));\r\n show(rect);\r\n }\r\n }\r\n\r\n function onTouchMove(event) {\r\n var touches = event.changedTouches;\r\n for (var i = 0; i < touches.length; i++) {\r\n var idx = ongoingTouchIndexById(touches[i].identifier);\r\n ongoingTouches.splice(idx, 1, copyTouch(touches[i]));\r\n }\r\n\r\n if (ongoingTouches.length > 1) {\r\n rect.attr(getRect(ongoingTouches[0], ongoingTouches[1]));\r\n show(rect);\r\n event.preventDefault();\r\n }\r\n }\r\n\r\n function onTouchCancel(event) {\r\n removeTouches(event.changedTouches);\r\n }\r\n\r\n function removeTouches(touches) {\r\n for (var i = 0; i < touches.length; i++) {\r\n var idx = ongoingTouchIndexById(touches[i].identifier);\r\n if (idx >= 0) {\r\n ongoingTouches.splice(idx, 1);\r\n }\r\n }\r\n }\r\n\r\n function onTouchEnd(event) {\r\n if (ongoingTouches.length > 1) {\r\n zoomIn(getRect(ongoingTouches[0], ongoingTouches[1]));\r\n }\r\n removeTouches(event.changedTouches);\r\n hide(rect);\r\n }\r\n\r\n function onMouseDown(event) {\r\n if (event.button === 0) {\r\n var point = position(event, svg);\r\n if (isInRect(point, chartRect)) {\r\n downPosition = point;\r\n rect.attr(getRect(downPosition, downPosition));\r\n show(rect);\r\n event.preventDefault();\r\n }\r\n }\r\n }\r\n\r\n function isInRect(point, rect) {\r\n return point.x >= rect.x1 && point.x <= rect.x2 && point.y >= rect.y2 && point.y <= rect.y1;\r\n }\r\n\r\n var reset = function () {\r\n chart.options.axisX.highLow = null;\r\n chart.options.axisY.highLow = null;\r\n chart.update(chart.data, chart.options);\r\n };\r\n\r\n function onMouseUp(event) {\r\n if (event.button === 0 && downPosition) {\r\n var box = getRect(downPosition, position(event, svg));\r\n zoomIn(box);\r\n downPosition = null;\r\n hide(rect);\r\n }\r\n else if (options.resetOnRightMouseBtn && event.button === 2) {\r\n reset();\r\n event.preventDefault();\r\n }\r\n }\r\n\r\n function zoomIn(rect) {\r\n if (rect.width > 5 && rect.height > 5) {\r\n var x1 = Math.max(0, rect.x - chartRect.x1);\r\n var x2 = Math.min(chartRect.width(), x1 + rect.width);\r\n var y2 = Math.min(chartRect.height(), chartRect.y1 - rect.y);\r\n var y1 = Math.max(0, y2 - rect.height);\r\n\r\n chart.options.axisX.highLow = { low: project(x1, axisX), high: project(x2, axisX) };\r\n chart.options.axisY.highLow = { low: project(y1, axisY), high: project(y2, axisY) };\r\n\r\n chart.update(chart.data, chart.options);\r\n onZoom && onZoom(chart, reset);\r\n }\r\n }\r\n\r\n function onMouseMove(event) {\r\n if (downPosition) {\r\n var point = position(event, svg);\r\n if (isInRect(point, chartRect)) {\r\n rect.attr(getRect(downPosition, point));\r\n event.preventDefault();\r\n }\r\n }\r\n }\r\n };\r\n\r\n };\r\n\r\n function hide(rect) {\r\n rect.attr({ style: 'display:none' });\r\n }\r\n\r\n function show(rect) {\r\n rect.attr({ style: 'display:block' });\r\n }\r\n\r\n function getRect(firstPoint, secondPoint) {\r\n var x = firstPoint.x;\r\n var y = firstPoint.y;\r\n var width = secondPoint.x - x;\r\n var height = secondPoint.y - y;\r\n if (width < 0) {\r\n width = -width;\r\n x = secondPoint.x;\r\n }\r\n if (height < 0) {\r\n height = -height;\r\n y = secondPoint.y;\r\n }\r\n return {\r\n x: x,\r\n y: y,\r\n width: width,\r\n height: height\r\n };\r\n }\r\n\r\n function position(event, svg) {\r\n return transform(event.clientX, event.clientY, svg);\r\n }\r\n\r\n function transform(x, y, svgElement) {\r\n var svg = svgElement.tagName === 'svg' ? svgElement : svgElement.ownerSVGElement;\r\n var matrix = svg.getScreenCTM();\r\n var point = svg.createSVGPoint();\r\n point.x = x;\r\n point.y = y;\r\n point = point.matrixTransform(matrix.inverse());\r\n return point || { x: 0, y: 0 };\r\n }\r\n\r\n function project(value, axis) {\r\n var max = axis.bounds.max;\r\n var min = axis.bounds.min;\r\n if (axis.scale && axis.scale.type === 'log') {\r\n var base = axis.scale.base;\r\n return Math.pow(base,\r\n value * baseLog(max / min, base) / axis.axisLength) * min;\r\n }\r\n return (value * axis.bounds.range / axis.axisLength) + min;\r\n }\r\n\r\n function baseLog(val, base) {\r\n return Math.log(val) / Math.log(base);\r\n }\r\n\r\n } (window, document, Chartist));\r\n\r\n\r\n return Chartist.plugins.tooltips;\r\n\r\n }));\n return Chartist.plugins.zoom;\n\n}));\n"]} \ No newline at end of file diff --git a/package.json b/package.json index 93c6067..1c44729 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "chartist-plugin-zoom", "description": "Zoom Plugin for Chartist.js", - "version": "0.3.0", + "version": "0.4.0", "author": "Hannes Kamecke", "homepage": "https://gionkunz.github.io/chartist-js/plugins.html", "repository": {