-
Notifications
You must be signed in to change notification settings - Fork 0
/
dygraph.js
executable file
·9464 lines (8490 loc) · 390 KB
/
dygraph.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(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Dygraph = f()}})(function(){var define,module,exports;return (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})({1:[function(require,module,exports){
// shim for using process in browser
var process = module.exports = {};
// cached from whatever global is present so that test runners that stub it
// don't break things. But we need to wrap it in a try catch in case it is
// wrapped in strict mode code which doesn't define any globals. It's inside a
// function because try/catches deoptimize in certain engines.
var cachedSetTimeout;
var cachedClearTimeout;
function defaultSetTimout() {
throw new Error('setTimeout has not been defined');
}
function defaultClearTimeout () {
throw new Error('clearTimeout has not been defined');
}
(function () {
try {
if (typeof setTimeout === 'function') {
cachedSetTimeout = setTimeout;
} else {
cachedSetTimeout = defaultSetTimout;
}
} catch (e) {
cachedSetTimeout = defaultSetTimout;
}
try {
if (typeof clearTimeout === 'function') {
cachedClearTimeout = clearTimeout;
} else {
cachedClearTimeout = defaultClearTimeout;
}
} catch (e) {
cachedClearTimeout = defaultClearTimeout;
}
} ())
function runTimeout(fun) {
if (cachedSetTimeout === setTimeout) {
//normal enviroments in sane situations
return setTimeout(fun, 0);
}
// if setTimeout wasn't available but was latter defined
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
cachedSetTimeout = setTimeout;
return setTimeout(fun, 0);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedSetTimeout(fun, 0);
} catch(e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedSetTimeout.call(null, fun, 0);
} catch(e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
return cachedSetTimeout.call(this, fun, 0);
}
}
}
function runClearTimeout(marker) {
if (cachedClearTimeout === clearTimeout) {
//normal enviroments in sane situations
return clearTimeout(marker);
}
// if clearTimeout wasn't available but was latter defined
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
cachedClearTimeout = clearTimeout;
return clearTimeout(marker);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedClearTimeout(marker);
} catch (e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedClearTimeout.call(null, marker);
} catch (e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
return cachedClearTimeout.call(this, marker);
}
}
}
var queue = [];
var draining = false;
var currentQueue;
var queueIndex = -1;
function cleanUpNextTick() {
if (!draining || !currentQueue) {
return;
}
draining = false;
if (currentQueue.length) {
queue = currentQueue.concat(queue);
} else {
queueIndex = -1;
}
if (queue.length) {
drainQueue();
}
}
function drainQueue() {
if (draining) {
return;
}
var timeout = runTimeout(cleanUpNextTick);
draining = true;
var len = queue.length;
while(len) {
currentQueue = queue;
queue = [];
while (++queueIndex < len) {
if (currentQueue) {
currentQueue[queueIndex].run();
}
}
queueIndex = -1;
len = queue.length;
}
currentQueue = null;
draining = false;
runClearTimeout(timeout);
}
process.nextTick = function (fun) {
var args = new Array(arguments.length - 1);
if (arguments.length > 1) {
for (var i = 1; i < arguments.length; i++) {
args[i - 1] = arguments[i];
}
}
queue.push(new Item(fun, args));
if (queue.length === 1 && !draining) {
runTimeout(drainQueue);
}
};
// v8 likes predictible objects
function Item(fun, array) {
this.fun = fun;
this.array = array;
}
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
process.title = 'browser';
process.browser = true;
process.env = {};
process.argv = [];
process.version = ''; // empty string to avoid regexp issues
process.versions = {};
function noop() {}
process.on = noop;
process.addListener = noop;
process.once = noop;
process.off = noop;
process.removeListener = noop;
process.removeAllListeners = noop;
process.emit = noop;
process.prependListener = noop;
process.prependOnceListener = noop;
process.listeners = function (name) { return [] }
process.binding = function (name) {
throw new Error('process.binding is not supported');
};
process.cwd = function () { return '/' };
process.chdir = function (dir) {
throw new Error('process.chdir is not supported');
};
process.umask = function() { return 0; };
},{}],2:[function(require,module,exports){
/**
* @license
* Copyright 2013 David Eberlein (david.eberlein@ch.sauter-bc.com)
* MIT-licensed (http://opensource.org/licenses/MIT)
*/
/**
* @fileoverview DataHandler implementation for the custom bars option.
* @author David Eberlein (david.eberlein@ch.sauter-bc.com)
*/
/*global Dygraph:false */
"use strict";
Object.defineProperty(exports, '__esModule', {
value: true
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _bars = require('./bars');
var _bars2 = _interopRequireDefault(_bars);
/**
* @constructor
* @extends Dygraph.DataHandlers.BarsHandler
*/
var CustomBarsHandler = function CustomBarsHandler() {};
CustomBarsHandler.prototype = new _bars2['default']();
/** @inheritDoc */
CustomBarsHandler.prototype.extractSeries = function (rawData, i, options) {
// TODO(danvk): pre-allocate series here.
var series = [];
var x, y, point;
var logScale = options.get('logscale');
for (var j = 0; j < rawData.length; j++) {
x = rawData[j][0];
point = rawData[j][i];
if (logScale && point !== null) {
// On the log scale, points less than zero do not exist.
// This will create a gap in the chart.
if (point[0] <= 0 || point[1] <= 0 || point[2] <= 0) {
point = null;
}
}
// Extract to the unified data format.
if (point !== null) {
y = point[1];
if (y !== null && !isNaN(y)) {
series.push([x, y, [point[0], point[2]]]);
} else {
series.push([x, y, [y, y]]);
}
} else {
series.push([x, null, [null, null]]);
}
}
return series;
};
/** @inheritDoc */
CustomBarsHandler.prototype.rollingAverage = function (originalData, rollPeriod, options) {
rollPeriod = Math.min(rollPeriod, originalData.length);
var rollingData = [];
var y, low, high, mid, count, i, extremes;
low = 0;
mid = 0;
high = 0;
count = 0;
for (i = 0; i < originalData.length; i++) {
y = originalData[i][1];
extremes = originalData[i][2];
rollingData[i] = originalData[i];
if (y !== null && !isNaN(y)) {
low += extremes[0];
mid += y;
high += extremes[1];
count += 1;
}
if (i - rollPeriod >= 0) {
var prev = originalData[i - rollPeriod];
if (prev[1] !== null && !isNaN(prev[1])) {
low -= prev[2][0];
mid -= prev[1];
high -= prev[2][1];
count -= 1;
}
}
if (count) {
rollingData[i] = [originalData[i][0], 1.0 * mid / count, [1.0 * low / count, 1.0 * high / count]];
} else {
rollingData[i] = [originalData[i][0], null, [null, null]];
}
}
return rollingData;
};
exports['default'] = CustomBarsHandler;
module.exports = exports['default'];
},{"./bars":5}],3:[function(require,module,exports){
/**
* @license
* Copyright 2013 David Eberlein (david.eberlein@ch.sauter-bc.com)
* MIT-licensed (http://opensource.org/licenses/MIT)
*/
/**
* @fileoverview DataHandler implementation for the error bars option.
* @author David Eberlein (david.eberlein@ch.sauter-bc.com)
*/
/*global Dygraph:false */
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
var _bars = require('./bars');
var _bars2 = _interopRequireDefault(_bars);
/**
* @constructor
* @extends BarsHandler
*/
var ErrorBarsHandler = function ErrorBarsHandler() {};
ErrorBarsHandler.prototype = new _bars2["default"]();
/** @inheritDoc */
ErrorBarsHandler.prototype.extractSeries = function (rawData, i, options) {
// TODO(danvk): pre-allocate series here.
var series = [];
var x, y, variance, point;
var sigma = options.get("sigma");
var logScale = options.get('logscale');
for (var j = 0; j < rawData.length; j++) {
x = rawData[j][0];
point = rawData[j][i];
if (logScale && point !== null) {
// On the log scale, points less than zero do not exist.
// This will create a gap in the chart.
if (point[0] <= 0 || point[0] - sigma * point[1] <= 0) {
point = null;
}
}
// Extract to the unified data format.
if (point !== null) {
y = point[0];
if (y !== null && !isNaN(y)) {
variance = sigma * point[1];
// preserve original error value in extras for further
// filtering
series.push([x, y, [y - variance, y + variance, point[1]]]);
} else {
series.push([x, y, [y, y, y]]);
}
} else {
series.push([x, null, [null, null, null]]);
}
}
return series;
};
/** @inheritDoc */
ErrorBarsHandler.prototype.rollingAverage = function (originalData, rollPeriod, options) {
rollPeriod = Math.min(rollPeriod, originalData.length);
var rollingData = [];
var sigma = options.get("sigma");
var i, j, y, v, sum, num_ok, stddev, variance, value;
// Calculate the rolling average for the first rollPeriod - 1 points
// where there is not enough data to roll over the full number of points
for (i = 0; i < originalData.length; i++) {
sum = 0;
variance = 0;
num_ok = 0;
for (j = Math.max(0, i - rollPeriod + 1); j < i + 1; j++) {
y = originalData[j][1];
if (y === null || isNaN(y)) continue;
num_ok++;
sum += y;
variance += Math.pow(originalData[j][2][2], 2);
}
if (num_ok) {
stddev = Math.sqrt(variance) / num_ok;
value = sum / num_ok;
rollingData[i] = [originalData[i][0], value, [value - sigma * stddev, value + sigma * stddev]];
} else {
// This explicitly preserves NaNs to aid with "independent
// series".
// See testRollingAveragePreservesNaNs.
v = rollPeriod == 1 ? originalData[i][1] : null;
rollingData[i] = [originalData[i][0], v, [v, v]];
}
}
return rollingData;
};
exports["default"] = ErrorBarsHandler;
module.exports = exports["default"];
},{"./bars":5}],4:[function(require,module,exports){
/**
* @license
* Copyright 2013 David Eberlein (david.eberlein@ch.sauter-bc.com)
* MIT-licensed (http://opensource.org/licenses/MIT)
*/
/**
* @fileoverview DataHandler implementation for the combination
* of error bars and fractions options.
* @author David Eberlein (david.eberlein@ch.sauter-bc.com)
*/
/*global Dygraph:false */
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
var _bars = require('./bars');
var _bars2 = _interopRequireDefault(_bars);
/**
* @constructor
* @extends Dygraph.DataHandlers.BarsHandler
*/
var FractionsBarsHandler = function FractionsBarsHandler() {};
FractionsBarsHandler.prototype = new _bars2["default"]();
/** @inheritDoc */
FractionsBarsHandler.prototype.extractSeries = function (rawData, i, options) {
// TODO(danvk): pre-allocate series here.
var series = [];
var x, y, point, num, den, value, stddev, variance;
var mult = 100.0;
var sigma = options.get("sigma");
var logScale = options.get('logscale');
for (var j = 0; j < rawData.length; j++) {
x = rawData[j][0];
point = rawData[j][i];
if (logScale && point !== null) {
// On the log scale, points less than zero do not exist.
// This will create a gap in the chart.
if (point[0] <= 0 || point[1] <= 0) {
point = null;
}
}
// Extract to the unified data format.
if (point !== null) {
num = point[0];
den = point[1];
if (num !== null && !isNaN(num)) {
value = den ? num / den : 0.0;
stddev = den ? sigma * Math.sqrt(value * (1 - value) / den) : 1.0;
variance = mult * stddev;
y = mult * value;
// preserve original values in extras for further filtering
series.push([x, y, [y - variance, y + variance, num, den]]);
} else {
series.push([x, num, [num, num, num, den]]);
}
} else {
series.push([x, null, [null, null, null, null]]);
}
}
return series;
};
/** @inheritDoc */
FractionsBarsHandler.prototype.rollingAverage = function (originalData, rollPeriod, options) {
rollPeriod = Math.min(rollPeriod, originalData.length);
var rollingData = [];
var sigma = options.get("sigma");
var wilsonInterval = options.get("wilsonInterval");
var low, high, i, stddev;
var num = 0;
var den = 0; // numerator/denominator
var mult = 100.0;
for (i = 0; i < originalData.length; i++) {
num += originalData[i][2][2];
den += originalData[i][2][3];
if (i - rollPeriod >= 0) {
num -= originalData[i - rollPeriod][2][2];
den -= originalData[i - rollPeriod][2][3];
}
var date = originalData[i][0];
var value = den ? num / den : 0.0;
if (wilsonInterval) {
// For more details on this confidence interval, see:
// http://en.wikipedia.org/wiki/Binomial_confidence_interval
if (den) {
var p = value < 0 ? 0 : value,
n = den;
var pm = sigma * Math.sqrt(p * (1 - p) / n + sigma * sigma / (4 * n * n));
var denom = 1 + sigma * sigma / den;
low = (p + sigma * sigma / (2 * den) - pm) / denom;
high = (p + sigma * sigma / (2 * den) + pm) / denom;
rollingData[i] = [date, p * mult, [low * mult, high * mult]];
} else {
rollingData[i] = [date, 0, [0, 0]];
}
} else {
stddev = den ? sigma * Math.sqrt(value * (1 - value) / den) : 1.0;
rollingData[i] = [date, mult * value, [mult * (value - stddev), mult * (value + stddev)]];
}
}
return rollingData;
};
exports["default"] = FractionsBarsHandler;
module.exports = exports["default"];
},{"./bars":5}],5:[function(require,module,exports){
/**
* @license
* Copyright 2013 David Eberlein (david.eberlein@ch.sauter-bc.com)
* MIT-licensed (http://opensource.org/licenses/MIT)
*/
/**
* @fileoverview DataHandler base implementation for the "bar"
* data formats. This implementation must be extended and the
* extractSeries and rollingAverage must be implemented.
* @author David Eberlein (david.eberlein@ch.sauter-bc.com)
*/
/*global Dygraph:false */
/*global DygraphLayout:false */
"use strict";
Object.defineProperty(exports, '__esModule', {
value: true
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _datahandler = require('./datahandler');
var _datahandler2 = _interopRequireDefault(_datahandler);
var _dygraphLayout = require('../dygraph-layout');
var _dygraphLayout2 = _interopRequireDefault(_dygraphLayout);
/**
* @constructor
* @extends {Dygraph.DataHandler}
*/
var BarsHandler = function BarsHandler() {
_datahandler2['default'].call(this);
};
BarsHandler.prototype = new _datahandler2['default']();
// TODO(danvk): figure out why the jsdoc has to be copy/pasted from superclass.
// (I get closure compiler errors if this isn't here.)
/**
* @override
* @param {!Array.<Array>} rawData The raw data passed into dygraphs where
* rawData[i] = [x,ySeries1,...,ySeriesN].
* @param {!number} seriesIndex Index of the series to extract. All other
* series should be ignored.
* @param {!DygraphOptions} options Dygraph options.
* @return {Array.<[!number,?number,?]>} The series in the unified data format
* where series[i] = [x,y,{extras}].
*/
BarsHandler.prototype.extractSeries = function (rawData, seriesIndex, options) {
// Not implemented here must be extended
};
/**
* @override
* @param {!Array.<[!number,?number,?]>} series The series in the unified
* data format where series[i] = [x,y,{extras}].
* @param {!number} rollPeriod The number of points over which to average the data
* @param {!DygraphOptions} options The dygraph options.
* TODO(danvk): be more specific than "Array" here.
* @return {!Array.<[!number,?number,?]>} the rolled series.
*/
BarsHandler.prototype.rollingAverage = function (series, rollPeriod, options) {
// Not implemented here, must be extended.
};
/** @inheritDoc */
BarsHandler.prototype.onPointsCreated_ = function (series, points) {
for (var i = 0; i < series.length; ++i) {
var item = series[i];
var point = points[i];
point.y_top = NaN;
point.y_bottom = NaN;
point.yval_minus = _datahandler2['default'].parseFloat(item[2][0]);
point.yval_plus = _datahandler2['default'].parseFloat(item[2][1]);
}
};
/** @inheritDoc */
BarsHandler.prototype.getExtremeYValues = function (series, dateWindow, options) {
var minY = null,
maxY = null,
y;
var firstIdx = 0;
var lastIdx = series.length - 1;
for (var j = firstIdx; j <= lastIdx; j++) {
y = series[j][1];
if (y === null || isNaN(y)) continue;
var low = series[j][2][0];
var high = series[j][2][1];
if (low > y) low = y; // this can happen with custom bars,
if (high < y) high = y; // e.g. in tests/custom-bars.html
if (maxY === null || high > maxY) maxY = high;
if (minY === null || low < minY) minY = low;
}
return [minY, maxY];
};
/** @inheritDoc */
BarsHandler.prototype.onLineEvaluated = function (points, axis, logscale) {
var point;
for (var j = 0; j < points.length; j++) {
// Copy over the error terms
point = points[j];
point.y_top = _dygraphLayout2['default'].calcYNormal_(axis, point.yval_minus, logscale);
point.y_bottom = _dygraphLayout2['default'].calcYNormal_(axis, point.yval_plus, logscale);
}
};
exports['default'] = BarsHandler;
module.exports = exports['default'];
},{"../dygraph-layout":13,"./datahandler":6}],6:[function(require,module,exports){
/**
* @license
* Copyright 2013 David Eberlein (david.eberlein@ch.sauter-bc.com)
* MIT-licensed (http://opensource.org/licenses/MIT)
*/
/**
* @fileoverview This file contains the managment of data handlers
* @author David Eberlein (david.eberlein@ch.sauter-bc.com)
*
* The idea is to define a common, generic data format that works for all data
* structures supported by dygraphs. To make this possible, the DataHandler
* interface is introduced. This makes it possible, that dygraph itself can work
* with the same logic for every data type independent of the actual format and
* the DataHandler takes care of the data format specific jobs.
* DataHandlers are implemented for all data types supported by Dygraphs and
* return Dygraphs compliant formats.
* By default the correct DataHandler is chosen based on the options set.
* Optionally the user may use his own DataHandler (similar to the plugin
* system).
*
*
* The unified data format returend by each handler is defined as so:
* series[n][point] = [x,y,(extras)]
*
* This format contains the common basis that is needed to draw a simple line
* series extended by optional extras for more complex graphing types. It
* contains a primitive x value as first array entry, a primitive y value as
* second array entry and an optional extras object for additional data needed.
*
* x must always be a number.
* y must always be a number, NaN of type number or null.
* extras is optional and must be interpreted by the DataHandler. It may be of
* any type.
*
* In practice this might look something like this:
* default: [x, yVal]
* errorBar / customBar: [x, yVal, [yTopVariance, yBottomVariance] ]
*
*/
/*global Dygraph:false */
/*global DygraphLayout:false */
"use strict";
/**
*
* The data handler is responsible for all data specific operations. All of the
* series data it receives and returns is always in the unified data format.
* Initially the unified data is created by the extractSeries method
* @constructor
*/
Object.defineProperty(exports, "__esModule", {
value: true
});
var DygraphDataHandler = function DygraphDataHandler() {};
var handler = DygraphDataHandler;
/**
* X-value array index constant for unified data samples.
* @const
* @type {number}
*/
handler.X = 0;
/**
* Y-value array index constant for unified data samples.
* @const
* @type {number}
*/
handler.Y = 1;
/**
* Extras-value array index constant for unified data samples.
* @const
* @type {number}
*/
handler.EXTRAS = 2;
/**
* Extracts one series from the raw data (a 2D array) into an array of the
* unified data format.
* This is where undesirable points (i.e. negative values on log scales and
* missing values through which we wish to connect lines) are dropped.
* TODO(danvk): the "missing values" bit above doesn't seem right.
*
* @param {!Array.<Array>} rawData The raw data passed into dygraphs where
* rawData[i] = [x,ySeries1,...,ySeriesN].
* @param {!number} seriesIndex Index of the series to extract. All other
* series should be ignored.
* @param {!DygraphOptions} options Dygraph options.
* @return {Array.<[!number,?number,?]>} The series in the unified data format
* where series[i] = [x,y,{extras}].
*/
handler.prototype.extractSeries = function (rawData, seriesIndex, options) {};
/**
* Converts a series to a Point array. The resulting point array must be
* returned in increasing order of idx property.
*
* @param {!Array.<[!number,?number,?]>} series The series in the unified
* data format where series[i] = [x,y,{extras}].
* @param {!string} setName Name of the series.
* @param {!number} boundaryIdStart Index offset of the first point, equal to the
* number of skipped points left of the date window minimum (if any).
* @return {!Array.<Dygraph.PointType>} List of points for this series.
*/
handler.prototype.seriesToPoints = function (series, setName, boundaryIdStart) {
// TODO(bhs): these loops are a hot-spot for high-point-count charts. In
// fact,
// on chrome+linux, they are 6 times more expensive than iterating through
// the
// points and drawing the lines. The brunt of the cost comes from allocating
// the |point| structures.
var points = [];
for (var i = 0; i < series.length; ++i) {
var item = series[i];
var yraw = item[1];
var yval = yraw === null ? null : handler.parseFloat(yraw);
var point = {
x: NaN,
y: NaN,
xval: handler.parseFloat(item[0]),
yval: yval,
name: setName, // TODO(danvk): is this really necessary?
idx: i + boundaryIdStart
};
points.push(point);
}
this.onPointsCreated_(series, points);
return points;
};
/**
* Callback called for each series after the series points have been generated
* which will later be used by the plotters to draw the graph.
* Here data may be added to the seriesPoints which is needed by the plotters.
* The indexes of series and points are in sync meaning the original data
* sample for series[i] is points[i].
*
* @param {!Array.<[!number,?number,?]>} series The series in the unified
* data format where series[i] = [x,y,{extras}].
* @param {!Array.<Dygraph.PointType>} points The corresponding points passed
* to the plotter.
* @protected
*/
handler.prototype.onPointsCreated_ = function (series, points) {};
/**
* Calculates the rolling average of a data set.
*
* @param {!Array.<[!number,?number,?]>} series The series in the unified
* data format where series[i] = [x,y,{extras}].
* @param {!number} rollPeriod The number of points over which to average the data
* @param {!DygraphOptions} options The dygraph options.
* @return {!Array.<[!number,?number,?]>} the rolled series.
*/
handler.prototype.rollingAverage = function (series, rollPeriod, options) {};
/**
* Computes the range of the data series (including confidence intervals).
*
* @param {!Array.<[!number,?number,?]>} series The series in the unified
* data format where series[i] = [x, y, {extras}].
* @param {!Array.<number>} dateWindow The x-value range to display with
* the format: [min, max].
* @param {!DygraphOptions} options The dygraph options.
* @return {Array.<number>} The low and high extremes of the series in the
* given window with the format: [low, high].
*/
handler.prototype.getExtremeYValues = function (series, dateWindow, options) {};
/**
* Callback called for each series after the layouting data has been
* calculated before the series is drawn. Here normalized positioning data
* should be calculated for the extras of each point.
*
* @param {!Array.<Dygraph.PointType>} points The points passed to
* the plotter.
* @param {!Object} axis The axis on which the series will be plotted.
* @param {!boolean} logscale Weather or not to use a logscale.
*/
handler.prototype.onLineEvaluated = function (points, axis, logscale) {};
/**
* Optimized replacement for parseFloat, which was way too slow when almost
* all values were type number, with few edge cases, none of which were strings.
* @param {?number} val
* @return {number}
* @protected
*/
handler.parseFloat = function (val) {
// parseFloat(null) is NaN
if (val === null) {
return NaN;
}
// Assume it's a number or NaN. If it's something else, I'll be shocked.
return val;
};
exports["default"] = DygraphDataHandler;
module.exports = exports["default"];
},{}],7:[function(require,module,exports){
/**
* @license
* Copyright 2013 David Eberlein (david.eberlein@ch.sauter-bc.com)
* MIT-licensed (http://opensource.org/licenses/MIT)
*/
/**
* @fileoverview DataHandler implementation for the fractions option.
* @author David Eberlein (david.eberlein@ch.sauter-bc.com)
*/
/*global Dygraph:false */
"use strict";
Object.defineProperty(exports, '__esModule', {
value: true
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _datahandler = require('./datahandler');
var _datahandler2 = _interopRequireDefault(_datahandler);
var _default = require('./default');
var _default2 = _interopRequireDefault(_default);
/**
* @extends DefaultHandler
* @constructor
*/
var DefaultFractionHandler = function DefaultFractionHandler() {};
DefaultFractionHandler.prototype = new _default2['default']();
DefaultFractionHandler.prototype.extractSeries = function (rawData, i, options) {
// TODO(danvk): pre-allocate series here.
var series = [];
var x, y, point, num, den, value;
var mult = 100.0;
var logScale = options.get('logscale');
for (var j = 0; j < rawData.length; j++) {
x = rawData[j][0];
point = rawData[j][i];
if (logScale && point !== null) {
// On the log scale, points less than zero do not exist.
// This will create a gap in the chart.
if (point[0] <= 0 || point[1] <= 0) {
point = null;
}
}
// Extract to the unified data format.
if (point !== null) {
num = point[0];
den = point[1];
if (num !== null && !isNaN(num)) {
value = den ? num / den : 0.0;
y = mult * value;
// preserve original values in extras for further filtering
series.push([x, y, [num, den]]);
} else {
series.push([x, num, [num, den]]);
}
} else {
series.push([x, null, [null, null]]);
}
}
return series;
};
DefaultFractionHandler.prototype.rollingAverage = function (originalData, rollPeriod, options) {
rollPeriod = Math.min(rollPeriod, originalData.length);
var rollingData = [];
var i;
var num = 0;
var den = 0; // numerator/denominator
var mult = 100.0;
for (i = 0; i < originalData.length; i++) {
num += originalData[i][2][0];
den += originalData[i][2][1];
if (i - rollPeriod >= 0) {
num -= originalData[i - rollPeriod][2][0];
den -= originalData[i - rollPeriod][2][1];
}
var date = originalData[i][0];
var value = den ? num / den : 0.0;
rollingData[i] = [date, mult * value];
}
return rollingData;
};
exports['default'] = DefaultFractionHandler;
module.exports = exports['default'];
},{"./datahandler":6,"./default":8}],8:[function(require,module,exports){
/**
* @license
* Copyright 2013 David Eberlein (david.eberlein@ch.sauter-bc.com)
* MIT-licensed (http://opensource.org/licenses/MIT)
*/
/**
* @fileoverview DataHandler default implementation used for simple line charts.
* @author David Eberlein (david.eberlein@ch.sauter-bc.com)
*/
/*global Dygraph:false */
"use strict";
Object.defineProperty(exports, '__esModule', {
value: true
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _datahandler = require('./datahandler');
var _datahandler2 = _interopRequireDefault(_datahandler);
/**
* @constructor
* @extends Dygraph.DataHandler
*/
var DefaultHandler = function DefaultHandler() {};
DefaultHandler.prototype = new _datahandler2['default']();
/** @inheritDoc */
DefaultHandler.prototype.extractSeries = function (rawData, i, options) {
// TODO(danvk): pre-allocate series here.
var series = [];
var logScale = options.get('logscale');
for (var j = 0; j < rawData.length; j++) {
var x = rawData[j][0];
var point = rawData[j][i];
if (logScale) {
// On the log scale, points less than zero do not exist.
// This will create a gap in the chart.
if (point <= 0) {
point = null;
}
}
series.push([x, point]);
}
return series;
};