diff --git a/src/config.js b/src/config.js index ae9aa9f..c4baae0 100644 --- a/src/config.js +++ b/src/config.js @@ -55,6 +55,8 @@ c3_chart_internal_fn.getDefaultConfig = function () { data_onmouseout: function () {}, data_onselected: function () {}, data_onunselected: function () {}, + data_ondragstart : function () {}, + data_ondragend : function () {}, data_url: undefined, data_json: undefined, data_rows: undefined, diff --git a/src/core.js b/src/core.js index 4dad60d..2a9c84c 100644 --- a/src/core.js +++ b/src/core.js @@ -113,6 +113,7 @@ c3_chart_internal_fn.initParams = function () { $$.clipPathForSubchart = $$.getClipPath($$.clipIdForSubchart), $$.dragStart = null; + $$.dragCurrent = null; $$.dragging = false; $$.flowing = false; $$.cancelClick = false; diff --git a/src/drag.js b/src/drag.js index 56ab070..e94bf6c 100644 --- a/src/drag.js +++ b/src/drag.js @@ -9,6 +9,7 @@ c3_chart_internal_fn.drag = function (mouse) { sx = $$.dragStart[0]; sy = $$.dragStart[1]; + $$.dragCurrent = mouse; mx = mouse[0]; my = mouse[1]; minX = Math.min(sx, mx); @@ -68,7 +69,11 @@ c3_chart_internal_fn.dragstart = function (mouse) { }; c3_chart_internal_fn.dragend = function () { - var $$ = this, config = $$.config; + var $$ = this, config = $$.config, + sx = $$.dragStart[0], + mx = $$.dragCurrent ? $$.dragCurrent[0] : sx, + minX = Math.min(sx, mx), + maxX = Math.max(sx, mx); if ($$.hasArcType()) { return; } if (! config.data_selection_enabled) { return; } // do nothing if not selectable $$.main.select('.' + CLASS.dragarea) @@ -77,5 +82,9 @@ c3_chart_internal_fn.dragend = function () { .remove(); $$.main.selectAll('.' + CLASS.shape) .classed(CLASS.INCLUDED, false); + if (config.data_ondragend) { + var drag_extent = [this.x.invert(minX), this.x.invert(maxX)]; + config.data_ondragend(drag_extent); + } $$.dragging = false; };