This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetricsgraphics.js
8252 lines (6863 loc) · 244 KB
/
metricsgraphics.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(root, factory) {
if (typeof define === 'function' && define.amd) {
define(['d3'], factory);
} else if (typeof exports === 'object') {
module.exports = factory(require('d3'));
} else {
root.MG = factory(root.d3);
}
}(this, function(d3) {
(typeof window === 'undefined' ? global : window).MG = {version: '2.11'};
//a set of helper functions, some that we've written, others that we've borrowed
MG.convert = {};
MG.convert.date = function(data, accessor, time_format) {
time_format = (typeof time_format === "undefined") ? '%Y-%m-%d' : time_format;
var parse_time = d3.timeParse(time_format);
data = data.map(function(d) {
d[accessor] = parse_time(d[accessor].trim());
return d;
});
return data;
}
MG.convert.number = function(data, accessor) {
data = data.map(function(d) {
d[accessor] = Number(d[accessor]);
return d;
});
return data;
}
MG.time_format = function(utc, specifier) {
return utc ? d3.utcFormat(specifier) : d3.timeFormat(specifier);
}
function mg_jquery_exists() {
if (typeof jQuery !== 'undefined' || typeof $ !== 'undefined') {
return true;
} else {
return false;
}
}
function mg_get_rollover_time_format(args) {
var fmt;
switch (args.processed.x_time_frame) {
case 'millis':
fmt = MG.time_format(args.utc_time, '%b %e, %Y %H:%M:%S.%L');
break;
case 'seconds':
fmt = MG.time_format(args.utc_time, '%b %e, %Y %H:%M:%S');
break;
case 'less-than-a-day':
fmt = MG.time_format(args.utc_time, '%b %e, %Y %I:%M%p');
break;
case 'four-days':
fmt = MG.time_format(args.utc_time, '%b %e, %Y %I:%M%p');
break;
default:
fmt = MG.time_format(args.utc_time, '%b %e, %Y');
}
return fmt;
}
function mg_data_in_plot_bounds(datum, args) {
return datum[args.x_accessor] >= args.processed.min_x &&
datum[args.x_accessor] <= args.processed.max_x &&
datum[args.y_accessor] >= args.processed.min_y &&
datum[args.y_accessor] <= args.processed.max_y;
}
function is_array(thing) {
return Object.prototype.toString.call(thing) === '[object Array]';
}
function is_function(thing) {
return Object.prototype.toString.call(thing) === '[object Function]';
}
function is_empty_array(thing) {
return is_array(thing) && thing.length === 0;
}
function is_object(thing) {
return Object.prototype.toString.call(thing) === '[object Object]';
}
function is_array_of_arrays(data) {
var all_elements = data.map(function(d) {
return is_array(d) === true && d.length > 0;
});
return d3.sum(all_elements) === data.length;
}
function is_array_of_objects(data) {
// is every element of data an object?
var all_elements = data.map(function(d) {
return is_object(d) === true;
});
return d3.sum(all_elements) === data.length;
}
function is_array_of_objects_or_empty(data) {
return is_empty_array(data) || is_array_of_objects(data);
}
function pluck(arr, accessor) {
return arr.map(function(d) {
return d[accessor] });
}
function count_array_elements(arr) {
return arr.reduce(function(a, b) { a[b] = a[b] + 1 || 1;
return a; }, {});
}
function mg_get_bottom(args) {
return args.height - args.bottom;
}
function mg_get_plot_bottom(args) {
// returns the pixel location of the bottom side of the plot area.
return mg_get_bottom(args) - args.buffer;
}
function mg_get_top(args) {
return args.top;
}
function mg_get_plot_top(args) {
// returns the pixel location of the top side of the plot area.
return mg_get_top(args) + args.buffer;
}
function mg_get_left(args) {
return args.left;
}
function mg_get_plot_left(args) {
// returns the pixel location of the left side of the plot area.
return mg_get_left(args) + args.buffer;
}
function mg_get_right(args) {
return args.width - args.right;
}
function mg_get_plot_right(args) {
// returns the pixel location of the right side of the plot area.
return mg_get_right(args) - args.buffer;
}
//////// adding elements, removing elements /////////////
function mg_exit_and_remove(elem) {
elem.exit().remove();
}
function mg_selectAll_and_remove(svg, cl) {
svg.selectAll(cl).remove();
}
function mg_add_g(svg, cl) {
return svg.append('g').classed(cl, true);
}
function mg_remove_element(svg, elem) {
svg.select(elem).remove();
}
//////// axis helper functions ////////////
function mg_make_rug(args, rug_class) {
var svg = mg_get_svg_child_of(args.target);
var all_data = mg_flatten_array(args.data);
var rug = svg.selectAll('line.' + rug_class).data(all_data);
rug.enter()
.append('line')
.attr('class', rug_class)
.attr('opacity', 0.3);
//remove rug elements that are no longer in use
mg_exit_and_remove(rug);
//set coordinates of new rug elements
mg_exit_and_remove(rug);
return rug;
}
function mg_add_color_accessor_to_rug(rug, args, rug_mono_class) {
if (args.color_accessor) {
rug.attr('stroke', args.scalefns.colorf);
rug.classed(rug_mono_class, false);
} else {
rug.attr('stroke', null);
rug.classed(rug_mono_class, true);
}
}
function mg_rotate_labels(labels, rotation_degree) {
if (rotation_degree) {
labels.attr({
dy: 0,
transform: function() {
var elem = d3.select(this);
return 'rotate(' + rotation_degree + ' ' + elem.attr('x') + ',' + elem.attr('y') + ')';
}
});
}
}
//////////////////////////////////////////////////
function mg_elements_are_overlapping(labels) {
labels = labels.node();
if (!labels) {
return false;
}
for (var i = 0; i < labels.length; i++) {
if (mg_is_horizontally_overlapping(labels[i], labels)) return true;
}
return false;
}
function mg_prevent_horizontal_overlap(labels, args) {
if (!labels || labels.length == 1) {
return;
}
//see if each of our labels overlaps any of the other labels
for (var i = 0; i < labels.length; i++) {
//if so, nudge it up a bit, if the label it intersects hasn't already been nudged
if (mg_is_horizontally_overlapping(labels[i], labels)) {
var node = d3.select(labels[i]);
var newY = +node.attr('y');
if (newY + 8 >= args.top) {
newY = args.top - 16;
}
node.attr('y', newY);
}
}
}
function mg_prevent_vertical_overlap(labels, args) {
if (!labels || labels.length == 1) {
return;
}
labels.sort(function(b, a) {
return d3.select(a).attr('y') - d3.select(b).attr('y');
});
labels.reverse();
var overlap_amount, label_i, label_j;
//see if each of our labels overlaps any of the other labels
for (var i = 0; i < labels.length; i++) {
//if so, nudge it up a bit, if the label it intersects hasn't already been nudged
label_i = d3.select(labels[i]).text();
for (var j = 0; j < labels.length; j++) {
label_j = d3.select(labels[j]).text();
overlap_amount = mg_is_vertically_overlapping(labels[i], labels[j]);
if (overlap_amount !== false && label_i !== label_j) {
var node = d3.select(labels[i]);
var newY = +node.attr('y');
newY = newY + overlap_amount;
node.attr('y', newY);
}
}
}
}
function mg_is_vertically_overlapping(element, sibling) {
var element_bbox = element.getBoundingClientRect();
var sibling_bbox = sibling.getBoundingClientRect();
if (element_bbox.top <= sibling_bbox.bottom && element_bbox.top >= sibling_bbox.top) {
return sibling_bbox.bottom - element_bbox.top;
}
return false;
}
function mg_is_horiz_overlap(element, sibling) {
var element_bbox = element.getBoundingClientRect();
var sibling_bbox = sibling.getBoundingClientRect();
if (element_bbox.right >= sibling_bbox.left || element_bbox.top >= sibling_bbox.top) {
return sibling_bbox.bottom - element_bbox.top;
}
return false;
}
function mg_is_horizontally_overlapping(element, labels) {
var element_bbox = element.getBoundingClientRect();
for (var i = 0; i < labels.length; i++) {
if (labels[i] == element) {
continue;
}
//check to see if this label overlaps with any of the other labels
var sibling_bbox = labels[i].getBoundingClientRect();
if (element_bbox.top === sibling_bbox.top &&
!(sibling_bbox.left > element_bbox.right || sibling_bbox.right < element_bbox.left)
) {
return true;
}
}
return false;
}
function mg_infer_type(args, ns) {
// must return categorical or numerical.
var testPoint = mg_flatten_array(args.data);
testPoint = testPoint[0][args[ns + '_accessor']];
return typeof testPoint === 'string' ? 'categorical' : 'numerical';
}
function mg_get_svg_child_of(selector_or_node) {
return d3.select(selector_or_node).select('svg');
}
function mg_flatten_array(arr) {
var flat_data = [];
return flat_data.concat.apply(flat_data, arr);
}
function mg_next_id() {
if (typeof MG._next_elem_id === 'undefined') {
MG._next_elem_id = 0;
}
return 'mg-' + (MG._next_elem_id++);
}
function mg_target_ref(target) {
if (typeof target === 'string') {
return mg_normalize(target);
} else if (target instanceof window.HTMLElement) {
var target_ref = target.getAttribute('data-mg-uid');
if (!target_ref) {
target_ref = mg_next_id();
target.setAttribute('data-mg-uid', target_ref);
}
return target_ref;
} else {
console.warn('The specified target should be a string or an HTMLElement.', target);
return mg_normalize(target);
}
}
function mg_normalize(string) {
return string
.replace(/[^a-zA-Z0-9 _-]+/g, '')
.replace(/ +?/g, '');
}
function get_pixel_dimension(target, dimension) {
return Number(d3.select(target).style(dimension).replace(/px/g, ''));
}
function get_width(target) {
return get_pixel_dimension(target, 'width');
}
function get_height(target) {
return get_pixel_dimension(target, 'height');
}
function isNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
var each = function(obj, iterator, context) {
// yanked out of underscore
var breaker = {};
if (obj === null) return obj;
if (Array.prototype.forEach && obj.forEach === Array.prototype.forEach) {
obj.forEach(iterator, context);
} else if (obj.length === +obj.length) {
for (var i = 0, length = obj.length; i < length; i++) {
if (iterator.call(context, obj[i], i, obj) === breaker) return;
}
} else {
for (var k in obj) {
if (iterator.call(context, obj[k], k, obj) === breaker) return;
}
}
return obj;
};
function merge_with_defaults(obj) {
// taken from underscore
each(Array.prototype.slice.call(arguments, 1), function(source) {
if (source) {
for (var prop in source) {
if (obj[prop] === void 0) obj[prop] = source[prop];
}
}
});
return obj;
}
MG.merge_with_defaults = merge_with_defaults;
function number_of_values(data, accessor, value) {
var values = data.filter(function(d) {
return d[accessor] === value;
});
return values.length;
}
function has_values_below(data, accessor, value) {
var values = data.filter(function(d) {
return d[accessor] <= value;
});
return values.length > 0;
}
function has_too_many_zeros(data, accessor, zero_count) {
return number_of_values(data, accessor, 0) >= zero_count;
}
function mg_is_date(obj) {
return Object.prototype.toString.call(obj) === '[object Date]';
}
function mg_is_object(obj) {
return Object.prototype.toString.call(obj) === '[object Object]';
}
function mg_is_array(obj) {
if (Array.isArray) {
return Array.isArray(obj);
}
return Object.prototype.toString.call(obj) === '[object Array]';
}
// deep copy
// http://stackoverflow.com/questions/728360/most-elegant-way-to-clone-a-javascript-object
MG.clone = function(obj) {
var copy;
// Handle the 3 simple types, and null or undefined
if (null === obj || "object" !== typeof obj) return obj;
// Handle Date
if (mg_is_date(obj)) {
copy = new Date();
copy.setTime(obj.getTime());
return copy;
}
// Handle Array
if (mg_is_array(obj)) {
copy = [];
for (var i = 0, len = obj.length; i < len; i++) {
copy[i] = MG.clone(obj[i]);
}
return copy;
}
// Handle Object
if (mg_is_object(obj)) {
copy = {};
for (var attr in obj) {
if (obj.hasOwnProperty(attr)) copy[attr] = MG.clone(obj[attr]);
}
return copy;
}
throw new Error("Unable to copy obj! Its type isn't supported.");
};
// give us the difference of two int arrays
// http://radu.cotescu.com/javascript-diff-function/
function arr_diff(a, b) {
var seen = [],
diff = [],
i;
for (i = 0; i < b.length; i++)
seen[b[i]] = true;
for (i = 0; i < a.length; i++)
if (!seen[a[i]])
diff.push(a[i]);
return diff;
}
MG.arr_diff = arr_diff;
/**
Print warning message to the console when a feature has been scheduled for removal
@author Dan de Havilland (github.com/dandehavilland)
@date 2014-12
*/
function warn_deprecation(message, untilVersion) {
console.warn('Deprecation: ' + message + (untilVersion ? '. This feature will be removed in ' + untilVersion + '.' : ' the near future.'));
console.trace();
}
MG.warn_deprecation = warn_deprecation;
/**
Truncate a string to fit within an SVG text node
CSS text-overlow doesn't apply to SVG <= 1.2
@author Dan de Havilland (github.com/dandehavilland)
@date 2014-12-02
*/
function truncate_text(textObj, textString, width) {
var bbox,
position = 0;
textObj.textContent = textString;
bbox = textObj.getBBox();
while (bbox.width > width) {
textObj.textContent = textString.slice(0, --position) + '...';
bbox = textObj.getBBox();
if (textObj.textContent === '...') {
break;
}
}
}
MG.truncate_text = truncate_text;
/**
Wrap the contents of a text node to a specific width
Adapted from bl.ocks.org/mbostock/7555321
@author Mike Bostock
@author Dan de Havilland
@date 2015-01-14
*/
function wrap_text(text, width, token, tspanAttrs) {
text.each(function() {
var text = d3.select(this),
words = text.text().split(token || /\s+/).reverse(),
word,
line = [],
lineNumber = 0,
lineHeight = 1.1, // ems
y = text.attr("y"),
dy = 0,
tspan = text.text(null)
.append("tspan")
.attr("x", 0)
.attr("y", dy + "em")
.attr(tspanAttrs || {});
while (!!(word = words.pop())) {
line.push(word);
tspan.text(line.join(" "));
if (width === null || tspan.node().getComputedTextLength() > width) {
line.pop();
tspan.text(line.join(" "));
line = [word];
tspan = text
.append("tspan")
.attr("x", 0)
.attr("y", ++lineNumber * lineHeight + dy + "em")
.attr(tspanAttrs || {})
.text(word);
}
}
});
}
MG.wrap_text = wrap_text;
function register(chartType, descriptor, defaults) {
MG.charts[chartType] = {
descriptor: descriptor,
defaults: defaults || {}
};
}
MG.register = register;
/**
Record of all registered hooks.
For internal use only.
*/
MG._hooks = {};
/**
Add a hook callthrough to the stack.
Hooks are executed in the order that they were registered.
*/
MG.add_hook = function(name, func, context) {
var hooks;
if (!MG._hooks[name]) {
MG._hooks[name] = [];
}
hooks = MG._hooks[name];
var already_registered =
hooks.filter(function(hook) {
return hook.func === func;
})
.length > 0;
if (already_registered) {
throw 'That function is already registered.';
}
hooks.push({
func: func,
context: context
});
};
/**
Execute registered hooks.
Optional arguments
*/
MG.call_hook = function(name) {
var hooks = MG._hooks[name],
result = [].slice.apply(arguments, [1]),
processed;
if (hooks) {
hooks.forEach(function(hook) {
if (hook.func) {
var params = processed || result;
if (params && params.constructor !== Array) {
params = [params];
}
params = [].concat.apply([], params);
processed = hook.func.apply(hook.context, params);
}
});
}
return processed || result;
};
MG.globals = {};
MG.deprecations = {
rollover_callback: { replacement: 'mouseover', version: '2.0' },
rollout_callback: { replacement: 'mouseout', version: '2.0' },
x_rollover_format: { replacement: 'x_mouseover', version: '2.10' },
y_rollover_format: { replacement: 'y_mouseover', version: '2.10' },
show_years: { replacement: 'show_secondary_x_label', version: '2.1' },
xax_start_at_min: { replacement: 'axes_not_compact', version: '2.7' },
interpolate_tension: { replacement: 'interpolate', version: '2.10' }
};
MG.globals.link = false;
MG.globals.version = "1.1";
MG.charts = {};
MG.data_graphic = function(args) {
'use strict';
var defaults = {
missing_is_zero: false, // if true, missing values will be treated as zeros
missing_is_hidden: false, // if true, missing values will appear as broken segments
missing_is_hidden_accessor: null, // the accessor that determines the boolean value for missing data points
legend: '' , // an array identifying the labels for a chart's lines
legend_target: '', // if set, the specified element is populated with a legend
error: '', // if set, a graph will show an error icon and log the error to the console
animate_on_load: false, // animate lines on load
top: 65, // the size of the top margin
title_y_position: 10, // how many pixels from the top edge (0) should we show the title at
center_title_full_width: false, // center the title over the full graph (i.e. ignore left and right margins)
bottom: 45, // the size of the bottom margin
right: 10, // size of the right margin
left: 50, // size of the left margin
buffer: 8, // the buffer between the actual chart area and the margins
width: 350, // the width of the entire graphic
height: 220, // the height of the entire graphic
full_width: false, // sets the graphic width to be the width of the parent element and resizes dynamically
full_height: false, // sets the graphic width to be the width of the parent element and resizes dynamically
small_height_threshold: 120, // the height threshold for when smaller text appears
small_width_threshold: 160, // the width threshold for when smaller text appears
xax_count: 6, // number of x axis ticks
xax_tick_length: 5, // x axis tick length
axes_not_compact: true,
yax_count: 3, // number of y axis ticks
yax_tick_length: 5, // y axis tick length
x_extended_ticks: false, // extends x axis ticks across chart - useful for tall charts
y_extended_ticks: false, // extends y axis ticks across chart - useful for long charts
y_scale_type: 'linear',
max_x: null,
max_y: null,
min_x: null,
min_y: null, // if set, y axis starts at an arbitrary value
min_y_from_data: false, // if set, y axis will start at minimum value rather than at 0
point_size: 2.5, // the size of the dot that appears on a line on mouse-over
x_accessor: 'date',
xax_units: '',
x_label: '',
x_sort: true,
x_axis: true,
y_axis: true,
x_axis_position: 'bottom',
y_axis_position: 'left',
x_axis_type: null, // TO BE INTRODUCED IN 2.10
y_axis_type: null, // TO BE INTRODUCED IN 2.10
ygroup_accessor: null,
xgroup_accessor:null,
y_padding_percentage: 0.05, // for categorical scales
y_outer_padding_percentage: .1, // for categorical scales
ygroup_padding_percentage:.25, // for categorical scales
ygroup_outer_padding_percentage: 0, // for categorical scales
x_padding_percentage: 0.05, // for categorical scales
x_outer_padding_percentage: .1, // for categorical scales
xgroup_padding_percentage:.25, // for categorical scales
xgroup_outer_padding_percentage: 0, // for categorical scales
y_categorical_show_guides: false,
x_categorical_show_guide: false,
rotate_x_labels: 0,
rotate_y_labels: 0,
y_accessor: 'value',
y_label: '',
yax_units: '',
yax_units_append: false,
x_rug: false,
y_rug: false,
mouseover_align: 'right', // implemented in point.js
x_mouseover: null,
y_mouseover: null,
transition_on_update: true,
mouseover: null,
click: null,
show_rollover_text: true,
show_confidence_band: null, // given [l, u] shows a confidence at each point from l to u
xax_format: null, // xax_format is a function that formats the labels for the x axis.
area: true,
chart_type: 'line',
data: [],
decimals: 2, // the number of decimals in any rollover
format: 'count', // format = {count, percentage}
inflator: 10/9, // for setting y axis max
linked: false, // links together all other graphs with linked:true, so rollovers in one trigger rollovers in the others
linked_format: '%Y-%m-%d', // What granularity to link on for graphs. Default is at day
list: false,
baselines: null, // sets the baseline lines
markers: null, // sets the marker lines
scalefns: {},
scales: {},
utc_time: false,
european_clock: false,
show_year_markers: false,
show_secondary_x_label: true,
secondary_x_format: null,
target: '#viz',
interpolate: d3.curveCatmullRom.alpha(0), // interpolation method to use when rendering lines; increase tension if your data is irregular and you notice artifacts
custom_line_color_map: [], // allows arbitrary mapping of lines to colors, e.g. [2,3] will map line 1 to color 2 and line 2 to color 3
colors: null, // UNIMPLEMENTED - allows direct color mapping to line colors. Will eventually require
max_data_size: null, // explicitly specify the the max number of line series, for use with custom_line_color_map
aggregate_rollover: false, // links the lines in a multi-line chart
show_tooltips: true // if enabled, a chart's description will appear in a tooltip (requires jquery)
};
MG.call_hook('global.defaults', defaults);
if (!args) { args = {}; }
var selected_chart = MG.charts[args.chart_type || defaults.chart_type];
merge_with_defaults(args, selected_chart.defaults, defaults);
if (args.list) {
args.x_accessor = 0;
args.y_accessor = 1;
}
// check for deprecated parameters
for (var key in MG.deprecations) {
if (args.hasOwnProperty(key)) {
var deprecation = MG.deprecations[key],
message = 'Use of `args.' + key + '` has been deprecated',
replacement = deprecation.replacement,
version;
// transparently alias the deprecated
if (replacement) {
if (args[replacement]) {
message += '. The replacement - `args.' + replacement + '` - has already been defined. This definition will be discarded.';
} else {
args[replacement] = args[key];
}
}
if (deprecation.warned) {
continue;
}
deprecation.warned = true;
if (replacement) {
message += ' in favor of `args.' + replacement + '`';
}
warn_deprecation(message, deprecation.version);
}
}
MG.call_hook('global.before_init', args);
new selected_chart.descriptor(args);
return args.data;
};
if (mg_jquery_exists()) {
/* ========================================================================
* Bootstrap: tooltip.js v3.3.5
* http://getbootstrap.com/javascript/#tooltip
* Inspired by the original jQuery.tipsy by Jason Frame
* ========================================================================
* Copyright 2011-2015 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* ======================================================================== */
+function ($) {
'use strict';
// TOOLTIP PUBLIC CLASS DEFINITION
// ===============================
var Tooltip = function (element, options) {
this.type = null
this.options = null
this.enabled = null
this.timeout = null
this.hoverState = null
this.$element = null
this.inState = null
this.init('tooltip', element, options)
}
Tooltip.VERSION = '3.3.5'
Tooltip.TRANSITION_DURATION = 150
Tooltip.DEFAULTS = {
animation: true,
placement: 'top',
selector: false,
template: '<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>',
trigger: 'hover focus',
title: '',
delay: 0,
html: false,
container: false,
viewport: {
selector: 'body',
padding: 0
}
}
Tooltip.prototype.init = function (type, element, options) {
this.enabled = true
this.type = type
this.$element = $(element)
this.options = this.getOptions(options)
this.$viewport = this.options.viewport && $($.isFunction(this.options.viewport) ? this.options.viewport.call(this, this.$element) : (this.options.viewport.selector || this.options.viewport))
this.inState = { click: false, hover: false, focus: false }
if (this.$element[0] instanceof document.constructor && !this.options.selector) {
throw new Error('`selector` option must be specified when initializing ' + this.type + ' on the window.document object!')
}
var triggers = this.options.trigger.split(' ')
for (var i = triggers.length; i--;) {
var trigger = triggers[i]
if (trigger == 'click') {
this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this))
} else if (trigger != 'manual') {
var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin'
var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout'
this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this))
this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this))
}
}
this.options.selector ?
(this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) :
this.fixTitle()
}
Tooltip.prototype.getDefaults = function () {
return Tooltip.DEFAULTS
}
Tooltip.prototype.getOptions = function (options) {
options = $.extend({}, this.getDefaults(), this.$element.data(), options)
if (options.delay && typeof options.delay == 'number') {
options.delay = {
show: options.delay,
hide: options.delay
}
}
return options
}
Tooltip.prototype.getDelegateOptions = function () {
var options = {}
var defaults = this.getDefaults()
this._options && $.each(this._options, function (key, value) {
if (defaults[key] != value) options[key] = value
})
return options
}
Tooltip.prototype.enter = function (obj) {
var self = obj instanceof this.constructor ?
obj : $(obj.currentTarget).data('bs.' + this.type)
if (!self) {
self = new this.constructor(obj.currentTarget, this.getDelegateOptions())
$(obj.currentTarget).data('bs.' + this.type, self)
}
if (obj instanceof $.Event) {
self.inState[obj.type == 'focusin' ? 'focus' : 'hover'] = true
}
if (self.tip().hasClass('in') || self.hoverState == 'in') {
self.hoverState = 'in'
return
}
clearTimeout(self.timeout)
self.hoverState = 'in'
if (!self.options.delay || !self.options.delay.show) return self.show()
self.timeout = setTimeout(function () {
if (self.hoverState == 'in') self.show()
}, self.options.delay.show)
}
Tooltip.prototype.isInStateTrue = function () {
for (var key in this.inState) {
if (this.inState[key]) return true
}
return false
}
Tooltip.prototype.leave = function (obj) {
var self = obj instanceof this.constructor ?
obj : $(obj.currentTarget).data('bs.' + this.type)
if (!self) {
self = new this.constructor(obj.currentTarget, this.getDelegateOptions())
$(obj.currentTarget).data('bs.' + this.type, self)
}
if (obj instanceof $.Event) {
self.inState[obj.type == 'focusout' ? 'focus' : 'hover'] = false
}
if (self.isInStateTrue()) return