Skip to content

Commit cad7d77

Browse files
authored
Merge pull request #56 from bnmajor/loading-progress
feat(progress): Add progress circle and text while plugin is loading
2 parents 513fd77 + 35c144b commit cad7d77

File tree

8 files changed

+72
-6
lines changed

8 files changed

+72
-6
lines changed

client/index.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,18 @@
33
<head>
44
<meta charset="UTF-8" />
55
<link rel="icon" type="image/svg+xml" href="/favicon.png" />
6+
<link rel="stylesheet" type="text/css" href="/client/src/style.css" />
67
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
8+
<script defer type="text/javascript" src="https://cdn.jsdelivr.net/npm/[email protected]/dist/itkVtkViewer.js">
9+
var loading = true
10+
</script>
711
</head>
812
<body>
913
<div class="content" style="position: absolute; width: 100vw; height: 100vh; top: 0; left: 0; overflow: hidden; background: black; margin: 0; padding: 0;"></div>
10-
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/[email protected]/dist/itkVtkViewer.js"></script>
14+
<div id="loadingText" class="loadingText">
15+
TensorBoard 3D is loading, please wait...
16+
</div>
17+
<div id="loading" class="loading"/>
18+
<div id="progress" class="progress"/>
1119
</body>
1220
</html>

client/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"material-ui": "^0.20.2",
3131
"ndarray-pack": "^1.2.1",
3232
"react": "^17.0.2",
33-
"react-dom": "^17.0.2"
33+
"react-dom": "^17.0.2",
34+
"regenerator-runtime": "^0.13.9"
3435
}
3536
}

client/src/ImageSelector.jsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ function ImageSelector(props) {
1919
const component = state.context.images.selectedComponent;
2020
const actorContext = state.context.images.actorContext.get(name)
2121

22+
useEffect(() => {
23+
if (actorContext && window.loading) {
24+
toggleProgressCircle(false)
25+
}
26+
}, [actorContext])
27+
2228
useEffect(async() => {
2329
const counts = await fetchJSON(`../tensorboard_plugin_3d/images/count`);
2430
setImageCount(counts);
@@ -36,6 +42,12 @@ function ImageSelector(props) {
3642
}
3743
}, [name, component, actorContext])
3844

45+
const toggleProgressCircle = (state) => {
46+
window.loading = state
47+
let elem = document.getElementById('loading')
48+
elem.style.display = state ? 'block' : 'none'
49+
}
50+
3951
const changeImage = async (idx) => {
4052
if (idx < 1)
4153
idx = 1
@@ -53,6 +65,7 @@ function ImageSelector(props) {
5365
}
5466
return image_data
5567
})
68+
toggleProgressCircle(true)
5669
window.itkVtkViewer.createViewer(
5770
document.querySelector('.content'),
5871
{

client/src/main.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ function modifiedCreateInterface(context) {
2929
context.uiGroups = new Map()
3030
}
3131

32+
if (window.loading) {
33+
const elem = document.getElementById('loadingText')
34+
elem.style.display = 'none'
35+
}
36+
3237
ReactDOM.render(
3338
<React.StrictMode>
3439
<CollapseUIButton service={ context.service }/>

client/src/style.css

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,42 @@
5555
top: 35px !important;
5656
max-width: 400px;
5757
}
58+
59+
.progress {
60+
color: white;
61+
font-size: 200%;
62+
height: 100vh;
63+
width: 100vw;
64+
text-align: center;
65+
vertical-align: middle;
66+
line-height: 100vh;
67+
}
68+
69+
.loading {
70+
border: 16px solid #f3f3f3; /* Light grey */
71+
border-top: 16px solid #3498db; /* Blue */
72+
border-radius: 50%;
73+
width: 120px;
74+
height: 120px;
75+
position: absolute;
76+
left: calc(50% - 60px);
77+
top: calc(50% - 60px);
78+
animation: spin 2s linear infinite;
79+
box-sizing: border-box;
80+
overflow: hidden;
81+
}
82+
83+
@keyframes spin {
84+
0% { transform: rotate(0deg); }
85+
100% { transform: rotate(360deg); }
86+
}
87+
88+
.loadingText {
89+
position: fixed;
90+
top: calc(50% + 80px);
91+
font-size: xx-large;
92+
color: white;
93+
text-align: center;
94+
width: 100%;
95+
font-style: italic;
96+
}

client/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const isDev = process.env.NODE_ENV !== 'production'
66

77
module.exports = {
88
mode: isDev ? 'development' : 'production',
9-
entry: './src/index.js',
9+
entry: ['regenerator-runtime/runtime.js', './src/index.js'],
1010
output: {
1111
path: path.resolve(__dirname, 'dist'),
1212
filename: 'index.js'

client/yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4642,7 +4642,7 @@ regenerator-runtime@^0.11.0:
46424642
resolved "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz"
46434643
integrity sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==
46444644

4645-
regenerator-runtime@^0.13.4:
4645+
regenerator-runtime@^0.13.4, regenerator-runtime@^0.13.9:
46464646
version "0.13.9"
46474647
resolved "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.9.tgz"
46484648
integrity sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA==

tensorboard_plugin_3d/static/index.html

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)