-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathdynamicLoad.html
63 lines (50 loc) · 2.28 KB
/
dynamicLoad.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dynamic Load</title>
<script type="module">
// TableauEventType represents the type of Tableau embedding event that can be listened for.
import { TableauEventType } from "https://public.tableau.com/javascripts/api/tableau.embedding.3.latest.js";
// List of visualizations to cycle through.
const vizList = ["https://public.tableau.com/views/RegionalSampleWorkbook/Flights",
"https://public.tableau.com/views/RegionalSampleWorkbook/Obesity",
"https://public.tableau.com/views/RegionalSampleWorkbook/College",
"https://public.tableau.com/views/RegionalSampleWorkbook/Stocks",
"https://public.tableau.com/views/RegionalSampleWorkbook/Storms"];
let vizLen = vizList.length, vizCount = 0;
function handleFirstInteractive(e) {
console.log(`Viz loaded: ${viz.src}`);
}
// Determine the correct visualization to display.
function loadViz(vizPlusMinus) {
vizCount = vizCount + vizPlusMinus;
if (vizCount >= vizLen) {
// Keep the vizCount in the bounds of the array index.
vizCount = 0;
} else if (vizCount < 0) {
vizCount = vizLen - 1;
}
viz.src = vizList[vizCount];
}
let viz = document.getElementById("tableauViz");
// Event fired when a viz first becomes interactive.
viz.addEventListener(TableauEventType.FirstInteractive, handleFirstInteractive);
viz.src = vizList[0];
// Attach event handlers to the "previous" and "next" button clicks.
document.getElementById("previous").onclick = () => loadViz(-1);
document.getElementById("next").onclick = () => loadViz(1);
</script>
</head>
<body>
<!-- Initialization of the Tableau visualization. -->
<div style="width:800px; height:700px;">
<tableau-viz id="tableauViz" hide-tabs></tableau-viz>
</div>
<!-- Buttons to show the previous or next visualization. -->
<div id="controls" style="padding:20px;">
<button style="width:100px;" id="previous">Previous</button>
<button style="width:100px;" id="next">Next</button>
</div>
</body>
</html>