D3: Detect mouse wheel event through overlaid SVG

smcs

In the following example, is there a way to for the zoomArea to detect a mouse wheel event that happens while pointing on one of the grey circles? The aim is to not interrupt the zoom behaviour when doing so. The circles should still be able to receive pointer events in order to e.g. display tooltips.

var dataset = [0, 2345786000, 10000000000];

var svg = d3.select("body").append("svg");
var w = 500, h = 200;
var padding = 50;
svg.attr("width", w)
   .attr("height", h);

// Background pattern 
var patternSize = 5;
svg.append("defs")
            .append("pattern")
            .attr("id", "dotPattern")
            .attr("patternUnits", "userSpaceOnUse")
            .attr("width", patternSize)
            .attr("height", patternSize)
            .append("circle")
            .attr("cx", patternSize / 2)
            .attr("cy", patternSize / 2)
            .attr("r", 2)
            .style("stroke", "none")
            .style("fill", "lightgrey")
            .style("opacity", 0.5);
   
var xScale = d3.time.scale()
    .domain([0, 10000000000])
    .range([padding, w-padding]);
var xAxis = d3.svg.axis()
    .scale(xScale)
    .ticks(5);
svg.append("g")
		.attr("class","axis")
    .attr("transform", "translate(0," + (h-padding) + ")")
    .call(xAxis);
    
var zoom = d3.behavior.zoom()
            .on("zoom", build)
            .scaleExtent([1, 20]);           
zoom.x(xScale);

var clipPath = svg.append("clipPath")
        .attr("id", "clip")
        .append("rect")
        .attr("x", padding)
        .attr("y", 0)
        .attr("width",w-2*padding)
        .attr("height", h-padding);
var zoomArea = svg.append("g")
         .attr("class", "zoomArea")
         .style("cursor","move")
         .attr("clip-path", "url(#clip)");
var zoomRect = zoomArea.append("rect")
     .attr("x", padding)
     .attr("y", 0)
     .attr("width", w-2*padding)
     .attr("height", h-padding)
     .style("fill", "url(#dotPattern)")
     .style("pointer-events", "all")
     .style("cursor","move")
     .call(zoom);

zoomArea.selectAll("circles")          
	.data(dataset)
  .enter()
  .append("circle")
  .attr("cx", function(d){
  	return xScale(d);
  })
  .attr("cy", h/2)
  .attr("r",10)
  .attr("fill","grey")

function build(){
					svg.select("g.axis").call(xAxis);
          d3.selectAll("circle")
          	  .attr("cx", function(d){
  							return xScale(d);
  						});
};    
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>

Cyril Cherian

Call zoom on circles as well.

zoomArea.selectAll("circles")          
    .data(dataset)
  .enter()
  .append("circle")
  .attr("cx", function(d){
    return xScale(d);
  })
  .attr("cy", h/2)
  .attr("r",10)
  .attr("fill","grey")
  .call(zoom);//call zoom on circle

Working code here

Hope this helps!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Mouse wheel event in not getting triggered

From Dev

Mouse wheel event in not getting triggered

From Dev

How to detect user mouse wheel scroll distance?

From Dev

Is there a way to detect mouse wheel hardware with web programming?

From Dev

Vimeo iFrame Stealing Mouse Wheel Event on Firefox

From Dev

Prevent ScrollViewer from handling Mouse Wheel Event

From Dev

Detect which scrollbar was moved with the wheel event

From Dev

Changing mouse size with mouse wheel up/down event

From Dev

Detect the number of times mouse wheel was spun and not the length it was spun

From Dev

How do you make an SVG element mouse event bubble up through another element?

From Dev

How do you make an SVG element mouse event bubble up through another element?

From Dev

Mouse event goes through the component

From Dev

mouse over event line path d3

From Java

d3 mouse event, add circles on click

From Dev

mouse over event line path d3

From Dev

Full page website and scrolling through sections using the mouse wheel

From Dev

Qt 5 : Mouse Wheel event behaviour for zooming image

From Dev

mouseleave event does not fire on mouse wheel scroll in IE11

From Dev

Does WPF have mouse wheel scrolling up and down event

From Dev

Does WPF have mouse wheel scrolling up and down event

From Dev

Count Number of Times a Mouse Wheel Scroll Event has Occurred

From Dev

Qt 5 : Mouse Wheel event behaviour for zooming image

From Dev

C# WF prevent trackbar from getting mouse wheel event

From Dev

Switching tabs in Gedit 3.* with the mouse wheel

From Dev

Mouse wheel zoom limitation in OpenLayers 3

From Dev

Switching tabs in Gedit 3.* with the mouse wheel

From Dev

Mouse wheel zoom limitation in OpenLayers 3

From Dev

SVG chart generated through D3 not crispy

From Dev

How to detect the model of the target of a mouse event in AngularJS

Related Related

  1. 1

    Mouse wheel event in not getting triggered

  2. 2

    Mouse wheel event in not getting triggered

  3. 3

    How to detect user mouse wheel scroll distance?

  4. 4

    Is there a way to detect mouse wheel hardware with web programming?

  5. 5

    Vimeo iFrame Stealing Mouse Wheel Event on Firefox

  6. 6

    Prevent ScrollViewer from handling Mouse Wheel Event

  7. 7

    Detect which scrollbar was moved with the wheel event

  8. 8

    Changing mouse size with mouse wheel up/down event

  9. 9

    Detect the number of times mouse wheel was spun and not the length it was spun

  10. 10

    How do you make an SVG element mouse event bubble up through another element?

  11. 11

    How do you make an SVG element mouse event bubble up through another element?

  12. 12

    Mouse event goes through the component

  13. 13

    mouse over event line path d3

  14. 14

    d3 mouse event, add circles on click

  15. 15

    mouse over event line path d3

  16. 16

    Full page website and scrolling through sections using the mouse wheel

  17. 17

    Qt 5 : Mouse Wheel event behaviour for zooming image

  18. 18

    mouseleave event does not fire on mouse wheel scroll in IE11

  19. 19

    Does WPF have mouse wheel scrolling up and down event

  20. 20

    Does WPF have mouse wheel scrolling up and down event

  21. 21

    Count Number of Times a Mouse Wheel Scroll Event has Occurred

  22. 22

    Qt 5 : Mouse Wheel event behaviour for zooming image

  23. 23

    C# WF prevent trackbar from getting mouse wheel event

  24. 24

    Switching tabs in Gedit 3.* with the mouse wheel

  25. 25

    Mouse wheel zoom limitation in OpenLayers 3

  26. 26

    Switching tabs in Gedit 3.* with the mouse wheel

  27. 27

    Mouse wheel zoom limitation in OpenLayers 3

  28. 28

    SVG chart generated through D3 not crispy

  29. 29

    How to detect the model of the target of a mouse event in AngularJS

HotTag

Archive