Skip to content

Commit

Permalink
doc(Example): Improve progress handler
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdain committed Feb 28, 2018
1 parent 541fed7 commit 91a67c5
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 16 deletions.
15 changes: 11 additions & 4 deletions Examples/Applications/GeometryViewer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import 'vtk.js/Sources/favicon';

import macro from 'vtk.js/Sources/macro';
import HttpDataAccessHelper from 'vtk.js/Sources/IO/Core/DataAccessHelper/HttpDataAccessHelper';
import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor';
import vtkColorMaps from 'vtk.js/Sources/Rendering/Core/ColorTransferFunction/ColorMaps';
Expand Down Expand Up @@ -402,10 +403,16 @@ export function load(container, options) {
container.appendChild(progressContainer);

const progressCallback = (progressEvent) => {
const percent = Math.floor(
100 * progressEvent.loaded / progressEvent.total
);
progressContainer.innerHTML = `Loading ${percent}%`;
if (progressEvent.lengthComputable) {
const percent = Math.floor(
100 * progressEvent.loaded / progressEvent.total
);
progressContainer.innerHTML = `Loading ${percent}%`;
} else {
progressContainer.innerHTML = macro.formatBytesToProperUnit(
progressEvent.loaded
);
}
};

createViewer(container);
Expand Down
16 changes: 12 additions & 4 deletions Examples/Applications/OBJViewer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import 'vtk.js/Sources/favicon';
import JSZip from 'jszip';

import macro from 'vtk.js/Sources/macro';

import HttpDataAccessHelper from 'vtk.js/Sources/IO/Core/DataAccessHelper/HttpDataAccessHelper';
import vtkFullScreenRenderWindow from 'vtk.js/Sources/Rendering/Misc/FullScreenRenderWindow';
import vtkURLExtract from 'vtk.js/Sources/Common/Core/URLExtract';
Expand Down Expand Up @@ -164,10 +166,16 @@ export function load(container, options) {
container.appendChild(progressContainer);

const progressCallback = (progressEvent) => {
const percent = Math.floor(
100 * progressEvent.loaded / progressEvent.total
);
progressContainer.innerHTML = `Loading ${percent}%`;
if (progressEvent.lengthComputable) {
const percent = Math.floor(
100 * progressEvent.loaded / progressEvent.total
);
progressContainer.innerHTML = `Loading ${percent}%`;
} else {
progressContainer.innerHTML = macro.formatBytesToProperUnit(
progressEvent.loaded
);
}
};

HttpDataAccessHelper.fetchBinary(options.fileURL, {
Expand Down
15 changes: 11 additions & 4 deletions Examples/Applications/SceneExplorer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import 'vtk.js/Sources/favicon';

import macro from 'vtk.js/Sources/macro';
import DataAccessHelper from 'vtk.js/Sources/IO/Core/DataAccessHelper';
import HttpDataAccessHelper from 'vtk.js/Sources/IO/Core/DataAccessHelper/HttpDataAccessHelper';
import vtkFullScreenRenderWindow from 'vtk.js/Sources/Rendering/Misc/FullScreenRenderWindow';
Expand Down Expand Up @@ -77,10 +78,16 @@ export function load(container, options) {
container.appendChild(progressContainer);

const progressCallback = (progressEvent) => {
const percent = Math.floor(
100 * progressEvent.loaded / progressEvent.total
);
progressContainer.innerHTML = `Loading ${percent}%`;
if (progressEvent.lengthComputable) {
const percent = Math.floor(
100 * progressEvent.loaded / progressEvent.total
);
progressContainer.innerHTML = `Loading ${percent}%`;
} else {
progressContainer.innerHTML = macro.formatBytesToProperUnit(
progressEvent.loaded
);
}
};

HttpDataAccessHelper.fetchBinary(options.fileURL, {
Expand Down
15 changes: 11 additions & 4 deletions Examples/Applications/VolumeViewer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import 'vtk.js/Sources/favicon';

import macro from 'vtk.js/Sources/macro';
import HttpDataAccessHelper from 'vtk.js/Sources/IO/Core/DataAccessHelper/HttpDataAccessHelper';
import vtkBoundingBox from 'vtk.js/Sources/Common/DataModel/BoundingBox';
import vtkColorTransferFunction from 'vtk.js/Sources/Rendering/Core/ColorTransferFunction';
Expand Down Expand Up @@ -191,10 +192,16 @@ export function load(container, options) {
container.appendChild(progressContainer);

const progressCallback = (progressEvent) => {
const percent = Math.floor(
100 * progressEvent.loaded / progressEvent.total
);
progressContainer.innerHTML = `Loading ${percent}%`;
if (progressEvent.lengthComputable) {
const percent = Math.floor(
100 * progressEvent.loaded / progressEvent.total
);
progressContainer.innerHTML = `Loading ${percent}%`;
} else {
progressContainer.innerHTML = macro.formatBytesToProperUnit(
progressEvent.loaded
);
}
};

HttpDataAccessHelper.fetchBinary(options.fileURL, {
Expand Down

0 comments on commit 91a67c5

Please sign in to comment.