[D3] Reuse Transitions in D3 v4

D3 transitions start executing as soon as they’re created, and they’re destroyed once they end. This can present some challenges when attempting to create reusable transitions. This lesson demonstrates how to overcome those challenges using various approaches to reusable transitions.

We can put reuseable transtion into a function, then use .call() method to use that transition.

d3.select(‘#block‘)
    .transition()
        .call(configure, 200, 600, d3.easePolyOut)
        .style(‘width‘, ‘400px‘)
    .transition()
        .call(configure, 0, 600, d3.easeBounceOut)
        .style(‘height‘, ‘500px‘)
    .transition()
        .call(configure, 0, 1200, d3.easeQuadOut)
        .style(‘background-color‘, ‘gold‘) ;

function configure (transition, delay, duration, ease) {
    return transition.delay(delay).duration(duration).ease(ease);
}
    
时间: 2024-12-09 03:05:05

[D3] Reuse Transitions in D3 v4的相关文章

D3.js 入门学习(二) V4的改动

//d3.scan /* 新的d3.scan方法对数组进行线性扫描,并根据指定的比较函数返回至少一个元素的索引. 这个方法有点类似于d3.min和d3.max. 而d3.scan可以得到极值的索引而不仅仅是计算极值. */ var a1 = [1,3,5,2,9]; var i = d3.scan(a1,function(a,b){ return b-a; // 返回最大值的索引, a-b; 返回最小值的索引 }); console.log(i); //4; //d3.ticks d3.tick

D3学习之:D3.js中的12中地图投影方式

特别感谢:1.[张天旭]的D3API汉化说明,已被引用到官方网站: 2.[馒头华华]提供的ourd3js.com上提供的学习系列教程,让我们这些新人起码有了一个方向. 不得不说,学习国外的新技术真的是一个很艰苦的过程. 在学习D3绘制地图的过程中,有朋友建议看一下其中投影的说明比较好,于是,凭借我这半吊子不到的英文水平,大致给翻译了下来,仅供参考: 原文链接:https://github.com/mbostock/d3/wiki/Geo-Projections#albers D3中一共提供了12

[D3] 12. Basic Transitions with D3

<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script src="../bower_components/underscore/underscore-min.js"></script> <script src="../v

[D3] Basic Interactivity with D3 v4

Data visualizations are a lot more interesting when they’re interactive. Whether it’s clicks, roll overs, or drags, it makes things more compelling, and D3 is up to the task. This lesson demonstrates how to implement basic interactions and shows how

d3.js 颜色比例尺 d3.scale.category10();

var width = 600; var height = 600; var dataset = d3.range(10); //返回[0,1,2,3,4,5,6,7,8,9] console.log(dataset); // 定义表示颜色的序数比例尺 var color = d3.scale.category10(); var svg = d3.select("body").append("svg") .attr("width",width)

[D3] Build a Line Chart with D3 v4

Line charts are often used to plot temporal data, like a stock price over time. In this lesson we’ll see how to use D3 APIs to create our own simplified version of the charts seen on Google Finance. var margin = { top: 10, right: 20, bottom: 65, left

[D3] Create Chart Axes with D3 v4

Most charts aren’t complete without axes to provide context and labeling for the graphical elements being displayed. This lesson introduces D3’s APIs for creating, customizing, and displaying axes while building on topics from previous lessons. var m

[D3] Build a Scatter Plot with D3 v4

Scatter plots, sometimes also known as bubble charts, are another common type of visualization. They’re extremely versatile thanks to their ability to display multiple dimensions of data simultaneously using x and y position, opacity, color, and even

D3.js Data-Driven Documents

D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to life using HTML, SVG, and CSS. D3’s emphasis on web standards gives you the full capabilities of modern browsers without tying yourself to a proprietar