Created
July 18, 2019 13:44
-
-
Save cemtopkaya/669a9e6fdd492bf90674b7406b9ede0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
</head> | |
<body> | |
<svg width="960" height="500" style="border:1px solid red;"></svg> | |
<script src="https://d3js.org/d3.v5.js"></script> | |
<script> | |
let log = console.log | |
var svg = d3.select("svg"); | |
var circles = svg.selectAll("circle") | |
.data([{ | |
"x": 30, | |
"y": 30, | |
"radius": 20, | |
"color": "green" | |
}]) | |
.enter() | |
.append("circle") | |
.attr("cx", d => d.x) | |
.attr("cy", d => d.y) | |
.attr("r", d => d.radius) | |
.style("fill", d => d.color) | |
circles | |
.on("mousedown", function () { | |
log("mousedown event:", event) | |
log("mousedown this:", this) | |
log("mousedown d3(this):", d3.select(this)) | |
}) | |
.call(d3.drag() | |
.on("start", () => log("start event: ", event)) | |
.on("drag", function () { | |
d3.select(this) | |
.attr("cx", d3.event.x) | |
.attr("cy", d3.event.y) | |
}) | |
// end listener'ına eklenmiş fn varsa siler | |
.on("end", null) | |
) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment