-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
85 lines (68 loc) · 2.33 KB
/
app.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Good for testing as it shows what line it's coming from
//can use alert instead of console.log to create pop up
console.log("Hello from DS14!");
let viz;
//Create a variable for URL
const url =
"https://public.tableau.com/views/LearnEmbeddedAnalytics/SalesOverviewDashboard";
//Create a variable for Viz Container
const vizContainer = document.getElementById("vizContainer");
console.log(vizContainer);
//Create a variable for the viz optons
const options = {
device: "desktop",
hideTabs: true,
};
//bring elements together
function initViz() {
viz = new tableau.Viz(vizContainer, url, options);
showButton.style.display = "none";
}
//Create a variable for hide button and connect it to clicking action
const hideButton = document.getElementById("hideButton");
hideButton.addEventListener("click", function () {
viz.hide();
showButton.style.display = "inline";
hideButton.style.display = "none";
});
const showButton = document.getElementById("showButton");
showButton.addEventListener("click", function () {
viz.show();
showButton.style.display = "none";
hideButton.style.display = "inline";
});
//export to PDF
const pdfButton = document.getElementById("pdfButton");
pdfButton.addEventListener("click", function () {
viz.showExportPDFDialog();
});
const ppButton = document.getElementById("ppButton");
ppButton.addEventListener("click", function () {
viz.showExportPowerPointDialog();
});
const dataButton = document.getElementById("dataButton");
dataButton.addEventListener("click", function () {
viz.showExportCrossTabDialog();
});
function getRangeValues() {
//get values from inputs
const minValue = document.getElementById("minValue").value;
const maxValue = document.getElementById("maxValue").value;
//get the workbook
const workbook = viz.getWorkbook();
//get active sheet (dashboard)
const activesheet = workbook.getActiveSheet();
//get all the sheets in the dashboard
const sheets = activesheet.getWorksheets();
//apply the filter to the sheet with the sames measure
const sheetToFilter = sheets[1];
sheetToFilter.applyRangeFilterAsync("SUM(Sales)", {
min: minValue,
max: maxValue,
});
}
document.getElementById("filterButton").addEventListener("click", function () {
getRangeValues();
});
//whenever (entire) page loads execute function
document.addEventListener("DOMContentLoaded", initViz);