当标签在背景中时,使用d3.js绘制SVG [英] Drawing a SVG with d3.js while tab is in background

查看:36
本文介绍了当标签在背景中时,使用d3.js绘制SVG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文:我正在开发一个Web应用程序,该应用程序必须显示一些相当复杂且不断更新(每秒多次)的SVG图像.该更新来自单独的服务器,并且只要Web前端收到更新,SVG便会更新.该Web应用程序是用 Scala.js 编写的,并且该图像是使用

Context: I am working on a webapp that has to display some fairly complicated and constantly updating (multiple times per second) SVG images. The updates stem from a seperate server and the SVG is updates as soon as an update is received by the web frontend. The webapp is written in Scala.js and the image is created using the d3js library (see also: scala-js-d3). We currently only support Google Chrome.

问题:该Web应用程序进入后台标签一段时间后,一旦再次导航到整个网站,该站点将无响应.根据应用程序在后台运行的时间长短,有时可能需要20秒才能使应用程序再次响应.有什么办法可以解决这个问题?

Problem: Once the webapp has been in a background tab for a while, the whole site gets unresponsive once navigated to again. Depending on how long the app was in the background, it sometimes takes up to 20 seconds for the application to be responsive again. Is there any way I can solve this?

推荐答案

最适合我的解决方案是一个非常简单的解决方案:

The solution that works best for me is a pretty simple one:

一旦应用程序位于背景标签中或最小化(可以使用

Once the application is in a background tab or minimized (can be detected using the Page Visibility API), I only update my model without drawing anything. Then, once the application is put into the foreground again, I re-draw everything. This fixed all of my performance problems.

这篇关于当标签在背景中时,使用d3.js绘制SVG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆