- 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.
- Raspberry Pi for Python Programmers Cookbook(Second Edition)
- .NET 4.0面向對象編程漫談:基礎篇
- FFmpeg入門詳解:音視頻流媒體播放器原理及應用
- Wireshark Network Security
- RTC程序設計:實時音視頻權威指南
- Java應用開發技術實例教程
- Visual C#通用范例開發金典
- Getting Started with Nano Server
- Buildbox 2.x Game Development
- Advanced UFT 12 for Test Engineers Cookbook
- 奔跑吧 Linux內核
- Android技術內幕(系統卷)
- MongoDB Administrator’s Guide
- 系統分析師UML用例實戰
- Java EE框架開發技術與案例教程