forked from Kitware/itk-vtk-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createPointSetsUI.js
70 lines (59 loc) · 2.22 KB
/
createPointSetsUI.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { reaction, autorun } from 'mobx'
import style from './ItkVtkViewer.module.css'
import createPointSetRepresentationSelector from './PointSets/createPointSetRepresentationSelector'
import createPointSetColorWidget from './PointSets/createPointSetColorWidget'
function createPointSetsUI(store, uiContainer) {
const pointSetsUIGroup = document.createElement('div')
pointSetsUIGroup.setAttribute('class', style.uiGroup)
const pointSetRepresentationRow = document.createElement('div')
pointSetRepresentationRow.setAttribute('class', style.uiRow)
pointSetRepresentationRow.className += ` ${store.id}-collapsible`
if (store.mainUI.collapsed) {
pointSetRepresentationRow.style.display = 'none'
}
const pointSetSelector = document.createElement('select')
pointSetSelector.setAttribute('class', style.selector)
pointSetSelector.id = `${store.id}-pointSetSelector`
pointSetRepresentationRow.appendChild(pointSetSelector)
pointSetSelector.addEventListener('change', event => {
event.preventDefault()
event.stopPropagation()
store.pointSetsUI.selectedPointSetIndex = pointSetSelector.selectedIndex
})
function updatePointSetNames(names) {
pointSetSelector.innerHTML = names
.map(name => `<option value="${name}">${name}</option>`)
.join('')
if (names.length > 1) {
pointSetSelector.disabled = false
} else {
pointSetSelector.disabled = true
}
}
reaction(
() => {
return store.pointSetsUI.names.slice()
},
names => {
updatePointSetNames(names)
}
)
if (store.pointSetsUI.pointSets.length > 0) {
store.pointSetsUI.selectedPointSetIndex = 0
}
autorun(() => {
const pointSets = store.pointSetsUI.pointSets
store.pointSetsUI.names = pointSets.map((pointSet, index) => {
const metadata = pointSet.getState().metadata
return !!metadata && !!metadata.name
? metadata.name
: `Point Set ${index}`
})
})
createPointSetRepresentationSelector(store, pointSetRepresentationRow)
pointSetsUIGroup.appendChild(pointSetRepresentationRow)
createPointSetColorWidget(store, pointSetsUIGroup)
uiContainer.appendChild(pointSetsUIGroup)
store.pointSetsUI.initialized = true
}
export default createPointSetsUI