<!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的更多相关文章

  1. D3.js 力导向图

    花了大半天看了一个八十几行的代码..心累 力导向图是之前就有画过很多次的东西,但是这次的代码看上去很陌生,然后发现是D3更新了4.0.... 先贴代码 var svg = d3.select(&quo ...

  2. svg操纵方案 基于 D3 还是 angular?

    之前还是想简单了, 现在重新写这篇.把逻辑拆分粒度的辨析,放到外面去. 问题提出:svg控制方案 基于 D3 还是 angular 根据这个,html 4种展现样式:普通的html,svg,2D ca ...

  3. D3.js 入门学习(二) V4的改动

    //d3.scan /* 新的d3.scan方法对数组进行线性扫描,并根据指定的比较函数返回至少一个元素的索引. 这个方法有点类似于d3.min和d3.max. 而d3.scan可以得到极值的索引而不 ...

  4. d3代码如何改造成update结构(恰当处理enter和exit)

    d3的enter和exit 网上有很多blog讲解.说的还凑合的见:https://blog.csdn.net/nicolecc/article/details/50786661 如何把自己的rude ...

  5. [D3] Add hovercard

    The way to add hovercard is Append a div with class 'hovercard' in the tick function, positioning th ...

  6. [D3] Add image to the node

    We can create node with 'g' container, then append 'image' to the nodes. // Create container for the ...

  7. [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 ...

  8. [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 ...

  9. d3.js V5版本在vue里使用 自定义节点图片

    var width = this.$refs.topInfo.offsetWidth; var height = this.$refs.topInfo.offsetHeight; var img_w ...

随机推荐

  1. RESTORE 无法处理数据库 'Students',因为它正由此会话使用。建议在执行此操作时使用 master 数据库。

    恢复数据库是总弹出报错对话框如下:RESTORE 无法处理数据库 'Students',因为它正由此会话使用.建议在执行此操作时使用 master 数据库.RESTORE DATABASE 正在异常终 ...

  2. SVM总结(转)

    支持向量机 看了JULY君的博客和文档后,个人对SVM的理解和总结,欢迎交流和指正.其理论部分可以查看下面文档链接,通俗易懂. 支持向量机通俗导论(理解SVM的三层境界)     第一篇:从四个关键词 ...

  3. oracle 基本信息

    查看Oracle是32位还是64位的方法: 方法一:使用sqlplus 64位: [oracle@qs-wg-db2 ~]$ sqlplus / as sysdba;   SQL*Plus: Rele ...

  4. mysql datetime与timestamp精确到毫秒的问题

    CREATE TABLE `tab1` (`tab1_id` VARCHAR(11) DEFAULT NULL,`create` TIMESTAMP(3) NULL DEFAULT NULL,`cre ...

  5. function方法控制是否隐藏部分内容

    $(document).ready(function() { $('input[type=radio][name=IE]').change(function() { if (this.value == ...

  6. 《Visual Basic开发实战1200例》包括第I卷、第II卷共计1200个例子,本书是第I卷,共计600个例子。

    本书以开发人员在项目开发中经常遇到的问题和必须掌握的技术为中心,介绍了应用Visual Basic进行程序开发各个方面的知识和技巧.主要包括基础知识.窗体界面设计.控件应用等.全书分6篇20章,共计6 ...

  7. X_PU

    通俗易懂告诉你CPU/GPU/TPU/NPU...XPU都是些什么鬼?[附把妹秘籍] 2017-10-27 19:54移动芯片/谷歌 作者:iot101君 物联网智库 原创 转载请注明来源和出处 现在 ...

  8. 57. Insert Interval (Array; Sort)

    Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessa ...

  9. VR

  10. cannot convert from 'wchar_t *' to 'char *' 问题

    MFC中使用unicode 会导致cstring之间的转换变的很复杂 经常遇到这样的错误cannot convert from 'wchar_t *' to 'char *' 强制转换成wchar_t ...