score:1
I ended up using the method in SVGEdit suggested by DuoPixel. It uses other SVGEdit method defined in svgcanvas.js so it's not really meant as a standalone. Here's a working link to DuoPixel method suggested in the comments: https://github.com/duopixel/Method-Draw/blob/master/method-draw/src/svgcanvas.js#L600
With the specific implementation in case the link changes:
// This method sends back an array or a NodeList full of elements that
// intersect the multi-select rubber-band-box on the current_layer only.
//
// Since the only browser that supports the SVG DOM getIntersectionList is Opera,
// we need to provide an implementation here. We brute-force it for now.
//
// Reference:
// Firefox does not implement getIntersectionList(), see https://bugzilla.mozilla.org/show_bug.cgi?id=501421
// Webkit does not implement getIntersectionList(), see https://bugs.webkit.org/show_bug.cgi?id=11274
var getIntersectionList = this.getIntersectionList = function(rect) {
if (rubberBox == null) { return null; }
var parent = current_group || getCurrentDrawing().getCurrentLayer();
if(!curBBoxes.length) {
// Cache all bboxes
curBBoxes = getVisibleElementsAndBBoxes(parent);
}
var resultList = null;
try {
resultList = parent.getIntersectionList(rect, null);
} catch(e) { }
if (resultList == null || typeof(resultList.item) != "function") {
resultList = [];
if(!rect) {
var rubberBBox = rubberBox.getBBox();
var bb = {};
for(var o in rubberBBox) {
bb[o] = rubberBBox[o] / current_zoom;
}
rubberBBox = bb;
} else {
var rubberBBox = rect;
}
var i = curBBoxes.length;
while (i--) {
if(!rubberBBox.width || !rubberBBox.width) continue;
if (svgedit.math.rectsIntersect(rubberBBox, curBBoxes[i].bbox)) {
resultList.push(curBBoxes[i].elem);
}
}
}
// addToSelection expects an array, but it's ok to pass a NodeList
// because using square-bracket notation is allowed:
// http://www.w3.org/TR/DOM-Level-2-Core/ecma-script-binding.html
return resultList;
};
score:10
Preface: @Duopixel's comment on your original post is great -- I didn't know that method exists. However, it looks like it only supports a rectangular region per the MSDN docs, whereas it seems more intuitive to have a circle around the mouse.
A couple of other techniques:
Use an invisible, thick stroke that "expands" your element, if you're not otherwise using the stroke for styling, or draw a transparent line/shape on top of the element that is some amount larger. Listen to the 'click' event for these elements.
Do a pairwise comparison of every element with that of the mouse's click radius. I made an example here: http://jsfiddle.net/AkPN2/5/. I only implemented circles because they were easy -- you'd need to add the geometry for rectangles.
Source: stackoverflow.com
Related Query
- How to determine nearby SVG elements on a mouse event?
- How do you make an SVG element mouse event bubble up through another element?
- How to selectively pass mouse events to underlying svg elements
- How to add border/outline/stroke to SVG elements in CSS?
- d3.js - How can I set the cursor to hand when mouseover these elements on SVG container?
- How to update the fill color on existing svg elements with d3.js?
- d3.on("mouseover") event does not work with nested SVG elements
- How do I associate SVG elements generated by graphviz to elements in the DOT source code
- How to get reference to SVG (child) elements nested in another SVG element (parent) using D3?
- Using Javascript D3 library, how can I determine mouse position in data set of an area element on mousemove event?
- How to throttle function call on mouse event with D3.js
- How to move elements along with svg group
- How to create SVG elements of different types based on data?
- How can I pass attributes of an SVG element to a new event in D3?
- D3.js how to transition in opposite direction with basic SVG elements
- How to assign click event to every svg element in d3js
- how to add dragend event on svg element
- How do I scroll d3 elements while keeping a portion of the svg in a fixed position?
- How to display rectangular div with data on mouse over event of any node in d3 js tree?
- D3: Detect mouse wheel event through overlaid SVG
- How to use D3 force layout with existing SVG elements as nodes
- How do you translate HTML elements along with SVG elements when zooming and panning with D3
- How to add links from CSV file to SVG elements generated with D3?
- How do you prevent the interference of MULTIPLE SVG elements (text labels) on mouseover of a different SVG element?
- How can the elements in SVG can't be dragged out of the scope of SVG?
- On a Google maps overlay, how do I create lines between svg elements in D3
- In D3 How to enable mouse over event for current particular path?
- How to apply (and change) classes to an SVG elements that already exist
- Mouse up event not working properly in SVG
- d3 SVG Line elements not firing onclick event
More Query from same tag
- NVD3 D3.JS Issue. A value shows as undefined in the tooltip (Even though is defined)
- D3.js- How to format tick values as quarters instead of months
- 2 D3.js force layout graphs on same page?
- Incorrect axis domains in a D3 based bar graph
- How to access d3 point coordinates after transform
- D3: Having trouble selecting a path from json data
- How to add URLs to bubble chart?
- draw a grid or rectangles using a scale
- d3 data selection for creating a simple chart
- C3.js chart.load not loading for x/y axis graph
- D3 JS Graphs not getting toggled on click of radio buttons
- Electron file loaded but not showing in Network tab
- Add text into an svg path using d3
- Get all ticks values (NVD3)
- selection enter does not add new element
- d3.js brush fill color histogram
- error in display of color of line and style
- Adding together xValue totals using dimple.js
- d3.js need repeated values on y axis
- d3.js donut chart with legend outside donut
- Drawing a simple graph using projected lines
- d3.js Bottom to Top force layout - drag behavior
- D3, Angular, scatter chart
- How to draw a 3d bar chart on a world map with d3.js?
- Toggle between selected radio button using D3
- D3 Chart values are not grouped (from JSON load)
- Using own JSON data in D3
- On mouse over linkText should diplay in force layout of d3.js
- Dragging a globe in D3
- d3 zoom on scroll does not work anymore on Chrome