D3 drag
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>d3</title>
</head>
<body>
<div class="test"> </div>
<script src="../js/jquery-2.1.4.js"></script>
<script src="../js/d3.js"></script>
<script>
$(function(){ var dragmove = function(d){
d3.select(this)
.attr({
cx: function(){
d.x = Math.max(20, Math.min(220, d3.event.x));
return d.x;
},
cy: function(){
d.y = Math.max(20, Math.min(105, d3.event.y));
return d.y;
}
})
} var drag = d3.behavior.drag()
.origin(function(d){
return d;
})
.on('drag', dragmove);
; var svg = d3.select('.test')
.selectAll('svg')
.data([{
x: 120,
y: 62
}])
.enter()
.append('svg')
.attr('width', 240)
.attr('height', 125)
; svg.append('circle')
.attr({
r: 20,
cx: function(d) {
return d.x;
},
cy: function(d){
return d.y
}
})
.call(drag)
;
})
</script>
</body>
</html>

D3 drag的更多相关文章
- D3.js 力导向图
花了大半天看了一个八十几行的代码..心累 力导向图是之前就有画过很多次的东西,但是这次的代码看上去很陌生,然后发现是D3更新了4.0.... 先贴代码 var svg = d3.select(&quo ...
- svg操纵方案 基于 D3 还是 angular?
之前还是想简单了, 现在重新写这篇.把逻辑拆分粒度的辨析,放到外面去. 问题提出:svg控制方案 基于 D3 还是 angular 根据这个,html 4种展现样式:普通的html,svg,2D ca ...
- D3.js 入门学习(二) V4的改动
//d3.scan /* 新的d3.scan方法对数组进行线性扫描,并根据指定的比较函数返回至少一个元素的索引. 这个方法有点类似于d3.min和d3.max. 而d3.scan可以得到极值的索引而不 ...
- d3代码如何改造成update结构(恰当处理enter和exit)
d3的enter和exit 网上有很多blog讲解.说的还凑合的见:https://blog.csdn.net/nicolecc/article/details/50786661 如何把自己的rude ...
- [D3] Add hovercard
The way to add hovercard is Append a div with class 'hovercard' in the tick function, positioning th ...
- [D3] Add image to the node
We can create node with 'g' container, then append 'image' to the nodes. // Create container for the ...
- [D3] Drawing path in D3
Here we have a force layout with three nodes. In the example, we will link three nodes with line and ...
- [D3] Creating a D3 Force Layout in React
Learn how to leverage d3's layout module to create a Force Layout inside of React. We'll take a look ...
- d3.js V5版本在vue里使用 自定义节点图片
var width = this.$refs.topInfo.offsetWidth; var height = this.$refs.topInfo.offsetHeight; var img_w ...
随机推荐
- 第一个struct2程序(2)
第三步 需要使用ActionForm了.在Struts1.x中,必须要单独建立一个ActionForm类(或是定义一个动作Form),而在Struts2中ActionForm和Action已经二合一了 ...
- dom node 查找父级parentNode
var o = document.querySelectorAll("a[href='baidu.com']"); var p = o[o.length-1];console.lo ...
- springboot CommandLineRunner
@SpringBootApplicationpublic class Application implements CommandLineRunner { public static void mai ...
- go语言中通过http访问需要认证的api
func main() { //生成client 参数为默认 client := &http.Client{} //生成要访问的url url := "https://api.XXX ...
- 第六章 图(d)深度优先搜索
- Python frozenset() 函数
Python frozenset() 函数 Python 内置函数 描述 frozenset() 返回一个冻结的集合,冻结后集合不能再添加或删除任何元素. 语法 frozenset() 函数语法: ...
- MyBatis核心配置文件详解
------------------------siwuxie095 MyBatis 核心配置文件详解 1.核心 ...
- git协议
常用三种协议:ssh, git, http ssh协议: 使用ssh传输,安全,可授权,需要用ssh登录,一般使用添加秘钥的方式.搭建方便. git协议: 使用git-daemon监听9418端口,配 ...
- Spring框架的特点
1. 为什么要学习Spring的框架 * 方便解耦,简化开发 * Spring就是一个大工厂,可以将所有对象创建和依赖关系维护,交给Spring管理 * AOP编程的支持 * Spring提供面向切面 ...
- SVN版本冲突中 Files 的值“ < < < < < < < .mine”无效路径中具有非法字符的解决办法
.NET 中 SVN版本冲突中 Files 的值“ < < < < < < < .mine”无效路径中具有非法字符的解决办法: 一. 1.将项目逐个进行编译, ...