-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
6418 lines (5668 loc) · 245 KB
/
index.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 (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined'
? (module.exports = factory())
: typeof define === 'function' && define.amd
? define(factory)
: ((global = typeof globalThis !== 'undefined' ? globalThis : global || self),
(global.solarSystemAnimation = factory()));
})(this, function () {
'use strict';
if (typeof Object.assign != 'function') {
Object.defineProperty(Object, 'assign', {
value: function assign(target, varArgs) {
if (target == null) {
// TypeError if undefined or null
throw new TypeError('Cannot convert undefined or null to object');
}
var to = Object(target);
for (var index = 1; index < arguments.length; index++) {
var nextSource = arguments[index];
if (nextSource != null) {
// Skip over if undefined or null
for (var nextKey in nextSource) {
// Avoid bugs when hasOwnProperty is shadowed
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
}
}
}
return to;
},
writable: true,
configurable: true,
});
}
if (!Array.prototype.includes) {
Object.defineProperty(Array.prototype, 'includes', {
value: function value(valueToFind, fromIndex) {
if (this == null) {
throw new TypeError('"this" is null or not defined');
} // 1. Let O be ? ToObject(this value).
var o = Object(this); // 2. Let len be ? ToLength(? Get(O, "length")).
var len = o.length >>> 0; // 3. If len is 0, return false.
if (len === 0) {
return false;
} // 4. Let n be ? ToInteger(fromIndex).
// (If fromIndex is undefined, this step produces the value 0.)
var n = fromIndex | 0; // 5. If n = 0, then
// a. Let k be n.
// 6. Else n < 0,
// a. Let k be len + n.
// b. If k < 0, let k be 0.
var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
function sameValueZero(x, y) {
return (
x === y ||
(typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y))
);
} // 7. Repeat, while k < len
while (k < len) {
// a. Let elementK be the result of ? Get(O, ! ToString(k)).
// b. If SameValueZero(valueToFind, elementK) is true, return true.
if (sameValueZero(o[k], valueToFind)) {
return true;
} // c. Increase k by 1.
k++;
} // 8. Return false
return false;
},
});
}
if (!Array.prototype.find) {
Object.defineProperty(Array.prototype, 'find', {
value: function value(predicate) {
// 1. Let O be ? ToObject(this value).
if (this == null) {
throw new TypeError('"this" is null or not defined');
}
var o = Object(this); // 2. Let len be ? ToLength(? Get(O, 'length')).
var len = o.length >>> 0; // 3. If IsCallable(predicate) is false, throw a TypeError exception.
if (typeof predicate !== 'function') {
throw new TypeError('predicate must be a function');
} // 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
var thisArg = arguments[1]; // 5. Let k be 0.
var k = 0; // 6. Repeat, while k < len
while (k < len) {
// a. Let Pk be ! ToString(k).
// b. Let kValue be ? Get(O, Pk).
// c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
// d. If testResult is true, return kValue.
var kValue = o[k];
if (predicate.call(thisArg, kValue, k, o)) {
return kValue;
} // e. Increase k by 1.
k++;
} // 7. Return undefined.
return undefined;
},
});
}
if (!Array.prototype.findIndex) {
Object.defineProperty(Array.prototype, 'findIndex', {
value: function value(predicate) {
// 1. Let O be ? ToObject(this value).
if (this == null) {
throw new TypeError('"this" is null or not defined');
}
var o = Object(this); // 2. Let len be ? ToLength(? Get(O, "length")).
var len = o.length >>> 0; // 3. If IsCallable(predicate) is false, throw a TypeError exception.
if (typeof predicate !== 'function') {
throw new TypeError('predicate must be a function');
} // 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
var thisArg = arguments[1]; // 5. Let k be 0.
var k = 0; // 6. Repeat, while k < len
while (k < len) {
// a. Let Pk be ! ToString(k).
// b. Let kValue be ? Get(O, Pk).
// c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
// d. If testResult is true, return k.
var kValue = o[k];
if (predicate.call(thisArg, kValue, k, o)) {
return k;
} // e. Increase k by 1.
k++;
} // 7. Return -1.
return -1;
},
});
}
if (!Object.values) {
Object.values = function (obj) {
var ownProps = Object.keys(obj),
i = ownProps.length,
resArray = new Array(i); // preallocate the Array
while (i--) {
resArray[i] = obj[ownProps[i]];
}
return resArray;
};
}
if (!Object.entries) {
Object.entries = function (obj) {
var ownProps = Object.keys(obj),
i = ownProps.length,
resArray = new Array(i); // preallocate the Array
while (i--) {
resArray[i] = [ownProps[i], obj[ownProps[i]]];
}
return resArray;
};
}
function addElement(name, parent) {
var tagName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'div';
var element = parent
.append(tagName)
.classed('fdg-'.concat(tagName), true)
.classed('fdg-'.concat(name), true)
.classed('fdg-'.concat(tagName, '--').concat(name), true);
return element;
}
// Returns a tween for a transition’s "d" attribute, transitioning any selected
// arcs from their current angle to the specified new angle.
function arcTween(newAngle, arc) {
// The function passed to attrTween is invoked for each selected element when
// the transition starts, and for each element returns the interpolator to use
// over the course of transition. This function is thus responsible for
// determining the starting angle of the transition (which is pulled from the
// element’s bound datum, d.endAngle), and the ending angle (simply the
// newAngle argument to the enclosing function).
return function (d) {
// To interpolate between the two angles, we use the default d3.interpolate.
// (Internally, this maps to d3.interpolateNumber, since both of the
// arguments to d3.interpolate are numbers.) The returned function takes a
// single argument t and returns a number between the starting angle and the
// ending angle. When t = 0, it returns d.endAngle; when t = 1, it returns
// newAngle; and for 0 < t < 1 it returns an angle in-between.
var interpolate = d3.interpolate(d.endAngle, newAngle); // The return value of the attrTween is also a function: the function that
// we want to run for each tick of the transition. Because we used
// attrTween("d"), the return value of this last function will be set to the
// "d" attribute at every tick. (It’s also possible to use transition.tween
// to run arbitrary code for every tick, say if you want to set multiple
// attributes from a single function.) The argument t ranges from 0, at the
// start of the transition, to 1, at the end.
return function (t) {
// Calculate the current arc angle based on the transition time, t. Since
// the t for the transition and the t for the interpolate both range from
// 0 to 1, we can pass t directly to the interpolator.
//
// Note that the interpolated angle is written into the element’s bound
// data object! This is important: it means that if the transition were
// interrupted, the data bound to the element would still be consistent
// with its appearance. Whenever we start a new arc transition, the
// correct starting angle can be inferred from the data.
d.endAngle = interpolate(t); // Lastly, compute the arc path given the updated data! In effect, this
// transition uses data-space interpolation: the data is interpolated
// (that is, the end angle) rather than the path string itself.
// Interpolating the angles in polar coordinates, rather than the raw path
// string, produces valid intermediate arcs during the transition.
return arc(d);
};
};
}
function csv(array) {
var and = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
var csv = array.join(', ');
if (and) csv = csv.replace(/, ([^,]*)$/, ' and $1');
return csv;
}
function _typeof(obj) {
'@babel/helpers - typeof';
if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
_typeof = function (obj) {
return typeof obj;
};
} else {
_typeof = function (obj) {
return obj &&
typeof Symbol === 'function' &&
obj.constructor === Symbol &&
obj !== Symbol.prototype
? 'symbol'
: typeof obj;
};
}
return _typeof(obj);
}
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;
}
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly)
symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
if (i % 2) {
ownKeys(Object(source), true).forEach(function (key) {
_defineProperty(target, key, source[key]);
});
} else if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(
target,
key,
Object.getOwnPropertyDescriptor(source, key)
);
});
}
}
return target;
}
function _toConsumableArray(arr) {
return (
_arrayWithoutHoles(arr) ||
_iterableToArray(arr) ||
_unsupportedIterableToArray(arr) ||
_nonIterableSpread()
);
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _iterableToArray(iter) {
if (typeof Symbol !== 'undefined' && Symbol.iterator in Object(iter))
return Array.from(iter);
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === 'string') return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === 'Object' && o.constructor) n = o.constructor.name;
if (n === 'Map' || n === 'Set') return Array.from(o);
if (n === 'Arguments' || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread() {
throw new TypeError(
'Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.'
);
}
function _createForOfIteratorHelper(o, allowArrayLike) {
var it;
if (typeof Symbol === 'undefined' || o[Symbol.iterator] == null) {
if (
Array.isArray(o) ||
(it = _unsupportedIterableToArray(o)) ||
(allowArrayLike && o && typeof o.length === 'number')
) {
if (it) o = it;
var i = 0;
var F = function () {};
return {
s: F,
n: function () {
if (i >= o.length)
return {
done: true,
};
return {
done: false,
value: o[i++],
};
},
e: function (e) {
throw e;
},
f: F,
};
}
throw new TypeError(
'Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.'
);
}
var normalCompletion = true,
didErr = false,
err;
return {
s: function () {
it = o[Symbol.iterator]();
},
n: function () {
var step = it.next();
normalCompletion = step.done;
return step;
},
e: function (e) {
didErr = true;
err = e;
},
f: function () {
try {
if (!normalCompletion && it.return != null) it.return();
} finally {
if (didErr) throw err;
}
},
};
}
/**
* Performs a deep merge of objects and returns new object. Does not modify
* objects (immutable) and merges arrays via concatenation.
*
* @param {...object} objects - Objects to merge
* @returns {object} New object with merged key/values
*/
function mergeDeep() {
var isObject = function isObject(obj) {
return obj && _typeof(obj) === 'object';
};
for (
var _len = arguments.length, objects = new Array(_len), _key = 0;
_key < _len;
_key++
) {
objects[_key] = arguments[_key];
}
return objects.reduce(function (prev, obj) {
Object.keys(obj).forEach(function (key) {
var pVal = prev[key];
var oVal = obj[key];
if (Array.isArray(pVal) && Array.isArray(oVal)) {
prev[key] = oVal; //pVal.concat(...oVal);
} else if (isObject(pVal) && isObject(oVal)) {
prev[key] = mergeDeep(pVal, oVal);
} else {
prev[key] = oVal;
}
});
return prev;
}, {});
}
function wrap(text, width) {
text.each(function () {
var text = d3.select(this),
words = text.text().split(/\s+/).reverse(),
word,
line = [],
lineNumber = 0,
fontStyle = text.style('font-size'),
fontSize = parseFloat(fontStyle),
fontUnit = fontStyle.replace(fontSize, ''),
x = text.attr('x'),
y = text.attr('y'),
dy = parseFloat(text.attr('dy')),
tspan = text
.text(null)
.append('tspan')
.attr('x', x)
.attr('y', y)
.attr('dy', dy + 'rem');
while ((word = words.pop())) {
line.push(word);
tspan.text(line.join(' '));
if (tspan.node().getComputedTextLength() > width) {
line.pop();
tspan.text(line.join(' '));
line = [word];
tspan = text
.append('tspan')
.attr('x', x)
.attr('y', y)
.attr('dy', ++lineNumber * fontSize + dy + fontUnit)
.text(word);
}
}
});
}
var util = {
addElement: addElement,
arcTween: arcTween,
csv: csv,
mergeDeep: mergeDeep,
wrap: wrap,
};
function dataMapping() {
return {
id_var: 'id',
event_var: 'event',
event_order_var: 'event_order',
// zero-indexed orbit
event_position_var: 'event_position',
// angle of event focus on orbit
start_timepoint_var: 'stdy',
end_timepoint_var: 'endy',
duration_var: 'duration',
};
}
function color() {
return {
colorBy: {
type: 'frequency',
// ['frequency', 'continuous', 'categorical']
variable: null,
label: null,
mirror: true,
// reverse color scheme?
stratify: true,
// present categories separately at each focus?
colorScheme: 'RdYlGn',
colorSchemes: ['blue', 'orange', 'red', 'purple', 'green', 'grey'],
// must be one of D3's sequential, single-hue color schemes: https://github.com/d3/d3-scale-chromatic#sequential-single-hue
nColors: 6, // min: 3, max: 9
},
color: 'rgb(170,170,170)',
fill: null, // boolean - defined in ./defineMetadata/defineIdDependentSettings
};
}
function size() {
return {
sizeBy: {
type: 'frequency',
// ['frequency', 'continuous']
variable: null,
label: null,
},
minRadius: null,
// defined in ./defineMetadata/updateIdDependentSettings
maxRadius: 10,
// defined in ./defineMetadata/updateIdDependentSettings
staticRadius: null, // defined in ./defineMetadata/updateIdDependentSettings
};
}
function shape() {
return {
shapeBy: {
type: 'categorical',
// ['categorical']
variable: null,
label: null,
shapes: ['circle', 'square', 'triangle', 'diamond', 'star', 'triangleDown'],
},
shape: 'circle', // string - default shape
};
}
function aesthetics() {
return _objectSpread2(_objectSpread2(_objectSpread2({}, color()), size()), shape());
}
function freqTable() {
return {
freqTable: {
display: true,
title: null,
columns: ['label', 'id', 'event'],
header: true,
bars: true,
structure: 'vertical',
// ['vertical', 'horizontal']
includeEventCentral: false,
displayIndividuals: true,
countType: 'id', // ['id', 'event'] - applies only when structure = 'horizontal'
},
};
}
function timing() {
return {
playPause: 'play',
delay: 5000,
speed: 'medium',
speeds: {
slow: Math.pow(2, 10),
medium: Math.pow(2, 8),
fast: Math.pow(2, 6),
},
speedChange: null,
// array of objects with timepoint and speed properties
timepoint: 0,
// initial timepoint
timeUnit: 'day',
// time unit that appears in labels
timeRelative: null,
// e.g. "from baseline"
duration: null,
// defined in ./defineMetadata/updateIdDependentSettings
loop: true,
resetDelay: 15000,
};
}
function dimensions() {
return {
width: {
main: null,
sidebar: null,
canvas: null,
},
// defined in ../layout
height: {
main: null,
},
// defined in ../layout
orbitRadius: null, // defined in ../defineMetadata/coordinates
};
}
function forceSimulation() {
return {
manyBody: 'forceManyBodyReuse',
// ['forceManyBody', 'forceManyBodyReuse', 'forceManyBodySampled']
chargeStrength: null,
// defined in ./defineMetadata/updateIdDependentSettings
collisionPadding: 1,
staticChargeStrength: null,
// defined in ./defineMetadata/updateIdDependentSettings
drawStaticSeparately: false,
// draw static shapes in a static force simulation to improve performance
staticLayout: 'circular', // ['circular', 'radial']
};
}
function modal() {
return {
modal: true,
// display modals?
modalSpeed: 10000,
// amount of time for which each modal appears
modalIndex: 0,
modalPosition: 'center',
// ['center', 'top-left', 'top-right', 'bottom-right', 'bottom-left']
modalWidth: '50%',
explanation: [
'Each shape in this animation represents an individual.',
'As <span class = "fdg-emphasized">time progresses</span> and individuals experience events, their shape gravitates toward the focus or "planet" representing that event.',
'The <span class = "fdg-emphasized">annotations</span> at each focus represent the [event-count-type].',
'The <span class = "fdg-emphasized">number of events</span> an individual has experienced determines the [frequency-aesthetic] of their shape.',
'<span class = "fdg-emphasized">Static shapes</span> represent individuals who never experience an event.',
'Use the <span class = "fdg-emphasized">controls</span> on the right to interact with and alter the animation.',
'Continue watching to learn how these individuals progress.', // over the course of [duration] days.',
],
// array of strings
information: null, // array of strings
};
}
function states() {
return {
events: null,
// defined in ./defineMetadata
individualUnit: 'individual',
individualLabel: 'Individuals',
eventUnit: 'event',
eventLabel: 'Events',
eventCentral: null,
// defined in ./defineMetadata/updateEventDependentSettings
eventCount: true,
// display [ n (%) ] beneath focus labels?
eventCountType: 'current-id',
// ['current-id', 'cumulative-id', 'cumulative-event']
eventChangeCount: null,
// defined in ./defineMetadata/updateEventDependentSettings
eventLabelFontWeight: 'bold',
eventLabelFontSize: '1.5rem',
eventCountFontWeight: 'bold',
eventCountFontSize: '1rem',
eventFocusLabelChange: null, // array of objects with old label, new label, and timepoint
};
}
function miscellaneous() {
return {
hideControls: false,
focusOffset: 'heuristic',
// ['heuristic', 'none', 'above', 'below']
stratificationPositioning: 'circular',
// ['circular', 'orbital']
annotations: null,
enforceFocusVicinity: false,
stateChange: 'chronological',
// ['chronological', 'ordered']
stateChangeAnnotation: true,
displayProgress: true,
footnotes: [],
root: {
'left-margin': '25%',
},
orbitShape: 'circle', // ['circle', 'ellipse']
};
}
// TODO: setting checks
function update() {
var _this = this;
// aesthetics
if (
!['frequency', 'continuous', 'categorical', null].includes(this.settings.colorBy.type)
) {
alert(
"[ '".concat(
this.settings.colorBy.type,
"' ] is not a valid [ colorBy.type ] setting. Please choose one of [ 'frequency' ], [ 'continuous' ], or [ 'categorical' ]. Defaulting to [ 'frequency' ]."
)
);
this.settings.colorBy.type = 'frequency';
}
if (!['frequency', 'continuous', null].includes(this.settings.sizeBy.type)) {
alert(
"[ '".concat(
this.settings.sizeBy.type,
"' ] is not a valid [ sizeBy.type ] setting. Please choose one of [ 'frequency' ] or [ 'continuous' ]. Defaulting to [ 'frequency' ]."
)
);
this.settings.sizeBy.type = 'frequency';
}
if (!['categorical', null].includes(this.settings.shapeBy.type)) {
alert(
"[ '".concat(
this.settings.shapeBy.type,
"' ] is not a valid [ shapeBy.type ] setting. Please choose [ 'categorical' ]. Defaulting to [ null ]."
)
);
this.settings.shapeBy.type = null;
}
this.settings.stratify = this.settings.colorBy.type === 'categorical';
this.settings.colorify = this.settings.colorBy.type !== null;
this.settings.sizify =
this.settings.sizeBy.type === 'frequency' ||
(this.settings.sizeBy.type === 'continuous' && this.settings.sizeBy.variable !== null);
this.settings.shapify = this.settings.shapeBy.variable !== null; // freq table
// TODO: add bars to horizontal table view
if (this.settings.freqTable.structure === 'horizontal' && !this.settings.stratify)
this.settings.freqTable.structure = 'vertical';
if (this.settings.freqTable.structure === 'horizontal')
this.settings.freqTable.bars = false; // Define array of modal text.
var texts = [];
if (Array.isArray(this.settings.explanation)) {
// Update explanation text depending on aesthetics.
this.settings.explanation = this.settings.explanation.map(function (text) {
// event count type
text = text.replace(
'[event-count-type]',
_this.settings.eventCountType === 'current-id'
? 'number of individuals currently experiencing the event'
: _this.settings.eventCountType === 'cumulative-id'
? 'number of individuals who have ever experienced the event'
: 'total number of events'
); // frequency aesthetic
if (/\[frequency-aesthetic]/.test(text)) {
if (
_this.settings.colorBy.type === 'frequency' &&
_this.settings.sizeBy.type === 'frequency'
)
text = text.replace('[frequency-aesthetic]', 'color and size');
else if (_this.settings.colorBy.type === 'frequency')
text = text.replace('[frequency-aesthetic]', 'color');
else if (_this.settings.sizeBy.type === 'frequency')
text = text.replace('[frequency-aesthetic]', 'size');
else text = null;
}
return text;
});
texts = texts.concat(
this.settings.explanation.filter(function (el) {
return el !== null && !(_this.settings.hideControls && el.includes('controls'));
})
);
}
if (Array.isArray(this.settings.information))
texts = texts.concat(this.settings.information);
this.settings.text = texts.filter(function (text) {
return typeof text === 'string';
}); // sequences
if (this.settings.sequences) {
this.settings.loop = false;
this.settings.runSequences = true;
this.settings.animationTrack = 'sequence';
this.settings.sequences.forEach(function (sequence) {
sequence.eventIndex = 0;
});
} else {
this.settings.runSequences = false;
this.settings.animationTrack = 'full';
} // progress
if (this.settings.stateChange === 'ordered') this.settings.displayProgress = false;
}
var settings = _objectSpread2(
_objectSpread2(
_objectSpread2(
_objectSpread2(
_objectSpread2(
_objectSpread2(
_objectSpread2(
_objectSpread2(
_objectSpread2(_objectSpread2({}, dataMapping()), aesthetics()),
freqTable()
),
timing()
),
dimensions()
),
forceSimulation()
),
modal()
),
states()
),
miscellaneous()
),
{},
{
update: update,
}
);
function controls(main) {
var container = this.util
.addElement('controls', main)
.classed('fdg-hidden', this.settings.hideControls);
var hide = this.util.addElement('hide', container, 'span');
return {
controlsContainer: container,
hide: hide,
};
}
function addTimer(progress) {
var timer = this.util.addElement('timer', progress);
timer.width = timer.node().clientWidth;
timer.innerRadius = timer.width / 8;
timer.svg = this.util
.addElement('timer__svg', timer, 'svg')
.attr('width', timer.width)
.attr('height', timer.width);
timer.arc = d3
.arc()
.innerRadius(timer.width / 2.25)
.outerRadius(timer.width / 2 - 1)
.startAngle(0);
timer.g = this.util
.addElement('timer__path', timer.svg, 'g')
.attr(
'transform',
'translate('.concat(timer.width / 2, ',').concat(timer.width / 2, ')')
);
timer.background = this.util
.addElement('timer__path', timer.g, 'path')
.classed('fdg-timer__path--background', true)
.datum({
endAngle: 2 * Math.PI,
})
.attr('d', timer.arc);
timer.foreground = this.util
.addElement('timer__path', timer.g, 'path')
.classed('fdg-timer__path--foreground', true)
.datum({
endAngle: 0,
})
.attr('d', timer.arc);
timer.percentComplete = this.util
.addElement('timer__percent-complete', timer.g, 'text')
.text('0%');
return timer;
}
function addCountdown(progress) {
var resetDelay = this.settings.resetDelay / 1000;
return this.util
.addElement('countdown', progress)
.classed('fdg-sidebar__label', true)
.selectAll('div')
.data(d3.range(-1, resetDelay))
.join('div')
.text(function (d) {
return 'Looping in '.concat(d + 1, ' second').concat(d === 0 ? '' : 's');
})
.classed('fdg-hidden', function (d) {
return d !== resetDelay - 1;
})
.classed('fdg-invisible', function (d) {
return d === resetDelay - 1;
});
}
function sidebar(main) {
var container = this.util.addElement('sidebar', main);
this.settings.width.sidebar = container.node().clientWidth;
var events = this.util.addElement('events', container).html(this.settings.eventLabel);
var legends = this.util.addElement('legends', container);
var progress = this.util
.addElement('progress', container)
.classed('fdg-hidden', !this.settings.displayProgress);
var timepoint = this.util
.addElement('timepoint', progress)
.classed('fdg-sidebar__label', true)
.html(
''
.concat(this.settings.timepoint, ' ')
.concat(
this.settings.timepoint !== 1
? this.settings.timeUnit + 's'
: this.settings.timeUnit
)
);
var timeRelative = this.util
.addElement('time-relative', progress)
.classed('fdg-sidebar__sub-label', true)
.html(this.settings.timeRelative);
var timer = addTimer.call(this, progress);
var countdown = addCountdown.call(this, progress);
var freqTable = this.util.addElement('freq-table', container);
return {
sidebarContainer: container,
events: events,
legends: legends,
progress: progress,
timepoint: timepoint,
timeRelative: timeRelative,
timer: timer,
countdown: countdown,
freqTable: freqTable,
};
}
function canvas(main) {
var _this = this;
var container = this.util.addElement('animation', main);
this.settings.width.canvas = container.node().clientWidth; // background SVG - orbits
var svgBackground = this.util
.addElement('svg--background', container, 'svg')
.attr('width', this.settings.width.main)
.attr('height', this.settings.height.main)
.style('position', 'absolute')
.style('left', -this.settings.width.sidebar)
.style('top', 0); // canvas - bubbles
var canvas = this.util
.addElement('canvas', container, 'canvas')
.attr('width', this.settings.width.canvas)
.attr('height', this.settings.height.main);
canvas.context = canvas.node().getContext('2d'); // foreground SVG - annotations
var svgForeground = this.util
.addElement('svg--foreground', container, 'svg')
.attr('width', this.settings.width.canvas)
.attr('height', this.settings.height.main);