-
Notifications
You must be signed in to change notification settings - Fork 52
/
PublicLab.Grapher.js
1951 lines (1614 loc) · 94.6 KB
/
PublicLab.Grapher.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
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
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
"use strict";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var ChartjsPlotter =
/*#__PURE__*/
function () {
_createClass(ChartjsPlotter, [{
key: "determineType",
value: function determineType() {
console.log("at type");
if (this.graphType == "Basic" || this.graphType == "Stepped" || this.graphType == "Point") {
return 'line';
} else if (this.graphType == "Horizontal") {
return 'horizontalBar';
} else if (this.graphType == "Vertical") {
return 'bar';
} else {
return this.graphType.toLowerCase();
}
}
}, {
key: "colorGenerator",
value: function colorGenerator(i, tb, count) {
console.log("at color");
var colors = ['rgba(255, 77, 210, 0.5)', 'rgba(0, 204, 255, 0.5)', 'rgba(128, 0, 255, 0.5)', 'rgba(255, 77, 77, 0.5)', 'rgba(0, 179, 0, 0.5)', 'rgba(255, 255, 0, 0.5)', 'rgba(255, 0, 102, 0.5)', 'rgba(0, 115, 230, 0.5)'];
var bordercolors = ['rgb(255, 0, 191)', 'rgb(0, 184, 230)', 'rgb(115, 0, 230)', 'rgb(255, 51, 51)', 'rgb(0, 153, 0)', 'rgb(230, 230, 0)', 'rgb(230, 0, 92)', 'rgb(0, 102, 204)'];
var length = 8;
if (this.graphType == "Pie" || this.graphType == "Doughnut") {
var colorSet = [];
var borderColorSet = [];
for (var j = 0; j < count; j++) {
colorSet.push(colors[j % length]);
borderColorSet.push(bordercolors[j % length]);
}
if (tb == "bg") {
return colorSet;
} else {
return borderColorSet;
}
} else {
if (tb == "bg") {
return colors[i % length];
} else {
return bordercolors[i % length];
}
}
}
}, {
key: "determineData",
value: function determineData(i) {
console.log("at data");
var h = {};
if (this.graphType == "Basic") {
h['fill'] = false;
} else if (this.graphType == "Stepped") {
h['steppedLine'] = true;
h['fill'] = false;
} else if (this.graphType == "Point") {
h['showLine'] = false;
h['pointRadius'] = 10;
}
h['backgroundColor'] = this.colorGenerator(i, "bg", this.dataHash['y_axis_values' + i].length);
h['borderColor'] = this.colorGenerator(i, "bo", this.dataHash['y_axis_values' + i].length);
h['borderWidth'] = 1;
h['label'] = this.dataHash['labels'][1][i];
h['data'] = this.dataHash['y_axis_values' + i];
return h;
}
}, {
key: "determineConfig",
value: function determineConfig() {
console.log("at config");
var config = {};
config['type'] = this.determineType();
var data = {};
data['labels'] = this.dataHash['x_axis_labels'];
var datasets = [];
for (var i = 0; i < this.length; i++) {
var h = this.determineData(i);
datasets.push(h);
}
var options = {
'responsive': true,
'maintainAspectRatio': true,
'chartArea': {
backgroundColor: 'rgb(204, 102, 255)'
}
};
options['scales'] = this.scales();
config['options'] = options;
data['datasets'] = datasets;
config['data'] = data;
return config;
}
}, {
key: "scales",
value: function scales() {
console.log("at scales");
var scales = {
xAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: this.dataHash['labels'][0]
}
}],
yAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'Value'
}
}]
};
return scales;
}
}, {
key: "saveAsImageFunction",
value: function saveAsImageFunction(canvId) {
console.log("entered image");
var newDate = new Date();
var timestamp = newDate.getTime();
var temp = canvId;
temp = "#" + temp;
$(temp).get(0).toBlob(function (blob) {
saveAs(blob, "chart" + timestamp);
});
}
}, {
key: "createSaveAsImageButton",
value: function createSaveAsImageButton(canvasDiv, canvasId) {
var saveImageButton = document.createElement("BUTTON");
saveImageButton.classList.add("btn");
saveImageButton.classList.add("btn-primary");
saveImageButton.innerHTML = "Save as Image";
saveImageButton.id = canvasId + "image";
canvasDiv.appendChild(saveImageButton);
console.log(this, "this");
var self = this;
document.getElementById(saveImageButton.id).onclick = function (e) {
self.saveAsImageFunction(canvasId);
};
}
}, {
key: "plotGraph",
value: function plotGraph() {
if (this.flag) {
console.log("at plotGraph");
document.getElementById(this.canvasContainerId).innerHTML = "";
}
var div = document.createElement('div');
div.classList.add(this.elementId + '_chart_container_' + this.graphCounting);
var canv = document.createElement('canvas');
canv.id = this.elementId + '_canvas_' + this.graphCounting;
div.appendChild(canv);
document.getElementById(this.canvasContainerId).appendChild(div);
var ctx = canv.getContext('2d');
var configuration = this.determineConfig();
new Chart(ctx, configuration);
this.createSaveAsImageButton(div, canv.id); // $('.'+this.carousalClass).carousel(2);
}
}]);
function ChartjsPlotter(hash, length, type, flag, canvasContainerId, elementId, graphCounting) {
_classCallCheck(this, ChartjsPlotter);
_defineProperty(this, 'use strict', void 0);
_defineProperty(this, "dataHash", {});
_defineProperty(this, "elementId", null);
_defineProperty(this, "graphCounting", 0);
_defineProperty(this, "canvasContainerId", null);
_defineProperty(this, "graphType", null);
_defineProperty(this, "length", 0);
_defineProperty(this, "flag", false);
this.dataHash = hash;
this.length = length;
this.graphType = type;
this.flag = flag;
this.canvasContainerId = canvasContainerId;
this.elementId = elementId;
this.graphCounting = graphCounting;
this.plotGraph();
}
return ChartjsPlotter;
}();
module.exports = ChartjsPlotter;
},{}],2:[function(require,module,exports){
"use strict";
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
// import {SimpleDataGrapher} from "./SimpleDataGrapher";
var SimpleDataGrapher = require('./SimpleDataGrapher');
var Papa = require("papaparse");
var CsvParser =
/*#__PURE__*/
function () {
//start is variable that will be passed to the function to sort out the columns. start will tell if the existing CSV file has headers or not, therefore, to start the iteration from 0 or 1 Used in header determination
function CsvParser(file, elementId, functionParameter) {
_classCallCheck(this, CsvParser);
_defineProperty(this, 'use strict', void 0);
_defineProperty(this, "csvFile", null);
_defineProperty(this, "csvMatrix", []);
_defineProperty(this, "csvHeaders", []);
_defineProperty(this, "csvFileStart", 1);
_defineProperty(this, "completeCsvMatrix", []);
_defineProperty(this, "completeCsvMatrixTranspose", []);
_defineProperty(this, "csvSampleData", []);
_defineProperty(this, "csvValidForYAxis", []);
_defineProperty(this, "elementId", null);
_defineProperty(this, "codapHeaders", []);
_defineProperty(this, "codapMatrix", []);
this.elementId = elementId;
this.csvFile = file;
if (functionParameter == "prevfile") {
return this;
} else {
this.allFunctionHandler(functionParameter);
}
} //since parsing a local file works asynchronously, a callback function is required to call the remaining functions after the parsing is complete
_createClass(CsvParser, [{
key: "callbackForLocalFile",
value: function callbackForLocalFile(csvMatrixLocal) {
this.csvMatrix = csvMatrixLocal;
this.csvHeaders = this.determineHeaders();
this.completeCsvMatrix = this.matrixForCompleteData();
var totalData = this.extractSampleData();
this.csvSampleData = totalData[0];
this.csvValidForYAxis = totalData[1];
this.completeCsvMatrixTranspose = this.createTranspose();
this.codapHeaders = this.headersForCodap();
this.codapMatrix = this.completeMatrixForCodap();
this.startFileProcessing();
} //a function handler that calls one function after the other after assigning the correct values to different class variables.
}, {
key: "allFunctionHandler",
value: function allFunctionHandler(functionParameter) {
if (functionParameter == "local") {
this.csvMatrix = this.parse();
} else {
if (functionParameter == "csvstring" || functionParameter == "remote") {
this.csvFile = this.csvFile.split("\n");
this.csvMatrix = this.parseString();
this.csvHeaders = this.determineHeaders();
this.completeCsvMatrix = this.matrixForCompleteData();
} else {
this.csvHeaders = this.headersForGoogleSheet();
this.completeCsvMatrix = this.completeMatrixForGoogleSheet();
}
var totalData = this.extractSampleData();
this.csvSampleData = totalData[0];
this.csvValidForYAxis = totalData[1];
this.completeCsvMatrixTranspose = this.createTranspose();
this.codapHeaders = this.headersForCodap();
this.codapMatrix = this.completeMatrixForCodap();
this.startFileProcessing();
}
} //parsing a local file, works asynchronously
}, {
key: "parse",
value: function parse() {
var _this = this;
var csvMatrixLocal = [];
var count = 0;
var f = this.parseReturn;
Papa.parse(this.csvFile, {
download: true,
dynamicTyping: true,
comments: true,
step: function step(row) {
csvMatrixLocal[count] = row.data[0];
count += 1;
},
complete: function complete() {
_this.callbackForLocalFile(csvMatrixLocal);
}
});
} // parsing string: for remote and csvString import options. Dat is parsed line by line but NOT asynchronously.
}, {
key: "parseString",
value: function parseString() {
var mat = [];
for (var i = 0; i < this.csvFile.length; i++) {
if (this.csvFile[i] == "" || this.csvFile[i] == " ") {
continue;
}
var dataHash = Papa.parse(this.csvFile[i], {
dynamicTyping: true,
comments: true
});
mat[i] = dataHash['data'][0];
}
return mat;
} // checks for the presence of the corresponding View object in elementIdSimpleDataGraphInstanceMap, if present, the CsvParser object is assigned to the View object and the flow resumes from View.js file
}, {
key: "startFileProcessing",
value: function startFileProcessing() {
var self = this;
if (self.elementId in SimpleDataGrapher.SimpleDataGrapher.elementIdSimpleDataGraphInstanceMap) {
SimpleDataGrapher.SimpleDataGrapher.elementIdSimpleDataGraphInstanceMap[self.elementId].view.continueViewManipulation(self);
}
} //preparing sample data for the user to choose the columns from
}, {
key: "extractSampleData",
value: function extractSampleData() {
var maxval = 5;
var csvSampleDataLocal = [];
var csvValidForYAxisLocal = [];
var totalDataLocal = [];
for (var i = 0; i < this.csvHeaders.length; i++) {
csvSampleDataLocal[i] = [];
}
if (this.completeCsvMatrix.length[0] < 5) {
maxval = this.completeCsvMatrix[0].length;
}
for (var i = 0; i < this.csvHeaders.length; i++) {
var counter = 0;
var bool = false;
for (var j = 0; j < this.completeCsvMatrix[i].length; j++) {
if (counter >= maxval) {
break;
} else if (this.completeCsvMatrix[i][j] !== null || this.completeCsvMatrix[i][j] !== undefined) {
if (typeof this.completeCsvMatrix[i][j] === 'number') {
bool = true;
}
counter += 1;
csvSampleDataLocal[i].push(this.completeCsvMatrix[i][j]);
}
}
if (bool) {
csvValidForYAxisLocal.push(this.csvHeaders[i]);
}
}
totalDataLocal = [csvSampleDataLocal, csvValidForYAxisLocal];
return totalDataLocal;
} //makes a 2D matrix with the transpose of the CSV file, each column having the same index as its column heading
}, {
key: "matrixForCompleteData",
value: function matrixForCompleteData() {
var completeCsvMatrixLocal = [];
for (var i = 0; i < this.csvHeaders.length; i++) {
completeCsvMatrixLocal[i] = [];
}
for (var i = this.csvFileStart; i < this.csvMatrix.length; i++) {
for (var j = 0; j < this.csvHeaders.length; j++) {
completeCsvMatrixLocal[j].push(this.csvMatrix[i][j]);
}
}
return completeCsvMatrixLocal;
} //Google Sheet's data is in a JSON, traversal through the JSON and string manipulation are used to extract the data
}, {
key: "completeMatrixForGoogleSheet",
value: function completeMatrixForGoogleSheet() {
var matrixComplete = [];
for (var i = 0; i < this.csvHeaders.length; i++) {
matrixComplete[i] = [];
}
for (var i = 0; i < this.csvHeaders.length; i++) {
for (var key in this.csvFile) {
var valueCell = this.csvFile[key][this.csvHeaders[i]]["$t"];
if (!isNaN(valueCell)) {
matrixComplete[i].push(+valueCell);
} else {
matrixComplete[i].push(valueCell);
}
}
}
for (var i = 0; i < this.csvHeaders.length; i++) {
this.csvHeaders[i] = this.csvHeaders[i].slice(4, this.csvHeaders[i].length);
}
return matrixComplete;
} // matrix in JSON form for CODAP export
}, {
key: "completeMatrixForCodap",
value: function completeMatrixForCodap() {
var codapMatrix = [];
for (var i = 1; i < this.completeCsvMatrixTranspose.length; i++) {
var element = {};
for (var j = 0; j < this.csvHeaders.length; j++) {
element[this.csvHeaders[j]] = this.completeCsvMatrixTranspose[i][j];
}
codapMatrix.push(element);
}
console.log("matrix codap", codapMatrix);
return codapMatrix;
} //checks if the first row has most of the potential header names, if not, assign dummy headers to the file.
}, {
key: "determineHeaders",
value: function determineHeaders() {
var csvHeadersLocal = [];
var flag = false;
for (var i = 0; i < this.csvMatrix[0].length; i++) {
if (i == 0) {
if (typeof this.csvMatrix[0][i] == "string") {
csvHeadersLocal[i] = this.csvMatrix[0][i];
} else {
flag = true;
break;
}
} else {
if (_typeof(this.csvMatrix[0][i]) == _typeof(this.csvMatrix[0][i - 1]) && _typeof(this.csvMatrix[0][i]) != 'object' || _typeof(this.csvMatrix[0][i]) != _typeof(this.csvMatrix[0][i - 1]) && csvHeadersLocal[i - 1].substring(0, 6) == "Column") {
csvHeadersLocal[i] = this.csvMatrix[0][i];
} //in case of an unnamed column
else if (_typeof(this.csvMatrix[0][i]) == 'object') {
csvHeadersLocal[i] = "Column" + (i + 1);
} else {
flag = true;
break;
}
}
} //if there are no headers present, make dummy header names
if (flag && csvHeadersLocal.length != this.csvMatrix[0].length) {
this.csvFileStart = 0;
for (var i = 0; i < this.csvMatrix[0].length; i++) {
csvHeadersLocal[i] = "Column" + (i + 1);
}
}
return csvHeadersLocal;
} //Google Sheet's data is in a JSON, extracting column names by string slicing
}, {
key: "headersForGoogleSheet",
value: function headersForGoogleSheet() {
var headers_sheet = [];
for (var key in this.csvFile) {
var h = this.csvFile[key];
for (var headKey in h) {
if (headKey.slice(0, 4) == "gsx$") {
headers_sheet.push(headKey);
}
}
break;
}
return headers_sheet;
} //determine a JSON for headers for CODAP
}, {
key: "headersForCodap",
value: function headersForCodap() {
var codapHeaders = [];
for (var i = 0; i < this.csvHeaders.length; i++) {
var element = {};
element["name"] = this.csvHeaders[i];
codapHeaders.push(element);
}
return codapHeaders;
} // creating the transpose of the entire data ie complete data + headers, for createSpreadsheet in View.js
}, {
key: "createTranspose",
value: function createTranspose() {
var completeCsvMatrixTransposeLocal = [];
for (var i = 0; i <= this.completeCsvMatrix[0].length; i++) {
completeCsvMatrixTransposeLocal[i] = [];
}
for (var i = 0; i < this.completeCsvMatrix.length; i++) {
completeCsvMatrixTransposeLocal[0][i] = this.csvHeaders[i];
}
for (var i = 0; i < this.completeCsvMatrix.length; i++) {
for (var j = 0; j < this.completeCsvMatrix[0].length; j++) {
completeCsvMatrixTransposeLocal[j + 1][i] = this.completeCsvMatrix[i][j];
}
}
console.log("transpose", completeCsvMatrixTransposeLocal);
return completeCsvMatrixTransposeLocal;
}
}]);
return CsvParser;
}();
;
module.exports = CsvParser;
},{"./SimpleDataGrapher":4,"papaparse":11}],3:[function(require,module,exports){
"use strict";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var PlotlyjsPlotter =
/*#__PURE__*/
function () {
_createClass(PlotlyjsPlotter, [{
key: "determineType2",
value: function determineType2() {
if (this.graphType == "Horizontal" || this.graphType == "Vertical") {
return "bar";
} else if (this.graphType == "Pie" || this.graphType == "Doughnut" || this.graphType == "Radar") {
return "pie";
} else if (this.graphType == "Basic" || this.graphType == "Stepped" || this.graphType == "Point") {
return "scatter";
}
}
}, {
key: "layoutMaker",
value: function layoutMaker() {
var layout = {};
if (this.graphType == "Horizontal" || this.graphType == "Vertical") {
layout["barmode"] = "group";
}
return layout;
}
}, {
key: "traceMaker",
value: function traceMaker() {
var trace = {};
trace["type"] = this.determineType2();
if (this.graphType == "Horizontal") {
trace["orientation"] = "h";
} else if (this.graphType == "Doughnut") {
trace["hole"] = 0.5;
} else if (this.graphType == "Basic") {
trace["mode"] = "lines";
} else if (this.graphType == "Point") {
trace["mode"] = "markers";
} else if (this.graphType == "Stepped") {
trace["mode"] = "lines+markers";
trace["line"] = {
"shape": 'hv'
};
}
return trace;
}
}, {
key: "keyDeterminer",
value: function keyDeterminer() {
var keys = ["x", "y"];
if (this.graphType == "Pie" || this.graphType == "Doughnut") {
keys[1] = "values";
keys[0] = "labels";
} else if (this.graphType == "Horizontal") {
keys[0] = "y";
keys[1] = "x";
}
return keys;
}
}, {
key: "plotGraph2",
value: function plotGraph2() {
if (this.flag) {
console.log("at plotGraph");
document.getElementById(this.canvasContainerId).innerHTML = "";
}
var layout = this.layoutMaker();
var data = [];
var keySet = this.keyDeterminer();
for (var i = 0; i < this.length; i++) {
var new_trace = this.traceMaker();
new_trace[keySet[0]] = this.dataHash['x_axis_labels'];
new_trace[keySet[1]] = this.dataHash['y_axis_values' + i];
new_trace["name"] = this.dataHash['labels'][1][i];
data.push(new_trace);
}
console.log(data);
var div = document.createElement('div');
div.id = this.elementId + '_chart_container_' + this.graphCounting;
document.getElementById(this.canvasContainerId).appendChild(div);
Plotly.newPlot(div.id, data, layout);
}
}]);
function PlotlyjsPlotter(hash, length, type, flag, canvasContainerId, elementId, graphCounting) {
_classCallCheck(this, PlotlyjsPlotter);
_defineProperty(this, 'use strict', void 0);
_defineProperty(this, "dataHash", {});
_defineProperty(this, "elementId", null);
_defineProperty(this, "graphCounting", 0);
_defineProperty(this, "canvasContainerId", null);
_defineProperty(this, "graphType", null);
_defineProperty(this, "length", 0);
_defineProperty(this, "flag", false);
this.dataHash = hash;
this.length = length;
this.graphType = type;
this.flag = flag;
this.canvasContainerId = canvasContainerId;
this.elementId = elementId;
this.graphCounting = graphCounting;
this.plotGraph2();
}
return PlotlyjsPlotter;
}();
module.exports = PlotlyjsPlotter;
},{}],4:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.SimpleDataGrapher = void 0;
var _View = require("./View");
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var SimpleDataGrapher = function SimpleDataGrapher(elementId) {
_classCallCheck(this, SimpleDataGrapher);
_defineProperty(this, 'use strict', void 0);
_defineProperty(this, "elementId", null);
_defineProperty(this, "view", null);
this.elementId = elementId;
SimpleDataGrapher.elementIdSimpleDataGraphInstanceMap[this.elementId] = this;
console.log(SimpleDataGrapher.elementIdSimpleDataGraphInstanceMap[this.elementId]);
this.view = new _View.View(elementId);
};
exports.SimpleDataGrapher = SimpleDataGrapher;
_defineProperty(SimpleDataGrapher, "elementIdSimpleDataGraphInstanceMap", {});
;
window.SimpleDataGrapher = SimpleDataGrapher;
},{"./View":5}],5:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.View = void 0;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var CsvParser = require('./CsvParser');
var SimpleDataGrapher = require('./SimpleDataGrapher');
var ChartjsPlotter = require('./ChartjsPlotter');
var PlotlyjsPlotter = require('./PlotlyjsPlotter');
var iframe_phone = require('iframe-phone');
var View =
/*#__PURE__*/
function () {
_createClass(View, [{
key: "handleFileSelectlocal",
//extracts the uploaded file from input field and creates an object of CsvParser class with the file as one of the parameters
value: function handleFileSelectlocal(event) {
this.csvFile = event.target.files[0];
console.log(event.target.files[0]);
console.log("iam here in handle");
if (this.csvFile['name'].split(".")[1] != "csv") {
alert("Invalid file type");
} else {
$('#' + this.dragDropHeadingId).text(this.csvFile['name']);
var self = this;
document.getElementById(this.uploadButtonId).onclick = function (e) {
self.csvParser = new CsvParser(self.csvFile, self.elementId, "local");
};
}
} //receives the string value and creates an object of CsvParser class with the string as one of the parameters
}, {
key: "handleFileSelectstring",
value: function handleFileSelectstring(val) {
console.log("i am at csv string handler", val); // var csv_string = val.split("\n");
this.csvFile = val;
var self = this;
document.getElementById(this.uploadButtonId).onclick = function (e) {
console.log("i am uploading");
self.csvParser = new CsvParser(self.csvFile, self.elementId, "csvstring");
};
} // function for using a previously uploaded and saved file from the data base
}, {
key: "usingPreviouslyUploadedFile",
value: function usingPreviouslyUploadedFile() {
var self = this;
console.log("prev file in use", self.elementId);
self.csvParser = new CsvParser("dummy", self.elementId, "prevfile");
console.log(self.csvParser, "checking");
} //receives the JSON file value and creates an object of CsvParser class with the file as one of the parameters
}, {
key: "handleFileSelectGoogleSheet",
value: function handleFileSelectGoogleSheet(googleSheetData) {
this.csvFile = googleSheetData;
var self = this;
document.getElementById(this.uploadButtonId).onclick = function (e) {
self.csvParser = new CsvParser(self.csvFile, self.elementId, "googleSheet");
};
} // get's the JSON form of the Google Sheet through Google Sheet's URL and passes it to the handler
}, {
key: "getValueGoogleSheet",
value: function getValueGoogleSheet(googleSheetLink) {
var self = this;
$.getJSON(googleSheetLink, function (data) {
self.handleFileSelectGoogleSheet(data.feed.entry);
});
} // uses a CORS proxy to fetch the value of a remote files and passes the received value to a callback function
}, {
key: "sendRemoteFileToHandler",
value: function sendRemoteFileToHandler(val) {
var _this = this;
var proxyurl = "https://cors-anywhere.herokuapp.com/";
var url = val;
fetch(proxyurl + url).then(function (response) {
return response.text();
}).then(function (contents) {
return _this.handleFileSelectremote(contents);
})["catch"](function (e) {
return console.log(e);
});
} // callback function which receives the remote file's value and creates an object of CsvParser class with the file as one of the parameters
}, {
key: "handleFileSelectremote",
value: function handleFileSelectremote(remoteVal) {
this.csvFile = remoteVal;
var self = this;
document.getElementById(this.uploadButtonId).onclick = function (e) {
console.log("i am uploading");
self.csvParser = new CsvParser(self.csvFile, self.elementId, "remote");
};
} // adapter function which switches between Plotly.js and Chart.js as a graph plotting library and creates theri respective objects which take over the graph plotting
}, {
key: "plotGraph",
value: function plotGraph(hash, length, type, flag, library) {
if (library == "chartjs") {
this.chartjsPlotter = new ChartjsPlotter(hash, length, type, flag, this.canvasContinerId, this.elementId, this.graphCounting);
} else {
this.plotlyjsPlotter = new PlotlyjsPlotter(hash, length, type, flag, this.canvasContinerId, this.elementId, this.graphCounting);
}
$('.' + this.carousalClass).carousel(2);
} //set tool tip for impot options
}, {
key: "setTooltip",
value: function setTooltip(importType) {
if (importType === "container_drag_drop") {
return "Select a local file from your system";
} else if (importType === "container_csv_string") {
var x = "Type in or Paste a CSV string. \r\n";
x += "Example: \r\n";
x += "A,B,C \r\n";
x += "1,2,3";
return x;
} else if (importType === "container_remote_link") {
return "Type in or Paste the link of a remote CSV file. Example: \
http://example.com/example.csv";
} else if (importType === "container_google_sheet") {
return "Type in or Paste the link of a Published Google Sheet. To publish a Google Sheet: 1. File -> Publish to the web -> Publish 2. Share -> Get shareable link -> Anyone with the link can -> More -> On - Public on the web -> Save 3. Copy link";
}
} //set tool tip for graph tips
}, {
key: "setTooltipGraph",
value: function setTooltipGraph(graphType) {
if (graphType == "Horizontal") {
return "Data is categorical and tells how many, widths proportional to the values";
} else if (graphType === "Vertical") {
return "Data is categorical and tells how many, heights proportional to the values";
} else if (graphType == "Stacked") {
return "Ideal for comparing the total amounts across each group/segmented bar";
} else if (graphType == "Basic") {
return "Used to visualize a trend in data over intervals of time or to see the growth of a quantity";
} else if (graphType == "Stepped") {
return "Vertical parts of a step chart denote changes in the data and their magnitude";
} else if (graphType == "Point") {
return "Used to show the relationship between two data variables";
} else if (graphType == "Pie") {
return "Used to show percentage or proportional data, should be used for less number of categories";
} else if (graphType == "Doughnut") {
return "Used to show percentage or proportional data, but have better data intensity ratio and space efficiency";
} else if (graphType == "Radar") {
return "Used to display multivariate observations with an arbitrary number of variables";
}
} // create a popover against each import method for adding a file title and description
}, {
key: "createPopover",
value: function createPopover(buttonId) {
var self = this;
var html = '<div id="myForm" class="hide"><label for="title" class="popover_headings">File Title:</label><input type="text" name="title" id=' + "title" + buttonId + ' class="form-control input-md"><label for="desc" class="popover_headings">File Description:</label><textarea rows="3" name="desc" id=' + "desc" + buttonId + ' class="form-control input-md"></textarea><button type="button" class="btn btn-primary popover_headings" id="save"> Save</button></div>';
$('#' + buttonId).popover({
placement: 'bottom',
title: 'Add Description',
html: true,
content: html
}).on('click', function () {
console.log("created popover");
$('#save').click(function (e) {
e.preventDefault();
self.fileTitle = $('#' + "title" + buttonId).val();
self.fileDescription = $('#' + "desc" + buttonId).val();
console.log(self.fileTitle, self.fileDescription, self, "got it");
});
});
} // renders the required buttons for saving the files if the use is logged in
}, {
key: "createButtons",
value: function createButtons(userLoginCheck) {
this.listenersForIntegration();
if (userLoginCheck == "yes") {
var save_file_button = document.createElement('button');
save_file_button.classList.add("btn");
save_file_button.classList.add("btn-primary");
save_file_button.innerHTML = "Save CSV";
save_file_button.id = this.elementId + "_save_CSV";
var upload_prev_file = document.createElement('button');
upload_prev_file.classList.add("btn");
upload_prev_file.classList.add("btn-primary");
upload_prev_file.innerHTML = "Choose a previously uploaded file";
upload_prev_file.id = this.elementId + "_prev_file";
var publish_research_button = document.createElement('button');
publish_research_button.classList.add("btn");
publish_research_button.classList.add("btn-primary");
publish_research_button.innerHTML = "Publish as a Research Note";
publish_research_button.id = this.elementId + "_publish";
var container = document.getElementById(this.upload_button_container);
var div_container = document.createElement('div');
div_container.appendChild(save_file_button);
div_container.appendChild(upload_prev_file);
var container2 = document.getElementById(this.feature_button_container);
container2.appendChild(publish_research_button);
container.prepend(div_container);
}
} // create dataset for CODAP table
}, {
key: "createDataset",
value: function createDataset() {
var dataset = {};
dataset["action"] = "create";
dataset["resource"] = "dataContext";
var values = {};
values["name"] = "my dataset";
values["title"] = "Case Table";
var collections = [];
var hashCollections = {};
hashCollections["name"] = "cases";
hashCollections["attrs"] = this.csvParser.codapHeaders;
collections.push(hashCollections);
values["collections"] = collections;
dataset["values"] = values;
var dataset2 = {};
dataset2["action"] = "create";
dataset2["resource"] = "dataContext[my dataset].item";
dataset2["values"] = this.csvParser.codapMatrix;
var dataset3 = {};
dataset3["action"] = "create";
dataset3["resource"] = "component";
var values3 = {};
values3["type"] = "caseTable";
values3["dataContext"] = "my dataset";
dataset3["values"] = values3;