<!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. JS中的继承实现方式

    第一种:通过prototype来实现 prototype.html <!DOCTYPE html><html lang="en"><head> ...

  2. 1D Blending

    [1D Blending] BlendTree有类型之分,分为1D.2D.本文记录1D. 1D Blending blends the child motions according to a sin ...

  3. IIS7配置下载apk以及目录浏览

    IIS7为了增加安全性,如果需要禁止目录浏览.只需要按下面的步骤执行就可以 1.选择站点:2.选择功能视图:3.选择IIS下面的目录浏览:4.在右上角的操作中选择“打开功能”:5.选择右边的禁用. 今 ...

  4. Redis启动与使用

    在redis文件夹下,启动redis服务端的命令如下: .\redis-server 也可以指定要加载的配置文件,如下: .\redis-server ..\redis.conf 启动redis客户端 ...

  5. 第六章 图(a)概述

  6. 第十章 泛型程序设计与C++标准模板库 泛型程序设计及STL的结构

  7. zoj1109-Language of FatMouse 【字典树】

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=109 Language of FatMouse Time Limit: 10 S ...

  8. MyBatis配置数据源的两种方式

    ---------------------siwuxie095                                     MyBatis 配置数据源的两种方式         1.配置方 ...

  9. discuz目录结构和插件创建

    discuz目录结构 api 外部接口功能实现 archiver 静态文档,静态化所用 config 配置 data 生成的数据 install 安装目录 source 源代码核心目录 |--modu ...

  10. php ZeroMQ 的使用

    一.ZeroMQ简介 ZMQ (以下 ZeroMQ 简称 ZMQ)是一个简单好用的传输层,像框架一样的一个 Socket Library,他使得 Socket 编程更加简单.简洁和性能更高.是一个消息 ...