Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit e1f46a1

Browse files
committed
Adding documentation for example pages, cleanup
1 parent 99efae6 commit e1f46a1

15 files changed

+180
-58
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ dist/
1212
node_modules/
1313
.DS_Store
1414
.env
15-
package-lock.json
15+
package-lock.json

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ If you'd like to add your own customization on top of our baseline, then you can
4141

4242
## Further Reading
4343

44-
API Reference - https://forge.autodesk.com/en/docs/dataviz/v1/reference/UI/
44+
API Reference - https://forge.autodesk.com/en/docs/dataviz/v1/reference/Core/
4545

4646
## License
4747

client/config/SensorStyles.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import co2Svg from "../../assets/images/co2_property.svg";
66

77
export const SpriteSize = 24;
88

9+
/**
10+
* @type {SensorStyleDefinitions}
11+
*/
912
export const SensorStyleDefinitions = {
1013
default: {
1114
url: circleSvg,

client/pages/AnimatedSprites.jsx

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ const sensorPositions = {
108108
/**
109109
* @component
110110
* @param {Object} props
111+
* @param {Object} props.appData Data passed to the AnimatedSprites.
112+
* @param {("AutodeskStaging"|"AutodeskProduction")} props.appData.env Forge API environment
113+
* @param {string} props.appData.docUrn Document URN of model
114+
*
115+
* @memberof Autodesk.DataVisualization.Examples
116+
* @alias Autodesk.DataVisualization.Examples.AnimatedSprites
111117
*/
112118
function AnimatedSprites(props) {
113119
const { env, docUrn } = props.appData;
@@ -119,18 +125,8 @@ function AnimatedSprites(props) {
119125
/**
120126
* Generates simulation data used for this sample app
121127
*
122-
* @returns {Object} The resulting simulation data in the following form:
123-
*
124-
* const obj = [
125-
* {
126-
* id: "Cafeteria",
127-
* position: { x: -143.3017, y: 87.1875, z: -16.9196 },
128-
* type: "thermometer",
129-
* sensorTypes: ["temperature"],
130-
* },
131-
* ...
132-
* ];
133-
*
128+
* @returns {Array.<SimulationData>} The resulting array of simulation data objects.
129+
* @alias Autodesk.DataVisualization.Examples.AnimatedSprites#generateSimulationData
134130
*
135131
*/
136132
function generateSimulationData() {
@@ -151,8 +147,9 @@ function AnimatedSprites(props) {
151147
* Generates viewables to be added to the view. These viewables are sprite-based objects
152148
* in the 3D viewer canvas, each representing a physical sensor in the real world.
153149
*
154-
* @param {Object} dataItems The simulation data generated in 'generateSimulationData'.
155-
* @returns {ViewableData} The resulting viewable data that carries all viewables.
150+
* @param {Array.<SimulationData>} dataItems The simulation data generated in 'generateSimulationData'.
151+
* @returns {Autodesk.DataVisualization.Core.ViewableData} The resulting viewable data that carries all viewables.
152+
* @alias Autodesk.DataVisualization.Examples.AnimatedSprites#generateViewableData
156153
*/
157154
async function generateViewableData(dataItems) {
158155
// Create a visual style shared by all the thermometers since they're the same type.
@@ -165,7 +162,7 @@ function AnimatedSprites(props) {
165162
fan00
166163
);
167164

168-
165+
169166
fans.forEach((fan) => ductFanStyle.preloadSprite(fan));
170167

171168
const motionStyle = new dataVizExtn.ViewableStyle(
@@ -211,6 +208,12 @@ function AnimatedSprites(props) {
211208
return viewableData;
212209
}
213210

211+
/**
212+
* Determines a random set of viewable ids that will be animated.
213+
*
214+
* @param {Autodesk.DataVisualization.Core.SpriteViewable[]} viewables
215+
* @returns {number[]}
216+
*/
214217
function getViewableIdsToAnimate(viewables) {
215218
let indices = viewables.map((v) => v.dbId);
216219
indices = indices.sort(() => Math.random() - 0.5); // Shuffle the list.
@@ -221,8 +224,9 @@ function AnimatedSprites(props) {
221224
* Handles `Autodesk.Viewing.GEOMETRY_LOADED_EVENT` event that is sent
222225
* when a model has been completely loaded in the viewer.
223226
*
224-
* @param {Viewer3D} viewer The viewer in which the model is loaded.
227+
* @param {Autodesk.Viewing.GuiViewer3D} viewer The viewer in which the model is loaded.
225228
* @param {Object} data Event data that contains the loaded model.
229+
* @alias Autodesk.DataVisualization.Examples.AnimatedSprites#onModelLoaded
226230
*/
227231
async function onModelLoaded(viewer, data) {
228232

client/pages/App.jsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@ import StructureInfo from "./StructureInfo.jsx";
1313
import Navisworks from "./Navisworks.jsx";
1414
import CustomPage from "./CustomPage.jsx";
1515

16+
/**
17+
*
18+
* @param {Object} props
19+
* @param {Object} props.appData Data passed to the application.
20+
* @param {("AutodeskStaging"|"AutodeskProduction")} props.appData.env Forge API environment
21+
* @param {string} props.appData.docUrn Document URN of model
22+
* @param {string} props.appData.adapterType Corresponds to Data Adapter used to query data. i.e - synthetic, azure etc.
23+
* @param {"derivativeV2"|"derivativeV2_EU"|"modelDerivativeV2"|"fluent"|"D3S"|"D3S_EU"} [props.appData.api] Please refer to LMV documentation for more information.
24+
* @param {string} [props.appData.dataStart] Start date for provided CSV data in ISO string format.
25+
* @param {string} [props.appData.dataEnd] End date for provided CSV data in ISO string format.
26+
* @param {Object} props.appContext Contains base urls used to query assets, LMV, data etc.
27+
* @param {string} [props.appContext.dataUrl] The base url used to configure a specific {@link Autodesk.DataVisualization.Data.DataAdapter}
28+
*/
1629
function App(props) {
1730
return (
1831
<div className="outer-container">

client/pages/Dot.jsx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
/**
2+
* This sample illustrates how to add Sprite Viewables.
3+
*/
4+
15
import React from "react";
26
import { Viewer } from "forge-dataviz-iot-react-components";
37
import ApplicationContext from "../../shared/config/ApplicationContext.js";
48

9+
/**
10+
* @type {SensorStyleDefinitions}
11+
*/
512
const SensorStyleDefinitions = {
613
co2: {
714
url: `${ApplicationContext.assetUrlPrefix}/images/co2.svg`,
@@ -41,11 +48,21 @@ const devices = [
4148
/**
4249
* An example illustrating how to add viewables to the scene.
4350
* @component
51+
* @memberof Autodesk.DataVisualization.Examples
4452
* @param {Object} props
53+
* @param {Object} props.appData Data passed to the Dot Page.
54+
* @param {("AutodeskStaging"|"AutodeskProduction")} props.appData.env Forge API environment
55+
* @param {string} props.appData.docUrn Document URN of model
4556
*/
4657
function Dot(props) {
47-
const { env, token, docUrn } = props.appData;
58+
const { env, docUrn } = props.appData;
4859

60+
/**
61+
* Handles `Autodesk.Viewing.GEOMETRY_LOADED_EVENT` event that is sent
62+
* when a model has been completely loaded in the viewer.
63+
*
64+
* @param {Autodesk.Viewing.GuiViewer3D} viewer The viewer in which the model is loaded.
65+
*/
4966
async function onModelLoaded(viewer) {
5067
const dataVizExt = await viewer.loadExtension("Autodesk.DataVisualization", { useInternal: true });
5168
const DATAVIZEXTN = Autodesk.DataVisualization.Core;
@@ -73,10 +90,18 @@ function Dot(props) {
7390
await viewableData.finish();
7491
dataVizExt.addViewables(viewableData);
7592

93+
/**
94+
* Called when a user clicks on a Sprite Viewable
95+
* @param {Event} event
96+
*/
7697
function onItemClick(event) {
77-
98+
7899
}
79100

101+
/**
102+
* Called when a user hovers over a Sprite Viewable
103+
* @param {Event} event
104+
*/
80105
function onItemHovering(event) {
81106
console.log("Show tooltip here", event.dbId);
82107
}

client/pages/EngineSimulation.jsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* This sample illustrates how to add a heatmap to groups of dbIds.
3+
*/
4+
15
import React, { useEffect, useRef, useState } from "react";
26
import { BaseApp } from "forge-dataviz-iot-react-components";
37
import DataHelper from "./DataHelper";
@@ -109,10 +113,23 @@ const RAW_DATA = [
109113
},
110114
];
111115

112-
class EventBus {}
116+
class EventBus { }
113117

114118
THREE.EventDispatcher.prototype.apply(EventBus.prototype);
115119

120+
/**
121+
*
122+
* @param {Object} props
123+
* @param {Object} props.appData Data passed to the EngineSimulation.
124+
* @param {("AutodeskStaging"|"AutodeskProduction")} props.appData.env Forge API environment
125+
* @param {string} props.appData.docUrn Document URN of model
126+
* @param {string} props.appData.adapterType Corresponds to Data Adapter used to query data. i.e - synthetic, azure etc.
127+
* @param {"derivativeV2"|"derivativeV2_EU"|"modelDerivativeV2"|"fluent"|"D3S"|"D3S_EU"} [props.appData.api] Please refer to LMV documentation for more information.
128+
* @param {Object} props.appContext Contains base urls used to query assets, LMV, data etc.
129+
* @param {string} [props.appContext.dataUrl] The base url used to configure a specific {@link Autodesk.DataVisualization.Data.DataAdapter}
130+
*
131+
* @memberof Autodesk.DataVisualization.Examples
132+
*/
116133
function EngineSimulation(props) {
117134
const eventBusRef = useRef(new EventBus());
118135
const [data, setData] = useState(null);
@@ -139,10 +156,6 @@ function EngineSimulation(props) {
139156
devicePanelData,
140157
};
141158
setData(dataRef.current);
142-
143-
return function cleanUp() {
144-
eventBusRef.current._listeners = {};
145-
};
146159
});
147160
}, []);
148161

client/pages/Heatmap.jsx

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
/**
2-
* This is a sample code to show how to render basic heatmap on the screen
2+
* This is a sample code to show how to render a basic heatmap on the screen
33
*
4-
* Heatmap is the terminology we used to show the corresponding sensor values in the room
5-
* and this is a step foreward by combine both Dot and ModelStructureInfo to created a combined
4+
* Heatmap is the terminology we use to show the corresponding sensor values in the room
5+
* and this is a step foreward by combining both Dot and ModelStructureInfo to create a combined
66
* user experience
77
*/
88

99
import React from "react";
1010
import { Viewer } from "forge-dataviz-iot-react-components";
1111
import ApplicationContext from "../../shared/config/ApplicationContext.js";
1212

13+
/**
14+
* @type {SensorStyleDefinitions}
15+
*/
1316
const SensorStyleDefinitions = {
1417
co2: {
1518
url: `${ApplicationContext.assetUrlPrefix}/images/co2.svg`,
@@ -51,10 +54,23 @@ const devices = [
5154
/**
5255
* @component Sample heatmap code
5356
* @param {Object} props
57+
* @param {Object} props
58+
* @param {Object} props.appData Data passed to the application.
59+
* @param {("AutodeskStaging"|"AutodeskProduction")} props.appData.env Forge API environment
60+
* @param {string} props.appData.docUrn Document URN of model
61+
*
62+
* @memberof Autodesk.DataVisualization.Examples
5463
*/
5564
function Heatmap(props) {
56-
const { env, token, docUrn } = props.appData;
57-
65+
const { env, docUrn } = props.appData;
66+
67+
/**
68+
* Handles `Autodesk.Viewing.GEOMETRY_LOADED_EVENT` event that is sent
69+
* when a model has been completely loaded in the viewer.
70+
*
71+
* @param {Autodesk.Viewing.GuiViewer3D} viewer The viewer in which the model is loaded.
72+
* @param {Object} data Event data that contains the loaded model.
73+
*/
5874
async function onModelLoaded(viewer, data) {
5975
const dataVizExt = await viewer.loadExtension("Autodesk.DataVisualization", { useInternal: true });
6076
const DATAVIZEXTN = Autodesk.DataVisualization.Core;
@@ -106,7 +122,8 @@ function Heatmap(props) {
106122
dataVizExt.registerSurfaceShadingColors("temperature", [0xff0000, 0x0000ff]);
107123

108124
/**
109-
* Interface for application to decide what is the current value for the heatmap
125+
* Interface for application to decide what the current value for the heatmap is.
126+
*
110127
* @param {string} device device id
111128
* @param {string} sensorType sensor type
112129
*/

client/pages/Navisworks.jsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* This sample illustrates adding Sprite viewables and rendering a heatmap on a NWD file.
3+
*/
4+
15
import React, { useEffect, useRef, useState } from "react";
26
import { BaseApp } from "forge-dataviz-iot-react-components";
37
import DataHelper from "./DataHelper";
@@ -10,7 +14,7 @@ import fan03 from "../../assets/images/fan-03.svg";
1014
import fan04 from "../../assets/images/fan-04.svg";
1115
import fan05 from "../../assets/images/fan-04.svg";
1216

13-
import { SpriteSize, SensorStyleDefinitions, PropIdGradientMap, PropertyIconMap } from "../config/SensorStyles.js";
17+
import { SpriteSize, SensorStyleDefinitions, PropIdGradientMap } from "../config/SensorStyles.js";
1418

1519
const fans = [fan00, fan01, fan02, fan03, fan04, fan05];
1620

@@ -53,6 +57,19 @@ const surfaceShadingConfig = {
5357
gradientSetting: PropIdGradientMap
5458
};
5559

60+
/**
61+
* @memberof Autodesk.DataVisualization.Examples
62+
*
63+
* @param {Object} props
64+
* @param {Object} props.appData Data passed to the Navisworks.
65+
* @param {("AutodeskStaging"|"AutodeskProduction")} [props.appData.env] Forge API environment
66+
* @param {string} props.appData.docUrn Document URN of model
67+
* @param {string} props.appData.adapterType Corresponds to Data Adapter used to query data. i.e - synthetic, azure etc.
68+
* @param {"derivativeV2"|"derivativeV2_EU"|"modelDerivativeV2"|"fluent"|"D3S"|"D3S_EU"} [props.appData.api] Please refer to LMV documentation for more information.
69+
* @param {Object} props.appContext Contains base urls used to query assets, LMV, data etc.
70+
* @param {string} [props.appContext.dataUrl] The base url used to configure a specific {@link Autodesk.DataVisualization.Data.DataAdapter}
71+
*
72+
*/
5673
function Navisworks(props) {
5774
const eventBusRef = useRef(new EventBus());
5875
const [data, setData] = useState(null);
@@ -79,14 +96,10 @@ function Navisworks(props) {
7996
devicePanelData,
8097
};
8198
setData(dataRef.current);
82-
83-
return function cleanUp() {
84-
eventBusRef.current._listeners = {};
85-
};
8699
});
87100
}, []);
88101

89-
eventBusRef.current.addEventListener("VIEWER_DATA_READY", (event) => {
102+
eventBusRef.current.addEventListener(EventTypes.VIEWABLES_LOADED, (event) => {
90103
let { dataVizExtn } = event.data;
91104

92105
let i = 0;

client/pages/ReferenceApp.jsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ class EventBus { }
1717

1818
THREE.EventDispatcher.prototype.apply(EventBus.prototype);
1919

20+
/**
21+
*
22+
* @param {Object} props
23+
* @param {Object} props.appData Data passed to the BaseApp.
24+
* @param {("AutodeskStaging"|"AutodeskProduction")} props.appData.env Forge API environment
25+
* @param {string} props.appData.docUrn Document URN of model
26+
* @param {string} props.appData.adapterType Corresponds to Data Adapter used to query data. i.e - synthetic, azure etc.
27+
* @param {"derivativeV2"|"derivativeV2_EU"|"modelDerivativeV2"|"fluent"|"D3S"|"D3S_EU"} [props.appData.api] Please refer to LMV documentation for more information.
28+
* @param {string} [props.appData.dataStart] Start date for provided CSV data in ISO string format.
29+
* @param {string} [props.appData.dataEnd] End date for provided CSV data in ISO string format.
30+
* @param {Object} props.appContext Contains base urls used to query assets, LMV, data etc.
31+
* @param {string} [props.appContext.dataUrl] The base url used to configure a specific {@link Autodesk.DataVisualization.Data.DataAdapter}
32+
*
33+
* @memberof Autodesk.DataVisualization.Examples
34+
*/
2035
function ReferenceApp(props) {
2136

2237
const eventBusRef = useRef(new EventBus());
@@ -60,6 +75,11 @@ function ReferenceApp(props) {
6075
// event.hasStopped = true;
6176
})
6277

78+
/**
79+
* Called when a user has selected a level in the {@link Autodesk.DataVisualization.UI.LevelsTree} or expanded/closed a
80+
* grouping in {@link Autodesk.DataVisualization.UI.DeviceTree}
81+
* @param {Event} event
82+
*/
6383
function handleNodeChange(event) {
6484
if (levelsExt) {
6585
let { selectedNodeId } = appStateRef.current;
@@ -124,10 +144,6 @@ function ReferenceApp(props) {
124144
devicePanelData
125145
};
126146
setData(dataRef.current);
127-
128-
return function cleanUp() {
129-
eventBusRef.current._listeners = {}
130-
}
131147
});
132148
}, []);
133149

@@ -146,4 +162,4 @@ function ReferenceApp(props) {
146162
);
147163
}
148164

149-
module.exports = ReferenceApp;
165+
module.exports = ReferenceApp;

0 commit comments

Comments
 (0)