aboutsummaryrefslogtreecommitdiff
path: root/docs/coverage/lib/crosstalk-1.2.1/js/crosstalk.js
blob: fd9eb53d224fcc9f64c9cfebe0f490c03f8b755f (plain) (blame)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
(function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}return e})()({1:[function(require,module,exports){
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Events = function () {
  function Events() {
    _classCallCheck(this, Events);

    this._types = {};
    this._seq = 0;
  }

  _createClass(Events, [{
    key: "on",
    value: function on(eventType, listener) {
      var subs = this._types[eventType];
      if (!subs) {
        subs = this._types[eventType] = {};
      }
      var sub = "sub" + this._seq++;
      subs[sub] = listener;
      return sub;
    }

    // Returns false if no match, or string for sub name if matched

  }, {
    key: "off",
    value: function off(eventType, listener) {
      var subs = this._types[eventType];
      if (typeof listener === "function") {
        for (var key in subs) {
          if (subs.hasOwnProperty(key)) {
            if (subs[key] === listener) {
              delete subs[key];
              return key;
            }
          }
        }
        return false;
      } else if (typeof listener === "string") {
        if (subs && subs[listener]) {
          delete subs[listener];
          return listener;
        }
        return false;
      } else {
        throw new Error("Unexpected type for listener");
      }
    }
  }, {
    key: "trigger",
    value: function trigger(eventType, arg, thisObj) {
      var subs = this._types[eventType];
      for (var key in subs) {
        if (subs.hasOwnProperty(key)) {
          subs[key].call(thisObj, arg);
        }
      }
    }
  }]);

  return Events;
}();

exports.default = Events;

},{}],2:[function(require,module,exports){
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.FilterHandle = undefined;

var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _events = require("./events");

var _events2 = _interopRequireDefault(_events);

var _filterset = require("./filterset");

var _filterset2 = _interopRequireDefault(_filterset);

var _group = require("./group");

var _group2 = _interopRequireDefault(_group);

var _util = require("./util");

var util = _interopRequireWildcard(_util);

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function getFilterSet(group) {
  var fsVar = group.var("filterset");
  var result = fsVar.get();
  if (!result) {
    result = new _filterset2.default();
    fsVar.set(result);
  }
  return result;
}

var id = 1;
function nextId() {
  return id++;
}

/**
 * Use this class to contribute to, and listen for changes to, the filter set
 * for the given group of widgets. Filter input controls should create one
 * `FilterHandle` and only call {@link FilterHandle#set}. Output widgets that
 * wish to displayed filtered data should create one `FilterHandle` and use
 * the {@link FilterHandle#filteredKeys} property and listen for change
 * events.
 *
 * If two (or more) `FilterHandle` instances in the same webpage share the
 * same group name, they will contribute to a single "filter set". Each
 * `FilterHandle` starts out with a `null` value, which means they take
 * nothing away from the set of data that should be shown. To make a
 * `FilterHandle` actually remove data from the filter set, set its value to
 * an array of keys which should be displayed. Crosstalk will aggregate the
 * various key arrays by finding their intersection; only keys that are
 * present in all non-null filter handles are considered part of the filter
 * set.
 *
 * @param {string} [group] - The name of the Crosstalk group, or if none,
 *   null or undefined (or any other falsy value). This can be changed later
 *   via the {@link FilterHandle#setGroup} method.
 * @param {Object} [extraInfo] - An object whose properties will be copied to
 *   the event object whenever an event is emitted.
 */

var FilterHandle = exports.FilterHandle = function () {
  function FilterHandle(group, extraInfo) {
    _classCallCheck(this, FilterHandle);

    this._eventRelay = new _events2.default();
    this._emitter = new util.SubscriptionTracker(this._eventRelay);

    // Name of the group we're currently tracking, if any. Can change over time.
    this._group = null;
    // The filterSet that we're tracking, if any. Can change over time.
    this._filterSet = null;
    // The Var we're currently tracking, if any. Can change over time.
    this._filterVar = null;
    // The event handler subscription we currently have on var.on("change").
    this._varOnChangeSub = null;

    this._extraInfo = util.extend({ sender: this }, extraInfo);

    this._id = "filter" + nextId();

    this.setGroup(group);
  }

  /**
   * Changes the Crosstalk group membership of this FilterHandle. If `set()` was
   * previously called on this handle, switching groups will clear those keys
   * from the old group's filter set. These keys will not be applied to the new
   * group's filter set either. In other words, `setGroup()` effectively calls
   * `clear()` before switching groups.
   *
   * @param {string} group - The name of the Crosstalk group, or null (or
   *   undefined) to clear the group.
   */


  _createClass(FilterHandle, [{
    key: "setGroup",
    value: function setGroup(group) {
      var _this = this;

      // If group is unchanged, do nothing
      if (this._group === group) return;
      // Treat null, undefined, and other falsy values the same
      if (!this._group && !group) return;

      if (this._filterVar) {
        this._filterVar.off("change", this._varOnChangeSub);
        this.clear();
        this._varOnChangeSub = null;
        this._filterVar = null;
        this._filterSet = null;
      }

      this._group = group;

      if (group) {
        group = (0, _group2.default)(group);
        this._filterSet = getFilterSet(group);
        this._filterVar = (0, _group2.default)(group).var("filter");
        var sub = this._filterVar.on("change", function (e) {
          _this._eventRelay.trigger("change", e, _this);
        });
        this._varOnChangeSub = sub;
      }
    }

    /**
     * Combine the given `extraInfo` (if any) with the handle's default
     * `_extraInfo` (if any).
     * @private
     */

  }, {
    key: "_mergeExtraInfo",
    value: function _mergeExtraInfo(extraInfo) {
      return util.extend({}, this._extraInfo ? this._extraInfo : null, extraInfo ? extraInfo : null);
    }

    /**
     * Close the handle. This clears this handle's contribution to the filter set,
     * and unsubscribes all event listeners.
     */

  }, {
    key: "close",
    value: function close() {
      this._emitter.removeAllListeners();
      this.clear();
      this.setGroup(null);
    }

    /**
     * Clear this handle's contribution to the filter set.
     *
     * @param {Object} [extraInfo] - Extra properties to be included on the event
     *   object that's passed to listeners (in addition to any options that were
     *   passed into the `FilterHandle` constructor).
     * 
     * @fires FilterHandle#change
     */

  }, {
    key: "clear",
    value: function clear(extraInfo) {
      if (!this._filterSet) return;
      this._filterSet.clear(this._id);
      this._onChange(extraInfo);
    }

    /**
     * Set this handle's contribution to the filter set. This array should consist
     * of the keys of the rows that _should_ be displayed; any keys that are not
     * present in the array will be considered _filtered out_. Note that multiple
     * `FilterHandle` instances in the group may each contribute an array of keys,
     * and only those keys that appear in _all_ of the arrays make it through the
     * filter.
     *
     * @param {string[]} keys - Empty array, or array of keys. To clear the
     *   filter, don't pass an empty array; instead, use the
     *   {@link FilterHandle#clear} method.
     * @param {Object} [extraInfo] - Extra properties to be included on the event
     *   object that's passed to listeners (in addition to any options that were
     *   passed into the `FilterHandle` constructor).
     * 
     * @fires FilterHandle#change
     */

  }, {
    key: "set",
    value: function set(keys, extraInfo) {
      if (!this._filterSet) return;
      this._filterSet.update(this._id, keys);
      this._onChange(extraInfo);
    }

    /**
     * @return {string[]|null} - Either: 1) an array of keys that made it through
     *   all of the `FilterHandle` instances, or, 2) `null`, which means no filter
     *   is being applied (all data should be displayed).
     */

  }, {
    key: "on",


    /**
     * Subscribe to events on this `FilterHandle`.
     *
     * @param {string} eventType - Indicates the type of events to listen to.
     *   Currently, only `"change"` is supported.
     * @param {FilterHandle~listener} listener - The callback function that
     *   will be invoked when the event occurs.
     * @return {string} - A token to pass to {@link FilterHandle#off} to cancel
     *   this subscription.
     */
    value: function on(eventType, listener) {
      return this._emitter.on(eventType, listener);
    }

    /**
     * Cancel event subscriptions created by {@link FilterHandle#on}.
     *
     * @param {string} eventType - The type of event to unsubscribe.
     * @param {string|FilterHandle~listener} listener - Either the callback
     *   function previously passed into {@link FilterHandle#on}, or the
     *   string that was returned from {@link FilterHandle#on}.
     */

  }, {
    key: "off",
    value: function off(eventType, listener) {
      return this._emitter.off(eventType, listener);
    }
  }, {
    key: "_onChange",
    value: function _onChange(extraInfo) {
      if (!this._filterSet) return;
      this._filterVar.set(this._filterSet.value, this._mergeExtraInfo(extraInfo));
    }

    /**
     * @callback FilterHandle~listener
     * @param {Object} event - An object containing details of the event. For
     *   `"change"` events, this includes the properties `value` (the new
     *   value of the filter set, or `null` if no filter set is active),
     *   `oldValue` (the previous value of the filter set), and `sender` (the
     *   `FilterHandle` instance that made the change).
     */

  }, {
    key: "filteredKeys",
    get: function get() {
      return this._filterSet ? this._filterSet.value : null;
    }
  }]);

  return FilterHandle;
}();

/**
 * @event FilterHandle#change
 * @type {object}
 * @property {object} value - The new value of the filter set, or `null`
 *   if no filter set is active.
 * @property {object} oldValue - The previous value of the filter set.
 * @property {FilterHandle} sender - The `FilterHandle` instance that
 *   changed the value.
 */

},{"./events":1,"./filterset":3,"./group":4,"./util":11}],3:[function(require,module,exports){
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _util = require("./util");

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function naturalComparator(a, b) {
  if (a === b) {
    return 0;
  } else if (a < b) {
    return -1;
  } else if (a > b) {
    return 1;
  }
}

/**
 * @private
 */

var FilterSet = function () {
  function FilterSet() {
    _classCallCheck(this, FilterSet);

    this.reset();
  }

  _createClass(FilterSet, [{
    key: "reset",
    value: function reset() {
      // Key: handle ID, Value: array of selected keys, or null
      this._handles = {};
      // Key: key string, Value: count of handles that include it
      this._keys = {};
      this._value = null;
      this._activeHandles = 0;
    }
  }, {
    key: "update",
    value: function update(handleId, keys) {
      if (keys !== null) {
        keys = keys.slice(0); // clone before sorting
        keys.sort(naturalComparator);
      }

      var _diffSortedLists = (0, _util.diffSortedLists)(this._handles[handleId], keys),
          added = _diffSortedLists.added,
          removed = _diffSortedLists.removed;

      this._handles[handleId] = keys;

      for (var i = 0; i < added.length; i++) {
        this._keys[added[i]] = (this._keys[added[i]] || 0) + 1;
      }
      for (var _i = 0; _i < removed.length; _i++) {
        this._keys[removed[_i]]--;
      }

      this._updateValue(keys);
    }

    /**
     * @param {string[]} keys Sorted array of strings that indicate
     * a superset of possible keys.
     * @private
     */

  }, {
    key: "_updateValue",
    value: function _updateValue() {
      var keys = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this._allKeys;

      var handleCount = Object.keys(this._handles).length;
      if (handleCount === 0) {
        this._value = null;
      } else {
        this._value = [];
        for (var i = 0; i < keys.length; i++) {
          var count = this._keys[keys[i]];
          if (count === handleCount) {
            this._value.push(keys[i]);
          }
        }
      }
    }
  }, {
    key: "clear",
    value: function clear(handleId) {
      if (typeof this._handles[handleId] === "undefined") {
        return;
      }

      var keys = this._handles[handleId];
      if (!keys) {
        keys = [];
      }

      for (var i = 0; i < keys.length; i++) {
        this._keys[keys[i]]--;
      }
      delete this._handles[handleId];

      this._updateValue();
    }
  }, {
    key: "value",
    get: function get() {
      return this._value;
    }
  }, {
    key: "_allKeys",
    get: function get() {
      var allKeys = Object.keys(this._keys);
      allKeys.sort(naturalComparator);
      return allKeys;
    }
  }]);

  return FilterSet;
}();

exports.default = FilterSet;

},{"./util":11}],4:[function(require,module,exports){
(function (global){
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

exports.default = group;

var _var2 = require("./var");

var _var3 = _interopRequireDefault(_var2);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

// Use a global so that multiple copies of crosstalk.js can be loaded and still
// have groups behave as singletons across all copies.
global.__crosstalk_groups = global.__crosstalk_groups || {};
var groups = global.__crosstalk_groups;

function group(groupName) {
  if (groupName && typeof groupName === "string") {
    if (!groups.hasOwnProperty(groupName)) {
      groups[groupName] = new Group(groupName);
    }
    return groups[groupName];
  } else if ((typeof groupName === "undefined" ? "undefined" : _typeof(groupName)) === "object" && groupName._vars && groupName.var) {
    // Appears to already be a group object
    return groupName;
  } else if (Array.isArray(groupName) && groupName.length == 1 && typeof groupName[0] === "string") {
    return group(groupName[0]);
  } else {
    throw new Error("Invalid groupName argument");
  }
}

var Group = function () {
  function Group(name) {
    _classCallCheck(this, Group);

    this.name = name;
    this._vars = {};
  }

  _createClass(Group, [{
    key: "var",
    value: function _var(name) {
      if (!name || typeof name !== "string") {
        throw new Error("Invalid var name");
      }

      if (!this._vars.hasOwnProperty(name)) this._vars[name] = new _var3.default(this, name);
      return this._vars[name];
    }
  }, {
    key: "has",
    value: function has(name) {
      if (!name || typeof name !== "string") {
        throw new Error("Invalid var name");
      }

      return this._vars.hasOwnProperty(name);
    }
  }]);

  return Group;
}();

}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})

},{"./var":12}],5:[function(require,module,exports){
(function (global){
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _group = require("./group");

var _group2 = _interopRequireDefault(_group);

var _selection = require("./selection");

var _filter = require("./filter");

var _input = require("./input");

require("./input_selectize");

require("./input_checkboxgroup");

require("./input_slider");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var defaultGroup = (0, _group2.default)("default");

function var_(name) {
  return defaultGroup.var(name);
}

function has(name) {
  return defaultGroup.has(name);
}

if (global.Shiny) {
  global.Shiny.addCustomMessageHandler("update-client-value", function (message) {
    if (typeof message.group === "string") {
      (0, _group2.default)(message.group).var(message.name).set(message.value);
    } else {
      var_(message.name).set(message.value);
    }
  });
}

var crosstalk = {
  group: _group2.default,
  var: var_,
  has: has,
  SelectionHandle: _selection.SelectionHandle,
  FilterHandle: _filter.FilterHandle,
  bind: _input.bind
};

/**
 * @namespace crosstalk
 */
exports.default = crosstalk;

global.crosstalk = crosstalk;

}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})

},{"./filter":2,"./group":4,"./input":6,"./input_checkboxgroup":7,"./input_selectize":8,"./input_slider":9,"./selection":10}],6:[function(require,module,exports){
(function (global){
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.register = register;
exports.bind = bind;
var $ = global.jQuery;

var bindings = {};

function register(reg) {
  bindings[reg.className] = reg;
  if (global.document && global.document.readyState !== "complete") {
    $(function () {
      bind();
    });
  } else if (global.document) {
    setTimeout(bind, 100);
  }
}

function bind() {
  Object.keys(bindings).forEach(function (className) {
    var binding = bindings[className];
    $("." + binding.className).not(".crosstalk-input-bound").each(function (i, el) {
      bindInstance(binding, el);
    });
  });
}

// Escape jQuery identifier
function $escape(val) {
  return val.replace(/([!"#$%&'()*+,./:;<=>?@[\\\]^`{|}~])/g, "\\$1");
}

function bindEl(el) {
  var $el = $(el);
  Object.keys(bindings).forEach(function (className) {
    if ($el.hasClass(className) && !$el.hasClass("crosstalk-input-bound")) {
      var binding = bindings[className];
      bindInstance(binding, el);
    }
  });
}

function bindInstance(binding, el) {
  var jsonEl = $(el).find("script[type='application/json'][data-for='" + $escape(el.id) + "']");
  var data = JSON.parse(jsonEl[0].innerText);

  var instance = binding.factory(el, data);
  $(el).data("crosstalk-instance", instance);
  $(el).addClass("crosstalk-input-bound");
}

if (global.Shiny) {
  var inputBinding = new global.Shiny.InputBinding();
  var _$ = global.jQuery;
  _$.extend(inputBinding, {
    find: function find(scope) {
      return _$(scope).find(".crosstalk-input");
    },
    initialize: function initialize(el) {
      if (!_$(el).hasClass("crosstalk-input-bound")) {
        bindEl(el);
      }
    },
    getId: function getId(el) {
      return el.id;
    },
    getValue: function getValue(el) {},
    setValue: function setValue(el, value) {},
    receiveMessage: function receiveMessage(el, data) {},
    subscribe: function subscribe(el, callback) {
      _$(el).data("crosstalk-instance").resume();
    },
    unsubscribe: function unsubscribe(el) {
      _$(el).data("crosstalk-instance").suspend();
    }
  });
  global.Shiny.inputBindings.register(inputBinding, "crosstalk.inputBinding");
}

}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})

},{}],7:[function(require,module,exports){
(function (global){
"use strict";

var _input = require("./input");

var input = _interopRequireWildcard(_input);

var _filter = require("./filter");

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

var $ = global.jQuery;

input.register({
  className: "crosstalk-input-checkboxgroup",

  factory: function factory(el, data) {
    /*
     * map: {"groupA": ["keyA", "keyB", ...], ...}
     * group: "ct-groupname"
     */
    var ctHandle = new _filter.FilterHandle(data.group);

    var lastKnownKeys = void 0;
    var $el = $(el);
    $el.on("change", "input[type='checkbox']", function () {
      var checked = $el.find("input[type='checkbox']:checked");
      if (checked.length === 0) {
        lastKnownKeys = null;
        ctHandle.clear();
      } else {
        var keys = {};
        checked.each(function () {
          data.map[this.value].forEach(function (key) {
            keys[key] = true;
          });
        });
        var keyArray = Object.keys(keys);
        keyArray.sort();
        lastKnownKeys = keyArray;
        ctHandle.set(keyArray);
      }
    });

    return {
      suspend: function suspend() {
        ctHandle.clear();
      },
      resume: function resume() {
        if (lastKnownKeys) ctHandle.set(lastKnownKeys);
      }
    };
  }
});

}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})

},{"./filter":2,"./input":6}],8:[function(require,module,exports){
(function (global){
"use strict";

var _input = require("./input");

var input = _interopRequireWildcard(_input);

var _util = require("./util");

var util = _interopRequireWildcard(_util);

var _filter = require("./filter");

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

var $ = global.jQuery;

input.register({
  className: "crosstalk-input-select",

  factory: function factory(el, data) {
    /*
     * items: {value: [...], label: [...]}
     * map: {"groupA": ["keyA", "keyB", ...], ...}
     * group: "ct-groupname"
     */

    var first = [{ value: "", label: "(All)" }];
    var items = util.dataframeToD3(data.items);
    var opts = {
      options: first.concat(items),
      valueField: "value",
      labelField: "label",
      searchField: "label"
    };

    var select = $(el).find("select")[0];

    var selectize = $(select).selectize(opts)[0].selectize;

    var ctHandle = new _filter.FilterHandle(data.group);

    var lastKnownKeys = void 0;
    selectize.on("change", function () {
      if (selectize.items.length === 0) {
        lastKnownKeys = null;
        ctHandle.clear();
      } else {
        var keys = {};
        selectize.items.forEach(function (group) {
          data.map[group].forEach(function (key) {
            keys[key] = true;
          });
        });
        var keyArray = Object.keys(keys);
        keyArray.sort();
        lastKnownKeys = keyArray;
        ctHandle.set(keyArray);
      }
    });

    return {
      suspend: function suspend() {
        ctHandle.clear();
      },
      resume: function resume() {
        if (lastKnownKeys) ctHandle.set(lastKnownKeys);
      }
    };
  }
});

}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})

},{"./filter":2,"./input":6,"./util":11}],9:[function(require,module,exports){
(function (global){
"use strict";

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var _input = require("./input");

var input = _interopRequireWildcard(_input);

var _filter = require("./filter");

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

var $ = global.jQuery;
var strftime = global.strftime;

input.register({
  className: "crosstalk-input-slider",

  factory: function factory(el, data) {
    /*
     * map: {"groupA": ["keyA", "keyB", ...], ...}
     * group: "ct-groupname"
     */
    var ctHandle = new _filter.FilterHandle(data.group);

    var opts = {};
    var $el = $(el).find("input");
    var dataType = $el.data("data-type");
    var timeFormat = $el.data("time-format");
    var round = $el.data("round");
    var timeFormatter = void 0;

    // Set up formatting functions
    if (dataType === "date") {
      timeFormatter = strftime.utc();
      opts.prettify = function (num) {
        return timeFormatter(timeFormat, new Date(num));
      };
    } else if (dataType === "datetime") {
      var timezone = $el.data("timezone");
      if (timezone) timeFormatter = strftime.timezone(timezone);else timeFormatter = strftime;

      opts.prettify = function (num) {
        return timeFormatter(timeFormat, new Date(num));
      };
    } else if (dataType === "number") {
      if (typeof round !== "undefined") opts.prettify = function (num) {
        var factor = Math.pow(10, round);
        return Math.round(num * factor) / factor;
      };
    }

    $el.ionRangeSlider(opts);

    function getValue() {
      var result = $el.data("ionRangeSlider").result;

      // Function for converting numeric value from slider to appropriate type.
      var convert = void 0;
      var dataType = $el.data("data-type");
      if (dataType === "date") {
        convert = function convert(val) {
          return formatDateUTC(new Date(+val));
        };
      } else if (dataType === "datetime") {
        convert = function convert(val) {
          // Convert ms to s
          return +val / 1000;
        };
      } else {
        convert = function convert(val) {
          return +val;
        };
      }

      if ($el.data("ionRangeSlider").options.type === "double") {
        return [convert(result.from), convert(result.to)];
      } else {
        return convert(result.from);
      }
    }

    var lastKnownKeys = null;

    $el.on("change.crosstalkSliderInput", function (event) {
      if (!$el.data("updating") && !$el.data("animating")) {
        var _getValue = getValue(),
            _getValue2 = _slicedToArray(_getValue, 2),
            from = _getValue2[0],
            to = _getValue2[1];

        var keys = [];
        for (var i = 0; i < data.values.length; i++) {
          var val = data.values[i];
          if (val >= from && val <= to) {
            keys.push(data.keys[i]);
          }
        }
        keys.sort();
        ctHandle.set(keys);
        lastKnownKeys = keys;
      }
    });

    // let $el = $(el);
    // $el.on("change", "input[type="checkbox"]", function() {
    //   let checked = $el.find("input[type="checkbox"]:checked");
    //   if (checked.length === 0) {
    //     ctHandle.clear();
    //   } else {
    //     let keys = {};
    //     checked.each(function() {
    //       data.map[this.value].forEach(function(key) {
    //         keys[key] = true;
    //       });
    //     });
    //     let keyArray = Object.keys(keys);
    //     keyArray.sort();
    //     ctHandle.set(keyArray);
    //   }
    // });

    return {
      suspend: function suspend() {
        ctHandle.clear();
      },
      resume: function resume() {
        if (lastKnownKeys) ctHandle.set(lastKnownKeys);
      }
    };
  }
});

// Convert a number to a string with leading zeros
function padZeros(n, digits) {
  var str = n.toString();
  while (str.length < digits) {
    str = "0" + str;
  }return str;
}

// Given a Date object, return a string in yyyy-mm-dd format, using the
// UTC date. This may be a day off from the date in the local time zone.
function formatDateUTC(date) {
  if (date instanceof Date) {
    return date.getUTCFullYear() + "-" + padZeros(date.getUTCMonth() + 1, 2) + "-" + padZeros(date.getUTCDate(), 2);
  } else {
    return null;
  }
}

}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})

},{"./filter":2,"./input":6}],10:[function(require,module,exports){
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.SelectionHandle = undefined;

var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _events = require("./events");

var _events2 = _interopRequireDefault(_events);

var _group = require("./group");

var _group2 = _interopRequireDefault(_group);

var _util = require("./util");

var util = _interopRequireWildcard(_util);

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

/**
 * Use this class to read and write (and listen for changes to) the selection
 * for a Crosstalk group. This is intended to be used for linked brushing.
 *
 * If two (or more) `SelectionHandle` instances in the same webpage share the
 * same group name, they will share the same state. Setting the selection using
 * one `SelectionHandle` instance will result in the `value` property instantly
 * changing across the others, and `"change"` event listeners on all instances
 * (including the one that initiated the sending) will fire.
 *
 * @param {string} [group] - The name of the Crosstalk group, or if none,
 *   null or undefined (or any other falsy value). This can be changed later
 *   via the [SelectionHandle#setGroup](#setGroup) method.
 * @param {Object} [extraInfo] - An object whose properties will be copied to
 *   the event object whenever an event is emitted.
 */
var SelectionHandle = exports.SelectionHandle = function () {
  function SelectionHandle() {
    var group = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
    var extraInfo = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;

    _classCallCheck(this, SelectionHandle);

    this._eventRelay = new _events2.default();
    this._emitter = new util.SubscriptionTracker(this._eventRelay);

    // Name of the group we're currently tracking, if any. Can change over time.
    this._group = null;
    // The Var we're currently tracking, if any. Can change over time.
    this._var = null;
    // The event handler subscription we currently have on var.on("change").
    this._varOnChangeSub = null;

    this._extraInfo = util.extend({ sender: this }, extraInfo);

    this.setGroup(group);
  }

  /**
   * Changes the Crosstalk group membership of this SelectionHandle. The group
   * being switched away from (if any) will not have its selection value
   * modified as a result of calling `setGroup`, even if this handle was the
   * most recent handle to set the selection of the group.
   *
   * The group being switched to (if any) will also not have its selection value
   * modified as a result of calling `setGroup`. If you want to set the
   * selection value of the new group, call `set` explicitly.
   *
   * @param {string} group - The name of the Crosstalk group, or null (or
   *   undefined) to clear the group.
   */


  _createClass(SelectionHandle, [{
    key: "setGroup",
    value: function setGroup(group) {
      var _this = this;

      // If group is unchanged, do nothing
      if (this._group === group) return;
      // Treat null, undefined, and other falsy values the same
      if (!this._group && !group) return;

      if (this._var) {
        this._var.off("change", this._varOnChangeSub);
        this._var = null;
        this._varOnChangeSub = null;
      }

      this._group = group;

      if (group) {
        this._var = (0, _group2.default)(group).var("selection");
        var sub = this._var.on("change", function (e) {
          _this._eventRelay.trigger("change", e, _this);
        });
        this._varOnChangeSub = sub;
      }
    }

    /**
     * Retrieves the current selection for the group represented by this
     * `SelectionHandle`.
     *
     * - If no selection is active, then this value will be falsy.
     * - If a selection is active, but no data points are selected, then this
     *   value will be an empty array.
     * - If a selection is active, and data points are selected, then the keys
     *   of the selected data points will be present in the array.
     */

  }, {
    key: "_mergeExtraInfo",


    /**
     * Combines the given `extraInfo` (if any) with the handle's default
     * `_extraInfo` (if any).
     * @private
     */
    value: function _mergeExtraInfo(extraInfo) {
      // Important incidental effect: shallow clone is returned
      return util.extend({}, this._extraInfo ? this._extraInfo : null, extraInfo ? extraInfo : null);
    }

    /**
     * Overwrites the current selection for the group, and raises the `"change"`
     * event among all of the group's '`SelectionHandle` instances (including
     * this one).
     *
     * @fires SelectionHandle#change
     * @param {string[]} selectedKeys - Falsy, empty array, or array of keys (see
     *   {@link SelectionHandle#value}).
     * @param {Object} [extraInfo] - Extra properties to be included on the event
     *   object that's passed to listeners (in addition to any options that were
     *   passed into the `SelectionHandle` constructor).
     */

  }, {
    key: "set",
    value: function set(selectedKeys, extraInfo) {
      if (this._var) this._var.set(selectedKeys, this._mergeExtraInfo(extraInfo));
    }

    /**
     * Overwrites the current selection for the group, and raises the `"change"`
     * event among all of the group's '`SelectionHandle` instances (including
     * this one).
     *
     * @fires SelectionHandle#change
     * @param {Object} [extraInfo] - Extra properties to be included on the event
     *   object that's passed to listeners (in addition to any that were passed
     *   into the `SelectionHandle` constructor).
     */

  }, {
    key: "clear",
    value: function clear(extraInfo) {
      if (this._var) this.set(void 0, this._mergeExtraInfo(extraInfo));
    }

    /**
     * Subscribes to events on this `SelectionHandle`.
     *
     * @param {string} eventType - Indicates the type of events to listen to.
     *   Currently, only `"change"` is supported.
     * @param {SelectionHandle~listener} listener - The callback function that
     *   will be invoked when the event occurs.
     * @return {string} - A token to pass to {@link SelectionHandle#off} to cancel
     *   this subscription.
     */

  }, {
    key: "on",
    value: function on(eventType, listener) {
      return this._emitter.on(eventType, listener);
    }

    /**
     * Cancels event subscriptions created by {@link SelectionHandle#on}.
     *
     * @param {string} eventType - The type of event to unsubscribe.
     * @param {string|SelectionHandle~listener} listener - Either the callback
     *   function previously passed into {@link SelectionHandle#on}, or the
     *   string that was returned from {@link SelectionHandle#on}.
     */

  }, {
    key: "off",
    value: function off(eventType, listener) {
      return this._emitter.off(eventType, listener);
    }

    /**
     * Shuts down the `SelectionHandle` object.
     *
     * Removes all event listeners that were added through this handle.
     */

  }, {
    key: "close",
    value: function close() {
      this._emitter.removeAllListeners();
      this.setGroup(null);
    }
  }, {
    key: "value",
    get: function get() {
      return this._var ? this._var.get() : null;
    }
  }]);

  return SelectionHandle;
}();

/**
 * @callback SelectionHandle~listener
 * @param {Object} event - An object containing details of the event. For
 *   `"change"` events, this includes the properties `value` (the new
 *   value of the selection, or `undefined` if no selection is active),
 *   `oldValue` (the previous value of the selection), and `sender` (the
 *   `SelectionHandle` instance that made the change).
 */

/**
 * @event SelectionHandle#change
 * @type {object}
 * @property {object} value - The new value of the selection, or `undefined`
 *   if no selection is active.
 * @property {object} oldValue - The previous value of the selection.
 * @property {SelectionHandle} sender - The `SelectionHandle` instance that
 *   changed the value.
 */

},{"./events":1,"./group":4,"./util":11}],11:[function(require,module,exports){
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

exports.extend = extend;
exports.checkSorted = checkSorted;
exports.diffSortedLists = diffSortedLists;
exports.dataframeToD3 = dataframeToD3;

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function extend(target) {
  for (var _len = arguments.length, sources = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
    sources[_key - 1] = arguments[_key];
  }

  for (var i = 0; i < sources.length; i++) {
    var src = sources[i];
    if (typeof src === "undefined" || src === null) continue;

    for (var key in src) {
      if (src.hasOwnProperty(key)) {
        target[key] = src[key];
      }
    }
  }
  return target;
}

function checkSorted(list) {
  for (var i = 1; i < list.length; i++) {
    if (list[i] <= list[i - 1]) {
      throw new Error("List is not sorted or contains duplicate");
    }
  }
}

function diffSortedLists(a, b) {
  var i_a = 0;
  var i_b = 0;

  if (!a) a = [];
  if (!b) b = [];

  var a_only = [];
  var b_only = [];

  checkSorted(a);
  checkSorted(b);

  while (i_a < a.length && i_b < b.length) {
    if (a[i_a] === b[i_b]) {
      i_a++;
      i_b++;
    } else if (a[i_a] < b[i_b]) {
      a_only.push(a[i_a++]);
    } else {
      b_only.push(b[i_b++]);
    }
  }

  if (i_a < a.length) a_only = a_only.concat(a.slice(i_a));
  if (i_b < b.length) b_only = b_only.concat(b.slice(i_b));
  return {
    removed: a_only,
    added: b_only
  };
}

// Convert from wide: { colA: [1,2,3], colB: [4,5,6], ... }
// to long: [ {colA: 1, colB: 4}, {colA: 2, colB: 5}, ... ]
function dataframeToD3(df) {
  var names = [];
  var length = void 0;
  for (var name in df) {
    if (df.hasOwnProperty(name)) names.push(name);
    if (_typeof(df[name]) !== "object" || typeof df[name].length === "undefined") {
      throw new Error("All fields must be arrays");
    } else if (typeof length !== "undefined" && length !== df[name].length) {
      throw new Error("All fields must be arrays of the same length");
    }
    length = df[name].length;
  }
  var results = [];
  var item = void 0;
  for (var row = 0; row < length; row++) {
    item = {};
    for (var col = 0; col < names.length; col++) {
      item[names[col]] = df[names[col]][row];
    }
    results.push(item);
  }
  return results;
}

/**
 * Keeps track of all event listener additions/removals and lets all active
 * listeners be removed with a single operation.
 *
 * @private
 */

var SubscriptionTracker = exports.SubscriptionTracker = function () {
  function SubscriptionTracker(emitter) {
    _classCallCheck(this, SubscriptionTracker);

    this._emitter = emitter;
    this._subs = {};
  }

  _createClass(SubscriptionTracker, [{
    key: "on",
    value: function on(eventType, listener) {
      var sub = this._emitter.on(eventType, listener);
      this._subs[sub] = eventType;
      return sub;
    }
  }, {
    key: "off",
    value: function off(eventType, listener) {
      var sub = this._emitter.off(eventType, listener);
      if (sub) {
        delete this._subs[sub];
      }
      return sub;
    }
  }, {
    key: "removeAllListeners",
    value: function removeAllListeners() {
      var _this = this;

      var current_subs = this._subs;
      this._subs = {};
      Object.keys(current_subs).forEach(function (sub) {
        _this._emitter.off(current_subs[sub], sub);
      });
    }
  }]);

  return SubscriptionTracker;
}();

},{}],12:[function(require,module,exports){
(function (global){
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _events = require("./events");

var _events2 = _interopRequireDefault(_events);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Var = function () {
  function Var(group, name, /*optional*/value) {
    _classCallCheck(this, Var);

    this._group = group;
    this._name = name;
    this._value = value;
    this._events = new _events2.default();
  }

  _createClass(Var, [{
    key: "get",
    value: function get() {
      return this._value;
    }
  }, {
    key: "set",
    value: function set(value, /*optional*/event) {
      if (this._value === value) {
        // Do nothing; the value hasn't changed
        return;
      }
      var oldValue = this._value;
      this._value = value;
      // Alert JavaScript listeners that the value has changed
      var evt = {};
      if (event && (typeof event === "undefined" ? "undefined" : _typeof(event)) === "object") {
        for (var k in event) {
          if (event.hasOwnProperty(k)) evt[k] = event[k];
        }
      }
      evt.oldValue = oldValue;
      evt.value = value;
      this._events.trigger("change", evt, this);

      // TODO: Make this extensible, to let arbitrary back-ends know that
      // something has changed
      if (global.Shiny && global.Shiny.onInputChange) {
        global.Shiny.onInputChange(".clientValue-" + (this._group.name !== null ? this._group.name + "-" : "") + this._name, typeof value === "undefined" ? null : value);
      }
    }
  }, {
    key: "on",
    value: function on(eventType, listener) {
      return this._events.on(eventType, listener);
    }
  }, {
    key: "off",
    value: function off(eventType, listener) {
      return this._events.off(eventType, listener);
    }
  }]);

  return Var;
}();

exports.default = Var;

}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})

},{"./events":1}]},{},[5])
//# sourceMappingURL=crosstalk.js.map

Contact - Imprint