[D3] Add hovercard
The way to add hovercard is
- Append a div with class 'hovercard'
- in the tick function, positioning the hovercard with 'd3.event.pageX and pageY'
.hovercard {
position: absolute;
max-width: 400px;
height: auto;
padding: 5px;
background-color: white;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-webkit-box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4);
-moz-box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4);
box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4);
pointer-events: none;
font: 12px sans-serif;
}
const hovercard = d3.select('body')
.append('div')
.attr('class', 'hovercard')
.style('opacity', 0)
.style('width', 400);
function ticked() {
// adjust nodes containers position
svgNodes
.attr('transform', d =>`translate(${d.x},${d.y})`)
.call(d3.drag()
.on('start', dragstarted)
.on('drag', dragged)
.on('end', dragended));
// Curve paths
path
.attr('d', (d) => {
const curve = d.battle_number * .5;
const dx = d.target.x - d.source.x;
const dy = d.target.y - d.source.y;
const dr = Math.sqrt(dx * dx * curve + dy * dy * curve);
return `M${d.source.x},${d.source.y}A${dr},${dr} 0 0,1 ${d.target.x},${d.target.y}`;
});
path.on('mouseover', d => {
hovercard
.transition()
.duration(300)
.delay(20)
.style('opacity', 1);
const tip =
'<h2>' + d.name + '</h2>' +
'<h4>' + d.source.name + ' attacked ' + d.target.name + ' and the outcome was a ' + d.attacker_outcome + '</h4>' +
'<h3>Details</h3>' +
'<strong> Attacker King: </strong>'+d.attacker_king + '<br/>'+
'<strong> Battle Type: </strong>'+d.battle_type + '<br/>'+
'<strong> Major Death?: </strong>'+d.major_death + '<br/>'+
'<strong> Major Capture?: </strong>'+d.major_capture + '<br/>'+
'<strong> Attacker Size: </strong>'+d.value + '<br/>'+
'<strong> Defender Size: </strong>'+d.defender_size + '<br/>'+
'<strong> Region / Location: </strong>'+d.region+ ' / ' + d.location + '<br/>'+
'<strong> Attacking Commander: </strong>'+d.attacker_commander + '<br/>'+
'<strong> Defending Commander: </strong>'+d.defender_commander;
hovercard
.html(tip)
.style('left', d3.event.pageX + 'px')
.style('top', d3.event.pageY + 'px');
});
path.on('mouseout', d => {
hovercard
.transition()
.duration(500)
.style('opacity', 0);
});
}
});
[D3] Add hovercard的更多相关文章
- [D3] Add label text
If we want to add text to a node or a image // Create container for the images const svgNodes = svg ...
- [D3] Add image to the node
We can create node with 'g' container, then append 'image' to the nodes. // Create container for the ...
- 【精心推荐】几款实用的 JavaScript 图形图表库
一款好的图表插件不是那么容易找到的.最近项目里需要实现统计图表功能,所以在网上搜罗了一圈,找到一些不错的图表插件,分享大家.众多周知,图形和图表要比文本更具表现力和说服力.这里给大家精心推荐几款实用的 ...
- 几款实用的 JavaScript 图形图表库
一款好的图表插件不是那么容易找到的.最近项目里需要实现统计图表功能,所以在网上搜罗了一圈,找到一些不错的图表插件,分享大家.众多周知,图形和图表要比文本更具表现力和说服力.这里给大家精心推荐几款实用的 ...
- NAND FLASH ECC校验原理与实现
ECC简介 由于NAND Flash的工艺不能保证NAND的Memory Array在其生命周期中保持性能的可靠,因此,在NAND的生产中及使用过程中会产生坏块.为了检测数据的可靠性,在应用NAND ...
- Hat's Fibonacci(大数加法+直接暴力)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1250 hdu1250: Hat's Fibonacci Time Limit: 2000/1000 M ...
- Unity XLua 官方教程学习
一.Lua 文件加载 1. 执行字符串 using UnityEngine; using XLua; public class ByString : MonoBehaviour { LuaEnv lu ...
- HDU 6071 Lazy Running(最短路)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6071 [题目大意] 给出四个点1,2,3,4,1和2,2和3,3和4,4和1 之间有路相连, 现在 ...
- Exce信息提取
Exce信息提取 Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Sub 信息汇总( ...
随机推荐
- BZOJ2636: crisis(可持久化线段树)
传送门: 解题思路: 题目描述是一大坑点,cancel后面是直接加ask或者redo的. 那么就可以愉快地可持久化了. 注意需要支持区间修改,那么就只需要在再次更新这个点的时候将标记储存在新的儿子中. ...
- CentOS7 PXE安装批量安装操作系统
1.安装相关软件 yum -y install tftp-server httpd dhcp syslinux 2.配置DHCP cp /usr/share/doc/dhcp-4.2.5/dhcpd. ...
- crawlspider抽屉爬取实例+分布
创建项目 scrapy startproject choutiPro 创建爬虫文件 scrapy genspider -t crawl chouti www.xxx.com 进入pycharm 培训 ...
- IDEA集成Python插件,SDK配置
(第一次写在博客园添加随笔, 会有些生硬,有不对的地方和描述错误之处希望可以指出) 最近在学习一个新的知识点,涉及到Python的使用,因为第一次接触很多地方都不是很明白 ,好,废话不多说,现在直接上 ...
- [Python] Working with file
Python allows you to open a file, do operations on it, and automatically close it afterwards using w ...
- JumpServer 堡垒机 指南
堡垒机介绍 在一个特定网络环境下,为了保障网络和数据不受外界入侵和破坏,而运用各种技术手段实时收集和监控网络环境中每一个组成部分的系统状态.安全事件.网络活动,以便集中报警.及时处理及审计定责. ...
- web前端响应式布局,自适应全部分辨率
写phpd的我. 近期公司要弄个app关键是没有web开发,而我有比較闲,那就扛枪上阵吧. 响应式布局,web端的?php我一直都是用tp框架,对于web首先想到的是bootstrap框架.仅仅是简单 ...
- try {}里有一个return语句 finally执行顺序
先看例子 package example; class Demo{ public static void main(String args[]) { int x=1; System.out.print ...
- Flume的client
Client:生产数据,运行在一个独立的线程.
- dropdown下拉菜单
<!--声明方式的下拉菜单:三个要点--> <!--1 外围容器用dropdown包裹--> <!--2 内部点击事件data-toggle--> <!--3 ...