score:1
Issues with your code:
d3.selectAll('circle') selects all the circles in the body and as far as the paths are concerned:
d3.select('path id') wouldn't work as the selector itself is messed up here. Try console logging the selection here.
Option 1:
Try replacing the legend mouse events with the following code:
.on("mouseover", function(d) {
// look for all the circles within the parent node
d3.select(this.parentNode).selectAll('circle').style('opacity', 0.4);
// change opacity of current circle
d3.select(this).style('opacity', 0.9);
// use parentNode to go until SVG and select all paths
d3.select(this.parentNode.parentNode.parentNode).select('g.paths').selectAll('path').style('opacity', 0.4);
// change opacity of path with data-legend = key
d3.select(this.parentNode.parentNode.parentNode).select('g.paths').selectAll('path[data-legend="'+d.key+'"]').style('opacity', 0.9);
})
.on('mouseout', function(d) {
// change all circles' and paths' opacity back to original values
d3.select(this.parentNode).selectAll('circle').style('opacity', 0.9);
d3.select(this.parentNode.parentNode.parentNode).select('g.paths').selectAll('path').style('opacity', 0.9);
});
I hope the comments are clear enough to understand the code. Just parsing through the parentNodes.
Option 2:
Add a class/id to the legend group representing the "state" i.e. Alabama, California etc.
And search for the SVG with selectedState on every mouseover and change the paths' opacity.
Hope this helps. :)
Source: stackoverflow.com
Related Query
- Selecting path, changing opacity based on legend mouseover
- D3 changing color of path stroke on mouseover
- Mouseover issues in D3.js, containing Path elements and changing tooltip data once focus is brushed?
- D3.js - Changing opacity of element on mouseover IF condition=false
- d3.js Changing the opacity of nodes and it's outgoing and incoming links based on a filter
- Selecting specific svg path based on JSON attribute in d3.js
- Insert nodes on path with changing distance based on their count
- Modifying SVG path opacity and it's marker
- Changing speed of D3 path animation
- D3 Selecting based on text value of node
- Add region around SVG path for mouseover
- Selecting path within G element and change style
- Selecting d3 data subset based on column
- Multiples with x/y axis and mouseover example - line path shows wrong values
- Changing text attribute based upon event handler in d3.js
- D3js : mouseover of one element change opacity of several others elements
- Changing size of D3 tick marks based on tick value
- Changing element size on mouseover using D3
- Keep stroke-dasharray consistent when path length is changing
- mouseover only on path in d3
- changing stroke-opacity of <svg> object's path
- Changing Data in d3 Based on Selection Input
- Selecting multiple path elements in a d3 map
- Changing an html attribute based on its current value in D3
- Selecting last path of svg with d3.js
- D3: Highlighting Parts of Path on Mouseover in Line Graph
- issue in re-rendering the path in a line chart based on user selection
- Changing arc outer radius based on data on d3.js
- Is there a way to make a D3 legend change based on user input to radio buttons?
- How to manipulate nodes based on dynamicaly changing text? (enter/exit/update)
More Query from same tag
- Basic question about accessing an array column
- find the x and y co-ordinates of the center and middle point inside a div
- how to select a custom central-meridian in d3?
- svg to image on demand
- Determine the height of paragraph
- Circular point scale
- D3 Sankey customization
- Flip d3js svg line
- Stroke left and right side of rect svg
- D3.js Line Graph - Error: <path> attribute d: Expected number
- Function is not correctly plotted + cosmetic questions d3js
- tickformat for d3.js time scale
- d3 javascript alternate colors on click
- Remove text if rect is below a certian height d3js v4
- Circle Not Generating For All Value In csv File In ScatterPlot d3js
- Reading csv data file with c3.js
- D3 not able to show line
- How to get D3.js's tidy tree graph from reducing the lateral distance of siblings as depth increases
- how to fill the area between the bars in the given example d3js
- d3js overlapping elements: how to "pass through" clicks to "lower" element?
- can webpack output separate script and module files for browser and node?
- How to parallelize d3.js or cubism.js
- how to display the xml tags data using force directed graph in d3.js
- What is causing certain data to display weird in this d3 chart?
- Specify a maximum size in d3 circle packer
- D3 V3 Multi-line Chart - Issues appending lines to svg
- Propagating events through overlapping svg elements
- D3 Treechart : Text on link(path) in version 4
- Padding not making a difference on bar chart
- selection.data returning different types of objects