forked from looker/custom_visualizations_v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello_world.js
79 lines (69 loc) · 2.37 KB
/
hello_world.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
looker.plugins.visualizations.add({
// Id and Label are legacy properties that no longer have any function besides documenting
// what the visualization used to have. The properties are now set via the manifest
// form within the admin/visualizations page of Looker
id: "hello_world",
label: "Hello World",
options: {
font_size: {
type: "string",
label: "Font Size",
values: [
{"Large": "large"},
{"Small": "small"}
],
display: "radio",
default: "large"
}
},
// Set up the initial state of the visualization
create: function(element, config) {
// Insert a <style> tag with some styles we'll use later.
element.innerHTML = `
<style>
.hello-world-vis {
/* Vertical centering */
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
text-align: center;
}
.hello-world-text-large {
font-size: 72px;
}
.hello-world-text-small {
font-size: 18px;
}
</style>
`;
// Create a container element to let us center the text.
var container = element.appendChild(document.createElement("div"));
container.className = "hello-world-vis";
// Create an element to contain the text.
this._textElement = container.appendChild(document.createElement("div"));
},
// Render in response to the data or settings changing
updateAsync: function(data, element, config, queryResponse, details, done) {
// Clear any errors from previous updates
this.clearErrors();
// Throw some errors and exit if the shape of the data isn't what this chart needs
if (queryResponse.fields.dimensions.length == 0) {
this.addError({title: "No Dimensions", message: "This chart requires dimensions."});
return;
}
// Grab the first cell of the data
var firstRow = data[0];
var firstCell = firstRow[queryResponse.fields.dimensions[0].name];
// Insert the data into the page
this._textElement.innerHTML = LookerCharts.Utils.htmlForCell(firstCell);
// Set the size to the user-selected size
if (config.font_size == "small") {
this._textElement.className = "hello-world-text-small";
} else {
this._textElement.className = "hello-world-text-large";
}
// We are done rendering! Let Looker know.
done()
}
});