How to use the d3-brush.brushSelection function in d3-brush

To help you get started, we’ve selected a few d3-brush examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github BigFatDog / parcoords-es / dist / parcoords.esm.js View on Github external
var convertBrushArguments = function convertBrushArguments(args) {
      var args_array = Array.prototype.slice.call(args);
      var axis = args_array[0];
      // ordinal scales do not have invert
      var yscale = config.dimensions[axis].yscale;

      var raw = brushSelection(args_array[2][0]) || [];
      var scaled = invertByScale(raw, yscale);

      return {
        axis: args_array[0],
        node: args_array[2][0],
        selection: {
          raw: raw,
          scaled: scaled
        }
      };
    };
github BigFatDog / parcoords-es / src / brush / 1d-multi / newBrush.js View on Github external
.on('end', function() {
      // Figure out if our latest brush has a selection
      const lastBrushID = brushes[axis][brushes[axis].length - 1].id;
      const lastBrush = document.getElementById(
        'brush-' +
          Object.keys(config.dimensions).indexOf(axis) +
          '-' +
          lastBrushID
      );
      const selection = brushSelection(lastBrush);

      // If it does, that means we need another one
      if (selection && selection[0] !== selection[1]) {
        newBrush(state, config, pc, events, brushGroup)(axis, _selector);
      }

      // Always draw brushes
      drawBrushes(brushes[axis], config, pc, axis, _selector);

      brushUpdated(
        config,
        pc,
        events
      )(selected(state, config, pc, events, brushGroup));
      events.call('brushend', pc, config.brushed);
    });
github BigFatDog / parcoords-es / src / api / brushable.js View on Github external
// to make a dummy selection element
                if (event.sourceEvent.ctrlKey) {
                  let html = select(this)
                    .select('.selection')
                    .nodes()[0].outerHTML;
                  html = html.replace(
                    'class="selection"',
                    'class="selection dummy' +
                      ' selection-' +
                      config.brushes.length +
                      '"'
                  );
                  let dat = select(this).nodes()[0].__data__;
                  let brush = {
                    id: config.brushes.length,
                    extent: brushSelection(this),
                    html: html,
                    data: dat,
                  };
                  config.brushes.push(brush);
                  select(select(this).nodes()[0].parentNode)
                    .select('.axis')
                    .nodes()[0].outerHTML += html;
                  pc.brush();
                  config.dimensions[d].brush.move(select(this, null));
                  select(this)
                    .select('.selection')
                    .attr('style', 'display:none');
                  pc.brushable();
                } else {
                  pc.brush();
                }
github naver / billboard.js / src / internals / util.js View on Github external
const getBrushSelection = ctx => {
	let selection = null;
	const event = d3Event;
	const main = ctx.context || ctx.main;

	// check from event
	if (event && event.constructor.name === "BrushEvent") {
		selection = event.selection;
	// check from brush area selection
	} else if (main && (selection = main.select(`.${CLASS.brush}`).node())) {
		selection = d3BrushSelection(selection);
	}

	return selection;
};
github BigFatDog / parcoords-es / dist / parcoords.esm.js View on Github external
return function () {
    var actives = [];
    var extents = [];
    var ranges = {};
    //get brush selections from each node, convert to actual values
    //invert order of values in array to comply with the parcoords architecture
    if (config.brushes.length === 0) {
      var nodes = pc.g().selectAll('.brush').nodes();
      for (var k = 0; k < nodes.length; k++) {
        if (brushSelection(nodes[k]) !== null) {
          actives.push(nodes[k].__data__);
          var values = [];
          var ranger = brushSelection(nodes[k]);
          if (typeof config.dimensions[nodes[k].__data__].yscale.domain()[0] === 'number') {
            for (var i = 0; i < ranger.length; i++) {
              if (actives.includes(nodes[k].__data__) && config.flipAxes.includes(nodes[k].__data__)) {
                values.push(config.dimensions[nodes[k].__data__].yscale.invert(ranger[i]));
              } else if (config.dimensions[nodes[k].__data__].yscale() !== 1) {
                values.unshift(config.dimensions[nodes[k].__data__].yscale.invert(ranger[i]));
              }
            }
            extents.push(values);
            for (var ii = 0; ii < extents.length; ii++) {
              if (extents[ii].length === 0) {
                extents[ii] = [1, 1];
              }
            }
          } else {
            ranges[nodes[k].__data__] = brushSelection(nodes[k]);
github BigFatDog / parcoords-es / src / brush / install1DAxes.js View on Github external
keys(config.dimensions).forEach(function(d) {
        let brush = brushes[d];
        //todo: brush check
        if (brush !== undefined && brushSelection(brushNodes[d]) !== null) {
          extents[d] = brush.extent();
        }
      });
      return extents;
github BigFatDog / parcoords-es / dist / parcoords.esm.js View on Github external
var is_brushed = function is_brushed(p) {
      return brushNodes[p] && brushSelection(brushNodes[p]) !== null;
    };
github BigFatDog / parcoords-es / src / brush / 1d-multi / selected.js View on Github external
const is_brushed = (p, pos) => {
    const axisBrushes = brushes[p];

    for (let i = 0; i < axisBrushes.length; i++) {
      const brush = document.getElementById('brush-' + pos + '-' + i);

      if (brush && brushSelection(brush) !== null) {
        return true;
      }
    }

    return false;
  };
github BigFatDog / parcoords-es / dist / parcoords.esm.js View on Github external
return Object.keys(config.dimensions).reduce(function (acc, cur) {
        var brush = brushes[cur];
        //todo: brush check
        if (brush !== undefined && brushSelection(brushNodes[cur]) !== null) {
          var raw = brushSelection(brushNodes[cur]);
          var yScale = config.dimensions[cur].yscale;
          var scaled = invertByScale(raw, yScale);

          acc[cur] = {
            extent: brush.extent(),
            selection: {
              raw: raw,
              scaled: scaled
            }
          };
        }

        return acc;
      }, {});
    } else {
github BigFatDog / parcoords-es / src / brush / 1d / brushExtents.js View on Github external
return Object.keys(config.dimensions).reduce((acc, cur) => {
      const brush = brushes[cur];
      //todo: brush check
      if (brush !== undefined && brushSelection(brushNodes[cur]) !== null) {
        const raw = brushSelection(brushNodes[cur]);
        const yScale = config.dimensions[cur].yscale;
        const scaled = invertByScale(raw, yScale);

        acc[cur] = {
          extent: brush.extent(),
          selection: {
            raw,
            scaled,
          },
        };
      }

      return acc;
    }, {});
  } else {

d3-brush

Select a one- or two-dimensional region using the mouse or touch.

ISC
Latest version published 3 years ago

Package Health Score

71 / 100
Full package analysis