-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
161 lines (151 loc) · 5.7 KB
/
index.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
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
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<style>
html, body, main {
width: 100%;
height: 100%;
}
main {
font-family: monospace;
font-size: 20px;
white-space: pre;
}
</style>
<script src="https://code.highcharts.com/adapters/standalone-framework.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
</head>
<!--
A demonstration of a custom view using Highcharts, manual/advanced querying, and selection.
-->
<body>
<main id="main"></main><!-- This element is where the view will render -->
<script src="/_global_/customview/v1/omniscope.js"></script><!-- Add the Omniscope custom view API -->
<script>
if (!omniscope || !omniscope.view) throw new Error("Omniscope chart API is not loaded");
omniscope.view.on("load", function() {
window.onerror = function(msg) {
omniscope.view.error(msg);
}
});
// Naively redraw on any of these events
// (load = first init, update = external settings/state change, resize = browser window resized)
omniscope.view.on(["load", "update", "resize"], function() {
try {
var query = {
// Use grouping and measure from options, as specified in manifest
"groupings": [
omniscope.view.context().options.items.split
],
"measures": [
omniscope.view.context().options.items.measures
],
// Use default filters for the view:
"filter": omniscope.view.context().dataConfig.filter
}
// Notify the container that the view is busy loading
omniscope.view.busy(true);
// Get the view endpoint using the Custom View API, this is needed to create the query builder.
var endpoint = omniscope.view.endpoint();
// Execute the query and render the view.
omniscope.query.builder(endpoint).table(query).on("load", function(event) {
renderView(event.data);
omniscope.view.busy(false); // Also notify the container view is now ready.
}).execute();
} catch (error) {
throw new Error(error.message);
}
});
// Using the query results, show it in the custom visualisation.
function renderView(queryResultData) {
// CREATE SPLIT LABELS.
var labels = [];
// Note the result is a 2d array - for more information see Query API docs.
for (var i = 0; i < queryResultData.records.length; i++) {
labels.push(queryResultData.records[i][0]);
}
// Get stored measure option
var measure = omniscope.view.context().options.items.measures;
var yAxisLabel = "";
// RECORD COUNT option doesn't have an input field associated with it
// hence we are checking to see if the input field is present.
if (!measure.inputField) {
yAxisLabel = measure.function;
} else {
yAxisLabel = measure.inputField + " (" + measure.function+")";
}
var bodyOffsets = document.body.getBoundingClientRect();
// High chart specific
new Highcharts.Chart({
chart: {
renderTo: 'main',
width: bodyOffsets.width,
height: bodyOffsets.height,
events: {
click: function() {
// On clicking anywhere on the chart other than point, trigger whitespace click.
omniscope.view.whitespaceClick();
}
},
type: "column"
},
title: {
text: null
},
xAxis: {
gridLineWidth: 1,
categories: labels,
type: "categories",
},
yAxis: {
gridLineDashStyle: 'longdash',
title: {
text: yAxisLabel
}
},
plotOptions: {
series: {
animation: 1000,
allowPointSelect: true,
dataLabels: {
enabled: true
},
states: {
select: {
color: 'blue'
}
},
point: {
events: {
click: function() {
// On clicking a bar trigger omniscope selection.
var fieldName = omniscope.view.context().options.items["split"].inputField;
var selectedValue = this.category;
var filter = {
"type": "AND",
"filters": [{
"type": "FIELD_VALUE",
"inputField": fieldName,
"operator": "=",
"value": selectedValue
}]
};
omniscope.view.context().viewSelection = { filter: filter };
omniscope.view.updated();
}
}
}
}
},
legend: {
enabled: false
},
series: [{
data: queryResultData.records
}]
});
}
</script>
</body>
</html>