In D3, the General Update Pattern is the name given to what happens when a data join is followed by operations on the enter, update, and exit selections. When a chart's data changes over time and each update can both create new elements and destroy existing ones, the General Update pattern can help convey meaning to users. This lesson demonstrates the pattern using animated transitions on a column chart.

function render(subject = 'math') {

    // Define a resuable transation variable
var t = d3.transition().duration(); var update = svg.selectAll('rect')
.data(data.filter(d => d[subject]), d => d.name); //d => d.name is a uniq idientifier // First: we want to remove the existing object which doesn't have any value
// Get rid of null value object
// Also animation y and height attr to produce
// fade out effect
update
.exit()
.transition(t)
.attr('y', height)
.attr('height', )
.remove(); // Second, we want to animate the existing elements height
update
.transition(t)
.delay()
.attr('y', d => yScale(d[subject]))
.attr('height', d => height - yScale(d[subject])); // Last, for the new data which is not in the page before
// We want to animate
update
.enter()
.append('rect')
.attr('y', height)
.attr('height', )
.attr('x', d => xScale(d.name))
.attr('width', d => xScale.bandwidth())
.transition(t)
.delay(update.exit().size() ? : ) // If page refresh, we don't want to wait 2000ms
.attr('y', d => yScale(d[subject]))
.attr('height', d => height - yScale(d[subject]));
} render();

[D3] Animate with the General Update Pattern in D3 v4的更多相关文章

  1. [D3] Animate Transitions in D3 v4

    D3 makes it easy to add meaningful animations to your data visualizations. Whether it’s fading in ne ...

  2. [D3] Animate Chart Axis Transitions in D3 v4

    When the data being rendered by a chart changes, sometimes it necessitates a change to the scales an ...

  3. D3.js系列——动态效果和Update、Enter、Exit的理解

    一.动态效果 D3 支持制作动态的图表.有时候,图表的变化需要缓慢的发生,以便于让用户看清楚变化的过程,也能给用户不小的友好感. 1.什么是动态效果 前面制作的图表是一蹴而就地出现,然后绘制完成后不再 ...

  4. d3代码如何改造成update结构(恰当处理enter和exit)

    d3的enter和exit 网上有很多blog讲解.说的还凑合的见:https://blog.csdn.net/nicolecc/article/details/50786661 如何把自己的rude ...

  5. [D3] Better Code Organization with selection.call() with D3 v4

    Most of D3’s native selection APIs also return the selection (or a new selection), to enable multipl ...

  6. [D3] SVG Graphics Containers and Text Elements in D3 v4

    SVG is a great output format for data visualizations because of its scalability, but it comes with s ...

  7. D3中动画(transition函数)的使用

    关于transition的几个基本点: 1. transition()是针对与每个DOM element的,每个DOM element的transition并不会影响其他DOM element的tra ...

  8. d3.js在vue项目中的安装及案例

    1. 安装: npm i d3 --save 2. 引入:main.js import * as d3 from "d3"; Vue.prototype.$d3 = d3; win ...

  9. d3js enter/exit深入了解

    在 Data joins 章节我们演示了当data和dom element个数相同时的情况 <div id="content"> <div></div ...

随机推荐

  1. python之路:发附带文件的邮件

    发邮件的思路(借用第三方服务): 1.模拟服务器,其中有:服务器地址,发送者地址.发送者的密码 2.创建一个带附件的实例:1.创建一个massage 2.massage包括发送者的地址.接受者的地址. ...

  2. jQuery判断字符串是否含有中文字符

    //判断字符串是不是中文String.prototype.isChinese = function () {    var reg = /[^\x00-\xff]/ig;//判断是否存在中文和全角字符 ...

  3. 【shell学习】经常使用条件推断-字符,数字,文件

    IF 推断 之前也写过简单的shell脚本,也不是转职运维.和系统相关的工作比較少.所以不怎么熟练. 近期因为系统总是出现各种乱七八糟的问题,也没有人来协助.仅仅好自己写shell脚本了,都是些基础的 ...

  4. KETTLE使用javascript步骤过滤特殊字符

    KETTLE使用javascript步骤过滤特殊字符 使用kettle在抽取大量excel数据时.总是遇到excel中有一些特殊字符,导致ExecuteSQL script步骤运行失败,本文记录一些方 ...

  5. 调用google翻译

    1. [代码]maven依赖     ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <dependency>     <groupId>org.a ...

  6. ASP.NET WebAPI RC 竟然不支持最常用的json传参

    壮士断腕(WCF Web API),为的是 ASP.NET Web API 的横空出世,再加上它的开放(开源),于是对之产生了一点点痴情,并写下了HttpClient + ASP.NET Web AP ...

  7. spark源码阅读

    根据spark2.2的编译顺序来确定源码阅读顺序,只阅读核心的基本部分. 1.common目录 ①Tags②Sketch③Networking④Shuffle Streaming Service⑤Un ...

  8. vue+mui+html5+ plus开发的混合应用底部导航的显示与隐藏

    1. 模板相关内容(template) <template> <div> <transition :name="transitionName"> ...

  9. deep-in-es6(五)

    解构 Destructuring: 解构赋值允许使用类似数组或对象字面量的语法将数组和对象的属性赋值给给中变量. 一般情况访问数组中的前三个元素: var first = arr[0]; var se ...

  10. Java中Thread源码剖析

    本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 关于线程,用很长时间了,主线程下的子线程去做一些事情,就是一个代理模式,主线程分代理权给子线程,子线 ...