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

  1. [D3] Add label text

    If we want to add text to a node or a image // Create container for the images const svgNodes = svg ...

  2. [D3] Add image to the node

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

  3. 【精心推荐】几款实用的 JavaScript 图形图表库

    一款好的图表插件不是那么容易找到的.最近项目里需要实现统计图表功能,所以在网上搜罗了一圈,找到一些不错的图表插件,分享大家.众多周知,图形和图表要比文本更具表现力和说服力.这里给大家精心推荐几款实用的 ...

  4. 几款实用的 JavaScript 图形图表库

    一款好的图表插件不是那么容易找到的.最近项目里需要实现统计图表功能,所以在网上搜罗了一圈,找到一些不错的图表插件,分享大家.众多周知,图形和图表要比文本更具表现力和说服力.这里给大家精心推荐几款实用的 ...

  5. NAND FLASH ECC校验原理与实现

    ECC简介 由于NAND Flash的工艺不能保证NAND的Memory Array在其生命周期中保持性能的可靠,因此,在NAND的生产中及使用过程中会产生坏块.为了检测数据的可靠性,在应用NAND  ...

  6. Hat's Fibonacci(大数加法+直接暴力)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1250 hdu1250: Hat's Fibonacci Time Limit: 2000/1000 M ...

  7. Unity XLua 官方教程学习

    一.Lua 文件加载 1. 执行字符串 using UnityEngine; using XLua; public class ByString : MonoBehaviour { LuaEnv lu ...

  8. 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 之间有路相连, 现在 ...

  9. Exce信息提取

    Exce信息提取 Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Sub 信息汇总( ...

随机推荐

  1. file---探测给定文件的类型

    file命令用来探测给定文件的类型.file命令对文件的检查分为文件系统.魔法幻数检查和语言检查3个过程. 语法 file(选项)(参数) 选项 -b:列出辨识结果时,不显示文件名称: -c:详细显示 ...

  2. Python excel 功能扩展库 ——> openpyxl 的基本使用

    说明:本文档内容参考自 https://www.cnblogs.com/zeke-python-road/p/8986318.html (作者:关关雎鸠`)的文档 from openpyxl impo ...

  3. 洛谷 P1885 Moo

    P1885 Moo 题目描述 奶牛Bessie最近在学习字符串操作,它用如下的规则逐一的构造出新的字符串: S(0) = “moo” S(1) = S(0) + “m”+ “ooo” + S(0) = ...

  4. swift 创建第一个UIAlertView 和UIActionSheet

    //创建 UIActionSheet //一定要指明类型.不编译不通过 func ActionSheet(sender:UITapGestureRecognizer)     {         le ...

  5. PHP的模板引擎smarty原理是什么(整理)

    PHP的模板引擎smarty原理是什么(整理) 一.总结 一句话总结:其实所有的模板引擎的工作原理是差不多的,无非就是在php程序里面用正则匹配将模板里面的标签替换为php代码从而将两者混合为一个ph ...

  6. css3.0滚动条的优化

    .ass_showFriends{width: 93%;height: 8.35rem;overflow-y: auto;} .ass_showFriends::-webkit-scrollbar{w ...

  7. [BZOJ4555 TJOI2016 HEOI2016 求和]

    ​ 第一篇博客,请大家多多关照.(鞠躬 BZOJ4555 TJOI2016 HEOI2016 求和 题意: ​ 给定一个正整数\(n\)(\(1\leqq n \leqq100000\)),求: \[ ...

  8. linux 查找文件和文件夹与下载命令

    查找命令: 查找根目录下查找文件夹名称叫dir的目录地址 find / -name dir  -d 查找/var/www/目录下叫index.jsp的文件 find /var/www/ -name i ...

  9. 手机浏览器,微信浏览器对background-color不显示的问题

    PC上的浏览器可以正常显示,但是到了手机上就不显示了,古怪的问题花了我一晚上都没解决. 今天突然想到会不会是某些特立独行的了浏览器为了彰显个性,采用不同别人的解析方式呢? 我的原来CSS是这么写的: ...

  10. 小的时候.by小雷

    小的时候,总是有很多想法.   想去做,却做不成.   因为,自己小,被父母约束着,被学校圈着,被老师教育着. 想买个小霸王游戏机,没钱.在父辈的眼中,"游戏" ,游戏室,电脑游戏 ...