forked from Canadian-Geospatial-Platform/geochart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
975 lines (935 loc) · 31 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
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
<!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 */
.MuiGrid2-container {
width: 600px;
}
</style>
<script>
const DATA_INPUT_LINE_1 = {
chart: 'line',
title: 'Line Chart with time on x and sliders',
query: {
type: "esriRegular",
url: "https://maps-cartes.services.geo.ca/server_serveur/rest/services/HC/airborne_radioactivity_en/MapServer/3",
queryOptions: {
whereClauses: [
{
field: "Location_Emplacement",
prefix: "'",
valueFrom: "Location_Emplacement",
suffix: "'"
}],
orderByField: "CollectionStart_DebutPrelevement"
}
},
geochart: {
borderWidth: 2,
useSteps: "after",
xAxis: {
type: 'time',
property: 'CollectionStart_DebutPrelevement',
label: 'Collected date',
usePalette: false
},
yAxis: {
type: 'linear',
property: 'Activity_Activite_mBqm3',
label: 'Activity mBqm3',
tooltipSuffix: "mBqm3"
}
},
category: {
property: 'Radionuclide_Radionucleide',
usePalette: false
},
ui: {
xSlider: {
display: true,
},
ySlider: {
display: true,
step: 0.1
},
stepsSwitcher: true,
scaleSwitcher: true,
resetStates: true,
description: 'This is a description text',
download: true
},
datasources: [{
display: "Saskatoon",
sourceItem: {
Location_Emplacement: "Saskatoon"
}
},{
display: "Vancouver",
sourceItem: {
Location_Emplacement: "Vancouver"
}
},{
display: "Regina",
sourceItem: {
Location_Emplacement: "Regina"
}
},{
display: "Ottawa",
sourceItem: {
Location_Emplacement: "Ottawa"
}
},{
display: "Montreal",
sourceItem: {
Location_Emplacement: "Montreal"
}
},{
display: "Quebec",
sourceItem: {
Location_Emplacement: "Quebec"
}
}]
};
const DATA_INPUT_LINE_2 = {
chart: 'line',
title: 'Line Chart with time on x and sliders and steps|tension',
query: {
type: "esriRegular",
url: "https://maps-cartes.services.geo.ca/server_serveur/rest/services/HC/airborne_radioactivity_en/MapServer/3",
queryOptions: {
whereClauses: [
{
field: "Location_Emplacement",
prefix: "'",
valueFrom: "Location_Emplacement",
suffix: "'"
}],
orderByField: "CollectionStart_DebutPrelevement"
}
},
geochart: {
borderWidth: 2,
useSteps: false,
tension: 0.3,
xAxis: {
type: 'time',
property: 'CollectionStart_DebutPrelevement',
label: 'Collected date',
usePalette: false
},
yAxis: {
type: 'logarithmic',
property: 'Activity_Activite_mBqm3',
label: 'Activity (mBqm3)'
}
},
category: {
property: 'Radionuclide_Radionucleide',
usePalette: false
},
ui: {
xSlider: {
display: true,
},
ySlider: {
display: true,
step: 0.1
}
},
datasources: [{
display: "Vancouver",
sourceItem: {
Location_Emplacement: "Vancouver"
}
},{
display: "Regina",
sourceItem: {
Location_Emplacement: "Regina"
}
},{
display: "Ottawa",
sourceItem: {
Location_Emplacement: "Ottawa"
}
},{
display: "Montreal",
sourceItem: {
Location_Emplacement: "Montreal"
}
},{
display: "Quebec",
sourceItem: {
Location_Emplacement: "Quebec"
}
}]
};
const DATA_INPUT_LINE_2_SLIM = {
chart: 'line',
title: 'Line Chart slim config',
query: {
type: "esriRegular",
url: "https://maps-cartes.services.geo.ca/server_serveur/rest/services/HC/airborne_radioactivity_en/MapServer/3",
queryOptions: {
whereClauses: [
{
field: "Location_Emplacement",
prefix: "'",
valueFrom: "Location_Emplacement",
suffix: "'"
}],
orderByField: "CollectionStart_DebutPrelevement"
}
},
geochart: {
xAxis: {
type: 'time',
property: 'CollectionStart_DebutPrelevement',
},
yAxis: {
property: 'Activity_Activite_mBqm3',
}
},
category: {
property: 'Radionuclide_Radionucleide',
usePalette: false
},
datasources: [{
display: "Vancouver",
sourceItem: {
Location_Emplacement: "Vancouver"
}
},{
display: "Regina",
sourceItem: {
Location_Emplacement: "Regina"
}
}]
};
const DATA_INPUT_BAR_3 = {
chart: 'bar',
title: 'Bar Chart with OGC Features',
query: {
type: "ogcAPIFeatures",
url: "https://demo.pygeoapi.io/master/collections/lakes",
queryOptions: {
whereClauses: [
{
field: "name",
prefix: "'",
valueIs: "L. Ontario",
suffix: "'"
}]
}
},
geochart: {
xAxis: {
property: 'name',
},
yAxis: {
property: 'id'
}
},
ui: {
resetStates: true,
download: true
},
datasources: [{
display: "Lake info 1",
}, {
display: "Lake info 2",
}]
};
const DATA_INPUT_LINE_3 = {
chart: 'line',
title: 'Line Chart with OGC Features',
query: {
type: "ogcAPIFeatures",
url: "https://api.czs-dev.services.geo.ca/collections/sante_canada_tab",
queryOptions: {
whereClauses: [
{
field: "location_name",
prefix: "'",
valueIs: "8000_8_45.1134_-66.8242",
suffix: "'"
}]
}
},
geochart: {
xAxis: {
type: 'time',
property: 'start_time',
},
yAxis: {
property: 'value_nsvhr'
}
},
ui: {
resetStates: true,
download: true
},
datasources: [{
display: "Data",
}]
};
const DATA_INPUT_2 = {
chart: 'bar',
title: 'Bar Chart',
geochart: {
xAxis: {
property: 'Location_Emplacement',
label: 'Location',
usePalette: false
},
yAxis: {
property: 'Activity_Activite_mBqm3',
label: 'Activity (mBqm3)',
}
},
category: {
property: 'Radionuclide_Radionucleide',
usePalette: false
},
ui: {
xSlider: {
display: true,
},
ySlider: {
display: true,
},
resetStates: true,
download: true
},
datasources: [{
value: "1",
display: "Feature 1",
items: [
{
Location_Emplacement: 'Victoria',
CollectionStart_DebutPrelevement: 1678320000000,
Radionuclide_Radionucleide: '7Be',
Activity_Activite_mBqm3: 2.7395,
OBJECTID: 56874
},
{
Location_Emplacement: 'Vancouver',
CollectionStart_DebutPrelevement: 1669248000000,
Radionuclide_Radionucleide: '7Be',
Activity_Activite_mBqm3: 0.83,
OBJECTID: 56875
},
{
Location_Emplacement: 'Vancouver',
CollectionStart_DebutPrelevement: 1669248000000,
Radionuclide_Radionucleide: '7Be',
Activity_Activite_mBqm3: 2,
OBJECTID: 56871
},
{
Location_Emplacement: 'Yellowknife',
CollectionStart_DebutPrelevement: 1679443200000,
Radionuclide_Radionucleide: '210Pb',
Activity_Activite_mBqm3: 1.0166,
OBJECTID: 56876
},
{
Location_Emplacement: 'Vancouver',
CollectionStart_DebutPrelevement: 1678406400000,
Radionuclide_Radionucleide: '210Pb',
Activity_Activite_mBqm3: 0.939,
OBJECTID: 56877
},
{
Location_Emplacement: 'Montreal',
CollectionStart_DebutPrelevement: 1679011200000,
Radionuclide_Radionucleide: '210Pb',
Activity_Activite_mBqm3: 1.1814,
OBJECTID: 56878
},
{
Location_Emplacement: 'Toronto',
CollectionStart_DebutPrelevement: 1677974400000,
Radionuclide_Radionucleide: '210Pb',
Activity_Activite_mBqm3: 0.6715,
OBJECTID: 56879
},
{
Location_Emplacement: 'Montreal',
CollectionStart_DebutPrelevement: 1668643200000,
Radionuclide_Radionucleide: '7Be',
Activity_Activite_mBqm3: 3.2589,
OBJECTID: 56880
}
]
}]
};
const DATA_INPUT_3 = {
chart: 'pie',
title: 'Pie Chart',
geochart: {
xAxis: {
property: 'Location_Emplacement',
usePalette: false
},
yAxis: {
property: 'Activity_Activite_mBqm3'
}
},
category: {
property: 'Radionuclide_Radionucleide',
usePalette: false
},
ui: {
resetStates: true,
download: true
},
datasources: [{
value: "1",
display: "Feature 1",
items: [
{
Location_Emplacement: 'Victoria',
CollectionStart_DebutPrelevement: 1678320000000,
Radionuclide_Radionucleide: '7Be',
Activity_Activite_mBqm3: 2.7395,
OBJECTID: 56874
},
{
Location_Emplacement: 'Vancouver',
CollectionStart_DebutPrelevement: 1669248000000,
Radionuclide_Radionucleide: '7Be',
Activity_Activite_mBqm3: 0.83,
OBJECTID: 56875
},
{
Location_Emplacement: 'Vancouver',
CollectionStart_DebutPrelevement: 1669248000000,
Radionuclide_Radionucleide: '7Be',
Activity_Activite_mBqm3: 0.83,
OBJECTID: 56871
},
{
Location_Emplacement: 'Yellowknife',
CollectionStart_DebutPrelevement: 1679443200000,
Radionuclide_Radionucleide: '210Pb',
Activity_Activite_mBqm3: 1.0166,
OBJECTID: 56876
},
{
Location_Emplacement: 'Vancouver',
CollectionStart_DebutPrelevement: 1678406400000,
Radionuclide_Radionucleide: '210Pb',
Activity_Activite_mBqm3: 0.939,
OBJECTID: 56877
},
{
Location_Emplacement: 'Montreal',
CollectionStart_DebutPrelevement: 1679011200000,
Radionuclide_Radionucleide: '210Pb',
Activity_Activite_mBqm3: 1.1814,
OBJECTID: 56878
},
{
Location_Emplacement: 'Toronto',
CollectionStart_DebutPrelevement: 1677974400000,
Radionuclide_Radionucleide: '210Pb',
Activity_Activite_mBqm3: 0.6715,
OBJECTID: 56879
},
{
Location_Emplacement: 'Montreal',
CollectionStart_DebutPrelevement: 1668643200000,
Radionuclide_Radionucleide: '7Be',
Activity_Activite_mBqm3: 3.2589,
OBJECTID: 56880
}
]
}]
};
const DATA_INPUT_4 = {
chart: 'doughnut',
title: 'Doughnut Chart',
geochart: {
xAxis: {
property: 'Location_Emplacement',
usePalette: false
},
yAxis: {
property: 'Activity_Activite_mBqm3'
}
},
category: {
property: 'Radionuclide_Radionucleide',
usePalette: false
},
ui: {
resetStates: true,
download: true
},
datasources: [{
value: "1",
display: "Feature 1",
items: [
{
Location_Emplacement: 'Victoria',
CollectionStart_DebutPrelevement: 1678320000000,
Radionuclide_Radionucleide: '7Be',
Activity_Activite_mBqm3: 2.7395,
OBJECTID: 56874
},
{
Location_Emplacement: 'Vancouver',
CollectionStart_DebutPrelevement: 1669248000000,
Radionuclide_Radionucleide: '7Be',
Activity_Activite_mBqm3: 0.83,
OBJECTID: 56875
},
{
Location_Emplacement: 'Vancouver',
CollectionStart_DebutPrelevement: 1669248000000,
Radionuclide_Radionucleide: '7Be',
Activity_Activite_mBqm3: 0.83,
OBJECTID: 56871
},
{
Location_Emplacement: 'Yellowknife',
CollectionStart_DebutPrelevement: 1679443200000,
Radionuclide_Radionucleide: '210Pb',
Activity_Activite_mBqm3: 1.0166,
OBJECTID: 56876
},
{
Location_Emplacement: 'Vancouver',
CollectionStart_DebutPrelevement: 1678406400000,
Radionuclide_Radionucleide: '210Pb',
Activity_Activite_mBqm3: 0.939,
OBJECTID: 56877
},
{
Location_Emplacement: 'Montreal',
CollectionStart_DebutPrelevement: 1679011200000,
Radionuclide_Radionucleide: '210Pb',
Activity_Activite_mBqm3: 1.1814,
OBJECTID: 56878
},
{
Location_Emplacement: 'Toronto',
CollectionStart_DebutPrelevement: 1677974400000,
Radionuclide_Radionucleide: '210Pb',
Activity_Activite_mBqm3: 0.6715,
OBJECTID: 56879
},
{
Location_Emplacement: 'Montreal',
CollectionStart_DebutPrelevement: 1668643200000,
Radionuclide_Radionucleide: '7Be',
Activity_Activite_mBqm3: 3.2589,
OBJECTID: 56880
}
]
}]
};
const DATA_INPUT_5 = {
chart: 'bar',
title: 'The Title 5',
geochart: {
xAxis: {
property: 'label'
},
yAxis: {
property: 'data'
},
},
category: {
property: 'location',
usePalette: false
},
ui: {
xSlider: {
display: true,
},
ySlider: {
display: true,
},
resetStates: true,
download: true
},
datasources: [{
display: "Feature",
items: [{
"data": 92,
"label": "Hockey",
"location": "Victoria"
},{
"data": 43.54,
"label": "Baseball",
"location": "Victoria"
},{
"data": 12.3,
"label": "Basketball",
"location": "Victoria"
},{
"data": 66,
"label": "Football",
"location": "Victoria"
},{
"data": 75,
"label": "Soccer",
"location": "Victoria"
},{
"data": 553,
"label": "Hockey",
"location": "Toronto"
},{
"data": 54,
"label": "Baseball",
"location": "Toronto"
},{
"data": 32.553,
"label": "Basketball",
"location": "Toronto"
},{
"data": 5.43,
"label": "Football",
"location": "Toronto"
},{
"data": 55,
"label": "Soccer",
"location": "Toronto"
},{
"data": 155,
"label": "Hockey",
"location": "Montreal"
},{
"data": 55,
"label": "Baseball",
"location": "Montreal"
},{
"data": 255,
"label": "Basketball",
"location": "Montreal"
}]
}]
};
const DATA_INPUT_6 = {
"chart": "line",
"title": "Line Chart with time on x and sliders",
"query": {
"type": "esriRegular",
"url": "https://services1.arcgis.com/HsjBaDykC1mjhXz9/ArcGIS/rest/services/CRMN___Tritium_in_Atmospheric_Water_Vapour_WFL1/FeatureServer/3",
"queryOptions": {
"whereClauses": [
{
"field": "Station",
"prefix": "'",
"valueFrom": "Station",
"suffix": "'"
}
],
"orderByField": "Date"
}
},
"geochart": {
"xAxis": {
"type": "time",
"property": "Date",
"label": "Collected date"
},
"yAxis": {
"type": "linear",
"property": "Activity_Activite_Bqm3",
"label": "Activity (mBqm3)",
"tooltipSuffix": "mBqm3"
},
"borderWidth": 1
},
"ui": {
"xSlider": {
"display": true
},
"ySlider": {
"display": true
},
"stepsSwitcher": true,
"resetStates": true,
"description": "This is an ArcGIS Online layer chart",
"download": true
},
"datasources": [
{
"display": "GE7",
"sourceItem": {
"Station": "GE7"
}
}
]
};
const OPTIONS_NATIVE_1 = {
responsive: true,
plugins: {
legend: {
display: false
}
}
};
const OPTIONS_NATIVE_2 = {
responsive: true,
plugins: {
legend: {
display: false
}
},
scales: {
y: {
border: {
color: "red"
},
suggestedMin: 0,
suggestedMax: 50,
}
}
};
const DATA_NATIVE_1 = {
labels: ['Hockey', 'Baseball', 'Baseketball', 'Football', 'Soccer', 'Curling'],
datasets: [
{
data: [12, 19, 3, 5, 2, 3],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)',
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)',
],
borderWidth: 1,
},
]
};
const DATA_NATIVE_2 = {
labels: ['Hockey', 'Baseball', 'Baseketball', 'Football', 'Soccer', 'Curling'],
datasets: [
{
label: 'Dataset 1',
data: [12, 19, 3, 5, 2, 3],
borderColor: "rgb(53, 162, 235)",
backgroundColor: 'rgba(53, 162, 235, 0.5)',
},
{
label: 'Dataset 2',
data: [22, 29, 13, 15, 12, 13],
borderColor: "rgb(255, 99, 132)",
backgroundColor: 'rgba(255, 99, 132, 0.5)',
},
],
};
const DATA_NATIVE_3 = {
labels: ['Hockey', 'Baseball', 'Baseketball', 'Football', 'Soccer', 'Curling'],
datasets: [
{
label: 'Dataset 1',
data: [12, 19, 3, 5, 2, 3],
borderColor: "rgb(53, 162, 235)",
backgroundColor: 'rgba(53, 162, 235, 0.5)',
stepped: 'middle',
},
{
label: 'Dataset 2',
data: [22, 29, 13, 15, 12, 13],
borderColor: "rgb(255, 99, 132)",
backgroundColor: 'rgba(255, 99, 132, 0.5)',
stepped: 'middle',
},
],
};
const DATA_NATIVE_4 = {
labels: ['Hockey', 'Baseball', 'Baseketball'],
datasets: [{
data: [{"x": 10, "y": 15}, {"x": 15, "y": 25}, {"x": 20, "y": 10}]
}]
};
</script>
</head>
<body>
<div style="text-align: center; height: 440px;">
<div style="display:inline-block; background-color: lightgreen; width: 49%; height: 100%; 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>
<span>Language: </span>
<select id="lang" onChange="languageChanged()">
<option selected value="en">English</option>
<option value="fr">Français</option>
</select>
</div>
<div>
<div>
<button onclick="importDataInputs(DATA_INPUT_LINE_1)">Import Chart w/ time w/steps</button>
<button onclick="importDataInputs(DATA_INPUT_LINE_2)">Import Chart w/ time logar. w/tension</button>
<button onclick="importDataInputs(DATA_INPUT_LINE_2_SLIM)">Import Chart slim</button>
<button onclick="importDataInputs(DATA_INPUT_LINE_3)">Imp. OGC Line</button>
<button onclick="importDataInputs(DATA_INPUT_BAR_3)">Imp. OGC Bar</button>
<br/>
<button onclick="importDataInputs(DATA_INPUT_2)">Import Data BAR</button>
<button onclick="importDataInputs(DATA_INPUT_3)">Import Data PIE</button>
<button onclick="importDataInputs(DATA_INPUT_4)">Import Data DOUGHNUT</button>
<button onclick="importDataInputs(DATA_INPUT_5)">Import Data BAR simple</button>
<button onclick="importDataInputs(DATA_INPUT_6)">Import Data w/ nulls</button>
</div>
<div>
<textarea id="CHARTDATAINPUTS" rows="18" style="width: 98%;"></textarea>
</div>
</div>
<div>
<button onclick="buildChartInputs()" style="padding:5px;"><strong>BUILD CHART FROM GEOCHART INPUTS</strong></button>
</div>
</div>
<div style="display:inline-block; background-color: aliceblue; width: 50%; height: 100%; 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="importOptionsParsed(OPTIONS_NATIVE_1)">Import Options (default)</button>
<button onclick="importOptionsParsed(OPTIONS_NATIVE_2)">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="importDataParsed(DATA_NATIVE_1)">Import Data 1 rec</button>
<button onclick="importDataParsed(DATA_NATIVE_2)">Import Data 2 recs</button>
<button onclick="importDataParsed(DATA_NATIVE_3)">Import Data 2 recs w/ steps</button>
<button onclick="importDataParsed(DATA_NATIVE_4)">Import Data using x,y</button>
</div>
<div>
<textarea id="CHARTDATAPARSED" rows="18" style="width: 98%"></textarea>
</div>
</div>
</div>
<div>
<button onclick="buildChartNative()" style="padding:5px;"><strong>BUILD CHART FROM CHART.JS PROPS</strong></button>
</div>
</div>
</div>
<!--------------- CHART IS HERE ----------------->
<div id="root2aca7b6b288c" style="position: relative; width: 800px;"></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>
function importDataInputs(inputs) {
document.getElementById('CHARTDATAINPUTS').value = JSON.stringify(inputs, null, 2);
}
function importDataParsed(data) {
document.getElementById('CHARTDATAPARSED').value = JSON.stringify(data, null, 2);
}
function importOptionsParsed(options) {
document.getElementById('CHARTOPTIONSPARSED').value = JSON.stringify(options, null, 2);
}
function buildChartInputs() {
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.
window.dispatchEvent(new CustomEvent("chart/load", { detail: { inputs: chartInputs } }));
}
function buildChartNative() {
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.
window.dispatchEvent(new CustomEvent("chart/load", { detail: { chart: chartType, data: chartData, options: chartOptions } }));
}
function redrawChart() {
// Emit a Chart Redraw event so the chart updates
window.dispatchEvent(new CustomEvent("chart/redraw"));
}
function languageChanged() {
// Emit a Chart Language changed event so the chart updates
window.dispatchEvent(new CustomEvent("chart/language", { detail: { language: event.target.value } }));
}
function isLoadingState(state) {
// Emit a Chart Redraw event so the chart updates
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
importDataInputs(DATA_INPUT_LINE_1); // DATA_INPUT_LINE_3
importDataParsed(DATA_NATIVE_1);
importOptionsParsed(OPTIONS_NATIVE_1);
// Wait 1 second for index.tsx to execute and the Chart to enter the DOM.
// This is hacky, but it's only to load default values off the start. It is also because we don't have a cgpv.init callback.
setTimeout(() => {
buildChartInputs();
}, 1000);
// Listen on the chart parsed to update the UI
window.addEventListener('chart/parsed', handleChartLoaded);
</script>
</body>
</html>