diff --git a/demo/brush-with-arguments.html b/demo/brush-with-arguments.html new file mode 100644 index 0000000..fabab19 --- /dev/null +++ b/demo/brush-with-arguments.html @@ -0,0 +1,78 @@ + + + + + +Brushing Example + + + + +
+

Loads an external csv file, creates a custom quantitative color scale + using L*a*b interpolation, and enables brushing. + +

Brush Debug

+

+

+ + + + + + diff --git a/demo/index.html b/demo/index.html index 3f6269a..45ca736 100644 --- a/demo/index.html +++ b/demo/index.html @@ -70,9 +70,6 @@

Demo

  • Slick Grid
  • -
  • - Marking -
  • Superformula
  • @@ -94,6 +91,9 @@

    Demo

  • multi instance
  • +
  • + brush with arguments +
  • - + \ No newline at end of file diff --git a/src/brush/1d/brushFor.js b/src/brush/1d/brushFor.js index b9f2bdb..2757082 100644 --- a/src/brush/1d/brushFor.js +++ b/src/brush/1d/brushFor.js @@ -1,11 +1,11 @@ -import { brushY } from 'd3-brush'; +import { brushY, brushSelection } from 'd3-brush'; import { event } from 'd3-selection'; import selected from './selected'; -const brushUpdated = (config, pc, events) => newSelection => { +const brushUpdated = (config, pc, events, args) => newSelection => { config.brushed = newSelection; - events.call('brush', pc, config.brushed); + events.call('brush', pc, config.brushed, args); pc.renderBrushed(); }; @@ -22,21 +22,54 @@ const brushFor = (state, config, pc, events, brushGroup) => ( const _brush = brushY(_selector).extent([[-15, 0], [15, brushRangeMax]]); + const convertBrushArguments = args => { + const args_array = Array.prototype.slice.call(args); + const axis = args_array[0]; + const selection_raw = brushSelection(args_array[2][0]); + const selection_scaled = selection_raw.map(d => + config.dimensions[axis].yscale.invert(d) + ); + + return { + axis: args_array[0], + node: args_array[2][0], + selection: { + raw: selection_raw, + scaled: selection_scaled, + }, + }; + }; + _brush .on('start', function() { if (event.sourceEvent !== null) { - events.call('brushstart', pc, config.brushed); + events.call( + 'brushstart', + pc, + config.brushed, + convertBrushArguments(arguments) + ); if (typeof event.sourceEvent.stopPropagation === 'function') { event.sourceEvent.stopPropagation(); } } }) .on('brush', function() { - brushUpdated(config, pc, events)(selected(state, config, brushGroup)()); + brushUpdated( + config, + pc, + events, + convertBrushArguments(arguments) + )(selected(state, config, brushGroup)()); }) .on('end', function() { brushUpdated(config, pc, events)(selected(state, config, brushGroup)()); - events.call('brushend', pc, config.brushed); + events.call( + 'brushend', + pc, + config.brushed, + convertBrushArguments(arguments) + ); }); state.brushes[axis] = _brush;