- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一张 map ,每个国家/地区的中心都有一个圆圈。在 general update pattern 之后,我应用了一个每 3 秒更新一次圆圈的动画。迈克博斯托克。然而,我的问题是我想对留在图表中的旧元素应用转换(即不属于 exit()
的一部分),但仅适用于那些在特定方面有变化的元素属性(因为这个属性定义了圆的颜色)。我想我应该将旧值作为一个属性存储在圆圈中,然后将这个属性值与更新数据中新分配的值进行比较。
但是,当我使用普通的 js if
子句时,它只为我提供了第一个元素,这意味着当这个圆圈的值发生变化时,所有其他圆圈也会进行转换。
我如何检查此模式中的旧值和新值?
这是一个示例代码:
//DATA JOIN
var countryCircles = circleCont.selectAll(".dataCircle")
.data(filData, function(d){ return d.id})
//EXIT OLD CIRCLES THAT ARE NOT INCLUDED IN NEW DATASET
countryCircles.exit()
.transition()
.ease(d3.easeLinear)
.duration(500)
.attr("r",0)
.remove()
//CHECK IF OLD CIRCLES THAT ARE INCLUDED CHANGED THE CRITICAL ATTRIBUTE VALUE (main)
if (countryCircles.attr('main') != countryCircles.data()[0].main) {
countryCircles
.attr("main", function(d) {return d.main})
.attr("id", function(d) {return "circle" + d.id})
.attr("class","dataCircle")
.transition()
.ease(d3.easeLinear)
.duration(500)
.ease(d3.easeLinear)
.attr("r",0)
.transition()
.duration(500)
.ease(d3.easeLinear)
.attr("r",10)
.style("fill", function(d) {
if (d.main === "nodata") {
return "grey"
} else {
return color_data.find(function (y) {
return y.main === d.main;
}).color;
}
})
} else {
countryCircles
.attr("main", function(d) {return d.main})
.attr("id", function(d) {return "circle" + d.id})
.attr("class","dataCircle")
}
//CREATE CIRCLES THAT ARRE NEW IN THE UPDATED DATASET
var newCircle = countryCircles.enter()
.append("circle")
.attr("class","dataCircle")
.attr("cx", getCX)
.attr("cy", getCY)
.attr("id", function(d) {return "circle" + d.id})
.attr("main", function(d) {return d.main})
.style("cursor","crosshair")
.attr("r", 0)
.transition()
.delay(500)
.duration(500)
.ease(d3.easeLinear)
.attr("r",10)
.style("fill", function(d) {
if (d.main === "nodata") {
return "grey"
} else {
return color_data.find(function (y) {
return y.main === d.main;
}).color;
}
})
最佳答案
好吧,解决方案有点直截了当(我是盲人......)。
我没有对单个元素使用 if 语句,而是使用 each()
函数并在其中检查更改。
...
//CHECK IF OLD CIRCLES THAT ARE INCLUDED CHANGED THE CRITICAL ATTRIBUTE VALUE (main)
countryCircles.each(function(d) {
if (d3.select(this).attr('main') != d3.select(this).data()[0].main) {
...
关于javascript - d3 v5 : How to transition only when a specific attribute changed?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56905954/
我正在 sitepoint 上阅读一篇文章 - http://www.sitepoint.com/how-to-create-mysql-events/关于mysql事件的主题,当你可以安排时我遇到了
我想为用户预订一个特定的时间(开始时间和结束时间),其他人不能在同一时间预订。例如:John预约了一个月5号7点到8点的时间,我想没有其他人可以在同一时间和日期预订。我想查一下时段,因为如果像John
I want to book a specific time for the user (start hour and end hour ) and no one else can book a
我已经克隆了 linux 内核 git 仓库: git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 我
我正在尝试获取下面突出显示的文本“frei ab 01.05.2017”。然而问题是,“section_content iw_right”类在该网站上出现了 19 次。我会执行 find_all 并仅
我尝试找到这个问题,但所有其他问题都与我的问题无关。 我的问题:我有类似 0xFreeFoodU 的东西,我必须获得特定的位置,然后翻转它们或将它们设为 1 或 0。 例如,位置 2、6、10、14、
我正在尝试创建一个登录功能,该功能允许我指定要从中选择数据的表以及要选择的字段。我已设法将表值传递给函数,并从所需的表中选择数据,但我的表有不同的字段。如何在查询中指定它是一个表选择: user_id
我是 Rails 的新手,在获取布局(用作唯一的静态登录页面)来加载我想与之关联的特定样式表时遇到了问题。例如:www.landing.com 加载landing.scss.erb . 作为背景,所有
我不明白为什么这两个示例的行为不同。 HTML 和 CSS 的目的只是简单地水平对齐 div,并让最后一个 div(向右)占据剩余空间(容器的剩余宽度)。 为正确的元素使用特定的 id: #left
我是 postfix 的新手。如何使用限制类或其他方法将特定用户的特定域列入黑名单。 假设我的机器有两个用户 - user1 和 user2。 我想将abc.com 到user1@mydomain 的
当记事本是 .txt 文件的默认程序时,我如何告诉 Windows 在写字板中打开 C:\test\test.txt? 最佳答案 接受的答案对我不起作用。我不确定这是因为我试图运行的程序,还是因为路径
对于下面的代码示例,我需要检查一个 tr ,type="a"并且有一个带有文本“3”作为 child 的 td ,是否存在: 1 1
var s = '-10px -10px'; var n = '33px'; 我需要一个产生这个结果的正则表达式:'-10px 33px' 类似于:s.replace(???, n) 最佳答案 如果您
一个项目 table: items 有许多分类法 table: taxonomies 使用连接表 item_taxonomies (item_id, taxonomy_id)。 使用分类组搜索项目。
h:panelGrid 表有 2 列。 这是必需的,第一列为整个表格宽度的 30%,第二列为整个表格宽度的 70%。 这种情况有一些配置吗?看起来 columnClasses 属性应用于所有列, 并且
特定阶段仅在特定计算机上卡在队列中 显示队列中的位置:1,但无法连接到代理,即使没有其他作业正在运行且队列为空 所有其他阶段都工作正常 故障阶段在不同的机器上工作正常 代理已在线并已启用 我们所有的代
我正在使用 CakePHP 3.3.10。我需要将 JavaScript 文件添加到特定 View 。 // default.ctp // I need to remove this script
首先,我发现提出问题很困难,欢迎反馈。 我必须制作一个机器学习代理来玩点和盒子。 我还处于早期阶段,但提出了一个问题:如果我让我的机器学习代理(具有特定的实现)与它自身的副本进行对抗来学习和改进它的游
我是开发 iOS 应用程序的新手,英语不是我的母语,所以请原谅我的任何错误和丑陋的代码。 我尝试创建的应用程序应该只在特定的一天显示一张特定的图像(如果日期更改,则更改图像)。因此我实现了一个检查日期
我写了一些函数,并编译成一个dll模块。在我的头文件中如下: #ifndef GET_DATAFEED_FORKDB_H #define GET_DATAFEED_FORKDB_H #include
我是一名优秀的程序员,十分优秀!