- Expert Data Visualization
- Jos Dirksen
- 179字
- 2021-07-09 18:22:42
Removing elements which aren't needed anymore
The final step we need to take is to remove rectangles that aren't needed anymore. If in the first call to update we add five rectangles, and in the next call only three are needed, we're stuck with two leftover ones. D3 also has an elegant mechanism to deal with that:
rectangles.exit().remove();
The call to exit() will select the elements for which no data is available. We can then do anything we want with those rectangles. In this case, we just remove them by calling remove(), but we could also change their opacity to make them look transparent, or animate them to slowly disappear.
For instance, if we replace the previous line of code with this:
rectangles.exit().attr("class", "remove");
Then set the CSS for the remove class to this:
.remove {
fill: red;
opacity: 0.2;
}
In that case, we'd see the following:

In the preceding screenshot, we've reused two existing rectangles, and instead of removing the five we don't need, we change their style to the remove class, which renders them semi-transparent red.
- Reporting with Visual Studio and Crystal Reports
- Testing with JUnit
- SOA實(shí)踐
- MongoDB for Java Developers
- 高級(jí)C/C++編譯技術(shù)(典藏版)
- Teaching with Google Classroom
- SQL基礎(chǔ)教程(第2版)
- Building Android UIs with Custom Views
- Multithreading in C# 5.0 Cookbook
- R語言數(shù)據(jù)可視化:科技圖表繪制
- Building Dynamics CRM 2015 Dashboards with Power BI
- 從0到1:HTML5 Canvas動(dòng)畫開發(fā)
- C#面向?qū)ο蟪绦蛟O(shè)計(jì)(第2版)
- Python硬件編程實(shí)戰(zhàn)
- 數(shù)據(jù)結(jié)構(gòu):Python語言描述