From 5da014ecab7baad4ed8a867e5cd0093e1ed7063d Mon Sep 17 00:00:00 2001 From: sekharreddykasu Date: Wed, 11 Feb 2015 11:03:08 +0530 Subject: [PATCH 1/2] Update jquery.ui.treemap.js Double click event added --- js/jquery.ui.treemap.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/js/jquery.ui.treemap.js b/js/jquery.ui.treemap.js index eeed883..7bf9623 100644 --- a/js/jquery.ui.treemap.js +++ b/js/jquery.ui.treemap.js @@ -750,6 +750,27 @@ TreemapUtils.squarify = function(rect,vals) { data = {"nodes": nodes, "ids": ids}; that._trigger('click',e,data); } + }).dblclick(function(e){ + if ( that._animationActive !== undefined && that._animationActive === true ) return; + var offset = that.element.offset(), + offsetX = parseInt(offset.left, 10), // offsets are float values on mac/FF + offsetY = parseInt(offset.top, 10), // convert them to ints so coordsToId will work + width = that.options.dimensions[0], + height = that.options.dimensions[1], + ids, + nodes, + data, + i; + + if (e.pageX < offsetX+width && e.pageY < (offsetY+height)) { + ids = that._coordsToId(e.pageX-offsetX,e.pageY-offsetY); + nodes = []; + for (i = 0; i < ids.length; i++ ) { + nodes.push(that._getNode([ids[i]])); + } + data = {"nodes": nodes, "ids": ids}; + that._trigger('dblclick',e,data); + } }); }, From 2830ba519ab40cb6e97c0f54991aafe6f7a55790 Mon Sep 17 00:00:00 2001 From: sekharreddykasu Date: Tue, 17 Feb 2015 17:17:41 +0530 Subject: [PATCH 2/2] refactored double click and click event. --- js/jquery.ui.treemap.js | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/js/jquery.ui.treemap.js b/js/jquery.ui.treemap.js index 7bf9623..5826ec7 100644 --- a/js/jquery.ui.treemap.js +++ b/js/jquery.ui.treemap.js @@ -730,28 +730,16 @@ TreemapUtils.squarify = function(rect,vals) { that._trigger('mousemove',e,data); } }).click(function(e){ - if ( that._animationActive !== undefined && that._animationActive === true ) return; - var offset = that.element.offset(), - offsetX = parseInt(offset.left, 10), // offsets are float values on mac/FF - offsetY = parseInt(offset.top, 10), // convert them to ints so coordsToId will work - width = that.options.dimensions[0], - height = that.options.dimensions[1], - ids, - nodes, - data, - i; - - if (e.pageX < offsetX+width && e.pageY < (offsetY+height)) { - ids = that._coordsToId(e.pageX-offsetX,e.pageY-offsetY); - nodes = []; - for (i = 0; i < ids.length; i++ ) { - nodes.push(that._getNode([ids[i]])); - } - data = {"nodes": nodes, "ids": ids}; - that._trigger('click',e,data); - } + that._clickEventHandler(e); }).dblclick(function(e){ - if ( that._animationActive !== undefined && that._animationActive === true ) return; + that._clickEventHandler(e); + + }); + }, + + _clickEventHandler: function(e){ + var that = this; + if ( that._animationActive !== undefined && that._animationActive === true ) return; var offset = that.element.offset(), offsetX = parseInt(offset.left, 10), // offsets are float values on mac/FF offsetY = parseInt(offset.top, 10), // convert them to ints so coordsToId will work @@ -769,11 +757,9 @@ TreemapUtils.squarify = function(rect,vals) { nodes.push(that._getNode([ids[i]])); } data = {"nodes": nodes, "ids": ids}; - that._trigger('dblclick',e,data); + that._trigger(e.type,e,data); } - }); }, - _refreshColorGradient: function() { var canvas = document.createElement("canvas"), colorStops = this.options.colorStops, @@ -908,7 +894,7 @@ TreemapUtils.squarify = function(rect,vals) { return TreemapUtils.hex2rgb(this.options.naColor); } var map = this.options.colorGradientMap.data; - var i = Math.floor(val*(map.length/4-1))*4; + var i = Math.floor(val*(map.length/4))*4; return [map[i],map[i+1],map[i+2]]; },