Skip to content

Commit d11e4d5

Browse files
authored
Merge pull request #21 from Kitware/extend-pure-js-docs
Extend pure js guide
2 parents b61d932 + dc56290 commit d11e4d5

File tree

23 files changed

+2052
-158
lines changed

23 files changed

+2052
-158
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
node_modules
22
docs/.vitepress/dist
33
docs/.vitepress/cache
4+
docs/public/demo/playground
5+
docs/public/demo/simple-app
46
examples/cpp/vtk
57
examples/cpp/*/build
68
dist

docs/.vitepress/config.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@ export default defineConfig({
8686
text: "For JavaScript developers",
8787
items: [
8888
{ text: "Getting started", link: "/guide/js/" },
89-
{ text: "Plain JavaScript", link: "/guide/js/plain" },
90-
{ text: "Building an application", link: "/guide/js/bundler" },
89+
{ text: "Working With Objects", link: "/guide/js/objects" },
90+
{ text: "Observers", link: "/guide/js/observers" },
91+
{ text: "HTML Script Tag", link: "/guide/js/plain" },
92+
{ text: "Bundler Integration", link: "/guide/js/bundler" },
9193
],
9294
},
9395
{

docs/guide/js/bundler.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Modern JavaScript development
1+
# Bundler Integration
22

33
Modern web development rely on package manager to bring project dependencies. This section covers how published releases can be used within a JavaScript project.
44

docs/guide/js/index.md

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
1-
# VTK.wasm from the JavaScript side
1+
# VTK.wasm from JavaScript
22

3-
While VTK is a comprehensive C++ library, WASM is giving us an opportunity to enable it on servers and clients like your browser.
3+
This guide focuses on using the VTK WASM bundle from plain JavaScript, requiring no prior C++ knowledge.
44

5-
In this guide we will focus on how WASM can be used from plain JavaScript without any C++ knowledge and using the WASM bundle generated for our trame needs.
5+
## Overview
6+
Most C++ classes from the [VTK C++ Documentation](https://vtk.org/doc/nightly/html/) are available through a single JavaScript object, which we refer to as the **vtk** namespace.
67

7-
## Available environment
8+
Once you have access to the **vtk** namespace (see [Bundler Integration](./bundler.md)), you can interact with VTK classes using standard JavaScript.
89

9-
Web development has many faces between ESM, UMD and plain script usage. Each path is different to some extent so we will cover each of them in their own guide.
10+
## The Why
1011

11-
- Plain JavaScript usage
12-
- Using modern bundler
12+
VTK is a powerful library with a somewhat steep learning curve, but VTK.wasm allows you to use VTK without needing to learn C++. This can be particularly beneficial for web developers who are already familiar with JavaScript and want to integrate advanced visualization capabilities into their web applications.
1313

14-
## What does it looks like?
15-
16-
Since our WASM bundle is based on our trame needs, it currently mainly focus on the rendering stack (PolyData, Mappers and Actors...) but we plan to extend it with more VTK class coverage down the road.
17-
18-
So if we ignore how to get your hand on a __vtk__ namespace (see section above), you will be able to write code like below to interact with the available VTK classes in plain JavaScript.
19-
20-
<<< ../../public/demo/example.js
21-
22-
Result:
23-
24-
<iframe src="/vtk-wasm/demo/plain-javascript.html" style="width: 100%; height: 40vh; border: none;"></iframe>
14+
The following sections will guide you through the essential aspects of using VTK.wasm with JavaScript:
2515

16+
- [Working With Objects](./objects.md)
17+
- [Observers](./observers.md)
18+
- [HTML Script Tag](./plain.md)
19+
- [Bundler Integration](./bundler.md)

docs/guide/js/objects.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Working With Objects
2+
3+
You can create and manipulate VTK objects using the **vtk** namespace. Here's an example that shows how you can create and manipulate VTK objects in JavaScript:
4+
5+
<iframe src="/vtk-wasm/demo/playground/index.html?example=objects" style="width: 100%; height: 51vh; border: none;"></iframe>

docs/guide/js/observers.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Observers
2+
3+
Listen to events on an object using the observe method. Remove observers by passing the 'tag' back to `object.unObserve` method.
4+
5+
<iframe src="/vtk-wasm/demo/playground/index.html?example=observers" style="width: 100%; height: 90vh; border: none;" scrolling="no"></iframe>

docs/guide/js/plain.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Plain JavaScript
1+
# HTML Script Tag
2+
3+
This guide explains how to use VTK-Wasm directly in an HTML file using a `<script>` tag without a build step.
24

35
The following examples rely on loading the `vtk.umd.js` bundle from a CDN. Also to mainly focus on the initialization part, we've externalized the JS/WASM code since that part does not change.
46

docs/public/demo/simple-app/assets/index-BKpEjZ8W.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

docs/public/demo/simple-app/assets/index-XX6AMuQ-.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/public/demo/simple-app/index.html

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)