score:65
the g
element is just an empty container which cannot capture click events (see documentation for pointer-events
property for details).
however, mouse events do bubble up to it. hence, the effect you desire can be achieved by first making sure that the g
receives all pointer events:
.g_main {
// ..
pointer-events: all;
}
and then appending an invisible rectangle to it as a place to hover over:
viz.on("mousemove", function () {
cx = d3.mouse(this)[0];
cy = d3.mouse(this)[1];
redrawline(cx, cy);
})
.on("mouseover", function () {
d3.selectall('.line_over').style("display", "block");
})
.on("mouseout", function () {
d3.selectall('.line_over').style("display", "none");
})
.append('rect')
.attr('class', 'click-capture')
.style('visibility', 'hidden')
.attr('x', 0)
.attr('y', 0)
.attr('width', width)
.attr('height', height);
working example: http://jsfiddle.net/h3w3k/
as for why they work when applied to the svg
element (from the docs):
note that the ‘svg’ element is not a graphics element, and in a conforming svg stand-alone file a rootmost ‘svg’ element will never be the target of pointer events, though events can bubble to this element. if a pointer event does not result in a positive hit-test on a graphics element, then it should evoke any user-agent-specific window behavior, such as a presenting a context menu or controls to allow zooming and panning of an svg document fragment.
Source: stackoverflow.com
Related Query
- d3.js - mouseover event not working properly on svg group
- d3 - mouseover and mouseout event not working properly
- Mouse up event not working properly in SVG
- D3 Clippath Mouseover event not working
- MouseOver event is not triggered in svg - clippath region in Chrome?
- Wheel event is not fired on a SVG group element in Safari
- d3.mouse not working properly on transformed SVG
- Can not capture mouseover event while dragging on an svg
- D3.js mouseover event not working in bar charts
- SVG path transition in D3 (v5) not working properly
- Click event in not working on D3 US Map, and mouseover event is working on particular states only
- Mouseover Event not working well with overlaid objects
- Adding text in svg on mouseover not working d3.js
- Title Attribute not working for an SVG Rect on Safari
- SVG not rendering properly as a backbone view
- D3 - Positioning tooltip on SVG element not working
- Exit not working properly
- d3.on("mouseover") event does not work with nested SVG elements
- D3: Zooming/Panning Line Graph in SVG is not working in Canvas
- In d3 on blur event is not working in firefox only
- Remove event listener with d3js not working
- d3.js - .exit().remove() a group element is not working
- SVG text element text-anchor="middle" not working in Firefox
- Positioning svg x/y coordinates with css not working with iOS devices?
- Slice and bounce effect not working properly in pie chart
- svg <a> element not working
- D3's scale not working properly
- SVG Marker Not Working
- CSS transform-origin not working for svg in safari
- The mouseover event for D3.js does not work in Leaflet
More Query from same tag
- Use d3 data binding for a secondary effect?
- Adding points to Voronoi Diagram in d3
- Adding a Tooltip in D3 to a Google Maps Overlay
- Filter based on the text content of elements
- Can't draw links by node property using D3 force layout
- D3 select on ID parentNode
- Monochromatic color palette generation with d3 library
- Is there any benefit installing d3.js via npm for Angular 2 TypeScript project?
- Visualizing world map using D3.js but cant visualize the json file
- How reference an svg class in css?
- d3: can't import text file with semicolon delimiter
- drag and make connection between circle with line using d3.js
- d3.csv map column values as keys in object
- Path intersection causes parts of them to disappear [D3 Path Generation]
- transform linechart to 'squared' chart not being a barchart
- d3.js custom tick values
- nvd3 and angular - Unable to fix axis values
- Staggered? Chained? Single DOM element addressed by a series of d3 transitions of varying delay() and duration()
- d3 area graph going out of bounds
- d3.js Subtransition with exit() and enter()
- Set d3 y-axis time format with 15 second increments and seconds % 15 == 0?
- Legend in horizontal multi bar chart
- d3js: How to select only x number of values from data
- d3.js multiple line chart highlighting datapoints only
- How to draw arrow head with D3 (Responsive)
- d3js multiple networks issue
- Adding markers to CanvasRenderingContext2D in javascript
- Can I get a value returned from a $.Deferred() that can be used in the display?
- D3: Skip Item based on condition
- c3js - D3js - Customize labels in a simple bar chart