src/modules/many.js
/**
   * Handles event of single mousedown (either as click, or beginning of a
   * brush drag event).
   *
   * For distinct (non-numeric values), the behavior is this:
   * - If shift is pressed: toggle the value (selected if it was unselected,
   *   and vice versa)
   * - If shift is not pressed: set the value to selected one, unless already
   *   selected, in which case unselect all values.
   *
   * For ranges (numeric values), the behavior is this:
   * - If the bar represents a single value (not binned), create a single value
   *   equality query, e.g. {"field": 16}.
   * - If the bar represents a range (binned), create a $gte / $lt range query,
   *   e.g. {"field": {"$gte": 20, "$lt": 25}} for a bin size of 5.
   *
   * @param  {Document} d    the data associated with the clicked bar
   */
Handles event of single mousedown (either as click, or beginning of a
brush drag event).

For distinct (non-numeric values), the behavior is this:
- If shift is pressed: toggle the value (selected if it was unselected,
and vice versa)
- If shift is not pressed: set the value to selected one, unless already
selected, in which case unselect all values.

For ranges (numeric values), the behavior is this:
- If the bar represents a single value (not binned), create a single value
equality query, e.g.

@param  {Document} d    the data associated with the clicked bar
Handles event of single mousedown ( either as click or beginning of a brush drag event ) . For distinct ( non - numeric values ) the behavior is this : - If shift is pressed : toggle the value ( selected if it was unselected and vice versa ) - If shift is not pressed : set the value to selected one unless already selected in which case unselect all values . For ranges ( numeric values ) the behavior is this : - If the bar represents a single value ( not binned ) create a single value equality query e . g . @param { Document } d the data associated with the clicked bar
function handleMouseDown(d) {
    if (!options.selectable) {
      return;
    }
    if (options.selectionType === 'distinct') {
      const qbAction = d3.event.shiftKey ?
        QueryAction.toggleDistinctValue : QueryAction.setValue;
      qbAction({
        field: options.fieldName,
        value: options.promoter(d.value),
        unsetIfSet: true
      });
    } else if (d3.event.shiftKey && lastNonShiftRangeValue) {
      QueryAction.setRangeValues({
        field: options.fieldName,
        min: options.promoter(Math.min(d.value, lastNonShiftRangeValue.value)),
        max: options.promoter(Math.max(d.value + d.dx, lastNonShiftRangeValue.value + lastNonShiftRangeValue.dx)),
        maxInclusive: d.dx === 0
      });
    } else {
      lastNonShiftRangeValue = d;
      if (d.dx > 0) {
        QueryAction.setRangeValues({
          field: options.fieldName,
          min: options.promoter(d.value),
          max: options.promoter(d.value + d.dx),
          unsetIfSet: true
        });
      } else {
        QueryAction.setValue({
          field: options.fieldName,
          value: options.promoter(d.bson),
          unsetIfSet: true
        });
      }
    }
    const parent = $(this).closest('.minichart');
    const background = parent.find('g.brush > rect.background')[0];
    const brushNode = parent.find('g.brush')[0];
    const start = d3.mouse(background)[0];
    const w = d3.select(window)
      .on('mousemove', mousemove)
      .on('mouseup', mouseup);
    d3.event.preventDefault(); 
    function mousemove() {
      const extent = [start, d3.mouse(background)[0]];
      d3.select(brushNode).call(brush.extent(sortBy(extent)));
      brushed.call(brushNode);
    }
    function mouseup() {
      w.on('mousemove', null).on('mouseup', null);
      brushend.call(brushNode);
    }
  }
function handleMouseDown ( d ) { if ( ! options . selectable ) { return ; } if ( options . selectionType === 'distinct' ) { const qbAction = d3 . event . shiftKey ? QueryAction . toggleDistinctValue : QueryAction . setValue ; qbAction ( { field : options . fieldName , value : options . promoter ( d . value ) , unsetIfSet : true } ) ; } else if ( d3 . event . shiftKey && lastNonShiftRangeValue ) { QueryAction . setRangeValues ( { field : options . fieldName , min : options . promoter ( Math . min ( d . value , lastNonShiftRangeValue . value ) ) , max : options . promoter ( Math . max ( d . value + d . dx , lastNonShiftRangeValue . value + lastNonShiftRangeValue . dx ) ) , maxInclusive : d . dx === 0 } ) ; } else { lastNonShiftRangeValue = d ; if ( d . dx > 0 ) { QueryAction . setRangeValues ( { field : options . fieldName , min : options . promoter ( d . value ) , max : options . promoter ( d . value + d . dx ) , unsetIfSet : true } ) ; } else { QueryAction . setValue ( { field : options . fieldName , value : options . promoter ( d . bson ) , unsetIfSet : true } ) ; } } const parent = $ ( this ) . closest ( '.minichart' ) ; const background = parent . find ( 'g.brush > rect.background' ) [ 0 ] ; const brushNode = parent . find ( 'g.brush' ) [ 0 ] ; const start = d3 . mouse ( background ) [ 0 ] ; const w = d3 . select ( window ) . on ( 'mousemove' , mousemove ) . on ( 'mouseup' , mouseup ) ; d3 . event . preventDefault ( ) ; function mousemove ( ) { const extent = [ start , d3 . mouse ( background ) [ 0 ] ] ; d3 . select ( brushNode ) . call ( brush . extent ( sortBy ( extent ) ) ) ; brushed . call ( brushNode ) ; } function mouseup ( ) { w . on ( 'mousemove' , null ) . on ( 'mouseup' , null ) ; brushend . call ( brushNode ) ; } }
Handles event of single mousedown (either as click, or beginning of a
 brush drag event).
Handles event of single mousedown ( either as click or beginning of a brush drag event ) .
// distinct values, behavior dependent on shift key // remember non-shift value so that range can be extended with shift // binned bars, turn single value into range // bars don't represent bins, build single value query // disable text dragging