-
Notifications
You must be signed in to change notification settings - Fork 0
/
clip-paths.js
23 lines (21 loc) · 891 Bytes
/
clip-paths.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//Define clipping path
svg.append("clipPath") //Make a new clipPath
.attr("id", "chart-area") //Assign an ID to reference later
.append("rect") //Within the clipPath, create a new shape to cover everything, usually rect
.attr("x", padding) // set to left and right padding
.attr("y", padding) // Set to top and bottom padding
.attr("width", w - padding * 3)
.attr("height", h - padding * 2);
// When adding elements do this
svg.append("g") //Create new g
.attr("id", "circles") //Assign ID of 'circles'
.attr("clip-path", "url(#chart-area)") //Add reference to clipPath
.selectAll("circle") //Continue as before…
.data(dataset)
.enter()
.append("circle")
// instead of this
svg.selectAll("circle")
.data(dataset)
.enter()
.append("circle")