score:7
Here's one way to draw a rect with a hole in. It relies on the evenodd fill-rule. The circle is inside the rect it becomes a hole in the rect and the blue background shows through.
<svg viewBox="0 0 250 250">
<rect width="100%" height="100%" fill="blue"/>
<path fill="#b4edb4" fill-rule="evenodd" d="M230,230H8V13h223
V236z M 120 80 a 50 50 0 1 0 0.00001 0z"/>
</svg>
score:1
@Robert Longson gave a nice answer but I was unable to duplicate it using my dataset and D3. So, thanks to @PaulLeBeau for his point about masks.
For the mask, you need a rect element, filled white for it to work. It uses this to know what to mask against(I think).
var thisMask = thisContainer.append("svg:mask")
.attr("id", board + '_mask')
thisMask.append("rect")
.attr('x', 0)
.attr('y', 0)
.attr('width', "100%")
.attr('height', "100%")
.style('fill','white')
And in the same mask element, you need the rest of the shapes you want to remove from the path.
So in my case, I wanted a collection of circles :
thisMask.selectAll('.circle')
.data(data)
.enter()
.append("circle")
.attr('cx', function(d) {
console.log('clippath', d)
return d.x
})
.attr('cy', function(d) {
return d.y
})
.attr('r', function(d) {
return d.radius
})
And that's it. I have updated the fiddle : https://jsfiddle.net/thatOneGuy/1spn8nne/4/
Source: stackoverflow.com
Related Query
- How to remove shapes from filled SVG path
- How to get projected path definition strings (not SVG elements) from a GeoJSON dataset with D3?
- d3.js- noob- how to bind data to path from external svg by path ID?
- How to link from path elements in one svg to a different element of another svg
- How to get rid of hairline from overlapping svg shapes
- How can I remove or replace SVG content?
- How do I remove all children elements from a node and then apply them again with different color and size?
- How to select a d3 svg path with a particular ID
- In d3, how to get the interpolated line data from a SVG line?
- How to update an svg path with d3.js
- How to draw a path smoothly from start point to end point in D3.js
- How to place svg shapes in a circle?
- How can I set the each line color or width in SVG path
- How can I animate infinite marker movement down an SVG path without very high CPU usage?
- Trying to add ID to svg path from json file
- How to add filled sections to SVG circles using d3.js
- How do I rotate or scale (transform) an SVG path relative to its center point?
- How can I remove a line from the 110m TopoJson world map?
- How can D3 select multiple shapes with shared attributes from a group?
- How to remove weekends dates from x axis in dc js chart
- How to highlight path from root to selected node in d3 js?
- How to create SVG shapes based on data?
- How to prevent SVG text from flowing out of its circle?
- How to add links from CSV file to SVG elements generated with D3?
- How to remove svg inside a div
- How to remove cursor pointer from d3 Pie chart
- How to fix unwanted circle on / break down of SVG path element for Sankey links with d3?
- How to get SVG path data of TopoJSON feature without adding it to the DOM?
- How to color SVG image based on value from color range using d3?
- How to remove D3 link text from visualization
More Query from same tag
- How to match data points in D3.js to match x-axis?
- D3 Multiline Chart with Tooltip Transition Issue
- JSON call error with d3js
- D3 ticks change position when changing focus
- Why is web server needed for dimple.js examples to run?
- How to make the cursor change in d3.js when I want?
- How to use nest and rollup functions in D3 to create a bar chart
- d3 line graph - how to start line to the right of Y axis?
- Mouseover d3.js map with different layers
- Parse flat array into a nested structure (tree)
- Adding D3 librarie to Jhipster gateway
- How to select a particular element in g elements and change its status in D3.js
- How to append the arrow marker dynamically in force layout d3.js
- How to find coordinates to put circle on polar scatterplot using d3
- How to update D3.js bubble chart with real-time JSON data?
- Rotate text around a circle
- How to disable legend in nvd3 or limit it's size
- D3 Tree update color of nodes dynamically
- How to auto-sort a bar-chart with a toggle function
- How to hide folders using partition layout based on available space in D3?
- How do you add rotation logic for mobile devices upon dragging on a 3d globe with D3.js and html canvas
- d3 clustered force layout, distance between cluster center
- Graphviz svg output, groups not positioned
- How ro replace d3.rainbow
- Armadillo projection in D3
- D3.js - Width of xAxis for a bar chart too short
- d3 v4: Data join for bar chart
- d3.js inline-block elements are failing in Firefox and IE
- SVG added to DOM using javascript is not visible.
- How can I know what dates are displayed in the axis?