-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.html
More file actions
239 lines (210 loc) · 10.4 KB
/
index.html
File metadata and controls
239 lines (210 loc) · 10.4 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Charts</title>
<link rel="shortcut icon" href="./favicon.ico" />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/icon?family=Material+Icons"
/>
<!-- <script src="http://localhost:8080/cgpv-main.js"></script> -->
<!-- <script src="https://alex-nrcan.github.io/geoview/cgpv-main.js"></script> -->
<script src="https://canadian-geospatial-platform.github.io/geoview/public/cgpv-main.js"></script>
<style>
/* To help with display */
.MuiGrid-container {
width: 900px;
}
</style>
</head>
<body>
<div style="text-align: center;">
<div style="display:inline-block; background-color: lightgreen; width: 49%; vertical-align:top;">
<div style="text-align: left;">
GEOCHART INPUTS <span style="font-size: small;">(these parameters will be parsed and sent to the Chart.js props on the right and GeoChart created below)</span>
</div>
<div style="margin-bottom: 5px;">
<span>Language: </span>
<select id="lang" onChange="languageChanged()">
<option selected value="en">English</option>
<option value="fr">Français</option>
</select>
</div>
<div>
<div style="margin-bottom: 10px;">
<span>Chart Config: </span>
<select id="selChart">
<option value="./configs/config-line-1.json">Import Chart time complete</option>
<option value="./configs/config-line-2.json">Import Chart time log. tension</option>
<option value="./configs/config-line-2-slim.json">Import Chart no sliders</option>
<option value="./configs/config-line-ogc-1.json">Imp. OGC Line (VPN)</option>
<option value="./configs/config-bar-1.json">Imp. OGC Bar (all)</option>
<option value="./configs/config-bar-1-single.json">Imp. OGC Bar (single)</option>
<option value="./configs/config-bar-2.json">Import Data BAR</option>
<option value="./configs/config-pie-1.json">Import Data PIE</option>
<option value="./configs/config-doughnut-1.json">Import Data DOUGHNUT</option>
<option value="./configs/config-bar-3.json">Import Data BAR simple</option>
<option value="./configs/config-line-4.json">Import Data w/ nulls</option>
<option value="./configs/config-line-5.json">Import Data test apostrophes</option>
</select>
</div>
<div>
<textarea id="CHARTDATAINPUTS" rows="18" style="width: 98%;"></textarea>
</div>
</div>
<div>
<button onclick="loadChartFromInputs()" style="padding:5px;"><strong>BUILD CHART FROM GEOCHART INPUTS</strong></button>
</div>
</div>
<div style="display:inline-block; background-color: aliceblue; width: 50%; vertical-align:top;">
<div style="text-align: left;">
CHART.JS PROPS <span style="font-size: small;">(these Chart.js native parameters are used to draw the actual chart itself)</span>
</div>
<div style="padding:10px;">
<select id="CHARTTYPE">
<option value='line' selected>Line</option>
<option value='bar'>Bar</option>
<option value='pie'>Pie</option>
<option value='doughnut'>Doughnut</option>
</select>
</div>
<div>
<div style="display:inline-block; width: 49%;">
<div>
<button onclick="importNativeOptionsParsed('./configs/native-options-1.json')">Import Options (default)</button>
<button onclick="importNativeOptionsParsed('./configs/native-options-2.json')">Import Options dummy scale</button>
</div>
<div>
<textarea id="CHARTOPTIONSPARSED" rows="18" style="width: 98%"></textarea>
</div>
</div>
<div style="display:inline-block; width: 49%;">
<div>
<button onclick="importNativeDataParsed('./configs/native-data-1.json')">Import Data 1 rec</button>
<button onclick="importNativeDataParsed('./configs/native-data-2.json')">Import Data 2 recs</button>
<button onclick="importNativeDataParsed('./configs/native-data-3.json')">Import Data 2 recs w/ steps</button>
<button onclick="importNativeDataParsed('./configs/native-data-4.json')">Import Data using x,y</button>
</div>
<div>
<textarea id="CHARTDATAPARSED" rows="18" style="width: 98%"></textarea>
</div>
</div>
</div>
<div>
<button onclick="loadChartFromNative()" style="padding:5px;"><strong>BUILD CHART FROM CHART.JS PROPS</strong></button>
</div>
</div>
</div>
<!------------- CHART IS HERE / ----------------->
<div id="root2aca7b6b288c" style="position: relative;"></div>
<!------------- / CHART IS HERE ----------------->
<div>
<button onclick="redrawChart()" style="padding:5px;"><strong>Looks weird? Redraw!</strong></button>
<button onclick="isLoadingState(1)" style="padding:5px;"><strong>Sim. loading whole chart</strong></button>
<button onclick="isLoadingState(2)" style="padding:5px;"><strong>Sim. lazy loading of datasource</strong></button>
<button onclick="isLoadingState(0)" style="padding:5px;"><strong>Clear loading sim.</strong></button>
</div>
<script>
async function importChartConfig(inputPath) {
// Fetch the json
const result = await fetch(inputPath);
const body = await result.json();
// Load
document.getElementById('CHARTDATAINPUTS').value = JSON.stringify(body, null, 2);
}
async function importNativeDataParsed(inputPath) {
// Fetch the json
const result = await fetch(inputPath);
const body = await result.json();
// Load
document.getElementById('CHARTDATAPARSED').value = JSON.stringify(body, null, 2);
}
async function importNativeOptionsParsed(inputPath) {
// Fetch the json
const result = await fetch(inputPath);
const body = await result.json();
// Load
document.getElementById('CHARTOPTIONSPARSED').value = JSON.stringify(body, null, 2);
}
function loadChartFromInputs() {
let chartInputs = null;
try {
if (document.getElementById('CHARTDATAINPUTS').value)
chartInputs = JSON.parse(document.getElementById('CHARTDATAINPUTS').value);
}
catch (ex) {
alert('Failed to create JSON from input data text area.');
console.error(ex);
}
// Emit a Chart Changed event so the chart updates
// This is not using the conventional way to communicate with the Chart. It simulates a ReactJS behavior.
window.dispatchEvent(new CustomEvent("chart/load", { detail: { inputs: chartInputs } }));
}
function loadChartFromNative() {
let chartType = document.getElementById('CHARTTYPE').value || 'line';
let chartData = null;
let chartOptions = null;
try {
if (document.getElementById('CHARTDATAPARSED').value)
chartData = JSON.parse(document.getElementById('CHARTDATAPARSED').value);
}
catch (ex) {
alert('Failed to create JSON from input data text area.');
console.error(ex);
}
try {
if (document.getElementById('CHARTOPTIONSPARSED').value)
chartOptions = JSON.parse(document.getElementById('CHARTOPTIONSPARSED').value);
}
catch (ex) {
alert('Failed to create JSON from input options text area.');
console.error(ex);
}
// Emit a Chart Changed event so the chart updates
// This is not using the conventional way to communicate with the Chart. It simulates a ReactJS behavior.
window.dispatchEvent(new CustomEvent("chart/load", { detail: { chart: chartType, data: chartData, options: chartOptions } }));
}
function redrawChart() {
// Emit a Chart Redraw event so the chart updates
// This is not using the conventional way to communicate with the Chart. It simulates a ReactJS behavior.
window.dispatchEvent(new CustomEvent("chart/redraw"));
}
function languageChanged() {
// Emit a Chart Language changed event so the chart updates
// This is not using the conventional way to communicate with the Chart. It simulates a ReactJS behavior.
window.dispatchEvent(new CustomEvent("chart/language", { detail: { language: event.target.value } }));
}
async function chartChanged(event) {
// Import the chart config
await importChartConfig(event.target.value);
// Also immediately build the chart
loadChartFromInputs();
}
function isLoadingState(state) {
// Emit a Chart Redraw event so the chart updates
// This is not using the conventional way to communicate with the Chart. It simulates a ReactJS behavior.
window.dispatchEvent(new CustomEvent("chart/isLoading", { detail: { state: state } }));
}
function handleChartLoaded(e) {
// Update ui
document.getElementById('CHARTTYPE').value = e.detail.chart;
document.getElementById('CHARTOPTIONSPARSED').value = JSON.stringify(e.detail.options, null, 2);
document.getElementById('CHARTDATAPARSED').value = JSON.stringify(e.detail.data, null, 2);
}
// Load data 1
importChartConfig('./configs/config-line-1.json').then((result) => {
// Now load the chart
loadChartFromInputs();
});
importNativeOptionsParsed('./configs/native-options-1.json');
importNativeDataParsed('./configs/native-data-1.json');
// Attach the event listener
const selectElement = document.getElementById("selChart");
selectElement.addEventListener("change", chartChanged);
// Listen on the chart parsed to update the UI
window.addEventListener('chart/parsed', handleChartLoaded);
</script>
</body>
</html>