forked from MicroStrategy/embedding-sdk-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11_Selection.html
More file actions
199 lines (163 loc) · 6.21 KB
/
11_Selection.html
File metadata and controls
199 lines (163 loc) · 6.21 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="https://demo.microstrategy.com/MicroStrategyLibrary/javascript/embeddinglib.js"></script>
<!-- This is for the jsfiddle button. You don't need it in your application. -->
<script type="text/javascript" src="js/jsfiddle.js"></script>
</head>
<body>
<div>This example shows how to make selections on visualization programmatically. </div>
<table class="visualTable">
<tr>
<td><button onclick="updateVisuals()">Get Visualizations </button><select id="visualSelector"></select></td>
</tr>
<tr>
<td><button onclick="getElements()">Get Elements </button></td>
</tr>
<tr>
<td><div id="elementPanel"></div>
Action:
<select id="actionSelector">
<option value="replace">replace</option>
<option value="add">add</option>
<option value="remove">remove</option>
</select>
</td>
</tr>
<tr><td><button onclick="applySelection()">Apply </button></td></td></tr>
</table>
<div id="mydossier"></div>
<script type="text/javascript">
var url = "https://demo.microstrategy.com/MicroStrategyLibrary/app/EC70648611E7A2F962E90080EFD58751/69AF3E7DB548FD6E23C57E9B71DD966B"
selectedAttribute = new Set()
document.addEventListener("DOMContentLoaded", function(){
var container = document.getElementById("mydossier")
//This page has multiple visualizations
microstrategy.dossier.create({
url: url,
enableResponsive: true,
placeholder: container,
containerHeight: '800px',
enableCollaboration: false,
dockedTOC: {
canClose: true,
dockChangeable: false,
isDocked:false
},
navigationBar: {
enabled: false
}
}).then((dossier) => {
d = dossier
d.registerEventHandler(microstrategy.dossier.EventType.ON_PAGE_SWITCHED, reset)
d.registerEventHandler(microstrategy.dossier.EventType.ON_PAGE_LOADED, reset)
})
})
reset = function() {
resetVisualSelector()
resetElementSelector()
selectedAttribute = new Set()
}
resetVisualSelector = function() {
let s = document.getElementById("visualSelector")
while (s.firstChild) {
s.removeChild(s.lastChild)
}
}
updateVisuals = function () {
d.getCurrentPageVisualizationList().then((visuals) => {
resetVisualSelector()
let s = document.getElementById("visualSelector")
for (visual of visuals) {
let o = document.createElement("option")
o.value = visual.key
o.innerText = visual.name
s.appendChild(o)
}
})
}
resetElementSelector = function() {
let elementPanel = document.getElementById("elementPanel")
while (elementPanel.firstChild) {
elementPanel.removeChild(elementPanel.lastChild)
}
}
getElements = function() {
let visualSelector = document.getElementById("visualSelector")
let key = visualSelector.selectedOptions[0].value
d.getAvailableElements(key).then(availableElements => {
attrElements = availableElements
resetElementSelector()
let elementPanel = document.getElementById("elementPanel")
for (attributeSelector of availableElements) {
let attr = attributeSelector.attribute
let elements = attributeSelector.elements
let nameSpan = document.createElement("span")
nameSpan.innerText = attr.name+" "
elementPanel.appendChild(nameSpan)
let s = document.createElement("select")
s.setAttribute("id", attr.id)
s.setAttribute("multiple", "true")
for (item of elements) {
let o = document.createElement("option")
o.value = item.name
o.id = item.id
o.innerText = item.name
s.appendChild(o)
}
elementPanel.appendChild(s)
let checkbox = document.createElement("input")
checkbox.setAttribute("type", "checkbox")
checkbox.setAttribute("attrID", attr.id)
checkbox.setAttribute("onchange", "selectAttr(this)")
elementPanel.appendChild(checkbox)
}
}).catch(error => {
})
}
selectAttr = function(input) {
let attrID = input.getAttribute("attrID")
if (input.checked) {
selectedAttribute.add(attrID)
} else {
selectedAttribute.delete(attrID)
}
}
applySelection = function() {
let visualSelector = document.getElementById("visualSelector")
let key = visualSelector.selectedOptions[0].value
let action = document.getElementById("actionSelector").value
let attributeElements = []
//Listen to specific visualization
d.registerGraphicsSelectEventHandlerToViz(key, (selectedElements)=> {
//console.log("GraphicsSelectEventHandlerToViz", key, selectedElements)
})
for (attr of attrElements) {
let attrID = attr.attribute.id
if (selectedAttribute.has(attrID)) {
let elementSelector = document.getElementById(attrID)
let attribute = { "id": attrID}
let elements = []
for (o of elementSelector.selectedOptions) {
elements.push({"id": o.id})
}
attributeElements.push({attribute,elements})
}
}
let obj = {
"vizKey": key,
"action": action,
"selection": {
attributeElements
}
}
// console.log(obj)
d.selectVizElement(obj).then(selection => {
//console.log(selection)
})
}
</script>
</body>
</html>