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 | import DygraphLayout from './dygraph-layout';
|
51 | import DygraphCanvasRenderer from './dygraph-canvas';
|
52 | import DygraphOptions from './dygraph-options';
|
53 | import DygraphInteraction from './dygraph-interaction-model';
|
54 | import * as DygraphTickers from './dygraph-tickers';
|
55 | import * as utils from './dygraph-utils';
|
56 | import DEFAULT_ATTRS from './dygraph-default-attrs';
|
57 | import OPTIONS_REFERENCE from './dygraph-options-reference';
|
58 | import IFrameTarp from './iframe-tarp';
|
59 |
|
60 | import DefaultHandler from './datahandler/default';
|
61 | import ErrorBarsHandler from './datahandler/bars-error';
|
62 | import CustomBarsHandler from './datahandler/bars-custom';
|
63 | import DefaultFractionHandler from './datahandler/default-fractions';
|
64 | import FractionsBarsHandler from './datahandler/bars-fractions';
|
65 | import BarsHandler from './datahandler/bars';
|
66 |
|
67 | import AnnotationsPlugin from './plugins/annotations';
|
68 | import AxesPlugin from './plugins/axes';
|
69 | import ChartLabelsPlugin from './plugins/chart-labels';
|
70 | import GridPlugin from './plugins/grid';
|
71 | import LegendPlugin from './plugins/legend';
|
72 | import RangeSelectorPlugin from './plugins/range-selector';
|
73 |
|
74 | import GVizChart from './dygraph-gviz';
|
75 |
|
76 | "use strict";
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 | var Dygraph = function Dygraph(div, data, opts) {
|
94 | this.__init__(div, data, opts);
|
95 | };
|
96 |
|
97 | Dygraph.NAME = "Dygraph";
|
98 | Dygraph.VERSION = "2.2.1";
|
99 |
|
100 |
|
101 | var _addrequire = {};
|
102 | Dygraph._require = function require(what) {
|
103 | return (what in _addrequire ? _addrequire[what] : Dygraph._require._b(what));
|
104 | };
|
105 | Dygraph._require._b = null;
|
106 | Dygraph._require.add = function add(what, towhat) {
|
107 | _addrequire[what] = towhat;
|
108 | };
|
109 |
|
110 |
|
111 | Dygraph.DEFAULT_ROLL_PERIOD = 1;
|
112 | Dygraph.DEFAULT_WIDTH = 480;
|
113 | Dygraph.DEFAULT_HEIGHT = 320;
|
114 |
|
115 |
|
116 | Dygraph.ANIMATION_STEPS = 12;
|
117 | Dygraph.ANIMATION_DURATION = 200;
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 | Dygraph.Plotters = DygraphCanvasRenderer._Plotters;
|
130 |
|
131 |
|
132 | Dygraph.addedAnnotationCSS = false;
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 | Dygraph.prototype.__init__ = function(div, file, attrs) {
|
144 | this.is_initial_draw_ = true;
|
145 | this.readyFns_ = [];
|
146 |
|
147 |
|
148 | if (attrs === null || attrs === undefined) { attrs = {}; }
|
149 |
|
150 | attrs = Dygraph.copyUserAttrs_(attrs);
|
151 |
|
152 | if (typeof(div) == 'string') {
|
153 | div = document.getElementById(div);
|
154 | }
|
155 |
|
156 | if (!div) {
|
157 | throw new Error('Constructing dygraph with a non-existent div!');
|
158 | }
|
159 |
|
160 |
|
161 |
|
162 | this.maindiv_ = div;
|
163 | this.file_ = file;
|
164 | this.rollPeriod_ = attrs.rollPeriod || Dygraph.DEFAULT_ROLL_PERIOD;
|
165 | this.previousVerticalX_ = -1;
|
166 | this.fractions_ = attrs.fractions || false;
|
167 | this.dateWindow_ = attrs.dateWindow || null;
|
168 |
|
169 | this.annotations_ = [];
|
170 |
|
171 |
|
172 |
|
173 | div.innerHTML = "";
|
174 |
|
175 | const resolved = window.getComputedStyle(div, null);
|
176 | if (resolved.paddingLeft !== "0px" ||
|
177 | resolved.paddingRight !== "0px" ||
|
178 | resolved.paddingTop !== "0px" ||
|
179 | resolved.paddingBottom !== "0px")
|
180 | console.error('Main div contains padding; graph will misbehave');
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 | if (div.style.width === '' && attrs.width) {
|
187 | div.style.width = attrs.width + "px";
|
188 | }
|
189 | if (div.style.height === '' && attrs.height) {
|
190 | div.style.height = attrs.height + "px";
|
191 | }
|
192 | if (div.style.height === '' && div.clientHeight === 0) {
|
193 | div.style.height = Dygraph.DEFAULT_HEIGHT + "px";
|
194 | if (div.style.width === '') {
|
195 | div.style.width = Dygraph.DEFAULT_WIDTH + "px";
|
196 | }
|
197 | }
|
198 |
|
199 |
|
200 |
|
201 | this.width_ = div.clientWidth || attrs.width || 0;
|
202 | this.height_ = div.clientHeight || attrs.height || 0;
|
203 |
|
204 |
|
205 | if (attrs.stackedGraph) {
|
206 | attrs.fillGraph = true;
|
207 |
|
208 | }
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 |
|
222 | this.user_attrs_ = {};
|
223 | utils.update(this.user_attrs_, attrs);
|
224 |
|
225 |
|
226 | this.attrs_ = {};
|
227 | utils.updateDeep(this.attrs_, DEFAULT_ATTRS);
|
228 |
|
229 | this.boundaryIds_ = [];
|
230 | this.setIndexByName_ = {};
|
231 | this.datasetIndex_ = [];
|
232 |
|
233 | this.registeredEvents_ = [];
|
234 | this.eventListeners_ = {};
|
235 |
|
236 | this.attributes_ = new DygraphOptions(this);
|
237 |
|
238 |
|
239 | this.createInterface_();
|
240 |
|
241 |
|
242 | this.plugins_ = [];
|
243 | var plugins = Dygraph.PLUGINS.concat(this.getOption('plugins'));
|
244 | for (var i = 0; i < plugins.length; i++) {
|
245 |
|
246 |
|
247 | var Plugin = plugins[i];
|
248 | var pluginInstance;
|
249 | if (typeof(Plugin.activate) !== 'undefined') {
|
250 | pluginInstance = Plugin;
|
251 | } else {
|
252 | pluginInstance = new Plugin();
|
253 | }
|
254 |
|
255 | var pluginDict = {
|
256 | plugin: pluginInstance,
|
257 | events: {},
|
258 | options: {},
|
259 | pluginOptions: {}
|
260 | };
|
261 |
|
262 | var handlers = pluginInstance.activate(this);
|
263 | for (var eventName in handlers) {
|
264 | if (!handlers.hasOwnProperty(eventName)) continue;
|
265 |
|
266 | pluginDict.events[eventName] = handlers[eventName];
|
267 | }
|
268 |
|
269 | this.plugins_.push(pluginDict);
|
270 | }
|
271 |
|
272 |
|
273 |
|
274 | for (var i = 0; i < this.plugins_.length; i++) {
|
275 | var plugin_dict = this.plugins_[i];
|
276 | for (var eventName in plugin_dict.events) {
|
277 | if (!plugin_dict.events.hasOwnProperty(eventName)) continue;
|
278 | var callback = plugin_dict.events[eventName];
|
279 |
|
280 | var pair = [plugin_dict.plugin, callback];
|
281 | if (!(eventName in this.eventListeners_)) {
|
282 | this.eventListeners_[eventName] = [pair];
|
283 | } else {
|
284 | this.eventListeners_[eventName].push(pair);
|
285 | }
|
286 | }
|
287 | }
|
288 |
|
289 | this.createDragInterface_();
|
290 |
|
291 | this.start_();
|
292 | };
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 | Dygraph.prototype.cascadeEvents_ = function(name, extra_props) {
|
301 | if (!(name in this.eventListeners_)) return false;
|
302 |
|
303 |
|
304 | var e = {
|
305 | dygraph: this,
|
306 | cancelable: false,
|
307 | defaultPrevented: false,
|
308 | preventDefault: function() {
|
309 | if (!e.cancelable) throw "Cannot call preventDefault on non-cancelable event.";
|
310 | e.defaultPrevented = true;
|
311 | },
|
312 | propagationStopped: false,
|
313 | stopPropagation: function() {
|
314 | e.propagationStopped = true;
|
315 | }
|
316 | };
|
317 | utils.update(e, extra_props);
|
318 |
|
319 | var callback_plugin_pairs = this.eventListeners_[name];
|
320 | if (callback_plugin_pairs) {
|
321 | for (var i = callback_plugin_pairs.length - 1; i >= 0; i--) {
|
322 | var plugin = callback_plugin_pairs[i][0];
|
323 | var callback = callback_plugin_pairs[i][1];
|
324 | callback.call(plugin, e);
|
325 | if (e.propagationStopped) break;
|
326 | }
|
327 | }
|
328 | return e.defaultPrevented;
|
329 | };
|
330 |
|
331 |
|
332 |
|
333 |
|
334 |
|
335 |
|
336 |
|
337 | Dygraph.prototype.getPluginInstance_ = function(type) {
|
338 | for (var i = 0; i < this.plugins_.length; i++) {
|
339 | var p = this.plugins_[i];
|
340 | if (p.plugin instanceof type) {
|
341 | return p.plugin;
|
342 | }
|
343 | }
|
344 | return null;
|
345 | };
|
346 |
|
347 |
|
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 |
|
354 |
|
355 |
|
356 | Dygraph.prototype.isZoomed = function(axis) {
|
357 | const isZoomedX = !!this.dateWindow_;
|
358 | if (axis === 'x') return isZoomedX;
|
359 |
|
360 | const isZoomedY = this.axes_.map(axis => !!axis.valueRange).indexOf(true) >= 0;
|
361 | if (axis === null || axis === undefined) {
|
362 | return isZoomedX || isZoomedY;
|
363 | }
|
364 | if (axis === 'y') return isZoomedY;
|
365 |
|
366 | throw new Error(`axis parameter is [${axis}] must be null, 'x' or 'y'.`);
|
367 | };
|
368 |
|
369 |
|
370 |
|
371 |
|
372 | Dygraph.prototype.toString = function() {
|
373 | var maindiv = this.maindiv_;
|
374 | var id = (maindiv && maindiv.id) ? maindiv.id : maindiv;
|
375 | return "[Dygraph " + id + "]";
|
376 | };
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 |
|
387 |
|
388 |
|
389 | Dygraph.prototype.attr_ = function(name, seriesName) {
|
390 | if (typeof process !== 'undefined' && process.env.NODE_ENV != 'production') {
|
391 |
|
392 | if (typeof(OPTIONS_REFERENCE) === 'undefined') {
|
393 | console.error('Must include options reference JS for testing');
|
394 | } else if (!OPTIONS_REFERENCE.hasOwnProperty(name)) {
|
395 | console.error('Dygraphs is using property ' + name + ', which has no ' +
|
396 | 'entry in the Dygraphs.OPTIONS_REFERENCE listing.');
|
397 |
|
398 | OPTIONS_REFERENCE[name] = true;
|
399 | }
|
400 | }
|
401 | return seriesName ? this.attributes_.getForSeries(name, seriesName) : this.attributes_.get(name);
|
402 | };
|
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 | Dygraph.prototype.getOption = function(name, opt_seriesName) {
|
419 | return this.attr_(name, opt_seriesName);
|
420 | };
|
421 |
|
422 |
|
423 |
|
424 |
|
425 |
|
426 |
|
427 |
|
428 |
|
429 |
|
430 | Dygraph.prototype.getNumericOption = function(name, opt_seriesName) {
|
431 | return (this.getOption(name, opt_seriesName));
|
432 | };
|
433 |
|
434 |
|
435 |
|
436 |
|
437 |
|
438 |
|
439 |
|
440 |
|
441 |
|
442 | Dygraph.prototype.getStringOption = function(name, opt_seriesName) {
|
443 | return (this.getOption(name, opt_seriesName));
|
444 | };
|
445 |
|
446 |
|
447 |
|
448 |
|
449 |
|
450 |
|
451 |
|
452 |
|
453 |
|
454 | Dygraph.prototype.getBooleanOption = function(name, opt_seriesName) {
|
455 | return (this.getOption(name, opt_seriesName));
|
456 | };
|
457 |
|
458 |
|
459 |
|
460 |
|
461 |
|
462 |
|
463 |
|
464 |
|
465 |
|
466 | Dygraph.prototype.getFunctionOption = function(name, opt_seriesName) {
|
467 | return (this.getOption(name, opt_seriesName));
|
468 | };
|
469 |
|
470 | Dygraph.prototype.getOptionForAxis = function(name, axis) {
|
471 | return this.attributes_.getForAxis(name, axis);
|
472 | };
|
473 |
|
474 |
|
475 |
|
476 |
|
477 |
|
478 |
|
479 | Dygraph.prototype.optionsViewForAxis_ = function(axis) {
|
480 | var self = this;
|
481 | return function(opt) {
|
482 | var axis_opts = self.user_attrs_.axes;
|
483 | if (axis_opts && axis_opts[axis] && axis_opts[axis].hasOwnProperty(opt)) {
|
484 | return axis_opts[axis][opt];
|
485 | }
|
486 |
|
487 |
|
488 | if (axis === 'x' && opt === 'logscale') {
|
489 |
|
490 |
|
491 | return false;
|
492 | }
|
493 |
|
494 |
|
495 |
|
496 | if (typeof(self.user_attrs_[opt]) != 'undefined') {
|
497 | return self.user_attrs_[opt];
|
498 | }
|
499 |
|
500 | axis_opts = self.attrs_.axes;
|
501 | if (axis_opts && axis_opts[axis] && axis_opts[axis].hasOwnProperty(opt)) {
|
502 | return axis_opts[axis][opt];
|
503 | }
|
504 |
|
505 |
|
506 | if (axis == 'y' && self.axes_[0].hasOwnProperty(opt)) {
|
507 | return self.axes_[0][opt];
|
508 | } else if (axis == 'y2' && self.axes_[1].hasOwnProperty(opt)) {
|
509 | return self.axes_[1][opt];
|
510 | }
|
511 | return self.attr_(opt);
|
512 | };
|
513 | };
|
514 |
|
515 |
|
516 |
|
517 |
|
518 |
|
519 | Dygraph.prototype.rollPeriod = function() {
|
520 | return this.rollPeriod_;
|
521 | };
|
522 |
|
523 |
|
524 |
|
525 |
|
526 |
|
527 |
|
528 |
|
529 | Dygraph.prototype.xAxisRange = function() {
|
530 | return this.dateWindow_ ? this.dateWindow_ : this.xAxisExtremes();
|
531 | };
|
532 |
|
533 |
|
534 |
|
535 |
|
536 | Dygraph.prototype.xAxisExtremes = function() {
|
537 | var pad = this.getNumericOption('xRangePad') / this.plotter_.area.w;
|
538 | if (this.numRows() === 0) {
|
539 | return [0 - pad, 1 + pad];
|
540 | }
|
541 | var left = this.rawData_[0][0];
|
542 | var right = this.rawData_[this.rawData_.length - 1][0];
|
543 | if (pad) {
|
544 |
|
545 | var range = right - left;
|
546 | left -= range * pad;
|
547 | right += range * pad;
|
548 | }
|
549 | return [left, right];
|
550 | };
|
551 |
|
552 |
|
553 |
|
554 |
|
555 |
|
556 |
|
557 | Dygraph.prototype.yAxisExtremes = function() {
|
558 |
|
559 | const packed = this.gatherDatasets_(this.rolledSeries_, null);
|
560 | const { extremes } = packed;
|
561 | const saveAxes = this.axes_;
|
562 | this.computeYAxisRanges_(extremes);
|
563 | const newAxes = this.axes_;
|
564 | this.axes_ = saveAxes;
|
565 | return newAxes.map(axis => axis.extremeRange);
|
566 | }
|
567 |
|
568 |
|
569 |
|
570 |
|
571 |
|
572 |
|
573 |
|
574 | Dygraph.prototype.yAxisRange = function(idx) {
|
575 | if (typeof(idx) == "undefined") idx = 0;
|
576 | if (idx < 0 || idx >= this.axes_.length) {
|
577 | return null;
|
578 | }
|
579 | var axis = this.axes_[idx];
|
580 | return [ axis.computedValueRange[0], axis.computedValueRange[1] ];
|
581 | };
|
582 |
|
583 |
|
584 |
|
585 |
|
586 |
|
587 |
|
588 | Dygraph.prototype.yAxisRanges = function() {
|
589 | var ret = [];
|
590 | for (var i = 0; i < this.axes_.length; i++) {
|
591 | ret.push(this.yAxisRange(i));
|
592 | }
|
593 | return ret;
|
594 | };
|
595 |
|
596 |
|
597 |
|
598 |
|
599 |
|
600 |
|
601 |
|
602 |
|
603 |
|
604 |
|
605 |
|
606 | Dygraph.prototype.toDomCoords = function(x, y, axis) {
|
607 | return [ this.toDomXCoord(x), this.toDomYCoord(y, axis) ];
|
608 | };
|
609 |
|
610 |
|
611 |
|
612 |
|
613 |
|
614 |
|
615 |
|
616 | Dygraph.prototype.toDomXCoord = function(x) {
|
617 | if (x === null) {
|
618 | return null;
|
619 | }
|
620 |
|
621 | var area = this.plotter_.area;
|
622 | var xRange = this.xAxisRange();
|
623 | return area.x + (x - xRange[0]) / (xRange[1] - xRange[0]) * area.w;
|
624 | };
|
625 |
|
626 |
|
627 |
|
628 |
|
629 |
|
630 |
|
631 |
|
632 | Dygraph.prototype.toDomYCoord = function(y, axis) {
|
633 | var pct = this.toPercentYCoord(y, axis);
|
634 |
|
635 | if (pct === null) {
|
636 | return null;
|
637 | }
|
638 | var area = this.plotter_.area;
|
639 | return area.y + pct * area.h;
|
640 | };
|
641 |
|
642 |
|
643 |
|
644 |
|
645 |
|
646 |
|
647 |
|
648 |
|
649 |
|
650 |
|
651 | Dygraph.prototype.toDataCoords = function(x, y, axis) {
|
652 | return [ this.toDataXCoord(x), this.toDataYCoord(y, axis) ];
|
653 | };
|
654 |
|
655 |
|
656 |
|
657 |
|
658 |
|
659 |
|
660 | Dygraph.prototype.toDataXCoord = function(x) {
|
661 | if (x === null) {
|
662 | return null;
|
663 | }
|
664 |
|
665 | var area = this.plotter_.area;
|
666 | var xRange = this.xAxisRange();
|
667 |
|
668 | if (!this.attributes_.getForAxis("logscale", 'x')) {
|
669 | return xRange[0] + (x - area.x) / area.w * (xRange[1] - xRange[0]);
|
670 | } else {
|
671 | var pct = (x - area.x) / area.w;
|
672 | return utils.logRangeFraction(xRange[0], xRange[1], pct);
|
673 | }
|
674 | };
|
675 |
|
676 |
|
677 |
|
678 |
|
679 |
|
680 |
|
681 |
|
682 | Dygraph.prototype.toDataYCoord = function(y, axis) {
|
683 | if (y === null) {
|
684 | return null;
|
685 | }
|
686 |
|
687 | var area = this.plotter_.area;
|
688 | var yRange = this.yAxisRange(axis);
|
689 |
|
690 | if (typeof(axis) == "undefined") axis = 0;
|
691 | if (!this.attributes_.getForAxis("logscale", axis)) {
|
692 | return yRange[0] + (area.y + area.h - y) / area.h * (yRange[1] - yRange[0]);
|
693 | } else {
|
694 |
|
695 | var pct = (y - area.y) / area.h;
|
696 |
|
697 | return utils.logRangeFraction(yRange[1], yRange[0], pct);
|
698 | }
|
699 | };
|
700 |
|
701 |
|
702 |
|
703 |
|
704 |
|
705 |
|
706 |
|
707 |
|
708 |
|
709 |
|
710 |
|
711 |
|
712 |
|
713 |
|
714 |
|
715 |
|
716 |
|
717 | Dygraph.prototype.toPercentYCoord = function(y, axis) {
|
718 | if (y === null) {
|
719 | return null;
|
720 | }
|
721 | if (typeof(axis) == "undefined") axis = 0;
|
722 |
|
723 | var yRange = this.yAxisRange(axis);
|
724 |
|
725 | var pct;
|
726 | var logscale = this.attributes_.getForAxis("logscale", axis);
|
727 | if (logscale) {
|
728 | var logr0 = utils.log10(yRange[0]);
|
729 | var logr1 = utils.log10(yRange[1]);
|
730 | pct = (logr1 - utils.log10(y)) / (logr1 - logr0);
|
731 | } else {
|
732 |
|
733 |
|
734 |
|
735 | pct = (yRange[1] - y) / (yRange[1] - yRange[0]);
|
736 | }
|
737 | return pct;
|
738 | };
|
739 |
|
740 |
|
741 |
|
742 |
|
743 |
|
744 |
|
745 |
|
746 |
|
747 |
|
748 |
|
749 |
|
750 |
|
751 |
|
752 |
|
753 | Dygraph.prototype.toPercentXCoord = function(x) {
|
754 | if (x === null) {
|
755 | return null;
|
756 | }
|
757 |
|
758 | var xRange = this.xAxisRange();
|
759 | var pct;
|
760 | var logscale = this.attributes_.getForAxis("logscale", 'x') ;
|
761 | if (logscale === true) {
|
762 | var logr0 = utils.log10(xRange[0]);
|
763 | var logr1 = utils.log10(xRange[1]);
|
764 | pct = (utils.log10(x) - logr0) / (logr1 - logr0);
|
765 | } else {
|
766 |
|
767 |
|
768 |
|
769 | pct = (x - xRange[0]) / (xRange[1] - xRange[0]);
|
770 | }
|
771 | return pct;
|
772 | };
|
773 |
|
774 |
|
775 |
|
776 |
|
777 |
|
778 | Dygraph.prototype.numColumns = function() {
|
779 | if (!this.rawData_) return 0;
|
780 | return this.rawData_[0] ? this.rawData_[0].length : this.attr_("labels").length;
|
781 | };
|
782 |
|
783 |
|
784 |
|
785 |
|
786 |
|
787 | Dygraph.prototype.numRows = function() {
|
788 | if (!this.rawData_) return 0;
|
789 | return this.rawData_.length;
|
790 | };
|
791 |
|
792 |
|
793 |
|
794 |
|
795 |
|
796 |
|
797 |
|
798 |
|
799 |
|
800 |
|
801 |
|
802 | Dygraph.prototype.getValue = function(row, col) {
|
803 | if (row < 0 || row >= this.rawData_.length) return null;
|
804 | if (col < 0 || col >= this.rawData_[row].length) return null;
|
805 |
|
806 | return this.rawData_[row][col];
|
807 | };
|
808 |
|
809 |
|
810 |
|
811 |
|
812 |
|
813 |
|
814 |
|
815 | Dygraph.prototype.createInterface_ = function() {
|
816 |
|
817 | var enclosing = this.maindiv_;
|
818 |
|
819 | this.graphDiv = document.createElement("div");
|
820 |
|
821 |
|
822 | this.graphDiv.style.textAlign = 'left';
|
823 | this.graphDiv.style.position = 'relative';
|
824 | enclosing.appendChild(this.graphDiv);
|
825 |
|
826 |
|
827 | this.canvas_ = utils.createCanvas();
|
828 | this.canvas_.style.position = "absolute";
|
829 | this.canvas_.style.top = 0;
|
830 | this.canvas_.style.left = 0;
|
831 |
|
832 |
|
833 | this.hidden_ = this.createPlotKitCanvas_(this.canvas_);
|
834 |
|
835 | this.canvas_ctx_ = utils.getContext(this.canvas_);
|
836 | this.hidden_ctx_ = utils.getContext(this.hidden_);
|
837 |
|
838 | this.resizeElements_();
|
839 |
|
840 |
|
841 | this.graphDiv.appendChild(this.hidden_);
|
842 | this.graphDiv.appendChild(this.canvas_);
|
843 | this.mouseEventElement_ = this.createMouseEventElement_();
|
844 |
|
845 |
|
846 | this.layout_ = new DygraphLayout(this);
|
847 |
|
848 | var dygraph = this;
|
849 |
|
850 | this.mouseMoveHandler_ = function(e) {
|
851 | dygraph.mouseMove_(e);
|
852 | };
|
853 |
|
854 | this.mouseOutHandler_ = function(e) {
|
855 |
|
856 |
|
857 |
|
858 | var target = e.target || e.fromElement;
|
859 | var relatedTarget = e.relatedTarget || e.toElement;
|
860 | if (utils.isNodeContainedBy(target, dygraph.graphDiv) &&
|
861 | !utils.isNodeContainedBy(relatedTarget, dygraph.graphDiv)) {
|
862 | dygraph.mouseOut_(e);
|
863 | }
|
864 | };
|
865 |
|
866 | this.addAndTrackEvent(window, 'mouseout', this.mouseOutHandler_);
|
867 | this.addAndTrackEvent(this.mouseEventElement_, 'mousemove', this.mouseMoveHandler_);
|
868 |
|
869 |
|
870 |
|
871 | if (!this.resizeHandler_) {
|
872 | this.resizeHandler_ = function(e) {
|
873 | dygraph.resize();
|
874 | };
|
875 |
|
876 |
|
877 |
|
878 | this.addAndTrackEvent(window, 'resize', this.resizeHandler_);
|
879 |
|
880 | this.resizeObserver_ = null;
|
881 | var resizeMode = this.getStringOption('resizable');
|
882 | if ((typeof(ResizeObserver) === 'undefined') &&
|
883 | (resizeMode !== "no")) {
|
884 | console.error('ResizeObserver unavailable; ignoring resizable property');
|
885 | resizeMode = "no";
|
886 | }
|
887 | if (resizeMode === "horizontal" ||
|
888 | resizeMode === "vertical" ||
|
889 | resizeMode === "both") {
|
890 | enclosing.style.resize = resizeMode;
|
891 | } else if (resizeMode !== "passive") {
|
892 | resizeMode = "no";
|
893 | }
|
894 | if (resizeMode !== "no") {
|
895 | const maindivOverflow = window.getComputedStyle(enclosing).overflow;
|
896 | if (window.getComputedStyle(enclosing).overflow === 'visible')
|
897 | enclosing.style.overflow = 'hidden';
|
898 | this.resizeObserver_ = new ResizeObserver(this.resizeHandler_);
|
899 | this.resizeObserver_.observe(enclosing);
|
900 | }
|
901 | }
|
902 | };
|
903 |
|
904 | Dygraph.prototype.resizeElements_ = function() {
|
905 | this.graphDiv.style.width = this.width_ + "px";
|
906 | this.graphDiv.style.height = this.height_ + "px";
|
907 |
|
908 | var pixelRatioOption = this.getNumericOption('pixelRatio')
|
909 |
|
910 | var canvasScale = pixelRatioOption || utils.getContextPixelRatio(this.canvas_ctx_);
|
911 | this.canvas_.width = this.width_ * canvasScale;
|
912 | this.canvas_.height = this.height_ * canvasScale;
|
913 | this.canvas_.style.width = this.width_ + "px";
|
914 | this.canvas_.style.height = this.height_ + "px";
|
915 | if (canvasScale !== 1) {
|
916 | this.canvas_ctx_.scale(canvasScale, canvasScale);
|
917 | }
|
918 |
|
919 | var hiddenScale = pixelRatioOption || utils.getContextPixelRatio(this.hidden_ctx_);
|
920 | this.hidden_.width = this.width_ * hiddenScale;
|
921 | this.hidden_.height = this.height_ * hiddenScale;
|
922 | this.hidden_.style.width = this.width_ + "px";
|
923 | this.hidden_.style.height = this.height_ + "px";
|
924 | if (hiddenScale !== 1) {
|
925 | this.hidden_ctx_.scale(hiddenScale, hiddenScale);
|
926 | }
|
927 | };
|
928 |
|
929 |
|
930 |
|
931 |
|
932 |
|
933 |
|
934 | Dygraph.prototype.destroy = function() {
|
935 | this.canvas_ctx_.restore();
|
936 | this.hidden_ctx_.restore();
|
937 |
|
938 |
|
939 | for (var i = this.plugins_.length - 1; i >= 0; i--) {
|
940 | var p = this.plugins_.pop();
|
941 | if (p.plugin.destroy) p.plugin.destroy();
|
942 | }
|
943 |
|
944 | var removeRecursive = function(node) {
|
945 | while (node.hasChildNodes()) {
|
946 | removeRecursive(node.firstChild);
|
947 | node.removeChild(node.firstChild);
|
948 | }
|
949 | };
|
950 |
|
951 | this.removeTrackedEvents_();
|
952 |
|
953 |
|
954 | utils.removeEvent(window, 'mouseout', this.mouseOutHandler_);
|
955 | utils.removeEvent(this.mouseEventElement_, 'mousemove', this.mouseMoveHandler_);
|
956 |
|
957 |
|
958 | if (this.resizeObserver_) {
|
959 | this.resizeObserver_.disconnect();
|
960 | this.resizeObserver_ = null;
|
961 | }
|
962 | utils.removeEvent(window, 'resize', this.resizeHandler_);
|
963 | this.resizeHandler_ = null;
|
964 |
|
965 | removeRecursive(this.maindiv_);
|
966 |
|
967 | var nullOut = function nullOut(obj) {
|
968 | for (var n in obj) {
|
969 | if (typeof(obj[n]) === 'object') {
|
970 | obj[n] = null;
|
971 | }
|
972 | }
|
973 | };
|
974 |
|
975 | nullOut(this.layout_);
|
976 | nullOut(this.plotter_);
|
977 | nullOut(this);
|
978 | };
|
979 |
|
980 |
|
981 |
|
982 |
|
983 |
|
984 |
|
985 |
|
986 |
|
987 |
|
988 | Dygraph.prototype.createPlotKitCanvas_ = function(canvas) {
|
989 | var h = utils.createCanvas();
|
990 | h.style.position = "absolute";
|
991 |
|
992 |
|
993 |
|
994 | h.style.top = canvas.style.top;
|
995 | h.style.left = canvas.style.left;
|
996 | h.width = this.width_;
|
997 | h.height = this.height_;
|
998 | h.style.width = this.width_ + "px";
|
999 | h.style.height = this.height_ + "px";
|
1000 | return h;
|
1001 | };
|
1002 |
|
1003 |
|
1004 |
|
1005 |
|
1006 |
|
1007 |
|
1008 | Dygraph.prototype.createMouseEventElement_ = function() {
|
1009 | return this.canvas_;
|
1010 | };
|
1011 |
|
1012 |
|
1013 |
|
1014 |
|
1015 |
|
1016 |
|
1017 |
|
1018 |
|
1019 | Dygraph.prototype.setColors_ = function() {
|
1020 | var labels = this.getLabels();
|
1021 | var num = labels.length - 1;
|
1022 | this.colors_ = [];
|
1023 | this.colorsMap_ = {};
|
1024 |
|
1025 |
|
1026 | var sat = this.getNumericOption('colorSaturation') || 1.0;
|
1027 | var val = this.getNumericOption('colorValue') || 0.5;
|
1028 | var half = Math.ceil(num / 2);
|
1029 |
|
1030 | var colors = this.getOption('colors');
|
1031 | var visibility = this.visibility();
|
1032 | for (var i = 0; i < num; i++) {
|
1033 | if (!visibility[i]) {
|
1034 | continue;
|
1035 | }
|
1036 | var label = labels[i + 1];
|
1037 | var colorStr = this.attributes_.getForSeries('color', label);
|
1038 | if (!colorStr) {
|
1039 | if (colors) {
|
1040 | colorStr = colors[i % colors.length];
|
1041 | } else {
|
1042 |
|
1043 | var idx = i % 2 ? (half + (i + 1)/ 2) : Math.ceil((i + 1) / 2);
|
1044 | var hue = (1.0 * idx / (1 + num));
|
1045 | colorStr = utils.hsvToRGB(hue, sat, val);
|
1046 | }
|
1047 | }
|
1048 | this.colors_.push(colorStr);
|
1049 | this.colorsMap_[label] = colorStr;
|
1050 | }
|
1051 | };
|
1052 |
|
1053 |
|
1054 |
|
1055 |
|
1056 |
|
1057 |
|
1058 |
|
1059 | Dygraph.prototype.getColors = function() {
|
1060 | return this.colors_;
|
1061 | };
|
1062 |
|
1063 |
|
1064 |
|
1065 |
|
1066 |
|
1067 |
|
1068 |
|
1069 |
|
1070 |
|
1071 |
|
1072 | Dygraph.prototype.getPropertiesForSeries = function(series_name) {
|
1073 | var idx = -1;
|
1074 | var labels = this.getLabels();
|
1075 | for (var i = 1; i < labels.length; i++) {
|
1076 | if (labels[i] == series_name) {
|
1077 | idx = i;
|
1078 | break;
|
1079 | }
|
1080 | }
|
1081 | if (idx == -1) return null;
|
1082 |
|
1083 | return {
|
1084 | name: series_name,
|
1085 | column: idx,
|
1086 | visible: this.visibility()[idx - 1],
|
1087 | color: this.colorsMap_[series_name],
|
1088 | axis: 1 + this.attributes_.axisForSeries(series_name)
|
1089 | };
|
1090 | };
|
1091 |
|
1092 |
|
1093 |
|
1094 |
|
1095 |
|
1096 | Dygraph.prototype.createRollInterface_ = function() {
|
1097 |
|
1098 | var roller = this.roller_;
|
1099 | if (!roller) {
|
1100 | this.roller_ = roller = document.createElement("input");
|
1101 | roller.type = "text";
|
1102 | roller.style.display = "none";
|
1103 | roller.className = 'dygraph-roller';
|
1104 | this.graphDiv.appendChild(roller);
|
1105 | }
|
1106 |
|
1107 | var display = this.getBooleanOption('showRoller') ? 'block' : 'none';
|
1108 |
|
1109 | var area = this.getArea();
|
1110 | var textAttr = {
|
1111 | "top": (area.y + area.h - 25) + "px",
|
1112 | "left": (area.x + 1) + "px",
|
1113 | "display": display
|
1114 | };
|
1115 | roller.size = "2";
|
1116 | roller.value = this.rollPeriod_;
|
1117 | utils.update(roller.style, textAttr);
|
1118 |
|
1119 | const that = this;
|
1120 | roller.onchange = function onchange() {
|
1121 | return that.adjustRoll(roller.value);
|
1122 | };
|
1123 | };
|
1124 |
|
1125 |
|
1126 |
|
1127 |
|
1128 |
|
1129 |
|
1130 | Dygraph.prototype.createDragInterface_ = function() {
|
1131 | var context = {
|
1132 |
|
1133 | isZooming: false,
|
1134 | isPanning: false,
|
1135 | is2DPan: false,
|
1136 | dragStartX: null,
|
1137 | dragStartY: null,
|
1138 | dragEndX: null,
|
1139 | dragEndY: null,
|
1140 | dragDirection: null,
|
1141 | prevEndX: null,
|
1142 | prevEndY: null,
|
1143 | prevDragDirection: null,
|
1144 | cancelNextDblclick: false,
|
1145 |
|
1146 |
|
1147 | initialLeftmostDate: null,
|
1148 |
|
1149 |
|
1150 |
|
1151 | xUnitsPerPixel: null,
|
1152 |
|
1153 |
|
1154 |
|
1155 |
|
1156 | dateRange: null,
|
1157 |
|
1158 |
|
1159 |
|
1160 | px: 0,
|
1161 | py: 0,
|
1162 |
|
1163 |
|
1164 |
|
1165 | boundedDates: null,
|
1166 | boundedValues: null,
|
1167 |
|
1168 |
|
1169 |
|
1170 | tarp: new IFrameTarp(),
|
1171 |
|
1172 |
|
1173 | initializeMouseDown: function(event, g, contextB) {
|
1174 |
|
1175 | if (event.preventDefault) {
|
1176 | event.preventDefault();
|
1177 | } else {
|
1178 | event.returnValue = false;
|
1179 | event.cancelBubble = true;
|
1180 | }
|
1181 |
|
1182 | var canvasPos = utils.findPos(g.canvas_);
|
1183 | contextB.px = canvasPos.x;
|
1184 | contextB.py = canvasPos.y;
|
1185 | contextB.dragStartX = utils.dragGetX_(event, contextB);
|
1186 | contextB.dragStartY = utils.dragGetY_(event, contextB);
|
1187 | contextB.cancelNextDblclick = false;
|
1188 | contextB.tarp.cover();
|
1189 | },
|
1190 | destroy: function() {
|
1191 | var context = this;
|
1192 | if (context.isZooming || context.isPanning) {
|
1193 | context.isZooming = false;
|
1194 | context.dragStartX = null;
|
1195 | context.dragStartY = null;
|
1196 | }
|
1197 |
|
1198 | if (context.isPanning) {
|
1199 | context.isPanning = false;
|
1200 | context.draggingDate = null;
|
1201 | context.dateRange = null;
|
1202 | for (var i = 0; i < self.axes_.length; i++) {
|
1203 | delete self.axes_[i].draggingValue;
|
1204 | delete self.axes_[i].dragValueRange;
|
1205 | }
|
1206 | }
|
1207 |
|
1208 | context.tarp.uncover();
|
1209 | }
|
1210 | };
|
1211 |
|
1212 | var interactionModel = this.getOption("interactionModel");
|
1213 |
|
1214 |
|
1215 | var self = this;
|
1216 |
|
1217 |
|
1218 | var bindHandler = function(handler) {
|
1219 | return function(event) {
|
1220 | handler(event, self, context);
|
1221 | };
|
1222 | };
|
1223 |
|
1224 | for (var eventName in interactionModel) {
|
1225 | if (!interactionModel.hasOwnProperty(eventName)) continue;
|
1226 | this.addAndTrackEvent(this.mouseEventElement_, eventName,
|
1227 | bindHandler(interactionModel[eventName]));
|
1228 | }
|
1229 |
|
1230 |
|
1231 |
|
1232 | if (!interactionModel.willDestroyContextMyself) {
|
1233 | var mouseUpHandler = function(event) {
|
1234 | context.destroy();
|
1235 | };
|
1236 |
|
1237 | this.addAndTrackEvent(document, 'mouseup', mouseUpHandler);
|
1238 | }
|
1239 | };
|
1240 |
|
1241 |
|
1242 |
|
1243 |
|
1244 |
|
1245 |
|
1246 |
|
1247 |
|
1248 |
|
1249 |
|
1250 |
|
1251 |
|
1252 |
|
1253 |
|
1254 |
|
1255 |
|
1256 |
|
1257 |
|
1258 |
|
1259 |
|
1260 |
|
1261 |
|
1262 |
|
1263 | Dygraph.prototype.drawZoomRect_ = function(direction, startX, endX, startY,
|
1264 | endY, prevDirection, prevEndX,
|
1265 | prevEndY) {
|
1266 | var ctx = this.canvas_ctx_;
|
1267 |
|
1268 |
|
1269 | if (prevDirection == utils.HORIZONTAL) {
|
1270 | ctx.clearRect(Math.min(startX, prevEndX), this.layout_.getPlotArea().y,
|
1271 | Math.abs(startX - prevEndX), this.layout_.getPlotArea().h);
|
1272 | } else if (prevDirection == utils.VERTICAL) {
|
1273 | ctx.clearRect(this.layout_.getPlotArea().x, Math.min(startY, prevEndY),
|
1274 | this.layout_.getPlotArea().w, Math.abs(startY - prevEndY));
|
1275 | }
|
1276 |
|
1277 |
|
1278 | if (direction == utils.HORIZONTAL) {
|
1279 | if (endX && startX) {
|
1280 | ctx.fillStyle = "rgba(128,128,128,0.33)";
|
1281 | ctx.fillRect(Math.min(startX, endX), this.layout_.getPlotArea().y,
|
1282 | Math.abs(endX - startX), this.layout_.getPlotArea().h);
|
1283 | }
|
1284 | } else if (direction == utils.VERTICAL) {
|
1285 | if (endY && startY) {
|
1286 | ctx.fillStyle = "rgba(128,128,128,0.33)";
|
1287 | ctx.fillRect(this.layout_.getPlotArea().x, Math.min(startY, endY),
|
1288 | this.layout_.getPlotArea().w, Math.abs(endY - startY));
|
1289 | }
|
1290 | }
|
1291 | };
|
1292 |
|
1293 |
|
1294 |
|
1295 |
|
1296 |
|
1297 | Dygraph.prototype.clearZoomRect_ = function() {
|
1298 | this.currentZoomRectArgs_ = null;
|
1299 | this.canvas_ctx_.clearRect(0, 0, this.width_, this.height_);
|
1300 | };
|
1301 |
|
1302 |
|
1303 |
|
1304 |
|
1305 |
|
1306 |
|
1307 |
|
1308 |
|
1309 |
|
1310 |
|
1311 |
|
1312 | Dygraph.prototype.doZoomX_ = function(lowX, highX) {
|
1313 | this.currentZoomRectArgs_ = null;
|
1314 |
|
1315 |
|
1316 | var minDate = this.toDataXCoord(lowX);
|
1317 | var maxDate = this.toDataXCoord(highX);
|
1318 | this.doZoomXDates_(minDate, maxDate);
|
1319 | };
|
1320 |
|
1321 |
|
1322 |
|
1323 |
|
1324 |
|
1325 |
|
1326 |
|
1327 |
|
1328 |
|
1329 |
|
1330 | Dygraph.prototype.doZoomXDates_ = function(minDate, maxDate) {
|
1331 |
|
1332 |
|
1333 |
|
1334 | var old_window = this.xAxisRange();
|
1335 | var new_window = [minDate, maxDate];
|
1336 | const zoomCallback = this.getFunctionOption('zoomCallback');
|
1337 | const that = this;
|
1338 | this.doAnimatedZoom(old_window, new_window, null, null, function animatedZoomCallback() {
|
1339 | if (zoomCallback) {
|
1340 | zoomCallback.call(that, minDate, maxDate, that.yAxisRanges());
|
1341 | }
|
1342 | });
|
1343 | };
|
1344 |
|
1345 |
|
1346 |
|
1347 |
|
1348 |
|
1349 |
|
1350 |
|
1351 |
|
1352 |
|
1353 | Dygraph.prototype.doZoomY_ = function(lowY, highY) {
|
1354 | this.currentZoomRectArgs_ = null;
|
1355 |
|
1356 |
|
1357 |
|
1358 |
|
1359 | var oldValueRanges = this.yAxisRanges();
|
1360 | var newValueRanges = [];
|
1361 | for (var i = 0; i < this.axes_.length; i++) {
|
1362 | var hi = this.toDataYCoord(lowY, i);
|
1363 | var low = this.toDataYCoord(highY, i);
|
1364 | newValueRanges.push([low, hi]);
|
1365 | }
|
1366 |
|
1367 | const zoomCallback = this.getFunctionOption('zoomCallback');
|
1368 | const that = this;
|
1369 | this.doAnimatedZoom(null, null, oldValueRanges, newValueRanges, function animatedZoomCallback() {
|
1370 | if (zoomCallback) {
|
1371 | const [minX, maxX] = that.xAxisRange();
|
1372 | zoomCallback.call(that, minX, maxX, that.yAxisRanges());
|
1373 | }
|
1374 | });
|
1375 | };
|
1376 |
|
1377 |
|
1378 |
|
1379 |
|
1380 |
|
1381 |
|
1382 | Dygraph.zoomAnimationFunction = function(frame, numFrames) {
|
1383 | var k = 1.5;
|
1384 | return (1.0 - Math.pow(k, -frame)) / (1.0 - Math.pow(k, -numFrames));
|
1385 | };
|
1386 |
|
1387 |
|
1388 |
|
1389 |
|
1390 |
|
1391 | Dygraph.prototype.resetZoom = function() {
|
1392 | const dirtyX = this.isZoomed('x');
|
1393 | const dirtyY = this.isZoomed('y');
|
1394 | const dirty = dirtyX || dirtyY;
|
1395 |
|
1396 |
|
1397 | this.clearSelection();
|
1398 |
|
1399 | if (!dirty) return;
|
1400 |
|
1401 |
|
1402 | const [minDate, maxDate] = this.xAxisExtremes();
|
1403 |
|
1404 | const animatedZooms = this.getBooleanOption('animatedZooms');
|
1405 | const zoomCallback = this.getFunctionOption('zoomCallback');
|
1406 |
|
1407 |
|
1408 |
|
1409 | if (!animatedZooms) {
|
1410 | this.dateWindow_ = null;
|
1411 | this.axes_.forEach(axis => {
|
1412 | if (axis.valueRange) delete axis.valueRange;
|
1413 | });
|
1414 |
|
1415 | this.drawGraph_();
|
1416 | if (zoomCallback) {
|
1417 | zoomCallback.call(this, minDate, maxDate, this.yAxisRanges());
|
1418 | }
|
1419 | return;
|
1420 | }
|
1421 |
|
1422 | var oldWindow=null, newWindow=null, oldValueRanges=null, newValueRanges=null;
|
1423 | if (dirtyX) {
|
1424 | oldWindow = this.xAxisRange();
|
1425 | newWindow = [minDate, maxDate];
|
1426 | }
|
1427 |
|
1428 | if (dirtyY) {
|
1429 | oldValueRanges = this.yAxisRanges();
|
1430 | newValueRanges = this.yAxisExtremes();
|
1431 | }
|
1432 |
|
1433 | const that = this;
|
1434 | this.doAnimatedZoom(oldWindow, newWindow, oldValueRanges, newValueRanges,
|
1435 | function animatedZoomCallback() {
|
1436 | that.dateWindow_ = null;
|
1437 | that.axes_.forEach(axis => {
|
1438 | if (axis.valueRange) delete axis.valueRange;
|
1439 | });
|
1440 | if (zoomCallback) {
|
1441 | zoomCallback.call(that, minDate, maxDate, that.yAxisRanges());
|
1442 | }
|
1443 | });
|
1444 | };
|
1445 |
|
1446 |
|
1447 |
|
1448 |
|
1449 |
|
1450 |
|
1451 | Dygraph.prototype.doAnimatedZoom = function(oldXRange, newXRange, oldYRanges, newYRanges, callback) {
|
1452 | var steps = this.getBooleanOption("animatedZooms") ?
|
1453 | Dygraph.ANIMATION_STEPS : 1;
|
1454 |
|
1455 | var windows = [];
|
1456 | var valueRanges = [];
|
1457 | var step, frac;
|
1458 |
|
1459 | if (oldXRange !== null && newXRange !== null) {
|
1460 | for (step = 1; step <= steps; step++) {
|
1461 | frac = Dygraph.zoomAnimationFunction(step, steps);
|
1462 | windows[step-1] = [oldXRange[0]*(1-frac) + frac*newXRange[0],
|
1463 | oldXRange[1]*(1-frac) + frac*newXRange[1]];
|
1464 | }
|
1465 | }
|
1466 |
|
1467 | if (oldYRanges !== null && newYRanges !== null) {
|
1468 | for (step = 1; step <= steps; step++) {
|
1469 | frac = Dygraph.zoomAnimationFunction(step, steps);
|
1470 | var thisRange = [];
|
1471 | for (var j = 0; j < this.axes_.length; j++) {
|
1472 | thisRange.push([oldYRanges[j][0]*(1-frac) + frac*newYRanges[j][0],
|
1473 | oldYRanges[j][1]*(1-frac) + frac*newYRanges[j][1]]);
|
1474 | }
|
1475 | valueRanges[step-1] = thisRange;
|
1476 | }
|
1477 | }
|
1478 |
|
1479 | const that = this;
|
1480 | utils.repeatAndCleanup(function (step) {
|
1481 | if (valueRanges.length) {
|
1482 | for (var i = 0; i < that.axes_.length; i++) {
|
1483 | var w = valueRanges[step][i];
|
1484 | that.axes_[i].valueRange = [w[0], w[1]];
|
1485 | }
|
1486 | }
|
1487 | if (windows.length) {
|
1488 | that.dateWindow_ = windows[step];
|
1489 | }
|
1490 | that.drawGraph_();
|
1491 | }, steps, Dygraph.ANIMATION_DURATION / steps, callback);
|
1492 | };
|
1493 |
|
1494 |
|
1495 |
|
1496 |
|
1497 |
|
1498 |
|
1499 | Dygraph.prototype.getArea = function() {
|
1500 | return this.plotter_.area;
|
1501 | };
|
1502 |
|
1503 |
|
1504 |
|
1505 |
|
1506 |
|
1507 |
|
1508 | Dygraph.prototype.eventToDomCoords = function(event) {
|
1509 | if (event.offsetX && event.offsetY) {
|
1510 | return [ event.offsetX, event.offsetY ];
|
1511 | } else {
|
1512 | var eventElementPos = utils.findPos(this.mouseEventElement_);
|
1513 | var canvasx = utils.pageX(event) - eventElementPos.x;
|
1514 | var canvasy = utils.pageY(event) - eventElementPos.y;
|
1515 | return [canvasx, canvasy];
|
1516 | }
|
1517 | };
|
1518 |
|
1519 |
|
1520 |
|
1521 |
|
1522 |
|
1523 |
|
1524 |
|
1525 | Dygraph.prototype.findClosestRow = function(domX) {
|
1526 | var minDistX = Infinity;
|
1527 | var closestRow = -1;
|
1528 | var sets = this.layout_.points;
|
1529 | for (var i = 0; i < sets.length; i++) {
|
1530 | var points = sets[i];
|
1531 | var len = points.length;
|
1532 | for (var j = 0; j < len; j++) {
|
1533 | var point = points[j];
|
1534 | if (!utils.isValidPoint(point, true)) continue;
|
1535 | var dist = Math.abs(point.canvasx - domX);
|
1536 | if (dist < minDistX) {
|
1537 | minDistX = dist;
|
1538 | closestRow = point.idx;
|
1539 | }
|
1540 | }
|
1541 | }
|
1542 |
|
1543 | return closestRow;
|
1544 | };
|
1545 |
|
1546 |
|
1547 |
|
1548 |
|
1549 |
|
1550 |
|
1551 |
|
1552 |
|
1553 |
|
1554 |
|
1555 |
|
1556 |
|
1557 |
|
1558 | Dygraph.prototype.findClosestPoint = function(domX, domY) {
|
1559 | var minDist = Infinity;
|
1560 | var dist, dx, dy, point, closestPoint, closestSeries, closestRow;
|
1561 | for ( var setIdx = this.layout_.points.length - 1 ; setIdx >= 0 ; --setIdx ) {
|
1562 | var points = this.layout_.points[setIdx];
|
1563 | for (var i = 0; i < points.length; ++i) {
|
1564 | point = points[i];
|
1565 | if (!utils.isValidPoint(point)) continue;
|
1566 | dx = point.canvasx - domX;
|
1567 | dy = point.canvasy - domY;
|
1568 | dist = dx * dx + dy * dy;
|
1569 | if (dist < minDist) {
|
1570 | minDist = dist;
|
1571 | closestPoint = point;
|
1572 | closestSeries = setIdx;
|
1573 | closestRow = point.idx;
|
1574 | }
|
1575 | }
|
1576 | }
|
1577 | var name = this.layout_.setNames[closestSeries];
|
1578 | return {
|
1579 | row: closestRow,
|
1580 | seriesName: name,
|
1581 | point: closestPoint
|
1582 | };
|
1583 | };
|
1584 |
|
1585 |
|
1586 |
|
1587 |
|
1588 |
|
1589 |
|
1590 |
|
1591 |
|
1592 |
|
1593 |
|
1594 |
|
1595 |
|
1596 |
|
1597 | Dygraph.prototype.findStackedPoint = function(domX, domY) {
|
1598 | var row = this.findClosestRow(domX);
|
1599 | var closestPoint, closestSeries;
|
1600 | for (var setIdx = 0; setIdx < this.layout_.points.length; ++setIdx) {
|
1601 | var boundary = this.getLeftBoundary_(setIdx);
|
1602 | var rowIdx = row - boundary;
|
1603 | var points = this.layout_.points[setIdx];
|
1604 | if (rowIdx >= points.length) continue;
|
1605 | var p1 = points[rowIdx];
|
1606 | if (!utils.isValidPoint(p1)) continue;
|
1607 | var py = p1.canvasy;
|
1608 | if (domX > p1.canvasx && rowIdx + 1 < points.length) {
|
1609 |
|
1610 | var p2 = points[rowIdx + 1];
|
1611 | if (utils.isValidPoint(p2)) {
|
1612 | var dx = p2.canvasx - p1.canvasx;
|
1613 | if (dx > 0) {
|
1614 | var r = (domX - p1.canvasx) / dx;
|
1615 | py += r * (p2.canvasy - p1.canvasy);
|
1616 | }
|
1617 | }
|
1618 | } else if (domX < p1.canvasx && rowIdx > 0) {
|
1619 |
|
1620 | var p0 = points[rowIdx - 1];
|
1621 | if (utils.isValidPoint(p0)) {
|
1622 | var dx = p1.canvasx - p0.canvasx;
|
1623 | if (dx > 0) {
|
1624 | var r = (p1.canvasx - domX) / dx;
|
1625 | py += r * (p0.canvasy - p1.canvasy);
|
1626 | }
|
1627 | }
|
1628 | }
|
1629 |
|
1630 | if (setIdx === 0 || py < domY) {
|
1631 | closestPoint = p1;
|
1632 | closestSeries = setIdx;
|
1633 | }
|
1634 | }
|
1635 | var name = this.layout_.setNames[closestSeries];
|
1636 | return {
|
1637 | row: row,
|
1638 | seriesName: name,
|
1639 | point: closestPoint
|
1640 | };
|
1641 | };
|
1642 |
|
1643 |
|
1644 |
|
1645 |
|
1646 |
|
1647 |
|
1648 |
|
1649 |
|
1650 | Dygraph.prototype.mouseMove_ = function(event) {
|
1651 |
|
1652 | var points = this.layout_.points;
|
1653 | if (points === undefined || points === null) return;
|
1654 |
|
1655 | var canvasCoords = this.eventToDomCoords(event);
|
1656 | var canvasx = canvasCoords[0];
|
1657 | var canvasy = canvasCoords[1];
|
1658 |
|
1659 | var highlightSeriesOpts = this.getOption("highlightSeriesOpts");
|
1660 | var selectionChanged = false;
|
1661 | if (highlightSeriesOpts && !this.isSeriesLocked()) {
|
1662 | var closest;
|
1663 | if (this.getBooleanOption("stackedGraph")) {
|
1664 | closest = this.findStackedPoint(canvasx, canvasy);
|
1665 | } else {
|
1666 | closest = this.findClosestPoint(canvasx, canvasy);
|
1667 | }
|
1668 | selectionChanged = this.setSelection(closest.row, closest.seriesName);
|
1669 | } else {
|
1670 | var idx = this.findClosestRow(canvasx);
|
1671 | selectionChanged = this.setSelection(idx);
|
1672 | }
|
1673 |
|
1674 | var callback = this.getFunctionOption("highlightCallback");
|
1675 | if (callback && selectionChanged) {
|
1676 | callback.call(this, event,
|
1677 | this.lastx_,
|
1678 | this.selPoints_,
|
1679 | this.lastRow_,
|
1680 | this.highlightSet_);
|
1681 | }
|
1682 | };
|
1683 |
|
1684 |
|
1685 |
|
1686 |
|
1687 |
|
1688 |
|
1689 | Dygraph.prototype.getLeftBoundary_ = function(setIdx) {
|
1690 | if (this.boundaryIds_[setIdx]) {
|
1691 | return this.boundaryIds_[setIdx][0];
|
1692 | } else {
|
1693 | for (var i = 0; i < this.boundaryIds_.length; i++) {
|
1694 | if (this.boundaryIds_[i] !== undefined) {
|
1695 | return this.boundaryIds_[i][0];
|
1696 | }
|
1697 | }
|
1698 | return 0;
|
1699 | }
|
1700 | };
|
1701 |
|
1702 | Dygraph.prototype.animateSelection_ = function(direction) {
|
1703 | var totalSteps = 10;
|
1704 | var millis = 30;
|
1705 | if (this.fadeLevel === undefined) this.fadeLevel = 0;
|
1706 | if (this.animateId === undefined) this.animateId = 0;
|
1707 | var start = this.fadeLevel;
|
1708 | var steps = direction < 0 ? start : totalSteps - start;
|
1709 | if (steps <= 0) {
|
1710 | if (this.fadeLevel) {
|
1711 | this.updateSelection_(1.0);
|
1712 | }
|
1713 | return;
|
1714 | }
|
1715 |
|
1716 | var thisId = ++this.animateId;
|
1717 | var that = this;
|
1718 | var cleanupIfClearing = function() {
|
1719 |
|
1720 |
|
1721 | if (that.fadeLevel !== 0 && direction < 0) {
|
1722 | that.fadeLevel = 0;
|
1723 | that.clearSelection();
|
1724 | }
|
1725 | };
|
1726 | utils.repeatAndCleanup(
|
1727 | function(n) {
|
1728 |
|
1729 | if (that.animateId != thisId) return;
|
1730 |
|
1731 | that.fadeLevel += direction;
|
1732 | if (that.fadeLevel === 0) {
|
1733 | that.clearSelection();
|
1734 | } else {
|
1735 | that.updateSelection_(that.fadeLevel / totalSteps);
|
1736 | }
|
1737 | },
|
1738 | steps, millis, cleanupIfClearing);
|
1739 | };
|
1740 |
|
1741 |
|
1742 |
|
1743 |
|
1744 |
|
1745 |
|
1746 | Dygraph.prototype.updateSelection_ = function(opt_animFraction) {
|
1747 |
|
1748 | this.cascadeEvents_('select', {
|
1749 | selectedRow: this.lastRow_ === -1 ? undefined : this.lastRow_,
|
1750 | selectedX: this.lastx_ === null ? undefined : this.lastx_,
|
1751 | selectedPoints: this.selPoints_
|
1752 | });
|
1753 |
|
1754 |
|
1755 |
|
1756 | var i;
|
1757 | var ctx = this.canvas_ctx_;
|
1758 | if (this.getOption('highlightSeriesOpts')) {
|
1759 | ctx.clearRect(0, 0, this.width_, this.height_);
|
1760 | var alpha = 1.0 - this.getNumericOption('highlightSeriesBackgroundAlpha');
|
1761 | var backgroundColor = utils.toRGB_(this.getOption('highlightSeriesBackgroundColor'));
|
1762 |
|
1763 | if (alpha) {
|
1764 |
|
1765 |
|
1766 |
|
1767 | var animateBackgroundFade = this.getBooleanOption('animateBackgroundFade');
|
1768 | if (animateBackgroundFade) {
|
1769 | if (opt_animFraction === undefined) {
|
1770 |
|
1771 | this.animateSelection_(1);
|
1772 | return;
|
1773 | }
|
1774 | alpha *= opt_animFraction;
|
1775 | }
|
1776 | ctx.fillStyle = 'rgba(' + backgroundColor.r + ',' + backgroundColor.g + ',' + backgroundColor.b + ',' + alpha + ')';
|
1777 | ctx.fillRect(0, 0, this.width_, this.height_);
|
1778 | }
|
1779 |
|
1780 |
|
1781 |
|
1782 | this.plotter_._renderLineChart(this.highlightSet_, ctx);
|
1783 | } else if (this.previousVerticalX_ >= 0) {
|
1784 |
|
1785 | var maxCircleSize = 0;
|
1786 | var labels = this.attr_('labels');
|
1787 | for (i = 1; i < labels.length; i++) {
|
1788 | var r = this.getNumericOption('highlightCircleSize', labels[i]);
|
1789 | if (r > maxCircleSize) maxCircleSize = r;
|
1790 | }
|
1791 | var px = this.previousVerticalX_;
|
1792 | ctx.clearRect(px - maxCircleSize - 1, 0,
|
1793 | 2 * maxCircleSize + 2, this.height_);
|
1794 | }
|
1795 |
|
1796 | if (this.selPoints_.length > 0) {
|
1797 |
|
1798 | var canvasx = this.selPoints_[0].canvasx;
|
1799 | ctx.save();
|
1800 | for (i = 0; i < this.selPoints_.length; i++) {
|
1801 | var pt = this.selPoints_[i];
|
1802 | if (isNaN(pt.canvasy)) continue;
|
1803 |
|
1804 | var circleSize = this.getNumericOption('highlightCircleSize', pt.name);
|
1805 | var callback = this.getFunctionOption("drawHighlightPointCallback", pt.name);
|
1806 | var color = this.plotter_.colors[pt.name];
|
1807 | if (!callback) {
|
1808 | callback = utils.Circles.DEFAULT;
|
1809 | }
|
1810 | ctx.lineWidth = this.getNumericOption('strokeWidth', pt.name);
|
1811 | ctx.strokeStyle = color;
|
1812 | ctx.fillStyle = color;
|
1813 | callback.call(this, this, pt.name, ctx, canvasx, pt.canvasy,
|
1814 | color, circleSize, pt.idx);
|
1815 | }
|
1816 | ctx.restore();
|
1817 |
|
1818 | this.previousVerticalX_ = canvasx;
|
1819 | }
|
1820 | };
|
1821 |
|
1822 |
|
1823 |
|
1824 |
|
1825 |
|
1826 |
|
1827 |
|
1828 |
|
1829 |
|
1830 |
|
1831 |
|
1832 |
|
1833 |
|
1834 |
|
1835 |
|
1836 |
|
1837 |
|
1838 |
|
1839 |
|
1840 | Dygraph.prototype.setSelection = function setSelection(row, opt_seriesName,
|
1841 | opt_locked,
|
1842 | opt_trigger_highlight_callback) {
|
1843 |
|
1844 | this.selPoints_ = [];
|
1845 |
|
1846 | var changed = false;
|
1847 | if (row !== false && row >= 0) {
|
1848 | if (row != this.lastRow_) changed = true;
|
1849 | this.lastRow_ = row;
|
1850 | for (var setIdx = 0; setIdx < this.layout_.points.length; ++setIdx) {
|
1851 | var points = this.layout_.points[setIdx];
|
1852 |
|
1853 |
|
1854 |
|
1855 | var setRow = row - this.getLeftBoundary_(setIdx);
|
1856 | if (setRow >= 0 && setRow < points.length && points[setRow].idx == row) {
|
1857 | var point = points[setRow];
|
1858 | if (point.yval !== null) this.selPoints_.push(point);
|
1859 | } else {
|
1860 | for (var pointIdx = 0; pointIdx < points.length; ++pointIdx) {
|
1861 | var point = points[pointIdx];
|
1862 | if (point.idx == row) {
|
1863 | if (point.yval !== null) {
|
1864 | this.selPoints_.push(point);
|
1865 | }
|
1866 | break;
|
1867 | }
|
1868 | }
|
1869 | }
|
1870 | }
|
1871 | } else {
|
1872 | if (this.lastRow_ >= 0) changed = true;
|
1873 | this.lastRow_ = -1;
|
1874 | }
|
1875 |
|
1876 | if (this.selPoints_.length) {
|
1877 | this.lastx_ = this.selPoints_[0].xval;
|
1878 | } else {
|
1879 | this.lastx_ = null;
|
1880 | }
|
1881 |
|
1882 | if (opt_seriesName !== undefined) {
|
1883 | if (this.highlightSet_ !== opt_seriesName) changed = true;
|
1884 | this.highlightSet_ = opt_seriesName;
|
1885 | }
|
1886 |
|
1887 | if (opt_locked !== undefined) {
|
1888 | this.lockedSet_ = opt_locked;
|
1889 | }
|
1890 |
|
1891 | if (changed) {
|
1892 | this.updateSelection_(undefined);
|
1893 |
|
1894 | if (opt_trigger_highlight_callback) {
|
1895 | var callback = this.getFunctionOption("highlightCallback");
|
1896 | if (callback) {
|
1897 | var event = {};
|
1898 | callback.call(this, event,
|
1899 | this.lastx_,
|
1900 | this.selPoints_,
|
1901 | this.lastRow_,
|
1902 | this.highlightSet_);
|
1903 | }
|
1904 | }
|
1905 | }
|
1906 | return changed;
|
1907 | };
|
1908 |
|
1909 |
|
1910 |
|
1911 |
|
1912 |
|
1913 |
|
1914 | Dygraph.prototype.mouseOut_ = function(event) {
|
1915 | if (this.getFunctionOption("unhighlightCallback")) {
|
1916 | this.getFunctionOption("unhighlightCallback").call(this, event);
|
1917 | }
|
1918 |
|
1919 | if (this.getBooleanOption("hideOverlayOnMouseOut") && !this.lockedSet_) {
|
1920 | this.clearSelection();
|
1921 | }
|
1922 | };
|
1923 |
|
1924 |
|
1925 |
|
1926 |
|
1927 |
|
1928 | Dygraph.prototype.clearSelection = function() {
|
1929 | this.cascadeEvents_('deselect', {});
|
1930 |
|
1931 | this.lockedSet_ = false;
|
1932 |
|
1933 | if (this.fadeLevel) {
|
1934 | this.animateSelection_(-1);
|
1935 | return;
|
1936 | }
|
1937 | this.canvas_ctx_.clearRect(0, 0, this.width_, this.height_);
|
1938 | this.fadeLevel = 0;
|
1939 | this.selPoints_ = [];
|
1940 | this.lastx_ = null;
|
1941 | this.lastRow_ = -1;
|
1942 | this.highlightSet_ = null;
|
1943 | };
|
1944 |
|
1945 |
|
1946 |
|
1947 |
|
1948 |
|
1949 |
|
1950 | Dygraph.prototype.getSelection = function() {
|
1951 | if (!this.selPoints_ || this.selPoints_.length < 1) {
|
1952 | return -1;
|
1953 | }
|
1954 |
|
1955 | for (var setIdx = 0; setIdx < this.layout_.points.length; setIdx++) {
|
1956 | var points = this.layout_.points[setIdx];
|
1957 | for (var row = 0; row < points.length; row++) {
|
1958 | if (points[row].x == this.selPoints_[0].x) {
|
1959 | return points[row].idx;
|
1960 | }
|
1961 | }
|
1962 | }
|
1963 | return -1;
|
1964 | };
|
1965 |
|
1966 |
|
1967 |
|
1968 |
|
1969 |
|
1970 | Dygraph.prototype.getHighlightSeries = function() {
|
1971 | return this.highlightSet_;
|
1972 | };
|
1973 |
|
1974 |
|
1975 |
|
1976 |
|
1977 |
|
1978 | Dygraph.prototype.isSeriesLocked = function() {
|
1979 | return this.lockedSet_;
|
1980 | };
|
1981 |
|
1982 |
|
1983 |
|
1984 |
|
1985 |
|
1986 |
|
1987 | Dygraph.prototype.loadedEvent_ = function(data) {
|
1988 | this.rawData_ = this.parseCSV_(data);
|
1989 | this.cascadeDataDidUpdateEvent_();
|
1990 | this.predraw_();
|
1991 | };
|
1992 |
|
1993 |
|
1994 |
|
1995 |
|
1996 |
|
1997 | Dygraph.prototype.addXTicks_ = function() {
|
1998 |
|
1999 | var range;
|
2000 | if (this.dateWindow_) {
|
2001 | range = [this.dateWindow_[0], this.dateWindow_[1]];
|
2002 | } else {
|
2003 | range = this.xAxisExtremes();
|
2004 | }
|
2005 |
|
2006 | var xAxisOptionsView = this.optionsViewForAxis_('x');
|
2007 | var xTicks = xAxisOptionsView('ticker')(
|
2008 | range[0],
|
2009 | range[1],
|
2010 | this.plotter_.area.w,
|
2011 | xAxisOptionsView,
|
2012 | this);
|
2013 |
|
2014 |
|
2015 | this.layout_.setXTicks(xTicks);
|
2016 | };
|
2017 |
|
2018 |
|
2019 |
|
2020 |
|
2021 |
|
2022 | Dygraph.prototype.getHandlerClass_ = function() {
|
2023 | var handlerClass;
|
2024 | if (this.attr_('dataHandler')) {
|
2025 | handlerClass = this.attr_('dataHandler');
|
2026 | } else if (this.fractions_) {
|
2027 | if (this.getBooleanOption('errorBars')) {
|
2028 | handlerClass = FractionsBarsHandler;
|
2029 | } else {
|
2030 | handlerClass = DefaultFractionHandler;
|
2031 | }
|
2032 | } else if (this.getBooleanOption('customBars')) {
|
2033 | handlerClass = CustomBarsHandler;
|
2034 | } else if (this.getBooleanOption('errorBars')) {
|
2035 | handlerClass = ErrorBarsHandler;
|
2036 | } else {
|
2037 | handlerClass = DefaultHandler;
|
2038 | }
|
2039 | return handlerClass;
|
2040 | };
|
2041 |
|
2042 |
|
2043 |
|
2044 |
|
2045 |
|
2046 |
|
2047 |
|
2048 |
|
2049 |
|
2050 | Dygraph.prototype.predraw_ = function() {
|
2051 | var start = new Date();
|
2052 |
|
2053 |
|
2054 | this.dataHandler_ = new (this.getHandlerClass_())();
|
2055 |
|
2056 | this.layout_.computePlotArea();
|
2057 |
|
2058 |
|
2059 | this.computeYAxes_();
|
2060 |
|
2061 | if (!this.is_initial_draw_) {
|
2062 | this.canvas_ctx_.restore();
|
2063 | this.hidden_ctx_.restore();
|
2064 | }
|
2065 |
|
2066 | this.canvas_ctx_.save();
|
2067 | this.hidden_ctx_.save();
|
2068 |
|
2069 |
|
2070 | this.plotter_ = new DygraphCanvasRenderer(this,
|
2071 | this.hidden_,
|
2072 | this.hidden_ctx_,
|
2073 | this.layout_);
|
2074 |
|
2075 |
|
2076 |
|
2077 | this.createRollInterface_();
|
2078 |
|
2079 | this.cascadeEvents_('predraw');
|
2080 |
|
2081 |
|
2082 |
|
2083 | this.rolledSeries_ = [null];
|
2084 | for (var i = 1; i < this.numColumns(); i++) {
|
2085 |
|
2086 | var series = this.dataHandler_.extractSeries(this.rawData_, i, this.attributes_);
|
2087 | if (this.rollPeriod_ > 1) {
|
2088 | series = this.dataHandler_.rollingAverage(series, this.rollPeriod_, this.attributes_, i);
|
2089 | }
|
2090 |
|
2091 | this.rolledSeries_.push(series);
|
2092 | }
|
2093 |
|
2094 |
|
2095 | this.drawGraph_();
|
2096 |
|
2097 |
|
2098 | var end = new Date();
|
2099 | this.drawingTimeMs_ = (end - start);
|
2100 | };
|
2101 |
|
2102 |
|
2103 |
|
2104 |
|
2105 |
|
2106 |
|
2107 |
|
2108 |
|
2109 |
|
2110 |
|
2111 |
|
2112 |
|
2113 |
|
2114 |
|
2115 |
|
2116 |
|
2117 |
|
2118 |
|
2119 |
|
2120 |
|
2121 |
|
2122 |
|
2123 |
|
2124 |
|
2125 | Dygraph.PointType = undefined;
|
2126 |
|
2127 |
|
2128 |
|
2129 |
|
2130 |
|
2131 |
|
2132 |
|
2133 |
|
2134 |
|
2135 |
|
2136 |
|
2137 |
|
2138 |
|
2139 |
|
2140 |
|
2141 |
|
2142 |
|
2143 |
|
2144 |
|
2145 | Dygraph.stackPoints_ = function(
|
2146 | points, cumulativeYval, seriesExtremes, fillMethod) {
|
2147 | var lastXval = null;
|
2148 | var prevPoint = null;
|
2149 | var nextPoint = null;
|
2150 | var nextPointIdx = -1;
|
2151 |
|
2152 |
|
2153 | var updateNextPoint = function(idx) {
|
2154 |
|
2155 |
|
2156 | if (nextPointIdx >= idx) return;
|
2157 |
|
2158 |
|
2159 |
|
2160 | for (var j = idx; j < points.length; ++j) {
|
2161 |
|
2162 |
|
2163 | nextPoint = null;
|
2164 | if (!isNaN(points[j].yval) && points[j].yval !== null) {
|
2165 | nextPointIdx = j;
|
2166 | nextPoint = points[j];
|
2167 | break;
|
2168 | }
|
2169 | }
|
2170 | };
|
2171 |
|
2172 | for (var i = 0; i < points.length; ++i) {
|
2173 | var point = points[i];
|
2174 | var xval = point.xval;
|
2175 | if (cumulativeYval[xval] === undefined) {
|
2176 | cumulativeYval[xval] = 0;
|
2177 | }
|
2178 |
|
2179 | var actualYval = point.yval;
|
2180 | if (isNaN(actualYval) || actualYval === null) {
|
2181 | if(fillMethod == 'none') {
|
2182 | actualYval = 0;
|
2183 | } else {
|
2184 |
|
2185 | updateNextPoint(i);
|
2186 | if (prevPoint && nextPoint && fillMethod != 'none') {
|
2187 |
|
2188 | actualYval = prevPoint.yval + (nextPoint.yval - prevPoint.yval) *
|
2189 | ((xval - prevPoint.xval) / (nextPoint.xval - prevPoint.xval));
|
2190 | } else if (prevPoint && fillMethod == 'all') {
|
2191 | actualYval = prevPoint.yval;
|
2192 | } else if (nextPoint && fillMethod == 'all') {
|
2193 | actualYval = nextPoint.yval;
|
2194 | } else {
|
2195 | actualYval = 0;
|
2196 | }
|
2197 | }
|
2198 | } else {
|
2199 | prevPoint = point;
|
2200 | }
|
2201 |
|
2202 | var stackedYval = cumulativeYval[xval];
|
2203 | if (lastXval != xval) {
|
2204 |
|
2205 | stackedYval += actualYval;
|
2206 | cumulativeYval[xval] = stackedYval;
|
2207 | }
|
2208 | lastXval = xval;
|
2209 |
|
2210 | point.yval_stacked = stackedYval;
|
2211 |
|
2212 | if (stackedYval > seriesExtremes[1]) {
|
2213 | seriesExtremes[1] = stackedYval;
|
2214 | }
|
2215 | if (stackedYval < seriesExtremes[0]) {
|
2216 | seriesExtremes[0] = stackedYval;
|
2217 | }
|
2218 | }
|
2219 | };
|
2220 |
|
2221 |
|
2222 |
|
2223 |
|
2224 |
|
2225 |
|
2226 |
|
2227 |
|
2228 |
|
2229 |
|
2230 |
|
2231 |
|
2232 |
|
2233 |
|
2234 |
|
2235 |
|
2236 |
|
2237 |
|
2238 |
|
2239 |
|
2240 | Dygraph.prototype.gatherDatasets_ = function(rolledSeries, dateWindow) {
|
2241 | var boundaryIds = [];
|
2242 | var points = [];
|
2243 | var cumulativeYval = [];
|
2244 | var extremes = {};
|
2245 | var seriesIdx, sampleIdx;
|
2246 | var firstIdx, lastIdx;
|
2247 | var axisIdx;
|
2248 |
|
2249 |
|
2250 |
|
2251 | var num_series = rolledSeries.length - 1;
|
2252 | var series;
|
2253 | for (seriesIdx = num_series; seriesIdx >= 1; seriesIdx--) {
|
2254 | if (!this.visibility()[seriesIdx - 1]) continue;
|
2255 |
|
2256 |
|
2257 |
|
2258 |
|
2259 | if (dateWindow) {
|
2260 | series = rolledSeries[seriesIdx];
|
2261 | var low = dateWindow[0];
|
2262 | var high = dateWindow[1];
|
2263 |
|
2264 |
|
2265 |
|
2266 | firstIdx = null;
|
2267 | lastIdx = null;
|
2268 | for (sampleIdx = 0; sampleIdx < series.length; sampleIdx++) {
|
2269 | if (series[sampleIdx][0] >= low && firstIdx === null) {
|
2270 | firstIdx = sampleIdx;
|
2271 | }
|
2272 | if (series[sampleIdx][0] <= high) {
|
2273 | lastIdx = sampleIdx;
|
2274 | }
|
2275 | }
|
2276 |
|
2277 | if (firstIdx === null) firstIdx = 0;
|
2278 | var correctedFirstIdx = firstIdx;
|
2279 | var isInvalidValue = true;
|
2280 | while (isInvalidValue && correctedFirstIdx > 0) {
|
2281 | correctedFirstIdx--;
|
2282 |
|
2283 | isInvalidValue = series[correctedFirstIdx][1] === null;
|
2284 | }
|
2285 |
|
2286 | if (lastIdx === null) lastIdx = series.length - 1;
|
2287 | var correctedLastIdx = lastIdx;
|
2288 | isInvalidValue = true;
|
2289 | while (isInvalidValue && correctedLastIdx < series.length - 1) {
|
2290 | correctedLastIdx++;
|
2291 | isInvalidValue = series[correctedLastIdx][1] === null;
|
2292 | }
|
2293 |
|
2294 | if (correctedFirstIdx!==firstIdx) {
|
2295 | firstIdx = correctedFirstIdx;
|
2296 | }
|
2297 | if (correctedLastIdx !== lastIdx) {
|
2298 | lastIdx = correctedLastIdx;
|
2299 | }
|
2300 |
|
2301 | boundaryIds[seriesIdx-1] = [firstIdx, lastIdx];
|
2302 |
|
2303 |
|
2304 | series = series.slice(firstIdx, lastIdx + 1);
|
2305 | } else {
|
2306 | series = rolledSeries[seriesIdx];
|
2307 | boundaryIds[seriesIdx-1] = [0, series.length-1];
|
2308 | }
|
2309 |
|
2310 | var seriesName = this.attr_("labels")[seriesIdx];
|
2311 | var seriesExtremes = this.dataHandler_.getExtremeYValues(series,
|
2312 | dateWindow, this.getBooleanOption("stepPlot", seriesName));
|
2313 |
|
2314 | var seriesPoints = this.dataHandler_.seriesToPoints(series,
|
2315 | seriesName, boundaryIds[seriesIdx-1][0]);
|
2316 |
|
2317 | if (this.getBooleanOption("stackedGraph")) {
|
2318 | axisIdx = this.attributes_.axisForSeries(seriesName);
|
2319 | if (cumulativeYval[axisIdx] === undefined) {
|
2320 | cumulativeYval[axisIdx] = [];
|
2321 | }
|
2322 | Dygraph.stackPoints_(seriesPoints, cumulativeYval[axisIdx], seriesExtremes,
|
2323 | this.getBooleanOption("stackedGraphNaNFill"));
|
2324 | }
|
2325 |
|
2326 | extremes[seriesName] = seriesExtremes;
|
2327 | points[seriesIdx] = seriesPoints;
|
2328 | }
|
2329 |
|
2330 | return { points: points, extremes: extremes, boundaryIds: boundaryIds };
|
2331 | };
|
2332 |
|
2333 |
|
2334 |
|
2335 |
|
2336 |
|
2337 |
|
2338 |
|
2339 |
|
2340 | Dygraph.prototype.drawGraph_ = function() {
|
2341 | var start = new Date();
|
2342 |
|
2343 |
|
2344 | var is_initial_draw = this.is_initial_draw_;
|
2345 | this.is_initial_draw_ = false;
|
2346 |
|
2347 | this.layout_.removeAllDatasets();
|
2348 | this.setColors_();
|
2349 | this.attrs_.pointSize = 0.5 * this.getNumericOption('highlightCircleSize');
|
2350 |
|
2351 | var packed = this.gatherDatasets_(this.rolledSeries_, this.dateWindow_);
|
2352 | var points = packed.points;
|
2353 | var extremes = packed.extremes;
|
2354 | this.boundaryIds_ = packed.boundaryIds;
|
2355 |
|
2356 | this.setIndexByName_ = {};
|
2357 | var labels = this.attr_("labels");
|
2358 | var dataIdx = 0;
|
2359 | for (var i = 1; i < points.length; i++) {
|
2360 | if (!this.visibility()[i - 1]) continue;
|
2361 | this.layout_.addDataset(labels[i], points[i]);
|
2362 | this.datasetIndex_[i] = dataIdx++;
|
2363 | }
|
2364 | for (var i = 0; i < labels.length; i++) {
|
2365 | this.setIndexByName_[labels[i]] = i;
|
2366 | }
|
2367 |
|
2368 | this.computeYAxisRanges_(extremes);
|
2369 | this.layout_.setYAxes(this.axes_);
|
2370 |
|
2371 | this.addXTicks_();
|
2372 |
|
2373 |
|
2374 | this.layout_.evaluate();
|
2375 | this.renderGraph_(is_initial_draw);
|
2376 |
|
2377 | if (this.getStringOption("timingName")) {
|
2378 | var end = new Date();
|
2379 | console.log(this.getStringOption("timingName") + " - drawGraph: " + (end - start) + "ms");
|
2380 | }
|
2381 | };
|
2382 |
|
2383 |
|
2384 |
|
2385 |
|
2386 |
|
2387 |
|
2388 |
|
2389 | Dygraph.prototype.renderGraph_ = function(is_initial_draw) {
|
2390 | this.cascadeEvents_('clearChart');
|
2391 | this.plotter_.clear();
|
2392 |
|
2393 | const underlayCallback = this.getFunctionOption('underlayCallback');
|
2394 | if (underlayCallback) {
|
2395 |
|
2396 |
|
2397 | underlayCallback.call(this,
|
2398 | this.hidden_ctx_, this.layout_.getPlotArea(), this, this);
|
2399 | }
|
2400 |
|
2401 | var e = {
|
2402 | canvas: this.hidden_,
|
2403 | drawingContext: this.hidden_ctx_
|
2404 | };
|
2405 | this.cascadeEvents_('willDrawChart', e);
|
2406 | this.plotter_.render();
|
2407 | this.cascadeEvents_('didDrawChart', e);
|
2408 | this.lastRow_ = -1;
|
2409 |
|
2410 |
|
2411 |
|
2412 | this.canvas_.getContext('2d').clearRect(0, 0, this.width_, this.height_);
|
2413 |
|
2414 | const drawCallback = this.getFunctionOption("drawCallback");
|
2415 | if (drawCallback !== null) {
|
2416 | drawCallback.call(this, this, is_initial_draw);
|
2417 | }
|
2418 | if (is_initial_draw) {
|
2419 | this.readyFired_ = true;
|
2420 | while (this.readyFns_.length > 0) {
|
2421 | var fn = this.readyFns_.pop();
|
2422 | fn(this);
|
2423 | }
|
2424 | }
|
2425 | };
|
2426 |
|
2427 |
|
2428 |
|
2429 |
|
2430 |
|
2431 |
|
2432 |
|
2433 |
|
2434 |
|
2435 |
|
2436 |
|
2437 | Dygraph.prototype.computeYAxes_ = function() {
|
2438 | var axis, index, opts, v;
|
2439 |
|
2440 |
|
2441 |
|
2442 |
|
2443 | this.axes_ = [];
|
2444 |
|
2445 | for (axis = 0; axis < this.attributes_.numAxes(); axis++) {
|
2446 |
|
2447 | opts = { g : this };
|
2448 | utils.update(opts, this.attributes_.axisOptions(axis));
|
2449 | this.axes_[axis] = opts;
|
2450 | }
|
2451 |
|
2452 | for (axis = 0; axis < this.axes_.length; axis++) {
|
2453 | if (axis === 0) {
|
2454 | opts = this.optionsViewForAxis_('y' + (axis ? '2' : ''));
|
2455 | v = opts("valueRange");
|
2456 | if (v) this.axes_[axis].valueRange = v;
|
2457 | } else {
|
2458 | var axes = this.user_attrs_.axes;
|
2459 | if (axes && axes.y2) {
|
2460 | v = axes.y2.valueRange;
|
2461 | if (v) this.axes_[axis].valueRange = v;
|
2462 | }
|
2463 | }
|
2464 | }
|
2465 | };
|
2466 |
|
2467 |
|
2468 |
|
2469 |
|
2470 |
|
2471 | Dygraph.prototype.numAxes = function() {
|
2472 | return this.attributes_.numAxes();
|
2473 | };
|
2474 |
|
2475 |
|
2476 |
|
2477 |
|
2478 |
|
2479 |
|
2480 |
|
2481 |
|
2482 | Dygraph.prototype.axisPropertiesForSeries = function(series) {
|
2483 |
|
2484 | return this.axes_[this.attributes_.axisForSeries(series)];
|
2485 | };
|
2486 |
|
2487 |
|
2488 |
|
2489 |
|
2490 |
|
2491 |
|
2492 |
|
2493 | Dygraph.prototype.computeYAxisRanges_ = function(extremes) {
|
2494 | var isNullUndefinedOrNaN = function(num) {
|
2495 | return isNaN(parseFloat(num));
|
2496 | };
|
2497 | var numAxes = this.attributes_.numAxes();
|
2498 | var ypadCompat, span, series, ypad;
|
2499 |
|
2500 | var p_axis;
|
2501 |
|
2502 |
|
2503 | for (var i = 0; i < numAxes; i++) {
|
2504 | var axis = this.axes_[i];
|
2505 | var logscale = this.attributes_.getForAxis("logscale", i);
|
2506 | var includeZero = this.attributes_.getForAxis("includeZero", i);
|
2507 | var independentTicks = this.attributes_.getForAxis("independentTicks", i);
|
2508 | series = this.attributes_.seriesForAxis(i);
|
2509 |
|
2510 |
|
2511 |
|
2512 |
|
2513 |
|
2514 |
|
2515 |
|
2516 |
|
2517 |
|
2518 |
|
2519 |
|
2520 |
|
2521 |
|
2522 |
|
2523 | ypadCompat = true;
|
2524 | ypad = 0.1;
|
2525 | const yRangePad = this.getNumericOption('yRangePad');
|
2526 | if (yRangePad !== null) {
|
2527 | ypadCompat = false;
|
2528 |
|
2529 | ypad = yRangePad / this.plotter_.area.h;
|
2530 | }
|
2531 |
|
2532 | if (series.length === 0) {
|
2533 |
|
2534 | axis.extremeRange = [0, 1];
|
2535 | } else {
|
2536 |
|
2537 | var minY = Infinity;
|
2538 | var maxY = -Infinity;
|
2539 | var extremeMinY, extremeMaxY;
|
2540 |
|
2541 | for (var j = 0; j < series.length; j++) {
|
2542 |
|
2543 | if (!extremes.hasOwnProperty(series[j])) continue;
|
2544 |
|
2545 |
|
2546 | extremeMinY = extremes[series[j]][0];
|
2547 | if (extremeMinY !== null) {
|
2548 | minY = Math.min(extremeMinY, minY);
|
2549 | }
|
2550 | extremeMaxY = extremes[series[j]][1];
|
2551 | if (extremeMaxY !== null) {
|
2552 | maxY = Math.max(extremeMaxY, maxY);
|
2553 | }
|
2554 | }
|
2555 |
|
2556 |
|
2557 | if (includeZero && !logscale) {
|
2558 | if (minY > 0) minY = 0;
|
2559 | if (maxY < 0) maxY = 0;
|
2560 | }
|
2561 |
|
2562 |
|
2563 | if (minY == Infinity) minY = 0;
|
2564 | if (maxY == -Infinity) maxY = 1;
|
2565 |
|
2566 | span = maxY - minY;
|
2567 |
|
2568 | if (span === 0) {
|
2569 | if (maxY !== 0) {
|
2570 | span = Math.abs(maxY);
|
2571 | } else {
|
2572 |
|
2573 | maxY = 1;
|
2574 | span = 1;
|
2575 | }
|
2576 | }
|
2577 |
|
2578 | var maxAxisY = maxY, minAxisY = minY;
|
2579 | if (ypadCompat) {
|
2580 | if (logscale) {
|
2581 | maxAxisY = maxY + ypad * span;
|
2582 | minAxisY = minY;
|
2583 | } else {
|
2584 | maxAxisY = maxY + ypad * span;
|
2585 | minAxisY = minY - ypad * span;
|
2586 |
|
2587 |
|
2588 |
|
2589 | if (minAxisY < 0 && minY >= 0) minAxisY = 0;
|
2590 | if (maxAxisY > 0 && maxY <= 0) maxAxisY = 0;
|
2591 | }
|
2592 | }
|
2593 | axis.extremeRange = [minAxisY, maxAxisY];
|
2594 | }
|
2595 | if (axis.valueRange) {
|
2596 |
|
2597 | var y0 = isNullUndefinedOrNaN(axis.valueRange[0]) ? axis.extremeRange[0] : axis.valueRange[0];
|
2598 | var y1 = isNullUndefinedOrNaN(axis.valueRange[1]) ? axis.extremeRange[1] : axis.valueRange[1];
|
2599 | axis.computedValueRange = [y0, y1];
|
2600 | } else {
|
2601 | axis.computedValueRange = axis.extremeRange;
|
2602 | }
|
2603 | if (!ypadCompat) {
|
2604 |
|
2605 |
|
2606 |
|
2607 | y0 = axis.computedValueRange[0];
|
2608 | y1 = axis.computedValueRange[1];
|
2609 |
|
2610 |
|
2611 | if (y0 === y1) {
|
2612 | if(y0 === 0) {
|
2613 | y1 = 1;
|
2614 | } else {
|
2615 | var delta = Math.abs(y0 / 10);
|
2616 | y0 -= delta;
|
2617 | y1 += delta;
|
2618 | }
|
2619 | }
|
2620 |
|
2621 | if (logscale) {
|
2622 | var y0pct = ypad / (2 * ypad - 1);
|
2623 | var y1pct = (ypad - 1) / (2 * ypad - 1);
|
2624 | axis.computedValueRange[0] = utils.logRangeFraction(y0, y1, y0pct);
|
2625 | axis.computedValueRange[1] = utils.logRangeFraction(y0, y1, y1pct);
|
2626 | } else {
|
2627 | span = y1 - y0;
|
2628 | axis.computedValueRange[0] = y0 - span * ypad;
|
2629 | axis.computedValueRange[1] = y1 + span * ypad;
|
2630 | }
|
2631 | }
|
2632 |
|
2633 | if (independentTicks) {
|
2634 | axis.independentTicks = independentTicks;
|
2635 | var opts = this.optionsViewForAxis_('y' + (i ? '2' : ''));
|
2636 | var ticker = opts('ticker');
|
2637 | axis.ticks = ticker(axis.computedValueRange[0],
|
2638 | axis.computedValueRange[1],
|
2639 | this.plotter_.area.h,
|
2640 | opts,
|
2641 | this);
|
2642 |
|
2643 | if (!p_axis) p_axis = axis;
|
2644 | }
|
2645 | }
|
2646 | if (p_axis === undefined) {
|
2647 | throw ("Configuration Error: At least one axis has to have the \"independentTicks\" option activated.");
|
2648 | }
|
2649 |
|
2650 |
|
2651 |
|
2652 | for (var i = 0; i < numAxes; i++) {
|
2653 | var axis = this.axes_[i];
|
2654 |
|
2655 | if (!axis.independentTicks) {
|
2656 | var opts = this.optionsViewForAxis_('y' + (i ? '2' : ''));
|
2657 | var ticker = opts('ticker');
|
2658 | var p_ticks = p_axis.ticks;
|
2659 | var p_scale = p_axis.computedValueRange[1] - p_axis.computedValueRange[0];
|
2660 | var scale = axis.computedValueRange[1] - axis.computedValueRange[0];
|
2661 | var tick_values = [];
|
2662 | for (var k = 0; k < p_ticks.length; k++) {
|
2663 | var y_frac = (p_ticks[k].v - p_axis.computedValueRange[0]) / p_scale;
|
2664 | var y_val = axis.computedValueRange[0] + y_frac * scale;
|
2665 | tick_values.push(y_val);
|
2666 | }
|
2667 |
|
2668 | axis.ticks = ticker(axis.computedValueRange[0],
|
2669 | axis.computedValueRange[1],
|
2670 | this.plotter_.area.h,
|
2671 | opts,
|
2672 | this,
|
2673 | tick_values);
|
2674 | }
|
2675 | }
|
2676 | };
|
2677 |
|
2678 |
|
2679 |
|
2680 |
|
2681 |
|
2682 |
|
2683 |
|
2684 | Dygraph.prototype.detectTypeFromString_ = function(str) {
|
2685 | var isDate = false;
|
2686 | var dashPos = str.indexOf('-');
|
2687 | if ((dashPos > 0 && (str[dashPos-1] != 'e' && str[dashPos-1] != 'E')) ||
|
2688 | str.indexOf('/') >= 0 ||
|
2689 | isNaN(parseFloat(str))) {
|
2690 | isDate = true;
|
2691 | }
|
2692 |
|
2693 | this.setXAxisOptions_(isDate);
|
2694 | };
|
2695 |
|
2696 | Dygraph.prototype.setXAxisOptions_ = function(isDate) {
|
2697 | if (isDate) {
|
2698 | this.attrs_.xValueParser = utils.dateParser;
|
2699 | this.attrs_.axes.x.valueFormatter = utils.dateValueFormatter;
|
2700 | this.attrs_.axes.x.ticker = DygraphTickers.dateTicker;
|
2701 | this.attrs_.axes.x.axisLabelFormatter = utils.dateAxisLabelFormatter;
|
2702 | } else {
|
2703 |
|
2704 | this.attrs_.xValueParser = function(x) { return parseFloat(x); };
|
2705 |
|
2706 |
|
2707 | this.attrs_.axes.x.valueFormatter = function(x) { return x; };
|
2708 | this.attrs_.axes.x.ticker = DygraphTickers.numericTicks;
|
2709 | this.attrs_.axes.x.axisLabelFormatter = this.attrs_.axes.x.valueFormatter;
|
2710 | }
|
2711 | };
|
2712 |
|
2713 |
|
2714 |
|
2715 |
|
2716 |
|
2717 |
|
2718 |
|
2719 |
|
2720 |
|
2721 |
|
2722 |
|
2723 |
|
2724 |
|
2725 |
|
2726 |
|
2727 |
|
2728 |
|
2729 |
|
2730 | Dygraph.prototype.parseCSV_ = function(data) {
|
2731 | var ret = [];
|
2732 | var line_delimiter = utils.detectLineDelimiter(data);
|
2733 | var lines = data.split(line_delimiter || "\n");
|
2734 | var vals, j;
|
2735 |
|
2736 |
|
2737 | var delim = this.getStringOption('delimiter');
|
2738 | if (lines[0].indexOf(delim) == -1 && lines[0].indexOf('\t') >= 0) {
|
2739 | delim = '\t';
|
2740 | }
|
2741 |
|
2742 | var start = 0;
|
2743 | if (!('labels' in this.user_attrs_)) {
|
2744 |
|
2745 | start = 1;
|
2746 | this.attrs_.labels = lines[0].split(delim);
|
2747 | this.attributes_.reparseSeries();
|
2748 | }
|
2749 | var line_no = 0;
|
2750 |
|
2751 | var xParser;
|
2752 | var defaultParserSet = false;
|
2753 | var expectedCols = this.attr_("labels").length;
|
2754 | var outOfOrder = false;
|
2755 | for (var i = start; i < lines.length; i++) {
|
2756 | var line = lines[i];
|
2757 | line_no = i;
|
2758 | if (line.length === 0) continue;
|
2759 | if (line[0] == '#') continue;
|
2760 | var inFields = line.split(delim);
|
2761 | if (inFields.length < 2) continue;
|
2762 |
|
2763 | var fields = [];
|
2764 | if (!defaultParserSet) {
|
2765 | this.detectTypeFromString_(inFields[0]);
|
2766 | xParser = this.getFunctionOption("xValueParser");
|
2767 | defaultParserSet = true;
|
2768 | }
|
2769 | fields[0] = xParser(inFields[0], this);
|
2770 |
|
2771 |
|
2772 | if (this.fractions_) {
|
2773 | for (j = 1; j < inFields.length; j++) {
|
2774 |
|
2775 | vals = inFields[j].split("/");
|
2776 | if (vals.length != 2) {
|
2777 | console.error('Expected fractional "num/den" values in CSV data ' +
|
2778 | "but found a value '" + inFields[j] + "' on line " +
|
2779 | (1 + i) + " ('" + line + "') which is not of this form.");
|
2780 | fields[j] = [0, 0];
|
2781 | } else {
|
2782 | fields[j] = [utils.parseFloat_(vals[0], i, line),
|
2783 | utils.parseFloat_(vals[1], i, line)];
|
2784 | }
|
2785 | }
|
2786 | } else if (this.getBooleanOption("errorBars")) {
|
2787 |
|
2788 | if (inFields.length % 2 != 1) {
|
2789 | console.error('Expected alternating (value, stdev.) pairs in CSV data ' +
|
2790 | 'but line ' + (1 + i) + ' has an odd number of values (' +
|
2791 | (inFields.length - 1) + "): '" + line + "'");
|
2792 | }
|
2793 | for (j = 1; j < inFields.length; j += 2) {
|
2794 | fields[(j + 1) / 2] = [utils.parseFloat_(inFields[j], i, line),
|
2795 | utils.parseFloat_(inFields[j + 1], i, line)];
|
2796 | }
|
2797 | } else if (this.getBooleanOption("customBars")) {
|
2798 |
|
2799 | for (j = 1; j < inFields.length; j++) {
|
2800 | var val = inFields[j];
|
2801 | if (/^ *$/.test(val)) {
|
2802 | fields[j] = [null, null, null];
|
2803 | } else {
|
2804 | vals = val.split(";");
|
2805 | if (vals.length == 3) {
|
2806 | fields[j] = [ utils.parseFloat_(vals[0], i, line),
|
2807 | utils.parseFloat_(vals[1], i, line),
|
2808 | utils.parseFloat_(vals[2], i, line) ];
|
2809 | } else {
|
2810 | console.warn('When using customBars, values must be either blank ' +
|
2811 | 'or "low;center;high" tuples (got "' + val +
|
2812 | '" on line ' + (1+i) + ')');
|
2813 | }
|
2814 | }
|
2815 | }
|
2816 | } else {
|
2817 |
|
2818 | for (j = 1; j < inFields.length; j++) {
|
2819 | fields[j] = utils.parseFloat_(inFields[j], i, line);
|
2820 | }
|
2821 | }
|
2822 | if (ret.length > 0 && fields[0] < ret[ret.length - 1][0]) {
|
2823 | outOfOrder = true;
|
2824 | }
|
2825 |
|
2826 | if (fields.length != expectedCols) {
|
2827 | console.error("Number of columns in line " + i + " (" + fields.length +
|
2828 | ") does not agree with number of labels (" + expectedCols +
|
2829 | ") " + line);
|
2830 | }
|
2831 |
|
2832 |
|
2833 |
|
2834 |
|
2835 |
|
2836 | if (i === 0 && this.attr_('labels')) {
|
2837 | var all_null = true;
|
2838 | for (j = 0; all_null && j < fields.length; j++) {
|
2839 | if (fields[j]) all_null = false;
|
2840 | }
|
2841 | if (all_null) {
|
2842 | console.warn("The dygraphs 'labels' option is set, but the first row " +
|
2843 | "of CSV data ('" + line + "') appears to also contain " +
|
2844 | "labels. Will drop the CSV labels and use the option " +
|
2845 | "labels.");
|
2846 | continue;
|
2847 | }
|
2848 | }
|
2849 | ret.push(fields);
|
2850 | }
|
2851 |
|
2852 | if (outOfOrder) {
|
2853 | console.warn("CSV is out of order; order it correctly to speed loading.");
|
2854 | ret.sort(function(a,b) { return a[0] - b[0]; });
|
2855 | }
|
2856 |
|
2857 | return ret;
|
2858 | };
|
2859 |
|
2860 |
|
2861 |
|
2862 | function validateNativeFormat(data) {
|
2863 | const firstRow = data[0];
|
2864 | const firstX = firstRow[0];
|
2865 | if (typeof firstX !== 'number' && !utils.isDateLike(firstX)) {
|
2866 | throw new Error(`Expected number or date but got ${typeof firstX}: ${firstX}.`);
|
2867 | }
|
2868 | for (let i = 1; i < firstRow.length; i++) {
|
2869 | const val = firstRow[i];
|
2870 | if (val === null || val === undefined) continue;
|
2871 | if (typeof val === 'number') continue;
|
2872 | if (utils.isArrayLike(val)) continue;
|
2873 | throw new Error(`Expected number or array but got ${typeof val}: ${val}.`);
|
2874 | }
|
2875 | }
|
2876 |
|
2877 |
|
2878 |
|
2879 |
|
2880 |
|
2881 |
|
2882 |
|
2883 |
|
2884 |
|
2885 | Dygraph.prototype.parseArray_ = function(data) {
|
2886 |
|
2887 | if (data.length === 0) {
|
2888 | data = [[0]];
|
2889 | }
|
2890 | if (data[0].length === 0) {
|
2891 | console.error("Data set cannot contain an empty row");
|
2892 | return null;
|
2893 | }
|
2894 |
|
2895 | validateNativeFormat(data);
|
2896 |
|
2897 | var i;
|
2898 | if (this.attr_("labels") === null) {
|
2899 | console.warn("Using default labels. Set labels explicitly via 'labels' " +
|
2900 | "in the options parameter");
|
2901 | this.attrs_.labels = [ "X" ];
|
2902 | for (i = 1; i < data[0].length; i++) {
|
2903 | this.attrs_.labels.push("Y" + i);
|
2904 | }
|
2905 | this.attributes_.reparseSeries();
|
2906 | } else {
|
2907 | var num_labels = this.attr_("labels");
|
2908 | if (num_labels.length != data[0].length) {
|
2909 | console.error("Mismatch between number of labels (" + num_labels + ")" +
|
2910 | " and number of columns in array (" + data[0].length + ")");
|
2911 | return null;
|
2912 | }
|
2913 | }
|
2914 |
|
2915 | if (utils.isDateLike(data[0][0])) {
|
2916 |
|
2917 | this.attrs_.axes.x.valueFormatter = utils.dateValueFormatter;
|
2918 | this.attrs_.axes.x.ticker = DygraphTickers.dateTicker;
|
2919 | this.attrs_.axes.x.axisLabelFormatter = utils.dateAxisLabelFormatter;
|
2920 |
|
2921 |
|
2922 | var parsedData = utils.clone(data);
|
2923 | for (i = 0; i < data.length; i++) {
|
2924 | if (parsedData[i].length === 0) {
|
2925 | console.error("Row " + (1 + i) + " of data is empty");
|
2926 | return null;
|
2927 | }
|
2928 | if (parsedData[i][0] === null ||
|
2929 | typeof(parsedData[i][0].getTime) != 'function' ||
|
2930 | isNaN(parsedData[i][0].getTime())) {
|
2931 | console.error("x value in row " + (1 + i) + " is not a Date");
|
2932 | return null;
|
2933 | }
|
2934 | parsedData[i][0] = parsedData[i][0].getTime();
|
2935 | }
|
2936 | return parsedData;
|
2937 | } else {
|
2938 |
|
2939 |
|
2940 | this.attrs_.axes.x.valueFormatter = function(x) { return x; };
|
2941 | this.attrs_.axes.x.ticker = DygraphTickers.numericTicks;
|
2942 | this.attrs_.axes.x.axisLabelFormatter = utils.numberAxisLabelFormatter;
|
2943 | return data;
|
2944 | }
|
2945 | };
|
2946 |
|
2947 |
|
2948 |
|
2949 |
|
2950 |
|
2951 |
|
2952 |
|
2953 |
|
2954 |
|
2955 |
|
2956 | Dygraph.prototype.parseDataTable_ = function(data) {
|
2957 | var shortTextForAnnotationNum = function(num) {
|
2958 |
|
2959 |
|
2960 |
|
2961 | var shortText = String.fromCharCode(65 + num % 26);
|
2962 | num = Math.floor(num / 26);
|
2963 | while ( num > 0 ) {
|
2964 | shortText = String.fromCharCode(65 + (num - 1) % 26 ) + shortText.toLowerCase();
|
2965 | num = Math.floor((num - 1) / 26);
|
2966 | }
|
2967 | return shortText;
|
2968 | };
|
2969 |
|
2970 | var cols = data.getNumberOfColumns();
|
2971 | var rows = data.getNumberOfRows();
|
2972 |
|
2973 | var indepType = data.getColumnType(0);
|
2974 | if (indepType == 'date' || indepType == 'datetime') {
|
2975 | this.attrs_.xValueParser = utils.dateParser;
|
2976 | this.attrs_.axes.x.valueFormatter = utils.dateValueFormatter;
|
2977 | this.attrs_.axes.x.ticker = DygraphTickers.dateTicker;
|
2978 | this.attrs_.axes.x.axisLabelFormatter = utils.dateAxisLabelFormatter;
|
2979 | } else if (indepType == 'number') {
|
2980 | this.attrs_.xValueParser = function(x) { return parseFloat(x); };
|
2981 | this.attrs_.axes.x.valueFormatter = function(x) { return x; };
|
2982 | this.attrs_.axes.x.ticker = DygraphTickers.numericTicks;
|
2983 | this.attrs_.axes.x.axisLabelFormatter = this.attrs_.axes.x.valueFormatter;
|
2984 | } else {
|
2985 | throw new Error(
|
2986 | "only 'date', 'datetime' and 'number' types are supported " +
|
2987 | "for column 1 of DataTable input (Got '" + indepType + "')");
|
2988 | }
|
2989 |
|
2990 |
|
2991 | var colIdx = [];
|
2992 | var annotationCols = {};
|
2993 | var hasAnnotations = false;
|
2994 | var i, j;
|
2995 | for (i = 1; i < cols; i++) {
|
2996 | var type = data.getColumnType(i);
|
2997 | if (type == 'number') {
|
2998 | colIdx.push(i);
|
2999 | } else if (type == 'string' && this.getBooleanOption('displayAnnotations')) {
|
3000 |
|
3001 | var dataIdx = colIdx[colIdx.length - 1];
|
3002 | if (!annotationCols.hasOwnProperty(dataIdx)) {
|
3003 | annotationCols[dataIdx] = [i];
|
3004 | } else {
|
3005 | annotationCols[dataIdx].push(i);
|
3006 | }
|
3007 | hasAnnotations = true;
|
3008 | } else {
|
3009 | throw new Error(
|
3010 | "Only 'number' is supported as a dependent type with Gviz." +
|
3011 | " 'string' is only supported if displayAnnotations is true");
|
3012 | }
|
3013 | }
|
3014 |
|
3015 |
|
3016 |
|
3017 | var labels = [data.getColumnLabel(0)];
|
3018 | for (i = 0; i < colIdx.length; i++) {
|
3019 | labels.push(data.getColumnLabel(colIdx[i]));
|
3020 | if (this.getBooleanOption("errorBars")) i += 1;
|
3021 | }
|
3022 | this.attrs_.labels = labels;
|
3023 | cols = labels.length;
|
3024 |
|
3025 | var ret = [];
|
3026 | var outOfOrder = false;
|
3027 | var annotations = [];
|
3028 | for (i = 0; i < rows; i++) {
|
3029 | var row = [];
|
3030 | if (typeof(data.getValue(i, 0)) === 'undefined' ||
|
3031 | data.getValue(i, 0) === null) {
|
3032 | console.warn("Ignoring row " + i +
|
3033 | " of DataTable because of undefined or null first column.");
|
3034 | continue;
|
3035 | }
|
3036 |
|
3037 | if (indepType == 'date' || indepType == 'datetime') {
|
3038 | row.push(data.getValue(i, 0).getTime());
|
3039 | } else {
|
3040 | row.push(data.getValue(i, 0));
|
3041 | }
|
3042 | if (!this.getBooleanOption("errorBars")) {
|
3043 | for (j = 0; j < colIdx.length; j++) {
|
3044 | var col = colIdx[j];
|
3045 | row.push(data.getValue(i, col));
|
3046 | if (hasAnnotations &&
|
3047 | annotationCols.hasOwnProperty(col) &&
|
3048 | data.getValue(i, annotationCols[col][0]) !== null) {
|
3049 | var ann = {};
|
3050 | ann.series = data.getColumnLabel(col);
|
3051 | ann.xval = row[0];
|
3052 | ann.shortText = shortTextForAnnotationNum(annotations.length);
|
3053 | ann.text = '';
|
3054 | for (var k = 0; k < annotationCols[col].length; k++) {
|
3055 | if (k) ann.text += "\n";
|
3056 | ann.text += data.getValue(i, annotationCols[col][k]);
|
3057 | }
|
3058 | annotations.push(ann);
|
3059 | }
|
3060 | }
|
3061 |
|
3062 |
|
3063 | for (j = 0; j < row.length; j++) {
|
3064 | if (!isFinite(row[j])) row[j] = null;
|
3065 | }
|
3066 | } else {
|
3067 | for (j = 0; j < cols - 1; j++) {
|
3068 | row.push([ data.getValue(i, 1 + 2 * j), data.getValue(i, 2 + 2 * j) ]);
|
3069 | }
|
3070 | }
|
3071 | if (ret.length > 0 && row[0] < ret[ret.length - 1][0]) {
|
3072 | outOfOrder = true;
|
3073 | }
|
3074 | ret.push(row);
|
3075 | }
|
3076 |
|
3077 | if (outOfOrder) {
|
3078 | console.warn("DataTable is out of order; order it correctly to speed loading.");
|
3079 | ret.sort(function(a,b) { return a[0] - b[0]; });
|
3080 | }
|
3081 | this.rawData_ = ret;
|
3082 |
|
3083 | if (annotations.length > 0) {
|
3084 | this.setAnnotations(annotations, true);
|
3085 | }
|
3086 | this.attributes_.reparseSeries();
|
3087 | };
|
3088 |
|
3089 |
|
3090 |
|
3091 |
|
3092 |
|
3093 |
|
3094 | Dygraph.prototype.cascadeDataDidUpdateEvent_ = function() {
|
3095 |
|
3096 |
|
3097 |
|
3098 | this.cascadeEvents_('dataDidUpdate', {});
|
3099 | };
|
3100 |
|
3101 |
|
3102 |
|
3103 |
|
3104 |
|
3105 |
|
3106 | Dygraph.prototype.start_ = function() {
|
3107 | var data = this.file_;
|
3108 |
|
3109 |
|
3110 | if (typeof data == 'function') {
|
3111 | data = data();
|
3112 | }
|
3113 |
|
3114 | const datatype = utils.typeArrayLike(data);
|
3115 | if (datatype == 'array') {
|
3116 | this.rawData_ = this.parseArray_(data);
|
3117 | this.cascadeDataDidUpdateEvent_();
|
3118 | this.predraw_();
|
3119 | } else if (datatype == 'object' &&
|
3120 | typeof data.getColumnRange == 'function') {
|
3121 |
|
3122 | this.parseDataTable_(data);
|
3123 | this.cascadeDataDidUpdateEvent_();
|
3124 | this.predraw_();
|
3125 | } else if (datatype == 'string') {
|
3126 |
|
3127 | var line_delimiter = utils.detectLineDelimiter(data);
|
3128 | if (line_delimiter) {
|
3129 | this.loadedEvent_(data);
|
3130 | } else {
|
3131 |
|
3132 | var req;
|
3133 | if (window.XMLHttpRequest) {
|
3134 |
|
3135 | req = new XMLHttpRequest();
|
3136 | } else {
|
3137 |
|
3138 | req = new ActiveXObject("Microsoft.XMLHTTP");
|
3139 | }
|
3140 |
|
3141 | var caller = this;
|
3142 | req.onreadystatechange = function () {
|
3143 | if (req.readyState == 4) {
|
3144 | if (req.status === 200 ||
|
3145 | req.status === 0) {
|
3146 | caller.loadedEvent_(req.responseText);
|
3147 | }
|
3148 | }
|
3149 | };
|
3150 |
|
3151 | req.open("GET", data, true);
|
3152 | req.send(null);
|
3153 | }
|
3154 | } else {
|
3155 | console.error("Unknown data format: " + datatype);
|
3156 | }
|
3157 | };
|
3158 |
|
3159 |
|
3160 |
|
3161 |
|
3162 |
|
3163 |
|
3164 |
|
3165 |
|
3166 |
|
3167 |
|
3168 |
|
3169 |
|
3170 |
|
3171 |
|
3172 |
|
3173 |
|
3174 |
|
3175 |
|
3176 |
|
3177 | Dygraph.prototype.updateOptions = function(input_attrs, block_redraw) {
|
3178 | if (typeof(block_redraw) == 'undefined') block_redraw = false;
|
3179 |
|
3180 |
|
3181 | var file = input_attrs.file;
|
3182 | var attrs = Dygraph.copyUserAttrs_(input_attrs);
|
3183 | var prevNumAxes = this.attributes_.numAxes();
|
3184 |
|
3185 |
|
3186 | if ('rollPeriod' in attrs) {
|
3187 | this.rollPeriod_ = attrs.rollPeriod;
|
3188 | }
|
3189 | if ('dateWindow' in attrs) {
|
3190 | this.dateWindow_ = attrs.dateWindow;
|
3191 | }
|
3192 |
|
3193 |
|
3194 |
|
3195 |
|
3196 |
|
3197 |
|
3198 |
|
3199 |
|
3200 |
|
3201 | var requiresNewPoints = utils.isPixelChangingOptionList(this.attr_("labels"), attrs);
|
3202 |
|
3203 | utils.updateDeep(this.user_attrs_, attrs);
|
3204 |
|
3205 | this.attributes_.reparseSeries();
|
3206 |
|
3207 | if (prevNumAxes < this.attributes_.numAxes()) this.plotter_.clear();
|
3208 | if (file) {
|
3209 |
|
3210 |
|
3211 | this.cascadeEvents_('dataWillUpdate', {});
|
3212 |
|
3213 | this.file_ = file;
|
3214 | if (!block_redraw) this.start_();
|
3215 | } else {
|
3216 | if (!block_redraw) {
|
3217 | if (requiresNewPoints) {
|
3218 | this.predraw_();
|
3219 | } else {
|
3220 | this.renderGraph_(false);
|
3221 | }
|
3222 | }
|
3223 | }
|
3224 | };
|
3225 |
|
3226 |
|
3227 |
|
3228 |
|
3229 |
|
3230 | Dygraph.copyUserAttrs_ = function(attrs) {
|
3231 | var my_attrs = {};
|
3232 | for (var k in attrs) {
|
3233 | if (!attrs.hasOwnProperty(k)) continue;
|
3234 | if (k == 'file') continue;
|
3235 | if (attrs.hasOwnProperty(k)) my_attrs[k] = attrs[k];
|
3236 | }
|
3237 | return my_attrs;
|
3238 | };
|
3239 |
|
3240 |
|
3241 |
|
3242 |
|
3243 |
|
3244 |
|
3245 |
|
3246 |
|
3247 |
|
3248 |
|
3249 |
|
3250 |
|
3251 | Dygraph.prototype.resize = function(width, height) {
|
3252 | if (this.resize_lock) {
|
3253 | return;
|
3254 | }
|
3255 | this.resize_lock = true;
|
3256 |
|
3257 | if ((width === null) != (height === null)) {
|
3258 | console.warn("Dygraph.resize() should be called with zero parameters or " +
|
3259 | "two non-NULL parameters. Pretending it was zero.");
|
3260 | width = height = null;
|
3261 | }
|
3262 |
|
3263 | var old_width = this.width_;
|
3264 | var old_height = this.height_;
|
3265 |
|
3266 | if (width) {
|
3267 | this.maindiv_.style.width = width + "px";
|
3268 | this.maindiv_.style.height = height + "px";
|
3269 | this.width_ = width;
|
3270 | this.height_ = height;
|
3271 | } else {
|
3272 | this.width_ = this.maindiv_.clientWidth;
|
3273 | this.height_ = this.maindiv_.clientHeight;
|
3274 | }
|
3275 |
|
3276 | if (old_width != this.width_ || old_height != this.height_) {
|
3277 |
|
3278 |
|
3279 | this.resizeElements_();
|
3280 | this.predraw_();
|
3281 | }
|
3282 |
|
3283 | this.resize_lock = false;
|
3284 | };
|
3285 |
|
3286 |
|
3287 |
|
3288 |
|
3289 |
|
3290 |
|
3291 | Dygraph.prototype.adjustRoll = function(length) {
|
3292 | this.rollPeriod_ = length;
|
3293 | this.predraw_();
|
3294 | };
|
3295 |
|
3296 |
|
3297 |
|
3298 |
|
3299 | Dygraph.prototype.visibility = function() {
|
3300 |
|
3301 |
|
3302 | if (!this.getOption("visibility")) {
|
3303 | this.attrs_.visibility = [];
|
3304 | }
|
3305 |
|
3306 | while (this.getOption("visibility").length < this.numColumns() - 1) {
|
3307 | this.attrs_.visibility.push(true);
|
3308 | }
|
3309 | return this.getOption("visibility");
|
3310 | };
|
3311 |
|
3312 |
|
3313 |
|
3314 |
|
3315 |
|
3316 |
|
3317 |
|
3318 |
|
3319 |
|
3320 |
|
3321 | Dygraph.prototype.setVisibility = function(num, value) {
|
3322 | var x = this.visibility();
|
3323 | var numIsObject = false;
|
3324 |
|
3325 | if (!Array.isArray(num)) {
|
3326 | if (num !== null && typeof num === 'object') {
|
3327 | numIsObject = true;
|
3328 | } else {
|
3329 | num = [num];
|
3330 | }
|
3331 | }
|
3332 |
|
3333 | if (numIsObject) {
|
3334 | for (var i in num) {
|
3335 | if (num.hasOwnProperty(i)) {
|
3336 | if (i < 0 || i >= x.length) {
|
3337 | console.warn("Invalid series number in setVisibility: " + i);
|
3338 | } else {
|
3339 | x[i] = num[i];
|
3340 | }
|
3341 | }
|
3342 | }
|
3343 | } else {
|
3344 | for (var i = 0; i < num.length; i++) {
|
3345 | if (typeof num[i] === 'boolean') {
|
3346 | if (i >= x.length) {
|
3347 | console.warn("Invalid series number in setVisibility: " + i);
|
3348 | } else {
|
3349 | x[i] = num[i];
|
3350 | }
|
3351 | } else {
|
3352 | if (num[i] < 0 || num[i] >= x.length) {
|
3353 | console.warn("Invalid series number in setVisibility: " + num[i]);
|
3354 | } else {
|
3355 | x[num[i]] = value;
|
3356 | }
|
3357 | }
|
3358 | }
|
3359 | }
|
3360 |
|
3361 | this.predraw_();
|
3362 | };
|
3363 |
|
3364 |
|
3365 |
|
3366 |
|
3367 |
|
3368 |
|
3369 |
|
3370 | Dygraph.prototype.size = function() {
|
3371 | return { width: this.width_, height: this.height_ };
|
3372 | };
|
3373 |
|
3374 |
|
3375 |
|
3376 |
|
3377 |
|
3378 |
|
3379 |
|
3380 | Dygraph.prototype.setAnnotations = function(ann, suppressDraw) {
|
3381 |
|
3382 | this.annotations_ = ann;
|
3383 | if (!this.layout_) {
|
3384 | console.warn("Tried to setAnnotations before dygraph was ready. " +
|
3385 | "Try setting them in a ready() block. See " +
|
3386 | "dygraphs.com/tests/annotation.html");
|
3387 | return;
|
3388 | }
|
3389 |
|
3390 | this.layout_.setAnnotations(this.annotations_);
|
3391 | if (!suppressDraw) {
|
3392 | this.predraw_();
|
3393 | }
|
3394 | };
|
3395 |
|
3396 |
|
3397 |
|
3398 |
|
3399 | Dygraph.prototype.annotations = function() {
|
3400 | return this.annotations_;
|
3401 | };
|
3402 |
|
3403 |
|
3404 |
|
3405 |
|
3406 |
|
3407 |
|
3408 |
|
3409 | Dygraph.prototype.getLabels = function() {
|
3410 | var labels = this.attr_("labels");
|
3411 | return labels ? labels.slice() : null;
|
3412 | };
|
3413 |
|
3414 |
|
3415 |
|
3416 |
|
3417 |
|
3418 | Dygraph.prototype.indexFromSetName = function(name) {
|
3419 | return this.setIndexByName_[name];
|
3420 | };
|
3421 |
|
3422 |
|
3423 |
|
3424 |
|
3425 |
|
3426 |
|
3427 |
|
3428 |
|
3429 |
|
3430 | Dygraph.prototype.getRowForX = function(xVal) {
|
3431 | var low = 0,
|
3432 | high = this.numRows() - 1;
|
3433 |
|
3434 | while (low <= high) {
|
3435 | var idx = (high + low) >> 1;
|
3436 | var x = this.getValue(idx, 0);
|
3437 | if (x < xVal) {
|
3438 | low = idx + 1;
|
3439 | } else if (x > xVal) {
|
3440 | high = idx - 1;
|
3441 | } else if (low != idx) {
|
3442 | high = idx;
|
3443 | } else {
|
3444 | return idx;
|
3445 | }
|
3446 | }
|
3447 |
|
3448 | return null;
|
3449 | };
|
3450 |
|
3451 |
|
3452 |
|
3453 |
|
3454 |
|
3455 |
|
3456 |
|
3457 |
|
3458 |
|
3459 |
|
3460 |
|
3461 |
|
3462 |
|
3463 | Dygraph.prototype.ready = function(callback) {
|
3464 | if (this.is_initial_draw_) {
|
3465 | this.readyFns_.push(callback);
|
3466 | } else {
|
3467 | callback.call(this, this);
|
3468 | }
|
3469 | };
|
3470 |
|
3471 |
|
3472 |
|
3473 |
|
3474 |
|
3475 |
|
3476 |
|
3477 |
|
3478 |
|
3479 |
|
3480 |
|
3481 | Dygraph.prototype.addAndTrackEvent = function(elem, type, fn) {
|
3482 | utils.addEvent(elem, type, fn);
|
3483 | this.registeredEvents_.push({elem, type, fn});
|
3484 | };
|
3485 |
|
3486 | Dygraph.prototype.removeTrackedEvents_ = function() {
|
3487 | if (this.registeredEvents_) {
|
3488 | for (var idx = 0; idx < this.registeredEvents_.length; idx++) {
|
3489 | var reg = this.registeredEvents_[idx];
|
3490 | utils.removeEvent(reg.elem, reg.type, reg.fn);
|
3491 | }
|
3492 | }
|
3493 |
|
3494 | this.registeredEvents_ = [];
|
3495 | };
|
3496 |
|
3497 |
|
3498 | Dygraph.PLUGINS = [
|
3499 | LegendPlugin,
|
3500 | AxesPlugin,
|
3501 | RangeSelectorPlugin,
|
3502 | ChartLabelsPlugin,
|
3503 | AnnotationsPlugin,
|
3504 | GridPlugin
|
3505 | ];
|
3506 |
|
3507 |
|
3508 |
|
3509 | Dygraph.GVizChart = GVizChart;
|
3510 | Dygraph.DASHED_LINE = utils.DASHED_LINE;
|
3511 | Dygraph.DOT_DASH_LINE = utils.DOT_DASH_LINE;
|
3512 | Dygraph.dateAxisLabelFormatter = utils.dateAxisLabelFormatter;
|
3513 | Dygraph.toRGB_ = utils.toRGB_;
|
3514 | Dygraph.findPos = utils.findPos;
|
3515 | Dygraph.pageX = utils.pageX;
|
3516 | Dygraph.pageY = utils.pageY;
|
3517 | Dygraph.dateString_ = utils.dateString_;
|
3518 | Dygraph.defaultInteractionModel = DygraphInteraction.defaultModel;
|
3519 | Dygraph.nonInteractiveModel = Dygraph.nonInteractiveModel_ = DygraphInteraction.nonInteractiveModel_;
|
3520 | Dygraph.Circles = utils.Circles;
|
3521 |
|
3522 | Dygraph.Plugins = {
|
3523 | Legend: LegendPlugin,
|
3524 | Axes: AxesPlugin,
|
3525 | Annotations: AnnotationsPlugin,
|
3526 | ChartLabels: ChartLabelsPlugin,
|
3527 | Grid: GridPlugin,
|
3528 | RangeSelector: RangeSelectorPlugin
|
3529 | };
|
3530 |
|
3531 | Dygraph.DataHandlers = {
|
3532 | DefaultHandler,
|
3533 | BarsHandler,
|
3534 | CustomBarsHandler,
|
3535 | DefaultFractionHandler,
|
3536 | ErrorBarsHandler,
|
3537 | FractionsBarsHandler
|
3538 | };
|
3539 |
|
3540 | Dygraph.startPan = DygraphInteraction.startPan;
|
3541 | Dygraph.startZoom = DygraphInteraction.startZoom;
|
3542 | Dygraph.movePan = DygraphInteraction.movePan;
|
3543 | Dygraph.moveZoom = DygraphInteraction.moveZoom;
|
3544 | Dygraph.endPan = DygraphInteraction.endPan;
|
3545 | Dygraph.endZoom = DygraphInteraction.endZoom;
|
3546 |
|
3547 | Dygraph.numericLinearTicks = DygraphTickers.numericLinearTicks;
|
3548 | Dygraph.numericTicks = DygraphTickers.numericTicks;
|
3549 | Dygraph.dateTicker = DygraphTickers.dateTicker;
|
3550 | Dygraph.Granularity = DygraphTickers.Granularity;
|
3551 | Dygraph.getDateAxis = DygraphTickers.getDateAxis;
|
3552 | Dygraph.floatFormat = utils.floatFormat;
|
3553 |
|
3554 | utils.setupDOMready_(Dygraph);
|
3555 |
|
3556 | export default Dygraph;
|