-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathselectMarks.html
72 lines (61 loc) · 2.38 KB
/
selectMarks.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Select Marks</title>
<script type="module">
// SelectionUpdateType is an enum for specifying the selection type for the select marks api.
// TableauEventType represents the type of Tableau embedding event that can be listened for.
import { SelectionUpdateType, TableauEventType } from "https://public.tableau.com/javascripts/api/tableau.embedding.3.latest.js";
function handleFirstInteractive(e) {
let sheet = viz.workbook.activeSheet;
// Select Marks.
const selectButton = document.getElementById("select");
selectButton.onclick = async () => {
const selections = [
{
fieldName: "College",
value: "Engineering",
},
];
await sheet.selectMarksByValueAsync(
selections,
SelectionUpdateType.Replace
);
};
// Add Marks to the Selection.
const addButton = document.getElementById("add");
addButton.onclick = async () => {
const selections = [
{
fieldName: "College",
value: "Business",
},
];
await sheet.selectMarksByValueAsync(selections, SelectionUpdateType.Add);
};
// Clear Marks.
const clearButton = document.getElementById("clear");
clearButton.onclick = async () => {
await sheet.clearSelectedMarksAsync();
};
}
const viz = document.getElementById("tableauViz");
// Event fired when a viz first becomes interactive.
viz.addEventListener(TableauEventType.FirstInteractive, handleFirstInteractive);
</script>
</head>
<body>
<div>
<!-- Initialization of the Tableau visualization. -->
<tableau-viz id="tableauViz" src="https://public.tableau.com/views/RegionalSampleWorkbook/College"
hide-tabs>
</tableau-viz>
</div>
<br />
<!-- Buttons to handle selection. -->
<button id="select">Select a value</button>
<button id="add">Add to the selection</button>
<button id="clear">Clear all</button>
</body>
</html>