[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 信息汇总( ...
随机推荐
- 通用查询实现方案(可用于DDD)[附源码] -- 设计思路
原文:通用查询实现方案(可用于DDD)[附源码] -- 设计思路 [声明] 写作不易,转载请注明出处(http://www.cnblogs.com/wiseant/p/3988592.html). ...
- Swift学习笔记(4)--字符串及基本使用
String是例如“hello, world”,“海贼王” 这样的有序的Character(字符)类型的值的集合,通过String类型来表示. Swift 的String类型与 Foundation ...
- Mysql学习总结(9)——MySql视图原理讲解与使用大全
一. 视图概述 视图是一个虚拟表,其内容由查询定义.同真实的表一样,视图包含一系列带有名称的列和行数据.但是,视图并不在数据库中以存储的数据值集形式存在.行和列数据来自由定义视图的查询所引用的表,并且 ...
- FZU 1968 Twinkling lights III
Twinkling lights III Time Limit: 8000ms Memory Limit: 131072KB This problem will be judged on FZU. O ...
- codevs——T1006 等差数列
http://codevs.cn/problem/1006/ 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Descr ...
- Quartus II sof文件转 jic文件
选择File->Convert Programming Files... Programming File Type选择JTAG Indirect ConfigurationFile(.jic) ...
- PhoneGap/Cordova Android应用签名公布注意事项
今天最终要公布Android HybirdApp了,安装曾经做原生应用的流程公布签名Apk,没想到立即遇到了几个问题.如今把它们的解决的方法整理下来. export signed Apk 遇到以下错误 ...
- 最小生成树-并查集-Kruskal-zoj-2048-special judge
Highways description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has a ...
- Unity3D:粒子系统Particle System
1. GameObject → Create Other → Particle System. 2. 选中 Particle System,可看到下列屬性: 3.Particle System: ...
- 实用的 Python 包 —— 使用 win32 的剪贴板
1. usage >> import win32clipboard >> win32clipboard.OpenClipboard() >> win32clipbo ...