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 | (function webpackUniversalModuleDefinition(root, factory) {
|
27 | if(typeof exports === 'object' && typeof module === 'object')
|
28 | module.exports = factory();
|
29 | else if(typeof define === 'function' && define.amd)
|
30 | define(factory);
|
31 | else if(typeof exports === 'object')
|
32 | exports["vis"] = factory();
|
33 | else
|
34 | root["vis"] = factory();
|
35 | })(this, function() {
|
36 | return (function(modules) {
|
37 |
|
38 | var installedModules = {};
|
39 |
|
40 |
|
41 | function __webpack_require__(moduleId) {
|
42 |
|
43 |
|
44 | if(installedModules[moduleId])
|
45 | return installedModules[moduleId].exports;
|
46 |
|
47 |
|
48 | var module = installedModules[moduleId] = {
|
49 | exports: {},
|
50 | id: moduleId,
|
51 | loaded: false
|
52 | };
|
53 |
|
54 |
|
55 | modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
56 |
|
57 |
|
58 | module.loaded = true;
|
59 |
|
60 |
|
61 | return module.exports;
|
62 | }
|
63 |
|
64 |
|
65 |
|
66 | __webpack_require__.m = modules;
|
67 |
|
68 |
|
69 | __webpack_require__.c = installedModules;
|
70 |
|
71 |
|
72 | __webpack_require__.p = "";
|
73 |
|
74 |
|
75 | return __webpack_require__(0);
|
76 | })
|
77 |
|
78 | ([
|
79 |
|
80 | function(module, exports, __webpack_require__) {
|
81 |
|
82 |
|
83 | exports.util = __webpack_require__(1);
|
84 | exports.DOMutil = __webpack_require__(2);
|
85 |
|
86 |
|
87 | exports.DataSet = __webpack_require__(3);
|
88 | exports.DataView = __webpack_require__(4);
|
89 |
|
90 |
|
91 | exports.Graph3d = __webpack_require__(5);
|
92 | exports.graph3d = {
|
93 | Camera: __webpack_require__(6),
|
94 | Filter: __webpack_require__(7),
|
95 | Point2d: __webpack_require__(8),
|
96 | Point3d: __webpack_require__(9),
|
97 | Slider: __webpack_require__(10),
|
98 | StepNumber: __webpack_require__(11)
|
99 | };
|
100 |
|
101 |
|
102 | exports.Timeline = __webpack_require__(12);
|
103 | exports.Graph2d = __webpack_require__(13);
|
104 | exports.timeline = {
|
105 | DataStep: __webpack_require__(14),
|
106 | Range: __webpack_require__(15),
|
107 | stack: __webpack_require__(16),
|
108 | TimeStep: __webpack_require__(17),
|
109 |
|
110 | components: {
|
111 | items: {
|
112 | Item: __webpack_require__(28),
|
113 | BackgroundItem: __webpack_require__(29),
|
114 | BoxItem: __webpack_require__(30),
|
115 | PointItem: __webpack_require__(31),
|
116 | RangeItem: __webpack_require__(32)
|
117 | },
|
118 |
|
119 | Component: __webpack_require__(18),
|
120 | CurrentTime: __webpack_require__(19),
|
121 | CustomTime: __webpack_require__(20),
|
122 | DataAxis: __webpack_require__(21),
|
123 | GraphGroup: __webpack_require__(22),
|
124 | Group: __webpack_require__(23),
|
125 | ItemSet: __webpack_require__(24),
|
126 | Legend: __webpack_require__(25),
|
127 | LineGraph: __webpack_require__(26),
|
128 | TimeAxis: __webpack_require__(27)
|
129 | }
|
130 | };
|
131 |
|
132 |
|
133 | exports.Network = __webpack_require__(33);
|
134 | exports.network = {
|
135 | Edge: __webpack_require__(34),
|
136 | Groups: __webpack_require__(35),
|
137 | Images: __webpack_require__(36),
|
138 | Node: __webpack_require__(37),
|
139 | Popup: __webpack_require__(38),
|
140 | dotparser: __webpack_require__(39),
|
141 | gephiParser: __webpack_require__(40)
|
142 | };
|
143 |
|
144 |
|
145 | exports.Graph = function () {
|
146 | throw new Error('Graph is renamed to Network. Please create a graph as new vis.Network(...)');
|
147 | };
|
148 |
|
149 |
|
150 | exports.moment = __webpack_require__(41);
|
151 | exports.hammer = __webpack_require__(42);
|
152 |
|
153 |
|
154 | },
|
155 |
|
156 | function(module, exports, __webpack_require__) {
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 | var moment = __webpack_require__(41);
|
163 |
|
164 | |
165 |
|
166 |
|
167 |
|
168 |
|
169 | exports.isNumber = function(object) {
|
170 | return (object instanceof Number || typeof object == 'number');
|
171 | };
|
172 |
|
173 | |
174 |
|
175 |
|
176 |
|
177 |
|
178 | exports.isString = function(object) {
|
179 | return (object instanceof String || typeof object == 'string');
|
180 | };
|
181 |
|
182 | |
183 |
|
184 |
|
185 |
|
186 |
|
187 | exports.isDate = function(object) {
|
188 | if (object instanceof Date) {
|
189 | return true;
|
190 | }
|
191 | else if (exports.isString(object)) {
|
192 |
|
193 | var match = ASPDateRegex.exec(object);
|
194 | if (match) {
|
195 | return true;
|
196 | }
|
197 | else if (!isNaN(Date.parse(object))) {
|
198 | return true;
|
199 | }
|
200 | }
|
201 |
|
202 | return false;
|
203 | };
|
204 |
|
205 | |
206 |
|
207 |
|
208 |
|
209 |
|
210 | exports.isDataTable = function(object) {
|
211 | return (typeof (google) !== 'undefined') &&
|
212 | (google.visualization) &&
|
213 | (google.visualization.DataTable) &&
|
214 | (object instanceof google.visualization.DataTable);
|
215 | };
|
216 |
|
217 | |
218 |
|
219 |
|
220 |
|
221 |
|
222 | exports.randomUUID = function() {
|
223 | var S4 = function () {
|
224 | return Math.floor(
|
225 | Math.random() * 0x10000
|
226 | ).toString(16);
|
227 | };
|
228 |
|
229 | return (
|
230 | S4() + S4() + '-' +
|
231 | S4() + '-' +
|
232 | S4() + '-' +
|
233 | S4() + '-' +
|
234 | S4() + S4() + S4()
|
235 | );
|
236 | };
|
237 |
|
238 | |
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 | exports.extend = function (a, b) {
|
246 | for (var i = 1, len = arguments.length; i < len; i++) {
|
247 | var other = arguments[i];
|
248 | for (var prop in other) {
|
249 | if (other.hasOwnProperty(prop)) {
|
250 | a[prop] = other[prop];
|
251 | }
|
252 | }
|
253 | }
|
254 |
|
255 | return a;
|
256 | };
|
257 |
|
258 | |
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 | exports.selectiveExtend = function (props, a, b) {
|
267 | if (!Array.isArray(props)) {
|
268 | throw new Error('Array with property names expected as first argument');
|
269 | }
|
270 |
|
271 | for (var i = 2; i < arguments.length; i++) {
|
272 | var other = arguments[i];
|
273 |
|
274 | for (var p = 0; p < props.length; p++) {
|
275 | var prop = props[p];
|
276 | if (other.hasOwnProperty(prop)) {
|
277 | a[prop] = other[prop];
|
278 | }
|
279 | }
|
280 | }
|
281 | return a;
|
282 | };
|
283 |
|
284 | |
285 |
|
286 |
|
287 |
|
288 |
|
289 |
|
290 |
|
291 |
|
292 | exports.selectiveDeepExtend = function (props, a, b) {
|
293 |
|
294 | if (Array.isArray(b)) {
|
295 | throw new TypeError('Arrays are not supported by deepExtend');
|
296 | }
|
297 | for (var i = 2; i < arguments.length; i++) {
|
298 | var other = arguments[i];
|
299 | for (var p = 0; p < props.length; p++) {
|
300 | var prop = props[p];
|
301 | if (other.hasOwnProperty(prop)) {
|
302 | if (b[prop] && b[prop].constructor === Object) {
|
303 | if (a[prop] === undefined) {
|
304 | a[prop] = {};
|
305 | }
|
306 | if (a[prop].constructor === Object) {
|
307 | exports.deepExtend(a[prop], b[prop]);
|
308 | }
|
309 | else {
|
310 | a[prop] = b[prop];
|
311 | }
|
312 | } else if (Array.isArray(b[prop])) {
|
313 | throw new TypeError('Arrays are not supported by deepExtend');
|
314 | } else {
|
315 | a[prop] = b[prop];
|
316 | }
|
317 |
|
318 | }
|
319 | }
|
320 | }
|
321 | return a;
|
322 | };
|
323 |
|
324 | |
325 |
|
326 |
|
327 |
|
328 |
|
329 |
|
330 |
|
331 |
|
332 | exports.selectiveNotDeepExtend = function (props, a, b) {
|
333 |
|
334 | if (Array.isArray(b)) {
|
335 | throw new TypeError('Arrays are not supported by deepExtend');
|
336 | }
|
337 | for (var prop in b) {
|
338 | if (b.hasOwnProperty(prop)) {
|
339 | if (props.indexOf(prop) == -1) {
|
340 | if (b[prop] && b[prop].constructor === Object) {
|
341 | if (a[prop] === undefined) {
|
342 | a[prop] = {};
|
343 | }
|
344 | if (a[prop].constructor === Object) {
|
345 | exports.deepExtend(a[prop], b[prop]);
|
346 | }
|
347 | else {
|
348 | a[prop] = b[prop];
|
349 | }
|
350 | } else if (Array.isArray(b[prop])) {
|
351 | throw new TypeError('Arrays are not supported by deepExtend');
|
352 | } else {
|
353 | a[prop] = b[prop];
|
354 | }
|
355 | }
|
356 | }
|
357 | }
|
358 | return a;
|
359 | };
|
360 |
|
361 | |
362 |
|
363 |
|
364 |
|
365 |
|
366 |
|
367 | exports.deepExtend = function(a, b) {
|
368 |
|
369 | if (Array.isArray(b)) {
|
370 | throw new TypeError('Arrays are not supported by deepExtend');
|
371 | }
|
372 |
|
373 | for (var prop in b) {
|
374 | if (b.hasOwnProperty(prop)) {
|
375 | if (b[prop] && b[prop].constructor === Object) {
|
376 | if (a[prop] === undefined) {
|
377 | a[prop] = {};
|
378 | }
|
379 | if (a[prop].constructor === Object) {
|
380 | exports.deepExtend(a[prop], b[prop]);
|
381 | }
|
382 | else {
|
383 | a[prop] = b[prop];
|
384 | }
|
385 | } else if (Array.isArray(b[prop])) {
|
386 | throw new TypeError('Arrays are not supported by deepExtend');
|
387 | } else {
|
388 | a[prop] = b[prop];
|
389 | }
|
390 | }
|
391 | }
|
392 | return a;
|
393 | };
|
394 |
|
395 | |
396 |
|
397 |
|
398 |
|
399 |
|
400 |
|
401 |
|
402 | exports.equalArray = function (a, b) {
|
403 | if (a.length != b.length) return false;
|
404 |
|
405 | for (var i = 0, len = a.length; i < len; i++) {
|
406 | if (a[i] != b[i]) return false;
|
407 | }
|
408 |
|
409 | return true;
|
410 | };
|
411 |
|
412 | |
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 |
|
419 |
|
420 |
|
421 | exports.convert = function(object, type) {
|
422 | var match;
|
423 |
|
424 | if (object === undefined) {
|
425 | return undefined;
|
426 | }
|
427 | if (object === null) {
|
428 | return null;
|
429 | }
|
430 |
|
431 | if (!type) {
|
432 | return object;
|
433 | }
|
434 | if (!(typeof type === 'string') && !(type instanceof String)) {
|
435 | throw new Error('Type must be a string');
|
436 | }
|
437 |
|
438 |
|
439 | switch (type) {
|
440 | case 'boolean':
|
441 | case 'Boolean':
|
442 | return Boolean(object);
|
443 |
|
444 | case 'number':
|
445 | case 'Number':
|
446 | return Number(object.valueOf());
|
447 |
|
448 | case 'string':
|
449 | case 'String':
|
450 | return String(object);
|
451 |
|
452 | case 'Date':
|
453 | if (exports.isNumber(object)) {
|
454 | return new Date(object);
|
455 | }
|
456 | if (object instanceof Date) {
|
457 | return new Date(object.valueOf());
|
458 | }
|
459 | else if (moment.isMoment(object)) {
|
460 | return new Date(object.valueOf());
|
461 | }
|
462 | if (exports.isString(object)) {
|
463 | match = ASPDateRegex.exec(object);
|
464 | if (match) {
|
465 |
|
466 | return new Date(Number(match[1]));
|
467 | }
|
468 | else {
|
469 | return moment(object).toDate();
|
470 | }
|
471 | }
|
472 | else {
|
473 | throw new Error(
|
474 | 'Cannot convert object of type ' + exports.getType(object) +
|
475 | ' to type Date');
|
476 | }
|
477 |
|
478 | case 'Moment':
|
479 | if (exports.isNumber(object)) {
|
480 | return moment(object);
|
481 | }
|
482 | if (object instanceof Date) {
|
483 | return moment(object.valueOf());
|
484 | }
|
485 | else if (moment.isMoment(object)) {
|
486 | return moment(object);
|
487 | }
|
488 | if (exports.isString(object)) {
|
489 | match = ASPDateRegex.exec(object);
|
490 | if (match) {
|
491 |
|
492 | return moment(Number(match[1]));
|
493 | }
|
494 | else {
|
495 | return moment(object);
|
496 | }
|
497 | }
|
498 | else {
|
499 | throw new Error(
|
500 | 'Cannot convert object of type ' + exports.getType(object) +
|
501 | ' to type Date');
|
502 | }
|
503 |
|
504 | case 'ISODate':
|
505 | if (exports.isNumber(object)) {
|
506 | return new Date(object);
|
507 | }
|
508 | else if (object instanceof Date) {
|
509 | return object.toISOString();
|
510 | }
|
511 | else if (moment.isMoment(object)) {
|
512 | return object.toDate().toISOString();
|
513 | }
|
514 | else if (exports.isString(object)) {
|
515 | match = ASPDateRegex.exec(object);
|
516 | if (match) {
|
517 |
|
518 | return new Date(Number(match[1])).toISOString();
|
519 | }
|
520 | else {
|
521 | return new Date(object).toISOString();
|
522 | }
|
523 | }
|
524 | else {
|
525 | throw new Error(
|
526 | 'Cannot convert object of type ' + exports.getType(object) +
|
527 | ' to type ISODate');
|
528 | }
|
529 |
|
530 | case 'ASPDate':
|
531 | if (exports.isNumber(object)) {
|
532 | return '/Date(' + object + ')/';
|
533 | }
|
534 | else if (object instanceof Date) {
|
535 | return '/Date(' + object.valueOf() + ')/';
|
536 | }
|
537 | else if (exports.isString(object)) {
|
538 | match = ASPDateRegex.exec(object);
|
539 | var value;
|
540 | if (match) {
|
541 |
|
542 | value = new Date(Number(match[1])).valueOf();
|
543 | }
|
544 | else {
|
545 | value = new Date(object).valueOf();
|
546 | }
|
547 | return '/Date(' + value + ')/';
|
548 | }
|
549 | else {
|
550 | throw new Error(
|
551 | 'Cannot convert object of type ' + exports.getType(object) +
|
552 | ' to type ASPDate');
|
553 | }
|
554 |
|
555 | default:
|
556 | throw new Error('Unknown type "' + type + '"');
|
557 | }
|
558 | };
|
559 |
|
560 |
|
561 |
|
562 |
|
563 | var ASPDateRegex = /^\/?Date\((\-?\d+)/i;
|
564 |
|
565 | |
566 |
|
567 |
|
568 |
|
569 |
|
570 | exports.getType = function(object) {
|
571 | var type = typeof object;
|
572 |
|
573 | if (type == 'object') {
|
574 | if (object == null) {
|
575 | return 'null';
|
576 | }
|
577 | if (object instanceof Boolean) {
|
578 | return 'Boolean';
|
579 | }
|
580 | if (object instanceof Number) {
|
581 | return 'Number';
|
582 | }
|
583 | if (object instanceof String) {
|
584 | return 'String';
|
585 | }
|
586 | if (object instanceof Array) {
|
587 | return 'Array';
|
588 | }
|
589 | if (object instanceof Date) {
|
590 | return 'Date';
|
591 | }
|
592 | return 'Object';
|
593 | }
|
594 | else if (type == 'number') {
|
595 | return 'Number';
|
596 | }
|
597 | else if (type == 'boolean') {
|
598 | return 'Boolean';
|
599 | }
|
600 | else if (type == 'string') {
|
601 | return 'String';
|
602 | }
|
603 |
|
604 | return type;
|
605 | };
|
606 |
|
607 | |
608 |
|
609 |
|
610 |
|
611 |
|
612 |
|
613 | exports.getAbsoluteLeft = function(elem) {
|
614 | return elem.getBoundingClientRect().left + window.pageXOffset;
|
615 | };
|
616 |
|
617 | |
618 |
|
619 |
|
620 |
|
621 |
|
622 |
|
623 | exports.getAbsoluteTop = function(elem) {
|
624 | return elem.getBoundingClientRect().top + window.pageYOffset;
|
625 | };
|
626 |
|
627 | |
628 |
|
629 |
|
630 |
|
631 |
|
632 | exports.addClassName = function(elem, className) {
|
633 | var classes = elem.className.split(' ');
|
634 | if (classes.indexOf(className) == -1) {
|
635 | classes.push(className);
|
636 | elem.className = classes.join(' ');
|
637 | }
|
638 | };
|
639 |
|
640 | |
641 |
|
642 |
|
643 |
|
644 |
|
645 | exports.removeClassName = function(elem, className) {
|
646 | var classes = elem.className.split(' ');
|
647 | var index = classes.indexOf(className);
|
648 | if (index != -1) {
|
649 | classes.splice(index, 1);
|
650 | elem.className = classes.join(' ');
|
651 | }
|
652 | };
|
653 |
|
654 | |
655 |
|
656 |
|
657 |
|
658 |
|
659 |
|
660 |
|
661 |
|
662 |
|
663 | exports.forEach = function(object, callback) {
|
664 | var i,
|
665 | len;
|
666 | if (object instanceof Array) {
|
667 |
|
668 | for (i = 0, len = object.length; i < len; i++) {
|
669 | callback(object[i], i, object);
|
670 | }
|
671 | }
|
672 | else {
|
673 |
|
674 | for (i in object) {
|
675 | if (object.hasOwnProperty(i)) {
|
676 | callback(object[i], i, object);
|
677 | }
|
678 | }
|
679 | }
|
680 | };
|
681 |
|
682 | |
683 |
|
684 |
|
685 |
|
686 |
|
687 |
|
688 | exports.toArray = function(object) {
|
689 | var array = [];
|
690 |
|
691 | for (var prop in object) {
|
692 | if (object.hasOwnProperty(prop)) array.push(object[prop]);
|
693 | }
|
694 |
|
695 | return array;
|
696 | }
|
697 |
|
698 | |
699 |
|
700 |
|
701 |
|
702 |
|
703 |
|
704 |
|
705 | exports.updateProperty = function(object, key, value) {
|
706 | if (object[key] !== value) {
|
707 | object[key] = value;
|
708 | return true;
|
709 | }
|
710 | else {
|
711 | return false;
|
712 | }
|
713 | };
|
714 |
|
715 | |
716 |
|
717 |
|
718 |
|
719 |
|
720 |
|
721 |
|
722 |
|
723 | exports.addEventListener = function(element, action, listener, useCapture) {
|
724 | if (element.addEventListener) {
|
725 | if (useCapture === undefined)
|
726 | useCapture = false;
|
727 |
|
728 | if (action === "mousewheel" && navigator.userAgent.indexOf("Firefox") >= 0) {
|
729 | action = "DOMMouseScroll";
|
730 | }
|
731 |
|
732 | element.addEventListener(action, listener, useCapture);
|
733 | } else {
|
734 | element.attachEvent("on" + action, listener);
|
735 | }
|
736 | };
|
737 |
|
738 | |
739 |
|
740 |
|
741 |
|
742 |
|
743 |
|
744 |
|
745 | exports.removeEventListener = function(element, action, listener, useCapture) {
|
746 | if (element.removeEventListener) {
|
747 |
|
748 | if (useCapture === undefined)
|
749 | useCapture = false;
|
750 |
|
751 | if (action === "mousewheel" && navigator.userAgent.indexOf("Firefox") >= 0) {
|
752 | action = "DOMMouseScroll";
|
753 | }
|
754 |
|
755 | element.removeEventListener(action, listener, useCapture);
|
756 | } else {
|
757 |
|
758 | element.detachEvent("on" + action, listener);
|
759 | }
|
760 | };
|
761 |
|
762 | |
763 |
|
764 |
|
765 | exports.preventDefault = function (event) {
|
766 | if (!event)
|
767 | event = window.event;
|
768 |
|
769 | if (event.preventDefault) {
|
770 | event.preventDefault();
|
771 | }
|
772 | else {
|
773 | event.returnValue = false;
|
774 | }
|
775 | };
|
776 |
|
777 | |
778 |
|
779 |
|
780 |
|
781 |
|
782 | exports.getTarget = function(event) {
|
783 |
|
784 | if (!event) {
|
785 | event = window.event;
|
786 | }
|
787 |
|
788 | var target;
|
789 |
|
790 | if (event.target) {
|
791 | target = event.target;
|
792 | }
|
793 | else if (event.srcElement) {
|
794 | target = event.srcElement;
|
795 | }
|
796 |
|
797 | if (target.nodeType != undefined && target.nodeType == 3) {
|
798 |
|
799 | target = target.parentNode;
|
800 | }
|
801 |
|
802 | return target;
|
803 | };
|
804 |
|
805 | exports.option = {};
|
806 |
|
807 | |
808 |
|
809 |
|
810 |
|
811 |
|
812 |
|
813 | exports.option.asBoolean = function (value, defaultValue) {
|
814 | if (typeof value == 'function') {
|
815 | value = value();
|
816 | }
|
817 |
|
818 | if (value != null) {
|
819 | return (value != false);
|
820 | }
|
821 |
|
822 | return defaultValue || null;
|
823 | };
|
824 |
|
825 | |
826 |
|
827 |
|
828 |
|
829 |
|
830 |
|
831 | exports.option.asNumber = function (value, defaultValue) {
|
832 | if (typeof value == 'function') {
|
833 | value = value();
|
834 | }
|
835 |
|
836 | if (value != null) {
|
837 | return Number(value) || defaultValue || null;
|
838 | }
|
839 |
|
840 | return defaultValue || null;
|
841 | };
|
842 |
|
843 | |
844 |
|
845 |
|
846 |
|
847 |
|
848 |
|
849 | exports.option.asString = function (value, defaultValue) {
|
850 | if (typeof value == 'function') {
|
851 | value = value();
|
852 | }
|
853 |
|
854 | if (value != null) {
|
855 | return String(value);
|
856 | }
|
857 |
|
858 | return defaultValue || null;
|
859 | };
|
860 |
|
861 | |
862 |
|
863 |
|
864 |
|
865 |
|
866 |
|
867 | exports.option.asSize = function (value, defaultValue) {
|
868 | if (typeof value == 'function') {
|
869 | value = value();
|
870 | }
|
871 |
|
872 | if (exports.isString(value)) {
|
873 | return value;
|
874 | }
|
875 | else if (exports.isNumber(value)) {
|
876 | return value + 'px';
|
877 | }
|
878 | else {
|
879 | return defaultValue || null;
|
880 | }
|
881 | };
|
882 |
|
883 | |
884 |
|
885 |
|
886 |
|
887 |
|
888 |
|
889 | exports.option.asElement = function (value, defaultValue) {
|
890 | if (typeof value == 'function') {
|
891 | value = value();
|
892 | }
|
893 |
|
894 | return value || defaultValue || null;
|
895 | };
|
896 |
|
897 |
|
898 |
|
899 | exports.GiveDec = function(Hex) {
|
900 | var Value;
|
901 |
|
902 | if (Hex == "A")
|
903 | Value = 10;
|
904 | else if (Hex == "B")
|
905 | Value = 11;
|
906 | else if (Hex == "C")
|
907 | Value = 12;
|
908 | else if (Hex == "D")
|
909 | Value = 13;
|
910 | else if (Hex == "E")
|
911 | Value = 14;
|
912 | else if (Hex == "F")
|
913 | Value = 15;
|
914 | else
|
915 | Value = eval(Hex);
|
916 |
|
917 | return Value;
|
918 | };
|
919 |
|
920 | exports.GiveHex = function(Dec) {
|
921 | var Value;
|
922 |
|
923 | if(Dec == 10)
|
924 | Value = "A";
|
925 | else if (Dec == 11)
|
926 | Value = "B";
|
927 | else if (Dec == 12)
|
928 | Value = "C";
|
929 | else if (Dec == 13)
|
930 | Value = "D";
|
931 | else if (Dec == 14)
|
932 | Value = "E";
|
933 | else if (Dec == 15)
|
934 | Value = "F";
|
935 | else
|
936 | Value = "" + Dec;
|
937 |
|
938 | return Value;
|
939 | };
|
940 |
|
941 | |
942 |
|
943 |
|
944 |
|
945 |
|
946 |
|
947 | exports.parseColor = function(color) {
|
948 | var c;
|
949 | if (exports.isString(color)) {
|
950 | if (exports.isValidRGB(color)) {
|
951 | var rgb = color.substr(4).substr(0,color.length-5).split(',');
|
952 | color = exports.RGBToHex(rgb[0],rgb[1],rgb[2]);
|
953 | }
|
954 | if (exports.isValidHex(color)) {
|
955 | var hsv = exports.hexToHSV(color);
|
956 | var lighterColorHSV = {h:hsv.h,s:hsv.s * 0.45,v:Math.min(1,hsv.v * 1.05)};
|
957 | var darkerColorHSV = {h:hsv.h,s:Math.min(1,hsv.v * 1.25),v:hsv.v*0.6};
|
958 | var darkerColorHex = exports.HSVToHex(darkerColorHSV.h ,darkerColorHSV.h ,darkerColorHSV.v);
|
959 | var lighterColorHex = exports.HSVToHex(lighterColorHSV.h,lighterColorHSV.s,lighterColorHSV.v);
|
960 |
|
961 | c = {
|
962 | background: color,
|
963 | border:darkerColorHex,
|
964 | highlight: {
|
965 | background:lighterColorHex,
|
966 | border:darkerColorHex
|
967 | },
|
968 | hover: {
|
969 | background:lighterColorHex,
|
970 | border:darkerColorHex
|
971 | }
|
972 | };
|
973 | }
|
974 | else {
|
975 | c = {
|
976 | background:color,
|
977 | border:color,
|
978 | highlight: {
|
979 | background:color,
|
980 | border:color
|
981 | },
|
982 | hover: {
|
983 | background:color,
|
984 | border:color
|
985 | }
|
986 | };
|
987 | }
|
988 | }
|
989 | else {
|
990 | c = {};
|
991 | c.background = color.background || 'white';
|
992 | c.border = color.border || c.background;
|
993 |
|
994 | if (exports.isString(color.highlight)) {
|
995 | c.highlight = {
|
996 | border: color.highlight,
|
997 | background: color.highlight
|
998 | }
|
999 | }
|
1000 | else {
|
1001 | c.highlight = {};
|
1002 | c.highlight.background = color.highlight && color.highlight.background || c.background;
|
1003 | c.highlight.border = color.highlight && color.highlight.border || c.border;
|
1004 | }
|
1005 |
|
1006 | if (exports.isString(color.hover)) {
|
1007 | c.hover = {
|
1008 | border: color.hover,
|
1009 | background: color.hover
|
1010 | }
|
1011 | }
|
1012 | else {
|
1013 | c.hover = {};
|
1014 | c.hover.background = color.hover && color.hover.background || c.background;
|
1015 | c.hover.border = color.hover && color.hover.border || c.border;
|
1016 | }
|
1017 | }
|
1018 |
|
1019 | return c;
|
1020 | };
|
1021 |
|
1022 | |
1023 |
|
1024 |
|
1025 |
|
1026 |
|
1027 |
|
1028 | exports.hexToRGB = function(hex) {
|
1029 | hex = hex.replace("#","").toUpperCase();
|
1030 |
|
1031 | var a = exports.GiveDec(hex.substring(0, 1));
|
1032 | var b = exports.GiveDec(hex.substring(1, 2));
|
1033 | var c = exports.GiveDec(hex.substring(2, 3));
|
1034 | var d = exports.GiveDec(hex.substring(3, 4));
|
1035 | var e = exports.GiveDec(hex.substring(4, 5));
|
1036 | var f = exports.GiveDec(hex.substring(5, 6));
|
1037 |
|
1038 | var r = (a * 16) + b;
|
1039 | var g = (c * 16) + d;
|
1040 | var b = (e * 16) + f;
|
1041 |
|
1042 | return {r:r,g:g,b:b};
|
1043 | };
|
1044 |
|
1045 | exports.RGBToHex = function(red,green,blue) {
|
1046 | var a = exports.GiveHex(Math.floor(red / 16));
|
1047 | var b = exports.GiveHex(red % 16);
|
1048 | var c = exports.GiveHex(Math.floor(green / 16));
|
1049 | var d = exports.GiveHex(green % 16);
|
1050 | var e = exports.GiveHex(Math.floor(blue / 16));
|
1051 | var f = exports.GiveHex(blue % 16);
|
1052 |
|
1053 | var hex = a + b + c + d + e + f;
|
1054 | return "#" + hex;
|
1055 | };
|
1056 |
|
1057 |
|
1058 | |
1059 |
|
1060 |
|
1061 |
|
1062 |
|
1063 |
|
1064 |
|
1065 |
|
1066 |
|
1067 | exports.RGBToHSV = function(red,green,blue) {
|
1068 | red=red/255; green=green/255; blue=blue/255;
|
1069 | var minRGB = Math.min(red,Math.min(green,blue));
|
1070 | var maxRGB = Math.max(red,Math.max(green,blue));
|
1071 |
|
1072 |
|
1073 | if (minRGB == maxRGB) {
|
1074 | return {h:0,s:0,v:minRGB};
|
1075 | }
|
1076 |
|
1077 |
|
1078 | var d = (red==minRGB) ? green-blue : ((blue==minRGB) ? red-green : blue-red);
|
1079 | var h = (red==minRGB) ? 3 : ((blue==minRGB) ? 1 : 5);
|
1080 | var hue = 60*(h - d/(maxRGB - minRGB))/360;
|
1081 | var saturation = (maxRGB - minRGB)/maxRGB;
|
1082 | var value = maxRGB;
|
1083 | return {h:hue,s:saturation,v:value};
|
1084 | };
|
1085 |
|
1086 |
|
1087 | |
1088 |
|
1089 |
|
1090 |
|
1091 |
|
1092 |
|
1093 |
|
1094 |
|
1095 | exports.HSVToRGB = function(h, s, v) {
|
1096 | var r, g, b;
|
1097 |
|
1098 | var i = Math.floor(h * 6);
|
1099 | var f = h * 6 - i;
|
1100 | var p = v * (1 - s);
|
1101 | var q = v * (1 - f * s);
|
1102 | var t = v * (1 - (1 - f) * s);
|
1103 |
|
1104 | switch (i % 6) {
|
1105 | case 0: r = v, g = t, b = p; break;
|
1106 | case 1: r = q, g = v, b = p; break;
|
1107 | case 2: r = p, g = v, b = t; break;
|
1108 | case 3: r = p, g = q, b = v; break;
|
1109 | case 4: r = t, g = p, b = v; break;
|
1110 | case 5: r = v, g = p, b = q; break;
|
1111 | }
|
1112 |
|
1113 | return {r:Math.floor(r * 255), g:Math.floor(g * 255), b:Math.floor(b * 255) };
|
1114 | };
|
1115 |
|
1116 | exports.HSVToHex = function(h, s, v) {
|
1117 | var rgb = exports.HSVToRGB(h, s, v);
|
1118 | return exports.RGBToHex(rgb.r, rgb.g, rgb.b);
|
1119 | };
|
1120 |
|
1121 | exports.hexToHSV = function(hex) {
|
1122 | var rgb = exports.hexToRGB(hex);
|
1123 | return exports.RGBToHSV(rgb.r, rgb.g, rgb.b);
|
1124 | };
|
1125 |
|
1126 | exports.isValidHex = function(hex) {
|
1127 | var isOk = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(hex);
|
1128 | return isOk;
|
1129 | };
|
1130 |
|
1131 | exports.isValidRGB = function(rgb) {
|
1132 | rgb = rgb.replace(" ","");
|
1133 | var isOk = /rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/i.test(rgb);
|
1134 | return isOk;
|
1135 | }
|
1136 |
|
1137 | |
1138 |
|
1139 |
|
1140 |
|
1141 |
|
1142 |
|
1143 |
|
1144 | exports.selectiveBridgeObject = function(fields, referenceObject) {
|
1145 | if (typeof referenceObject == "object") {
|
1146 | var objectTo = Object.create(referenceObject);
|
1147 | for (var i = 0; i < fields.length; i++) {
|
1148 | if (referenceObject.hasOwnProperty(fields[i])) {
|
1149 | if (typeof referenceObject[fields[i]] == "object") {
|
1150 | objectTo[fields[i]] = exports.bridgeObject(referenceObject[fields[i]]);
|
1151 | }
|
1152 | }
|
1153 | }
|
1154 | return objectTo;
|
1155 | }
|
1156 | else {
|
1157 | return null;
|
1158 | }
|
1159 | };
|
1160 |
|
1161 | |
1162 |
|
1163 |
|
1164 |
|
1165 |
|
1166 |
|
1167 |
|
1168 | exports.bridgeObject = function(referenceObject) {
|
1169 | if (typeof referenceObject == "object") {
|
1170 | var objectTo = Object.create(referenceObject);
|
1171 | for (var i in referenceObject) {
|
1172 | if (referenceObject.hasOwnProperty(i)) {
|
1173 | if (typeof referenceObject[i] == "object") {
|
1174 | objectTo[i] = exports.bridgeObject(referenceObject[i]);
|
1175 | }
|
1176 | }
|
1177 | }
|
1178 | return objectTo;
|
1179 | }
|
1180 | else {
|
1181 | return null;
|
1182 | }
|
1183 | };
|
1184 |
|
1185 |
|
1186 | |
1187 |
|
1188 |
|
1189 |
|
1190 |
|
1191 |
|
1192 |
|
1193 |
|
1194 |
|
1195 | exports.mergeOptions = function (mergeTarget, options, option) {
|
1196 | if (options[option] !== undefined) {
|
1197 | if (typeof options[option] == 'boolean') {
|
1198 | mergeTarget[option].enabled = options[option];
|
1199 | }
|
1200 | else {
|
1201 | mergeTarget[option].enabled = true;
|
1202 | for (prop in options[option]) {
|
1203 | if (options[option].hasOwnProperty(prop)) {
|
1204 | mergeTarget[option][prop] = options[option][prop];
|
1205 | }
|
1206 | }
|
1207 | }
|
1208 | }
|
1209 | }
|
1210 |
|
1211 |
|
1212 | |
1213 |
|
1214 |
|
1215 |
|
1216 |
|
1217 |
|
1218 |
|
1219 |
|
1220 |
|
1221 | exports.mergeOptions = function (mergeTarget, options, option) {
|
1222 | if (options[option] !== undefined) {
|
1223 | if (typeof options[option] == 'boolean') {
|
1224 | mergeTarget[option].enabled = options[option];
|
1225 | }
|
1226 | else {
|
1227 | mergeTarget[option].enabled = true;
|
1228 | for (prop in options[option]) {
|
1229 | if (options[option].hasOwnProperty(prop)) {
|
1230 | mergeTarget[option][prop] = options[option][prop];
|
1231 | }
|
1232 | }
|
1233 | }
|
1234 | }
|
1235 | }
|
1236 |
|
1237 |
|
1238 |
|
1239 |
|
1240 | |
1241 |
|
1242 |
|
1243 |
|
1244 |
|
1245 |
|
1246 |
|
1247 |
|
1248 |
|
1249 |
|
1250 |
|
1251 |
|
1252 |
|
1253 |
|
1254 |
|
1255 |
|
1256 |
|
1257 | exports.binarySearch = function(orderedItems, range, field, field2) {
|
1258 | var array = orderedItems;
|
1259 |
|
1260 | var maxIterations = 10000;
|
1261 | var iteration = 0;
|
1262 | var found = false;
|
1263 | var low = 0;
|
1264 | var high = array.length;
|
1265 | var newLow = low;
|
1266 | var newHigh = high;
|
1267 | var guess = Math.floor(0.5*(high+low));
|
1268 | var value;
|
1269 |
|
1270 | if (high == 0) {
|
1271 | guess = -1;
|
1272 | }
|
1273 | else if (high == 1) {
|
1274 | if (array[guess].isVisible(range)) {
|
1275 | guess = 0;
|
1276 | }
|
1277 | else {
|
1278 | guess = -1;
|
1279 | }
|
1280 | }
|
1281 | else {
|
1282 | high -= 1;
|
1283 |
|
1284 | while (found == false && iteration < maxIterations) {
|
1285 | value = field2 === undefined ? array[guess][field] : array[guess][field][field2];
|
1286 |
|
1287 | if (array[guess].isVisible(range)) {
|
1288 | found = true;
|
1289 | }
|
1290 | else {
|
1291 | if (value < range.start) {
|
1292 | newLow = Math.floor(0.5*(high+low));
|
1293 | }
|
1294 | else {
|
1295 | newHigh = Math.floor(0.5*(high+low));
|
1296 | }
|
1297 |
|
1298 | if (low == newLow && high == newHigh) {
|
1299 | guess = -1;
|
1300 | found = true;
|
1301 | }
|
1302 | else {
|
1303 | high = newHigh; low = newLow;
|
1304 | guess = Math.floor(0.5*(high+low));
|
1305 | }
|
1306 | }
|
1307 | iteration++;
|
1308 | }
|
1309 | if (iteration >= maxIterations) {
|
1310 | console.log("BinarySearch too many iterations. Aborting.");
|
1311 | }
|
1312 | }
|
1313 | return guess;
|
1314 | };
|
1315 |
|
1316 | |
1317 |
|
1318 |
|
1319 |
|
1320 |
|
1321 |
|
1322 |
|
1323 |
|
1324 |
|
1325 |
|
1326 |
|
1327 |
|
1328 |
|
1329 |
|
1330 |
|
1331 |
|
1332 |
|
1333 | exports.binarySearchGeneric = function(orderedItems, target, field, sidePreference) {
|
1334 | var maxIterations = 10000;
|
1335 | var iteration = 0;
|
1336 | var array = orderedItems;
|
1337 | var found = false;
|
1338 | var low = 0;
|
1339 | var high = array.length;
|
1340 | var newLow = low;
|
1341 | var newHigh = high;
|
1342 | var guess = Math.floor(0.5*(high+low));
|
1343 | var newGuess;
|
1344 | var prevValue, value, nextValue;
|
1345 |
|
1346 | if (high == 0) {guess = -1;}
|
1347 | else if (high == 1) {
|
1348 | value = array[guess][field];
|
1349 | if (value == target) {
|
1350 | guess = 0;
|
1351 | }
|
1352 | else {
|
1353 | guess = -1;
|
1354 | }
|
1355 | }
|
1356 | else {
|
1357 | high -= 1;
|
1358 | while (found == false && iteration < maxIterations) {
|
1359 | prevValue = array[Math.max(0,guess - 1)][field];
|
1360 | value = array[guess][field];
|
1361 | nextValue = array[Math.min(array.length-1,guess + 1)][field];
|
1362 |
|
1363 | if (value == target || prevValue < target && value > target || value < target && nextValue > target) {
|
1364 | found = true;
|
1365 | if (value != target) {
|
1366 | if (sidePreference == 'before') {
|
1367 | if (prevValue < target && value > target) {
|
1368 | guess = Math.max(0,guess - 1);
|
1369 | }
|
1370 | }
|
1371 | else {
|
1372 | if (value < target && nextValue > target) {
|
1373 | guess = Math.min(array.length-1,guess + 1);
|
1374 | }
|
1375 | }
|
1376 | }
|
1377 | }
|
1378 | else {
|
1379 | if (value < target) {
|
1380 | newLow = Math.floor(0.5*(high+low));
|
1381 | }
|
1382 | else {
|
1383 | newHigh = Math.floor(0.5*(high+low));
|
1384 | }
|
1385 | newGuess = Math.floor(0.5*(high+low));
|
1386 |
|
1387 | if (low == newLow && high == newHigh) {
|
1388 | guess = -1;
|
1389 | found = true;
|
1390 | }
|
1391 | else {
|
1392 | high = newHigh; low = newLow;
|
1393 | guess = Math.floor(0.5*(high+low));
|
1394 | }
|
1395 | }
|
1396 | iteration++;
|
1397 | }
|
1398 | if (iteration >= maxIterations) {
|
1399 | console.log("BinarySearch too many iterations. Aborting.");
|
1400 | }
|
1401 | }
|
1402 | return guess;
|
1403 | };
|
1404 |
|
1405 | |
1406 |
|
1407 |
|
1408 |
|
1409 |
|
1410 |
|
1411 |
|
1412 |
|
1413 |
|
1414 | exports.easeInOutQuad = function (t, start, end, duration) {
|
1415 | var change = end - start;
|
1416 | t /= duration/2;
|
1417 | if (t < 1) return change/2*t*t + start;
|
1418 | t--;
|
1419 | return -change/2 * (t*(t-2) - 1) + start;
|
1420 | };
|
1421 |
|
1422 |
|
1423 |
|
1424 | |
1425 |
|
1426 |
|
1427 |
|
1428 |
|
1429 | exports.easingFunctions = {
|
1430 |
|
1431 | linear: function (t) {
|
1432 | return t
|
1433 | },
|
1434 |
|
1435 | easeInQuad: function (t) {
|
1436 | return t * t
|
1437 | },
|
1438 |
|
1439 | easeOutQuad: function (t) {
|
1440 | return t * (2 - t)
|
1441 | },
|
1442 |
|
1443 | easeInOutQuad: function (t) {
|
1444 | return t < .5 ? 2 * t * t : -1 + (4 - 2 * t) * t
|
1445 | },
|
1446 |
|
1447 | easeInCubic: function (t) {
|
1448 | return t * t * t
|
1449 | },
|
1450 |
|
1451 | easeOutCubic: function (t) {
|
1452 | return (--t) * t * t + 1
|
1453 | },
|
1454 |
|
1455 | easeInOutCubic: function (t) {
|
1456 | return t < .5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1
|
1457 | },
|
1458 |
|
1459 | easeInQuart: function (t) {
|
1460 | return t * t * t * t
|
1461 | },
|
1462 |
|
1463 | easeOutQuart: function (t) {
|
1464 | return 1 - (--t) * t * t * t
|
1465 | },
|
1466 |
|
1467 | easeInOutQuart: function (t) {
|
1468 | return t < .5 ? 8 * t * t * t * t : 1 - 8 * (--t) * t * t * t
|
1469 | },
|
1470 |
|
1471 | easeInQuint: function (t) {
|
1472 | return t * t * t * t * t
|
1473 | },
|
1474 |
|
1475 | easeOutQuint: function (t) {
|
1476 | return 1 + (--t) * t * t * t * t
|
1477 | },
|
1478 |
|
1479 | easeInOutQuint: function (t) {
|
1480 | return t < .5 ? 16 * t * t * t * t * t : 1 + 16 * (--t) * t * t * t * t
|
1481 | }
|
1482 | };
|
1483 |
|
1484 | },
|
1485 |
|
1486 | function(module, exports, __webpack_require__) {
|
1487 |
|
1488 |
|
1489 |
|
1490 | |
1491 |
|
1492 |
|
1493 |
|
1494 |
|
1495 | exports.prepareElements = function(JSONcontainer) {
|
1496 |
|
1497 | for (var elementType in JSONcontainer) {
|
1498 | if (JSONcontainer.hasOwnProperty(elementType)) {
|
1499 | JSONcontainer[elementType].redundant = JSONcontainer[elementType].used;
|
1500 | JSONcontainer[elementType].used = [];
|
1501 | }
|
1502 | }
|
1503 | };
|
1504 |
|
1505 | |
1506 |
|
1507 |
|
1508 |
|
1509 |
|
1510 |
|
1511 |
|
1512 | exports.cleanupElements = function(JSONcontainer) {
|
1513 |
|
1514 | for (var elementType in JSONcontainer) {
|
1515 | if (JSONcontainer.hasOwnProperty(elementType)) {
|
1516 | if (JSONcontainer[elementType].redundant) {
|
1517 | for (var i = 0; i < JSONcontainer[elementType].redundant.length; i++) {
|
1518 | JSONcontainer[elementType].redundant[i].parentNode.removeChild(JSONcontainer[elementType].redundant[i]);
|
1519 | }
|
1520 | JSONcontainer[elementType].redundant = [];
|
1521 | }
|
1522 | }
|
1523 | }
|
1524 | };
|
1525 |
|
1526 | |
1527 |
|
1528 |
|
1529 |
|
1530 |
|
1531 |
|
1532 |
|
1533 |
|
1534 |
|
1535 |
|
1536 | exports.getSVGElement = function (elementType, JSONcontainer, svgContainer) {
|
1537 | var element;
|
1538 |
|
1539 | if (JSONcontainer.hasOwnProperty(elementType)) {
|
1540 |
|
1541 | if (JSONcontainer[elementType].redundant.length > 0) {
|
1542 | element = JSONcontainer[elementType].redundant[0];
|
1543 | JSONcontainer[elementType].redundant.shift();
|
1544 | }
|
1545 | else {
|
1546 |
|
1547 | element = document.createElementNS('http://www.w3.org/2000/svg', elementType);
|
1548 | svgContainer.appendChild(element);
|
1549 | }
|
1550 | }
|
1551 | else {
|
1552 |
|
1553 | element = document.createElementNS('http://www.w3.org/2000/svg', elementType);
|
1554 | JSONcontainer[elementType] = {used: [], redundant: []};
|
1555 | svgContainer.appendChild(element);
|
1556 | }
|
1557 | JSONcontainer[elementType].used.push(element);
|
1558 | return element;
|
1559 | };
|
1560 |
|
1561 |
|
1562 | |
1563 |
|
1564 |
|
1565 |
|
1566 |
|
1567 |
|
1568 |
|
1569 |
|
1570 |
|
1571 |
|
1572 | exports.getDOMElement = function (elementType, JSONcontainer, DOMContainer, insertBefore) {
|
1573 | var element;
|
1574 |
|
1575 | if (JSONcontainer.hasOwnProperty(elementType)) {
|
1576 |
|
1577 | if (JSONcontainer[elementType].redundant.length > 0) {
|
1578 | element = JSONcontainer[elementType].redundant[0];
|
1579 | JSONcontainer[elementType].redundant.shift();
|
1580 | }
|
1581 | else {
|
1582 |
|
1583 | element = document.createElement(elementType);
|
1584 | if (insertBefore !== undefined) {
|
1585 | DOMContainer.insertBefore(element, insertBefore);
|
1586 | }
|
1587 | else {
|
1588 | DOMContainer.appendChild(element);
|
1589 | }
|
1590 | }
|
1591 | }
|
1592 | else {
|
1593 |
|
1594 | element = document.createElement(elementType);
|
1595 | JSONcontainer[elementType] = {used: [], redundant: []};
|
1596 | if (insertBefore !== undefined) {
|
1597 | DOMContainer.insertBefore(element, insertBefore);
|
1598 | }
|
1599 | else {
|
1600 | DOMContainer.appendChild(element);
|
1601 | }
|
1602 | }
|
1603 | JSONcontainer[elementType].used.push(element);
|
1604 | return element;
|
1605 | };
|
1606 |
|
1607 |
|
1608 |
|
1609 |
|
1610 | |
1611 |
|
1612 |
|
1613 |
|
1614 |
|
1615 |
|
1616 |
|
1617 |
|
1618 |
|
1619 |
|
1620 |
|
1621 |
|
1622 | exports.drawPoint = function(x, y, group, JSONcontainer, svgContainer) {
|
1623 | var point;
|
1624 | if (group.options.drawPoints.style == 'circle') {
|
1625 | point = exports.getSVGElement('circle',JSONcontainer,svgContainer);
|
1626 | point.setAttributeNS(null, "cx", x);
|
1627 | point.setAttributeNS(null, "cy", y);
|
1628 | point.setAttributeNS(null, "r", 0.5 * group.options.drawPoints.size);
|
1629 | point.setAttributeNS(null, "class", group.className + " point");
|
1630 | }
|
1631 | else {
|
1632 | point = exports.getSVGElement('rect',JSONcontainer,svgContainer);
|
1633 | point.setAttributeNS(null, "x", x - 0.5*group.options.drawPoints.size);
|
1634 | point.setAttributeNS(null, "y", y - 0.5*group.options.drawPoints.size);
|
1635 | point.setAttributeNS(null, "width", group.options.drawPoints.size);
|
1636 | point.setAttributeNS(null, "height", group.options.drawPoints.size);
|
1637 | point.setAttributeNS(null, "class", group.className + " point");
|
1638 | }
|
1639 | return point;
|
1640 | };
|
1641 |
|
1642 | |
1643 |
|
1644 |
|
1645 |
|
1646 |
|
1647 |
|
1648 |
|
1649 | exports.drawBar = function (x, y, width, height, className, JSONcontainer, svgContainer) {
|
1650 |
|
1651 | var rect = exports.getSVGElement('rect',JSONcontainer, svgContainer);
|
1652 | rect.setAttributeNS(null, "x", x - 0.5 * width);
|
1653 | rect.setAttributeNS(null, "y", y);
|
1654 | rect.setAttributeNS(null, "width", width);
|
1655 | rect.setAttributeNS(null, "height", height);
|
1656 | rect.setAttributeNS(null, "class", className);
|
1657 |
|
1658 | };
|
1659 |
|
1660 | },
|
1661 |
|
1662 | function(module, exports, __webpack_require__) {
|
1663 |
|
1664 | var util = __webpack_require__(1);
|
1665 |
|
1666 | |
1667 |
|
1668 |
|
1669 |
|
1670 |
|
1671 |
|
1672 |
|
1673 |
|
1674 |
|
1675 |
|
1676 |
|
1677 |
|
1678 |
|
1679 |
|
1680 |
|
1681 |
|
1682 |
|
1683 |
|
1684 |
|
1685 |
|
1686 |
|
1687 |
|
1688 |
|
1689 |
|
1690 |
|
1691 |
|
1692 |
|
1693 |
|
1694 |
|
1695 |
|
1696 |
|
1697 |
|
1698 |
|
1699 |
|
1700 |
|
1701 |
|
1702 |
|
1703 |
|
1704 | function DataSet (data, options) {
|
1705 |
|
1706 | if (data && !Array.isArray(data) && !util.isDataTable(data)) {
|
1707 | options = data;
|
1708 | data = null;
|
1709 | }
|
1710 |
|
1711 | this._options = options || {};
|
1712 | this._data = {};
|
1713 | this._fieldId = this._options.fieldId || 'id';
|
1714 | this._type = {};
|
1715 |
|
1716 |
|
1717 |
|
1718 | if (this._options.type) {
|
1719 | for (var field in this._options.type) {
|
1720 | if (this._options.type.hasOwnProperty(field)) {
|
1721 | var value = this._options.type[field];
|
1722 | if (value == 'Date' || value == 'ISODate' || value == 'ASPDate') {
|
1723 | this._type[field] = 'Date';
|
1724 | }
|
1725 | else {
|
1726 | this._type[field] = value;
|
1727 | }
|
1728 | }
|
1729 | }
|
1730 | }
|
1731 |
|
1732 |
|
1733 | if (this._options.convert) {
|
1734 | throw new Error('Option "convert" is deprecated. Use "type" instead.');
|
1735 | }
|
1736 |
|
1737 | this._subscribers = {};
|
1738 |
|
1739 |
|
1740 | if (data) {
|
1741 | this.add(data);
|
1742 | }
|
1743 | }
|
1744 |
|
1745 | |
1746 |
|
1747 |
|
1748 |
|
1749 |
|
1750 |
|
1751 |
|
1752 |
|
1753 |
|
1754 | DataSet.prototype.on = function(event, callback) {
|
1755 | var subscribers = this._subscribers[event];
|
1756 | if (!subscribers) {
|
1757 | subscribers = [];
|
1758 | this._subscribers[event] = subscribers;
|
1759 | }
|
1760 |
|
1761 | subscribers.push({
|
1762 | callback: callback
|
1763 | });
|
1764 | };
|
1765 |
|
1766 |
|
1767 | DataSet.prototype.subscribe = DataSet.prototype.on;
|
1768 |
|
1769 | |
1770 |
|
1771 |
|
1772 |
|
1773 |
|
1774 | DataSet.prototype.off = function(event, callback) {
|
1775 | var subscribers = this._subscribers[event];
|
1776 | if (subscribers) {
|
1777 | this._subscribers[event] = subscribers.filter(function (listener) {
|
1778 | return (listener.callback != callback);
|
1779 | });
|
1780 | }
|
1781 | };
|
1782 |
|
1783 |
|
1784 | DataSet.prototype.unsubscribe = DataSet.prototype.off;
|
1785 |
|
1786 | |
1787 |
|
1788 |
|
1789 |
|
1790 |
|
1791 |
|
1792 |
|
1793 | DataSet.prototype._trigger = function (event, params, senderId) {
|
1794 | if (event == '*') {
|
1795 | throw new Error('Cannot trigger event *');
|
1796 | }
|
1797 |
|
1798 | var subscribers = [];
|
1799 | if (event in this._subscribers) {
|
1800 | subscribers = subscribers.concat(this._subscribers[event]);
|
1801 | }
|
1802 | if ('*' in this._subscribers) {
|
1803 | subscribers = subscribers.concat(this._subscribers['*']);
|
1804 | }
|
1805 |
|
1806 | for (var i = 0; i < subscribers.length; i++) {
|
1807 | var subscriber = subscribers[i];
|
1808 | if (subscriber.callback) {
|
1809 | subscriber.callback(event, params, senderId || null);
|
1810 | }
|
1811 | }
|
1812 | };
|
1813 |
|
1814 | |
1815 |
|
1816 |
|
1817 |
|
1818 |
|
1819 |
|
1820 |
|
1821 | DataSet.prototype.add = function (data, senderId) {
|
1822 | var addedIds = [],
|
1823 | id,
|
1824 | me = this;
|
1825 |
|
1826 | if (Array.isArray(data)) {
|
1827 |
|
1828 | for (var i = 0, len = data.length; i < len; i++) {
|
1829 | id = me._addItem(data[i]);
|
1830 | addedIds.push(id);
|
1831 | }
|
1832 | }
|
1833 | else if (util.isDataTable(data)) {
|
1834 |
|
1835 | var columns = this._getColumnNames(data);
|
1836 | for (var row = 0, rows = data.getNumberOfRows(); row < rows; row++) {
|
1837 | var item = {};
|
1838 | for (var col = 0, cols = columns.length; col < cols; col++) {
|
1839 | var field = columns[col];
|
1840 | item[field] = data.getValue(row, col);
|
1841 | }
|
1842 |
|
1843 | id = me._addItem(item);
|
1844 | addedIds.push(id);
|
1845 | }
|
1846 | }
|
1847 | else if (data instanceof Object) {
|
1848 |
|
1849 | id = me._addItem(data);
|
1850 | addedIds.push(id);
|
1851 | }
|
1852 | else {
|
1853 | throw new Error('Unknown dataType');
|
1854 | }
|
1855 |
|
1856 | if (addedIds.length) {
|
1857 | this._trigger('add', {items: addedIds}, senderId);
|
1858 | }
|
1859 |
|
1860 | return addedIds;
|
1861 | };
|
1862 |
|
1863 | |
1864 |
|
1865 |
|
1866 |
|
1867 |
|
1868 |
|
1869 | DataSet.prototype.update = function (data, senderId) {
|
1870 | var addedIds = [],
|
1871 | updatedIds = [],
|
1872 | me = this,
|
1873 | fieldId = me._fieldId;
|
1874 |
|
1875 | var addOrUpdate = function (item) {
|
1876 | var id = item[fieldId];
|
1877 | if (me._data[id]) {
|
1878 |
|
1879 | id = me._updateItem(item);
|
1880 | updatedIds.push(id);
|
1881 | }
|
1882 | else {
|
1883 |
|
1884 | id = me._addItem(item);
|
1885 | addedIds.push(id);
|
1886 | }
|
1887 | };
|
1888 |
|
1889 | if (Array.isArray(data)) {
|
1890 |
|
1891 | for (var i = 0, len = data.length; i < len; i++) {
|
1892 | addOrUpdate(data[i]);
|
1893 | }
|
1894 | }
|
1895 | else if (util.isDataTable(data)) {
|
1896 |
|
1897 | var columns = this._getColumnNames(data);
|
1898 | for (var row = 0, rows = data.getNumberOfRows(); row < rows; row++) {
|
1899 | var item = {};
|
1900 | for (var col = 0, cols = columns.length; col < cols; col++) {
|
1901 | var field = columns[col];
|
1902 | item[field] = data.getValue(row, col);
|
1903 | }
|
1904 |
|
1905 | addOrUpdate(item);
|
1906 | }
|
1907 | }
|
1908 | else if (data instanceof Object) {
|
1909 |
|
1910 | addOrUpdate(data);
|
1911 | }
|
1912 | else {
|
1913 | throw new Error('Unknown dataType');
|
1914 | }
|
1915 |
|
1916 | if (addedIds.length) {
|
1917 | this._trigger('add', {items: addedIds}, senderId);
|
1918 | }
|
1919 | if (updatedIds.length) {
|
1920 | this._trigger('update', {items: updatedIds}, senderId);
|
1921 | }
|
1922 |
|
1923 | return addedIds.concat(updatedIds);
|
1924 | };
|
1925 |
|
1926 | |
1927 |
|
1928 |
|
1929 |
|
1930 |
|
1931 |
|
1932 |
|
1933 |
|
1934 |
|
1935 |
|
1936 |
|
1937 |
|
1938 |
|
1939 |
|
1940 |
|
1941 |
|
1942 |
|
1943 |
|
1944 |
|
1945 |
|
1946 |
|
1947 |
|
1948 |
|
1949 |
|
1950 |
|
1951 |
|
1952 |
|
1953 |
|
1954 |
|
1955 |
|
1956 |
|
1957 |
|
1958 |
|
1959 |
|
1960 |
|
1961 | DataSet.prototype.get = function (args) {
|
1962 | var me = this;
|
1963 |
|
1964 |
|
1965 | var id, ids, options, data;
|
1966 | var firstType = util.getType(arguments[0]);
|
1967 | if (firstType == 'String' || firstType == 'Number') {
|
1968 |
|
1969 | id = arguments[0];
|
1970 | options = arguments[1];
|
1971 | data = arguments[2];
|
1972 | }
|
1973 | else if (firstType == 'Array') {
|
1974 |
|
1975 | ids = arguments[0];
|
1976 | options = arguments[1];
|
1977 | data = arguments[2];
|
1978 | }
|
1979 | else {
|
1980 |
|
1981 | options = arguments[0];
|
1982 | data = arguments[1];
|
1983 | }
|
1984 |
|
1985 |
|
1986 | var returnType;
|
1987 | if (options && options.returnType) {
|
1988 | var allowedValues = ["DataTable", "Array", "Object"];
|
1989 | returnType = allowedValues.indexOf(options.returnType) == -1 ? "Array" : options.returnType;
|
1990 |
|
1991 | if (data && (returnType != util.getType(data))) {
|
1992 | throw new Error('Type of parameter "data" (' + util.getType(data) + ') ' +
|
1993 | 'does not correspond with specified options.type (' + options.type + ')');
|
1994 | }
|
1995 | if (returnType == 'DataTable' && !util.isDataTable(data)) {
|
1996 | throw new Error('Parameter "data" must be a DataTable ' +
|
1997 | 'when options.type is "DataTable"');
|
1998 | }
|
1999 | }
|
2000 | else if (data) {
|
2001 | returnType = (util.getType(data) == 'DataTable') ? 'DataTable' : 'Array';
|
2002 | }
|
2003 | else {
|
2004 | returnType = 'Array';
|
2005 | }
|
2006 |
|
2007 |
|
2008 | var type = options && options.type || this._options.type;
|
2009 | var filter = options && options.filter;
|
2010 | var items = [], item, itemId, i, len;
|
2011 |
|
2012 |
|
2013 | if (id != undefined) {
|
2014 |
|
2015 | item = me._getItem(id, type);
|
2016 | if (filter && !filter(item)) {
|
2017 | item = null;
|
2018 | }
|
2019 | }
|
2020 | else if (ids != undefined) {
|
2021 |
|
2022 | for (i = 0, len = ids.length; i < len; i++) {
|
2023 | item = me._getItem(ids[i], type);
|
2024 | if (!filter || filter(item)) {
|
2025 | items.push(item);
|
2026 | }
|
2027 | }
|
2028 | }
|
2029 | else {
|
2030 |
|
2031 | for (itemId in this._data) {
|
2032 | if (this._data.hasOwnProperty(itemId)) {
|
2033 | item = me._getItem(itemId, type);
|
2034 | if (!filter || filter(item)) {
|
2035 | items.push(item);
|
2036 | }
|
2037 | }
|
2038 | }
|
2039 | }
|
2040 |
|
2041 |
|
2042 | if (options && options.order && id == undefined) {
|
2043 | this._sort(items, options.order);
|
2044 | }
|
2045 |
|
2046 |
|
2047 | if (options && options.fields) {
|
2048 | var fields = options.fields;
|
2049 | if (id != undefined) {
|
2050 | item = this._filterFields(item, fields);
|
2051 | }
|
2052 | else {
|
2053 | for (i = 0, len = items.length; i < len; i++) {
|
2054 | items[i] = this._filterFields(items[i], fields);
|
2055 | }
|
2056 | }
|
2057 | }
|
2058 |
|
2059 |
|
2060 | if (returnType == 'DataTable') {
|
2061 | var columns = this._getColumnNames(data);
|
2062 | if (id != undefined) {
|
2063 |
|
2064 | me._appendRow(data, columns, item);
|
2065 | }
|
2066 | else {
|
2067 |
|
2068 | for (i = 0; i < items.length; i++) {
|
2069 | me._appendRow(data, columns, items[i]);
|
2070 | }
|
2071 | }
|
2072 | return data;
|
2073 | }
|
2074 | else if (returnType == "Object") {
|
2075 | var result = {};
|
2076 | for (i = 0; i < items.length; i++) {
|
2077 | result[items[i].id] = items[i];
|
2078 | }
|
2079 | return result;
|
2080 | }
|
2081 | else {
|
2082 |
|
2083 | if (id != undefined) {
|
2084 |
|
2085 | return item;
|
2086 | }
|
2087 | else {
|
2088 |
|
2089 | if (data) {
|
2090 |
|
2091 | for (i = 0, len = items.length; i < len; i++) {
|
2092 | data.push(items[i]);
|
2093 | }
|
2094 | return data;
|
2095 | }
|
2096 | else {
|
2097 |
|
2098 | return items;
|
2099 | }
|
2100 | }
|
2101 | }
|
2102 | };
|
2103 |
|
2104 | |
2105 |
|
2106 |
|
2107 |
|
2108 |
|
2109 |
|
2110 |
|
2111 |
|
2112 | DataSet.prototype.getIds = function (options) {
|
2113 | var data = this._data,
|
2114 | filter = options && options.filter,
|
2115 | order = options && options.order,
|
2116 | type = options && options.type || this._options.type,
|
2117 | i,
|
2118 | len,
|
2119 | id,
|
2120 | item,
|
2121 | items,
|
2122 | ids = [];
|
2123 |
|
2124 | if (filter) {
|
2125 |
|
2126 | if (order) {
|
2127 |
|
2128 | items = [];
|
2129 | for (id in data) {
|
2130 | if (data.hasOwnProperty(id)) {
|
2131 | item = this._getItem(id, type);
|
2132 | if (filter(item)) {
|
2133 | items.push(item);
|
2134 | }
|
2135 | }
|
2136 | }
|
2137 |
|
2138 | this._sort(items, order);
|
2139 |
|
2140 | for (i = 0, len = items.length; i < len; i++) {
|
2141 | ids[i] = items[i][this._fieldId];
|
2142 | }
|
2143 | }
|
2144 | else {
|
2145 |
|
2146 | for (id in data) {
|
2147 | if (data.hasOwnProperty(id)) {
|
2148 | item = this._getItem(id, type);
|
2149 | if (filter(item)) {
|
2150 | ids.push(item[this._fieldId]);
|
2151 | }
|
2152 | }
|
2153 | }
|
2154 | }
|
2155 | }
|
2156 | else {
|
2157 |
|
2158 | if (order) {
|
2159 |
|
2160 | items = [];
|
2161 | for (id in data) {
|
2162 | if (data.hasOwnProperty(id)) {
|
2163 | items.push(data[id]);
|
2164 | }
|
2165 | }
|
2166 |
|
2167 | this._sort(items, order);
|
2168 |
|
2169 | for (i = 0, len = items.length; i < len; i++) {
|
2170 | ids[i] = items[i][this._fieldId];
|
2171 | }
|
2172 | }
|
2173 | else {
|
2174 |
|
2175 | for (id in data) {
|
2176 | if (data.hasOwnProperty(id)) {
|
2177 | item = data[id];
|
2178 | ids.push(item[this._fieldId]);
|
2179 | }
|
2180 | }
|
2181 | }
|
2182 | }
|
2183 |
|
2184 | return ids;
|
2185 | };
|
2186 |
|
2187 | |
2188 |
|
2189 |
|
2190 |
|
2191 | DataSet.prototype.getDataSet = function () {
|
2192 | return this;
|
2193 | };
|
2194 |
|
2195 | |
2196 |
|
2197 |
|
2198 |
|
2199 |
|
2200 |
|
2201 |
|
2202 |
|
2203 |
|
2204 |
|
2205 | DataSet.prototype.forEach = function (callback, options) {
|
2206 | var filter = options && options.filter,
|
2207 | type = options && options.type || this._options.type,
|
2208 | data = this._data,
|
2209 | item,
|
2210 | id;
|
2211 |
|
2212 | if (options && options.order) {
|
2213 |
|
2214 | var items = this.get(options);
|
2215 |
|
2216 | for (var i = 0, len = items.length; i < len; i++) {
|
2217 | item = items[i];
|
2218 | id = item[this._fieldId];
|
2219 | callback(item, id);
|
2220 | }
|
2221 | }
|
2222 | else {
|
2223 |
|
2224 | for (id in data) {
|
2225 | if (data.hasOwnProperty(id)) {
|
2226 | item = this._getItem(id, type);
|
2227 | if (!filter || filter(item)) {
|
2228 | callback(item, id);
|
2229 | }
|
2230 | }
|
2231 | }
|
2232 | }
|
2233 | };
|
2234 |
|
2235 | |
2236 |
|
2237 |
|
2238 |
|
2239 |
|
2240 |
|
2241 |
|
2242 |
|
2243 |
|
2244 |
|
2245 |
|
2246 | DataSet.prototype.map = function (callback, options) {
|
2247 | var filter = options && options.filter,
|
2248 | type = options && options.type || this._options.type,
|
2249 | mappedItems = [],
|
2250 | data = this._data,
|
2251 | item;
|
2252 |
|
2253 |
|
2254 | for (var id in data) {
|
2255 | if (data.hasOwnProperty(id)) {
|
2256 | item = this._getItem(id, type);
|
2257 | if (!filter || filter(item)) {
|
2258 | mappedItems.push(callback(item, id));
|
2259 | }
|
2260 | }
|
2261 | }
|
2262 |
|
2263 |
|
2264 | if (options && options.order) {
|
2265 | this._sort(mappedItems, options.order);
|
2266 | }
|
2267 |
|
2268 | return mappedItems;
|
2269 | };
|
2270 |
|
2271 | |
2272 |
|
2273 |
|
2274 |
|
2275 |
|
2276 |
|
2277 |
|
2278 | DataSet.prototype._filterFields = function (item, fields) {
|
2279 | var filteredItem = {};
|
2280 |
|
2281 | for (var field in item) {
|
2282 | if (item.hasOwnProperty(field) && (fields.indexOf(field) != -1)) {
|
2283 | filteredItem[field] = item[field];
|
2284 | }
|
2285 | }
|
2286 |
|
2287 | return filteredItem;
|
2288 | };
|
2289 |
|
2290 | |
2291 |
|
2292 |
|
2293 |
|
2294 |
|
2295 |
|
2296 | DataSet.prototype._sort = function (items, order) {
|
2297 | if (util.isString(order)) {
|
2298 |
|
2299 | var name = order;
|
2300 | items.sort(function (a, b) {
|
2301 | var av = a[name];
|
2302 | var bv = b[name];
|
2303 | return (av > bv) ? 1 : ((av < bv) ? -1 : 0);
|
2304 | });
|
2305 | }
|
2306 | else if (typeof order === 'function') {
|
2307 |
|
2308 | items.sort(order);
|
2309 | }
|
2310 |
|
2311 |
|
2312 | else {
|
2313 | throw new TypeError('Order must be a function or a string');
|
2314 | }
|
2315 | };
|
2316 |
|
2317 | |
2318 |
|
2319 |
|
2320 |
|
2321 |
|
2322 |
|
2323 |
|
2324 | DataSet.prototype.remove = function (id, senderId) {
|
2325 | var removedIds = [],
|
2326 | i, len, removedId;
|
2327 |
|
2328 | if (Array.isArray(id)) {
|
2329 | for (i = 0, len = id.length; i < len; i++) {
|
2330 | removedId = this._remove(id[i]);
|
2331 | if (removedId != null) {
|
2332 | removedIds.push(removedId);
|
2333 | }
|
2334 | }
|
2335 | }
|
2336 | else {
|
2337 | removedId = this._remove(id);
|
2338 | if (removedId != null) {
|
2339 | removedIds.push(removedId);
|
2340 | }
|
2341 | }
|
2342 |
|
2343 | if (removedIds.length) {
|
2344 | this._trigger('remove', {items: removedIds}, senderId);
|
2345 | }
|
2346 |
|
2347 | return removedIds;
|
2348 | };
|
2349 |
|
2350 | |
2351 |
|
2352 |
|
2353 |
|
2354 |
|
2355 |
|
2356 | DataSet.prototype._remove = function (id) {
|
2357 | if (util.isNumber(id) || util.isString(id)) {
|
2358 | if (this._data[id]) {
|
2359 | delete this._data[id];
|
2360 | return id;
|
2361 | }
|
2362 | }
|
2363 | else if (id instanceof Object) {
|
2364 | var itemId = id[this._fieldId];
|
2365 | if (itemId && this._data[itemId]) {
|
2366 | delete this._data[itemId];
|
2367 | return itemId;
|
2368 | }
|
2369 | }
|
2370 | return null;
|
2371 | };
|
2372 |
|
2373 | |
2374 |
|
2375 |
|
2376 |
|
2377 |
|
2378 | DataSet.prototype.clear = function (senderId) {
|
2379 | var ids = Object.keys(this._data);
|
2380 |
|
2381 | this._data = {};
|
2382 |
|
2383 | this._trigger('remove', {items: ids}, senderId);
|
2384 |
|
2385 | return ids;
|
2386 | };
|
2387 |
|
2388 | |
2389 |
|
2390 |
|
2391 |
|
2392 |
|
2393 | DataSet.prototype.max = function (field) {
|
2394 | var data = this._data,
|
2395 | max = null,
|
2396 | maxField = null;
|
2397 |
|
2398 | for (var id in data) {
|
2399 | if (data.hasOwnProperty(id)) {
|
2400 | var item = data[id];
|
2401 | var itemField = item[field];
|
2402 | if (itemField != null && (!max || itemField > maxField)) {
|
2403 | max = item;
|
2404 | maxField = itemField;
|
2405 | }
|
2406 | }
|
2407 | }
|
2408 |
|
2409 | return max;
|
2410 | };
|
2411 |
|
2412 | |
2413 |
|
2414 |
|
2415 |
|
2416 |
|
2417 | DataSet.prototype.min = function (field) {
|
2418 | var data = this._data,
|
2419 | min = null,
|
2420 | minField = null;
|
2421 |
|
2422 | for (var id in data) {
|
2423 | if (data.hasOwnProperty(id)) {
|
2424 | var item = data[id];
|
2425 | var itemField = item[field];
|
2426 | if (itemField != null && (!min || itemField < minField)) {
|
2427 | min = item;
|
2428 | minField = itemField;
|
2429 | }
|
2430 | }
|
2431 | }
|
2432 |
|
2433 | return min;
|
2434 | };
|
2435 |
|
2436 | |
2437 |
|
2438 |
|
2439 |
|
2440 |
|
2441 |
|
2442 |
|
2443 | DataSet.prototype.distinct = function (field) {
|
2444 | var data = this._data;
|
2445 | var values = [];
|
2446 | var fieldType = this._options.type && this._options.type[field] || null;
|
2447 | var count = 0;
|
2448 | var i;
|
2449 |
|
2450 | for (var prop in data) {
|
2451 | if (data.hasOwnProperty(prop)) {
|
2452 | var item = data[prop];
|
2453 | var value = item[field];
|
2454 | var exists = false;
|
2455 | for (i = 0; i < count; i++) {
|
2456 | if (values[i] == value) {
|
2457 | exists = true;
|
2458 | break;
|
2459 | }
|
2460 | }
|
2461 | if (!exists && (value !== undefined)) {
|
2462 | values[count] = value;
|
2463 | count++;
|
2464 | }
|
2465 | }
|
2466 | }
|
2467 |
|
2468 | if (fieldType) {
|
2469 | for (i = 0; i < values.length; i++) {
|
2470 | values[i] = util.convert(values[i], fieldType);
|
2471 | }
|
2472 | }
|
2473 |
|
2474 | return values;
|
2475 | };
|
2476 |
|
2477 | |
2478 |
|
2479 |
|
2480 |
|
2481 |
|
2482 |
|
2483 | DataSet.prototype._addItem = function (item) {
|
2484 | var id = item[this._fieldId];
|
2485 |
|
2486 | if (id != undefined) {
|
2487 |
|
2488 | if (this._data[id]) {
|
2489 |
|
2490 | throw new Error('Cannot add item: item with id ' + id + ' already exists');
|
2491 | }
|
2492 | }
|
2493 | else {
|
2494 |
|
2495 | id = util.randomUUID();
|
2496 | item[this._fieldId] = id;
|
2497 | }
|
2498 |
|
2499 | var d = {};
|
2500 | for (var field in item) {
|
2501 | if (item.hasOwnProperty(field)) {
|
2502 | var fieldType = this._type[field];
|
2503 | d[field] = util.convert(item[field], fieldType);
|
2504 | }
|
2505 | }
|
2506 | this._data[id] = d;
|
2507 |
|
2508 | return id;
|
2509 | };
|
2510 |
|
2511 | |
2512 |
|
2513 |
|
2514 |
|
2515 |
|
2516 |
|
2517 |
|
2518 | DataSet.prototype._getItem = function (id, types) {
|
2519 | var field, value;
|
2520 |
|
2521 |
|
2522 | var raw = this._data[id];
|
2523 | if (!raw) {
|
2524 | return null;
|
2525 | }
|
2526 |
|
2527 |
|
2528 | var converted = {};
|
2529 | if (types) {
|
2530 | for (field in raw) {
|
2531 | if (raw.hasOwnProperty(field)) {
|
2532 | value = raw[field];
|
2533 | converted[field] = util.convert(value, types[field]);
|
2534 | }
|
2535 | }
|
2536 | }
|
2537 | else {
|
2538 |
|
2539 | for (field in raw) {
|
2540 | if (raw.hasOwnProperty(field)) {
|
2541 | value = raw[field];
|
2542 | converted[field] = value;
|
2543 | }
|
2544 | }
|
2545 | }
|
2546 | return converted;
|
2547 | };
|
2548 |
|
2549 | |
2550 |
|
2551 |
|
2552 |
|
2553 |
|
2554 |
|
2555 |
|
2556 |
|
2557 | DataSet.prototype._updateItem = function (item) {
|
2558 | var id = item[this._fieldId];
|
2559 | if (id == undefined) {
|
2560 | throw new Error('Cannot update item: item has no id (item: ' + JSON.stringify(item) + ')');
|
2561 | }
|
2562 | var d = this._data[id];
|
2563 | if (!d) {
|
2564 |
|
2565 | throw new Error('Cannot update item: no item with id ' + id + ' found');
|
2566 | }
|
2567 |
|
2568 |
|
2569 | for (var field in item) {
|
2570 | if (item.hasOwnProperty(field)) {
|
2571 | var fieldType = this._type[field];
|
2572 | d[field] = util.convert(item[field], fieldType);
|
2573 | }
|
2574 | }
|
2575 |
|
2576 | return id;
|
2577 | };
|
2578 |
|
2579 | |
2580 |
|
2581 |
|
2582 |
|
2583 |
|
2584 |
|
2585 | DataSet.prototype._getColumnNames = function (dataTable) {
|
2586 | var columns = [];
|
2587 | for (var col = 0, cols = dataTable.getNumberOfColumns(); col < cols; col++) {
|
2588 | columns[col] = dataTable.getColumnId(col) || dataTable.getColumnLabel(col);
|
2589 | }
|
2590 | return columns;
|
2591 | };
|
2592 |
|
2593 | |
2594 |
|
2595 |
|
2596 |
|
2597 |
|
2598 |
|
2599 |
|
2600 | DataSet.prototype._appendRow = function (dataTable, columns, item) {
|
2601 | var row = dataTable.addRow();
|
2602 |
|
2603 | for (var col = 0, cols = columns.length; col < cols; col++) {
|
2604 | var field = columns[col];
|
2605 | dataTable.setValue(row, col, item[field]);
|
2606 | }
|
2607 | };
|
2608 |
|
2609 | module.exports = DataSet;
|
2610 |
|
2611 |
|
2612 | },
|
2613 |
|
2614 | function(module, exports, __webpack_require__) {
|
2615 |
|
2616 | var util = __webpack_require__(1);
|
2617 | var DataSet = __webpack_require__(3);
|
2618 |
|
2619 | |
2620 |
|
2621 |
|
2622 |
|
2623 |
|
2624 |
|
2625 |
|
2626 |
|
2627 |
|
2628 |
|
2629 | function DataView (data, options) {
|
2630 | this._data = null;
|
2631 | this._ids = {};
|
2632 | this._options = options || {};
|
2633 | this._fieldId = 'id';
|
2634 | this._subscribers = {};
|
2635 |
|
2636 | var me = this;
|
2637 | this.listener = function () {
|
2638 | me._onEvent.apply(me, arguments);
|
2639 | };
|
2640 |
|
2641 | this.setData(data);
|
2642 | }
|
2643 |
|
2644 |
|
2645 |
|
2646 |
|
2647 | |
2648 |
|
2649 |
|
2650 |
|
2651 | DataView.prototype.setData = function (data) {
|
2652 | var ids, i, len;
|
2653 |
|
2654 | if (this._data) {
|
2655 |
|
2656 | if (this._data.unsubscribe) {
|
2657 | this._data.unsubscribe('*', this.listener);
|
2658 | }
|
2659 |
|
2660 |
|
2661 | ids = [];
|
2662 | for (var id in this._ids) {
|
2663 | if (this._ids.hasOwnProperty(id)) {
|
2664 | ids.push(id);
|
2665 | }
|
2666 | }
|
2667 | this._ids = {};
|
2668 | this._trigger('remove', {items: ids});
|
2669 | }
|
2670 |
|
2671 | this._data = data;
|
2672 |
|
2673 | if (this._data) {
|
2674 |
|
2675 | this._fieldId = this._options.fieldId ||
|
2676 | (this._data && this._data.options && this._data.options.fieldId) ||
|
2677 | 'id';
|
2678 |
|
2679 |
|
2680 | ids = this._data.getIds({filter: this._options && this._options.filter});
|
2681 | for (i = 0, len = ids.length; i < len; i++) {
|
2682 | id = ids[i];
|
2683 | this._ids[id] = true;
|
2684 | }
|
2685 | this._trigger('add', {items: ids});
|
2686 |
|
2687 |
|
2688 | if (this._data.on) {
|
2689 | this._data.on('*', this.listener);
|
2690 | }
|
2691 | }
|
2692 | };
|
2693 |
|
2694 | |
2695 |
|
2696 |
|
2697 |
|
2698 |
|
2699 |
|
2700 |
|
2701 |
|
2702 |
|
2703 |
|
2704 |
|
2705 |
|
2706 |
|
2707 |
|
2708 |
|
2709 |
|
2710 |
|
2711 |
|
2712 |
|
2713 |
|
2714 |
|
2715 |
|
2716 |
|
2717 |
|
2718 |
|
2719 |
|
2720 |
|
2721 |
|
2722 |
|
2723 |
|
2724 |
|
2725 |
|
2726 |
|
2727 |
|
2728 | DataView.prototype.get = function (args) {
|
2729 | var me = this;
|
2730 |
|
2731 |
|
2732 | var ids, options, data;
|
2733 | var firstType = util.getType(arguments[0]);
|
2734 | if (firstType == 'String' || firstType == 'Number' || firstType == 'Array') {
|
2735 |
|
2736 | ids = arguments[0];
|
2737 | options = arguments[1];
|
2738 | data = arguments[2];
|
2739 | }
|
2740 | else {
|
2741 |
|
2742 | options = arguments[0];
|
2743 | data = arguments[1];
|
2744 | }
|
2745 |
|
2746 |
|
2747 | var viewOptions = util.extend({}, this._options, options);
|
2748 |
|
2749 |
|
2750 | if (this._options.filter && options && options.filter) {
|
2751 | viewOptions.filter = function (item) {
|
2752 | return me._options.filter(item) && options.filter(item);
|
2753 | }
|
2754 | }
|
2755 |
|
2756 |
|
2757 | var getArguments = [];
|
2758 | if (ids != undefined) {
|
2759 | getArguments.push(ids);
|
2760 | }
|
2761 | getArguments.push(viewOptions);
|
2762 | getArguments.push(data);
|
2763 |
|
2764 | return this._data && this._data.get.apply(this._data, getArguments);
|
2765 | };
|
2766 |
|
2767 | |
2768 |
|
2769 |
|
2770 |
|
2771 |
|
2772 |
|
2773 |
|
2774 |
|
2775 | DataView.prototype.getIds = function (options) {
|
2776 | var ids;
|
2777 |
|
2778 | if (this._data) {
|
2779 | var defaultFilter = this._options.filter;
|
2780 | var filter;
|
2781 |
|
2782 | if (options && options.filter) {
|
2783 | if (defaultFilter) {
|
2784 | filter = function (item) {
|
2785 | return defaultFilter(item) && options.filter(item);
|
2786 | }
|
2787 | }
|
2788 | else {
|
2789 | filter = options.filter;
|
2790 | }
|
2791 | }
|
2792 | else {
|
2793 | filter = defaultFilter;
|
2794 | }
|
2795 |
|
2796 | ids = this._data.getIds({
|
2797 | filter: filter,
|
2798 | order: options && options.order
|
2799 | });
|
2800 | }
|
2801 | else {
|
2802 | ids = [];
|
2803 | }
|
2804 |
|
2805 | return ids;
|
2806 | };
|
2807 |
|
2808 | |
2809 |
|
2810 |
|
2811 |
|
2812 |
|
2813 | DataView.prototype.getDataSet = function () {
|
2814 | var dataSet = this;
|
2815 | while (dataSet instanceof DataView) {
|
2816 | dataSet = dataSet._data;
|
2817 | }
|
2818 | return dataSet || null;
|
2819 | };
|
2820 |
|
2821 | |
2822 |
|
2823 |
|
2824 |
|
2825 |
|
2826 |
|
2827 |
|
2828 |
|
2829 |
|
2830 | DataView.prototype._onEvent = function (event, params, senderId) {
|
2831 | var i, len, id, item,
|
2832 | ids = params && params.items,
|
2833 | data = this._data,
|
2834 | added = [],
|
2835 | updated = [],
|
2836 | removed = [];
|
2837 |
|
2838 | if (ids && data) {
|
2839 | switch (event) {
|
2840 | case 'add':
|
2841 |
|
2842 | for (i = 0, len = ids.length; i < len; i++) {
|
2843 | id = ids[i];
|
2844 | item = this.get(id);
|
2845 | if (item) {
|
2846 | this._ids[id] = true;
|
2847 | added.push(id);
|
2848 | }
|
2849 | }
|
2850 |
|
2851 | break;
|
2852 |
|
2853 | case 'update':
|
2854 |
|
2855 |
|
2856 | for (i = 0, len = ids.length; i < len; i++) {
|
2857 | id = ids[i];
|
2858 | item = this.get(id);
|
2859 |
|
2860 | if (item) {
|
2861 | if (this._ids[id]) {
|
2862 | updated.push(id);
|
2863 | }
|
2864 | else {
|
2865 | this._ids[id] = true;
|
2866 | added.push(id);
|
2867 | }
|
2868 | }
|
2869 | else {
|
2870 | if (this._ids[id]) {
|
2871 | delete this._ids[id];
|
2872 | removed.push(id);
|
2873 | }
|
2874 | else {
|
2875 |
|
2876 | }
|
2877 | }
|
2878 | }
|
2879 |
|
2880 | break;
|
2881 |
|
2882 | case 'remove':
|
2883 |
|
2884 | for (i = 0, len = ids.length; i < len; i++) {
|
2885 | id = ids[i];
|
2886 | if (this._ids[id]) {
|
2887 | delete this._ids[id];
|
2888 | removed.push(id);
|
2889 | }
|
2890 | }
|
2891 |
|
2892 | break;
|
2893 | }
|
2894 |
|
2895 | if (added.length) {
|
2896 | this._trigger('add', {items: added}, senderId);
|
2897 | }
|
2898 | if (updated.length) {
|
2899 | this._trigger('update', {items: updated}, senderId);
|
2900 | }
|
2901 | if (removed.length) {
|
2902 | this._trigger('remove', {items: removed}, senderId);
|
2903 | }
|
2904 | }
|
2905 | };
|
2906 |
|
2907 |
|
2908 | DataView.prototype.on = DataSet.prototype.on;
|
2909 | DataView.prototype.off = DataSet.prototype.off;
|
2910 | DataView.prototype._trigger = DataSet.prototype._trigger;
|
2911 |
|
2912 |
|
2913 | DataView.prototype.subscribe = DataView.prototype.on;
|
2914 | DataView.prototype.unsubscribe = DataView.prototype.off;
|
2915 |
|
2916 | module.exports = DataView;
|
2917 |
|
2918 | },
|
2919 |
|
2920 | function(module, exports, __webpack_require__) {
|
2921 |
|
2922 | var Emitter = __webpack_require__(50);
|
2923 | var DataSet = __webpack_require__(3);
|
2924 | var DataView = __webpack_require__(4);
|
2925 | var util = __webpack_require__(1);
|
2926 | var Point3d = __webpack_require__(9);
|
2927 | var Point2d = __webpack_require__(8);
|
2928 | var Camera = __webpack_require__(6);
|
2929 | var Filter = __webpack_require__(7);
|
2930 | var Slider = __webpack_require__(10);
|
2931 | var StepNumber = __webpack_require__(11);
|
2932 |
|
2933 | |
2934 |
|
2935 |
|
2936 |
|
2937 |
|
2938 |
|
2939 |
|
2940 |
|
2941 |
|
2942 |
|
2943 |
|
2944 | function Graph3d(container, data, options) {
|
2945 | if (!(this instanceof Graph3d)) {
|
2946 | throw new SyntaxError('Constructor must be called with the new operator');
|
2947 | }
|
2948 |
|
2949 |
|
2950 | this.containerElement = container;
|
2951 | this.width = '400px';
|
2952 | this.height = '400px';
|
2953 | this.margin = 10;
|
2954 | this.defaultXCenter = '55%';
|
2955 | this.defaultYCenter = '50%';
|
2956 |
|
2957 | this.xLabel = 'x';
|
2958 | this.yLabel = 'y';
|
2959 | this.zLabel = 'z';
|
2960 | this.filterLabel = 'time';
|
2961 | this.legendLabel = 'value';
|
2962 |
|
2963 | this.style = Graph3d.STYLE.DOT;
|
2964 | this.showPerspective = true;
|
2965 | this.showGrid = true;
|
2966 | this.keepAspectRatio = true;
|
2967 | this.showShadow = false;
|
2968 | this.showGrayBottom = false;
|
2969 | this.showTooltip = false;
|
2970 | this.verticalRatio = 0.5;
|
2971 |
|
2972 | this.animationInterval = 1000;
|
2973 | this.animationPreload = false;
|
2974 |
|
2975 | this.camera = new Camera();
|
2976 | this.eye = new Point3d(0, 0, -1);
|
2977 |
|
2978 | this.dataTable = null;
|
2979 | this.dataPoints = null;
|
2980 |
|
2981 |
|
2982 | this.colX = undefined;
|
2983 | this.colY = undefined;
|
2984 | this.colZ = undefined;
|
2985 | this.colValue = undefined;
|
2986 | this.colFilter = undefined;
|
2987 |
|
2988 | this.xMin = 0;
|
2989 | this.xStep = undefined;
|
2990 | this.xMax = 1;
|
2991 | this.yMin = 0;
|
2992 | this.yStep = undefined;
|
2993 | this.yMax = 1;
|
2994 | this.zMin = 0;
|
2995 | this.zStep = undefined;
|
2996 | this.zMax = 1;
|
2997 | this.valueMin = 0;
|
2998 | this.valueMax = 1;
|
2999 | this.xBarWidth = 1;
|
3000 | this.yBarWidth = 1;
|
3001 |
|
3002 |
|
3003 |
|
3004 | this.colorAxis = '#4D4D4D';
|
3005 | this.colorGrid = '#D3D3D3';
|
3006 | this.colorDot = '#7DC1FF';
|
3007 | this.colorDotBorder = '#3267D2';
|
3008 |
|
3009 |
|
3010 | this.create();
|
3011 |
|
3012 |
|
3013 | this.setOptions(options);
|
3014 |
|
3015 |
|
3016 | if (data) {
|
3017 | this.setData(data);
|
3018 | }
|
3019 | }
|
3020 |
|
3021 |
|
3022 | Emitter(Graph3d.prototype);
|
3023 |
|
3024 | |
3025 |
|
3026 |
|
3027 | Graph3d.prototype._setScale = function() {
|
3028 | this.scale = new Point3d(1 / (this.xMax - this.xMin),
|
3029 | 1 / (this.yMax - this.yMin),
|
3030 | 1 / (this.zMax - this.zMin));
|
3031 |
|
3032 |
|
3033 | if (this.keepAspectRatio) {
|
3034 | if (this.scale.x < this.scale.y) {
|
3035 |
|
3036 | this.scale.y = this.scale.x;
|
3037 | }
|
3038 | else {
|
3039 |
|
3040 | this.scale.x = this.scale.y;
|
3041 | }
|
3042 | }
|
3043 |
|
3044 |
|
3045 | this.scale.z *= this.verticalRatio;
|
3046 |
|
3047 |
|
3048 |
|
3049 | this.scale.value = 1 / (this.valueMax - this.valueMin);
|
3050 |
|
3051 |
|
3052 | var xCenter = (this.xMax + this.xMin) / 2 * this.scale.x;
|
3053 | var yCenter = (this.yMax + this.yMin) / 2 * this.scale.y;
|
3054 | var zCenter = (this.zMax + this.zMin) / 2 * this.scale.z;
|
3055 | this.camera.setArmLocation(xCenter, yCenter, zCenter);
|
3056 | };
|
3057 |
|
3058 |
|
3059 | |
3060 |
|
3061 |
|
3062 |
|
3063 |
|
3064 |
|
3065 | Graph3d.prototype._convert3Dto2D = function(point3d) {
|
3066 | var translation = this._convertPointToTranslation(point3d);
|
3067 | return this._convertTranslationToScreen(translation);
|
3068 | };
|
3069 |
|
3070 | |
3071 |
|
3072 |
|
3073 |
|
3074 |
|
3075 |
|
3076 |
|
3077 |
|
3078 | Graph3d.prototype._convertPointToTranslation = function(point3d) {
|
3079 | var ax = point3d.x * this.scale.x,
|
3080 | ay = point3d.y * this.scale.y,
|
3081 | az = point3d.z * this.scale.z,
|
3082 |
|
3083 | cx = this.camera.getCameraLocation().x,
|
3084 | cy = this.camera.getCameraLocation().y,
|
3085 | cz = this.camera.getCameraLocation().z,
|
3086 |
|
3087 |
|
3088 | sinTx = Math.sin(this.camera.getCameraRotation().x),
|
3089 | cosTx = Math.cos(this.camera.getCameraRotation().x),
|
3090 | sinTy = Math.sin(this.camera.getCameraRotation().y),
|
3091 | cosTy = Math.cos(this.camera.getCameraRotation().y),
|
3092 | sinTz = Math.sin(this.camera.getCameraRotation().z),
|
3093 | cosTz = Math.cos(this.camera.getCameraRotation().z),
|
3094 |
|
3095 |
|
3096 | dx = cosTy * (sinTz * (ay - cy) + cosTz * (ax - cx)) - sinTy * (az - cz),
|
3097 | dy = sinTx * (cosTy * (az - cz) + sinTy * (sinTz * (ay - cy) + cosTz * (ax - cx))) + cosTx * (cosTz * (ay - cy) - sinTz * (ax-cx)),
|
3098 | dz = cosTx * (cosTy * (az - cz) + sinTy * (sinTz * (ay - cy) + cosTz * (ax - cx))) - sinTx * (cosTz * (ay - cy) - sinTz * (ax-cx));
|
3099 |
|
3100 | return new Point3d(dx, dy, dz);
|
3101 | };
|
3102 |
|
3103 | |
3104 |
|
3105 |
|
3106 |
|
3107 |
|
3108 |
|
3109 |
|
3110 | Graph3d.prototype._convertTranslationToScreen = function(translation) {
|
3111 | var ex = this.eye.x,
|
3112 | ey = this.eye.y,
|
3113 | ez = this.eye.z,
|
3114 | dx = translation.x,
|
3115 | dy = translation.y,
|
3116 | dz = translation.z;
|
3117 |
|
3118 |
|
3119 | var bx;
|
3120 | var by;
|
3121 | if (this.showPerspective) {
|
3122 | bx = (dx - ex) * (ez / dz);
|
3123 | by = (dy - ey) * (ez / dz);
|
3124 | }
|
3125 | else {
|
3126 | bx = dx * -(ez / this.camera.getArmLength());
|
3127 | by = dy * -(ez / this.camera.getArmLength());
|
3128 | }
|
3129 |
|
3130 |
|
3131 |
|
3132 | return new Point2d(
|
3133 | this.xcenter + bx * this.frame.canvas.clientWidth,
|
3134 | this.ycenter - by * this.frame.canvas.clientWidth);
|
3135 | };
|
3136 |
|
3137 | |
3138 |
|
3139 |
|
3140 |
|
3141 | Graph3d.prototype._setBackgroundColor = function(backgroundColor) {
|
3142 | var fill = 'white';
|
3143 | var stroke = 'gray';
|
3144 | var strokeWidth = 1;
|
3145 |
|
3146 | if (typeof(backgroundColor) === 'string') {
|
3147 | fill = backgroundColor;
|
3148 | stroke = 'none';
|
3149 | strokeWidth = 0;
|
3150 | }
|
3151 | else if (typeof(backgroundColor) === 'object') {
|
3152 | if (backgroundColor.fill !== undefined) fill = backgroundColor.fill;
|
3153 | if (backgroundColor.stroke !== undefined) stroke = backgroundColor.stroke;
|
3154 | if (backgroundColor.strokeWidth !== undefined) strokeWidth = backgroundColor.strokeWidth;
|
3155 | }
|
3156 | else if (backgroundColor === undefined) {
|
3157 |
|
3158 | }
|
3159 | else {
|
3160 | throw 'Unsupported type of backgroundColor';
|
3161 | }
|
3162 |
|
3163 | this.frame.style.backgroundColor = fill;
|
3164 | this.frame.style.borderColor = stroke;
|
3165 | this.frame.style.borderWidth = strokeWidth + 'px';
|
3166 | this.frame.style.borderStyle = 'solid';
|
3167 | };
|
3168 |
|
3169 |
|
3170 |
|
3171 | Graph3d.STYLE = {
|
3172 | BAR: 0,
|
3173 | BARCOLOR: 1,
|
3174 | BARSIZE: 2,
|
3175 | DOT : 3,
|
3176 | DOTLINE : 4,
|
3177 | DOTCOLOR: 5,
|
3178 | DOTSIZE: 6,
|
3179 | GRID : 7,
|
3180 | LINE: 8,
|
3181 | SURFACE : 9
|
3182 | };
|
3183 |
|
3184 | |
3185 |
|
3186 |
|
3187 |
|
3188 |
|
3189 |
|
3190 | Graph3d.prototype._getStyleNumber = function(styleName) {
|
3191 | switch (styleName) {
|
3192 | case 'dot': return Graph3d.STYLE.DOT;
|
3193 | case 'dot-line': return Graph3d.STYLE.DOTLINE;
|
3194 | case 'dot-color': return Graph3d.STYLE.DOTCOLOR;
|
3195 | case 'dot-size': return Graph3d.STYLE.DOTSIZE;
|
3196 | case 'line': return Graph3d.STYLE.LINE;
|
3197 | case 'grid': return Graph3d.STYLE.GRID;
|
3198 | case 'surface': return Graph3d.STYLE.SURFACE;
|
3199 | case 'bar': return Graph3d.STYLE.BAR;
|
3200 | case 'bar-color': return Graph3d.STYLE.BARCOLOR;
|
3201 | case 'bar-size': return Graph3d.STYLE.BARSIZE;
|
3202 | }
|
3203 |
|
3204 | return -1;
|
3205 | };
|
3206 |
|
3207 | |
3208 |
|
3209 |
|
3210 |
|
3211 |
|
3212 | Graph3d.prototype._determineColumnIndexes = function(data, style) {
|
3213 | if (this.style === Graph3d.STYLE.DOT ||
|
3214 | this.style === Graph3d.STYLE.DOTLINE ||
|
3215 | this.style === Graph3d.STYLE.LINE ||
|
3216 | this.style === Graph3d.STYLE.GRID ||
|
3217 | this.style === Graph3d.STYLE.SURFACE ||
|
3218 | this.style === Graph3d.STYLE.BAR) {
|
3219 |
|
3220 | this.colX = 0;
|
3221 | this.colY = 1;
|
3222 | this.colZ = 2;
|
3223 | this.colValue = undefined;
|
3224 |
|
3225 | if (data.getNumberOfColumns() > 3) {
|
3226 | this.colFilter = 3;
|
3227 | }
|
3228 | }
|
3229 | else if (this.style === Graph3d.STYLE.DOTCOLOR ||
|
3230 | this.style === Graph3d.STYLE.DOTSIZE ||
|
3231 | this.style === Graph3d.STYLE.BARCOLOR ||
|
3232 | this.style === Graph3d.STYLE.BARSIZE) {
|
3233 |
|
3234 | this.colX = 0;
|
3235 | this.colY = 1;
|
3236 | this.colZ = 2;
|
3237 | this.colValue = 3;
|
3238 |
|
3239 | if (data.getNumberOfColumns() > 4) {
|
3240 | this.colFilter = 4;
|
3241 | }
|
3242 | }
|
3243 | else {
|
3244 | throw 'Unknown style "' + this.style + '"';
|
3245 | }
|
3246 | };
|
3247 |
|
3248 | Graph3d.prototype.getNumberOfRows = function(data) {
|
3249 | return data.length;
|
3250 | }
|
3251 |
|
3252 |
|
3253 | Graph3d.prototype.getNumberOfColumns = function(data) {
|
3254 | var counter = 0;
|
3255 | for (var column in data[0]) {
|
3256 | if (data[0].hasOwnProperty(column)) {
|
3257 | counter++;
|
3258 | }
|
3259 | }
|
3260 | return counter;
|
3261 | }
|
3262 |
|
3263 |
|
3264 | Graph3d.prototype.getDistinctValues = function(data, column) {
|
3265 | var distinctValues = [];
|
3266 | for (var i = 0; i < data.length; i++) {
|
3267 | if (distinctValues.indexOf(data[i][column]) == -1) {
|
3268 | distinctValues.push(data[i][column]);
|
3269 | }
|
3270 | }
|
3271 | return distinctValues;
|
3272 | }
|
3273 |
|
3274 |
|
3275 | Graph3d.prototype.getColumnRange = function(data,column) {
|
3276 | var minMax = {min:data[0][column],max:data[0][column]};
|
3277 | for (var i = 0; i < data.length; i++) {
|
3278 | if (minMax.min > data[i][column]) { minMax.min = data[i][column]; }
|
3279 | if (minMax.max < data[i][column]) { minMax.max = data[i][column]; }
|
3280 | }
|
3281 | return minMax;
|
3282 | };
|
3283 |
|
3284 | |
3285 |
|
3286 |
|
3287 |
|
3288 |
|
3289 |
|
3290 | Graph3d.prototype._dataInitialize = function (rawData, style) {
|
3291 | var me = this;
|
3292 |
|
3293 |
|
3294 | if (this.dataSet) {
|
3295 | this.dataSet.off('*', this._onChange);
|
3296 | }
|
3297 |
|
3298 | if (rawData === undefined)
|
3299 | return;
|
3300 |
|
3301 | if (Array.isArray(rawData)) {
|
3302 | rawData = new DataSet(rawData);
|
3303 | }
|
3304 |
|
3305 | var data;
|
3306 | if (rawData instanceof DataSet || rawData instanceof DataView) {
|
3307 | data = rawData.get();
|
3308 | }
|
3309 | else {
|
3310 | throw new Error('Array, DataSet, or DataView expected');
|
3311 | }
|
3312 |
|
3313 | if (data.length == 0)
|
3314 | return;
|
3315 |
|
3316 | this.dataSet = rawData;
|
3317 | this.dataTable = data;
|
3318 |
|
3319 |
|
3320 | this._onChange = function () {
|
3321 | me.setData(me.dataSet);
|
3322 | };
|
3323 | this.dataSet.on('*', this._onChange);
|
3324 |
|
3325 |
|
3326 |
|
3327 |
|
3328 |
|
3329 |
|
3330 |
|
3331 |
|
3332 | this.colX = 'x';
|
3333 | this.colY = 'y';
|
3334 | this.colZ = 'z';
|
3335 | this.colValue = 'style';
|
3336 | this.colFilter = 'filter';
|
3337 |
|
3338 |
|
3339 |
|
3340 |
|
3341 | if (data[0].hasOwnProperty('filter')) {
|
3342 | if (this.dataFilter === undefined) {
|
3343 | this.dataFilter = new Filter(rawData, this.colFilter, this);
|
3344 | this.dataFilter.setOnLoadCallback(function() {me.redraw();});
|
3345 | }
|
3346 | }
|
3347 |
|
3348 |
|
3349 | var withBars = this.style == Graph3d.STYLE.BAR ||
|
3350 | this.style == Graph3d.STYLE.BARCOLOR ||
|
3351 | this.style == Graph3d.STYLE.BARSIZE;
|
3352 |
|
3353 |
|
3354 | if (withBars) {
|
3355 | if (this.defaultXBarWidth !== undefined) {
|
3356 | this.xBarWidth = this.defaultXBarWidth;
|
3357 | }
|
3358 | else {
|
3359 | var dataX = this.getDistinctValues(data,this.colX);
|
3360 | this.xBarWidth = (dataX[1] - dataX[0]) || 1;
|
3361 | }
|
3362 |
|
3363 | if (this.defaultYBarWidth !== undefined) {
|
3364 | this.yBarWidth = this.defaultYBarWidth;
|
3365 | }
|
3366 | else {
|
3367 | var dataY = this.getDistinctValues(data,this.colY);
|
3368 | this.yBarWidth = (dataY[1] - dataY[0]) || 1;
|
3369 | }
|
3370 | }
|
3371 |
|
3372 |
|
3373 | var xRange = this.getColumnRange(data,this.colX);
|
3374 | if (withBars) {
|
3375 | xRange.min -= this.xBarWidth / 2;
|
3376 | xRange.max += this.xBarWidth / 2;
|
3377 | }
|
3378 | this.xMin = (this.defaultXMin !== undefined) ? this.defaultXMin : xRange.min;
|
3379 | this.xMax = (this.defaultXMax !== undefined) ? this.defaultXMax : xRange.max;
|
3380 | if (this.xMax <= this.xMin) this.xMax = this.xMin + 1;
|
3381 | this.xStep = (this.defaultXStep !== undefined) ? this.defaultXStep : (this.xMax-this.xMin)/5;
|
3382 |
|
3383 | var yRange = this.getColumnRange(data,this.colY);
|
3384 | if (withBars) {
|
3385 | yRange.min -= this.yBarWidth / 2;
|
3386 | yRange.max += this.yBarWidth / 2;
|
3387 | }
|
3388 | this.yMin = (this.defaultYMin !== undefined) ? this.defaultYMin : yRange.min;
|
3389 | this.yMax = (this.defaultYMax !== undefined) ? this.defaultYMax : yRange.max;
|
3390 | if (this.yMax <= this.yMin) this.yMax = this.yMin + 1;
|
3391 | this.yStep = (this.defaultYStep !== undefined) ? this.defaultYStep : (this.yMax-this.yMin)/5;
|
3392 |
|
3393 | var zRange = this.getColumnRange(data,this.colZ);
|
3394 | this.zMin = (this.defaultZMin !== undefined) ? this.defaultZMin : zRange.min;
|
3395 | this.zMax = (this.defaultZMax !== undefined) ? this.defaultZMax : zRange.max;
|
3396 | if (this.zMax <= this.zMin) this.zMax = this.zMin + 1;
|
3397 | this.zStep = (this.defaultZStep !== undefined) ? this.defaultZStep : (this.zMax-this.zMin)/5;
|
3398 |
|
3399 | if (this.colValue !== undefined) {
|
3400 | var valueRange = this.getColumnRange(data,this.colValue);
|
3401 | this.valueMin = (this.defaultValueMin !== undefined) ? this.defaultValueMin : valueRange.min;
|
3402 | this.valueMax = (this.defaultValueMax !== undefined) ? this.defaultValueMax : valueRange.max;
|
3403 | if (this.valueMax <= this.valueMin) this.valueMax = this.valueMin + 1;
|
3404 | }
|
3405 |
|
3406 |
|
3407 | this._setScale();
|
3408 | };
|
3409 |
|
3410 |
|
3411 |
|
3412 | |
3413 |
|
3414 |
|
3415 |
|
3416 |
|
3417 | Graph3d.prototype._getDataPoints = function (data) {
|
3418 |
|
3419 | var x, y, i, z, obj, point;
|
3420 |
|
3421 | var dataPoints = [];
|
3422 |
|
3423 | if (this.style === Graph3d.STYLE.GRID ||
|
3424 | this.style === Graph3d.STYLE.SURFACE) {
|
3425 |
|
3426 |
|
3427 |
|
3428 |
|
3429 | var dataX = [];
|
3430 | var dataY = [];
|
3431 | for (i = 0; i < this.getNumberOfRows(data); i++) {
|
3432 | x = data[i][this.colX] || 0;
|
3433 | y = data[i][this.colY] || 0;
|
3434 |
|
3435 | if (dataX.indexOf(x) === -1) {
|
3436 | dataX.push(x);
|
3437 | }
|
3438 | if (dataY.indexOf(y) === -1) {
|
3439 | dataY.push(y);
|
3440 | }
|
3441 | }
|
3442 |
|
3443 | function sortNumber(a, b) {
|
3444 | return a - b;
|
3445 | }
|
3446 | dataX.sort(sortNumber);
|
3447 | dataY.sort(sortNumber);
|
3448 |
|
3449 |
|
3450 | var dataMatrix = [];
|
3451 | for (i = 0; i < data.length; i++) {
|
3452 | x = data[i][this.colX] || 0;
|
3453 | y = data[i][this.colY] || 0;
|
3454 | z = data[i][this.colZ] || 0;
|
3455 |
|
3456 | var xIndex = dataX.indexOf(x);
|
3457 | var yIndex = dataY.indexOf(y);
|
3458 |
|
3459 | if (dataMatrix[xIndex] === undefined) {
|
3460 | dataMatrix[xIndex] = [];
|
3461 | }
|
3462 |
|
3463 | var point3d = new Point3d();
|
3464 | point3d.x = x;
|
3465 | point3d.y = y;
|
3466 | point3d.z = z;
|
3467 |
|
3468 | obj = {};
|
3469 | obj.point = point3d;
|
3470 | obj.trans = undefined;
|
3471 | obj.screen = undefined;
|
3472 | obj.bottom = new Point3d(x, y, this.zMin);
|
3473 |
|
3474 | dataMatrix[xIndex][yIndex] = obj;
|
3475 |
|
3476 | dataPoints.push(obj);
|
3477 | }
|
3478 |
|
3479 |
|
3480 | for (x = 0; x < dataMatrix.length; x++) {
|
3481 | for (y = 0; y < dataMatrix[x].length; y++) {
|
3482 | if (dataMatrix[x][y]) {
|
3483 | dataMatrix[x][y].pointRight = (x < dataMatrix.length-1) ? dataMatrix[x+1][y] : undefined;
|
3484 | dataMatrix[x][y].pointTop = (y < dataMatrix[x].length-1) ? dataMatrix[x][y+1] : undefined;
|
3485 | dataMatrix[x][y].pointCross =
|
3486 | (x < dataMatrix.length-1 && y < dataMatrix[x].length-1) ?
|
3487 | dataMatrix[x+1][y+1] :
|
3488 | undefined;
|
3489 | }
|
3490 | }
|
3491 | }
|
3492 | }
|
3493 | else {
|
3494 |
|
3495 | for (i = 0; i < data.length; i++) {
|
3496 | point = new Point3d();
|
3497 | point.x = data[i][this.colX] || 0;
|
3498 | point.y = data[i][this.colY] || 0;
|
3499 | point.z = data[i][this.colZ] || 0;
|
3500 |
|
3501 | if (this.colValue !== undefined) {
|
3502 | point.value = data[i][this.colValue] || 0;
|
3503 | }
|
3504 |
|
3505 | obj = {};
|
3506 | obj.point = point;
|
3507 | obj.bottom = new Point3d(point.x, point.y, this.zMin);
|
3508 | obj.trans = undefined;
|
3509 | obj.screen = undefined;
|
3510 |
|
3511 | dataPoints.push(obj);
|
3512 | }
|
3513 | }
|
3514 |
|
3515 | return dataPoints;
|
3516 | };
|
3517 |
|
3518 | |
3519 |
|
3520 |
|
3521 |
|
3522 |
|
3523 |
|
3524 | Graph3d.prototype.create = function () {
|
3525 |
|
3526 | while (this.containerElement.hasChildNodes()) {
|
3527 | this.containerElement.removeChild(this.containerElement.firstChild);
|
3528 | }
|
3529 |
|
3530 | this.frame = document.createElement('div');
|
3531 | this.frame.style.position = 'relative';
|
3532 | this.frame.style.overflow = 'hidden';
|
3533 |
|
3534 |
|
3535 | this.frame.canvas = document.createElement( 'canvas' );
|
3536 | this.frame.canvas.style.position = 'relative';
|
3537 | this.frame.appendChild(this.frame.canvas);
|
3538 |
|
3539 | {
|
3540 | var noCanvas = document.createElement( 'DIV' );
|
3541 | noCanvas.style.color = 'red';
|
3542 | noCanvas.style.fontWeight = 'bold' ;
|
3543 | noCanvas.style.padding = '10px';
|
3544 | noCanvas.innerHTML = 'Error: your browser does not support HTML canvas';
|
3545 | this.frame.canvas.appendChild(noCanvas);
|
3546 | }
|
3547 |
|
3548 | this.frame.filter = document.createElement( 'div' );
|
3549 | this.frame.filter.style.position = 'absolute';
|
3550 | this.frame.filter.style.bottom = '0px';
|
3551 | this.frame.filter.style.left = '0px';
|
3552 | this.frame.filter.style.width = '100%';
|
3553 | this.frame.appendChild(this.frame.filter);
|
3554 |
|
3555 |
|
3556 | var me = this;
|
3557 | var onmousedown = function (event) {me._onMouseDown(event);};
|
3558 | var ontouchstart = function (event) {me._onTouchStart(event);};
|
3559 | var onmousewheel = function (event) {me._onWheel(event);};
|
3560 | var ontooltip = function (event) {me._onTooltip(event);};
|
3561 |
|
3562 |
|
3563 | util.addEventListener(this.frame.canvas, 'keydown', onkeydown);
|
3564 | util.addEventListener(this.frame.canvas, 'mousedown', onmousedown);
|
3565 | util.addEventListener(this.frame.canvas, 'touchstart', ontouchstart);
|
3566 | util.addEventListener(this.frame.canvas, 'mousewheel', onmousewheel);
|
3567 | util.addEventListener(this.frame.canvas, 'mousemove', ontooltip);
|
3568 |
|
3569 |
|
3570 | this.containerElement.appendChild(this.frame);
|
3571 | };
|
3572 |
|
3573 |
|
3574 | |
3575 |
|
3576 |
|
3577 |
|
3578 |
|
3579 |
|
3580 |
|
3581 | Graph3d.prototype.setSize = function(width, height) {
|
3582 | this.frame.style.width = width;
|
3583 | this.frame.style.height = height;
|
3584 |
|
3585 | this._resizeCanvas();
|
3586 | };
|
3587 |
|
3588 | |
3589 |
|
3590 |
|
3591 | Graph3d.prototype._resizeCanvas = function() {
|
3592 | this.frame.canvas.style.width = '100%';
|
3593 | this.frame.canvas.style.height = '100%';
|
3594 |
|
3595 | this.frame.canvas.width = this.frame.canvas.clientWidth;
|
3596 | this.frame.canvas.height = this.frame.canvas.clientHeight;
|
3597 |
|
3598 |
|
3599 | this.frame.filter.style.width = (this.frame.canvas.clientWidth - 2 * 10) + 'px';
|
3600 | };
|
3601 |
|
3602 | |
3603 |
|
3604 |
|
3605 | Graph3d.prototype.animationStart = function() {
|
3606 | if (!this.frame.filter || !this.frame.filter.slider)
|
3607 | throw 'No animation available';
|
3608 |
|
3609 | this.frame.filter.slider.play();
|
3610 | };
|
3611 |
|
3612 |
|
3613 | |
3614 |
|
3615 |
|
3616 | Graph3d.prototype.animationStop = function() {
|
3617 | if (!this.frame.filter || !this.frame.filter.slider) return;
|
3618 |
|
3619 | this.frame.filter.slider.stop();
|
3620 | };
|
3621 |
|
3622 |
|
3623 | |
3624 |
|
3625 |
|
3626 |
|
3627 |
|
3628 |
|
3629 | Graph3d.prototype._resizeCenter = function() {
|
3630 |
|
3631 | if (this.defaultXCenter.charAt(this.defaultXCenter.length-1) === '%') {
|
3632 | this.xcenter =
|
3633 | parseFloat(this.defaultXCenter) / 100 *
|
3634 | this.frame.canvas.clientWidth;
|
3635 | }
|
3636 | else {
|
3637 | this.xcenter = parseFloat(this.defaultXCenter);
|
3638 | }
|
3639 |
|
3640 |
|
3641 | if (this.defaultYCenter.charAt(this.defaultYCenter.length-1) === '%') {
|
3642 | this.ycenter =
|
3643 | parseFloat(this.defaultYCenter) / 100 *
|
3644 | (this.frame.canvas.clientHeight - this.frame.filter.clientHeight);
|
3645 | }
|
3646 | else {
|
3647 | this.ycenter = parseFloat(this.defaultYCenter);
|
3648 | }
|
3649 | };
|
3650 |
|
3651 | |
3652 |
|
3653 |
|
3654 |
|
3655 |
|
3656 |
|
3657 |
|
3658 |
|
3659 |
|
3660 |
|
3661 |
|
3662 |
|
3663 |
|
3664 |
|
3665 |
|
3666 |
|
3667 | Graph3d.prototype.setCameraPosition = function(pos) {
|
3668 | if (pos === undefined) {
|
3669 | return;
|
3670 | }
|
3671 |
|
3672 | if (pos.horizontal !== undefined && pos.vertical !== undefined) {
|
3673 | this.camera.setArmRotation(pos.horizontal, pos.vertical);
|
3674 | }
|
3675 |
|
3676 | if (pos.distance !== undefined) {
|
3677 | this.camera.setArmLength(pos.distance);
|
3678 | }
|
3679 |
|
3680 | this.redraw();
|
3681 | };
|
3682 |
|
3683 |
|
3684 | |
3685 |
|
3686 |
|
3687 |
|
3688 |
|
3689 | Graph3d.prototype.getCameraPosition = function() {
|
3690 | var pos = this.camera.getArmRotation();
|
3691 | pos.distance = this.camera.getArmLength();
|
3692 | return pos;
|
3693 | };
|
3694 |
|
3695 | |
3696 |
|
3697 |
|
3698 | Graph3d.prototype._readData = function(data) {
|
3699 |
|
3700 | this._dataInitialize(data, this.style);
|
3701 |
|
3702 |
|
3703 | if (this.dataFilter) {
|
3704 |
|
3705 | this.dataPoints = this.dataFilter._getDataPoints();
|
3706 | }
|
3707 | else {
|
3708 |
|
3709 | this.dataPoints = this._getDataPoints(this.dataTable);
|
3710 | }
|
3711 |
|
3712 |
|
3713 | this._redrawFilter();
|
3714 | };
|
3715 |
|
3716 | |
3717 |
|
3718 |
|
3719 |
|
3720 | Graph3d.prototype.setData = function (data) {
|
3721 | this._readData(data);
|
3722 | this.redraw();
|
3723 |
|
3724 |
|
3725 | if (this.animationAutoStart && this.dataFilter) {
|
3726 | this.animationStart();
|
3727 | }
|
3728 | };
|
3729 |
|
3730 | |
3731 |
|
3732 |
|
3733 |
|
3734 | Graph3d.prototype.setOptions = function (options) {
|
3735 | var cameraPosition = undefined;
|
3736 |
|
3737 | this.animationStop();
|
3738 |
|
3739 | if (options !== undefined) {
|
3740 |
|
3741 | if (options.width !== undefined) this.width = options.width;
|
3742 | if (options.height !== undefined) this.height = options.height;
|
3743 |
|
3744 | if (options.xCenter !== undefined) this.defaultXCenter = options.xCenter;
|
3745 | if (options.yCenter !== undefined) this.defaultYCenter = options.yCenter;
|
3746 |
|
3747 | if (options.filterLabel !== undefined) this.filterLabel = options.filterLabel;
|
3748 | if (options.legendLabel !== undefined) this.legendLabel = options.legendLabel;
|
3749 | if (options.xLabel !== undefined) this.xLabel = options.xLabel;
|
3750 | if (options.yLabel !== undefined) this.yLabel = options.yLabel;
|
3751 | if (options.zLabel !== undefined) this.zLabel = options.zLabel;
|
3752 |
|
3753 | if (options.style !== undefined) {
|
3754 | var styleNumber = this._getStyleNumber(options.style);
|
3755 | if (styleNumber !== -1) {
|
3756 | this.style = styleNumber;
|
3757 | }
|
3758 | }
|
3759 | if (options.showGrid !== undefined) this.showGrid = options.showGrid;
|
3760 | if (options.showPerspective !== undefined) this.showPerspective = options.showPerspective;
|
3761 | if (options.showShadow !== undefined) this.showShadow = options.showShadow;
|
3762 | if (options.tooltip !== undefined) this.showTooltip = options.tooltip;
|
3763 | if (options.showAnimationControls !== undefined) this.showAnimationControls = options.showAnimationControls;
|
3764 | if (options.keepAspectRatio !== undefined) this.keepAspectRatio = options.keepAspectRatio;
|
3765 | if (options.verticalRatio !== undefined) this.verticalRatio = options.verticalRatio;
|
3766 |
|
3767 | if (options.animationInterval !== undefined) this.animationInterval = options.animationInterval;
|
3768 | if (options.animationPreload !== undefined) this.animationPreload = options.animationPreload;
|
3769 | if (options.animationAutoStart !== undefined)this.animationAutoStart = options.animationAutoStart;
|
3770 |
|
3771 | if (options.xBarWidth !== undefined) this.defaultXBarWidth = options.xBarWidth;
|
3772 | if (options.yBarWidth !== undefined) this.defaultYBarWidth = options.yBarWidth;
|
3773 |
|
3774 | if (options.xMin !== undefined) this.defaultXMin = options.xMin;
|
3775 | if (options.xStep !== undefined) this.defaultXStep = options.xStep;
|
3776 | if (options.xMax !== undefined) this.defaultXMax = options.xMax;
|
3777 | if (options.yMin !== undefined) this.defaultYMin = options.yMin;
|
3778 | if (options.yStep !== undefined) this.defaultYStep = options.yStep;
|
3779 | if (options.yMax !== undefined) this.defaultYMax = options.yMax;
|
3780 | if (options.zMin !== undefined) this.defaultZMin = options.zMin;
|
3781 | if (options.zStep !== undefined) this.defaultZStep = options.zStep;
|
3782 | if (options.zMax !== undefined) this.defaultZMax = options.zMax;
|
3783 | if (options.valueMin !== undefined) this.defaultValueMin = options.valueMin;
|
3784 | if (options.valueMax !== undefined) this.defaultValueMax = options.valueMax;
|
3785 |
|
3786 | if (options.cameraPosition !== undefined) cameraPosition = options.cameraPosition;
|
3787 |
|
3788 | if (cameraPosition !== undefined) {
|
3789 | this.camera.setArmRotation(cameraPosition.horizontal, cameraPosition.vertical);
|
3790 | this.camera.setArmLength(cameraPosition.distance);
|
3791 | }
|
3792 | else {
|
3793 | this.camera.setArmRotation(1.0, 0.5);
|
3794 | this.camera.setArmLength(1.7);
|
3795 | }
|
3796 | }
|
3797 |
|
3798 | this._setBackgroundColor(options && options.backgroundColor);
|
3799 |
|
3800 | this.setSize(this.width, this.height);
|
3801 |
|
3802 |
|
3803 | if (this.dataTable) {
|
3804 | this.setData(this.dataTable);
|
3805 | }
|
3806 |
|
3807 |
|
3808 | if (this.animationAutoStart && this.dataFilter) {
|
3809 | this.animationStart();
|
3810 | }
|
3811 | };
|
3812 |
|
3813 | |
3814 |
|
3815 |
|
3816 | Graph3d.prototype.redraw = function() {
|
3817 | if (this.dataPoints === undefined) {
|
3818 | throw 'Error: graph data not initialized';
|
3819 | }
|
3820 |
|
3821 | this._resizeCanvas();
|
3822 | this._resizeCenter();
|
3823 | this._redrawSlider();
|
3824 | this._redrawClear();
|
3825 | this._redrawAxis();
|
3826 |
|
3827 | if (this.style === Graph3d.STYLE.GRID ||
|
3828 | this.style === Graph3d.STYLE.SURFACE) {
|
3829 | this._redrawDataGrid();
|
3830 | }
|
3831 | else if (this.style === Graph3d.STYLE.LINE) {
|
3832 | this._redrawDataLine();
|
3833 | }
|
3834 | else if (this.style === Graph3d.STYLE.BAR ||
|
3835 | this.style === Graph3d.STYLE.BARCOLOR ||
|
3836 | this.style === Graph3d.STYLE.BARSIZE) {
|
3837 | this._redrawDataBar();
|
3838 | }
|
3839 | else {
|
3840 |
|
3841 | this._redrawDataDot();
|
3842 | }
|
3843 |
|
3844 | this._redrawInfo();
|
3845 | this._redrawLegend();
|
3846 | };
|
3847 |
|
3848 | |
3849 |
|
3850 |
|
3851 | Graph3d.prototype._redrawClear = function() {
|
3852 | var canvas = this.frame.canvas;
|
3853 | var ctx = canvas.getContext('2d');
|
3854 |
|
3855 | ctx.clearRect(0, 0, canvas.width, canvas.height);
|
3856 | };
|
3857 |
|
3858 |
|
3859 | |
3860 |
|
3861 |
|
3862 | Graph3d.prototype._redrawLegend = function() {
|
3863 | var y;
|
3864 |
|
3865 | if (this.style === Graph3d.STYLE.DOTCOLOR ||
|
3866 | this.style === Graph3d.STYLE.DOTSIZE) {
|
3867 |
|
3868 | var dotSize = this.frame.clientWidth * 0.02;
|
3869 |
|
3870 | var widthMin, widthMax;
|
3871 | if (this.style === Graph3d.STYLE.DOTSIZE) {
|
3872 | widthMin = dotSize / 2;
|
3873 | widthMax = dotSize / 2 + dotSize * 2;
|
3874 | }
|
3875 | else {
|
3876 | widthMin = 20;
|
3877 | widthMax = 20;
|
3878 | }
|
3879 |
|
3880 | var height = Math.max(this.frame.clientHeight * 0.25, 100);
|
3881 | var top = this.margin;
|
3882 | var right = this.frame.clientWidth - this.margin;
|
3883 | var left = right - widthMax;
|
3884 | var bottom = top + height;
|
3885 | }
|
3886 |
|
3887 | var canvas = this.frame.canvas;
|
3888 | var ctx = canvas.getContext('2d');
|
3889 | ctx.lineWidth = 1;
|
3890 | ctx.font = '14px arial';
|
3891 |
|
3892 | if (this.style === Graph3d.STYLE.DOTCOLOR) {
|
3893 |
|
3894 | var ymin = 0;
|
3895 | var ymax = height;
|
3896 | for (y = ymin; y < ymax; y++) {
|
3897 | var f = (y - ymin) / (ymax - ymin);
|
3898 |
|
3899 |
|
3900 | var hue = f * 240;
|
3901 | var color = this._hsv2rgb(hue, 1, 1);
|
3902 |
|
3903 | ctx.strokeStyle = color;
|
3904 | ctx.beginPath();
|
3905 | ctx.moveTo(left, top + y);
|
3906 | ctx.lineTo(right, top + y);
|
3907 | ctx.stroke();
|
3908 | }
|
3909 |
|
3910 | ctx.strokeStyle = this.colorAxis;
|
3911 | ctx.strokeRect(left, top, widthMax, height);
|
3912 | }
|
3913 |
|
3914 | if (this.style === Graph3d.STYLE.DOTSIZE) {
|
3915 |
|
3916 | ctx.strokeStyle = this.colorAxis;
|
3917 | ctx.fillStyle = this.colorDot;
|
3918 | ctx.beginPath();
|
3919 | ctx.moveTo(left, top);
|
3920 | ctx.lineTo(right, top);
|
3921 | ctx.lineTo(right - widthMax + widthMin, bottom);
|
3922 | ctx.lineTo(left, bottom);
|
3923 | ctx.closePath();
|
3924 | ctx.fill();
|
3925 | ctx.stroke();
|
3926 | }
|
3927 |
|
3928 | if (this.style === Graph3d.STYLE.DOTCOLOR ||
|
3929 | this.style === Graph3d.STYLE.DOTSIZE) {
|
3930 |
|
3931 | var gridLineLen = 5;
|
3932 | var step = new StepNumber(this.valueMin, this.valueMax, (this.valueMax-this.valueMin)/5, true);
|
3933 | step.start();
|
3934 | if (step.getCurrent() < this.valueMin) {
|
3935 | step.next();
|
3936 | }
|
3937 | while (!step.end()) {
|
3938 | y = bottom - (step.getCurrent() - this.valueMin) / (this.valueMax - this.valueMin) * height;
|
3939 |
|
3940 | ctx.beginPath();
|
3941 | ctx.moveTo(left - gridLineLen, y);
|
3942 | ctx.lineTo(left, y);
|
3943 | ctx.stroke();
|
3944 |
|
3945 | ctx.textAlign = 'right';
|
3946 | ctx.textBaseline = 'middle';
|
3947 | ctx.fillStyle = this.colorAxis;
|
3948 | ctx.fillText(step.getCurrent(), left - 2 * gridLineLen, y);
|
3949 |
|
3950 | step.next();
|
3951 | }
|
3952 |
|
3953 | ctx.textAlign = 'right';
|
3954 | ctx.textBaseline = 'top';
|
3955 | var label = this.legendLabel;
|
3956 | ctx.fillText(label, right, bottom + this.margin);
|
3957 | }
|
3958 | };
|
3959 |
|
3960 | |
3961 |
|
3962 |
|
3963 | Graph3d.prototype._redrawFilter = function() {
|
3964 | this.frame.filter.innerHTML = '';
|
3965 |
|
3966 | if (this.dataFilter) {
|
3967 | var options = {
|
3968 | 'visible': this.showAnimationControls
|
3969 | };
|
3970 | var slider = new Slider(this.frame.filter, options);
|
3971 | this.frame.filter.slider = slider;
|
3972 |
|
3973 |
|
3974 | this.frame.filter.style.padding = '10px';
|
3975 |
|
3976 |
|
3977 | slider.setValues(this.dataFilter.values);
|
3978 | slider.setPlayInterval(this.animationInterval);
|
3979 |
|
3980 |
|
3981 | var me = this;
|
3982 | var onchange = function () {
|
3983 | var index = slider.getIndex();
|
3984 |
|
3985 | me.dataFilter.selectValue(index);
|
3986 | me.dataPoints = me.dataFilter._getDataPoints();
|
3987 |
|
3988 | me.redraw();
|
3989 | };
|
3990 | slider.setOnChangeCallback(onchange);
|
3991 | }
|
3992 | else {
|
3993 | this.frame.filter.slider = undefined;
|
3994 | }
|
3995 | };
|
3996 |
|
3997 | |
3998 |
|
3999 |
|
4000 | Graph3d.prototype._redrawSlider = function() {
|
4001 | if ( this.frame.filter.slider !== undefined) {
|
4002 | this.frame.filter.slider.redraw();
|
4003 | }
|
4004 | };
|
4005 |
|
4006 |
|
4007 | |
4008 |
|
4009 |
|
4010 | Graph3d.prototype._redrawInfo = function() {
|
4011 | if (this.dataFilter) {
|
4012 | var canvas = this.frame.canvas;
|
4013 | var ctx = canvas.getContext('2d');
|
4014 |
|
4015 | ctx.font = '14px arial';
|
4016 | ctx.lineStyle = 'gray';
|
4017 | ctx.fillStyle = 'gray';
|
4018 | ctx.textAlign = 'left';
|
4019 | ctx.textBaseline = 'top';
|
4020 |
|
4021 | var x = this.margin;
|
4022 | var y = this.margin;
|
4023 | ctx.fillText(this.dataFilter.getLabel() + ': ' + this.dataFilter.getSelectedValue(), x, y);
|
4024 | }
|
4025 | };
|
4026 |
|
4027 |
|
4028 | |
4029 |
|
4030 |
|
4031 | Graph3d.prototype._redrawAxis = function() {
|
4032 | var canvas = this.frame.canvas,
|
4033 | ctx = canvas.getContext('2d'),
|
4034 | from, to, step, prettyStep,
|
4035 | text, xText, yText, zText,
|
4036 | offset, xOffset, yOffset,
|
4037 | xMin2d, xMax2d;
|
4038 |
|
4039 |
|
4040 |
|
4041 | ctx.font = 24 / this.camera.getArmLength() + 'px arial';
|
4042 |
|
4043 |
|
4044 | var gridLenX = 0.025 / this.scale.x;
|
4045 | var gridLenY = 0.025 / this.scale.y;
|
4046 | var textMargin = 5 / this.camera.getArmLength();
|
4047 | var armAngle = this.camera.getArmRotation().horizontal;
|
4048 |
|
4049 |
|
4050 | ctx.lineWidth = 1;
|
4051 | prettyStep = (this.defaultXStep === undefined);
|
4052 | step = new StepNumber(this.xMin, this.xMax, this.xStep, prettyStep);
|
4053 | step.start();
|
4054 | if (step.getCurrent() < this.xMin) {
|
4055 | step.next();
|
4056 | }
|
4057 | while (!step.end()) {
|
4058 | var x = step.getCurrent();
|
4059 |
|
4060 | if (this.showGrid) {
|
4061 | from = this._convert3Dto2D(new Point3d(x, this.yMin, this.zMin));
|
4062 | to = this._convert3Dto2D(new Point3d(x, this.yMax, this.zMin));
|
4063 | ctx.strokeStyle = this.colorGrid;
|
4064 | ctx.beginPath();
|
4065 | ctx.moveTo(from.x, from.y);
|
4066 | ctx.lineTo(to.x, to.y);
|
4067 | ctx.stroke();
|
4068 | }
|
4069 | else {
|
4070 | from = this._convert3Dto2D(new Point3d(x, this.yMin, this.zMin));
|
4071 | to = this._convert3Dto2D(new Point3d(x, this.yMin+gridLenX, this.zMin));
|
4072 | ctx.strokeStyle = this.colorAxis;
|
4073 | ctx.beginPath();
|
4074 | ctx.moveTo(from.x, from.y);
|
4075 | ctx.lineTo(to.x, to.y);
|
4076 | ctx.stroke();
|
4077 |
|
4078 | from = this._convert3Dto2D(new Point3d(x, this.yMax, this.zMin));
|
4079 | to = this._convert3Dto2D(new Point3d(x, this.yMax-gridLenX, this.zMin));
|
4080 | ctx.strokeStyle = this.colorAxis;
|
4081 | ctx.beginPath();
|
4082 | ctx.moveTo(from.x, from.y);
|
4083 | ctx.lineTo(to.x, to.y);
|
4084 | ctx.stroke();
|
4085 | }
|
4086 |
|
4087 | yText = (Math.cos(armAngle) > 0) ? this.yMin : this.yMax;
|
4088 | text = this._convert3Dto2D(new Point3d(x, yText, this.zMin));
|
4089 | if (Math.cos(armAngle * 2) > 0) {
|
4090 | ctx.textAlign = 'center';
|
4091 | ctx.textBaseline = 'top';
|
4092 | text.y += textMargin;
|
4093 | }
|
4094 | else if (Math.sin(armAngle * 2) < 0){
|
4095 | ctx.textAlign = 'right';
|
4096 | ctx.textBaseline = 'middle';
|
4097 | }
|
4098 | else {
|
4099 | ctx.textAlign = 'left';
|
4100 | ctx.textBaseline = 'middle';
|
4101 | }
|
4102 | ctx.fillStyle = this.colorAxis;
|
4103 | ctx.fillText(' ' + step.getCurrent() + ' ', text.x, text.y);
|
4104 |
|
4105 | step.next();
|
4106 | }
|
4107 |
|
4108 |
|
4109 | ctx.lineWidth = 1;
|
4110 | prettyStep = (this.defaultYStep === undefined);
|
4111 | step = new StepNumber(this.yMin, this.yMax, this.yStep, prettyStep);
|
4112 | step.start();
|
4113 | if (step.getCurrent() < this.yMin) {
|
4114 | step.next();
|
4115 | }
|
4116 | while (!step.end()) {
|
4117 | if (this.showGrid) {
|
4118 | from = this._convert3Dto2D(new Point3d(this.xMin, step.getCurrent(), this.zMin));
|
4119 | to = this._convert3Dto2D(new Point3d(this.xMax, step.getCurrent(), this.zMin));
|
4120 | ctx.strokeStyle = this.colorGrid;
|
4121 | ctx.beginPath();
|
4122 | ctx.moveTo(from.x, from.y);
|
4123 | ctx.lineTo(to.x, to.y);
|
4124 | ctx.stroke();
|
4125 | }
|
4126 | else {
|
4127 | from = this._convert3Dto2D(new Point3d(this.xMin, step.getCurrent(), this.zMin));
|
4128 | to = this._convert3Dto2D(new Point3d(this.xMin+gridLenY, step.getCurrent(), this.zMin));
|
4129 | ctx.strokeStyle = this.colorAxis;
|
4130 | ctx.beginPath();
|
4131 | ctx.moveTo(from.x, from.y);
|
4132 | ctx.lineTo(to.x, to.y);
|
4133 | ctx.stroke();
|
4134 |
|
4135 | from = this._convert3Dto2D(new Point3d(this.xMax, step.getCurrent(), this.zMin));
|
4136 | to = this._convert3Dto2D(new Point3d(this.xMax-gridLenY, step.getCurrent(), this.zMin));
|
4137 | ctx.strokeStyle = this.colorAxis;
|
4138 | ctx.beginPath();
|
4139 | ctx.moveTo(from.x, from.y);
|
4140 | ctx.lineTo(to.x, to.y);
|
4141 | ctx.stroke();
|
4142 | }
|
4143 |
|
4144 | xText = (Math.sin(armAngle ) > 0) ? this.xMin : this.xMax;
|
4145 | text = this._convert3Dto2D(new Point3d(xText, step.getCurrent(), this.zMin));
|
4146 | if (Math.cos(armAngle * 2) < 0) {
|
4147 | ctx.textAlign = 'center';
|
4148 | ctx.textBaseline = 'top';
|
4149 | text.y += textMargin;
|
4150 | }
|
4151 | else if (Math.sin(armAngle * 2) > 0){
|
4152 | ctx.textAlign = 'right';
|
4153 | ctx.textBaseline = 'middle';
|
4154 | }
|
4155 | else {
|
4156 | ctx.textAlign = 'left';
|
4157 | ctx.textBaseline = 'middle';
|
4158 | }
|
4159 | ctx.fillStyle = this.colorAxis;
|
4160 | ctx.fillText(' ' + step.getCurrent() + ' ', text.x, text.y);
|
4161 |
|
4162 | step.next();
|
4163 | }
|
4164 |
|
4165 |
|
4166 | ctx.lineWidth = 1;
|
4167 | prettyStep = (this.defaultZStep === undefined);
|
4168 | step = new StepNumber(this.zMin, this.zMax, this.zStep, prettyStep);
|
4169 | step.start();
|
4170 | if (step.getCurrent() < this.zMin) {
|
4171 | step.next();
|
4172 | }
|
4173 | xText = (Math.cos(armAngle ) > 0) ? this.xMin : this.xMax;
|
4174 | yText = (Math.sin(armAngle ) < 0) ? this.yMin : this.yMax;
|
4175 | while (!step.end()) {
|
4176 |
|
4177 | from = this._convert3Dto2D(new Point3d(xText, yText, step.getCurrent()));
|
4178 | ctx.strokeStyle = this.colorAxis;
|
4179 | ctx.beginPath();
|
4180 | ctx.moveTo(from.x, from.y);
|
4181 | ctx.lineTo(from.x - textMargin, from.y);
|
4182 | ctx.stroke();
|
4183 |
|
4184 | ctx.textAlign = 'right';
|
4185 | ctx.textBaseline = 'middle';
|
4186 | ctx.fillStyle = this.colorAxis;
|
4187 | ctx.fillText(step.getCurrent() + ' ', from.x - 5, from.y);
|
4188 |
|
4189 | step.next();
|
4190 | }
|
4191 | ctx.lineWidth = 1;
|
4192 | from = this._convert3Dto2D(new Point3d(xText, yText, this.zMin));
|
4193 | to = this._convert3Dto2D(new Point3d(xText, yText, this.zMax));
|
4194 | ctx.strokeStyle = this.colorAxis;
|
4195 | ctx.beginPath();
|
4196 | ctx.moveTo(from.x, from.y);
|
4197 | ctx.lineTo(to.x, to.y);
|
4198 | ctx.stroke();
|
4199 |
|
4200 |
|
4201 | ctx.lineWidth = 1;
|
4202 |
|
4203 | xMin2d = this._convert3Dto2D(new Point3d(this.xMin, this.yMin, this.zMin));
|
4204 | xMax2d = this._convert3Dto2D(new Point3d(this.xMax, this.yMin, this.zMin));
|
4205 | ctx.strokeStyle = this.colorAxis;
|
4206 | ctx.beginPath();
|
4207 | ctx.moveTo(xMin2d.x, xMin2d.y);
|
4208 | ctx.lineTo(xMax2d.x, xMax2d.y);
|
4209 | ctx.stroke();
|
4210 |
|
4211 | xMin2d = this._convert3Dto2D(new Point3d(this.xMin, this.yMax, this.zMin));
|
4212 | xMax2d = this._convert3Dto2D(new Point3d(this.xMax, this.yMax, this.zMin));
|
4213 | ctx.strokeStyle = this.colorAxis;
|
4214 | ctx.beginPath();
|
4215 | ctx.moveTo(xMin2d.x, xMin2d.y);
|
4216 | ctx.lineTo(xMax2d.x, xMax2d.y);
|
4217 | ctx.stroke();
|
4218 |
|
4219 |
|
4220 | ctx.lineWidth = 1;
|
4221 |
|
4222 | from = this._convert3Dto2D(new Point3d(this.xMin, this.yMin, this.zMin));
|
4223 | to = this._convert3Dto2D(new Point3d(this.xMin, this.yMax, this.zMin));
|
4224 | ctx.strokeStyle = this.colorAxis;
|
4225 | ctx.beginPath();
|
4226 | ctx.moveTo(from.x, from.y);
|
4227 | ctx.lineTo(to.x, to.y);
|
4228 | ctx.stroke();
|
4229 |
|
4230 | from = this._convert3Dto2D(new Point3d(this.xMax, this.yMin, this.zMin));
|
4231 | to = this._convert3Dto2D(new Point3d(this.xMax, this.yMax, this.zMin));
|
4232 | ctx.strokeStyle = this.colorAxis;
|
4233 | ctx.beginPath();
|
4234 | ctx.moveTo(from.x, from.y);
|
4235 | ctx.lineTo(to.x, to.y);
|
4236 | ctx.stroke();
|
4237 |
|
4238 |
|
4239 | var xLabel = this.xLabel;
|
4240 | if (xLabel.length > 0) {
|
4241 | yOffset = 0.1 / this.scale.y;
|
4242 | xText = (this.xMin + this.xMax) / 2;
|
4243 | yText = (Math.cos(armAngle) > 0) ? this.yMin - yOffset: this.yMax + yOffset;
|
4244 | text = this._convert3Dto2D(new Point3d(xText, yText, this.zMin));
|
4245 | if (Math.cos(armAngle * 2) > 0) {
|
4246 | ctx.textAlign = 'center';
|
4247 | ctx.textBaseline = 'top';
|
4248 | }
|
4249 | else if (Math.sin(armAngle * 2) < 0){
|
4250 | ctx.textAlign = 'right';
|
4251 | ctx.textBaseline = 'middle';
|
4252 | }
|
4253 | else {
|
4254 | ctx.textAlign = 'left';
|
4255 | ctx.textBaseline = 'middle';
|
4256 | }
|
4257 | ctx.fillStyle = this.colorAxis;
|
4258 | ctx.fillText(xLabel, text.x, text.y);
|
4259 | }
|
4260 |
|
4261 |
|
4262 | var yLabel = this.yLabel;
|
4263 | if (yLabel.length > 0) {
|
4264 | xOffset = 0.1 / this.scale.x;
|
4265 | xText = (Math.sin(armAngle ) > 0) ? this.xMin - xOffset : this.xMax + xOffset;
|
4266 | yText = (this.yMin + this.yMax) / 2;
|
4267 | text = this._convert3Dto2D(new Point3d(xText, yText, this.zMin));
|
4268 | if (Math.cos(armAngle * 2) < 0) {
|
4269 | ctx.textAlign = 'center';
|
4270 | ctx.textBaseline = 'top';
|
4271 | }
|
4272 | else if (Math.sin(armAngle * 2) > 0){
|
4273 | ctx.textAlign = 'right';
|
4274 | ctx.textBaseline = 'middle';
|
4275 | }
|
4276 | else {
|
4277 | ctx.textAlign = 'left';
|
4278 | ctx.textBaseline = 'middle';
|
4279 | }
|
4280 | ctx.fillStyle = this.colorAxis;
|
4281 | ctx.fillText(yLabel, text.x, text.y);
|
4282 | }
|
4283 |
|
4284 |
|
4285 | var zLabel = this.zLabel;
|
4286 | if (zLabel.length > 0) {
|
4287 | offset = 30;
|
4288 | xText = (Math.cos(armAngle ) > 0) ? this.xMin : this.xMax;
|
4289 | yText = (Math.sin(armAngle ) < 0) ? this.yMin : this.yMax;
|
4290 | zText = (this.zMin + this.zMax) / 2;
|
4291 | text = this._convert3Dto2D(new Point3d(xText, yText, zText));
|
4292 | ctx.textAlign = 'right';
|
4293 | ctx.textBaseline = 'middle';
|
4294 | ctx.fillStyle = this.colorAxis;
|
4295 | ctx.fillText(zLabel, text.x - offset, text.y);
|
4296 | }
|
4297 | };
|
4298 |
|
4299 | |
4300 |
|
4301 |
|
4302 |
|
4303 |
|
4304 |
|
4305 | Graph3d.prototype._hsv2rgb = function(H, S, V) {
|
4306 | var R, G, B, C, Hi, X;
|
4307 |
|
4308 | C = V * S;
|
4309 | Hi = Math.floor(H/60);
|
4310 | X = C * (1 - Math.abs(((H/60) % 2) - 1));
|
4311 |
|
4312 | switch (Hi) {
|
4313 | case 0: R = C; G = X; B = 0; break;
|
4314 | case 1: R = X; G = C; B = 0; break;
|
4315 | case 2: R = 0; G = C; B = X; break;
|
4316 | case 3: R = 0; G = X; B = C; break;
|
4317 | case 4: R = X; G = 0; B = C; break;
|
4318 | case 5: R = C; G = 0; B = X; break;
|
4319 |
|
4320 | default: R = 0; G = 0; B = 0; break;
|
4321 | }
|
4322 |
|
4323 | return 'RGB(' + parseInt(R*255) + ',' + parseInt(G*255) + ',' + parseInt(B*255) + ')';
|
4324 | };
|
4325 |
|
4326 |
|
4327 | |
4328 |
|
4329 |
|
4330 |
|
4331 | Graph3d.prototype._redrawDataGrid = function() {
|
4332 | var canvas = this.frame.canvas,
|
4333 | ctx = canvas.getContext('2d'),
|
4334 | point, right, top, cross,
|
4335 | i,
|
4336 | topSideVisible, fillStyle, strokeStyle, lineWidth,
|
4337 | h, s, v, zAvg;
|
4338 |
|
4339 |
|
4340 | if (this.dataPoints === undefined || this.dataPoints.length <= 0)
|
4341 | return;
|
4342 |
|
4343 |
|
4344 | for (i = 0; i < this.dataPoints.length; i++) {
|
4345 | var trans = this._convertPointToTranslation(this.dataPoints[i].point);
|
4346 | var screen = this._convertTranslationToScreen(trans);
|
4347 |
|
4348 | this.dataPoints[i].trans = trans;
|
4349 | this.dataPoints[i].screen = screen;
|
4350 |
|
4351 |
|
4352 | var transBottom = this._convertPointToTranslation(this.dataPoints[i].bottom);
|
4353 | this.dataPoints[i].dist = this.showPerspective ? transBottom.length() : -transBottom.z;
|
4354 | }
|
4355 |
|
4356 |
|
4357 | var sortDepth = function (a, b) {
|
4358 | return b.dist - a.dist;
|
4359 | };
|
4360 | this.dataPoints.sort(sortDepth);
|
4361 |
|
4362 | if (this.style === Graph3d.STYLE.SURFACE) {
|
4363 | for (i = 0; i < this.dataPoints.length; i++) {
|
4364 | point = this.dataPoints[i];
|
4365 | right = this.dataPoints[i].pointRight;
|
4366 | top = this.dataPoints[i].pointTop;
|
4367 | cross = this.dataPoints[i].pointCross;
|
4368 |
|
4369 | if (point !== undefined && right !== undefined && top !== undefined && cross !== undefined) {
|
4370 |
|
4371 | if (this.showGrayBottom || this.showShadow) {
|
4372 |
|
4373 |
|
4374 |
|
4375 |
|
4376 | var aDiff = Point3d.subtract(cross.trans, point.trans);
|
4377 | var bDiff = Point3d.subtract(top.trans, right.trans);
|
4378 | var crossproduct = Point3d.crossProduct(aDiff, bDiff);
|
4379 | var len = crossproduct.length();
|
4380 |
|
4381 |
|
4382 | topSideVisible = (crossproduct.z > 0);
|
4383 | }
|
4384 | else {
|
4385 | topSideVisible = true;
|
4386 | }
|
4387 |
|
4388 | if (topSideVisible) {
|
4389 |
|
4390 | zAvg = (point.point.z + right.point.z + top.point.z + cross.point.z) / 4;
|
4391 | h = (1 - (zAvg - this.zMin) * this.scale.z / this.verticalRatio) * 240;
|
4392 | s = 1;
|
4393 |
|
4394 | if (this.showShadow) {
|
4395 | v = Math.min(1 + (crossproduct.x / len) / 2, 1);
|
4396 | fillStyle = this._hsv2rgb(h, s, v);
|
4397 | strokeStyle = fillStyle;
|
4398 | }
|
4399 | else {
|
4400 | v = 1;
|
4401 | fillStyle = this._hsv2rgb(h, s, v);
|
4402 | strokeStyle = this.colorAxis;
|
4403 | }
|
4404 | }
|
4405 | else {
|
4406 | fillStyle = 'gray';
|
4407 | strokeStyle = this.colorAxis;
|
4408 | }
|
4409 | lineWidth = 0.5;
|
4410 |
|
4411 | ctx.lineWidth = lineWidth;
|
4412 | ctx.fillStyle = fillStyle;
|
4413 | ctx.strokeStyle = strokeStyle;
|
4414 | ctx.beginPath();
|
4415 | ctx.moveTo(point.screen.x, point.screen.y);
|
4416 | ctx.lineTo(right.screen.x, right.screen.y);
|
4417 | ctx.lineTo(cross.screen.x, cross.screen.y);
|
4418 | ctx.lineTo(top.screen.x, top.screen.y);
|
4419 | ctx.closePath();
|
4420 | ctx.fill();
|
4421 | ctx.stroke();
|
4422 | }
|
4423 | }
|
4424 | }
|
4425 | else {
|
4426 | for (i = 0; i < this.dataPoints.length; i++) {
|
4427 | point = this.dataPoints[i];
|
4428 | right = this.dataPoints[i].pointRight;
|
4429 | top = this.dataPoints[i].pointTop;
|
4430 |
|
4431 | if (point !== undefined) {
|
4432 | if (this.showPerspective) {
|
4433 | lineWidth = 2 / -point.trans.z;
|
4434 | }
|
4435 | else {
|
4436 | lineWidth = 2 * -(this.eye.z / this.camera.getArmLength());
|
4437 | }
|
4438 | }
|
4439 |
|
4440 | if (point !== undefined && right !== undefined) {
|
4441 |
|
4442 | zAvg = (point.point.z + right.point.z) / 2;
|
4443 | h = (1 - (zAvg - this.zMin) * this.scale.z / this.verticalRatio) * 240;
|
4444 |
|
4445 | ctx.lineWidth = lineWidth;
|
4446 | ctx.strokeStyle = this._hsv2rgb(h, 1, 1);
|
4447 | ctx.beginPath();
|
4448 | ctx.moveTo(point.screen.x, point.screen.y);
|
4449 | ctx.lineTo(right.screen.x, right.screen.y);
|
4450 | ctx.stroke();
|
4451 | }
|
4452 |
|
4453 | if (point !== undefined && top !== undefined) {
|
4454 |
|
4455 | zAvg = (point.point.z + top.point.z) / 2;
|
4456 | h = (1 - (zAvg - this.zMin) * this.scale.z / this.verticalRatio) * 240;
|
4457 |
|
4458 | ctx.lineWidth = lineWidth;
|
4459 | ctx.strokeStyle = this._hsv2rgb(h, 1, 1);
|
4460 | ctx.beginPath();
|
4461 | ctx.moveTo(point.screen.x, point.screen.y);
|
4462 | ctx.lineTo(top.screen.x, top.screen.y);
|
4463 | ctx.stroke();
|
4464 | }
|
4465 | }
|
4466 | }
|
4467 | };
|
4468 |
|
4469 |
|
4470 | |
4471 |
|
4472 |
|
4473 |
|
4474 | Graph3d.prototype._redrawDataDot = function() {
|
4475 | var canvas = this.frame.canvas;
|
4476 | var ctx = canvas.getContext('2d');
|
4477 | var i;
|
4478 |
|
4479 | if (this.dataPoints === undefined || this.dataPoints.length <= 0)
|
4480 | return;
|
4481 |
|
4482 |
|
4483 | for (i = 0; i < this.dataPoints.length; i++) {
|
4484 | var trans = this._convertPointToTranslation(this.dataPoints[i].point);
|
4485 | var screen = this._convertTranslationToScreen(trans);
|
4486 | this.dataPoints[i].trans = trans;
|
4487 | this.dataPoints[i].screen = screen;
|
4488 |
|
4489 |
|
4490 | var transBottom = this._convertPointToTranslation(this.dataPoints[i].bottom);
|
4491 | this.dataPoints[i].dist = this.showPerspective ? transBottom.length() : -transBottom.z;
|
4492 | }
|
4493 |
|
4494 |
|
4495 | var sortDepth = function (a, b) {
|
4496 | return b.dist - a.dist;
|
4497 | };
|
4498 | this.dataPoints.sort(sortDepth);
|
4499 |
|
4500 |
|
4501 | var dotSize = this.frame.clientWidth * 0.02;
|
4502 | for (i = 0; i < this.dataPoints.length; i++) {
|
4503 | var point = this.dataPoints[i];
|
4504 |
|
4505 | if (this.style === Graph3d.STYLE.DOTLINE) {
|
4506 |
|
4507 |
|
4508 | var from = this._convert3Dto2D(point.bottom);
|
4509 | ctx.lineWidth = 1;
|
4510 | ctx.strokeStyle = this.colorGrid;
|
4511 | ctx.beginPath();
|
4512 | ctx.moveTo(from.x, from.y);
|
4513 | ctx.lineTo(point.screen.x, point.screen.y);
|
4514 | ctx.stroke();
|
4515 | }
|
4516 |
|
4517 |
|
4518 | var size;
|
4519 | if (this.style === Graph3d.STYLE.DOTSIZE) {
|
4520 | size = dotSize/2 + 2*dotSize * (point.point.value - this.valueMin) / (this.valueMax - this.valueMin);
|
4521 | }
|
4522 | else {
|
4523 | size = dotSize;
|
4524 | }
|
4525 |
|
4526 | var radius;
|
4527 | if (this.showPerspective) {
|
4528 | radius = size / -point.trans.z;
|
4529 | }
|
4530 | else {
|
4531 | radius = size * -(this.eye.z / this.camera.getArmLength());
|
4532 | }
|
4533 | if (radius < 0) {
|
4534 | radius = 0;
|
4535 | }
|
4536 |
|
4537 | var hue, color, borderColor;
|
4538 | if (this.style === Graph3d.STYLE.DOTCOLOR ) {
|
4539 |
|
4540 | hue = (1 - (point.point.value - this.valueMin) * this.scale.value) * 240;
|
4541 | color = this._hsv2rgb(hue, 1, 1);
|
4542 | borderColor = this._hsv2rgb(hue, 1, 0.8);
|
4543 | }
|
4544 | else if (this.style === Graph3d.STYLE.DOTSIZE) {
|
4545 | color = this.colorDot;
|
4546 | borderColor = this.colorDotBorder;
|
4547 | }
|
4548 | else {
|
4549 |
|
4550 | hue = (1 - (point.point.z - this.zMin) * this.scale.z / this.verticalRatio) * 240;
|
4551 | color = this._hsv2rgb(hue, 1, 1);
|
4552 | borderColor = this._hsv2rgb(hue, 1, 0.8);
|
4553 | }
|
4554 |
|
4555 |
|
4556 | ctx.lineWidth = 1.0;
|
4557 | ctx.strokeStyle = borderColor;
|
4558 | ctx.fillStyle = color;
|
4559 | ctx.beginPath();
|
4560 | ctx.arc(point.screen.x, point.screen.y, radius, 0, Math.PI*2, true);
|
4561 | ctx.fill();
|
4562 | ctx.stroke();
|
4563 | }
|
4564 | };
|
4565 |
|
4566 | |
4567 |
|
4568 |
|
4569 |
|
4570 | Graph3d.prototype._redrawDataBar = function() {
|
4571 | var canvas = this.frame.canvas;
|
4572 | var ctx = canvas.getContext('2d');
|
4573 | var i, j, surface, corners;
|
4574 |
|
4575 | if (this.dataPoints === undefined || this.dataPoints.length <= 0)
|
4576 | return;
|
4577 |
|
4578 |
|
4579 | for (i = 0; i < this.dataPoints.length; i++) {
|
4580 | var trans = this._convertPointToTranslation(this.dataPoints[i].point);
|
4581 | var screen = this._convertTranslationToScreen(trans);
|
4582 | this.dataPoints[i].trans = trans;
|
4583 | this.dataPoints[i].screen = screen;
|
4584 |
|
4585 |
|
4586 | var transBottom = this._convertPointToTranslation(this.dataPoints[i].bottom);
|
4587 | this.dataPoints[i].dist = this.showPerspective ? transBottom.length() : -transBottom.z;
|
4588 | }
|
4589 |
|
4590 |
|
4591 | var sortDepth = function (a, b) {
|
4592 | return b.dist - a.dist;
|
4593 | };
|
4594 | this.dataPoints.sort(sortDepth);
|
4595 |
|
4596 |
|
4597 | var xWidth = this.xBarWidth / 2;
|
4598 | var yWidth = this.yBarWidth / 2;
|
4599 | for (i = 0; i < this.dataPoints.length; i++) {
|
4600 | var point = this.dataPoints[i];
|
4601 |
|
4602 |
|
4603 | var hue, color, borderColor;
|
4604 | if (this.style === Graph3d.STYLE.BARCOLOR ) {
|
4605 |
|
4606 | hue = (1 - (point.point.value - this.valueMin) * this.scale.value) * 240;
|
4607 | color = this._hsv2rgb(hue, 1, 1);
|
4608 | borderColor = this._hsv2rgb(hue, 1, 0.8);
|
4609 | }
|
4610 | else if (this.style === Graph3d.STYLE.BARSIZE) {
|
4611 | color = this.colorDot;
|
4612 | borderColor = this.colorDotBorder;
|
4613 | }
|
4614 | else {
|
4615 |
|
4616 | hue = (1 - (point.point.z - this.zMin) * this.scale.z / this.verticalRatio) * 240;
|
4617 | color = this._hsv2rgb(hue, 1, 1);
|
4618 | borderColor = this._hsv2rgb(hue, 1, 0.8);
|
4619 | }
|
4620 |
|
4621 |
|
4622 | if (this.style === Graph3d.STYLE.BARSIZE) {
|
4623 | xWidth = (this.xBarWidth / 2) * ((point.point.value - this.valueMin) / (this.valueMax - this.valueMin) * 0.8 + 0.2);
|
4624 | yWidth = (this.yBarWidth / 2) * ((point.point.value - this.valueMin) / (this.valueMax - this.valueMin) * 0.8 + 0.2);
|
4625 | }
|
4626 |
|
4627 |
|
4628 | var me = this;
|
4629 | var point3d = point.point;
|
4630 | var top = [
|
4631 | {point: new Point3d(point3d.x - xWidth, point3d.y - yWidth, point3d.z)},
|
4632 | {point: new Point3d(point3d.x + xWidth, point3d.y - yWidth, point3d.z)},
|
4633 | {point: new Point3d(point3d.x + xWidth, point3d.y + yWidth, point3d.z)},
|
4634 | {point: new Point3d(point3d.x - xWidth, point3d.y + yWidth, point3d.z)}
|
4635 | ];
|
4636 | var bottom = [
|
4637 | {point: new Point3d(point3d.x - xWidth, point3d.y - yWidth, this.zMin)},
|
4638 | {point: new Point3d(point3d.x + xWidth, point3d.y - yWidth, this.zMin)},
|
4639 | {point: new Point3d(point3d.x + xWidth, point3d.y + yWidth, this.zMin)},
|
4640 | {point: new Point3d(point3d.x - xWidth, point3d.y + yWidth, this.zMin)}
|
4641 | ];
|
4642 |
|
4643 |
|
4644 | top.forEach(function (obj) {
|
4645 | obj.screen = me._convert3Dto2D(obj.point);
|
4646 | });
|
4647 | bottom.forEach(function (obj) {
|
4648 | obj.screen = me._convert3Dto2D(obj.point);
|
4649 | });
|
4650 |
|
4651 |
|
4652 | var surfaces = [
|
4653 | {corners: top, center: Point3d.avg(bottom[0].point, bottom[2].point)},
|
4654 | {corners: [top[0], top[1], bottom[1], bottom[0]], center: Point3d.avg(bottom[1].point, bottom[0].point)},
|
4655 | {corners: [top[1], top[2], bottom[2], bottom[1]], center: Point3d.avg(bottom[2].point, bottom[1].point)},
|
4656 | {corners: [top[2], top[3], bottom[3], bottom[2]], center: Point3d.avg(bottom[3].point, bottom[2].point)},
|
4657 | {corners: [top[3], top[0], bottom[0], bottom[3]], center: Point3d.avg(bottom[0].point, bottom[3].point)}
|
4658 | ];
|
4659 | point.surfaces = surfaces;
|
4660 |
|
4661 |
|
4662 | for (j = 0; j < surfaces.length; j++) {
|
4663 | surface = surfaces[j];
|
4664 | var transCenter = this._convertPointToTranslation(surface.center);
|
4665 | surface.dist = this.showPerspective ? transCenter.length() : -transCenter.z;
|
4666 |
|
4667 |
|
4668 |
|
4669 | }
|
4670 |
|
4671 |
|
4672 | surfaces.sort(function (a, b) {
|
4673 | var diff = b.dist - a.dist;
|
4674 | if (diff) return diff;
|
4675 |
|
4676 |
|
4677 | if (a.corners === top) return 1;
|
4678 | if (b.corners === top) return -1;
|
4679 |
|
4680 |
|
4681 | return 0;
|
4682 | });
|
4683 |
|
4684 |
|
4685 | ctx.lineWidth = 1;
|
4686 | ctx.strokeStyle = borderColor;
|
4687 | ctx.fillStyle = color;
|
4688 |
|
4689 | for (j = 2; j < surfaces.length; j++) {
|
4690 | surface = surfaces[j];
|
4691 | corners = surface.corners;
|
4692 | ctx.beginPath();
|
4693 | ctx.moveTo(corners[3].screen.x, corners[3].screen.y);
|
4694 | ctx.lineTo(corners[0].screen.x, corners[0].screen.y);
|
4695 | ctx.lineTo(corners[1].screen.x, corners[1].screen.y);
|
4696 | ctx.lineTo(corners[2].screen.x, corners[2].screen.y);
|
4697 | ctx.lineTo(corners[3].screen.x, corners[3].screen.y);
|
4698 | ctx.fill();
|
4699 | ctx.stroke();
|
4700 | }
|
4701 | }
|
4702 | };
|
4703 |
|
4704 |
|
4705 | |
4706 |
|
4707 |
|
4708 |
|
4709 | Graph3d.prototype._redrawDataLine = function() {
|
4710 | var canvas = this.frame.canvas,
|
4711 | ctx = canvas.getContext('2d'),
|
4712 | point, i;
|
4713 |
|
4714 | if (this.dataPoints === undefined || this.dataPoints.length <= 0)
|
4715 | return;
|
4716 |
|
4717 |
|
4718 | for (i = 0; i < this.dataPoints.length; i++) {
|
4719 | var trans = this._convertPointToTranslation(this.dataPoints[i].point);
|
4720 | var screen = this._convertTranslationToScreen(trans);
|
4721 |
|
4722 | this.dataPoints[i].trans = trans;
|
4723 | this.dataPoints[i].screen = screen;
|
4724 | }
|
4725 |
|
4726 |
|
4727 | if (this.dataPoints.length > 0) {
|
4728 | point = this.dataPoints[0];
|
4729 |
|
4730 | ctx.lineWidth = 1;
|
4731 | ctx.strokeStyle = 'blue';
|
4732 | ctx.beginPath();
|
4733 | ctx.moveTo(point.screen.x, point.screen.y);
|
4734 | }
|
4735 |
|
4736 |
|
4737 | for (i = 1; i < this.dataPoints.length; i++) {
|
4738 | point = this.dataPoints[i];
|
4739 | ctx.lineTo(point.screen.x, point.screen.y);
|
4740 | }
|
4741 |
|
4742 |
|
4743 | if (this.dataPoints.length > 0) {
|
4744 | ctx.stroke();
|
4745 | }
|
4746 | };
|
4747 |
|
4748 | |
4749 |
|
4750 |
|
4751 |
|
4752 |
|
4753 | Graph3d.prototype._onMouseDown = function(event) {
|
4754 | event = event || window.event;
|
4755 |
|
4756 |
|
4757 |
|
4758 | if (this.leftButtonDown) {
|
4759 | this._onMouseUp(event);
|
4760 | }
|
4761 |
|
4762 |
|
4763 | this.leftButtonDown = event.which ? (event.which === 1) : (event.button === 1);
|
4764 | if (!this.leftButtonDown && !this.touchDown) return;
|
4765 |
|
4766 |
|
4767 | this.startMouseX = getMouseX(event);
|
4768 | this.startMouseY = getMouseY(event);
|
4769 |
|
4770 | this.startStart = new Date(this.start);
|
4771 | this.startEnd = new Date(this.end);
|
4772 | this.startArmRotation = this.camera.getArmRotation();
|
4773 |
|
4774 | this.frame.style.cursor = 'move';
|
4775 |
|
4776 |
|
4777 |
|
4778 |
|
4779 | var me = this;
|
4780 | this.onmousemove = function (event) {me._onMouseMove(event);};
|
4781 | this.onmouseup = function (event) {me._onMouseUp(event);};
|
4782 | util.addEventListener(document, 'mousemove', me.onmousemove);
|
4783 | util.addEventListener(document, 'mouseup', me.onmouseup);
|
4784 | util.preventDefault(event);
|
4785 | };
|
4786 |
|
4787 |
|
4788 | |
4789 |
|
4790 |
|
4791 |
|
4792 |
|
4793 | Graph3d.prototype._onMouseMove = function (event) {
|
4794 | event = event || window.event;
|
4795 |
|
4796 |
|
4797 | var diffX = parseFloat(getMouseX(event)) - this.startMouseX;
|
4798 | var diffY = parseFloat(getMouseY(event)) - this.startMouseY;
|
4799 |
|
4800 | var horizontalNew = this.startArmRotation.horizontal + diffX / 200;
|
4801 | var verticalNew = this.startArmRotation.vertical + diffY / 200;
|
4802 |
|
4803 | var snapAngle = 4;
|
4804 | var snapValue = Math.sin(snapAngle / 360 * 2 * Math.PI);
|
4805 |
|
4806 |
|
4807 |
|
4808 | if (Math.abs(Math.sin(horizontalNew)) < snapValue) {
|
4809 | horizontalNew = Math.round((horizontalNew / Math.PI)) * Math.PI - 0.001;
|
4810 | }
|
4811 | if (Math.abs(Math.cos(horizontalNew)) < snapValue) {
|
4812 | horizontalNew = (Math.round((horizontalNew/ Math.PI - 0.5)) + 0.5) * Math.PI - 0.001;
|
4813 | }
|
4814 |
|
4815 |
|
4816 | if (Math.abs(Math.sin(verticalNew)) < snapValue) {
|
4817 | verticalNew = Math.round((verticalNew / Math.PI)) * Math.PI;
|
4818 | }
|
4819 | if (Math.abs(Math.cos(verticalNew)) < snapValue) {
|
4820 | verticalNew = (Math.round((verticalNew/ Math.PI - 0.5)) + 0.5) * Math.PI;
|
4821 | }
|
4822 |
|
4823 | this.camera.setArmRotation(horizontalNew, verticalNew);
|
4824 | this.redraw();
|
4825 |
|
4826 |
|
4827 | var parameters = this.getCameraPosition();
|
4828 | this.emit('cameraPositionChange', parameters);
|
4829 |
|
4830 | util.preventDefault(event);
|
4831 | };
|
4832 |
|
4833 |
|
4834 | |
4835 |
|
4836 |
|
4837 |
|
4838 |
|
4839 | Graph3d.prototype._onMouseUp = function (event) {
|
4840 | this.frame.style.cursor = 'auto';
|
4841 | this.leftButtonDown = false;
|
4842 |
|
4843 |
|
4844 | util.removeEventListener(document, 'mousemove', this.onmousemove);
|
4845 | util.removeEventListener(document, 'mouseup', this.onmouseup);
|
4846 | util.preventDefault(event);
|
4847 | };
|
4848 |
|
4849 | |
4850 |
|
4851 |
|
4852 |
|
4853 | Graph3d.prototype._onTooltip = function (event) {
|
4854 | var delay = 300;
|
4855 | var mouseX = getMouseX(event) - util.getAbsoluteLeft(this.frame);
|
4856 | var mouseY = getMouseY(event) - util.getAbsoluteTop(this.frame);
|
4857 |
|
4858 | if (!this.showTooltip) {
|
4859 | return;
|
4860 | }
|
4861 |
|
4862 | if (this.tooltipTimeout) {
|
4863 | clearTimeout(this.tooltipTimeout);
|
4864 | }
|
4865 |
|
4866 |
|
4867 | if (this.leftButtonDown) {
|
4868 | this._hideTooltip();
|
4869 | return;
|
4870 | }
|
4871 |
|
4872 | if (this.tooltip && this.tooltip.dataPoint) {
|
4873 |
|
4874 | var dataPoint = this._dataPointFromXY(mouseX, mouseY);
|
4875 | if (dataPoint !== this.tooltip.dataPoint) {
|
4876 |
|
4877 | if (dataPoint) {
|
4878 | this._showTooltip(dataPoint);
|
4879 | }
|
4880 | else {
|
4881 | this._hideTooltip();
|
4882 | }
|
4883 | }
|
4884 | }
|
4885 | else {
|
4886 |
|
4887 | var me = this;
|
4888 | this.tooltipTimeout = setTimeout(function () {
|
4889 | me.tooltipTimeout = null;
|
4890 |
|
4891 |
|
4892 | var dataPoint = me._dataPointFromXY(mouseX, mouseY);
|
4893 | if (dataPoint) {
|
4894 | me._showTooltip(dataPoint);
|
4895 | }
|
4896 | }, delay);
|
4897 | }
|
4898 | };
|
4899 |
|
4900 | |
4901 |
|
4902 |
|
4903 | Graph3d.prototype._onTouchStart = function(event) {
|
4904 | this.touchDown = true;
|
4905 |
|
4906 | var me = this;
|
4907 | this.ontouchmove = function (event) {me._onTouchMove(event);};
|
4908 | this.ontouchend = function (event) {me._onTouchEnd(event);};
|
4909 | util.addEventListener(document, 'touchmove', me.ontouchmove);
|
4910 | util.addEventListener(document, 'touchend', me.ontouchend);
|
4911 |
|
4912 | this._onMouseDown(event);
|
4913 | };
|
4914 |
|
4915 | |
4916 |
|
4917 |
|
4918 | Graph3d.prototype._onTouchMove = function(event) {
|
4919 | this._onMouseMove(event);
|
4920 | };
|
4921 |
|
4922 | |
4923 |
|
4924 |
|
4925 | Graph3d.prototype._onTouchEnd = function(event) {
|
4926 | this.touchDown = false;
|
4927 |
|
4928 | util.removeEventListener(document, 'touchmove', this.ontouchmove);
|
4929 | util.removeEventListener(document, 'touchend', this.ontouchend);
|
4930 |
|
4931 | this._onMouseUp(event);
|
4932 | };
|
4933 |
|
4934 |
|
4935 | |
4936 |
|
4937 |
|
4938 |
|
4939 |
|
4940 | Graph3d.prototype._onWheel = function(event) {
|
4941 | if (!event)
|
4942 | event = window.event;
|
4943 |
|
4944 |
|
4945 | var delta = 0;
|
4946 | if (event.wheelDelta) {
|
4947 | delta = event.wheelDelta/120;
|
4948 | } else if (event.detail) {
|
4949 |
|
4950 |
|
4951 | delta = -event.detail/3;
|
4952 | }
|
4953 |
|
4954 |
|
4955 |
|
4956 |
|
4957 | if (delta) {
|
4958 | var oldLength = this.camera.getArmLength();
|
4959 | var newLength = oldLength * (1 - delta / 10);
|
4960 |
|
4961 | this.camera.setArmLength(newLength);
|
4962 | this.redraw();
|
4963 |
|
4964 | this._hideTooltip();
|
4965 | }
|
4966 |
|
4967 |
|
4968 | var parameters = this.getCameraPosition();
|
4969 | this.emit('cameraPositionChange', parameters);
|
4970 |
|
4971 |
|
4972 |
|
4973 |
|
4974 | util.preventDefault(event);
|
4975 | };
|
4976 |
|
4977 | |
4978 |
|
4979 |
|
4980 |
|
4981 |
|
4982 |
|
4983 |
|
4984 | Graph3d.prototype._insideTriangle = function (point, triangle) {
|
4985 | var a = triangle[0],
|
4986 | b = triangle[1],
|
4987 | c = triangle[2];
|
4988 |
|
4989 | function sign (x) {
|
4990 | return x > 0 ? 1 : x < 0 ? -1 : 0;
|
4991 | }
|
4992 |
|
4993 | var as = sign((b.x - a.x) * (point.y - a.y) - (b.y - a.y) * (point.x - a.x));
|
4994 | var bs = sign((c.x - b.x) * (point.y - b.y) - (c.y - b.y) * (point.x - b.x));
|
4995 | var cs = sign((a.x - c.x) * (point.y - c.y) - (a.y - c.y) * (point.x - c.x));
|
4996 |
|
4997 |
|
4998 | return (as == 0 || bs == 0 || as == bs) &&
|
4999 | (bs == 0 || cs == 0 || bs == cs) &&
|
5000 | (as == 0 || cs == 0 || as == cs);
|
5001 | };
|
5002 |
|
5003 | |
5004 |
|
5005 |
|
5006 |
|
5007 |
|
5008 |
|
5009 |
|
5010 | Graph3d.prototype._dataPointFromXY = function (x, y) {
|
5011 | var i,
|
5012 | distMax = 100,
|
5013 | dataPoint = null,
|
5014 | closestDataPoint = null,
|
5015 | closestDist = null,
|
5016 | center = new Point2d(x, y);
|
5017 |
|
5018 | if (this.style === Graph3d.STYLE.BAR ||
|
5019 | this.style === Graph3d.STYLE.BARCOLOR ||
|
5020 | this.style === Graph3d.STYLE.BARSIZE) {
|
5021 |
|
5022 | for (i = this.dataPoints.length - 1; i >= 0; i--) {
|
5023 | dataPoint = this.dataPoints[i];
|
5024 | var surfaces = dataPoint.surfaces;
|
5025 | if (surfaces) {
|
5026 | for (var s = surfaces.length - 1; s >= 0; s--) {
|
5027 |
|
5028 | var surface = surfaces[s];
|
5029 | var corners = surface.corners;
|
5030 | var triangle1 = [corners[0].screen, corners[1].screen, corners[2].screen];
|
5031 | var triangle2 = [corners[2].screen, corners[3].screen, corners[0].screen];
|
5032 | if (this._insideTriangle(center, triangle1) ||
|
5033 | this._insideTriangle(center, triangle2)) {
|
5034 |
|
5035 | return dataPoint;
|
5036 | }
|
5037 | }
|
5038 | }
|
5039 | }
|
5040 | }
|
5041 | else {
|
5042 |
|
5043 | for (i = 0; i < this.dataPoints.length; i++) {
|
5044 | dataPoint = this.dataPoints[i];
|
5045 | var point = dataPoint.screen;
|
5046 | if (point) {
|
5047 | var distX = Math.abs(x - point.x);
|
5048 | var distY = Math.abs(y - point.y);
|
5049 | var dist = Math.sqrt(distX * distX + distY * distY);
|
5050 |
|
5051 | if ((closestDist === null || dist < closestDist) && dist < distMax) {
|
5052 | closestDist = dist;
|
5053 | closestDataPoint = dataPoint;
|
5054 | }
|
5055 | }
|
5056 | }
|
5057 | }
|
5058 |
|
5059 |
|
5060 | return closestDataPoint;
|
5061 | };
|
5062 |
|
5063 | |
5064 |
|
5065 |
|
5066 |
|
5067 |
|
5068 | Graph3d.prototype._showTooltip = function (dataPoint) {
|
5069 | var content, line, dot;
|
5070 |
|
5071 | if (!this.tooltip) {
|
5072 | content = document.createElement('div');
|
5073 | content.style.position = 'absolute';
|
5074 | content.style.padding = '10px';
|
5075 | content.style.border = '1px solid #4d4d4d';
|
5076 | content.style.color = '#1a1a1a';
|
5077 | content.style.background = 'rgba(255,255,255,0.7)';
|
5078 | content.style.borderRadius = '2px';
|
5079 | content.style.boxShadow = '5px 5px 10px rgba(128,128,128,0.5)';
|
5080 |
|
5081 | line = document.createElement('div');
|
5082 | line.style.position = 'absolute';
|
5083 | line.style.height = '40px';
|
5084 | line.style.width = '0';
|
5085 | line.style.borderLeft = '1px solid #4d4d4d';
|
5086 |
|
5087 | dot = document.createElement('div');
|
5088 | dot.style.position = 'absolute';
|
5089 | dot.style.height = '0';
|
5090 | dot.style.width = '0';
|
5091 | dot.style.border = '5px solid #4d4d4d';
|
5092 | dot.style.borderRadius = '5px';
|
5093 |
|
5094 | this.tooltip = {
|
5095 | dataPoint: null,
|
5096 | dom: {
|
5097 | content: content,
|
5098 | line: line,
|
5099 | dot: dot
|
5100 | }
|
5101 | };
|
5102 | }
|
5103 | else {
|
5104 | content = this.tooltip.dom.content;
|
5105 | line = this.tooltip.dom.line;
|
5106 | dot = this.tooltip.dom.dot;
|
5107 | }
|
5108 |
|
5109 | this._hideTooltip();
|
5110 |
|
5111 | this.tooltip.dataPoint = dataPoint;
|
5112 | if (typeof this.showTooltip === 'function') {
|
5113 | content.innerHTML = this.showTooltip(dataPoint.point);
|
5114 | }
|
5115 | else {
|
5116 | content.innerHTML = '<table>' +
|
5117 | '<tr><td>x:</td><td>' + dataPoint.point.x + '</td></tr>' +
|
5118 | '<tr><td>y:</td><td>' + dataPoint.point.y + '</td></tr>' +
|
5119 | '<tr><td>z:</td><td>' + dataPoint.point.z + '</td></tr>' +
|
5120 | '</table>';
|
5121 | }
|
5122 |
|
5123 | content.style.left = '0';
|
5124 | content.style.top = '0';
|
5125 | this.frame.appendChild(content);
|
5126 | this.frame.appendChild(line);
|
5127 | this.frame.appendChild(dot);
|
5128 |
|
5129 |
|
5130 | var contentWidth = content.offsetWidth;
|
5131 | var contentHeight = content.offsetHeight;
|
5132 | var lineHeight = line.offsetHeight;
|
5133 | var dotWidth = dot.offsetWidth;
|
5134 | var dotHeight = dot.offsetHeight;
|
5135 |
|
5136 | var left = dataPoint.screen.x - contentWidth / 2;
|
5137 | left = Math.min(Math.max(left, 10), this.frame.clientWidth - 10 - contentWidth);
|
5138 |
|
5139 | line.style.left = dataPoint.screen.x + 'px';
|
5140 | line.style.top = (dataPoint.screen.y - lineHeight) + 'px';
|
5141 | content.style.left = left + 'px';
|
5142 | content.style.top = (dataPoint.screen.y - lineHeight - contentHeight) + 'px';
|
5143 | dot.style.left = (dataPoint.screen.x - dotWidth / 2) + 'px';
|
5144 | dot.style.top = (dataPoint.screen.y - dotHeight / 2) + 'px';
|
5145 | };
|
5146 |
|
5147 | |
5148 |
|
5149 |
|
5150 |
|
5151 | Graph3d.prototype._hideTooltip = function () {
|
5152 | if (this.tooltip) {
|
5153 | this.tooltip.dataPoint = null;
|
5154 |
|
5155 | for (var prop in this.tooltip.dom) {
|
5156 | if (this.tooltip.dom.hasOwnProperty(prop)) {
|
5157 | var elem = this.tooltip.dom[prop];
|
5158 | if (elem && elem.parentNode) {
|
5159 | elem.parentNode.removeChild(elem);
|
5160 | }
|
5161 | }
|
5162 | }
|
5163 | }
|
5164 | };
|
5165 |
|
5166 |
|
5167 |
|
5168 |
|
5169 | |
5170 |
|
5171 |
|
5172 |
|
5173 |
|
5174 | getMouseX = function(event) {
|
5175 | if ('clientX' in event) return event.clientX;
|
5176 | return event.targetTouches[0] && event.targetTouches[0].clientX || 0;
|
5177 | };
|
5178 |
|
5179 | |
5180 |
|
5181 |
|
5182 |
|
5183 |
|
5184 | getMouseY = function(event) {
|
5185 | if ('clientY' in event) return event.clientY;
|
5186 | return event.targetTouches[0] && event.targetTouches[0].clientY || 0;
|
5187 | };
|
5188 |
|
5189 | module.exports = Graph3d;
|
5190 |
|
5191 |
|
5192 | },
|
5193 |
|
5194 | function(module, exports, __webpack_require__) {
|
5195 |
|
5196 | var Point3d = __webpack_require__(9);
|
5197 |
|
5198 | |
5199 |
|
5200 |
|
5201 |
|
5202 |
|
5203 |
|
5204 |
|
5205 |
|
5206 |
|
5207 |
|
5208 | Camera = function () {
|
5209 | this.armLocation = new Point3d();
|
5210 | this.armRotation = {};
|
5211 | this.armRotation.horizontal = 0;
|
5212 | this.armRotation.vertical = 0;
|
5213 | this.armLength = 1.7;
|
5214 |
|
5215 | this.cameraLocation = new Point3d();
|
5216 | this.cameraRotation = new Point3d(0.5*Math.PI, 0, 0);
|
5217 |
|
5218 | this.calculateCameraOrientation();
|
5219 | };
|
5220 |
|
5221 | |
5222 |
|
5223 |
|
5224 |
|
5225 |
|
5226 |
|
5227 | Camera.prototype.setArmLocation = function(x, y, z) {
|
5228 | this.armLocation.x = x;
|
5229 | this.armLocation.y = y;
|
5230 | this.armLocation.z = z;
|
5231 |
|
5232 | this.calculateCameraOrientation();
|
5233 | };
|
5234 |
|
5235 | |
5236 |
|
5237 |
|
5238 |
|
5239 |
|
5240 |
|
5241 |
|
5242 |
|
5243 | Camera.prototype.setArmRotation = function(horizontal, vertical) {
|
5244 | if (horizontal !== undefined) {
|
5245 | this.armRotation.horizontal = horizontal;
|
5246 | }
|
5247 |
|
5248 | if (vertical !== undefined) {
|
5249 | this.armRotation.vertical = vertical;
|
5250 | if (this.armRotation.vertical < 0) this.armRotation.vertical = 0;
|
5251 | if (this.armRotation.vertical > 0.5*Math.PI) this.armRotation.vertical = 0.5*Math.PI;
|
5252 | }
|
5253 |
|
5254 | if (horizontal !== undefined || vertical !== undefined) {
|
5255 | this.calculateCameraOrientation();
|
5256 | }
|
5257 | };
|
5258 |
|
5259 | |
5260 |
|
5261 |
|
5262 |
|
5263 | Camera.prototype.getArmRotation = function() {
|
5264 | var rot = {};
|
5265 | rot.horizontal = this.armRotation.horizontal;
|
5266 | rot.vertical = this.armRotation.vertical;
|
5267 |
|
5268 | return rot;
|
5269 | };
|
5270 |
|
5271 | |
5272 |
|
5273 |
|
5274 |
|
5275 | Camera.prototype.setArmLength = function(length) {
|
5276 | if (length === undefined)
|
5277 | return;
|
5278 |
|
5279 | this.armLength = length;
|
5280 |
|
5281 |
|
5282 |
|
5283 |
|
5284 | if (this.armLength < 0.71) this.armLength = 0.71;
|
5285 | if (this.armLength > 5.0) this.armLength = 5.0;
|
5286 |
|
5287 | this.calculateCameraOrientation();
|
5288 | };
|
5289 |
|
5290 | |
5291 |
|
5292 |
|
5293 |
|
5294 | Camera.prototype.getArmLength = function() {
|
5295 | return this.armLength;
|
5296 | };
|
5297 |
|
5298 | |
5299 |
|
5300 |
|
5301 |
|
5302 | Camera.prototype.getCameraLocation = function() {
|
5303 | return this.cameraLocation;
|
5304 | };
|
5305 |
|
5306 | |
5307 |
|
5308 |
|
5309 |
|
5310 | Camera.prototype.getCameraRotation = function() {
|
5311 | return this.cameraRotation;
|
5312 | };
|
5313 |
|
5314 | |
5315 |
|
5316 |
|
5317 |
|
5318 | Camera.prototype.calculateCameraOrientation = function() {
|
5319 |
|
5320 | this.cameraLocation.x = this.armLocation.x - this.armLength * Math.sin(this.armRotation.horizontal) * Math.cos(this.armRotation.vertical);
|
5321 | this.cameraLocation.y = this.armLocation.y - this.armLength * Math.cos(this.armRotation.horizontal) * Math.cos(this.armRotation.vertical);
|
5322 | this.cameraLocation.z = this.armLocation.z + this.armLength * Math.sin(this.armRotation.vertical);
|
5323 |
|
5324 |
|
5325 | this.cameraRotation.x = Math.PI/2 - this.armRotation.vertical;
|
5326 | this.cameraRotation.y = 0;
|
5327 | this.cameraRotation.z = -this.armRotation.horizontal;
|
5328 | };
|
5329 |
|
5330 | module.exports = Camera;
|
5331 |
|
5332 | },
|
5333 |
|
5334 | function(module, exports, __webpack_require__) {
|
5335 |
|
5336 | var DataView = __webpack_require__(4);
|
5337 |
|
5338 | |
5339 |
|
5340 |
|
5341 |
|
5342 |
|
5343 |
|
5344 |
|
5345 | function Filter (data, column, graph) {
|
5346 | this.data = data;
|
5347 | this.column = column;
|
5348 | this.graph = graph;
|
5349 |
|
5350 | this.index = undefined;
|
5351 | this.value = undefined;
|
5352 |
|
5353 |
|
5354 | this.values = graph.getDistinctValues(data.get(), this.column);
|
5355 |
|
5356 |
|
5357 | this.values.sort(function (a, b) {
|
5358 | return a > b ? 1 : a < b ? -1 : 0;
|
5359 | });
|
5360 |
|
5361 | if (this.values.length > 0) {
|
5362 | this.selectValue(0);
|
5363 | }
|
5364 |
|
5365 |
|
5366 | this.dataPoints = [];
|
5367 |
|
5368 | this.loaded = false;
|
5369 | this.onLoadCallback = undefined;
|
5370 |
|
5371 | if (graph.animationPreload) {
|
5372 | this.loaded = false;
|
5373 | this.loadInBackground();
|
5374 | }
|
5375 | else {
|
5376 | this.loaded = true;
|
5377 | }
|
5378 | };
|
5379 |
|
5380 |
|
5381 | |
5382 |
|
5383 |
|
5384 |
|
5385 | Filter.prototype.isLoaded = function() {
|
5386 | return this.loaded;
|
5387 | };
|
5388 |
|
5389 |
|
5390 | |
5391 |
|
5392 |
|
5393 |
|
5394 | Filter.prototype.getLoadedProgress = function() {
|
5395 | var len = this.values.length;
|
5396 |
|
5397 | var i = 0;
|
5398 | while (this.dataPoints[i]) {
|
5399 | i++;
|
5400 | }
|
5401 |
|
5402 | return Math.round(i / len * 100);
|
5403 | };
|
5404 |
|
5405 |
|
5406 | |
5407 |
|
5408 |
|
5409 |
|
5410 | Filter.prototype.getLabel = function() {
|
5411 | return this.graph.filterLabel;
|
5412 | };
|
5413 |
|
5414 |
|
5415 | |
5416 |
|
5417 |
|
5418 |
|
5419 | Filter.prototype.getColumn = function() {
|
5420 | return this.column;
|
5421 | };
|
5422 |
|
5423 | |
5424 |
|
5425 |
|
5426 |
|
5427 | Filter.prototype.getSelectedValue = function() {
|
5428 | if (this.index === undefined)
|
5429 | return undefined;
|
5430 |
|
5431 | return this.values[this.index];
|
5432 | };
|
5433 |
|
5434 | |
5435 |
|
5436 |
|
5437 |
|
5438 | Filter.prototype.getValues = function() {
|
5439 | return this.values;
|
5440 | };
|
5441 |
|
5442 | |
5443 |
|
5444 |
|
5445 |
|
5446 |
|
5447 | Filter.prototype.getValue = function(index) {
|
5448 | if (index >= this.values.length)
|
5449 | throw 'Error: index out of range';
|
5450 |
|
5451 | return this.values[index];
|
5452 | };
|
5453 |
|
5454 |
|
5455 | |
5456 |
|
5457 |
|
5458 |
|
5459 |
|
5460 | Filter.prototype._getDataPoints = function(index) {
|
5461 | if (index === undefined)
|
5462 | index = this.index;
|
5463 |
|
5464 | if (index === undefined)
|
5465 | return [];
|
5466 |
|
5467 | var dataPoints;
|
5468 | if (this.dataPoints[index]) {
|
5469 | dataPoints = this.dataPoints[index];
|
5470 | }
|
5471 | else {
|
5472 | var f = {};
|
5473 | f.column = this.column;
|
5474 | f.value = this.values[index];
|
5475 |
|
5476 | var dataView = new DataView(this.data,{filter: function (item) {return (item[f.column] == f.value);}}).get();
|
5477 | dataPoints = this.graph._getDataPoints(dataView);
|
5478 |
|
5479 | this.dataPoints[index] = dataPoints;
|
5480 | }
|
5481 |
|
5482 | return dataPoints;
|
5483 | };
|
5484 |
|
5485 |
|
5486 |
|
5487 | |
5488 |
|
5489 |
|
5490 | Filter.prototype.setOnLoadCallback = function(callback) {
|
5491 | this.onLoadCallback = callback;
|
5492 | };
|
5493 |
|
5494 |
|
5495 | |
5496 |
|
5497 |
|
5498 |
|
5499 |
|
5500 | Filter.prototype.selectValue = function(index) {
|
5501 | if (index >= this.values.length)
|
5502 | throw 'Error: index out of range';
|
5503 |
|
5504 | this.index = index;
|
5505 | this.value = this.values[index];
|
5506 | };
|
5507 |
|
5508 | |
5509 |
|
5510 |
|
5511 |
|
5512 | Filter.prototype.loadInBackground = function(index) {
|
5513 | if (index === undefined)
|
5514 | index = 0;
|
5515 |
|
5516 | var frame = this.graph.frame;
|
5517 |
|
5518 | if (index < this.values.length) {
|
5519 | var dataPointsTemp = this._getDataPoints(index);
|
5520 |
|
5521 |
|
5522 |
|
5523 | if (frame.progress === undefined) {
|
5524 | frame.progress = document.createElement('DIV');
|
5525 | frame.progress.style.position = 'absolute';
|
5526 | frame.progress.style.color = 'gray';
|
5527 | frame.appendChild(frame.progress);
|
5528 | }
|
5529 | var progress = this.getLoadedProgress();
|
5530 | frame.progress.innerHTML = 'Loading animation... ' + progress + '%';
|
5531 |
|
5532 | frame.progress.style.bottom = 60 + 'px';
|
5533 | frame.progress.style.left = 10 + 'px';
|
5534 |
|
5535 | var me = this;
|
5536 | setTimeout(function() {me.loadInBackground(index+1);}, 10);
|
5537 | this.loaded = false;
|
5538 | }
|
5539 | else {
|
5540 | this.loaded = true;
|
5541 |
|
5542 |
|
5543 | if (frame.progress !== undefined) {
|
5544 | frame.removeChild(frame.progress);
|
5545 | frame.progress = undefined;
|
5546 | }
|
5547 |
|
5548 | if (this.onLoadCallback)
|
5549 | this.onLoadCallback();
|
5550 | }
|
5551 | };
|
5552 |
|
5553 | module.exports = Filter;
|
5554 |
|
5555 |
|
5556 | },
|
5557 |
|
5558 | function(module, exports, __webpack_require__) {
|
5559 |
|
5560 | |
5561 |
|
5562 |
|
5563 |
|
5564 |
|
5565 | Point2d = function (x, y) {
|
5566 | this.x = x !== undefined ? x : 0;
|
5567 | this.y = y !== undefined ? y : 0;
|
5568 | };
|
5569 |
|
5570 | module.exports = Point2d;
|
5571 |
|
5572 |
|
5573 | },
|
5574 |
|
5575 | function(module, exports, __webpack_require__) {
|
5576 |
|
5577 | |
5578 |
|
5579 |
|
5580 |
|
5581 |
|
5582 |
|
5583 | function Point3d(x, y, z) {
|
5584 | this.x = x !== undefined ? x : 0;
|
5585 | this.y = y !== undefined ? y : 0;
|
5586 | this.z = z !== undefined ? z : 0;
|
5587 | };
|
5588 |
|
5589 | |
5590 |
|
5591 |
|
5592 |
|
5593 |
|
5594 |
|
5595 | Point3d.subtract = function(a, b) {
|
5596 | var sub = new Point3d();
|
5597 | sub.x = a.x - b.x;
|
5598 | sub.y = a.y - b.y;
|
5599 | sub.z = a.z - b.z;
|
5600 | return sub;
|
5601 | };
|
5602 |
|
5603 | |
5604 |
|
5605 |
|
5606 |
|
5607 |
|
5608 |
|
5609 | Point3d.add = function(a, b) {
|
5610 | var sum = new Point3d();
|
5611 | sum.x = a.x + b.x;
|
5612 | sum.y = a.y + b.y;
|
5613 | sum.z = a.z + b.z;
|
5614 | return sum;
|
5615 | };
|
5616 |
|
5617 | |
5618 |
|
5619 |
|
5620 |
|
5621 |
|
5622 |
|
5623 | Point3d.avg = function(a, b) {
|
5624 | return new Point3d(
|
5625 | (a.x + b.x) / 2,
|
5626 | (a.y + b.y) / 2,
|
5627 | (a.z + b.z) / 2
|
5628 | );
|
5629 | };
|
5630 |
|
5631 | |
5632 |
|
5633 |
|
5634 |
|
5635 |
|
5636 |
|
5637 |
|
5638 | Point3d.crossProduct = function(a, b) {
|
5639 | var crossproduct = new Point3d();
|
5640 |
|
5641 | crossproduct.x = a.y * b.z - a.z * b.y;
|
5642 | crossproduct.y = a.z * b.x - a.x * b.z;
|
5643 | crossproduct.z = a.x * b.y - a.y * b.x;
|
5644 |
|
5645 | return crossproduct;
|
5646 | };
|
5647 |
|
5648 |
|
5649 | |
5650 |
|
5651 |
|
5652 |
|
5653 | Point3d.prototype.length = function() {
|
5654 | return Math.sqrt(
|
5655 | this.x * this.x +
|
5656 | this.y * this.y +
|
5657 | this.z * this.z
|
5658 | );
|
5659 | };
|
5660 |
|
5661 | module.exports = Point3d;
|
5662 |
|
5663 |
|
5664 | },
|
5665 |
|
5666 | function(module, exports, __webpack_require__) {
|
5667 |
|
5668 | var util = __webpack_require__(1);
|
5669 |
|
5670 | |
5671 |
|
5672 |
|
5673 |
|
5674 |
|
5675 |
|
5676 |
|
5677 |
|
5678 |
|
5679 | function Slider(container, options) {
|
5680 | if (container === undefined) {
|
5681 | throw 'Error: No container element defined';
|
5682 | }
|
5683 | this.container = container;
|
5684 | this.visible = (options && options.visible != undefined) ? options.visible : true;
|
5685 |
|
5686 | if (this.visible) {
|
5687 | this.frame = document.createElement('DIV');
|
5688 |
|
5689 | this.frame.style.width = '100%';
|
5690 | this.frame.style.position = 'relative';
|
5691 | this.container.appendChild(this.frame);
|
5692 |
|
5693 | this.frame.prev = document.createElement('INPUT');
|
5694 | this.frame.prev.type = 'BUTTON';
|
5695 | this.frame.prev.value = 'Prev';
|
5696 | this.frame.appendChild(this.frame.prev);
|
5697 |
|
5698 | this.frame.play = document.createElement('INPUT');
|
5699 | this.frame.play.type = 'BUTTON';
|
5700 | this.frame.play.value = 'Play';
|
5701 | this.frame.appendChild(this.frame.play);
|
5702 |
|
5703 | this.frame.next = document.createElement('INPUT');
|
5704 | this.frame.next.type = 'BUTTON';
|
5705 | this.frame.next.value = 'Next';
|
5706 | this.frame.appendChild(this.frame.next);
|
5707 |
|
5708 | this.frame.bar = document.createElement('INPUT');
|
5709 | this.frame.bar.type = 'BUTTON';
|
5710 | this.frame.bar.style.position = 'absolute';
|
5711 | this.frame.bar.style.border = '1px solid red';
|
5712 | this.frame.bar.style.width = '100px';
|
5713 | this.frame.bar.style.height = '6px';
|
5714 | this.frame.bar.style.borderRadius = '2px';
|
5715 | this.frame.bar.style.MozBorderRadius = '2px';
|
5716 | this.frame.bar.style.border = '1px solid #7F7F7F';
|
5717 | this.frame.bar.style.backgroundColor = '#E5E5E5';
|
5718 | this.frame.appendChild(this.frame.bar);
|
5719 |
|
5720 | this.frame.slide = document.createElement('INPUT');
|
5721 | this.frame.slide.type = 'BUTTON';
|
5722 | this.frame.slide.style.margin = '0px';
|
5723 | this.frame.slide.value = ' ';
|
5724 | this.frame.slide.style.position = 'relative';
|
5725 | this.frame.slide.style.left = '-100px';
|
5726 | this.frame.appendChild(this.frame.slide);
|
5727 |
|
5728 |
|
5729 | var me = this;
|
5730 | this.frame.slide.onmousedown = function (event) {me._onMouseDown(event);};
|
5731 | this.frame.prev.onclick = function (event) {me.prev(event);};
|
5732 | this.frame.play.onclick = function (event) {me.togglePlay(event);};
|
5733 | this.frame.next.onclick = function (event) {me.next(event);};
|
5734 | }
|
5735 |
|
5736 | this.onChangeCallback = undefined;
|
5737 |
|
5738 | this.values = [];
|
5739 | this.index = undefined;
|
5740 |
|
5741 | this.playTimeout = undefined;
|
5742 | this.playInterval = 1000;
|
5743 | this.playLoop = true;
|
5744 | }
|
5745 |
|
5746 | |
5747 |
|
5748 |
|
5749 | Slider.prototype.prev = function() {
|
5750 | var index = this.getIndex();
|
5751 | if (index > 0) {
|
5752 | index--;
|
5753 | this.setIndex(index);
|
5754 | }
|
5755 | };
|
5756 |
|
5757 | |
5758 |
|
5759 |
|
5760 | Slider.prototype.next = function() {
|
5761 | var index = this.getIndex();
|
5762 | if (index < this.values.length - 1) {
|
5763 | index++;
|
5764 | this.setIndex(index);
|
5765 | }
|
5766 | };
|
5767 |
|
5768 | |
5769 |
|
5770 |
|
5771 | Slider.prototype.playNext = function() {
|
5772 | var start = new Date();
|
5773 |
|
5774 | var index = this.getIndex();
|
5775 | if (index < this.values.length - 1) {
|
5776 | index++;
|
5777 | this.setIndex(index);
|
5778 | }
|
5779 | else if (this.playLoop) {
|
5780 |
|
5781 | index = 0;
|
5782 | this.setIndex(index);
|
5783 | }
|
5784 |
|
5785 | var end = new Date();
|
5786 | var diff = (end - start);
|
5787 |
|
5788 |
|
5789 |
|
5790 | var interval = Math.max(this.playInterval - diff, 0);
|
5791 |
|
5792 |
|
5793 | var me = this;
|
5794 | this.playTimeout = setTimeout(function() {me.playNext();}, interval);
|
5795 | };
|
5796 |
|
5797 | |
5798 |
|
5799 |
|
5800 | Slider.prototype.togglePlay = function() {
|
5801 | if (this.playTimeout === undefined) {
|
5802 | this.play();
|
5803 | } else {
|
5804 | this.stop();
|
5805 | }
|
5806 | };
|
5807 |
|
5808 | |
5809 |
|
5810 |
|
5811 | Slider.prototype.play = function() {
|
5812 |
|
5813 | if (this.playTimeout) return;
|
5814 |
|
5815 | this.playNext();
|
5816 |
|
5817 | if (this.frame) {
|
5818 | this.frame.play.value = 'Stop';
|
5819 | }
|
5820 | };
|
5821 |
|
5822 | |
5823 |
|
5824 |
|
5825 | Slider.prototype.stop = function() {
|
5826 | clearInterval(this.playTimeout);
|
5827 | this.playTimeout = undefined;
|
5828 |
|
5829 | if (this.frame) {
|
5830 | this.frame.play.value = 'Play';
|
5831 | }
|
5832 | };
|
5833 |
|
5834 | |
5835 |
|
5836 |
|
5837 |
|
5838 | Slider.prototype.setOnChangeCallback = function(callback) {
|
5839 | this.onChangeCallback = callback;
|
5840 | };
|
5841 |
|
5842 | |
5843 |
|
5844 |
|
5845 |
|
5846 | Slider.prototype.setPlayInterval = function(interval) {
|
5847 | this.playInterval = interval;
|
5848 | };
|
5849 |
|
5850 | |
5851 |
|
5852 |
|
5853 |
|
5854 | Slider.prototype.getPlayInterval = function(interval) {
|
5855 | return this.playInterval;
|
5856 | };
|
5857 |
|
5858 | |
5859 |
|
5860 |
|
5861 |
|
5862 |
|
5863 |
|
5864 | Slider.prototype.setPlayLoop = function(doLoop) {
|
5865 | this.playLoop = doLoop;
|
5866 | };
|
5867 |
|
5868 |
|
5869 | |
5870 |
|
5871 |
|
5872 | Slider.prototype.onChange = function() {
|
5873 | if (this.onChangeCallback !== undefined) {
|
5874 | this.onChangeCallback();
|
5875 | }
|
5876 | };
|
5877 |
|
5878 | |
5879 |
|
5880 |
|
5881 | Slider.prototype.redraw = function() {
|
5882 | if (this.frame) {
|
5883 |
|
5884 | this.frame.bar.style.top = (this.frame.clientHeight/2 -
|
5885 | this.frame.bar.offsetHeight/2) + 'px';
|
5886 | this.frame.bar.style.width = (this.frame.clientWidth -
|
5887 | this.frame.prev.clientWidth -
|
5888 | this.frame.play.clientWidth -
|
5889 | this.frame.next.clientWidth - 30) + 'px';
|
5890 |
|
5891 |
|
5892 | var left = this.indexToLeft(this.index);
|
5893 | this.frame.slide.style.left = (left) + 'px';
|
5894 | }
|
5895 | };
|
5896 |
|
5897 |
|
5898 | |
5899 |
|
5900 |
|
5901 |
|
5902 | Slider.prototype.setValues = function(values) {
|
5903 | this.values = values;
|
5904 |
|
5905 | if (this.values.length > 0)
|
5906 | this.setIndex(0);
|
5907 | else
|
5908 | this.index = undefined;
|
5909 | };
|
5910 |
|
5911 | |
5912 |
|
5913 |
|
5914 |
|
5915 | Slider.prototype.setIndex = function(index) {
|
5916 | if (index < this.values.length) {
|
5917 | this.index = index;
|
5918 |
|
5919 | this.redraw();
|
5920 | this.onChange();
|
5921 | }
|
5922 | else {
|
5923 | throw 'Error: index out of range';
|
5924 | }
|
5925 | };
|
5926 |
|
5927 | |
5928 |
|
5929 |
|
5930 |
|
5931 | Slider.prototype.getIndex = function() {
|
5932 | return this.index;
|
5933 | };
|
5934 |
|
5935 |
|
5936 | |
5937 |
|
5938 |
|
5939 |
|
5940 | Slider.prototype.get = function() {
|
5941 | return this.values[this.index];
|
5942 | };
|
5943 |
|
5944 |
|
5945 | Slider.prototype._onMouseDown = function(event) {
|
5946 |
|
5947 | var leftButtonDown = event.which ? (event.which === 1) : (event.button === 1);
|
5948 | if (!leftButtonDown) return;
|
5949 |
|
5950 | this.startClientX = event.clientX;
|
5951 | this.startSlideX = parseFloat(this.frame.slide.style.left);
|
5952 |
|
5953 | this.frame.style.cursor = 'move';
|
5954 |
|
5955 |
|
5956 |
|
5957 |
|
5958 | var me = this;
|
5959 | this.onmousemove = function (event) {me._onMouseMove(event);};
|
5960 | this.onmouseup = function (event) {me._onMouseUp(event);};
|
5961 | util.addEventListener(document, 'mousemove', this.onmousemove);
|
5962 | util.addEventListener(document, 'mouseup', this.onmouseup);
|
5963 | util.preventDefault(event);
|
5964 | };
|
5965 |
|
5966 |
|
5967 | Slider.prototype.leftToIndex = function (left) {
|
5968 | var width = parseFloat(this.frame.bar.style.width) -
|
5969 | this.frame.slide.clientWidth - 10;
|
5970 | var x = left - 3;
|
5971 |
|
5972 | var index = Math.round(x / width * (this.values.length-1));
|
5973 | if (index < 0) index = 0;
|
5974 | if (index > this.values.length-1) index = this.values.length-1;
|
5975 |
|
5976 | return index;
|
5977 | };
|
5978 |
|
5979 | Slider.prototype.indexToLeft = function (index) {
|
5980 | var width = parseFloat(this.frame.bar.style.width) -
|
5981 | this.frame.slide.clientWidth - 10;
|
5982 |
|
5983 | var x = index / (this.values.length-1) * width;
|
5984 | var left = x + 3;
|
5985 |
|
5986 | return left;
|
5987 | };
|
5988 |
|
5989 |
|
5990 |
|
5991 | Slider.prototype._onMouseMove = function (event) {
|
5992 | var diff = event.clientX - this.startClientX;
|
5993 | var x = this.startSlideX + diff;
|
5994 |
|
5995 | var index = this.leftToIndex(x);
|
5996 |
|
5997 | this.setIndex(index);
|
5998 |
|
5999 | util.preventDefault();
|
6000 | };
|
6001 |
|
6002 |
|
6003 | Slider.prototype._onMouseUp = function (event) {
|
6004 | this.frame.style.cursor = 'auto';
|
6005 |
|
6006 |
|
6007 | util.removeEventListener(document, 'mousemove', this.onmousemove);
|
6008 | util.removeEventListener(document, 'mouseup', this.onmouseup);
|
6009 |
|
6010 | util.preventDefault();
|
6011 | };
|
6012 |
|
6013 | module.exports = Slider;
|
6014 |
|
6015 |
|
6016 | },
|
6017 |
|
6018 | function(module, exports, __webpack_require__) {
|
6019 |
|
6020 | |
6021 |
|
6022 |
|
6023 |
|
6024 |
|
6025 |
|
6026 |
|
6027 |
|
6028 |
|
6029 |
|
6030 |
|
6031 |
|
6032 |
|
6033 |
|
6034 |
|
6035 |
|
6036 |
|
6037 |
|
6038 |
|
6039 |
|
6040 |
|
6041 |
|
6042 |
|
6043 |
|
6044 |
|
6045 | function StepNumber(start, end, step, prettyStep) {
|
6046 |
|
6047 | this._start = 0;
|
6048 | this._end = 0;
|
6049 | this._step = 1;
|
6050 | this.prettyStep = true;
|
6051 | this.precision = 5;
|
6052 |
|
6053 | this._current = 0;
|
6054 | this.setRange(start, end, step, prettyStep);
|
6055 | };
|
6056 |
|
6057 | |
6058 |
|
6059 |
|
6060 |
|
6061 |
|
6062 |
|
6063 |
|
6064 |
|
6065 |
|
6066 | StepNumber.prototype.setRange = function(start, end, step, prettyStep) {
|
6067 | this._start = start ? start : 0;
|
6068 | this._end = end ? end : 0;
|
6069 |
|
6070 | this.setStep(step, prettyStep);
|
6071 | };
|
6072 |
|
6073 | |
6074 |
|
6075 |
|
6076 |
|
6077 |
|
6078 |
|
6079 | StepNumber.prototype.setStep = function(step, prettyStep) {
|
6080 | if (step === undefined || step <= 0)
|
6081 | return;
|
6082 |
|
6083 | if (prettyStep !== undefined)
|
6084 | this.prettyStep = prettyStep;
|
6085 |
|
6086 | if (this.prettyStep === true)
|
6087 | this._step = StepNumber.calculatePrettyStep(step);
|
6088 | else
|
6089 | this._step = step;
|
6090 | };
|
6091 |
|
6092 | |
6093 |
|
6094 |
|
6095 |
|
6096 |
|
6097 |
|
6098 |
|
6099 | StepNumber.calculatePrettyStep = function (step) {
|
6100 | var log10 = function (x) {return Math.log(x) / Math.LN10;};
|
6101 |
|
6102 |
|
6103 | var step1 = Math.pow(10, Math.round(log10(step))),
|
6104 | step2 = 2 * Math.pow(10, Math.round(log10(step / 2))),
|
6105 | step5 = 5 * Math.pow(10, Math.round(log10(step / 5)));
|
6106 |
|
6107 |
|
6108 | var prettyStep = step1;
|
6109 | if (Math.abs(step2 - step) <= Math.abs(prettyStep - step)) prettyStep = step2;
|
6110 | if (Math.abs(step5 - step) <= Math.abs(prettyStep - step)) prettyStep = step5;
|
6111 |
|
6112 |
|
6113 | if (prettyStep <= 0) {
|
6114 | prettyStep = 1;
|
6115 | }
|
6116 |
|
6117 | return prettyStep;
|
6118 | };
|
6119 |
|
6120 | |
6121 |
|
6122 |
|
6123 |
|
6124 | StepNumber.prototype.getCurrent = function () {
|
6125 | return parseFloat(this._current.toPrecision(this.precision));
|
6126 | };
|
6127 |
|
6128 | |
6129 |
|
6130 |
|
6131 |
|
6132 | StepNumber.prototype.getStep = function () {
|
6133 | return this._step;
|
6134 | };
|
6135 |
|
6136 | |
6137 |
|
6138 |
|
6139 |
|
6140 | StepNumber.prototype.start = function() {
|
6141 | this._current = this._start - this._start % this._step;
|
6142 | };
|
6143 |
|
6144 | |
6145 |
|
6146 |
|
6147 | StepNumber.prototype.next = function () {
|
6148 | this._current += this._step;
|
6149 | };
|
6150 |
|
6151 | |
6152 |
|
6153 |
|
6154 |
|
6155 | StepNumber.prototype.end = function () {
|
6156 | return (this._current > this._end);
|
6157 | };
|
6158 |
|
6159 | module.exports = StepNumber;
|
6160 |
|
6161 |
|
6162 | },
|
6163 |
|
6164 | function(module, exports, __webpack_require__) {
|
6165 |
|
6166 | var Emitter = __webpack_require__(50);
|
6167 | var Hammer = __webpack_require__(42);
|
6168 | var util = __webpack_require__(1);
|
6169 | var DataSet = __webpack_require__(3);
|
6170 | var DataView = __webpack_require__(4);
|
6171 | var Range = __webpack_require__(15);
|
6172 | var Core = __webpack_require__(44);
|
6173 | var TimeAxis = __webpack_require__(27);
|
6174 | var CurrentTime = __webpack_require__(19);
|
6175 | var CustomTime = __webpack_require__(20);
|
6176 | var ItemSet = __webpack_require__(24);
|
6177 |
|
6178 | |
6179 |
|
6180 |
|
6181 |
|
6182 |
|
6183 |
|
6184 |
|
6185 |
|
6186 | function Timeline (container, items, options) {
|
6187 | if (!(this instanceof Timeline)) {
|
6188 | throw new SyntaxError('Constructor must be called with the new operator');
|
6189 | }
|
6190 |
|
6191 | var me = this;
|
6192 | this.defaultOptions = {
|
6193 | start: null,
|
6194 | end: null,
|
6195 |
|
6196 | autoResize: true,
|
6197 |
|
6198 | orientation: 'bottom',
|
6199 | width: null,
|
6200 | height: null,
|
6201 | maxHeight: null,
|
6202 | minHeight: null
|
6203 | };
|
6204 | this.options = util.deepExtend({}, this.defaultOptions);
|
6205 |
|
6206 |
|
6207 | this._create(container);
|
6208 |
|
6209 |
|
6210 | this.components = [];
|
6211 |
|
6212 | this.body = {
|
6213 | dom: this.dom,
|
6214 | domProps: this.props,
|
6215 | emitter: {
|
6216 | on: this.on.bind(this),
|
6217 | off: this.off.bind(this),
|
6218 | emit: this.emit.bind(this)
|
6219 | },
|
6220 | util: {
|
6221 | snap: null,
|
6222 | toScreen: me._toScreen.bind(me),
|
6223 | toGlobalScreen: me._toGlobalScreen.bind(me),
|
6224 | toTime: me._toTime.bind(me),
|
6225 | toGlobalTime : me._toGlobalTime.bind(me)
|
6226 | }
|
6227 | };
|
6228 |
|
6229 |
|
6230 | this.range = new Range(this.body);
|
6231 | this.components.push(this.range);
|
6232 | this.body.range = this.range;
|
6233 |
|
6234 |
|
6235 | this.timeAxis = new TimeAxis(this.body);
|
6236 | this.components.push(this.timeAxis);
|
6237 | this.body.util.snap = this.timeAxis.snap.bind(this.timeAxis);
|
6238 |
|
6239 |
|
6240 | this.currentTime = new CurrentTime(this.body);
|
6241 | this.components.push(this.currentTime);
|
6242 |
|
6243 |
|
6244 |
|
6245 | this.customTime = new CustomTime(this.body);
|
6246 | this.components.push(this.customTime);
|
6247 |
|
6248 |
|
6249 | this.itemSet = new ItemSet(this.body);
|
6250 | this.components.push(this.itemSet);
|
6251 |
|
6252 | this.itemsData = null;
|
6253 | this.groupsData = null;
|
6254 |
|
6255 |
|
6256 | if (options) {
|
6257 | this.setOptions(options);
|
6258 | }
|
6259 |
|
6260 |
|
6261 | if (items) {
|
6262 | this.setItems(items);
|
6263 | }
|
6264 | else {
|
6265 | this.redraw();
|
6266 | }
|
6267 | }
|
6268 |
|
6269 |
|
6270 | Timeline.prototype = new Core();
|
6271 |
|
6272 | |
6273 |
|
6274 |
|
6275 |
|
6276 | Timeline.prototype.setItems = function(items) {
|
6277 | var initialLoad = (this.itemsData == null);
|
6278 |
|
6279 |
|
6280 | var newDataSet;
|
6281 | if (!items) {
|
6282 | newDataSet = null;
|
6283 | }
|
6284 | else if (items instanceof DataSet || items instanceof DataView) {
|
6285 | newDataSet = items;
|
6286 | }
|
6287 | else {
|
6288 |
|
6289 | newDataSet = new DataSet(items, {
|
6290 | type: {
|
6291 | start: 'Date',
|
6292 | end: 'Date'
|
6293 | }
|
6294 | });
|
6295 | }
|
6296 |
|
6297 |
|
6298 | this.itemsData = newDataSet;
|
6299 | this.itemSet && this.itemSet.setItems(newDataSet);
|
6300 | if (initialLoad) {
|
6301 | if (this.options.start != undefined || this.options.end != undefined) {
|
6302 | var start = this.options.start != undefined ? this.options.start : null;
|
6303 | var end = this.options.end != undefined ? this.options.end : null;
|
6304 |
|
6305 | this.setWindow(start, end, {animate: false});
|
6306 | }
|
6307 | else {
|
6308 | this.fit({animate: false});
|
6309 | }
|
6310 | }
|
6311 | };
|
6312 |
|
6313 | |
6314 |
|
6315 |
|
6316 |
|
6317 | Timeline.prototype.setGroups = function(groups) {
|
6318 |
|
6319 | var newDataSet;
|
6320 | if (!groups) {
|
6321 | newDataSet = null;
|
6322 | }
|
6323 | else if (groups instanceof DataSet || groups instanceof DataView) {
|
6324 | newDataSet = groups;
|
6325 | }
|
6326 | else {
|
6327 |
|
6328 | newDataSet = new DataSet(groups);
|
6329 | }
|
6330 |
|
6331 | this.groupsData = newDataSet;
|
6332 | this.itemSet.setGroups(newDataSet);
|
6333 | };
|
6334 |
|
6335 | |
6336 |
|
6337 |
|
6338 |
|
6339 |
|
6340 |
|
6341 |
|
6342 |
|
6343 |
|
6344 |
|
6345 |
|
6346 |
|
6347 |
|
6348 |
|
6349 |
|
6350 |
|
6351 | Timeline.prototype.setSelection = function(ids, options) {
|
6352 | this.itemSet && this.itemSet.setSelection(ids);
|
6353 |
|
6354 | if (options && options.focus) {
|
6355 | this.focus(ids, options);
|
6356 | }
|
6357 | };
|
6358 |
|
6359 | |
6360 |
|
6361 |
|
6362 |
|
6363 | Timeline.prototype.getSelection = function() {
|
6364 | return this.itemSet && this.itemSet.getSelection() || [];
|
6365 | };
|
6366 |
|
6367 | |
6368 |
|
6369 |
|
6370 |
|
6371 |
|
6372 |
|
6373 |
|
6374 |
|
6375 |
|
6376 |
|
6377 |
|
6378 |
|
6379 | Timeline.prototype.focus = function(id, options) {
|
6380 | if (!this.itemsData || id == undefined) return;
|
6381 |
|
6382 | var ids = Array.isArray(id) ? id : [id];
|
6383 |
|
6384 |
|
6385 | var itemsData = this.itemsData.getDataSet().get(ids, {
|
6386 | type: {
|
6387 | start: 'Date',
|
6388 | end: 'Date'
|
6389 | }
|
6390 | });
|
6391 |
|
6392 |
|
6393 | var start = null;
|
6394 | var end = null;
|
6395 | itemsData.forEach(function (itemData) {
|
6396 | var s = itemData.start.valueOf();
|
6397 | var e = 'end' in itemData ? itemData.end.valueOf() : itemData.start.valueOf();
|
6398 |
|
6399 | if (start === null || s < start) {
|
6400 | start = s;
|
6401 | }
|
6402 |
|
6403 | if (end === null || e > end) {
|
6404 | end = e;
|
6405 | }
|
6406 | });
|
6407 |
|
6408 | if (start !== null && end !== null) {
|
6409 |
|
6410 | var middle = (start + end) / 2;
|
6411 | var interval = Math.max((this.range.end - this.range.start), (end - start) * 1.1);
|
6412 |
|
6413 | var animate = (options && options.animate !== undefined) ? options.animate : true;
|
6414 | this.range.setRange(middle - interval / 2, middle + interval / 2, animate);
|
6415 | }
|
6416 | };
|
6417 |
|
6418 | |
6419 |
|
6420 |
|
6421 |
|
6422 |
|
6423 |
|
6424 | Timeline.prototype.getItemRange = function() {
|
6425 |
|
6426 | var dataset = this.itemsData.getDataSet(),
|
6427 | min = null,
|
6428 | max = null;
|
6429 |
|
6430 | if (dataset) {
|
6431 |
|
6432 | var minItem = dataset.min('start');
|
6433 | min = minItem ? util.convert(minItem.start, 'Date').valueOf() : null;
|
6434 |
|
6435 |
|
6436 |
|
6437 |
|
6438 | var maxStartItem = dataset.max('start');
|
6439 | if (maxStartItem) {
|
6440 | max = util.convert(maxStartItem.start, 'Date').valueOf();
|
6441 | }
|
6442 | var maxEndItem = dataset.max('end');
|
6443 | if (maxEndItem) {
|
6444 | if (max == null) {
|
6445 | max = util.convert(maxEndItem.end, 'Date').valueOf();
|
6446 | }
|
6447 | else {
|
6448 | max = Math.max(max, util.convert(maxEndItem.end, 'Date').valueOf());
|
6449 | }
|
6450 | }
|
6451 | }
|
6452 |
|
6453 | return {
|
6454 | min: (min != null) ? new Date(min) : null,
|
6455 | max: (max != null) ? new Date(max) : null
|
6456 | };
|
6457 | };
|
6458 |
|
6459 |
|
6460 | module.exports = Timeline;
|
6461 |
|
6462 |
|
6463 | },
|
6464 |
|
6465 | function(module, exports, __webpack_require__) {
|
6466 |
|
6467 | var Emitter = __webpack_require__(50);
|
6468 | var Hammer = __webpack_require__(42);
|
6469 | var util = __webpack_require__(1);
|
6470 | var DataSet = __webpack_require__(3);
|
6471 | var DataView = __webpack_require__(4);
|
6472 | var Range = __webpack_require__(15);
|
6473 | var Core = __webpack_require__(44);
|
6474 | var TimeAxis = __webpack_require__(27);
|
6475 | var CurrentTime = __webpack_require__(19);
|
6476 | var CustomTime = __webpack_require__(20);
|
6477 | var LineGraph = __webpack_require__(26);
|
6478 |
|
6479 | |
6480 |
|
6481 |
|
6482 |
|
6483 |
|
6484 |
|
6485 |
|
6486 |
|
6487 | function Graph2d (container, items, options, groups) {
|
6488 | var me = this;
|
6489 | this.defaultOptions = {
|
6490 | start: null,
|
6491 | end: null,
|
6492 |
|
6493 | autoResize: true,
|
6494 |
|
6495 | orientation: 'bottom',
|
6496 | width: null,
|
6497 | height: null,
|
6498 | maxHeight: null,
|
6499 | minHeight: null
|
6500 | };
|
6501 | this.options = util.deepExtend({}, this.defaultOptions);
|
6502 |
|
6503 |
|
6504 | this._create(container);
|
6505 |
|
6506 |
|
6507 | this.components = [];
|
6508 |
|
6509 | this.body = {
|
6510 | dom: this.dom,
|
6511 | domProps: this.props,
|
6512 | emitter: {
|
6513 | on: this.on.bind(this),
|
6514 | off: this.off.bind(this),
|
6515 | emit: this.emit.bind(this)
|
6516 | },
|
6517 | util: {
|
6518 | snap: null,
|
6519 | toScreen: me._toScreen.bind(me),
|
6520 | toGlobalScreen: me._toGlobalScreen.bind(me),
|
6521 | toTime: me._toTime.bind(me),
|
6522 | toGlobalTime : me._toGlobalTime.bind(me)
|
6523 | }
|
6524 | };
|
6525 |
|
6526 |
|
6527 | this.range = new Range(this.body);
|
6528 | this.components.push(this.range);
|
6529 | this.body.range = this.range;
|
6530 |
|
6531 |
|
6532 | this.timeAxis = new TimeAxis(this.body);
|
6533 | this.components.push(this.timeAxis);
|
6534 | this.body.util.snap = this.timeAxis.snap.bind(this.timeAxis);
|
6535 |
|
6536 |
|
6537 | this.currentTime = new CurrentTime(this.body);
|
6538 | this.components.push(this.currentTime);
|
6539 |
|
6540 |
|
6541 |
|
6542 | this.customTime = new CustomTime(this.body);
|
6543 | this.components.push(this.customTime);
|
6544 |
|
6545 |
|
6546 | this.linegraph = new LineGraph(this.body);
|
6547 | this.components.push(this.linegraph);
|
6548 |
|
6549 | this.itemsData = null;
|
6550 | this.groupsData = null;
|
6551 |
|
6552 |
|
6553 | if (options) {
|
6554 | this.setOptions(options);
|
6555 | }
|
6556 |
|
6557 |
|
6558 | if (groups) {
|
6559 | this.setGroups(groups);
|
6560 | }
|
6561 |
|
6562 |
|
6563 | if (items) {
|
6564 | this.setItems(items);
|
6565 | }
|
6566 | else {
|
6567 | this.redraw();
|
6568 | }
|
6569 | }
|
6570 |
|
6571 |
|
6572 | Graph2d.prototype = new Core();
|
6573 |
|
6574 | |
6575 |
|
6576 |
|
6577 |
|
6578 | Graph2d.prototype.setItems = function(items) {
|
6579 | var initialLoad = (this.itemsData == null);
|
6580 |
|
6581 |
|
6582 | var newDataSet;
|
6583 | if (!items) {
|
6584 | newDataSet = null;
|
6585 | }
|
6586 | else if (items instanceof DataSet || items instanceof DataView) {
|
6587 | newDataSet = items;
|
6588 | }
|
6589 | else {
|
6590 |
|
6591 | newDataSet = new DataSet(items, {
|
6592 | type: {
|
6593 | start: 'Date',
|
6594 | end: 'Date'
|
6595 | }
|
6596 | });
|
6597 | }
|
6598 |
|
6599 |
|
6600 | this.itemsData = newDataSet;
|
6601 | this.linegraph && this.linegraph.setItems(newDataSet);
|
6602 |
|
6603 | if (initialLoad && ('start' in this.options || 'end' in this.options)) {
|
6604 | this.fit();
|
6605 |
|
6606 | var start = ('start' in this.options) ? util.convert(this.options.start, 'Date') : null;
|
6607 | var end = ('end' in this.options) ? util.convert(this.options.end, 'Date') : null;
|
6608 |
|
6609 | this.setWindow(start, end);
|
6610 | }
|
6611 | };
|
6612 |
|
6613 | |
6614 |
|
6615 |
|
6616 |
|
6617 | Graph2d.prototype.setGroups = function(groups) {
|
6618 |
|
6619 | var newDataSet;
|
6620 | if (!groups) {
|
6621 | newDataSet = null;
|
6622 | }
|
6623 | else if (groups instanceof DataSet || groups instanceof DataView) {
|
6624 | newDataSet = groups;
|
6625 | }
|
6626 | else {
|
6627 |
|
6628 | newDataSet = new DataSet(groups);
|
6629 | }
|
6630 |
|
6631 | this.groupsData = newDataSet;
|
6632 | this.linegraph.setGroups(newDataSet);
|
6633 | };
|
6634 |
|
6635 | |
6636 |
|
6637 |
|
6638 |
|
6639 |
|
6640 |
|
6641 | Graph2d.prototype.getLegend = function(groupId, width, height) {
|
6642 | if (width === undefined) {width = 15;}
|
6643 | if (height === undefined) {height = 15;}
|
6644 | if (this.linegraph.groups[groupId] !== undefined) {
|
6645 | return this.linegraph.groups[groupId].getLegend(width,height);
|
6646 | }
|
6647 | else {
|
6648 | return "cannot find group:" + groupId;
|
6649 | }
|
6650 | }
|
6651 |
|
6652 | |
6653 |
|
6654 |
|
6655 |
|
6656 |
|
6657 | Graph2d.prototype.isGroupVisible = function(groupId) {
|
6658 | if (this.linegraph.groups[groupId] !== undefined) {
|
6659 | return (this.linegraph.groups[groupId].visible && (this.linegraph.options.groups.visibility[groupId] === undefined || this.linegraph.options.groups.visibility[groupId] == true));
|
6660 | }
|
6661 | else {
|
6662 | return false;
|
6663 | }
|
6664 | }
|
6665 |
|
6666 |
|
6667 | |
6668 |
|
6669 |
|
6670 |
|
6671 |
|
6672 |
|
6673 | Graph2d.prototype.getItemRange = function() {
|
6674 | var min = null;
|
6675 | var max = null;
|
6676 |
|
6677 |
|
6678 | for (var groupId in this.linegraph.groups) {
|
6679 | if (this.linegraph.groups.hasOwnProperty(groupId)) {
|
6680 | if (this.linegraph.groups[groupId].visible == true) {
|
6681 | for (var i = 0; i < this.linegraph.groups[groupId].itemsData.length; i++) {
|
6682 | var item = this.linegraph.groups[groupId].itemsData[i];
|
6683 | var value = util.convert(item.x, 'Date').valueOf();
|
6684 | min = min == null ? value : min > value ? value : min;
|
6685 | max = max == null ? value : max < value ? value : max;
|
6686 | }
|
6687 | }
|
6688 | }
|
6689 | }
|
6690 |
|
6691 | return {
|
6692 | min: (min != null) ? new Date(min) : null,
|
6693 | max: (max != null) ? new Date(max) : null
|
6694 | };
|
6695 | };
|
6696 |
|
6697 |
|
6698 |
|
6699 | module.exports = Graph2d;
|
6700 |
|
6701 |
|
6702 | },
|
6703 |
|
6704 | function(module, exports, __webpack_require__) {
|
6705 |
|
6706 | |
6707 |
|
6708 |
|
6709 |
|
6710 |
|
6711 |
|
6712 |
|
6713 |
|
6714 |
|
6715 |
|
6716 |
|
6717 |
|
6718 |
|
6719 |
|
6720 |
|
6721 |
|
6722 |
|
6723 |
|
6724 |
|
6725 |
|
6726 |
|
6727 |
|
6728 |
|
6729 |
|
6730 |
|
6731 |
|
6732 | function DataStep(start, end, minimumStep, containerHeight, customRange) {
|
6733 |
|
6734 | this.current = 0;
|
6735 |
|
6736 | this.autoScale = true;
|
6737 | this.stepIndex = 0;
|
6738 | this.step = 1;
|
6739 | this.scale = 1;
|
6740 |
|
6741 | this.marginStart;
|
6742 | this.marginEnd;
|
6743 | this.deadSpace = 0;
|
6744 |
|
6745 | this.majorSteps = [1, 2, 5, 10];
|
6746 | this.minorSteps = [0.25, 0.5, 1, 2];
|
6747 |
|
6748 | this.setRange(start, end, minimumStep, containerHeight, customRange);
|
6749 | }
|
6750 |
|
6751 |
|
6752 |
|
6753 | |
6754 |
|
6755 |
|
6756 |
|
6757 |
|
6758 |
|
6759 |
|
6760 |
|
6761 |
|
6762 |
|
6763 | DataStep.prototype.setRange = function(start, end, minimumStep, containerHeight, customRange) {
|
6764 | this._start = customRange.min === undefined ? start : customRange.min;
|
6765 | this._end = customRange.max === undefined ? end : customRange.max;
|
6766 |
|
6767 | if (this._start == this._end) {
|
6768 | this._start -= 0.75;
|
6769 | this._end += 1;
|
6770 | }
|
6771 |
|
6772 | if (this.autoScale) {
|
6773 | this.setMinimumStep(minimumStep, containerHeight);
|
6774 | }
|
6775 | this.setFirst(customRange);
|
6776 | };
|
6777 |
|
6778 | |
6779 |
|
6780 |
|
6781 |
|
6782 | DataStep.prototype.setMinimumStep = function(minimumStep, containerHeight) {
|
6783 |
|
6784 | var size = this._end - this._start;
|
6785 | var safeSize = size * 1.2;
|
6786 | var minimumStepValue = minimumStep * (safeSize / containerHeight);
|
6787 | var orderOfMagnitude = Math.round(Math.log(safeSize)/Math.LN10);
|
6788 |
|
6789 | var minorStepIdx = -1;
|
6790 | var magnitudefactor = Math.pow(10,orderOfMagnitude);
|
6791 |
|
6792 | var start = 0;
|
6793 | if (orderOfMagnitude < 0) {
|
6794 | start = orderOfMagnitude;
|
6795 | }
|
6796 |
|
6797 | var solutionFound = false;
|
6798 | for (var i = start; Math.abs(i) <= Math.abs(orderOfMagnitude); i++) {
|
6799 | magnitudefactor = Math.pow(10,i);
|
6800 | for (var j = 0; j < this.minorSteps.length; j++) {
|
6801 | var stepSize = magnitudefactor * this.minorSteps[j];
|
6802 | if (stepSize >= minimumStepValue) {
|
6803 | solutionFound = true;
|
6804 | minorStepIdx = j;
|
6805 | break;
|
6806 | }
|
6807 | }
|
6808 | if (solutionFound == true) {
|
6809 | break;
|
6810 | }
|
6811 | }
|
6812 | this.stepIndex = minorStepIdx;
|
6813 | this.scale = magnitudefactor;
|
6814 | this.step = magnitudefactor * this.minorSteps[minorStepIdx];
|
6815 | };
|
6816 |
|
6817 |
|
6818 |
|
6819 | |
6820 |
|
6821 |
|
6822 |
|
6823 | DataStep.prototype.setFirst = function(customRange) {
|
6824 | if (customRange === undefined) {
|
6825 | customRange = {};
|
6826 | }
|
6827 | var niceStart = customRange.min === undefined ? this._start - (this.scale * 2 * this.minorSteps[this.stepIndex]) : customRange.min;
|
6828 | var niceEnd = customRange.max === undefined ? this._end + (this.scale * this.minorSteps[this.stepIndex]) : customRange.max;
|
6829 |
|
6830 | this.marginEnd = customRange.max === undefined ? this.roundToMinor(niceEnd) : customRange.max;
|
6831 | this.marginStart = customRange.min === undefined ? this.roundToMinor(niceStart) : customRange.min;
|
6832 | this.deadSpace = this.roundToMinor(niceEnd) - niceEnd + this.roundToMinor(niceStart) - niceStart;
|
6833 | this.marginRange = this.marginEnd - this.marginStart;
|
6834 |
|
6835 | this.current = this.marginEnd;
|
6836 |
|
6837 | };
|
6838 |
|
6839 | DataStep.prototype.roundToMinor = function(value) {
|
6840 | var rounded = value - (value % (this.scale * this.minorSteps[this.stepIndex]));
|
6841 | if (value % (this.scale * this.minorSteps[this.stepIndex]) > 0.5 * (this.scale * this.minorSteps[this.stepIndex])) {
|
6842 | return rounded + (this.scale * this.minorSteps[this.stepIndex]);
|
6843 | }
|
6844 | else {
|
6845 | return rounded;
|
6846 | }
|
6847 | }
|
6848 |
|
6849 |
|
6850 | |
6851 |
|
6852 |
|
6853 |
|
6854 | DataStep.prototype.hasNext = function () {
|
6855 | return (this.current >= this.marginStart);
|
6856 | };
|
6857 |
|
6858 | |
6859 |
|
6860 |
|
6861 | DataStep.prototype.next = function() {
|
6862 | var prev = this.current;
|
6863 | this.current -= this.step;
|
6864 |
|
6865 |
|
6866 | if (this.current == prev) {
|
6867 | this.current = this._end;
|
6868 | }
|
6869 | };
|
6870 |
|
6871 | |
6872 |
|
6873 |
|
6874 | DataStep.prototype.previous = function() {
|
6875 | this.current += this.step;
|
6876 | this.marginEnd += this.step;
|
6877 | this.marginRange = this.marginEnd - this.marginStart;
|
6878 | };
|
6879 |
|
6880 |
|
6881 |
|
6882 | |
6883 |
|
6884 |
|
6885 |
|
6886 | DataStep.prototype.getCurrent = function() {
|
6887 | var toPrecision = '' + Number(this.current).toPrecision(5);
|
6888 | if (toPrecision.indexOf(",") != -1 || toPrecision.indexOf(".") != -1) {
|
6889 | for (var i = toPrecision.length-1; i > 0; i--) {
|
6890 | if (toPrecision[i] == "0") {
|
6891 | toPrecision = toPrecision.slice(0,i);
|
6892 | }
|
6893 | else if (toPrecision[i] == "." || toPrecision[i] == ",") {
|
6894 | toPrecision = toPrecision.slice(0,i);
|
6895 | break;
|
6896 | }
|
6897 | else{
|
6898 | break;
|
6899 | }
|
6900 | }
|
6901 | }
|
6902 |
|
6903 | return toPrecision;
|
6904 | };
|
6905 |
|
6906 |
|
6907 |
|
6908 | |
6909 |
|
6910 |
|
6911 |
|
6912 |
|
6913 |
|
6914 | DataStep.prototype.snap = function(date) {
|
6915 |
|
6916 | };
|
6917 |
|
6918 | |
6919 |
|
6920 |
|
6921 |
|
6922 |
|
6923 | DataStep.prototype.isMajor = function() {
|
6924 | return (this.current % (this.scale * this.majorSteps[this.stepIndex]) == 0);
|
6925 | };
|
6926 |
|
6927 | module.exports = DataStep;
|
6928 |
|
6929 |
|
6930 | },
|
6931 |
|
6932 | function(module, exports, __webpack_require__) {
|
6933 |
|
6934 | var util = __webpack_require__(1);
|
6935 | var hammerUtil = __webpack_require__(43);
|
6936 | var moment = __webpack_require__(41);
|
6937 | var Component = __webpack_require__(18);
|
6938 |
|
6939 | |
6940 |
|
6941 |
|
6942 |
|
6943 |
|
6944 |
|
6945 |
|
6946 |
|
6947 | function Range(body, options) {
|
6948 | var now = moment().hours(0).minutes(0).seconds(0).milliseconds(0);
|
6949 | this.start = now.clone().add(-3, 'days').valueOf();
|
6950 | this.end = now.clone().add(4, 'days').valueOf();
|
6951 |
|
6952 | this.body = body;
|
6953 |
|
6954 |
|
6955 | this.defaultOptions = {
|
6956 | start: null,
|
6957 | end: null,
|
6958 | direction: 'horizontal',
|
6959 | moveable: true,
|
6960 | zoomable: true,
|
6961 | min: null,
|
6962 | max: null,
|
6963 | zoomMin: 10,
|
6964 | zoomMax: 1000 * 60 * 60 * 24 * 365 * 10000
|
6965 | };
|
6966 | this.options = util.extend({}, this.defaultOptions);
|
6967 |
|
6968 | this.props = {
|
6969 | touch: {}
|
6970 | };
|
6971 | this.animateTimer = null;
|
6972 |
|
6973 |
|
6974 | this.body.emitter.on('dragstart', this._onDragStart.bind(this));
|
6975 | this.body.emitter.on('drag', this._onDrag.bind(this));
|
6976 | this.body.emitter.on('dragend', this._onDragEnd.bind(this));
|
6977 |
|
6978 |
|
6979 | this.body.emitter.on('hold', this._onHold.bind(this));
|
6980 |
|
6981 |
|
6982 | this.body.emitter.on('mousewheel', this._onMouseWheel.bind(this));
|
6983 | this.body.emitter.on('DOMMouseScroll', this._onMouseWheel.bind(this));
|
6984 |
|
6985 |
|
6986 | this.body.emitter.on('touch', this._onTouch.bind(this));
|
6987 | this.body.emitter.on('pinch', this._onPinch.bind(this));
|
6988 |
|
6989 | this.setOptions(options);
|
6990 | }
|
6991 |
|
6992 | Range.prototype = new Component();
|
6993 |
|
6994 | |
6995 |
|
6996 |
|
6997 |
|
6998 |
|
6999 |
|
7000 |
|
7001 |
|
7002 |
|
7003 |
|
7004 |
|
7005 |
|
7006 |
|
7007 |
|
7008 |
|
7009 |
|
7010 | Range.prototype.setOptions = function (options) {
|
7011 | if (options) {
|
7012 |
|
7013 | var fields = ['direction', 'min', 'max', 'zoomMin', 'zoomMax', 'moveable', 'zoomable', 'activate'];
|
7014 | util.selectiveExtend(fields, this.options, options);
|
7015 |
|
7016 | if ('start' in options || 'end' in options) {
|
7017 |
|
7018 | this.setRange(options.start, options.end);
|
7019 | }
|
7020 | }
|
7021 | };
|
7022 |
|
7023 | |
7024 |
|
7025 |
|
7026 |
|
7027 | function validateDirection (direction) {
|
7028 | if (direction != 'horizontal' && direction != 'vertical') {
|
7029 | throw new TypeError('Unknown direction "' + direction + '". ' +
|
7030 | 'Choose "horizontal" or "vertical".');
|
7031 | }
|
7032 | }
|
7033 |
|
7034 | |
7035 |
|
7036 |
|
7037 |
|
7038 |
|
7039 |
|
7040 |
|
7041 |
|
7042 |
|
7043 |
|
7044 |
|
7045 | Range.prototype.setRange = function(start, end, animate) {
|
7046 | var _start = start != undefined ? util.convert(start, 'Date').valueOf() : null;
|
7047 | var _end = end != undefined ? util.convert(end, 'Date').valueOf() : null;
|
7048 |
|
7049 | this._cancelAnimation();
|
7050 |
|
7051 | if (animate) {
|
7052 | var me = this;
|
7053 | var initStart = this.start;
|
7054 | var initEnd = this.end;
|
7055 | var duration = typeof animate === 'number' ? animate : 500;
|
7056 | var initTime = new Date().valueOf();
|
7057 | var anyChanged = false;
|
7058 |
|
7059 | function next() {
|
7060 | if (!me.props.touch.dragging) {
|
7061 | var now = new Date().valueOf();
|
7062 | var time = now - initTime;
|
7063 | var done = time > duration;
|
7064 | var s = (done || _start === null) ? _start : util.easeInOutQuad(time, initStart, _start, duration);
|
7065 | var e = (done || _end === null) ? _end : util.easeInOutQuad(time, initEnd, _end, duration);
|
7066 |
|
7067 | changed = me._applyRange(s, e);
|
7068 | anyChanged = anyChanged || changed;
|
7069 | if (changed) {
|
7070 | me.body.emitter.emit('rangechange', {start: new Date(me.start), end: new Date(me.end)});
|
7071 | }
|
7072 |
|
7073 | if (done) {
|
7074 | if (anyChanged) {
|
7075 | me.body.emitter.emit('rangechanged', {start: new Date(me.start), end: new Date(me.end)});
|
7076 | }
|
7077 | }
|
7078 | else {
|
7079 |
|
7080 |
|
7081 | me.animateTimer = setTimeout(next, 20);
|
7082 | }
|
7083 | }
|
7084 | }
|
7085 |
|
7086 | return next();
|
7087 | }
|
7088 | else {
|
7089 | var changed = this._applyRange(_start, _end);
|
7090 | if (changed) {
|
7091 | var params = {start: new Date(this.start), end: new Date(this.end)};
|
7092 | this.body.emitter.emit('rangechange', params);
|
7093 | this.body.emitter.emit('rangechanged', params);
|
7094 | }
|
7095 | }
|
7096 | };
|
7097 |
|
7098 | |
7099 |
|
7100 |
|
7101 |
|
7102 | Range.prototype._cancelAnimation = function () {
|
7103 | if (this.animateTimer) {
|
7104 | clearTimeout(this.animateTimer);
|
7105 | this.animateTimer = null;
|
7106 | }
|
7107 | };
|
7108 |
|
7109 | |
7110 |
|
7111 |
|
7112 |
|
7113 |
|
7114 |
|
7115 |
|
7116 |
|
7117 |
|
7118 | Range.prototype._applyRange = function(start, end) {
|
7119 | var newStart = (start != null) ? util.convert(start, 'Date').valueOf() : this.start,
|
7120 | newEnd = (end != null) ? util.convert(end, 'Date').valueOf() : this.end,
|
7121 | max = (this.options.max != null) ? util.convert(this.options.max, 'Date').valueOf() : null,
|
7122 | min = (this.options.min != null) ? util.convert(this.options.min, 'Date').valueOf() : null,
|
7123 | diff;
|
7124 |
|
7125 |
|
7126 | if (isNaN(newStart) || newStart === null) {
|
7127 | throw new Error('Invalid start "' + start + '"');
|
7128 | }
|
7129 | if (isNaN(newEnd) || newEnd === null) {
|
7130 | throw new Error('Invalid end "' + end + '"');
|
7131 | }
|
7132 |
|
7133 |
|
7134 | if (newEnd < newStart) {
|
7135 | newEnd = newStart;
|
7136 | }
|
7137 |
|
7138 |
|
7139 | if (min !== null) {
|
7140 | if (newStart < min) {
|
7141 | diff = (min - newStart);
|
7142 | newStart += diff;
|
7143 | newEnd += diff;
|
7144 |
|
7145 |
|
7146 | if (max != null) {
|
7147 | if (newEnd > max) {
|
7148 | newEnd = max;
|
7149 | }
|
7150 | }
|
7151 | }
|
7152 | }
|
7153 |
|
7154 |
|
7155 | if (max !== null) {
|
7156 | if (newEnd > max) {
|
7157 | diff = (newEnd - max);
|
7158 | newStart -= diff;
|
7159 | newEnd -= diff;
|
7160 |
|
7161 |
|
7162 | if (min != null) {
|
7163 | if (newStart < min) {
|
7164 | newStart = min;
|
7165 | }
|
7166 | }
|
7167 | }
|
7168 | }
|
7169 |
|
7170 |
|
7171 | if (this.options.zoomMin !== null) {
|
7172 | var zoomMin = parseFloat(this.options.zoomMin);
|
7173 | if (zoomMin < 0) {
|
7174 | zoomMin = 0;
|
7175 | }
|
7176 | if ((newEnd - newStart) < zoomMin) {
|
7177 | if ((this.end - this.start) === zoomMin) {
|
7178 |
|
7179 | newStart = this.start;
|
7180 | newEnd = this.end;
|
7181 | }
|
7182 | else {
|
7183 |
|
7184 | diff = (zoomMin - (newEnd - newStart));
|
7185 | newStart -= diff / 2;
|
7186 | newEnd += diff / 2;
|
7187 | }
|
7188 | }
|
7189 | }
|
7190 |
|
7191 |
|
7192 | if (this.options.zoomMax !== null) {
|
7193 | var zoomMax = parseFloat(this.options.zoomMax);
|
7194 | if (zoomMax < 0) {
|
7195 | zoomMax = 0;
|
7196 | }
|
7197 | if ((newEnd - newStart) > zoomMax) {
|
7198 | if ((this.end - this.start) === zoomMax) {
|
7199 |
|
7200 | newStart = this.start;
|
7201 | newEnd = this.end;
|
7202 | }
|
7203 | else {
|
7204 |
|
7205 | diff = ((newEnd - newStart) - zoomMax);
|
7206 | newStart += diff / 2;
|
7207 | newEnd -= diff / 2;
|
7208 | }
|
7209 | }
|
7210 | }
|
7211 |
|
7212 | var changed = (this.start != newStart || this.end != newEnd);
|
7213 |
|
7214 | this.start = newStart;
|
7215 | this.end = newEnd;
|
7216 |
|
7217 | return changed;
|
7218 | };
|
7219 |
|
7220 | |
7221 |
|
7222 |
|
7223 |
|
7224 | Range.prototype.getRange = function() {
|
7225 | return {
|
7226 | start: this.start,
|
7227 | end: this.end
|
7228 | };
|
7229 | };
|
7230 |
|
7231 | |
7232 |
|
7233 |
|
7234 |
|
7235 |
|
7236 |
|
7237 | Range.prototype.conversion = function (width) {
|
7238 | return Range.conversion(this.start, this.end, width);
|
7239 | };
|
7240 |
|
7241 | |
7242 |
|
7243 |
|
7244 |
|
7245 |
|
7246 |
|
7247 |
|
7248 |
|
7249 | Range.conversion = function (start, end, width) {
|
7250 | if (width != 0 && (end - start != 0)) {
|
7251 | return {
|
7252 | offset: start,
|
7253 | scale: width / (end - start)
|
7254 | }
|
7255 | }
|
7256 | else {
|
7257 | return {
|
7258 | offset: 0,
|
7259 | scale: 1
|
7260 | };
|
7261 | }
|
7262 | };
|
7263 |
|
7264 | |
7265 |
|
7266 |
|
7267 |
|
7268 |
|
7269 | Range.prototype._onDragStart = function(event) {
|
7270 |
|
7271 | if (!this.options.moveable) return;
|
7272 |
|
7273 |
|
7274 |
|
7275 | if (!this.props.touch.allowDragging) return;
|
7276 |
|
7277 | this.props.touch.start = this.start;
|
7278 | this.props.touch.end = this.end;
|
7279 | this.props.touch.dragging = true;
|
7280 |
|
7281 | if (this.body.dom.root) {
|
7282 | this.body.dom.root.style.cursor = 'move';
|
7283 | }
|
7284 | };
|
7285 |
|
7286 | |
7287 |
|
7288 |
|
7289 |
|
7290 |
|
7291 | Range.prototype._onDrag = function (event) {
|
7292 |
|
7293 | if (!this.options.moveable) return;
|
7294 | var direction = this.options.direction;
|
7295 | validateDirection(direction);
|
7296 |
|
7297 |
|
7298 |
|
7299 | if (!this.props.touch.allowDragging) return;
|
7300 |
|
7301 | var delta = (direction == 'horizontal') ? event.gesture.deltaX : event.gesture.deltaY;
|
7302 | var interval = (this.props.touch.end - this.props.touch.start);
|
7303 | var width = (direction == 'horizontal') ? this.body.domProps.center.width : this.body.domProps.center.height;
|
7304 | var diffRange = -delta / width * interval;
|
7305 | this._applyRange(this.props.touch.start + diffRange, this.props.touch.end + diffRange);
|
7306 |
|
7307 |
|
7308 | this.body.emitter.emit('rangechange', {
|
7309 | start: new Date(this.start),
|
7310 | end: new Date(this.end)
|
7311 | });
|
7312 | };
|
7313 |
|
7314 | |
7315 |
|
7316 |
|
7317 |
|
7318 |
|
7319 | Range.prototype._onDragEnd = function (event) {
|
7320 |
|
7321 | if (!this.options.moveable) return;
|
7322 |
|
7323 |
|
7324 |
|
7325 | if (!this.props.touch.allowDragging) return;
|
7326 |
|
7327 | this.props.touch.dragging = false;
|
7328 | if (this.body.dom.root) {
|
7329 | this.body.dom.root.style.cursor = 'auto';
|
7330 | }
|
7331 |
|
7332 |
|
7333 | this.body.emitter.emit('rangechanged', {
|
7334 | start: new Date(this.start),
|
7335 | end: new Date(this.end)
|
7336 | });
|
7337 | };
|
7338 |
|
7339 | |
7340 |
|
7341 |
|
7342 |
|
7343 |
|
7344 |
|
7345 | Range.prototype._onMouseWheel = function(event) {
|
7346 |
|
7347 | if (!(this.options.zoomable && this.options.moveable)) return;
|
7348 |
|
7349 |
|
7350 | var delta = 0;
|
7351 | if (event.wheelDelta) {
|
7352 | delta = event.wheelDelta / 120;
|
7353 | } else if (event.detail) {
|
7354 |
|
7355 |
|
7356 | delta = -event.detail / 3;
|
7357 | }
|
7358 |
|
7359 |
|
7360 |
|
7361 |
|
7362 | if (delta) {
|
7363 |
|
7364 |
|
7365 |
|
7366 |
|
7367 | var scale;
|
7368 | if (delta < 0) {
|
7369 | scale = 1 - (delta / 5);
|
7370 | }
|
7371 | else {
|
7372 | scale = 1 / (1 + (delta / 5)) ;
|
7373 | }
|
7374 |
|
7375 |
|
7376 | var gesture = hammerUtil.fakeGesture(this, event),
|
7377 | pointer = getPointer(gesture.center, this.body.dom.center),
|
7378 | pointerDate = this._pointerToDate(pointer);
|
7379 |
|
7380 | this.zoom(scale, pointerDate);
|
7381 | }
|
7382 |
|
7383 |
|
7384 |
|
7385 | event.preventDefault();
|
7386 | };
|
7387 |
|
7388 | |
7389 |
|
7390 |
|
7391 |
|
7392 | Range.prototype._onTouch = function (event) {
|
7393 | this.props.touch.start = this.start;
|
7394 | this.props.touch.end = this.end;
|
7395 | this.props.touch.allowDragging = true;
|
7396 | this.props.touch.center = null;
|
7397 | };
|
7398 |
|
7399 | |
7400 |
|
7401 |
|
7402 |
|
7403 | Range.prototype._onHold = function () {
|
7404 | this.props.touch.allowDragging = false;
|
7405 | };
|
7406 |
|
7407 | |
7408 |
|
7409 |
|
7410 |
|
7411 |
|
7412 | Range.prototype._onPinch = function (event) {
|
7413 |
|
7414 | if (!(this.options.zoomable && this.options.moveable)) return;
|
7415 |
|
7416 | this.props.touch.allowDragging = false;
|
7417 |
|
7418 | if (event.gesture.touches.length > 1) {
|
7419 | if (!this.props.touch.center) {
|
7420 | this.props.touch.center = getPointer(event.gesture.center, this.body.dom.center);
|
7421 | }
|
7422 |
|
7423 | var scale = 1 / event.gesture.scale,
|
7424 | initDate = this._pointerToDate(this.props.touch.center);
|
7425 |
|
7426 |
|
7427 | var newStart = parseInt(initDate + (this.props.touch.start - initDate) * scale);
|
7428 | var newEnd = parseInt(initDate + (this.props.touch.end - initDate) * scale);
|
7429 |
|
7430 |
|
7431 | this.setRange(newStart, newEnd);
|
7432 | }
|
7433 | };
|
7434 |
|
7435 | |
7436 |
|
7437 |
|
7438 |
|
7439 |
|
7440 |
|
7441 | Range.prototype._pointerToDate = function (pointer) {
|
7442 | var conversion;
|
7443 | var direction = this.options.direction;
|
7444 |
|
7445 | validateDirection(direction);
|
7446 |
|
7447 | if (direction == 'horizontal') {
|
7448 | var width = this.body.domProps.center.width;
|
7449 | conversion = this.conversion(width);
|
7450 | return pointer.x / conversion.scale + conversion.offset;
|
7451 | }
|
7452 | else {
|
7453 | var height = this.body.domProps.center.height;
|
7454 | conversion = this.conversion(height);
|
7455 | return pointer.y / conversion.scale + conversion.offset;
|
7456 | }
|
7457 | };
|
7458 |
|
7459 | |
7460 |
|
7461 |
|
7462 |
|
7463 |
|
7464 |
|
7465 |
|
7466 | function getPointer (touch, element) {
|
7467 | return {
|
7468 | x: touch.pageX - util.getAbsoluteLeft(element),
|
7469 | y: touch.pageY - util.getAbsoluteTop(element)
|
7470 | };
|
7471 | }
|
7472 |
|
7473 | |
7474 |
|
7475 |
|
7476 |
|
7477 |
|
7478 |
|
7479 |
|
7480 |
|
7481 |
|
7482 |
|
7483 | Range.prototype.zoom = function(scale, center) {
|
7484 |
|
7485 | if (center == null) {
|
7486 | center = (this.start + this.end) / 2;
|
7487 | }
|
7488 |
|
7489 |
|
7490 | var newStart = center + (this.start - center) * scale;
|
7491 | var newEnd = center + (this.end - center) * scale;
|
7492 |
|
7493 | this.setRange(newStart, newEnd);
|
7494 | };
|
7495 |
|
7496 | |
7497 |
|
7498 |
|
7499 |
|
7500 |
|
7501 |
|
7502 | Range.prototype.move = function(delta) {
|
7503 |
|
7504 | var diff = (this.end - this.start);
|
7505 |
|
7506 |
|
7507 | var newStart = this.start + diff * delta;
|
7508 | var newEnd = this.end + diff * delta;
|
7509 |
|
7510 |
|
7511 |
|
7512 | this.start = newStart;
|
7513 | this.end = newEnd;
|
7514 | };
|
7515 |
|
7516 | |
7517 |
|
7518 |
|
7519 |
|
7520 | Range.prototype.moveTo = function(moveTo) {
|
7521 | var center = (this.start + this.end) / 2;
|
7522 |
|
7523 | var diff = center - moveTo;
|
7524 |
|
7525 |
|
7526 | var newStart = this.start - diff;
|
7527 | var newEnd = this.end - diff;
|
7528 |
|
7529 | this.setRange(newStart, newEnd);
|
7530 | };
|
7531 |
|
7532 | module.exports = Range;
|
7533 |
|
7534 |
|
7535 | },
|
7536 |
|
7537 | function(module, exports, __webpack_require__) {
|
7538 |
|
7539 |
|
7540 | var EPSILON = 0.001;
|
7541 |
|
7542 | |
7543 |
|
7544 |
|
7545 |
|
7546 | exports.orderByStart = function(items) {
|
7547 | items.sort(function (a, b) {
|
7548 | return a.data.start - b.data.start;
|
7549 | });
|
7550 | };
|
7551 |
|
7552 | |
7553 |
|
7554 |
|
7555 |
|
7556 |
|
7557 | exports.orderByEnd = function(items) {
|
7558 | items.sort(function (a, b) {
|
7559 | var aTime = ('end' in a.data) ? a.data.end : a.data.start,
|
7560 | bTime = ('end' in b.data) ? b.data.end : b.data.start;
|
7561 |
|
7562 | return aTime - bTime;
|
7563 | });
|
7564 | };
|
7565 |
|
7566 | |
7567 |
|
7568 |
|
7569 |
|
7570 |
|
7571 |
|
7572 |
|
7573 |
|
7574 |
|
7575 |
|
7576 |
|
7577 | exports.stack = function(items, margin, force) {
|
7578 | var i, iMax;
|
7579 |
|
7580 | if (force) {
|
7581 |
|
7582 | for (i = 0, iMax = items.length; i < iMax; i++) {
|
7583 | items[i].top = null;
|
7584 | }
|
7585 | }
|
7586 |
|
7587 |
|
7588 | for (i = 0, iMax = items.length; i < iMax; i++) {
|
7589 | var item = items[i];
|
7590 | if (item.top === null) {
|
7591 |
|
7592 | item.top = margin.axis;
|
7593 |
|
7594 | do {
|
7595 |
|
7596 |
|
7597 | var collidingItem = null;
|
7598 | for (var j = 0, jj = items.length; j < jj; j++) {
|
7599 | var other = items[j];
|
7600 | if (other.top !== null && other !== item && exports.collision(item, other, margin.item)) {
|
7601 | collidingItem = other;
|
7602 | break;
|
7603 | }
|
7604 | }
|
7605 |
|
7606 | if (collidingItem != null) {
|
7607 |
|
7608 | item.top = collidingItem.top + collidingItem.height + margin.item.vertical;
|
7609 | }
|
7610 | } while (collidingItem);
|
7611 | }
|
7612 | }
|
7613 | };
|
7614 |
|
7615 | |
7616 |
|
7617 |
|
7618 |
|
7619 |
|
7620 |
|
7621 |
|
7622 | exports.nostack = function(items, margin) {
|
7623 | var i, iMax;
|
7624 |
|
7625 |
|
7626 | for (i = 0, iMax = items.length; i < iMax; i++) {
|
7627 | items[i].top = margin.axis;
|
7628 | }
|
7629 | };
|
7630 |
|
7631 | |
7632 |
|
7633 |
|
7634 |
|
7635 |
|
7636 |
|
7637 |
|
7638 |
|
7639 |
|
7640 |
|
7641 | exports.collision = function(a, b, margin) {
|
7642 | return ((a.left - margin.horizontal + EPSILON) < (b.left + b.width) &&
|
7643 | (a.left + a.width + margin.horizontal - EPSILON) > b.left &&
|
7644 | (a.top - margin.vertical + EPSILON) < (b.top + b.height) &&
|
7645 | (a.top + a.height + margin.vertical - EPSILON) > b.top);
|
7646 | };
|
7647 |
|
7648 |
|
7649 | },
|
7650 |
|
7651 | function(module, exports, __webpack_require__) {
|
7652 |
|
7653 | var moment = __webpack_require__(41);
|
7654 |
|
7655 | |
7656 |
|
7657 |
|
7658 |
|
7659 |
|
7660 |
|
7661 |
|
7662 |
|
7663 |
|
7664 |
|
7665 |
|
7666 |
|
7667 |
|
7668 |
|
7669 |
|
7670 |
|
7671 |
|
7672 |
|
7673 |
|
7674 |
|
7675 |
|
7676 |
|
7677 |
|
7678 |
|
7679 |
|
7680 |
|
7681 | function TimeStep(start, end, minimumStep) {
|
7682 |
|
7683 | this.current = new Date();
|
7684 | this._start = new Date();
|
7685 | this._end = new Date();
|
7686 |
|
7687 | this.autoScale = true;
|
7688 | this.scale = TimeStep.SCALE.DAY;
|
7689 | this.step = 1;
|
7690 |
|
7691 |
|
7692 | this.setRange(start, end, minimumStep);
|
7693 | }
|
7694 |
|
7695 |
|
7696 | TimeStep.SCALE = {
|
7697 | MILLISECOND: 1,
|
7698 | SECOND: 2,
|
7699 | MINUTE: 3,
|
7700 | HOUR: 4,
|
7701 | DAY: 5,
|
7702 | WEEKDAY: 6,
|
7703 | MONTH: 7,
|
7704 | YEAR: 8
|
7705 | };
|
7706 |
|
7707 |
|
7708 | |
7709 |
|
7710 |
|
7711 |
|
7712 |
|
7713 |
|
7714 |
|
7715 |
|
7716 |
|
7717 |
|
7718 | TimeStep.prototype.setRange = function(start, end, minimumStep) {
|
7719 | if (!(start instanceof Date) || !(end instanceof Date)) {
|
7720 | throw "No legal start or end date in method setRange";
|
7721 | }
|
7722 |
|
7723 | this._start = (start != undefined) ? new Date(start.valueOf()) : new Date();
|
7724 | this._end = (end != undefined) ? new Date(end.valueOf()) : new Date();
|
7725 |
|
7726 | if (this.autoScale) {
|
7727 | this.setMinimumStep(minimumStep);
|
7728 | }
|
7729 | };
|
7730 |
|
7731 | |
7732 |
|
7733 |
|
7734 | TimeStep.prototype.first = function() {
|
7735 | this.current = new Date(this._start.valueOf());
|
7736 | this.roundToMinor();
|
7737 | };
|
7738 |
|
7739 | |
7740 |
|
7741 |
|
7742 |
|
7743 | TimeStep.prototype.roundToMinor = function() {
|
7744 |
|
7745 |
|
7746 |
|
7747 | switch (this.scale) {
|
7748 | case TimeStep.SCALE.YEAR:
|
7749 | this.current.setFullYear(this.step * Math.floor(this.current.getFullYear() / this.step));
|
7750 | this.current.setMonth(0);
|
7751 | case TimeStep.SCALE.MONTH: this.current.setDate(1);
|
7752 | case TimeStep.SCALE.DAY:
|
7753 | case TimeStep.SCALE.WEEKDAY: this.current.setHours(0);
|
7754 | case TimeStep.SCALE.HOUR: this.current.setMinutes(0);
|
7755 | case TimeStep.SCALE.MINUTE: this.current.setSeconds(0);
|
7756 | case TimeStep.SCALE.SECOND: this.current.setMilliseconds(0);
|
7757 |
|
7758 | }
|
7759 |
|
7760 | if (this.step != 1) {
|
7761 |
|
7762 | switch (this.scale) {
|
7763 | case TimeStep.SCALE.MILLISECOND: this.current.setMilliseconds(this.current.getMilliseconds() - this.current.getMilliseconds() % this.step); break;
|
7764 | case TimeStep.SCALE.SECOND: this.current.setSeconds(this.current.getSeconds() - this.current.getSeconds() % this.step); break;
|
7765 | case TimeStep.SCALE.MINUTE: this.current.setMinutes(this.current.getMinutes() - this.current.getMinutes() % this.step); break;
|
7766 | case TimeStep.SCALE.HOUR: this.current.setHours(this.current.getHours() - this.current.getHours() % this.step); break;
|
7767 | case TimeStep.SCALE.WEEKDAY:
|
7768 | case TimeStep.SCALE.DAY: this.current.setDate((this.current.getDate()-1) - (this.current.getDate()-1) % this.step + 1); break;
|
7769 | case TimeStep.SCALE.MONTH: this.current.setMonth(this.current.getMonth() - this.current.getMonth() % this.step); break;
|
7770 | case TimeStep.SCALE.YEAR: this.current.setFullYear(this.current.getFullYear() - this.current.getFullYear() % this.step); break;
|
7771 | default: break;
|
7772 | }
|
7773 | }
|
7774 | };
|
7775 |
|
7776 | |
7777 |
|
7778 |
|
7779 |
|
7780 | TimeStep.prototype.hasNext = function () {
|
7781 | return (this.current.valueOf() <= this._end.valueOf());
|
7782 | };
|
7783 |
|
7784 | |
7785 |
|
7786 |
|
7787 | TimeStep.prototype.next = function() {
|
7788 | var prev = this.current.valueOf();
|
7789 |
|
7790 |
|
7791 |
|
7792 | if (this.current.getMonth() < 6) {
|
7793 | switch (this.scale) {
|
7794 | case TimeStep.SCALE.MILLISECOND:
|
7795 |
|
7796 | this.current = new Date(this.current.valueOf() + this.step); break;
|
7797 | case TimeStep.SCALE.SECOND: this.current = new Date(this.current.valueOf() + this.step * 1000); break;
|
7798 | case TimeStep.SCALE.MINUTE: this.current = new Date(this.current.valueOf() + this.step * 1000 * 60); break;
|
7799 | case TimeStep.SCALE.HOUR:
|
7800 | this.current = new Date(this.current.valueOf() + this.step * 1000 * 60 * 60);
|
7801 |
|
7802 | var h = this.current.getHours();
|
7803 | this.current.setHours(h - (h % this.step));
|
7804 | break;
|
7805 | case TimeStep.SCALE.WEEKDAY:
|
7806 | case TimeStep.SCALE.DAY: this.current.setDate(this.current.getDate() + this.step); break;
|
7807 | case TimeStep.SCALE.MONTH: this.current.setMonth(this.current.getMonth() + this.step); break;
|
7808 | case TimeStep.SCALE.YEAR: this.current.setFullYear(this.current.getFullYear() + this.step); break;
|
7809 | default: break;
|
7810 | }
|
7811 | }
|
7812 | else {
|
7813 | switch (this.scale) {
|
7814 | case TimeStep.SCALE.MILLISECOND: this.current = new Date(this.current.valueOf() + this.step); break;
|
7815 | case TimeStep.SCALE.SECOND: this.current.setSeconds(this.current.getSeconds() + this.step); break;
|
7816 | case TimeStep.SCALE.MINUTE: this.current.setMinutes(this.current.getMinutes() + this.step); break;
|
7817 | case TimeStep.SCALE.HOUR: this.current.setHours(this.current.getHours() + this.step); break;
|
7818 | case TimeStep.SCALE.WEEKDAY:
|
7819 | case TimeStep.SCALE.DAY: this.current.setDate(this.current.getDate() + this.step); break;
|
7820 | case TimeStep.SCALE.MONTH: this.current.setMonth(this.current.getMonth() + this.step); break;
|
7821 | case TimeStep.SCALE.YEAR: this.current.setFullYear(this.current.getFullYear() + this.step); break;
|
7822 | default: break;
|
7823 | }
|
7824 | }
|
7825 |
|
7826 | if (this.step != 1) {
|
7827 |
|
7828 | switch (this.scale) {
|
7829 | case TimeStep.SCALE.MILLISECOND: if(this.current.getMilliseconds() < this.step) this.current.setMilliseconds(0); break;
|
7830 | case TimeStep.SCALE.SECOND: if(this.current.getSeconds() < this.step) this.current.setSeconds(0); break;
|
7831 | case TimeStep.SCALE.MINUTE: if(this.current.getMinutes() < this.step) this.current.setMinutes(0); break;
|
7832 | case TimeStep.SCALE.HOUR: if(this.current.getHours() < this.step) this.current.setHours(0); break;
|
7833 | case TimeStep.SCALE.WEEKDAY:
|
7834 | case TimeStep.SCALE.DAY: if(this.current.getDate() < this.step+1) this.current.setDate(1); break;
|
7835 | case TimeStep.SCALE.MONTH: if(this.current.getMonth() < this.step) this.current.setMonth(0); break;
|
7836 | case TimeStep.SCALE.YEAR: break;
|
7837 | default: break;
|
7838 | }
|
7839 | }
|
7840 |
|
7841 |
|
7842 | if (this.current.valueOf() == prev) {
|
7843 | this.current = new Date(this._end.valueOf());
|
7844 | }
|
7845 | };
|
7846 |
|
7847 |
|
7848 | |
7849 |
|
7850 |
|
7851 |
|
7852 | TimeStep.prototype.getCurrent = function() {
|
7853 | return this.current;
|
7854 | };
|
7855 |
|
7856 | |
7857 |
|
7858 |
|
7859 |
|
7860 |
|
7861 |
|
7862 |
|
7863 |
|
7864 |
|
7865 |
|
7866 |
|
7867 |
|
7868 |
|
7869 | TimeStep.prototype.setScale = function(newScale, newStep) {
|
7870 | this.scale = newScale;
|
7871 |
|
7872 | if (newStep > 0) {
|
7873 | this.step = newStep;
|
7874 | }
|
7875 |
|
7876 | this.autoScale = false;
|
7877 | };
|
7878 |
|
7879 | |
7880 |
|
7881 |
|
7882 |
|
7883 | TimeStep.prototype.setAutoScale = function (enable) {
|
7884 | this.autoScale = enable;
|
7885 | };
|
7886 |
|
7887 |
|
7888 | |
7889 |
|
7890 |
|
7891 |
|
7892 | TimeStep.prototype.setMinimumStep = function(minimumStep) {
|
7893 | if (minimumStep == undefined) {
|
7894 | return;
|
7895 | }
|
7896 |
|
7897 | var stepYear = (1000 * 60 * 60 * 24 * 30 * 12);
|
7898 | var stepMonth = (1000 * 60 * 60 * 24 * 30);
|
7899 | var stepDay = (1000 * 60 * 60 * 24);
|
7900 | var stepHour = (1000 * 60 * 60);
|
7901 | var stepMinute = (1000 * 60);
|
7902 | var stepSecond = (1000);
|
7903 | var stepMillisecond= (1);
|
7904 |
|
7905 |
|
7906 | if (stepYear*1000 > minimumStep) {this.scale = TimeStep.SCALE.YEAR; this.step = 1000;}
|
7907 | if (stepYear*500 > minimumStep) {this.scale = TimeStep.SCALE.YEAR; this.step = 500;}
|
7908 | if (stepYear*100 > minimumStep) {this.scale = TimeStep.SCALE.YEAR; this.step = 100;}
|
7909 | if (stepYear*50 > minimumStep) {this.scale = TimeStep.SCALE.YEAR; this.step = 50;}
|
7910 | if (stepYear*10 > minimumStep) {this.scale = TimeStep.SCALE.YEAR; this.step = 10;}
|
7911 | if (stepYear*5 > minimumStep) {this.scale = TimeStep.SCALE.YEAR; this.step = 5;}
|
7912 | if (stepYear > minimumStep) {this.scale = TimeStep.SCALE.YEAR; this.step = 1;}
|
7913 | if (stepMonth*3 > minimumStep) {this.scale = TimeStep.SCALE.MONTH; this.step = 3;}
|
7914 | if (stepMonth > minimumStep) {this.scale = TimeStep.SCALE.MONTH; this.step = 1;}
|
7915 | if (stepDay*5 > minimumStep) {this.scale = TimeStep.SCALE.DAY; this.step = 5;}
|
7916 | if (stepDay*2 > minimumStep) {this.scale = TimeStep.SCALE.DAY; this.step = 2;}
|
7917 | if (stepDay > minimumStep) {this.scale = TimeStep.SCALE.DAY; this.step = 1;}
|
7918 | if (stepDay/2 > minimumStep) {this.scale = TimeStep.SCALE.WEEKDAY; this.step = 1;}
|
7919 | if (stepHour*4 > minimumStep) {this.scale = TimeStep.SCALE.HOUR; this.step = 4;}
|
7920 | if (stepHour > minimumStep) {this.scale = TimeStep.SCALE.HOUR; this.step = 1;}
|
7921 | if (stepMinute*15 > minimumStep) {this.scale = TimeStep.SCALE.MINUTE; this.step = 15;}
|
7922 | if (stepMinute*10 > minimumStep) {this.scale = TimeStep.SCALE.MINUTE; this.step = 10;}
|
7923 | if (stepMinute*5 > minimumStep) {this.scale = TimeStep.SCALE.MINUTE; this.step = 5;}
|
7924 | if (stepMinute > minimumStep) {this.scale = TimeStep.SCALE.MINUTE; this.step = 1;}
|
7925 | if (stepSecond*15 > minimumStep) {this.scale = TimeStep.SCALE.SECOND; this.step = 15;}
|
7926 | if (stepSecond*10 > minimumStep) {this.scale = TimeStep.SCALE.SECOND; this.step = 10;}
|
7927 | if (stepSecond*5 > minimumStep) {this.scale = TimeStep.SCALE.SECOND; this.step = 5;}
|
7928 | if (stepSecond > minimumStep) {this.scale = TimeStep.SCALE.SECOND; this.step = 1;}
|
7929 | if (stepMillisecond*200 > minimumStep) {this.scale = TimeStep.SCALE.MILLISECOND; this.step = 200;}
|
7930 | if (stepMillisecond*100 > minimumStep) {this.scale = TimeStep.SCALE.MILLISECOND; this.step = 100;}
|
7931 | if (stepMillisecond*50 > minimumStep) {this.scale = TimeStep.SCALE.MILLISECOND; this.step = 50;}
|
7932 | if (stepMillisecond*10 > minimumStep) {this.scale = TimeStep.SCALE.MILLISECOND; this.step = 10;}
|
7933 | if (stepMillisecond*5 > minimumStep) {this.scale = TimeStep.SCALE.MILLISECOND; this.step = 5;}
|
7934 | if (stepMillisecond > minimumStep) {this.scale = TimeStep.SCALE.MILLISECOND; this.step = 1;}
|
7935 | };
|
7936 |
|
7937 | |
7938 |
|
7939 |
|
7940 |
|
7941 |
|
7942 |
|
7943 | TimeStep.prototype.snap = function(date) {
|
7944 | var clone = new Date(date.valueOf());
|
7945 |
|
7946 | if (this.scale == TimeStep.SCALE.YEAR) {
|
7947 | var year = clone.getFullYear() + Math.round(clone.getMonth() / 12);
|
7948 | clone.setFullYear(Math.round(year / this.step) * this.step);
|
7949 | clone.setMonth(0);
|
7950 | clone.setDate(0);
|
7951 | clone.setHours(0);
|
7952 | clone.setMinutes(0);
|
7953 | clone.setSeconds(0);
|
7954 | clone.setMilliseconds(0);
|
7955 | }
|
7956 | else if (this.scale == TimeStep.SCALE.MONTH) {
|
7957 | if (clone.getDate() > 15) {
|
7958 | clone.setDate(1);
|
7959 | clone.setMonth(clone.getMonth() + 1);
|
7960 |
|
7961 | }
|
7962 | else {
|
7963 | clone.setDate(1);
|
7964 | }
|
7965 |
|
7966 | clone.setHours(0);
|
7967 | clone.setMinutes(0);
|
7968 | clone.setSeconds(0);
|
7969 | clone.setMilliseconds(0);
|
7970 | }
|
7971 | else if (this.scale == TimeStep.SCALE.DAY) {
|
7972 |
|
7973 | switch (this.step) {
|
7974 | case 5:
|
7975 | case 2:
|
7976 | clone.setHours(Math.round(clone.getHours() / 24) * 24); break;
|
7977 | default:
|
7978 | clone.setHours(Math.round(clone.getHours() / 12) * 12); break;
|
7979 | }
|
7980 | clone.setMinutes(0);
|
7981 | clone.setSeconds(0);
|
7982 | clone.setMilliseconds(0);
|
7983 | }
|
7984 | else if (this.scale == TimeStep.SCALE.WEEKDAY) {
|
7985 |
|
7986 | switch (this.step) {
|
7987 | case 5:
|
7988 | case 2:
|
7989 | clone.setHours(Math.round(clone.getHours() / 12) * 12); break;
|
7990 | default:
|
7991 | clone.setHours(Math.round(clone.getHours() / 6) * 6); break;
|
7992 | }
|
7993 | clone.setMinutes(0);
|
7994 | clone.setSeconds(0);
|
7995 | clone.setMilliseconds(0);
|
7996 | }
|
7997 | else if (this.scale == TimeStep.SCALE.HOUR) {
|
7998 | switch (this.step) {
|
7999 | case 4:
|
8000 | clone.setMinutes(Math.round(clone.getMinutes() / 60) * 60); break;
|
8001 | default:
|
8002 | clone.setMinutes(Math.round(clone.getMinutes() / 30) * 30); break;
|
8003 | }
|
8004 | clone.setSeconds(0);
|
8005 | clone.setMilliseconds(0);
|
8006 | } else if (this.scale == TimeStep.SCALE.MINUTE) {
|
8007 |
|
8008 | switch (this.step) {
|
8009 | case 15:
|
8010 | case 10:
|
8011 | clone.setMinutes(Math.round(clone.getMinutes() / 5) * 5);
|
8012 | clone.setSeconds(0);
|
8013 | break;
|
8014 | case 5:
|
8015 | clone.setSeconds(Math.round(clone.getSeconds() / 60) * 60); break;
|
8016 | default:
|
8017 | clone.setSeconds(Math.round(clone.getSeconds() / 30) * 30); break;
|
8018 | }
|
8019 | clone.setMilliseconds(0);
|
8020 | }
|
8021 | else if (this.scale == TimeStep.SCALE.SECOND) {
|
8022 |
|
8023 | switch (this.step) {
|
8024 | case 15:
|
8025 | case 10:
|
8026 | clone.setSeconds(Math.round(clone.getSeconds() / 5) * 5);
|
8027 | clone.setMilliseconds(0);
|
8028 | break;
|
8029 | case 5:
|
8030 | clone.setMilliseconds(Math.round(clone.getMilliseconds() / 1000) * 1000); break;
|
8031 | default:
|
8032 | clone.setMilliseconds(Math.round(clone.getMilliseconds() / 500) * 500); break;
|
8033 | }
|
8034 | }
|
8035 | else if (this.scale == TimeStep.SCALE.MILLISECOND) {
|
8036 | var step = this.step > 5 ? this.step / 2 : 1;
|
8037 | clone.setMilliseconds(Math.round(clone.getMilliseconds() / step) * step);
|
8038 | }
|
8039 |
|
8040 | return clone;
|
8041 | };
|
8042 |
|
8043 | |
8044 |
|
8045 |
|
8046 |
|
8047 |
|
8048 | TimeStep.prototype.isMajor = function() {
|
8049 | switch (this.scale) {
|
8050 | case TimeStep.SCALE.MILLISECOND:
|
8051 | return (this.current.getMilliseconds() == 0);
|
8052 | case TimeStep.SCALE.SECOND:
|
8053 | return (this.current.getSeconds() == 0);
|
8054 | case TimeStep.SCALE.MINUTE:
|
8055 | return (this.current.getHours() == 0) && (this.current.getMinutes() == 0);
|
8056 |
|
8057 | case TimeStep.SCALE.HOUR:
|
8058 | return (this.current.getHours() == 0);
|
8059 | case TimeStep.SCALE.WEEKDAY:
|
8060 | case TimeStep.SCALE.DAY:
|
8061 | return (this.current.getDate() == 1);
|
8062 | case TimeStep.SCALE.MONTH:
|
8063 | return (this.current.getMonth() == 0);
|
8064 | case TimeStep.SCALE.YEAR:
|
8065 | return false;
|
8066 | default:
|
8067 | return false;
|
8068 | }
|
8069 | };
|
8070 |
|
8071 |
|
8072 | |
8073 |
|
8074 |
|
8075 |
|
8076 |
|
8077 |
|
8078 | TimeStep.prototype.getLabelMinor = function(date) {
|
8079 | if (date == undefined) {
|
8080 | date = this.current;
|
8081 | }
|
8082 |
|
8083 | switch (this.scale) {
|
8084 | case TimeStep.SCALE.MILLISECOND: return moment(date).format('SSS');
|
8085 | case TimeStep.SCALE.SECOND: return moment(date).format('s');
|
8086 | case TimeStep.SCALE.MINUTE: return moment(date).format('HH:mm');
|
8087 | case TimeStep.SCALE.HOUR: return moment(date).format('HH:mm');
|
8088 | case TimeStep.SCALE.WEEKDAY: return moment(date).format('ddd D');
|
8089 | case TimeStep.SCALE.DAY: return moment(date).format('D');
|
8090 | case TimeStep.SCALE.MONTH: return moment(date).format('MMM');
|
8091 | case TimeStep.SCALE.YEAR: return moment(date).format('YYYY');
|
8092 | default: return '';
|
8093 | }
|
8094 | };
|
8095 |
|
8096 |
|
8097 | |
8098 |
|
8099 |
|
8100 |
|
8101 |
|
8102 |
|
8103 | TimeStep.prototype.getLabelMajor = function(date) {
|
8104 | if (date == undefined) {
|
8105 | date = this.current;
|
8106 | }
|
8107 |
|
8108 |
|
8109 | switch (this.scale) {
|
8110 | case TimeStep.SCALE.MILLISECOND:return moment(date).format('HH:mm:ss');
|
8111 | case TimeStep.SCALE.SECOND: return moment(date).format('D MMMM HH:mm');
|
8112 | case TimeStep.SCALE.MINUTE:
|
8113 | case TimeStep.SCALE.HOUR: return moment(date).format('ddd D MMMM');
|
8114 | case TimeStep.SCALE.WEEKDAY:
|
8115 | case TimeStep.SCALE.DAY: return moment(date).format('MMMM YYYY');
|
8116 | case TimeStep.SCALE.MONTH: return moment(date).format('YYYY');
|
8117 | case TimeStep.SCALE.YEAR: return '';
|
8118 | default: return '';
|
8119 | }
|
8120 | };
|
8121 |
|
8122 | module.exports = TimeStep;
|
8123 |
|
8124 |
|
8125 | },
|
8126 |
|
8127 | function(module, exports, __webpack_require__) {
|
8128 |
|
8129 | |
8130 |
|
8131 |
|
8132 |
|
8133 |
|
8134 | function Component (body, options) {
|
8135 | this.options = null;
|
8136 | this.props = null;
|
8137 | }
|
8138 |
|
8139 | |
8140 |
|
8141 |
|
8142 |
|
8143 |
|
8144 | Component.prototype.setOptions = function(options) {
|
8145 | if (options) {
|
8146 | util.extend(this.options, options);
|
8147 | }
|
8148 | };
|
8149 |
|
8150 | |
8151 |
|
8152 |
|
8153 |
|
8154 | Component.prototype.redraw = function() {
|
8155 |
|
8156 | return false;
|
8157 | };
|
8158 |
|
8159 | |
8160 |
|
8161 |
|
8162 | Component.prototype.destroy = function() {
|
8163 |
|
8164 | };
|
8165 |
|
8166 | |
8167 |
|
8168 |
|
8169 |
|
8170 |
|
8171 |
|
8172 | Component.prototype._isResized = function() {
|
8173 | var resized = (this.props._previousWidth !== this.props.width ||
|
8174 | this.props._previousHeight !== this.props.height);
|
8175 |
|
8176 | this.props._previousWidth = this.props.width;
|
8177 | this.props._previousHeight = this.props.height;
|
8178 |
|
8179 | return resized;
|
8180 | };
|
8181 |
|
8182 | module.exports = Component;
|
8183 |
|
8184 |
|
8185 | },
|
8186 |
|
8187 | function(module, exports, __webpack_require__) {
|
8188 |
|
8189 | var util = __webpack_require__(1);
|
8190 | var Component = __webpack_require__(18);
|
8191 | var moment = __webpack_require__(41);
|
8192 | var locales = __webpack_require__(45);
|
8193 |
|
8194 | |
8195 |
|
8196 |
|
8197 |
|
8198 |
|
8199 |
|
8200 |
|
8201 |
|
8202 | function CurrentTime (body, options) {
|
8203 | this.body = body;
|
8204 |
|
8205 |
|
8206 | this.defaultOptions = {
|
8207 | showCurrentTime: true,
|
8208 |
|
8209 | locales: locales,
|
8210 | locale: 'en'
|
8211 | };
|
8212 | this.options = util.extend({}, this.defaultOptions);
|
8213 | this.offset = 0;
|
8214 |
|
8215 | this._create();
|
8216 |
|
8217 | this.setOptions(options);
|
8218 | }
|
8219 |
|
8220 | CurrentTime.prototype = new Component();
|
8221 |
|
8222 | |
8223 |
|
8224 |
|
8225 |
|
8226 | CurrentTime.prototype._create = function() {
|
8227 | var bar = document.createElement('div');
|
8228 | bar.className = 'currenttime';
|
8229 | bar.style.position = 'absolute';
|
8230 | bar.style.top = '0px';
|
8231 | bar.style.height = '100%';
|
8232 |
|
8233 | this.bar = bar;
|
8234 | };
|
8235 |
|
8236 | |
8237 |
|
8238 |
|
8239 | CurrentTime.prototype.destroy = function () {
|
8240 | this.options.showCurrentTime = false;
|
8241 | this.redraw();
|
8242 |
|
8243 | this.body = null;
|
8244 | };
|
8245 |
|
8246 | |
8247 |
|
8248 |
|
8249 |
|
8250 |
|
8251 | CurrentTime.prototype.setOptions = function(options) {
|
8252 | if (options) {
|
8253 |
|
8254 | util.selectiveExtend(['showCurrentTime', 'locale', 'locales'], this.options, options);
|
8255 | }
|
8256 | };
|
8257 |
|
8258 | |
8259 |
|
8260 |
|
8261 |
|
8262 | CurrentTime.prototype.redraw = function() {
|
8263 | if (this.options.showCurrentTime) {
|
8264 | var parent = this.body.dom.backgroundVertical;
|
8265 | if (this.bar.parentNode != parent) {
|
8266 |
|
8267 | if (this.bar.parentNode) {
|
8268 | this.bar.parentNode.removeChild(this.bar);
|
8269 | }
|
8270 | parent.appendChild(this.bar);
|
8271 |
|
8272 | this.start();
|
8273 | }
|
8274 |
|
8275 | var now = new Date(new Date().valueOf() + this.offset);
|
8276 | var x = this.body.util.toScreen(now);
|
8277 |
|
8278 | var locale = this.options.locales[this.options.locale];
|
8279 | var title = locale.current + ' ' + locale.time + ': ' + moment(now).format('dddd, MMMM Do YYYY, H:mm:ss');
|
8280 | title = title.charAt(0).toUpperCase() + title.substring(1);
|
8281 |
|
8282 | this.bar.style.left = x + 'px';
|
8283 | this.bar.title = title;
|
8284 | }
|
8285 | else {
|
8286 |
|
8287 | if (this.bar.parentNode) {
|
8288 | this.bar.parentNode.removeChild(this.bar);
|
8289 | }
|
8290 | this.stop();
|
8291 | }
|
8292 |
|
8293 | return false;
|
8294 | };
|
8295 |
|
8296 | |
8297 |
|
8298 |
|
8299 | CurrentTime.prototype.start = function() {
|
8300 | var me = this;
|
8301 |
|
8302 | function update () {
|
8303 | me.stop();
|
8304 |
|
8305 |
|
8306 | var scale = me.body.range.conversion(me.body.domProps.center.width).scale;
|
8307 | var interval = 1 / scale / 10;
|
8308 | if (interval < 30) interval = 30;
|
8309 | if (interval > 1000) interval = 1000;
|
8310 |
|
8311 | me.redraw();
|
8312 |
|
8313 |
|
8314 | me.currentTimeTimer = setTimeout(update, interval);
|
8315 | }
|
8316 |
|
8317 | update();
|
8318 | };
|
8319 |
|
8320 | |
8321 |
|
8322 |
|
8323 | CurrentTime.prototype.stop = function() {
|
8324 | if (this.currentTimeTimer !== undefined) {
|
8325 | clearTimeout(this.currentTimeTimer);
|
8326 | delete this.currentTimeTimer;
|
8327 | }
|
8328 | };
|
8329 |
|
8330 | |
8331 |
|
8332 |
|
8333 |
|
8334 |
|
8335 |
|
8336 | CurrentTime.prototype.setCurrentTime = function(time) {
|
8337 | var t = util.convert(time, 'Date').valueOf();
|
8338 | var now = new Date().valueOf();
|
8339 | this.offset = t - now;
|
8340 | this.redraw();
|
8341 | };
|
8342 |
|
8343 | |
8344 |
|
8345 |
|
8346 |
|
8347 | CurrentTime.prototype.getCurrentTime = function() {
|
8348 | return new Date(new Date().valueOf() + this.offset);
|
8349 | };
|
8350 |
|
8351 | module.exports = CurrentTime;
|
8352 |
|
8353 |
|
8354 | },
|
8355 |
|
8356 | function(module, exports, __webpack_require__) {
|
8357 |
|
8358 | var Hammer = __webpack_require__(42);
|
8359 | var util = __webpack_require__(1);
|
8360 | var Component = __webpack_require__(18);
|
8361 | var moment = __webpack_require__(41);
|
8362 | var locales = __webpack_require__(45);
|
8363 |
|
8364 | |
8365 |
|
8366 |
|
8367 |
|
8368 |
|
8369 |
|
8370 |
|
8371 |
|
8372 |
|
8373 | function CustomTime (body, options) {
|
8374 | this.body = body;
|
8375 |
|
8376 |
|
8377 | this.defaultOptions = {
|
8378 | showCustomTime: false,
|
8379 | locales: locales,
|
8380 | locale: 'en'
|
8381 | };
|
8382 | this.options = util.extend({}, this.defaultOptions);
|
8383 |
|
8384 | this.customTime = new Date();
|
8385 | this.eventParams = {};
|
8386 |
|
8387 |
|
8388 | this._create();
|
8389 |
|
8390 | this.setOptions(options);
|
8391 | }
|
8392 |
|
8393 | CustomTime.prototype = new Component();
|
8394 |
|
8395 | |
8396 |
|
8397 |
|
8398 |
|
8399 |
|
8400 | CustomTime.prototype.setOptions = function(options) {
|
8401 | if (options) {
|
8402 |
|
8403 | util.selectiveExtend(['showCustomTime', 'locale', 'locales'], this.options, options);
|
8404 | }
|
8405 | };
|
8406 |
|
8407 | |
8408 |
|
8409 |
|
8410 |
|
8411 | CustomTime.prototype._create = function() {
|
8412 | var bar = document.createElement('div');
|
8413 | bar.className = 'customtime';
|
8414 | bar.style.position = 'absolute';
|
8415 | bar.style.top = '0px';
|
8416 | bar.style.height = '100%';
|
8417 | this.bar = bar;
|
8418 |
|
8419 | var drag = document.createElement('div');
|
8420 | drag.style.position = 'relative';
|
8421 | drag.style.top = '0px';
|
8422 | drag.style.left = '-10px';
|
8423 | drag.style.height = '100%';
|
8424 | drag.style.width = '20px';
|
8425 | bar.appendChild(drag);
|
8426 |
|
8427 |
|
8428 | this.hammer = Hammer(bar, {
|
8429 | prevent_default: true
|
8430 | });
|
8431 | this.hammer.on('dragstart', this._onDragStart.bind(this));
|
8432 | this.hammer.on('drag', this._onDrag.bind(this));
|
8433 | this.hammer.on('dragend', this._onDragEnd.bind(this));
|
8434 | };
|
8435 |
|
8436 | |
8437 |
|
8438 |
|
8439 | CustomTime.prototype.destroy = function () {
|
8440 | this.options.showCustomTime = false;
|
8441 | this.redraw();
|
8442 |
|
8443 | this.hammer.enable(false);
|
8444 | this.hammer = null;
|
8445 |
|
8446 | this.body = null;
|
8447 | };
|
8448 |
|
8449 | |
8450 |
|
8451 |
|
8452 |
|
8453 | CustomTime.prototype.redraw = function () {
|
8454 | if (this.options.showCustomTime) {
|
8455 | var parent = this.body.dom.backgroundVertical;
|
8456 | if (this.bar.parentNode != parent) {
|
8457 |
|
8458 | if (this.bar.parentNode) {
|
8459 | this.bar.parentNode.removeChild(this.bar);
|
8460 | }
|
8461 | parent.appendChild(this.bar);
|
8462 | }
|
8463 |
|
8464 | var x = this.body.util.toScreen(this.customTime);
|
8465 |
|
8466 | var locale = this.options.locales[this.options.locale];
|
8467 | var title = locale.time + ': ' + moment(this.customTime).format('dddd, MMMM Do YYYY, H:mm:ss');
|
8468 | title = title.charAt(0).toUpperCase() + title.substring(1);
|
8469 |
|
8470 | this.bar.style.left = x + 'px';
|
8471 | this.bar.title = title;
|
8472 | }
|
8473 | else {
|
8474 |
|
8475 | if (this.bar.parentNode) {
|
8476 | this.bar.parentNode.removeChild(this.bar);
|
8477 | }
|
8478 | }
|
8479 |
|
8480 | return false;
|
8481 | };
|
8482 |
|
8483 | |
8484 |
|
8485 |
|
8486 |
|
8487 | CustomTime.prototype.setCustomTime = function(time) {
|
8488 | this.customTime = util.convert(time, 'Date');
|
8489 | this.redraw();
|
8490 | };
|
8491 |
|
8492 | |
8493 |
|
8494 |
|
8495 |
|
8496 | CustomTime.prototype.getCustomTime = function() {
|
8497 | return new Date(this.customTime.valueOf());
|
8498 | };
|
8499 |
|
8500 | |
8501 |
|
8502 |
|
8503 |
|
8504 |
|
8505 | CustomTime.prototype._onDragStart = function(event) {
|
8506 | this.eventParams.dragging = true;
|
8507 | this.eventParams.customTime = this.customTime;
|
8508 |
|
8509 | event.stopPropagation();
|
8510 | event.preventDefault();
|
8511 | };
|
8512 |
|
8513 | |
8514 |
|
8515 |
|
8516 |
|
8517 |
|
8518 | CustomTime.prototype._onDrag = function (event) {
|
8519 | if (!this.eventParams.dragging) return;
|
8520 |
|
8521 | var deltaX = event.gesture.deltaX,
|
8522 | x = this.body.util.toScreen(this.eventParams.customTime) + deltaX,
|
8523 | time = this.body.util.toTime(x);
|
8524 |
|
8525 | this.setCustomTime(time);
|
8526 |
|
8527 |
|
8528 | this.body.emitter.emit('timechange', {
|
8529 | time: new Date(this.customTime.valueOf())
|
8530 | });
|
8531 |
|
8532 | event.stopPropagation();
|
8533 | event.preventDefault();
|
8534 | };
|
8535 |
|
8536 | |
8537 |
|
8538 |
|
8539 |
|
8540 |
|
8541 | CustomTime.prototype._onDragEnd = function (event) {
|
8542 | if (!this.eventParams.dragging) return;
|
8543 |
|
8544 |
|
8545 | this.body.emitter.emit('timechanged', {
|
8546 | time: new Date(this.customTime.valueOf())
|
8547 | });
|
8548 |
|
8549 | event.stopPropagation();
|
8550 | event.preventDefault();
|
8551 | };
|
8552 |
|
8553 | module.exports = CustomTime;
|
8554 |
|
8555 |
|
8556 | },
|
8557 |
|
8558 | function(module, exports, __webpack_require__) {
|
8559 |
|
8560 | var util = __webpack_require__(1);
|
8561 | var DOMutil = __webpack_require__(2);
|
8562 | var Component = __webpack_require__(18);
|
8563 | var DataStep = __webpack_require__(14);
|
8564 |
|
8565 | |
8566 |
|
8567 |
|
8568 |
|
8569 |
|
8570 |
|
8571 |
|
8572 |
|
8573 | function DataAxis (body, options, svg, linegraphOptions) {
|
8574 | this.id = util.randomUUID();
|
8575 | this.body = body;
|
8576 |
|
8577 | this.defaultOptions = {
|
8578 | orientation: 'left',
|
8579 | showMinorLabels: true,
|
8580 | showMajorLabels: true,
|
8581 | icons: true,
|
8582 | majorLinesOffset: 7,
|
8583 | minorLinesOffset: 4,
|
8584 | labelOffsetX: 10,
|
8585 | labelOffsetY: 2,
|
8586 | iconWidth: 20,
|
8587 | width: '40px',
|
8588 | visible: true,
|
8589 | customRange: {
|
8590 | left: {min:undefined, max:undefined},
|
8591 | right: {min:undefined, max:undefined}
|
8592 | }
|
8593 | };
|
8594 |
|
8595 | this.linegraphOptions = linegraphOptions;
|
8596 | this.linegraphSVG = svg;
|
8597 | this.props = {};
|
8598 | this.DOMelements = {
|
8599 | lines: {},
|
8600 | labels: {}
|
8601 | };
|
8602 |
|
8603 | this.dom = {};
|
8604 |
|
8605 | this.range = {start:0, end:0};
|
8606 |
|
8607 | this.options = util.extend({}, this.defaultOptions);
|
8608 | this.conversionFactor = 1;
|
8609 |
|
8610 | this.setOptions(options);
|
8611 | this.width = Number(('' + this.options.width).replace("px",""));
|
8612 | this.minWidth = this.width;
|
8613 | this.height = this.linegraphSVG.offsetHeight;
|
8614 |
|
8615 | this.stepPixels = 25;
|
8616 | this.stepPixelsForced = 25;
|
8617 | this.lineOffset = 0;
|
8618 | this.master = true;
|
8619 | this.svgElements = {};
|
8620 |
|
8621 |
|
8622 | this.groups = {};
|
8623 | this.amountOfGroups = 0;
|
8624 |
|
8625 |
|
8626 | this._create();
|
8627 | }
|
8628 |
|
8629 | DataAxis.prototype = new Component();
|
8630 |
|
8631 |
|
8632 |
|
8633 | DataAxis.prototype.addGroup = function(label, graphOptions) {
|
8634 | if (!this.groups.hasOwnProperty(label)) {
|
8635 | this.groups[label] = graphOptions;
|
8636 | }
|
8637 | this.amountOfGroups += 1;
|
8638 | };
|
8639 |
|
8640 | DataAxis.prototype.updateGroup = function(label, graphOptions) {
|
8641 | this.groups[label] = graphOptions;
|
8642 | };
|
8643 |
|
8644 | DataAxis.prototype.removeGroup = function(label) {
|
8645 | if (this.groups.hasOwnProperty(label)) {
|
8646 | delete this.groups[label];
|
8647 | this.amountOfGroups -= 1;
|
8648 | }
|
8649 | };
|
8650 |
|
8651 |
|
8652 | DataAxis.prototype.setOptions = function (options) {
|
8653 | if (options) {
|
8654 | var redraw = false;
|
8655 | if (this.options.orientation != options.orientation && options.orientation !== undefined) {
|
8656 | redraw = true;
|
8657 | }
|
8658 | var fields = [
|
8659 | 'orientation',
|
8660 | 'showMinorLabels',
|
8661 | 'showMajorLabels',
|
8662 | 'icons',
|
8663 | 'majorLinesOffset',
|
8664 | 'minorLinesOffset',
|
8665 | 'labelOffsetX',
|
8666 | 'labelOffsetY',
|
8667 | 'iconWidth',
|
8668 | 'width',
|
8669 | 'visible',
|
8670 | 'customRange'
|
8671 | ];
|
8672 | util.selectiveExtend(fields, this.options, options);
|
8673 |
|
8674 | this.minWidth = Number(('' + this.options.width).replace("px",""));
|
8675 |
|
8676 | if (redraw == true && this.dom.frame) {
|
8677 | this.hide();
|
8678 | this.show();
|
8679 | }
|
8680 | }
|
8681 | };
|
8682 |
|
8683 |
|
8684 | |
8685 |
|
8686 |
|
8687 | DataAxis.prototype._create = function() {
|
8688 | this.dom.frame = document.createElement('div');
|
8689 | this.dom.frame.style.width = this.options.width;
|
8690 | this.dom.frame.style.height = this.height;
|
8691 |
|
8692 | this.dom.lineContainer = document.createElement('div');
|
8693 | this.dom.lineContainer.style.width = '100%';
|
8694 | this.dom.lineContainer.style.height = this.height;
|
8695 |
|
8696 |
|
8697 | this.svg = document.createElementNS('http://www.w3.org/2000/svg',"svg");
|
8698 | this.svg.style.position = "absolute";
|
8699 | this.svg.style.top = '0px';
|
8700 | this.svg.style.height = '100%';
|
8701 | this.svg.style.width = '100%';
|
8702 | this.svg.style.display = "block";
|
8703 | this.dom.frame.appendChild(this.svg);
|
8704 | };
|
8705 |
|
8706 | DataAxis.prototype._redrawGroupIcons = function () {
|
8707 | DOMutil.prepareElements(this.svgElements);
|
8708 |
|
8709 | var x;
|
8710 | var iconWidth = this.options.iconWidth;
|
8711 | var iconHeight = 15;
|
8712 | var iconOffset = 4;
|
8713 | var y = iconOffset + 0.5 * iconHeight;
|
8714 |
|
8715 | if (this.options.orientation == 'left') {
|
8716 | x = iconOffset;
|
8717 | }
|
8718 | else {
|
8719 | x = this.width - iconWidth - iconOffset;
|
8720 | }
|
8721 |
|
8722 | for (var groupId in this.groups) {
|
8723 | if (this.groups.hasOwnProperty(groupId)) {
|
8724 | if (this.groups[groupId].visible == true && (this.linegraphOptions.visibility[groupId] === undefined || this.linegraphOptions.visibility[groupId] == true)) {
|
8725 | this.groups[groupId].drawIcon(x, y, this.svgElements, this.svg, iconWidth, iconHeight);
|
8726 | y += iconHeight + iconOffset;
|
8727 | }
|
8728 | }
|
8729 | }
|
8730 |
|
8731 | DOMutil.cleanupElements(this.svgElements);
|
8732 | };
|
8733 |
|
8734 | |
8735 |
|
8736 |
|
8737 | DataAxis.prototype.show = function() {
|
8738 | if (!this.dom.frame.parentNode) {
|
8739 | if (this.options.orientation == 'left') {
|
8740 | this.body.dom.left.appendChild(this.dom.frame);
|
8741 | }
|
8742 | else {
|
8743 | this.body.dom.right.appendChild(this.dom.frame);
|
8744 | }
|
8745 | }
|
8746 |
|
8747 | if (!this.dom.lineContainer.parentNode) {
|
8748 | this.body.dom.backgroundHorizontal.appendChild(this.dom.lineContainer);
|
8749 | }
|
8750 | };
|
8751 |
|
8752 | |
8753 |
|
8754 |
|
8755 | DataAxis.prototype.hide = function() {
|
8756 | if (this.dom.frame.parentNode) {
|
8757 | this.dom.frame.parentNode.removeChild(this.dom.frame);
|
8758 | }
|
8759 |
|
8760 | if (this.dom.lineContainer.parentNode) {
|
8761 | this.dom.lineContainer.parentNode.removeChild(this.dom.lineContainer);
|
8762 | }
|
8763 | };
|
8764 |
|
8765 | |
8766 |
|
8767 |
|
8768 |
|
8769 |
|
8770 |
|
8771 | DataAxis.prototype.setRange = function (start, end) {
|
8772 | this.range.start = start;
|
8773 | this.range.end = end;
|
8774 | };
|
8775 |
|
8776 | |
8777 |
|
8778 |
|
8779 |
|
8780 | DataAxis.prototype.redraw = function () {
|
8781 | var changeCalled = false;
|
8782 | var activeGroups = 0;
|
8783 | for (var groupId in this.groups) {
|
8784 | if (this.groups.hasOwnProperty(groupId)) {
|
8785 | if (this.groups[groupId].visible == true && (this.linegraphOptions.visibility[groupId] === undefined || this.linegraphOptions.visibility[groupId] == true)) {
|
8786 | activeGroups++;
|
8787 | }
|
8788 | }
|
8789 | }
|
8790 | if (this.amountOfGroups == 0 || activeGroups == 0) {
|
8791 | this.hide();
|
8792 | }
|
8793 | else {
|
8794 | this.show();
|
8795 | this.height = Number(this.linegraphSVG.style.height.replace("px",""));
|
8796 |
|
8797 |
|
8798 | this.dom.lineContainer.style.height = this.height + 'px';
|
8799 | this.width = this.options.visible == true ? Number(('' + this.options.width).replace("px","")) : 0;
|
8800 |
|
8801 | var props = this.props;
|
8802 | var frame = this.dom.frame;
|
8803 |
|
8804 |
|
8805 | frame.className = 'dataaxis';
|
8806 |
|
8807 |
|
8808 | this._calculateCharSize();
|
8809 |
|
8810 | var orientation = this.options.orientation;
|
8811 | var showMinorLabels = this.options.showMinorLabels;
|
8812 | var showMajorLabels = this.options.showMajorLabels;
|
8813 |
|
8814 |
|
8815 | props.minorLabelHeight = showMinorLabels ? props.minorCharHeight : 0;
|
8816 | props.majorLabelHeight = showMajorLabels ? props.majorCharHeight : 0;
|
8817 |
|
8818 | props.minorLineWidth = this.body.dom.backgroundHorizontal.offsetWidth - this.lineOffset - this.width + 2 * this.options.minorLinesOffset;
|
8819 | props.minorLineHeight = 1;
|
8820 | props.majorLineWidth = this.body.dom.backgroundHorizontal.offsetWidth - this.lineOffset - this.width + 2 * this.options.majorLinesOffset;
|
8821 | props.majorLineHeight = 1;
|
8822 |
|
8823 |
|
8824 | if (orientation == 'left') {
|
8825 | frame.style.top = '0';
|
8826 | frame.style.left = '0';
|
8827 | frame.style.bottom = '';
|
8828 | frame.style.width = this.width + 'px';
|
8829 | frame.style.height = this.height + "px";
|
8830 | }
|
8831 | else {
|
8832 | frame.style.top = '';
|
8833 | frame.style.bottom = '0';
|
8834 | frame.style.left = '0';
|
8835 | frame.style.width = this.width + 'px';
|
8836 | frame.style.height = this.height + "px";
|
8837 | }
|
8838 | changeCalled = this._redrawLabels();
|
8839 | if (this.options.icons == true) {
|
8840 | this._redrawGroupIcons();
|
8841 | }
|
8842 | }
|
8843 | return changeCalled;
|
8844 | };
|
8845 |
|
8846 | |
8847 |
|
8848 |
|
8849 |
|
8850 | DataAxis.prototype._redrawLabels = function () {
|
8851 | DOMutil.prepareElements(this.DOMelements.lines);
|
8852 | DOMutil.prepareElements(this.DOMelements.labels);
|
8853 |
|
8854 | var orientation = this.options['orientation'];
|
8855 |
|
8856 |
|
8857 | var minimumStep = this.master ? this.props.majorCharHeight || 10 : this.stepPixelsForced;
|
8858 |
|
8859 | var step = new DataStep(this.range.start, this.range.end, minimumStep, this.dom.frame.offsetHeight, this.options.customRange[this.options.orientation]);
|
8860 | this.step = step;
|
8861 |
|
8862 |
|
8863 | var stepPixels = (this.dom.frame.offsetHeight - (step.deadSpace * (this.dom.frame.offsetHeight / step.marginRange))) / (((step.marginRange - step.deadSpace) / step.step));
|
8864 | this.stepPixels = stepPixels;
|
8865 |
|
8866 | var amountOfSteps = this.height / stepPixels;
|
8867 | var stepDifference = 0;
|
8868 |
|
8869 | if (this.master == false) {
|
8870 | stepPixels = this.stepPixelsForced;
|
8871 | stepDifference = Math.round((this.dom.frame.offsetHeight / stepPixels) - amountOfSteps);
|
8872 | for (var i = 0; i < 0.5 * stepDifference; i++) {
|
8873 | step.previous();
|
8874 | }
|
8875 | amountOfSteps = this.height / stepPixels;
|
8876 | }
|
8877 | else {
|
8878 | amountOfSteps += 0.25;
|
8879 | }
|
8880 |
|
8881 |
|
8882 | this.valueAtZero = step.marginEnd;
|
8883 | var marginStartPos = 0;
|
8884 |
|
8885 |
|
8886 | var max = 1;
|
8887 |
|
8888 | this.maxLabelSize = 0;
|
8889 | var y = 0;
|
8890 | while (max < Math.round(amountOfSteps)) {
|
8891 | step.next();
|
8892 | y = Math.round(max * stepPixels);
|
8893 | marginStartPos = max * stepPixels;
|
8894 | var isMajor = step.isMajor();
|
8895 |
|
8896 | if (this.options['showMinorLabels'] && isMajor == false || this.master == false && this.options['showMinorLabels'] == true) {
|
8897 | this._redrawLabel(y - 2, step.getCurrent(), orientation, 'yAxis minor', this.props.minorCharHeight);
|
8898 | }
|
8899 |
|
8900 | if (isMajor && this.options['showMajorLabels'] && this.master == true ||
|
8901 | this.options['showMinorLabels'] == false && this.master == false && isMajor == true) {
|
8902 | if (y >= 0) {
|
8903 | this._redrawLabel(y - 2, step.getCurrent(), orientation, 'yAxis major', this.props.majorCharHeight);
|
8904 | }
|
8905 | this._redrawLine(y, orientation, 'grid horizontal major', this.options.majorLinesOffset, this.props.majorLineWidth);
|
8906 | }
|
8907 | else {
|
8908 | this._redrawLine(y, orientation, 'grid horizontal minor', this.options.minorLinesOffset, this.props.minorLineWidth);
|
8909 | }
|
8910 |
|
8911 | max++;
|
8912 | }
|
8913 |
|
8914 | if (this.master == false) {
|
8915 | this.conversionFactor = y / (this.valueAtZero - step.current);
|
8916 | }
|
8917 | else {
|
8918 | this.conversionFactor = this.dom.frame.offsetHeight / step.marginRange;
|
8919 | }
|
8920 |
|
8921 | var offset = this.options.icons == true ? this.options.iconWidth + this.options.labelOffsetX + 15 : this.options.labelOffsetX + 15;
|
8922 |
|
8923 | if (this.maxLabelSize > (this.width - offset) && this.options.visible == true) {
|
8924 | this.width = this.maxLabelSize + offset;
|
8925 | this.options.width = this.width + "px";
|
8926 | DOMutil.cleanupElements(this.DOMelements.lines);
|
8927 | DOMutil.cleanupElements(this.DOMelements.labels);
|
8928 | this.redraw();
|
8929 | return true;
|
8930 | }
|
8931 |
|
8932 | else if (this.maxLabelSize < (this.width - offset) && this.options.visible == true && this.width > this.minWidth) {
|
8933 | this.width = Math.max(this.minWidth,this.maxLabelSize + offset);
|
8934 | this.options.width = this.width + "px";
|
8935 | DOMutil.cleanupElements(this.DOMelements.lines);
|
8936 | DOMutil.cleanupElements(this.DOMelements.labels);
|
8937 | this.redraw();
|
8938 | return true;
|
8939 | }
|
8940 | else {
|
8941 | DOMutil.cleanupElements(this.DOMelements.lines);
|
8942 | DOMutil.cleanupElements(this.DOMelements.labels);
|
8943 | return false;
|
8944 | }
|
8945 | };
|
8946 |
|
8947 | DataAxis.prototype.convertValue = function (value) {
|
8948 | var invertedValue = this.valueAtZero - value;
|
8949 | var convertedValue = invertedValue * this.conversionFactor;
|
8950 | return convertedValue;
|
8951 | };
|
8952 |
|
8953 | |
8954 |
|
8955 |
|
8956 |
|
8957 |
|
8958 |
|
8959 |
|
8960 |
|
8961 |
|
8962 | DataAxis.prototype._redrawLabel = function (y, text, orientation, className, characterHeight) {
|
8963 |
|
8964 | var label = DOMutil.getDOMElement('div',this.DOMelements.labels, this.dom.frame);
|
8965 | label.className = className;
|
8966 | label.innerHTML = text;
|
8967 | if (orientation == 'left') {
|
8968 | label.style.left = '-' + this.options.labelOffsetX + 'px';
|
8969 | label.style.textAlign = "right";
|
8970 | }
|
8971 | else {
|
8972 | label.style.right = '-' + this.options.labelOffsetX + 'px';
|
8973 | label.style.textAlign = "left";
|
8974 | }
|
8975 |
|
8976 | label.style.top = y - 0.5 * characterHeight + this.options.labelOffsetY + 'px';
|
8977 |
|
8978 | text += '';
|
8979 |
|
8980 | var largestWidth = Math.max(this.props.majorCharWidth,this.props.minorCharWidth);
|
8981 | if (this.maxLabelSize < text.length * largestWidth) {
|
8982 | this.maxLabelSize = text.length * largestWidth;
|
8983 | }
|
8984 | };
|
8985 |
|
8986 | |
8987 |
|
8988 |
|
8989 |
|
8990 |
|
8991 |
|
8992 |
|
8993 |
|
8994 | DataAxis.prototype._redrawLine = function (y, orientation, className, offset, width) {
|
8995 | if (this.master == true) {
|
8996 | var line = DOMutil.getDOMElement('div',this.DOMelements.lines, this.dom.lineContainer);
|
8997 | line.className = className;
|
8998 | line.innerHTML = '';
|
8999 |
|
9000 | if (orientation == 'left') {
|
9001 | line.style.left = (this.width - offset) + 'px';
|
9002 | }
|
9003 | else {
|
9004 | line.style.right = (this.width - offset) + 'px';
|
9005 | }
|
9006 |
|
9007 | line.style.width = width + 'px';
|
9008 | line.style.top = y + 'px';
|
9009 | }
|
9010 | };
|
9011 |
|
9012 |
|
9013 |
|
9014 |
|
9015 |
|
9016 | |
9017 |
|
9018 |
|
9019 |
|
9020 |
|
9021 | DataAxis.prototype._calculateCharSize = function () {
|
9022 |
|
9023 | if (!('minorCharHeight' in this.props)) {
|
9024 | var textMinor = document.createTextNode('0');
|
9025 | var measureCharMinor = document.createElement('DIV');
|
9026 | measureCharMinor.className = 'yAxis minor measure';
|
9027 | measureCharMinor.appendChild(textMinor);
|
9028 | this.dom.frame.appendChild(measureCharMinor);
|
9029 |
|
9030 | this.props.minorCharHeight = measureCharMinor.clientHeight;
|
9031 | this.props.minorCharWidth = measureCharMinor.clientWidth;
|
9032 |
|
9033 | this.dom.frame.removeChild(measureCharMinor);
|
9034 | }
|
9035 |
|
9036 | if (!('majorCharHeight' in this.props)) {
|
9037 | var textMajor = document.createTextNode('0');
|
9038 | var measureCharMajor = document.createElement('DIV');
|
9039 | measureCharMajor.className = 'yAxis major measure';
|
9040 | measureCharMajor.appendChild(textMajor);
|
9041 | this.dom.frame.appendChild(measureCharMajor);
|
9042 |
|
9043 | this.props.majorCharHeight = measureCharMajor.clientHeight;
|
9044 | this.props.majorCharWidth = measureCharMajor.clientWidth;
|
9045 |
|
9046 | this.dom.frame.removeChild(measureCharMajor);
|
9047 | }
|
9048 | };
|
9049 |
|
9050 | |
9051 |
|
9052 |
|
9053 |
|
9054 |
|
9055 |
|
9056 | DataAxis.prototype.snap = function(date) {
|
9057 | return this.step.snap(date);
|
9058 | };
|
9059 |
|
9060 | module.exports = DataAxis;
|
9061 |
|
9062 |
|
9063 | },
|
9064 |
|
9065 | function(module, exports, __webpack_require__) {
|
9066 |
|
9067 | var util = __webpack_require__(1);
|
9068 | var DOMutil = __webpack_require__(2);
|
9069 |
|
9070 | |
9071 |
|
9072 |
|
9073 |
|
9074 |
|
9075 |
|
9076 | function GraphGroup (group, groupId, options, groupsUsingDefaultStyles) {
|
9077 | this.id = groupId;
|
9078 | var fields = ['sampling','style','sort','yAxisOrientation','barChart','drawPoints','shaded','catmullRom']
|
9079 | this.options = util.selectiveBridgeObject(fields,options);
|
9080 | this.usingDefaultStyle = group.className === undefined;
|
9081 | this.groupsUsingDefaultStyles = groupsUsingDefaultStyles;
|
9082 | this.zeroPosition = 0;
|
9083 | this.update(group);
|
9084 | if (this.usingDefaultStyle == true) {
|
9085 | this.groupsUsingDefaultStyles[0] += 1;
|
9086 | }
|
9087 | this.itemsData = [];
|
9088 | this.visible = group.visible === undefined ? true : group.visible;
|
9089 | }
|
9090 |
|
9091 | GraphGroup.prototype.setItems = function(items) {
|
9092 | if (items != null) {
|
9093 | this.itemsData = items;
|
9094 | if (this.options.sort == true) {
|
9095 | this.itemsData.sort(function (a,b) {return a.x - b.x;})
|
9096 | }
|
9097 | }
|
9098 | else {
|
9099 | this.itemsData = [];
|
9100 | }
|
9101 | };
|
9102 |
|
9103 | GraphGroup.prototype.setZeroPosition = function(pos) {
|
9104 | this.zeroPosition = pos;
|
9105 | };
|
9106 |
|
9107 | GraphGroup.prototype.setOptions = function(options) {
|
9108 | if (options !== undefined) {
|
9109 | var fields = ['sampling','style','sort','yAxisOrientation','barChart'];
|
9110 | util.selectiveDeepExtend(fields, this.options, options);
|
9111 |
|
9112 | util.mergeOptions(this.options, options,'catmullRom');
|
9113 | util.mergeOptions(this.options, options,'drawPoints');
|
9114 | util.mergeOptions(this.options, options,'shaded');
|
9115 |
|
9116 | if (options.catmullRom) {
|
9117 | if (typeof options.catmullRom == 'object') {
|
9118 | if (options.catmullRom.parametrization) {
|
9119 | if (options.catmullRom.parametrization == 'uniform') {
|
9120 | this.options.catmullRom.alpha = 0;
|
9121 | }
|
9122 | else if (options.catmullRom.parametrization == 'chordal') {
|
9123 | this.options.catmullRom.alpha = 1.0;
|
9124 | }
|
9125 | else {
|
9126 | this.options.catmullRom.parametrization = 'centripetal';
|
9127 | this.options.catmullRom.alpha = 0.5;
|
9128 | }
|
9129 | }
|
9130 | }
|
9131 | }
|
9132 | }
|
9133 | };
|
9134 |
|
9135 | GraphGroup.prototype.update = function(group) {
|
9136 | this.group = group;
|
9137 | this.content = group.content || 'graph';
|
9138 | this.className = group.className || this.className || "graphGroup" + this.groupsUsingDefaultStyles[0] % 10;
|
9139 | this.visible = group.visible === undefined ? true : group.visible;
|
9140 | this.setOptions(group.options);
|
9141 | };
|
9142 |
|
9143 | GraphGroup.prototype.drawIcon = function(x, y, JSONcontainer, SVGcontainer, iconWidth, iconHeight) {
|
9144 | var fillHeight = iconHeight * 0.5;
|
9145 | var path, fillPath;
|
9146 |
|
9147 | var outline = DOMutil.getSVGElement("rect", JSONcontainer, SVGcontainer);
|
9148 | outline.setAttributeNS(null, "x", x);
|
9149 | outline.setAttributeNS(null, "y", y - fillHeight);
|
9150 | outline.setAttributeNS(null, "width", iconWidth);
|
9151 | outline.setAttributeNS(null, "height", 2*fillHeight);
|
9152 | outline.setAttributeNS(null, "class", "outline");
|
9153 |
|
9154 | if (this.options.style == 'line') {
|
9155 | path = DOMutil.getSVGElement("path", JSONcontainer, SVGcontainer);
|
9156 | path.setAttributeNS(null, "class", this.className);
|
9157 | path.setAttributeNS(null, "d", "M" + x + ","+y+" L" + (x + iconWidth) + ","+y+"");
|
9158 | if (this.options.shaded.enabled == true) {
|
9159 | fillPath = DOMutil.getSVGElement("path", JSONcontainer, SVGcontainer);
|
9160 | if (this.options.shaded.orientation == 'top') {
|
9161 | fillPath.setAttributeNS(null, "d", "M"+x+", " + (y - fillHeight) +
|
9162 | "L"+x+","+y+" L"+ (x + iconWidth) + ","+y+" L"+ (x + iconWidth) + "," + (y - fillHeight));
|
9163 | }
|
9164 | else {
|
9165 | fillPath.setAttributeNS(null, "d", "M"+x+","+y+" " +
|
9166 | "L"+x+"," + (y + fillHeight) + " " +
|
9167 | "L"+ (x + iconWidth) + "," + (y + fillHeight) +
|
9168 | "L"+ (x + iconWidth) + ","+y);
|
9169 | }
|
9170 | fillPath.setAttributeNS(null, "class", this.className + " iconFill");
|
9171 | }
|
9172 |
|
9173 | if (this.options.drawPoints.enabled == true) {
|
9174 | DOMutil.drawPoint(x + 0.5 * iconWidth,y, this, JSONcontainer, SVGcontainer);
|
9175 | }
|
9176 | }
|
9177 | else {
|
9178 | var barWidth = Math.round(0.3 * iconWidth);
|
9179 | var bar1Height = Math.round(0.4 * iconHeight);
|
9180 | var bar2Height = Math.round(0.75 * iconHeight);
|
9181 |
|
9182 | var offset = Math.round((iconWidth - (2 * barWidth))/3);
|
9183 |
|
9184 | DOMutil.drawBar(x + 0.5*barWidth + offset , y + fillHeight - bar1Height - 1, barWidth, bar1Height, this.className + ' bar', JSONcontainer, SVGcontainer);
|
9185 | DOMutil.drawBar(x + 1.5*barWidth + offset + 2, y + fillHeight - bar2Height - 1, barWidth, bar2Height, this.className + ' bar', JSONcontainer, SVGcontainer);
|
9186 | }
|
9187 | };
|
9188 |
|
9189 | |
9190 |
|
9191 |
|
9192 |
|
9193 |
|
9194 |
|
9195 | GraphGroup.prototype.getLegend = function(iconWidth, iconHeight) {
|
9196 | var svg = document.createElementNS('http://www.w3.org/2000/svg',"svg");
|
9197 | this.drawIcon(0,0.5*iconHeight,[],svg,iconWidth,iconHeight);
|
9198 | return {icon: svg, label: this.content, orientation:this.options.yAxisOrientation};
|
9199 | }
|
9200 |
|
9201 | module.exports = GraphGroup;
|
9202 |
|
9203 |
|
9204 | },
|
9205 |
|
9206 | function(module, exports, __webpack_require__) {
|
9207 |
|
9208 | var util = __webpack_require__(1);
|
9209 | var stack = __webpack_require__(16);
|
9210 | var RangeItem = __webpack_require__(32);
|
9211 |
|
9212 | |
9213 |
|
9214 |
|
9215 |
|
9216 |
|
9217 |
|
9218 | function Group (groupId, data, itemSet) {
|
9219 | this.groupId = groupId;
|
9220 |
|
9221 | this.itemSet = itemSet;
|
9222 |
|
9223 | this.dom = {};
|
9224 | this.props = {
|
9225 | label: {
|
9226 | width: 0,
|
9227 | height: 0
|
9228 | }
|
9229 | };
|
9230 | this.className = null;
|
9231 |
|
9232 | this.items = {};
|
9233 | this.visibleItems = [];
|
9234 | this.orderedItems = {
|
9235 | byStart: [],
|
9236 | byEnd: []
|
9237 | };
|
9238 |
|
9239 | this._create();
|
9240 |
|
9241 | this.setData(data);
|
9242 | }
|
9243 |
|
9244 | |
9245 |
|
9246 |
|
9247 |
|
9248 | Group.prototype._create = function() {
|
9249 | var label = document.createElement('div');
|
9250 | label.className = 'vlabel';
|
9251 | this.dom.label = label;
|
9252 |
|
9253 | var inner = document.createElement('div');
|
9254 | inner.className = 'inner';
|
9255 | label.appendChild(inner);
|
9256 | this.dom.inner = inner;
|
9257 |
|
9258 | var foreground = document.createElement('div');
|
9259 | foreground.className = 'group';
|
9260 | foreground['timeline-group'] = this;
|
9261 | this.dom.foreground = foreground;
|
9262 |
|
9263 | this.dom.background = document.createElement('div');
|
9264 | this.dom.background.className = 'group';
|
9265 |
|
9266 | this.dom.axis = document.createElement('div');
|
9267 | this.dom.axis.className = 'group';
|
9268 |
|
9269 |
|
9270 |
|
9271 |
|
9272 | this.dom.marker = document.createElement('div');
|
9273 | this.dom.marker.style.visibility = 'hidden';
|
9274 | this.dom.marker.innerHTML = '?';
|
9275 | this.dom.background.appendChild(this.dom.marker);
|
9276 | };
|
9277 |
|
9278 | |
9279 |
|
9280 |
|
9281 |
|
9282 | Group.prototype.setData = function(data) {
|
9283 |
|
9284 | var content = data && data.content;
|
9285 | if (content instanceof Element) {
|
9286 | this.dom.inner.appendChild(content);
|
9287 | }
|
9288 | else if (content !== undefined && content !== null) {
|
9289 | this.dom.inner.innerHTML = content;
|
9290 | }
|
9291 | else {
|
9292 | this.dom.inner.innerHTML = this.groupId || '';
|
9293 | }
|
9294 |
|
9295 |
|
9296 | this.dom.label.title = data && data.title || '';
|
9297 |
|
9298 | if (!this.dom.inner.firstChild) {
|
9299 | util.addClassName(this.dom.inner, 'hidden');
|
9300 | }
|
9301 | else {
|
9302 | util.removeClassName(this.dom.inner, 'hidden');
|
9303 | }
|
9304 |
|
9305 |
|
9306 | var className = data && data.className || null;
|
9307 | if (className != this.className) {
|
9308 | if (this.className) {
|
9309 | util.removeClassName(this.dom.label, this.className);
|
9310 | util.removeClassName(this.dom.foreground, this.className);
|
9311 | util.removeClassName(this.dom.background, this.className);
|
9312 | util.removeClassName(this.dom.axis, this.className);
|
9313 | }
|
9314 | util.addClassName(this.dom.label, className);
|
9315 | util.addClassName(this.dom.foreground, className);
|
9316 | util.addClassName(this.dom.background, className);
|
9317 | util.addClassName(this.dom.axis, className);
|
9318 | this.className = className;
|
9319 | }
|
9320 | };
|
9321 |
|
9322 | |
9323 |
|
9324 |
|
9325 |
|
9326 | Group.prototype.getLabelWidth = function() {
|
9327 | return this.props.label.width;
|
9328 | };
|
9329 |
|
9330 |
|
9331 | |
9332 |
|
9333 |
|
9334 |
|
9335 |
|
9336 |
|
9337 |
|
9338 | Group.prototype.redraw = function(range, margin, restack) {
|
9339 | var resized = false;
|
9340 |
|
9341 | this.visibleItems = this._updateVisibleItems(this.orderedItems, this.visibleItems, range);
|
9342 |
|
9343 |
|
9344 |
|
9345 | var markerHeight = this.dom.marker.clientHeight;
|
9346 | if (markerHeight != this.lastMarkerHeight) {
|
9347 | this.lastMarkerHeight = markerHeight;
|
9348 |
|
9349 | util.forEach(this.items, function (item) {
|
9350 | item.dirty = true;
|
9351 | if (item.displayed) item.redraw();
|
9352 | });
|
9353 |
|
9354 | restack = true;
|
9355 | }
|
9356 |
|
9357 |
|
9358 | if (this.itemSet.options.stack) {
|
9359 | stack.stack(this.visibleItems, margin, restack);
|
9360 | }
|
9361 | else {
|
9362 | stack.nostack(this.visibleItems, margin);
|
9363 | }
|
9364 |
|
9365 |
|
9366 | var height;
|
9367 | var visibleItems = this.visibleItems;
|
9368 | if (visibleItems.length) {
|
9369 | var min = visibleItems[0].top;
|
9370 | var max = visibleItems[0].top + visibleItems[0].height;
|
9371 | util.forEach(visibleItems, function (item) {
|
9372 | min = Math.min(min, item.top);
|
9373 | max = Math.max(max, (item.top + item.height));
|
9374 | });
|
9375 | if (min > margin.axis) {
|
9376 |
|
9377 | var offset = min - margin.axis;
|
9378 | max -= offset;
|
9379 | util.forEach(visibleItems, function (item) {
|
9380 | item.top -= offset;
|
9381 | });
|
9382 | }
|
9383 | height = max + margin.item.vertical / 2;
|
9384 | }
|
9385 | else {
|
9386 | height = margin.axis + margin.item.vertical;
|
9387 | }
|
9388 | height = Math.max(height, this.props.label.height);
|
9389 |
|
9390 |
|
9391 | var foreground = this.dom.foreground;
|
9392 | this.top = foreground.offsetTop;
|
9393 | this.left = foreground.offsetLeft;
|
9394 | this.width = foreground.offsetWidth;
|
9395 | resized = util.updateProperty(this, 'height', height) || resized;
|
9396 |
|
9397 |
|
9398 | resized = util.updateProperty(this.props.label, 'width', this.dom.inner.clientWidth) || resized;
|
9399 | resized = util.updateProperty(this.props.label, 'height', this.dom.inner.clientHeight) || resized;
|
9400 |
|
9401 |
|
9402 | this.dom.background.style.height = height + 'px';
|
9403 | this.dom.foreground.style.height = height + 'px';
|
9404 | this.dom.label.style.height = height + 'px';
|
9405 |
|
9406 |
|
9407 | for (var i = 0, ii = this.visibleItems.length; i < ii; i++) {
|
9408 | var item = this.visibleItems[i];
|
9409 | item.repositionY();
|
9410 | }
|
9411 |
|
9412 | return resized;
|
9413 | };
|
9414 |
|
9415 | |
9416 |
|
9417 |
|
9418 | Group.prototype.show = function() {
|
9419 | if (!this.dom.label.parentNode) {
|
9420 | this.itemSet.dom.labelSet.appendChild(this.dom.label);
|
9421 | }
|
9422 |
|
9423 | if (!this.dom.foreground.parentNode) {
|
9424 | this.itemSet.dom.foreground.appendChild(this.dom.foreground);
|
9425 | }
|
9426 |
|
9427 | if (!this.dom.background.parentNode) {
|
9428 | this.itemSet.dom.background.appendChild(this.dom.background);
|
9429 | }
|
9430 |
|
9431 | if (!this.dom.axis.parentNode) {
|
9432 | this.itemSet.dom.axis.appendChild(this.dom.axis);
|
9433 | }
|
9434 | };
|
9435 |
|
9436 | |
9437 |
|
9438 |
|
9439 | Group.prototype.hide = function() {
|
9440 | var label = this.dom.label;
|
9441 | if (label.parentNode) {
|
9442 | label.parentNode.removeChild(label);
|
9443 | }
|
9444 |
|
9445 | var foreground = this.dom.foreground;
|
9446 | if (foreground.parentNode) {
|
9447 | foreground.parentNode.removeChild(foreground);
|
9448 | }
|
9449 |
|
9450 | var background = this.dom.background;
|
9451 | if (background.parentNode) {
|
9452 | background.parentNode.removeChild(background);
|
9453 | }
|
9454 |
|
9455 | var axis = this.dom.axis;
|
9456 | if (axis.parentNode) {
|
9457 | axis.parentNode.removeChild(axis);
|
9458 | }
|
9459 | };
|
9460 |
|
9461 | |
9462 |
|
9463 |
|
9464 |
|
9465 | Group.prototype.add = function(item) {
|
9466 | this.items[item.id] = item;
|
9467 | item.setParent(this);
|
9468 |
|
9469 | if (this.visibleItems.indexOf(item) == -1) {
|
9470 | var range = this.itemSet.body.range;
|
9471 | this._checkIfVisible(item, this.visibleItems, range);
|
9472 | }
|
9473 | };
|
9474 |
|
9475 | |
9476 |
|
9477 |
|
9478 |
|
9479 | Group.prototype.remove = function(item) {
|
9480 | delete this.items[item.id];
|
9481 | item.setParent(this.itemSet);
|
9482 |
|
9483 |
|
9484 | var index = this.visibleItems.indexOf(item);
|
9485 | if (index != -1) this.visibleItems.splice(index, 1);
|
9486 |
|
9487 |
|
9488 | };
|
9489 |
|
9490 | |
9491 |
|
9492 |
|
9493 |
|
9494 | Group.prototype.removeFromDataSet = function(item) {
|
9495 | this.itemSet.removeItem(item.id);
|
9496 | };
|
9497 |
|
9498 | |
9499 |
|
9500 |
|
9501 | Group.prototype.order = function() {
|
9502 | var array = util.toArray(this.items);
|
9503 | this.orderedItems.byStart = array;
|
9504 | this.orderedItems.byEnd = this._constructByEndArray(array);
|
9505 |
|
9506 | stack.orderByStart(this.orderedItems.byStart);
|
9507 | stack.orderByEnd(this.orderedItems.byEnd);
|
9508 | };
|
9509 |
|
9510 | |
9511 |
|
9512 |
|
9513 |
|
9514 |
|
9515 |
|
9516 | Group.prototype._constructByEndArray = function(array) {
|
9517 | var endArray = [];
|
9518 |
|
9519 | for (var i = 0; i < array.length; i++) {
|
9520 | if (array[i] instanceof RangeItem) {
|
9521 | endArray.push(array[i]);
|
9522 | }
|
9523 | }
|
9524 | return endArray;
|
9525 | };
|
9526 |
|
9527 | |
9528 |
|
9529 |
|
9530 |
|
9531 |
|
9532 |
|
9533 |
|
9534 |
|
9535 | Group.prototype._updateVisibleItems = function(orderedItems, visibleItems, range) {
|
9536 | var initialPosByStart,
|
9537 | newVisibleItems = [],
|
9538 | i;
|
9539 |
|
9540 |
|
9541 |
|
9542 | if (visibleItems.length > 0) {
|
9543 | for (i = 0; i < visibleItems.length; i++) {
|
9544 | this._checkIfVisible(visibleItems[i], newVisibleItems, range);
|
9545 | }
|
9546 | }
|
9547 |
|
9548 |
|
9549 | if (newVisibleItems.length == 0) {
|
9550 | initialPosByStart = util.binarySearch(orderedItems.byStart, range, 'data','start');
|
9551 | }
|
9552 | else {
|
9553 | initialPosByStart = orderedItems.byStart.indexOf(newVisibleItems[0]);
|
9554 | }
|
9555 |
|
9556 |
|
9557 | var initialPosByEnd = util.binarySearch(orderedItems.byEnd, range, 'data','end');
|
9558 |
|
9559 |
|
9560 | if (initialPosByStart != -1) {
|
9561 | for (i = initialPosByStart; i >= 0; i--) {
|
9562 | if (this._checkIfInvisible(orderedItems.byStart[i], newVisibleItems, range)) {break;}
|
9563 | }
|
9564 | for (i = initialPosByStart + 1; i < orderedItems.byStart.length; i++) {
|
9565 | if (this._checkIfInvisible(orderedItems.byStart[i], newVisibleItems, range)) {break;}
|
9566 | }
|
9567 | }
|
9568 |
|
9569 |
|
9570 | if (initialPosByEnd != -1) {
|
9571 | for (i = initialPosByEnd; i >= 0; i--) {
|
9572 | if (this._checkIfInvisible(orderedItems.byEnd[i], newVisibleItems, range)) {break;}
|
9573 | }
|
9574 | for (i = initialPosByEnd + 1; i < orderedItems.byEnd.length; i++) {
|
9575 | if (this._checkIfInvisible(orderedItems.byEnd[i], newVisibleItems, range)) {break;}
|
9576 | }
|
9577 | }
|
9578 |
|
9579 | return newVisibleItems;
|
9580 | };
|
9581 |
|
9582 |
|
9583 |
|
9584 | |
9585 |
|
9586 |
|
9587 |
|
9588 |
|
9589 |
|
9590 |
|
9591 |
|
9592 |
|
9593 |
|
9594 | Group.prototype._checkIfInvisible = function(item, visibleItems, range) {
|
9595 | if (item.isVisible(range)) {
|
9596 | if (!item.displayed) item.show();
|
9597 | item.repositionX();
|
9598 | if (visibleItems.indexOf(item) == -1) {
|
9599 | visibleItems.push(item);
|
9600 | }
|
9601 | return false;
|
9602 | }
|
9603 | else {
|
9604 | if (item.displayed) item.hide();
|
9605 | return true;
|
9606 | }
|
9607 | };
|
9608 |
|
9609 | |
9610 |
|
9611 |
|
9612 |
|
9613 |
|
9614 |
|
9615 |
|
9616 |
|
9617 |
|
9618 |
|
9619 |
|
9620 | Group.prototype._checkIfVisible = function(item, visibleItems, range) {
|
9621 | if (item.isVisible(range)) {
|
9622 | if (!item.displayed) item.show();
|
9623 |
|
9624 | item.repositionX();
|
9625 | visibleItems.push(item);
|
9626 | }
|
9627 | else {
|
9628 | if (item.displayed) item.hide();
|
9629 | }
|
9630 | };
|
9631 |
|
9632 | module.exports = Group;
|
9633 |
|
9634 |
|
9635 | },
|
9636 |
|
9637 | function(module, exports, __webpack_require__) {
|
9638 |
|
9639 | var Hammer = __webpack_require__(42);
|
9640 | var util = __webpack_require__(1);
|
9641 | var DataSet = __webpack_require__(3);
|
9642 | var DataView = __webpack_require__(4);
|
9643 | var Component = __webpack_require__(18);
|
9644 | var Group = __webpack_require__(23);
|
9645 | var BoxItem = __webpack_require__(30);
|
9646 | var PointItem = __webpack_require__(31);
|
9647 | var RangeItem = __webpack_require__(32);
|
9648 | var BackgroundItem = __webpack_require__(29);
|
9649 |
|
9650 |
|
9651 | var UNGROUPED = '__ungrouped__';
|
9652 |
|
9653 | |
9654 |
|
9655 |
|
9656 |
|
9657 |
|
9658 |
|
9659 |
|
9660 |
|
9661 |
|
9662 | function ItemSet(body, options) {
|
9663 | this.body = body;
|
9664 |
|
9665 | this.defaultOptions = {
|
9666 | type: null,
|
9667 | orientation: 'bottom',
|
9668 | align: 'auto',
|
9669 | stack: true,
|
9670 | groupOrder: null,
|
9671 |
|
9672 | selectable: true,
|
9673 | editable: {
|
9674 | updateTime: false,
|
9675 | updateGroup: false,
|
9676 | add: false,
|
9677 | remove: false
|
9678 | },
|
9679 |
|
9680 | onAdd: function (item, callback) {
|
9681 | callback(item);
|
9682 | },
|
9683 | onUpdate: function (item, callback) {
|
9684 | callback(item);
|
9685 | },
|
9686 | onMove: function (item, callback) {
|
9687 | callback(item);
|
9688 | },
|
9689 | onRemove: function (item, callback) {
|
9690 | callback(item);
|
9691 | },
|
9692 | onMoving: function (item, callback) {
|
9693 | callback(item);
|
9694 | },
|
9695 |
|
9696 | margin: {
|
9697 | item: {
|
9698 | horizontal: 10,
|
9699 | vertical: 10
|
9700 | },
|
9701 | axis: 20
|
9702 | },
|
9703 | padding: 5
|
9704 | };
|
9705 |
|
9706 |
|
9707 | this.options = util.extend({}, this.defaultOptions);
|
9708 |
|
9709 |
|
9710 | this.itemOptions = {
|
9711 | type: {start: 'Date', end: 'Date'}
|
9712 | };
|
9713 |
|
9714 | this.conversion = {
|
9715 | toScreen: body.util.toScreen,
|
9716 | toTime: body.util.toTime
|
9717 | };
|
9718 | this.dom = {};
|
9719 | this.props = {};
|
9720 | this.hammer = null;
|
9721 |
|
9722 | var me = this;
|
9723 | this.itemsData = null;
|
9724 | this.groupsData = null;
|
9725 |
|
9726 |
|
9727 | this.itemListeners = {
|
9728 | 'add': function (event, params, senderId) {
|
9729 | me._onAdd(params.items);
|
9730 | },
|
9731 | 'update': function (event, params, senderId) {
|
9732 | me._onUpdate(params.items);
|
9733 | },
|
9734 | 'remove': function (event, params, senderId) {
|
9735 | me._onRemove(params.items);
|
9736 | }
|
9737 | };
|
9738 |
|
9739 |
|
9740 | this.groupListeners = {
|
9741 | 'add': function (event, params, senderId) {
|
9742 | me._onAddGroups(params.items);
|
9743 | },
|
9744 | 'update': function (event, params, senderId) {
|
9745 | me._onUpdateGroups(params.items);
|
9746 | },
|
9747 | 'remove': function (event, params, senderId) {
|
9748 | me._onRemoveGroups(params.items);
|
9749 | }
|
9750 | };
|
9751 |
|
9752 | this.items = {};
|
9753 | this.groups = {};
|
9754 | this.groupIds = [];
|
9755 |
|
9756 | this.selection = [];
|
9757 | this.stackDirty = true;
|
9758 |
|
9759 | this.touchParams = {};
|
9760 |
|
9761 |
|
9762 | this._create();
|
9763 |
|
9764 | this.setOptions(options);
|
9765 | }
|
9766 |
|
9767 | ItemSet.prototype = new Component();
|
9768 |
|
9769 |
|
9770 | ItemSet.types = {
|
9771 | background: BackgroundItem,
|
9772 | box: BoxItem,
|
9773 | range: RangeItem,
|
9774 | point: PointItem
|
9775 | };
|
9776 |
|
9777 | |
9778 |
|
9779 |
|
9780 | ItemSet.prototype._create = function(){
|
9781 | var frame = document.createElement('div');
|
9782 | frame.className = 'itemset';
|
9783 | frame['timeline-itemset'] = this;
|
9784 | this.dom.frame = frame;
|
9785 |
|
9786 |
|
9787 | var background = document.createElement('div');
|
9788 | background.className = 'background';
|
9789 | frame.appendChild(background);
|
9790 | this.dom.background = background;
|
9791 |
|
9792 |
|
9793 | var foreground = document.createElement('div');
|
9794 | foreground.className = 'foreground';
|
9795 | frame.appendChild(foreground);
|
9796 | this.dom.foreground = foreground;
|
9797 |
|
9798 |
|
9799 | var axis = document.createElement('div');
|
9800 | axis.className = 'axis';
|
9801 | this.dom.axis = axis;
|
9802 |
|
9803 |
|
9804 | var labelSet = document.createElement('div');
|
9805 | labelSet.className = 'labelset';
|
9806 | this.dom.labelSet = labelSet;
|
9807 |
|
9808 |
|
9809 | this._updateUngrouped();
|
9810 |
|
9811 |
|
9812 |
|
9813 |
|
9814 |
|
9815 | this.hammer = Hammer(this.body.dom.centerContainer, {
|
9816 | prevent_default: true
|
9817 | });
|
9818 |
|
9819 |
|
9820 | this.hammer.on('touch', this._onTouch.bind(this));
|
9821 | this.hammer.on('dragstart', this._onDragStart.bind(this));
|
9822 | this.hammer.on('drag', this._onDrag.bind(this));
|
9823 | this.hammer.on('dragend', this._onDragEnd.bind(this));
|
9824 |
|
9825 |
|
9826 | this.hammer.on('tap', this._onSelectItem.bind(this));
|
9827 |
|
9828 |
|
9829 | this.hammer.on('hold', this._onMultiSelectItem.bind(this));
|
9830 |
|
9831 |
|
9832 | this.hammer.on('doubletap', this._onAddItem.bind(this));
|
9833 |
|
9834 |
|
9835 | this.show();
|
9836 | };
|
9837 |
|
9838 | |
9839 |
|
9840 |
|
9841 |
|
9842 |
|
9843 |
|
9844 |
|
9845 |
|
9846 |
|
9847 |
|
9848 |
|
9849 |
|
9850 |
|
9851 |
|
9852 |
|
9853 |
|
9854 |
|
9855 |
|
9856 |
|
9857 |
|
9858 |
|
9859 |
|
9860 |
|
9861 |
|
9862 |
|
9863 |
|
9864 |
|
9865 |
|
9866 |
|
9867 |
|
9868 |
|
9869 |
|
9870 |
|
9871 |
|
9872 |
|
9873 |
|
9874 |
|
9875 |
|
9876 |
|
9877 |
|
9878 |
|
9879 |
|
9880 |
|
9881 |
|
9882 |
|
9883 |
|
9884 |
|
9885 |
|
9886 |
|
9887 |
|
9888 |
|
9889 |
|
9890 |
|
9891 |
|
9892 |
|
9893 |
|
9894 |
|
9895 |
|
9896 |
|
9897 |
|
9898 |
|
9899 |
|
9900 |
|
9901 |
|
9902 | ItemSet.prototype.setOptions = function(options) {
|
9903 | if (options) {
|
9904 |
|
9905 | var fields = ['type', 'align', 'orientation', 'padding', 'stack', 'selectable', 'groupOrder', 'dataAttributes', 'template'];
|
9906 | util.selectiveExtend(fields, this.options, options);
|
9907 |
|
9908 | if ('margin' in options) {
|
9909 | if (typeof options.margin === 'number') {
|
9910 | this.options.margin.axis = options.margin;
|
9911 | this.options.margin.item.horizontal = options.margin;
|
9912 | this.options.margin.item.vertical = options.margin;
|
9913 | }
|
9914 | else if (typeof options.margin === 'object') {
|
9915 | util.selectiveExtend(['axis'], this.options.margin, options.margin);
|
9916 | if ('item' in options.margin) {
|
9917 | if (typeof options.margin.item === 'number') {
|
9918 | this.options.margin.item.horizontal = options.margin.item;
|
9919 | this.options.margin.item.vertical = options.margin.item;
|
9920 | }
|
9921 | else if (typeof options.margin.item === 'object') {
|
9922 | util.selectiveExtend(['horizontal', 'vertical'], this.options.margin.item, options.margin.item);
|
9923 | }
|
9924 | }
|
9925 | }
|
9926 | }
|
9927 |
|
9928 | if ('editable' in options) {
|
9929 | if (typeof options.editable === 'boolean') {
|
9930 | this.options.editable.updateTime = options.editable;
|
9931 | this.options.editable.updateGroup = options.editable;
|
9932 | this.options.editable.add = options.editable;
|
9933 | this.options.editable.remove = options.editable;
|
9934 | }
|
9935 | else if (typeof options.editable === 'object') {
|
9936 | util.selectiveExtend(['updateTime', 'updateGroup', 'add', 'remove'], this.options.editable, options.editable);
|
9937 | }
|
9938 | }
|
9939 |
|
9940 |
|
9941 | var addCallback = (function (name) {
|
9942 | var fn = options[name];
|
9943 | if (fn) {
|
9944 | if (!(fn instanceof Function)) {
|
9945 | throw new Error('option ' + name + ' must be a function ' + name + '(item, callback)');
|
9946 | }
|
9947 | this.options[name] = fn;
|
9948 | }
|
9949 | }).bind(this);
|
9950 | ['onAdd', 'onUpdate', 'onRemove', 'onMove', 'onMoving'].forEach(addCallback);
|
9951 |
|
9952 |
|
9953 | this.markDirty();
|
9954 | }
|
9955 | };
|
9956 |
|
9957 | |
9958 |
|
9959 |
|
9960 | ItemSet.prototype.markDirty = function() {
|
9961 | this.groupIds = [];
|
9962 | this.stackDirty = true;
|
9963 | };
|
9964 |
|
9965 | |
9966 |
|
9967 |
|
9968 | ItemSet.prototype.destroy = function() {
|
9969 | this.hide();
|
9970 | this.setItems(null);
|
9971 | this.setGroups(null);
|
9972 |
|
9973 | this.hammer = null;
|
9974 |
|
9975 | this.body = null;
|
9976 | this.conversion = null;
|
9977 | };
|
9978 |
|
9979 | |
9980 |
|
9981 |
|
9982 | ItemSet.prototype.hide = function() {
|
9983 |
|
9984 | if (this.dom.frame.parentNode) {
|
9985 | this.dom.frame.parentNode.removeChild(this.dom.frame);
|
9986 | }
|
9987 |
|
9988 |
|
9989 | if (this.dom.axis.parentNode) {
|
9990 | this.dom.axis.parentNode.removeChild(this.dom.axis);
|
9991 | }
|
9992 |
|
9993 |
|
9994 | if (this.dom.labelSet.parentNode) {
|
9995 | this.dom.labelSet.parentNode.removeChild(this.dom.labelSet);
|
9996 | }
|
9997 | };
|
9998 |
|
9999 | |
10000 |
|
10001 |
|
10002 |
|
10003 | ItemSet.prototype.show = function() {
|
10004 |
|
10005 | if (!this.dom.frame.parentNode) {
|
10006 | this.body.dom.center.appendChild(this.dom.frame);
|
10007 | }
|
10008 |
|
10009 |
|
10010 | if (!this.dom.axis.parentNode) {
|
10011 | this.body.dom.backgroundVertical.appendChild(this.dom.axis);
|
10012 | }
|
10013 |
|
10014 |
|
10015 | if (!this.dom.labelSet.parentNode) {
|
10016 | this.body.dom.left.appendChild(this.dom.labelSet);
|
10017 | }
|
10018 | };
|
10019 |
|
10020 | |
10021 |
|
10022 |
|
10023 |
|
10024 |
|
10025 |
|
10026 |
|
10027 | ItemSet.prototype.setSelection = function(ids) {
|
10028 | var i, ii, id, item;
|
10029 |
|
10030 | if (ids == undefined) ids = [];
|
10031 | if (!Array.isArray(ids)) ids = [ids];
|
10032 |
|
10033 |
|
10034 | for (i = 0, ii = this.selection.length; i < ii; i++) {
|
10035 | id = this.selection[i];
|
10036 | item = this.items[id];
|
10037 | if (item) item.unselect();
|
10038 | }
|
10039 |
|
10040 |
|
10041 | this.selection = [];
|
10042 | for (i = 0, ii = ids.length; i < ii; i++) {
|
10043 | id = ids[i];
|
10044 | item = this.items[id];
|
10045 | if (item) {
|
10046 | this.selection.push(id);
|
10047 | item.select();
|
10048 | }
|
10049 | }
|
10050 | };
|
10051 |
|
10052 | |
10053 |
|
10054 |
|
10055 |
|
10056 | ItemSet.prototype.getSelection = function() {
|
10057 | return this.selection.concat([]);
|
10058 | };
|
10059 |
|
10060 | |
10061 |
|
10062 |
|
10063 |
|
10064 | ItemSet.prototype.getVisibleItems = function() {
|
10065 | var range = this.body.range.getRange();
|
10066 | var left = this.body.util.toScreen(range.start);
|
10067 | var right = this.body.util.toScreen(range.end);
|
10068 |
|
10069 | var ids = [];
|
10070 | for (var groupId in this.groups) {
|
10071 | if (this.groups.hasOwnProperty(groupId)) {
|
10072 | var group = this.groups[groupId];
|
10073 | var rawVisibleItems = group.visibleItems;
|
10074 |
|
10075 |
|
10076 |
|
10077 | for (var i = 0; i < rawVisibleItems.length; i++) {
|
10078 | var item = rawVisibleItems[i];
|
10079 |
|
10080 | if ((item.left < right) && (item.left + item.width > left)) {
|
10081 | ids.push(item.id);
|
10082 | }
|
10083 | }
|
10084 | }
|
10085 | }
|
10086 |
|
10087 | return ids;
|
10088 | };
|
10089 |
|
10090 | |
10091 |
|
10092 |
|
10093 |
|
10094 |
|
10095 | ItemSet.prototype._deselect = function(id) {
|
10096 | var selection = this.selection;
|
10097 | for (var i = 0, ii = selection.length; i < ii; i++) {
|
10098 | if (selection[i] == id) {
|
10099 | selection.splice(i, 1);
|
10100 | break;
|
10101 | }
|
10102 | }
|
10103 | };
|
10104 |
|
10105 | |
10106 |
|
10107 |
|
10108 |
|
10109 | ItemSet.prototype.redraw = function() {
|
10110 | var margin = this.options.margin,
|
10111 | range = this.body.range,
|
10112 | asSize = util.option.asSize,
|
10113 | options = this.options,
|
10114 | orientation = options.orientation,
|
10115 | resized = false,
|
10116 | frame = this.dom.frame,
|
10117 | editable = options.editable.updateTime || options.editable.updateGroup;
|
10118 |
|
10119 |
|
10120 | this.props.top = this.body.domProps.top.height + this.body.domProps.border.top;
|
10121 | this.props.left = this.body.domProps.left.width + this.body.domProps.border.left;
|
10122 |
|
10123 |
|
10124 | frame.className = 'itemset' + (editable ? ' editable' : '');
|
10125 |
|
10126 |
|
10127 | resized = this._orderGroups() || resized;
|
10128 |
|
10129 |
|
10130 |
|
10131 | var visibleInterval = range.end - range.start;
|
10132 | var zoomed = (visibleInterval != this.lastVisibleInterval) || (this.props.width != this.props.lastWidth);
|
10133 | if (zoomed) this.stackDirty = true;
|
10134 | this.lastVisibleInterval = visibleInterval;
|
10135 | this.props.lastWidth = this.props.width;
|
10136 |
|
10137 |
|
10138 | var restack = this.stackDirty,
|
10139 | firstGroup = this._firstGroup(),
|
10140 | firstMargin = {
|
10141 | item: margin.item,
|
10142 | axis: margin.axis
|
10143 | },
|
10144 | nonFirstMargin = {
|
10145 | item: margin.item,
|
10146 | axis: margin.item.vertical / 2
|
10147 | },
|
10148 | height = 0,
|
10149 | minHeight = margin.axis + margin.item.vertical;
|
10150 | util.forEach(this.groups, function (group) {
|
10151 | var groupMargin = (group == firstGroup) ? firstMargin : nonFirstMargin;
|
10152 | var groupResized = group.redraw(range, groupMargin, restack);
|
10153 | resized = groupResized || resized;
|
10154 | height += group.height;
|
10155 | });
|
10156 | height = Math.max(height, minHeight);
|
10157 | this.stackDirty = false;
|
10158 |
|
10159 |
|
10160 | frame.style.height = asSize(height);
|
10161 |
|
10162 |
|
10163 | this.props.width = frame.offsetWidth;
|
10164 | this.props.height = height;
|
10165 |
|
10166 |
|
10167 |
|
10168 |
|
10169 | this.dom.axis.style.top = asSize((orientation == 'top') ?
|
10170 | (this.body.domProps.top.height + this.body.domProps.border.top) :
|
10171 | (this.body.domProps.top.height + this.body.domProps.centerContainer.height));
|
10172 | this.dom.axis.style.left = '0';
|
10173 |
|
10174 |
|
10175 | resized = this._isResized() || resized;
|
10176 |
|
10177 | return resized;
|
10178 | };
|
10179 |
|
10180 | |
10181 |
|
10182 |
|
10183 |
|
10184 |
|
10185 | ItemSet.prototype._firstGroup = function() {
|
10186 | var firstGroupIndex = (this.options.orientation == 'top') ? 0 : (this.groupIds.length - 1);
|
10187 | var firstGroupId = this.groupIds[firstGroupIndex];
|
10188 | var firstGroup = this.groups[firstGroupId] || this.groups[UNGROUPED];
|
10189 |
|
10190 | return firstGroup || null;
|
10191 | };
|
10192 |
|
10193 | |
10194 |
|
10195 |
|
10196 |
|
10197 |
|
10198 | ItemSet.prototype._updateUngrouped = function() {
|
10199 | var ungrouped = this.groups[UNGROUPED];
|
10200 |
|
10201 | if (this.groupsData) {
|
10202 |
|
10203 | if (ungrouped) {
|
10204 | ungrouped.hide();
|
10205 | delete this.groups[UNGROUPED];
|
10206 | }
|
10207 | }
|
10208 | else {
|
10209 |
|
10210 | if (!ungrouped) {
|
10211 | var id = null;
|
10212 | var data = null;
|
10213 | ungrouped = new Group(id, data, this);
|
10214 | this.groups[UNGROUPED] = ungrouped;
|
10215 |
|
10216 | for (var itemId in this.items) {
|
10217 | if (this.items.hasOwnProperty(itemId)) {
|
10218 | ungrouped.add(this.items[itemId]);
|
10219 | }
|
10220 | }
|
10221 |
|
10222 | ungrouped.show();
|
10223 | }
|
10224 | }
|
10225 | };
|
10226 |
|
10227 | |
10228 |
|
10229 |
|
10230 |
|
10231 | ItemSet.prototype.getLabelSet = function() {
|
10232 | return this.dom.labelSet;
|
10233 | };
|
10234 |
|
10235 | |
10236 |
|
10237 |
|
10238 |
|
10239 | ItemSet.prototype.setItems = function(items) {
|
10240 | var me = this,
|
10241 | ids,
|
10242 | oldItemsData = this.itemsData;
|
10243 |
|
10244 |
|
10245 | if (!items) {
|
10246 | this.itemsData = null;
|
10247 | }
|
10248 | else if (items instanceof DataSet || items instanceof DataView) {
|
10249 | this.itemsData = items;
|
10250 | }
|
10251 | else {
|
10252 | throw new TypeError('Data must be an instance of DataSet or DataView');
|
10253 | }
|
10254 |
|
10255 | if (oldItemsData) {
|
10256 |
|
10257 | util.forEach(this.itemListeners, function (callback, event) {
|
10258 | oldItemsData.off(event, callback);
|
10259 | });
|
10260 |
|
10261 |
|
10262 | ids = oldItemsData.getIds();
|
10263 | this._onRemove(ids);
|
10264 | }
|
10265 |
|
10266 | if (this.itemsData) {
|
10267 |
|
10268 | var id = this.id;
|
10269 | util.forEach(this.itemListeners, function (callback, event) {
|
10270 | me.itemsData.on(event, callback, id);
|
10271 | });
|
10272 |
|
10273 |
|
10274 | ids = this.itemsData.getIds();
|
10275 | this._onAdd(ids);
|
10276 |
|
10277 |
|
10278 | this._updateUngrouped();
|
10279 | }
|
10280 | };
|
10281 |
|
10282 | |
10283 |
|
10284 |
|
10285 |
|
10286 | ItemSet.prototype.getItems = function() {
|
10287 | return this.itemsData;
|
10288 | };
|
10289 |
|
10290 | |
10291 |
|
10292 |
|
10293 |
|
10294 | ItemSet.prototype.setGroups = function(groups) {
|
10295 | var me = this,
|
10296 | ids;
|
10297 |
|
10298 |
|
10299 | if (this.groupsData) {
|
10300 | util.forEach(this.groupListeners, function (callback, event) {
|
10301 | me.groupsData.unsubscribe(event, callback);
|
10302 | });
|
10303 |
|
10304 |
|
10305 | ids = this.groupsData.getIds();
|
10306 | this.groupsData = null;
|
10307 | this._onRemoveGroups(ids);
|
10308 | }
|
10309 |
|
10310 |
|
10311 | if (!groups) {
|
10312 | this.groupsData = null;
|
10313 | }
|
10314 | else if (groups instanceof DataSet || groups instanceof DataView) {
|
10315 | this.groupsData = groups;
|
10316 | }
|
10317 | else {
|
10318 | throw new TypeError('Data must be an instance of DataSet or DataView');
|
10319 | }
|
10320 |
|
10321 | if (this.groupsData) {
|
10322 |
|
10323 | var id = this.id;
|
10324 | util.forEach(this.groupListeners, function (callback, event) {
|
10325 | me.groupsData.on(event, callback, id);
|
10326 | });
|
10327 |
|
10328 |
|
10329 | ids = this.groupsData.getIds();
|
10330 | this._onAddGroups(ids);
|
10331 | }
|
10332 |
|
10333 |
|
10334 | this._updateUngrouped();
|
10335 |
|
10336 |
|
10337 | this._order();
|
10338 |
|
10339 | this.body.emitter.emit('change');
|
10340 | };
|
10341 |
|
10342 | |
10343 |
|
10344 |
|
10345 |
|
10346 | ItemSet.prototype.getGroups = function() {
|
10347 | return this.groupsData;
|
10348 | };
|
10349 |
|
10350 | |
10351 |
|
10352 |
|
10353 |
|
10354 | ItemSet.prototype.removeItem = function(id) {
|
10355 | var item = this.itemsData.get(id),
|
10356 | dataset = this.itemsData.getDataSet();
|
10357 |
|
10358 | if (item) {
|
10359 |
|
10360 | this.options.onRemove(item, function (item) {
|
10361 | if (item) {
|
10362 |
|
10363 |
|
10364 | dataset.remove(id);
|
10365 | }
|
10366 | });
|
10367 | }
|
10368 | };
|
10369 |
|
10370 | |
10371 |
|
10372 |
|
10373 |
|
10374 |
|
10375 | ItemSet.prototype._onUpdate = function(ids) {
|
10376 | var me = this;
|
10377 |
|
10378 | ids.forEach(function (id) {
|
10379 | var itemData = me.itemsData.get(id, me.itemOptions),
|
10380 | item = me.items[id],
|
10381 | type = itemData.type || me.options.type || (itemData.end ? 'range' : 'box');
|
10382 |
|
10383 | var constructor = ItemSet.types[type];
|
10384 |
|
10385 | if (item) {
|
10386 |
|
10387 | if (!constructor || !(item instanceof constructor)) {
|
10388 |
|
10389 | me._removeItem(item);
|
10390 | item = null;
|
10391 | }
|
10392 | else {
|
10393 | me._updateItem(item, itemData);
|
10394 | }
|
10395 | }
|
10396 |
|
10397 | if (!item) {
|
10398 |
|
10399 | if (constructor) {
|
10400 | item = new constructor(itemData, me.conversion, me.options);
|
10401 | item.id = id; // TODO: not so nice setting id afterwards
|
10402 | me._addItem(item);
|
10403 | }
|
10404 | else if (type == 'rangeoverflow') {
|
10405 |
|
10406 | throw new TypeError('Item type "rangeoverflow" is deprecated. Use css styling instead: ' +
|
10407 | '.vis.timeline .item.range .content {overflow: visible;}');
|
10408 | }
|
10409 | else {
|
10410 | throw new TypeError('Unknown item type "' + type + '"');
|
10411 | }
|
10412 | }
|
10413 | });
|
10414 |
|
10415 | this._order();
|
10416 | this.stackDirty = true;
|
10417 | this.body.emitter.emit('change');
|
10418 | };
|
10419 |
|
10420 | |
10421 |
|
10422 |
|
10423 |
|
10424 |
|
10425 | ItemSet.prototype._onAdd = ItemSet.prototype._onUpdate;
|
10426 |
|
10427 | |
10428 |
|
10429 |
|
10430 |
|
10431 |
|
10432 | ItemSet.prototype._onRemove = function(ids) {
|
10433 | var count = 0;
|
10434 | var me = this;
|
10435 | ids.forEach(function (id) {
|
10436 | var item = me.items[id];
|
10437 | if (item) {
|
10438 | count++;
|
10439 | me._removeItem(item);
|
10440 | }
|
10441 | });
|
10442 |
|
10443 | if (count) {
|
10444 |
|
10445 | this._order();
|
10446 | this.stackDirty = true;
|
10447 | this.body.emitter.emit('change');
|
10448 | }
|
10449 | };
|
10450 |
|
10451 | |
10452 |
|
10453 |
|
10454 |
|
10455 | ItemSet.prototype._order = function() {
|
10456 |
|
10457 |
|
10458 | util.forEach(this.groups, function (group) {
|
10459 | group.order();
|
10460 | });
|
10461 | };
|
10462 |
|
10463 | |
10464 |
|
10465 |
|
10466 |
|
10467 |
|
10468 | ItemSet.prototype._onUpdateGroups = function(ids) {
|
10469 | this._onAddGroups(ids);
|
10470 | };
|
10471 |
|
10472 | |
10473 |
|
10474 |
|
10475 |
|
10476 |
|
10477 | ItemSet.prototype._onAddGroups = function(ids) {
|
10478 | var me = this;
|
10479 |
|
10480 | ids.forEach(function (id) {
|
10481 | var groupData = me.groupsData.get(id);
|
10482 | var group = me.groups[id];
|
10483 |
|
10484 | if (!group) {
|
10485 |
|
10486 | if (id == UNGROUPED) {
|
10487 | throw new Error('Illegal group id. ' + id + ' is a reserved id.');
|
10488 | }
|
10489 |
|
10490 | var groupOptions = Object.create(me.options);
|
10491 | util.extend(groupOptions, {
|
10492 | height: null
|
10493 | });
|
10494 |
|
10495 | group = new Group(id, groupData, me);
|
10496 | me.groups[id] = group;
|
10497 |
|
10498 |
|
10499 | for (var itemId in me.items) {
|
10500 | if (me.items.hasOwnProperty(itemId)) {
|
10501 | var item = me.items[itemId];
|
10502 | if (item.data.group == id) {
|
10503 | group.add(item);
|
10504 | }
|
10505 | }
|
10506 | }
|
10507 |
|
10508 | group.order();
|
10509 | group.show();
|
10510 | }
|
10511 | else {
|
10512 |
|
10513 | group.setData(groupData);
|
10514 | }
|
10515 | });
|
10516 |
|
10517 | this.body.emitter.emit('change');
|
10518 | };
|
10519 |
|
10520 | |
10521 |
|
10522 |
|
10523 |
|
10524 |
|
10525 | ItemSet.prototype._onRemoveGroups = function(ids) {
|
10526 | var groups = this.groups;
|
10527 | ids.forEach(function (id) {
|
10528 | var group = groups[id];
|
10529 |
|
10530 | if (group) {
|
10531 | group.hide();
|
10532 | delete groups[id];
|
10533 | }
|
10534 | });
|
10535 |
|
10536 | this.markDirty();
|
10537 |
|
10538 | this.body.emitter.emit('change');
|
10539 | };
|
10540 |
|
10541 | |
10542 |
|
10543 |
|
10544 |
|
10545 |
|
10546 | ItemSet.prototype._orderGroups = function () {
|
10547 | if (this.groupsData) {
|
10548 |
|
10549 | var groupIds = this.groupsData.getIds({
|
10550 | order: this.options.groupOrder
|
10551 | });
|
10552 |
|
10553 | var changed = !util.equalArray(groupIds, this.groupIds);
|
10554 | if (changed) {
|
10555 |
|
10556 | var groups = this.groups;
|
10557 | groupIds.forEach(function (groupId) {
|
10558 | groups[groupId].hide();
|
10559 | });
|
10560 |
|
10561 |
|
10562 | groupIds.forEach(function (groupId) {
|
10563 | groups[groupId].show();
|
10564 | });
|
10565 |
|
10566 | this.groupIds = groupIds;
|
10567 | }
|
10568 |
|
10569 | return changed;
|
10570 | }
|
10571 | else {
|
10572 | return false;
|
10573 | }
|
10574 | };
|
10575 |
|
10576 | |
10577 |
|
10578 |
|
10579 |
|
10580 |
|
10581 | ItemSet.prototype._addItem = function(item) {
|
10582 | this.items[item.id] = item;
|
10583 |
|
10584 |
|
10585 | var groupId = this.groupsData ? item.data.group : UNGROUPED;
|
10586 | var group = this.groups[groupId];
|
10587 | if (group) group.add(item);
|
10588 | };
|
10589 |
|
10590 | |
10591 |
|
10592 |
|
10593 |
|
10594 |
|
10595 |
|
10596 | ItemSet.prototype._updateItem = function(item, itemData) {
|
10597 | var oldGroupId = item.data.group;
|
10598 |
|
10599 |
|
10600 | item.setData(itemData);
|
10601 |
|
10602 |
|
10603 | if (oldGroupId != item.data.group) {
|
10604 | var oldGroup = this.groups[oldGroupId];
|
10605 | if (oldGroup) oldGroup.remove(item);
|
10606 |
|
10607 | var groupId = this.groupsData ? item.data.group : UNGROUPED;
|
10608 | var group = this.groups[groupId];
|
10609 | if (group) group.add(item);
|
10610 | }
|
10611 | };
|
10612 |
|
10613 | |
10614 |
|
10615 |
|
10616 |
|
10617 |
|
10618 |
|
10619 | ItemSet.prototype._removeItem = function(item) {
|
10620 |
|
10621 | item.hide();
|
10622 |
|
10623 |
|
10624 | delete this.items[item.id];
|
10625 |
|
10626 |
|
10627 | var index = this.selection.indexOf(item.id);
|
10628 | if (index != -1) this.selection.splice(index, 1);
|
10629 |
|
10630 |
|
10631 | var groupId = this.groupsData ? item.data.group : UNGROUPED;
|
10632 | var group = this.groups[groupId];
|
10633 | if (group) group.remove(item);
|
10634 | };
|
10635 |
|
10636 | |
10637 |
|
10638 |
|
10639 |
|
10640 |
|
10641 |
|
10642 | ItemSet.prototype._constructByEndArray = function(array) {
|
10643 | var endArray = [];
|
10644 |
|
10645 | for (var i = 0; i < array.length; i++) {
|
10646 | if (array[i] instanceof RangeItem) {
|
10647 | endArray.push(array[i]);
|
10648 | }
|
10649 | }
|
10650 | return endArray;
|
10651 | };
|
10652 |
|
10653 | |
10654 |
|
10655 |
|
10656 |
|
10657 |
|
10658 |
|
10659 |
|
10660 |
|
10661 |
|
10662 | ItemSet.prototype._onTouch = function (event) {
|
10663 |
|
10664 | this.touchParams.item = ItemSet.itemFromTarget(event);
|
10665 | };
|
10666 |
|
10667 | |
10668 |
|
10669 |
|
10670 |
|
10671 |
|
10672 | ItemSet.prototype._onDragStart = function (event) {
|
10673 | if (!this.options.editable.updateTime && !this.options.editable.updateGroup) {
|
10674 | return;
|
10675 | }
|
10676 |
|
10677 | var item = this.touchParams.item || null,
|
10678 | me = this,
|
10679 | props;
|
10680 |
|
10681 | if (item && item.selected) {
|
10682 | var dragLeftItem = event.target.dragLeftItem;
|
10683 | var dragRightItem = event.target.dragRightItem;
|
10684 |
|
10685 | if (dragLeftItem) {
|
10686 | props = {
|
10687 | item: dragLeftItem
|
10688 | };
|
10689 |
|
10690 | if (me.options.editable.updateTime) {
|
10691 | props.start = item.data.start.valueOf();
|
10692 | }
|
10693 | if (me.options.editable.updateGroup) {
|
10694 | if ('group' in item.data) props.group = item.data.group;
|
10695 | }
|
10696 |
|
10697 | this.touchParams.itemProps = [props];
|
10698 | }
|
10699 | else if (dragRightItem) {
|
10700 | props = {
|
10701 | item: dragRightItem
|
10702 | };
|
10703 |
|
10704 | if (me.options.editable.updateTime) {
|
10705 | props.end = item.data.end.valueOf();
|
10706 | }
|
10707 | if (me.options.editable.updateGroup) {
|
10708 | if ('group' in item.data) props.group = item.data.group;
|
10709 | }
|
10710 |
|
10711 | this.touchParams.itemProps = [props];
|
10712 | }
|
10713 | else {
|
10714 | this.touchParams.itemProps = this.getSelection().map(function (id) {
|
10715 | var item = me.items[id];
|
10716 | var props = {
|
10717 | item: item
|
10718 | };
|
10719 |
|
10720 | if (me.options.editable.updateTime) {
|
10721 | if ('start' in item.data) props.start = item.data.start.valueOf();
|
10722 | if ('end' in item.data) props.end = item.data.end.valueOf();
|
10723 | }
|
10724 | if (me.options.editable.updateGroup) {
|
10725 | if ('group' in item.data) props.group = item.data.group;
|
10726 | }
|
10727 |
|
10728 | return props;
|
10729 | });
|
10730 | }
|
10731 |
|
10732 | event.stopPropagation();
|
10733 | }
|
10734 | };
|
10735 |
|
10736 | |
10737 |
|
10738 |
|
10739 |
|
10740 |
|
10741 | ItemSet.prototype._onDrag = function (event) {
|
10742 | if (this.touchParams.itemProps) {
|
10743 | var me = this;
|
10744 | var range = this.body.range;
|
10745 | var snap = this.body.util.snap || null;
|
10746 | var deltaX = event.gesture.deltaX;
|
10747 | var scale = (this.props.width / (range.end - range.start));
|
10748 | var offset = deltaX / scale;
|
10749 |
|
10750 |
|
10751 | this.touchParams.itemProps.forEach(function (props) {
|
10752 | var newProps = {};
|
10753 |
|
10754 | if ('start' in props) {
|
10755 | var start = new Date(props.start + offset);
|
10756 | newProps.start = snap ? snap(start) : start;
|
10757 | }
|
10758 |
|
10759 | if ('end' in props) {
|
10760 | var end = new Date(props.end + offset);
|
10761 | newProps.end = snap ? snap(end) : end;
|
10762 | }
|
10763 |
|
10764 | if ('group' in props) {
|
10765 |
|
10766 | var group = ItemSet.groupFromTarget(event);
|
10767 | newProps.group = group && group.groupId;
|
10768 | }
|
10769 |
|
10770 |
|
10771 | var itemData = util.extend({}, props.item.data, newProps);
|
10772 | me.options.onMoving(itemData, function (itemData) {
|
10773 | if (itemData) {
|
10774 | me._updateItemProps(props.item, itemData);
|
10775 | }
|
10776 | });
|
10777 | });
|
10778 |
|
10779 | this.stackDirty = true;
|
10780 | this.body.emitter.emit('change');
|
10781 |
|
10782 | event.stopPropagation();
|
10783 | }
|
10784 | };
|
10785 |
|
10786 | |
10787 |
|
10788 |
|
10789 |
|
10790 |
|
10791 |
|
10792 | ItemSet.prototype._updateItemProps = function(item, props) {
|
10793 |
|
10794 | if ('start' in props) item.data.start = props.start;
|
10795 | if ('end' in props) item.data.end = props.end;
|
10796 | if ('group' in props && item.data.group != props.group) {
|
10797 | this._moveToGroup(item, props.group)
|
10798 | }
|
10799 | };
|
10800 |
|
10801 | |
10802 |
|
10803 |
|
10804 |
|
10805 |
|
10806 |
|
10807 | ItemSet.prototype._moveToGroup = function(item, groupId) {
|
10808 | var group = this.groups[groupId];
|
10809 | if (group && group.groupId != item.data.group) {
|
10810 | var oldGroup = item.parent;
|
10811 | oldGroup.remove(item);
|
10812 | oldGroup.order();
|
10813 | group.add(item);
|
10814 | group.order();
|
10815 |
|
10816 | item.data.group = group.groupId;
|
10817 | }
|
10818 | };
|
10819 |
|
10820 | |
10821 |
|
10822 |
|
10823 |
|
10824 |
|
10825 | ItemSet.prototype._onDragEnd = function (event) {
|
10826 | if (this.touchParams.itemProps) {
|
10827 |
|
10828 | var changes = [],
|
10829 | me = this,
|
10830 | dataset = this.itemsData.getDataSet();
|
10831 |
|
10832 | var itemProps = this.touchParams.itemProps ;
|
10833 | this.touchParams.itemProps = null;
|
10834 | itemProps.forEach(function (props) {
|
10835 | var id = props.item.id,
|
10836 | itemData = me.itemsData.get(id, me.itemOptions);
|
10837 |
|
10838 | var changed = false;
|
10839 | if ('start' in props.item.data) {
|
10840 | changed = (props.start != props.item.data.start.valueOf());
|
10841 | itemData.start = util.convert(props.item.data.start,
|
10842 | dataset._options.type && dataset._options.type.start || 'Date');
|
10843 | }
|
10844 | if ('end' in props.item.data) {
|
10845 | changed = changed || (props.end != props.item.data.end.valueOf());
|
10846 | itemData.end = util.convert(props.item.data.end,
|
10847 | dataset._options.type && dataset._options.type.end || 'Date');
|
10848 | }
|
10849 | if ('group' in props.item.data) {
|
10850 | changed = changed || (props.group != props.item.data.group);
|
10851 | itemData.group = props.item.data.group;
|
10852 | }
|
10853 |
|
10854 |
|
10855 | if (changed) {
|
10856 | me.options.onMove(itemData, function (itemData) {
|
10857 | if (itemData) {
|
10858 |
|
10859 | itemData[dataset._fieldId] = id;
|
10860 | changes.push(itemData);
|
10861 | }
|
10862 | else {
|
10863 |
|
10864 | me._updateItemProps(props.item, props);
|
10865 |
|
10866 | me.stackDirty = true;
|
10867 | me.body.emitter.emit('change');
|
10868 | }
|
10869 | });
|
10870 | }
|
10871 | });
|
10872 |
|
10873 |
|
10874 | if (changes.length) {
|
10875 | dataset.update(changes);
|
10876 | }
|
10877 |
|
10878 | event.stopPropagation();
|
10879 | }
|
10880 | };
|
10881 |
|
10882 | |
10883 |
|
10884 |
|
10885 |
|
10886 |
|
10887 | ItemSet.prototype._onSelectItem = function (event) {
|
10888 | if (!this.options.selectable) return;
|
10889 |
|
10890 | var ctrlKey = event.gesture.srcEvent && event.gesture.srcEvent.ctrlKey;
|
10891 | var shiftKey = event.gesture.srcEvent && event.gesture.srcEvent.shiftKey;
|
10892 | if (ctrlKey || shiftKey) {
|
10893 | this._onMultiSelectItem(event);
|
10894 | return;
|
10895 | }
|
10896 |
|
10897 | var oldSelection = this.getSelection();
|
10898 |
|
10899 | var item = ItemSet.itemFromTarget(event);
|
10900 | var selection = item ? [item.id] : [];
|
10901 | this.setSelection(selection);
|
10902 |
|
10903 | var newSelection = this.getSelection();
|
10904 |
|
10905 |
|
10906 |
|
10907 | if (newSelection.length > 0 || oldSelection.length > 0) {
|
10908 | this.body.emitter.emit('select', {
|
10909 | items: this.getSelection()
|
10910 | });
|
10911 | }
|
10912 |
|
10913 | event.stopPropagation();
|
10914 | };
|
10915 |
|
10916 | |
10917 |
|
10918 |
|
10919 |
|
10920 |
|
10921 | ItemSet.prototype._onAddItem = function (event) {
|
10922 | if (!this.options.selectable) return;
|
10923 | if (!this.options.editable.add) return;
|
10924 |
|
10925 | var me = this,
|
10926 | snap = this.body.util.snap || null,
|
10927 | item = ItemSet.itemFromTarget(event);
|
10928 |
|
10929 | if (item) {
|
10930 |
|
10931 |
|
10932 |
|
10933 | var itemData = me.itemsData.get(item.id);
|
10934 | this.options.onUpdate(itemData, function (itemData) {
|
10935 | if (itemData) {
|
10936 | me.itemsData.update(itemData);
|
10937 | }
|
10938 | });
|
10939 | }
|
10940 | else {
|
10941 |
|
10942 | var xAbs = util.getAbsoluteLeft(this.dom.frame);
|
10943 | var x = event.gesture.center.pageX - xAbs;
|
10944 | var start = this.body.util.toTime(x);
|
10945 | var newItem = {
|
10946 | start: snap ? snap(start) : start,
|
10947 | content: 'new item'
|
10948 | };
|
10949 |
|
10950 |
|
10951 | if (this.options.type === 'range') {
|
10952 | var end = this.body.util.toTime(x + this.props.width / 5);
|
10953 | newItem.end = snap ? snap(end) : end;
|
10954 | }
|
10955 |
|
10956 | newItem[this.itemsData._fieldId] = util.randomUUID();
|
10957 |
|
10958 | var group = ItemSet.groupFromTarget(event);
|
10959 | if (group) {
|
10960 | newItem.group = group.groupId;
|
10961 | }
|
10962 |
|
10963 |
|
10964 | this.options.onAdd(newItem, function (item) {
|
10965 | if (item) {
|
10966 | me.itemsData.add(item);
|
10967 |
|
10968 | }
|
10969 | });
|
10970 | }
|
10971 | };
|
10972 |
|
10973 | |
10974 |
|
10975 |
|
10976 |
|
10977 |
|
10978 | ItemSet.prototype._onMultiSelectItem = function (event) {
|
10979 | if (!this.options.selectable) return;
|
10980 |
|
10981 | var selection,
|
10982 | item = ItemSet.itemFromTarget(event);
|
10983 |
|
10984 | if (item) {
|
10985 |
|
10986 | selection = this.getSelection();
|
10987 | var index = selection.indexOf(item.id);
|
10988 | if (index == -1) {
|
10989 |
|
10990 | selection.push(item.id);
|
10991 | }
|
10992 | else {
|
10993 |
|
10994 | selection.splice(index, 1);
|
10995 | }
|
10996 | this.setSelection(selection);
|
10997 |
|
10998 | this.body.emitter.emit('select', {
|
10999 | items: this.getSelection()
|
11000 | });
|
11001 |
|
11002 | event.stopPropagation();
|
11003 | }
|
11004 | };
|
11005 |
|
11006 | |
11007 |
|
11008 |
|
11009 |
|
11010 |
|
11011 |
|
11012 | ItemSet.itemFromTarget = function(event) {
|
11013 | var target = event.target;
|
11014 | while (target) {
|
11015 | if (target.hasOwnProperty('timeline-item')) {
|
11016 | return target['timeline-item'];
|
11017 | }
|
11018 | target = target.parentNode;
|
11019 | }
|
11020 |
|
11021 | return null;
|
11022 | };
|
11023 |
|
11024 | |
11025 |
|
11026 |
|
11027 |
|
11028 |
|
11029 |
|
11030 | ItemSet.groupFromTarget = function(event) {
|
11031 | var target = event.target;
|
11032 | while (target) {
|
11033 | if (target.hasOwnProperty('timeline-group')) {
|
11034 | return target['timeline-group'];
|
11035 | }
|
11036 | target = target.parentNode;
|
11037 | }
|
11038 |
|
11039 | return null;
|
11040 | };
|
11041 |
|
11042 | |
11043 |
|
11044 |
|
11045 |
|
11046 |
|
11047 |
|
11048 | ItemSet.itemSetFromTarget = function(event) {
|
11049 | var target = event.target;
|
11050 | while (target) {
|
11051 | if (target.hasOwnProperty('timeline-itemset')) {
|
11052 | return target['timeline-itemset'];
|
11053 | }
|
11054 | target = target.parentNode;
|
11055 | }
|
11056 |
|
11057 | return null;
|
11058 | };
|
11059 |
|
11060 | module.exports = ItemSet;
|
11061 |
|
11062 |
|
11063 | },
|
11064 |
|
11065 | function(module, exports, __webpack_require__) {
|
11066 |
|
11067 | var util = __webpack_require__(1);
|
11068 | var DOMutil = __webpack_require__(2);
|
11069 | var Component = __webpack_require__(18);
|
11070 |
|
11071 | |
11072 |
|
11073 |
|
11074 | function Legend(body, options, side, linegraphOptions) {
|
11075 | this.body = body;
|
11076 | this.defaultOptions = {
|
11077 | enabled: true,
|
11078 | icons: true,
|
11079 | iconSize: 20,
|
11080 | iconSpacing: 6,
|
11081 | left: {
|
11082 | visible: true,
|
11083 | position: 'top-left'
|
11084 | },
|
11085 | right: {
|
11086 | visible: true,
|
11087 | position: 'top-left'
|
11088 | }
|
11089 | }
|
11090 | this.side = side;
|
11091 | this.options = util.extend({},this.defaultOptions);
|
11092 | this.linegraphOptions = linegraphOptions;
|
11093 |
|
11094 | this.svgElements = {};
|
11095 | this.dom = {};
|
11096 | this.groups = {};
|
11097 | this.amountOfGroups = 0;
|
11098 | this._create();
|
11099 |
|
11100 | this.setOptions(options);
|
11101 | }
|
11102 |
|
11103 | Legend.prototype = new Component();
|
11104 |
|
11105 |
|
11106 | Legend.prototype.addGroup = function(label, graphOptions) {
|
11107 | if (!this.groups.hasOwnProperty(label)) {
|
11108 | this.groups[label] = graphOptions;
|
11109 | }
|
11110 | this.amountOfGroups += 1;
|
11111 | };
|
11112 |
|
11113 | Legend.prototype.updateGroup = function(label, graphOptions) {
|
11114 | this.groups[label] = graphOptions;
|
11115 | };
|
11116 |
|
11117 | Legend.prototype.removeGroup = function(label) {
|
11118 | if (this.groups.hasOwnProperty(label)) {
|
11119 | delete this.groups[label];
|
11120 | this.amountOfGroups -= 1;
|
11121 | }
|
11122 | };
|
11123 |
|
11124 | Legend.prototype._create = function() {
|
11125 | this.dom.frame = document.createElement('div');
|
11126 | this.dom.frame.className = 'legend';
|
11127 | this.dom.frame.style.position = "absolute";
|
11128 | this.dom.frame.style.top = "10px";
|
11129 | this.dom.frame.style.display = "block";
|
11130 |
|
11131 | this.dom.textArea = document.createElement('div');
|
11132 | this.dom.textArea.className = 'legendText';
|
11133 | this.dom.textArea.style.position = "relative";
|
11134 | this.dom.textArea.style.top = "0px";
|
11135 |
|
11136 | this.svg = document.createElementNS('http://www.w3.org/2000/svg',"svg");
|
11137 | this.svg.style.position = 'absolute';
|
11138 | this.svg.style.top = 0 +'px';
|
11139 | this.svg.style.width = this.options.iconSize + 5 + 'px';
|
11140 |
|
11141 | this.dom.frame.appendChild(this.svg);
|
11142 | this.dom.frame.appendChild(this.dom.textArea);
|
11143 | };
|
11144 |
|
11145 | |
11146 |
|
11147 |
|
11148 | Legend.prototype.hide = function() {
|
11149 |
|
11150 | if (this.dom.frame.parentNode) {
|
11151 | this.dom.frame.parentNode.removeChild(this.dom.frame);
|
11152 | }
|
11153 | };
|
11154 |
|
11155 | |
11156 |
|
11157 |
|
11158 |
|
11159 | Legend.prototype.show = function() {
|
11160 |
|
11161 | if (!this.dom.frame.parentNode) {
|
11162 | this.body.dom.center.appendChild(this.dom.frame);
|
11163 | }
|
11164 | };
|
11165 |
|
11166 | Legend.prototype.setOptions = function(options) {
|
11167 | var fields = ['enabled','orientation','icons','left','right'];
|
11168 | util.selectiveDeepExtend(fields, this.options, options);
|
11169 | };
|
11170 |
|
11171 | Legend.prototype.redraw = function() {
|
11172 | var activeGroups = 0;
|
11173 | for (var groupId in this.groups) {
|
11174 | if (this.groups.hasOwnProperty(groupId)) {
|
11175 | if (this.groups[groupId].visible == true && (this.linegraphOptions.visibility[groupId] === undefined || this.linegraphOptions.visibility[groupId] == true)) {
|
11176 | activeGroups++;
|
11177 | }
|
11178 | }
|
11179 | }
|
11180 |
|
11181 | if (this.options[this.side].visible == false || this.amountOfGroups == 0 || this.options.enabled == false || activeGroups == 0) {
|
11182 | this.hide();
|
11183 | }
|
11184 | else {
|
11185 | this.show();
|
11186 | if (this.options[this.side].position == 'top-left' || this.options[this.side].position == 'bottom-left') {
|
11187 | this.dom.frame.style.left = '4px';
|
11188 | this.dom.frame.style.textAlign = "left";
|
11189 | this.dom.textArea.style.textAlign = "left";
|
11190 | this.dom.textArea.style.left = (this.options.iconSize + 15) + 'px';
|
11191 | this.dom.textArea.style.right = '';
|
11192 | this.svg.style.left = 0 +'px';
|
11193 | this.svg.style.right = '';
|
11194 | }
|
11195 | else {
|
11196 | this.dom.frame.style.right = '4px';
|
11197 | this.dom.frame.style.textAlign = "right";
|
11198 | this.dom.textArea.style.textAlign = "right";
|
11199 | this.dom.textArea.style.right = (this.options.iconSize + 15) + 'px';
|
11200 | this.dom.textArea.style.left = '';
|
11201 | this.svg.style.right = 0 +'px';
|
11202 | this.svg.style.left = '';
|
11203 | }
|
11204 |
|
11205 | if (this.options[this.side].position == 'top-left' || this.options[this.side].position == 'top-right') {
|
11206 | this.dom.frame.style.top = 4 - Number(this.body.dom.center.style.top.replace("px","")) + 'px';
|
11207 | this.dom.frame.style.bottom = '';
|
11208 | }
|
11209 | else {
|
11210 | this.dom.frame.style.bottom = 4 - Number(this.body.dom.center.style.top.replace("px","")) + 'px';
|
11211 | this.dom.frame.style.top = '';
|
11212 | }
|
11213 |
|
11214 | if (this.options.icons == false) {
|
11215 | this.dom.frame.style.width = this.dom.textArea.offsetWidth + 10 + 'px';
|
11216 | this.dom.textArea.style.right = '';
|
11217 | this.dom.textArea.style.left = '';
|
11218 | this.svg.style.width = '0px';
|
11219 | }
|
11220 | else {
|
11221 | this.dom.frame.style.width = this.options.iconSize + 15 + this.dom.textArea.offsetWidth + 10 + 'px'
|
11222 | this.drawLegendIcons();
|
11223 | }
|
11224 |
|
11225 | var content = '';
|
11226 | for (var groupId in this.groups) {
|
11227 | if (this.groups.hasOwnProperty(groupId)) {
|
11228 | if (this.groups[groupId].visible == true && (this.linegraphOptions.visibility[groupId] === undefined || this.linegraphOptions.visibility[groupId] == true)) {
|
11229 | content += this.groups[groupId].content + '<br />';
|
11230 | }
|
11231 | }
|
11232 | }
|
11233 | this.dom.textArea.innerHTML = content;
|
11234 | this.dom.textArea.style.lineHeight = ((0.75 * this.options.iconSize) + this.options.iconSpacing) + 'px';
|
11235 | }
|
11236 | };
|
11237 |
|
11238 | Legend.prototype.drawLegendIcons = function() {
|
11239 | if (this.dom.frame.parentNode) {
|
11240 | DOMutil.prepareElements(this.svgElements);
|
11241 | var padding = window.getComputedStyle(this.dom.frame).paddingTop;
|
11242 | var iconOffset = Number(padding.replace('px',''));
|
11243 | var x = iconOffset;
|
11244 | var iconWidth = this.options.iconSize;
|
11245 | var iconHeight = 0.75 * this.options.iconSize;
|
11246 | var y = iconOffset + 0.5 * iconHeight + 3;
|
11247 |
|
11248 | this.svg.style.width = iconWidth + 5 + iconOffset + 'px';
|
11249 |
|
11250 | for (var groupId in this.groups) {
|
11251 | if (this.groups.hasOwnProperty(groupId)) {
|
11252 | if (this.groups[groupId].visible == true && (this.linegraphOptions.visibility[groupId] === undefined || this.linegraphOptions.visibility[groupId] == true)) {
|
11253 | this.groups[groupId].drawIcon(x, y, this.svgElements, this.svg, iconWidth, iconHeight);
|
11254 | y += iconHeight + this.options.iconSpacing;
|
11255 | }
|
11256 | }
|
11257 | }
|
11258 |
|
11259 | DOMutil.cleanupElements(this.svgElements);
|
11260 | }
|
11261 | };
|
11262 |
|
11263 | module.exports = Legend;
|
11264 |
|
11265 |
|
11266 | },
|
11267 |
|
11268 | function(module, exports, __webpack_require__) {
|
11269 |
|
11270 | var util = __webpack_require__(1);
|
11271 | var DOMutil = __webpack_require__(2);
|
11272 | var DataSet = __webpack_require__(3);
|
11273 | var DataView = __webpack_require__(4);
|
11274 | var Component = __webpack_require__(18);
|
11275 | var DataAxis = __webpack_require__(21);
|
11276 | var GraphGroup = __webpack_require__(22);
|
11277 | var Legend = __webpack_require__(25);
|
11278 |
|
11279 | var UNGROUPED = '__ungrouped__';
|
11280 |
|
11281 | |
11282 |
|
11283 |
|
11284 |
|
11285 |
|
11286 |
|
11287 |
|
11288 | function LineGraph(body, options) {
|
11289 | this.id = util.randomUUID();
|
11290 | this.body = body;
|
11291 |
|
11292 | this.defaultOptions = {
|
11293 | yAxisOrientation: 'left',
|
11294 | defaultGroup: 'default',
|
11295 | sort: true,
|
11296 | sampling: true,
|
11297 | graphHeight: '400px',
|
11298 | shaded: {
|
11299 | enabled: false,
|
11300 | orientation: 'bottom'
|
11301 | },
|
11302 | style: 'line',
|
11303 | barChart: {
|
11304 | width: 50,
|
11305 | handleOverlap: 'overlap',
|
11306 | align: 'center'
|
11307 | },
|
11308 | catmullRom: {
|
11309 | enabled: true,
|
11310 | parametrization: 'centripetal',
|
11311 | alpha: 0.5
|
11312 | },
|
11313 | drawPoints: {
|
11314 | enabled: true,
|
11315 | size: 6,
|
11316 | style: 'square'
|
11317 | },
|
11318 | dataAxis: {
|
11319 | showMinorLabels: true,
|
11320 | showMajorLabels: true,
|
11321 | icons: false,
|
11322 | width: '40px',
|
11323 | visible: true,
|
11324 | customRange: {
|
11325 | left: {min:undefined, max:undefined},
|
11326 | right: {min:undefined, max:undefined}
|
11327 | }
|
11328 | },
|
11329 | legend: {
|
11330 | enabled: false,
|
11331 | icons: true,
|
11332 | left: {
|
11333 | visible: true,
|
11334 | position: 'top-left'
|
11335 | },
|
11336 | right: {
|
11337 | visible: true,
|
11338 | position: 'top-right'
|
11339 | }
|
11340 | },
|
11341 | groups: {
|
11342 | visibility: {}
|
11343 | }
|
11344 | };
|
11345 |
|
11346 |
|
11347 | this.options = util.extend({}, this.defaultOptions);
|
11348 | this.dom = {};
|
11349 | this.props = {};
|
11350 | this.hammer = null;
|
11351 | this.groups = {};
|
11352 | this.abortedGraphUpdate = false;
|
11353 |
|
11354 | var me = this;
|
11355 | this.itemsData = null;
|
11356 | this.groupsData = null;
|
11357 |
|
11358 |
|
11359 | this.itemListeners = {
|
11360 | 'add': function (event, params, senderId) {
|
11361 | me._onAdd(params.items);
|
11362 | },
|
11363 | 'update': function (event, params, senderId) {
|
11364 | me._onUpdate(params.items);
|
11365 | },
|
11366 | 'remove': function (event, params, senderId) {
|
11367 | me._onRemove(params.items);
|
11368 | }
|
11369 | };
|
11370 |
|
11371 |
|
11372 | this.groupListeners = {
|
11373 | 'add': function (event, params, senderId) {
|
11374 | me._onAddGroups(params.items);
|
11375 | },
|
11376 | 'update': function (event, params, senderId) {
|
11377 | me._onUpdateGroups(params.items);
|
11378 | },
|
11379 | 'remove': function (event, params, senderId) {
|
11380 | me._onRemoveGroups(params.items);
|
11381 | }
|
11382 | };
|
11383 |
|
11384 | this.items = {};
|
11385 | this.selection = [];
|
11386 | this.lastStart = this.body.range.start;
|
11387 | this.touchParams = {};
|
11388 |
|
11389 | this.svgElements = {};
|
11390 | this.setOptions(options);
|
11391 | this.groupsUsingDefaultStyles = [0];
|
11392 |
|
11393 | this.body.emitter.on("rangechanged", function() {
|
11394 | me.lastStart = me.body.range.start;
|
11395 | me.svg.style.left = util.option.asSize(-me.width);
|
11396 | me._updateGraph.apply(me);
|
11397 | });
|
11398 |
|
11399 |
|
11400 | this._create();
|
11401 | this.body.emitter.emit("change");
|
11402 | }
|
11403 |
|
11404 | LineGraph.prototype = new Component();
|
11405 |
|
11406 | |
11407 |
|
11408 |
|
11409 | LineGraph.prototype._create = function(){
|
11410 | var frame = document.createElement('div');
|
11411 | frame.className = 'LineGraph';
|
11412 | this.dom.frame = frame;
|
11413 |
|
11414 |
|
11415 | this.svg = document.createElementNS('http://www.w3.org/2000/svg',"svg");
|
11416 | this.svg.style.position = "relative";
|
11417 | this.svg.style.height = ('' + this.options.graphHeight).replace("px",'') + 'px';
|
11418 | this.svg.style.display = "block";
|
11419 | frame.appendChild(this.svg);
|
11420 |
|
11421 |
|
11422 | this.options.dataAxis.orientation = 'left';
|
11423 | this.yAxisLeft = new DataAxis(this.body, this.options.dataAxis, this.svg, this.options.groups);
|
11424 |
|
11425 | this.options.dataAxis.orientation = 'right';
|
11426 | this.yAxisRight = new DataAxis(this.body, this.options.dataAxis, this.svg, this.options.groups);
|
11427 | delete this.options.dataAxis.orientation;
|
11428 |
|
11429 |
|
11430 | this.legendLeft = new Legend(this.body, this.options.legend, 'left', this.options.groups);
|
11431 | this.legendRight = new Legend(this.body, this.options.legend, 'right', this.options.groups);
|
11432 |
|
11433 | this.show();
|
11434 | };
|
11435 |
|
11436 | |
11437 |
|
11438 |
|
11439 |
|
11440 | LineGraph.prototype.setOptions = function(options) {
|
11441 | if (options) {
|
11442 | var fields = ['sampling','defaultGroup','graphHeight','yAxisOrientation','style','barChart','dataAxis','sort','groups'];
|
11443 | util.selectiveDeepExtend(fields, this.options, options);
|
11444 | util.mergeOptions(this.options, options,'catmullRom');
|
11445 | util.mergeOptions(this.options, options,'drawPoints');
|
11446 | util.mergeOptions(this.options, options,'shaded');
|
11447 | util.mergeOptions(this.options, options,'legend');
|
11448 |
|
11449 | if (options.catmullRom) {
|
11450 | if (typeof options.catmullRom == 'object') {
|
11451 | if (options.catmullRom.parametrization) {
|
11452 | if (options.catmullRom.parametrization == 'uniform') {
|
11453 | this.options.catmullRom.alpha = 0;
|
11454 | }
|
11455 | else if (options.catmullRom.parametrization == 'chordal') {
|
11456 | this.options.catmullRom.alpha = 1.0;
|
11457 | }
|
11458 | else {
|
11459 | this.options.catmullRom.parametrization = 'centripetal';
|
11460 | this.options.catmullRom.alpha = 0.5;
|
11461 | }
|
11462 | }
|
11463 | }
|
11464 | }
|
11465 |
|
11466 | if (this.yAxisLeft) {
|
11467 | if (options.dataAxis !== undefined) {
|
11468 | this.yAxisLeft.setOptions(this.options.dataAxis);
|
11469 | this.yAxisRight.setOptions(this.options.dataAxis);
|
11470 | }
|
11471 | }
|
11472 |
|
11473 | if (this.legendLeft) {
|
11474 | if (options.legend !== undefined) {
|
11475 | this.legendLeft.setOptions(this.options.legend);
|
11476 | this.legendRight.setOptions(this.options.legend);
|
11477 | }
|
11478 | }
|
11479 |
|
11480 | if (this.groups.hasOwnProperty(UNGROUPED)) {
|
11481 | this.groups[UNGROUPED].setOptions(options);
|
11482 | }
|
11483 | }
|
11484 | if (this.dom.frame) {
|
11485 | this._updateGraph();
|
11486 | }
|
11487 | };
|
11488 |
|
11489 | |
11490 |
|
11491 |
|
11492 | LineGraph.prototype.hide = function() {
|
11493 |
|
11494 | if (this.dom.frame.parentNode) {
|
11495 | this.dom.frame.parentNode.removeChild(this.dom.frame);
|
11496 | }
|
11497 | };
|
11498 |
|
11499 | |
11500 |
|
11501 |
|
11502 |
|
11503 | LineGraph.prototype.show = function() {
|
11504 |
|
11505 | if (!this.dom.frame.parentNode) {
|
11506 | this.body.dom.center.appendChild(this.dom.frame);
|
11507 | }
|
11508 | };
|
11509 |
|
11510 |
|
11511 | |
11512 |
|
11513 |
|
11514 |
|
11515 | LineGraph.prototype.setItems = function(items) {
|
11516 | var me = this,
|
11517 | ids,
|
11518 | oldItemsData = this.itemsData;
|
11519 |
|
11520 |
|
11521 | if (!items) {
|
11522 | this.itemsData = null;
|
11523 | }
|
11524 | else if (items instanceof DataSet || items instanceof DataView) {
|
11525 | this.itemsData = items;
|
11526 | }
|
11527 | else {
|
11528 | throw new TypeError('Data must be an instance of DataSet or DataView');
|
11529 | }
|
11530 |
|
11531 | if (oldItemsData) {
|
11532 |
|
11533 | util.forEach(this.itemListeners, function (callback, event) {
|
11534 | oldItemsData.off(event, callback);
|
11535 | });
|
11536 |
|
11537 |
|
11538 | ids = oldItemsData.getIds();
|
11539 | this._onRemove(ids);
|
11540 | }
|
11541 |
|
11542 | if (this.itemsData) {
|
11543 |
|
11544 | var id = this.id;
|
11545 | util.forEach(this.itemListeners, function (callback, event) {
|
11546 | me.itemsData.on(event, callback, id);
|
11547 | });
|
11548 |
|
11549 |
|
11550 | ids = this.itemsData.getIds();
|
11551 | this._onAdd(ids);
|
11552 | }
|
11553 | this._updateUngrouped();
|
11554 | this._updateGraph();
|
11555 | this.redraw();
|
11556 | };
|
11557 |
|
11558 | |
11559 |
|
11560 |
|
11561 |
|
11562 | LineGraph.prototype.setGroups = function(groups) {
|
11563 | var me = this,
|
11564 | ids;
|
11565 |
|
11566 |
|
11567 | if (this.groupsData) {
|
11568 | util.forEach(this.groupListeners, function (callback, event) {
|
11569 | me.groupsData.unsubscribe(event, callback);
|
11570 | });
|
11571 |
|
11572 |
|
11573 | ids = this.groupsData.getIds();
|
11574 | this.groupsData = null;
|
11575 | this._onRemoveGroups(ids);
|
11576 | }
|
11577 |
|
11578 |
|
11579 | if (!groups) {
|
11580 | this.groupsData = null;
|
11581 | }
|
11582 | else if (groups instanceof DataSet || groups instanceof DataView) {
|
11583 | this.groupsData = groups;
|
11584 | }
|
11585 | else {
|
11586 | throw new TypeError('Data must be an instance of DataSet or DataView');
|
11587 | }
|
11588 |
|
11589 | if (this.groupsData) {
|
11590 |
|
11591 | var id = this.id;
|
11592 | util.forEach(this.groupListeners, function (callback, event) {
|
11593 | me.groupsData.on(event, callback, id);
|
11594 | });
|
11595 |
|
11596 |
|
11597 | ids = this.groupsData.getIds();
|
11598 | this._onAddGroups(ids);
|
11599 | }
|
11600 | this._onUpdate();
|
11601 | };
|
11602 |
|
11603 |
|
11604 | |
11605 |
|
11606 |
|
11607 |
|
11608 |
|
11609 | LineGraph.prototype._onUpdate = function(ids) {
|
11610 | this._updateUngrouped();
|
11611 | this._updateAllGroupData();
|
11612 | this._updateGraph();
|
11613 | this.redraw();
|
11614 | };
|
11615 | LineGraph.prototype._onAdd = function (ids) {this._onUpdate(ids);};
|
11616 | LineGraph.prototype._onRemove = function (ids) {this._onUpdate(ids);};
|
11617 | LineGraph.prototype._onUpdateGroups = function (groupIds) {
|
11618 | for (var i = 0; i < groupIds.length; i++) {
|
11619 | var group = this.groupsData.get(groupIds[i]);
|
11620 | this._updateGroup(group, groupIds[i]);
|
11621 | }
|
11622 |
|
11623 | this._updateGraph();
|
11624 | this.redraw();
|
11625 | };
|
11626 | LineGraph.prototype._onAddGroups = function (groupIds) {this._onUpdateGroups(groupIds);};
|
11627 |
|
11628 | LineGraph.prototype._onRemoveGroups = function (groupIds) {
|
11629 | for (var i = 0; i < groupIds.length; i++) {
|
11630 | if (!this.groups.hasOwnProperty(groupIds[i])) {
|
11631 | if (this.groups[groupIds[i]].options.yAxisOrientation == 'right') {
|
11632 | this.yAxisRight.removeGroup(groupIds[i]);
|
11633 | this.legendRight.removeGroup(groupIds[i]);
|
11634 | this.legendRight.redraw();
|
11635 | }
|
11636 | else {
|
11637 | this.yAxisLeft.removeGroup(groupIds[i]);
|
11638 | this.legendLeft.removeGroup(groupIds[i]);
|
11639 | this.legendLeft.redraw();
|
11640 | }
|
11641 | delete this.groups[groupIds[i]];
|
11642 | }
|
11643 | }
|
11644 | this._updateUngrouped();
|
11645 | this._updateGraph();
|
11646 | this.redraw();
|
11647 | };
|
11648 |
|
11649 | |
11650 |
|
11651 |
|
11652 |
|
11653 |
|
11654 |
|
11655 |
|
11656 | LineGraph.prototype._updateGroup = function (group, groupId) {
|
11657 | if (!this.groups.hasOwnProperty(groupId)) {
|
11658 | this.groups[groupId] = new GraphGroup(group, groupId, this.options, this.groupsUsingDefaultStyles);
|
11659 | if (this.groups[groupId].options.yAxisOrientation == 'right') {
|
11660 | this.yAxisRight.addGroup(groupId, this.groups[groupId]);
|
11661 | this.legendRight.addGroup(groupId, this.groups[groupId]);
|
11662 | }
|
11663 | else {
|
11664 | this.yAxisLeft.addGroup(groupId, this.groups[groupId]);
|
11665 | this.legendLeft.addGroup(groupId, this.groups[groupId]);
|
11666 | }
|
11667 | }
|
11668 | else {
|
11669 | this.groups[groupId].update(group);
|
11670 | if (this.groups[groupId].options.yAxisOrientation == 'right') {
|
11671 | this.yAxisRight.updateGroup(groupId, this.groups[groupId]);
|
11672 | this.legendRight.updateGroup(groupId, this.groups[groupId]);
|
11673 | }
|
11674 | else {
|
11675 | this.yAxisLeft.updateGroup(groupId, this.groups[groupId]);
|
11676 | this.legendLeft.updateGroup(groupId, this.groups[groupId]);
|
11677 | }
|
11678 | }
|
11679 | this.legendLeft.redraw();
|
11680 | this.legendRight.redraw();
|
11681 | };
|
11682 |
|
11683 | LineGraph.prototype._updateAllGroupData = function () {
|
11684 | if (this.itemsData != null) {
|
11685 | var groupsContent = {};
|
11686 | var groupId;
|
11687 | for (groupId in this.groups) {
|
11688 | if (this.groups.hasOwnProperty(groupId)) {
|
11689 | groupsContent[groupId] = [];
|
11690 | }
|
11691 | }
|
11692 | for (var itemId in this.itemsData._data) {
|
11693 | if (this.itemsData._data.hasOwnProperty(itemId)) {
|
11694 | var item = this.itemsData._data[itemId];
|
11695 | item.x = util.convert(item.x,"Date");
|
11696 | groupsContent[item.group].push(item);
|
11697 | }
|
11698 | }
|
11699 | for (groupId in this.groups) {
|
11700 | if (this.groups.hasOwnProperty(groupId)) {
|
11701 | this.groups[groupId].setItems(groupsContent[groupId]);
|
11702 | }
|
11703 | }
|
11704 | }
|
11705 | };
|
11706 |
|
11707 | |
11708 |
|
11709 |
|
11710 |
|
11711 |
|
11712 | LineGraph.prototype._updateUngrouped = function() {
|
11713 | if (this.itemsData && this.itemsData != null) {
|
11714 | var ungroupedCounter = 0;
|
11715 | for (var itemId in this.itemsData._data) {
|
11716 | if (this.itemsData._data.hasOwnProperty(itemId)) {
|
11717 | var item = this.itemsData._data[itemId];
|
11718 | if (item != undefined) {
|
11719 | if (item.hasOwnProperty('group')) {
|
11720 | if (item.group === undefined) {
|
11721 | item.group = UNGROUPED;
|
11722 | }
|
11723 | }
|
11724 | else {
|
11725 | item.group = UNGROUPED;
|
11726 | }
|
11727 | ungroupedCounter = item.group == UNGROUPED ? ungroupedCounter + 1 : ungroupedCounter;
|
11728 | }
|
11729 | }
|
11730 | }
|
11731 |
|
11732 | if (ungroupedCounter == 0) {
|
11733 | delete this.groups[UNGROUPED];
|
11734 | this.legendLeft.removeGroup(UNGROUPED);
|
11735 | this.legendRight.removeGroup(UNGROUPED);
|
11736 | this.yAxisLeft.removeGroup(UNGROUPED);
|
11737 | this.yAxisRight.removeGroup(UNGROUPED);
|
11738 | }
|
11739 | else {
|
11740 | var group = {id: UNGROUPED, content: this.options.defaultGroup};
|
11741 | this._updateGroup(group, UNGROUPED);
|
11742 | }
|
11743 | }
|
11744 | else {
|
11745 | delete this.groups[UNGROUPED];
|
11746 | this.legendLeft.removeGroup(UNGROUPED);
|
11747 | this.legendRight.removeGroup(UNGROUPED);
|
11748 | this.yAxisLeft.removeGroup(UNGROUPED);
|
11749 | this.yAxisRight.removeGroup(UNGROUPED);
|
11750 | }
|
11751 |
|
11752 | this.legendLeft.redraw();
|
11753 | this.legendRight.redraw();
|
11754 | };
|
11755 |
|
11756 |
|
11757 | |
11758 |
|
11759 |
|
11760 |
|
11761 | LineGraph.prototype.redraw = function() {
|
11762 | var resized = false;
|
11763 |
|
11764 | this.svg.style.height = ('' + this.options.graphHeight).replace('px','') + 'px';
|
11765 | if (this.lastWidth === undefined && this.width || this.lastWidth != this.width) {
|
11766 | resized = true;
|
11767 | }
|
11768 |
|
11769 | resized = this._isResized() || resized;
|
11770 |
|
11771 | var visibleInterval = this.body.range.end - this.body.range.start;
|
11772 | var zoomed = (visibleInterval != this.lastVisibleInterval) || (this.width != this.lastWidth);
|
11773 | this.lastVisibleInterval = visibleInterval;
|
11774 | this.lastWidth = this.width;
|
11775 |
|
11776 |
|
11777 | this.width = this.dom.frame.offsetWidth;
|
11778 |
|
11779 |
|
11780 |
|
11781 | if (resized == true) {
|
11782 | this.svg.style.width = util.option.asSize(3*this.width);
|
11783 | this.svg.style.left = util.option.asSize(-this.width);
|
11784 | }
|
11785 |
|
11786 | if (zoomed == true || this.abortedGraphUpdate == true) {
|
11787 | this._updateGraph();
|
11788 | }
|
11789 | else {
|
11790 |
|
11791 | if (this.lastStart != 0) {
|
11792 | var offset = this.body.range.start - this.lastStart;
|
11793 | var range = this.body.range.end - this.body.range.start;
|
11794 | if (this.width != 0) {
|
11795 | var rangePerPixelInv = this.width/range;
|
11796 | var xOffset = offset * rangePerPixelInv;
|
11797 | this.svg.style.left = (-this.width - xOffset) + "px";
|
11798 | }
|
11799 | }
|
11800 |
|
11801 | }
|
11802 |
|
11803 | this.legendLeft.redraw();
|
11804 | this.legendRight.redraw();
|
11805 |
|
11806 | return resized;
|
11807 | };
|
11808 |
|
11809 | |
11810 |
|
11811 |
|
11812 |
|
11813 | LineGraph.prototype._updateGraph = function () {
|
11814 |
|
11815 | DOMutil.prepareElements(this.svgElements);
|
11816 | if (this.width != 0 && this.itemsData != null) {
|
11817 | var group, i;
|
11818 | var preprocessedGroupData = {};
|
11819 | var processedGroupData = {};
|
11820 | var groupRanges = {};
|
11821 | var changeCalled = false;
|
11822 |
|
11823 |
|
11824 | var groupIds = [];
|
11825 | for (var groupId in this.groups) {
|
11826 | if (this.groups.hasOwnProperty(groupId)) {
|
11827 | group = this.groups[groupId];
|
11828 | if (group.visible == true && (this.options.groups.visibility[groupId] === undefined || this.options.groups.visibility[groupId] == true)) {
|
11829 | groupIds.push(groupId);
|
11830 | }
|
11831 | }
|
11832 | }
|
11833 | if (groupIds.length > 0) {
|
11834 |
|
11835 | var minDate = this.body.util.toGlobalTime(- this.body.domProps.root.width);
|
11836 | var maxDate = this.body.util.toGlobalTime(2 * this.body.domProps.root.width);
|
11837 | var groupsData = {};
|
11838 |
|
11839 | this._getRelevantData(groupIds, groupsData, minDate, maxDate);
|
11840 |
|
11841 | for (i = 0; i < groupIds.length; i++) {
|
11842 | preprocessedGroupData[groupIds[i]] = this._convertXcoordinates(groupsData[groupIds[i]]);
|
11843 | }
|
11844 |
|
11845 | this._getYRanges(groupIds, preprocessedGroupData, groupRanges);
|
11846 |
|
11847 |
|
11848 |
|
11849 | changeCalled = this._updateYAxis(groupIds, groupRanges);
|
11850 | if (changeCalled == true) {
|
11851 | DOMutil.cleanupElements(this.svgElements);
|
11852 | this.abortedGraphUpdate = true;
|
11853 | this.body.emitter.emit("change");
|
11854 | return;
|
11855 | }
|
11856 | this.abortedGraphUpdate = false;
|
11857 |
|
11858 |
|
11859 | for (i = 0; i < groupIds.length; i++) {
|
11860 | group = this.groups[groupIds[i]];
|
11861 | processedGroupData[groupIds[i]] = this._convertYcoordinates(groupsData[groupIds[i]], group);
|
11862 | }
|
11863 |
|
11864 |
|
11865 |
|
11866 | for (i = 0; i < groupIds.length; i++) {
|
11867 | group = this.groups[groupIds[i]];
|
11868 | if (group.options.style == 'line') {
|
11869 | this._drawLineGraph(processedGroupData[groupIds[i]], group);
|
11870 | }
|
11871 | }
|
11872 | this._drawBarGraphs(groupIds, processedGroupData);
|
11873 | }
|
11874 | }
|
11875 |
|
11876 |
|
11877 | DOMutil.cleanupElements(this.svgElements);
|
11878 | };
|
11879 |
|
11880 |
|
11881 | LineGraph.prototype._getRelevantData = function (groupIds, groupsData, minDate, maxDate) {
|
11882 |
|
11883 |
|
11884 |
|
11885 |
|
11886 |
|
11887 | var group, i, j, item;
|
11888 | if (groupIds.length > 0) {
|
11889 | for (i = 0; i < groupIds.length; i++) {
|
11890 | group = this.groups[groupIds[i]];
|
11891 | groupsData[groupIds[i]] = [];
|
11892 | var dataContainer = groupsData[groupIds[i]];
|
11893 |
|
11894 | if (group.options.sort == true) {
|
11895 | var guess = Math.max(0, util.binarySearchGeneric(group.itemsData, minDate, 'x', 'before'));
|
11896 | for (j = guess; j < group.itemsData.length; j++) {
|
11897 | item = group.itemsData[j];
|
11898 | if (item !== undefined) {
|
11899 | if (item.x > maxDate) {
|
11900 | dataContainer.push(item);
|
11901 | break;
|
11902 | }
|
11903 | else {
|
11904 | dataContainer.push(item);
|
11905 | }
|
11906 | }
|
11907 | }
|
11908 | }
|
11909 | else {
|
11910 | for (j = 0; j < group.itemsData.length; j++) {
|
11911 | item = group.itemsData[j];
|
11912 | if (item !== undefined) {
|
11913 | if (item.x > minDate && item.x < maxDate) {
|
11914 | dataContainer.push(item);
|
11915 | }
|
11916 | }
|
11917 | }
|
11918 | }
|
11919 | }
|
11920 | }
|
11921 |
|
11922 | this._applySampling(groupIds, groupsData);
|
11923 | };
|
11924 |
|
11925 | LineGraph.prototype._applySampling = function (groupIds, groupsData) {
|
11926 | var group;
|
11927 | if (groupIds.length > 0) {
|
11928 | for (var i = 0; i < groupIds.length; i++) {
|
11929 | group = this.groups[groupIds[i]];
|
11930 | if (group.options.sampling == true) {
|
11931 | var dataContainer = groupsData[groupIds[i]];
|
11932 | if (dataContainer.length > 0) {
|
11933 | var increment = 1;
|
11934 | var amountOfPoints = dataContainer.length;
|
11935 |
|
11936 |
|
11937 |
|
11938 | var xDistance = this.body.util.toGlobalScreen(dataContainer[dataContainer.length - 1].x) - this.body.util.toGlobalScreen(dataContainer[0].x);
|
11939 | var pointsPerPixel = amountOfPoints / xDistance;
|
11940 | increment = Math.min(Math.ceil(0.2 * amountOfPoints), Math.max(1, Math.round(pointsPerPixel)));
|
11941 |
|
11942 | var sampledData = [];
|
11943 | for (var j = 0; j < amountOfPoints; j += increment) {
|
11944 | sampledData.push(dataContainer[j]);
|
11945 |
|
11946 | }
|
11947 | groupsData[groupIds[i]] = sampledData;
|
11948 | }
|
11949 | }
|
11950 | }
|
11951 | }
|
11952 | };
|
11953 |
|
11954 | LineGraph.prototype._getYRanges = function (groupIds, groupsData, groupRanges) {
|
11955 | var groupData, group, i,j;
|
11956 | var barCombinedDataLeft = [];
|
11957 | var barCombinedDataRight = [];
|
11958 | var barCombinedData;
|
11959 | if (groupIds.length > 0) {
|
11960 | for (i = 0; i < groupIds.length; i++) {
|
11961 | groupData = groupsData[groupIds[i]];
|
11962 | if (groupData.length > 0) {
|
11963 | group = this.groups[groupIds[i]];
|
11964 | if (group.options.style == 'line' || group.options.barChart.handleOverlap != "stack") {
|
11965 | var yMin = groupData[0].y;
|
11966 | var yMax = groupData[0].y;
|
11967 | for (j = 0; j < groupData.length; j++) {
|
11968 | yMin = yMin > groupData[j].y ? groupData[j].y : yMin;
|
11969 | yMax = yMax < groupData[j].y ? groupData[j].y : yMax;
|
11970 | }
|
11971 | groupRanges[groupIds[i]] = {min: yMin, max: yMax, yAxisOrientation: group.options.yAxisOrientation};
|
11972 | }
|
11973 | else if (group.options.style == 'bar') {
|
11974 | if (group.options.yAxisOrientation == 'left') {
|
11975 | barCombinedData = barCombinedDataLeft;
|
11976 | }
|
11977 | else {
|
11978 | barCombinedData = barCombinedDataRight;
|
11979 | }
|
11980 |
|
11981 | groupRanges[groupIds[i]] = {min: 0, max: 0, yAxisOrientation: group.options.yAxisOrientation, ignore: true};
|
11982 |
|
11983 |
|
11984 | for (j = 0; j < groupData.length; j++) {
|
11985 | barCombinedData.push({
|
11986 | x: groupData[j].x,
|
11987 | y: groupData[j].y,
|
11988 | groupId: groupIds[i]
|
11989 | });
|
11990 | }
|
11991 | }
|
11992 | }
|
11993 | }
|
11994 |
|
11995 | var intersections;
|
11996 | if (barCombinedDataLeft.length > 0) {
|
11997 |
|
11998 | barCombinedDataLeft.sort(function (a, b) {
|
11999 | if (a.x == b.x) {
|
12000 | return a.groupId - b.groupId;
|
12001 | } else {
|
12002 | return a.x - b.x;
|
12003 | }
|
12004 | });
|
12005 | intersections = {};
|
12006 | this._getDataIntersections(intersections, barCombinedDataLeft);
|
12007 | groupRanges["__barchartLeft"] = this._getStackedBarYRange(intersections, barCombinedDataLeft);
|
12008 | groupRanges["__barchartLeft"].yAxisOrientation = "left";
|
12009 | groupIds.push("__barchartLeft");
|
12010 | }
|
12011 | if (barCombinedDataRight.length > 0) {
|
12012 |
|
12013 | barCombinedDataRight.sort(function (a, b) {
|
12014 | if (a.x == b.x) {
|
12015 | return a.groupId - b.groupId;
|
12016 | } else {
|
12017 | return a.x - b.x;
|
12018 | }
|
12019 | });
|
12020 | intersections = {};
|
12021 | this._getDataIntersections(intersections, barCombinedDataRight);
|
12022 | groupRanges["__barchartRight"] = this._getStackedBarYRange(intersections, barCombinedDataRight);
|
12023 | groupRanges["__barchartRight"].yAxisOrientation = "right";
|
12024 | groupIds.push("__barchartRight");
|
12025 | }
|
12026 | }
|
12027 | };
|
12028 |
|
12029 | LineGraph.prototype._getStackedBarYRange = function (intersections, combinedData) {
|
12030 | var key;
|
12031 | var yMin = combinedData[0].y;
|
12032 | var yMax = combinedData[0].y;
|
12033 | for (var i = 0; i < combinedData.length; i++) {
|
12034 | key = combinedData[i].x;
|
12035 | if (intersections[key] === undefined) {
|
12036 | yMin = yMin > combinedData[i].y ? combinedData[i].y : yMin;
|
12037 | yMax = yMax < combinedData[i].y ? combinedData[i].y : yMax;
|
12038 | }
|
12039 | else {
|
12040 | intersections[key].accumulated += combinedData[i].y;
|
12041 | }
|
12042 | }
|
12043 | for (var xpos in intersections) {
|
12044 | if (intersections.hasOwnProperty(xpos)) {
|
12045 | yMin = yMin > intersections[xpos].accumulated ? intersections[xpos].accumulated : yMin;
|
12046 | yMax = yMax < intersections[xpos].accumulated ? intersections[xpos].accumulated : yMax;
|
12047 | }
|
12048 | }
|
12049 |
|
12050 | return {min: yMin, max: yMax};
|
12051 | };
|
12052 |
|
12053 |
|
12054 | |
12055 |
|
12056 |
|
12057 |
|
12058 |
|
12059 |
|
12060 | LineGraph.prototype._updateYAxis = function (groupIds, groupRanges) {
|
12061 | var changeCalled = false;
|
12062 | var yAxisLeftUsed = false;
|
12063 | var yAxisRightUsed = false;
|
12064 | var minLeft = 1e9, minRight = 1e9, maxLeft = -1e9, maxRight = -1e9, minVal, maxVal;
|
12065 |
|
12066 | if (groupIds.length > 0) {
|
12067 | for (var i = 0; i < groupIds.length; i++) {
|
12068 | if (groupRanges.hasOwnProperty(groupIds[i])) {
|
12069 | if (groupRanges[groupIds[i]].ignore !== true) {
|
12070 | minVal = groupRanges[groupIds[i]].min;
|
12071 | maxVal = groupRanges[groupIds[i]].max;
|
12072 |
|
12073 | if (groupRanges[groupIds[i]].yAxisOrientation == 'left') {
|
12074 | yAxisLeftUsed = true;
|
12075 | minLeft = minLeft > minVal ? minVal : minLeft;
|
12076 | maxLeft = maxLeft < maxVal ? maxVal : maxLeft;
|
12077 | }
|
12078 | else {
|
12079 | yAxisRightUsed = true;
|
12080 | minRight = minRight > minVal ? minVal : minRight;
|
12081 | maxRight = maxRight < maxVal ? maxVal : maxRight;
|
12082 | }
|
12083 | }
|
12084 | }
|
12085 | }
|
12086 |
|
12087 | if (yAxisLeftUsed == true) {
|
12088 | this.yAxisLeft.setRange(minLeft, maxLeft);
|
12089 | }
|
12090 | if (yAxisRightUsed == true) {
|
12091 | this.yAxisRight.setRange(minRight, maxRight);
|
12092 | }
|
12093 | }
|
12094 |
|
12095 | changeCalled = this._toggleAxisVisiblity(yAxisLeftUsed , this.yAxisLeft) || changeCalled;
|
12096 | changeCalled = this._toggleAxisVisiblity(yAxisRightUsed, this.yAxisRight) || changeCalled;
|
12097 |
|
12098 | if (yAxisRightUsed == true && yAxisLeftUsed == true) {
|
12099 | this.yAxisLeft.drawIcons = true;
|
12100 | this.yAxisRight.drawIcons = true;
|
12101 | }
|
12102 | else {
|
12103 | this.yAxisLeft.drawIcons = false;
|
12104 | this.yAxisRight.drawIcons = false;
|
12105 | }
|
12106 |
|
12107 | this.yAxisRight.master = !yAxisLeftUsed;
|
12108 |
|
12109 | if (this.yAxisRight.master == false) {
|
12110 | if (yAxisRightUsed == true) {this.yAxisLeft.lineOffset = this.yAxisRight.width;}
|
12111 | else {this.yAxisLeft.lineOffset = 0;}
|
12112 |
|
12113 | changeCalled = this.yAxisLeft.redraw() || changeCalled;
|
12114 | this.yAxisRight.stepPixelsForced = this.yAxisLeft.stepPixels;
|
12115 | changeCalled = this.yAxisRight.redraw() || changeCalled;
|
12116 | }
|
12117 | else {
|
12118 | changeCalled = this.yAxisRight.redraw() || changeCalled;
|
12119 | }
|
12120 |
|
12121 |
|
12122 | if (groupIds.indexOf("__barchartLeft") != -1) {
|
12123 | groupIds.splice(groupIds.indexOf("__barchartLeft"),1);
|
12124 | }
|
12125 | if (groupIds.indexOf("__barchartRight") != -1) {
|
12126 | groupIds.splice(groupIds.indexOf("__barchartRight"),1);
|
12127 | }
|
12128 |
|
12129 | return changeCalled;
|
12130 | };
|
12131 |
|
12132 | |
12133 |
|
12134 |
|
12135 |
|
12136 |
|
12137 |
|
12138 |
|
12139 |
|
12140 | LineGraph.prototype._toggleAxisVisiblity = function (axisUsed, axis) {
|
12141 | var changed = false;
|
12142 | if (axisUsed == false) {
|
12143 | if (axis.dom.frame.parentNode) {
|
12144 | axis.hide();
|
12145 | changed = true;
|
12146 | }
|
12147 | }
|
12148 | else {
|
12149 | if (!axis.dom.frame.parentNode) {
|
12150 | axis.show();
|
12151 | changed = true;
|
12152 | }
|
12153 | }
|
12154 | return changed;
|
12155 | };
|
12156 |
|
12157 |
|
12158 | |
12159 |
|
12160 |
|
12161 |
|
12162 |
|
12163 |
|
12164 | LineGraph.prototype._drawBarGraphs = function (groupIds, processedGroupData) {
|
12165 | var combinedData = [];
|
12166 | var intersections = {};
|
12167 | var coreDistance;
|
12168 | var key, drawData;
|
12169 | var group;
|
12170 | var i,j;
|
12171 | var barPoints = 0;
|
12172 |
|
12173 |
|
12174 | for (i = 0; i < groupIds.length; i++) {
|
12175 | group = this.groups[groupIds[i]];
|
12176 | if (group.options.style == 'bar') {
|
12177 | if (group.visible == true && (this.options.groups.visibility[groupIds[i]] === undefined || this.options.groups.visibility[groupIds[i]] == true)) {
|
12178 | for (j = 0; j < processedGroupData[groupIds[i]].length; j++) {
|
12179 | combinedData.push({
|
12180 | x: processedGroupData[groupIds[i]][j].x,
|
12181 | y: processedGroupData[groupIds[i]][j].y,
|
12182 | groupId: groupIds[i]
|
12183 | });
|
12184 | barPoints += 1;
|
12185 | }
|
12186 | }
|
12187 | }
|
12188 | }
|
12189 |
|
12190 | if (barPoints == 0) {return;}
|
12191 |
|
12192 |
|
12193 | combinedData.sort(function (a, b) {
|
12194 | if (a.x == b.x) {
|
12195 | return a.groupId - b.groupId;
|
12196 | } else {
|
12197 | return a.x - b.x;
|
12198 | }
|
12199 | });
|
12200 |
|
12201 |
|
12202 | this._getDataIntersections(intersections, combinedData);
|
12203 |
|
12204 |
|
12205 | for (i = 0; i < combinedData.length; i++) {
|
12206 | group = this.groups[combinedData[i].groupId];
|
12207 | var minWidth = 0.1 * group.options.barChart.width;
|
12208 |
|
12209 | key = combinedData[i].x;
|
12210 | var heightOffset = 0;
|
12211 | if (intersections[key] === undefined) {
|
12212 | if (i+1 < combinedData.length) {coreDistance = Math.abs(combinedData[i+1].x - key);}
|
12213 | if (i > 0) {coreDistance = Math.min(coreDistance,Math.abs(combinedData[i-1].x - key));}
|
12214 | drawData = this._getSafeDrawData(coreDistance, group, minWidth);
|
12215 | }
|
12216 | else {
|
12217 | var nextKey = i + (intersections[key].amount - intersections[key].resolved);
|
12218 | var prevKey = i - (intersections[key].resolved + 1);
|
12219 | if (nextKey < combinedData.length) {coreDistance = Math.abs(combinedData[nextKey].x - key);}
|
12220 | if (prevKey > 0) {coreDistance = Math.min(coreDistance,Math.abs(combinedData[prevKey].x - key));}
|
12221 | drawData = this._getSafeDrawData(coreDistance, group, minWidth);
|
12222 | intersections[key].resolved += 1;
|
12223 |
|
12224 | if (group.options.barChart.handleOverlap == 'stack') {
|
12225 | heightOffset = intersections[key].accumulated;
|
12226 | intersections[key].accumulated += group.zeroPosition - combinedData[i].y;
|
12227 | }
|
12228 | else if (group.options.barChart.handleOverlap == 'sideBySide') {
|
12229 | drawData.width = drawData.width / intersections[key].amount;
|
12230 | drawData.offset += (intersections[key].resolved) * drawData.width - (0.5*drawData.width * (intersections[key].amount+1));
|
12231 | if (group.options.barChart.align == 'left') {drawData.offset -= 0.5*drawData.width;}
|
12232 | else if (group.options.barChart.align == 'right') {drawData.offset += 0.5*drawData.width;}
|
12233 | }
|
12234 | }
|
12235 | DOMutil.drawBar(combinedData[i].x + drawData.offset, combinedData[i].y - heightOffset, drawData.width, group.zeroPosition - combinedData[i].y, group.className + ' bar', this.svgElements, this.svg);
|
12236 |
|
12237 | if (group.options.drawPoints.enabled == true) {
|
12238 | DOMutil.drawPoint(combinedData[i].x + drawData.offset, combinedData[i].y - heightOffset, group, this.svgElements, this.svg);
|
12239 | }
|
12240 | }
|
12241 | };
|
12242 |
|
12243 | |
12244 |
|
12245 |
|
12246 |
|
12247 |
|
12248 |
|
12249 | LineGraph.prototype._getDataIntersections = function (intersections, combinedData) {
|
12250 |
|
12251 | var coreDistance;
|
12252 | for (var i = 0; i < combinedData.length; i++) {
|
12253 | if (i + 1 < combinedData.length) {
|
12254 | coreDistance = Math.abs(combinedData[i + 1].x - combinedData[i].x);
|
12255 | }
|
12256 | if (i > 0) {
|
12257 | coreDistance = Math.min(coreDistance, Math.abs(combinedData[i - 1].x - combinedData[i].x));
|
12258 | }
|
12259 | if (coreDistance == 0) {
|
12260 | if (intersections[combinedData[i].x] === undefined) {
|
12261 | intersections[combinedData[i].x] = {amount: 0, resolved: 0, accumulated: 0};
|
12262 | }
|
12263 | intersections[combinedData[i].x].amount += 1;
|
12264 | }
|
12265 | }
|
12266 | };
|
12267 |
|
12268 | |
12269 |
|
12270 |
|
12271 |
|
12272 |
|
12273 |
|
12274 |
|
12275 |
|
12276 |
|
12277 | LineGraph.prototype._getSafeDrawData = function (coreDistance, group, minWidth) {
|
12278 | var width, offset;
|
12279 | if (coreDistance < group.options.barChart.width && coreDistance > 0) {
|
12280 | width = coreDistance < minWidth ? minWidth : coreDistance;
|
12281 |
|
12282 | offset = 0;
|
12283 | if (group.options.barChart.align == 'left') {
|
12284 | offset -= 0.5 * coreDistance;
|
12285 | }
|
12286 | else if (group.options.barChart.align == 'right') {
|
12287 | offset += 0.5 * coreDistance;
|
12288 | }
|
12289 | }
|
12290 | else {
|
12291 |
|
12292 | width = group.options.barChart.width;
|
12293 | offset = 0;
|
12294 | if (group.options.barChart.align == 'left') {
|
12295 | offset -= 0.5 * group.options.barChart.width;
|
12296 | }
|
12297 | else if (group.options.barChart.align == 'right') {
|
12298 | offset += 0.5 * group.options.barChart.width;
|
12299 | }
|
12300 | }
|
12301 |
|
12302 | return {width: width, offset: offset};
|
12303 | };
|
12304 |
|
12305 |
|
12306 | |
12307 |
|
12308 |
|
12309 |
|
12310 |
|
12311 |
|
12312 | LineGraph.prototype._drawLineGraph = function (dataset, group) {
|
12313 | if (dataset != null) {
|
12314 | if (dataset.length > 0) {
|
12315 | var path, d;
|
12316 | var svgHeight = Number(this.svg.style.height.replace("px",""));
|
12317 | path = DOMutil.getSVGElement('path', this.svgElements, this.svg);
|
12318 | path.setAttributeNS(null, "class", group.className);
|
12319 |
|
12320 |
|
12321 | if (group.options.catmullRom.enabled == true) {
|
12322 | d = this._catmullRom(dataset, group);
|
12323 | }
|
12324 | else {
|
12325 | d = this._linear(dataset);
|
12326 | }
|
12327 |
|
12328 |
|
12329 | if (group.options.shaded.enabled == true) {
|
12330 | var fillPath = DOMutil.getSVGElement('path',this.svgElements, this.svg);
|
12331 | var dFill;
|
12332 | if (group.options.shaded.orientation == 'top') {
|
12333 | dFill = "M" + dataset[0].x + "," + 0 + " " + d + "L" + dataset[dataset.length - 1].x + "," + 0;
|
12334 | }
|
12335 | else {
|
12336 | dFill = "M" + dataset[0].x + "," + svgHeight + " " + d + "L" + dataset[dataset.length - 1].x + "," + svgHeight;
|
12337 | }
|
12338 | fillPath.setAttributeNS(null, "class", group.className + " fill");
|
12339 | fillPath.setAttributeNS(null, "d", dFill);
|
12340 | }
|
12341 |
|
12342 | path.setAttributeNS(null, "d", "M" + d);
|
12343 |
|
12344 |
|
12345 | if (group.options.drawPoints.enabled == true) {
|
12346 | this._drawPoints(dataset, group, this.svgElements, this.svg);
|
12347 | }
|
12348 | }
|
12349 | }
|
12350 | };
|
12351 |
|
12352 | |
12353 |
|
12354 |
|
12355 |
|
12356 |
|
12357 |
|
12358 |
|
12359 |
|
12360 |
|
12361 | LineGraph.prototype._drawPoints = function (dataset, group, JSONcontainer, svg, offset) {
|
12362 | if (offset === undefined) {offset = 0;}
|
12363 | for (var i = 0; i < dataset.length; i++) {
|
12364 | DOMutil.drawPoint(dataset[i].x + offset, dataset[i].y, group, JSONcontainer, svg);
|
12365 | }
|
12366 | };
|
12367 |
|
12368 |
|
12369 |
|
12370 | |
12371 |
|
12372 |
|
12373 |
|
12374 |
|
12375 |
|
12376 |
|
12377 |
|
12378 |
|
12379 | LineGraph.prototype._convertXcoordinates = function (datapoints) {
|
12380 | var extractedData = [];
|
12381 | var xValue, yValue;
|
12382 | var toScreen = this.body.util.toScreen;
|
12383 |
|
12384 | for (var i = 0; i < datapoints.length; i++) {
|
12385 | xValue = toScreen(datapoints[i].x) + this.width;
|
12386 | yValue = datapoints[i].y;
|
12387 | extractedData.push({x: xValue, y: yValue});
|
12388 | }
|
12389 |
|
12390 | return extractedData;
|
12391 | };
|
12392 |
|
12393 |
|
12394 |
|
12395 | |
12396 |
|
12397 |
|
12398 |
|
12399 |
|
12400 |
|
12401 |
|
12402 |
|
12403 |
|
12404 | LineGraph.prototype._convertYcoordinates = function (datapoints, group) {
|
12405 | var extractedData = [];
|
12406 | var xValue, yValue;
|
12407 | var toScreen = this.body.util.toScreen;
|
12408 | var axis = this.yAxisLeft;
|
12409 | var svgHeight = Number(this.svg.style.height.replace("px",""));
|
12410 | if (group.options.yAxisOrientation == 'right') {
|
12411 | axis = this.yAxisRight;
|
12412 | }
|
12413 |
|
12414 | for (var i = 0; i < datapoints.length; i++) {
|
12415 | xValue = toScreen(datapoints[i].x) + this.width;
|
12416 | yValue = Math.round(axis.convertValue(datapoints[i].y));
|
12417 | extractedData.push({x: xValue, y: yValue});
|
12418 | }
|
12419 |
|
12420 | group.setZeroPosition(Math.min(svgHeight, axis.convertValue(0)));
|
12421 |
|
12422 | return extractedData;
|
12423 | };
|
12424 |
|
12425 | |
12426 |
|
12427 |
|
12428 |
|
12429 |
|
12430 |
|
12431 |
|
12432 | LineGraph.prototype._catmullRomUniform = function(data) {
|
12433 |
|
12434 | var p0, p1, p2, p3, bp1, bp2;
|
12435 | var d = Math.round(data[0].x) + "," + Math.round(data[0].y) + " ";
|
12436 | var normalization = 1/6;
|
12437 | var length = data.length;
|
12438 | for (var i = 0; i < length - 1; i++) {
|
12439 |
|
12440 | p0 = (i == 0) ? data[0] : data[i-1];
|
12441 | p1 = data[i];
|
12442 | p2 = data[i+1];
|
12443 | p3 = (i + 2 < length) ? data[i+2] : p2;
|
12444 |
|
12445 |
|
12446 |
|
12447 |
|
12448 |
|
12449 |
|
12450 |
|
12451 |
|
12452 |
|
12453 | bp1 = { x: ((-p0.x + 6*p1.x + p2.x) *normalization), y: ((-p0.y + 6*p1.y + p2.y) *normalization)};
|
12454 | bp2 = { x: (( p1.x + 6*p2.x - p3.x) *normalization), y: (( p1.y + 6*p2.y - p3.y) *normalization)};
|
12455 |
|
12456 |
|
12457 | d += "C" +
|
12458 | bp1.x + "," +
|
12459 | bp1.y + " " +
|
12460 | bp2.x + "," +
|
12461 | bp2.y + " " +
|
12462 | p2.x + "," +
|
12463 | p2.y + " ";
|
12464 | }
|
12465 |
|
12466 | return d;
|
12467 | };
|
12468 |
|
12469 | |
12470 |
|
12471 |
|
12472 |
|
12473 |
|
12474 |
|
12475 |
|
12476 |
|
12477 |
|
12478 |
|
12479 | LineGraph.prototype._catmullRom = function(data, group) {
|
12480 | var alpha = group.options.catmullRom.alpha;
|
12481 | if (alpha == 0 || alpha === undefined) {
|
12482 | return this._catmullRomUniform(data);
|
12483 | }
|
12484 | else {
|
12485 | var p0, p1, p2, p3, bp1, bp2, d1,d2,d3, A, B, N, M;
|
12486 | var d3powA, d2powA, d3pow2A, d2pow2A, d1pow2A, d1powA;
|
12487 | var d = Math.round(data[0].x) + "," + Math.round(data[0].y) + " ";
|
12488 | var length = data.length;
|
12489 | for (var i = 0; i < length - 1; i++) {
|
12490 |
|
12491 | p0 = (i == 0) ? data[0] : data[i-1];
|
12492 | p1 = data[i];
|
12493 | p2 = data[i+1];
|
12494 | p3 = (i + 2 < length) ? data[i+2] : p2;
|
12495 |
|
12496 | d1 = Math.sqrt(Math.pow(p0.x - p1.x,2) + Math.pow(p0.y - p1.y,2));
|
12497 | d2 = Math.sqrt(Math.pow(p1.x - p2.x,2) + Math.pow(p1.y - p2.y,2));
|
12498 | d3 = Math.sqrt(Math.pow(p2.x - p3.x,2) + Math.pow(p2.y - p3.y,2));
|
12499 |
|
12500 |
|
12501 |
|
12502 |
|
12503 |
|
12504 |
|
12505 |
|
12506 |
|
12507 |
|
12508 |
|
12509 |
|
12510 |
|
12511 |
|
12512 |
|
12513 |
|
12514 |
|
12515 | d3powA = Math.pow(d3, alpha);
|
12516 | d3pow2A = Math.pow(d3,2*alpha);
|
12517 | d2powA = Math.pow(d2, alpha);
|
12518 | d2pow2A = Math.pow(d2,2*alpha);
|
12519 | d1powA = Math.pow(d1, alpha);
|
12520 | d1pow2A = Math.pow(d1,2*alpha);
|
12521 |
|
12522 | A = 2*d1pow2A + 3*d1powA * d2powA + d2pow2A;
|
12523 | B = 2*d3pow2A + 3*d3powA * d2powA + d2pow2A;
|
12524 | N = 3*d1powA * (d1powA + d2powA);
|
12525 | if (N > 0) {N = 1 / N;}
|
12526 | M = 3*d3powA * (d3powA + d2powA);
|
12527 | if (M > 0) {M = 1 / M;}
|
12528 |
|
12529 | bp1 = { x: ((-d2pow2A * p0.x + A*p1.x + d1pow2A * p2.x) * N),
|
12530 | y: ((-d2pow2A * p0.y + A*p1.y + d1pow2A * p2.y) * N)};
|
12531 |
|
12532 | bp2 = { x: (( d3pow2A * p1.x + B*p2.x - d2pow2A * p3.x) * M),
|
12533 | y: (( d3pow2A * p1.y + B*p2.y - d2pow2A * p3.y) * M)};
|
12534 |
|
12535 | if (bp1.x == 0 && bp1.y == 0) {bp1 = p1;}
|
12536 | if (bp2.x == 0 && bp2.y == 0) {bp2 = p2;}
|
12537 | d += "C" +
|
12538 | bp1.x + "," +
|
12539 | bp1.y + " " +
|
12540 | bp2.x + "," +
|
12541 | bp2.y + " " +
|
12542 | p2.x + "," +
|
12543 | p2.y + " ";
|
12544 | }
|
12545 |
|
12546 | return d;
|
12547 | }
|
12548 | };
|
12549 |
|
12550 | |
12551 |
|
12552 |
|
12553 |
|
12554 |
|
12555 |
|
12556 | LineGraph.prototype._linear = function(data) {
|
12557 |
|
12558 | var d = "";
|
12559 | for (var i = 0; i < data.length; i++) {
|
12560 | if (i == 0) {
|
12561 | d += data[i].x + "," + data[i].y;
|
12562 | }
|
12563 | else {
|
12564 | d += " " + data[i].x + "," + data[i].y;
|
12565 | }
|
12566 | }
|
12567 | return d;
|
12568 | };
|
12569 |
|
12570 | module.exports = LineGraph;
|
12571 |
|
12572 |
|
12573 | },
|
12574 |
|
12575 | function(module, exports, __webpack_require__) {
|
12576 |
|
12577 | var util = __webpack_require__(1);
|
12578 | var Component = __webpack_require__(18);
|
12579 | var TimeStep = __webpack_require__(17);
|
12580 | var moment = __webpack_require__(41);
|
12581 |
|
12582 | |
12583 |
|
12584 |
|
12585 |
|
12586 |
|
12587 |
|
12588 |
|
12589 |
|
12590 | function TimeAxis (body, options) {
|
12591 | this.dom = {
|
12592 | foreground: null,
|
12593 | majorLines: [],
|
12594 | majorTexts: [],
|
12595 | minorLines: [],
|
12596 | minorTexts: [],
|
12597 | redundant: {
|
12598 | majorLines: [],
|
12599 | majorTexts: [],
|
12600 | minorLines: [],
|
12601 | minorTexts: []
|
12602 | }
|
12603 | };
|
12604 | this.props = {
|
12605 | range: {
|
12606 | start: 0,
|
12607 | end: 0,
|
12608 | minimumStep: 0
|
12609 | },
|
12610 | lineTop: 0
|
12611 | };
|
12612 |
|
12613 | this.defaultOptions = {
|
12614 | orientation: 'bottom',
|
12615 |
|
12616 | showMinorLabels: true,
|
12617 | showMajorLabels: true
|
12618 | };
|
12619 | this.options = util.extend({}, this.defaultOptions);
|
12620 |
|
12621 | this.body = body;
|
12622 |
|
12623 |
|
12624 | this._create();
|
12625 |
|
12626 | this.setOptions(options);
|
12627 | }
|
12628 |
|
12629 | TimeAxis.prototype = new Component();
|
12630 |
|
12631 | |
12632 |
|
12633 |
|
12634 |
|
12635 |
|
12636 |
|
12637 |
|
12638 |
|
12639 | TimeAxis.prototype.setOptions = function(options) {
|
12640 | if (options) {
|
12641 |
|
12642 | util.selectiveExtend(['orientation', 'showMinorLabels', 'showMajorLabels'], this.options, options);
|
12643 |
|
12644 |
|
12645 |
|
12646 | if ('locale' in options) {
|
12647 | if (typeof moment.locale === 'function') {
|
12648 |
|
12649 | moment.locale(options.locale);
|
12650 | }
|
12651 | else {
|
12652 | moment.lang(options.locale);
|
12653 | }
|
12654 | }
|
12655 | }
|
12656 | };
|
12657 |
|
12658 | |
12659 |
|
12660 |
|
12661 | TimeAxis.prototype._create = function() {
|
12662 | this.dom.foreground = document.createElement('div');
|
12663 | this.dom.background = document.createElement('div');
|
12664 |
|
12665 | this.dom.foreground.className = 'timeaxis foreground';
|
12666 | this.dom.background.className = 'timeaxis background';
|
12667 | };
|
12668 |
|
12669 | |
12670 |
|
12671 |
|
12672 | TimeAxis.prototype.destroy = function() {
|
12673 |
|
12674 | if (this.dom.foreground.parentNode) {
|
12675 | this.dom.foreground.parentNode.removeChild(this.dom.foreground);
|
12676 | }
|
12677 | if (this.dom.background.parentNode) {
|
12678 | this.dom.background.parentNode.removeChild(this.dom.background);
|
12679 | }
|
12680 |
|
12681 | this.body = null;
|
12682 | };
|
12683 |
|
12684 | |
12685 |
|
12686 |
|
12687 |
|
12688 | TimeAxis.prototype.redraw = function () {
|
12689 | var options = this.options,
|
12690 | props = this.props,
|
12691 | foreground = this.dom.foreground,
|
12692 | background = this.dom.background;
|
12693 |
|
12694 |
|
12695 | var parent = (options.orientation == 'top') ? this.body.dom.top : this.body.dom.bottom;
|
12696 | var parentChanged = (foreground.parentNode !== parent);
|
12697 |
|
12698 |
|
12699 | this._calculateCharSize();
|
12700 |
|
12701 |
|
12702 | var orientation = this.options.orientation,
|
12703 | showMinorLabels = this.options.showMinorLabels,
|
12704 | showMajorLabels = this.options.showMajorLabels;
|
12705 |
|
12706 |
|
12707 | props.minorLabelHeight = showMinorLabels ? props.minorCharHeight : 0;
|
12708 | props.majorLabelHeight = showMajorLabels ? props.majorCharHeight : 0;
|
12709 | props.height = props.minorLabelHeight + props.majorLabelHeight;
|
12710 | props.width = foreground.offsetWidth;
|
12711 |
|
12712 | props.minorLineHeight = this.body.domProps.root.height - props.majorLabelHeight -
|
12713 | (options.orientation == 'top' ? this.body.domProps.bottom.height : this.body.domProps.top.height);
|
12714 | props.minorLineWidth = 1;
|
12715 | props.majorLineHeight = props.minorLineHeight + props.majorLabelHeight;
|
12716 | props.majorLineWidth = 1;
|
12717 |
|
12718 |
|
12719 | var foregroundNextSibling = foreground.nextSibling;
|
12720 | var backgroundNextSibling = background.nextSibling;
|
12721 | foreground.parentNode && foreground.parentNode.removeChild(foreground);
|
12722 | background.parentNode && background.parentNode.removeChild(background);
|
12723 |
|
12724 | foreground.style.height = this.props.height + 'px';
|
12725 |
|
12726 | this._repaintLabels();
|
12727 |
|
12728 |
|
12729 | if (foregroundNextSibling) {
|
12730 | parent.insertBefore(foreground, foregroundNextSibling);
|
12731 | }
|
12732 | else {
|
12733 | parent.appendChild(foreground)
|
12734 | }
|
12735 | if (backgroundNextSibling) {
|
12736 | this.body.dom.backgroundVertical.insertBefore(background, backgroundNextSibling);
|
12737 | }
|
12738 | else {
|
12739 | this.body.dom.backgroundVertical.appendChild(background)
|
12740 | }
|
12741 |
|
12742 | return this._isResized() || parentChanged;
|
12743 | };
|
12744 |
|
12745 | |
12746 |
|
12747 |
|
12748 |
|
12749 | TimeAxis.prototype._repaintLabels = function () {
|
12750 | var orientation = this.options.orientation;
|
12751 |
|
12752 |
|
12753 | var start = util.convert(this.body.range.start, 'Number'),
|
12754 | end = util.convert(this.body.range.end, 'Number'),
|
12755 | minimumStep = this.body.util.toTime((this.props.minorCharWidth || 10) * 7).valueOf()
|
12756 | -this.body.util.toTime(0).valueOf();
|
12757 | var step = new TimeStep(new Date(start), new Date(end), minimumStep);
|
12758 | this.step = step;
|
12759 |
|
12760 |
|
12761 |
|
12762 |
|
12763 | var dom = this.dom;
|
12764 | dom.redundant.majorLines = dom.majorLines;
|
12765 | dom.redundant.majorTexts = dom.majorTexts;
|
12766 | dom.redundant.minorLines = dom.minorLines;
|
12767 | dom.redundant.minorTexts = dom.minorTexts;
|
12768 | dom.majorLines = [];
|
12769 | dom.majorTexts = [];
|
12770 | dom.minorLines = [];
|
12771 | dom.minorTexts = [];
|
12772 |
|
12773 | step.first();
|
12774 | var xFirstMajorLabel = undefined;
|
12775 | var max = 0;
|
12776 | while (step.hasNext() && max < 1000) {
|
12777 | max++;
|
12778 | var cur = step.getCurrent(),
|
12779 | x = this.body.util.toScreen(cur),
|
12780 | isMajor = step.isMajor();
|
12781 |
|
12782 |
|
12783 |
|
12784 | if (this.options.showMinorLabels) {
|
12785 | this._repaintMinorText(x, step.getLabelMinor(), orientation);
|
12786 | }
|
12787 |
|
12788 | if (isMajor && this.options.showMajorLabels) {
|
12789 | if (x > 0) {
|
12790 | if (xFirstMajorLabel == undefined) {
|
12791 | xFirstMajorLabel = x;
|
12792 | }
|
12793 | this._repaintMajorText(x, step.getLabelMajor(), orientation);
|
12794 | }
|
12795 | this._repaintMajorLine(x, orientation);
|
12796 | }
|
12797 | else {
|
12798 | this._repaintMinorLine(x, orientation);
|
12799 | }
|
12800 |
|
12801 | step.next();
|
12802 | }
|
12803 |
|
12804 |
|
12805 | if (this.options.showMajorLabels) {
|
12806 | var leftTime = this.body.util.toTime(0),
|
12807 | leftText = step.getLabelMajor(leftTime),
|
12808 | widthText = leftText.length * (this.props.majorCharWidth || 10) + 10;
|
12809 |
|
12810 | if (xFirstMajorLabel == undefined || widthText < xFirstMajorLabel) {
|
12811 | this._repaintMajorText(0, leftText, orientation);
|
12812 | }
|
12813 | }
|
12814 |
|
12815 |
|
12816 | util.forEach(this.dom.redundant, function (arr) {
|
12817 | while (arr.length) {
|
12818 | var elem = arr.pop();
|
12819 | if (elem && elem.parentNode) {
|
12820 | elem.parentNode.removeChild(elem);
|
12821 | }
|
12822 | }
|
12823 | });
|
12824 | };
|
12825 |
|
12826 | |
12827 |
|
12828 |
|
12829 |
|
12830 |
|
12831 |
|
12832 |
|
12833 | TimeAxis.prototype._repaintMinorText = function (x, text, orientation) {
|
12834 |
|
12835 | var label = this.dom.redundant.minorTexts.shift();
|
12836 |
|
12837 | if (!label) {
|
12838 |
|
12839 | var content = document.createTextNode('');
|
12840 | label = document.createElement('div');
|
12841 | label.appendChild(content);
|
12842 | label.className = 'text minor';
|
12843 | this.dom.foreground.appendChild(label);
|
12844 | }
|
12845 | this.dom.minorTexts.push(label);
|
12846 |
|
12847 | label.childNodes[0].nodeValue = text;
|
12848 |
|
12849 | label.style.top = (orientation == 'top') ? (this.props.majorLabelHeight + 'px') : '0';
|
12850 | label.style.left = x + 'px';
|
12851 |
|
12852 | };
|
12853 |
|
12854 | |
12855 |
|
12856 |
|
12857 |
|
12858 |
|
12859 |
|
12860 |
|
12861 | TimeAxis.prototype._repaintMajorText = function (x, text, orientation) {
|
12862 |
|
12863 | var label = this.dom.redundant.majorTexts.shift();
|
12864 |
|
12865 | if (!label) {
|
12866 |
|
12867 | var content = document.createTextNode(text);
|
12868 | label = document.createElement('div');
|
12869 | label.className = 'text major';
|
12870 | label.appendChild(content);
|
12871 | this.dom.foreground.appendChild(label);
|
12872 | }
|
12873 | this.dom.majorTexts.push(label);
|
12874 |
|
12875 | label.childNodes[0].nodeValue = text;
|
12876 |
|
12877 |
|
12878 | label.style.top = (orientation == 'top') ? '0' : (this.props.minorLabelHeight + 'px');
|
12879 | label.style.left = x + 'px';
|
12880 | };
|
12881 |
|
12882 | |
12883 |
|
12884 |
|
12885 |
|
12886 |
|
12887 |
|
12888 | TimeAxis.prototype._repaintMinorLine = function (x, orientation) {
|
12889 |
|
12890 | var line = this.dom.redundant.minorLines.shift();
|
12891 |
|
12892 | if (!line) {
|
12893 |
|
12894 | line = document.createElement('div');
|
12895 | line.className = 'grid vertical minor';
|
12896 | this.dom.background.appendChild(line);
|
12897 | }
|
12898 | this.dom.minorLines.push(line);
|
12899 |
|
12900 | var props = this.props;
|
12901 | if (orientation == 'top') {
|
12902 | line.style.top = props.majorLabelHeight + 'px';
|
12903 | }
|
12904 | else {
|
12905 | line.style.top = this.body.domProps.top.height + 'px';
|
12906 | }
|
12907 | line.style.height = props.minorLineHeight + 'px';
|
12908 | line.style.left = (x - props.minorLineWidth / 2) + 'px';
|
12909 | };
|
12910 |
|
12911 | |
12912 |
|
12913 |
|
12914 |
|
12915 |
|
12916 |
|
12917 | TimeAxis.prototype._repaintMajorLine = function (x, orientation) {
|
12918 |
|
12919 | var line = this.dom.redundant.majorLines.shift();
|
12920 |
|
12921 | if (!line) {
|
12922 |
|
12923 | line = document.createElement('DIV');
|
12924 | line.className = 'grid vertical major';
|
12925 | this.dom.background.appendChild(line);
|
12926 | }
|
12927 | this.dom.majorLines.push(line);
|
12928 |
|
12929 | var props = this.props;
|
12930 | if (orientation == 'top') {
|
12931 | line.style.top = '0';
|
12932 | }
|
12933 | else {
|
12934 | line.style.top = this.body.domProps.top.height + 'px';
|
12935 | }
|
12936 | line.style.left = (x - props.majorLineWidth / 2) + 'px';
|
12937 | line.style.height = props.majorLineHeight + 'px';
|
12938 | };
|
12939 |
|
12940 | |
12941 |
|
12942 |
|
12943 |
|
12944 |
|
12945 | TimeAxis.prototype._calculateCharSize = function () {
|
12946 |
|
12947 |
|
12948 |
|
12949 |
|
12950 | if (!this.dom.measureCharMinor) {
|
12951 | this.dom.measureCharMinor = document.createElement('DIV');
|
12952 | this.dom.measureCharMinor.className = 'text minor measure';
|
12953 | this.dom.measureCharMinor.style.position = 'absolute';
|
12954 |
|
12955 | this.dom.measureCharMinor.appendChild(document.createTextNode('0'));
|
12956 | this.dom.foreground.appendChild(this.dom.measureCharMinor);
|
12957 | }
|
12958 | this.props.minorCharHeight = this.dom.measureCharMinor.clientHeight;
|
12959 | this.props.minorCharWidth = this.dom.measureCharMinor.clientWidth;
|
12960 |
|
12961 |
|
12962 | if (!this.dom.measureCharMajor) {
|
12963 | this.dom.measureCharMajor = document.createElement('DIV');
|
12964 | this.dom.measureCharMajor.className = 'text minor measure';
|
12965 | this.dom.measureCharMajor.style.position = 'absolute';
|
12966 |
|
12967 | this.dom.measureCharMajor.appendChild(document.createTextNode('0'));
|
12968 | this.dom.foreground.appendChild(this.dom.measureCharMajor);
|
12969 | }
|
12970 | this.props.majorCharHeight = this.dom.measureCharMajor.clientHeight;
|
12971 | this.props.majorCharWidth = this.dom.measureCharMajor.clientWidth;
|
12972 | };
|
12973 |
|
12974 | |
12975 |
|
12976 |
|
12977 |
|
12978 |
|
12979 |
|
12980 | TimeAxis.prototype.snap = function(date) {
|
12981 | return this.step.snap(date);
|
12982 | };
|
12983 |
|
12984 | module.exports = TimeAxis;
|
12985 |
|
12986 |
|
12987 | },
|
12988 |
|
12989 | function(module, exports, __webpack_require__) {
|
12990 |
|
12991 | var Hammer = __webpack_require__(42);
|
12992 |
|
12993 | |
12994 |
|
12995 |
|
12996 |
|
12997 |
|
12998 |
|
12999 |
|
13000 |
|
13001 |
|
13002 | function Item (data, conversion, options) {
|
13003 | this.id = null;
|
13004 | this.parent = null;
|
13005 | this.data = data;
|
13006 | this.dom = null;
|
13007 | this.conversion = conversion || {};
|
13008 | this.options = options || {};
|
13009 |
|
13010 | this.selected = false;
|
13011 | this.displayed = false;
|
13012 | this.dirty = true;
|
13013 |
|
13014 | this.top = null;
|
13015 | this.left = null;
|
13016 | this.width = null;
|
13017 | this.height = null;
|
13018 | }
|
13019 |
|
13020 | |
13021 |
|
13022 |
|
13023 | Item.prototype.select = function() {
|
13024 | this.selected = true;
|
13025 | this.dirty = true;
|
13026 | if (this.displayed) this.redraw();
|
13027 | };
|
13028 |
|
13029 | |
13030 |
|
13031 |
|
13032 | Item.prototype.unselect = function() {
|
13033 | this.selected = false;
|
13034 | this.dirty = true;
|
13035 | if (this.displayed) this.redraw();
|
13036 | };
|
13037 |
|
13038 | |
13039 |
|
13040 |
|
13041 |
|
13042 |
|
13043 | Item.prototype.setData = function(data) {
|
13044 | this.data = data;
|
13045 | this.dirty = true;
|
13046 | if (this.displayed) this.redraw();
|
13047 | };
|
13048 |
|
13049 | |
13050 |
|
13051 |
|
13052 |
|
13053 | Item.prototype.setParent = function(parent) {
|
13054 | if (this.displayed) {
|
13055 | this.hide();
|
13056 | this.parent = parent;
|
13057 | if (this.parent) {
|
13058 | this.show();
|
13059 | }
|
13060 | }
|
13061 | else {
|
13062 | this.parent = parent;
|
13063 | }
|
13064 | };
|
13065 |
|
13066 | |
13067 |
|
13068 |
|
13069 |
|
13070 |
|
13071 | Item.prototype.isVisible = function(range) {
|
13072 |
|
13073 | return false;
|
13074 | };
|
13075 |
|
13076 | |
13077 |
|
13078 |
|
13079 |
|
13080 | Item.prototype.show = function() {
|
13081 | return false;
|
13082 | };
|
13083 |
|
13084 | |
13085 |
|
13086 |
|
13087 |
|
13088 | Item.prototype.hide = function() {
|
13089 | return false;
|
13090 | };
|
13091 |
|
13092 | |
13093 |
|
13094 |
|
13095 | Item.prototype.redraw = function() {
|
13096 |
|
13097 | };
|
13098 |
|
13099 | |
13100 |
|
13101 |
|
13102 | Item.prototype.repositionX = function() {
|
13103 |
|
13104 | };
|
13105 |
|
13106 | |
13107 |
|
13108 |
|
13109 | Item.prototype.repositionY = function() {
|
13110 |
|
13111 | };
|
13112 |
|
13113 | |
13114 |
|
13115 |
|
13116 |
|
13117 |
|
13118 | Item.prototype._repaintDeleteButton = function (anchor) {
|
13119 | if (this.selected && this.options.editable.remove && !this.dom.deleteButton) {
|
13120 |
|
13121 | var me = this;
|
13122 |
|
13123 | var deleteButton = document.createElement('div');
|
13124 | deleteButton.className = 'delete';
|
13125 | deleteButton.title = 'Delete this item';
|
13126 |
|
13127 | Hammer(deleteButton, {
|
13128 | preventDefault: true
|
13129 | }).on('tap', function (event) {
|
13130 | me.parent.removeFromDataSet(me);
|
13131 | event.stopPropagation();
|
13132 | });
|
13133 |
|
13134 | anchor.appendChild(deleteButton);
|
13135 | this.dom.deleteButton = deleteButton;
|
13136 | }
|
13137 | else if (!this.selected && this.dom.deleteButton) {
|
13138 |
|
13139 | if (this.dom.deleteButton.parentNode) {
|
13140 | this.dom.deleteButton.parentNode.removeChild(this.dom.deleteButton);
|
13141 | }
|
13142 | this.dom.deleteButton = null;
|
13143 | }
|
13144 | };
|
13145 |
|
13146 | |
13147 |
|
13148 |
|
13149 |
|
13150 |
|
13151 | Item.prototype._updateContents = function (element) {
|
13152 | var content;
|
13153 | if (this.options.template) {
|
13154 | var itemData = this.parent.itemSet.itemsData.get(this.id);
|
13155 | content = this.options.template(itemData);
|
13156 | }
|
13157 | else {
|
13158 | content = this.data.content;
|
13159 | }
|
13160 |
|
13161 | if (content instanceof Element) {
|
13162 | element.innerHTML = '';
|
13163 | element.appendChild(content);
|
13164 | }
|
13165 | else if (content != undefined) {
|
13166 | element.innerHTML = content;
|
13167 | }
|
13168 | else {
|
13169 | throw new Error('Property "content" missing in item ' + this.data.id);
|
13170 | }
|
13171 | };
|
13172 |
|
13173 | |
13174 |
|
13175 |
|
13176 |
|
13177 |
|
13178 | Item.prototype._updateTitle = function (element) {
|
13179 | if (this.data.title != null) {
|
13180 | element.title = this.data.title || '';
|
13181 | }
|
13182 | else {
|
13183 | element.removeAttribute('title');
|
13184 | }
|
13185 | };
|
13186 |
|
13187 | |
13188 |
|
13189 |
|
13190 |
|
13191 |
|
13192 | Item.prototype._updateDataAttributes = function(element) {
|
13193 | if (this.options.dataAttributes && this.options.dataAttributes.length > 0) {
|
13194 | for (var i = 0; i < this.options.dataAttributes.length; i++) {
|
13195 | var name = this.options.dataAttributes[i];
|
13196 | var value = this.data[name];
|
13197 |
|
13198 | if (value != null) {
|
13199 | element.setAttribute('data-' + name, value);
|
13200 | }
|
13201 | else {
|
13202 | element.removeAttribute('data-' + name);
|
13203 | }
|
13204 | }
|
13205 | }
|
13206 | };
|
13207 |
|
13208 | module.exports = Item;
|
13209 |
|
13210 |
|
13211 | },
|
13212 |
|
13213 | function(module, exports, __webpack_require__) {
|
13214 |
|
13215 | var Hammer = __webpack_require__(42);
|
13216 | var Item = __webpack_require__(28);
|
13217 | var RangeItem = __webpack_require__(32);
|
13218 |
|
13219 | |
13220 |
|
13221 |
|
13222 |
|
13223 |
|
13224 |
|
13225 |
|
13226 |
|
13227 |
|
13228 |
|
13229 |
|
13230 | function BackgroundItem (data, conversion, options) {
|
13231 | this.props = {
|
13232 | content: {
|
13233 | width: 0
|
13234 | }
|
13235 | };
|
13236 | this.overflow = false;
|
13237 |
|
13238 |
|
13239 | if (data) {
|
13240 | if (data.start == undefined) {
|
13241 | throw new Error('Property "start" missing in item ' + data.id);
|
13242 | }
|
13243 | if (data.end == undefined) {
|
13244 | throw new Error('Property "end" missing in item ' + data.id);
|
13245 | }
|
13246 | }
|
13247 |
|
13248 | Item.call(this, data, conversion, options);
|
13249 | }
|
13250 |
|
13251 | BackgroundItem.prototype = new Item (null, null, null);
|
13252 |
|
13253 | BackgroundItem.prototype.baseClassName = 'item background';
|
13254 |
|
13255 | |
13256 |
|
13257 |
|
13258 |
|
13259 |
|
13260 | BackgroundItem.prototype.isVisible = function(range) {
|
13261 |
|
13262 | return (this.data.start < range.end) && (this.data.end > range.start);
|
13263 | };
|
13264 |
|
13265 | |
13266 |
|
13267 |
|
13268 | BackgroundItem.prototype.redraw = function() {
|
13269 | var dom = this.dom;
|
13270 | if (!dom) {
|
13271 |
|
13272 | this.dom = {};
|
13273 | dom = this.dom;
|
13274 |
|
13275 |
|
13276 | dom.box = document.createElement('div');
|
13277 |
|
13278 |
|
13279 |
|
13280 | dom.content = document.createElement('div');
|
13281 | dom.content.className = 'content';
|
13282 | dom.box.appendChild(dom.content);
|
13283 |
|
13284 |
|
13285 | dom.box['timeline-item'] = this;
|
13286 |
|
13287 | this.dirty = true;
|
13288 | }
|
13289 |
|
13290 |
|
13291 | if (!this.parent) {
|
13292 | throw new Error('Cannot redraw item: no parent attached');
|
13293 | }
|
13294 | if (!dom.box.parentNode) {
|
13295 | var background = this.parent.dom.background;
|
13296 | if (!background) {
|
13297 | throw new Error('Cannot redraw time axis: parent has no background container element');
|
13298 | }
|
13299 | background.appendChild(dom.box);
|
13300 | }
|
13301 | this.displayed = true;
|
13302 |
|
13303 |
|
13304 |
|
13305 |
|
13306 |
|
13307 | if (this.dirty) {
|
13308 | this._updateContents(this.dom.content);
|
13309 | this._updateTitle(this.dom.content);
|
13310 | this._updateDataAttributes(this.dom.content);
|
13311 |
|
13312 |
|
13313 | var className = (this.data.className ? (' ' + this.data.className) : '') +
|
13314 | (this.selected ? ' selected' : '');
|
13315 | dom.box.className = this.baseClassName + className;
|
13316 |
|
13317 |
|
13318 | this.overflow = window.getComputedStyle(dom.content).overflow !== 'hidden';
|
13319 |
|
13320 |
|
13321 | this.props.content.width = this.dom.content.offsetWidth;
|
13322 | this.height = 0;
|
13323 |
|
13324 | this.dirty = false;
|
13325 | }
|
13326 | };
|
13327 |
|
13328 | |
13329 |
|
13330 |
|
13331 |
|
13332 | BackgroundItem.prototype.show = RangeItem.prototype.show;
|
13333 |
|
13334 | |
13335 |
|
13336 |
|
13337 |
|
13338 | BackgroundItem.prototype.hide = RangeItem.prototype.hide;
|
13339 |
|
13340 | |
13341 |
|
13342 |
|
13343 |
|
13344 | BackgroundItem.prototype.repositionX = RangeItem.prototype.repositionX;
|
13345 |
|
13346 | |
13347 |
|
13348 |
|
13349 |
|
13350 | BackgroundItem.prototype.repositionY = function() {
|
13351 | var onTop = this.options.orientation === 'top';
|
13352 | this.dom.content.style.top = onTop ? '' : '0';
|
13353 | this.dom.content.style.bottom = onTop ? '0' : '';
|
13354 | };
|
13355 |
|
13356 | module.exports = BackgroundItem;
|
13357 |
|
13358 |
|
13359 | },
|
13360 |
|
13361 | function(module, exports, __webpack_require__) {
|
13362 |
|
13363 | var Item = __webpack_require__(28);
|
13364 |
|
13365 | |
13366 |
|
13367 |
|
13368 |
|
13369 |
|
13370 |
|
13371 |
|
13372 |
|
13373 |
|
13374 |
|
13375 | function BoxItem (data, conversion, options) {
|
13376 | this.props = {
|
13377 | dot: {
|
13378 | width: 0,
|
13379 | height: 0
|
13380 | },
|
13381 | line: {
|
13382 | width: 0,
|
13383 | height: 0
|
13384 | }
|
13385 | };
|
13386 |
|
13387 |
|
13388 | if (data) {
|
13389 | if (data.start == undefined) {
|
13390 | throw new Error('Property "start" missing in item ' + data);
|
13391 | }
|
13392 | }
|
13393 |
|
13394 | Item.call(this, data, conversion, options);
|
13395 | }
|
13396 |
|
13397 | BoxItem.prototype = new Item (null, null, null);
|
13398 |
|
13399 | |
13400 |
|
13401 |
|
13402 |
|
13403 |
|
13404 | BoxItem.prototype.isVisible = function(range) {
|
13405 |
|
13406 |
|
13407 | var interval = (range.end - range.start) / 4;
|
13408 | return (this.data.start > range.start - interval) && (this.data.start < range.end + interval);
|
13409 | };
|
13410 |
|
13411 | |
13412 |
|
13413 |
|
13414 | BoxItem.prototype.redraw = function() {
|
13415 | var dom = this.dom;
|
13416 | if (!dom) {
|
13417 |
|
13418 | this.dom = {};
|
13419 | dom = this.dom;
|
13420 |
|
13421 |
|
13422 | dom.box = document.createElement('DIV');
|
13423 |
|
13424 |
|
13425 | dom.content = document.createElement('DIV');
|
13426 | dom.content.className = 'content';
|
13427 | dom.box.appendChild(dom.content);
|
13428 |
|
13429 |
|
13430 | dom.line = document.createElement('DIV');
|
13431 | dom.line.className = 'line';
|
13432 |
|
13433 |
|
13434 | dom.dot = document.createElement('DIV');
|
13435 | dom.dot.className = 'dot';
|
13436 |
|
13437 |
|
13438 | dom.box['timeline-item'] = this;
|
13439 |
|
13440 | this.dirty = true;
|
13441 | }
|
13442 |
|
13443 |
|
13444 | if (!this.parent) {
|
13445 | throw new Error('Cannot redraw item: no parent attached');
|
13446 | }
|
13447 | if (!dom.box.parentNode) {
|
13448 | var foreground = this.parent.dom.foreground;
|
13449 | if (!foreground) throw new Error('Cannot redraw time axis: parent has no foreground container element');
|
13450 | foreground.appendChild(dom.box);
|
13451 | }
|
13452 | if (!dom.line.parentNode) {
|
13453 | var background = this.parent.dom.background;
|
13454 | if (!background) throw new Error('Cannot redraw time axis: parent has no background container element');
|
13455 | background.appendChild(dom.line);
|
13456 | }
|
13457 | if (!dom.dot.parentNode) {
|
13458 | var axis = this.parent.dom.axis;
|
13459 | if (!background) throw new Error('Cannot redraw time axis: parent has no axis container element');
|
13460 | axis.appendChild(dom.dot);
|
13461 | }
|
13462 | this.displayed = true;
|
13463 |
|
13464 |
|
13465 |
|
13466 |
|
13467 |
|
13468 | if (this.dirty) {
|
13469 | this._updateContents(this.dom.content);
|
13470 | this._updateTitle(this.dom.box);
|
13471 | this._updateDataAttributes(this.dom.box);
|
13472 |
|
13473 |
|
13474 | var className = (this.data.className? ' ' + this.data.className : '') +
|
13475 | (this.selected ? ' selected' : '');
|
13476 | dom.box.className = 'item box' + className;
|
13477 | dom.line.className = 'item line' + className;
|
13478 | dom.dot.className = 'item dot' + className;
|
13479 |
|
13480 |
|
13481 | this.props.dot.height = dom.dot.offsetHeight;
|
13482 | this.props.dot.width = dom.dot.offsetWidth;
|
13483 | this.props.line.width = dom.line.offsetWidth;
|
13484 | this.width = dom.box.offsetWidth;
|
13485 | this.height = dom.box.offsetHeight;
|
13486 |
|
13487 | this.dirty = false;
|
13488 | }
|
13489 |
|
13490 | this._repaintDeleteButton(dom.box);
|
13491 | };
|
13492 |
|
13493 | |
13494 |
|
13495 |
|
13496 |
|
13497 | BoxItem.prototype.show = function() {
|
13498 | if (!this.displayed) {
|
13499 | this.redraw();
|
13500 | }
|
13501 | };
|
13502 |
|
13503 | |
13504 |
|
13505 |
|
13506 | BoxItem.prototype.hide = function() {
|
13507 | if (this.displayed) {
|
13508 | var dom = this.dom;
|
13509 |
|
13510 | if (dom.box.parentNode) dom.box.parentNode.removeChild(dom.box);
|
13511 | if (dom.line.parentNode) dom.line.parentNode.removeChild(dom.line);
|
13512 | if (dom.dot.parentNode) dom.dot.parentNode.removeChild(dom.dot);
|
13513 |
|
13514 | this.top = null;
|
13515 | this.left = null;
|
13516 |
|
13517 | this.displayed = false;
|
13518 | }
|
13519 | };
|
13520 |
|
13521 | |
13522 |
|
13523 |
|
13524 |
|
13525 | BoxItem.prototype.repositionX = function() {
|
13526 | var start = this.conversion.toScreen(this.data.start);
|
13527 | var align = this.options.align;
|
13528 | var left;
|
13529 | var box = this.dom.box;
|
13530 | var line = this.dom.line;
|
13531 | var dot = this.dom.dot;
|
13532 |
|
13533 |
|
13534 | if (align == 'right') {
|
13535 | this.left = start - this.width;
|
13536 | }
|
13537 | else if (align == 'left') {
|
13538 | this.left = start;
|
13539 | }
|
13540 | else {
|
13541 |
|
13542 | this.left = start - this.width / 2;
|
13543 | }
|
13544 |
|
13545 |
|
13546 | box.style.left = this.left + 'px';
|
13547 |
|
13548 |
|
13549 | line.style.left = (start - this.props.line.width / 2) + 'px';
|
13550 |
|
13551 |
|
13552 | dot.style.left = (start - this.props.dot.width / 2) + 'px';
|
13553 | };
|
13554 |
|
13555 | |
13556 |
|
13557 |
|
13558 |
|
13559 | BoxItem.prototype.repositionY = function() {
|
13560 | var orientation = this.options.orientation;
|
13561 | var box = this.dom.box;
|
13562 | var line = this.dom.line;
|
13563 | var dot = this.dom.dot;
|
13564 |
|
13565 | if (orientation == 'top') {
|
13566 | box.style.top = (this.top || 0) + 'px';
|
13567 |
|
13568 | line.style.top = '0';
|
13569 | line.style.height = (this.parent.top + this.top + 1) + 'px';
|
13570 | line.style.bottom = '';
|
13571 | }
|
13572 | else {
|
13573 | var itemSetHeight = this.parent.itemSet.props.height;
|
13574 | var lineHeight = itemSetHeight - this.parent.top - this.parent.height + this.top;
|
13575 |
|
13576 | box.style.top = (this.parent.height - this.top - this.height || 0) + 'px';
|
13577 | line.style.top = (itemSetHeight - lineHeight) + 'px';
|
13578 | line.style.bottom = '0';
|
13579 | }
|
13580 |
|
13581 | dot.style.top = (-this.props.dot.height / 2) + 'px';
|
13582 | };
|
13583 |
|
13584 | module.exports = BoxItem;
|
13585 |
|
13586 |
|
13587 | },
|
13588 |
|
13589 | function(module, exports, __webpack_require__) {
|
13590 |
|
13591 | var Item = __webpack_require__(28);
|
13592 |
|
13593 | |
13594 |
|
13595 |
|
13596 |
|
13597 |
|
13598 |
|
13599 |
|
13600 |
|
13601 |
|
13602 |
|
13603 | function PointItem (data, conversion, options) {
|
13604 | this.props = {
|
13605 | dot: {
|
13606 | top: 0,
|
13607 | width: 0,
|
13608 | height: 0
|
13609 | },
|
13610 | content: {
|
13611 | height: 0,
|
13612 | marginLeft: 0
|
13613 | }
|
13614 | };
|
13615 |
|
13616 |
|
13617 | if (data) {
|
13618 | if (data.start == undefined) {
|
13619 | throw new Error('Property "start" missing in item ' + data);
|
13620 | }
|
13621 | }
|
13622 |
|
13623 | Item.call(this, data, conversion, options);
|
13624 | }
|
13625 |
|
13626 | PointItem.prototype = new Item (null, null, null);
|
13627 |
|
13628 | |
13629 |
|
13630 |
|
13631 |
|
13632 |
|
13633 | PointItem.prototype.isVisible = function(range) {
|
13634 |
|
13635 |
|
13636 | var interval = (range.end - range.start) / 4;
|
13637 | return (this.data.start > range.start - interval) && (this.data.start < range.end + interval);
|
13638 | };
|
13639 |
|
13640 | |
13641 |
|
13642 |
|
13643 | PointItem.prototype.redraw = function() {
|
13644 | var dom = this.dom;
|
13645 | if (!dom) {
|
13646 |
|
13647 | this.dom = {};
|
13648 | dom = this.dom;
|
13649 |
|
13650 |
|
13651 | dom.point = document.createElement('div');
|
13652 |
|
13653 |
|
13654 |
|
13655 | dom.content = document.createElement('div');
|
13656 | dom.content.className = 'content';
|
13657 | dom.point.appendChild(dom.content);
|
13658 |
|
13659 |
|
13660 | dom.dot = document.createElement('div');
|
13661 | dom.point.appendChild(dom.dot);
|
13662 |
|
13663 |
|
13664 | dom.point['timeline-item'] = this;
|
13665 |
|
13666 | this.dirty = true;
|
13667 | }
|
13668 |
|
13669 |
|
13670 | if (!this.parent) {
|
13671 | throw new Error('Cannot redraw item: no parent attached');
|
13672 | }
|
13673 | if (!dom.point.parentNode) {
|
13674 | var foreground = this.parent.dom.foreground;
|
13675 | if (!foreground) {
|
13676 | throw new Error('Cannot redraw time axis: parent has no foreground container element');
|
13677 | }
|
13678 | foreground.appendChild(dom.point);
|
13679 | }
|
13680 | this.displayed = true;
|
13681 |
|
13682 |
|
13683 |
|
13684 |
|
13685 |
|
13686 | if (this.dirty) {
|
13687 | this._updateContents(this.dom.content);
|
13688 | this._updateTitle(this.dom.point);
|
13689 | this._updateDataAttributes(this.dom.point);
|
13690 |
|
13691 |
|
13692 | var className = (this.data.className? ' ' + this.data.className : '') +
|
13693 | (this.selected ? ' selected' : '');
|
13694 | dom.point.className = 'item point' + className;
|
13695 | dom.dot.className = 'item dot' + className;
|
13696 |
|
13697 |
|
13698 | this.width = dom.point.offsetWidth;
|
13699 | this.height = dom.point.offsetHeight;
|
13700 | this.props.dot.width = dom.dot.offsetWidth;
|
13701 | this.props.dot.height = dom.dot.offsetHeight;
|
13702 | this.props.content.height = dom.content.offsetHeight;
|
13703 |
|
13704 |
|
13705 | dom.content.style.marginLeft = 2 * this.props.dot.width + 'px';
|
13706 |
|
13707 |
|
13708 | dom.dot.style.top = ((this.height - this.props.dot.height) / 2) + 'px';
|
13709 | dom.dot.style.left = (this.props.dot.width / 2) + 'px';
|
13710 |
|
13711 | this.dirty = false;
|
13712 | }
|
13713 |
|
13714 | this._repaintDeleteButton(dom.point);
|
13715 | };
|
13716 |
|
13717 | |
13718 |
|
13719 |
|
13720 |
|
13721 | PointItem.prototype.show = function() {
|
13722 | if (!this.displayed) {
|
13723 | this.redraw();
|
13724 | }
|
13725 | };
|
13726 |
|
13727 | |
13728 |
|
13729 |
|
13730 | PointItem.prototype.hide = function() {
|
13731 | if (this.displayed) {
|
13732 | if (this.dom.point.parentNode) {
|
13733 | this.dom.point.parentNode.removeChild(this.dom.point);
|
13734 | }
|
13735 |
|
13736 | this.top = null;
|
13737 | this.left = null;
|
13738 |
|
13739 | this.displayed = false;
|
13740 | }
|
13741 | };
|
13742 |
|
13743 | |
13744 |
|
13745 |
|
13746 |
|
13747 | PointItem.prototype.repositionX = function() {
|
13748 | var start = this.conversion.toScreen(this.data.start);
|
13749 |
|
13750 | this.left = start - this.props.dot.width;
|
13751 |
|
13752 |
|
13753 | this.dom.point.style.left = this.left + 'px';
|
13754 | };
|
13755 |
|
13756 | |
13757 |
|
13758 |
|
13759 |
|
13760 | PointItem.prototype.repositionY = function() {
|
13761 | var orientation = this.options.orientation,
|
13762 | point = this.dom.point;
|
13763 |
|
13764 | if (orientation == 'top') {
|
13765 | point.style.top = this.top + 'px';
|
13766 | }
|
13767 | else {
|
13768 | point.style.top = (this.parent.height - this.top - this.height) + 'px';
|
13769 | }
|
13770 | };
|
13771 |
|
13772 | module.exports = PointItem;
|
13773 |
|
13774 |
|
13775 | },
|
13776 |
|
13777 | function(module, exports, __webpack_require__) {
|
13778 |
|
13779 | var Hammer = __webpack_require__(42);
|
13780 | var Item = __webpack_require__(28);
|
13781 |
|
13782 | |
13783 |
|
13784 |
|
13785 |
|
13786 |
|
13787 |
|
13788 |
|
13789 |
|
13790 |
|
13791 |
|
13792 | function RangeItem (data, conversion, options) {
|
13793 | this.props = {
|
13794 | content: {
|
13795 | width: 0
|
13796 | }
|
13797 | };
|
13798 | this.overflow = false;
|
13799 |
|
13800 |
|
13801 | if (data) {
|
13802 | if (data.start == undefined) {
|
13803 | throw new Error('Property "start" missing in item ' + data.id);
|
13804 | }
|
13805 | if (data.end == undefined) {
|
13806 | throw new Error('Property "end" missing in item ' + data.id);
|
13807 | }
|
13808 | }
|
13809 |
|
13810 | Item.call(this, data, conversion, options);
|
13811 | }
|
13812 |
|
13813 | RangeItem.prototype = new Item (null, null, null);
|
13814 |
|
13815 | RangeItem.prototype.baseClassName = 'item range';
|
13816 |
|
13817 | |
13818 |
|
13819 |
|
13820 |
|
13821 |
|
13822 | RangeItem.prototype.isVisible = function(range) {
|
13823 |
|
13824 | return (this.data.start < range.end) && (this.data.end > range.start);
|
13825 | };
|
13826 |
|
13827 | |
13828 |
|
13829 |
|
13830 | RangeItem.prototype.redraw = function() {
|
13831 | var dom = this.dom;
|
13832 | if (!dom) {
|
13833 |
|
13834 | this.dom = {};
|
13835 | dom = this.dom;
|
13836 |
|
13837 |
|
13838 | dom.box = document.createElement('div');
|
13839 |
|
13840 |
|
13841 |
|
13842 | dom.content = document.createElement('div');
|
13843 | dom.content.className = 'content';
|
13844 | dom.box.appendChild(dom.content);
|
13845 |
|
13846 |
|
13847 | dom.box['timeline-item'] = this;
|
13848 |
|
13849 | this.dirty = true;
|
13850 | }
|
13851 |
|
13852 |
|
13853 | if (!this.parent) {
|
13854 | throw new Error('Cannot redraw item: no parent attached');
|
13855 | }
|
13856 | if (!dom.box.parentNode) {
|
13857 | var foreground = this.parent.dom.foreground;
|
13858 | if (!foreground) {
|
13859 | throw new Error('Cannot redraw time axis: parent has no foreground container element');
|
13860 | }
|
13861 | foreground.appendChild(dom.box);
|
13862 | }
|
13863 | this.displayed = true;
|
13864 |
|
13865 |
|
13866 |
|
13867 |
|
13868 |
|
13869 | if (this.dirty) {
|
13870 | this._updateContents(this.dom.content);
|
13871 | this._updateTitle(this.dom.box);
|
13872 | this._updateDataAttributes(this.dom.box);
|
13873 |
|
13874 |
|
13875 | var className = (this.data.className ? (' ' + this.data.className) : '') +
|
13876 | (this.selected ? ' selected' : '');
|
13877 | dom.box.className = this.baseClassName + className;
|
13878 |
|
13879 |
|
13880 | this.overflow = window.getComputedStyle(dom.content).overflow !== 'hidden';
|
13881 |
|
13882 |
|
13883 | this.props.content.width = this.dom.content.offsetWidth;
|
13884 | this.height = this.dom.box.offsetHeight;
|
13885 |
|
13886 | this.dirty = false;
|
13887 | }
|
13888 |
|
13889 | this._repaintDeleteButton(dom.box);
|
13890 | this._repaintDragLeft();
|
13891 | this._repaintDragRight();
|
13892 | };
|
13893 |
|
13894 | |
13895 |
|
13896 |
|
13897 |
|
13898 | RangeItem.prototype.show = function() {
|
13899 | if (!this.displayed) {
|
13900 | this.redraw();
|
13901 | }
|
13902 | };
|
13903 |
|
13904 | |
13905 |
|
13906 |
|
13907 |
|
13908 | RangeItem.prototype.hide = function() {
|
13909 | if (this.displayed) {
|
13910 | var box = this.dom.box;
|
13911 |
|
13912 | if (box.parentNode) {
|
13913 | box.parentNode.removeChild(box);
|
13914 | }
|
13915 |
|
13916 | this.top = null;
|
13917 | this.left = null;
|
13918 |
|
13919 | this.displayed = false;
|
13920 | }
|
13921 | };
|
13922 |
|
13923 | |
13924 |
|
13925 |
|
13926 |
|
13927 | RangeItem.prototype.repositionX = function() {
|
13928 | var parentWidth = this.parent.width;
|
13929 | var start = this.conversion.toScreen(this.data.start);
|
13930 | var end = this.conversion.toScreen(this.data.end);
|
13931 | var contentLeft;
|
13932 | var contentWidth;
|
13933 |
|
13934 |
|
13935 | if (start < -parentWidth) {
|
13936 | start = -parentWidth;
|
13937 | }
|
13938 | if (end > 2 * parentWidth) {
|
13939 | end = 2 * parentWidth;
|
13940 | }
|
13941 | var boxWidth = Math.max(end - start, 1);
|
13942 |
|
13943 | if (this.overflow) {
|
13944 | this.left = start;
|
13945 | this.width = boxWidth + this.props.content.width;
|
13946 | contentWidth = this.props.content.width;
|
13947 |
|
13948 |
|
13949 |
|
13950 |
|
13951 | }
|
13952 | else {
|
13953 | this.left = start;
|
13954 | this.width = boxWidth;
|
13955 | contentWidth = Math.min(end - start, this.props.content.width);
|
13956 | }
|
13957 |
|
13958 | this.dom.box.style.left = this.left + 'px';
|
13959 | this.dom.box.style.width = boxWidth + 'px';
|
13960 |
|
13961 | switch (this.options.align) {
|
13962 | case 'left':
|
13963 | this.dom.content.style.left = '0';
|
13964 | break;
|
13965 |
|
13966 | case 'right':
|
13967 | this.dom.content.style.left = Math.max((boxWidth - contentWidth - 2 * this.options.padding), 0) + 'px';
|
13968 | break;
|
13969 |
|
13970 | case 'center':
|
13971 | this.dom.content.style.left = Math.max((boxWidth - contentWidth - 2 * this.options.padding) / 2, 0) + 'px';
|
13972 | break;
|
13973 |
|
13974 | default:
|
13975 | if (this.overflow) {
|
13976 |
|
13977 | contentLeft = Math.max(-start, 0);
|
13978 | }
|
13979 | else {
|
13980 |
|
13981 | if (start < 0) {
|
13982 | contentLeft = Math.min(-start,
|
13983 | (end - start - this.props.content.width - 2 * this.options.padding));
|
13984 |
|
13985 | }
|
13986 | else {
|
13987 | contentLeft = 0;
|
13988 | }
|
13989 | }
|
13990 | this.dom.content.style.left = contentLeft + 'px';
|
13991 | }
|
13992 | };
|
13993 |
|
13994 | |
13995 |
|
13996 |
|
13997 |
|
13998 | RangeItem.prototype.repositionY = function() {
|
13999 | var orientation = this.options.orientation,
|
14000 | box = this.dom.box;
|
14001 |
|
14002 | if (orientation == 'top') {
|
14003 | box.style.top = this.top + 'px';
|
14004 | }
|
14005 | else {
|
14006 | box.style.top = (this.parent.height - this.top - this.height) + 'px';
|
14007 | }
|
14008 | };
|
14009 |
|
14010 | |
14011 |
|
14012 |
|
14013 |
|
14014 | RangeItem.prototype._repaintDragLeft = function () {
|
14015 | if (this.selected && this.options.editable.updateTime && !this.dom.dragLeft) {
|
14016 |
|
14017 | var dragLeft = document.createElement('div');
|
14018 | dragLeft.className = 'drag-left';
|
14019 | dragLeft.dragLeftItem = this;
|
14020 |
|
14021 |
|
14022 | Hammer(dragLeft, {
|
14023 | preventDefault: true
|
14024 | }).on('drag', function () {
|
14025 |
|
14026 | });
|
14027 |
|
14028 | this.dom.box.appendChild(dragLeft);
|
14029 | this.dom.dragLeft = dragLeft;
|
14030 | }
|
14031 | else if (!this.selected && this.dom.dragLeft) {
|
14032 |
|
14033 | if (this.dom.dragLeft.parentNode) {
|
14034 | this.dom.dragLeft.parentNode.removeChild(this.dom.dragLeft);
|
14035 | }
|
14036 | this.dom.dragLeft = null;
|
14037 | }
|
14038 | };
|
14039 |
|
14040 | |
14041 |
|
14042 |
|
14043 |
|
14044 | RangeItem.prototype._repaintDragRight = function () {
|
14045 | if (this.selected && this.options.editable.updateTime && !this.dom.dragRight) {
|
14046 |
|
14047 | var dragRight = document.createElement('div');
|
14048 | dragRight.className = 'drag-right';
|
14049 | dragRight.dragRightItem = this;
|
14050 |
|
14051 |
|
14052 | Hammer(dragRight, {
|
14053 | preventDefault: true
|
14054 | }).on('drag', function () {
|
14055 |
|
14056 | });
|
14057 |
|
14058 | this.dom.box.appendChild(dragRight);
|
14059 | this.dom.dragRight = dragRight;
|
14060 | }
|
14061 | else if (!this.selected && this.dom.dragRight) {
|
14062 |
|
14063 | if (this.dom.dragRight.parentNode) {
|
14064 | this.dom.dragRight.parentNode.removeChild(this.dom.dragRight);
|
14065 | }
|
14066 | this.dom.dragRight = null;
|
14067 | }
|
14068 | };
|
14069 |
|
14070 | module.exports = RangeItem;
|
14071 |
|
14072 |
|
14073 | },
|
14074 |
|
14075 | function(module, exports, __webpack_require__) {
|
14076 |
|
14077 | var Emitter = __webpack_require__(50);
|
14078 | var Hammer = __webpack_require__(42);
|
14079 | var mousetrap = __webpack_require__(51);
|
14080 | var util = __webpack_require__(1);
|
14081 | var hammerUtil = __webpack_require__(43);
|
14082 | var DataSet = __webpack_require__(3);
|
14083 | var DataView = __webpack_require__(4);
|
14084 | var dotparser = __webpack_require__(39);
|
14085 | var gephiParser = __webpack_require__(40);
|
14086 | var Groups = __webpack_require__(35);
|
14087 | var Images = __webpack_require__(36);
|
14088 | var Node = __webpack_require__(37);
|
14089 | var Edge = __webpack_require__(34);
|
14090 | var Popup = __webpack_require__(38);
|
14091 | var MixinLoader = __webpack_require__(48);
|
14092 | var Activator = __webpack_require__(49);
|
14093 | var locales = __webpack_require__(46);
|
14094 |
|
14095 |
|
14096 | __webpack_require__(47);
|
14097 |
|
14098 | |
14099 |
|
14100 |
|
14101 |
|
14102 |
|
14103 |
|
14104 |
|
14105 |
|
14106 |
|
14107 |
|
14108 |
|
14109 | function Network (container, data, options) {
|
14110 | if (!(this instanceof Network)) {
|
14111 | throw new SyntaxError('Constructor must be called with the new operator');
|
14112 | }
|
14113 |
|
14114 | this._initializeMixinLoaders();
|
14115 |
|
14116 |
|
14117 | this.containerElement = container;
|
14118 |
|
14119 |
|
14120 | this.renderRefreshRate = 60;
|
14121 | this.renderTimestep = 1000 / this.renderRefreshRate;
|
14122 | this.renderTime = 0.5 * this.renderTimestep;
|
14123 | this.maxPhysicsTicksPerRender = 3;
|
14124 | this.physicsDiscreteStepsize = 0.50;
|
14125 |
|
14126 | this.initializing = true;
|
14127 |
|
14128 | this.triggerFunctions = {add:null,edit:null,editEdge:null,connect:null,del:null};
|
14129 |
|
14130 |
|
14131 | this.defaultOptions = {
|
14132 | nodes: {
|
14133 | mass: 1,
|
14134 | radiusMin: 10,
|
14135 | radiusMax: 30,
|
14136 | radius: 10,
|
14137 | shape: 'ellipse',
|
14138 | image: undefined,
|
14139 | widthMin: 16,
|
14140 | widthMax: 64,
|
14141 | fontColor: 'black',
|
14142 | fontSize: 14,
|
14143 | fontFace: 'verdana',
|
14144 | fontFill: undefined,
|
14145 | level: -1,
|
14146 | color: {
|
14147 | border: '#2B7CE9',
|
14148 | background: '#97C2FC',
|
14149 | highlight: {
|
14150 | border: '#2B7CE9',
|
14151 | background: '#D2E5FF'
|
14152 | },
|
14153 | hover: {
|
14154 | border: '#2B7CE9',
|
14155 | background: '#D2E5FF'
|
14156 | }
|
14157 | },
|
14158 | borderColor: '#2B7CE9',
|
14159 | backgroundColor: '#97C2FC',
|
14160 | highlightColor: '#D2E5FF',
|
14161 | group: undefined,
|
14162 | borderWidth: 1,
|
14163 | borderWidthSelected: undefined
|
14164 | },
|
14165 | edges: {
|
14166 | widthMin: 1,
|
14167 | widthMax: 15,
|
14168 | width: 1,
|
14169 | widthSelectionMultiplier: 2,
|
14170 | hoverWidth: 1.5,
|
14171 | style: 'line',
|
14172 | color: {
|
14173 | color:'#848484',
|
14174 | highlight:'#848484',
|
14175 | hover: '#848484'
|
14176 | },
|
14177 | fontColor: '#343434',
|
14178 | fontSize: 14,
|
14179 | fontFace: 'arial',
|
14180 | fontFill: 'white',
|
14181 | arrowScaleFactor: 1,
|
14182 | dash: {
|
14183 | length: 10,
|
14184 | gap: 5,
|
14185 | altLength: undefined
|
14186 | },
|
14187 | inheritColor: "from"
|
14188 | },
|
14189 | configurePhysics:false,
|
14190 | physics: {
|
14191 | barnesHut: {
|
14192 | enabled: true,
|
14193 | theta: 1 / 0.6,
|
14194 | gravitationalConstant: -2000,
|
14195 | centralGravity: 0.3,
|
14196 | springLength: 95,
|
14197 | springConstant: 0.04,
|
14198 | damping: 0.09
|
14199 | },
|
14200 | repulsion: {
|
14201 | centralGravity: 0.0,
|
14202 | springLength: 200,
|
14203 | springConstant: 0.05,
|
14204 | nodeDistance: 100,
|
14205 | damping: 0.09
|
14206 | },
|
14207 | hierarchicalRepulsion: {
|
14208 | enabled: false,
|
14209 | centralGravity: 0.0,
|
14210 | springLength: 100,
|
14211 | springConstant: 0.01,
|
14212 | nodeDistance: 150,
|
14213 | damping: 0.09
|
14214 | },
|
14215 | damping: null,
|
14216 | centralGravity: null,
|
14217 | springLength: null,
|
14218 | springConstant: null
|
14219 | },
|
14220 | clustering: {
|
14221 | enabled: false,
|
14222 | initialMaxNodes: 100,
|
14223 | clusterThreshold:500,
|
14224 | reduceToNodes:300,
|
14225 | chainThreshold: 0.4,
|
14226 | clusterEdgeThreshold: 20,
|
14227 | sectorThreshold: 100,
|
14228 | screenSizeThreshold: 0.2,
|
14229 | fontSizeMultiplier: 4.0,
|
14230 | maxFontSize: 1000,
|
14231 | forceAmplification: 0.1,
|
14232 | distanceAmplification: 0.1,
|
14233 | edgeGrowth: 20,
|
14234 | nodeScaling: {width: 1,
|
14235 | height: 1,
|
14236 | radius: 1},
|
14237 | maxNodeSizeIncrements: 600,
|
14238 | activeAreaBoxSize: 80,
|
14239 | clusterLevelDifference: 2
|
14240 | },
|
14241 | navigation: {
|
14242 | enabled: false
|
14243 | },
|
14244 | keyboard: {
|
14245 | enabled: false,
|
14246 | speed: {x: 10, y: 10, zoom: 0.02}
|
14247 | },
|
14248 | dataManipulation: {
|
14249 | enabled: false,
|
14250 | initiallyVisible: false
|
14251 | },
|
14252 | hierarchicalLayout: {
|
14253 | enabled:false,
|
14254 | levelSeparation: 150,
|
14255 | nodeSpacing: 100,
|
14256 | direction: "UD",
|
14257 | layout: "hubsize"
|
14258 | },
|
14259 | freezeForStabilization: false,
|
14260 | smoothCurves: {
|
14261 | enabled: true,
|
14262 | dynamic: true,
|
14263 | type: "continuous",
|
14264 | roundness: 0.5
|
14265 | },
|
14266 | dynamicSmoothCurves: true,
|
14267 | maxVelocity: 30,
|
14268 | minVelocity: 0.1,
|
14269 | stabilize: true,
|
14270 | stabilizationIterations: 1000,
|
14271 | locale: 'en',
|
14272 | locales: locales,
|
14273 | tooltip: {
|
14274 | delay: 300,
|
14275 | fontColor: 'black',
|
14276 | fontSize: 14,
|
14277 | fontFace: 'verdana',
|
14278 | color: {
|
14279 | border: '#666',
|
14280 | background: '#FFFFC6'
|
14281 | }
|
14282 | },
|
14283 | dragNetwork: true,
|
14284 | dragNodes: true,
|
14285 | zoomable: true,
|
14286 | hover: false,
|
14287 | hideEdgesOnDrag: false,
|
14288 | hideNodesOnDrag: false,
|
14289 | width : '100%',
|
14290 | height : '100%',
|
14291 | selectable: true
|
14292 | };
|
14293 | this.constants = util.extend({}, this.defaultOptions);
|
14294 |
|
14295 | this.hoverObj = {nodes:{},edges:{}};
|
14296 | this.controlNodesActive = false;
|
14297 | this.navigationHammers = {existing:[], new: []};
|
14298 |
|
14299 |
|
14300 | this.animationSpeed = 1/this.renderRefreshRate;
|
14301 | this.animationEasingFunction = "easeInOutQuint";
|
14302 | this.easingTime = 0;
|
14303 | this.sourceScale = 0;
|
14304 | this.targetScale = 0;
|
14305 | this.sourceTranslation = 0;
|
14306 | this.targetTranslation = 0;
|
14307 | this.lockedOnNodeId = null;
|
14308 | this.lockedOnNodeOffset = null;
|
14309 |
|
14310 |
|
14311 | var network = this;
|
14312 | this.groups = new Groups();
|
14313 | this.images = new Images();
|
14314 | this.images.setOnloadCallback(function () {
|
14315 | network._redraw();
|
14316 | });
|
14317 |
|
14318 |
|
14319 | this.xIncrement = 0;
|
14320 | this.yIncrement = 0;
|
14321 | this.zoomIncrement = 0;
|
14322 |
|
14323 |
|
14324 |
|
14325 | this._loadPhysicsSystem();
|
14326 |
|
14327 | this._create();
|
14328 |
|
14329 | this._loadSectorSystem();
|
14330 |
|
14331 | this._loadClusterSystem();
|
14332 |
|
14333 | this._loadSelectionSystem();
|
14334 |
|
14335 | this._loadHierarchySystem();
|
14336 |
|
14337 |
|
14338 |
|
14339 | this._setTranslation(this.frame.clientWidth / 2, this.frame.clientHeight / 2);
|
14340 | this._setScale(1);
|
14341 | this.setOptions(options);
|
14342 |
|
14343 |
|
14344 | this.freezeSimulation = false;
|
14345 | this.cachedFunctions = {};
|
14346 | this.stabilized = false;
|
14347 | this.stabilizationIterations = null;
|
14348 |
|
14349 |
|
14350 | this.calculationNodes = {};
|
14351 | this.calculationNodeIndices = [];
|
14352 | this.nodeIndices = [];
|
14353 | this.nodes = {};
|
14354 | this.edges = {};
|
14355 |
|
14356 |
|
14357 | this.canvasTopLeft = {"x": 0,"y": 0};
|
14358 | this.canvasBottomRight = {"x": 0,"y": 0};
|
14359 | this.pointerPosition = {"x": 0,"y": 0};
|
14360 | this.areaCenter = {};
|
14361 | this.scale = 1;
|
14362 | this.previousScale = this.scale;
|
14363 |
|
14364 |
|
14365 | this.nodesData = null;
|
14366 | this.edgesData = null;
|
14367 |
|
14368 |
|
14369 | this.nodesListeners = {
|
14370 | 'add': function (event, params) {
|
14371 | network._addNodes(params.items);
|
14372 | network.start();
|
14373 | },
|
14374 | 'update': function (event, params) {
|
14375 | network._updateNodes(params.items);
|
14376 | network.start();
|
14377 | },
|
14378 | 'remove': function (event, params) {
|
14379 | network._removeNodes(params.items);
|
14380 | network.start();
|
14381 | }
|
14382 | };
|
14383 | this.edgesListeners = {
|
14384 | 'add': function (event, params) {
|
14385 | network._addEdges(params.items);
|
14386 | network.start();
|
14387 | },
|
14388 | 'update': function (event, params) {
|
14389 | network._updateEdges(params.items);
|
14390 | network.start();
|
14391 | },
|
14392 | 'remove': function (event, params) {
|
14393 | network._removeEdges(params.items);
|
14394 | network.start();
|
14395 | }
|
14396 | };
|
14397 |
|
14398 |
|
14399 | this.moving = true;
|
14400 | this.timer = undefined;
|
14401 |
|
14402 |
|
14403 | this.setData(data,this.constants.clustering.enabled || this.constants.hierarchicalLayout.enabled);
|
14404 |
|
14405 |
|
14406 | this.initializing = false;
|
14407 | if (this.constants.hierarchicalLayout.enabled == true) {
|
14408 | this._setupHierarchicalLayout();
|
14409 | }
|
14410 | else {
|
14411 |
|
14412 | if (this.constants.stabilize == false) {
|
14413 | this.zoomExtent(undefined, true,this.constants.clustering.enabled);
|
14414 | }
|
14415 | }
|
14416 |
|
14417 |
|
14418 | if (this.constants.clustering.enabled) {
|
14419 | this.startWithClustering();
|
14420 | }
|
14421 | }
|
14422 |
|
14423 |
|
14424 | Emitter(Network.prototype);
|
14425 |
|
14426 | |
14427 |
|
14428 |
|
14429 |
|
14430 |
|
14431 |
|
14432 |
|
14433 | Network.prototype._getScriptPath = function() {
|
14434 | var scripts = document.getElementsByTagName( 'script' );
|
14435 |
|
14436 |
|
14437 | for (var i = 0; i < scripts.length; i++) {
|
14438 | var src = scripts[i].src;
|
14439 | var match = src && /\/?vis(.min)?\.js$/.exec(src);
|
14440 | if (match) {
|
14441 |
|
14442 | return src.substring(0, src.length - match[0].length);
|
14443 | }
|
14444 | }
|
14445 |
|
14446 | return null;
|
14447 | };
|
14448 |
|
14449 |
|
14450 | |
14451 |
|
14452 |
|
14453 |
|
14454 | Network.prototype._getRange = function() {
|
14455 | var minY = 1e9, maxY = -1e9, minX = 1e9, maxX = -1e9, node;
|
14456 | for (var nodeId in this.nodes) {
|
14457 | if (this.nodes.hasOwnProperty(nodeId)) {
|
14458 | node = this.nodes[nodeId];
|
14459 | if (minX > (node.x)) {minX = node.x;}
|
14460 | if (maxX < (node.x)) {maxX = node.x;}
|
14461 | if (minY > (node.y)) {minY = node.y;}
|
14462 | if (maxY < (node.y)) {maxY = node.y;}
|
14463 | }
|
14464 | }
|
14465 | if (minX == 1e9 && maxX == -1e9 && minY == 1e9 && maxY == -1e9) {
|
14466 | minY = 0, maxY = 0, minX = 0, maxX = 0;
|
14467 | }
|
14468 | return {minX: minX, maxX: maxX, minY: minY, maxY: maxY};
|
14469 | };
|
14470 |
|
14471 |
|
14472 | |
14473 |
|
14474 |
|
14475 |
|
14476 |
|
14477 | Network.prototype._findCenter = function(range) {
|
14478 | return {x: (0.5 * (range.maxX + range.minX)),
|
14479 | y: (0.5 * (range.maxY + range.minY))};
|
14480 | };
|
14481 |
|
14482 |
|
14483 | |
14484 |
|
14485 |
|
14486 |
|
14487 |
|
14488 |
|
14489 | Network.prototype.zoomExtent = function(animationOptions, initialZoom, disableStart) {
|
14490 | if (initialZoom === undefined) {
|
14491 | initialZoom = false;
|
14492 | }
|
14493 | if (disableStart === undefined) {
|
14494 | disableStart = false;
|
14495 | }
|
14496 | if (animationOptions === undefined) {
|
14497 | animationOptions = false;
|
14498 | }
|
14499 |
|
14500 | var range = this._getRange();
|
14501 | var zoomLevel;
|
14502 |
|
14503 | if (initialZoom == true) {
|
14504 | var numberOfNodes = this.nodeIndices.length;
|
14505 | if (this.constants.smoothCurves == true) {
|
14506 | if (this.constants.clustering.enabled == true &&
|
14507 | numberOfNodes >= this.constants.clustering.initialMaxNodes) {
|
14508 | zoomLevel = 49.07548 / (numberOfNodes + 142.05338) + 9.1444e-04;
|
14509 | }
|
14510 | else {
|
14511 | zoomLevel = 12.662 / (numberOfNodes + 7.4147) + 0.0964822;
|
14512 | }
|
14513 | }
|
14514 | else {
|
14515 | if (this.constants.clustering.enabled == true &&
|
14516 | numberOfNodes >= this.constants.clustering.initialMaxNodes) {
|
14517 | zoomLevel = 77.5271985 / (numberOfNodes + 187.266146) + 4.76710517e-05;
|
14518 | }
|
14519 | else {
|
14520 | zoomLevel = 30.5062972 / (numberOfNodes + 19.93597763) + 0.08413486;
|
14521 | }
|
14522 | }
|
14523 |
|
14524 |
|
14525 | var factor = Math.min(this.frame.canvas.clientWidth / 600, this.frame.canvas.clientHeight / 600);
|
14526 | zoomLevel *= factor;
|
14527 | }
|
14528 | else {
|
14529 | var xDistance = (Math.abs(range.minX) + Math.abs(range.maxX)) * 1.1;
|
14530 | var yDistance = (Math.abs(range.minY) + Math.abs(range.maxY)) * 1.1;
|
14531 |
|
14532 | var xZoomLevel = this.frame.canvas.clientWidth / xDistance;
|
14533 | var yZoomLevel = this.frame.canvas.clientHeight / yDistance;
|
14534 |
|
14535 | zoomLevel = (xZoomLevel <= yZoomLevel) ? xZoomLevel : yZoomLevel;
|
14536 | }
|
14537 |
|
14538 | if (zoomLevel > 1.0) {
|
14539 | zoomLevel = 1.0;
|
14540 | }
|
14541 |
|
14542 |
|
14543 | var center = this._findCenter(range);
|
14544 | if (disableStart == false) {
|
14545 | var options = {position: center, scale: zoomLevel, animation: animationOptions};
|
14546 | this.moveTo(options);
|
14547 | this.moving = true;
|
14548 | this.start();
|
14549 | }
|
14550 | else {
|
14551 | center.x *= zoomLevel;
|
14552 | center.y *= zoomLevel;
|
14553 | center.x -= 0.5 * this.frame.canvas.clientWidth;
|
14554 | center.y -= 0.5 * this.frame.canvas.clientHeight;
|
14555 | this._setScale(zoomLevel);
|
14556 | this._setTranslation(-center.x,-center.y);
|
14557 | }
|
14558 | };
|
14559 |
|
14560 |
|
14561 | |
14562 |
|
14563 |
|
14564 |
|
14565 | Network.prototype._updateNodeIndexList = function() {
|
14566 | this._clearNodeIndexList();
|
14567 | for (var idx in this.nodes) {
|
14568 | if (this.nodes.hasOwnProperty(idx)) {
|
14569 | this.nodeIndices.push(idx);
|
14570 | }
|
14571 | }
|
14572 | };
|
14573 |
|
14574 |
|
14575 | |
14576 |
|
14577 |
|
14578 |
|
14579 |
|
14580 |
|
14581 |
|
14582 |
|
14583 |
|
14584 |
|
14585 |
|
14586 | Network.prototype.setData = function(data, disableStart) {
|
14587 | if (disableStart === undefined) {
|
14588 | disableStart = false;
|
14589 | }
|
14590 |
|
14591 | this.initializing = true;
|
14592 |
|
14593 | if (data && data.dot && (data.nodes || data.edges)) {
|
14594 | throw new SyntaxError('Data must contain either parameter "dot" or ' +
|
14595 | ' parameter pair "nodes" and "edges", but not both.');
|
14596 | }
|
14597 |
|
14598 |
|
14599 | this.setOptions(data && data.options);
|
14600 |
|
14601 | if (data && data.dot) {
|
14602 |
|
14603 | if(data && data.dot) {
|
14604 | var dotData = dotparser.DOTToGraph(data.dot);
|
14605 | this.setData(dotData);
|
14606 | return;
|
14607 | }
|
14608 | }
|
14609 | else if (data && data.gephi) {
|
14610 |
|
14611 | if(data && data.gephi) {
|
14612 | var gephiData = gephiParser.parseGephi(data.gephi);
|
14613 | this.setData(gephiData);
|
14614 | return;
|
14615 | }
|
14616 | }
|
14617 | else {
|
14618 | this._setNodes(data && data.nodes);
|
14619 | this._setEdges(data && data.edges);
|
14620 | }
|
14621 | this._putDataInSector();
|
14622 | if (disableStart == false) {
|
14623 | if (this.constants.hierarchicalLayout.enabled == true) {
|
14624 | this._resetLevels();
|
14625 | this._setupHierarchicalLayout();
|
14626 | }
|
14627 | else {
|
14628 |
|
14629 | if (this.constants.stabilize) {
|
14630 | this._stabilize();
|
14631 | }
|
14632 | }
|
14633 | this.start();
|
14634 | }
|
14635 | this.initializing = false;
|
14636 | };
|
14637 |
|
14638 | |
14639 |
|
14640 |
|
14641 |
|
14642 | Network.prototype.setOptions = function (options) {
|
14643 | if (options) {
|
14644 | var prop;
|
14645 |
|
14646 | var fields = ['nodes','edges','smoothCurves','hierarchicalLayout','clustering','navigation','keyboard','dataManipulation',
|
14647 | 'onAdd','onEdit','onEditEdge','onConnect','onDelete','clickToUse'
|
14648 | ];
|
14649 | util.selectiveNotDeepExtend(fields,this.constants, options);
|
14650 | util.selectiveNotDeepExtend(['color'],this.constants.nodes, options.nodes);
|
14651 | util.selectiveNotDeepExtend(['color','length'],this.constants.edges, options.edges);
|
14652 |
|
14653 | if (options.physics) {
|
14654 | util.mergeOptions(this.constants.physics, options.physics,'barnesHut');
|
14655 | util.mergeOptions(this.constants.physics, options.physics,'repulsion');
|
14656 |
|
14657 | if (options.physics.hierarchicalRepulsion) {
|
14658 | this.constants.hierarchicalLayout.enabled = true;
|
14659 | this.constants.physics.hierarchicalRepulsion.enabled = true;
|
14660 | this.constants.physics.barnesHut.enabled = false;
|
14661 | for (prop in options.physics.hierarchicalRepulsion) {
|
14662 | if (options.physics.hierarchicalRepulsion.hasOwnProperty(prop)) {
|
14663 | this.constants.physics.hierarchicalRepulsion[prop] = options.physics.hierarchicalRepulsion[prop];
|
14664 | }
|
14665 | }
|
14666 | }
|
14667 | }
|
14668 |
|
14669 | if (options.onAdd) {this.triggerFunctions.add = options.onAdd;}
|
14670 | if (options.onEdit) {this.triggerFunctions.edit = options.onEdit;}
|
14671 | if (options.onEditEdge) {this.triggerFunctions.editEdge = options.onEditEdge;}
|
14672 | if (options.onConnect) {this.triggerFunctions.connect = options.onConnect;}
|
14673 | if (options.onDelete) {this.triggerFunctions.del = options.onDelete;}
|
14674 |
|
14675 | util.mergeOptions(this.constants, options,'smoothCurves');
|
14676 | util.mergeOptions(this.constants, options,'hierarchicalLayout');
|
14677 | util.mergeOptions(this.constants, options,'clustering');
|
14678 | util.mergeOptions(this.constants, options,'navigation');
|
14679 | util.mergeOptions(this.constants, options,'keyboard');
|
14680 | util.mergeOptions(this.constants, options,'dataManipulation');
|
14681 |
|
14682 |
|
14683 | if (options.dataManipulation) {
|
14684 | this.editMode = this.constants.dataManipulation.initiallyVisible;
|
14685 | }
|
14686 |
|
14687 |
|
14688 |
|
14689 | if (options.edges) {
|
14690 | if (options.edges.color !== undefined) {
|
14691 | if (util.isString(options.edges.color)) {
|
14692 | this.constants.edges.color = {};
|
14693 | this.constants.edges.color.color = options.edges.color;
|
14694 | this.constants.edges.color.highlight = options.edges.color;
|
14695 | this.constants.edges.color.hover = options.edges.color;
|
14696 | }
|
14697 | else {
|
14698 | if (options.edges.color.color !== undefined) {this.constants.edges.color.color = options.edges.color.color;}
|
14699 | if (options.edges.color.highlight !== undefined) {this.constants.edges.color.highlight = options.edges.color.highlight;}
|
14700 | if (options.edges.color.hover !== undefined) {this.constants.edges.color.hover = options.edges.color.hover;}
|
14701 | }
|
14702 | }
|
14703 |
|
14704 | if (!options.edges.fontColor) {
|
14705 | if (options.edges.color !== undefined) {
|
14706 | if (util.isString(options.edges.color)) {this.constants.edges.fontColor = options.edges.color;}
|
14707 | else if (options.edges.color.color !== undefined) {this.constants.edges.fontColor = options.edges.color.color;}
|
14708 | }
|
14709 | }
|
14710 | }
|
14711 |
|
14712 | if (options.nodes) {
|
14713 | if (options.nodes.color) {
|
14714 | var newColorObj = util.parseColor(options.nodes.color);
|
14715 | this.constants.nodes.color.background = newColorObj.background;
|
14716 | this.constants.nodes.color.border = newColorObj.border;
|
14717 | this.constants.nodes.color.highlight.background = newColorObj.highlight.background;
|
14718 | this.constants.nodes.color.highlight.border = newColorObj.highlight.border;
|
14719 | this.constants.nodes.color.hover.background = newColorObj.hover.background;
|
14720 | this.constants.nodes.color.hover.border = newColorObj.hover.border;
|
14721 | }
|
14722 | }
|
14723 | if (options.groups) {
|
14724 | for (var groupname in options.groups) {
|
14725 | if (options.groups.hasOwnProperty(groupname)) {
|
14726 | var group = options.groups[groupname];
|
14727 | this.groups.add(groupname, group);
|
14728 | }
|
14729 | }
|
14730 | }
|
14731 |
|
14732 | if (options.tooltip) {
|
14733 | for (prop in options.tooltip) {
|
14734 | if (options.tooltip.hasOwnProperty(prop)) {
|
14735 | this.constants.tooltip[prop] = options.tooltip[prop];
|
14736 | }
|
14737 | }
|
14738 | if (options.tooltip.color) {
|
14739 | this.constants.tooltip.color = util.parseColor(options.tooltip.color);
|
14740 | }
|
14741 | }
|
14742 |
|
14743 | if ('clickToUse' in options) {
|
14744 | if (options.clickToUse) {
|
14745 | this.activator = new Activator(this.frame);
|
14746 | this.activator.on('change', this._createKeyBinds.bind(this));
|
14747 | }
|
14748 | else {
|
14749 | if (this.activator) {
|
14750 | this.activator.destroy();
|
14751 | delete this.activator;
|
14752 | }
|
14753 | }
|
14754 | }
|
14755 |
|
14756 | if (options.labels) {
|
14757 | throw new Error('Option "labels" is deprecated. Use options "locale" and "locales" instead.');
|
14758 | }
|
14759 | }
|
14760 |
|
14761 |
|
14762 |
|
14763 | this._loadPhysicsSystem();
|
14764 |
|
14765 | this._loadNavigationControls();
|
14766 |
|
14767 | this._loadManipulationSystem();
|
14768 |
|
14769 | this._configureSmoothCurves();
|
14770 |
|
14771 |
|
14772 |
|
14773 | this._createKeyBinds();
|
14774 | this.setSize(this.constants.width, this.constants.height);
|
14775 | this.moving = true;
|
14776 | this.start();
|
14777 | };
|
14778 |
|
14779 | |
14780 |
|
14781 |
|
14782 |
|
14783 |
|
14784 |
|
14785 |
|
14786 | Network.prototype._create = function () {
|
14787 |
|
14788 | while (this.containerElement.hasChildNodes()) {
|
14789 | this.containerElement.removeChild(this.containerElement.firstChild);
|
14790 | }
|
14791 |
|
14792 | this.frame = document.createElement('div');
|
14793 | this.frame.className = 'vis network-frame';
|
14794 | this.frame.style.position = 'relative';
|
14795 | this.frame.style.overflow = 'hidden';
|
14796 |
|
14797 |
|
14798 | this.frame.canvas = document.createElement( 'canvas' );
|
14799 | this.frame.canvas.style.position = 'relative';
|
14800 | this.frame.appendChild(this.frame.canvas);
|
14801 | if (!this.frame.canvas.getContext) {
|
14802 | var noCanvas = document.createElement( 'DIV' );
|
14803 | noCanvas.style.color = 'red';
|
14804 | noCanvas.style.fontWeight = 'bold' ;
|
14805 | noCanvas.style.padding = '10px';
|
14806 | noCanvas.innerHTML = 'Error: your browser does not support HTML canvas';
|
14807 | this.frame.canvas.appendChild(noCanvas);
|
14808 | }
|
14809 |
|
14810 | var me = this;
|
14811 | this.drag = {};
|
14812 | this.pinch = {};
|
14813 | this.hammer = Hammer(this.frame.canvas, {
|
14814 | prevent_default: true
|
14815 | });
|
14816 | this.hammer.on('tap', me._onTap.bind(me) );
|
14817 | this.hammer.on('doubletap', me._onDoubleTap.bind(me) );
|
14818 | this.hammer.on('hold', me._onHold.bind(me) );
|
14819 | this.hammer.on('pinch', me._onPinch.bind(me) );
|
14820 | this.hammer.on('touch', me._onTouch.bind(me) );
|
14821 | this.hammer.on('dragstart', me._onDragStart.bind(me) );
|
14822 | this.hammer.on('drag', me._onDrag.bind(me) );
|
14823 | this.hammer.on('dragend', me._onDragEnd.bind(me) );
|
14824 | this.hammer.on('release', me._onRelease.bind(me) );
|
14825 | this.hammer.on('mousewheel',me._onMouseWheel.bind(me) );
|
14826 | this.hammer.on('DOMMouseScroll',me._onMouseWheel.bind(me) );
|
14827 | this.hammer.on('mousemove', me._onMouseMoveTitle.bind(me) );
|
14828 |
|
14829 |
|
14830 | this.containerElement.appendChild(this.frame);
|
14831 |
|
14832 | };
|
14833 |
|
14834 |
|
14835 | |
14836 |
|
14837 |
|
14838 |
|
14839 | Network.prototype._createKeyBinds = function() {
|
14840 | var me = this;
|
14841 | this.mousetrap = mousetrap;
|
14842 |
|
14843 | this.mousetrap.reset();
|
14844 |
|
14845 | if (this.constants.keyboard.enabled && this.isActive()) {
|
14846 | this.mousetrap.bind("up", this._moveUp.bind(me) , "keydown");
|
14847 | this.mousetrap.bind("up", this._yStopMoving.bind(me), "keyup");
|
14848 | this.mousetrap.bind("down", this._moveDown.bind(me) , "keydown");
|
14849 | this.mousetrap.bind("down", this._yStopMoving.bind(me), "keyup");
|
14850 | this.mousetrap.bind("left", this._moveLeft.bind(me) , "keydown");
|
14851 | this.mousetrap.bind("left", this._xStopMoving.bind(me), "keyup");
|
14852 | this.mousetrap.bind("right",this._moveRight.bind(me), "keydown");
|
14853 | this.mousetrap.bind("right",this._xStopMoving.bind(me), "keyup");
|
14854 | this.mousetrap.bind("=", this._zoomIn.bind(me), "keydown");
|
14855 | this.mousetrap.bind("=", this._stopZoom.bind(me), "keyup");
|
14856 | this.mousetrap.bind("-", this._zoomOut.bind(me), "keydown");
|
14857 | this.mousetrap.bind("-", this._stopZoom.bind(me), "keyup");
|
14858 | this.mousetrap.bind("[", this._zoomIn.bind(me), "keydown");
|
14859 | this.mousetrap.bind("[", this._stopZoom.bind(me), "keyup");
|
14860 | this.mousetrap.bind("]", this._zoomOut.bind(me), "keydown");
|
14861 | this.mousetrap.bind("]", this._stopZoom.bind(me), "keyup");
|
14862 | this.mousetrap.bind("pageup",this._zoomIn.bind(me), "keydown");
|
14863 | this.mousetrap.bind("pageup",this._stopZoom.bind(me), "keyup");
|
14864 | this.mousetrap.bind("pagedown",this._zoomOut.bind(me),"keydown");
|
14865 | this.mousetrap.bind("pagedown",this._stopZoom.bind(me), "keyup");
|
14866 | }
|
14867 |
|
14868 | if (this.constants.dataManipulation.enabled == true) {
|
14869 | this.mousetrap.bind("escape",this._createManipulatorBar.bind(me));
|
14870 | this.mousetrap.bind("del",this._deleteSelected.bind(me));
|
14871 | }
|
14872 | };
|
14873 |
|
14874 | |
14875 |
|
14876 |
|
14877 |
|
14878 |
|
14879 |
|
14880 | Network.prototype._getPointer = function (touch) {
|
14881 | return {
|
14882 | x: touch.pageX - util.getAbsoluteLeft(this.frame.canvas),
|
14883 | y: touch.pageY - util.getAbsoluteTop(this.frame.canvas)
|
14884 | };
|
14885 | };
|
14886 |
|
14887 | |
14888 |
|
14889 |
|
14890 |
|
14891 |
|
14892 | Network.prototype._onTouch = function (event) {
|
14893 | this.drag.pointer = this._getPointer(event.gesture.center);
|
14894 | this.drag.pinched = false;
|
14895 | this.pinch.scale = this._getScale();
|
14896 |
|
14897 | this._handleTouch(this.drag.pointer);
|
14898 | };
|
14899 |
|
14900 | |
14901 |
|
14902 |
|
14903 |
|
14904 | Network.prototype._onDragStart = function () {
|
14905 | this._handleDragStart();
|
14906 | };
|
14907 |
|
14908 |
|
14909 | |
14910 |
|
14911 |
|
14912 |
|
14913 |
|
14914 |
|
14915 | Network.prototype._handleDragStart = function() {
|
14916 | var drag = this.drag;
|
14917 | var node = this._getNodeAt(drag.pointer);
|
14918 |
|
14919 |
|
14920 | drag.dragging = true;
|
14921 | drag.selection = [];
|
14922 | drag.translation = this._getTranslation();
|
14923 | drag.nodeId = null;
|
14924 |
|
14925 | if (node != null) {
|
14926 | drag.nodeId = node.id;
|
14927 |
|
14928 | if (!node.isSelected()) {
|
14929 | this._selectObject(node,false);
|
14930 | }
|
14931 |
|
14932 | this.emit("dragStart",{nodeIds:this.getSelection().nodes});
|
14933 |
|
14934 |
|
14935 | for (var objectId in this.selectionObj.nodes) {
|
14936 | if (this.selectionObj.nodes.hasOwnProperty(objectId)) {
|
14937 | var object = this.selectionObj.nodes[objectId];
|
14938 | var s = {
|
14939 | id: object.id,
|
14940 | node: object,
|
14941 |
|
14942 |
|
14943 | x: object.x,
|
14944 | y: object.y,
|
14945 | xFixed: object.xFixed,
|
14946 | yFixed: object.yFixed
|
14947 | };
|
14948 |
|
14949 | object.xFixed = true;
|
14950 | object.yFixed = true;
|
14951 |
|
14952 | drag.selection.push(s);
|
14953 | }
|
14954 | }
|
14955 | }
|
14956 | };
|
14957 |
|
14958 |
|
14959 | |
14960 |
|
14961 |
|
14962 |
|
14963 | Network.prototype._onDrag = function (event) {
|
14964 | this._handleOnDrag(event)
|
14965 | };
|
14966 |
|
14967 |
|
14968 | |
14969 |
|
14970 |
|
14971 |
|
14972 |
|
14973 |
|
14974 | Network.prototype._handleOnDrag = function(event) {
|
14975 | if (this.drag.pinched) {
|
14976 | return;
|
14977 | }
|
14978 |
|
14979 |
|
14980 | this.releaseNode();
|
14981 |
|
14982 | var pointer = this._getPointer(event.gesture.center);
|
14983 | var me = this;
|
14984 | var drag = this.drag;
|
14985 | var selection = drag.selection;
|
14986 | if (selection && selection.length && this.constants.dragNodes == true) {
|
14987 |
|
14988 | var deltaX = pointer.x - drag.pointer.x;
|
14989 | var deltaY = pointer.y - drag.pointer.y;
|
14990 |
|
14991 |
|
14992 | selection.forEach(function (s) {
|
14993 | var node = s.node;
|
14994 |
|
14995 | if (!s.xFixed) {
|
14996 | node.x = me._XconvertDOMtoCanvas(me._XconvertCanvasToDOM(s.x) + deltaX);
|
14997 | }
|
14998 |
|
14999 | if (!s.yFixed) {
|
15000 | node.y = me._YconvertDOMtoCanvas(me._YconvertCanvasToDOM(s.y) + deltaY);
|
15001 | }
|
15002 | });
|
15003 |
|
15004 |
|
15005 |
|
15006 | if (!this.moving) {
|
15007 | this.moving = true;
|
15008 | this.start();
|
15009 | }
|
15010 | }
|
15011 | else {
|
15012 | if (this.constants.dragNetwork == true) {
|
15013 |
|
15014 | var diffX = pointer.x - this.drag.pointer.x;
|
15015 | var diffY = pointer.y - this.drag.pointer.y;
|
15016 |
|
15017 | this._setTranslation(
|
15018 | this.drag.translation.x + diffX,
|
15019 | this.drag.translation.y + diffY
|
15020 | );
|
15021 | this._redraw();
|
15022 |
|
15023 |
|
15024 | }
|
15025 | }
|
15026 | };
|
15027 |
|
15028 | |
15029 |
|
15030 |
|
15031 |
|
15032 | Network.prototype._onDragEnd = function (event) {
|
15033 | this._handleDragEnd(event);
|
15034 | };
|
15035 |
|
15036 |
|
15037 | Network.prototype._handleDragEnd = function(event) {
|
15038 | this.drag.dragging = false;
|
15039 | var selection = this.drag.selection;
|
15040 | if (selection && selection.length) {
|
15041 | selection.forEach(function (s) {
|
15042 |
|
15043 | s.node.xFixed = s.xFixed;
|
15044 | s.node.yFixed = s.yFixed;
|
15045 | });
|
15046 | this.moving = true;
|
15047 | this.start();
|
15048 | }
|
15049 | else {
|
15050 | this._redraw();
|
15051 | }
|
15052 | this.emit("dragEnd",{nodeIds:this.getSelection().nodes});
|
15053 | }
|
15054 | |
15055 |
|
15056 |
|
15057 |
|
15058 | Network.prototype._onTap = function (event) {
|
15059 | var pointer = this._getPointer(event.gesture.center);
|
15060 | this.pointerPosition = pointer;
|
15061 | this._handleTap(pointer);
|
15062 |
|
15063 | };
|
15064 |
|
15065 |
|
15066 | |
15067 |
|
15068 |
|
15069 |
|
15070 | Network.prototype._onDoubleTap = function (event) {
|
15071 | var pointer = this._getPointer(event.gesture.center);
|
15072 | this._handleDoubleTap(pointer);
|
15073 | };
|
15074 |
|
15075 |
|
15076 | |
15077 |
|
15078 |
|
15079 |
|
15080 | Network.prototype._onHold = function (event) {
|
15081 | var pointer = this._getPointer(event.gesture.center);
|
15082 | this.pointerPosition = pointer;
|
15083 | this._handleOnHold(pointer);
|
15084 | };
|
15085 |
|
15086 | |
15087 |
|
15088 |
|
15089 |
|
15090 |
|
15091 | Network.prototype._onRelease = function (event) {
|
15092 | var pointer = this._getPointer(event.gesture.center);
|
15093 | this._handleOnRelease(pointer);
|
15094 | };
|
15095 |
|
15096 | |
15097 |
|
15098 |
|
15099 |
|
15100 |
|
15101 | Network.prototype._onPinch = function (event) {
|
15102 | var pointer = this._getPointer(event.gesture.center);
|
15103 |
|
15104 | this.drag.pinched = true;
|
15105 | if (!('scale' in this.pinch)) {
|
15106 | this.pinch.scale = 1;
|
15107 | }
|
15108 |
|
15109 |
|
15110 | var scale = this.pinch.scale * event.gesture.scale;
|
15111 | this._zoom(scale, pointer)
|
15112 | };
|
15113 |
|
15114 | |
15115 |
|
15116 |
|
15117 |
|
15118 |
|
15119 |
|
15120 |
|
15121 | Network.prototype._zoom = function(scale, pointer) {
|
15122 | if (this.constants.zoomable == true) {
|
15123 | var scaleOld = this._getScale();
|
15124 | if (scale < 0.00001) {
|
15125 | scale = 0.00001;
|
15126 | }
|
15127 | if (scale > 10) {
|
15128 | scale = 10;
|
15129 | }
|
15130 |
|
15131 | var preScaleDragPointer = null;
|
15132 | if (this.drag !== undefined) {
|
15133 | if (this.drag.dragging == true) {
|
15134 | preScaleDragPointer = this.DOMtoCanvas(this.drag.pointer);
|
15135 | }
|
15136 | }
|
15137 |
|
15138 | var translation = this._getTranslation();
|
15139 |
|
15140 | var scaleFrac = scale / scaleOld;
|
15141 | var tx = (1 - scaleFrac) * pointer.x + translation.x * scaleFrac;
|
15142 | var ty = (1 - scaleFrac) * pointer.y + translation.y * scaleFrac;
|
15143 |
|
15144 | this.areaCenter = {"x" : this._XconvertDOMtoCanvas(pointer.x),
|
15145 | "y" : this._YconvertDOMtoCanvas(pointer.y)};
|
15146 |
|
15147 | this._setScale(scale);
|
15148 | this._setTranslation(tx, ty);
|
15149 | this.updateClustersDefault();
|
15150 |
|
15151 | if (preScaleDragPointer != null) {
|
15152 | var postScaleDragPointer = this.canvasToDOM(preScaleDragPointer);
|
15153 | this.drag.pointer.x = postScaleDragPointer.x;
|
15154 | this.drag.pointer.y = postScaleDragPointer.y;
|
15155 | }
|
15156 |
|
15157 | this._redraw();
|
15158 |
|
15159 | if (scaleOld < scale) {
|
15160 | this.emit("zoom", {direction:"+"});
|
15161 | }
|
15162 | else {
|
15163 | this.emit("zoom", {direction:"-"});
|
15164 | }
|
15165 |
|
15166 | return scale;
|
15167 | }
|
15168 | };
|
15169 |
|
15170 |
|
15171 | |
15172 |
|
15173 |
|
15174 |
|
15175 |
|
15176 |
|
15177 |
|
15178 | Network.prototype._onMouseWheel = function(event) {
|
15179 |
|
15180 | var delta = 0;
|
15181 | if (event.wheelDelta) {
|
15182 | delta = event.wheelDelta/120;
|
15183 | } else if (event.detail) {
|
15184 |
|
15185 |
|
15186 | delta = -event.detail/3;
|
15187 | }
|
15188 |
|
15189 |
|
15190 |
|
15191 |
|
15192 | if (delta) {
|
15193 |
|
15194 |
|
15195 | var scale = this._getScale();
|
15196 | var zoom = delta / 10;
|
15197 | if (delta < 0) {
|
15198 | zoom = zoom / (1 - zoom);
|
15199 | }
|
15200 | scale *= (1 + zoom);
|
15201 |
|
15202 |
|
15203 | var gesture = hammerUtil.fakeGesture(this, event);
|
15204 | var pointer = this._getPointer(gesture.center);
|
15205 |
|
15206 |
|
15207 | this._zoom(scale, pointer);
|
15208 | }
|
15209 |
|
15210 |
|
15211 | event.preventDefault();
|
15212 | };
|
15213 |
|
15214 |
|
15215 | |
15216 |
|
15217 |
|
15218 |
|
15219 |
|
15220 | Network.prototype._onMouseMoveTitle = function (event) {
|
15221 | var gesture = hammerUtil.fakeGesture(this, event);
|
15222 | var pointer = this._getPointer(gesture.center);
|
15223 |
|
15224 |
|
15225 | if (this.popupObj) {
|
15226 | this._checkHidePopup(pointer);
|
15227 | }
|
15228 |
|
15229 |
|
15230 |
|
15231 | var me = this;
|
15232 | var checkShow = function() {
|
15233 | me._checkShowPopup(pointer);
|
15234 | };
|
15235 | if (this.popupTimer) {
|
15236 | clearInterval(this.popupTimer);
|
15237 | }
|
15238 | if (!this.drag.dragging) {
|
15239 | this.popupTimer = setTimeout(checkShow, this.constants.tooltip.delay);
|
15240 | }
|
15241 |
|
15242 |
|
15243 | |
15244 |
|
15245 |
|
15246 | if (this.constants.hover == true) {
|
15247 |
|
15248 | for (var edgeId in this.hoverObj.edges) {
|
15249 | if (this.hoverObj.edges.hasOwnProperty(edgeId)) {
|
15250 | this.hoverObj.edges[edgeId].hover = false;
|
15251 | delete this.hoverObj.edges[edgeId];
|
15252 | }
|
15253 | }
|
15254 |
|
15255 |
|
15256 | var obj = this._getNodeAt(pointer);
|
15257 | if (obj == null) {
|
15258 | obj = this._getEdgeAt(pointer);
|
15259 | }
|
15260 | if (obj != null) {
|
15261 | this._hoverObject(obj);
|
15262 | }
|
15263 |
|
15264 |
|
15265 | for (var nodeId in this.hoverObj.nodes) {
|
15266 | if (this.hoverObj.nodes.hasOwnProperty(nodeId)) {
|
15267 | if (obj instanceof Node && obj.id != nodeId || obj instanceof Edge || obj == null) {
|
15268 | this._blurObject(this.hoverObj.nodes[nodeId]);
|
15269 | delete this.hoverObj.nodes[nodeId];
|
15270 | }
|
15271 | }
|
15272 | }
|
15273 | this.redraw();
|
15274 | }
|
15275 | };
|
15276 |
|
15277 | |
15278 |
|
15279 |
|
15280 |
|
15281 |
|
15282 |
|
15283 |
|
15284 |
|
15285 | Network.prototype._checkShowPopup = function (pointer) {
|
15286 | var obj = {
|
15287 | left: this._XconvertDOMtoCanvas(pointer.x),
|
15288 | top: this._YconvertDOMtoCanvas(pointer.y),
|
15289 | right: this._XconvertDOMtoCanvas(pointer.x),
|
15290 | bottom: this._YconvertDOMtoCanvas(pointer.y)
|
15291 | };
|
15292 |
|
15293 | var id;
|
15294 | var lastPopupNode = this.popupObj;
|
15295 |
|
15296 | if (this.popupObj == undefined) {
|
15297 |
|
15298 | var nodes = this.nodes;
|
15299 | for (id in nodes) {
|
15300 | if (nodes.hasOwnProperty(id)) {
|
15301 | var node = nodes[id];
|
15302 | if (node.getTitle() !== undefined && node.isOverlappingWith(obj)) {
|
15303 | this.popupObj = node;
|
15304 | break;
|
15305 | }
|
15306 | }
|
15307 | }
|
15308 | }
|
15309 |
|
15310 | if (this.popupObj === undefined) {
|
15311 |
|
15312 | var edges = this.edges;
|
15313 | for (id in edges) {
|
15314 | if (edges.hasOwnProperty(id)) {
|
15315 | var edge = edges[id];
|
15316 | if (edge.connected && (edge.getTitle() !== undefined) &&
|
15317 | edge.isOverlappingWith(obj)) {
|
15318 | this.popupObj = edge;
|
15319 | break;
|
15320 | }
|
15321 | }
|
15322 | }
|
15323 | }
|
15324 |
|
15325 | if (this.popupObj) {
|
15326 |
|
15327 | if (this.popupObj != lastPopupNode) {
|
15328 | var me = this;
|
15329 | if (!me.popup) {
|
15330 | me.popup = new Popup(me.frame, me.constants.tooltip);
|
15331 | }
|
15332 |
|
15333 |
|
15334 |
|
15335 |
|
15336 | me.popup.setPosition(pointer.x - 3, pointer.y - 3);
|
15337 | me.popup.setText(me.popupObj.getTitle());
|
15338 | me.popup.show();
|
15339 | }
|
15340 | }
|
15341 | else {
|
15342 | if (this.popup) {
|
15343 | this.popup.hide();
|
15344 | }
|
15345 | }
|
15346 | };
|
15347 |
|
15348 |
|
15349 | |
15350 |
|
15351 |
|
15352 |
|
15353 |
|
15354 |
|
15355 | Network.prototype._checkHidePopup = function (pointer) {
|
15356 | if (!this.popupObj || !this._getNodeAt(pointer) ) {
|
15357 | this.popupObj = undefined;
|
15358 | if (this.popup) {
|
15359 | this.popup.hide();
|
15360 | }
|
15361 | }
|
15362 | };
|
15363 |
|
15364 |
|
15365 | |
15366 |
|
15367 |
|
15368 |
|
15369 |
|
15370 |
|
15371 |
|
15372 | Network.prototype.setSize = function(width, height) {
|
15373 | var emitEvent = false;
|
15374 | if (width != this.constants.width || height != this.constants.height || this.frame.style.width != width || this.frame.style.height != height) {
|
15375 | this.frame.style.width = width;
|
15376 | this.frame.style.height = height;
|
15377 |
|
15378 | this.frame.canvas.style.width = '100%';
|
15379 | this.frame.canvas.style.height = '100%';
|
15380 |
|
15381 | this.frame.canvas.width = this.frame.canvas.clientWidth;
|
15382 | this.frame.canvas.height = this.frame.canvas.clientHeight;
|
15383 |
|
15384 | this.constants.width = width;
|
15385 | this.constants.height = height;
|
15386 |
|
15387 | emitEvent = true;
|
15388 | }
|
15389 | else {
|
15390 |
|
15391 |
|
15392 |
|
15393 | if (this.frame.canvas.width != this.frame.canvas.clientWidth) {
|
15394 | this.frame.canvas.width = this.frame.canvas.clientWidth;
|
15395 | emitEvent = true;
|
15396 | }
|
15397 | if (this.frame.canvas.height != this.frame.canvas.clientHeight) {
|
15398 | this.frame.canvas.height = this.frame.canvas.clientHeight;
|
15399 | emitEvent = true;
|
15400 | }
|
15401 | }
|
15402 |
|
15403 | if (emitEvent == true) {
|
15404 | this.emit('resize', {width:this.frame.canvas.width,height:this.frame.canvas.height});
|
15405 | }
|
15406 | };
|
15407 |
|
15408 | |
15409 |
|
15410 |
|
15411 |
|
15412 |
|
15413 | Network.prototype._setNodes = function(nodes) {
|
15414 | var oldNodesData = this.nodesData;
|
15415 |
|
15416 | if (nodes instanceof DataSet || nodes instanceof DataView) {
|
15417 | this.nodesData = nodes;
|
15418 | }
|
15419 | else if (nodes instanceof Array) {
|
15420 | this.nodesData = new DataSet();
|
15421 | this.nodesData.add(nodes);
|
15422 | }
|
15423 | else if (!nodes) {
|
15424 | this.nodesData = new DataSet();
|
15425 | }
|
15426 | else {
|
15427 | throw new TypeError('Array or DataSet expected');
|
15428 | }
|
15429 |
|
15430 | if (oldNodesData) {
|
15431 |
|
15432 | util.forEach(this.nodesListeners, function (callback, event) {
|
15433 | oldNodesData.off(event, callback);
|
15434 | });
|
15435 | }
|
15436 |
|
15437 |
|
15438 | this.nodes = {};
|
15439 |
|
15440 | if (this.nodesData) {
|
15441 |
|
15442 | var me = this;
|
15443 | util.forEach(this.nodesListeners, function (callback, event) {
|
15444 | me.nodesData.on(event, callback);
|
15445 | });
|
15446 |
|
15447 |
|
15448 | var ids = this.nodesData.getIds();
|
15449 | this._addNodes(ids);
|
15450 | }
|
15451 | this._updateSelection();
|
15452 | };
|
15453 |
|
15454 | |
15455 |
|
15456 |
|
15457 |
|
15458 |
|
15459 | Network.prototype._addNodes = function(ids) {
|
15460 | var id;
|
15461 | for (var i = 0, len = ids.length; i < len; i++) {
|
15462 | id = ids[i];
|
15463 | var data = this.nodesData.get(id);
|
15464 | var node = new Node(data, this.images, this.groups, this.constants);
|
15465 | this.nodes[id] = node;
|
15466 | if ((node.xFixed == false || node.yFixed == false) && (node.x === null || node.y === null)) {
|
15467 | var radius = 10 * 0.1*ids.length + 10;
|
15468 | var angle = 2 * Math.PI * Math.random();
|
15469 | if (node.xFixed == false) {node.x = radius * Math.cos(angle);}
|
15470 | if (node.yFixed == false) {node.y = radius * Math.sin(angle);}
|
15471 | }
|
15472 | this.moving = true;
|
15473 | }
|
15474 |
|
15475 | this._updateNodeIndexList();
|
15476 | if (this.constants.hierarchicalLayout.enabled == true && this.initializing == false) {
|
15477 | this._resetLevels();
|
15478 | this._setupHierarchicalLayout();
|
15479 | }
|
15480 | this._updateCalculationNodes();
|
15481 | this._reconnectEdges();
|
15482 | this._updateValueRange(this.nodes);
|
15483 | this.updateLabels();
|
15484 | };
|
15485 |
|
15486 | |
15487 |
|
15488 |
|
15489 |
|
15490 |
|
15491 | Network.prototype._updateNodes = function(ids) {
|
15492 | var nodes = this.nodes,
|
15493 | nodesData = this.nodesData;
|
15494 | for (var i = 0, len = ids.length; i < len; i++) {
|
15495 | var id = ids[i];
|
15496 | var node = nodes[id];
|
15497 | var data = nodesData.get(id);
|
15498 | if (node) {
|
15499 |
|
15500 | node.setProperties(data, this.constants);
|
15501 | }
|
15502 | else {
|
15503 |
|
15504 | node = new Node(properties, this.images, this.groups, this.constants);
|
15505 | nodes[id] = node;
|
15506 | }
|
15507 | }
|
15508 | this.moving = true;
|
15509 | if (this.constants.hierarchicalLayout.enabled == true && this.initializing == false) {
|
15510 | this._resetLevels();
|
15511 | this._setupHierarchicalLayout();
|
15512 | }
|
15513 | this._updateNodeIndexList();
|
15514 | this._reconnectEdges();
|
15515 | this._updateValueRange(nodes);
|
15516 | };
|
15517 |
|
15518 | |
15519 |
|
15520 |
|
15521 |
|
15522 |
|
15523 | Network.prototype._removeNodes = function(ids) {
|
15524 | var nodes = this.nodes;
|
15525 | for (var i = 0, len = ids.length; i < len; i++) {
|
15526 | var id = ids[i];
|
15527 | delete nodes[id];
|
15528 | }
|
15529 | this._updateNodeIndexList();
|
15530 | if (this.constants.hierarchicalLayout.enabled == true && this.initializing == false) {
|
15531 | this._resetLevels();
|
15532 | this._setupHierarchicalLayout();
|
15533 | }
|
15534 | this._updateCalculationNodes();
|
15535 | this._reconnectEdges();
|
15536 | this._updateSelection();
|
15537 | this._updateValueRange(nodes);
|
15538 | };
|
15539 |
|
15540 | |
15541 |
|
15542 |
|
15543 |
|
15544 |
|
15545 |
|
15546 | Network.prototype._setEdges = function(edges) {
|
15547 | var oldEdgesData = this.edgesData;
|
15548 |
|
15549 | if (edges instanceof DataSet || edges instanceof DataView) {
|
15550 | this.edgesData = edges;
|
15551 | }
|
15552 | else if (edges instanceof Array) {
|
15553 | this.edgesData = new DataSet();
|
15554 | this.edgesData.add(edges);
|
15555 | }
|
15556 | else if (!edges) {
|
15557 | this.edgesData = new DataSet();
|
15558 | }
|
15559 | else {
|
15560 | throw new TypeError('Array or DataSet expected');
|
15561 | }
|
15562 |
|
15563 | if (oldEdgesData) {
|
15564 |
|
15565 | util.forEach(this.edgesListeners, function (callback, event) {
|
15566 | oldEdgesData.off(event, callback);
|
15567 | });
|
15568 | }
|
15569 |
|
15570 |
|
15571 | this.edges = {};
|
15572 |
|
15573 | if (this.edgesData) {
|
15574 |
|
15575 | var me = this;
|
15576 | util.forEach(this.edgesListeners, function (callback, event) {
|
15577 | me.edgesData.on(event, callback);
|
15578 | });
|
15579 |
|
15580 |
|
15581 | var ids = this.edgesData.getIds();
|
15582 | this._addEdges(ids);
|
15583 | }
|
15584 |
|
15585 | this._reconnectEdges();
|
15586 | };
|
15587 |
|
15588 | |
15589 |
|
15590 |
|
15591 |
|
15592 |
|
15593 | Network.prototype._addEdges = function (ids) {
|
15594 | var edges = this.edges,
|
15595 | edgesData = this.edgesData;
|
15596 |
|
15597 | for (var i = 0, len = ids.length; i < len; i++) {
|
15598 | var id = ids[i];
|
15599 |
|
15600 | var oldEdge = edges[id];
|
15601 | if (oldEdge) {
|
15602 | oldEdge.disconnect();
|
15603 | }
|
15604 |
|
15605 | var data = edgesData.get(id, {"showInternalIds" : true});
|
15606 | edges[id] = new Edge(data, this, this.constants);
|
15607 | }
|
15608 | this.moving = true;
|
15609 | this._updateValueRange(edges);
|
15610 | this._createBezierNodes();
|
15611 | this._updateCalculationNodes();
|
15612 | if (this.constants.hierarchicalLayout.enabled == true && this.initializing == false) {
|
15613 | this._resetLevels();
|
15614 | this._setupHierarchicalLayout();
|
15615 | }
|
15616 | };
|
15617 |
|
15618 | |
15619 |
|
15620 |
|
15621 |
|
15622 |
|
15623 | Network.prototype._updateEdges = function (ids) {
|
15624 | var edges = this.edges,
|
15625 | edgesData = this.edgesData;
|
15626 | for (var i = 0, len = ids.length; i < len; i++) {
|
15627 | var id = ids[i];
|
15628 |
|
15629 | var data = edgesData.get(id);
|
15630 | var edge = edges[id];
|
15631 | if (edge) {
|
15632 |
|
15633 | edge.disconnect();
|
15634 | edge.setProperties(data, this.constants);
|
15635 | edge.connect();
|
15636 | }
|
15637 | else {
|
15638 |
|
15639 | edge = new Edge(data, this, this.constants);
|
15640 | this.edges[id] = edge;
|
15641 | }
|
15642 | }
|
15643 |
|
15644 | this._createBezierNodes();
|
15645 | if (this.constants.hierarchicalLayout.enabled == true && this.initializing == false) {
|
15646 | this._resetLevels();
|
15647 | this._setupHierarchicalLayout();
|
15648 | }
|
15649 | this.moving = true;
|
15650 | this._updateValueRange(edges);
|
15651 | };
|
15652 |
|
15653 | |
15654 |
|
15655 |
|
15656 |
|
15657 |
|
15658 | Network.prototype._removeEdges = function (ids) {
|
15659 | var edges = this.edges;
|
15660 | for (var i = 0, len = ids.length; i < len; i++) {
|
15661 | var id = ids[i];
|
15662 | var edge = edges[id];
|
15663 | if (edge) {
|
15664 | if (edge.via != null) {
|
15665 | delete this.sectors['support']['nodes'][edge.via.id];
|
15666 | }
|
15667 | edge.disconnect();
|
15668 | delete edges[id];
|
15669 | }
|
15670 | }
|
15671 |
|
15672 | this.moving = true;
|
15673 | this._updateValueRange(edges);
|
15674 | if (this.constants.hierarchicalLayout.enabled == true && this.initializing == false) {
|
15675 | this._resetLevels();
|
15676 | this._setupHierarchicalLayout();
|
15677 | }
|
15678 | this._updateCalculationNodes();
|
15679 | };
|
15680 |
|
15681 | |
15682 |
|
15683 |
|
15684 |
|
15685 | Network.prototype._reconnectEdges = function() {
|
15686 | var id,
|
15687 | nodes = this.nodes,
|
15688 | edges = this.edges;
|
15689 | for (id in nodes) {
|
15690 | if (nodes.hasOwnProperty(id)) {
|
15691 | nodes[id].edges = [];
|
15692 | nodes[id].dynamicEdges = [];
|
15693 | }
|
15694 | }
|
15695 |
|
15696 | for (id in edges) {
|
15697 | if (edges.hasOwnProperty(id)) {
|
15698 | var edge = edges[id];
|
15699 | edge.from = null;
|
15700 | edge.to = null;
|
15701 | edge.connect();
|
15702 | }
|
15703 | }
|
15704 | };
|
15705 |
|
15706 | |
15707 |
|
15708 |
|
15709 |
|
15710 |
|
15711 |
|
15712 |
|
15713 |
|
15714 | Network.prototype._updateValueRange = function(obj) {
|
15715 | var id;
|
15716 |
|
15717 |
|
15718 | var valueMin = undefined;
|
15719 | var valueMax = undefined;
|
15720 | for (id in obj) {
|
15721 | if (obj.hasOwnProperty(id)) {
|
15722 | var value = obj[id].getValue();
|
15723 | if (value !== undefined) {
|
15724 | valueMin = (valueMin === undefined) ? value : Math.min(value, valueMin);
|
15725 | valueMax = (valueMax === undefined) ? value : Math.max(value, valueMax);
|
15726 | }
|
15727 | }
|
15728 | }
|
15729 |
|
15730 |
|
15731 | if (valueMin !== undefined && valueMax !== undefined) {
|
15732 | for (id in obj) {
|
15733 | if (obj.hasOwnProperty(id)) {
|
15734 | obj[id].setValueRange(valueMin, valueMax);
|
15735 | }
|
15736 | }
|
15737 | }
|
15738 | };
|
15739 |
|
15740 | |
15741 |
|
15742 |
|
15743 |
|
15744 | Network.prototype.redraw = function() {
|
15745 | this.setSize(this.constants.width, this.constants.height);
|
15746 | this._redraw();
|
15747 | };
|
15748 |
|
15749 | |
15750 |
|
15751 |
|
15752 |
|
15753 | Network.prototype._redraw = function() {
|
15754 | var ctx = this.frame.canvas.getContext('2d');
|
15755 |
|
15756 | var w = this.frame.canvas.width;
|
15757 | var h = this.frame.canvas.height;
|
15758 | ctx.clearRect(0, 0, w, h);
|
15759 |
|
15760 |
|
15761 | ctx.save();
|
15762 | ctx.translate(this.translation.x, this.translation.y);
|
15763 | ctx.scale(this.scale, this.scale);
|
15764 |
|
15765 | this.canvasTopLeft = {
|
15766 | "x": this._XconvertDOMtoCanvas(0),
|
15767 | "y": this._YconvertDOMtoCanvas(0)
|
15768 | };
|
15769 | this.canvasBottomRight = {
|
15770 | "x": this._XconvertDOMtoCanvas(this.frame.canvas.clientWidth),
|
15771 | "y": this._YconvertDOMtoCanvas(this.frame.canvas.clientHeight)
|
15772 | };
|
15773 |
|
15774 |
|
15775 | this._doInAllSectors("_drawAllSectorNodes",ctx);
|
15776 | if (this.drag.dragging == false || this.drag.dragging === undefined || this.constants.hideEdgesOnDrag == false) {
|
15777 | this._doInAllSectors("_drawEdges",ctx);
|
15778 | }
|
15779 |
|
15780 | if (this.drag.dragging == false || this.drag.dragging === undefined || this.constants.hideNodesOnDrag == false) {
|
15781 | this._doInAllSectors("_drawNodes",ctx,false);
|
15782 | }
|
15783 |
|
15784 | if (this.controlNodesActive == true) {
|
15785 | this._doInAllSectors("_drawControlNodes",ctx);
|
15786 | }
|
15787 |
|
15788 |
|
15789 |
|
15790 |
|
15791 |
|
15792 | ctx.restore();
|
15793 | };
|
15794 |
|
15795 | |
15796 |
|
15797 |
|
15798 |
|
15799 |
|
15800 |
|
15801 | Network.prototype._setTranslation = function(offsetX, offsetY) {
|
15802 | if (this.translation === undefined) {
|
15803 | this.translation = {
|
15804 | x: 0,
|
15805 | y: 0
|
15806 | };
|
15807 | }
|
15808 |
|
15809 | if (offsetX !== undefined) {
|
15810 | this.translation.x = offsetX;
|
15811 | }
|
15812 | if (offsetY !== undefined) {
|
15813 | this.translation.y = offsetY;
|
15814 | }
|
15815 |
|
15816 | this.emit('viewChanged');
|
15817 | };
|
15818 |
|
15819 | |
15820 |
|
15821 |
|
15822 |
|
15823 |
|
15824 | Network.prototype._getTranslation = function() {
|
15825 | return {
|
15826 | x: this.translation.x,
|
15827 | y: this.translation.y
|
15828 | };
|
15829 | };
|
15830 |
|
15831 | |
15832 |
|
15833 |
|
15834 |
|
15835 |
|
15836 | Network.prototype._setScale = function(scale) {
|
15837 | this.scale = scale;
|
15838 | };
|
15839 |
|
15840 | |
15841 |
|
15842 |
|
15843 |
|
15844 |
|
15845 | Network.prototype._getScale = function() {
|
15846 | return this.scale;
|
15847 | };
|
15848 |
|
15849 | |
15850 |
|
15851 |
|
15852 |
|
15853 |
|
15854 |
|
15855 |
|
15856 | Network.prototype._XconvertDOMtoCanvas = function(x) {
|
15857 | return (x - this.translation.x) / this.scale;
|
15858 | };
|
15859 |
|
15860 | |
15861 |
|
15862 |
|
15863 |
|
15864 |
|
15865 |
|
15866 |
|
15867 | Network.prototype._XconvertCanvasToDOM = function(x) {
|
15868 | return x * this.scale + this.translation.x;
|
15869 | };
|
15870 |
|
15871 | |
15872 |
|
15873 |
|
15874 |
|
15875 |
|
15876 |
|
15877 |
|
15878 | Network.prototype._YconvertDOMtoCanvas = function(y) {
|
15879 | return (y - this.translation.y) / this.scale;
|
15880 | };
|
15881 |
|
15882 | |
15883 |
|
15884 |
|
15885 |
|
15886 |
|
15887 |
|
15888 |
|
15889 | Network.prototype._YconvertCanvasToDOM = function(y) {
|
15890 | return y * this.scale + this.translation.y ;
|
15891 | };
|
15892 |
|
15893 |
|
15894 | |
15895 |
|
15896 |
|
15897 |
|
15898 |
|
15899 |
|
15900 | Network.prototype.canvasToDOM = function (pos) {
|
15901 | return {x: this._XconvertCanvasToDOM(pos.x), y: this._YconvertCanvasToDOM(pos.y)};
|
15902 | };
|
15903 |
|
15904 | |
15905 |
|
15906 |
|
15907 |
|
15908 |
|
15909 |
|
15910 | Network.prototype.DOMtoCanvas = function (pos) {
|
15911 | return {x: this._XconvertDOMtoCanvas(pos.x), y: this._YconvertDOMtoCanvas(pos.y)};
|
15912 | };
|
15913 |
|
15914 | |
15915 |
|
15916 |
|
15917 |
|
15918 |
|
15919 |
|
15920 |
|
15921 | Network.prototype._drawNodes = function(ctx,alwaysShow) {
|
15922 | if (alwaysShow === undefined) {
|
15923 | alwaysShow = false;
|
15924 | }
|
15925 |
|
15926 |
|
15927 | var nodes = this.nodes;
|
15928 | var selected = [];
|
15929 |
|
15930 | for (var id in nodes) {
|
15931 | if (nodes.hasOwnProperty(id)) {
|
15932 | nodes[id].setScaleAndPos(this.scale,this.canvasTopLeft,this.canvasBottomRight);
|
15933 | if (nodes[id].isSelected()) {
|
15934 | selected.push(id);
|
15935 | }
|
15936 | else {
|
15937 | if (nodes[id].inArea() || alwaysShow) {
|
15938 | nodes[id].draw(ctx);
|
15939 | }
|
15940 | }
|
15941 | }
|
15942 | }
|
15943 |
|
15944 |
|
15945 | for (var s = 0, sMax = selected.length; s < sMax; s++) {
|
15946 | if (nodes[selected[s]].inArea() || alwaysShow) {
|
15947 | nodes[selected[s]].draw(ctx);
|
15948 | }
|
15949 | }
|
15950 | };
|
15951 |
|
15952 | |
15953 |
|
15954 |
|
15955 |
|
15956 |
|
15957 |
|
15958 | Network.prototype._drawEdges = function(ctx) {
|
15959 | var edges = this.edges;
|
15960 | for (var id in edges) {
|
15961 | if (edges.hasOwnProperty(id)) {
|
15962 | var edge = edges[id];
|
15963 | edge.setScale(this.scale);
|
15964 | if (edge.connected) {
|
15965 | edges[id].draw(ctx);
|
15966 | }
|
15967 | }
|
15968 | }
|
15969 | };
|
15970 |
|
15971 | |
15972 |
|
15973 |
|
15974 |
|
15975 |
|
15976 |
|
15977 | Network.prototype._drawControlNodes = function(ctx) {
|
15978 | var edges = this.edges;
|
15979 | for (var id in edges) {
|
15980 | if (edges.hasOwnProperty(id)) {
|
15981 | edges[id]._drawControlNodes(ctx);
|
15982 | }
|
15983 | }
|
15984 | };
|
15985 |
|
15986 | |
15987 |
|
15988 |
|
15989 |
|
15990 | Network.prototype._stabilize = function() {
|
15991 | if (this.constants.freezeForStabilization == true) {
|
15992 | this._freezeDefinedNodes();
|
15993 | }
|
15994 |
|
15995 |
|
15996 | var count = 0;
|
15997 | while (this.moving && count < this.constants.stabilizationIterations) {
|
15998 | this._physicsTick();
|
15999 | count++;
|
16000 | }
|
16001 | this.zoomExtent(undefined,false,true);
|
16002 | if (this.constants.freezeForStabilization == true) {
|
16003 | this._restoreFrozenNodes();
|
16004 | }
|
16005 | };
|
16006 |
|
16007 | |
16008 |
|
16009 |
|
16010 |
|
16011 |
|
16012 |
|
16013 | Network.prototype._freezeDefinedNodes = function() {
|
16014 | var nodes = this.nodes;
|
16015 | for (var id in nodes) {
|
16016 | if (nodes.hasOwnProperty(id)) {
|
16017 | if (nodes[id].x != null && nodes[id].y != null) {
|
16018 | nodes[id].fixedData.x = nodes[id].xFixed;
|
16019 | nodes[id].fixedData.y = nodes[id].yFixed;
|
16020 | nodes[id].xFixed = true;
|
16021 | nodes[id].yFixed = true;
|
16022 | }
|
16023 | }
|
16024 | }
|
16025 | };
|
16026 |
|
16027 | |
16028 |
|
16029 |
|
16030 |
|
16031 |
|
16032 | Network.prototype._restoreFrozenNodes = function() {
|
16033 | var nodes = this.nodes;
|
16034 | for (var id in nodes) {
|
16035 | if (nodes.hasOwnProperty(id)) {
|
16036 | if (nodes[id].fixedData.x != null) {
|
16037 | nodes[id].xFixed = nodes[id].fixedData.x;
|
16038 | nodes[id].yFixed = nodes[id].fixedData.y;
|
16039 | }
|
16040 | }
|
16041 | }
|
16042 | };
|
16043 |
|
16044 |
|
16045 | |
16046 |
|
16047 |
|
16048 |
|
16049 |
|
16050 |
|
16051 | Network.prototype._isMoving = function(vmin) {
|
16052 | var nodes = this.nodes;
|
16053 | for (var id in nodes) {
|
16054 | if (nodes.hasOwnProperty(id) && nodes[id].isMoving(vmin)) {
|
16055 | return true;
|
16056 | }
|
16057 | }
|
16058 | return false;
|
16059 | };
|
16060 |
|
16061 |
|
16062 | |
16063 |
|
16064 |
|
16065 |
|
16066 |
|
16067 |
|
16068 | Network.prototype._discreteStepNodes = function() {
|
16069 | var interval = this.physicsDiscreteStepsize;
|
16070 | var nodes = this.nodes;
|
16071 | var nodeId;
|
16072 | var nodesPresent = false;
|
16073 |
|
16074 | if (this.constants.maxVelocity > 0) {
|
16075 | for (nodeId in nodes) {
|
16076 | if (nodes.hasOwnProperty(nodeId)) {
|
16077 | nodes[nodeId].discreteStepLimited(interval, this.constants.maxVelocity);
|
16078 | nodesPresent = true;
|
16079 | }
|
16080 | }
|
16081 | }
|
16082 | else {
|
16083 | for (nodeId in nodes) {
|
16084 | if (nodes.hasOwnProperty(nodeId)) {
|
16085 | nodes[nodeId].discreteStep(interval);
|
16086 | nodesPresent = true;
|
16087 | }
|
16088 | }
|
16089 | }
|
16090 |
|
16091 | if (nodesPresent == true) {
|
16092 | var vminCorrected = this.constants.minVelocity / Math.max(this.scale,0.05);
|
16093 | if (vminCorrected > 0.5*this.constants.maxVelocity) {
|
16094 | return true;
|
16095 | }
|
16096 | else {
|
16097 | return this._isMoving(vminCorrected);
|
16098 | }
|
16099 | }
|
16100 | return false;
|
16101 | };
|
16102 |
|
16103 | |
16104 |
|
16105 |
|
16106 |
|
16107 |
|
16108 | Network.prototype._physicsTick = function() {
|
16109 | if (!this.freezeSimulation) {
|
16110 | if (this.moving == true) {
|
16111 | var mainMovingStatus = false;
|
16112 | var supportMovingStatus = false;
|
16113 |
|
16114 | this._doInAllActiveSectors("_initializeForceCalculation");
|
16115 | var mainMoving = this._doInAllActiveSectors("_discreteStepNodes");
|
16116 | if (this.constants.smoothCurves.enabled == true && this.constants.smoothCurves.dynamic == true) {
|
16117 | supportMovingStatus = this._doInSupportSector("_discreteStepNodes");
|
16118 | }
|
16119 |
|
16120 | for (var i = 0; i < mainMoving.length; i++) {mainMovingStatus = mainMoving[0] || mainMovingStatus;}
|
16121 |
|
16122 |
|
16123 | this.moving = mainMovingStatus || supportMovingStatus;
|
16124 |
|
16125 | this.stabilizationIterations++;
|
16126 | }
|
16127 | }
|
16128 | };
|
16129 |
|
16130 |
|
16131 | |
16132 |
|
16133 |
|
16134 |
|
16135 |
|
16136 |
|
16137 | Network.prototype._animationStep = function() {
|
16138 |
|
16139 | this.timer = undefined;
|
16140 |
|
16141 | this._handleNavigation();
|
16142 |
|
16143 |
|
16144 | this.start();
|
16145 |
|
16146 |
|
16147 | var calculationTime = Date.now();
|
16148 | var maxSteps = 1;
|
16149 | this._physicsTick();
|
16150 | var timeRequired = Date.now() - calculationTime;
|
16151 | while (timeRequired < 0.9*(this.renderTimestep - this.renderTime) && maxSteps < this.maxPhysicsTicksPerRender) {
|
16152 | this._physicsTick();
|
16153 | timeRequired = Date.now() - calculationTime;
|
16154 | maxSteps++;
|
16155 | }
|
16156 |
|
16157 | var renderTime = Date.now();
|
16158 | this._redraw();
|
16159 | this.renderTime = Date.now() - renderTime;
|
16160 | };
|
16161 |
|
16162 | if (typeof window !== 'undefined') {
|
16163 | window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame ||
|
16164 | window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
|
16165 | }
|
16166 |
|
16167 | |
16168 |
|
16169 |
|
16170 | Network.prototype.start = function() {
|
16171 | if (this.moving == true || this.xIncrement != 0 || this.yIncrement != 0 || this.zoomIncrement != 0) {
|
16172 | if (!this.timer) {
|
16173 | var ua = navigator.userAgent.toLowerCase();
|
16174 |
|
16175 | var requiresTimeout = false;
|
16176 | if (ua.indexOf('msie 9.0') != -1) {
|
16177 | requiresTimeout = true;
|
16178 | }
|
16179 | else if (ua.indexOf('safari') != -1) {
|
16180 | if (ua.indexOf('chrome') <= -1) {
|
16181 | requiresTimeout = true;
|
16182 | }
|
16183 | }
|
16184 |
|
16185 | if (requiresTimeout == true) {
|
16186 | this.timer = window.setTimeout(this._animationStep.bind(this), this.renderTimestep);
|
16187 | }
|
16188 | else{
|
16189 | this.timer = window.requestAnimationFrame(this._animationStep.bind(this), this.renderTimestep);
|
16190 | }
|
16191 | }
|
16192 | }
|
16193 | else {
|
16194 | this._redraw();
|
16195 | if (this.stabilizationIterations > 0) {
|
16196 |
|
16197 |
|
16198 |
|
16199 |
|
16200 | var me = this;
|
16201 | var params = {
|
16202 | iterations: me.stabilizationIterations
|
16203 | };
|
16204 | me.stabilizationIterations = 0;
|
16205 | setTimeout(function () {
|
16206 | me.emit("stabilized", params);
|
16207 | }, 0);
|
16208 | }
|
16209 | }
|
16210 | };
|
16211 |
|
16212 |
|
16213 | |
16214 |
|
16215 |
|
16216 |
|
16217 |
|
16218 | Network.prototype._handleNavigation = function() {
|
16219 | if (this.xIncrement != 0 || this.yIncrement != 0) {
|
16220 | var translation = this._getTranslation();
|
16221 | this._setTranslation(translation.x+this.xIncrement, translation.y+this.yIncrement);
|
16222 | }
|
16223 | if (this.zoomIncrement != 0) {
|
16224 | var center = {
|
16225 | x: this.frame.canvas.clientWidth / 2,
|
16226 | y: this.frame.canvas.clientHeight / 2
|
16227 | };
|
16228 | this._zoom(this.scale*(1 + this.zoomIncrement), center);
|
16229 | }
|
16230 | };
|
16231 |
|
16232 |
|
16233 | |
16234 |
|
16235 |
|
16236 | Network.prototype.toggleFreeze = function() {
|
16237 | if (this.freezeSimulation == false) {
|
16238 | this.freezeSimulation = true;
|
16239 | }
|
16240 | else {
|
16241 | this.freezeSimulation = false;
|
16242 | this.start();
|
16243 | }
|
16244 | };
|
16245 |
|
16246 |
|
16247 | |
16248 |
|
16249 |
|
16250 |
|
16251 |
|
16252 |
|
16253 | Network.prototype._configureSmoothCurves = function(disableStart) {
|
16254 | if (disableStart === undefined) {
|
16255 | disableStart = true;
|
16256 | }
|
16257 | if (this.constants.smoothCurves.enabled == true && this.constants.smoothCurves.dynamic == true) {
|
16258 | this._createBezierNodes();
|
16259 |
|
16260 | for (var nodeId in this.sectors['support']['nodes']) {
|
16261 | if (this.sectors['support']['nodes'].hasOwnProperty(nodeId)) {
|
16262 | if (this.edges[this.sectors['support']['nodes'][nodeId].parentEdgeId] === undefined) {
|
16263 | delete this.sectors['support']['nodes'][nodeId];
|
16264 | }
|
16265 | }
|
16266 | }
|
16267 | }
|
16268 | else {
|
16269 |
|
16270 | this.sectors['support']['nodes'] = {};
|
16271 | for (var edgeId in this.edges) {
|
16272 | if (this.edges.hasOwnProperty(edgeId)) {
|
16273 | this.edges[edgeId].via = null;
|
16274 | }
|
16275 | }
|
16276 | }
|
16277 |
|
16278 |
|
16279 | this._updateCalculationNodes();
|
16280 | if (!disableStart) {
|
16281 | this.moving = true;
|
16282 | this.start();
|
16283 | }
|
16284 | };
|
16285 |
|
16286 |
|
16287 | |
16288 |
|
16289 |
|
16290 |
|
16291 |
|
16292 |
|
16293 | Network.prototype._createBezierNodes = function() {
|
16294 | if (this.constants.smoothCurves.enabled == true && this.constants.smoothCurves.dynamic == true) {
|
16295 | for (var edgeId in this.edges) {
|
16296 | if (this.edges.hasOwnProperty(edgeId)) {
|
16297 | var edge = this.edges[edgeId];
|
16298 | if (edge.via == null) {
|
16299 | var nodeId = "edgeId:".concat(edge.id);
|
16300 | this.sectors['support']['nodes'][nodeId] = new Node(
|
16301 | {id:nodeId,
|
16302 | mass:1,
|
16303 | shape:'circle',
|
16304 | image:"",
|
16305 | internalMultiplier:1
|
16306 | },{},{},this.constants);
|
16307 | edge.via = this.sectors['support']['nodes'][nodeId];
|
16308 | edge.via.parentEdgeId = edge.id;
|
16309 | edge.positionBezierNode();
|
16310 | }
|
16311 | }
|
16312 | }
|
16313 | }
|
16314 | };
|
16315 |
|
16316 | |
16317 |
|
16318 |
|
16319 |
|
16320 |
|
16321 | Network.prototype._initializeMixinLoaders = function () {
|
16322 | for (var mixin in MixinLoader) {
|
16323 | if (MixinLoader.hasOwnProperty(mixin)) {
|
16324 | Network.prototype[mixin] = MixinLoader[mixin];
|
16325 | }
|
16326 | }
|
16327 | };
|
16328 |
|
16329 | |
16330 |
|
16331 |
|
16332 | Network.prototype.storePosition = function() {
|
16333 | var dataArray = [];
|
16334 | for (var nodeId in this.nodes) {
|
16335 | if (this.nodes.hasOwnProperty(nodeId)) {
|
16336 | var node = this.nodes[nodeId];
|
16337 | var allowedToMoveX = !this.nodes.xFixed;
|
16338 | var allowedToMoveY = !this.nodes.yFixed;
|
16339 | if (this.nodesData._data[nodeId].x != Math.round(node.x) || this.nodesData._data[nodeId].y != Math.round(node.y)) {
|
16340 | dataArray.push({id:nodeId,x:Math.round(node.x),y:Math.round(node.y),allowedToMoveX:allowedToMoveX,allowedToMoveY:allowedToMoveY});
|
16341 | }
|
16342 | }
|
16343 | }
|
16344 | this.nodesData.update(dataArray);
|
16345 | };
|
16346 |
|
16347 |
|
16348 | |
16349 |
|
16350 |
|
16351 |
|
16352 |
|
16353 |
|
16354 | Network.prototype.focusOnNode = function (nodeId, options) {
|
16355 | if (this.nodes.hasOwnProperty(nodeId)) {
|
16356 | if (options === undefined) {
|
16357 | options = {};
|
16358 | }
|
16359 | var nodePosition = {x: this.nodes[nodeId].x, y: this.nodes[nodeId].y};
|
16360 | options.position = nodePosition;
|
16361 | options.lockedOnNode = nodeId;
|
16362 |
|
16363 | this.moveTo(options)
|
16364 | }
|
16365 | else {
|
16366 | console.log("This nodeId cannot be found.");
|
16367 | }
|
16368 | };
|
16369 |
|
16370 | |
16371 |
|
16372 |
|
16373 |
|
16374 |
|
16375 |
|
16376 |
|
16377 | Network.prototype.moveTo = function (options) {
|
16378 | if (options === undefined) {
|
16379 | options = {};
|
16380 | return;
|
16381 | }
|
16382 | if (options.offset === undefined) {options.offset = {x: 0, y: 0}; }
|
16383 | if (options.offset.x === undefined) {options.offset.x = 0; }
|
16384 | if (options.offset.y === undefined) {options.offset.y = 0; }
|
16385 | if (options.scale === undefined) {options.scale = this._getScale(); }
|
16386 | if (options.position === undefined) {options.position = this._getTranslation();}
|
16387 | if (options.animation === undefined) {options.animation = {duration:0}; }
|
16388 | if (options.animation === false ) {options.animation = {duration:0}; }
|
16389 | if (options.animation === true ) {options.animation = {}; }
|
16390 | if (options.animation.duration === undefined) {options.animation.duration = 1000; }
|
16391 | if (options.animation.easingFunction === undefined) {options.animation.easingFunction = "easeInOutQuad"; }
|
16392 |
|
16393 | this.animateView(options);
|
16394 | };
|
16395 |
|
16396 | |
16397 |
|
16398 |
|
16399 |
|
16400 |
|
16401 |
|
16402 |
|
16403 |
|
16404 |
|
16405 |
|
16406 |
|
16407 | Network.prototype.animateView = function (options) {
|
16408 | if (options === undefined) {
|
16409 | options = {};
|
16410 | return;
|
16411 | }
|
16412 |
|
16413 |
|
16414 | this.releaseNode();
|
16415 | if (options.locked == true) {
|
16416 | this.lockedOnNodeId = options.lockedOnNode;
|
16417 | this.lockedOnNodeOffset = options.offset;
|
16418 | }
|
16419 |
|
16420 |
|
16421 | if (this.easingTime != 0) {
|
16422 | this._transitionRedraw(1);
|
16423 | }
|
16424 |
|
16425 | this.sourceScale = this._getScale();
|
16426 | this.sourceTranslation = this._getTranslation();
|
16427 | this.targetScale = options.scale;
|
16428 |
|
16429 |
|
16430 |
|
16431 | this._setScale(this.targetScale);
|
16432 | var viewCenter = this.DOMtoCanvas({x: 0.5 * this.frame.canvas.clientWidth, y: 0.5 * this.frame.canvas.clientHeight});
|
16433 | var distanceFromCenter = {
|
16434 | x: viewCenter.x - options.position.x,
|
16435 | y: viewCenter.y - options.position.y
|
16436 | };
|
16437 | this.targetTranslation = {
|
16438 | x: this.sourceTranslation.x + distanceFromCenter.x * this.targetScale + options.offset.x,
|
16439 | y: this.sourceTranslation.y + distanceFromCenter.y * this.targetScale + options.offset.y
|
16440 | };
|
16441 |
|
16442 |
|
16443 | if (options.animation.duration == 0) {
|
16444 | if (this.lockedOnNodeId != null) {
|
16445 | this._classicRedraw = this._redraw;
|
16446 | this._redraw = this._lockedRedraw;
|
16447 | }
|
16448 | else {
|
16449 | this._setScale(this.targetScale);
|
16450 | this._setTranslation(this.targetTranslation.x, this.targetTranslation.y);
|
16451 | this._redraw();
|
16452 | }
|
16453 | }
|
16454 | else {
|
16455 | this.animationSpeed = 1 / (this.renderRefreshRate * options.animation.duration * 0.001) || 1 / this.renderRefreshRate;
|
16456 | this.animationEasingFunction = options.animation.easingFunction;
|
16457 | this._classicRedraw = this._redraw;
|
16458 | this._redraw = this._transitionRedraw;
|
16459 | this._redraw();
|
16460 | this.moving = true;
|
16461 | this.start();
|
16462 | }
|
16463 | };
|
16464 |
|
16465 |
|
16466 | Network.prototype._lockedRedraw = function () {
|
16467 | var nodePosition = {x: this.nodes[this.lockedOnNodeId].x, y: this.nodes[this.lockedOnNodeId].y};
|
16468 | var viewCenter = this.DOMtoCanvas({x: 0.5 * this.frame.canvas.clientWidth, y: 0.5 * this.frame.canvas.clientHeight});
|
16469 | var distanceFromCenter = {
|
16470 | x: viewCenter.x - nodePosition.x,
|
16471 | y: viewCenter.y - nodePosition.y
|
16472 | };
|
16473 | var sourceTranslation = this._getTranslation();
|
16474 | var targetTranslation = {
|
16475 | x: sourceTranslation.x + distanceFromCenter.x * this.scale + this.lockedOnNodeOffset.x,
|
16476 | y: sourceTranslation.y + distanceFromCenter.y * this.scale + this.lockedOnNodeOffset.y
|
16477 | };
|
16478 |
|
16479 | this._setTranslation(targetTranslation.x,targetTranslation.y);
|
16480 | this._classicRedraw();
|
16481 | }
|
16482 |
|
16483 | Network.prototype.releaseNode = function () {
|
16484 | if (this.lockedOnNodeId != null) {
|
16485 | this._redraw = this._classicRedraw;
|
16486 | this.lockedOnNodeId = null;
|
16487 | this.lockedOnNodeOffset = null;
|
16488 | }
|
16489 | }
|
16490 |
|
16491 | |
16492 |
|
16493 |
|
16494 |
|
16495 |
|
16496 | Network.prototype._transitionRedraw = function (easingTime) {
|
16497 | this.easingTime = easingTime || this.easingTime + this.animationSpeed;
|
16498 | this.easingTime += this.animationSpeed;
|
16499 |
|
16500 | var progress = util.easingFunctions[this.animationEasingFunction](this.easingTime);
|
16501 |
|
16502 | this._setScale(this.sourceScale + (this.targetScale - this.sourceScale) * progress);
|
16503 | this._setTranslation(
|
16504 | this.sourceTranslation.x + (this.targetTranslation.x - this.sourceTranslation.x) * progress,
|
16505 | this.sourceTranslation.y + (this.targetTranslation.y - this.sourceTranslation.y) * progress
|
16506 | );
|
16507 |
|
16508 | this._classicRedraw();
|
16509 | this.moving = true;
|
16510 |
|
16511 |
|
16512 | if (this.easingTime >= 1.0) {
|
16513 | this.easingTime = 0;
|
16514 | if (this.lockedOnNodeId != null) {
|
16515 | this._redraw = this._lockedRedraw;
|
16516 | }
|
16517 | else {
|
16518 | this._redraw = this._classicRedraw;
|
16519 | }
|
16520 | this.emit("animationFinished");
|
16521 | }
|
16522 | };
|
16523 |
|
16524 | Network.prototype._classicRedraw = function () {
|
16525 |
|
16526 | };
|
16527 |
|
16528 | |
16529 |
|
16530 |
|
16531 |
|
16532 | Network.prototype.isActive = function () {
|
16533 | return !this.activator || this.activator.active;
|
16534 | };
|
16535 |
|
16536 |
|
16537 | |
16538 |
|
16539 |
|
16540 |
|
16541 | Network.prototype.setScale = function () {
|
16542 | return this._setScale();
|
16543 | };
|
16544 |
|
16545 |
|
16546 | |
16547 |
|
16548 |
|
16549 |
|
16550 | Network.prototype.getScale = function () {
|
16551 | return this._getScale();
|
16552 | };
|
16553 |
|
16554 |
|
16555 |
|
16556 | module.exports = Network;
|
16557 |
|
16558 |
|
16559 | },
|
16560 |
|
16561 | function(module, exports, __webpack_require__) {
|
16562 |
|
16563 | var util = __webpack_require__(1);
|
16564 | var Node = __webpack_require__(37);
|
16565 |
|
16566 | |
16567 |
|
16568 |
|
16569 |
|
16570 |
|
16571 |
|
16572 |
|
16573 |
|
16574 |
|
16575 |
|
16576 |
|
16577 |
|
16578 |
|
16579 |
|
16580 |
|
16581 | function Edge (properties, network, networkConstants) {
|
16582 | if (!network) {
|
16583 | throw "No network provided";
|
16584 | }
|
16585 | var fields = ['edges','physics'];
|
16586 | var constants = util.selectiveBridgeObject(fields,networkConstants);
|
16587 | this.options = constants.edges;
|
16588 | this.physics = constants.physics;
|
16589 | this.options['smoothCurves'] = networkConstants['smoothCurves'];
|
16590 |
|
16591 |
|
16592 | this.network = network;
|
16593 |
|
16594 |
|
16595 | this.id = undefined;
|
16596 | this.fromId = undefined;
|
16597 | this.toId = undefined;
|
16598 | this.title = undefined;
|
16599 | this.widthSelected = this.options.width * this.options.widthSelectionMultiplier;
|
16600 | this.value = undefined;
|
16601 | this.selected = false;
|
16602 | this.hover = false;
|
16603 | this.labelDimensions = {top:0,left:0,width:0,height:0};
|
16604 |
|
16605 | this.from = null;
|
16606 | this.to = null;
|
16607 | this.via = null;
|
16608 |
|
16609 |
|
16610 |
|
16611 | this.originalFromId = [];
|
16612 | this.originalToId = [];
|
16613 |
|
16614 | this.connected = false;
|
16615 |
|
16616 | this.widthFixed = false;
|
16617 | this.lengthFixed = false;
|
16618 |
|
16619 | this.setProperties(properties);
|
16620 |
|
16621 | this.controlNodesEnabled = false;
|
16622 | this.controlNodes = {from:null, to:null, positions:{}};
|
16623 | this.connectedNode = null;
|
16624 | }
|
16625 |
|
16626 | |
16627 |
|
16628 |
|
16629 |
|
16630 |
|
16631 | Edge.prototype.setProperties = function(properties) {
|
16632 | if (!properties) {
|
16633 | return;
|
16634 | }
|
16635 |
|
16636 | var fields = ['style','fontSize','fontFace','fontColor','fontFill','width',
|
16637 | 'widthSelectionMultiplier','hoverWidth','arrowScaleFactor','dash','inheritColor'
|
16638 | ];
|
16639 | util.selectiveDeepExtend(fields, this.options, properties);
|
16640 |
|
16641 | if (properties.from !== undefined) {this.fromId = properties.from;}
|
16642 | if (properties.to !== undefined) {this.toId = properties.to;}
|
16643 |
|
16644 | if (properties.id !== undefined) {this.id = properties.id;}
|
16645 | if (properties.label !== undefined) {this.label = properties.label;}
|
16646 |
|
16647 | if (properties.title !== undefined) {this.title = properties.title;}
|
16648 | if (properties.value !== undefined) {this.value = properties.value;}
|
16649 | if (properties.length !== undefined) {this.physics.springLength = properties.length;}
|
16650 |
|
16651 | if (properties.color !== undefined) {
|
16652 | this.options.inheritColor = false;
|
16653 | if (util.isString(properties.color)) {
|
16654 | this.options.color.color = properties.color;
|
16655 | this.options.color.highlight = properties.color;
|
16656 | }
|
16657 | else {
|
16658 | if (properties.color.color !== undefined) {this.options.color.color = properties.color.color;}
|
16659 | if (properties.color.highlight !== undefined) {this.options.color.highlight = properties.color.highlight;}
|
16660 | if (properties.color.hover !== undefined) {this.options.color.hover = properties.color.hover;}
|
16661 | }
|
16662 | }
|
16663 |
|
16664 |
|
16665 | this.connect();
|
16666 |
|
16667 | this.widthFixed = this.widthFixed || (properties.width !== undefined);
|
16668 | this.lengthFixed = this.lengthFixed || (properties.length !== undefined);
|
16669 |
|
16670 | this.widthSelected = this.options.width* this.options.widthSelectionMultiplier;
|
16671 |
|
16672 |
|
16673 | switch (this.options.style) {
|
16674 | case 'line': this.draw = this._drawLine; break;
|
16675 | case 'arrow': this.draw = this._drawArrow; break;
|
16676 | case 'arrow-center': this.draw = this._drawArrowCenter; break;
|
16677 | case 'dash-line': this.draw = this._drawDashLine; break;
|
16678 | default: this.draw = this._drawLine; break;
|
16679 | }
|
16680 | };
|
16681 |
|
16682 | |
16683 |
|
16684 |
|
16685 | Edge.prototype.connect = function () {
|
16686 | this.disconnect();
|
16687 |
|
16688 | this.from = this.network.nodes[this.fromId] || null;
|
16689 | this.to = this.network.nodes[this.toId] || null;
|
16690 | this.connected = (this.from && this.to);
|
16691 |
|
16692 | if (this.connected) {
|
16693 | this.from.attachEdge(this);
|
16694 | this.to.attachEdge(this);
|
16695 | }
|
16696 | else {
|
16697 | if (this.from) {
|
16698 | this.from.detachEdge(this);
|
16699 | }
|
16700 | if (this.to) {
|
16701 | this.to.detachEdge(this);
|
16702 | }
|
16703 | }
|
16704 | };
|
16705 |
|
16706 | |
16707 |
|
16708 |
|
16709 | Edge.prototype.disconnect = function () {
|
16710 | if (this.from) {
|
16711 | this.from.detachEdge(this);
|
16712 | this.from = null;
|
16713 | }
|
16714 | if (this.to) {
|
16715 | this.to.detachEdge(this);
|
16716 | this.to = null;
|
16717 | }
|
16718 |
|
16719 | this.connected = false;
|
16720 | };
|
16721 |
|
16722 | |
16723 |
|
16724 |
|
16725 |
|
16726 |
|
16727 | Edge.prototype.getTitle = function() {
|
16728 | return typeof this.title === "function" ? this.title() : this.title;
|
16729 | };
|
16730 |
|
16731 |
|
16732 | |
16733 |
|
16734 |
|
16735 |
|
16736 | Edge.prototype.getValue = function() {
|
16737 | return this.value;
|
16738 | };
|
16739 |
|
16740 | |
16741 |
|
16742 |
|
16743 |
|
16744 |
|
16745 |
|
16746 | Edge.prototype.setValueRange = function(min, max) {
|
16747 | if (!this.widthFixed && this.value !== undefined) {
|
16748 | var scale = (this.options.widthMax - this.options.widthMin) / (max - min);
|
16749 | this.options.width= (this.value - min) * scale + this.options.widthMin;
|
16750 | this.widthSelected = this.options.width* this.options.widthSelectionMultiplier;
|
16751 | }
|
16752 | };
|
16753 |
|
16754 | |
16755 |
|
16756 |
|
16757 |
|
16758 |
|
16759 |
|
16760 | Edge.prototype.draw = function(ctx) {
|
16761 | throw "Method draw not initialized in edge";
|
16762 | };
|
16763 |
|
16764 | |
16765 |
|
16766 |
|
16767 |
|
16768 |
|
16769 | Edge.prototype.isOverlappingWith = function(obj) {
|
16770 | if (this.connected) {
|
16771 | var distMax = 10;
|
16772 | var xFrom = this.from.x;
|
16773 | var yFrom = this.from.y;
|
16774 | var xTo = this.to.x;
|
16775 | var yTo = this.to.y;
|
16776 | var xObj = obj.left;
|
16777 | var yObj = obj.top;
|
16778 |
|
16779 | var dist = this._getDistanceToEdge(xFrom, yFrom, xTo, yTo, xObj, yObj);
|
16780 |
|
16781 | return (dist < distMax);
|
16782 | }
|
16783 | else {
|
16784 | return false
|
16785 | }
|
16786 | };
|
16787 |
|
16788 | Edge.prototype._getColor = function() {
|
16789 | var colorObj = this.options.color;
|
16790 | if (this.options.inheritColor == "to") {
|
16791 | colorObj = {
|
16792 | highlight: this.to.options.color.highlight.border,
|
16793 | hover: this.to.options.color.hover.border,
|
16794 | color: this.to.options.color.border
|
16795 | };
|
16796 | }
|
16797 | else if (this.options.inheritColor == "from" || this.options.inheritColor == true) {
|
16798 | colorObj = {
|
16799 | highlight: this.from.options.color.highlight.border,
|
16800 | hover: this.from.options.color.hover.border,
|
16801 | color: this.from.options.color.border
|
16802 | };
|
16803 | }
|
16804 |
|
16805 | if (this.selected == true) {return colorObj.highlight;}
|
16806 | else if (this.hover == true) {return colorObj.hover;}
|
16807 | else {return colorObj.color;}
|
16808 | }
|
16809 |
|
16810 |
|
16811 | |
16812 |
|
16813 |
|
16814 |
|
16815 |
|
16816 |
|
16817 |
|
16818 | Edge.prototype._drawLine = function(ctx) {
|
16819 |
|
16820 | ctx.strokeStyle = this._getColor();
|
16821 | ctx.lineWidth = this._getLineWidth();
|
16822 |
|
16823 | if (this.from != this.to) {
|
16824 |
|
16825 | var via = this._line(ctx);
|
16826 |
|
16827 |
|
16828 | var point;
|
16829 | if (this.label) {
|
16830 | if (this.options.smoothCurves.enabled == true && via != null) {
|
16831 | var midpointX = 0.5*(0.5*(this.from.x + via.x) + 0.5*(this.to.x + via.x));
|
16832 | var midpointY = 0.5*(0.5*(this.from.y + via.y) + 0.5*(this.to.y + via.y));
|
16833 | point = {x:midpointX, y:midpointY};
|
16834 | }
|
16835 | else {
|
16836 | point = this._pointOnLine(0.5);
|
16837 | }
|
16838 | this._label(ctx, this.label, point.x, point.y);
|
16839 | }
|
16840 | }
|
16841 | else {
|
16842 | var x, y;
|
16843 | var radius = this.physics.springLength / 4;
|
16844 | var node = this.from;
|
16845 | if (!node.width) {
|
16846 | node.resize(ctx);
|
16847 | }
|
16848 | if (node.width > node.height) {
|
16849 | x = node.x + node.width / 2;
|
16850 | y = node.y - radius;
|
16851 | }
|
16852 | else {
|
16853 | x = node.x + radius;
|
16854 | y = node.y - node.height / 2;
|
16855 | }
|
16856 | this._circle(ctx, x, y, radius);
|
16857 | point = this._pointOnCircle(x, y, radius, 0.5);
|
16858 | this._label(ctx, this.label, point.x, point.y);
|
16859 | }
|
16860 | };
|
16861 |
|
16862 | |
16863 |
|
16864 |
|
16865 |
|
16866 |
|
16867 |
|
16868 | Edge.prototype._getLineWidth = function() {
|
16869 | if (this.selected == true) {
|
16870 | return Math.max(Math.min(this.widthSelected, this.options.widthMax), 0.3*this.networkScaleInv);
|
16871 | }
|
16872 | else {
|
16873 | if (this.hover == true) {
|
16874 | return Math.max(Math.min(this.options.hoverWidth, this.options.widthMax), 0.3*this.networkScaleInv);
|
16875 | }
|
16876 | else {
|
16877 | return Math.max(this.options.width, 0.3*this.networkScaleInv);
|
16878 | }
|
16879 | }
|
16880 | };
|
16881 |
|
16882 | Edge.prototype._getViaCoordinates = function () {
|
16883 | var xVia = null;
|
16884 | var yVia = null;
|
16885 | var factor = this.options.smoothCurves.roundness;
|
16886 | var type = this.options.smoothCurves.type;
|
16887 |
|
16888 | var dx = Math.abs(this.from.x - this.to.x);
|
16889 | var dy = Math.abs(this.from.y - this.to.y);
|
16890 | if (type == 'discrete' || type == 'diagonalCross') {
|
16891 | if (Math.abs(this.from.x - this.to.x) < Math.abs(this.from.y - this.to.y)) {
|
16892 | if (this.from.y > this.to.y) {
|
16893 | if (this.from.x < this.to.x) {
|
16894 | xVia = this.from.x + factor * dy;
|
16895 | yVia = this.from.y - factor * dy;
|
16896 | }
|
16897 | else if (this.from.x > this.to.x) {
|
16898 | xVia = this.from.x - factor * dy;
|
16899 | yVia = this.from.y - factor * dy;
|
16900 | }
|
16901 | }
|
16902 | else if (this.from.y < this.to.y) {
|
16903 | if (this.from.x < this.to.x) {
|
16904 | xVia = this.from.x + factor * dy;
|
16905 | yVia = this.from.y + factor * dy;
|
16906 | }
|
16907 | else if (this.from.x > this.to.x) {
|
16908 | xVia = this.from.x - factor * dy;
|
16909 | yVia = this.from.y + factor * dy;
|
16910 | }
|
16911 | }
|
16912 | if (type == "discrete") {
|
16913 | xVia = dx < factor * dy ? this.from.x : xVia;
|
16914 | }
|
16915 | }
|
16916 | else if (Math.abs(this.from.x - this.to.x) > Math.abs(this.from.y - this.to.y)) {
|
16917 | if (this.from.y > this.to.y) {
|
16918 | if (this.from.x < this.to.x) {
|
16919 | xVia = this.from.x + factor * dx;
|
16920 | yVia = this.from.y - factor * dx;
|
16921 | }
|
16922 | else if (this.from.x > this.to.x) {
|
16923 | xVia = this.from.x - factor * dx;
|
16924 | yVia = this.from.y - factor * dx;
|
16925 | }
|
16926 | }
|
16927 | else if (this.from.y < this.to.y) {
|
16928 | if (this.from.x < this.to.x) {
|
16929 | xVia = this.from.x + factor * dx;
|
16930 | yVia = this.from.y + factor * dx;
|
16931 | }
|
16932 | else if (this.from.x > this.to.x) {
|
16933 | xVia = this.from.x - factor * dx;
|
16934 | yVia = this.from.y + factor * dx;
|
16935 | }
|
16936 | }
|
16937 | if (type == "discrete") {
|
16938 | yVia = dy < factor * dx ? this.from.y : yVia;
|
16939 | }
|
16940 | }
|
16941 | }
|
16942 | else if (type == "straightCross") {
|
16943 | if (Math.abs(this.from.x - this.to.x) < Math.abs(this.from.y - this.to.y)) {
|
16944 | xVia = this.from.x;
|
16945 | if (this.from.y < this.to.y) {
|
16946 | yVia = this.to.y - (1-factor) * dy;
|
16947 | }
|
16948 | else {
|
16949 | yVia = this.to.y + (1-factor) * dy;
|
16950 | }
|
16951 | }
|
16952 | else if (Math.abs(this.from.x - this.to.x) > Math.abs(this.from.y - this.to.y)) {
|
16953 | if (this.from.x < this.to.x) {
|
16954 | xVia = this.to.x - (1-factor) * dx;
|
16955 | }
|
16956 | else {
|
16957 | xVia = this.to.x + (1-factor) * dx;
|
16958 | }
|
16959 | yVia = this.from.y;
|
16960 | }
|
16961 | }
|
16962 | else if (type == 'horizontal') {
|
16963 | if (this.from.x < this.to.x) {
|
16964 | xVia = this.to.x - (1-factor) * dx;
|
16965 | }
|
16966 | else {
|
16967 | xVia = this.to.x + (1-factor) * dx;
|
16968 | }
|
16969 | yVia = this.from.y;
|
16970 | }
|
16971 | else if (type == 'vertical') {
|
16972 | xVia = this.from.x;
|
16973 | if (this.from.y < this.to.y) {
|
16974 | yVia = this.to.y - (1-factor) * dy;
|
16975 | }
|
16976 | else {
|
16977 | yVia = this.to.y + (1-factor) * dy;
|
16978 | }
|
16979 | }
|
16980 | else {
|
16981 | if (Math.abs(this.from.x - this.to.x) < Math.abs(this.from.y - this.to.y)) {
|
16982 | if (this.from.y > this.to.y) {
|
16983 | if (this.from.x < this.to.x) {
|
16984 |
|
16985 | xVia = this.from.x + factor * dy;
|
16986 | yVia = this.from.y - factor * dy;
|
16987 | xVia = this.to.x < xVia ? this.to.x : xVia;
|
16988 | }
|
16989 | else if (this.from.x > this.to.x) {
|
16990 |
|
16991 | xVia = this.from.x - factor * dy;
|
16992 | yVia = this.from.y - factor * dy;
|
16993 | xVia = this.to.x > xVia ? this.to.x :xVia;
|
16994 | }
|
16995 | }
|
16996 | else if (this.from.y < this.to.y) {
|
16997 | if (this.from.x < this.to.x) {
|
16998 |
|
16999 | xVia = this.from.x + factor * dy;
|
17000 | yVia = this.from.y + factor * dy;
|
17001 | xVia = this.to.x < xVia ? this.to.x : xVia;
|
17002 | }
|
17003 | else if (this.from.x > this.to.x) {
|
17004 |
|
17005 | xVia = this.from.x - factor * dy;
|
17006 | yVia = this.from.y + factor * dy;
|
17007 | xVia = this.to.x > xVia ? this.to.x : xVia;
|
17008 | }
|
17009 | }
|
17010 | }
|
17011 | else if (Math.abs(this.from.x - this.to.x) > Math.abs(this.from.y - this.to.y)) {
|
17012 | if (this.from.y > this.to.y) {
|
17013 | if (this.from.x < this.to.x) {
|
17014 |
|
17015 | xVia = this.from.x + factor * dx;
|
17016 | yVia = this.from.y - factor * dx;
|
17017 | yVia = this.to.y > yVia ? this.to.y : yVia;
|
17018 | }
|
17019 | else if (this.from.x > this.to.x) {
|
17020 |
|
17021 | xVia = this.from.x - factor * dx;
|
17022 | yVia = this.from.y - factor * dx;
|
17023 | yVia = this.to.y > yVia ? this.to.y : yVia;
|
17024 | }
|
17025 | }
|
17026 | else if (this.from.y < this.to.y) {
|
17027 | if (this.from.x < this.to.x) {
|
17028 |
|
17029 | xVia = this.from.x + factor * dx;
|
17030 | yVia = this.from.y + factor * dx;
|
17031 | yVia = this.to.y < yVia ? this.to.y : yVia;
|
17032 | }
|
17033 | else if (this.from.x > this.to.x) {
|
17034 |
|
17035 | xVia = this.from.x - factor * dx;
|
17036 | yVia = this.from.y + factor * dx;
|
17037 | yVia = this.to.y < yVia ? this.to.y : yVia;
|
17038 | }
|
17039 | }
|
17040 | }
|
17041 | }
|
17042 |
|
17043 |
|
17044 | return {x:xVia, y:yVia};
|
17045 | }
|
17046 |
|
17047 | |
17048 |
|
17049 |
|
17050 |
|
17051 |
|
17052 | Edge.prototype._line = function (ctx) {
|
17053 |
|
17054 | ctx.beginPath();
|
17055 | ctx.moveTo(this.from.x, this.from.y);
|
17056 | if (this.options.smoothCurves.enabled == true) {
|
17057 | if (this.options.smoothCurves.dynamic == false) {
|
17058 | var via = this._getViaCoordinates();
|
17059 | if (via.x == null) {
|
17060 | ctx.lineTo(this.to.x, this.to.y);
|
17061 | ctx.stroke();
|
17062 | return null;
|
17063 | }
|
17064 | else {
|
17065 |
|
17066 |
|
17067 | ctx.quadraticCurveTo(via.x,via.y,this.to.x, this.to.y);
|
17068 | ctx.stroke();
|
17069 | return via;
|
17070 | }
|
17071 | }
|
17072 | else {
|
17073 | ctx.quadraticCurveTo(this.via.x,this.via.y,this.to.x, this.to.y);
|
17074 | ctx.stroke();
|
17075 | return this.via;
|
17076 | }
|
17077 | }
|
17078 | else {
|
17079 | ctx.lineTo(this.to.x, this.to.y);
|
17080 | ctx.stroke();
|
17081 | return null;
|
17082 | }
|
17083 | };
|
17084 |
|
17085 | |
17086 |
|
17087 |
|
17088 |
|
17089 |
|
17090 |
|
17091 |
|
17092 |
|
17093 | Edge.prototype._circle = function (ctx, x, y, radius) {
|
17094 |
|
17095 | ctx.beginPath();
|
17096 | ctx.arc(x, y, radius, 0, 2 * Math.PI, false);
|
17097 | ctx.stroke();
|
17098 | };
|
17099 |
|
17100 | |
17101 |
|
17102 |
|
17103 |
|
17104 |
|
17105 |
|
17106 |
|
17107 |
|
17108 | Edge.prototype._label = function (ctx, text, x, y) {
|
17109 | if (text) {
|
17110 |
|
17111 | ctx.font = ((this.from.selected || this.to.selected) ? "bold " : "") +
|
17112 | this.options.fontSize + "px " + this.options.fontFace;
|
17113 |
|
17114 |
|
17115 | var lines = String(text).split('\n');
|
17116 | var lineCount = lines.length;
|
17117 | var fontSize = (Number(this.options.fontSize) + 4);
|
17118 | var yLine = y + (1 - lineCount) / 2 * fontSize;
|
17119 |
|
17120 | var width = ctx.measureText(lines[0]).width;
|
17121 | for (var i = 1; i < lineCount; i++) {
|
17122 | var lineWidth = ctx.measureText(lines[i]).width;
|
17123 | width = lineWidth > width ? lineWidth : width;
|
17124 | }
|
17125 | var height = this.options.fontSize * lineCount;
|
17126 | var left = x - width / 2;
|
17127 | var top = y - height / 2;
|
17128 |
|
17129 | this.labelDimensions = {top:top,left:left,width:width,height:height};
|
17130 |
|
17131 | if (this.options.fontFill !== undefined && this.options.fontFill !== null && this.options.fontFill !== "none") {
|
17132 | ctx.fillStyle = this.options.fontFill;
|
17133 | ctx.fillRect(left, top, width, height);
|
17134 | }
|
17135 |
|
17136 |
|
17137 | ctx.fillStyle = this.options.fontColor || "black";
|
17138 | ctx.textAlign = "center";
|
17139 | ctx.textBaseline = "middle";
|
17140 |
|
17141 | for (var i = 0; i < lineCount; i++) {
|
17142 | ctx.fillText(lines[i], x, yLine);
|
17143 | yLine += fontSize;
|
17144 | }
|
17145 | }
|
17146 | };
|
17147 |
|
17148 | |
17149 |
|
17150 |
|
17151 |
|
17152 |
|
17153 |
|
17154 |
|
17155 |
|
17156 |
|
17157 | Edge.prototype._drawDashLine = function(ctx) {
|
17158 |
|
17159 | if (this.selected == true) {ctx.strokeStyle = this.options.color.highlight;}
|
17160 | else if (this.hover == true) {ctx.strokeStyle = this.options.color.hover;}
|
17161 | else {ctx.strokeStyle = this.options.color.color;}
|
17162 |
|
17163 | ctx.lineWidth = this._getLineWidth();
|
17164 |
|
17165 | var via = null;
|
17166 |
|
17167 | if (ctx.mozDash !== undefined || ctx.setLineDash !== undefined) {
|
17168 |
|
17169 | var pattern = [0];
|
17170 | if (this.options.dash.length !== undefined && this.options.dash.gap !== undefined) {
|
17171 | pattern = [this.options.dash.length,this.options.dash.gap];
|
17172 | }
|
17173 | else {
|
17174 | pattern = [5,5];
|
17175 | }
|
17176 |
|
17177 |
|
17178 | if (typeof ctx.setLineDash !== 'undefined') {
|
17179 | ctx.setLineDash(pattern);
|
17180 | ctx.lineDashOffset = 0;
|
17181 |
|
17182 | } else {
|
17183 | ctx.mozDash = pattern;
|
17184 | ctx.mozDashOffset = 0;
|
17185 | }
|
17186 |
|
17187 |
|
17188 | via = this._line(ctx);
|
17189 |
|
17190 |
|
17191 | if (typeof ctx.setLineDash !== 'undefined') {
|
17192 | ctx.setLineDash([0]);
|
17193 | ctx.lineDashOffset = 0;
|
17194 |
|
17195 | } else {
|
17196 | ctx.mozDash = [0];
|
17197 | ctx.mozDashOffset = 0;
|
17198 | }
|
17199 | }
|
17200 | else {
|
17201 |
|
17202 | ctx.beginPath();
|
17203 | ctx.lineCap = 'round';
|
17204 | if (this.options.dash.altLength !== undefined)
|
17205 | {
|
17206 | ctx.dashedLine(this.from.x,this.from.y,this.to.x,this.to.y,
|
17207 | [this.options.dash.length,this.options.dash.gap,this.options.dash.altLength,this.options.dash.gap]);
|
17208 | }
|
17209 | else if (this.options.dash.length !== undefined && this.options.dash.gap !== undefined)
|
17210 | {
|
17211 | ctx.dashedLine(this.from.x,this.from.y,this.to.x,this.to.y,
|
17212 | [this.options.dash.length,this.options.dash.gap]);
|
17213 | }
|
17214 | else
|
17215 | {
|
17216 | ctx.moveTo(this.from.x, this.from.y);
|
17217 | ctx.lineTo(this.to.x, this.to.y);
|
17218 | }
|
17219 | ctx.stroke();
|
17220 | }
|
17221 |
|
17222 |
|
17223 | if (this.label) {
|
17224 | var point;
|
17225 | if (this.options.smoothCurves.enabled == true && via != null) {
|
17226 | var midpointX = 0.5*(0.5*(this.from.x + via.x) + 0.5*(this.to.x + via.x));
|
17227 | var midpointY = 0.5*(0.5*(this.from.y + via.y) + 0.5*(this.to.y + via.y));
|
17228 | point = {x:midpointX, y:midpointY};
|
17229 | }
|
17230 | else {
|
17231 | point = this._pointOnLine(0.5);
|
17232 | }
|
17233 | this._label(ctx, this.label, point.x, point.y);
|
17234 | }
|
17235 | };
|
17236 |
|
17237 | |
17238 |
|
17239 |
|
17240 |
|
17241 |
|
17242 |
|
17243 | Edge.prototype._pointOnLine = function (percentage) {
|
17244 | return {
|
17245 | x: (1 - percentage) * this.from.x + percentage * this.to.x,
|
17246 | y: (1 - percentage) * this.from.y + percentage * this.to.y
|
17247 | }
|
17248 | };
|
17249 |
|
17250 | |
17251 |
|
17252 |
|
17253 |
|
17254 |
|
17255 |
|
17256 |
|
17257 |
|
17258 |
|
17259 | Edge.prototype._pointOnCircle = function (x, y, radius, percentage) {
|
17260 | var angle = (percentage - 3/8) * 2 * Math.PI;
|
17261 | return {
|
17262 | x: x + radius * Math.cos(angle),
|
17263 | y: y - radius * Math.sin(angle)
|
17264 | }
|
17265 | };
|
17266 |
|
17267 | |
17268 |
|
17269 |
|
17270 |
|
17271 |
|
17272 |
|
17273 |
|
17274 | Edge.prototype._drawArrowCenter = function(ctx) {
|
17275 | var point;
|
17276 |
|
17277 | if (this.selected == true) {ctx.strokeStyle = this.options.color.highlight; ctx.fillStyle = this.options.color.highlight;}
|
17278 | else if (this.hover == true) {ctx.strokeStyle = this.options.color.hover; ctx.fillStyle = this.options.color.hover;}
|
17279 | else {ctx.strokeStyle = this.options.color.color; ctx.fillStyle = this.options.color.color;}
|
17280 | ctx.lineWidth = this._getLineWidth();
|
17281 |
|
17282 | if (this.from != this.to) {
|
17283 |
|
17284 | var via = this._line(ctx);
|
17285 |
|
17286 | var angle = Math.atan2((this.to.y - this.from.y), (this.to.x - this.from.x));
|
17287 | var length = (10 + 5 * this.options.width) * this.options.arrowScaleFactor;
|
17288 |
|
17289 | if (this.options.smoothCurves.enabled == true && via != null) {
|
17290 | var midpointX = 0.5*(0.5*(this.from.x + via.x) + 0.5*(this.to.x + via.x));
|
17291 | var midpointY = 0.5*(0.5*(this.from.y + via.y) + 0.5*(this.to.y + via.y));
|
17292 | point = {x:midpointX, y:midpointY};
|
17293 | }
|
17294 | else {
|
17295 | point = this._pointOnLine(0.5);
|
17296 | }
|
17297 |
|
17298 | ctx.arrow(point.x, point.y, angle, length);
|
17299 | ctx.fill();
|
17300 | ctx.stroke();
|
17301 |
|
17302 |
|
17303 | if (this.label) {
|
17304 | this._label(ctx, this.label, point.x, point.y);
|
17305 | }
|
17306 | }
|
17307 | else {
|
17308 |
|
17309 | var x, y;
|
17310 | var radius = 0.25 * Math.max(100,this.physics.springLength);
|
17311 | var node = this.from;
|
17312 | if (!node.width) {
|
17313 | node.resize(ctx);
|
17314 | }
|
17315 | if (node.width > node.height) {
|
17316 | x = node.x + node.width * 0.5;
|
17317 | y = node.y - radius;
|
17318 | }
|
17319 | else {
|
17320 | x = node.x + radius;
|
17321 | y = node.y - node.height * 0.5;
|
17322 | }
|
17323 | this._circle(ctx, x, y, radius);
|
17324 |
|
17325 |
|
17326 | var angle = 0.2 * Math.PI;
|
17327 | var length = (10 + 5 * this.options.width) * this.options.arrowScaleFactor;
|
17328 | point = this._pointOnCircle(x, y, radius, 0.5);
|
17329 | ctx.arrow(point.x, point.y, angle, length);
|
17330 | ctx.fill();
|
17331 | ctx.stroke();
|
17332 |
|
17333 |
|
17334 | if (this.label) {
|
17335 | point = this._pointOnCircle(x, y, radius, 0.5);
|
17336 | this._label(ctx, this.label, point.x, point.y);
|
17337 | }
|
17338 | }
|
17339 | };
|
17340 |
|
17341 |
|
17342 |
|
17343 | |
17344 |
|
17345 |
|
17346 |
|
17347 |
|
17348 |
|
17349 |
|
17350 | Edge.prototype._drawArrow = function(ctx) {
|
17351 |
|
17352 | if (this.selected == true) {ctx.strokeStyle = this.options.color.highlight; ctx.fillStyle = this.options.color.highlight;}
|
17353 | else if (this.hover == true) {ctx.strokeStyle = this.options.color.hover; ctx.fillStyle = this.options.color.hover;}
|
17354 | else {ctx.strokeStyle = this.options.color.color; ctx.fillStyle = this.options.color.color;}
|
17355 |
|
17356 | ctx.lineWidth = this._getLineWidth();
|
17357 |
|
17358 | var angle, length;
|
17359 |
|
17360 | if (this.from != this.to) {
|
17361 | angle = Math.atan2((this.to.y - this.from.y), (this.to.x - this.from.x));
|
17362 | var dx = (this.to.x - this.from.x);
|
17363 | var dy = (this.to.y - this.from.y);
|
17364 | var edgeSegmentLength = Math.sqrt(dx * dx + dy * dy);
|
17365 |
|
17366 | var fromBorderDist = this.from.distanceToBorder(ctx, angle + Math.PI);
|
17367 | var fromBorderPoint = (edgeSegmentLength - fromBorderDist) / edgeSegmentLength;
|
17368 | var xFrom = (fromBorderPoint) * this.from.x + (1 - fromBorderPoint) * this.to.x;
|
17369 | var yFrom = (fromBorderPoint) * this.from.y + (1 - fromBorderPoint) * this.to.y;
|
17370 |
|
17371 | var via;
|
17372 | if (this.options.smoothCurves.dynamic == true && this.options.smoothCurves.enabled == true ) {
|
17373 | via = this.via;
|
17374 | }
|
17375 | else if (this.options.smoothCurves.enabled == true) {
|
17376 | via = this._getViaCoordinates();
|
17377 | }
|
17378 |
|
17379 | if (this.options.smoothCurves.enabled == true && via.x != null) {
|
17380 | angle = Math.atan2((this.to.y - via.y), (this.to.x - via.x));
|
17381 | dx = (this.to.x - via.x);
|
17382 | dy = (this.to.y - via.y);
|
17383 | edgeSegmentLength = Math.sqrt(dx * dx + dy * dy);
|
17384 | }
|
17385 | var toBorderDist = this.to.distanceToBorder(ctx, angle);
|
17386 | var toBorderPoint = (edgeSegmentLength - toBorderDist) / edgeSegmentLength;
|
17387 |
|
17388 | var xTo,yTo;
|
17389 | if (this.options.smoothCurves.enabled == true && via.x != null) {
|
17390 | xTo = (1 - toBorderPoint) * via.x + toBorderPoint * this.to.x;
|
17391 | yTo = (1 - toBorderPoint) * via.y + toBorderPoint * this.to.y;
|
17392 | }
|
17393 | else {
|
17394 | xTo = (1 - toBorderPoint) * this.from.x + toBorderPoint * this.to.x;
|
17395 | yTo = (1 - toBorderPoint) * this.from.y + toBorderPoint * this.to.y;
|
17396 | }
|
17397 |
|
17398 | ctx.beginPath();
|
17399 | ctx.moveTo(xFrom,yFrom);
|
17400 | if (this.options.smoothCurves.enabled == true && via.x != null) {
|
17401 | ctx.quadraticCurveTo(via.x,via.y,xTo, yTo);
|
17402 | }
|
17403 | else {
|
17404 | ctx.lineTo(xTo, yTo);
|
17405 | }
|
17406 | ctx.stroke();
|
17407 |
|
17408 |
|
17409 | length = (10 + 5 * this.options.width) * this.options.arrowScaleFactor;
|
17410 | ctx.arrow(xTo, yTo, angle, length);
|
17411 | ctx.fill();
|
17412 | ctx.stroke();
|
17413 |
|
17414 |
|
17415 | if (this.label) {
|
17416 | var point;
|
17417 | if (this.options.smoothCurves.enabled == true && via != null) {
|
17418 | var midpointX = 0.5*(0.5*(this.from.x + via.x) + 0.5*(this.to.x + via.x));
|
17419 | var midpointY = 0.5*(0.5*(this.from.y + via.y) + 0.5*(this.to.y + via.y));
|
17420 | point = {x:midpointX, y:midpointY};
|
17421 | }
|
17422 | else {
|
17423 | point = this._pointOnLine(0.5);
|
17424 | }
|
17425 | this._label(ctx, this.label, point.x, point.y);
|
17426 | }
|
17427 | }
|
17428 | else {
|
17429 |
|
17430 | var node = this.from;
|
17431 | var x, y, arrow;
|
17432 | var radius = 0.25 * Math.max(100,this.physics.springLength);
|
17433 | if (!node.width) {
|
17434 | node.resize(ctx);
|
17435 | }
|
17436 | if (node.width > node.height) {
|
17437 | x = node.x + node.width * 0.5;
|
17438 | y = node.y - radius;
|
17439 | arrow = {
|
17440 | x: x,
|
17441 | y: node.y,
|
17442 | angle: 0.9 * Math.PI
|
17443 | };
|
17444 | }
|
17445 | else {
|
17446 | x = node.x + radius;
|
17447 | y = node.y - node.height * 0.5;
|
17448 | arrow = {
|
17449 | x: node.x,
|
17450 | y: y,
|
17451 | angle: 0.6 * Math.PI
|
17452 | };
|
17453 | }
|
17454 | ctx.beginPath();
|
17455 |
|
17456 | ctx.arc(x, y, radius, 0, 2 * Math.PI, false);
|
17457 | ctx.stroke();
|
17458 |
|
17459 |
|
17460 | var length = (10 + 5 * this.options.width) * this.options.arrowScaleFactor;
|
17461 | ctx.arrow(arrow.x, arrow.y, arrow.angle, length);
|
17462 | ctx.fill();
|
17463 | ctx.stroke();
|
17464 |
|
17465 |
|
17466 | if (this.label) {
|
17467 | point = this._pointOnCircle(x, y, radius, 0.5);
|
17468 | this._label(ctx, this.label, point.x, point.y);
|
17469 | }
|
17470 | }
|
17471 | };
|
17472 |
|
17473 |
|
17474 |
|
17475 | |
17476 |
|
17477 |
|
17478 |
|
17479 |
|
17480 |
|
17481 |
|
17482 |
|
17483 |
|
17484 |
|
17485 |
|
17486 |
|
17487 | Edge.prototype._getDistanceToEdge = function (x1,y1, x2,y2, x3,y3) {
|
17488 | var returnValue = 0;
|
17489 | if (this.from != this.to) {
|
17490 | if (this.options.smoothCurves.enabled == true) {
|
17491 | var xVia, yVia;
|
17492 | if (this.options.smoothCurves.enabled == true && this.options.smoothCurves.dynamic == true) {
|
17493 | xVia = this.via.x;
|
17494 | yVia = this.via.y;
|
17495 | }
|
17496 | else {
|
17497 | var via = this._getViaCoordinates();
|
17498 | xVia = via.x;
|
17499 | yVia = via.y;
|
17500 | }
|
17501 | var minDistance = 1e9;
|
17502 | var distance;
|
17503 | var i,t,x,y, lastX, lastY;
|
17504 | for (i = 0; i < 10; i++) {
|
17505 | t = 0.1*i;
|
17506 | x = Math.pow(1-t,2)*x1 + (2*t*(1 - t))*xVia + Math.pow(t,2)*x2;
|
17507 | y = Math.pow(1-t,2)*y1 + (2*t*(1 - t))*yVia + Math.pow(t,2)*y2;
|
17508 | if (i > 0) {
|
17509 | distance = this._getDistanceToLine(lastX,lastY,x,y, x3,y3);
|
17510 | minDistance = distance < minDistance ? distance : minDistance;
|
17511 | }
|
17512 | lastX = x; lastY = y;
|
17513 | }
|
17514 | returnValue = minDistance;
|
17515 | }
|
17516 | else {
|
17517 | returnValue = this._getDistanceToLine(x1,y1,x2,y2,x3,y3);
|
17518 | }
|
17519 | }
|
17520 | else {
|
17521 | var x, y, dx, dy;
|
17522 | var radius = 0.25 * this.physics.springLength;
|
17523 | var node = this.from;
|
17524 | if (node.width > node.height) {
|
17525 | x = node.x + 0.5 * node.width;
|
17526 | y = node.y - radius;
|
17527 | }
|
17528 | else {
|
17529 | x = node.x + radius;
|
17530 | y = node.y - 0.5 * node.height;
|
17531 | }
|
17532 | dx = x - x3;
|
17533 | dy = y - y3;
|
17534 | returnValue = Math.abs(Math.sqrt(dx*dx + dy*dy) - radius);
|
17535 | }
|
17536 |
|
17537 | if (this.labelDimensions.left < x3 &&
|
17538 | this.labelDimensions.left + this.labelDimensions.width > x3 &&
|
17539 | this.labelDimensions.top < y3 &&
|
17540 | this.labelDimensions.top + this.labelDimensions.height > y3) {
|
17541 | return 0;
|
17542 | }
|
17543 | else {
|
17544 | return returnValue;
|
17545 | }
|
17546 | };
|
17547 |
|
17548 | Edge.prototype._getDistanceToLine = function(x1,y1,x2,y2,x3,y3) {
|
17549 | var px = x2-x1,
|
17550 | py = y2-y1,
|
17551 | something = px*px + py*py,
|
17552 | u = ((x3 - x1) * px + (y3 - y1) * py) / something;
|
17553 |
|
17554 | if (u > 1) {
|
17555 | u = 1;
|
17556 | }
|
17557 | else if (u < 0) {
|
17558 | u = 0;
|
17559 | }
|
17560 |
|
17561 | var x = x1 + u * px,
|
17562 | y = y1 + u * py,
|
17563 | dx = x - x3,
|
17564 | dy = y - y3;
|
17565 |
|
17566 |
|
17567 |
|
17568 |
|
17569 |
|
17570 |
|
17571 |
|
17572 | return Math.sqrt(dx*dx + dy*dy);
|
17573 | }
|
17574 |
|
17575 | |
17576 |
|
17577 |
|
17578 |
|
17579 |
|
17580 | Edge.prototype.setScale = function(scale) {
|
17581 | this.networkScaleInv = 1.0/scale;
|
17582 | };
|
17583 |
|
17584 |
|
17585 | Edge.prototype.select = function() {
|
17586 | this.selected = true;
|
17587 | };
|
17588 |
|
17589 | Edge.prototype.unselect = function() {
|
17590 | this.selected = false;
|
17591 | };
|
17592 |
|
17593 | Edge.prototype.positionBezierNode = function() {
|
17594 | if (this.via !== null && this.from !== null && this.to !== null) {
|
17595 | this.via.x = 0.5 * (this.from.x + this.to.x);
|
17596 | this.via.y = 0.5 * (this.from.y + this.to.y);
|
17597 | }
|
17598 | };
|
17599 |
|
17600 | |
17601 |
|
17602 |
|
17603 |
|
17604 | Edge.prototype._drawControlNodes = function(ctx) {
|
17605 | if (this.controlNodesEnabled == true) {
|
17606 | if (this.controlNodes.from === null && this.controlNodes.to === null) {
|
17607 | var nodeIdFrom = "edgeIdFrom:".concat(this.id);
|
17608 | var nodeIdTo = "edgeIdTo:".concat(this.id);
|
17609 | var constants = {
|
17610 | nodes:{group:'', radius:8},
|
17611 | physics:{damping:0},
|
17612 | clustering: {maxNodeSizeIncrements: 0 ,nodeScaling: {width:0, height: 0, radius:0}}
|
17613 | };
|
17614 | this.controlNodes.from = new Node(
|
17615 | {id:nodeIdFrom,
|
17616 | shape:'dot',
|
17617 | color:{background:'#ff4e00', border:'#3c3c3c', highlight: {background:'#07f968'}}
|
17618 | },{},{},constants);
|
17619 | this.controlNodes.to = new Node(
|
17620 | {id:nodeIdTo,
|
17621 | shape:'dot',
|
17622 | color:{background:'#ff4e00', border:'#3c3c3c', highlight: {background:'#07f968'}}
|
17623 | },{},{},constants);
|
17624 | }
|
17625 |
|
17626 | if (this.controlNodes.from.selected == false && this.controlNodes.to.selected == false) {
|
17627 | this.controlNodes.positions = this.getControlNodePositions(ctx);
|
17628 | this.controlNodes.from.x = this.controlNodes.positions.from.x;
|
17629 | this.controlNodes.from.y = this.controlNodes.positions.from.y;
|
17630 | this.controlNodes.to.x = this.controlNodes.positions.to.x;
|
17631 | this.controlNodes.to.y = this.controlNodes.positions.to.y;
|
17632 | }
|
17633 |
|
17634 | this.controlNodes.from.draw(ctx);
|
17635 | this.controlNodes.to.draw(ctx);
|
17636 | }
|
17637 | else {
|
17638 | this.controlNodes = {from:null, to:null, positions:{}};
|
17639 | }
|
17640 | };
|
17641 |
|
17642 | |
17643 |
|
17644 |
|
17645 |
|
17646 | Edge.prototype._enableControlNodes = function() {
|
17647 | this.controlNodesEnabled = true;
|
17648 | };
|
17649 |
|
17650 | |
17651 |
|
17652 |
|
17653 |
|
17654 | Edge.prototype._disableControlNodes = function() {
|
17655 | this.controlNodesEnabled = false;
|
17656 | };
|
17657 |
|
17658 | |
17659 |
|
17660 |
|
17661 |
|
17662 |
|
17663 |
|
17664 |
|
17665 | Edge.prototype._getSelectedControlNode = function(x,y) {
|
17666 | var positions = this.controlNodes.positions;
|
17667 | var fromDistance = Math.sqrt(Math.pow(x - positions.from.x,2) + Math.pow(y - positions.from.y,2));
|
17668 | var toDistance = Math.sqrt(Math.pow(x - positions.to.x ,2) + Math.pow(y - positions.to.y ,2));
|
17669 |
|
17670 | if (fromDistance < 15) {
|
17671 | this.connectedNode = this.from;
|
17672 | this.from = this.controlNodes.from;
|
17673 | return this.controlNodes.from;
|
17674 | }
|
17675 | else if (toDistance < 15) {
|
17676 | this.connectedNode = this.to;
|
17677 | this.to = this.controlNodes.to;
|
17678 | return this.controlNodes.to;
|
17679 | }
|
17680 | else {
|
17681 | return null;
|
17682 | }
|
17683 | };
|
17684 |
|
17685 |
|
17686 | |
17687 |
|
17688 |
|
17689 |
|
17690 | Edge.prototype._restoreControlNodes = function() {
|
17691 | if (this.controlNodes.from.selected == true) {
|
17692 | this.from = this.connectedNode;
|
17693 | this.connectedNode = null;
|
17694 | this.controlNodes.from.unselect();
|
17695 | }
|
17696 | if (this.controlNodes.to.selected == true) {
|
17697 | this.to = this.connectedNode;
|
17698 | this.connectedNode = null;
|
17699 | this.controlNodes.to.unselect();
|
17700 | }
|
17701 | };
|
17702 |
|
17703 | |
17704 |
|
17705 |
|
17706 |
|
17707 |
|
17708 |
|
17709 | Edge.prototype.getControlNodePositions = function(ctx) {
|
17710 | var angle = Math.atan2((this.to.y - this.from.y), (this.to.x - this.from.x));
|
17711 | var dx = (this.to.x - this.from.x);
|
17712 | var dy = (this.to.y - this.from.y);
|
17713 | var edgeSegmentLength = Math.sqrt(dx * dx + dy * dy);
|
17714 | var fromBorderDist = this.from.distanceToBorder(ctx, angle + Math.PI);
|
17715 | var fromBorderPoint = (edgeSegmentLength - fromBorderDist) / edgeSegmentLength;
|
17716 | var xFrom = (fromBorderPoint) * this.from.x + (1 - fromBorderPoint) * this.to.x;
|
17717 | var yFrom = (fromBorderPoint) * this.from.y + (1 - fromBorderPoint) * this.to.y;
|
17718 |
|
17719 | var via;
|
17720 | if (this.options.smoothCurves.dynamic == true && this.options.smoothCurves.enabled == true) {
|
17721 | via = this.via;
|
17722 | }
|
17723 | else if (this.options.smoothCurves.enabled == true) {
|
17724 | via = this._getViaCoordinates();
|
17725 | }
|
17726 |
|
17727 | if (this.options.smoothCurves.enabled == true && via.x != null) {
|
17728 | angle = Math.atan2((this.to.y - via.y), (this.to.x - via.x));
|
17729 | dx = (this.to.x - via.x);
|
17730 | dy = (this.to.y - via.y);
|
17731 | edgeSegmentLength = Math.sqrt(dx * dx + dy * dy);
|
17732 | }
|
17733 | var toBorderDist = this.to.distanceToBorder(ctx, angle);
|
17734 | var toBorderPoint = (edgeSegmentLength - toBorderDist) / edgeSegmentLength;
|
17735 |
|
17736 | var xTo,yTo;
|
17737 | if (this.options.smoothCurves.enabled == true && via.x != null) {
|
17738 | xTo = (1 - toBorderPoint) * via.x + toBorderPoint * this.to.x;
|
17739 | yTo = (1 - toBorderPoint) * via.y + toBorderPoint * this.to.y;
|
17740 | }
|
17741 | else {
|
17742 | xTo = (1 - toBorderPoint) * this.from.x + toBorderPoint * this.to.x;
|
17743 | yTo = (1 - toBorderPoint) * this.from.y + toBorderPoint * this.to.y;
|
17744 | }
|
17745 |
|
17746 | return {from:{x:xFrom,y:yFrom},to:{x:xTo,y:yTo}};
|
17747 | };
|
17748 |
|
17749 | module.exports = Edge;
|
17750 |
|
17751 | },
|
17752 |
|
17753 | function(module, exports, __webpack_require__) {
|
17754 |
|
17755 | var util = __webpack_require__(1);
|
17756 |
|
17757 | |
17758 |
|
17759 |
|
17760 |
|
17761 | function Groups() {
|
17762 | this.clear();
|
17763 | this.defaultIndex = 0;
|
17764 | }
|
17765 |
|
17766 |
|
17767 | |
17768 |
|
17769 |
|
17770 | Groups.DEFAULT = [
|
17771 | {border: "#2B7CE9", background: "#97C2FC", highlight: {border: "#2B7CE9", background: "#D2E5FF"}, hover: {border: "#2B7CE9", background: "#D2E5FF"}},
|
17772 | {border: "#FFA500", background: "#FFFF00", highlight: {border: "#FFA500", background: "#FFFFA3"}, hover: {border: "#FFA500", background: "#FFFFA3"}},
|
17773 | {border: "#FA0A10", background: "#FB7E81", highlight: {border: "#FA0A10", background: "#FFAFB1"}, hover: {border: "#FA0A10", background: "#FFAFB1"}},
|
17774 | {border: "#41A906", background: "#7BE141", highlight: {border: "#41A906", background: "#A1EC76"}, hover: {border: "#41A906", background: "#A1EC76"}},
|
17775 | {border: "#E129F0", background: "#EB7DF4", highlight: {border: "#E129F0", background: "#F0B3F5"}, hover: {border: "#E129F0", background: "#F0B3F5"}},
|
17776 | {border: "#7C29F0", background: "#AD85E4", highlight: {border: "#7C29F0", background: "#D3BDF0"}, hover: {border: "#7C29F0", background: "#D3BDF0"}},
|
17777 | {border: "#C37F00", background: "#FFA807", highlight: {border: "#C37F00", background: "#FFCA66"}, hover: {border: "#C37F00", background: "#FFCA66"}},
|
17778 | {border: "#4220FB", background: "#6E6EFD", highlight: {border: "#4220FB", background: "#9B9BFD"}, hover: {border: "#4220FB", background: "#9B9BFD"}},
|
17779 | {border: "#FD5A77", background: "#FFC0CB", highlight: {border: "#FD5A77", background: "#FFD1D9"}, hover: {border: "#FD5A77", background: "#FFD1D9"}},
|
17780 | {border: "#4AD63A", background: "#C2FABC", highlight: {border: "#4AD63A", background: "#E6FFE3"}, hover: {border: "#4AD63A", background: "#E6FFE3"}}
|
17781 | ];
|
17782 |
|
17783 |
|
17784 | |
17785 |
|
17786 |
|
17787 | Groups.prototype.clear = function () {
|
17788 | this.groups = {};
|
17789 | this.groups.length = function()
|
17790 | {
|
17791 | var i = 0;
|
17792 | for ( var p in this ) {
|
17793 | if (this.hasOwnProperty(p)) {
|
17794 | i++;
|
17795 | }
|
17796 | }
|
17797 | return i;
|
17798 | }
|
17799 | };
|
17800 |
|
17801 |
|
17802 | |
17803 |
|
17804 |
|
17805 |
|
17806 |
|
17807 |
|
17808 | Groups.prototype.get = function (groupname) {
|
17809 | var group = this.groups[groupname];
|
17810 | if (group == undefined) {
|
17811 |
|
17812 | var index = this.defaultIndex % Groups.DEFAULT.length;
|
17813 | this.defaultIndex++;
|
17814 | group = {};
|
17815 | group.color = Groups.DEFAULT[index];
|
17816 | this.groups[groupname] = group;
|
17817 | }
|
17818 |
|
17819 | return group;
|
17820 | };
|
17821 |
|
17822 | |
17823 |
|
17824 |
|
17825 |
|
17826 |
|
17827 |
|
17828 |
|
17829 | Groups.prototype.add = function (groupname, style) {
|
17830 | this.groups[groupname] = style;
|
17831 | if (style.color) {
|
17832 | style.color = util.parseColor(style.color);
|
17833 | }
|
17834 | return style;
|
17835 | };
|
17836 |
|
17837 | module.exports = Groups;
|
17838 |
|
17839 |
|
17840 | },
|
17841 |
|
17842 | function(module, exports, __webpack_require__) {
|
17843 |
|
17844 | |
17845 |
|
17846 |
|
17847 |
|
17848 | function Images() {
|
17849 | this.images = {};
|
17850 |
|
17851 | this.callback = undefined;
|
17852 | }
|
17853 |
|
17854 | |
17855 |
|
17856 |
|
17857 |
|
17858 |
|
17859 | Images.prototype.setOnloadCallback = function(callback) {
|
17860 | this.callback = callback;
|
17861 | };
|
17862 |
|
17863 | |
17864 |
|
17865 |
|
17866 |
|
17867 |
|
17868 |
|
17869 | Images.prototype.load = function(url, brokenUrl) {
|
17870 | var img = this.images[url];
|
17871 | if (img == undefined) {
|
17872 |
|
17873 | var images = this;
|
17874 | img = new Image();
|
17875 | this.images[url] = img;
|
17876 | img.onload = function() {
|
17877 | if (images.callback) {
|
17878 | images.callback(this);
|
17879 | }
|
17880 | };
|
17881 |
|
17882 | img.onerror = function () {
|
17883 | this.src = brokenUrl;
|
17884 | if (images.callback) {
|
17885 | images.callback(this);
|
17886 | }
|
17887 | };
|
17888 |
|
17889 | img.src = url;
|
17890 | }
|
17891 |
|
17892 | return img;
|
17893 | };
|
17894 |
|
17895 | module.exports = Images;
|
17896 |
|
17897 |
|
17898 | },
|
17899 |
|
17900 | function(module, exports, __webpack_require__) {
|
17901 |
|
17902 | var util = __webpack_require__(1);
|
17903 |
|
17904 | |
17905 |
|
17906 |
|
17907 |
|
17908 |
|
17909 |
|
17910 |
|
17911 |
|
17912 |
|
17913 |
|
17914 |
|
17915 |
|
17916 |
|
17917 |
|
17918 |
|
17919 |
|
17920 |
|
17921 |
|
17922 |
|
17923 |
|
17924 |
|
17925 |
|
17926 |
|
17927 |
|
17928 |
|
17929 | function Node(properties, imagelist, grouplist, networkConstants) {
|
17930 | var constants = util.selectiveBridgeObject(['nodes'],networkConstants);
|
17931 | this.options = constants.nodes;
|
17932 |
|
17933 | this.selected = false;
|
17934 | this.hover = false;
|
17935 |
|
17936 | this.edges = [];
|
17937 | this.dynamicEdges = [];
|
17938 | this.reroutedEdges = {};
|
17939 |
|
17940 | this.fontDrawThreshold = 3;
|
17941 |
|
17942 |
|
17943 | this.id = undefined;
|
17944 | this.x = null;
|
17945 | this.y = null;
|
17946 | this.allowedToMoveX = false;
|
17947 | this.allowedToMoveY = false;
|
17948 | this.xFixed = false;
|
17949 | this.yFixed = false;
|
17950 | this.horizontalAlignLeft = true;
|
17951 | this.verticalAlignTop = true;
|
17952 | this.baseRadiusValue = networkConstants.nodes.radius;
|
17953 | this.radiusFixed = false;
|
17954 | this.level = -1;
|
17955 | this.preassignedLevel = false;
|
17956 | this.hierarchyEnumerated = false;
|
17957 |
|
17958 |
|
17959 | this.imagelist = imagelist;
|
17960 | this.grouplist = grouplist;
|
17961 |
|
17962 |
|
17963 | this.fx = 0.0;
|
17964 | this.fy = 0.0;
|
17965 | this.vx = 0.0;
|
17966 | this.vy = 0.0;
|
17967 | this.damping = networkConstants.physics.damping;
|
17968 | this.fixedData = {x:null,y:null};
|
17969 |
|
17970 | this.setProperties(properties, constants);
|
17971 |
|
17972 |
|
17973 | this.resetCluster();
|
17974 | this.dynamicEdgesLength = 0;
|
17975 | this.clusterSession = 0;
|
17976 | this.clusterSizeWidthFactor = networkConstants.clustering.nodeScaling.width;
|
17977 | this.clusterSizeHeightFactor = networkConstants.clustering.nodeScaling.height;
|
17978 | this.clusterSizeRadiusFactor = networkConstants.clustering.nodeScaling.radius;
|
17979 | this.maxNodeSizeIncrements = networkConstants.clustering.maxNodeSizeIncrements;
|
17980 | this.growthIndicator = 0;
|
17981 |
|
17982 |
|
17983 | this.networkScaleInv = 1;
|
17984 | this.networkScale = 1;
|
17985 | this.canvasTopLeft = {"x": -300, "y": -300};
|
17986 | this.canvasBottomRight = {"x": 300, "y": 300};
|
17987 | this.parentEdgeId = null;
|
17988 | }
|
17989 |
|
17990 | |
17991 |
|
17992 |
|
17993 | Node.prototype.resetCluster = function() {
|
17994 |
|
17995 | this.formationScale = undefined;
|
17996 | this.clusterSize = 1;
|
17997 | this.containedNodes = {};
|
17998 | this.containedEdges = {};
|
17999 | this.clusterSessions = [];
|
18000 | };
|
18001 |
|
18002 | |
18003 |
|
18004 |
|
18005 |
|
18006 | Node.prototype.attachEdge = function(edge) {
|
18007 | if (this.edges.indexOf(edge) == -1) {
|
18008 | this.edges.push(edge);
|
18009 | }
|
18010 | if (this.dynamicEdges.indexOf(edge) == -1) {
|
18011 | this.dynamicEdges.push(edge);
|
18012 | }
|
18013 | this.dynamicEdgesLength = this.dynamicEdges.length;
|
18014 | };
|
18015 |
|
18016 | |
18017 |
|
18018 |
|
18019 |
|
18020 | Node.prototype.detachEdge = function(edge) {
|
18021 | var index = this.edges.indexOf(edge);
|
18022 | if (index != -1) {
|
18023 | this.edges.splice(index, 1);
|
18024 | }
|
18025 | index = this.dynamicEdges.indexOf(edge);
|
18026 | if (index != -1) {
|
18027 | this.dynamicEdges.splice(index, 1);
|
18028 | }
|
18029 | this.dynamicEdgesLength = this.dynamicEdges.length;
|
18030 | };
|
18031 |
|
18032 |
|
18033 | |
18034 |
|
18035 |
|
18036 |
|
18037 |
|
18038 | Node.prototype.setProperties = function(properties, constants) {
|
18039 | if (!properties) {
|
18040 | return;
|
18041 | }
|
18042 |
|
18043 | var fields = ['borderWidth','borderWidthSelected','shape','image','brokenImage','radius','fontColor',
|
18044 | 'fontSize','fontFace','fontFill','group','mass'
|
18045 | ];
|
18046 | util.selectiveDeepExtend(fields, this.options, properties);
|
18047 |
|
18048 | this.originalLabel = undefined;
|
18049 |
|
18050 | if (properties.id !== undefined) {this.id = properties.id;}
|
18051 | if (properties.label !== undefined) {this.label = properties.label; this.originalLabel = properties.label;}
|
18052 | if (properties.title !== undefined) {this.title = properties.title;}
|
18053 | if (properties.x !== undefined) {this.x = properties.x;}
|
18054 | if (properties.y !== undefined) {this.y = properties.y;}
|
18055 | if (properties.value !== undefined) {this.value = properties.value;}
|
18056 | if (properties.level !== undefined) {this.level = properties.level; this.preassignedLevel = true;}
|
18057 |
|
18058 |
|
18059 | if (properties.horizontalAlignLeft !== undefined) {this.horizontalAlignLeft = properties.horizontalAlignLeft;}
|
18060 | if (properties.verticalAlignTop !== undefined) {this.verticalAlignTop = properties.verticalAlignTop;}
|
18061 | if (properties.triggerFunction !== undefined) {this.triggerFunction = properties.triggerFunction;}
|
18062 |
|
18063 | if (this.id === undefined) {
|
18064 | throw "Node must have an id";
|
18065 | }
|
18066 |
|
18067 |
|
18068 | if (typeof this.options.group === 'number' || (typeof this.options.group === 'string' && this.options.group != '')) {
|
18069 | var groupObj = this.grouplist.get(this.options.group);
|
18070 | for (var prop in groupObj) {
|
18071 | if (groupObj.hasOwnProperty(prop)) {
|
18072 | this.options[prop] = groupObj[prop];
|
18073 | }
|
18074 | }
|
18075 | }
|
18076 |
|
18077 |
|
18078 |
|
18079 | if (properties.radius !== undefined) {this.baseRadiusValue = this.options.radius;}
|
18080 | if (properties.color !== undefined) {this.options.color = util.parseColor(properties.color);}
|
18081 |
|
18082 | if (this.options.image!== undefined && this.options.image!= "") {
|
18083 | if (this.imagelist) {
|
18084 | this.imageObj = this.imagelist.load(this.options.image, this.options.brokenImage);
|
18085 | }
|
18086 | else {
|
18087 | throw "No imagelist provided";
|
18088 | }
|
18089 | }
|
18090 |
|
18091 | if (properties.allowedToMoveX !== undefined) {
|
18092 | this.xFixed = !properties.allowedToMoveX;
|
18093 | this.allowedToMoveX = properties.allowedToMoveX;
|
18094 | }
|
18095 | else if (properties.x !== undefined && this.allowedToMoveX == false) {
|
18096 | this.xFixed = true;
|
18097 | }
|
18098 |
|
18099 |
|
18100 | if (properties.allowedToMoveY !== undefined) {
|
18101 | this.yFixed = !properties.allowedToMoveY;
|
18102 | this.allowedToMoveY = properties.allowedToMoveY;
|
18103 | }
|
18104 | else if (properties.y !== undefined && this.allowedToMoveY == false) {
|
18105 | this.yFixed = true;
|
18106 | }
|
18107 |
|
18108 | this.radiusFixed = this.radiusFixed || (properties.radius !== undefined);
|
18109 |
|
18110 | if (this.options.shape == 'image') {
|
18111 | this.options.radiusMin = constants.nodes.widthMin;
|
18112 | this.options.radiusMax = constants.nodes.widthMax;
|
18113 | }
|
18114 |
|
18115 |
|
18116 |
|
18117 |
|
18118 | switch (this.options.shape) {
|
18119 | case 'database': this.draw = this._drawDatabase; this.resize = this._resizeDatabase; break;
|
18120 | case 'box': this.draw = this._drawBox; this.resize = this._resizeBox; break;
|
18121 | case 'circle': this.draw = this._drawCircle; this.resize = this._resizeCircle; break;
|
18122 | case 'ellipse': this.draw = this._drawEllipse; this.resize = this._resizeEllipse; break;
|
18123 |
|
18124 | case 'image': this.draw = this._drawImage; this.resize = this._resizeImage; break;
|
18125 | case 'text': this.draw = this._drawText; this.resize = this._resizeText; break;
|
18126 | case 'dot': this.draw = this._drawDot; this.resize = this._resizeShape; break;
|
18127 | case 'square': this.draw = this._drawSquare; this.resize = this._resizeShape; break;
|
18128 | case 'triangle': this.draw = this._drawTriangle; this.resize = this._resizeShape; break;
|
18129 | case 'triangleDown': this.draw = this._drawTriangleDown; this.resize = this._resizeShape; break;
|
18130 | case 'star': this.draw = this._drawStar; this.resize = this._resizeShape; break;
|
18131 | default: this.draw = this._drawEllipse; this.resize = this._resizeEllipse; break;
|
18132 | }
|
18133 |
|
18134 | this._reset();
|
18135 |
|
18136 | };
|
18137 |
|
18138 | |
18139 |
|
18140 |
|
18141 | Node.prototype.select = function() {
|
18142 | this.selected = true;
|
18143 | this._reset();
|
18144 | };
|
18145 |
|
18146 | |
18147 |
|
18148 |
|
18149 | Node.prototype.unselect = function() {
|
18150 | this.selected = false;
|
18151 | this._reset();
|
18152 | };
|
18153 |
|
18154 |
|
18155 | |
18156 |
|
18157 |
|
18158 | Node.prototype.clearSizeCache = function() {
|
18159 | this._reset();
|
18160 | };
|
18161 |
|
18162 | |
18163 |
|
18164 |
|
18165 |
|
18166 | Node.prototype._reset = function() {
|
18167 | this.width = undefined;
|
18168 | this.height = undefined;
|
18169 | };
|
18170 |
|
18171 | |
18172 |
|
18173 |
|
18174 |
|
18175 |
|
18176 | Node.prototype.getTitle = function() {
|
18177 | return typeof this.title === "function" ? this.title() : this.title;
|
18178 | };
|
18179 |
|
18180 | |
18181 |
|
18182 |
|
18183 |
|
18184 |
|
18185 |
|
18186 | Node.prototype.distanceToBorder = function (ctx, angle) {
|
18187 | var borderWidth = 1;
|
18188 |
|
18189 | if (!this.width) {
|
18190 | this.resize(ctx);
|
18191 | }
|
18192 |
|
18193 | switch (this.options.shape) {
|
18194 | case 'circle':
|
18195 | case 'dot':
|
18196 | return this.options.radius+ borderWidth;
|
18197 |
|
18198 | case 'ellipse':
|
18199 | var a = this.width / 2;
|
18200 | var b = this.height / 2;
|
18201 | var w = (Math.sin(angle) * a);
|
18202 | var h = (Math.cos(angle) * b);
|
18203 | return a * b / Math.sqrt(w * w + h * h);
|
18204 |
|
18205 |
|
18206 |
|
18207 |
|
18208 |
|
18209 | case 'box':
|
18210 | case 'image':
|
18211 | case 'text':
|
18212 | default:
|
18213 | if (this.width) {
|
18214 | return Math.min(
|
18215 | Math.abs(this.width / 2 / Math.cos(angle)),
|
18216 | Math.abs(this.height / 2 / Math.sin(angle))) + borderWidth;
|
18217 |
|
18218 | }
|
18219 | else {
|
18220 | return 0;
|
18221 | }
|
18222 |
|
18223 | }
|
18224 |
|
18225 | };
|
18226 |
|
18227 | |
18228 |
|
18229 |
|
18230 |
|
18231 |
|
18232 | Node.prototype._setForce = function(fx, fy) {
|
18233 | this.fx = fx;
|
18234 | this.fy = fy;
|
18235 | };
|
18236 |
|
18237 | |
18238 |
|
18239 |
|
18240 |
|
18241 |
|
18242 |
|
18243 | Node.prototype._addForce = function(fx, fy) {
|
18244 | this.fx += fx;
|
18245 | this.fy += fy;
|
18246 | };
|
18247 |
|
18248 | |
18249 |
|
18250 |
|
18251 |
|
18252 | Node.prototype.discreteStep = function(interval) {
|
18253 | if (!this.xFixed) {
|
18254 | var dx = this.damping * this.vx;
|
18255 | var ax = (this.fx - dx) / this.options.mass;
|
18256 | this.vx += ax * interval;
|
18257 | this.x += this.vx * interval;
|
18258 | }
|
18259 | else {
|
18260 | this.fx = 0;
|
18261 | this.vx = 0;
|
18262 | }
|
18263 |
|
18264 | if (!this.yFixed) {
|
18265 | var dy = this.damping * this.vy;
|
18266 | var ay = (this.fy - dy) / this.options.mass;
|
18267 | this.vy += ay * interval;
|
18268 | this.y += this.vy * interval;
|
18269 | }
|
18270 | else {
|
18271 | this.fy = 0;
|
18272 | this.vy = 0;
|
18273 | }
|
18274 | };
|
18275 |
|
18276 |
|
18277 |
|
18278 | |
18279 |
|
18280 |
|
18281 |
|
18282 |
|
18283 | Node.prototype.discreteStepLimited = function(interval, maxVelocity) {
|
18284 | if (!this.xFixed) {
|
18285 | var dx = this.damping * this.vx;
|
18286 | var ax = (this.fx - dx) / this.options.mass;
|
18287 | this.vx += ax * interval;
|
18288 | this.vx = (Math.abs(this.vx) > maxVelocity) ? ((this.vx > 0) ? maxVelocity : -maxVelocity) : this.vx;
|
18289 | this.x += this.vx * interval;
|
18290 | }
|
18291 | else {
|
18292 | this.fx = 0;
|
18293 | this.vx = 0;
|
18294 | }
|
18295 |
|
18296 | if (!this.yFixed) {
|
18297 | var dy = this.damping * this.vy;
|
18298 | var ay = (this.fy - dy) / this.options.mass;
|
18299 | this.vy += ay * interval;
|
18300 | this.vy = (Math.abs(this.vy) > maxVelocity) ? ((this.vy > 0) ? maxVelocity : -maxVelocity) : this.vy;
|
18301 | this.y += this.vy * interval;
|
18302 | }
|
18303 | else {
|
18304 | this.fy = 0;
|
18305 | this.vy = 0;
|
18306 | }
|
18307 | };
|
18308 |
|
18309 | |
18310 |
|
18311 |
|
18312 |
|
18313 | Node.prototype.isFixed = function() {
|
18314 | return (this.xFixed && this.yFixed);
|
18315 | };
|
18316 |
|
18317 | |
18318 |
|
18319 |
|
18320 |
|
18321 |
|
18322 | Node.prototype.isMoving = function(vmin) {
|
18323 | var velocity = Math.sqrt(Math.pow(this.vx,2) + Math.pow(this.vy,2));
|
18324 |
|
18325 | return (velocity > vmin);
|
18326 | };
|
18327 |
|
18328 | |
18329 |
|
18330 |
|
18331 |
|
18332 | Node.prototype.isSelected = function() {
|
18333 | return this.selected;
|
18334 | };
|
18335 |
|
18336 | |
18337 |
|
18338 |
|
18339 |
|
18340 | Node.prototype.getValue = function() {
|
18341 | return this.value;
|
18342 | };
|
18343 |
|
18344 | |
18345 |
|
18346 |
|
18347 |
|
18348 |
|
18349 |
|
18350 | Node.prototype.getDistance = function(x, y) {
|
18351 | var dx = this.x - x,
|
18352 | dy = this.y - y;
|
18353 | return Math.sqrt(dx * dx + dy * dy);
|
18354 | };
|
18355 |
|
18356 |
|
18357 | |
18358 |
|
18359 |
|
18360 |
|
18361 |
|
18362 |
|
18363 | Node.prototype.setValueRange = function(min, max) {
|
18364 | if (!this.radiusFixed && this.value !== undefined) {
|
18365 | if (max == min) {
|
18366 | this.options.radius= (this.options.radiusMin + this.options.radiusMax) / 2;
|
18367 | }
|
18368 | else {
|
18369 | var scale = (this.options.radiusMax - this.options.radiusMin) / (max - min);
|
18370 | this.options.radius= (this.value - min) * scale + this.options.radiusMin;
|
18371 | }
|
18372 | }
|
18373 | this.baseRadiusValue = this.options.radius;
|
18374 | };
|
18375 |
|
18376 | |
18377 |
|
18378 |
|
18379 |
|
18380 |
|
18381 | Node.prototype.draw = function(ctx) {
|
18382 | throw "Draw method not initialized for node";
|
18383 | };
|
18384 |
|
18385 | |
18386 |
|
18387 |
|
18388 |
|
18389 |
|
18390 | Node.prototype.resize = function(ctx) {
|
18391 | throw "Resize method not initialized for node";
|
18392 | };
|
18393 |
|
18394 | |
18395 |
|
18396 |
|
18397 |
|
18398 |
|
18399 | Node.prototype.isOverlappingWith = function(obj) {
|
18400 | return (this.left < obj.right &&
|
18401 | this.left + this.width > obj.left &&
|
18402 | this.top < obj.bottom &&
|
18403 | this.top + this.height > obj.top);
|
18404 | };
|
18405 |
|
18406 | Node.prototype._resizeImage = function (ctx) {
|
18407 |
|
18408 |
|
18409 | if (!this.width || !this.height) {
|
18410 | var width, height;
|
18411 | if (this.value) {
|
18412 | this.options.radius= this.baseRadiusValue;
|
18413 | var scale = this.imageObj.height / this.imageObj.width;
|
18414 | if (scale !== undefined) {
|
18415 | width = this.options.radius|| this.imageObj.width;
|
18416 | height = this.options.radius* scale || this.imageObj.height;
|
18417 | }
|
18418 | else {
|
18419 | width = 0;
|
18420 | height = 0;
|
18421 | }
|
18422 | }
|
18423 | else {
|
18424 | width = this.imageObj.width;
|
18425 | height = this.imageObj.height;
|
18426 | }
|
18427 | this.width = width;
|
18428 | this.height = height;
|
18429 |
|
18430 | this.growthIndicator = 0;
|
18431 | if (this.width > 0 && this.height > 0) {
|
18432 | this.width += Math.min(this.clusterSize - 1, this.maxNodeSizeIncrements) * this.clusterSizeWidthFactor;
|
18433 | this.height += Math.min(this.clusterSize - 1, this.maxNodeSizeIncrements) * this.clusterSizeHeightFactor;
|
18434 | this.options.radius+= Math.min(this.clusterSize - 1, this.maxNodeSizeIncrements) * this.clusterSizeRadiusFactor;
|
18435 | this.growthIndicator = this.width - width;
|
18436 | }
|
18437 | }
|
18438 |
|
18439 | };
|
18440 |
|
18441 | Node.prototype._drawImage = function (ctx) {
|
18442 | this._resizeImage(ctx);
|
18443 |
|
18444 | this.left = this.x - this.width / 2;
|
18445 | this.top = this.y - this.height / 2;
|
18446 |
|
18447 | var yLabel;
|
18448 | if (this.imageObj.width != 0 ) {
|
18449 |
|
18450 | if (this.clusterSize > 1) {
|
18451 | var lineWidth = ((this.clusterSize > 1) ? 10 : 0.0);
|
18452 | lineWidth *= this.networkScaleInv;
|
18453 | lineWidth = Math.min(0.2 * this.width,lineWidth);
|
18454 |
|
18455 | ctx.globalAlpha = 0.5;
|
18456 | ctx.drawImage(this.imageObj, this.left - lineWidth, this.top - lineWidth, this.width + 2*lineWidth, this.height + 2*lineWidth);
|
18457 | }
|
18458 |
|
18459 |
|
18460 | ctx.globalAlpha = 1.0;
|
18461 | ctx.drawImage(this.imageObj, this.left, this.top, this.width, this.height);
|
18462 | yLabel = this.y + this.height / 2;
|
18463 | }
|
18464 | else {
|
18465 |
|
18466 | yLabel = this.y;
|
18467 | }
|
18468 |
|
18469 | this._label(ctx, this.label, this.x, yLabel, undefined, "top");
|
18470 | };
|
18471 |
|
18472 |
|
18473 | Node.prototype._resizeBox = function (ctx) {
|
18474 | if (!this.width) {
|
18475 | var margin = 5;
|
18476 | var textSize = this.getTextSize(ctx);
|
18477 | this.width = textSize.width + 2 * margin;
|
18478 | this.height = textSize.height + 2 * margin;
|
18479 |
|
18480 | this.width += Math.min(this.clusterSize - 1, this.maxNodeSizeIncrements) * 0.5 * this.clusterSizeWidthFactor;
|
18481 | this.height += Math.min(this.clusterSize - 1, this.maxNodeSizeIncrements) * 0.5 * this.clusterSizeHeightFactor;
|
18482 | this.growthIndicator = this.width - (textSize.width + 2 * margin);
|
18483 |
|
18484 |
|
18485 | }
|
18486 | };
|
18487 |
|
18488 | Node.prototype._drawBox = function (ctx) {
|
18489 | this._resizeBox(ctx);
|
18490 |
|
18491 | this.left = this.x - this.width / 2;
|
18492 | this.top = this.y - this.height / 2;
|
18493 |
|
18494 | var clusterLineWidth = 2.5;
|
18495 | var borderWidth = this.options.borderWidth;
|
18496 | var selectionLineWidth = this.options.borderWidthSelected || 2 * this.options.borderWidth;
|
18497 |
|
18498 | ctx.strokeStyle = this.selected ? this.options.color.highlight.border : this.hover ? this.options.color.hover.border : this.options.color.border;
|
18499 |
|
18500 |
|
18501 | if (this.clusterSize > 1) {
|
18502 | ctx.lineWidth = (this.selected ? selectionLineWidth : borderWidth) + ((this.clusterSize > 1) ? clusterLineWidth : 0.0);
|
18503 | ctx.lineWidth *= this.networkScaleInv;
|
18504 | ctx.lineWidth = Math.min(this.width,ctx.lineWidth);
|
18505 |
|
18506 | ctx.roundRect(this.left-2*ctx.lineWidth, this.top-2*ctx.lineWidth, this.width+4*ctx.lineWidth, this.height+4*ctx.lineWidth, this.options.radius);
|
18507 | ctx.stroke();
|
18508 | }
|
18509 | ctx.lineWidth = (this.selected ? selectionLineWidth : borderWidth) + ((this.clusterSize > 1) ? clusterLineWidth : 0.0);
|
18510 | ctx.lineWidth *= this.networkScaleInv;
|
18511 | ctx.lineWidth = Math.min(this.width,ctx.lineWidth);
|
18512 |
|
18513 | ctx.fillStyle = this.selected ? this.options.color.highlight.background : this.options.color.background;
|
18514 |
|
18515 | ctx.roundRect(this.left, this.top, this.width, this.height, this.options.radius);
|
18516 | ctx.fill();
|
18517 | ctx.stroke();
|
18518 |
|
18519 | this._label(ctx, this.label, this.x, this.y);
|
18520 | };
|
18521 |
|
18522 |
|
18523 | Node.prototype._resizeDatabase = function (ctx) {
|
18524 | if (!this.width) {
|
18525 | var margin = 5;
|
18526 | var textSize = this.getTextSize(ctx);
|
18527 | var size = textSize.width + 2 * margin;
|
18528 | this.width = size;
|
18529 | this.height = size;
|
18530 |
|
18531 |
|
18532 | this.width += Math.min(this.clusterSize - 1, this.maxNodeSizeIncrements) * this.clusterSizeWidthFactor;
|
18533 | this.height += Math.min(this.clusterSize - 1, this.maxNodeSizeIncrements) * this.clusterSizeHeightFactor;
|
18534 | this.options.radius+= Math.min(this.clusterSize - 1, this.maxNodeSizeIncrements) * this.clusterSizeRadiusFactor;
|
18535 | this.growthIndicator = this.width - size;
|
18536 | }
|
18537 | };
|
18538 |
|
18539 | Node.prototype._drawDatabase = function (ctx) {
|
18540 | this._resizeDatabase(ctx);
|
18541 | this.left = this.x - this.width / 2;
|
18542 | this.top = this.y - this.height / 2;
|
18543 |
|
18544 | var clusterLineWidth = 2.5;
|
18545 | var borderWidth = this.options.borderWidth;
|
18546 | var selectionLineWidth = this.options.borderWidthSelected || 2 * this.options.borderWidth;
|
18547 |
|
18548 | ctx.strokeStyle = this.selected ? this.options.color.highlight.border : this.hover ? this.options.color.hover.border : this.options.color.border;
|
18549 |
|
18550 |
|
18551 | if (this.clusterSize > 1) {
|
18552 | ctx.lineWidth = (this.selected ? selectionLineWidth : borderWidth) + ((this.clusterSize > 1) ? clusterLineWidth : 0.0);
|
18553 | ctx.lineWidth *= this.networkScaleInv;
|
18554 | ctx.lineWidth = Math.min(this.width,ctx.lineWidth);
|
18555 |
|
18556 | ctx.database(this.x - this.width/2 - 2*ctx.lineWidth, this.y - this.height*0.5 - 2*ctx.lineWidth, this.width + 4*ctx.lineWidth, this.height + 4*ctx.lineWidth);
|
18557 | ctx.stroke();
|
18558 | }
|
18559 | ctx.lineWidth = (this.selected ? selectionLineWidth : borderWidth) + ((this.clusterSize > 1) ? clusterLineWidth : 0.0);
|
18560 | ctx.lineWidth *= this.networkScaleInv;
|
18561 | ctx.lineWidth = Math.min(this.width,ctx.lineWidth);
|
18562 |
|
18563 | ctx.fillStyle = this.selected ? this.options.color.highlight.background : this.hover ? this.options.color.hover.background : this.options.color.background;
|
18564 | ctx.database(this.x - this.width/2, this.y - this.height*0.5, this.width, this.height);
|
18565 | ctx.fill();
|
18566 | ctx.stroke();
|
18567 |
|
18568 | this._label(ctx, this.label, this.x, this.y);
|
18569 | };
|
18570 |
|
18571 |
|
18572 | Node.prototype._resizeCircle = function (ctx) {
|
18573 | if (!this.width) {
|
18574 | var margin = 5;
|
18575 | var textSize = this.getTextSize(ctx);
|
18576 | var diameter = Math.max(textSize.width, textSize.height) + 2 * margin;
|
18577 | this.options.radius = diameter / 2;
|
18578 |
|
18579 | this.width = diameter;
|
18580 | this.height = diameter;
|
18581 |
|
18582 |
|
18583 |
|
18584 |
|
18585 | this.options.radius += Math.min(this.clusterSize - 1, this.maxNodeSizeIncrements) * 0.5 * this.clusterSizeRadiusFactor;
|
18586 | this.growthIndicator = this.options.radius- 0.5*diameter;
|
18587 | }
|
18588 | };
|
18589 |
|
18590 | Node.prototype._drawCircle = function (ctx) {
|
18591 | this._resizeCircle(ctx);
|
18592 | this.left = this.x - this.width / 2;
|
18593 | this.top = this.y - this.height / 2;
|
18594 |
|
18595 | var clusterLineWidth = 2.5;
|
18596 | var borderWidth = this.options.borderWidth;
|
18597 | var selectionLineWidth = this.options.borderWidthSelected || 2 * this.options.borderWidth;
|
18598 |
|
18599 | ctx.strokeStyle = this.selected ? this.options.color.highlight.border : this.hover ? this.options.color.hover.border : this.options.color.border;
|
18600 |
|
18601 |
|
18602 | if (this.clusterSize > 1) {
|
18603 | ctx.lineWidth = (this.selected ? selectionLineWidth : borderWidth) + ((this.clusterSize > 1) ? clusterLineWidth : 0.0);
|
18604 | ctx.lineWidth *= this.networkScaleInv;
|
18605 | ctx.lineWidth = Math.min(this.width,ctx.lineWidth);
|
18606 |
|
18607 | ctx.circle(this.x, this.y, this.options.radius+2*ctx.lineWidth);
|
18608 | ctx.stroke();
|
18609 | }
|
18610 | ctx.lineWidth = (this.selected ? selectionLineWidth : borderWidth) + ((this.clusterSize > 1) ? clusterLineWidth : 0.0);
|
18611 | ctx.lineWidth *= this.networkScaleInv;
|
18612 | ctx.lineWidth = Math.min(this.width,ctx.lineWidth);
|
18613 |
|
18614 | ctx.fillStyle = this.selected ? this.options.color.highlight.background : this.hover ? this.options.color.hover.background : this.options.color.background;
|
18615 | ctx.circle(this.x, this.y, this.options.radius);
|
18616 | ctx.fill();
|
18617 | ctx.stroke();
|
18618 |
|
18619 | this._label(ctx, this.label, this.x, this.y);
|
18620 | };
|
18621 |
|
18622 | Node.prototype._resizeEllipse = function (ctx) {
|
18623 | if (!this.width) {
|
18624 | var textSize = this.getTextSize(ctx);
|
18625 |
|
18626 | this.width = textSize.width * 1.5;
|
18627 | this.height = textSize.height * 2;
|
18628 | if (this.width < this.height) {
|
18629 | this.width = this.height;
|
18630 | }
|
18631 | var defaultSize = this.width;
|
18632 |
|
18633 |
|
18634 | this.width += Math.min(this.clusterSize - 1, this.maxNodeSizeIncrements) * this.clusterSizeWidthFactor;
|
18635 | this.height += Math.min(this.clusterSize - 1, this.maxNodeSizeIncrements) * this.clusterSizeHeightFactor;
|
18636 | this.options.radius += Math.min(this.clusterSize - 1, this.maxNodeSizeIncrements) * this.clusterSizeRadiusFactor;
|
18637 | this.growthIndicator = this.width - defaultSize;
|
18638 | }
|
18639 | };
|
18640 |
|
18641 | Node.prototype._drawEllipse = function (ctx) {
|
18642 | this._resizeEllipse(ctx);
|
18643 | this.left = this.x - this.width / 2;
|
18644 | this.top = this.y - this.height / 2;
|
18645 |
|
18646 | var clusterLineWidth = 2.5;
|
18647 | var borderWidth = this.options.borderWidth;
|
18648 | var selectionLineWidth = this.options.borderWidthSelected || 2 * this.options.borderWidth;
|
18649 |
|
18650 | ctx.strokeStyle = this.selected ? this.options.color.highlight.border : this.hover ? this.options.color.hover.border : this.options.color.border;
|
18651 |
|
18652 |
|
18653 | if (this.clusterSize > 1) {
|
18654 | ctx.lineWidth = (this.selected ? selectionLineWidth : borderWidth) + ((this.clusterSize > 1) ? clusterLineWidth : 0.0);
|
18655 | ctx.lineWidth *= this.networkScaleInv;
|
18656 | ctx.lineWidth = Math.min(this.width,ctx.lineWidth);
|
18657 |
|
18658 | ctx.ellipse(this.left-2*ctx.lineWidth, this.top-2*ctx.lineWidth, this.width+4*ctx.lineWidth, this.height+4*ctx.lineWidth);
|
18659 | ctx.stroke();
|
18660 | }
|
18661 | ctx.lineWidth = (this.selected ? selectionLineWidth : borderWidth) + ((this.clusterSize > 1) ? clusterLineWidth : 0.0);
|
18662 | ctx.lineWidth *= this.networkScaleInv;
|
18663 | ctx.lineWidth = Math.min(this.width,ctx.lineWidth);
|
18664 |
|
18665 | ctx.fillStyle = this.selected ? this.options.color.highlight.background : this.hover ? this.options.color.hover.background : this.options.color.background;
|
18666 |
|
18667 | ctx.ellipse(this.left, this.top, this.width, this.height);
|
18668 | ctx.fill();
|
18669 | ctx.stroke();
|
18670 | this._label(ctx, this.label, this.x, this.y);
|
18671 | };
|
18672 |
|
18673 | Node.prototype._drawDot = function (ctx) {
|
18674 | this._drawShape(ctx, 'circle');
|
18675 | };
|
18676 |
|
18677 | Node.prototype._drawTriangle = function (ctx) {
|
18678 | this._drawShape(ctx, 'triangle');
|
18679 | };
|
18680 |
|
18681 | Node.prototype._drawTriangleDown = function (ctx) {
|
18682 | this._drawShape(ctx, 'triangleDown');
|
18683 | };
|
18684 |
|
18685 | Node.prototype._drawSquare = function (ctx) {
|
18686 | this._drawShape(ctx, 'square');
|
18687 | };
|
18688 |
|
18689 | Node.prototype._drawStar = function (ctx) {
|
18690 | this._drawShape(ctx, 'star');
|
18691 | };
|
18692 |
|
18693 | Node.prototype._resizeShape = function (ctx) {
|
18694 | if (!this.width) {
|
18695 | this.options.radius= this.baseRadiusValue;
|
18696 | var size = 2 * this.options.radius;
|
18697 | this.width = size;
|
18698 | this.height = size;
|
18699 |
|
18700 |
|
18701 | this.width += Math.min(this.clusterSize - 1, this.maxNodeSizeIncrements) * this.clusterSizeWidthFactor;
|
18702 | this.height += Math.min(this.clusterSize - 1, this.maxNodeSizeIncrements) * this.clusterSizeHeightFactor;
|
18703 | this.options.radius+= Math.min(this.clusterSize - 1, this.maxNodeSizeIncrements) * 0.5 * this.clusterSizeRadiusFactor;
|
18704 | this.growthIndicator = this.width - size;
|
18705 | }
|
18706 | };
|
18707 |
|
18708 | Node.prototype._drawShape = function (ctx, shape) {
|
18709 | this._resizeShape(ctx);
|
18710 |
|
18711 | this.left = this.x - this.width / 2;
|
18712 | this.top = this.y - this.height / 2;
|
18713 |
|
18714 | var clusterLineWidth = 2.5;
|
18715 | var borderWidth = this.options.borderWidth;
|
18716 | var selectionLineWidth = this.options.borderWidthSelected || 2 * this.options.borderWidth;
|
18717 | var radiusMultiplier = 2;
|
18718 |
|
18719 |
|
18720 | switch (shape) {
|
18721 | case 'dot': radiusMultiplier = 2; break;
|
18722 | case 'square': radiusMultiplier = 2; break;
|
18723 | case 'triangle': radiusMultiplier = 3; break;
|
18724 | case 'triangleDown': radiusMultiplier = 3; break;
|
18725 | case 'star': radiusMultiplier = 4; break;
|
18726 | }
|
18727 |
|
18728 | ctx.strokeStyle = this.selected ? this.options.color.highlight.border : this.hover ? this.options.color.hover.border : this.options.color.border;
|
18729 |
|
18730 | if (this.clusterSize > 1) {
|
18731 | ctx.lineWidth = (this.selected ? selectionLineWidth : borderWidth) + ((this.clusterSize > 1) ? clusterLineWidth : 0.0);
|
18732 | ctx.lineWidth *= this.networkScaleInv;
|
18733 | ctx.lineWidth = Math.min(this.width,ctx.lineWidth);
|
18734 |
|
18735 | ctx[shape](this.x, this.y, this.options.radius+ radiusMultiplier * ctx.lineWidth);
|
18736 | ctx.stroke();
|
18737 | }
|
18738 | ctx.lineWidth = (this.selected ? selectionLineWidth : borderWidth) + ((this.clusterSize > 1) ? clusterLineWidth : 0.0);
|
18739 | ctx.lineWidth *= this.networkScaleInv;
|
18740 | ctx.lineWidth = Math.min(this.width,ctx.lineWidth);
|
18741 |
|
18742 | ctx.fillStyle = this.selected ? this.options.color.highlight.background : this.hover ? this.options.color.hover.background : this.options.color.background;
|
18743 | ctx[shape](this.x, this.y, this.options.radius);
|
18744 | ctx.fill();
|
18745 | ctx.stroke();
|
18746 |
|
18747 | if (this.label) {
|
18748 | this._label(ctx, this.label, this.x, this.y + this.height / 2, undefined, 'top',true);
|
18749 | }
|
18750 | };
|
18751 |
|
18752 | Node.prototype._resizeText = function (ctx) {
|
18753 | if (!this.width) {
|
18754 | var margin = 5;
|
18755 | var textSize = this.getTextSize(ctx);
|
18756 | this.width = textSize.width + 2 * margin;
|
18757 | this.height = textSize.height + 2 * margin;
|
18758 |
|
18759 |
|
18760 | this.width += Math.min(this.clusterSize - 1, this.maxNodeSizeIncrements) * this.clusterSizeWidthFactor;
|
18761 | this.height += Math.min(this.clusterSize - 1, this.maxNodeSizeIncrements) * this.clusterSizeHeightFactor;
|
18762 | this.options.radius+= Math.min(this.clusterSize - 1, this.maxNodeSizeIncrements) * this.clusterSizeRadiusFactor;
|
18763 | this.growthIndicator = this.width - (textSize.width + 2 * margin);
|
18764 | }
|
18765 | };
|
18766 |
|
18767 | Node.prototype._drawText = function (ctx) {
|
18768 | this._resizeText(ctx);
|
18769 | this.left = this.x - this.width / 2;
|
18770 | this.top = this.y - this.height / 2;
|
18771 |
|
18772 | this._label(ctx, this.label, this.x, this.y);
|
18773 | };
|
18774 |
|
18775 |
|
18776 | Node.prototype._label = function (ctx, text, x, y, align, baseline, labelUnderNode) {
|
18777 | if (text && Number(this.options.fontSize) * this.networkScale > this.fontDrawThreshold) {
|
18778 | ctx.font = (this.selected ? "bold " : "") + this.options.fontSize + "px " + this.options.fontFace;
|
18779 | ctx.textAlign = align || "center";
|
18780 | ctx.textBaseline = baseline || "middle";
|
18781 |
|
18782 | var lines = text.split('\n');
|
18783 | var lineCount = lines.length;
|
18784 | var fontSize = (Number(this.options.fontSize) + 4);
|
18785 | var yLine = y + (1 - lineCount) / 2 * fontSize;
|
18786 | if (labelUnderNode == true) {
|
18787 | yLine = y + (1 - lineCount) / (2 * fontSize);
|
18788 | }
|
18789 |
|
18790 |
|
18791 | if (this.options.fontFill !== undefined && this.options.fontFill !== null && this.options.fontFill !== "none") {
|
18792 | var width = ctx.measureText(lines[0]).width;
|
18793 | for (var i = 1; i < lineCount; i++) {
|
18794 | var lineWidth = ctx.measureText(lines[i]).width;
|
18795 | width = lineWidth > width ? lineWidth : width;
|
18796 | }
|
18797 | var height = this.options.fontSize * lineCount;
|
18798 | var left = x - width / 2;
|
18799 | var top = y - height / 2;
|
18800 | if (ctx.textBaseline == "top") {
|
18801 | top += 0.5 * fontSize;
|
18802 | }
|
18803 | ctx.fillStyle = this.options.fontFill;
|
18804 | ctx.fillRect(left, top, width, height);
|
18805 | }
|
18806 |
|
18807 |
|
18808 | ctx.fillStyle = this.options.fontColor || "black";
|
18809 | for (var i = 0; i < lineCount; i++) {
|
18810 | ctx.fillText(lines[i], x, yLine);
|
18811 | yLine += fontSize;
|
18812 | }
|
18813 | }
|
18814 | };
|
18815 |
|
18816 |
|
18817 | Node.prototype.getTextSize = function(ctx) {
|
18818 | if (this.label !== undefined) {
|
18819 | ctx.font = (this.selected ? "bold " : "") + this.options.fontSize + "px " + this.options.fontFace;
|
18820 |
|
18821 | var lines = this.label.split('\n'),
|
18822 | height = (Number(this.options.fontSize) + 4) * lines.length,
|
18823 | width = 0;
|
18824 |
|
18825 | for (var i = 0, iMax = lines.length; i < iMax; i++) {
|
18826 | width = Math.max(width, ctx.measureText(lines[i]).width);
|
18827 | }
|
18828 |
|
18829 | return {"width": width, "height": height};
|
18830 | }
|
18831 | else {
|
18832 | return {"width": 0, "height": 0};
|
18833 | }
|
18834 | };
|
18835 |
|
18836 | |
18837 |
|
18838 |
|
18839 |
|
18840 |
|
18841 |
|
18842 | Node.prototype.inArea = function() {
|
18843 | if (this.width !== undefined) {
|
18844 | return (this.x + this.width *this.networkScaleInv >= this.canvasTopLeft.x &&
|
18845 | this.x - this.width *this.networkScaleInv < this.canvasBottomRight.x &&
|
18846 | this.y + this.height*this.networkScaleInv >= this.canvasTopLeft.y &&
|
18847 | this.y - this.height*this.networkScaleInv < this.canvasBottomRight.y);
|
18848 | }
|
18849 | else {
|
18850 | return true;
|
18851 | }
|
18852 | };
|
18853 |
|
18854 | |
18855 |
|
18856 |
|
18857 |
|
18858 | Node.prototype.inView = function() {
|
18859 | return (this.x >= this.canvasTopLeft.x &&
|
18860 | this.x < this.canvasBottomRight.x &&
|
18861 | this.y >= this.canvasTopLeft.y &&
|
18862 | this.y < this.canvasBottomRight.y);
|
18863 | };
|
18864 |
|
18865 | |
18866 |
|
18867 |
|
18868 |
|
18869 |
|
18870 |
|
18871 |
|
18872 |
|
18873 | Node.prototype.setScaleAndPos = function(scale,canvasTopLeft,canvasBottomRight) {
|
18874 | this.networkScaleInv = 1.0/scale;
|
18875 | this.networkScale = scale;
|
18876 | this.canvasTopLeft = canvasTopLeft;
|
18877 | this.canvasBottomRight = canvasBottomRight;
|
18878 | };
|
18879 |
|
18880 |
|
18881 | |
18882 |
|
18883 |
|
18884 |
|
18885 |
|
18886 | Node.prototype.setScale = function(scale) {
|
18887 | this.networkScaleInv = 1.0/scale;
|
18888 | this.networkScale = scale;
|
18889 | };
|
18890 |
|
18891 |
|
18892 |
|
18893 | |
18894 |
|
18895 |
|
18896 | Node.prototype.clearVelocity = function() {
|
18897 | this.vx = 0;
|
18898 | this.vy = 0;
|
18899 | };
|
18900 |
|
18901 |
|
18902 | |
18903 |
|
18904 |
|
18905 |
|
18906 |
|
18907 | Node.prototype.updateVelocity = function(massBeforeClustering) {
|
18908 | var energyBefore = this.vx * this.vx * massBeforeClustering;
|
18909 |
|
18910 | this.vx = Math.sqrt(energyBefore/this.options.mass);
|
18911 | energyBefore = this.vy * this.vy * massBeforeClustering;
|
18912 |
|
18913 | this.vy = Math.sqrt(energyBefore/this.options.mass);
|
18914 | };
|
18915 |
|
18916 | module.exports = Node;
|
18917 |
|
18918 |
|
18919 | },
|
18920 |
|
18921 | function(module, exports, __webpack_require__) {
|
18922 |
|
18923 | |
18924 |
|
18925 |
|
18926 |
|
18927 |
|
18928 |
|
18929 |
|
18930 |
|
18931 |
|
18932 | function Popup(container, x, y, text, style) {
|
18933 | if (container) {
|
18934 | this.container = container;
|
18935 | }
|
18936 | else {
|
18937 | this.container = document.body;
|
18938 | }
|
18939 |
|
18940 |
|
18941 | if (style === undefined) {
|
18942 | if (typeof x === "object") {
|
18943 | style = x;
|
18944 | x = undefined;
|
18945 | } else if (typeof text === "object") {
|
18946 | style = text;
|
18947 | text = undefined;
|
18948 | } else {
|
18949 |
|
18950 | style = {
|
18951 | fontColor: 'black',
|
18952 | fontSize: 14,
|
18953 | fontFace: 'verdana',
|
18954 | color: {
|
18955 | border: '#666',
|
18956 | background: '#FFFFC6'
|
18957 | }
|
18958 | }
|
18959 | }
|
18960 | }
|
18961 |
|
18962 | this.x = 0;
|
18963 | this.y = 0;
|
18964 | this.padding = 5;
|
18965 |
|
18966 | if (x !== undefined && y !== undefined ) {
|
18967 | this.setPosition(x, y);
|
18968 | }
|
18969 | if (text !== undefined) {
|
18970 | this.setText(text);
|
18971 | }
|
18972 |
|
18973 |
|
18974 | this.frame = document.createElement("div");
|
18975 | var styleAttr = this.frame.style;
|
18976 | styleAttr.position = "absolute";
|
18977 | styleAttr.visibility = "hidden";
|
18978 | styleAttr.border = "1px solid " + style.color.border;
|
18979 | styleAttr.color = style.fontColor;
|
18980 | styleAttr.fontSize = style.fontSize + "px";
|
18981 | styleAttr.fontFamily = style.fontFace;
|
18982 | styleAttr.padding = this.padding + "px";
|
18983 | styleAttr.backgroundColor = style.color.background;
|
18984 | styleAttr.borderRadius = "3px";
|
18985 | styleAttr.MozBorderRadius = "3px";
|
18986 | styleAttr.WebkitBorderRadius = "3px";
|
18987 | styleAttr.boxShadow = "3px 3px 10px rgba(128, 128, 128, 0.5)";
|
18988 | styleAttr.whiteSpace = "nowrap";
|
18989 | this.container.appendChild(this.frame);
|
18990 | }
|
18991 |
|
18992 | |
18993 |
|
18994 |
|
18995 |
|
18996 | Popup.prototype.setPosition = function(x, y) {
|
18997 | this.x = parseInt(x);
|
18998 | this.y = parseInt(y);
|
18999 | };
|
19000 |
|
19001 | |
19002 |
|
19003 |
|
19004 |
|
19005 | Popup.prototype.setText = function(text) {
|
19006 | this.frame.innerHTML = text;
|
19007 | };
|
19008 |
|
19009 | |
19010 |
|
19011 |
|
19012 |
|
19013 | Popup.prototype.show = function (show) {
|
19014 | if (show === undefined) {
|
19015 | show = true;
|
19016 | }
|
19017 |
|
19018 | if (show) {
|
19019 | var height = this.frame.clientHeight;
|
19020 | var width = this.frame.clientWidth;
|
19021 | var maxHeight = this.frame.parentNode.clientHeight;
|
19022 | var maxWidth = this.frame.parentNode.clientWidth;
|
19023 |
|
19024 | var top = (this.y - height);
|
19025 | if (top + height + this.padding > maxHeight) {
|
19026 | top = maxHeight - height - this.padding;
|
19027 | }
|
19028 | if (top < this.padding) {
|
19029 | top = this.padding;
|
19030 | }
|
19031 |
|
19032 | var left = this.x;
|
19033 | if (left + width + this.padding > maxWidth) {
|
19034 | left = maxWidth - width - this.padding;
|
19035 | }
|
19036 | if (left < this.padding) {
|
19037 | left = this.padding;
|
19038 | }
|
19039 |
|
19040 | this.frame.style.left = left + "px";
|
19041 | this.frame.style.top = top + "px";
|
19042 | this.frame.style.visibility = "visible";
|
19043 | }
|
19044 | else {
|
19045 | this.hide();
|
19046 | }
|
19047 | };
|
19048 |
|
19049 | |
19050 |
|
19051 |
|
19052 | Popup.prototype.hide = function () {
|
19053 | this.frame.style.visibility = "hidden";
|
19054 | };
|
19055 |
|
19056 | module.exports = Popup;
|
19057 |
|
19058 |
|
19059 | },
|
19060 |
|
19061 | function(module, exports, __webpack_require__) {
|
19062 |
|
19063 | |
19064 |
|
19065 |
|
19066 |
|
19067 |
|
19068 |
|
19069 |
|
19070 |
|
19071 |
|
19072 |
|
19073 |
|
19074 | function parseDOT (data) {
|
19075 | dot = data;
|
19076 | return parseGraph();
|
19077 | }
|
19078 |
|
19079 |
|
19080 | var TOKENTYPE = {
|
19081 | NULL : 0,
|
19082 | DELIMITER : 1,
|
19083 | IDENTIFIER: 2,
|
19084 | UNKNOWN : 3
|
19085 | };
|
19086 |
|
19087 |
|
19088 | var DELIMITERS = {
|
19089 | '{': true,
|
19090 | '}': true,
|
19091 | '[': true,
|
19092 | ']': true,
|
19093 | ';': true,
|
19094 | '=': true,
|
19095 | ',': true,
|
19096 |
|
19097 | '->': true,
|
19098 | '--': true
|
19099 | };
|
19100 |
|
19101 | var dot = '';
|
19102 | var index = 0;
|
19103 | var c = '';
|
19104 | var token = '';
|
19105 | var tokenType = TOKENTYPE.NULL;
|
19106 |
|
19107 | |
19108 |
|
19109 |
|
19110 |
|
19111 |
|
19112 | function first() {
|
19113 | index = 0;
|
19114 | c = dot.charAt(0);
|
19115 | }
|
19116 |
|
19117 | |
19118 |
|
19119 |
|
19120 |
|
19121 |
|
19122 | function next() {
|
19123 | index++;
|
19124 | c = dot.charAt(index);
|
19125 | }
|
19126 |
|
19127 | |
19128 |
|
19129 |
|
19130 |
|
19131 | function nextPreview() {
|
19132 | return dot.charAt(index + 1);
|
19133 | }
|
19134 |
|
19135 | |
19136 |
|
19137 |
|
19138 |
|
19139 |
|
19140 | var regexAlphaNumeric = /[a-zA-Z_0-9.:#]/;
|
19141 | function isAlphaNumeric(c) {
|
19142 | return regexAlphaNumeric.test(c);
|
19143 | }
|
19144 |
|
19145 | |
19146 |
|
19147 |
|
19148 |
|
19149 |
|
19150 |
|
19151 | function merge (a, b) {
|
19152 | if (!a) {
|
19153 | a = {};
|
19154 | }
|
19155 |
|
19156 | if (b) {
|
19157 | for (var name in b) {
|
19158 | if (b.hasOwnProperty(name)) {
|
19159 | a[name] = b[name];
|
19160 | }
|
19161 | }
|
19162 | }
|
19163 | return a;
|
19164 | }
|
19165 |
|
19166 | |
19167 |
|
19168 |
|
19169 |
|
19170 |
|
19171 |
|
19172 |
|
19173 |
|
19174 |
|
19175 |
|
19176 |
|
19177 |
|
19178 | function setValue(obj, path, value) {
|
19179 | var keys = path.split('.');
|
19180 | var o = obj;
|
19181 | while (keys.length) {
|
19182 | var key = keys.shift();
|
19183 | if (keys.length) {
|
19184 |
|
19185 | if (!o[key]) {
|
19186 | o[key] = {};
|
19187 | }
|
19188 | o = o[key];
|
19189 | }
|
19190 | else {
|
19191 |
|
19192 | o[key] = value;
|
19193 | }
|
19194 | }
|
19195 | }
|
19196 |
|
19197 | |
19198 |
|
19199 |
|
19200 |
|
19201 |
|
19202 |
|
19203 | function addNode(graph, node) {
|
19204 | var i, len;
|
19205 | var current = null;
|
19206 |
|
19207 |
|
19208 | var graphs = [graph];
|
19209 | var root = graph;
|
19210 | while (root.parent) {
|
19211 | graphs.push(root.parent);
|
19212 | root = root.parent;
|
19213 | }
|
19214 |
|
19215 |
|
19216 | if (root.nodes) {
|
19217 | for (i = 0, len = root.nodes.length; i < len; i++) {
|
19218 | if (node.id === root.nodes[i].id) {
|
19219 | current = root.nodes[i];
|
19220 | break;
|
19221 | }
|
19222 | }
|
19223 | }
|
19224 |
|
19225 | if (!current) {
|
19226 |
|
19227 | current = {
|
19228 | id: node.id
|
19229 | };
|
19230 | if (graph.node) {
|
19231 |
|
19232 | current.attr = merge(current.attr, graph.node);
|
19233 | }
|
19234 | }
|
19235 |
|
19236 |
|
19237 | for (i = graphs.length - 1; i >= 0; i--) {
|
19238 | var g = graphs[i];
|
19239 |
|
19240 | if (!g.nodes) {
|
19241 | g.nodes = [];
|
19242 | }
|
19243 | if (g.nodes.indexOf(current) == -1) {
|
19244 | g.nodes.push(current);
|
19245 | }
|
19246 | }
|
19247 |
|
19248 |
|
19249 | if (node.attr) {
|
19250 | current.attr = merge(current.attr, node.attr);
|
19251 | }
|
19252 | }
|
19253 |
|
19254 | |
19255 |
|
19256 |
|
19257 |
|
19258 |
|
19259 | function addEdge(graph, edge) {
|
19260 | if (!graph.edges) {
|
19261 | graph.edges = [];
|
19262 | }
|
19263 | graph.edges.push(edge);
|
19264 | if (graph.edge) {
|
19265 | var attr = merge({}, graph.edge);
|
19266 | edge.attr = merge(attr, edge.attr);
|
19267 | }
|
19268 | }
|
19269 |
|
19270 | |
19271 |
|
19272 |
|
19273 |
|
19274 |
|
19275 |
|
19276 |
|
19277 |
|
19278 |
|
19279 | function createEdge(graph, from, to, type, attr) {
|
19280 | var edge = {
|
19281 | from: from,
|
19282 | to: to,
|
19283 | type: type
|
19284 | };
|
19285 |
|
19286 | if (graph.edge) {
|
19287 | edge.attr = merge({}, graph.edge);
|
19288 | }
|
19289 | edge.attr = merge(edge.attr || {}, attr);
|
19290 |
|
19291 | return edge;
|
19292 | }
|
19293 |
|
19294 | |
19295 |
|
19296 |
|
19297 |
|
19298 | function getToken() {
|
19299 | tokenType = TOKENTYPE.NULL;
|
19300 | token = '';
|
19301 |
|
19302 |
|
19303 | while (c == ' ' || c == '\t' || c == '\n' || c == '\r') {
|
19304 | next();
|
19305 | }
|
19306 |
|
19307 | do {
|
19308 | var isComment = false;
|
19309 |
|
19310 |
|
19311 | if (c == '#') {
|
19312 |
|
19313 | var i = index - 1;
|
19314 | while (dot.charAt(i) == ' ' || dot.charAt(i) == '\t') {
|
19315 | i--;
|
19316 | }
|
19317 | if (dot.charAt(i) == '\n' || dot.charAt(i) == '') {
|
19318 |
|
19319 | while (c != '' && c != '\n') {
|
19320 | next();
|
19321 | }
|
19322 | isComment = true;
|
19323 | }
|
19324 | }
|
19325 | if (c == '/' && nextPreview() == '/') {
|
19326 |
|
19327 | while (c != '' && c != '\n') {
|
19328 | next();
|
19329 | }
|
19330 | isComment = true;
|
19331 | }
|
19332 | if (c == '/' && nextPreview() == '*') {
|
19333 |
|
19334 | while (c != '') {
|
19335 | if (c == '*' && nextPreview() == '/') {
|
19336 |
|
19337 | next();
|
19338 | next();
|
19339 | break;
|
19340 | }
|
19341 | else {
|
19342 | next();
|
19343 | }
|
19344 | }
|
19345 | isComment = true;
|
19346 | }
|
19347 |
|
19348 |
|
19349 | while (c == ' ' || c == '\t' || c == '\n' || c == '\r') {
|
19350 | next();
|
19351 | }
|
19352 | }
|
19353 | while (isComment);
|
19354 |
|
19355 |
|
19356 | if (c == '') {
|
19357 |
|
19358 | tokenType = TOKENTYPE.DELIMITER;
|
19359 | return;
|
19360 | }
|
19361 |
|
19362 |
|
19363 | var c2 = c + nextPreview();
|
19364 | if (DELIMITERS[c2]) {
|
19365 | tokenType = TOKENTYPE.DELIMITER;
|
19366 | token = c2;
|
19367 | next();
|
19368 | next();
|
19369 | return;
|
19370 | }
|
19371 |
|
19372 |
|
19373 | if (DELIMITERS[c]) {
|
19374 | tokenType = TOKENTYPE.DELIMITER;
|
19375 | token = c;
|
19376 | next();
|
19377 | return;
|
19378 | }
|
19379 |
|
19380 |
|
19381 |
|
19382 | if (isAlphaNumeric(c) || c == '-') {
|
19383 | token += c;
|
19384 | next();
|
19385 |
|
19386 | while (isAlphaNumeric(c)) {
|
19387 | token += c;
|
19388 | next();
|
19389 | }
|
19390 | if (token == 'false') {
|
19391 | token = false;
|
19392 | }
|
19393 | else if (token == 'true') {
|
19394 | token = true;
|
19395 | }
|
19396 | else if (!isNaN(Number(token))) {
|
19397 | token = Number(token);
|
19398 | }
|
19399 | tokenType = TOKENTYPE.IDENTIFIER;
|
19400 | return;
|
19401 | }
|
19402 |
|
19403 |
|
19404 | if (c == '"') {
|
19405 | next();
|
19406 | while (c != '' && (c != '"' || (c == '"' && nextPreview() == '"'))) {
|
19407 | token += c;
|
19408 | if (c == '"') {
|
19409 | next();
|
19410 | }
|
19411 | next();
|
19412 | }
|
19413 | if (c != '"') {
|
19414 | throw newSyntaxError('End of string " expected');
|
19415 | }
|
19416 | next();
|
19417 | tokenType = TOKENTYPE.IDENTIFIER;
|
19418 | return;
|
19419 | }
|
19420 |
|
19421 |
|
19422 | tokenType = TOKENTYPE.UNKNOWN;
|
19423 | while (c != '') {
|
19424 | token += c;
|
19425 | next();
|
19426 | }
|
19427 | throw new SyntaxError('Syntax error in part "' + chop(token, 30) + '"');
|
19428 | }
|
19429 |
|
19430 | |
19431 |
|
19432 |
|
19433 |
|
19434 | function parseGraph() {
|
19435 | var graph = {};
|
19436 |
|
19437 | first();
|
19438 | getToken();
|
19439 |
|
19440 |
|
19441 | if (token == 'strict') {
|
19442 | graph.strict = true;
|
19443 | getToken();
|
19444 | }
|
19445 |
|
19446 |
|
19447 | if (token == 'graph' || token == 'digraph') {
|
19448 | graph.type = token;
|
19449 | getToken();
|
19450 | }
|
19451 |
|
19452 |
|
19453 | if (tokenType == TOKENTYPE.IDENTIFIER) {
|
19454 | graph.id = token;
|
19455 | getToken();
|
19456 | }
|
19457 |
|
19458 |
|
19459 | if (token != '{') {
|
19460 | throw newSyntaxError('Angle bracket { expected');
|
19461 | }
|
19462 | getToken();
|
19463 |
|
19464 |
|
19465 | parseStatements(graph);
|
19466 |
|
19467 |
|
19468 | if (token != '}') {
|
19469 | throw newSyntaxError('Angle bracket } expected');
|
19470 | }
|
19471 | getToken();
|
19472 |
|
19473 |
|
19474 | if (token !== '') {
|
19475 | throw newSyntaxError('End of file expected');
|
19476 | }
|
19477 | getToken();
|
19478 |
|
19479 |
|
19480 | delete graph.node;
|
19481 | delete graph.edge;
|
19482 | delete graph.graph;
|
19483 |
|
19484 | return graph;
|
19485 | }
|
19486 |
|
19487 | |
19488 |
|
19489 |
|
19490 |
|
19491 | function parseStatements (graph) {
|
19492 | while (token !== '' && token != '}') {
|
19493 | parseStatement(graph);
|
19494 | if (token == ';') {
|
19495 | getToken();
|
19496 | }
|
19497 | }
|
19498 | }
|
19499 |
|
19500 | |
19501 |
|
19502 |
|
19503 |
|
19504 |
|
19505 |
|
19506 | function parseStatement(graph) {
|
19507 |
|
19508 | var subgraph = parseSubgraph(graph);
|
19509 | if (subgraph) {
|
19510 |
|
19511 | parseEdge(graph, subgraph);
|
19512 |
|
19513 | return;
|
19514 | }
|
19515 |
|
19516 |
|
19517 | var attr = parseAttributeStatement(graph);
|
19518 | if (attr) {
|
19519 | return;
|
19520 | }
|
19521 |
|
19522 |
|
19523 | if (tokenType != TOKENTYPE.IDENTIFIER) {
|
19524 | throw newSyntaxError('Identifier expected');
|
19525 | }
|
19526 | var id = token;
|
19527 | getToken();
|
19528 |
|
19529 | if (token == '=') {
|
19530 |
|
19531 | getToken();
|
19532 | if (tokenType != TOKENTYPE.IDENTIFIER) {
|
19533 | throw newSyntaxError('Identifier expected');
|
19534 | }
|
19535 | graph[id] = token;
|
19536 | getToken();
|
19537 |
|
19538 | }
|
19539 | else {
|
19540 | parseNodeStatement(graph, id);
|
19541 | }
|
19542 | }
|
19543 |
|
19544 | |
19545 |
|
19546 |
|
19547 |
|
19548 |
|
19549 | function parseSubgraph (graph) {
|
19550 | var subgraph = null;
|
19551 |
|
19552 |
|
19553 | if (token == 'subgraph') {
|
19554 | subgraph = {};
|
19555 | subgraph.type = 'subgraph';
|
19556 | getToken();
|
19557 |
|
19558 |
|
19559 | if (tokenType == TOKENTYPE.IDENTIFIER) {
|
19560 | subgraph.id = token;
|
19561 | getToken();
|
19562 | }
|
19563 | }
|
19564 |
|
19565 |
|
19566 | if (token == '{') {
|
19567 | getToken();
|
19568 |
|
19569 | if (!subgraph) {
|
19570 | subgraph = {};
|
19571 | }
|
19572 | subgraph.parent = graph;
|
19573 | subgraph.node = graph.node;
|
19574 | subgraph.edge = graph.edge;
|
19575 | subgraph.graph = graph.graph;
|
19576 |
|
19577 |
|
19578 | parseStatements(subgraph);
|
19579 |
|
19580 |
|
19581 | if (token != '}') {
|
19582 | throw newSyntaxError('Angle bracket } expected');
|
19583 | }
|
19584 | getToken();
|
19585 |
|
19586 |
|
19587 | delete subgraph.node;
|
19588 | delete subgraph.edge;
|
19589 | delete subgraph.graph;
|
19590 | delete subgraph.parent;
|
19591 |
|
19592 |
|
19593 | if (!graph.subgraphs) {
|
19594 | graph.subgraphs = [];
|
19595 | }
|
19596 | graph.subgraphs.push(subgraph);
|
19597 | }
|
19598 |
|
19599 | return subgraph;
|
19600 | }
|
19601 |
|
19602 | |
19603 |
|
19604 |
|
19605 |
|
19606 |
|
19607 |
|
19608 |
|
19609 |
|
19610 |
|
19611 | function parseAttributeStatement (graph) {
|
19612 |
|
19613 | if (token == 'node') {
|
19614 | getToken();
|
19615 |
|
19616 |
|
19617 | graph.node = parseAttributeList();
|
19618 | return 'node';
|
19619 | }
|
19620 | else if (token == 'edge') {
|
19621 | getToken();
|
19622 |
|
19623 |
|
19624 | graph.edge = parseAttributeList();
|
19625 | return 'edge';
|
19626 | }
|
19627 | else if (token == 'graph') {
|
19628 | getToken();
|
19629 |
|
19630 |
|
19631 | graph.graph = parseAttributeList();
|
19632 | return 'graph';
|
19633 | }
|
19634 |
|
19635 | return null;
|
19636 | }
|
19637 |
|
19638 | |
19639 |
|
19640 |
|
19641 |
|
19642 |
|
19643 | function parseNodeStatement(graph, id) {
|
19644 |
|
19645 | var node = {
|
19646 | id: id
|
19647 | };
|
19648 | var attr = parseAttributeList();
|
19649 | if (attr) {
|
19650 | node.attr = attr;
|
19651 | }
|
19652 | addNode(graph, node);
|
19653 |
|
19654 |
|
19655 | parseEdge(graph, id);
|
19656 | }
|
19657 |
|
19658 | |
19659 |
|
19660 |
|
19661 |
|
19662 |
|
19663 | function parseEdge(graph, from) {
|
19664 | while (token == '->' || token == '--') {
|
19665 | var to;
|
19666 | var type = token;
|
19667 | getToken();
|
19668 |
|
19669 | var subgraph = parseSubgraph(graph);
|
19670 | if (subgraph) {
|
19671 | to = subgraph;
|
19672 | }
|
19673 | else {
|
19674 | if (tokenType != TOKENTYPE.IDENTIFIER) {
|
19675 | throw newSyntaxError('Identifier or subgraph expected');
|
19676 | }
|
19677 | to = token;
|
19678 | addNode(graph, {
|
19679 | id: to
|
19680 | });
|
19681 | getToken();
|
19682 | }
|
19683 |
|
19684 |
|
19685 | var attr = parseAttributeList();
|
19686 |
|
19687 |
|
19688 | var edge = createEdge(graph, from, to, type, attr);
|
19689 | addEdge(graph, edge);
|
19690 |
|
19691 | from = to;
|
19692 | }
|
19693 | }
|
19694 |
|
19695 | |
19696 |
|
19697 |
|
19698 |
|
19699 |
|
19700 | function parseAttributeList() {
|
19701 | var attr = null;
|
19702 |
|
19703 | while (token == '[') {
|
19704 | getToken();
|
19705 | attr = {};
|
19706 | while (token !== '' && token != ']') {
|
19707 | if (tokenType != TOKENTYPE.IDENTIFIER) {
|
19708 | throw newSyntaxError('Attribute name expected');
|
19709 | }
|
19710 | var name = token;
|
19711 |
|
19712 | getToken();
|
19713 | if (token != '=') {
|
19714 | throw newSyntaxError('Equal sign = expected');
|
19715 | }
|
19716 | getToken();
|
19717 |
|
19718 | if (tokenType != TOKENTYPE.IDENTIFIER) {
|
19719 | throw newSyntaxError('Attribute value expected');
|
19720 | }
|
19721 | var value = token;
|
19722 | setValue(attr, name, value);
|
19723 |
|
19724 | getToken();
|
19725 | if (token ==',') {
|
19726 | getToken();
|
19727 | }
|
19728 | }
|
19729 |
|
19730 | if (token != ']') {
|
19731 | throw newSyntaxError('Bracket ] expected');
|
19732 | }
|
19733 | getToken();
|
19734 | }
|
19735 |
|
19736 | return attr;
|
19737 | }
|
19738 |
|
19739 | |
19740 |
|
19741 |
|
19742 |
|
19743 |
|
19744 | function newSyntaxError(message) {
|
19745 | return new SyntaxError(message + ', got "' + chop(token, 30) + '" (char ' + index + ')');
|
19746 | }
|
19747 |
|
19748 | |
19749 |
|
19750 |
|
19751 |
|
19752 |
|
19753 |
|
19754 | function chop (text, maxLength) {
|
19755 | return (text.length <= maxLength) ? text : (text.substr(0, 27) + '...');
|
19756 | }
|
19757 |
|
19758 | |
19759 |
|
19760 |
|
19761 |
|
19762 |
|
19763 |
|
19764 | function forEach2(array1, array2, fn) {
|
19765 | if (array1 instanceof Array) {
|
19766 | array1.forEach(function (elem1) {
|
19767 | if (array2 instanceof Array) {
|
19768 | array2.forEach(function (elem2) {
|
19769 | fn(elem1, elem2);
|
19770 | });
|
19771 | }
|
19772 | else {
|
19773 | fn(elem1, array2);
|
19774 | }
|
19775 | });
|
19776 | }
|
19777 | else {
|
19778 | if (array2 instanceof Array) {
|
19779 | array2.forEach(function (elem2) {
|
19780 | fn(array1, elem2);
|
19781 | });
|
19782 | }
|
19783 | else {
|
19784 | fn(array1, array2);
|
19785 | }
|
19786 | }
|
19787 | }
|
19788 |
|
19789 | |
19790 |
|
19791 |
|
19792 |
|
19793 |
|
19794 |
|
19795 | function DOTToGraph (data) {
|
19796 |
|
19797 | var dotData = parseDOT(data);
|
19798 | var graphData = {
|
19799 | nodes: [],
|
19800 | edges: [],
|
19801 | options: {}
|
19802 | };
|
19803 |
|
19804 |
|
19805 | if (dotData.nodes) {
|
19806 | dotData.nodes.forEach(function (dotNode) {
|
19807 | var graphNode = {
|
19808 | id: dotNode.id,
|
19809 | label: String(dotNode.label || dotNode.id)
|
19810 | };
|
19811 | merge(graphNode, dotNode.attr);
|
19812 | if (graphNode.image) {
|
19813 | graphNode.shape = 'image';
|
19814 | }
|
19815 | graphData.nodes.push(graphNode);
|
19816 | });
|
19817 | }
|
19818 |
|
19819 |
|
19820 | if (dotData.edges) {
|
19821 | |
19822 |
|
19823 |
|
19824 |
|
19825 |
|
19826 | function convertEdge(dotEdge) {
|
19827 | var graphEdge = {
|
19828 | from: dotEdge.from,
|
19829 | to: dotEdge.to
|
19830 | };
|
19831 | merge(graphEdge, dotEdge.attr);
|
19832 | graphEdge.style = (dotEdge.type == '->') ? 'arrow' : 'line';
|
19833 | return graphEdge;
|
19834 | }
|
19835 |
|
19836 | dotData.edges.forEach(function (dotEdge) {
|
19837 | var from, to;
|
19838 | if (dotEdge.from instanceof Object) {
|
19839 | from = dotEdge.from.nodes;
|
19840 | }
|
19841 | else {
|
19842 | from = {
|
19843 | id: dotEdge.from
|
19844 | }
|
19845 | }
|
19846 |
|
19847 | if (dotEdge.to instanceof Object) {
|
19848 | to = dotEdge.to.nodes;
|
19849 | }
|
19850 | else {
|
19851 | to = {
|
19852 | id: dotEdge.to
|
19853 | }
|
19854 | }
|
19855 |
|
19856 | if (dotEdge.from instanceof Object && dotEdge.from.edges) {
|
19857 | dotEdge.from.edges.forEach(function (subEdge) {
|
19858 | var graphEdge = convertEdge(subEdge);
|
19859 | graphData.edges.push(graphEdge);
|
19860 | });
|
19861 | }
|
19862 |
|
19863 | forEach2(from, to, function (from, to) {
|
19864 | var subEdge = createEdge(graphData, from.id, to.id, dotEdge.type, dotEdge.attr);
|
19865 | var graphEdge = convertEdge(subEdge);
|
19866 | graphData.edges.push(graphEdge);
|
19867 | });
|
19868 |
|
19869 | if (dotEdge.to instanceof Object && dotEdge.to.edges) {
|
19870 | dotEdge.to.edges.forEach(function (subEdge) {
|
19871 | var graphEdge = convertEdge(subEdge);
|
19872 | graphData.edges.push(graphEdge);
|
19873 | });
|
19874 | }
|
19875 | });
|
19876 | }
|
19877 |
|
19878 |
|
19879 | if (dotData.attr) {
|
19880 | graphData.options = dotData.attr;
|
19881 | }
|
19882 |
|
19883 | return graphData;
|
19884 | }
|
19885 |
|
19886 |
|
19887 | exports.parseDOT = parseDOT;
|
19888 | exports.DOTToGraph = DOTToGraph;
|
19889 |
|
19890 |
|
19891 | },
|
19892 |
|
19893 | function(module, exports, __webpack_require__) {
|
19894 |
|
19895 |
|
19896 | function parseGephi(gephiJSON, options) {
|
19897 | var edges = [];
|
19898 | var nodes = [];
|
19899 | this.options = {
|
19900 | edges: {
|
19901 | inheritColor: true
|
19902 | },
|
19903 | nodes: {
|
19904 | allowedToMove: false,
|
19905 | parseColor: false
|
19906 | }
|
19907 | };
|
19908 |
|
19909 | if (options !== undefined) {
|
19910 | this.options.nodes['allowedToMove'] = options.allowedToMove | false;
|
19911 | this.options.nodes['parseColor'] = options.parseColor | false;
|
19912 | this.options.edges['inheritColor'] = options.inheritColor | true;
|
19913 | }
|
19914 |
|
19915 | var gEdges = gephiJSON.edges;
|
19916 | var gNodes = gephiJSON.nodes;
|
19917 | for (var i = 0; i < gEdges.length; i++) {
|
19918 | var edge = {};
|
19919 | var gEdge = gEdges[i];
|
19920 | edge['id'] = gEdge.id;
|
19921 | edge['from'] = gEdge.source;
|
19922 | edge['to'] = gEdge.target;
|
19923 | edge['attributes'] = gEdge.attributes;
|
19924 |
|
19925 |
|
19926 | edge['color'] = gEdge.color;
|
19927 | edge['inheritColor'] = edge['color'] !== undefined ? false : this.options.inheritColor;
|
19928 | edges.push(edge);
|
19929 | }
|
19930 |
|
19931 | for (var i = 0; i < gNodes.length; i++) {
|
19932 | var node = {};
|
19933 | var gNode = gNodes[i];
|
19934 | node['id'] = gNode.id;
|
19935 | node['attributes'] = gNode.attributes;
|
19936 | node['x'] = gNode.x;
|
19937 | node['y'] = gNode.y;
|
19938 | node['label'] = gNode.label;
|
19939 | if (this.options.nodes.parseColor == true) {
|
19940 | node['color'] = gNode.color;
|
19941 | }
|
19942 | else {
|
19943 | node['color'] = gNode.color !== undefined ? {background:gNode.color, border:gNode.color} : undefined;
|
19944 | }
|
19945 | node['radius'] = gNode.size;
|
19946 | node['allowedToMoveX'] = this.options.nodes.allowedToMove;
|
19947 | node['allowedToMoveY'] = this.options.nodes.allowedToMove;
|
19948 | nodes.push(node);
|
19949 | }
|
19950 |
|
19951 | return {nodes:nodes, edges:edges};
|
19952 | }
|
19953 |
|
19954 | exports.parseGephi = parseGephi;
|
19955 |
|
19956 | },
|
19957 |
|
19958 | function(module, exports, __webpack_require__) {
|
19959 |
|
19960 |
|
19961 |
|
19962 | module.exports = (typeof window !== 'undefined') && window['moment'] || __webpack_require__(52);
|
19963 |
|
19964 |
|
19965 | },
|
19966 |
|
19967 | function(module, exports, __webpack_require__) {
|
19968 |
|
19969 |
|
19970 |
|
19971 | if (typeof window !== 'undefined') {
|
19972 | module.exports = window['Hammer'] || __webpack_require__(53);
|
19973 | }
|
19974 | else {
|
19975 | module.exports = function () {
|
19976 | throw Error('hammer.js is only available in a browser, not in node.js.');
|
19977 | }
|
19978 | }
|
19979 |
|
19980 |
|
19981 | },
|
19982 |
|
19983 | function(module, exports, __webpack_require__) {
|
19984 |
|
19985 | var Hammer = __webpack_require__(42);
|
19986 |
|
19987 | |
19988 |
|
19989 |
|
19990 |
|
19991 |
|
19992 | exports.fakeGesture = function(element, event) {
|
19993 | var eventType = null;
|
19994 |
|
19995 |
|
19996 |
|
19997 |
|
19998 |
|
19999 | var touches = Hammer.event.getTouchList(event, eventType);
|
20000 | var gesture = Hammer.event.collectEventData(this, eventType, touches, event);
|
20001 |
|
20002 |
|
20003 |
|
20004 | if (isNaN(gesture.center.pageX)) {
|
20005 | gesture.center.pageX = event.pageX;
|
20006 | }
|
20007 | if (isNaN(gesture.center.pageY)) {
|
20008 | gesture.center.pageY = event.pageY;
|
20009 | }
|
20010 |
|
20011 | return gesture;
|
20012 | };
|
20013 |
|
20014 |
|
20015 | },
|
20016 |
|
20017 | function(module, exports, __webpack_require__) {
|
20018 |
|
20019 | var Emitter = __webpack_require__(50);
|
20020 | var Hammer = __webpack_require__(42);
|
20021 | var util = __webpack_require__(1);
|
20022 | var DataSet = __webpack_require__(3);
|
20023 | var DataView = __webpack_require__(4);
|
20024 | var Range = __webpack_require__(15);
|
20025 | var TimeAxis = __webpack_require__(27);
|
20026 | var CurrentTime = __webpack_require__(19);
|
20027 | var CustomTime = __webpack_require__(20);
|
20028 | var ItemSet = __webpack_require__(24);
|
20029 | var Activator = __webpack_require__(49);
|
20030 |
|
20031 | |
20032 |
|
20033 |
|
20034 |
|
20035 |
|
20036 |
|
20037 |
|
20038 | function Core () {}
|
20039 |
|
20040 |
|
20041 | Emitter(Core.prototype);
|
20042 |
|
20043 | |
20044 |
|
20045 |
|
20046 |
|
20047 |
|
20048 |
|
20049 |
|
20050 | Core.prototype._create = function (container) {
|
20051 | this.dom = {};
|
20052 |
|
20053 | this.dom.root = document.createElement('div');
|
20054 | this.dom.background = document.createElement('div');
|
20055 | this.dom.backgroundVertical = document.createElement('div');
|
20056 | this.dom.backgroundHorizontal = document.createElement('div');
|
20057 | this.dom.centerContainer = document.createElement('div');
|
20058 | this.dom.leftContainer = document.createElement('div');
|
20059 | this.dom.rightContainer = document.createElement('div');
|
20060 | this.dom.center = document.createElement('div');
|
20061 | this.dom.left = document.createElement('div');
|
20062 | this.dom.right = document.createElement('div');
|
20063 | this.dom.top = document.createElement('div');
|
20064 | this.dom.bottom = document.createElement('div');
|
20065 | this.dom.shadowTop = document.createElement('div');
|
20066 | this.dom.shadowBottom = document.createElement('div');
|
20067 | this.dom.shadowTopLeft = document.createElement('div');
|
20068 | this.dom.shadowBottomLeft = document.createElement('div');
|
20069 | this.dom.shadowTopRight = document.createElement('div');
|
20070 | this.dom.shadowBottomRight = document.createElement('div');
|
20071 |
|
20072 | this.dom.root.className = 'vis timeline root';
|
20073 | this.dom.background.className = 'vispanel background';
|
20074 | this.dom.backgroundVertical.className = 'vispanel background vertical';
|
20075 | this.dom.backgroundHorizontal.className = 'vispanel background horizontal';
|
20076 | this.dom.centerContainer.className = 'vispanel center';
|
20077 | this.dom.leftContainer.className = 'vispanel left';
|
20078 | this.dom.rightContainer.className = 'vispanel right';
|
20079 | this.dom.top.className = 'vispanel top';
|
20080 | this.dom.bottom.className = 'vispanel bottom';
|
20081 | this.dom.left.className = 'content';
|
20082 | this.dom.center.className = 'content';
|
20083 | this.dom.right.className = 'content';
|
20084 | this.dom.shadowTop.className = 'shadow top';
|
20085 | this.dom.shadowBottom.className = 'shadow bottom';
|
20086 | this.dom.shadowTopLeft.className = 'shadow top';
|
20087 | this.dom.shadowBottomLeft.className = 'shadow bottom';
|
20088 | this.dom.shadowTopRight.className = 'shadow top';
|
20089 | this.dom.shadowBottomRight.className = 'shadow bottom';
|
20090 |
|
20091 | this.dom.root.appendChild(this.dom.background);
|
20092 | this.dom.root.appendChild(this.dom.backgroundVertical);
|
20093 | this.dom.root.appendChild(this.dom.backgroundHorizontal);
|
20094 | this.dom.root.appendChild(this.dom.centerContainer);
|
20095 | this.dom.root.appendChild(this.dom.leftContainer);
|
20096 | this.dom.root.appendChild(this.dom.rightContainer);
|
20097 | this.dom.root.appendChild(this.dom.top);
|
20098 | this.dom.root.appendChild(this.dom.bottom);
|
20099 |
|
20100 | this.dom.centerContainer.appendChild(this.dom.center);
|
20101 | this.dom.leftContainer.appendChild(this.dom.left);
|
20102 | this.dom.rightContainer.appendChild(this.dom.right);
|
20103 |
|
20104 | this.dom.centerContainer.appendChild(this.dom.shadowTop);
|
20105 | this.dom.centerContainer.appendChild(this.dom.shadowBottom);
|
20106 | this.dom.leftContainer.appendChild(this.dom.shadowTopLeft);
|
20107 | this.dom.leftContainer.appendChild(this.dom.shadowBottomLeft);
|
20108 | this.dom.rightContainer.appendChild(this.dom.shadowTopRight);
|
20109 | this.dom.rightContainer.appendChild(this.dom.shadowBottomRight);
|
20110 |
|
20111 | this.on('rangechange', this.redraw.bind(this));
|
20112 | this.on('change', this.redraw.bind(this));
|
20113 | this.on('touch', this._onTouch.bind(this));
|
20114 | this.on('pinch', this._onPinch.bind(this));
|
20115 | this.on('dragstart', this._onDragStart.bind(this));
|
20116 | this.on('drag', this._onDrag.bind(this));
|
20117 |
|
20118 |
|
20119 |
|
20120 | this.hammer = Hammer(this.dom.root, {
|
20121 | preventDefault: true
|
20122 | });
|
20123 | this.listeners = {};
|
20124 |
|
20125 | var me = this;
|
20126 | var events = [
|
20127 | 'touch', 'pinch',
|
20128 | 'tap', 'doubletap', 'hold',
|
20129 | 'dragstart', 'drag', 'dragend',
|
20130 | 'mousewheel', 'DOMMouseScroll'
|
20131 | ];
|
20132 | events.forEach(function (event) {
|
20133 | var listener = function () {
|
20134 | var args = [event].concat(Array.prototype.slice.call(arguments, 0));
|
20135 | if (me.isActive()) {
|
20136 | me.emit.apply(me, args);
|
20137 | }
|
20138 | };
|
20139 | me.hammer.on(event, listener);
|
20140 | me.listeners[event] = listener;
|
20141 | });
|
20142 |
|
20143 |
|
20144 | this.props = {
|
20145 | root: {},
|
20146 | background: {},
|
20147 | centerContainer: {},
|
20148 | leftContainer: {},
|
20149 | rightContainer: {},
|
20150 | center: {},
|
20151 | left: {},
|
20152 | right: {},
|
20153 | top: {},
|
20154 | bottom: {},
|
20155 | border: {},
|
20156 | scrollTop: 0,
|
20157 | scrollTopMin: 0
|
20158 | };
|
20159 | this.touch = {};
|
20160 |
|
20161 |
|
20162 | if (!container) throw new Error('No container provided');
|
20163 | container.appendChild(this.dom.root);
|
20164 | };
|
20165 |
|
20166 | |
20167 |
|
20168 |
|
20169 |
|
20170 |
|
20171 |
|
20172 |
|
20173 |
|
20174 |
|
20175 |
|
20176 |
|
20177 |
|
20178 |
|
20179 |
|
20180 |
|
20181 |
|
20182 |
|
20183 |
|
20184 |
|
20185 |
|
20186 |
|
20187 |
|
20188 |
|
20189 |
|
20190 |
|
20191 | Core.prototype.setOptions = function (options) {
|
20192 | if (options) {
|
20193 |
|
20194 | var fields = ['width', 'height', 'minHeight', 'maxHeight', 'autoResize', 'start', 'end', 'orientation', 'clickToUse', 'dataAttributes'];
|
20195 | util.selectiveExtend(fields, this.options, options);
|
20196 |
|
20197 | if ('clickToUse' in options) {
|
20198 | if (options.clickToUse) {
|
20199 | this.activator = new Activator(this.dom.root);
|
20200 | }
|
20201 | else {
|
20202 | if (this.activator) {
|
20203 | this.activator.destroy();
|
20204 | delete this.activator;
|
20205 | }
|
20206 | }
|
20207 | }
|
20208 |
|
20209 |
|
20210 | this._initAutoResize();
|
20211 | }
|
20212 |
|
20213 |
|
20214 | this.components.forEach(function (component) {
|
20215 | component.setOptions(options);
|
20216 | });
|
20217 |
|
20218 |
|
20219 | if (options && options.order) {
|
20220 | throw new Error('Option order is deprecated. There is no replacement for this feature.');
|
20221 | }
|
20222 |
|
20223 |
|
20224 | this.redraw();
|
20225 | };
|
20226 |
|
20227 | |
20228 |
|
20229 |
|
20230 |
|
20231 | Core.prototype.isActive = function () {
|
20232 | return !this.activator || this.activator.active;
|
20233 | };
|
20234 |
|
20235 | |
20236 |
|
20237 |
|
20238 | Core.prototype.destroy = function () {
|
20239 |
|
20240 | this.clear();
|
20241 |
|
20242 |
|
20243 | this.off();
|
20244 |
|
20245 |
|
20246 | this._stopAutoResize();
|
20247 |
|
20248 |
|
20249 | if (this.dom.root.parentNode) {
|
20250 | this.dom.root.parentNode.removeChild(this.dom.root);
|
20251 | }
|
20252 | this.dom = null;
|
20253 |
|
20254 |
|
20255 | if (this.activator) {
|
20256 | this.activator.destroy();
|
20257 | delete this.activator;
|
20258 | }
|
20259 |
|
20260 |
|
20261 | for (var event in this.listeners) {
|
20262 | if (this.listeners.hasOwnProperty(event)) {
|
20263 | delete this.listeners[event];
|
20264 | }
|
20265 | }
|
20266 | this.listeners = null;
|
20267 | this.hammer = null;
|
20268 |
|
20269 |
|
20270 | this.components.forEach(function (component) {
|
20271 | component.destroy();
|
20272 | });
|
20273 |
|
20274 | this.body = null;
|
20275 | };
|
20276 |
|
20277 |
|
20278 | |
20279 |
|
20280 |
|
20281 |
|
20282 | Core.prototype.setCustomTime = function (time) {
|
20283 | if (!this.customTime) {
|
20284 | throw new Error('Cannot get custom time: Custom time bar is not enabled');
|
20285 | }
|
20286 |
|
20287 | this.customTime.setCustomTime(time);
|
20288 | };
|
20289 |
|
20290 | |
20291 |
|
20292 |
|
20293 |
|
20294 | Core.prototype.getCustomTime = function() {
|
20295 | if (!this.customTime) {
|
20296 | throw new Error('Cannot get custom time: Custom time bar is not enabled');
|
20297 | }
|
20298 |
|
20299 | return this.customTime.getCustomTime();
|
20300 | };
|
20301 |
|
20302 |
|
20303 | |
20304 |
|
20305 |
|
20306 |
|
20307 | Core.prototype.getVisibleItems = function() {
|
20308 | return this.itemSet && this.itemSet.getVisibleItems() || [];
|
20309 | };
|
20310 |
|
20311 |
|
20312 |
|
20313 | |
20314 |
|
20315 |
|
20316 |
|
20317 |
|
20318 |
|
20319 |
|
20320 |
|
20321 |
|
20322 |
|
20323 | Core.prototype.clear = function(what) {
|
20324 |
|
20325 | if (!what || what.items) {
|
20326 | this.setItems(null);
|
20327 | }
|
20328 |
|
20329 |
|
20330 | if (!what || what.groups) {
|
20331 | this.setGroups(null);
|
20332 | }
|
20333 |
|
20334 |
|
20335 | if (!what || what.options) {
|
20336 | this.components.forEach(function (component) {
|
20337 | component.setOptions(component.defaultOptions);
|
20338 | });
|
20339 |
|
20340 | this.setOptions(this.defaultOptions);
|
20341 | }
|
20342 | };
|
20343 |
|
20344 | |
20345 |
|
20346 |
|
20347 |
|
20348 |
|
20349 |
|
20350 |
|
20351 |
|
20352 |
|
20353 | Core.prototype.fit = function(options) {
|
20354 |
|
20355 | var dataRange = this.getItemRange();
|
20356 |
|
20357 |
|
20358 | var start = dataRange.min;
|
20359 | var end = dataRange.max;
|
20360 | if (start != null && end != null) {
|
20361 | var interval = (end.valueOf() - start.valueOf());
|
20362 | if (interval <= 0) {
|
20363 |
|
20364 | interval = 24 * 60 * 60 * 1000;
|
20365 | }
|
20366 | start = new Date(start.valueOf() - interval * 0.05);
|
20367 | end = new Date(end.valueOf() + interval * 0.05);
|
20368 | }
|
20369 |
|
20370 |
|
20371 | if (start === null && end === null) {
|
20372 | return;
|
20373 | }
|
20374 |
|
20375 | var animate = (options && options.animate !== undefined) ? options.animate : true;
|
20376 | this.range.setRange(start, end, animate);
|
20377 | };
|
20378 |
|
20379 | |
20380 |
|
20381 |
|
20382 |
|
20383 |
|
20384 |
|
20385 |
|
20386 |
|
20387 |
|
20388 |
|
20389 |
|
20390 |
|
20391 |
|
20392 |
|
20393 |
|
20394 |
|
20395 |
|
20396 |
|
20397 |
|
20398 | Core.prototype.setWindow = function(start, end, options) {
|
20399 | var animate = (options && options.animate !== undefined) ? options.animate : true;
|
20400 | if (arguments.length == 1) {
|
20401 | var range = arguments[0];
|
20402 | this.range.setRange(range.start, range.end, animate);
|
20403 | }
|
20404 | else {
|
20405 | this.range.setRange(start, end, animate);
|
20406 | }
|
20407 | };
|
20408 |
|
20409 | |
20410 |
|
20411 |
|
20412 |
|
20413 |
|
20414 |
|
20415 |
|
20416 |
|
20417 |
|
20418 |
|
20419 | Core.prototype.moveTo = function(time, options) {
|
20420 | var interval = this.range.end - this.range.start;
|
20421 | var t = util.convert(time, 'Date').valueOf();
|
20422 |
|
20423 | var start = t - interval / 2;
|
20424 | var end = t + interval / 2;
|
20425 | var animate = (options && options.animate !== undefined) ? options.animate : true;
|
20426 |
|
20427 | this.range.setRange(start, end, animate);
|
20428 | };
|
20429 |
|
20430 | |
20431 |
|
20432 |
|
20433 |
|
20434 | Core.prototype.getWindow = function() {
|
20435 | var range = this.range.getRange();
|
20436 | return {
|
20437 | start: new Date(range.start),
|
20438 | end: new Date(range.end)
|
20439 | };
|
20440 | };
|
20441 |
|
20442 | |
20443 |
|
20444 |
|
20445 |
|
20446 | Core.prototype.redraw = function() {
|
20447 | var resized = false,
|
20448 | options = this.options,
|
20449 | props = this.props,
|
20450 | dom = this.dom;
|
20451 |
|
20452 | if (!dom) return;
|
20453 |
|
20454 |
|
20455 | if (options.orientation == 'top') {
|
20456 | util.addClassName(dom.root, 'top');
|
20457 | util.removeClassName(dom.root, 'bottom');
|
20458 | }
|
20459 | else {
|
20460 | util.removeClassName(dom.root, 'top');
|
20461 | util.addClassName(dom.root, 'bottom');
|
20462 | }
|
20463 |
|
20464 |
|
20465 | dom.root.style.maxHeight = util.option.asSize(options.maxHeight, '');
|
20466 | dom.root.style.minHeight = util.option.asSize(options.minHeight, '');
|
20467 | dom.root.style.width = util.option.asSize(options.width, '');
|
20468 |
|
20469 |
|
20470 | props.border.left = (dom.centerContainer.offsetWidth - dom.centerContainer.clientWidth) / 2;
|
20471 | props.border.right = props.border.left;
|
20472 | props.border.top = (dom.centerContainer.offsetHeight - dom.centerContainer.clientHeight) / 2;
|
20473 | props.border.bottom = props.border.top;
|
20474 | var borderRootHeight= dom.root.offsetHeight - dom.root.clientHeight;
|
20475 | var borderRootWidth = dom.root.offsetWidth - dom.root.clientWidth;
|
20476 |
|
20477 |
|
20478 |
|
20479 | if (dom.centerContainer.clientHeight === 0) {
|
20480 | props.border.left = props.border.top;
|
20481 | props.border.right = props.border.left;
|
20482 | }
|
20483 | if (dom.root.clientHeight === 0) {
|
20484 | borderRootWidth = borderRootHeight;
|
20485 | }
|
20486 |
|
20487 |
|
20488 |
|
20489 | props.center.height = dom.center.offsetHeight;
|
20490 | props.left.height = dom.left.offsetHeight;
|
20491 | props.right.height = dom.right.offsetHeight;
|
20492 | props.top.height = dom.top.clientHeight || -props.border.top;
|
20493 | props.bottom.height = dom.bottom.clientHeight || -props.border.bottom;
|
20494 |
|
20495 |
|
20496 |
|
20497 |
|
20498 |
|
20499 | var contentHeight = Math.max(props.left.height, props.center.height, props.right.height);
|
20500 | var autoHeight = props.top.height + contentHeight + props.bottom.height +
|
20501 | borderRootHeight + props.border.top + props.border.bottom;
|
20502 | dom.root.style.height = util.option.asSize(options.height, autoHeight + 'px');
|
20503 |
|
20504 |
|
20505 | props.root.height = dom.root.offsetHeight;
|
20506 | props.background.height = props.root.height - borderRootHeight;
|
20507 | var containerHeight = props.root.height - props.top.height - props.bottom.height -
|
20508 | borderRootHeight;
|
20509 | props.centerContainer.height = containerHeight;
|
20510 | props.leftContainer.height = containerHeight;
|
20511 | props.rightContainer.height = props.leftContainer.height;
|
20512 |
|
20513 |
|
20514 | props.root.width = dom.root.offsetWidth;
|
20515 | props.background.width = props.root.width - borderRootWidth;
|
20516 | props.left.width = dom.leftContainer.clientWidth || -props.border.left;
|
20517 | props.leftContainer.width = props.left.width;
|
20518 | props.right.width = dom.rightContainer.clientWidth || -props.border.right;
|
20519 | props.rightContainer.width = props.right.width;
|
20520 | var centerWidth = props.root.width - props.left.width - props.right.width - borderRootWidth;
|
20521 | props.center.width = centerWidth;
|
20522 | props.centerContainer.width = centerWidth;
|
20523 | props.top.width = centerWidth;
|
20524 | props.bottom.width = centerWidth;
|
20525 |
|
20526 |
|
20527 | dom.background.style.height = props.background.height + 'px';
|
20528 | dom.backgroundVertical.style.height = props.background.height + 'px';
|
20529 | dom.backgroundHorizontal.style.height = props.centerContainer.height + 'px';
|
20530 | dom.centerContainer.style.height = props.centerContainer.height + 'px';
|
20531 | dom.leftContainer.style.height = props.leftContainer.height + 'px';
|
20532 | dom.rightContainer.style.height = props.rightContainer.height + 'px';
|
20533 |
|
20534 | dom.background.style.width = props.background.width + 'px';
|
20535 | dom.backgroundVertical.style.width = props.centerContainer.width + 'px';
|
20536 | dom.backgroundHorizontal.style.width = props.background.width + 'px';
|
20537 | dom.centerContainer.style.width = props.center.width + 'px';
|
20538 | dom.top.style.width = props.top.width + 'px';
|
20539 | dom.bottom.style.width = props.bottom.width + 'px';
|
20540 |
|
20541 |
|
20542 | dom.background.style.left = '0';
|
20543 | dom.background.style.top = '0';
|
20544 | dom.backgroundVertical.style.left = (props.left.width + props.border.left) + 'px';
|
20545 | dom.backgroundVertical.style.top = '0';
|
20546 | dom.backgroundHorizontal.style.left = '0';
|
20547 | dom.backgroundHorizontal.style.top = props.top.height + 'px';
|
20548 | dom.centerContainer.style.left = props.left.width + 'px';
|
20549 | dom.centerContainer.style.top = props.top.height + 'px';
|
20550 | dom.leftContainer.style.left = '0';
|
20551 | dom.leftContainer.style.top = props.top.height + 'px';
|
20552 | dom.rightContainer.style.left = (props.left.width + props.center.width) + 'px';
|
20553 | dom.rightContainer.style.top = props.top.height + 'px';
|
20554 | dom.top.style.left = props.left.width + 'px';
|
20555 | dom.top.style.top = '0';
|
20556 | dom.bottom.style.left = props.left.width + 'px';
|
20557 | dom.bottom.style.top = (props.top.height + props.centerContainer.height) + 'px';
|
20558 |
|
20559 |
|
20560 |
|
20561 | this._updateScrollTop();
|
20562 |
|
20563 |
|
20564 | var offset = this.props.scrollTop;
|
20565 | if (options.orientation == 'bottom') {
|
20566 | offset += Math.max(this.props.centerContainer.height - this.props.center.height -
|
20567 | this.props.border.top - this.props.border.bottom, 0);
|
20568 | }
|
20569 | dom.center.style.left = '0';
|
20570 | dom.center.style.top = offset + 'px';
|
20571 | dom.left.style.left = '0';
|
20572 | dom.left.style.top = offset + 'px';
|
20573 | dom.right.style.left = '0';
|
20574 | dom.right.style.top = offset + 'px';
|
20575 |
|
20576 |
|
20577 | var visibilityTop = this.props.scrollTop == 0 ? 'hidden' : '';
|
20578 | var visibilityBottom = this.props.scrollTop == this.props.scrollTopMin ? 'hidden' : '';
|
20579 | dom.shadowTop.style.visibility = visibilityTop;
|
20580 | dom.shadowBottom.style.visibility = visibilityBottom;
|
20581 | dom.shadowTopLeft.style.visibility = visibilityTop;
|
20582 | dom.shadowBottomLeft.style.visibility = visibilityBottom;
|
20583 | dom.shadowTopRight.style.visibility = visibilityTop;
|
20584 | dom.shadowBottomRight.style.visibility = visibilityBottom;
|
20585 |
|
20586 |
|
20587 | this.components.forEach(function (component) {
|
20588 | resized = component.redraw() || resized;
|
20589 | });
|
20590 | if (resized) {
|
20591 |
|
20592 | this.redraw();
|
20593 | }
|
20594 | };
|
20595 |
|
20596 |
|
20597 | Core.prototype.repaint = function () {
|
20598 | throw new Error('Function repaint is deprecated. Use redraw instead.');
|
20599 | };
|
20600 |
|
20601 | |
20602 |
|
20603 |
|
20604 |
|
20605 |
|
20606 |
|
20607 |
|
20608 | Core.prototype.setCurrentTime = function(time) {
|
20609 | if (!this.currentTime) {
|
20610 | throw new Error('Option showCurrentTime must be true');
|
20611 | }
|
20612 |
|
20613 | this.currentTime.setCurrentTime(time);
|
20614 | };
|
20615 |
|
20616 | |
20617 |
|
20618 |
|
20619 |
|
20620 |
|
20621 | Core.prototype.getCurrentTime = function() {
|
20622 | if (!this.currentTime) {
|
20623 | throw new Error('Option showCurrentTime must be true');
|
20624 | }
|
20625 |
|
20626 | return this.currentTime.getCurrentTime();
|
20627 | };
|
20628 |
|
20629 | |
20630 |
|
20631 |
|
20632 |
|
20633 |
|
20634 |
|
20635 |
|
20636 | Core.prototype._toTime = function(x) {
|
20637 | var conversion = this.range.conversion(this.props.center.width);
|
20638 | return new Date(x / conversion.scale + conversion.offset);
|
20639 | };
|
20640 |
|
20641 |
|
20642 | |
20643 |
|
20644 |
|
20645 |
|
20646 |
|
20647 |
|
20648 |
|
20649 | Core.prototype._toGlobalTime = function(x) {
|
20650 | var conversion = this.range.conversion(this.props.root.width);
|
20651 | return new Date(x / conversion.scale + conversion.offset);
|
20652 | };
|
20653 |
|
20654 | |
20655 |
|
20656 |
|
20657 |
|
20658 |
|
20659 |
|
20660 |
|
20661 |
|
20662 | Core.prototype._toScreen = function(time) {
|
20663 | var conversion = this.range.conversion(this.props.center.width);
|
20664 | return (time.valueOf() - conversion.offset) * conversion.scale;
|
20665 | };
|
20666 |
|
20667 |
|
20668 | |
20669 |
|
20670 |
|
20671 |
|
20672 |
|
20673 |
|
20674 |
|
20675 |
|
20676 |
|
20677 | Core.prototype._toGlobalScreen = function(time) {
|
20678 | var conversion = this.range.conversion(this.props.root.width);
|
20679 | return (time.valueOf() - conversion.offset) * conversion.scale;
|
20680 | };
|
20681 |
|
20682 |
|
20683 | |
20684 |
|
20685 |
|
20686 |
|
20687 | Core.prototype._initAutoResize = function () {
|
20688 | if (this.options.autoResize == true) {
|
20689 | this._startAutoResize();
|
20690 | }
|
20691 | else {
|
20692 | this._stopAutoResize();
|
20693 | }
|
20694 | };
|
20695 |
|
20696 | |
20697 |
|
20698 |
|
20699 |
|
20700 |
|
20701 | Core.prototype._startAutoResize = function () {
|
20702 | var me = this;
|
20703 |
|
20704 | this._stopAutoResize();
|
20705 |
|
20706 | this._onResize = function() {
|
20707 | if (me.options.autoResize != true) {
|
20708 |
|
20709 | me._stopAutoResize();
|
20710 | return;
|
20711 | }
|
20712 |
|
20713 | if (me.dom.root) {
|
20714 |
|
20715 |
|
20716 |
|
20717 |
|
20718 | if ((me.dom.root.offsetWidth != me.props.lastWidth) ||
|
20719 | (me.dom.root.offsetHeight != me.props.lastHeight)) {
|
20720 | me.props.lastWidth = me.dom.root.offsetWidth;
|
20721 | me.props.lastHeight = me.dom.root.offsetHeight;
|
20722 |
|
20723 | me.emit('change');
|
20724 | }
|
20725 | }
|
20726 | };
|
20727 |
|
20728 |
|
20729 | util.addEventListener(window, 'resize', this._onResize);
|
20730 |
|
20731 | this.watchTimer = setInterval(this._onResize, 1000);
|
20732 | };
|
20733 |
|
20734 | |
20735 |
|
20736 |
|
20737 |
|
20738 | Core.prototype._stopAutoResize = function () {
|
20739 | if (this.watchTimer) {
|
20740 | clearInterval(this.watchTimer);
|
20741 | this.watchTimer = undefined;
|
20742 | }
|
20743 |
|
20744 |
|
20745 | util.removeEventListener(window, 'resize', this._onResize);
|
20746 | this._onResize = null;
|
20747 | };
|
20748 |
|
20749 | |
20750 |
|
20751 |
|
20752 |
|
20753 |
|
20754 | Core.prototype._onTouch = function (event) {
|
20755 | this.touch.allowDragging = true;
|
20756 | };
|
20757 |
|
20758 | |
20759 |
|
20760 |
|
20761 |
|
20762 |
|
20763 | Core.prototype._onPinch = function (event) {
|
20764 | this.touch.allowDragging = false;
|
20765 | };
|
20766 |
|
20767 | |
20768 |
|
20769 |
|
20770 |
|
20771 |
|
20772 | Core.prototype._onDragStart = function (event) {
|
20773 | this.touch.initialScrollTop = this.props.scrollTop;
|
20774 | };
|
20775 |
|
20776 | |
20777 |
|
20778 |
|
20779 |
|
20780 |
|
20781 | Core.prototype._onDrag = function (event) {
|
20782 |
|
20783 |
|
20784 | if (!this.touch.allowDragging) return;
|
20785 |
|
20786 | var delta = event.gesture.deltaY;
|
20787 |
|
20788 | var oldScrollTop = this._getScrollTop();
|
20789 | var newScrollTop = this._setScrollTop(this.touch.initialScrollTop + delta);
|
20790 |
|
20791 | if (newScrollTop != oldScrollTop) {
|
20792 | this.redraw();
|
20793 | }
|
20794 | };
|
20795 |
|
20796 | |
20797 |
|
20798 |
|
20799 |
|
20800 |
|
20801 |
|
20802 | Core.prototype._setScrollTop = function (scrollTop) {
|
20803 | this.props.scrollTop = scrollTop;
|
20804 | this._updateScrollTop();
|
20805 | return this.props.scrollTop;
|
20806 | };
|
20807 |
|
20808 | |
20809 |
|
20810 |
|
20811 |
|
20812 |
|
20813 | Core.prototype._updateScrollTop = function () {
|
20814 |
|
20815 | var scrollTopMin = Math.min(this.props.centerContainer.height - this.props.center.height, 0);
|
20816 | if (scrollTopMin != this.props.scrollTopMin) {
|
20817 |
|
20818 |
|
20819 | if (this.options.orientation == 'bottom') {
|
20820 | this.props.scrollTop += (scrollTopMin - this.props.scrollTopMin);
|
20821 | }
|
20822 | this.props.scrollTopMin = scrollTopMin;
|
20823 | }
|
20824 |
|
20825 |
|
20826 | if (this.props.scrollTop > 0) this.props.scrollTop = 0;
|
20827 | if (this.props.scrollTop < scrollTopMin) this.props.scrollTop = scrollTopMin;
|
20828 |
|
20829 | return this.props.scrollTop;
|
20830 | };
|
20831 |
|
20832 | |
20833 |
|
20834 |
|
20835 |
|
20836 |
|
20837 | Core.prototype._getScrollTop = function () {
|
20838 | return this.props.scrollTop;
|
20839 | };
|
20840 |
|
20841 | module.exports = Core;
|
20842 |
|
20843 |
|
20844 | },
|
20845 |
|
20846 | function(module, exports, __webpack_require__) {
|
20847 |
|
20848 |
|
20849 | exports['en'] = {
|
20850 | current: 'current',
|
20851 | time: 'time'
|
20852 | };
|
20853 | exports['en_EN'] = exports['en'];
|
20854 | exports['en_US'] = exports['en'];
|
20855 |
|
20856 |
|
20857 | exports['nl'] = {
|
20858 | custom: 'aangepaste',
|
20859 | time: 'tijd'
|
20860 | };
|
20861 | exports['nl_NL'] = exports['nl'];
|
20862 | exports['nl_BE'] = exports['nl'];
|
20863 |
|
20864 |
|
20865 | },
|
20866 |
|
20867 | function(module, exports, __webpack_require__) {
|
20868 |
|
20869 |
|
20870 | exports['en'] = {
|
20871 | edit: 'Edit',
|
20872 | del: 'Delete selected',
|
20873 | back: 'Back',
|
20874 | addNode: 'Add Node',
|
20875 | addEdge: 'Add Edge',
|
20876 | editNode: 'Edit Node',
|
20877 | editEdge: 'Edit Edge',
|
20878 | addDescription: 'Click in an empty space to place a new node.',
|
20879 | edgeDescription: 'Click on a node and drag the edge to another node to connect them.',
|
20880 | editEdgeDescription: 'Click on the control points and drag them to a node to connect to it.',
|
20881 | createEdgeError: 'Cannot link edges to a cluster.',
|
20882 | deleteClusterError: 'Clusters cannot be deleted.'
|
20883 | };
|
20884 | exports['en_EN'] = exports['en'];
|
20885 | exports['en_US'] = exports['en'];
|
20886 |
|
20887 |
|
20888 | exports['nl'] = {
|
20889 | edit: 'Wijzigen',
|
20890 | del: 'Selectie verwijderen',
|
20891 | back: 'Terug',
|
20892 | addNode: 'Node toevoegen',
|
20893 | addEdge: 'Link toevoegen',
|
20894 | editNode: 'Node wijzigen',
|
20895 | editEdge: 'Link wijzigen',
|
20896 | addDescription: 'Klik op een leeg gebied om een nieuwe node te maken.',
|
20897 | edgeDescription: 'Klik op een node en sleep de link naar een andere node om ze te verbinden.',
|
20898 | editEdgeDescription: 'Klik op de verbindingspunten en sleep ze naar een node om daarmee te verbinden.',
|
20899 | createEdgeError: 'Kan geen link maken naar een cluster.',
|
20900 | deleteClusterError: 'Clusters kunnen niet worden verwijderd.'
|
20901 | };
|
20902 | exports['nl_NL'] = exports['nl'];
|
20903 | exports['nl_BE'] = exports['nl'];
|
20904 |
|
20905 |
|
20906 | },
|
20907 |
|
20908 | function(module, exports, __webpack_require__) {
|
20909 |
|
20910 | |
20911 |
|
20912 |
|
20913 | if (typeof CanvasRenderingContext2D !== 'undefined') {
|
20914 |
|
20915 | |
20916 |
|
20917 |
|
20918 | CanvasRenderingContext2D.prototype.circle = function(x, y, r) {
|
20919 | this.beginPath();
|
20920 | this.arc(x, y, r, 0, 2*Math.PI, false);
|
20921 | };
|
20922 |
|
20923 | |
20924 |
|
20925 |
|
20926 |
|
20927 |
|
20928 |
|
20929 | CanvasRenderingContext2D.prototype.square = function(x, y, r) {
|
20930 | this.beginPath();
|
20931 | this.rect(x - r, y - r, r * 2, r * 2);
|
20932 | };
|
20933 |
|
20934 | |
20935 |
|
20936 |
|
20937 |
|
20938 |
|
20939 |
|
20940 | CanvasRenderingContext2D.prototype.triangle = function(x, y, r) {
|
20941 |
|
20942 | this.beginPath();
|
20943 |
|
20944 | var s = r * 2;
|
20945 | var s2 = s / 2;
|
20946 | var ir = Math.sqrt(3) / 6 * s;
|
20947 | var h = Math.sqrt(s * s - s2 * s2);
|
20948 |
|
20949 | this.moveTo(x, y - (h - ir));
|
20950 | this.lineTo(x + s2, y + ir);
|
20951 | this.lineTo(x - s2, y + ir);
|
20952 | this.lineTo(x, y - (h - ir));
|
20953 | this.closePath();
|
20954 | };
|
20955 |
|
20956 | |
20957 |
|
20958 |
|
20959 |
|
20960 |
|
20961 |
|
20962 | CanvasRenderingContext2D.prototype.triangleDown = function(x, y, r) {
|
20963 |
|
20964 | this.beginPath();
|
20965 |
|
20966 | var s = r * 2;
|
20967 | var s2 = s / 2;
|
20968 | var ir = Math.sqrt(3) / 6 * s;
|
20969 | var h = Math.sqrt(s * s - s2 * s2);
|
20970 |
|
20971 | this.moveTo(x, y + (h - ir));
|
20972 | this.lineTo(x + s2, y - ir);
|
20973 | this.lineTo(x - s2, y - ir);
|
20974 | this.lineTo(x, y + (h - ir));
|
20975 | this.closePath();
|
20976 | };
|
20977 |
|
20978 | |
20979 |
|
20980 |
|
20981 |
|
20982 |
|
20983 |
|
20984 | CanvasRenderingContext2D.prototype.star = function(x, y, r) {
|
20985 |
|
20986 | this.beginPath();
|
20987 |
|
20988 | for (var n = 0; n < 10; n++) {
|
20989 | var radius = (n % 2 === 0) ? r * 1.3 : r * 0.5;
|
20990 | this.lineTo(
|
20991 | x + radius * Math.sin(n * 2 * Math.PI / 10),
|
20992 | y - radius * Math.cos(n * 2 * Math.PI / 10)
|
20993 | );
|
20994 | }
|
20995 |
|
20996 | this.closePath();
|
20997 | };
|
20998 |
|
20999 | |
21000 |
|
21001 |
|
21002 | CanvasRenderingContext2D.prototype.roundRect = function(x, y, w, h, r) {
|
21003 | var r2d = Math.PI/180;
|
21004 | if( w - ( 2 * r ) < 0 ) { r = ( w / 2 ); }
|
21005 | if( h - ( 2 * r ) < 0 ) { r = ( h / 2 ); }
|
21006 | this.beginPath();
|
21007 | this.moveTo(x+r,y);
|
21008 | this.lineTo(x+w-r,y);
|
21009 | this.arc(x+w-r,y+r,r,r2d*270,r2d*360,false);
|
21010 | this.lineTo(x+w,y+h-r);
|
21011 | this.arc(x+w-r,y+h-r,r,0,r2d*90,false);
|
21012 | this.lineTo(x+r,y+h);
|
21013 | this.arc(x+r,y+h-r,r,r2d*90,r2d*180,false);
|
21014 | this.lineTo(x,y+r);
|
21015 | this.arc(x+r,y+r,r,r2d*180,r2d*270,false);
|
21016 | };
|
21017 |
|
21018 | |
21019 |
|
21020 |
|
21021 | CanvasRenderingContext2D.prototype.ellipse = function(x, y, w, h) {
|
21022 | var kappa = .5522848,
|
21023 | ox = (w / 2) * kappa,
|
21024 | oy = (h / 2) * kappa,
|
21025 | xe = x + w,
|
21026 | ye = y + h,
|
21027 | xm = x + w / 2,
|
21028 | ym = y + h / 2;
|
21029 |
|
21030 | this.beginPath();
|
21031 | this.moveTo(x, ym);
|
21032 | this.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y);
|
21033 | this.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
|
21034 | this.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
|
21035 | this.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);
|
21036 | };
|
21037 |
|
21038 |
|
21039 |
|
21040 | |
21041 |
|
21042 |
|
21043 | CanvasRenderingContext2D.prototype.database = function(x, y, w, h) {
|
21044 | var f = 1/3;
|
21045 | var wEllipse = w;
|
21046 | var hEllipse = h * f;
|
21047 |
|
21048 | var kappa = .5522848,
|
21049 | ox = (wEllipse / 2) * kappa,
|
21050 | oy = (hEllipse / 2) * kappa,
|
21051 | xe = x + wEllipse,
|
21052 | ye = y + hEllipse,
|
21053 | xm = x + wEllipse / 2,
|
21054 | ym = y + hEllipse / 2,
|
21055 | ymb = y + (h - hEllipse/2),
|
21056 | yeb = y + h;
|
21057 |
|
21058 | this.beginPath();
|
21059 | this.moveTo(xe, ym);
|
21060 |
|
21061 | this.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
|
21062 | this.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);
|
21063 |
|
21064 | this.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y);
|
21065 | this.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
|
21066 |
|
21067 | this.lineTo(xe, ymb);
|
21068 |
|
21069 | this.bezierCurveTo(xe, ymb + oy, xm + ox, yeb, xm, yeb);
|
21070 | this.bezierCurveTo(xm - ox, yeb, x, ymb + oy, x, ymb);
|
21071 |
|
21072 | this.lineTo(x, ym);
|
21073 | };
|
21074 |
|
21075 |
|
21076 | |
21077 |
|
21078 |
|
21079 | CanvasRenderingContext2D.prototype.arrow = function(x, y, angle, length) {
|
21080 |
|
21081 | var xt = x - length * Math.cos(angle);
|
21082 | var yt = y - length * Math.sin(angle);
|
21083 |
|
21084 |
|
21085 |
|
21086 | var xi = x - length * 0.9 * Math.cos(angle);
|
21087 | var yi = y - length * 0.9 * Math.sin(angle);
|
21088 |
|
21089 |
|
21090 | var xl = xt + length / 3 * Math.cos(angle + 0.5 * Math.PI);
|
21091 | var yl = yt + length / 3 * Math.sin(angle + 0.5 * Math.PI);
|
21092 |
|
21093 |
|
21094 | var xr = xt + length / 3 * Math.cos(angle - 0.5 * Math.PI);
|
21095 | var yr = yt + length / 3 * Math.sin(angle - 0.5 * Math.PI);
|
21096 |
|
21097 | this.beginPath();
|
21098 | this.moveTo(x, y);
|
21099 | this.lineTo(xl, yl);
|
21100 | this.lineTo(xi, yi);
|
21101 | this.lineTo(xr, yr);
|
21102 | this.closePath();
|
21103 | };
|
21104 |
|
21105 | |
21106 |
|
21107 |
|
21108 |
|
21109 |
|
21110 |
|
21111 | CanvasRenderingContext2D.prototype.dashedLine = function(x,y,x2,y2,dashArray){
|
21112 | if (!dashArray) dashArray=[10,5];
|
21113 | if (dashLength==0) dashLength = 0.001;
|
21114 | var dashCount = dashArray.length;
|
21115 | this.moveTo(x, y);
|
21116 | var dx = (x2-x), dy = (y2-y);
|
21117 | var slope = dy/dx;
|
21118 | var distRemaining = Math.sqrt( dx*dx + dy*dy );
|
21119 | var dashIndex=0, draw=true;
|
21120 | while (distRemaining>=0.1){
|
21121 | var dashLength = dashArray[dashIndex++%dashCount];
|
21122 | if (dashLength > distRemaining) dashLength = distRemaining;
|
21123 | var xStep = Math.sqrt( dashLength*dashLength / (1 + slope*slope) );
|
21124 | if (dx<0) xStep = -xStep;
|
21125 | x += xStep;
|
21126 | y += slope*xStep;
|
21127 | this[draw ? 'lineTo' : 'moveTo'](x,y);
|
21128 | distRemaining -= dashLength;
|
21129 | draw = !draw;
|
21130 | }
|
21131 | };
|
21132 |
|
21133 |
|
21134 | }
|
21135 |
|
21136 |
|
21137 | },
|
21138 |
|
21139 | function(module, exports, __webpack_require__) {
|
21140 |
|
21141 | var PhysicsMixin = __webpack_require__(60);
|
21142 | var ClusterMixin = __webpack_require__(54);
|
21143 | var SectorsMixin = __webpack_require__(55);
|
21144 | var SelectionMixin = __webpack_require__(56);
|
21145 | var ManipulationMixin = __webpack_require__(57);
|
21146 | var NavigationMixin = __webpack_require__(58);
|
21147 | var HierarchicalLayoutMixin = __webpack_require__(59);
|
21148 |
|
21149 | |
21150 |
|
21151 |
|
21152 |
|
21153 |
|
21154 |
|
21155 | exports._loadMixin = function (sourceVariable) {
|
21156 | for (var mixinFunction in sourceVariable) {
|
21157 | if (sourceVariable.hasOwnProperty(mixinFunction)) {
|
21158 | this[mixinFunction] = sourceVariable[mixinFunction];
|
21159 | }
|
21160 | }
|
21161 | };
|
21162 |
|
21163 |
|
21164 | |
21165 |
|
21166 |
|
21167 |
|
21168 |
|
21169 |
|
21170 | exports._clearMixin = function (sourceVariable) {
|
21171 | for (var mixinFunction in sourceVariable) {
|
21172 | if (sourceVariable.hasOwnProperty(mixinFunction)) {
|
21173 | this[mixinFunction] = undefined;
|
21174 | }
|
21175 | }
|
21176 | };
|
21177 |
|
21178 |
|
21179 | |
21180 |
|
21181 |
|
21182 |
|
21183 |
|
21184 | exports._loadPhysicsSystem = function () {
|
21185 | this._loadMixin(PhysicsMixin);
|
21186 | this._loadSelectedForceSolver();
|
21187 | if (this.constants.configurePhysics == true) {
|
21188 | this._loadPhysicsConfiguration();
|
21189 | }
|
21190 | };
|
21191 |
|
21192 |
|
21193 | |
21194 |
|
21195 |
|
21196 |
|
21197 |
|
21198 | exports._loadClusterSystem = function () {
|
21199 | this.clusterSession = 0;
|
21200 | this.hubThreshold = 5;
|
21201 | this._loadMixin(ClusterMixin);
|
21202 | };
|
21203 |
|
21204 |
|
21205 | |
21206 |
|
21207 |
|
21208 |
|
21209 |
|
21210 | exports._loadSectorSystem = function () {
|
21211 | this.sectors = {};
|
21212 | this.activeSector = ["default"];
|
21213 | this.sectors["active"] = {};
|
21214 | this.sectors["active"]["default"] = {"nodes": {},
|
21215 | "edges": {},
|
21216 | "nodeIndices": [],
|
21217 | "formationScale": 1.0,
|
21218 | "drawingNode": undefined };
|
21219 | this.sectors["frozen"] = {};
|
21220 | this.sectors["support"] = {"nodes": {},
|
21221 | "edges": {},
|
21222 | "nodeIndices": [],
|
21223 | "formationScale": 1.0,
|
21224 | "drawingNode": undefined };
|
21225 |
|
21226 | this.nodeIndices = this.sectors["active"]["default"]["nodeIndices"];
|
21227 |
|
21228 | this._loadMixin(SectorsMixin);
|
21229 | };
|
21230 |
|
21231 |
|
21232 | |
21233 |
|
21234 |
|
21235 |
|
21236 |
|
21237 | exports._loadSelectionSystem = function () {
|
21238 | this.selectionObj = {nodes: {}, edges: {}};
|
21239 |
|
21240 | this._loadMixin(SelectionMixin);
|
21241 | };
|
21242 |
|
21243 |
|
21244 | |
21245 |
|
21246 |
|
21247 |
|
21248 |
|
21249 | exports._loadManipulationSystem = function () {
|
21250 |
|
21251 | this.blockConnectingEdgeSelection = false;
|
21252 | this.forceAppendSelection = false;
|
21253 |
|
21254 | if (this.constants.dataManipulation.enabled == true) {
|
21255 |
|
21256 | if (this.manipulationDiv === undefined) {
|
21257 | this.manipulationDiv = document.createElement('div');
|
21258 | this.manipulationDiv.className = 'network-manipulationDiv';
|
21259 | this.manipulationDiv.id = 'network-manipulationDiv';
|
21260 | if (this.editMode == true) {
|
21261 | this.manipulationDiv.style.display = "block";
|
21262 | }
|
21263 | else {
|
21264 | this.manipulationDiv.style.display = "none";
|
21265 | }
|
21266 | this.frame.appendChild(this.manipulationDiv);
|
21267 | }
|
21268 |
|
21269 | if (this.editModeDiv === undefined) {
|
21270 | this.editModeDiv = document.createElement('div');
|
21271 | this.editModeDiv.className = 'network-manipulation-editMode';
|
21272 | this.editModeDiv.id = 'network-manipulation-editMode';
|
21273 | if (this.editMode == true) {
|
21274 | this.editModeDiv.style.display = "none";
|
21275 | }
|
21276 | else {
|
21277 | this.editModeDiv.style.display = "block";
|
21278 | }
|
21279 | this.frame.appendChild(this.editModeDiv);
|
21280 | }
|
21281 |
|
21282 | if (this.closeDiv === undefined) {
|
21283 | this.closeDiv = document.createElement('div');
|
21284 | this.closeDiv.className = 'network-manipulation-closeDiv';
|
21285 | this.closeDiv.id = 'network-manipulation-closeDiv';
|
21286 | this.closeDiv.style.display = this.manipulationDiv.style.display;
|
21287 | this.frame.appendChild(this.closeDiv);
|
21288 | }
|
21289 |
|
21290 |
|
21291 | this._loadMixin(ManipulationMixin);
|
21292 |
|
21293 |
|
21294 | this._createManipulatorBar();
|
21295 | }
|
21296 | else {
|
21297 | if (this.manipulationDiv !== undefined) {
|
21298 |
|
21299 | this._createManipulatorBar();
|
21300 |
|
21301 |
|
21302 | this.frame.removeChild(this.manipulationDiv);
|
21303 | this.frame.removeChild(this.editModeDiv);
|
21304 | this.frame.removeChild(this.closeDiv);
|
21305 |
|
21306 | this.manipulationDiv = undefined;
|
21307 | this.editModeDiv = undefined;
|
21308 | this.closeDiv = undefined;
|
21309 |
|
21310 | this._clearMixin(ManipulationMixin);
|
21311 | }
|
21312 | }
|
21313 | };
|
21314 |
|
21315 |
|
21316 | |
21317 |
|
21318 |
|
21319 |
|
21320 |
|
21321 | exports._loadNavigationControls = function () {
|
21322 | this._loadMixin(NavigationMixin);
|
21323 |
|
21324 | this._cleanNavigation();
|
21325 | if (this.constants.navigation.enabled == true) {
|
21326 | this._loadNavigationElements();
|
21327 | }
|
21328 | };
|
21329 |
|
21330 |
|
21331 | |
21332 |
|
21333 |
|
21334 |
|
21335 |
|
21336 | exports._loadHierarchySystem = function () {
|
21337 | this._loadMixin(HierarchicalLayoutMixin);
|
21338 | };
|
21339 |
|
21340 |
|
21341 | },
|
21342 |
|
21343 | function(module, exports, __webpack_require__) {
|
21344 |
|
21345 | var mousetrap = __webpack_require__(51);
|
21346 | var Emitter = __webpack_require__(50);
|
21347 | var Hammer = __webpack_require__(42);
|
21348 | var util = __webpack_require__(1);
|
21349 |
|
21350 | |
21351 |
|
21352 |
|
21353 |
|
21354 |
|
21355 |
|
21356 |
|
21357 |
|
21358 |
|
21359 |
|
21360 | function Activator(container) {
|
21361 | this.active = false;
|
21362 |
|
21363 | this.dom = {
|
21364 | container: container
|
21365 | };
|
21366 |
|
21367 | this.dom.overlay = document.createElement('div');
|
21368 | this.dom.overlay.className = 'overlay';
|
21369 |
|
21370 | this.dom.container.appendChild(this.dom.overlay);
|
21371 |
|
21372 | this.hammer = Hammer(this.dom.overlay, {prevent_default: false});
|
21373 | this.hammer.on('tap', this._onTapOverlay.bind(this));
|
21374 |
|
21375 |
|
21376 | var me = this;
|
21377 | var events = [
|
21378 | 'touch', 'pinch',
|
21379 | 'doubletap', 'hold',
|
21380 | 'dragstart', 'drag', 'dragend',
|
21381 | 'mousewheel', 'DOMMouseScroll'
|
21382 | ];
|
21383 | events.forEach(function (event) {
|
21384 | me.hammer.on(event, function (event) {
|
21385 | event.stopPropagation();
|
21386 | });
|
21387 | });
|
21388 |
|
21389 |
|
21390 | this.windowHammer = Hammer(window, {prevent_default: false});
|
21391 | this.windowHammer.on('tap', function (event) {
|
21392 |
|
21393 | if (!_hasParent(event.target, container)) {
|
21394 | me.deactivate();
|
21395 | }
|
21396 | });
|
21397 |
|
21398 |
|
21399 | this.escListener = this.deactivate.bind(this);
|
21400 | }
|
21401 |
|
21402 |
|
21403 | Emitter(Activator.prototype);
|
21404 |
|
21405 |
|
21406 | Activator.current = null;
|
21407 |
|
21408 | |
21409 |
|
21410 |
|
21411 | Activator.prototype.destroy = function () {
|
21412 | this.deactivate();
|
21413 |
|
21414 |
|
21415 | this.dom.overlay.parentNode.removeChild(this.dom.overlay);
|
21416 |
|
21417 |
|
21418 | this.hammer = null;
|
21419 | this.windowHammer = null;
|
21420 |
|
21421 | };
|
21422 |
|
21423 | |
21424 |
|
21425 |
|
21426 |
|
21427 | Activator.prototype.activate = function () {
|
21428 |
|
21429 | if (Activator.current) {
|
21430 | Activator.current.deactivate();
|
21431 | }
|
21432 | Activator.current = this;
|
21433 |
|
21434 | this.active = true;
|
21435 | this.dom.overlay.style.display = 'none';
|
21436 | util.addClassName(this.dom.container, 'vis-active');
|
21437 |
|
21438 | this.emit('change');
|
21439 | this.emit('activate');
|
21440 |
|
21441 |
|
21442 |
|
21443 | mousetrap.bind('esc', this.escListener);
|
21444 | };
|
21445 |
|
21446 | |
21447 |
|
21448 |
|
21449 |
|
21450 | Activator.prototype.deactivate = function () {
|
21451 | this.active = false;
|
21452 | this.dom.overlay.style.display = '';
|
21453 | util.removeClassName(this.dom.container, 'vis-active');
|
21454 | mousetrap.unbind('esc', this.escListener);
|
21455 |
|
21456 | this.emit('change');
|
21457 | this.emit('deactivate');
|
21458 | };
|
21459 |
|
21460 | |
21461 |
|
21462 |
|
21463 |
|
21464 |
|
21465 | Activator.prototype._onTapOverlay = function (event) {
|
21466 |
|
21467 | this.activate();
|
21468 | event.stopPropagation();
|
21469 | };
|
21470 |
|
21471 | |
21472 |
|
21473 |
|
21474 |
|
21475 |
|
21476 |
|
21477 |
|
21478 |
|
21479 |
|
21480 | function _hasParent(element, parent) {
|
21481 | while (element) {
|
21482 | if (element === parent) {
|
21483 | return true
|
21484 | }
|
21485 | element = element.parentNode;
|
21486 | }
|
21487 | return false;
|
21488 | }
|
21489 |
|
21490 | module.exports = Activator;
|
21491 |
|
21492 |
|
21493 | },
|
21494 |
|
21495 | function(module, exports, __webpack_require__) {
|
21496 |
|
21497 |
|
21498 | |
21499 |
|
21500 |
|
21501 |
|
21502 | module.exports = Emitter;
|
21503 |
|
21504 | |
21505 |
|
21506 |
|
21507 |
|
21508 |
|
21509 |
|
21510 | function Emitter(obj) {
|
21511 | if (obj) return mixin(obj);
|
21512 | };
|
21513 |
|
21514 | |
21515 |
|
21516 |
|
21517 |
|
21518 |
|
21519 |
|
21520 |
|
21521 |
|
21522 | function mixin(obj) {
|
21523 | for (var key in Emitter.prototype) {
|
21524 | obj[key] = Emitter.prototype[key];
|
21525 | }
|
21526 | return obj;
|
21527 | }
|
21528 |
|
21529 | |
21530 |
|
21531 |
|
21532 |
|
21533 |
|
21534 |
|
21535 |
|
21536 |
|
21537 |
|
21538 | Emitter.prototype.on =
|
21539 | Emitter.prototype.addEventListener = function(event, fn){
|
21540 | this._callbacks = this._callbacks || {};
|
21541 | (this._callbacks[event] = this._callbacks[event] || [])
|
21542 | .push(fn);
|
21543 | return this;
|
21544 | };
|
21545 |
|
21546 | |
21547 |
|
21548 |
|
21549 |
|
21550 |
|
21551 |
|
21552 |
|
21553 |
|
21554 |
|
21555 |
|
21556 | Emitter.prototype.once = function(event, fn){
|
21557 | var self = this;
|
21558 | this._callbacks = this._callbacks || {};
|
21559 |
|
21560 | function on() {
|
21561 | self.off(event, on);
|
21562 | fn.apply(this, arguments);
|
21563 | }
|
21564 |
|
21565 | on.fn = fn;
|
21566 | this.on(event, on);
|
21567 | return this;
|
21568 | };
|
21569 |
|
21570 | |
21571 |
|
21572 |
|
21573 |
|
21574 |
|
21575 |
|
21576 |
|
21577 |
|
21578 |
|
21579 |
|
21580 | Emitter.prototype.off =
|
21581 | Emitter.prototype.removeListener =
|
21582 | Emitter.prototype.removeAllListeners =
|
21583 | Emitter.prototype.removeEventListener = function(event, fn){
|
21584 | this._callbacks = this._callbacks || {};
|
21585 |
|
21586 |
|
21587 | if (0 == arguments.length) {
|
21588 | this._callbacks = {};
|
21589 | return this;
|
21590 | }
|
21591 |
|
21592 |
|
21593 | var callbacks = this._callbacks[event];
|
21594 | if (!callbacks) return this;
|
21595 |
|
21596 |
|
21597 | if (1 == arguments.length) {
|
21598 | delete this._callbacks[event];
|
21599 | return this;
|
21600 | }
|
21601 |
|
21602 |
|
21603 | var cb;
|
21604 | for (var i = 0; i < callbacks.length; i++) {
|
21605 | cb = callbacks[i];
|
21606 | if (cb === fn || cb.fn === fn) {
|
21607 | callbacks.splice(i, 1);
|
21608 | break;
|
21609 | }
|
21610 | }
|
21611 | return this;
|
21612 | };
|
21613 |
|
21614 | |
21615 |
|
21616 |
|
21617 |
|
21618 |
|
21619 |
|
21620 |
|
21621 |
|
21622 | Emitter.prototype.emit = function(event){
|
21623 | this._callbacks = this._callbacks || {};
|
21624 | var args = [].slice.call(arguments, 1)
|
21625 | , callbacks = this._callbacks[event];
|
21626 |
|
21627 | if (callbacks) {
|
21628 | callbacks = callbacks.slice(0);
|
21629 | for (var i = 0, len = callbacks.length; i < len; ++i) {
|
21630 | callbacks[i].apply(this, args);
|
21631 | }
|
21632 | }
|
21633 |
|
21634 | return this;
|
21635 | };
|
21636 |
|
21637 | |
21638 |
|
21639 |
|
21640 |
|
21641 |
|
21642 |
|
21643 |
|
21644 |
|
21645 | Emitter.prototype.listeners = function(event){
|
21646 | this._callbacks = this._callbacks || {};
|
21647 | return this._callbacks[event] || [];
|
21648 | };
|
21649 |
|
21650 | |
21651 |
|
21652 |
|
21653 |
|
21654 |
|
21655 |
|
21656 |
|
21657 |
|
21658 | Emitter.prototype.hasListeners = function(event){
|
21659 | return !! this.listeners(event).length;
|
21660 | };
|
21661 |
|
21662 |
|
21663 | },
|
21664 |
|
21665 | function(module, exports, __webpack_require__) {
|
21666 |
|
21667 | |
21668 |
|
21669 |
|
21670 |
|
21671 |
|
21672 |
|
21673 |
|
21674 |
|
21675 |
|
21676 |
|
21677 |
|
21678 |
|
21679 |
|
21680 |
|
21681 |
|
21682 |
|
21683 |
|
21684 |
|
21685 |
|
21686 |
|
21687 |
|
21688 |
|
21689 | |
21690 |
|
21691 |
|
21692 |
|
21693 |
|
21694 |
|
21695 |
|
21696 |
|
21697 |
|
21698 | var _MAP = {
|
21699 | 8: 'backspace',
|
21700 | 9: 'tab',
|
21701 | 13: 'enter',
|
21702 | 16: 'shift',
|
21703 | 17: 'ctrl',
|
21704 | 18: 'alt',
|
21705 | 20: 'capslock',
|
21706 | 27: 'esc',
|
21707 | 32: 'space',
|
21708 | 33: 'pageup',
|
21709 | 34: 'pagedown',
|
21710 | 35: 'end',
|
21711 | 36: 'home',
|
21712 | 37: 'left',
|
21713 | 38: 'up',
|
21714 | 39: 'right',
|
21715 | 40: 'down',
|
21716 | 45: 'ins',
|
21717 | 46: 'del',
|
21718 | 91: 'meta',
|
21719 | 93: 'meta',
|
21720 | 224: 'meta'
|
21721 | },
|
21722 |
|
21723 | |
21724 |
|
21725 |
|
21726 |
|
21727 |
|
21728 |
|
21729 |
|
21730 |
|
21731 | _KEYCODE_MAP = {
|
21732 | 106: '*',
|
21733 | 107: '+',
|
21734 | 109: '-',
|
21735 | 110: '.',
|
21736 | 111 : '/',
|
21737 | 186: ';',
|
21738 | 187: '=',
|
21739 | 188: ',',
|
21740 | 189: '-',
|
21741 | 190: '.',
|
21742 | 191: '/',
|
21743 | 192: '`',
|
21744 | 219: '[',
|
21745 | 220: '\\',
|
21746 | 221: ']',
|
21747 | 222: '\''
|
21748 | },
|
21749 |
|
21750 | |
21751 |
|
21752 |
|
21753 |
|
21754 |
|
21755 |
|
21756 |
|
21757 |
|
21758 |
|
21759 |
|
21760 | _SHIFT_MAP = {
|
21761 | '~': '`',
|
21762 | '!': '1',
|
21763 | '@': '2',
|
21764 | '#': '3',
|
21765 | '$': '4',
|
21766 | '%': '5',
|
21767 | '^': '6',
|
21768 | '&': '7',
|
21769 | '*': '8',
|
21770 | '(': '9',
|
21771 | ')': '0',
|
21772 | '_': '-',
|
21773 | '+': '=',
|
21774 | ':': ';',
|
21775 | '\"': '\'',
|
21776 | '<': ',',
|
21777 | '>': '.',
|
21778 | '?': '/',
|
21779 | '|': '\\'
|
21780 | },
|
21781 |
|
21782 | |
21783 |
|
21784 |
|
21785 |
|
21786 |
|
21787 |
|
21788 | _SPECIAL_ALIASES = {
|
21789 | 'option': 'alt',
|
21790 | 'command': 'meta',
|
21791 | 'return': 'enter',
|
21792 | 'escape': 'esc'
|
21793 | },
|
21794 |
|
21795 | |
21796 |
|
21797 |
|
21798 |
|
21799 |
|
21800 |
|
21801 |
|
21802 | _REVERSE_MAP,
|
21803 |
|
21804 | |
21805 |
|
21806 |
|
21807 |
|
21808 |
|
21809 | _callbacks = {},
|
21810 |
|
21811 | |
21812 |
|
21813 |
|
21814 |
|
21815 |
|
21816 | _direct_map = {},
|
21817 |
|
21818 | |
21819 |
|
21820 |
|
21821 |
|
21822 |
|
21823 |
|
21824 | _sequence_levels = {},
|
21825 |
|
21826 | |
21827 |
|
21828 |
|
21829 |
|
21830 |
|
21831 | _reset_timer,
|
21832 |
|
21833 | |
21834 |
|
21835 |
|
21836 |
|
21837 |
|
21838 | _ignore_next_keyup = false,
|
21839 |
|
21840 | |
21841 |
|
21842 |
|
21843 |
|
21844 |
|
21845 |
|
21846 | _inside_sequence = false;
|
21847 |
|
21848 | |
21849 |
|
21850 |
|
21851 |
|
21852 | for (var i = 1; i < 20; ++i) {
|
21853 | _MAP[111 + i] = 'f' + i;
|
21854 | }
|
21855 |
|
21856 | |
21857 |
|
21858 |
|
21859 | for (i = 0; i <= 9; ++i) {
|
21860 | _MAP[i + 96] = i;
|
21861 | }
|
21862 |
|
21863 | |
21864 |
|
21865 |
|
21866 |
|
21867 |
|
21868 |
|
21869 |
|
21870 |
|
21871 | function _addEvent(object, type, callback) {
|
21872 | if (object.addEventListener) {
|
21873 | return object.addEventListener(type, callback, false);
|
21874 | }
|
21875 |
|
21876 | object.attachEvent('on' + type, callback);
|
21877 | }
|
21878 |
|
21879 | |
21880 |
|
21881 |
|
21882 |
|
21883 |
|
21884 |
|
21885 | function _characterFromEvent(e) {
|
21886 |
|
21887 |
|
21888 | if (e.type == 'keypress') {
|
21889 | return String.fromCharCode(e.which);
|
21890 | }
|
21891 |
|
21892 |
|
21893 | if (_MAP[e.which]) {
|
21894 | return _MAP[e.which];
|
21895 | }
|
21896 |
|
21897 | if (_KEYCODE_MAP[e.which]) {
|
21898 | return _KEYCODE_MAP[e.which];
|
21899 | }
|
21900 |
|
21901 |
|
21902 | return String.fromCharCode(e.which).toLowerCase();
|
21903 | }
|
21904 |
|
21905 | |
21906 |
|
21907 |
|
21908 |
|
21909 |
|
21910 |
|
21911 | function _stop(e) {
|
21912 | var element = e.target || e.srcElement,
|
21913 | tag_name = element.tagName;
|
21914 |
|
21915 |
|
21916 | if ((' ' + element.className + ' ').indexOf(' mousetrap ') > -1) {
|
21917 | return false;
|
21918 | }
|
21919 |
|
21920 |
|
21921 | return tag_name == 'INPUT' || tag_name == 'SELECT' || tag_name == 'TEXTAREA' || (element.contentEditable && element.contentEditable == 'true');
|
21922 | }
|
21923 |
|
21924 | |
21925 |
|
21926 |
|
21927 |
|
21928 |
|
21929 |
|
21930 |
|
21931 | function _modifiersMatch(modifiers1, modifiers2) {
|
21932 | return modifiers1.sort().join(',') === modifiers2.sort().join(',');
|
21933 | }
|
21934 |
|
21935 | |
21936 |
|
21937 |
|
21938 |
|
21939 |
|
21940 |
|
21941 | function _resetSequences(do_not_reset) {
|
21942 | do_not_reset = do_not_reset || {};
|
21943 |
|
21944 | var active_sequences = false,
|
21945 | key;
|
21946 |
|
21947 | for (key in _sequence_levels) {
|
21948 | if (do_not_reset[key]) {
|
21949 | active_sequences = true;
|
21950 | continue;
|
21951 | }
|
21952 | _sequence_levels[key] = 0;
|
21953 | }
|
21954 |
|
21955 | if (!active_sequences) {
|
21956 | _inside_sequence = false;
|
21957 | }
|
21958 | }
|
21959 |
|
21960 | |
21961 |
|
21962 |
|
21963 |
|
21964 |
|
21965 |
|
21966 |
|
21967 |
|
21968 |
|
21969 |
|
21970 |
|
21971 | function _getMatches(character, modifiers, action, remove, combination) {
|
21972 | var i,
|
21973 | callback,
|
21974 | matches = [];
|
21975 |
|
21976 |
|
21977 | if (!_callbacks[character]) {
|
21978 | return [];
|
21979 | }
|
21980 |
|
21981 |
|
21982 | if (action == 'keyup' && _isModifier(character)) {
|
21983 | modifiers = [character];
|
21984 | }
|
21985 |
|
21986 |
|
21987 |
|
21988 | for (i = 0; i < _callbacks[character].length; ++i) {
|
21989 | callback = _callbacks[character][i];
|
21990 |
|
21991 |
|
21992 |
|
21993 | if (callback.seq && _sequence_levels[callback.seq] != callback.level) {
|
21994 | continue;
|
21995 | }
|
21996 |
|
21997 |
|
21998 |
|
21999 | if (action != callback.action) {
|
22000 | continue;
|
22001 | }
|
22002 |
|
22003 |
|
22004 |
|
22005 |
|
22006 | if (action == 'keypress' || _modifiersMatch(modifiers, callback.modifiers)) {
|
22007 |
|
22008 |
|
22009 |
|
22010 | if (remove && callback.combo == combination) {
|
22011 | _callbacks[character].splice(i, 1);
|
22012 | }
|
22013 |
|
22014 | matches.push(callback);
|
22015 | }
|
22016 | }
|
22017 |
|
22018 | return matches;
|
22019 | }
|
22020 |
|
22021 | |
22022 |
|
22023 |
|
22024 |
|
22025 |
|
22026 |
|
22027 | function _eventModifiers(e) {
|
22028 | var modifiers = [];
|
22029 |
|
22030 | if (e.shiftKey) {
|
22031 | modifiers.push('shift');
|
22032 | }
|
22033 |
|
22034 | if (e.altKey) {
|
22035 | modifiers.push('alt');
|
22036 | }
|
22037 |
|
22038 | if (e.ctrlKey) {
|
22039 | modifiers.push('ctrl');
|
22040 | }
|
22041 |
|
22042 | if (e.metaKey) {
|
22043 | modifiers.push('meta');
|
22044 | }
|
22045 |
|
22046 | return modifiers;
|
22047 | }
|
22048 |
|
22049 | |
22050 |
|
22051 |
|
22052 |
|
22053 |
|
22054 |
|
22055 |
|
22056 |
|
22057 |
|
22058 |
|
22059 | function _fireCallback(callback, e) {
|
22060 | if (callback(e) === false) {
|
22061 | if (e.preventDefault) {
|
22062 | e.preventDefault();
|
22063 | }
|
22064 |
|
22065 | if (e.stopPropagation) {
|
22066 | e.stopPropagation();
|
22067 | }
|
22068 |
|
22069 | e.returnValue = false;
|
22070 | e.cancelBubble = true;
|
22071 | }
|
22072 | }
|
22073 |
|
22074 | |
22075 |
|
22076 |
|
22077 |
|
22078 |
|
22079 |
|
22080 |
|
22081 | function _handleCharacter(character, e) {
|
22082 |
|
22083 |
|
22084 | if (_stop(e)) {
|
22085 | return;
|
22086 | }
|
22087 |
|
22088 | var callbacks = _getMatches(character, _eventModifiers(e), e.type),
|
22089 | i,
|
22090 | do_not_reset = {},
|
22091 | processed_sequence_callback = false;
|
22092 |
|
22093 |
|
22094 | for (i = 0; i < callbacks.length; ++i) {
|
22095 |
|
22096 |
|
22097 |
|
22098 |
|
22099 |
|
22100 |
|
22101 | if (callbacks[i].seq) {
|
22102 | processed_sequence_callback = true;
|
22103 |
|
22104 |
|
22105 | do_not_reset[callbacks[i].seq] = 1;
|
22106 | _fireCallback(callbacks[i].callback, e);
|
22107 | continue;
|
22108 | }
|
22109 |
|
22110 |
|
22111 |
|
22112 | if (!processed_sequence_callback && !_inside_sequence) {
|
22113 | _fireCallback(callbacks[i].callback, e);
|
22114 | }
|
22115 | }
|
22116 |
|
22117 |
|
22118 |
|
22119 |
|
22120 | if (e.type == _inside_sequence && !_isModifier(character)) {
|
22121 | _resetSequences(do_not_reset);
|
22122 | }
|
22123 | }
|
22124 |
|
22125 | |
22126 |
|
22127 |
|
22128 |
|
22129 |
|
22130 |
|
22131 | function _handleKey(e) {
|
22132 |
|
22133 |
|
22134 |
|
22135 | e.which = typeof e.which == "number" ? e.which : e.keyCode;
|
22136 |
|
22137 | var character = _characterFromEvent(e);
|
22138 |
|
22139 |
|
22140 | if (!character) {
|
22141 | return;
|
22142 | }
|
22143 |
|
22144 | if (e.type == 'keyup' && _ignore_next_keyup == character) {
|
22145 | _ignore_next_keyup = false;
|
22146 | return;
|
22147 | }
|
22148 |
|
22149 | _handleCharacter(character, e);
|
22150 | }
|
22151 |
|
22152 | |
22153 |
|
22154 |
|
22155 |
|
22156 |
|
22157 |
|
22158 | function _isModifier(key) {
|
22159 | return key == 'shift' || key == 'ctrl' || key == 'alt' || key == 'meta';
|
22160 | }
|
22161 |
|
22162 | |
22163 |
|
22164 |
|
22165 |
|
22166 |
|
22167 |
|
22168 |
|
22169 |
|
22170 | function _resetSequenceTimer() {
|
22171 | clearTimeout(_reset_timer);
|
22172 | _reset_timer = setTimeout(_resetSequences, 1000);
|
22173 | }
|
22174 |
|
22175 | |
22176 |
|
22177 |
|
22178 |
|
22179 |
|
22180 |
|
22181 | function _getReverseMap() {
|
22182 | if (!_REVERSE_MAP) {
|
22183 | _REVERSE_MAP = {};
|
22184 | for (var key in _MAP) {
|
22185 |
|
22186 |
|
22187 |
|
22188 | if (key > 95 && key < 112) {
|
22189 | continue;
|
22190 | }
|
22191 |
|
22192 | if (_MAP.hasOwnProperty(key)) {
|
22193 | _REVERSE_MAP[_MAP[key]] = key;
|
22194 | }
|
22195 | }
|
22196 | }
|
22197 | return _REVERSE_MAP;
|
22198 | }
|
22199 |
|
22200 | |
22201 |
|
22202 |
|
22203 |
|
22204 |
|
22205 |
|
22206 |
|
22207 | function _pickBestAction(key, modifiers, action) {
|
22208 |
|
22209 |
|
22210 |
|
22211 | if (!action) {
|
22212 | action = _getReverseMap()[key] ? 'keydown' : 'keypress';
|
22213 | }
|
22214 |
|
22215 |
|
22216 |
|
22217 | if (action == 'keypress' && modifiers.length) {
|
22218 | action = 'keydown';
|
22219 | }
|
22220 |
|
22221 | return action;
|
22222 | }
|
22223 |
|
22224 | |
22225 |
|
22226 |
|
22227 |
|
22228 |
|
22229 |
|
22230 |
|
22231 |
|
22232 |
|
22233 | function _bindSequence(combo, keys, callback, action) {
|
22234 |
|
22235 |
|
22236 |
|
22237 | _sequence_levels[combo] = 0;
|
22238 |
|
22239 |
|
22240 |
|
22241 | if (!action) {
|
22242 | action = _pickBestAction(keys[0], []);
|
22243 | }
|
22244 |
|
22245 | |
22246 |
|
22247 |
|
22248 |
|
22249 |
|
22250 |
|
22251 |
|
22252 | var _increaseSequence = function(e) {
|
22253 | _inside_sequence = action;
|
22254 | ++_sequence_levels[combo];
|
22255 | _resetSequenceTimer();
|
22256 | },
|
22257 |
|
22258 | |
22259 |
|
22260 |
|
22261 |
|
22262 |
|
22263 |
|
22264 |
|
22265 | _callbackAndReset = function(e) {
|
22266 | _fireCallback(callback, e);
|
22267 |
|
22268 |
|
22269 |
|
22270 |
|
22271 | if (action !== 'keyup') {
|
22272 | _ignore_next_keyup = _characterFromEvent(e);
|
22273 | }
|
22274 |
|
22275 |
|
22276 |
|
22277 | setTimeout(_resetSequences, 10);
|
22278 | },
|
22279 | i;
|
22280 |
|
22281 |
|
22282 |
|
22283 |
|
22284 | for (i = 0; i < keys.length; ++i) {
|
22285 | _bindSingle(keys[i], i < keys.length - 1 ? _increaseSequence : _callbackAndReset, action, combo, i);
|
22286 | }
|
22287 | }
|
22288 |
|
22289 | |
22290 |
|
22291 |
|
22292 |
|
22293 |
|
22294 |
|
22295 |
|
22296 |
|
22297 |
|
22298 |
|
22299 | function _bindSingle(combination, callback, action, sequence_name, level) {
|
22300 |
|
22301 |
|
22302 | combination = combination.replace(/\s+/g, ' ');
|
22303 |
|
22304 | var sequence = combination.split(' '),
|
22305 | i,
|
22306 | key,
|
22307 | keys,
|
22308 | modifiers = [];
|
22309 |
|
22310 |
|
22311 |
|
22312 | if (sequence.length > 1) {
|
22313 | return _bindSequence(combination, sequence, callback, action);
|
22314 | }
|
22315 |
|
22316 |
|
22317 |
|
22318 | keys = combination === '+' ? ['+'] : combination.split('+');
|
22319 |
|
22320 | for (i = 0; i < keys.length; ++i) {
|
22321 | key = keys[i];
|
22322 |
|
22323 |
|
22324 | if (_SPECIAL_ALIASES[key]) {
|
22325 | key = _SPECIAL_ALIASES[key];
|
22326 | }
|
22327 |
|
22328 |
|
22329 |
|
22330 |
|
22331 | if (action && action != 'keypress' && _SHIFT_MAP[key]) {
|
22332 | key = _SHIFT_MAP[key];
|
22333 | modifiers.push('shift');
|
22334 | }
|
22335 |
|
22336 |
|
22337 | if (_isModifier(key)) {
|
22338 | modifiers.push(key);
|
22339 | }
|
22340 | }
|
22341 |
|
22342 |
|
22343 |
|
22344 | action = _pickBestAction(key, modifiers, action);
|
22345 |
|
22346 |
|
22347 |
|
22348 | if (!_callbacks[key]) {
|
22349 | _callbacks[key] = [];
|
22350 | }
|
22351 |
|
22352 |
|
22353 | _getMatches(key, modifiers, action, !sequence_name, combination);
|
22354 |
|
22355 |
|
22356 |
|
22357 |
|
22358 |
|
22359 |
|
22360 |
|
22361 | _callbacks[key][sequence_name ? 'unshift' : 'push']({
|
22362 | callback: callback,
|
22363 | modifiers: modifiers,
|
22364 | action: action,
|
22365 | seq: sequence_name,
|
22366 | level: level,
|
22367 | combo: combination
|
22368 | });
|
22369 | }
|
22370 |
|
22371 | |
22372 |
|
22373 |
|
22374 |
|
22375 |
|
22376 |
|
22377 |
|
22378 |
|
22379 | function _bindMultiple(combinations, callback, action) {
|
22380 | for (var i = 0; i < combinations.length; ++i) {
|
22381 | _bindSingle(combinations[i], callback, action);
|
22382 | }
|
22383 | }
|
22384 |
|
22385 |
|
22386 | _addEvent(document, 'keypress', _handleKey);
|
22387 | _addEvent(document, 'keydown', _handleKey);
|
22388 | _addEvent(document, 'keyup', _handleKey);
|
22389 |
|
22390 | var mousetrap = {
|
22391 |
|
22392 | |
22393 |
|
22394 |
|
22395 |
|
22396 |
|
22397 |
|
22398 |
|
22399 |
|
22400 |
|
22401 |
|
22402 |
|
22403 |
|
22404 |
|
22405 |
|
22406 |
|
22407 | bind: function(keys, callback, action) {
|
22408 | _bindMultiple(keys instanceof Array ? keys : [keys], callback, action);
|
22409 | _direct_map[keys + ':' + action] = callback;
|
22410 | return this;
|
22411 | },
|
22412 |
|
22413 | |
22414 |
|
22415 |
|
22416 |
|
22417 |
|
22418 |
|
22419 |
|
22420 |
|
22421 |
|
22422 |
|
22423 |
|
22424 |
|
22425 |
|
22426 |
|
22427 |
|
22428 |
|
22429 |
|
22430 | unbind: function(keys, action) {
|
22431 | if (_direct_map[keys + ':' + action]) {
|
22432 | delete _direct_map[keys + ':' + action];
|
22433 | this.bind(keys, function() {}, action);
|
22434 | }
|
22435 | return this;
|
22436 | },
|
22437 |
|
22438 | |
22439 |
|
22440 |
|
22441 |
|
22442 |
|
22443 |
|
22444 |
|
22445 | trigger: function(keys, action) {
|
22446 | _direct_map[keys + ':' + action]();
|
22447 | return this;
|
22448 | },
|
22449 |
|
22450 | |
22451 |
|
22452 |
|
22453 |
|
22454 |
|
22455 |
|
22456 |
|
22457 | reset: function() {
|
22458 | _callbacks = {};
|
22459 | _direct_map = {};
|
22460 | return this;
|
22461 | }
|
22462 | };
|
22463 |
|
22464 | module.exports = mousetrap;
|
22465 |
|
22466 |
|
22467 |
|
22468 | },
|
22469 |
|
22470 | function(module, exports, __webpack_require__) {
|
22471 |
|
22472 | var __WEBPACK_AMD_DEFINE_RESULT__;(function(global, module) {
|
22473 |
|
22474 |
|
22475 |
|
22476 |
|
22477 |
|
22478 | (function (undefined) {
|
22479 | |
22480 |
|
22481 |
|
22482 |
|
22483 | var moment,
|
22484 | VERSION = '2.8.3',
|
22485 |
|
22486 | globalScope = typeof global !== 'undefined' ? global : this,
|
22487 | oldGlobalMoment,
|
22488 | round = Math.round,
|
22489 | hasOwnProperty = Object.prototype.hasOwnProperty,
|
22490 | i,
|
22491 |
|
22492 | YEAR = 0,
|
22493 | MONTH = 1,
|
22494 | DATE = 2,
|
22495 | HOUR = 3,
|
22496 | MINUTE = 4,
|
22497 | SECOND = 5,
|
22498 | MILLISECOND = 6,
|
22499 |
|
22500 |
|
22501 | locales = {},
|
22502 |
|
22503 |
|
22504 | momentProperties = [],
|
22505 |
|
22506 |
|
22507 | hasModule = (typeof module !== 'undefined' && module.exports),
|
22508 |
|
22509 |
|
22510 | aspNetJsonRegex = /^\/?Date\((\-?\d+)/i,
|
22511 | aspNetTimeSpanJsonRegex = /(\-)?(?:(\d*)\.)?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?)?/,
|
22512 |
|
22513 |
|
22514 |
|
22515 | isoDurationRegex = /^(-)?P(?:(?:([0-9,.]*)Y)?(?:([0-9,.]*)M)?(?:([0-9,.]*)D)?(?:T(?:([0-9,.]*)H)?(?:([0-9,.]*)M)?(?:([0-9,.]*)S)?)?|([0-9,.]*)W)$/,
|
22516 |
|
22517 |
|
22518 | formattingTokens = /(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Q|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|S{1,4}|X|zz?|ZZ?|.)/g,
|
22519 | localFormattingTokens = /(\[[^\[]*\])|(\\)?(LT|LL?L?L?|l{1,4})/g,
|
22520 |
|
22521 |
|
22522 | parseTokenOneOrTwoDigits = /\d\d?/,
|
22523 | parseTokenOneToThreeDigits = /\d{1,3}/,
|
22524 | parseTokenOneToFourDigits = /\d{1,4}/,
|
22525 | parseTokenOneToSixDigits = /[+\-]?\d{1,6}/,
|
22526 | parseTokenDigits = /\d+/,
|
22527 | parseTokenWord = /[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i,
|
22528 | parseTokenTimezone = /Z|[\+\-]\d\d:?\d\d/gi,
|
22529 | parseTokenT = /T/i,
|
22530 | parseTokenTimestampMs = /[\+\-]?\d+(\.\d{1,3})?/,
|
22531 | parseTokenOrdinal = /\d{1,2}/,
|
22532 |
|
22533 |
|
22534 | parseTokenOneDigit = /\d/,
|
22535 | parseTokenTwoDigits = /\d\d/,
|
22536 | parseTokenThreeDigits = /\d{3}/,
|
22537 | parseTokenFourDigits = /\d{4}/,
|
22538 | parseTokenSixDigits = /[+-]?\d{6}/,
|
22539 | parseTokenSignedNumber = /[+-]?\d+/,
|
22540 |
|
22541 |
|
22542 |
|
22543 | isoRegex = /^\s*(?:[+-]\d{6}|\d{4})-(?:(\d\d-\d\d)|(W\d\d$)|(W\d\d-\d)|(\d\d\d))((T| )(\d\d(:\d\d(:\d\d(\.\d+)?)?)?)?([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?$/,
|
22544 |
|
22545 | isoFormat = 'YYYY-MM-DDTHH:mm:ssZ',
|
22546 |
|
22547 | isoDates = [
|
22548 | ['YYYYYY-MM-DD', /[+-]\d{6}-\d{2}-\d{2}/],
|
22549 | ['YYYY-MM-DD', /\d{4}-\d{2}-\d{2}/],
|
22550 | ['GGGG-[W]WW-E', /\d{4}-W\d{2}-\d/],
|
22551 | ['GGGG-[W]WW', /\d{4}-W\d{2}/],
|
22552 | ['YYYY-DDD', /\d{4}-\d{3}/]
|
22553 | ],
|
22554 |
|
22555 |
|
22556 | isoTimes = [
|
22557 | ['HH:mm:ss.SSSS', /(T| )\d\d:\d\d:\d\d\.\d+/],
|
22558 | ['HH:mm:ss', /(T| )\d\d:\d\d:\d\d/],
|
22559 | ['HH:mm', /(T| )\d\d:\d\d/],
|
22560 | ['HH', /(T| )\d\d/]
|
22561 | ],
|
22562 |
|
22563 |
|
22564 | parseTimezoneChunker = /([\+\-]|\d\d)/gi,
|
22565 |
|
22566 |
|
22567 | proxyGettersAndSetters = 'Date|Hours|Minutes|Seconds|Milliseconds'.split('|'),
|
22568 | unitMillisecondFactors = {
|
22569 | 'Milliseconds' : 1,
|
22570 | 'Seconds' : 1e3,
|
22571 | 'Minutes' : 6e4,
|
22572 | 'Hours' : 36e5,
|
22573 | 'Days' : 864e5,
|
22574 | 'Months' : 2592e6,
|
22575 | 'Years' : 31536e6
|
22576 | },
|
22577 |
|
22578 | unitAliases = {
|
22579 | ms : 'millisecond',
|
22580 | s : 'second',
|
22581 | m : 'minute',
|
22582 | h : 'hour',
|
22583 | d : 'day',
|
22584 | D : 'date',
|
22585 | w : 'week',
|
22586 | W : 'isoWeek',
|
22587 | M : 'month',
|
22588 | Q : 'quarter',
|
22589 | y : 'year',
|
22590 | DDD : 'dayOfYear',
|
22591 | e : 'weekday',
|
22592 | E : 'isoWeekday',
|
22593 | gg: 'weekYear',
|
22594 | GG: 'isoWeekYear'
|
22595 | },
|
22596 |
|
22597 | camelFunctions = {
|
22598 | dayofyear : 'dayOfYear',
|
22599 | isoweekday : 'isoWeekday',
|
22600 | isoweek : 'isoWeek',
|
22601 | weekyear : 'weekYear',
|
22602 | isoweekyear : 'isoWeekYear'
|
22603 | },
|
22604 |
|
22605 |
|
22606 | formatFunctions = {},
|
22607 |
|
22608 |
|
22609 | relativeTimeThresholds = {
|
22610 | s: 45,
|
22611 | m: 45,
|
22612 | h: 22,
|
22613 | d: 26,
|
22614 | M: 11
|
22615 | },
|
22616 |
|
22617 |
|
22618 | ordinalizeTokens = 'DDD w W M D d'.split(' '),
|
22619 | paddedTokens = 'M D H h m s w W'.split(' '),
|
22620 |
|
22621 | formatTokenFunctions = {
|
22622 | M : function () {
|
22623 | return this.month() + 1;
|
22624 | },
|
22625 | MMM : function (format) {
|
22626 | return this.localeData().monthsShort(this, format);
|
22627 | },
|
22628 | MMMM : function (format) {
|
22629 | return this.localeData().months(this, format);
|
22630 | },
|
22631 | D : function () {
|
22632 | return this.date();
|
22633 | },
|
22634 | DDD : function () {
|
22635 | return this.dayOfYear();
|
22636 | },
|
22637 | d : function () {
|
22638 | return this.day();
|
22639 | },
|
22640 | dd : function (format) {
|
22641 | return this.localeData().weekdaysMin(this, format);
|
22642 | },
|
22643 | ddd : function (format) {
|
22644 | return this.localeData().weekdaysShort(this, format);
|
22645 | },
|
22646 | dddd : function (format) {
|
22647 | return this.localeData().weekdays(this, format);
|
22648 | },
|
22649 | w : function () {
|
22650 | return this.week();
|
22651 | },
|
22652 | W : function () {
|
22653 | return this.isoWeek();
|
22654 | },
|
22655 | YY : function () {
|
22656 | return leftZeroFill(this.year() % 100, 2);
|
22657 | },
|
22658 | YYYY : function () {
|
22659 | return leftZeroFill(this.year(), 4);
|
22660 | },
|
22661 | YYYYY : function () {
|
22662 | return leftZeroFill(this.year(), 5);
|
22663 | },
|
22664 | YYYYYY : function () {
|
22665 | var y = this.year(), sign = y >= 0 ? '+' : '-';
|
22666 | return sign + leftZeroFill(Math.abs(y), 6);
|
22667 | },
|
22668 | gg : function () {
|
22669 | return leftZeroFill(this.weekYear() % 100, 2);
|
22670 | },
|
22671 | gggg : function () {
|
22672 | return leftZeroFill(this.weekYear(), 4);
|
22673 | },
|
22674 | ggggg : function () {
|
22675 | return leftZeroFill(this.weekYear(), 5);
|
22676 | },
|
22677 | GG : function () {
|
22678 | return leftZeroFill(this.isoWeekYear() % 100, 2);
|
22679 | },
|
22680 | GGGG : function () {
|
22681 | return leftZeroFill(this.isoWeekYear(), 4);
|
22682 | },
|
22683 | GGGGG : function () {
|
22684 | return leftZeroFill(this.isoWeekYear(), 5);
|
22685 | },
|
22686 | e : function () {
|
22687 | return this.weekday();
|
22688 | },
|
22689 | E : function () {
|
22690 | return this.isoWeekday();
|
22691 | },
|
22692 | a : function () {
|
22693 | return this.localeData().meridiem(this.hours(), this.minutes(), true);
|
22694 | },
|
22695 | A : function () {
|
22696 | return this.localeData().meridiem(this.hours(), this.minutes(), false);
|
22697 | },
|
22698 | H : function () {
|
22699 | return this.hours();
|
22700 | },
|
22701 | h : function () {
|
22702 | return this.hours() % 12 || 12;
|
22703 | },
|
22704 | m : function () {
|
22705 | return this.minutes();
|
22706 | },
|
22707 | s : function () {
|
22708 | return this.seconds();
|
22709 | },
|
22710 | S : function () {
|
22711 | return toInt(this.milliseconds() / 100);
|
22712 | },
|
22713 | SS : function () {
|
22714 | return leftZeroFill(toInt(this.milliseconds() / 10), 2);
|
22715 | },
|
22716 | SSS : function () {
|
22717 | return leftZeroFill(this.milliseconds(), 3);
|
22718 | },
|
22719 | SSSS : function () {
|
22720 | return leftZeroFill(this.milliseconds(), 3);
|
22721 | },
|
22722 | Z : function () {
|
22723 | var a = -this.zone(),
|
22724 | b = '+';
|
22725 | if (a < 0) {
|
22726 | a = -a;
|
22727 | b = '-';
|
22728 | }
|
22729 | return b + leftZeroFill(toInt(a / 60), 2) + ':' + leftZeroFill(toInt(a) % 60, 2);
|
22730 | },
|
22731 | ZZ : function () {
|
22732 | var a = -this.zone(),
|
22733 | b = '+';
|
22734 | if (a < 0) {
|
22735 | a = -a;
|
22736 | b = '-';
|
22737 | }
|
22738 | return b + leftZeroFill(toInt(a / 60), 2) + leftZeroFill(toInt(a) % 60, 2);
|
22739 | },
|
22740 | z : function () {
|
22741 | return this.zoneAbbr();
|
22742 | },
|
22743 | zz : function () {
|
22744 | return this.zoneName();
|
22745 | },
|
22746 | X : function () {
|
22747 | return this.unix();
|
22748 | },
|
22749 | Q : function () {
|
22750 | return this.quarter();
|
22751 | }
|
22752 | },
|
22753 |
|
22754 | deprecations = {},
|
22755 |
|
22756 | lists = ['months', 'monthsShort', 'weekdays', 'weekdaysShort', 'weekdaysMin'];
|
22757 |
|
22758 |
|
22759 |
|
22760 | function dfl(a, b, c) {
|
22761 | switch (arguments.length) {
|
22762 | case 2: return a != null ? a : b;
|
22763 | case 3: return a != null ? a : b != null ? b : c;
|
22764 | default: throw new Error('Implement me');
|
22765 | }
|
22766 | }
|
22767 |
|
22768 | function hasOwnProp(a, b) {
|
22769 | return hasOwnProperty.call(a, b);
|
22770 | }
|
22771 |
|
22772 | function defaultParsingFlags() {
|
22773 |
|
22774 |
|
22775 | return {
|
22776 | empty : false,
|
22777 | unusedTokens : [],
|
22778 | unusedInput : [],
|
22779 | overflow : -2,
|
22780 | charsLeftOver : 0,
|
22781 | nullInput : false,
|
22782 | invalidMonth : null,
|
22783 | invalidFormat : false,
|
22784 | userInvalidated : false,
|
22785 | iso: false
|
22786 | };
|
22787 | }
|
22788 |
|
22789 | function printMsg(msg) {
|
22790 | if (moment.suppressDeprecationWarnings === false &&
|
22791 | typeof console !== 'undefined' && console.warn) {
|
22792 | console.warn('Deprecation warning: ' + msg);
|
22793 | }
|
22794 | }
|
22795 |
|
22796 | function deprecate(msg, fn) {
|
22797 | var firstTime = true;
|
22798 | return extend(function () {
|
22799 | if (firstTime) {
|
22800 | printMsg(msg);
|
22801 | firstTime = false;
|
22802 | }
|
22803 | return fn.apply(this, arguments);
|
22804 | }, fn);
|
22805 | }
|
22806 |
|
22807 | function deprecateSimple(name, msg) {
|
22808 | if (!deprecations[name]) {
|
22809 | printMsg(msg);
|
22810 | deprecations[name] = true;
|
22811 | }
|
22812 | }
|
22813 |
|
22814 | function padToken(func, count) {
|
22815 | return function (a) {
|
22816 | return leftZeroFill(func.call(this, a), count);
|
22817 | };
|
22818 | }
|
22819 | function ordinalizeToken(func, period) {
|
22820 | return function (a) {
|
22821 | return this.localeData().ordinal(func.call(this, a), period);
|
22822 | };
|
22823 | }
|
22824 |
|
22825 | while (ordinalizeTokens.length) {
|
22826 | i = ordinalizeTokens.pop();
|
22827 | formatTokenFunctions[i + 'o'] = ordinalizeToken(formatTokenFunctions[i], i);
|
22828 | }
|
22829 | while (paddedTokens.length) {
|
22830 | i = paddedTokens.pop();
|
22831 | formatTokenFunctions[i + i] = padToken(formatTokenFunctions[i], 2);
|
22832 | }
|
22833 | formatTokenFunctions.DDDD = padToken(formatTokenFunctions.DDD, 3);
|
22834 |
|
22835 |
|
22836 | |
22837 |
|
22838 |
|
22839 |
|
22840 | function Locale() {
|
22841 | }
|
22842 |
|
22843 |
|
22844 | function Moment(config, skipOverflow) {
|
22845 | if (skipOverflow !== false) {
|
22846 | checkOverflow(config);
|
22847 | }
|
22848 | copyConfig(this, config);
|
22849 | this._d = new Date(+config._d);
|
22850 | }
|
22851 |
|
22852 |
|
22853 | function Duration(duration) {
|
22854 | var normalizedInput = normalizeObjectUnits(duration),
|
22855 | years = normalizedInput.year || 0,
|
22856 | quarters = normalizedInput.quarter || 0,
|
22857 | months = normalizedInput.month || 0,
|
22858 | weeks = normalizedInput.week || 0,
|
22859 | days = normalizedInput.day || 0,
|
22860 | hours = normalizedInput.hour || 0,
|
22861 | minutes = normalizedInput.minute || 0,
|
22862 | seconds = normalizedInput.second || 0,
|
22863 | milliseconds = normalizedInput.millisecond || 0;
|
22864 |
|
22865 |
|
22866 | this._milliseconds = +milliseconds +
|
22867 | seconds * 1e3 +
|
22868 | minutes * 6e4 +
|
22869 | hours * 36e5;
|
22870 |
|
22871 |
|
22872 | this._days = +days +
|
22873 | weeks * 7;
|
22874 |
|
22875 |
|
22876 |
|
22877 | this._months = +months +
|
22878 | quarters * 3 +
|
22879 | years * 12;
|
22880 |
|
22881 | this._data = {};
|
22882 |
|
22883 | this._locale = moment.localeData();
|
22884 |
|
22885 | this._bubble();
|
22886 | }
|
22887 |
|
22888 | |
22889 |
|
22890 |
|
22891 |
|
22892 |
|
22893 | function extend(a, b) {
|
22894 | for (var i in b) {
|
22895 | if (hasOwnProp(b, i)) {
|
22896 | a[i] = b[i];
|
22897 | }
|
22898 | }
|
22899 |
|
22900 | if (hasOwnProp(b, 'toString')) {
|
22901 | a.toString = b.toString;
|
22902 | }
|
22903 |
|
22904 | if (hasOwnProp(b, 'valueOf')) {
|
22905 | a.valueOf = b.valueOf;
|
22906 | }
|
22907 |
|
22908 | return a;
|
22909 | }
|
22910 |
|
22911 | function copyConfig(to, from) {
|
22912 | var i, prop, val;
|
22913 |
|
22914 | if (typeof from._isAMomentObject !== 'undefined') {
|
22915 | to._isAMomentObject = from._isAMomentObject;
|
22916 | }
|
22917 | if (typeof from._i !== 'undefined') {
|
22918 | to._i = from._i;
|
22919 | }
|
22920 | if (typeof from._f !== 'undefined') {
|
22921 | to._f = from._f;
|
22922 | }
|
22923 | if (typeof from._l !== 'undefined') {
|
22924 | to._l = from._l;
|
22925 | }
|
22926 | if (typeof from._strict !== 'undefined') {
|
22927 | to._strict = from._strict;
|
22928 | }
|
22929 | if (typeof from._tzm !== 'undefined') {
|
22930 | to._tzm = from._tzm;
|
22931 | }
|
22932 | if (typeof from._isUTC !== 'undefined') {
|
22933 | to._isUTC = from._isUTC;
|
22934 | }
|
22935 | if (typeof from._offset !== 'undefined') {
|
22936 | to._offset = from._offset;
|
22937 | }
|
22938 | if (typeof from._pf !== 'undefined') {
|
22939 | to._pf = from._pf;
|
22940 | }
|
22941 | if (typeof from._locale !== 'undefined') {
|
22942 | to._locale = from._locale;
|
22943 | }
|
22944 |
|
22945 | if (momentProperties.length > 0) {
|
22946 | for (i in momentProperties) {
|
22947 | prop = momentProperties[i];
|
22948 | val = from[prop];
|
22949 | if (typeof val !== 'undefined') {
|
22950 | to[prop] = val;
|
22951 | }
|
22952 | }
|
22953 | }
|
22954 |
|
22955 | return to;
|
22956 | }
|
22957 |
|
22958 | function absRound(number) {
|
22959 | if (number < 0) {
|
22960 | return Math.ceil(number);
|
22961 | } else {
|
22962 | return Math.floor(number);
|
22963 | }
|
22964 | }
|
22965 |
|
22966 |
|
22967 |
|
22968 | function leftZeroFill(number, targetLength, forceSign) {
|
22969 | var output = '' + Math.abs(number),
|
22970 | sign = number >= 0;
|
22971 |
|
22972 | while (output.length < targetLength) {
|
22973 | output = '0' + output;
|
22974 | }
|
22975 | return (sign ? (forceSign ? '+' : '') : '-') + output;
|
22976 | }
|
22977 |
|
22978 | function positiveMomentsDifference(base, other) {
|
22979 | var res = {milliseconds: 0, months: 0};
|
22980 |
|
22981 | res.months = other.month() - base.month() +
|
22982 | (other.year() - base.year()) * 12;
|
22983 | if (base.clone().add(res.months, 'M').isAfter(other)) {
|
22984 | --res.months;
|
22985 | }
|
22986 |
|
22987 | res.milliseconds = +other - +(base.clone().add(res.months, 'M'));
|
22988 |
|
22989 | return res;
|
22990 | }
|
22991 |
|
22992 | function momentsDifference(base, other) {
|
22993 | var res;
|
22994 | other = makeAs(other, base);
|
22995 | if (base.isBefore(other)) {
|
22996 | res = positiveMomentsDifference(base, other);
|
22997 | } else {
|
22998 | res = positiveMomentsDifference(other, base);
|
22999 | res.milliseconds = -res.milliseconds;
|
23000 | res.months = -res.months;
|
23001 | }
|
23002 |
|
23003 | return res;
|
23004 | }
|
23005 |
|
23006 |
|
23007 | function createAdder(direction, name) {
|
23008 | return function (val, period) {
|
23009 | var dur, tmp;
|
23010 |
|
23011 | if (period !== null && !isNaN(+period)) {
|
23012 | deprecateSimple(name, 'moment().' + name + '(period, number) is deprecated. Please use moment().' + name + '(number, period).');
|
23013 | tmp = val; val = period; period = tmp;
|
23014 | }
|
23015 |
|
23016 | val = typeof val === 'string' ? +val : val;
|
23017 | dur = moment.duration(val, period);
|
23018 | addOrSubtractDurationFromMoment(this, dur, direction);
|
23019 | return this;
|
23020 | };
|
23021 | }
|
23022 |
|
23023 | function addOrSubtractDurationFromMoment(mom, duration, isAdding, updateOffset) {
|
23024 | var milliseconds = duration._milliseconds,
|
23025 | days = duration._days,
|
23026 | months = duration._months;
|
23027 | updateOffset = updateOffset == null ? true : updateOffset;
|
23028 |
|
23029 | if (milliseconds) {
|
23030 | mom._d.setTime(+mom._d + milliseconds * isAdding);
|
23031 | }
|
23032 | if (days) {
|
23033 | rawSetter(mom, 'Date', rawGetter(mom, 'Date') + days * isAdding);
|
23034 | }
|
23035 | if (months) {
|
23036 | rawMonthSetter(mom, rawGetter(mom, 'Month') + months * isAdding);
|
23037 | }
|
23038 | if (updateOffset) {
|
23039 | moment.updateOffset(mom, days || months);
|
23040 | }
|
23041 | }
|
23042 |
|
23043 |
|
23044 | function isArray(input) {
|
23045 | return Object.prototype.toString.call(input) === '[object Array]';
|
23046 | }
|
23047 |
|
23048 | function isDate(input) {
|
23049 | return Object.prototype.toString.call(input) === '[object Date]' ||
|
23050 | input instanceof Date;
|
23051 | }
|
23052 |
|
23053 |
|
23054 | function compareArrays(array1, array2, dontConvert) {
|
23055 | var len = Math.min(array1.length, array2.length),
|
23056 | lengthDiff = Math.abs(array1.length - array2.length),
|
23057 | diffs = 0,
|
23058 | i;
|
23059 | for (i = 0; i < len; i++) {
|
23060 | if ((dontConvert && array1[i] !== array2[i]) ||
|
23061 | (!dontConvert && toInt(array1[i]) !== toInt(array2[i]))) {
|
23062 | diffs++;
|
23063 | }
|
23064 | }
|
23065 | return diffs + lengthDiff;
|
23066 | }
|
23067 |
|
23068 | function normalizeUnits(units) {
|
23069 | if (units) {
|
23070 | var lowered = units.toLowerCase().replace(/(.)s$/, '$1');
|
23071 | units = unitAliases[units] || camelFunctions[lowered] || lowered;
|
23072 | }
|
23073 | return units;
|
23074 | }
|
23075 |
|
23076 | function normalizeObjectUnits(inputObject) {
|
23077 | var normalizedInput = {},
|
23078 | normalizedProp,
|
23079 | prop;
|
23080 |
|
23081 | for (prop in inputObject) {
|
23082 | if (hasOwnProp(inputObject, prop)) {
|
23083 | normalizedProp = normalizeUnits(prop);
|
23084 | if (normalizedProp) {
|
23085 | normalizedInput[normalizedProp] = inputObject[prop];
|
23086 | }
|
23087 | }
|
23088 | }
|
23089 |
|
23090 | return normalizedInput;
|
23091 | }
|
23092 |
|
23093 | function makeList(field) {
|
23094 | var count, setter;
|
23095 |
|
23096 | if (field.indexOf('week') === 0) {
|
23097 | count = 7;
|
23098 | setter = 'day';
|
23099 | }
|
23100 | else if (field.indexOf('month') === 0) {
|
23101 | count = 12;
|
23102 | setter = 'month';
|
23103 | }
|
23104 | else {
|
23105 | return;
|
23106 | }
|
23107 |
|
23108 | moment[field] = function (format, index) {
|
23109 | var i, getter,
|
23110 | method = moment._locale[field],
|
23111 | results = [];
|
23112 |
|
23113 | if (typeof format === 'number') {
|
23114 | index = format;
|
23115 | format = undefined;
|
23116 | }
|
23117 |
|
23118 | getter = function (i) {
|
23119 | var m = moment().utc().set(setter, i);
|
23120 | return method.call(moment._locale, m, format || '');
|
23121 | };
|
23122 |
|
23123 | if (index != null) {
|
23124 | return getter(index);
|
23125 | }
|
23126 | else {
|
23127 | for (i = 0; i < count; i++) {
|
23128 | results.push(getter(i));
|
23129 | }
|
23130 | return results;
|
23131 | }
|
23132 | };
|
23133 | }
|
23134 |
|
23135 | function toInt(argumentForCoercion) {
|
23136 | var coercedNumber = +argumentForCoercion,
|
23137 | value = 0;
|
23138 |
|
23139 | if (coercedNumber !== 0 && isFinite(coercedNumber)) {
|
23140 | if (coercedNumber >= 0) {
|
23141 | value = Math.floor(coercedNumber);
|
23142 | } else {
|
23143 | value = Math.ceil(coercedNumber);
|
23144 | }
|
23145 | }
|
23146 |
|
23147 | return value;
|
23148 | }
|
23149 |
|
23150 | function daysInMonth(year, month) {
|
23151 | return new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
|
23152 | }
|
23153 |
|
23154 | function weeksInYear(year, dow, doy) {
|
23155 | return weekOfYear(moment([year, 11, 31 + dow - doy]), dow, doy).week;
|
23156 | }
|
23157 |
|
23158 | function daysInYear(year) {
|
23159 | return isLeapYear(year) ? 366 : 365;
|
23160 | }
|
23161 |
|
23162 | function isLeapYear(year) {
|
23163 | return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
|
23164 | }
|
23165 |
|
23166 | function checkOverflow(m) {
|
23167 | var overflow;
|
23168 | if (m._a && m._pf.overflow === -2) {
|
23169 | overflow =
|
23170 | m._a[MONTH] < 0 || m._a[MONTH] > 11 ? MONTH :
|
23171 | m._a[DATE] < 1 || m._a[DATE] > daysInMonth(m._a[YEAR], m._a[MONTH]) ? DATE :
|
23172 | m._a[HOUR] < 0 || m._a[HOUR] > 23 ? HOUR :
|
23173 | m._a[MINUTE] < 0 || m._a[MINUTE] > 59 ? MINUTE :
|
23174 | m._a[SECOND] < 0 || m._a[SECOND] > 59 ? SECOND :
|
23175 | m._a[MILLISECOND] < 0 || m._a[MILLISECOND] > 999 ? MILLISECOND :
|
23176 | -1;
|
23177 |
|
23178 | if (m._pf._overflowDayOfYear && (overflow < YEAR || overflow > DATE)) {
|
23179 | overflow = DATE;
|
23180 | }
|
23181 |
|
23182 | m._pf.overflow = overflow;
|
23183 | }
|
23184 | }
|
23185 |
|
23186 | function isValid(m) {
|
23187 | if (m._isValid == null) {
|
23188 | m._isValid = !isNaN(m._d.getTime()) &&
|
23189 | m._pf.overflow < 0 &&
|
23190 | !m._pf.empty &&
|
23191 | !m._pf.invalidMonth &&
|
23192 | !m._pf.nullInput &&
|
23193 | !m._pf.invalidFormat &&
|
23194 | !m._pf.userInvalidated;
|
23195 |
|
23196 | if (m._strict) {
|
23197 | m._isValid = m._isValid &&
|
23198 | m._pf.charsLeftOver === 0 &&
|
23199 | m._pf.unusedTokens.length === 0;
|
23200 | }
|
23201 | }
|
23202 | return m._isValid;
|
23203 | }
|
23204 |
|
23205 | function normalizeLocale(key) {
|
23206 | return key ? key.toLowerCase().replace('_', '-') : key;
|
23207 | }
|
23208 |
|
23209 |
|
23210 |
|
23211 |
|
23212 | function chooseLocale(names) {
|
23213 | var i = 0, j, next, locale, split;
|
23214 |
|
23215 | while (i < names.length) {
|
23216 | split = normalizeLocale(names[i]).split('-');
|
23217 | j = split.length;
|
23218 | next = normalizeLocale(names[i + 1]);
|
23219 | next = next ? next.split('-') : null;
|
23220 | while (j > 0) {
|
23221 | locale = loadLocale(split.slice(0, j).join('-'));
|
23222 | if (locale) {
|
23223 | return locale;
|
23224 | }
|
23225 | if (next && next.length >= j && compareArrays(split, next, true) >= j - 1) {
|
23226 |
|
23227 | break;
|
23228 | }
|
23229 | j--;
|
23230 | }
|
23231 | i++;
|
23232 | }
|
23233 | return null;
|
23234 | }
|
23235 |
|
23236 | function loadLocale(name) {
|
23237 | var oldLocale = null;
|
23238 | if (!locales[name] && hasModule) {
|
23239 | try {
|
23240 | oldLocale = moment.locale();
|
23241 | !(function webpackMissingModule() { var e = new Error("Cannot find module \"./locale\""); e.code = 'MODULE_NOT_FOUND'; throw e; }());
|
23242 |
|
23243 | moment.locale(oldLocale);
|
23244 | } catch (e) { }
|
23245 | }
|
23246 | return locales[name];
|
23247 | }
|
23248 |
|
23249 |
|
23250 | function makeAs(input, model) {
|
23251 | return model._isUTC ? moment(input).zone(model._offset || 0) :
|
23252 | moment(input).local();
|
23253 | }
|
23254 |
|
23255 | |
23256 |
|
23257 |
|
23258 |
|
23259 |
|
23260 | extend(Locale.prototype, {
|
23261 |
|
23262 | set : function (config) {
|
23263 | var prop, i;
|
23264 | for (i in config) {
|
23265 | prop = config[i];
|
23266 | if (typeof prop === 'function') {
|
23267 | this[i] = prop;
|
23268 | } else {
|
23269 | this['_' + i] = prop;
|
23270 | }
|
23271 | }
|
23272 | },
|
23273 |
|
23274 | _months : 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_'),
|
23275 | months : function (m) {
|
23276 | return this._months[m.month()];
|
23277 | },
|
23278 |
|
23279 | _monthsShort : 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_'),
|
23280 | monthsShort : function (m) {
|
23281 | return this._monthsShort[m.month()];
|
23282 | },
|
23283 |
|
23284 | monthsParse : function (monthName) {
|
23285 | var i, mom, regex;
|
23286 |
|
23287 | if (!this._monthsParse) {
|
23288 | this._monthsParse = [];
|
23289 | }
|
23290 |
|
23291 | for (i = 0; i < 12; i++) {
|
23292 |
|
23293 | if (!this._monthsParse[i]) {
|
23294 | mom = moment.utc([2000, i]);
|
23295 | regex = '^' + this.months(mom, '') + '|^' + this.monthsShort(mom, '');
|
23296 | this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i');
|
23297 | }
|
23298 |
|
23299 | if (this._monthsParse[i].test(monthName)) {
|
23300 | return i;
|
23301 | }
|
23302 | }
|
23303 | },
|
23304 |
|
23305 | _weekdays : 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'),
|
23306 | weekdays : function (m) {
|
23307 | return this._weekdays[m.day()];
|
23308 | },
|
23309 |
|
23310 | _weekdaysShort : 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'),
|
23311 | weekdaysShort : function (m) {
|
23312 | return this._weekdaysShort[m.day()];
|
23313 | },
|
23314 |
|
23315 | _weekdaysMin : 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_'),
|
23316 | weekdaysMin : function (m) {
|
23317 | return this._weekdaysMin[m.day()];
|
23318 | },
|
23319 |
|
23320 | weekdaysParse : function (weekdayName) {
|
23321 | var i, mom, regex;
|
23322 |
|
23323 | if (!this._weekdaysParse) {
|
23324 | this._weekdaysParse = [];
|
23325 | }
|
23326 |
|
23327 | for (i = 0; i < 7; i++) {
|
23328 |
|
23329 | if (!this._weekdaysParse[i]) {
|
23330 | mom = moment([2000, 1]).day(i);
|
23331 | regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysShort(mom, '') + '|^' + this.weekdaysMin(mom, '');
|
23332 | this._weekdaysParse[i] = new RegExp(regex.replace('.', ''), 'i');
|
23333 | }
|
23334 |
|
23335 | if (this._weekdaysParse[i].test(weekdayName)) {
|
23336 | return i;
|
23337 | }
|
23338 | }
|
23339 | },
|
23340 |
|
23341 | _longDateFormat : {
|
23342 | LT : 'h:mm A',
|
23343 | L : 'MM/DD/YYYY',
|
23344 | LL : 'MMMM D, YYYY',
|
23345 | LLL : 'MMMM D, YYYY LT',
|
23346 | LLLL : 'dddd, MMMM D, YYYY LT'
|
23347 | },
|
23348 | longDateFormat : function (key) {
|
23349 | var output = this._longDateFormat[key];
|
23350 | if (!output && this._longDateFormat[key.toUpperCase()]) {
|
23351 | output = this._longDateFormat[key.toUpperCase()].replace(/MMMM|MM|DD|dddd/g, function (val) {
|
23352 | return val.slice(1);
|
23353 | });
|
23354 | this._longDateFormat[key] = output;
|
23355 | }
|
23356 | return output;
|
23357 | },
|
23358 |
|
23359 | isPM : function (input) {
|
23360 |
|
23361 |
|
23362 | return ((input + '').toLowerCase().charAt(0) === 'p');
|
23363 | },
|
23364 |
|
23365 | _meridiemParse : /[ap]\.?m?\.?/i,
|
23366 | meridiem : function (hours, minutes, isLower) {
|
23367 | if (hours > 11) {
|
23368 | return isLower ? 'pm' : 'PM';
|
23369 | } else {
|
23370 | return isLower ? 'am' : 'AM';
|
23371 | }
|
23372 | },
|
23373 |
|
23374 | _calendar : {
|
23375 | sameDay : '[Today at] LT',
|
23376 | nextDay : '[Tomorrow at] LT',
|
23377 | nextWeek : 'dddd [at] LT',
|
23378 | lastDay : '[Yesterday at] LT',
|
23379 | lastWeek : '[Last] dddd [at] LT',
|
23380 | sameElse : 'L'
|
23381 | },
|
23382 | calendar : function (key, mom) {
|
23383 | var output = this._calendar[key];
|
23384 | return typeof output === 'function' ? output.apply(mom) : output;
|
23385 | },
|
23386 |
|
23387 | _relativeTime : {
|
23388 | future : 'in %s',
|
23389 | past : '%s ago',
|
23390 | s : 'a few seconds',
|
23391 | m : 'a minute',
|
23392 | mm : '%d minutes',
|
23393 | h : 'an hour',
|
23394 | hh : '%d hours',
|
23395 | d : 'a day',
|
23396 | dd : '%d days',
|
23397 | M : 'a month',
|
23398 | MM : '%d months',
|
23399 | y : 'a year',
|
23400 | yy : '%d years'
|
23401 | },
|
23402 |
|
23403 | relativeTime : function (number, withoutSuffix, string, isFuture) {
|
23404 | var output = this._relativeTime[string];
|
23405 | return (typeof output === 'function') ?
|
23406 | output(number, withoutSuffix, string, isFuture) :
|
23407 | output.replace(/%d/i, number);
|
23408 | },
|
23409 |
|
23410 | pastFuture : function (diff, output) {
|
23411 | var format = this._relativeTime[diff > 0 ? 'future' : 'past'];
|
23412 | return typeof format === 'function' ? format(output) : format.replace(/%s/i, output);
|
23413 | },
|
23414 |
|
23415 | ordinal : function (number) {
|
23416 | return this._ordinal.replace('%d', number);
|
23417 | },
|
23418 | _ordinal : '%d',
|
23419 |
|
23420 | preparse : function (string) {
|
23421 | return string;
|
23422 | },
|
23423 |
|
23424 | postformat : function (string) {
|
23425 | return string;
|
23426 | },
|
23427 |
|
23428 | week : function (mom) {
|
23429 | return weekOfYear(mom, this._week.dow, this._week.doy).week;
|
23430 | },
|
23431 |
|
23432 | _week : {
|
23433 | dow : 0,
|
23434 | doy : 6
|
23435 | },
|
23436 |
|
23437 | _invalidDate: 'Invalid date',
|
23438 | invalidDate: function () {
|
23439 | return this._invalidDate;
|
23440 | }
|
23441 | });
|
23442 |
|
23443 | |
23444 |
|
23445 |
|
23446 |
|
23447 |
|
23448 | function removeFormattingTokens(input) {
|
23449 | if (input.match(/\[[\s\S]/)) {
|
23450 | return input.replace(/^\[|\]$/g, '');
|
23451 | }
|
23452 | return input.replace(/\\/g, '');
|
23453 | }
|
23454 |
|
23455 | function makeFormatFunction(format) {
|
23456 | var array = format.match(formattingTokens), i, length;
|
23457 |
|
23458 | for (i = 0, length = array.length; i < length; i++) {
|
23459 | if (formatTokenFunctions[array[i]]) {
|
23460 | array[i] = formatTokenFunctions[array[i]];
|
23461 | } else {
|
23462 | array[i] = removeFormattingTokens(array[i]);
|
23463 | }
|
23464 | }
|
23465 |
|
23466 | return function (mom) {
|
23467 | var output = '';
|
23468 | for (i = 0; i < length; i++) {
|
23469 | output += array[i] instanceof Function ? array[i].call(mom, format) : array[i];
|
23470 | }
|
23471 | return output;
|
23472 | };
|
23473 | }
|
23474 |
|
23475 |
|
23476 | function formatMoment(m, format) {
|
23477 | if (!m.isValid()) {
|
23478 | return m.localeData().invalidDate();
|
23479 | }
|
23480 |
|
23481 | format = expandFormat(format, m.localeData());
|
23482 |
|
23483 | if (!formatFunctions[format]) {
|
23484 | formatFunctions[format] = makeFormatFunction(format);
|
23485 | }
|
23486 |
|
23487 | return formatFunctions[format](m);
|
23488 | }
|
23489 |
|
23490 | function expandFormat(format, locale) {
|
23491 | var i = 5;
|
23492 |
|
23493 | function replaceLongDateFormatTokens(input) {
|
23494 | return locale.longDateFormat(input) || input;
|
23495 | }
|
23496 |
|
23497 | localFormattingTokens.lastIndex = 0;
|
23498 | while (i >= 0 && localFormattingTokens.test(format)) {
|
23499 | format = format.replace(localFormattingTokens, replaceLongDateFormatTokens);
|
23500 | localFormattingTokens.lastIndex = 0;
|
23501 | i -= 1;
|
23502 | }
|
23503 |
|
23504 | return format;
|
23505 | }
|
23506 |
|
23507 |
|
23508 | |
23509 |
|
23510 |
|
23511 |
|
23512 |
|
23513 |
|
23514 | function getParseRegexForToken(token, config) {
|
23515 | var a, strict = config._strict;
|
23516 | switch (token) {
|
23517 | case 'Q':
|
23518 | return parseTokenOneDigit;
|
23519 | case 'DDDD':
|
23520 | return parseTokenThreeDigits;
|
23521 | case 'YYYY':
|
23522 | case 'GGGG':
|
23523 | case 'gggg':
|
23524 | return strict ? parseTokenFourDigits : parseTokenOneToFourDigits;
|
23525 | case 'Y':
|
23526 | case 'G':
|
23527 | case 'g':
|
23528 | return parseTokenSignedNumber;
|
23529 | case 'YYYYYY':
|
23530 | case 'YYYYY':
|
23531 | case 'GGGGG':
|
23532 | case 'ggggg':
|
23533 | return strict ? parseTokenSixDigits : parseTokenOneToSixDigits;
|
23534 | case 'S':
|
23535 | if (strict) {
|
23536 | return parseTokenOneDigit;
|
23537 | }
|
23538 |
|
23539 | case 'SS':
|
23540 | if (strict) {
|
23541 | return parseTokenTwoDigits;
|
23542 | }
|
23543 |
|
23544 | case 'SSS':
|
23545 | if (strict) {
|
23546 | return parseTokenThreeDigits;
|
23547 | }
|
23548 |
|
23549 | case 'DDD':
|
23550 | return parseTokenOneToThreeDigits;
|
23551 | case 'MMM':
|
23552 | case 'MMMM':
|
23553 | case 'dd':
|
23554 | case 'ddd':
|
23555 | case 'dddd':
|
23556 | return parseTokenWord;
|
23557 | case 'a':
|
23558 | case 'A':
|
23559 | return config._locale._meridiemParse;
|
23560 | case 'X':
|
23561 | return parseTokenTimestampMs;
|
23562 | case 'Z':
|
23563 | case 'ZZ':
|
23564 | return parseTokenTimezone;
|
23565 | case 'T':
|
23566 | return parseTokenT;
|
23567 | case 'SSSS':
|
23568 | return parseTokenDigits;
|
23569 | case 'MM':
|
23570 | case 'DD':
|
23571 | case 'YY':
|
23572 | case 'GG':
|
23573 | case 'gg':
|
23574 | case 'HH':
|
23575 | case 'hh':
|
23576 | case 'mm':
|
23577 | case 'ss':
|
23578 | case 'ww':
|
23579 | case 'WW':
|
23580 | return strict ? parseTokenTwoDigits : parseTokenOneOrTwoDigits;
|
23581 | case 'M':
|
23582 | case 'D':
|
23583 | case 'd':
|
23584 | case 'H':
|
23585 | case 'h':
|
23586 | case 'm':
|
23587 | case 's':
|
23588 | case 'w':
|
23589 | case 'W':
|
23590 | case 'e':
|
23591 | case 'E':
|
23592 | return parseTokenOneOrTwoDigits;
|
23593 | case 'Do':
|
23594 | return parseTokenOrdinal;
|
23595 | default :
|
23596 | a = new RegExp(regexpEscape(unescapeFormat(token.replace('\\', '')), 'i'));
|
23597 | return a;
|
23598 | }
|
23599 | }
|
23600 |
|
23601 | function timezoneMinutesFromString(string) {
|
23602 | string = string || '';
|
23603 | var possibleTzMatches = (string.match(parseTokenTimezone) || []),
|
23604 | tzChunk = possibleTzMatches[possibleTzMatches.length - 1] || [],
|
23605 | parts = (tzChunk + '').match(parseTimezoneChunker) || ['-', 0, 0],
|
23606 | minutes = +(parts[1] * 60) + toInt(parts[2]);
|
23607 |
|
23608 | return parts[0] === '+' ? -minutes : minutes;
|
23609 | }
|
23610 |
|
23611 |
|
23612 | function addTimeToArrayFromToken(token, input, config) {
|
23613 | var a, datePartArray = config._a;
|
23614 |
|
23615 | switch (token) {
|
23616 |
|
23617 | case 'Q':
|
23618 | if (input != null) {
|
23619 | datePartArray[MONTH] = (toInt(input) - 1) * 3;
|
23620 | }
|
23621 | break;
|
23622 |
|
23623 | case 'M' :
|
23624 | case 'MM' :
|
23625 | if (input != null) {
|
23626 | datePartArray[MONTH] = toInt(input) - 1;
|
23627 | }
|
23628 | break;
|
23629 | case 'MMM' :
|
23630 | case 'MMMM' :
|
23631 | a = config._locale.monthsParse(input);
|
23632 |
|
23633 | if (a != null) {
|
23634 | datePartArray[MONTH] = a;
|
23635 | } else {
|
23636 | config._pf.invalidMonth = input;
|
23637 | }
|
23638 | break;
|
23639 |
|
23640 | case 'D' :
|
23641 | case 'DD' :
|
23642 | if (input != null) {
|
23643 | datePartArray[DATE] = toInt(input);
|
23644 | }
|
23645 | break;
|
23646 | case 'Do' :
|
23647 | if (input != null) {
|
23648 | datePartArray[DATE] = toInt(parseInt(input, 10));
|
23649 | }
|
23650 | break;
|
23651 |
|
23652 | case 'DDD' :
|
23653 | case 'DDDD' :
|
23654 | if (input != null) {
|
23655 | config._dayOfYear = toInt(input);
|
23656 | }
|
23657 |
|
23658 | break;
|
23659 |
|
23660 | case 'YY' :
|
23661 | datePartArray[YEAR] = moment.parseTwoDigitYear(input);
|
23662 | break;
|
23663 | case 'YYYY' :
|
23664 | case 'YYYYY' :
|
23665 | case 'YYYYYY' :
|
23666 | datePartArray[YEAR] = toInt(input);
|
23667 | break;
|
23668 |
|
23669 | case 'a' :
|
23670 | case 'A' :
|
23671 | config._isPm = config._locale.isPM(input);
|
23672 | break;
|
23673 |
|
23674 | case 'H' :
|
23675 | case 'HH' :
|
23676 | case 'h' :
|
23677 | case 'hh' :
|
23678 | datePartArray[HOUR] = toInt(input);
|
23679 | break;
|
23680 |
|
23681 | case 'm' :
|
23682 | case 'mm' :
|
23683 | datePartArray[MINUTE] = toInt(input);
|
23684 | break;
|
23685 |
|
23686 | case 's' :
|
23687 | case 'ss' :
|
23688 | datePartArray[SECOND] = toInt(input);
|
23689 | break;
|
23690 |
|
23691 | case 'S' :
|
23692 | case 'SS' :
|
23693 | case 'SSS' :
|
23694 | case 'SSSS' :
|
23695 | datePartArray[MILLISECOND] = toInt(('0.' + input) * 1000);
|
23696 | break;
|
23697 |
|
23698 | case 'X':
|
23699 | config._d = new Date(parseFloat(input) * 1000);
|
23700 | break;
|
23701 |
|
23702 | case 'Z' :
|
23703 | case 'ZZ' :
|
23704 | config._useUTC = true;
|
23705 | config._tzm = timezoneMinutesFromString(input);
|
23706 | break;
|
23707 |
|
23708 | case 'dd':
|
23709 | case 'ddd':
|
23710 | case 'dddd':
|
23711 | a = config._locale.weekdaysParse(input);
|
23712 |
|
23713 | if (a != null) {
|
23714 | config._w = config._w || {};
|
23715 | config._w['d'] = a;
|
23716 | } else {
|
23717 | config._pf.invalidWeekday = input;
|
23718 | }
|
23719 | break;
|
23720 |
|
23721 | case 'w':
|
23722 | case 'ww':
|
23723 | case 'W':
|
23724 | case 'WW':
|
23725 | case 'd':
|
23726 | case 'e':
|
23727 | case 'E':
|
23728 | token = token.substr(0, 1);
|
23729 |
|
23730 | case 'gggg':
|
23731 | case 'GGGG':
|
23732 | case 'GGGGG':
|
23733 | token = token.substr(0, 2);
|
23734 | if (input) {
|
23735 | config._w = config._w || {};
|
23736 | config._w[token] = toInt(input);
|
23737 | }
|
23738 | break;
|
23739 | case 'gg':
|
23740 | case 'GG':
|
23741 | config._w = config._w || {};
|
23742 | config._w[token] = moment.parseTwoDigitYear(input);
|
23743 | }
|
23744 | }
|
23745 |
|
23746 | function dayOfYearFromWeekInfo(config) {
|
23747 | var w, weekYear, week, weekday, dow, doy, temp;
|
23748 |
|
23749 | w = config._w;
|
23750 | if (w.GG != null || w.W != null || w.E != null) {
|
23751 | dow = 1;
|
23752 | doy = 4;
|
23753 |
|
23754 |
|
23755 |
|
23756 |
|
23757 |
|
23758 | weekYear = dfl(w.GG, config._a[YEAR], weekOfYear(moment(), 1, 4).year);
|
23759 | week = dfl(w.W, 1);
|
23760 | weekday = dfl(w.E, 1);
|
23761 | } else {
|
23762 | dow = config._locale._week.dow;
|
23763 | doy = config._locale._week.doy;
|
23764 |
|
23765 | weekYear = dfl(w.gg, config._a[YEAR], weekOfYear(moment(), dow, doy).year);
|
23766 | week = dfl(w.w, 1);
|
23767 |
|
23768 | if (w.d != null) {
|
23769 |
|
23770 | weekday = w.d;
|
23771 | if (weekday < dow) {
|
23772 | ++week;
|
23773 | }
|
23774 | } else if (w.e != null) {
|
23775 |
|
23776 | weekday = w.e + dow;
|
23777 | } else {
|
23778 |
|
23779 | weekday = dow;
|
23780 | }
|
23781 | }
|
23782 | temp = dayOfYearFromWeeks(weekYear, week, weekday, doy, dow);
|
23783 |
|
23784 | config._a[YEAR] = temp.year;
|
23785 | config._dayOfYear = temp.dayOfYear;
|
23786 | }
|
23787 |
|
23788 |
|
23789 |
|
23790 |
|
23791 |
|
23792 | function dateFromConfig(config) {
|
23793 | var i, date, input = [], currentDate, yearToUse;
|
23794 |
|
23795 | if (config._d) {
|
23796 | return;
|
23797 | }
|
23798 |
|
23799 | currentDate = currentDateArray(config);
|
23800 |
|
23801 |
|
23802 | if (config._w && config._a[DATE] == null && config._a[MONTH] == null) {
|
23803 | dayOfYearFromWeekInfo(config);
|
23804 | }
|
23805 |
|
23806 |
|
23807 | if (config._dayOfYear) {
|
23808 | yearToUse = dfl(config._a[YEAR], currentDate[YEAR]);
|
23809 |
|
23810 | if (config._dayOfYear > daysInYear(yearToUse)) {
|
23811 | config._pf._overflowDayOfYear = true;
|
23812 | }
|
23813 |
|
23814 | date = makeUTCDate(yearToUse, 0, config._dayOfYear);
|
23815 | config._a[MONTH] = date.getUTCMonth();
|
23816 | config._a[DATE] = date.getUTCDate();
|
23817 | }
|
23818 |
|
23819 |
|
23820 |
|
23821 |
|
23822 |
|
23823 |
|
23824 | for (i = 0; i < 3 && config._a[i] == null; ++i) {
|
23825 | config._a[i] = input[i] = currentDate[i];
|
23826 | }
|
23827 |
|
23828 |
|
23829 | for (; i < 7; i++) {
|
23830 | config._a[i] = input[i] = (config._a[i] == null) ? (i === 2 ? 1 : 0) : config._a[i];
|
23831 | }
|
23832 |
|
23833 | config._d = (config._useUTC ? makeUTCDate : makeDate).apply(null, input);
|
23834 |
|
23835 |
|
23836 | if (config._tzm != null) {
|
23837 | config._d.setUTCMinutes(config._d.getUTCMinutes() + config._tzm);
|
23838 | }
|
23839 | }
|
23840 |
|
23841 | function dateFromObject(config) {
|
23842 | var normalizedInput;
|
23843 |
|
23844 | if (config._d) {
|
23845 | return;
|
23846 | }
|
23847 |
|
23848 | normalizedInput = normalizeObjectUnits(config._i);
|
23849 | config._a = [
|
23850 | normalizedInput.year,
|
23851 | normalizedInput.month,
|
23852 | normalizedInput.day,
|
23853 | normalizedInput.hour,
|
23854 | normalizedInput.minute,
|
23855 | normalizedInput.second,
|
23856 | normalizedInput.millisecond
|
23857 | ];
|
23858 |
|
23859 | dateFromConfig(config);
|
23860 | }
|
23861 |
|
23862 | function currentDateArray(config) {
|
23863 | var now = new Date();
|
23864 | if (config._useUTC) {
|
23865 | return [
|
23866 | now.getUTCFullYear(),
|
23867 | now.getUTCMonth(),
|
23868 | now.getUTCDate()
|
23869 | ];
|
23870 | } else {
|
23871 | return [now.getFullYear(), now.getMonth(), now.getDate()];
|
23872 | }
|
23873 | }
|
23874 |
|
23875 |
|
23876 | function makeDateFromStringAndFormat(config) {
|
23877 | if (config._f === moment.ISO_8601) {
|
23878 | parseISO(config);
|
23879 | return;
|
23880 | }
|
23881 |
|
23882 | config._a = [];
|
23883 | config._pf.empty = true;
|
23884 |
|
23885 |
|
23886 | var string = '' + config._i,
|
23887 | i, parsedInput, tokens, token, skipped,
|
23888 | stringLength = string.length,
|
23889 | totalParsedInputLength = 0;
|
23890 |
|
23891 | tokens = expandFormat(config._f, config._locale).match(formattingTokens) || [];
|
23892 |
|
23893 | for (i = 0; i < tokens.length; i++) {
|
23894 | token = tokens[i];
|
23895 | parsedInput = (string.match(getParseRegexForToken(token, config)) || [])[0];
|
23896 | if (parsedInput) {
|
23897 | skipped = string.substr(0, string.indexOf(parsedInput));
|
23898 | if (skipped.length > 0) {
|
23899 | config._pf.unusedInput.push(skipped);
|
23900 | }
|
23901 | string = string.slice(string.indexOf(parsedInput) + parsedInput.length);
|
23902 | totalParsedInputLength += parsedInput.length;
|
23903 | }
|
23904 |
|
23905 | if (formatTokenFunctions[token]) {
|
23906 | if (parsedInput) {
|
23907 | config._pf.empty = false;
|
23908 | }
|
23909 | else {
|
23910 | config._pf.unusedTokens.push(token);
|
23911 | }
|
23912 | addTimeToArrayFromToken(token, parsedInput, config);
|
23913 | }
|
23914 | else if (config._strict && !parsedInput) {
|
23915 | config._pf.unusedTokens.push(token);
|
23916 | }
|
23917 | }
|
23918 |
|
23919 |
|
23920 | config._pf.charsLeftOver = stringLength - totalParsedInputLength;
|
23921 | if (string.length > 0) {
|
23922 | config._pf.unusedInput.push(string);
|
23923 | }
|
23924 |
|
23925 |
|
23926 | if (config._isPm && config._a[HOUR] < 12) {
|
23927 | config._a[HOUR] += 12;
|
23928 | }
|
23929 |
|
23930 | if (config._isPm === false && config._a[HOUR] === 12) {
|
23931 | config._a[HOUR] = 0;
|
23932 | }
|
23933 |
|
23934 | dateFromConfig(config);
|
23935 | checkOverflow(config);
|
23936 | }
|
23937 |
|
23938 | function unescapeFormat(s) {
|
23939 | return s.replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched, p1, p2, p3, p4) {
|
23940 | return p1 || p2 || p3 || p4;
|
23941 | });
|
23942 | }
|
23943 |
|
23944 |
|
23945 | function regexpEscape(s) {
|
23946 | return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
|
23947 | }
|
23948 |
|
23949 |
|
23950 | function makeDateFromStringAndArray(config) {
|
23951 | var tempConfig,
|
23952 | bestMoment,
|
23953 |
|
23954 | scoreToBeat,
|
23955 | i,
|
23956 | currentScore;
|
23957 |
|
23958 | if (config._f.length === 0) {
|
23959 | config._pf.invalidFormat = true;
|
23960 | config._d = new Date(NaN);
|
23961 | return;
|
23962 | }
|
23963 |
|
23964 | for (i = 0; i < config._f.length; i++) {
|
23965 | currentScore = 0;
|
23966 | tempConfig = copyConfig({}, config);
|
23967 | if (config._useUTC != null) {
|
23968 | tempConfig._useUTC = config._useUTC;
|
23969 | }
|
23970 | tempConfig._pf = defaultParsingFlags();
|
23971 | tempConfig._f = config._f[i];
|
23972 | makeDateFromStringAndFormat(tempConfig);
|
23973 |
|
23974 | if (!isValid(tempConfig)) {
|
23975 | continue;
|
23976 | }
|
23977 |
|
23978 |
|
23979 | currentScore += tempConfig._pf.charsLeftOver;
|
23980 |
|
23981 |
|
23982 | currentScore += tempConfig._pf.unusedTokens.length * 10;
|
23983 |
|
23984 | tempConfig._pf.score = currentScore;
|
23985 |
|
23986 | if (scoreToBeat == null || currentScore < scoreToBeat) {
|
23987 | scoreToBeat = currentScore;
|
23988 | bestMoment = tempConfig;
|
23989 | }
|
23990 | }
|
23991 |
|
23992 | extend(config, bestMoment || tempConfig);
|
23993 | }
|
23994 |
|
23995 |
|
23996 | function parseISO(config) {
|
23997 | var i, l,
|
23998 | string = config._i,
|
23999 | match = isoRegex.exec(string);
|
24000 |
|
24001 | if (match) {
|
24002 | config._pf.iso = true;
|
24003 | for (i = 0, l = isoDates.length; i < l; i++) {
|
24004 | if (isoDates[i][1].exec(string)) {
|
24005 |
|
24006 | config._f = isoDates[i][0] + (match[6] || ' ');
|
24007 | break;
|
24008 | }
|
24009 | }
|
24010 | for (i = 0, l = isoTimes.length; i < l; i++) {
|
24011 | if (isoTimes[i][1].exec(string)) {
|
24012 | config._f += isoTimes[i][0];
|
24013 | break;
|
24014 | }
|
24015 | }
|
24016 | if (string.match(parseTokenTimezone)) {
|
24017 | config._f += 'Z';
|
24018 | }
|
24019 | makeDateFromStringAndFormat(config);
|
24020 | } else {
|
24021 | config._isValid = false;
|
24022 | }
|
24023 | }
|
24024 |
|
24025 |
|
24026 | function makeDateFromString(config) {
|
24027 | parseISO(config);
|
24028 | if (config._isValid === false) {
|
24029 | delete config._isValid;
|
24030 | moment.createFromInputFallback(config);
|
24031 | }
|
24032 | }
|
24033 |
|
24034 | function map(arr, fn) {
|
24035 | var res = [], i;
|
24036 | for (i = 0; i < arr.length; ++i) {
|
24037 | res.push(fn(arr[i], i));
|
24038 | }
|
24039 | return res;
|
24040 | }
|
24041 |
|
24042 | function makeDateFromInput(config) {
|
24043 | var input = config._i, matched;
|
24044 | if (input === undefined) {
|
24045 | config._d = new Date();
|
24046 | } else if (isDate(input)) {
|
24047 | config._d = new Date(+input);
|
24048 | } else if ((matched = aspNetJsonRegex.exec(input)) !== null) {
|
24049 | config._d = new Date(+matched[1]);
|
24050 | } else if (typeof input === 'string') {
|
24051 | makeDateFromString(config);
|
24052 | } else if (isArray(input)) {
|
24053 | config._a = map(input.slice(0), function (obj) {
|
24054 | return parseInt(obj, 10);
|
24055 | });
|
24056 | dateFromConfig(config);
|
24057 | } else if (typeof(input) === 'object') {
|
24058 | dateFromObject(config);
|
24059 | } else if (typeof(input) === 'number') {
|
24060 |
|
24061 | config._d = new Date(input);
|
24062 | } else {
|
24063 | moment.createFromInputFallback(config);
|
24064 | }
|
24065 | }
|
24066 |
|
24067 | function makeDate(y, m, d, h, M, s, ms) {
|
24068 |
|
24069 |
|
24070 | var date = new Date(y, m, d, h, M, s, ms);
|
24071 |
|
24072 |
|
24073 | if (y < 1970) {
|
24074 | date.setFullYear(y);
|
24075 | }
|
24076 | return date;
|
24077 | }
|
24078 |
|
24079 | function makeUTCDate(y) {
|
24080 | var date = new Date(Date.UTC.apply(null, arguments));
|
24081 | if (y < 1970) {
|
24082 | date.setUTCFullYear(y);
|
24083 | }
|
24084 | return date;
|
24085 | }
|
24086 |
|
24087 | function parseWeekday(input, locale) {
|
24088 | if (typeof input === 'string') {
|
24089 | if (!isNaN(input)) {
|
24090 | input = parseInt(input, 10);
|
24091 | }
|
24092 | else {
|
24093 | input = locale.weekdaysParse(input);
|
24094 | if (typeof input !== 'number') {
|
24095 | return null;
|
24096 | }
|
24097 | }
|
24098 | }
|
24099 | return input;
|
24100 | }
|
24101 |
|
24102 | |
24103 |
|
24104 |
|
24105 |
|
24106 |
|
24107 |
|
24108 | function substituteTimeAgo(string, number, withoutSuffix, isFuture, locale) {
|
24109 | return locale.relativeTime(number || 1, !!withoutSuffix, string, isFuture);
|
24110 | }
|
24111 |
|
24112 | function relativeTime(posNegDuration, withoutSuffix, locale) {
|
24113 | var duration = moment.duration(posNegDuration).abs(),
|
24114 | seconds = round(duration.as('s')),
|
24115 | minutes = round(duration.as('m')),
|
24116 | hours = round(duration.as('h')),
|
24117 | days = round(duration.as('d')),
|
24118 | months = round(duration.as('M')),
|
24119 | years = round(duration.as('y')),
|
24120 |
|
24121 | args = seconds < relativeTimeThresholds.s && ['s', seconds] ||
|
24122 | minutes === 1 && ['m'] ||
|
24123 | minutes < relativeTimeThresholds.m && ['mm', minutes] ||
|
24124 | hours === 1 && ['h'] ||
|
24125 | hours < relativeTimeThresholds.h && ['hh', hours] ||
|
24126 | days === 1 && ['d'] ||
|
24127 | days < relativeTimeThresholds.d && ['dd', days] ||
|
24128 | months === 1 && ['M'] ||
|
24129 | months < relativeTimeThresholds.M && ['MM', months] ||
|
24130 | years === 1 && ['y'] || ['yy', years];
|
24131 |
|
24132 | args[2] = withoutSuffix;
|
24133 | args[3] = +posNegDuration > 0;
|
24134 | args[4] = locale;
|
24135 | return substituteTimeAgo.apply({}, args);
|
24136 | }
|
24137 |
|
24138 |
|
24139 | |
24140 |
|
24141 |
|
24142 |
|
24143 |
|
24144 |
|
24145 |
|
24146 |
|
24147 |
|
24148 |
|
24149 |
|
24150 |
|
24151 | function weekOfYear(mom, firstDayOfWeek, firstDayOfWeekOfYear) {
|
24152 | var end = firstDayOfWeekOfYear - firstDayOfWeek,
|
24153 | daysToDayOfWeek = firstDayOfWeekOfYear - mom.day(),
|
24154 | adjustedMoment;
|
24155 |
|
24156 |
|
24157 | if (daysToDayOfWeek > end) {
|
24158 | daysToDayOfWeek -= 7;
|
24159 | }
|
24160 |
|
24161 | if (daysToDayOfWeek < end - 7) {
|
24162 | daysToDayOfWeek += 7;
|
24163 | }
|
24164 |
|
24165 | adjustedMoment = moment(mom).add(daysToDayOfWeek, 'd');
|
24166 | return {
|
24167 | week: Math.ceil(adjustedMoment.dayOfYear() / 7),
|
24168 | year: adjustedMoment.year()
|
24169 | };
|
24170 | }
|
24171 |
|
24172 |
|
24173 | function dayOfYearFromWeeks(year, week, weekday, firstDayOfWeekOfYear, firstDayOfWeek) {
|
24174 | var d = makeUTCDate(year, 0, 1).getUTCDay(), daysToAdd, dayOfYear;
|
24175 |
|
24176 | d = d === 0 ? 7 : d;
|
24177 | weekday = weekday != null ? weekday : firstDayOfWeek;
|
24178 | daysToAdd = firstDayOfWeek - d + (d > firstDayOfWeekOfYear ? 7 : 0) - (d < firstDayOfWeek ? 7 : 0);
|
24179 | dayOfYear = 7 * (week - 1) + (weekday - firstDayOfWeek) + daysToAdd + 1;
|
24180 |
|
24181 | return {
|
24182 | year: dayOfYear > 0 ? year : year - 1,
|
24183 | dayOfYear: dayOfYear > 0 ? dayOfYear : daysInYear(year - 1) + dayOfYear
|
24184 | };
|
24185 | }
|
24186 |
|
24187 | |
24188 |
|
24189 |
|
24190 |
|
24191 | function makeMoment(config) {
|
24192 | var input = config._i,
|
24193 | format = config._f;
|
24194 |
|
24195 | config._locale = config._locale || moment.localeData(config._l);
|
24196 |
|
24197 | if (input === null || (format === undefined && input === '')) {
|
24198 | return moment.invalid({nullInput: true});
|
24199 | }
|
24200 |
|
24201 | if (typeof input === 'string') {
|
24202 | config._i = input = config._locale.preparse(input);
|
24203 | }
|
24204 |
|
24205 | if (moment.isMoment(input)) {
|
24206 | return new Moment(input, true);
|
24207 | } else if (format) {
|
24208 | if (isArray(format)) {
|
24209 | makeDateFromStringAndArray(config);
|
24210 | } else {
|
24211 | makeDateFromStringAndFormat(config);
|
24212 | }
|
24213 | } else {
|
24214 | makeDateFromInput(config);
|
24215 | }
|
24216 |
|
24217 | return new Moment(config);
|
24218 | }
|
24219 |
|
24220 | moment = function (input, format, locale, strict) {
|
24221 | var c;
|
24222 |
|
24223 | if (typeof(locale) === 'boolean') {
|
24224 | strict = locale;
|
24225 | locale = undefined;
|
24226 | }
|
24227 |
|
24228 |
|
24229 | c = {};
|
24230 | c._isAMomentObject = true;
|
24231 | c._i = input;
|
24232 | c._f = format;
|
24233 | c._l = locale;
|
24234 | c._strict = strict;
|
24235 | c._isUTC = false;
|
24236 | c._pf = defaultParsingFlags();
|
24237 |
|
24238 | return makeMoment(c);
|
24239 | };
|
24240 |
|
24241 | moment.suppressDeprecationWarnings = false;
|
24242 |
|
24243 | moment.createFromInputFallback = deprecate(
|
24244 | 'moment construction falls back to js Date. This is ' +
|
24245 | 'discouraged and will be removed in upcoming major ' +
|
24246 | 'release. Please refer to ' +
|
24247 | 'https://github.com/moment/moment/issues/1407 for more info.',
|
24248 | function (config) {
|
24249 | config._d = new Date(config._i);
|
24250 | }
|
24251 | );
|
24252 |
|
24253 |
|
24254 |
|
24255 |
|
24256 |
|
24257 |
|
24258 | function pickBy(fn, moments) {
|
24259 | var res, i;
|
24260 | if (moments.length === 1 && isArray(moments[0])) {
|
24261 | moments = moments[0];
|
24262 | }
|
24263 | if (!moments.length) {
|
24264 | return moment();
|
24265 | }
|
24266 | res = moments[0];
|
24267 | for (i = 1; i < moments.length; ++i) {
|
24268 | if (moments[i][fn](res)) {
|
24269 | res = moments[i];
|
24270 | }
|
24271 | }
|
24272 | return res;
|
24273 | }
|
24274 |
|
24275 | moment.min = function () {
|
24276 | var args = [].slice.call(arguments, 0);
|
24277 |
|
24278 | return pickBy('isBefore', args);
|
24279 | };
|
24280 |
|
24281 | moment.max = function () {
|
24282 | var args = [].slice.call(arguments, 0);
|
24283 |
|
24284 | return pickBy('isAfter', args);
|
24285 | };
|
24286 |
|
24287 |
|
24288 | moment.utc = function (input, format, locale, strict) {
|
24289 | var c;
|
24290 |
|
24291 | if (typeof(locale) === 'boolean') {
|
24292 | strict = locale;
|
24293 | locale = undefined;
|
24294 | }
|
24295 |
|
24296 |
|
24297 | c = {};
|
24298 | c._isAMomentObject = true;
|
24299 | c._useUTC = true;
|
24300 | c._isUTC = true;
|
24301 | c._l = locale;
|
24302 | c._i = input;
|
24303 | c._f = format;
|
24304 | c._strict = strict;
|
24305 | c._pf = defaultParsingFlags();
|
24306 |
|
24307 | return makeMoment(c).utc();
|
24308 | };
|
24309 |
|
24310 |
|
24311 | moment.unix = function (input) {
|
24312 | return moment(input * 1000);
|
24313 | };
|
24314 |
|
24315 |
|
24316 | moment.duration = function (input, key) {
|
24317 | var duration = input,
|
24318 |
|
24319 | match = null,
|
24320 | sign,
|
24321 | ret,
|
24322 | parseIso,
|
24323 | diffRes;
|
24324 |
|
24325 | if (moment.isDuration(input)) {
|
24326 | duration = {
|
24327 | ms: input._milliseconds,
|
24328 | d: input._days,
|
24329 | M: input._months
|
24330 | };
|
24331 | } else if (typeof input === 'number') {
|
24332 | duration = {};
|
24333 | if (key) {
|
24334 | duration[key] = input;
|
24335 | } else {
|
24336 | duration.milliseconds = input;
|
24337 | }
|
24338 | } else if (!!(match = aspNetTimeSpanJsonRegex.exec(input))) {
|
24339 | sign = (match[1] === '-') ? -1 : 1;
|
24340 | duration = {
|
24341 | y: 0,
|
24342 | d: toInt(match[DATE]) * sign,
|
24343 | h: toInt(match[HOUR]) * sign,
|
24344 | m: toInt(match[MINUTE]) * sign,
|
24345 | s: toInt(match[SECOND]) * sign,
|
24346 | ms: toInt(match[MILLISECOND]) * sign
|
24347 | };
|
24348 | } else if (!!(match = isoDurationRegex.exec(input))) {
|
24349 | sign = (match[1] === '-') ? -1 : 1;
|
24350 | parseIso = function (inp) {
|
24351 |
|
24352 |
|
24353 |
|
24354 | var res = inp && parseFloat(inp.replace(',', '.'));
|
24355 |
|
24356 | return (isNaN(res) ? 0 : res) * sign;
|
24357 | };
|
24358 | duration = {
|
24359 | y: parseIso(match[2]),
|
24360 | M: parseIso(match[3]),
|
24361 | d: parseIso(match[4]),
|
24362 | h: parseIso(match[5]),
|
24363 | m: parseIso(match[6]),
|
24364 | s: parseIso(match[7]),
|
24365 | w: parseIso(match[8])
|
24366 | };
|
24367 | } else if (typeof duration === 'object' &&
|
24368 | ('from' in duration || 'to' in duration)) {
|
24369 | diffRes = momentsDifference(moment(duration.from), moment(duration.to));
|
24370 |
|
24371 | duration = {};
|
24372 | duration.ms = diffRes.milliseconds;
|
24373 | duration.M = diffRes.months;
|
24374 | }
|
24375 |
|
24376 | ret = new Duration(duration);
|
24377 |
|
24378 | if (moment.isDuration(input) && hasOwnProp(input, '_locale')) {
|
24379 | ret._locale = input._locale;
|
24380 | }
|
24381 |
|
24382 | return ret;
|
24383 | };
|
24384 |
|
24385 |
|
24386 | moment.version = VERSION;
|
24387 |
|
24388 |
|
24389 | moment.defaultFormat = isoFormat;
|
24390 |
|
24391 |
|
24392 | moment.ISO_8601 = function () {};
|
24393 |
|
24394 |
|
24395 |
|
24396 | moment.momentProperties = momentProperties;
|
24397 |
|
24398 |
|
24399 |
|
24400 | moment.updateOffset = function () {};
|
24401 |
|
24402 |
|
24403 | moment.relativeTimeThreshold = function (threshold, limit) {
|
24404 | if (relativeTimeThresholds[threshold] === undefined) {
|
24405 | return false;
|
24406 | }
|
24407 | if (limit === undefined) {
|
24408 | return relativeTimeThresholds[threshold];
|
24409 | }
|
24410 | relativeTimeThresholds[threshold] = limit;
|
24411 | return true;
|
24412 | };
|
24413 |
|
24414 | moment.lang = deprecate(
|
24415 | 'moment.lang is deprecated. Use moment.locale instead.',
|
24416 | function (key, value) {
|
24417 | return moment.locale(key, value);
|
24418 | }
|
24419 | );
|
24420 |
|
24421 |
|
24422 |
|
24423 |
|
24424 | moment.locale = function (key, values) {
|
24425 | var data;
|
24426 | if (key) {
|
24427 | if (typeof(values) !== 'undefined') {
|
24428 | data = moment.defineLocale(key, values);
|
24429 | }
|
24430 | else {
|
24431 | data = moment.localeData(key);
|
24432 | }
|
24433 |
|
24434 | if (data) {
|
24435 | moment.duration._locale = moment._locale = data;
|
24436 | }
|
24437 | }
|
24438 |
|
24439 | return moment._locale._abbr;
|
24440 | };
|
24441 |
|
24442 | moment.defineLocale = function (name, values) {
|
24443 | if (values !== null) {
|
24444 | values.abbr = name;
|
24445 | if (!locales[name]) {
|
24446 | locales[name] = new Locale();
|
24447 | }
|
24448 | locales[name].set(values);
|
24449 |
|
24450 |
|
24451 | moment.locale(name);
|
24452 |
|
24453 | return locales[name];
|
24454 | } else {
|
24455 |
|
24456 | delete locales[name];
|
24457 | return null;
|
24458 | }
|
24459 | };
|
24460 |
|
24461 | moment.langData = deprecate(
|
24462 | 'moment.langData is deprecated. Use moment.localeData instead.',
|
24463 | function (key) {
|
24464 | return moment.localeData(key);
|
24465 | }
|
24466 | );
|
24467 |
|
24468 |
|
24469 | moment.localeData = function (key) {
|
24470 | var locale;
|
24471 |
|
24472 | if (key && key._locale && key._locale._abbr) {
|
24473 | key = key._locale._abbr;
|
24474 | }
|
24475 |
|
24476 | if (!key) {
|
24477 | return moment._locale;
|
24478 | }
|
24479 |
|
24480 | if (!isArray(key)) {
|
24481 |
|
24482 | locale = loadLocale(key);
|
24483 | if (locale) {
|
24484 | return locale;
|
24485 | }
|
24486 | key = [key];
|
24487 | }
|
24488 |
|
24489 | return chooseLocale(key);
|
24490 | };
|
24491 |
|
24492 |
|
24493 | moment.isMoment = function (obj) {
|
24494 | return obj instanceof Moment ||
|
24495 | (obj != null && hasOwnProp(obj, '_isAMomentObject'));
|
24496 | };
|
24497 |
|
24498 |
|
24499 | moment.isDuration = function (obj) {
|
24500 | return obj instanceof Duration;
|
24501 | };
|
24502 |
|
24503 | for (i = lists.length - 1; i >= 0; --i) {
|
24504 | makeList(lists[i]);
|
24505 | }
|
24506 |
|
24507 | moment.normalizeUnits = function (units) {
|
24508 | return normalizeUnits(units);
|
24509 | };
|
24510 |
|
24511 | moment.invalid = function (flags) {
|
24512 | var m = moment.utc(NaN);
|
24513 | if (flags != null) {
|
24514 | extend(m._pf, flags);
|
24515 | }
|
24516 | else {
|
24517 | m._pf.userInvalidated = true;
|
24518 | }
|
24519 |
|
24520 | return m;
|
24521 | };
|
24522 |
|
24523 | moment.parseZone = function () {
|
24524 | return moment.apply(null, arguments).parseZone();
|
24525 | };
|
24526 |
|
24527 | moment.parseTwoDigitYear = function (input) {
|
24528 | return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
|
24529 | };
|
24530 |
|
24531 | |
24532 |
|
24533 |
|
24534 |
|
24535 |
|
24536 | extend(moment.fn = Moment.prototype, {
|
24537 |
|
24538 | clone : function () {
|
24539 | return moment(this);
|
24540 | },
|
24541 |
|
24542 | valueOf : function () {
|
24543 | return +this._d + ((this._offset || 0) * 60000);
|
24544 | },
|
24545 |
|
24546 | unix : function () {
|
24547 | return Math.floor(+this / 1000);
|
24548 | },
|
24549 |
|
24550 | toString : function () {
|
24551 | return this.clone().locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ');
|
24552 | },
|
24553 |
|
24554 | toDate : function () {
|
24555 | return this._offset ? new Date(+this) : this._d;
|
24556 | },
|
24557 |
|
24558 | toISOString : function () {
|
24559 | var m = moment(this).utc();
|
24560 | if (0 < m.year() && m.year() <= 9999) {
|
24561 | return formatMoment(m, 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
|
24562 | } else {
|
24563 | return formatMoment(m, 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
|
24564 | }
|
24565 | },
|
24566 |
|
24567 | toArray : function () {
|
24568 | var m = this;
|
24569 | return [
|
24570 | m.year(),
|
24571 | m.month(),
|
24572 | m.date(),
|
24573 | m.hours(),
|
24574 | m.minutes(),
|
24575 | m.seconds(),
|
24576 | m.milliseconds()
|
24577 | ];
|
24578 | },
|
24579 |
|
24580 | isValid : function () {
|
24581 | return isValid(this);
|
24582 | },
|
24583 |
|
24584 | isDSTShifted : function () {
|
24585 | if (this._a) {
|
24586 | return this.isValid() && compareArrays(this._a, (this._isUTC ? moment.utc(this._a) : moment(this._a)).toArray()) > 0;
|
24587 | }
|
24588 |
|
24589 | return false;
|
24590 | },
|
24591 |
|
24592 | parsingFlags : function () {
|
24593 | return extend({}, this._pf);
|
24594 | },
|
24595 |
|
24596 | invalidAt: function () {
|
24597 | return this._pf.overflow;
|
24598 | },
|
24599 |
|
24600 | utc : function (keepLocalTime) {
|
24601 | return this.zone(0, keepLocalTime);
|
24602 | },
|
24603 |
|
24604 | local : function (keepLocalTime) {
|
24605 | if (this._isUTC) {
|
24606 | this.zone(0, keepLocalTime);
|
24607 | this._isUTC = false;
|
24608 |
|
24609 | if (keepLocalTime) {
|
24610 | this.add(this._dateTzOffset(), 'm');
|
24611 | }
|
24612 | }
|
24613 | return this;
|
24614 | },
|
24615 |
|
24616 | format : function (inputString) {
|
24617 | var output = formatMoment(this, inputString || moment.defaultFormat);
|
24618 | return this.localeData().postformat(output);
|
24619 | },
|
24620 |
|
24621 | add : createAdder(1, 'add'),
|
24622 |
|
24623 | subtract : createAdder(-1, 'subtract'),
|
24624 |
|
24625 | diff : function (input, units, asFloat) {
|
24626 | var that = makeAs(input, this),
|
24627 | zoneDiff = (this.zone() - that.zone()) * 6e4,
|
24628 | diff, output, daysAdjust;
|
24629 |
|
24630 | units = normalizeUnits(units);
|
24631 |
|
24632 | if (units === 'year' || units === 'month') {
|
24633 |
|
24634 | diff = (this.daysInMonth() + that.daysInMonth()) * 432e5;
|
24635 |
|
24636 | output = ((this.year() - that.year()) * 12) + (this.month() - that.month());
|
24637 |
|
24638 |
|
24639 | daysAdjust = (this - moment(this).startOf('month')) -
|
24640 | (that - moment(that).startOf('month'));
|
24641 |
|
24642 | daysAdjust -= ((this.zone() - moment(this).startOf('month').zone()) -
|
24643 | (that.zone() - moment(that).startOf('month').zone())) * 6e4;
|
24644 | output += daysAdjust / diff;
|
24645 | if (units === 'year') {
|
24646 | output = output / 12;
|
24647 | }
|
24648 | } else {
|
24649 | diff = (this - that);
|
24650 | output = units === 'second' ? diff / 1e3 :
|
24651 | units === 'minute' ? diff / 6e4 :
|
24652 | units === 'hour' ? diff / 36e5 :
|
24653 | units === 'day' ? (diff - zoneDiff) / 864e5 :
|
24654 | units === 'week' ? (diff - zoneDiff) / 6048e5 :
|
24655 | diff;
|
24656 | }
|
24657 | return asFloat ? output : absRound(output);
|
24658 | },
|
24659 |
|
24660 | from : function (time, withoutSuffix) {
|
24661 | return moment.duration({to: this, from: time}).locale(this.locale()).humanize(!withoutSuffix);
|
24662 | },
|
24663 |
|
24664 | fromNow : function (withoutSuffix) {
|
24665 | return this.from(moment(), withoutSuffix);
|
24666 | },
|
24667 |
|
24668 | calendar : function (time) {
|
24669 |
|
24670 |
|
24671 | var now = time || moment(),
|
24672 | sod = makeAs(now, this).startOf('day'),
|
24673 | diff = this.diff(sod, 'days', true),
|
24674 | format = diff < -6 ? 'sameElse' :
|
24675 | diff < -1 ? 'lastWeek' :
|
24676 | diff < 0 ? 'lastDay' :
|
24677 | diff < 1 ? 'sameDay' :
|
24678 | diff < 2 ? 'nextDay' :
|
24679 | diff < 7 ? 'nextWeek' : 'sameElse';
|
24680 | return this.format(this.localeData().calendar(format, this));
|
24681 | },
|
24682 |
|
24683 | isLeapYear : function () {
|
24684 | return isLeapYear(this.year());
|
24685 | },
|
24686 |
|
24687 | isDST : function () {
|
24688 | return (this.zone() < this.clone().month(0).zone() ||
|
24689 | this.zone() < this.clone().month(5).zone());
|
24690 | },
|
24691 |
|
24692 | day : function (input) {
|
24693 | var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay();
|
24694 | if (input != null) {
|
24695 | input = parseWeekday(input, this.localeData());
|
24696 | return this.add(input - day, 'd');
|
24697 | } else {
|
24698 | return day;
|
24699 | }
|
24700 | },
|
24701 |
|
24702 | month : makeAccessor('Month', true),
|
24703 |
|
24704 | startOf : function (units) {
|
24705 | units = normalizeUnits(units);
|
24706 |
|
24707 |
|
24708 | switch (units) {
|
24709 | case 'year':
|
24710 | this.month(0);
|
24711 |
|
24712 | case 'quarter':
|
24713 | case 'month':
|
24714 | this.date(1);
|
24715 |
|
24716 | case 'week':
|
24717 | case 'isoWeek':
|
24718 | case 'day':
|
24719 | this.hours(0);
|
24720 |
|
24721 | case 'hour':
|
24722 | this.minutes(0);
|
24723 |
|
24724 | case 'minute':
|
24725 | this.seconds(0);
|
24726 |
|
24727 | case 'second':
|
24728 | this.milliseconds(0);
|
24729 |
|
24730 | }
|
24731 |
|
24732 |
|
24733 | if (units === 'week') {
|
24734 | this.weekday(0);
|
24735 | } else if (units === 'isoWeek') {
|
24736 | this.isoWeekday(1);
|
24737 | }
|
24738 |
|
24739 |
|
24740 | if (units === 'quarter') {
|
24741 | this.month(Math.floor(this.month() / 3) * 3);
|
24742 | }
|
24743 |
|
24744 | return this;
|
24745 | },
|
24746 |
|
24747 | endOf: function (units) {
|
24748 | units = normalizeUnits(units);
|
24749 | return this.startOf(units).add(1, (units === 'isoWeek' ? 'week' : units)).subtract(1, 'ms');
|
24750 | },
|
24751 |
|
24752 | isAfter: function (input, units) {
|
24753 | units = normalizeUnits(typeof units !== 'undefined' ? units : 'millisecond');
|
24754 | if (units === 'millisecond') {
|
24755 | input = moment.isMoment(input) ? input : moment(input);
|
24756 | return +this > +input;
|
24757 | } else {
|
24758 | return +this.clone().startOf(units) > +moment(input).startOf(units);
|
24759 | }
|
24760 | },
|
24761 |
|
24762 | isBefore: function (input, units) {
|
24763 | units = normalizeUnits(typeof units !== 'undefined' ? units : 'millisecond');
|
24764 | if (units === 'millisecond') {
|
24765 | input = moment.isMoment(input) ? input : moment(input);
|
24766 | return +this < +input;
|
24767 | } else {
|
24768 | return +this.clone().startOf(units) < +moment(input).startOf(units);
|
24769 | }
|
24770 | },
|
24771 |
|
24772 | isSame: function (input, units) {
|
24773 | units = normalizeUnits(units || 'millisecond');
|
24774 | if (units === 'millisecond') {
|
24775 | input = moment.isMoment(input) ? input : moment(input);
|
24776 | return +this === +input;
|
24777 | } else {
|
24778 | return +this.clone().startOf(units) === +makeAs(input, this).startOf(units);
|
24779 | }
|
24780 | },
|
24781 |
|
24782 | min: deprecate(
|
24783 | 'moment().min is deprecated, use moment.min instead. https://github.com/moment/moment/issues/1548',
|
24784 | function (other) {
|
24785 | other = moment.apply(null, arguments);
|
24786 | return other < this ? this : other;
|
24787 | }
|
24788 | ),
|
24789 |
|
24790 | max: deprecate(
|
24791 | 'moment().max is deprecated, use moment.max instead. https://github.com/moment/moment/issues/1548',
|
24792 | function (other) {
|
24793 | other = moment.apply(null, arguments);
|
24794 | return other > this ? this : other;
|
24795 | }
|
24796 | ),
|
24797 |
|
24798 |
|
24799 |
|
24800 |
|
24801 |
|
24802 |
|
24803 |
|
24804 |
|
24805 |
|
24806 |
|
24807 |
|
24808 | zone : function (input, keepLocalTime) {
|
24809 | var offset = this._offset || 0,
|
24810 | localAdjust;
|
24811 | if (input != null) {
|
24812 | if (typeof input === 'string') {
|
24813 | input = timezoneMinutesFromString(input);
|
24814 | }
|
24815 | if (Math.abs(input) < 16) {
|
24816 | input = input * 60;
|
24817 | }
|
24818 | if (!this._isUTC && keepLocalTime) {
|
24819 | localAdjust = this._dateTzOffset();
|
24820 | }
|
24821 | this._offset = input;
|
24822 | this._isUTC = true;
|
24823 | if (localAdjust != null) {
|
24824 | this.subtract(localAdjust, 'm');
|
24825 | }
|
24826 | if (offset !== input) {
|
24827 | if (!keepLocalTime || this._changeInProgress) {
|
24828 | addOrSubtractDurationFromMoment(this,
|
24829 | moment.duration(offset - input, 'm'), 1, false);
|
24830 | } else if (!this._changeInProgress) {
|
24831 | this._changeInProgress = true;
|
24832 | moment.updateOffset(this, true);
|
24833 | this._changeInProgress = null;
|
24834 | }
|
24835 | }
|
24836 | } else {
|
24837 | return this._isUTC ? offset : this._dateTzOffset();
|
24838 | }
|
24839 | return this;
|
24840 | },
|
24841 |
|
24842 | zoneAbbr : function () {
|
24843 | return this._isUTC ? 'UTC' : '';
|
24844 | },
|
24845 |
|
24846 | zoneName : function () {
|
24847 | return this._isUTC ? 'Coordinated Universal Time' : '';
|
24848 | },
|
24849 |
|
24850 | parseZone : function () {
|
24851 | if (this._tzm) {
|
24852 | this.zone(this._tzm);
|
24853 | } else if (typeof this._i === 'string') {
|
24854 | this.zone(this._i);
|
24855 | }
|
24856 | return this;
|
24857 | },
|
24858 |
|
24859 | hasAlignedHourOffset : function (input) {
|
24860 | if (!input) {
|
24861 | input = 0;
|
24862 | }
|
24863 | else {
|
24864 | input = moment(input).zone();
|
24865 | }
|
24866 |
|
24867 | return (this.zone() - input) % 60 === 0;
|
24868 | },
|
24869 |
|
24870 | daysInMonth : function () {
|
24871 | return daysInMonth(this.year(), this.month());
|
24872 | },
|
24873 |
|
24874 | dayOfYear : function (input) {
|
24875 | var dayOfYear = round((moment(this).startOf('day') - moment(this).startOf('year')) / 864e5) + 1;
|
24876 | return input == null ? dayOfYear : this.add((input - dayOfYear), 'd');
|
24877 | },
|
24878 |
|
24879 | quarter : function (input) {
|
24880 | return input == null ? Math.ceil((this.month() + 1) / 3) : this.month((input - 1) * 3 + this.month() % 3);
|
24881 | },
|
24882 |
|
24883 | weekYear : function (input) {
|
24884 | var year = weekOfYear(this, this.localeData()._week.dow, this.localeData()._week.doy).year;
|
24885 | return input == null ? year : this.add((input - year), 'y');
|
24886 | },
|
24887 |
|
24888 | isoWeekYear : function (input) {
|
24889 | var year = weekOfYear(this, 1, 4).year;
|
24890 | return input == null ? year : this.add((input - year), 'y');
|
24891 | },
|
24892 |
|
24893 | week : function (input) {
|
24894 | var week = this.localeData().week(this);
|
24895 | return input == null ? week : this.add((input - week) * 7, 'd');
|
24896 | },
|
24897 |
|
24898 | isoWeek : function (input) {
|
24899 | var week = weekOfYear(this, 1, 4).week;
|
24900 | return input == null ? week : this.add((input - week) * 7, 'd');
|
24901 | },
|
24902 |
|
24903 | weekday : function (input) {
|
24904 | var weekday = (this.day() + 7 - this.localeData()._week.dow) % 7;
|
24905 | return input == null ? weekday : this.add(input - weekday, 'd');
|
24906 | },
|
24907 |
|
24908 | isoWeekday : function (input) {
|
24909 |
|
24910 |
|
24911 |
|
24912 | return input == null ? this.day() || 7 : this.day(this.day() % 7 ? input : input - 7);
|
24913 | },
|
24914 |
|
24915 | isoWeeksInYear : function () {
|
24916 | return weeksInYear(this.year(), 1, 4);
|
24917 | },
|
24918 |
|
24919 | weeksInYear : function () {
|
24920 | var weekInfo = this.localeData()._week;
|
24921 | return weeksInYear(this.year(), weekInfo.dow, weekInfo.doy);
|
24922 | },
|
24923 |
|
24924 | get : function (units) {
|
24925 | units = normalizeUnits(units);
|
24926 | return this[units]();
|
24927 | },
|
24928 |
|
24929 | set : function (units, value) {
|
24930 | units = normalizeUnits(units);
|
24931 | if (typeof this[units] === 'function') {
|
24932 | this[units](value);
|
24933 | }
|
24934 | return this;
|
24935 | },
|
24936 |
|
24937 |
|
24938 |
|
24939 |
|
24940 | locale : function (key) {
|
24941 | var newLocaleData;
|
24942 |
|
24943 | if (key === undefined) {
|
24944 | return this._locale._abbr;
|
24945 | } else {
|
24946 | newLocaleData = moment.localeData(key);
|
24947 | if (newLocaleData != null) {
|
24948 | this._locale = newLocaleData;
|
24949 | }
|
24950 | return this;
|
24951 | }
|
24952 | },
|
24953 |
|
24954 | lang : deprecate(
|
24955 | 'moment().lang() is deprecated. Use moment().localeData() instead.',
|
24956 | function (key) {
|
24957 | if (key === undefined) {
|
24958 | return this.localeData();
|
24959 | } else {
|
24960 | return this.locale(key);
|
24961 | }
|
24962 | }
|
24963 | ),
|
24964 |
|
24965 | localeData : function () {
|
24966 | return this._locale;
|
24967 | },
|
24968 |
|
24969 | _dateTzOffset : function () {
|
24970 |
|
24971 |
|
24972 | return Math.round(this._d.getTimezoneOffset() / 15) * 15;
|
24973 | }
|
24974 | });
|
24975 |
|
24976 | function rawMonthSetter(mom, value) {
|
24977 | var dayOfMonth;
|
24978 |
|
24979 |
|
24980 | if (typeof value === 'string') {
|
24981 | value = mom.localeData().monthsParse(value);
|
24982 |
|
24983 | if (typeof value !== 'number') {
|
24984 | return mom;
|
24985 | }
|
24986 | }
|
24987 |
|
24988 | dayOfMonth = Math.min(mom.date(),
|
24989 | daysInMonth(mom.year(), value));
|
24990 | mom._d['set' + (mom._isUTC ? 'UTC' : '') + 'Month'](value, dayOfMonth);
|
24991 | return mom;
|
24992 | }
|
24993 |
|
24994 | function rawGetter(mom, unit) {
|
24995 | return mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit]();
|
24996 | }
|
24997 |
|
24998 | function rawSetter(mom, unit, value) {
|
24999 | if (unit === 'Month') {
|
25000 | return rawMonthSetter(mom, value);
|
25001 | } else {
|
25002 | return mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value);
|
25003 | }
|
25004 | }
|
25005 |
|
25006 | function makeAccessor(unit, keepTime) {
|
25007 | return function (value) {
|
25008 | if (value != null) {
|
25009 | rawSetter(this, unit, value);
|
25010 | moment.updateOffset(this, keepTime);
|
25011 | return this;
|
25012 | } else {
|
25013 | return rawGetter(this, unit);
|
25014 | }
|
25015 | };
|
25016 | }
|
25017 |
|
25018 | moment.fn.millisecond = moment.fn.milliseconds = makeAccessor('Milliseconds', false);
|
25019 | moment.fn.second = moment.fn.seconds = makeAccessor('Seconds', false);
|
25020 | moment.fn.minute = moment.fn.minutes = makeAccessor('Minutes', false);
|
25021 |
|
25022 |
|
25023 |
|
25024 |
|
25025 | moment.fn.hour = moment.fn.hours = makeAccessor('Hours', true);
|
25026 |
|
25027 | moment.fn.date = makeAccessor('Date', true);
|
25028 | moment.fn.dates = deprecate('dates accessor is deprecated. Use date instead.', makeAccessor('Date', true));
|
25029 | moment.fn.year = makeAccessor('FullYear', true);
|
25030 | moment.fn.years = deprecate('years accessor is deprecated. Use year instead.', makeAccessor('FullYear', true));
|
25031 |
|
25032 |
|
25033 | moment.fn.days = moment.fn.day;
|
25034 | moment.fn.months = moment.fn.month;
|
25035 | moment.fn.weeks = moment.fn.week;
|
25036 | moment.fn.isoWeeks = moment.fn.isoWeek;
|
25037 | moment.fn.quarters = moment.fn.quarter;
|
25038 |
|
25039 |
|
25040 | moment.fn.toJSON = moment.fn.toISOString;
|
25041 |
|
25042 | |
25043 |
|
25044 |
|
25045 |
|
25046 |
|
25047 | function daysToYears (days) {
|
25048 |
|
25049 | return days * 400 / 146097;
|
25050 | }
|
25051 |
|
25052 | function yearsToDays (years) {
|
25053 |
|
25054 |
|
25055 | return years * 146097 / 400;
|
25056 | }
|
25057 |
|
25058 | extend(moment.duration.fn = Duration.prototype, {
|
25059 |
|
25060 | _bubble : function () {
|
25061 | var milliseconds = this._milliseconds,
|
25062 | days = this._days,
|
25063 | months = this._months,
|
25064 | data = this._data,
|
25065 | seconds, minutes, hours, years = 0;
|
25066 |
|
25067 |
|
25068 |
|
25069 | data.milliseconds = milliseconds % 1000;
|
25070 |
|
25071 | seconds = absRound(milliseconds / 1000);
|
25072 | data.seconds = seconds % 60;
|
25073 |
|
25074 | minutes = absRound(seconds / 60);
|
25075 | data.minutes = minutes % 60;
|
25076 |
|
25077 | hours = absRound(minutes / 60);
|
25078 | data.hours = hours % 24;
|
25079 |
|
25080 | days += absRound(hours / 24);
|
25081 |
|
25082 |
|
25083 | years = absRound(daysToYears(days));
|
25084 | days -= absRound(yearsToDays(years));
|
25085 |
|
25086 |
|
25087 |
|
25088 | months += absRound(days / 30);
|
25089 | days %= 30;
|
25090 |
|
25091 |
|
25092 | years += absRound(months / 12);
|
25093 | months %= 12;
|
25094 |
|
25095 | data.days = days;
|
25096 | data.months = months;
|
25097 | data.years = years;
|
25098 | },
|
25099 |
|
25100 | abs : function () {
|
25101 | this._milliseconds = Math.abs(this._milliseconds);
|
25102 | this._days = Math.abs(this._days);
|
25103 | this._months = Math.abs(this._months);
|
25104 |
|
25105 | this._data.milliseconds = Math.abs(this._data.milliseconds);
|
25106 | this._data.seconds = Math.abs(this._data.seconds);
|
25107 | this._data.minutes = Math.abs(this._data.minutes);
|
25108 | this._data.hours = Math.abs(this._data.hours);
|
25109 | this._data.months = Math.abs(this._data.months);
|
25110 | this._data.years = Math.abs(this._data.years);
|
25111 |
|
25112 | return this;
|
25113 | },
|
25114 |
|
25115 | weeks : function () {
|
25116 | return absRound(this.days() / 7);
|
25117 | },
|
25118 |
|
25119 | valueOf : function () {
|
25120 | return this._milliseconds +
|
25121 | this._days * 864e5 +
|
25122 | (this._months % 12) * 2592e6 +
|
25123 | toInt(this._months / 12) * 31536e6;
|
25124 | },
|
25125 |
|
25126 | humanize : function (withSuffix) {
|
25127 | var output = relativeTime(this, !withSuffix, this.localeData());
|
25128 |
|
25129 | if (withSuffix) {
|
25130 | output = this.localeData().pastFuture(+this, output);
|
25131 | }
|
25132 |
|
25133 | return this.localeData().postformat(output);
|
25134 | },
|
25135 |
|
25136 | add : function (input, val) {
|
25137 |
|
25138 | var dur = moment.duration(input, val);
|
25139 |
|
25140 | this._milliseconds += dur._milliseconds;
|
25141 | this._days += dur._days;
|
25142 | this._months += dur._months;
|
25143 |
|
25144 | this._bubble();
|
25145 |
|
25146 | return this;
|
25147 | },
|
25148 |
|
25149 | subtract : function (input, val) {
|
25150 | var dur = moment.duration(input, val);
|
25151 |
|
25152 | this._milliseconds -= dur._milliseconds;
|
25153 | this._days -= dur._days;
|
25154 | this._months -= dur._months;
|
25155 |
|
25156 | this._bubble();
|
25157 |
|
25158 | return this;
|
25159 | },
|
25160 |
|
25161 | get : function (units) {
|
25162 | units = normalizeUnits(units);
|
25163 | return this[units.toLowerCase() + 's']();
|
25164 | },
|
25165 |
|
25166 | as : function (units) {
|
25167 | var days, months;
|
25168 | units = normalizeUnits(units);
|
25169 |
|
25170 | if (units === 'month' || units === 'year') {
|
25171 | days = this._days + this._milliseconds / 864e5;
|
25172 | months = this._months + daysToYears(days) * 12;
|
25173 | return units === 'month' ? months : months / 12;
|
25174 | } else {
|
25175 |
|
25176 | days = this._days + yearsToDays(this._months / 12);
|
25177 | switch (units) {
|
25178 | case 'week': return days / 7 + this._milliseconds / 6048e5;
|
25179 | case 'day': return days + this._milliseconds / 864e5;
|
25180 | case 'hour': return days * 24 + this._milliseconds / 36e5;
|
25181 | case 'minute': return days * 24 * 60 + this._milliseconds / 6e4;
|
25182 | case 'second': return days * 24 * 60 * 60 + this._milliseconds / 1000;
|
25183 |
|
25184 | case 'millisecond': return Math.floor(days * 24 * 60 * 60 * 1000) + this._milliseconds;
|
25185 | default: throw new Error('Unknown unit ' + units);
|
25186 | }
|
25187 | }
|
25188 | },
|
25189 |
|
25190 | lang : moment.fn.lang,
|
25191 | locale : moment.fn.locale,
|
25192 |
|
25193 | toIsoString : deprecate(
|
25194 | 'toIsoString() is deprecated. Please use toISOString() instead ' +
|
25195 | '(notice the capitals)',
|
25196 | function () {
|
25197 | return this.toISOString();
|
25198 | }
|
25199 | ),
|
25200 |
|
25201 | toISOString : function () {
|
25202 |
|
25203 | var years = Math.abs(this.years()),
|
25204 | months = Math.abs(this.months()),
|
25205 | days = Math.abs(this.days()),
|
25206 | hours = Math.abs(this.hours()),
|
25207 | minutes = Math.abs(this.minutes()),
|
25208 | seconds = Math.abs(this.seconds() + this.milliseconds() / 1000);
|
25209 |
|
25210 | if (!this.asSeconds()) {
|
25211 |
|
25212 |
|
25213 | return 'P0D';
|
25214 | }
|
25215 |
|
25216 | return (this.asSeconds() < 0 ? '-' : '') +
|
25217 | 'P' +
|
25218 | (years ? years + 'Y' : '') +
|
25219 | (months ? months + 'M' : '') +
|
25220 | (days ? days + 'D' : '') +
|
25221 | ((hours || minutes || seconds) ? 'T' : '') +
|
25222 | (hours ? hours + 'H' : '') +
|
25223 | (minutes ? minutes + 'M' : '') +
|
25224 | (seconds ? seconds + 'S' : '');
|
25225 | },
|
25226 |
|
25227 | localeData : function () {
|
25228 | return this._locale;
|
25229 | }
|
25230 | });
|
25231 |
|
25232 | moment.duration.fn.toString = moment.duration.fn.toISOString;
|
25233 |
|
25234 | function makeDurationGetter(name) {
|
25235 | moment.duration.fn[name] = function () {
|
25236 | return this._data[name];
|
25237 | };
|
25238 | }
|
25239 |
|
25240 | for (i in unitMillisecondFactors) {
|
25241 | if (hasOwnProp(unitMillisecondFactors, i)) {
|
25242 | makeDurationGetter(i.toLowerCase());
|
25243 | }
|
25244 | }
|
25245 |
|
25246 | moment.duration.fn.asMilliseconds = function () {
|
25247 | return this.as('ms');
|
25248 | };
|
25249 | moment.duration.fn.asSeconds = function () {
|
25250 | return this.as('s');
|
25251 | };
|
25252 | moment.duration.fn.asMinutes = function () {
|
25253 | return this.as('m');
|
25254 | };
|
25255 | moment.duration.fn.asHours = function () {
|
25256 | return this.as('h');
|
25257 | };
|
25258 | moment.duration.fn.asDays = function () {
|
25259 | return this.as('d');
|
25260 | };
|
25261 | moment.duration.fn.asWeeks = function () {
|
25262 | return this.as('weeks');
|
25263 | };
|
25264 | moment.duration.fn.asMonths = function () {
|
25265 | return this.as('M');
|
25266 | };
|
25267 | moment.duration.fn.asYears = function () {
|
25268 | return this.as('y');
|
25269 | };
|
25270 |
|
25271 | |
25272 |
|
25273 |
|
25274 |
|
25275 |
|
25276 |
|
25277 | moment.locale('en', {
|
25278 | ordinal : function (number) {
|
25279 | var b = number % 10,
|
25280 | output = (toInt(number % 100 / 10) === 1) ? 'th' :
|
25281 | (b === 1) ? 'st' :
|
25282 | (b === 2) ? 'nd' :
|
25283 | (b === 3) ? 'rd' : 'th';
|
25284 | return number + output;
|
25285 | }
|
25286 | });
|
25287 |
|
25288 |
|
25289 |
|
25290 | |
25291 |
|
25292 |
|
25293 |
|
25294 | function makeGlobal(shouldDeprecate) {
|
25295 |
|
25296 | if (typeof ender !== 'undefined') {
|
25297 | return;
|
25298 | }
|
25299 | oldGlobalMoment = globalScope.moment;
|
25300 | if (shouldDeprecate) {
|
25301 | globalScope.moment = deprecate(
|
25302 | 'Accessing Moment through the global scope is ' +
|
25303 | 'deprecated, and will be removed in an upcoming ' +
|
25304 | 'release.',
|
25305 | moment);
|
25306 | } else {
|
25307 | globalScope.moment = moment;
|
25308 | }
|
25309 | }
|
25310 |
|
25311 |
|
25312 | if (hasModule) {
|
25313 | module.exports = moment;
|
25314 | } else if (true) {
|
25315 | !(__WEBPACK_AMD_DEFINE_RESULT__ = function (require, exports, module) {
|
25316 | if (module.config && module.config() && module.config().noGlobal === true) {
|
25317 |
|
25318 | globalScope.moment = oldGlobalMoment;
|
25319 | }
|
25320 |
|
25321 | return moment;
|
25322 | }.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
25323 | makeGlobal(true);
|
25324 | } else {
|
25325 | makeGlobal();
|
25326 | }
|
25327 | }).call(this);
|
25328 |
|
25329 | }.call(exports, (function() { return this; }()), __webpack_require__(65)(module)))
|
25330 |
|
25331 | },
|
25332 |
|
25333 | function(module, exports, __webpack_require__) {
|
25334 |
|
25335 | var __WEBPACK_AMD_DEFINE_RESULT__; |
25336 |
|
25337 |
|
25338 |
|
25339 |
|
25340 |
|
25341 | (function(window, undefined) {
|
25342 | 'use strict';
|
25343 |
|
25344 | |
25345 |
|
25346 |
|
25347 |
|
25348 |
|
25349 |
|
25350 |
|
25351 |
|
25352 | |
25353 |
|
25354 |
|
25355 |
|
25356 |
|
25357 |
|
25358 |
|
25359 |
|
25360 |
|
25361 |
|
25362 |
|
25363 | var Hammer = function Hammer(element, options) {
|
25364 | return new Hammer.Instance(element, options || {});
|
25365 | };
|
25366 |
|
25367 | |
25368 |
|
25369 |
|
25370 |
|
25371 |
|
25372 |
|
25373 |
|
25374 | Hammer.VERSION = '1.1.3';
|
25375 |
|
25376 | |
25377 |
|
25378 |
|
25379 |
|
25380 |
|
25381 |
|
25382 |
|
25383 |
|
25384 |
|
25385 |
|
25386 |
|
25387 |
|
25388 |
|
25389 |
|
25390 | Hammer.defaults = {
|
25391 | |
25392 |
|
25393 |
|
25394 |
|
25395 |
|
25396 |
|
25397 | behavior: {
|
25398 | |
25399 |
|
25400 |
|
25401 |
|
25402 |
|
25403 |
|
25404 |
|
25405 | userSelect: 'none',
|
25406 |
|
25407 | |
25408 |
|
25409 |
|
25410 |
|
25411 |
|
25412 |
|
25413 |
|
25414 | touchAction: 'pan-y',
|
25415 |
|
25416 | |
25417 |
|
25418 |
|
25419 |
|
25420 |
|
25421 |
|
25422 |
|
25423 |
|
25424 | touchCallout: 'none',
|
25425 |
|
25426 | |
25427 |
|
25428 |
|
25429 |
|
25430 |
|
25431 |
|
25432 | contentZooming: 'none',
|
25433 |
|
25434 | |
25435 |
|
25436 |
|
25437 |
|
25438 |
|
25439 |
|
25440 |
|
25441 | userDrag: 'none',
|
25442 |
|
25443 | |
25444 |
|
25445 |
|
25446 |
|
25447 |
|
25448 |
|
25449 |
|
25450 |
|
25451 |
|
25452 |
|
25453 |
|
25454 | tapHighlightColor: 'rgba(0,0,0,0)'
|
25455 | }
|
25456 | };
|
25457 |
|
25458 | |
25459 |
|
25460 |
|
25461 |
|
25462 |
|
25463 |
|
25464 | Hammer.DOCUMENT = document;
|
25465 |
|
25466 | |
25467 |
|
25468 |
|
25469 |
|
25470 |
|
25471 | Hammer.HAS_POINTEREVENTS = navigator.pointerEnabled || navigator.msPointerEnabled;
|
25472 |
|
25473 | |
25474 |
|
25475 |
|
25476 |
|
25477 |
|
25478 | Hammer.HAS_TOUCHEVENTS = ('ontouchstart' in window);
|
25479 |
|
25480 | |
25481 |
|
25482 |
|
25483 |
|
25484 |
|
25485 | Hammer.IS_MOBILE = /mobile|tablet|ip(ad|hone|od)|android|silk/i.test(navigator.userAgent);
|
25486 |
|
25487 | |
25488 |
|
25489 |
|
25490 |
|
25491 |
|
25492 | Hammer.NO_MOUSEEVENTS = (Hammer.HAS_TOUCHEVENTS && Hammer.IS_MOBILE) || Hammer.HAS_POINTEREVENTS;
|
25493 |
|
25494 | |
25495 |
|
25496 |
|
25497 |
|
25498 |
|
25499 |
|
25500 | Hammer.CALCULATE_INTERVAL = 25;
|
25501 |
|
25502 | |
25503 |
|
25504 |
|
25505 |
|
25506 |
|
25507 |
|
25508 |
|
25509 |
|
25510 | var EVENT_TYPES = {};
|
25511 |
|
25512 | |
25513 |
|
25514 |
|
25515 |
|
25516 |
|
25517 |
|
25518 |
|
25519 | var DIRECTION_DOWN = Hammer.DIRECTION_DOWN = 'down';
|
25520 | var DIRECTION_LEFT = Hammer.DIRECTION_LEFT = 'left';
|
25521 | var DIRECTION_UP = Hammer.DIRECTION_UP = 'up';
|
25522 | var DIRECTION_RIGHT = Hammer.DIRECTION_RIGHT = 'right';
|
25523 |
|
25524 | |
25525 |
|
25526 |
|
25527 |
|
25528 |
|
25529 |
|
25530 |
|
25531 | var POINTER_MOUSE = Hammer.POINTER_MOUSE = 'mouse';
|
25532 | var POINTER_TOUCH = Hammer.POINTER_TOUCH = 'touch';
|
25533 | var POINTER_PEN = Hammer.POINTER_PEN = 'pen';
|
25534 |
|
25535 | |
25536 |
|
25537 |
|
25538 |
|
25539 |
|
25540 |
|
25541 |
|
25542 | var EVENT_START = Hammer.EVENT_START = 'start';
|
25543 | var EVENT_MOVE = Hammer.EVENT_MOVE = 'move';
|
25544 | var EVENT_END = Hammer.EVENT_END = 'end';
|
25545 | var EVENT_RELEASE = Hammer.EVENT_RELEASE = 'release';
|
25546 | var EVENT_TOUCH = Hammer.EVENT_TOUCH = 'touch';
|
25547 |
|
25548 | |
25549 |
|
25550 |
|
25551 |
|
25552 |
|
25553 |
|
25554 |
|
25555 | Hammer.READY = false;
|
25556 |
|
25557 | |
25558 |
|
25559 |
|
25560 |
|
25561 |
|
25562 | Hammer.plugins = Hammer.plugins || {};
|
25563 |
|
25564 | |
25565 |
|
25566 |
|
25567 |
|
25568 |
|
25569 |
|
25570 | Hammer.gestures = Hammer.gestures || {};
|
25571 |
|
25572 | |
25573 |
|
25574 |
|
25575 |
|
25576 |
|
25577 | function setup() {
|
25578 | if(Hammer.READY) {
|
25579 | return;
|
25580 | }
|
25581 |
|
25582 |
|
25583 | Event.determineEventTypes();
|
25584 |
|
25585 |
|
25586 | Utils.each(Hammer.gestures, function(gesture) {
|
25587 | Detection.register(gesture);
|
25588 | });
|
25589 |
|
25590 |
|
25591 | Event.onTouch(Hammer.DOCUMENT, EVENT_MOVE, Detection.detect);
|
25592 | Event.onTouch(Hammer.DOCUMENT, EVENT_END, Detection.detect);
|
25593 |
|
25594 |
|
25595 | Hammer.READY = true;
|
25596 | }
|
25597 |
|
25598 | |
25599 |
|
25600 |
|
25601 |
|
25602 |
|
25603 |
|
25604 | var Utils = Hammer.utils = {
|
25605 | |
25606 |
|
25607 |
|
25608 |
|
25609 |
|
25610 |
|
25611 |
|
25612 |
|
25613 |
|
25614 | extend: function extend(dest, src, merge) {
|
25615 | for(var key in src) {
|
25616 | if(!src.hasOwnProperty(key) || (dest[key] !== undefined && merge)) {
|
25617 | continue;
|
25618 | }
|
25619 | dest[key] = src[key];
|
25620 | }
|
25621 | return dest;
|
25622 | },
|
25623 |
|
25624 | |
25625 |
|
25626 |
|
25627 |
|
25628 |
|
25629 |
|
25630 |
|
25631 | on: function on(element, type, handler) {
|
25632 | element.addEventListener(type, handler, false);
|
25633 | },
|
25634 |
|
25635 | |
25636 |
|
25637 |
|
25638 |
|
25639 |
|
25640 |
|
25641 |
|
25642 | off: function off(element, type, handler) {
|
25643 | element.removeEventListener(type, handler, false);
|
25644 | },
|
25645 |
|
25646 | |
25647 |
|
25648 |
|
25649 |
|
25650 |
|
25651 |
|
25652 |
|
25653 |
|
25654 |
|
25655 |
|
25656 | each: function each(obj, iterator, context) {
|
25657 | var i, len;
|
25658 |
|
25659 |
|
25660 | if('forEach' in obj) {
|
25661 | obj.forEach(iterator, context);
|
25662 |
|
25663 | } else if(obj.length !== undefined) {
|
25664 | for(i = 0, len = obj.length; i < len; i++) {
|
25665 | if(iterator.call(context, obj[i], i, obj) === false) {
|
25666 | return;
|
25667 | }
|
25668 | }
|
25669 |
|
25670 | } else {
|
25671 | for(i in obj) {
|
25672 | if(obj.hasOwnProperty(i) &&
|
25673 | iterator.call(context, obj[i], i, obj) === false) {
|
25674 | return;
|
25675 | }
|
25676 | }
|
25677 | }
|
25678 | },
|
25679 |
|
25680 | |
25681 |
|
25682 |
|
25683 |
|
25684 |
|
25685 |
|
25686 |
|
25687 | inStr: function inStr(src, find) {
|
25688 | return src.indexOf(find) > -1;
|
25689 | },
|
25690 |
|
25691 | |
25692 |
|
25693 |
|
25694 |
|
25695 |
|
25696 |
|
25697 |
|
25698 | inArray: function inArray(src, find) {
|
25699 | if(src.indexOf) {
|
25700 | var index = src.indexOf(find);
|
25701 | return (index === -1) ? false : index;
|
25702 | } else {
|
25703 | for(var i = 0, len = src.length; i < len; i++) {
|
25704 | if(src[i] === find) {
|
25705 | return i;
|
25706 | }
|
25707 | }
|
25708 | return false;
|
25709 | }
|
25710 | },
|
25711 |
|
25712 | |
25713 |
|
25714 |
|
25715 |
|
25716 |
|
25717 |
|
25718 | toArray: function toArray(obj) {
|
25719 | return Array.prototype.slice.call(obj, 0);
|
25720 | },
|
25721 |
|
25722 | |
25723 |
|
25724 |
|
25725 |
|
25726 |
|
25727 |
|
25728 |
|
25729 | hasParent: function hasParent(node, parent) {
|
25730 | while(node) {
|
25731 | if(node == parent) {
|
25732 | return true;
|
25733 | }
|
25734 | node = node.parentNode;
|
25735 | }
|
25736 | return false;
|
25737 | },
|
25738 |
|
25739 | |
25740 |
|
25741 |
|
25742 |
|
25743 |
|
25744 |
|
25745 | getCenter: function getCenter(touches) {
|
25746 | var pageX = [],
|
25747 | pageY = [],
|
25748 | clientX = [],
|
25749 | clientY = [],
|
25750 | min = Math.min,
|
25751 | max = Math.max;
|
25752 |
|
25753 |
|
25754 | if(touches.length === 1) {
|
25755 | return {
|
25756 | pageX: touches[0].pageX,
|
25757 | pageY: touches[0].pageY,
|
25758 | clientX: touches[0].clientX,
|
25759 | clientY: touches[0].clientY
|
25760 | };
|
25761 | }
|
25762 |
|
25763 | Utils.each(touches, function(touch) {
|
25764 | pageX.push(touch.pageX);
|
25765 | pageY.push(touch.pageY);
|
25766 | clientX.push(touch.clientX);
|
25767 | clientY.push(touch.clientY);
|
25768 | });
|
25769 |
|
25770 | return {
|
25771 | pageX: (min.apply(Math, pageX) + max.apply(Math, pageX)) / 2,
|
25772 | pageY: (min.apply(Math, pageY) + max.apply(Math, pageY)) / 2,
|
25773 | clientX: (min.apply(Math, clientX) + max.apply(Math, clientX)) / 2,
|
25774 | clientY: (min.apply(Math, clientY) + max.apply(Math, clientY)) / 2
|
25775 | };
|
25776 | },
|
25777 |
|
25778 | |
25779 |
|
25780 |
|
25781 |
|
25782 |
|
25783 |
|
25784 |
|
25785 |
|
25786 | getVelocity: function getVelocity(deltaTime, deltaX, deltaY) {
|
25787 | return {
|
25788 | x: Math.abs(deltaX / deltaTime) || 0,
|
25789 | y: Math.abs(deltaY / deltaTime) || 0
|
25790 | };
|
25791 | },
|
25792 |
|
25793 | |
25794 |
|
25795 |
|
25796 |
|
25797 |
|
25798 |
|
25799 |
|
25800 | getAngle: function getAngle(touch1, touch2) {
|
25801 | var x = touch2.clientX - touch1.clientX,
|
25802 | y = touch2.clientY - touch1.clientY;
|
25803 |
|
25804 | return Math.atan2(y, x) * 180 / Math.PI;
|
25805 | },
|
25806 |
|
25807 | |
25808 |
|
25809 |
|
25810 |
|
25811 |
|
25812 |
|
25813 |
|
25814 | getDirection: function getDirection(touch1, touch2) {
|
25815 | var x = Math.abs(touch1.clientX - touch2.clientX),
|
25816 | y = Math.abs(touch1.clientY - touch2.clientY);
|
25817 |
|
25818 | if(x >= y) {
|
25819 | return touch1.clientX - touch2.clientX > 0 ? DIRECTION_LEFT : DIRECTION_RIGHT;
|
25820 | }
|
25821 | return touch1.clientY - touch2.clientY > 0 ? DIRECTION_UP : DIRECTION_DOWN;
|
25822 | },
|
25823 |
|
25824 | |
25825 |
|
25826 |
|
25827 |
|
25828 |
|
25829 |
|
25830 |
|
25831 | getDistance: function getDistance(touch1, touch2) {
|
25832 | var x = touch2.clientX - touch1.clientX,
|
25833 | y = touch2.clientY - touch1.clientY;
|
25834 |
|
25835 | return Math.sqrt((x * x) + (y * y));
|
25836 | },
|
25837 |
|
25838 | |
25839 |
|
25840 |
|
25841 |
|
25842 |
|
25843 |
|
25844 |
|
25845 |
|
25846 | getScale: function getScale(start, end) {
|
25847 |
|
25848 | if(start.length >= 2 && end.length >= 2) {
|
25849 | return this.getDistance(end[0], end[1]) / this.getDistance(start[0], start[1]);
|
25850 | }
|
25851 | return 1;
|
25852 | },
|
25853 |
|
25854 | |
25855 |
|
25856 |
|
25857 |
|
25858 |
|
25859 |
|
25860 |
|
25861 | getRotation: function getRotation(start, end) {
|
25862 |
|
25863 | if(start.length >= 2 && end.length >= 2) {
|
25864 | return this.getAngle(end[1], end[0]) - this.getAngle(start[1], start[0]);
|
25865 | }
|
25866 | return 0;
|
25867 | },
|
25868 |
|
25869 | |
25870 |
|
25871 |
|
25872 |
|
25873 |
|
25874 |
|
25875 | isVertical: function isVertical(direction) {
|
25876 | return direction == DIRECTION_UP || direction == DIRECTION_DOWN;
|
25877 | },
|
25878 |
|
25879 | |
25880 |
|
25881 |
|
25882 |
|
25883 |
|
25884 |
|
25885 |
|
25886 |
|
25887 | setPrefixedCss: function setPrefixedCss(element, prop, value, toggle) {
|
25888 | var prefixes = ['', 'Webkit', 'Moz', 'O', 'ms'];
|
25889 | prop = Utils.toCamelCase(prop);
|
25890 |
|
25891 | for(var i = 0; i < prefixes.length; i++) {
|
25892 | var p = prop;
|
25893 |
|
25894 | if(prefixes[i]) {
|
25895 | p = prefixes[i] + p.slice(0, 1).toUpperCase() + p.slice(1);
|
25896 | }
|
25897 |
|
25898 |
|
25899 | if(p in element.style) {
|
25900 | element.style[p] = (toggle == null || toggle) && value || '';
|
25901 | break;
|
25902 | }
|
25903 | }
|
25904 | },
|
25905 |
|
25906 | |
25907 |
|
25908 |
|
25909 |
|
25910 |
|
25911 |
|
25912 |
|
25913 |
|
25914 |
|
25915 |
|
25916 | toggleBehavior: function toggleBehavior(element, props, toggle) {
|
25917 | if(!props || !element || !element.style) {
|
25918 | return;
|
25919 | }
|
25920 |
|
25921 |
|
25922 | Utils.each(props, function(value, prop) {
|
25923 | Utils.setPrefixedCss(element, prop, value, toggle);
|
25924 | });
|
25925 |
|
25926 | var falseFn = toggle && function() {
|
25927 | return false;
|
25928 | };
|
25929 |
|
25930 |
|
25931 | if(props.userSelect == 'none') {
|
25932 | element.onselectstart = falseFn;
|
25933 | }
|
25934 |
|
25935 | if(props.userDrag == 'none') {
|
25936 | element.ondragstart = falseFn;
|
25937 | }
|
25938 | },
|
25939 |
|
25940 | |
25941 |
|
25942 |
|
25943 |
|
25944 |
|
25945 |
|
25946 | toCamelCase: function toCamelCase(str) {
|
25947 | return str.replace(/[_-]([a-z])/g, function(s) {
|
25948 | return s[1].toUpperCase();
|
25949 | });
|
25950 | }
|
25951 | };
|
25952 |
|
25953 |
|
25954 | |
25955 |
|
25956 |
|
25957 | |
25958 |
|
25959 |
|
25960 |
|
25961 | var Event = Hammer.event = {
|
25962 | |
25963 |
|
25964 |
|
25965 |
|
25966 |
|
25967 |
|
25968 |
|
25969 | preventMouseEvents: false,
|
25970 |
|
25971 | |
25972 |
|
25973 |
|
25974 |
|
25975 |
|
25976 |
|
25977 | started: false,
|
25978 |
|
25979 | |
25980 |
|
25981 |
|
25982 |
|
25983 |
|
25984 |
|
25985 | shouldDetect: false,
|
25986 |
|
25987 | |
25988 |
|
25989 |
|
25990 |
|
25991 |
|
25992 |
|
25993 |
|
25994 |
|
25995 |
|
25996 | on: function on(element, type, handler, hook) {
|
25997 | var types = type.split(' ');
|
25998 | Utils.each(types, function(type) {
|
25999 | Utils.on(element, type, handler);
|
26000 | hook && hook(type);
|
26001 | });
|
26002 | },
|
26003 |
|
26004 | |
26005 |
|
26006 |
|
26007 |
|
26008 |
|
26009 |
|
26010 |
|
26011 |
|
26012 |
|
26013 | off: function off(element, type, handler, hook) {
|
26014 | var types = type.split(' ');
|
26015 | Utils.each(types, function(type) {
|
26016 | Utils.off(element, type, handler);
|
26017 | hook && hook(type);
|
26018 | });
|
26019 | },
|
26020 |
|
26021 | |
26022 |
|
26023 |
|
26024 |
|
26025 |
|
26026 |
|
26027 |
|
26028 |
|
26029 |
|
26030 | onTouch: function onTouch(element, eventType, handler) {
|
26031 | var self = this;
|
26032 |
|
26033 | var onTouchHandler = function onTouchHandler(ev) {
|
26034 | var srcType = ev.type.toLowerCase(),
|
26035 | isPointer = Hammer.HAS_POINTEREVENTS,
|
26036 | isMouse = Utils.inStr(srcType, 'mouse'),
|
26037 | triggerType;
|
26038 |
|
26039 |
|
26040 |
|
26041 | if(isMouse && self.preventMouseEvents) {
|
26042 | return;
|
26043 |
|
26044 |
|
26045 | } else if(isMouse && eventType == EVENT_START && ev.button === 0) {
|
26046 | self.preventMouseEvents = false;
|
26047 | self.shouldDetect = true;
|
26048 | } else if(isPointer && eventType == EVENT_START) {
|
26049 | self.shouldDetect = (ev.buttons === 1 || PointerEvent.matchType(POINTER_TOUCH, ev));
|
26050 |
|
26051 | } else if(!isMouse && eventType == EVENT_START) {
|
26052 | self.preventMouseEvents = true;
|
26053 | self.shouldDetect = true;
|
26054 | }
|
26055 |
|
26056 |
|
26057 | if(isPointer && eventType != EVENT_END) {
|
26058 | PointerEvent.updatePointer(eventType, ev);
|
26059 | }
|
26060 |
|
26061 |
|
26062 | if(self.shouldDetect) {
|
26063 | triggerType = self.doDetect.call(self, ev, eventType, element, handler);
|
26064 | }
|
26065 |
|
26066 |
|
26067 |
|
26068 | if(triggerType == EVENT_END) {
|
26069 | self.preventMouseEvents = false;
|
26070 | self.shouldDetect = false;
|
26071 | PointerEvent.reset();
|
26072 |
|
26073 | }
|
26074 |
|
26075 | if(isPointer && eventType == EVENT_END) {
|
26076 | PointerEvent.updatePointer(eventType, ev);
|
26077 | }
|
26078 | };
|
26079 |
|
26080 | this.on(element, EVENT_TYPES[eventType], onTouchHandler);
|
26081 | return onTouchHandler;
|
26082 | },
|
26083 |
|
26084 | |
26085 |
|
26086 |
|
26087 |
|
26088 |
|
26089 |
|
26090 |
|
26091 |
|
26092 |
|
26093 |
|
26094 | doDetect: function doDetect(ev, eventType, element, handler) {
|
26095 | var touchList = this.getTouchList(ev, eventType);
|
26096 | var touchListLength = touchList.length;
|
26097 | var triggerType = eventType;
|
26098 | var triggerChange = touchList.trigger;
|
26099 | var changedLength = touchListLength;
|
26100 |
|
26101 |
|
26102 | if(eventType == EVENT_START) {
|
26103 | triggerChange = EVENT_TOUCH;
|
26104 |
|
26105 | } else if(eventType == EVENT_END) {
|
26106 | triggerChange = EVENT_RELEASE;
|
26107 |
|
26108 |
|
26109 | changedLength = touchList.length - ((ev.changedTouches) ? ev.changedTouches.length : 1);
|
26110 | }
|
26111 |
|
26112 |
|
26113 |
|
26114 |
|
26115 | if(changedLength > 0 && this.started) {
|
26116 | triggerType = EVENT_MOVE;
|
26117 | }
|
26118 |
|
26119 |
|
26120 | this.started = true;
|
26121 |
|
26122 |
|
26123 | var evData = this.collectEventData(element, triggerType, touchList, ev);
|
26124 |
|
26125 |
|
26126 |
|
26127 | if(eventType != EVENT_END) {
|
26128 | handler.call(Detection, evData);
|
26129 | }
|
26130 |
|
26131 |
|
26132 | if(triggerChange) {
|
26133 | evData.changedLength = changedLength;
|
26134 | evData.eventType = triggerChange;
|
26135 |
|
26136 | handler.call(Detection, evData);
|
26137 |
|
26138 | evData.eventType = triggerType;
|
26139 | delete evData.changedLength;
|
26140 | }
|
26141 |
|
26142 |
|
26143 | if(triggerType == EVENT_END) {
|
26144 | handler.call(Detection, evData);
|
26145 |
|
26146 |
|
26147 |
|
26148 | this.started = false;
|
26149 | }
|
26150 |
|
26151 | return triggerType;
|
26152 | },
|
26153 |
|
26154 | |
26155 |
|
26156 |
|
26157 |
|
26158 |
|
26159 |
|
26160 |
|
26161 | determineEventTypes: function determineEventTypes() {
|
26162 | var types;
|
26163 | if(Hammer.HAS_POINTEREVENTS) {
|
26164 | if(window.PointerEvent) {
|
26165 | types = [
|
26166 | 'pointerdown',
|
26167 | 'pointermove',
|
26168 | 'pointerup pointercancel lostpointercapture'
|
26169 | ];
|
26170 | } else {
|
26171 | types = [
|
26172 | 'MSPointerDown',
|
26173 | 'MSPointerMove',
|
26174 | 'MSPointerUp MSPointerCancel MSLostPointerCapture'
|
26175 | ];
|
26176 | }
|
26177 | } else if(Hammer.NO_MOUSEEVENTS) {
|
26178 | types = [
|
26179 | 'touchstart',
|
26180 | 'touchmove',
|
26181 | 'touchend touchcancel'
|
26182 | ];
|
26183 | } else {
|
26184 | types = [
|
26185 | 'touchstart mousedown',
|
26186 | 'touchmove mousemove',
|
26187 | 'touchend touchcancel mouseup'
|
26188 | ];
|
26189 | }
|
26190 |
|
26191 | EVENT_TYPES[EVENT_START] = types[0];
|
26192 | EVENT_TYPES[EVENT_MOVE] = types[1];
|
26193 | EVENT_TYPES[EVENT_END] = types[2];
|
26194 | return EVENT_TYPES;
|
26195 | },
|
26196 |
|
26197 | |
26198 |
|
26199 |
|
26200 |
|
26201 |
|
26202 |
|
26203 |
|
26204 | getTouchList: function getTouchList(ev, eventType) {
|
26205 |
|
26206 | if(Hammer.HAS_POINTEREVENTS) {
|
26207 | return PointerEvent.getTouchList();
|
26208 | }
|
26209 |
|
26210 |
|
26211 | if(ev.touches) {
|
26212 | if(eventType == EVENT_MOVE) {
|
26213 | return ev.touches;
|
26214 | }
|
26215 |
|
26216 | var identifiers = [];
|
26217 | var concat = [].concat(Utils.toArray(ev.touches), Utils.toArray(ev.changedTouches));
|
26218 | var touchList = [];
|
26219 |
|
26220 | Utils.each(concat, function(touch) {
|
26221 | if(Utils.inArray(identifiers, touch.identifier) === false) {
|
26222 | touchList.push(touch);
|
26223 | }
|
26224 | identifiers.push(touch.identifier);
|
26225 | });
|
26226 |
|
26227 | return touchList;
|
26228 | }
|
26229 |
|
26230 |
|
26231 | ev.identifier = 1;
|
26232 | return [ev];
|
26233 | },
|
26234 |
|
26235 | |
26236 |
|
26237 |
|
26238 |
|
26239 |
|
26240 |
|
26241 |
|
26242 |
|
26243 |
|
26244 | collectEventData: function collectEventData(element, eventType, touches, ev) {
|
26245 |
|
26246 | var pointerType = POINTER_TOUCH;
|
26247 | if(Utils.inStr(ev.type, 'mouse') || PointerEvent.matchType(POINTER_MOUSE, ev)) {
|
26248 | pointerType = POINTER_MOUSE;
|
26249 | } else if(PointerEvent.matchType(POINTER_PEN, ev)) {
|
26250 | pointerType = POINTER_PEN;
|
26251 | }
|
26252 |
|
26253 | return {
|
26254 | center: Utils.getCenter(touches),
|
26255 | timeStamp: Date.now(),
|
26256 | target: ev.target,
|
26257 | touches: touches,
|
26258 | eventType: eventType,
|
26259 | pointerType: pointerType,
|
26260 | srcEvent: ev,
|
26261 |
|
26262 | |
26263 |
|
26264 |
|
26265 |
|
26266 | preventDefault: function() {
|
26267 | var srcEvent = this.srcEvent;
|
26268 | srcEvent.preventManipulation && srcEvent.preventManipulation();
|
26269 | srcEvent.preventDefault && srcEvent.preventDefault();
|
26270 | },
|
26271 |
|
26272 | |
26273 |
|
26274 |
|
26275 | stopPropagation: function() {
|
26276 | this.srcEvent.stopPropagation();
|
26277 | },
|
26278 |
|
26279 | |
26280 |
|
26281 |
|
26282 |
|
26283 |
|
26284 | stopDetect: function() {
|
26285 | return Detection.stopDetect();
|
26286 | }
|
26287 | };
|
26288 | }
|
26289 | };
|
26290 |
|
26291 |
|
26292 | |
26293 |
|
26294 |
|
26295 |
|
26296 |
|
26297 |
|
26298 | var PointerEvent = Hammer.PointerEvent = {
|
26299 | |
26300 |
|
26301 |
|
26302 |
|
26303 |
|
26304 | pointers: {},
|
26305 |
|
26306 | |
26307 |
|
26308 |
|
26309 |
|
26310 |
|
26311 | getTouchList: function getTouchList() {
|
26312 | var touchlist = [];
|
26313 |
|
26314 | Utils.each(this.pointers, function(pointer) {
|
26315 | touchlist.push(pointer);
|
26316 | });
|
26317 | return touchlist;
|
26318 | },
|
26319 |
|
26320 | |
26321 |
|
26322 |
|
26323 |
|
26324 |
|
26325 |
|
26326 | updatePointer: function updatePointer(eventType, pointerEvent) {
|
26327 | if(eventType == EVENT_END || (eventType != EVENT_END && pointerEvent.buttons !== 1)) {
|
26328 | delete this.pointers[pointerEvent.pointerId];
|
26329 | } else {
|
26330 | pointerEvent.identifier = pointerEvent.pointerId;
|
26331 | this.pointers[pointerEvent.pointerId] = pointerEvent;
|
26332 | }
|
26333 | },
|
26334 |
|
26335 | |
26336 |
|
26337 |
|
26338 |
|
26339 |
|
26340 |
|
26341 | matchType: function matchType(pointerType, ev) {
|
26342 | if(!ev.pointerType) {
|
26343 | return false;
|
26344 | }
|
26345 |
|
26346 | var pt = ev.pointerType,
|
26347 | types = {};
|
26348 |
|
26349 | types[POINTER_MOUSE] = (pt === (ev.MSPOINTER_TYPE_MOUSE || POINTER_MOUSE));
|
26350 | types[POINTER_TOUCH] = (pt === (ev.MSPOINTER_TYPE_TOUCH || POINTER_TOUCH));
|
26351 | types[POINTER_PEN] = (pt === (ev.MSPOINTER_TYPE_PEN || POINTER_PEN));
|
26352 | return types[pointerType];
|
26353 | },
|
26354 |
|
26355 | |
26356 |
|
26357 |
|
26358 |
|
26359 | reset: function resetList() {
|
26360 | this.pointers = {};
|
26361 | }
|
26362 | };
|
26363 |
|
26364 |
|
26365 | |
26366 |
|
26367 |
|
26368 |
|
26369 |
|
26370 |
|
26371 | var Detection = Hammer.detection = {
|
26372 |
|
26373 | gestures: [],
|
26374 |
|
26375 |
|
26376 | current: null,
|
26377 |
|
26378 |
|
26379 |
|
26380 | previous: null,
|
26381 |
|
26382 |
|
26383 | stopped: false,
|
26384 |
|
26385 | |
26386 |
|
26387 |
|
26388 |
|
26389 |
|
26390 |
|
26391 | startDetect: function startDetect(inst, eventData) {
|
26392 |
|
26393 | if(this.current) {
|
26394 | return;
|
26395 | }
|
26396 |
|
26397 | this.stopped = false;
|
26398 |
|
26399 |
|
26400 | this.current = {
|
26401 | inst: inst,
|
26402 | startEvent: Utils.extend({}, eventData),
|
26403 | lastEvent: false,
|
26404 | lastCalcEvent: false,
|
26405 | futureCalcEvent: false,
|
26406 | lastCalcData: {},
|
26407 | name: ''
|
26408 | };
|
26409 |
|
26410 | this.detect(eventData);
|
26411 | },
|
26412 |
|
26413 | |
26414 |
|
26415 |
|
26416 |
|
26417 |
|
26418 |
|
26419 | detect: function detect(eventData) {
|
26420 | if(!this.current || this.stopped) {
|
26421 | return;
|
26422 | }
|
26423 |
|
26424 |
|
26425 | eventData = this.extendEventData(eventData);
|
26426 |
|
26427 |
|
26428 | var inst = this.current.inst,
|
26429 | instOptions = inst.options;
|
26430 |
|
26431 |
|
26432 | Utils.each(this.gestures, function triggerGesture(gesture) {
|
26433 |
|
26434 | if(!this.stopped && inst.enabled && instOptions[gesture.name]) {
|
26435 | gesture.handler.call(gesture, eventData, inst);
|
26436 | }
|
26437 | }, this);
|
26438 |
|
26439 |
|
26440 | if(this.current) {
|
26441 | this.current.lastEvent = eventData;
|
26442 | }
|
26443 |
|
26444 | if(eventData.eventType == EVENT_END) {
|
26445 | this.stopDetect();
|
26446 | }
|
26447 |
|
26448 | return eventData;
|
26449 | },
|
26450 |
|
26451 | |
26452 |
|
26453 |
|
26454 |
|
26455 |
|
26456 |
|
26457 | stopDetect: function stopDetect() {
|
26458 |
|
26459 |
|
26460 | this.previous = Utils.extend({}, this.current);
|
26461 |
|
26462 |
|
26463 | this.current = null;
|
26464 | this.stopped = true;
|
26465 | },
|
26466 |
|
26467 | |
26468 |
|
26469 |
|
26470 |
|
26471 |
|
26472 |
|
26473 |
|
26474 |
|
26475 |
|
26476 | getCalculatedData: function getCalculatedData(ev, center, deltaTime, deltaX, deltaY) {
|
26477 | var cur = this.current,
|
26478 | recalc = false,
|
26479 | calcEv = cur.lastCalcEvent,
|
26480 | calcData = cur.lastCalcData;
|
26481 |
|
26482 | if(calcEv && ev.timeStamp - calcEv.timeStamp > Hammer.CALCULATE_INTERVAL) {
|
26483 | center = calcEv.center;
|
26484 | deltaTime = ev.timeStamp - calcEv.timeStamp;
|
26485 | deltaX = ev.center.clientX - calcEv.center.clientX;
|
26486 | deltaY = ev.center.clientY - calcEv.center.clientY;
|
26487 | recalc = true;
|
26488 | }
|
26489 |
|
26490 | if(ev.eventType == EVENT_TOUCH || ev.eventType == EVENT_RELEASE) {
|
26491 | cur.futureCalcEvent = ev;
|
26492 | }
|
26493 |
|
26494 | if(!cur.lastCalcEvent || recalc) {
|
26495 | calcData.velocity = Utils.getVelocity(deltaTime, deltaX, deltaY);
|
26496 | calcData.angle = Utils.getAngle(center, ev.center);
|
26497 | calcData.direction = Utils.getDirection(center, ev.center);
|
26498 |
|
26499 | cur.lastCalcEvent = cur.futureCalcEvent || ev;
|
26500 | cur.futureCalcEvent = ev;
|
26501 | }
|
26502 |
|
26503 | ev.velocityX = calcData.velocity.x;
|
26504 | ev.velocityY = calcData.velocity.y;
|
26505 | ev.interimAngle = calcData.angle;
|
26506 | ev.interimDirection = calcData.direction;
|
26507 | },
|
26508 |
|
26509 | |
26510 |
|
26511 |
|
26512 |
|
26513 |
|
26514 |
|
26515 | extendEventData: function extendEventData(ev) {
|
26516 | var cur = this.current,
|
26517 | startEv = cur.startEvent,
|
26518 | lastEv = cur.lastEvent || startEv;
|
26519 |
|
26520 |
|
26521 | if(ev.eventType == EVENT_TOUCH || ev.eventType == EVENT_RELEASE) {
|
26522 | startEv.touches = [];
|
26523 | Utils.each(ev.touches, function(touch) {
|
26524 | startEv.touches.push({
|
26525 | clientX: touch.clientX,
|
26526 | clientY: touch.clientY
|
26527 | });
|
26528 | });
|
26529 | }
|
26530 |
|
26531 | var deltaTime = ev.timeStamp - startEv.timeStamp,
|
26532 | deltaX = ev.center.clientX - startEv.center.clientX,
|
26533 | deltaY = ev.center.clientY - startEv.center.clientY;
|
26534 |
|
26535 | this.getCalculatedData(ev, lastEv.center, deltaTime, deltaX, deltaY);
|
26536 |
|
26537 | Utils.extend(ev, {
|
26538 | startEvent: startEv,
|
26539 |
|
26540 | deltaTime: deltaTime,
|
26541 | deltaX: deltaX,
|
26542 | deltaY: deltaY,
|
26543 |
|
26544 | distance: Utils.getDistance(startEv.center, ev.center),
|
26545 | angle: Utils.getAngle(startEv.center, ev.center),
|
26546 | direction: Utils.getDirection(startEv.center, ev.center),
|
26547 | scale: Utils.getScale(startEv.touches, ev.touches),
|
26548 | rotation: Utils.getRotation(startEv.touches, ev.touches)
|
26549 | });
|
26550 |
|
26551 | return ev;
|
26552 | },
|
26553 |
|
26554 | |
26555 |
|
26556 |
|
26557 |
|
26558 |
|
26559 |
|
26560 | register: function register(gesture) {
|
26561 |
|
26562 | var options = gesture.defaults || {};
|
26563 | if(options[gesture.name] === undefined) {
|
26564 | options[gesture.name] = true;
|
26565 | }
|
26566 |
|
26567 |
|
26568 | Utils.extend(Hammer.defaults, options, true);
|
26569 |
|
26570 |
|
26571 | gesture.index = gesture.index || 1000;
|
26572 |
|
26573 |
|
26574 | this.gestures.push(gesture);
|
26575 |
|
26576 |
|
26577 | this.gestures.sort(function(a, b) {
|
26578 | if(a.index < b.index) {
|
26579 | return -1;
|
26580 | }
|
26581 | if(a.index > b.index) {
|
26582 | return 1;
|
26583 | }
|
26584 | return 0;
|
26585 | });
|
26586 |
|
26587 | return this.gestures;
|
26588 | }
|
26589 | };
|
26590 |
|
26591 |
|
26592 | |
26593 |
|
26594 |
|
26595 |
|
26596 | |
26597 |
|
26598 |
|
26599 |
|
26600 |
|
26601 |
|
26602 |
|
26603 |
|
26604 |
|
26605 |
|
26606 | Hammer.Instance = function(element, options) {
|
26607 | var self = this;
|
26608 |
|
26609 |
|
26610 |
|
26611 | setup();
|
26612 |
|
26613 | |
26614 |
|
26615 |
|
26616 |
|
26617 | this.element = element;
|
26618 |
|
26619 | |
26620 |
|
26621 |
|
26622 |
|
26623 |
|
26624 | this.enabled = true;
|
26625 |
|
26626 | |
26627 |
|
26628 |
|
26629 |
|
26630 |
|
26631 |
|
26632 | Utils.each(options, function(value, name) {
|
26633 | delete options[name];
|
26634 | options[Utils.toCamelCase(name)] = value;
|
26635 | });
|
26636 |
|
26637 | this.options = Utils.extend(Utils.extend({}, Hammer.defaults), options || {});
|
26638 |
|
26639 |
|
26640 | if(this.options.behavior) {
|
26641 | Utils.toggleBehavior(this.element, this.options.behavior, true);
|
26642 | }
|
26643 |
|
26644 | |
26645 |
|
26646 |
|
26647 |
|
26648 |
|
26649 | this.eventStartHandler = Event.onTouch(element, EVENT_START, function(ev) {
|
26650 | if(self.enabled && ev.eventType == EVENT_START) {
|
26651 | Detection.startDetect(self, ev);
|
26652 | } else if(ev.eventType == EVENT_TOUCH) {
|
26653 | Detection.detect(ev);
|
26654 | }
|
26655 | });
|
26656 |
|
26657 | |
26658 |
|
26659 |
|
26660 |
|
26661 |
|
26662 | this.eventHandlers = [];
|
26663 | };
|
26664 |
|
26665 | Hammer.Instance.prototype = {
|
26666 | |
26667 |
|
26668 |
|
26669 |
|
26670 |
|
26671 |
|
26672 |
|
26673 |
|
26674 | on: function onEvent(gestures, handler) {
|
26675 | var self = this;
|
26676 | Event.on(self.element, gestures, handler, function(type) {
|
26677 | self.eventHandlers.push({ gesture: type, handler: handler });
|
26678 | });
|
26679 | return self;
|
26680 | },
|
26681 |
|
26682 | |
26683 |
|
26684 |
|
26685 |
|
26686 |
|
26687 |
|
26688 |
|
26689 | off: function offEvent(gestures, handler) {
|
26690 | var self = this;
|
26691 |
|
26692 | Event.off(self.element, gestures, handler, function(type) {
|
26693 | var index = Utils.inArray({ gesture: type, handler: handler });
|
26694 | if(index !== false) {
|
26695 | self.eventHandlers.splice(index, 1);
|
26696 | }
|
26697 | });
|
26698 | return self;
|
26699 | },
|
26700 |
|
26701 | |
26702 |
|
26703 |
|
26704 |
|
26705 |
|
26706 |
|
26707 |
|
26708 | trigger: function triggerEvent(gesture, eventData) {
|
26709 |
|
26710 | if(!eventData) {
|
26711 | eventData = {};
|
26712 | }
|
26713 |
|
26714 |
|
26715 | var event = Hammer.DOCUMENT.createEvent('Event');
|
26716 | event.initEvent(gesture, true, true);
|
26717 | event.gesture = eventData;
|
26718 |
|
26719 |
|
26720 |
|
26721 | var element = this.element;
|
26722 | if(Utils.hasParent(eventData.target, element)) {
|
26723 | element = eventData.target;
|
26724 | }
|
26725 |
|
26726 | element.dispatchEvent(event);
|
26727 | return this;
|
26728 | },
|
26729 |
|
26730 | |
26731 |
|
26732 |
|
26733 |
|
26734 |
|
26735 |
|
26736 | enable: function enable(state) {
|
26737 | this.enabled = state;
|
26738 | return this;
|
26739 | },
|
26740 |
|
26741 | |
26742 |
|
26743 |
|
26744 |
|
26745 |
|
26746 | dispose: function dispose() {
|
26747 | var i, eh;
|
26748 |
|
26749 |
|
26750 | Utils.toggleBehavior(this.element, this.options.behavior, false);
|
26751 |
|
26752 |
|
26753 | for(i = -1; (eh = this.eventHandlers[++i]);) {
|
26754 | Utils.off(this.element, eh.gesture, eh.handler);
|
26755 | }
|
26756 |
|
26757 | this.eventHandlers = [];
|
26758 |
|
26759 |
|
26760 | Event.off(this.element, EVENT_TYPES[EVENT_START], this.eventStartHandler);
|
26761 |
|
26762 | return null;
|
26763 | }
|
26764 | };
|
26765 |
|
26766 |
|
26767 | |
26768 |
|
26769 |
|
26770 | |
26771 |
|
26772 |
|
26773 |
|
26774 |
|
26775 |
|
26776 |
|
26777 |
|
26778 |
|
26779 |
|
26780 |
|
26781 |
|
26782 |
|
26783 | |
26784 |
|
26785 |
|
26786 |
|
26787 | |
26788 |
|
26789 |
|
26790 |
|
26791 | |
26792 |
|
26793 |
|
26794 |
|
26795 | |
26796 |
|
26797 |
|
26798 |
|
26799 | |
26800 |
|
26801 |
|
26802 |
|
26803 | |
26804 |
|
26805 |
|
26806 |
|
26807 | |
26808 |
|
26809 |
|
26810 |
|
26811 |
|
26812 | |
26813 |
|
26814 |
|
26815 | (function(name) {
|
26816 | var triggered = false;
|
26817 |
|
26818 | function dragGesture(ev, inst) {
|
26819 | var cur = Detection.current;
|
26820 |
|
26821 |
|
26822 | if(inst.options.dragMaxTouches > 0 &&
|
26823 | ev.touches.length > inst.options.dragMaxTouches) {
|
26824 | return;
|
26825 | }
|
26826 |
|
26827 | switch(ev.eventType) {
|
26828 | case EVENT_START:
|
26829 | triggered = false;
|
26830 | break;
|
26831 |
|
26832 | case EVENT_MOVE:
|
26833 |
|
26834 |
|
26835 | if(ev.distance < inst.options.dragMinDistance &&
|
26836 | cur.name != name) {
|
26837 | return;
|
26838 | }
|
26839 |
|
26840 | var startCenter = cur.startEvent.center;
|
26841 |
|
26842 |
|
26843 | if(cur.name != name) {
|
26844 | cur.name = name;
|
26845 | if(inst.options.dragDistanceCorrection && ev.distance > 0) {
|
26846 |
|
26847 |
|
26848 |
|
26849 | var factor = Math.abs(inst.options.dragMinDistance / ev.distance);
|
26850 | startCenter.pageX += ev.deltaX * factor;
|
26851 | startCenter.pageY += ev.deltaY * factor;
|
26852 | startCenter.clientX += ev.deltaX * factor;
|
26853 | startCenter.clientY += ev.deltaY * factor;
|
26854 |
|
26855 |
|
26856 | ev = Detection.extendEventData(ev);
|
26857 | }
|
26858 | }
|
26859 |
|
26860 |
|
26861 | if(cur.lastEvent.dragLockToAxis ||
|
26862 | ( inst.options.dragLockToAxis &&
|
26863 | inst.options.dragLockMinDistance <= ev.distance
|
26864 | )) {
|
26865 | ev.dragLockToAxis = true;
|
26866 | }
|
26867 |
|
26868 |
|
26869 | var lastDirection = cur.lastEvent.direction;
|
26870 | if(ev.dragLockToAxis && lastDirection !== ev.direction) {
|
26871 | if(Utils.isVertical(lastDirection)) {
|
26872 | ev.direction = (ev.deltaY < 0) ? DIRECTION_UP : DIRECTION_DOWN;
|
26873 | } else {
|
26874 | ev.direction = (ev.deltaX < 0) ? DIRECTION_LEFT : DIRECTION_RIGHT;
|
26875 | }
|
26876 | }
|
26877 |
|
26878 |
|
26879 | if(!triggered) {
|
26880 | inst.trigger(name + 'start', ev);
|
26881 | triggered = true;
|
26882 | }
|
26883 |
|
26884 |
|
26885 | inst.trigger(name, ev);
|
26886 | inst.trigger(name + ev.direction, ev);
|
26887 |
|
26888 | var isVertical = Utils.isVertical(ev.direction);
|
26889 |
|
26890 |
|
26891 | if((inst.options.dragBlockVertical && isVertical) ||
|
26892 | (inst.options.dragBlockHorizontal && !isVertical)) {
|
26893 | ev.preventDefault();
|
26894 | }
|
26895 | break;
|
26896 |
|
26897 | case EVENT_RELEASE:
|
26898 | if(triggered && ev.changedLength <= inst.options.dragMaxTouches) {
|
26899 | inst.trigger(name + 'end', ev);
|
26900 | triggered = false;
|
26901 | }
|
26902 | break;
|
26903 |
|
26904 | case EVENT_END:
|
26905 | triggered = false;
|
26906 | break;
|
26907 | }
|
26908 | }
|
26909 |
|
26910 | Hammer.gestures.Drag = {
|
26911 | name: name,
|
26912 | index: 50,
|
26913 | handler: dragGesture,
|
26914 | defaults: {
|
26915 | |
26916 |
|
26917 |
|
26918 |
|
26919 |
|
26920 |
|
26921 | dragMinDistance: 10,
|
26922 |
|
26923 | |
26924 |
|
26925 |
|
26926 |
|
26927 |
|
26928 |
|
26929 |
|
26930 |
|
26931 |
|
26932 | dragDistanceCorrection: true,
|
26933 |
|
26934 | |
26935 |
|
26936 |
|
26937 |
|
26938 |
|
26939 |
|
26940 | dragMaxTouches: 1,
|
26941 |
|
26942 | |
26943 |
|
26944 |
|
26945 |
|
26946 |
|
26947 |
|
26948 |
|
26949 |
|
26950 | dragBlockHorizontal: false,
|
26951 |
|
26952 | |
26953 |
|
26954 |
|
26955 |
|
26956 |
|
26957 |
|
26958 | dragBlockVertical: false,
|
26959 |
|
26960 | |
26961 |
|
26962 |
|
26963 |
|
26964 |
|
26965 |
|
26966 |
|
26967 | dragLockToAxis: false,
|
26968 |
|
26969 | |
26970 |
|
26971 |
|
26972 |
|
26973 |
|
26974 |
|
26975 |
|
26976 | dragLockMinDistance: 25
|
26977 | }
|
26978 | };
|
26979 | })('drag');
|
26980 |
|
26981 | |
26982 |
|
26983 |
|
26984 | |
26985 |
|
26986 |
|
26987 |
|
26988 |
|
26989 |
|
26990 |
|
26991 | |
26992 |
|
26993 |
|
26994 |
|
26995 | Hammer.gestures.Gesture = {
|
26996 | name: 'gesture',
|
26997 | index: 1337,
|
26998 | handler: function releaseGesture(ev, inst) {
|
26999 | inst.trigger(this.name, ev);
|
27000 | }
|
27001 | };
|
27002 |
|
27003 | |
27004 |
|
27005 |
|
27006 | |
27007 |
|
27008 |
|
27009 |
|
27010 |
|
27011 |
|
27012 | |
27013 |
|
27014 |
|
27015 |
|
27016 |
|
27017 | |
27018 |
|
27019 |
|
27020 | (function(name) {
|
27021 | var timer;
|
27022 |
|
27023 | function holdGesture(ev, inst) {
|
27024 | var options = inst.options,
|
27025 | current = Detection.current;
|
27026 |
|
27027 | switch(ev.eventType) {
|
27028 | case EVENT_START:
|
27029 | clearTimeout(timer);
|
27030 |
|
27031 |
|
27032 | current.name = name;
|
27033 |
|
27034 |
|
27035 |
|
27036 | timer = setTimeout(function() {
|
27037 | if(current && current.name == name) {
|
27038 | inst.trigger(name, ev);
|
27039 | }
|
27040 | }, options.holdTimeout);
|
27041 | break;
|
27042 |
|
27043 | case EVENT_MOVE:
|
27044 | if(ev.distance > options.holdThreshold) {
|
27045 | clearTimeout(timer);
|
27046 | }
|
27047 | break;
|
27048 |
|
27049 | case EVENT_RELEASE:
|
27050 | clearTimeout(timer);
|
27051 | break;
|
27052 | }
|
27053 | }
|
27054 |
|
27055 | Hammer.gestures.Hold = {
|
27056 | name: name,
|
27057 | index: 10,
|
27058 | defaults: {
|
27059 | |
27060 |
|
27061 |
|
27062 |
|
27063 |
|
27064 | holdTimeout: 500,
|
27065 |
|
27066 | |
27067 |
|
27068 |
|
27069 |
|
27070 |
|
27071 |
|
27072 | holdThreshold: 2
|
27073 | },
|
27074 | handler: holdGesture
|
27075 | };
|
27076 | })('hold');
|
27077 |
|
27078 | |
27079 |
|
27080 |
|
27081 | |
27082 |
|
27083 |
|
27084 |
|
27085 |
|
27086 |
|
27087 | |
27088 |
|
27089 |
|
27090 |
|
27091 | Hammer.gestures.Release = {
|
27092 | name: 'release',
|
27093 | index: Infinity,
|
27094 | handler: function releaseGesture(ev, inst) {
|
27095 | if(ev.eventType == EVENT_RELEASE) {
|
27096 | inst.trigger(this.name, ev);
|
27097 | }
|
27098 | }
|
27099 | };
|
27100 |
|
27101 | |
27102 |
|
27103 |
|
27104 | |
27105 |
|
27106 |
|
27107 |
|
27108 |
|
27109 |
|
27110 |
|
27111 |
|
27112 |
|
27113 |
|
27114 |
|
27115 |
|
27116 |
|
27117 | |
27118 |
|
27119 |
|
27120 |
|
27121 | |
27122 |
|
27123 |
|
27124 |
|
27125 | |
27126 |
|
27127 |
|
27128 |
|
27129 | |
27130 |
|
27131 |
|
27132 |
|
27133 | |
27134 |
|
27135 |
|
27136 |
|
27137 | Hammer.gestures.Swipe = {
|
27138 | name: 'swipe',
|
27139 | index: 40,
|
27140 | defaults: {
|
27141 | |
27142 |
|
27143 |
|
27144 |
|
27145 |
|
27146 | swipeMinTouches: 1,
|
27147 |
|
27148 | |
27149 |
|
27150 |
|
27151 |
|
27152 |
|
27153 | swipeMaxTouches: 1,
|
27154 |
|
27155 | |
27156 |
|
27157 |
|
27158 |
|
27159 |
|
27160 |
|
27161 | swipeVelocityX: 0.6,
|
27162 |
|
27163 | |
27164 |
|
27165 |
|
27166 |
|
27167 |
|
27168 |
|
27169 | swipeVelocityY: 0.6
|
27170 | },
|
27171 |
|
27172 | handler: function swipeGesture(ev, inst) {
|
27173 | if(ev.eventType == EVENT_RELEASE) {
|
27174 | var touches = ev.touches.length,
|
27175 | options = inst.options;
|
27176 |
|
27177 |
|
27178 | if(touches < options.swipeMinTouches ||
|
27179 | touches > options.swipeMaxTouches) {
|
27180 | return;
|
27181 | }
|
27182 |
|
27183 |
|
27184 |
|
27185 | if(ev.velocityX > options.swipeVelocityX ||
|
27186 | ev.velocityY > options.swipeVelocityY) {
|
27187 |
|
27188 | inst.trigger(this.name, ev);
|
27189 | inst.trigger(this.name + ev.direction, ev);
|
27190 | }
|
27191 | }
|
27192 | }
|
27193 | };
|
27194 |
|
27195 | |
27196 |
|
27197 |
|
27198 | |
27199 |
|
27200 |
|
27201 |
|
27202 |
|
27203 |
|
27204 | |
27205 |
|
27206 |
|
27207 |
|
27208 | |
27209 |
|
27210 |
|
27211 |
|
27212 |
|
27213 | |
27214 |
|
27215 |
|
27216 | (function(name) {
|
27217 | var hasMoved = false;
|
27218 |
|
27219 | function tapGesture(ev, inst) {
|
27220 | var options = inst.options,
|
27221 | current = Detection.current,
|
27222 | prev = Detection.previous,
|
27223 | sincePrev,
|
27224 | didDoubleTap;
|
27225 |
|
27226 | switch(ev.eventType) {
|
27227 | case EVENT_START:
|
27228 | hasMoved = false;
|
27229 | break;
|
27230 |
|
27231 | case EVENT_MOVE:
|
27232 | hasMoved = hasMoved || (ev.distance > options.tapMaxDistance);
|
27233 | break;
|
27234 |
|
27235 | case EVENT_END:
|
27236 | if(!Utils.inStr(ev.srcEvent.type, 'cancel') && ev.deltaTime < options.tapMaxTime && !hasMoved) {
|
27237 |
|
27238 | sincePrev = prev && prev.lastEvent && ev.timeStamp - prev.lastEvent.timeStamp;
|
27239 | didDoubleTap = false;
|
27240 |
|
27241 |
|
27242 | if(prev && prev.name == name &&
|
27243 | (sincePrev && sincePrev < options.doubleTapInterval) &&
|
27244 | ev.distance < options.doubleTapDistance) {
|
27245 | inst.trigger('doubletap', ev);
|
27246 | didDoubleTap = true;
|
27247 | }
|
27248 |
|
27249 |
|
27250 | if(!didDoubleTap || options.tapAlways) {
|
27251 | current.name = name;
|
27252 | inst.trigger(current.name, ev);
|
27253 | }
|
27254 | }
|
27255 | break;
|
27256 | }
|
27257 | }
|
27258 |
|
27259 | Hammer.gestures.Tap = {
|
27260 | name: name,
|
27261 | index: 100,
|
27262 | handler: tapGesture,
|
27263 | defaults: {
|
27264 | |
27265 |
|
27266 |
|
27267 |
|
27268 |
|
27269 |
|
27270 | tapMaxTime: 250,
|
27271 |
|
27272 | |
27273 |
|
27274 |
|
27275 |
|
27276 |
|
27277 |
|
27278 | tapMaxDistance: 10,
|
27279 |
|
27280 | |
27281 |
|
27282 |
|
27283 |
|
27284 |
|
27285 |
|
27286 | tapAlways: true,
|
27287 |
|
27288 | |
27289 |
|
27290 |
|
27291 |
|
27292 |
|
27293 |
|
27294 | doubleTapDistance: 20,
|
27295 |
|
27296 | |
27297 |
|
27298 |
|
27299 |
|
27300 |
|
27301 |
|
27302 | doubleTapInterval: 300
|
27303 | }
|
27304 | };
|
27305 | })('tap');
|
27306 |
|
27307 | |
27308 |
|
27309 |
|
27310 | |
27311 |
|
27312 |
|
27313 |
|
27314 |
|
27315 |
|
27316 | |
27317 |
|
27318 |
|
27319 |
|
27320 | Hammer.gestures.Touch = {
|
27321 | name: 'touch',
|
27322 | index: -Infinity,
|
27323 | defaults: {
|
27324 | |
27325 |
|
27326 |
|
27327 |
|
27328 |
|
27329 |
|
27330 |
|
27331 |
|
27332 | preventDefault: false,
|
27333 |
|
27334 | |
27335 |
|
27336 |
|
27337 |
|
27338 |
|
27339 |
|
27340 | preventMouse: false
|
27341 | },
|
27342 | handler: function touchGesture(ev, inst) {
|
27343 | if(inst.options.preventMouse && ev.pointerType == POINTER_MOUSE) {
|
27344 | ev.stopDetect();
|
27345 | return;
|
27346 | }
|
27347 |
|
27348 | if(inst.options.preventDefault) {
|
27349 | ev.preventDefault();
|
27350 | }
|
27351 |
|
27352 | if(ev.eventType == EVENT_TOUCH) {
|
27353 | inst.trigger('touch', ev);
|
27354 | }
|
27355 | }
|
27356 | };
|
27357 |
|
27358 | |
27359 |
|
27360 |
|
27361 | |
27362 |
|
27363 |
|
27364 |
|
27365 |
|
27366 |
|
27367 |
|
27368 |
|
27369 | |
27370 |
|
27371 |
|
27372 |
|
27373 | |
27374 |
|
27375 |
|
27376 |
|
27377 | |
27378 |
|
27379 |
|
27380 |
|
27381 | |
27382 |
|
27383 |
|
27384 |
|
27385 | |
27386 |
|
27387 |
|
27388 |
|
27389 | |
27390 |
|
27391 |
|
27392 |
|
27393 |
|
27394 | |
27395 |
|
27396 |
|
27397 | (function(name) {
|
27398 | var triggered = false;
|
27399 |
|
27400 | function transformGesture(ev, inst) {
|
27401 | switch(ev.eventType) {
|
27402 | case EVENT_START:
|
27403 | triggered = false;
|
27404 | break;
|
27405 |
|
27406 | case EVENT_MOVE:
|
27407 |
|
27408 | if(ev.touches.length < 2) {
|
27409 | return;
|
27410 | }
|
27411 |
|
27412 | var scaleThreshold = Math.abs(1 - ev.scale);
|
27413 | var rotationThreshold = Math.abs(ev.rotation);
|
27414 |
|
27415 |
|
27416 |
|
27417 | if(scaleThreshold < inst.options.transformMinScale &&
|
27418 | rotationThreshold < inst.options.transformMinRotation) {
|
27419 | return;
|
27420 | }
|
27421 |
|
27422 |
|
27423 | Detection.current.name = name;
|
27424 |
|
27425 |
|
27426 | if(!triggered) {
|
27427 | inst.trigger(name + 'start', ev);
|
27428 | triggered = true;
|
27429 | }
|
27430 |
|
27431 | inst.trigger(name, ev);
|
27432 |
|
27433 |
|
27434 | if(rotationThreshold > inst.options.transformMinRotation) {
|
27435 | inst.trigger('rotate', ev);
|
27436 | }
|
27437 |
|
27438 |
|
27439 | if(scaleThreshold > inst.options.transformMinScale) {
|
27440 | inst.trigger('pinch', ev);
|
27441 | inst.trigger('pinch' + (ev.scale < 1 ? 'in' : 'out'), ev);
|
27442 | }
|
27443 | break;
|
27444 |
|
27445 | case EVENT_RELEASE:
|
27446 | if(triggered && ev.changedLength < 2) {
|
27447 | inst.trigger(name + 'end', ev);
|
27448 | triggered = false;
|
27449 | }
|
27450 | break;
|
27451 | }
|
27452 | }
|
27453 |
|
27454 | Hammer.gestures.Transform = {
|
27455 | name: name,
|
27456 | index: 45,
|
27457 | defaults: {
|
27458 | |
27459 |
|
27460 |
|
27461 |
|
27462 |
|
27463 |
|
27464 | transformMinScale: 0.01,
|
27465 |
|
27466 | |
27467 |
|
27468 |
|
27469 |
|
27470 |
|
27471 |
|
27472 | transformMinRotation: 1
|
27473 | },
|
27474 |
|
27475 | handler: transformGesture
|
27476 | };
|
27477 | })('transform');
|
27478 |
|
27479 | |
27480 |
|
27481 |
|
27482 |
|
27483 |
|
27484 | if(true) {
|
27485 | !(__WEBPACK_AMD_DEFINE_RESULT__ = function() {
|
27486 | return Hammer;
|
27487 | }.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
27488 |
|
27489 | } else if(typeof module !== 'undefined' && module.exports) {
|
27490 | module.exports = Hammer;
|
27491 |
|
27492 | } else {
|
27493 | window.Hammer = Hammer;
|
27494 | }
|
27495 |
|
27496 | })(window);
|
27497 |
|
27498 | },
|
27499 |
|
27500 | function(module, exports, __webpack_require__) {
|
27501 |
|
27502 | |
27503 |
|
27504 |
|
27505 |
|
27506 |
|
27507 |
|
27508 | |
27509 |
|
27510 |
|
27511 |
|
27512 | exports.startWithClustering = function() {
|
27513 |
|
27514 | this.clusterToFit(this.constants.clustering.initialMaxNodes, true);
|
27515 |
|
27516 |
|
27517 | this.updateLabels();
|
27518 |
|
27519 |
|
27520 |
|
27521 | if (this.stabilize) {
|
27522 | this._stabilize();
|
27523 | }
|
27524 | this.start();
|
27525 | };
|
27526 |
|
27527 | |
27528 |
|
27529 |
|
27530 |
|
27531 |
|
27532 |
|
27533 | exports.clusterToFit = function(maxNumberOfNodes, reposition) {
|
27534 | var numberOfNodes = this.nodeIndices.length;
|
27535 |
|
27536 | var maxLevels = 50;
|
27537 | var level = 0;
|
27538 |
|
27539 |
|
27540 | while (numberOfNodes > maxNumberOfNodes && level < maxLevels) {
|
27541 | if (level % 3 == 0) {
|
27542 | this.forceAggregateHubs(true);
|
27543 | this.normalizeClusterLevels();
|
27544 | }
|
27545 | else {
|
27546 | this.increaseClusterLevel();
|
27547 | }
|
27548 |
|
27549 | numberOfNodes = this.nodeIndices.length;
|
27550 | level += 1;
|
27551 | }
|
27552 |
|
27553 |
|
27554 | if (level > 0 && reposition == true) {
|
27555 | this.repositionNodes();
|
27556 | }
|
27557 | this._updateCalculationNodes();
|
27558 | };
|
27559 |
|
27560 | |
27561 |
|
27562 |
|
27563 |
|
27564 |
|
27565 |
|
27566 | exports.openCluster = function(node) {
|
27567 | var isMovingBeforeClustering = this.moving;
|
27568 | if (node.clusterSize > this.constants.clustering.sectorThreshold && this._nodeInActiveArea(node) &&
|
27569 | !(this._sector() == "default" && this.nodeIndices.length == 1)) {
|
27570 |
|
27571 | this._addSector(node);
|
27572 | var level = 0;
|
27573 |
|
27574 |
|
27575 | while ((this.nodeIndices.length < this.constants.clustering.initialMaxNodes) && (level < 10)) {
|
27576 | this.decreaseClusterLevel();
|
27577 | level += 1;
|
27578 | }
|
27579 |
|
27580 | }
|
27581 | else {
|
27582 | this._expandClusterNode(node,false,true);
|
27583 |
|
27584 |
|
27585 | this._updateNodeIndexList();
|
27586 | this._updateDynamicEdges();
|
27587 | this._updateCalculationNodes();
|
27588 | this.updateLabels();
|
27589 | }
|
27590 |
|
27591 |
|
27592 | if (this.moving != isMovingBeforeClustering) {
|
27593 | this.start();
|
27594 | }
|
27595 | };
|
27596 |
|
27597 |
|
27598 | |
27599 |
|
27600 |
|
27601 | exports.updateClustersDefault = function() {
|
27602 | if (this.constants.clustering.enabled == true) {
|
27603 | this.updateClusters(0,false,false);
|
27604 | }
|
27605 | };
|
27606 |
|
27607 |
|
27608 | |
27609 |
|
27610 |
|
27611 |
|
27612 |
|
27613 | exports.increaseClusterLevel = function() {
|
27614 | this.updateClusters(-1,false,true);
|
27615 | };
|
27616 |
|
27617 |
|
27618 | |
27619 |
|
27620 |
|
27621 |
|
27622 |
|
27623 | exports.decreaseClusterLevel = function() {
|
27624 | this.updateClusters(1,false,true);
|
27625 | };
|
27626 |
|
27627 |
|
27628 | |
27629 |
|
27630 |
|
27631 |
|
27632 |
|
27633 |
|
27634 |
|
27635 |
|
27636 |
|
27637 |
|
27638 |
|
27639 |
|
27640 | exports.updateClusters = function(zoomDirection,recursive,force,doNotStart) {
|
27641 | var isMovingBeforeClustering = this.moving;
|
27642 | var amountOfNodes = this.nodeIndices.length;
|
27643 |
|
27644 |
|
27645 | if (this.previousScale > this.scale && zoomDirection == 0) {
|
27646 | this._collapseSector();
|
27647 | }
|
27648 |
|
27649 |
|
27650 | if (this.previousScale > this.scale || zoomDirection == -1) {
|
27651 |
|
27652 |
|
27653 | this._formClusters(force);
|
27654 | }
|
27655 | else if (this.previousScale < this.scale || zoomDirection == 1) {
|
27656 | if (force == true) {
|
27657 |
|
27658 |
|
27659 | this._openClusters(recursive,force);
|
27660 | }
|
27661 | else {
|
27662 |
|
27663 | this._openClustersBySize();
|
27664 | }
|
27665 | }
|
27666 | this._updateNodeIndexList();
|
27667 |
|
27668 |
|
27669 | if (this.nodeIndices.length == amountOfNodes && (this.previousScale > this.scale || zoomDirection == -1)) {
|
27670 | this._aggregateHubs(force);
|
27671 | this._updateNodeIndexList();
|
27672 | }
|
27673 |
|
27674 |
|
27675 | if (this.previousScale > this.scale || zoomDirection == -1) {
|
27676 | this.handleChains();
|
27677 | this._updateNodeIndexList();
|
27678 | }
|
27679 |
|
27680 | this.previousScale = this.scale;
|
27681 |
|
27682 |
|
27683 | this._updateDynamicEdges();
|
27684 | this.updateLabels();
|
27685 |
|
27686 |
|
27687 | if (this.nodeIndices.length < amountOfNodes) {
|
27688 | this.clusterSession += 1;
|
27689 |
|
27690 | this.normalizeClusterLevels();
|
27691 | }
|
27692 |
|
27693 | if (doNotStart == false || doNotStart === undefined) {
|
27694 |
|
27695 | if (this.moving != isMovingBeforeClustering) {
|
27696 | this.start();
|
27697 | }
|
27698 | }
|
27699 |
|
27700 | this._updateCalculationNodes();
|
27701 | };
|
27702 |
|
27703 | |
27704 |
|
27705 |
|
27706 | exports.handleChains = function() {
|
27707 |
|
27708 | var chainPercentage = this._getChainFraction();
|
27709 | if (chainPercentage > this.constants.clustering.chainThreshold) {
|
27710 | this._reduceAmountOfChains(1 - this.constants.clustering.chainThreshold / chainPercentage)
|
27711 |
|
27712 | }
|
27713 | };
|
27714 |
|
27715 | |
27716 |
|
27717 |
|
27718 |
|
27719 |
|
27720 |
|
27721 | exports._aggregateHubs = function(force) {
|
27722 | this._getHubSize();
|
27723 | this._formClustersByHub(force,false);
|
27724 | };
|
27725 |
|
27726 |
|
27727 | |
27728 |
|
27729 |
|
27730 |
|
27731 | exports.forceAggregateHubs = function(doNotStart) {
|
27732 | var isMovingBeforeClustering = this.moving;
|
27733 | var amountOfNodes = this.nodeIndices.length;
|
27734 |
|
27735 | this._aggregateHubs(true);
|
27736 |
|
27737 |
|
27738 | this._updateNodeIndexList();
|
27739 | this._updateDynamicEdges();
|
27740 | this.updateLabels();
|
27741 |
|
27742 |
|
27743 | if (this.nodeIndices.length != amountOfNodes) {
|
27744 | this.clusterSession += 1;
|
27745 | }
|
27746 |
|
27747 | if (doNotStart == false || doNotStart === undefined) {
|
27748 |
|
27749 | if (this.moving != isMovingBeforeClustering) {
|
27750 | this.start();
|
27751 | }
|
27752 | }
|
27753 | };
|
27754 |
|
27755 | |
27756 |
|
27757 |
|
27758 |
|
27759 |
|
27760 | exports._openClustersBySize = function() {
|
27761 | for (var nodeId in this.nodes) {
|
27762 | if (this.nodes.hasOwnProperty(nodeId)) {
|
27763 | var node = this.nodes[nodeId];
|
27764 | if (node.inView() == true) {
|
27765 | if ((node.width*this.scale > this.constants.clustering.screenSizeThreshold * this.frame.canvas.clientWidth) ||
|
27766 | (node.height*this.scale > this.constants.clustering.screenSizeThreshold * this.frame.canvas.clientHeight)) {
|
27767 | this.openCluster(node);
|
27768 | }
|
27769 | }
|
27770 | }
|
27771 | }
|
27772 | };
|
27773 |
|
27774 |
|
27775 | |
27776 |
|
27777 |
|
27778 |
|
27779 |
|
27780 |
|
27781 | exports._openClusters = function(recursive,force) {
|
27782 | for (var i = 0; i < this.nodeIndices.length; i++) {
|
27783 | var node = this.nodes[this.nodeIndices[i]];
|
27784 | this._expandClusterNode(node,recursive,force);
|
27785 | this._updateCalculationNodes();
|
27786 | }
|
27787 | };
|
27788 |
|
27789 | |
27790 |
|
27791 |
|
27792 |
|
27793 |
|
27794 |
|
27795 |
|
27796 |
|
27797 |
|
27798 |
|
27799 |
|
27800 | exports._expandClusterNode = function(parentNode, recursive, force, openAll) {
|
27801 |
|
27802 | if (parentNode.clusterSize > 1) {
|
27803 |
|
27804 | if (parentNode.clusterSize < this.constants.clustering.sectorThreshold) {
|
27805 | openAll = true;
|
27806 | }
|
27807 | recursive = openAll ? true : recursive;
|
27808 |
|
27809 |
|
27810 | if (parentNode.formationScale < this.scale || force == true) {
|
27811 |
|
27812 | for (var containedNodeId in parentNode.containedNodes) {
|
27813 | if (parentNode.containedNodes.hasOwnProperty(containedNodeId)) {
|
27814 | var childNode = parentNode.containedNodes[containedNodeId];
|
27815 |
|
27816 |
|
27817 |
|
27818 | if (force == true) {
|
27819 | if (childNode.clusterSession == parentNode.clusterSessions[parentNode.clusterSessions.length-1]
|
27820 | || openAll) {
|
27821 | this._expelChildFromParent(parentNode,containedNodeId,recursive,force,openAll);
|
27822 | }
|
27823 | }
|
27824 | else {
|
27825 | if (this._nodeInActiveArea(parentNode)) {
|
27826 | this._expelChildFromParent(parentNode,containedNodeId,recursive,force,openAll);
|
27827 | }
|
27828 | }
|
27829 | }
|
27830 | }
|
27831 | }
|
27832 | }
|
27833 | };
|
27834 |
|
27835 | |
27836 |
|
27837 |
|
27838 |
|
27839 |
|
27840 |
|
27841 |
|
27842 |
|
27843 |
|
27844 |
|
27845 |
|
27846 |
|
27847 |
|
27848 |
|
27849 |
|
27850 | exports._expelChildFromParent = function(parentNode, containedNodeId, recursive, force, openAll) {
|
27851 | var childNode = parentNode.containedNodes[containedNodeId];
|
27852 |
|
27853 |
|
27854 | if (childNode.formationScale < this.scale || force == true) {
|
27855 |
|
27856 | this._unselectAll();
|
27857 |
|
27858 |
|
27859 | this.nodes[containedNodeId] = childNode;
|
27860 |
|
27861 |
|
27862 | this._releaseContainedEdges(parentNode,childNode);
|
27863 |
|
27864 |
|
27865 | this._connectEdgeBackToChild(parentNode,childNode);
|
27866 |
|
27867 |
|
27868 | this._validateEdges(parentNode);
|
27869 |
|
27870 |
|
27871 | parentNode.options.mass -= childNode.options.mass;
|
27872 | parentNode.clusterSize -= childNode.clusterSize;
|
27873 | parentNode.options.fontSize = Math.min(this.constants.clustering.maxFontSize, this.constants.nodes.fontSize + this.constants.clustering.fontSizeMultiplier*parentNode.clusterSize);
|
27874 | parentNode.dynamicEdgesLength = parentNode.dynamicEdges.length;
|
27875 |
|
27876 |
|
27877 | childNode.x = parentNode.x + parentNode.growthIndicator * (0.5 - Math.random());
|
27878 | childNode.y = parentNode.y + parentNode.growthIndicator * (0.5 - Math.random());
|
27879 |
|
27880 |
|
27881 | delete parentNode.containedNodes[containedNodeId];
|
27882 |
|
27883 |
|
27884 | var othersPresent = false;
|
27885 | for (var childNodeId in parentNode.containedNodes) {
|
27886 | if (parentNode.containedNodes.hasOwnProperty(childNodeId)) {
|
27887 | if (parentNode.containedNodes[childNodeId].clusterSession == childNode.clusterSession) {
|
27888 | othersPresent = true;
|
27889 | break;
|
27890 | }
|
27891 | }
|
27892 | }
|
27893 |
|
27894 | if (othersPresent == false) {
|
27895 | parentNode.clusterSessions.pop();
|
27896 | }
|
27897 |
|
27898 | this._repositionBezierNodes(childNode);
|
27899 |
|
27900 |
|
27901 |
|
27902 | childNode.clusterSession = 0;
|
27903 |
|
27904 |
|
27905 | parentNode.clearSizeCache();
|
27906 |
|
27907 |
|
27908 | this.moving = true;
|
27909 | }
|
27910 |
|
27911 |
|
27912 | if (recursive == true) {
|
27913 | this._expandClusterNode(childNode,recursive,force,openAll);
|
27914 | }
|
27915 | };
|
27916 |
|
27917 |
|
27918 | |
27919 |
|
27920 |
|
27921 |
|
27922 |
|
27923 |
|
27924 | exports._repositionBezierNodes = function(node) {
|
27925 | for (var i = 0; i < node.dynamicEdges.length; i++) {
|
27926 | node.dynamicEdges[i].positionBezierNode();
|
27927 | }
|
27928 | };
|
27929 |
|
27930 |
|
27931 | |
27932 |
|
27933 |
|
27934 |
|
27935 |
|
27936 |
|
27937 |
|
27938 |
|
27939 |
|
27940 | exports._formClusters = function(force) {
|
27941 | if (force == false) {
|
27942 | this._formClustersByZoom();
|
27943 | }
|
27944 | else {
|
27945 | this._forceClustersByZoom();
|
27946 | }
|
27947 | };
|
27948 |
|
27949 |
|
27950 | |
27951 |
|
27952 |
|
27953 |
|
27954 |
|
27955 | exports._formClustersByZoom = function() {
|
27956 | var dx,dy,length,
|
27957 | minLength = this.constants.clustering.clusterEdgeThreshold/this.scale;
|
27958 |
|
27959 |
|
27960 |
|
27961 | for (var edgeId in this.edges) {
|
27962 | if (this.edges.hasOwnProperty(edgeId)) {
|
27963 | var edge = this.edges[edgeId];
|
27964 | if (edge.connected) {
|
27965 | if (edge.toId != edge.fromId) {
|
27966 | dx = (edge.to.x - edge.from.x);
|
27967 | dy = (edge.to.y - edge.from.y);
|
27968 | length = Math.sqrt(dx * dx + dy * dy);
|
27969 |
|
27970 |
|
27971 | if (length < minLength) {
|
27972 |
|
27973 | var parentNode = edge.from;
|
27974 | var childNode = edge.to;
|
27975 | if (edge.to.options.mass > edge.from.options.mass) {
|
27976 | parentNode = edge.to;
|
27977 | childNode = edge.from;
|
27978 | }
|
27979 |
|
27980 | if (childNode.dynamicEdgesLength == 1) {
|
27981 | this._addToCluster(parentNode,childNode,false);
|
27982 | }
|
27983 | else if (parentNode.dynamicEdgesLength == 1) {
|
27984 | this._addToCluster(childNode,parentNode,false);
|
27985 | }
|
27986 | }
|
27987 | }
|
27988 | }
|
27989 | }
|
27990 | }
|
27991 | };
|
27992 |
|
27993 | |
27994 |
|
27995 |
|
27996 |
|
27997 |
|
27998 |
|
27999 | exports._forceClustersByZoom = function() {
|
28000 | for (var nodeId in this.nodes) {
|
28001 |
|
28002 | if (this.nodes.hasOwnProperty(nodeId)) {
|
28003 | var childNode = this.nodes[nodeId];
|
28004 |
|
28005 |
|
28006 | if (childNode.dynamicEdgesLength == 1 && childNode.dynamicEdges.length != 0) {
|
28007 | var edge = childNode.dynamicEdges[0];
|
28008 | var parentNode = (edge.toId == childNode.id) ? this.nodes[edge.fromId] : this.nodes[edge.toId];
|
28009 |
|
28010 |
|
28011 | if (childNode.id != parentNode.id) {
|
28012 | if (parentNode.options.mass > childNode.options.mass) {
|
28013 | this._addToCluster(parentNode,childNode,true);
|
28014 | }
|
28015 | else {
|
28016 | this._addToCluster(childNode,parentNode,true);
|
28017 | }
|
28018 | }
|
28019 | }
|
28020 | }
|
28021 | }
|
28022 | };
|
28023 |
|
28024 |
|
28025 | |
28026 |
|
28027 |
|
28028 |
|
28029 |
|
28030 |
|
28031 |
|
28032 | exports._clusterToSmallestNeighbour = function(node) {
|
28033 | var smallestNeighbour = -1;
|
28034 | var smallestNeighbourNode = null;
|
28035 | for (var i = 0; i < node.dynamicEdges.length; i++) {
|
28036 | if (node.dynamicEdges[i] !== undefined) {
|
28037 | var neighbour = null;
|
28038 | if (node.dynamicEdges[i].fromId != node.id) {
|
28039 | neighbour = node.dynamicEdges[i].from;
|
28040 | }
|
28041 | else if (node.dynamicEdges[i].toId != node.id) {
|
28042 | neighbour = node.dynamicEdges[i].to;
|
28043 | }
|
28044 |
|
28045 |
|
28046 | if (neighbour != null && smallestNeighbour > neighbour.clusterSessions.length) {
|
28047 | smallestNeighbour = neighbour.clusterSessions.length;
|
28048 | smallestNeighbourNode = neighbour;
|
28049 | }
|
28050 | }
|
28051 | }
|
28052 |
|
28053 | if (neighbour != null && this.nodes[neighbour.id] !== undefined) {
|
28054 | this._addToCluster(neighbour, node, true);
|
28055 | }
|
28056 | };
|
28057 |
|
28058 |
|
28059 | |
28060 |
|
28061 |
|
28062 |
|
28063 |
|
28064 |
|
28065 |
|
28066 | exports._formClustersByHub = function(force, onlyEqual) {
|
28067 |
|
28068 | for (var nodeId in this.nodes) {
|
28069 |
|
28070 | if (this.nodes.hasOwnProperty(nodeId)) {
|
28071 | this._formClusterFromHub(this.nodes[nodeId],force,onlyEqual);
|
28072 | }
|
28073 | }
|
28074 | };
|
28075 |
|
28076 | |
28077 |
|
28078 |
|
28079 |
|
28080 |
|
28081 |
|
28082 |
|
28083 |
|
28084 |
|
28085 | exports._formClusterFromHub = function(hubNode, force, onlyEqual, absorptionSizeOffset) {
|
28086 | if (absorptionSizeOffset === undefined) {
|
28087 | absorptionSizeOffset = 0;
|
28088 | }
|
28089 |
|
28090 | if ((hubNode.dynamicEdgesLength >= this.hubThreshold && onlyEqual == false) ||
|
28091 | (hubNode.dynamicEdgesLength == this.hubThreshold && onlyEqual == true)) {
|
28092 |
|
28093 | var dx,dy,length;
|
28094 | var minLength = this.constants.clustering.clusterEdgeThreshold/this.scale;
|
28095 | var allowCluster = false;
|
28096 |
|
28097 |
|
28098 | var edgesIdarray = [];
|
28099 | var amountOfInitialEdges = hubNode.dynamicEdges.length;
|
28100 | for (var j = 0; j < amountOfInitialEdges; j++) {
|
28101 | edgesIdarray.push(hubNode.dynamicEdges[j].id);
|
28102 | }
|
28103 |
|
28104 |
|
28105 |
|
28106 | if (force == false) {
|
28107 | allowCluster = false;
|
28108 | for (j = 0; j < amountOfInitialEdges; j++) {
|
28109 | var edge = this.edges[edgesIdarray[j]];
|
28110 | if (edge !== undefined) {
|
28111 | if (edge.connected) {
|
28112 | if (edge.toId != edge.fromId) {
|
28113 | dx = (edge.to.x - edge.from.x);
|
28114 | dy = (edge.to.y - edge.from.y);
|
28115 | length = Math.sqrt(dx * dx + dy * dy);
|
28116 |
|
28117 | if (length < minLength) {
|
28118 | allowCluster = true;
|
28119 | break;
|
28120 | }
|
28121 | }
|
28122 | }
|
28123 | }
|
28124 | }
|
28125 | }
|
28126 |
|
28127 |
|
28128 | if ((!force && allowCluster) || force) {
|
28129 |
|
28130 | for (j = 0; j < amountOfInitialEdges; j++) {
|
28131 | edge = this.edges[edgesIdarray[j]];
|
28132 |
|
28133 | if (edge !== undefined) {
|
28134 | var childNode = this.nodes[(edge.fromId == hubNode.id) ? edge.toId : edge.fromId];
|
28135 |
|
28136 | if ((childNode.dynamicEdges.length <= (this.hubThreshold + absorptionSizeOffset)) &&
|
28137 | (childNode.id != hubNode.id)) {
|
28138 | this._addToCluster(hubNode,childNode,force);
|
28139 | }
|
28140 | }
|
28141 | }
|
28142 | }
|
28143 | }
|
28144 | };
|
28145 |
|
28146 |
|
28147 |
|
28148 | |
28149 |
|
28150 |
|
28151 |
|
28152 |
|
28153 |
|
28154 |
|
28155 |
|
28156 | exports._addToCluster = function(parentNode, childNode, force) {
|
28157 |
|
28158 | parentNode.containedNodes[childNode.id] = childNode;
|
28159 |
|
28160 |
|
28161 | for (var i = 0; i < childNode.dynamicEdges.length; i++) {
|
28162 | var edge = childNode.dynamicEdges[i];
|
28163 | if (edge.toId == parentNode.id || edge.fromId == parentNode.id) {
|
28164 | this._addToContainedEdges(parentNode,childNode,edge);
|
28165 | }
|
28166 | else {
|
28167 | this._connectEdgeToCluster(parentNode,childNode,edge);
|
28168 | }
|
28169 | }
|
28170 |
|
28171 | childNode.dynamicEdges = [];
|
28172 |
|
28173 |
|
28174 | this._containCircularEdgesFromNode(parentNode,childNode);
|
28175 |
|
28176 |
|
28177 |
|
28178 | delete this.nodes[childNode.id];
|
28179 |
|
28180 |
|
28181 | var massBefore = parentNode.options.mass;
|
28182 | childNode.clusterSession = this.clusterSession;
|
28183 | parentNode.options.mass += childNode.options.mass;
|
28184 | parentNode.clusterSize += childNode.clusterSize;
|
28185 | parentNode.options.fontSize = Math.min(this.constants.clustering.maxFontSize, this.constants.nodes.fontSize + this.constants.clustering.fontSizeMultiplier*parentNode.clusterSize);
|
28186 |
|
28187 |
|
28188 | if (parentNode.clusterSessions[parentNode.clusterSessions.length - 1] != this.clusterSession) {
|
28189 | parentNode.clusterSessions.push(this.clusterSession);
|
28190 | }
|
28191 |
|
28192 |
|
28193 | if (force == true) {
|
28194 |
|
28195 | parentNode.formationScale = 0;
|
28196 | }
|
28197 | else {
|
28198 | parentNode.formationScale = this.scale;
|
28199 | }
|
28200 |
|
28201 |
|
28202 | parentNode.clearSizeCache();
|
28203 |
|
28204 |
|
28205 | parentNode.containedNodes[childNode.id].formationScale = parentNode.formationScale;
|
28206 |
|
28207 |
|
28208 | childNode.clearVelocity();
|
28209 |
|
28210 |
|
28211 | parentNode.updateVelocity(massBefore);
|
28212 |
|
28213 |
|
28214 | this.moving = true;
|
28215 | };
|
28216 |
|
28217 |
|
28218 | |
28219 |
|
28220 |
|
28221 |
|
28222 |
|
28223 |
|
28224 | exports._updateDynamicEdges = function() {
|
28225 | for (var i = 0; i < this.nodeIndices.length; i++) {
|
28226 | var node = this.nodes[this.nodeIndices[i]];
|
28227 | node.dynamicEdgesLength = node.dynamicEdges.length;
|
28228 |
|
28229 |
|
28230 | var correction = 0;
|
28231 | if (node.dynamicEdgesLength > 1) {
|
28232 | for (var j = 0; j < node.dynamicEdgesLength - 1; j++) {
|
28233 | var edgeToId = node.dynamicEdges[j].toId;
|
28234 | var edgeFromId = node.dynamicEdges[j].fromId;
|
28235 | for (var k = j+1; k < node.dynamicEdgesLength; k++) {
|
28236 | if ((node.dynamicEdges[k].toId == edgeToId && node.dynamicEdges[k].fromId == edgeFromId) ||
|
28237 | (node.dynamicEdges[k].fromId == edgeToId && node.dynamicEdges[k].toId == edgeFromId)) {
|
28238 | correction += 1;
|
28239 | }
|
28240 | }
|
28241 | }
|
28242 | }
|
28243 | node.dynamicEdgesLength -= correction;
|
28244 | }
|
28245 | };
|
28246 |
|
28247 |
|
28248 | |
28249 |
|
28250 |
|
28251 |
|
28252 |
|
28253 |
|
28254 |
|
28255 |
|
28256 | exports._addToContainedEdges = function(parentNode, childNode, edge) {
|
28257 |
|
28258 | if (!(parentNode.containedEdges.hasOwnProperty(childNode.id))) {
|
28259 | parentNode.containedEdges[childNode.id] = []
|
28260 | }
|
28261 |
|
28262 | parentNode.containedEdges[childNode.id].push(edge);
|
28263 |
|
28264 |
|
28265 | delete this.edges[edge.id];
|
28266 |
|
28267 |
|
28268 | for (var i = 0; i < parentNode.dynamicEdges.length; i++) {
|
28269 | if (parentNode.dynamicEdges[i].id == edge.id) {
|
28270 | parentNode.dynamicEdges.splice(i,1);
|
28271 | break;
|
28272 | }
|
28273 | }
|
28274 | };
|
28275 |
|
28276 | |
28277 |
|
28278 |
|
28279 |
|
28280 |
|
28281 |
|
28282 |
|
28283 |
|
28284 |
|
28285 | exports._connectEdgeToCluster = function(parentNode, childNode, edge) {
|
28286 |
|
28287 | if (edge.toId == edge.fromId) {
|
28288 | this._addToContainedEdges(parentNode, childNode, edge);
|
28289 | }
|
28290 | else {
|
28291 | if (edge.toId == childNode.id) {
|
28292 | edge.originalToId.push(childNode.id);
|
28293 | edge.to = parentNode;
|
28294 | edge.toId = parentNode.id;
|
28295 | }
|
28296 | else {
|
28297 |
|
28298 | edge.originalFromId.push(childNode.id);
|
28299 | edge.from = parentNode;
|
28300 | edge.fromId = parentNode.id;
|
28301 | }
|
28302 |
|
28303 | this._addToReroutedEdges(parentNode,childNode,edge);
|
28304 | }
|
28305 | };
|
28306 |
|
28307 |
|
28308 | |
28309 |
|
28310 |
|
28311 |
|
28312 |
|
28313 |
|
28314 |
|
28315 |
|
28316 | exports._containCircularEdgesFromNode = function(parentNode, childNode) {
|
28317 |
|
28318 | for (var i = 0; i < parentNode.dynamicEdges.length; i++) {
|
28319 | var edge = parentNode.dynamicEdges[i];
|
28320 |
|
28321 | if (edge.toId == edge.fromId) {
|
28322 | this._addToContainedEdges(parentNode, childNode, edge);
|
28323 | }
|
28324 | }
|
28325 | };
|
28326 |
|
28327 |
|
28328 | |
28329 |
|
28330 |
|
28331 |
|
28332 |
|
28333 |
|
28334 |
|
28335 |
|
28336 | exports._addToReroutedEdges = function(parentNode, childNode, edge) {
|
28337 |
|
28338 |
|
28339 | if (!(parentNode.reroutedEdges.hasOwnProperty(childNode.id))) {
|
28340 | parentNode.reroutedEdges[childNode.id] = [];
|
28341 | }
|
28342 | parentNode.reroutedEdges[childNode.id].push(edge);
|
28343 |
|
28344 |
|
28345 | parentNode.dynamicEdges.push(edge);
|
28346 | };
|
28347 |
|
28348 |
|
28349 |
|
28350 | |
28351 |
|
28352 |
|
28353 |
|
28354 |
|
28355 |
|
28356 |
|
28357 | exports._connectEdgeBackToChild = function(parentNode, childNode) {
|
28358 | if (parentNode.reroutedEdges.hasOwnProperty(childNode.id)) {
|
28359 | for (var i = 0; i < parentNode.reroutedEdges[childNode.id].length; i++) {
|
28360 | var edge = parentNode.reroutedEdges[childNode.id][i];
|
28361 | if (edge.originalFromId[edge.originalFromId.length-1] == childNode.id) {
|
28362 | edge.originalFromId.pop();
|
28363 | edge.fromId = childNode.id;
|
28364 | edge.from = childNode;
|
28365 | }
|
28366 | else {
|
28367 | edge.originalToId.pop();
|
28368 | edge.toId = childNode.id;
|
28369 | edge.to = childNode;
|
28370 | }
|
28371 |
|
28372 |
|
28373 | childNode.dynamicEdges.push(edge);
|
28374 |
|
28375 |
|
28376 | for (var j = 0; j < parentNode.dynamicEdges.length; j++) {
|
28377 | if (parentNode.dynamicEdges[j].id == edge.id) {
|
28378 | parentNode.dynamicEdges.splice(j,1);
|
28379 | break;
|
28380 | }
|
28381 | }
|
28382 | }
|
28383 |
|
28384 | delete parentNode.reroutedEdges[childNode.id];
|
28385 | }
|
28386 | };
|
28387 |
|
28388 |
|
28389 | |
28390 |
|
28391 |
|
28392 |
|
28393 |
|
28394 |
|
28395 |
|
28396 |
|
28397 | exports._validateEdges = function(parentNode) {
|
28398 | for (var i = 0; i < parentNode.dynamicEdges.length; i++) {
|
28399 | var edge = parentNode.dynamicEdges[i];
|
28400 | if (parentNode.id != edge.toId && parentNode.id != edge.fromId) {
|
28401 | parentNode.dynamicEdges.splice(i,1);
|
28402 | }
|
28403 | }
|
28404 | };
|
28405 |
|
28406 |
|
28407 | |
28408 |
|
28409 |
|
28410 |
|
28411 |
|
28412 |
|
28413 |
|
28414 |
|
28415 | exports._releaseContainedEdges = function(parentNode, childNode) {
|
28416 | for (var i = 0; i < parentNode.containedEdges[childNode.id].length; i++) {
|
28417 | var edge = parentNode.containedEdges[childNode.id][i];
|
28418 |
|
28419 |
|
28420 | this.edges[edge.id] = edge;
|
28421 |
|
28422 |
|
28423 | childNode.dynamicEdges.push(edge);
|
28424 | parentNode.dynamicEdges.push(edge);
|
28425 | }
|
28426 |
|
28427 | delete parentNode.containedEdges[childNode.id];
|
28428 |
|
28429 | };
|
28430 |
|
28431 |
|
28432 |
|
28433 |
|
28434 |
|
28435 |
|
28436 |
|
28437 | |
28438 |
|
28439 |
|
28440 | exports.updateLabels = function() {
|
28441 | var nodeId;
|
28442 |
|
28443 | for (nodeId in this.nodes) {
|
28444 | if (this.nodes.hasOwnProperty(nodeId)) {
|
28445 | var node = this.nodes[nodeId];
|
28446 | if (node.clusterSize > 1) {
|
28447 | node.label = "[".concat(String(node.clusterSize),"]");
|
28448 | }
|
28449 | }
|
28450 | }
|
28451 |
|
28452 |
|
28453 | for (nodeId in this.nodes) {
|
28454 | if (this.nodes.hasOwnProperty(nodeId)) {
|
28455 | node = this.nodes[nodeId];
|
28456 | if (node.clusterSize == 1) {
|
28457 | if (node.originalLabel !== undefined) {
|
28458 | node.label = node.originalLabel;
|
28459 | }
|
28460 | else {
|
28461 | node.label = String(node.id);
|
28462 | }
|
28463 | }
|
28464 | }
|
28465 | }
|
28466 |
|
28467 |
|
28468 |
|
28469 |
|
28470 |
|
28471 |
|
28472 |
|
28473 |
|
28474 |
|
28475 | };
|
28476 |
|
28477 |
|
28478 | |
28479 |
|
28480 |
|
28481 |
|
28482 |
|
28483 |
|
28484 | exports.normalizeClusterLevels = function() {
|
28485 | var maxLevel = 0;
|
28486 | var minLevel = 1e9;
|
28487 | var clusterLevel = 0;
|
28488 | var nodeId;
|
28489 |
|
28490 |
|
28491 | for (nodeId in this.nodes) {
|
28492 | if (this.nodes.hasOwnProperty(nodeId)) {
|
28493 | clusterLevel = this.nodes[nodeId].clusterSessions.length;
|
28494 | if (maxLevel < clusterLevel) {maxLevel = clusterLevel;}
|
28495 | if (minLevel > clusterLevel) {minLevel = clusterLevel;}
|
28496 | }
|
28497 | }
|
28498 |
|
28499 | if (maxLevel - minLevel > this.constants.clustering.clusterLevelDifference) {
|
28500 | var amountOfNodes = this.nodeIndices.length;
|
28501 | var targetLevel = maxLevel - this.constants.clustering.clusterLevelDifference;
|
28502 |
|
28503 | for (nodeId in this.nodes) {
|
28504 | if (this.nodes.hasOwnProperty(nodeId)) {
|
28505 | if (this.nodes[nodeId].clusterSessions.length < targetLevel) {
|
28506 | this._clusterToSmallestNeighbour(this.nodes[nodeId]);
|
28507 | }
|
28508 | }
|
28509 | }
|
28510 | this._updateNodeIndexList();
|
28511 | this._updateDynamicEdges();
|
28512 |
|
28513 | if (this.nodeIndices.length != amountOfNodes) {
|
28514 | this.clusterSession += 1;
|
28515 | }
|
28516 | }
|
28517 | };
|
28518 |
|
28519 |
|
28520 |
|
28521 | |
28522 |
|
28523 |
|
28524 |
|
28525 |
|
28526 |
|
28527 |
|
28528 |
|
28529 | exports._nodeInActiveArea = function(node) {
|
28530 | return (
|
28531 | Math.abs(node.x - this.areaCenter.x) <= this.constants.clustering.activeAreaBoxSize/this.scale
|
28532 | &&
|
28533 | Math.abs(node.y - this.areaCenter.y) <= this.constants.clustering.activeAreaBoxSize/this.scale
|
28534 | )
|
28535 | };
|
28536 |
|
28537 |
|
28538 | |
28539 |
|
28540 |
|
28541 |
|
28542 |
|
28543 | exports.repositionNodes = function() {
|
28544 | for (var i = 0; i < this.nodeIndices.length; i++) {
|
28545 | var node = this.nodes[this.nodeIndices[i]];
|
28546 | if ((node.xFixed == false || node.yFixed == false)) {
|
28547 | var radius = 10 * 0.1*this.nodeIndices.length * Math.min(100,node.options.mass);
|
28548 | var angle = 2 * Math.PI * Math.random();
|
28549 | if (node.xFixed == false) {node.x = radius * Math.cos(angle);}
|
28550 | if (node.yFixed == false) {node.y = radius * Math.sin(angle);}
|
28551 | this._repositionBezierNodes(node);
|
28552 | }
|
28553 | }
|
28554 | };
|
28555 |
|
28556 |
|
28557 | |
28558 |
|
28559 |
|
28560 |
|
28561 |
|
28562 |
|
28563 | exports._getHubSize = function() {
|
28564 | var average = 0;
|
28565 | var averageSquared = 0;
|
28566 | var hubCounter = 0;
|
28567 | var largestHub = 0;
|
28568 |
|
28569 | for (var i = 0; i < this.nodeIndices.length; i++) {
|
28570 |
|
28571 | var node = this.nodes[this.nodeIndices[i]];
|
28572 | if (node.dynamicEdgesLength > largestHub) {
|
28573 | largestHub = node.dynamicEdgesLength;
|
28574 | }
|
28575 | average += node.dynamicEdgesLength;
|
28576 | averageSquared += Math.pow(node.dynamicEdgesLength,2);
|
28577 | hubCounter += 1;
|
28578 | }
|
28579 | average = average / hubCounter;
|
28580 | averageSquared = averageSquared / hubCounter;
|
28581 |
|
28582 | var variance = averageSquared - Math.pow(average,2);
|
28583 |
|
28584 | var standardDeviation = Math.sqrt(variance);
|
28585 |
|
28586 | this.hubThreshold = Math.floor(average + 2*standardDeviation);
|
28587 |
|
28588 |
|
28589 | if (this.hubThreshold > largestHub) {
|
28590 | this.hubThreshold = largestHub;
|
28591 | }
|
28592 |
|
28593 |
|
28594 |
|
28595 | };
|
28596 |
|
28597 |
|
28598 | |
28599 |
|
28600 |
|
28601 |
|
28602 |
|
28603 |
|
28604 |
|
28605 | exports._reduceAmountOfChains = function(fraction) {
|
28606 | this.hubThreshold = 2;
|
28607 | var reduceAmount = Math.floor(this.nodeIndices.length * fraction);
|
28608 | for (var nodeId in this.nodes) {
|
28609 | if (this.nodes.hasOwnProperty(nodeId)) {
|
28610 | if (this.nodes[nodeId].dynamicEdgesLength == 2 && this.nodes[nodeId].dynamicEdges.length >= 2) {
|
28611 | if (reduceAmount > 0) {
|
28612 | this._formClusterFromHub(this.nodes[nodeId],true,true,1);
|
28613 | reduceAmount -= 1;
|
28614 | }
|
28615 | }
|
28616 | }
|
28617 | }
|
28618 | };
|
28619 |
|
28620 | |
28621 |
|
28622 |
|
28623 |
|
28624 |
|
28625 |
|
28626 | exports._getChainFraction = function() {
|
28627 | var chains = 0;
|
28628 | var total = 0;
|
28629 | for (var nodeId in this.nodes) {
|
28630 | if (this.nodes.hasOwnProperty(nodeId)) {
|
28631 | if (this.nodes[nodeId].dynamicEdgesLength == 2 && this.nodes[nodeId].dynamicEdges.length >= 2) {
|
28632 | chains += 1;
|
28633 | }
|
28634 | total += 1;
|
28635 | }
|
28636 | }
|
28637 | return chains/total;
|
28638 | };
|
28639 |
|
28640 |
|
28641 | },
|
28642 |
|
28643 | function(module, exports, __webpack_require__) {
|
28644 |
|
28645 | var util = __webpack_require__(1);
|
28646 |
|
28647 | |
28648 |
|
28649 |
|
28650 |
|
28651 |
|
28652 |
|
28653 |
|
28654 |
|
28655 | |
28656 |
|
28657 |
|
28658 |
|
28659 |
|
28660 |
|
28661 | exports._putDataInSector = function() {
|
28662 | this.sectors["active"][this._sector()].nodes = this.nodes;
|
28663 | this.sectors["active"][this._sector()].edges = this.edges;
|
28664 | this.sectors["active"][this._sector()].nodeIndices = this.nodeIndices;
|
28665 | };
|
28666 |
|
28667 |
|
28668 | |
28669 |
|
28670 |
|
28671 |
|
28672 |
|
28673 |
|
28674 |
|
28675 |
|
28676 |
|
28677 | exports._switchToSector = function(sectorId, sectorType) {
|
28678 | if (sectorType === undefined || sectorType == "active") {
|
28679 | this._switchToActiveSector(sectorId);
|
28680 | }
|
28681 | else {
|
28682 | this._switchToFrozenSector(sectorId);
|
28683 | }
|
28684 | };
|
28685 |
|
28686 |
|
28687 | |
28688 |
|
28689 |
|
28690 |
|
28691 |
|
28692 |
|
28693 |
|
28694 | exports._switchToActiveSector = function(sectorId) {
|
28695 | this.nodeIndices = this.sectors["active"][sectorId]["nodeIndices"];
|
28696 | this.nodes = this.sectors["active"][sectorId]["nodes"];
|
28697 | this.edges = this.sectors["active"][sectorId]["edges"];
|
28698 | };
|
28699 |
|
28700 |
|
28701 | |
28702 |
|
28703 |
|
28704 |
|
28705 |
|
28706 |
|
28707 | exports._switchToSupportSector = function() {
|
28708 | this.nodeIndices = this.sectors["support"]["nodeIndices"];
|
28709 | this.nodes = this.sectors["support"]["nodes"];
|
28710 | this.edges = this.sectors["support"]["edges"];
|
28711 | };
|
28712 |
|
28713 |
|
28714 | |
28715 |
|
28716 |
|
28717 |
|
28718 |
|
28719 |
|
28720 |
|
28721 | exports._switchToFrozenSector = function(sectorId) {
|
28722 | this.nodeIndices = this.sectors["frozen"][sectorId]["nodeIndices"];
|
28723 | this.nodes = this.sectors["frozen"][sectorId]["nodes"];
|
28724 | this.edges = this.sectors["frozen"][sectorId]["edges"];
|
28725 | };
|
28726 |
|
28727 |
|
28728 | |
28729 |
|
28730 |
|
28731 |
|
28732 |
|
28733 |
|
28734 | exports._loadLatestSector = function() {
|
28735 | this._switchToSector(this._sector());
|
28736 | };
|
28737 |
|
28738 |
|
28739 | |
28740 |
|
28741 |
|
28742 |
|
28743 |
|
28744 |
|
28745 | exports._sector = function() {
|
28746 | return this.activeSector[this.activeSector.length-1];
|
28747 | };
|
28748 |
|
28749 |
|
28750 | |
28751 |
|
28752 |
|
28753 |
|
28754 |
|
28755 |
|
28756 | exports._previousSector = function() {
|
28757 | if (this.activeSector.length > 1) {
|
28758 | return this.activeSector[this.activeSector.length-2];
|
28759 | }
|
28760 | else {
|
28761 | throw new TypeError('there are not enough sectors in the this.activeSector array.');
|
28762 | }
|
28763 | };
|
28764 |
|
28765 |
|
28766 | |
28767 |
|
28768 |
|
28769 |
|
28770 |
|
28771 |
|
28772 |
|
28773 |
|
28774 | exports._setActiveSector = function(newId) {
|
28775 | this.activeSector.push(newId);
|
28776 | };
|
28777 |
|
28778 |
|
28779 | |
28780 |
|
28781 |
|
28782 |
|
28783 |
|
28784 |
|
28785 | exports._forgetLastSector = function() {
|
28786 | this.activeSector.pop();
|
28787 | };
|
28788 |
|
28789 |
|
28790 | |
28791 |
|
28792 |
|
28793 |
|
28794 |
|
28795 |
|
28796 |
|
28797 | exports._createNewSector = function(newId) {
|
28798 |
|
28799 | this.sectors["active"][newId] = {"nodes":{},
|
28800 | "edges":{},
|
28801 | "nodeIndices":[],
|
28802 | "formationScale": this.scale,
|
28803 | "drawingNode": undefined};
|
28804 |
|
28805 |
|
28806 | this.sectors["active"][newId]['drawingNode'] = new Node(
|
28807 | {id:newId,
|
28808 | color: {
|
28809 | background: "#eaefef",
|
28810 | border: "495c5e"
|
28811 | }
|
28812 | },{},{},this.constants);
|
28813 | this.sectors["active"][newId]['drawingNode'].clusterSize = 2;
|
28814 | };
|
28815 |
|
28816 |
|
28817 | |
28818 |
|
28819 |
|
28820 |
|
28821 |
|
28822 |
|
28823 |
|
28824 | exports._deleteActiveSector = function(sectorId) {
|
28825 | delete this.sectors["active"][sectorId];
|
28826 | };
|
28827 |
|
28828 |
|
28829 | |
28830 |
|
28831 |
|
28832 |
|
28833 |
|
28834 |
|
28835 |
|
28836 | exports._deleteFrozenSector = function(sectorId) {
|
28837 | delete this.sectors["frozen"][sectorId];
|
28838 | };
|
28839 |
|
28840 |
|
28841 | |
28842 |
|
28843 |
|
28844 |
|
28845 |
|
28846 |
|
28847 |
|
28848 | exports._freezeSector = function(sectorId) {
|
28849 |
|
28850 | this.sectors["frozen"][sectorId] = this.sectors["active"][sectorId];
|
28851 |
|
28852 |
|
28853 | this._deleteActiveSector(sectorId);
|
28854 | };
|
28855 |
|
28856 |
|
28857 | |
28858 |
|
28859 |
|
28860 |
|
28861 |
|
28862 |
|
28863 |
|
28864 | exports._activateSector = function(sectorId) {
|
28865 |
|
28866 | this.sectors["active"][sectorId] = this.sectors["frozen"][sectorId];
|
28867 |
|
28868 |
|
28869 | this._deleteFrozenSector(sectorId);
|
28870 | };
|
28871 |
|
28872 |
|
28873 | |
28874 |
|
28875 |
|
28876 |
|
28877 |
|
28878 |
|
28879 |
|
28880 |
|
28881 |
|
28882 | exports._mergeThisWithFrozen = function(sectorId) {
|
28883 |
|
28884 | for (var nodeId in this.nodes) {
|
28885 | if (this.nodes.hasOwnProperty(nodeId)) {
|
28886 | this.sectors["frozen"][sectorId]["nodes"][nodeId] = this.nodes[nodeId];
|
28887 | }
|
28888 | }
|
28889 |
|
28890 |
|
28891 | for (var edgeId in this.edges) {
|
28892 | if (this.edges.hasOwnProperty(edgeId)) {
|
28893 | this.sectors["frozen"][sectorId]["edges"][edgeId] = this.edges[edgeId];
|
28894 | }
|
28895 | }
|
28896 |
|
28897 |
|
28898 | for (var i = 0; i < this.nodeIndices.length; i++) {
|
28899 | this.sectors["frozen"][sectorId]["nodeIndices"].push(this.nodeIndices[i]);
|
28900 | }
|
28901 | };
|
28902 |
|
28903 |
|
28904 | |
28905 |
|
28906 |
|
28907 |
|
28908 |
|
28909 |
|
28910 | exports._collapseThisToSingleCluster = function() {
|
28911 | this.clusterToFit(1,false);
|
28912 | };
|
28913 |
|
28914 |
|
28915 | |
28916 |
|
28917 |
|
28918 |
|
28919 |
|
28920 |
|
28921 | exports._addSector = function(node) {
|
28922 |
|
28923 | var sector = this._sector();
|
28924 |
|
28925 |
|
28926 |
|
28927 |
|
28928 |
|
28929 |
|
28930 |
|
28931 |
|
28932 |
|
28933 |
|
28934 | delete this.nodes[node.id];
|
28935 |
|
28936 | var unqiueIdentifier = util.randomUUID();
|
28937 |
|
28938 |
|
28939 | this._freezeSector(sector);
|
28940 |
|
28941 |
|
28942 | this._createNewSector(unqiueIdentifier);
|
28943 |
|
28944 |
|
28945 | this._setActiveSector(unqiueIdentifier);
|
28946 |
|
28947 |
|
28948 | this._switchToSector(this._sector());
|
28949 |
|
28950 |
|
28951 | this.nodes[node.id] = node;
|
28952 | };
|
28953 |
|
28954 |
|
28955 | |
28956 |
|
28957 |
|
28958 |
|
28959 |
|
28960 |
|
28961 | exports._collapseSector = function() {
|
28962 |
|
28963 | var sector = this._sector();
|
28964 |
|
28965 |
|
28966 | if (sector != "default") {
|
28967 | if ((this.nodeIndices.length == 1) ||
|
28968 | (this.sectors["active"][sector]["drawingNode"].width*this.scale < this.constants.clustering.screenSizeThreshold * this.frame.canvas.clientWidth) ||
|
28969 | (this.sectors["active"][sector]["drawingNode"].height*this.scale < this.constants.clustering.screenSizeThreshold * this.frame.canvas.clientHeight)) {
|
28970 | var previousSector = this._previousSector();
|
28971 |
|
28972 |
|
28973 | this._collapseThisToSingleCluster();
|
28974 |
|
28975 |
|
28976 |
|
28977 | this._mergeThisWithFrozen(previousSector);
|
28978 |
|
28979 |
|
28980 |
|
28981 | this._deleteActiveSector(sector);
|
28982 |
|
28983 |
|
28984 | this._activateSector(previousSector);
|
28985 |
|
28986 |
|
28987 | this._switchToSector(previousSector);
|
28988 |
|
28989 |
|
28990 | this._forgetLastSector();
|
28991 |
|
28992 |
|
28993 | this._updateNodeIndexList();
|
28994 |
|
28995 |
|
28996 | this._updateCalculationNodes();
|
28997 | }
|
28998 | }
|
28999 | };
|
29000 |
|
29001 |
|
29002 | |
29003 |
|
29004 |
|
29005 |
|
29006 |
|
29007 |
|
29008 |
|
29009 |
|
29010 |
|
29011 | exports._doInAllActiveSectors = function(runFunction,argument) {
|
29012 | var returnValues = [];
|
29013 | if (argument === undefined) {
|
29014 | for (var sector in this.sectors["active"]) {
|
29015 | if (this.sectors["active"].hasOwnProperty(sector)) {
|
29016 |
|
29017 | this._switchToActiveSector(sector);
|
29018 | returnValues.push( this[runFunction]() );
|
29019 | }
|
29020 | }
|
29021 | }
|
29022 | else {
|
29023 | for (var sector in this.sectors["active"]) {
|
29024 | if (this.sectors["active"].hasOwnProperty(sector)) {
|
29025 |
|
29026 | this._switchToActiveSector(sector);
|
29027 | var args = Array.prototype.splice.call(arguments, 1);
|
29028 | if (args.length > 1) {
|
29029 | returnValues.push( this[runFunction](args[0],args[1]) );
|
29030 | }
|
29031 | else {
|
29032 | returnValues.push( this[runFunction](argument) );
|
29033 | }
|
29034 | }
|
29035 | }
|
29036 | }
|
29037 |
|
29038 | this._loadLatestSector();
|
29039 | return returnValues;
|
29040 | };
|
29041 |
|
29042 |
|
29043 | |
29044 |
|
29045 |
|
29046 |
|
29047 |
|
29048 |
|
29049 |
|
29050 |
|
29051 |
|
29052 | exports._doInSupportSector = function(runFunction,argument) {
|
29053 | var returnValues = false;
|
29054 | if (argument === undefined) {
|
29055 | this._switchToSupportSector();
|
29056 | returnValues = this[runFunction]();
|
29057 | }
|
29058 | else {
|
29059 | this._switchToSupportSector();
|
29060 | var args = Array.prototype.splice.call(arguments, 1);
|
29061 | if (args.length > 1) {
|
29062 | returnValues = this[runFunction](args[0],args[1]);
|
29063 | }
|
29064 | else {
|
29065 | returnValues = this[runFunction](argument);
|
29066 | }
|
29067 | }
|
29068 |
|
29069 | this._loadLatestSector();
|
29070 | return returnValues;
|
29071 | };
|
29072 |
|
29073 |
|
29074 | |
29075 |
|
29076 |
|
29077 |
|
29078 |
|
29079 |
|
29080 |
|
29081 |
|
29082 |
|
29083 | exports._doInAllFrozenSectors = function(runFunction,argument) {
|
29084 | if (argument === undefined) {
|
29085 | for (var sector in this.sectors["frozen"]) {
|
29086 | if (this.sectors["frozen"].hasOwnProperty(sector)) {
|
29087 |
|
29088 | this._switchToFrozenSector(sector);
|
29089 | this[runFunction]();
|
29090 | }
|
29091 | }
|
29092 | }
|
29093 | else {
|
29094 | for (var sector in this.sectors["frozen"]) {
|
29095 | if (this.sectors["frozen"].hasOwnProperty(sector)) {
|
29096 |
|
29097 | this._switchToFrozenSector(sector);
|
29098 | var args = Array.prototype.splice.call(arguments, 1);
|
29099 | if (args.length > 1) {
|
29100 | this[runFunction](args[0],args[1]);
|
29101 | }
|
29102 | else {
|
29103 | this[runFunction](argument);
|
29104 | }
|
29105 | }
|
29106 | }
|
29107 | }
|
29108 | this._loadLatestSector();
|
29109 | };
|
29110 |
|
29111 |
|
29112 | |
29113 |
|
29114 |
|
29115 |
|
29116 |
|
29117 |
|
29118 |
|
29119 |
|
29120 |
|
29121 | exports._doInAllSectors = function(runFunction,argument) {
|
29122 | var args = Array.prototype.splice.call(arguments, 1);
|
29123 | if (argument === undefined) {
|
29124 | this._doInAllActiveSectors(runFunction);
|
29125 | this._doInAllFrozenSectors(runFunction);
|
29126 | }
|
29127 | else {
|
29128 | if (args.length > 1) {
|
29129 | this._doInAllActiveSectors(runFunction,args[0],args[1]);
|
29130 | this._doInAllFrozenSectors(runFunction,args[0],args[1]);
|
29131 | }
|
29132 | else {
|
29133 | this._doInAllActiveSectors(runFunction,argument);
|
29134 | this._doInAllFrozenSectors(runFunction,argument);
|
29135 | }
|
29136 | }
|
29137 | };
|
29138 |
|
29139 |
|
29140 | |
29141 |
|
29142 |
|
29143 |
|
29144 |
|
29145 |
|
29146 | exports._clearNodeIndexList = function() {
|
29147 | var sector = this._sector();
|
29148 | this.sectors["active"][sector]["nodeIndices"] = [];
|
29149 | this.nodeIndices = this.sectors["active"][sector]["nodeIndices"];
|
29150 | };
|
29151 |
|
29152 |
|
29153 | |
29154 |
|
29155 |
|
29156 |
|
29157 |
|
29158 |
|
29159 |
|
29160 | exports._drawSectorNodes = function(ctx,sectorType) {
|
29161 | var minY = 1e9, maxY = -1e9, minX = 1e9, maxX = -1e9, node;
|
29162 | for (var sector in this.sectors[sectorType]) {
|
29163 | if (this.sectors[sectorType].hasOwnProperty(sector)) {
|
29164 | if (this.sectors[sectorType][sector]["drawingNode"] !== undefined) {
|
29165 |
|
29166 | this._switchToSector(sector,sectorType);
|
29167 |
|
29168 | minY = 1e9; maxY = -1e9; minX = 1e9; maxX = -1e9;
|
29169 | for (var nodeId in this.nodes) {
|
29170 | if (this.nodes.hasOwnProperty(nodeId)) {
|
29171 | node = this.nodes[nodeId];
|
29172 | node.resize(ctx);
|
29173 | if (minX > node.x - 0.5 * node.width) {minX = node.x - 0.5 * node.width;}
|
29174 | if (maxX < node.x + 0.5 * node.width) {maxX = node.x + 0.5 * node.width;}
|
29175 | if (minY > node.y - 0.5 * node.height) {minY = node.y - 0.5 * node.height;}
|
29176 | if (maxY < node.y + 0.5 * node.height) {maxY = node.y + 0.5 * node.height;}
|
29177 | }
|
29178 | }
|
29179 | node = this.sectors[sectorType][sector]["drawingNode"];
|
29180 | node.x = 0.5 * (maxX + minX);
|
29181 | node.y = 0.5 * (maxY + minY);
|
29182 | node.width = 2 * (node.x - minX);
|
29183 | node.height = 2 * (node.y - minY);
|
29184 | node.radius = Math.sqrt(Math.pow(0.5*node.width,2) + Math.pow(0.5*node.height,2));
|
29185 | node.setScale(this.scale);
|
29186 | node._drawCircle(ctx);
|
29187 | }
|
29188 | }
|
29189 | }
|
29190 | };
|
29191 |
|
29192 | exports._drawAllSectorNodes = function(ctx) {
|
29193 | this._drawSectorNodes(ctx,"frozen");
|
29194 | this._drawSectorNodes(ctx,"active");
|
29195 | this._loadLatestSector();
|
29196 | };
|
29197 |
|
29198 |
|
29199 | },
|
29200 |
|
29201 | function(module, exports, __webpack_require__) {
|
29202 |
|
29203 | var Node = __webpack_require__(37);
|
29204 |
|
29205 | |
29206 |
|
29207 |
|
29208 |
|
29209 |
|
29210 |
|
29211 |
|
29212 | exports._getNodesOverlappingWith = function(object, overlappingNodes) {
|
29213 | var nodes = this.nodes;
|
29214 | for (var nodeId in nodes) {
|
29215 | if (nodes.hasOwnProperty(nodeId)) {
|
29216 | if (nodes[nodeId].isOverlappingWith(object)) {
|
29217 | overlappingNodes.push(nodeId);
|
29218 | }
|
29219 | }
|
29220 | }
|
29221 | };
|
29222 |
|
29223 | |
29224 |
|
29225 |
|
29226 |
|
29227 |
|
29228 |
|
29229 | exports._getAllNodesOverlappingWith = function (object) {
|
29230 | var overlappingNodes = [];
|
29231 | this._doInAllActiveSectors("_getNodesOverlappingWith",object,overlappingNodes);
|
29232 | return overlappingNodes;
|
29233 | };
|
29234 |
|
29235 |
|
29236 | |
29237 |
|
29238 |
|
29239 |
|
29240 |
|
29241 |
|
29242 |
|
29243 | exports._pointerToPositionObject = function(pointer) {
|
29244 | var x = this._XconvertDOMtoCanvas(pointer.x);
|
29245 | var y = this._YconvertDOMtoCanvas(pointer.y);
|
29246 |
|
29247 | return {
|
29248 | left: x,
|
29249 | top: y,
|
29250 | right: x,
|
29251 | bottom: y
|
29252 | };
|
29253 | };
|
29254 |
|
29255 |
|
29256 | |
29257 |
|
29258 |
|
29259 |
|
29260 |
|
29261 |
|
29262 |
|
29263 | exports._getNodeAt = function (pointer) {
|
29264 |
|
29265 | var positionObject = this._pointerToPositionObject(pointer);
|
29266 | var overlappingNodes = this._getAllNodesOverlappingWith(positionObject);
|
29267 |
|
29268 |
|
29269 |
|
29270 | if (overlappingNodes.length > 0) {
|
29271 | return this.nodes[overlappingNodes[overlappingNodes.length - 1]];
|
29272 | }
|
29273 | else {
|
29274 | return null;
|
29275 | }
|
29276 | };
|
29277 |
|
29278 |
|
29279 | |
29280 |
|
29281 |
|
29282 |
|
29283 |
|
29284 |
|
29285 | exports._getEdgesOverlappingWith = function (object, overlappingEdges) {
|
29286 | var edges = this.edges;
|
29287 | for (var edgeId in edges) {
|
29288 | if (edges.hasOwnProperty(edgeId)) {
|
29289 | if (edges[edgeId].isOverlappingWith(object)) {
|
29290 | overlappingEdges.push(edgeId);
|
29291 | }
|
29292 | }
|
29293 | }
|
29294 | };
|
29295 |
|
29296 |
|
29297 | |
29298 |
|
29299 |
|
29300 |
|
29301 |
|
29302 |
|
29303 | exports._getAllEdgesOverlappingWith = function (object) {
|
29304 | var overlappingEdges = [];
|
29305 | this._doInAllActiveSectors("_getEdgesOverlappingWith",object,overlappingEdges);
|
29306 | return overlappingEdges;
|
29307 | };
|
29308 |
|
29309 | |
29310 |
|
29311 |
|
29312 |
|
29313 |
|
29314 |
|
29315 |
|
29316 |
|
29317 | exports._getEdgeAt = function(pointer) {
|
29318 | var positionObject = this._pointerToPositionObject(pointer);
|
29319 | var overlappingEdges = this._getAllEdgesOverlappingWith(positionObject);
|
29320 |
|
29321 | if (overlappingEdges.length > 0) {
|
29322 | return this.edges[overlappingEdges[overlappingEdges.length - 1]];
|
29323 | }
|
29324 | else {
|
29325 | return null;
|
29326 | }
|
29327 | };
|
29328 |
|
29329 |
|
29330 | |
29331 |
|
29332 |
|
29333 |
|
29334 |
|
29335 |
|
29336 | exports._addToSelection = function(obj) {
|
29337 | if (obj instanceof Node) {
|
29338 | this.selectionObj.nodes[obj.id] = obj;
|
29339 | }
|
29340 | else {
|
29341 | this.selectionObj.edges[obj.id] = obj;
|
29342 | }
|
29343 | };
|
29344 |
|
29345 | |
29346 |
|
29347 |
|
29348 |
|
29349 |
|
29350 |
|
29351 | exports._addToHover = function(obj) {
|
29352 | if (obj instanceof Node) {
|
29353 | this.hoverObj.nodes[obj.id] = obj;
|
29354 | }
|
29355 | else {
|
29356 | this.hoverObj.edges[obj.id] = obj;
|
29357 | }
|
29358 | };
|
29359 |
|
29360 |
|
29361 | |
29362 |
|
29363 |
|
29364 |
|
29365 |
|
29366 |
|
29367 | exports._removeFromSelection = function(obj) {
|
29368 | if (obj instanceof Node) {
|
29369 | delete this.selectionObj.nodes[obj.id];
|
29370 | }
|
29371 | else {
|
29372 | delete this.selectionObj.edges[obj.id];
|
29373 | }
|
29374 | };
|
29375 |
|
29376 | |
29377 |
|
29378 |
|
29379 |
|
29380 |
|
29381 |
|
29382 | exports._unselectAll = function(doNotTrigger) {
|
29383 | if (doNotTrigger === undefined) {
|
29384 | doNotTrigger = false;
|
29385 | }
|
29386 | for(var nodeId in this.selectionObj.nodes) {
|
29387 | if(this.selectionObj.nodes.hasOwnProperty(nodeId)) {
|
29388 | this.selectionObj.nodes[nodeId].unselect();
|
29389 | }
|
29390 | }
|
29391 | for(var edgeId in this.selectionObj.edges) {
|
29392 | if(this.selectionObj.edges.hasOwnProperty(edgeId)) {
|
29393 | this.selectionObj.edges[edgeId].unselect();
|
29394 | }
|
29395 | }
|
29396 |
|
29397 | this.selectionObj = {nodes:{},edges:{}};
|
29398 |
|
29399 | if (doNotTrigger == false) {
|
29400 | this.emit('select', this.getSelection());
|
29401 | }
|
29402 | };
|
29403 |
|
29404 | |
29405 |
|
29406 |
|
29407 |
|
29408 |
|
29409 |
|
29410 | exports._unselectClusters = function(doNotTrigger) {
|
29411 | if (doNotTrigger === undefined) {
|
29412 | doNotTrigger = false;
|
29413 | }
|
29414 |
|
29415 | for (var nodeId in this.selectionObj.nodes) {
|
29416 | if (this.selectionObj.nodes.hasOwnProperty(nodeId)) {
|
29417 | if (this.selectionObj.nodes[nodeId].clusterSize > 1) {
|
29418 | this.selectionObj.nodes[nodeId].unselect();
|
29419 | this._removeFromSelection(this.selectionObj.nodes[nodeId]);
|
29420 | }
|
29421 | }
|
29422 | }
|
29423 |
|
29424 | if (doNotTrigger == false) {
|
29425 | this.emit('select', this.getSelection());
|
29426 | }
|
29427 | };
|
29428 |
|
29429 |
|
29430 | |
29431 |
|
29432 |
|
29433 |
|
29434 |
|
29435 |
|
29436 | exports._getSelectedNodeCount = function() {
|
29437 | var count = 0;
|
29438 | for (var nodeId in this.selectionObj.nodes) {
|
29439 | if (this.selectionObj.nodes.hasOwnProperty(nodeId)) {
|
29440 | count += 1;
|
29441 | }
|
29442 | }
|
29443 | return count;
|
29444 | };
|
29445 |
|
29446 | |
29447 |
|
29448 |
|
29449 |
|
29450 |
|
29451 |
|
29452 | exports._getSelectedNode = function() {
|
29453 | for (var nodeId in this.selectionObj.nodes) {
|
29454 | if (this.selectionObj.nodes.hasOwnProperty(nodeId)) {
|
29455 | return this.selectionObj.nodes[nodeId];
|
29456 | }
|
29457 | }
|
29458 | return null;
|
29459 | };
|
29460 |
|
29461 | |
29462 |
|
29463 |
|
29464 |
|
29465 |
|
29466 |
|
29467 | exports._getSelectedEdge = function() {
|
29468 | for (var edgeId in this.selectionObj.edges) {
|
29469 | if (this.selectionObj.edges.hasOwnProperty(edgeId)) {
|
29470 | return this.selectionObj.edges[edgeId];
|
29471 | }
|
29472 | }
|
29473 | return null;
|
29474 | };
|
29475 |
|
29476 |
|
29477 | |
29478 |
|
29479 |
|
29480 |
|
29481 |
|
29482 |
|
29483 | exports._getSelectedEdgeCount = function() {
|
29484 | var count = 0;
|
29485 | for (var edgeId in this.selectionObj.edges) {
|
29486 | if (this.selectionObj.edges.hasOwnProperty(edgeId)) {
|
29487 | count += 1;
|
29488 | }
|
29489 | }
|
29490 | return count;
|
29491 | };
|
29492 |
|
29493 |
|
29494 | |
29495 |
|
29496 |
|
29497 |
|
29498 |
|
29499 |
|
29500 | exports._getSelectedObjectCount = function() {
|
29501 | var count = 0;
|
29502 | for(var nodeId in this.selectionObj.nodes) {
|
29503 | if(this.selectionObj.nodes.hasOwnProperty(nodeId)) {
|
29504 | count += 1;
|
29505 | }
|
29506 | }
|
29507 | for(var edgeId in this.selectionObj.edges) {
|
29508 | if(this.selectionObj.edges.hasOwnProperty(edgeId)) {
|
29509 | count += 1;
|
29510 | }
|
29511 | }
|
29512 | return count;
|
29513 | };
|
29514 |
|
29515 | |
29516 |
|
29517 |
|
29518 |
|
29519 |
|
29520 |
|
29521 | exports._selectionIsEmpty = function() {
|
29522 | for(var nodeId in this.selectionObj.nodes) {
|
29523 | if(this.selectionObj.nodes.hasOwnProperty(nodeId)) {
|
29524 | return false;
|
29525 | }
|
29526 | }
|
29527 | for(var edgeId in this.selectionObj.edges) {
|
29528 | if(this.selectionObj.edges.hasOwnProperty(edgeId)) {
|
29529 | return false;
|
29530 | }
|
29531 | }
|
29532 | return true;
|
29533 | };
|
29534 |
|
29535 |
|
29536 | |
29537 |
|
29538 |
|
29539 |
|
29540 |
|
29541 |
|
29542 | exports._clusterInSelection = function() {
|
29543 | for(var nodeId in this.selectionObj.nodes) {
|
29544 | if(this.selectionObj.nodes.hasOwnProperty(nodeId)) {
|
29545 | if (this.selectionObj.nodes[nodeId].clusterSize > 1) {
|
29546 | return true;
|
29547 | }
|
29548 | }
|
29549 | }
|
29550 | return false;
|
29551 | };
|
29552 |
|
29553 | |
29554 |
|
29555 |
|
29556 |
|
29557 |
|
29558 |
|
29559 | exports._selectConnectedEdges = function(node) {
|
29560 | for (var i = 0; i < node.dynamicEdges.length; i++) {
|
29561 | var edge = node.dynamicEdges[i];
|
29562 | edge.select();
|
29563 | this._addToSelection(edge);
|
29564 | }
|
29565 | };
|
29566 |
|
29567 | |
29568 |
|
29569 |
|
29570 |
|
29571 |
|
29572 |
|
29573 | exports._hoverConnectedEdges = function(node) {
|
29574 | for (var i = 0; i < node.dynamicEdges.length; i++) {
|
29575 | var edge = node.dynamicEdges[i];
|
29576 | edge.hover = true;
|
29577 | this._addToHover(edge);
|
29578 | }
|
29579 | };
|
29580 |
|
29581 |
|
29582 | |
29583 |
|
29584 |
|
29585 |
|
29586 |
|
29587 |
|
29588 | exports._unselectConnectedEdges = function(node) {
|
29589 | for (var i = 0; i < node.dynamicEdges.length; i++) {
|
29590 | var edge = node.dynamicEdges[i];
|
29591 | edge.unselect();
|
29592 | this._removeFromSelection(edge);
|
29593 | }
|
29594 | };
|
29595 |
|
29596 |
|
29597 |
|
29598 |
|
29599 | |
29600 |
|
29601 |
|
29602 |
|
29603 |
|
29604 |
|
29605 |
|
29606 |
|
29607 |
|
29608 | exports._selectObject = function(object, append, doNotTrigger, highlightEdges) {
|
29609 | if (doNotTrigger === undefined) {
|
29610 | doNotTrigger = false;
|
29611 | }
|
29612 | if (highlightEdges === undefined) {
|
29613 | highlightEdges = true;
|
29614 | }
|
29615 |
|
29616 | if (this._selectionIsEmpty() == false && append == false && this.forceAppendSelection == false) {
|
29617 | this._unselectAll(true);
|
29618 | }
|
29619 |
|
29620 | if (object.selected == false) {
|
29621 | object.select();
|
29622 | this._addToSelection(object);
|
29623 | if (object instanceof Node && this.blockConnectingEdgeSelection == false && highlightEdges == true) {
|
29624 | this._selectConnectedEdges(object);
|
29625 | }
|
29626 | }
|
29627 | else {
|
29628 | object.unselect();
|
29629 | this._removeFromSelection(object);
|
29630 | }
|
29631 |
|
29632 | if (doNotTrigger == false) {
|
29633 | this.emit('select', this.getSelection());
|
29634 | }
|
29635 | };
|
29636 |
|
29637 |
|
29638 | |
29639 |
|
29640 |
|
29641 |
|
29642 |
|
29643 |
|
29644 |
|
29645 | exports._blurObject = function(object) {
|
29646 | if (object.hover == true) {
|
29647 | object.hover = false;
|
29648 | this.emit("blurNode",{node:object.id});
|
29649 | }
|
29650 | };
|
29651 |
|
29652 | |
29653 |
|
29654 |
|
29655 |
|
29656 |
|
29657 |
|
29658 |
|
29659 | exports._hoverObject = function(object) {
|
29660 | if (object.hover == false) {
|
29661 | object.hover = true;
|
29662 | this._addToHover(object);
|
29663 | if (object instanceof Node) {
|
29664 | this.emit("hoverNode",{node:object.id});
|
29665 | }
|
29666 | }
|
29667 | if (object instanceof Node) {
|
29668 | this._hoverConnectedEdges(object);
|
29669 | }
|
29670 | };
|
29671 |
|
29672 |
|
29673 | |
29674 |
|
29675 |
|
29676 |
|
29677 |
|
29678 |
|
29679 |
|
29680 |
|
29681 | exports._handleTouch = function(pointer) {
|
29682 | };
|
29683 |
|
29684 |
|
29685 | |
29686 |
|
29687 |
|
29688 |
|
29689 |
|
29690 |
|
29691 | exports._handleTap = function(pointer) {
|
29692 | var node = this._getNodeAt(pointer);
|
29693 | if (node != null) {
|
29694 | this._selectObject(node,false);
|
29695 | }
|
29696 | else {
|
29697 | var edge = this._getEdgeAt(pointer);
|
29698 | if (edge != null) {
|
29699 | this._selectObject(edge,false);
|
29700 | }
|
29701 | else {
|
29702 | this._unselectAll();
|
29703 | }
|
29704 | }
|
29705 | this.emit("click", this.getSelection());
|
29706 | this._redraw();
|
29707 | };
|
29708 |
|
29709 |
|
29710 | |
29711 |
|
29712 |
|
29713 |
|
29714 |
|
29715 |
|
29716 | exports._handleDoubleTap = function(pointer) {
|
29717 | var node = this._getNodeAt(pointer);
|
29718 | if (node != null && node !== undefined) {
|
29719 |
|
29720 | this.areaCenter = {"x" : this._XconvertDOMtoCanvas(pointer.x),
|
29721 | "y" : this._YconvertDOMtoCanvas(pointer.y)};
|
29722 | this.openCluster(node);
|
29723 | }
|
29724 | this.emit("doubleClick", this.getSelection());
|
29725 | };
|
29726 |
|
29727 |
|
29728 | |
29729 |
|
29730 |
|
29731 |
|
29732 |
|
29733 |
|
29734 | exports._handleOnHold = function(pointer) {
|
29735 | var node = this._getNodeAt(pointer);
|
29736 | if (node != null) {
|
29737 | this._selectObject(node,true);
|
29738 | }
|
29739 | else {
|
29740 | var edge = this._getEdgeAt(pointer);
|
29741 | if (edge != null) {
|
29742 | this._selectObject(edge,true);
|
29743 | }
|
29744 | }
|
29745 | this._redraw();
|
29746 | };
|
29747 |
|
29748 |
|
29749 | |
29750 |
|
29751 |
|
29752 |
|
29753 |
|
29754 | exports._handleOnRelease = function(pointer) {
|
29755 |
|
29756 | };
|
29757 |
|
29758 |
|
29759 |
|
29760 | |
29761 |
|
29762 |
|
29763 |
|
29764 |
|
29765 | exports.getSelection = function() {
|
29766 | var nodeIds = this.getSelectedNodes();
|
29767 | var edgeIds = this.getSelectedEdges();
|
29768 | return {nodes:nodeIds, edges:edgeIds};
|
29769 | };
|
29770 |
|
29771 | |
29772 |
|
29773 |
|
29774 |
|
29775 |
|
29776 |
|
29777 | exports.getSelectedNodes = function() {
|
29778 | var idArray = [];
|
29779 | for(var nodeId in this.selectionObj.nodes) {
|
29780 | if(this.selectionObj.nodes.hasOwnProperty(nodeId)) {
|
29781 | idArray.push(nodeId);
|
29782 | }
|
29783 | }
|
29784 | return idArray
|
29785 | };
|
29786 |
|
29787 | |
29788 |
|
29789 |
|
29790 |
|
29791 |
|
29792 |
|
29793 | exports.getSelectedEdges = function() {
|
29794 | var idArray = [];
|
29795 | for(var edgeId in this.selectionObj.edges) {
|
29796 | if(this.selectionObj.edges.hasOwnProperty(edgeId)) {
|
29797 | idArray.push(edgeId);
|
29798 | }
|
29799 | }
|
29800 | return idArray;
|
29801 | };
|
29802 |
|
29803 |
|
29804 | |
29805 |
|
29806 |
|
29807 |
|
29808 |
|
29809 | exports.setSelection = function(selection) {
|
29810 | var i, iMax, id;
|
29811 |
|
29812 | if (!selection || (selection.length == undefined))
|
29813 | throw 'Selection must be an array with ids';
|
29814 |
|
29815 |
|
29816 | this._unselectAll(true);
|
29817 |
|
29818 | for (i = 0, iMax = selection.length; i < iMax; i++) {
|
29819 | id = selection[i];
|
29820 |
|
29821 | var node = this.nodes[id];
|
29822 | if (!node) {
|
29823 | throw new RangeError('Node with id "' + id + '" not found');
|
29824 | }
|
29825 | this._selectObject(node,true,true);
|
29826 | }
|
29827 |
|
29828 | console.log("setSelection is deprecated. Please use selectNodes instead.")
|
29829 |
|
29830 | this.redraw();
|
29831 | };
|
29832 |
|
29833 |
|
29834 | |
29835 |
|
29836 |
|
29837 |
|
29838 |
|
29839 |
|
29840 | exports.selectNodes = function(selection, highlightEdges) {
|
29841 | var i, iMax, id;
|
29842 |
|
29843 | if (!selection || (selection.length == undefined))
|
29844 | throw 'Selection must be an array with ids';
|
29845 |
|
29846 |
|
29847 | this._unselectAll(true);
|
29848 |
|
29849 | for (i = 0, iMax = selection.length; i < iMax; i++) {
|
29850 | id = selection[i];
|
29851 |
|
29852 | var node = this.nodes[id];
|
29853 | if (!node) {
|
29854 | throw new RangeError('Node with id "' + id + '" not found');
|
29855 | }
|
29856 | this._selectObject(node,true,true,highlightEdges);
|
29857 | }
|
29858 | this.redraw();
|
29859 | };
|
29860 |
|
29861 |
|
29862 | |
29863 |
|
29864 |
|
29865 |
|
29866 |
|
29867 | exports.selectEdges = function(selection) {
|
29868 | var i, iMax, id;
|
29869 |
|
29870 | if (!selection || (selection.length == undefined))
|
29871 | throw 'Selection must be an array with ids';
|
29872 |
|
29873 |
|
29874 | this._unselectAll(true);
|
29875 |
|
29876 | for (i = 0, iMax = selection.length; i < iMax; i++) {
|
29877 | id = selection[i];
|
29878 |
|
29879 | var edge = this.edges[id];
|
29880 | if (!edge) {
|
29881 | throw new RangeError('Edge with id "' + id + '" not found');
|
29882 | }
|
29883 | this._selectObject(edge,true,true,highlightEdges);
|
29884 | }
|
29885 | this.redraw();
|
29886 | };
|
29887 |
|
29888 | |
29889 |
|
29890 |
|
29891 |
|
29892 | exports._updateSelection = function () {
|
29893 | for(var nodeId in this.selectionObj.nodes) {
|
29894 | if(this.selectionObj.nodes.hasOwnProperty(nodeId)) {
|
29895 | if (!this.nodes.hasOwnProperty(nodeId)) {
|
29896 | delete this.selectionObj.nodes[nodeId];
|
29897 | }
|
29898 | }
|
29899 | }
|
29900 | for(var edgeId in this.selectionObj.edges) {
|
29901 | if(this.selectionObj.edges.hasOwnProperty(edgeId)) {
|
29902 | if (!this.edges.hasOwnProperty(edgeId)) {
|
29903 | delete this.selectionObj.edges[edgeId];
|
29904 | }
|
29905 | }
|
29906 | }
|
29907 | };
|
29908 |
|
29909 |
|
29910 | },
|
29911 |
|
29912 | function(module, exports, __webpack_require__) {
|
29913 |
|
29914 | var util = __webpack_require__(1);
|
29915 | var Node = __webpack_require__(37);
|
29916 | var Edge = __webpack_require__(34);
|
29917 |
|
29918 | |
29919 |
|
29920 |
|
29921 |
|
29922 |
|
29923 | exports._clearManipulatorBar = function() {
|
29924 | while (this.manipulationDiv.hasChildNodes()) {
|
29925 | this.manipulationDiv.removeChild(this.manipulationDiv.firstChild);
|
29926 | }
|
29927 | };
|
29928 |
|
29929 | |
29930 |
|
29931 |
|
29932 |
|
29933 |
|
29934 |
|
29935 |
|
29936 | exports._restoreOverloadedFunctions = function() {
|
29937 | for (var functionName in this.cachedFunctions) {
|
29938 | if (this.cachedFunctions.hasOwnProperty(functionName)) {
|
29939 | this[functionName] = this.cachedFunctions[functionName];
|
29940 | }
|
29941 | }
|
29942 | };
|
29943 |
|
29944 | |
29945 |
|
29946 |
|
29947 |
|
29948 |
|
29949 | exports._toggleEditMode = function() {
|
29950 | this.editMode = !this.editMode;
|
29951 | var toolbar = document.getElementById("network-manipulationDiv");
|
29952 | var closeDiv = document.getElementById("network-manipulation-closeDiv");
|
29953 | var editModeDiv = document.getElementById("network-manipulation-editMode");
|
29954 | if (this.editMode == true) {
|
29955 | toolbar.style.display="block";
|
29956 | closeDiv.style.display="block";
|
29957 | editModeDiv.style.display="none";
|
29958 | closeDiv.onclick = this._toggleEditMode.bind(this);
|
29959 | }
|
29960 | else {
|
29961 | toolbar.style.display="none";
|
29962 | closeDiv.style.display="none";
|
29963 | editModeDiv.style.display="block";
|
29964 | closeDiv.onclick = null;
|
29965 | }
|
29966 | this._createManipulatorBar()
|
29967 | };
|
29968 |
|
29969 | |
29970 |
|
29971 |
|
29972 |
|
29973 |
|
29974 | exports._createManipulatorBar = function() {
|
29975 |
|
29976 | if (this.boundFunction) {
|
29977 | this.off('select', this.boundFunction);
|
29978 | }
|
29979 |
|
29980 | var locale = this.constants.locales[this.constants.locale];
|
29981 |
|
29982 | if (this.edgeBeingEdited !== undefined) {
|
29983 | this.edgeBeingEdited._disableControlNodes();
|
29984 | this.edgeBeingEdited = undefined;
|
29985 | this.selectedControlNode = null;
|
29986 | this.controlNodesActive = false;
|
29987 | }
|
29988 |
|
29989 |
|
29990 | this._restoreOverloadedFunctions();
|
29991 |
|
29992 |
|
29993 | this.freezeSimulation = false;
|
29994 |
|
29995 |
|
29996 | this.blockConnectingEdgeSelection = false;
|
29997 | this.forceAppendSelection = false;
|
29998 |
|
29999 | if (this.editMode == true) {
|
30000 | while (this.manipulationDiv.hasChildNodes()) {
|
30001 | this.manipulationDiv.removeChild(this.manipulationDiv.firstChild);
|
30002 | }
|
30003 |
|
30004 |
|
30005 | this.manipulationDiv.innerHTML = "" +
|
30006 | "<span class='network-manipulationUI add' id='network-manipulate-addNode'>" +
|
30007 | "<span class='network-manipulationLabel'>"+locale['addNode'] +"</span></span>" +
|
30008 | "<div class='network-seperatorLine'></div>" +
|
30009 | "<span class='network-manipulationUI connect' id='network-manipulate-connectNode'>" +
|
30010 | "<span class='network-manipulationLabel'>"+locale['addEdge'] +"</span></span>";
|
30011 | if (this._getSelectedNodeCount() == 1 && this.triggerFunctions.edit) {
|
30012 | this.manipulationDiv.innerHTML += "" +
|
30013 | "<div class='network-seperatorLine'></div>" +
|
30014 | "<span class='network-manipulationUI edit' id='network-manipulate-editNode'>" +
|
30015 | "<span class='network-manipulationLabel'>"+locale['editNode'] +"</span></span>";
|
30016 | }
|
30017 | else if (this._getSelectedEdgeCount() == 1 && this._getSelectedNodeCount() == 0) {
|
30018 | this.manipulationDiv.innerHTML += "" +
|
30019 | "<div class='network-seperatorLine'></div>" +
|
30020 | "<span class='network-manipulationUI edit' id='network-manipulate-editEdge'>" +
|
30021 | "<span class='network-manipulationLabel'>"+locale['editEdge'] +"</span></span>";
|
30022 | }
|
30023 | if (this._selectionIsEmpty() == false) {
|
30024 | this.manipulationDiv.innerHTML += "" +
|
30025 | "<div class='network-seperatorLine'></div>" +
|
30026 | "<span class='network-manipulationUI delete' id='network-manipulate-delete'>" +
|
30027 | "<span class='network-manipulationLabel'>"+locale['del'] +"</span></span>";
|
30028 | }
|
30029 |
|
30030 |
|
30031 |
|
30032 | var addNodeButton = document.getElementById("network-manipulate-addNode");
|
30033 | addNodeButton.onclick = this._createAddNodeToolbar.bind(this);
|
30034 | var addEdgeButton = document.getElementById("network-manipulate-connectNode");
|
30035 | addEdgeButton.onclick = this._createAddEdgeToolbar.bind(this);
|
30036 | if (this._getSelectedNodeCount() == 1 && this.triggerFunctions.edit) {
|
30037 | var editButton = document.getElementById("network-manipulate-editNode");
|
30038 | editButton.onclick = this._editNode.bind(this);
|
30039 | }
|
30040 | else if (this._getSelectedEdgeCount() == 1 && this._getSelectedNodeCount() == 0) {
|
30041 | var editButton = document.getElementById("network-manipulate-editEdge");
|
30042 | editButton.onclick = this._createEditEdgeToolbar.bind(this);
|
30043 | }
|
30044 | if (this._selectionIsEmpty() == false) {
|
30045 | var deleteButton = document.getElementById("network-manipulate-delete");
|
30046 | deleteButton.onclick = this._deleteSelected.bind(this);
|
30047 | }
|
30048 | var closeDiv = document.getElementById("network-manipulation-closeDiv");
|
30049 | closeDiv.onclick = this._toggleEditMode.bind(this);
|
30050 |
|
30051 | this.boundFunction = this._createManipulatorBar.bind(this);
|
30052 | this.on('select', this.boundFunction);
|
30053 | }
|
30054 | else {
|
30055 | this.editModeDiv.innerHTML = "" +
|
30056 | "<span class='network-manipulationUI edit editmode' id='network-manipulate-editModeButton'>" +
|
30057 | "<span class='network-manipulationLabel'>" + locale['edit'] + "</span></span>";
|
30058 | var editModeButton = document.getElementById("network-manipulate-editModeButton");
|
30059 | editModeButton.onclick = this._toggleEditMode.bind(this);
|
30060 | }
|
30061 | };
|
30062 |
|
30063 |
|
30064 |
|
30065 | |
30066 |
|
30067 |
|
30068 |
|
30069 |
|
30070 | exports._createAddNodeToolbar = function() {
|
30071 |
|
30072 | this._clearManipulatorBar();
|
30073 | if (this.boundFunction) {
|
30074 | this.off('select', this.boundFunction);
|
30075 | }
|
30076 |
|
30077 | var locale = this.constants.locales[this.constants.locale];
|
30078 |
|
30079 |
|
30080 | this.manipulationDiv.innerHTML = "" +
|
30081 | "<span class='network-manipulationUI back' id='network-manipulate-back'>" +
|
30082 | "<span class='network-manipulationLabel'>" + locale['back'] + " </span></span>" +
|
30083 | "<div class='network-seperatorLine'></div>" +
|
30084 | "<span class='network-manipulationUI none' id='network-manipulate-back'>" +
|
30085 | "<span id='network-manipulatorLabel' class='network-manipulationLabel'>" + locale['addDescription'] + "</span></span>";
|
30086 |
|
30087 |
|
30088 | var backButton = document.getElementById("network-manipulate-back");
|
30089 | backButton.onclick = this._createManipulatorBar.bind(this);
|
30090 |
|
30091 |
|
30092 | this.boundFunction = this._addNode.bind(this);
|
30093 | this.on('select', this.boundFunction);
|
30094 | };
|
30095 |
|
30096 |
|
30097 | |
30098 |
|
30099 |
|
30100 |
|
30101 |
|
30102 | exports._createAddEdgeToolbar = function() {
|
30103 |
|
30104 | this._clearManipulatorBar();
|
30105 | this._unselectAll(true);
|
30106 | this.freezeSimulation = true;
|
30107 |
|
30108 | var locale = this.constants.locales[this.constants.locale];
|
30109 |
|
30110 | if (this.boundFunction) {
|
30111 | this.off('select', this.boundFunction);
|
30112 | }
|
30113 |
|
30114 | this._unselectAll();
|
30115 | this.forceAppendSelection = false;
|
30116 | this.blockConnectingEdgeSelection = true;
|
30117 |
|
30118 | this.manipulationDiv.innerHTML = "" +
|
30119 | "<span class='network-manipulationUI back' id='network-manipulate-back'>" +
|
30120 | "<span class='network-manipulationLabel'>" + locale['back'] + " </span></span>" +
|
30121 | "<div class='network-seperatorLine'></div>" +
|
30122 | "<span class='network-manipulationUI none' id='network-manipulate-back'>" +
|
30123 | "<span id='network-manipulatorLabel' class='network-manipulationLabel'>" + locale['edgeDescription'] + "</span></span>";
|
30124 |
|
30125 |
|
30126 | var backButton = document.getElementById("network-manipulate-back");
|
30127 | backButton.onclick = this._createManipulatorBar.bind(this);
|
30128 |
|
30129 |
|
30130 | this.boundFunction = this._handleConnect.bind(this);
|
30131 | this.on('select', this.boundFunction);
|
30132 |
|
30133 |
|
30134 | this.cachedFunctions["_handleTouch"] = this._handleTouch;
|
30135 | this.cachedFunctions["_handleOnRelease"] = this._handleOnRelease;
|
30136 | this.cachedFunctions["_handleDragStart"] = this._handleDragStart;
|
30137 | this.cachedFunctions["_handleDragEnd"] = this._handleDragEnd;
|
30138 | this._handleTouch = this._handleConnect;
|
30139 | this._handleOnRelease = function () {};
|
30140 | this._handleDragStart = function () {};
|
30141 | this._handleDragEnd = this._finishConnect;
|
30142 |
|
30143 |
|
30144 | this._redraw();
|
30145 | };
|
30146 |
|
30147 | |
30148 |
|
30149 |
|
30150 |
|
30151 |
|
30152 | exports._createEditEdgeToolbar = function() {
|
30153 |
|
30154 | this._clearManipulatorBar();
|
30155 | this.controlNodesActive = true;
|
30156 |
|
30157 | if (this.boundFunction) {
|
30158 | this.off('select', this.boundFunction);
|
30159 | }
|
30160 |
|
30161 | this.edgeBeingEdited = this._getSelectedEdge();
|
30162 | this.edgeBeingEdited._enableControlNodes();
|
30163 |
|
30164 | var locale = this.constants.locales[this.constants.locale];
|
30165 |
|
30166 | this.manipulationDiv.innerHTML = "" +
|
30167 | "<span class='network-manipulationUI back' id='network-manipulate-back'>" +
|
30168 | "<span class='network-manipulationLabel'>" + locale['back'] + " </span></span>" +
|
30169 | "<div class='network-seperatorLine'></div>" +
|
30170 | "<span class='network-manipulationUI none' id='network-manipulate-back'>" +
|
30171 | "<span id='network-manipulatorLabel' class='network-manipulationLabel'>" + locale['editEdgeDescription'] + "</span></span>";
|
30172 |
|
30173 |
|
30174 | var backButton = document.getElementById("network-manipulate-back");
|
30175 | backButton.onclick = this._createManipulatorBar.bind(this);
|
30176 |
|
30177 |
|
30178 | this.cachedFunctions["_handleTouch"] = this._handleTouch;
|
30179 | this.cachedFunctions["_handleOnRelease"] = this._handleOnRelease;
|
30180 | this.cachedFunctions["_handleTap"] = this._handleTap;
|
30181 | this.cachedFunctions["_handleDragStart"] = this._handleDragStart;
|
30182 | this.cachedFunctions["_handleOnDrag"] = this._handleOnDrag;
|
30183 | this._handleTouch = this._selectControlNode;
|
30184 | this._handleTap = function () {};
|
30185 | this._handleOnDrag = this._controlNodeDrag;
|
30186 | this._handleDragStart = function () {}
|
30187 | this._handleOnRelease = this._releaseControlNode;
|
30188 |
|
30189 |
|
30190 | this._redraw();
|
30191 | };
|
30192 |
|
30193 |
|
30194 | |
30195 |
|
30196 |
|
30197 |
|
30198 |
|
30199 |
|
30200 | exports._selectControlNode = function(pointer) {
|
30201 | this.edgeBeingEdited.controlNodes.from.unselect();
|
30202 | this.edgeBeingEdited.controlNodes.to.unselect();
|
30203 | this.selectedControlNode = this.edgeBeingEdited._getSelectedControlNode(this._XconvertDOMtoCanvas(pointer.x),this._YconvertDOMtoCanvas(pointer.y));
|
30204 | if (this.selectedControlNode !== null) {
|
30205 | this.selectedControlNode.select();
|
30206 | this.freezeSimulation = true;
|
30207 | }
|
30208 | this._redraw();
|
30209 | };
|
30210 |
|
30211 |
|
30212 | |
30213 |
|
30214 |
|
30215 |
|
30216 |
|
30217 |
|
30218 | exports._controlNodeDrag = function(event) {
|
30219 | var pointer = this._getPointer(event.gesture.center);
|
30220 | if (this.selectedControlNode !== null && this.selectedControlNode !== undefined) {
|
30221 | this.selectedControlNode.x = this._XconvertDOMtoCanvas(pointer.x);
|
30222 | this.selectedControlNode.y = this._YconvertDOMtoCanvas(pointer.y);
|
30223 | }
|
30224 | this._redraw();
|
30225 | };
|
30226 |
|
30227 | exports._releaseControlNode = function(pointer) {
|
30228 | var newNode = this._getNodeAt(pointer);
|
30229 | if (newNode != null) {
|
30230 | if (this.edgeBeingEdited.controlNodes.from.selected == true) {
|
30231 | this._editEdge(newNode.id, this.edgeBeingEdited.to.id);
|
30232 | this.edgeBeingEdited.controlNodes.from.unselect();
|
30233 | }
|
30234 | if (this.edgeBeingEdited.controlNodes.to.selected == true) {
|
30235 | this._editEdge(this.edgeBeingEdited.from.id, newNode.id);
|
30236 | this.edgeBeingEdited.controlNodes.to.unselect();
|
30237 | }
|
30238 | }
|
30239 | else {
|
30240 | this.edgeBeingEdited._restoreControlNodes();
|
30241 | }
|
30242 | this.freezeSimulation = false;
|
30243 | this._redraw();
|
30244 | };
|
30245 |
|
30246 | |
30247 |
|
30248 |
|
30249 |
|
30250 |
|
30251 |
|
30252 | exports._handleConnect = function(pointer) {
|
30253 | if (this._getSelectedNodeCount() == 0) {
|
30254 | var node = this._getNodeAt(pointer);
|
30255 |
|
30256 | if (node != null) {
|
30257 | if (node.clusterSize > 1) {
|
30258 | alert(this.constants.locales[this.constants.locale]['createEdgeError'])
|
30259 | }
|
30260 | else {
|
30261 | this._selectObject(node,false);
|
30262 | var supportNodes = this.sectors['support']['nodes'];
|
30263 |
|
30264 |
|
30265 | supportNodes['targetNode'] = new Node({id:'targetNode'},{},{},this.constants);
|
30266 | var targetNode = supportNodes['targetNode'];
|
30267 | targetNode.x = node.x;
|
30268 | targetNode.y = node.y;
|
30269 |
|
30270 |
|
30271 | this.edges['connectionEdge'] = new Edge({id:"connectionEdge",from:node.id,to:targetNode.id}, this, this.constants);
|
30272 | var connectionEdge = this.edges['connectionEdge'];
|
30273 | connectionEdge.from = node;
|
30274 | connectionEdge.connected = true;
|
30275 | connectionEdge.options.smoothCurves = {enabled: true,
|
30276 | dynamic: false,
|
30277 | type: "continuous",
|
30278 | roundness: 0.5
|
30279 | };
|
30280 | connectionEdge.selected = true;
|
30281 | connectionEdge.to = targetNode;
|
30282 |
|
30283 | this.cachedFunctions["_handleOnDrag"] = this._handleOnDrag;
|
30284 | this._handleOnDrag = function(event) {
|
30285 | var pointer = this._getPointer(event.gesture.center);
|
30286 | var connectionEdge = this.edges['connectionEdge'];
|
30287 | connectionEdge.to.x = this._XconvertDOMtoCanvas(pointer.x);
|
30288 | connectionEdge.to.y = this._YconvertDOMtoCanvas(pointer.y);
|
30289 | };
|
30290 |
|
30291 | this.moving = true;
|
30292 | this.start();
|
30293 | }
|
30294 | }
|
30295 | }
|
30296 | };
|
30297 |
|
30298 | exports._finishConnect = function(event) {
|
30299 | if (this._getSelectedNodeCount() == 1) {
|
30300 | var pointer = this._getPointer(event.gesture.center);
|
30301 |
|
30302 | this._handleOnDrag = this.cachedFunctions["_handleOnDrag"];
|
30303 | delete this.cachedFunctions["_handleOnDrag"];
|
30304 |
|
30305 |
|
30306 | var connectFromId = this.edges['connectionEdge'].fromId;
|
30307 |
|
30308 |
|
30309 | delete this.edges['connectionEdge'];
|
30310 | delete this.sectors['support']['nodes']['targetNode'];
|
30311 | delete this.sectors['support']['nodes']['targetViaNode'];
|
30312 |
|
30313 | var node = this._getNodeAt(pointer);
|
30314 | if (node != null) {
|
30315 | if (node.clusterSize > 1) {
|
30316 | alert(this.constants.locales[this.constants.locale]["createEdgeError"])
|
30317 | }
|
30318 | else {
|
30319 | this._createEdge(connectFromId,node.id);
|
30320 | this._createManipulatorBar();
|
30321 | }
|
30322 | }
|
30323 | this._unselectAll();
|
30324 | }
|
30325 | };
|
30326 |
|
30327 |
|
30328 | |
30329 |
|
30330 |
|
30331 | exports._addNode = function() {
|
30332 | if (this._selectionIsEmpty() && this.editMode == true) {
|
30333 | var positionObject = this._pointerToPositionObject(this.pointerPosition);
|
30334 | var defaultData = {id:util.randomUUID(),x:positionObject.left,y:positionObject.top,label:"new",allowedToMoveX:true,allowedToMoveY:true};
|
30335 | if (this.triggerFunctions.add) {
|
30336 | if (this.triggerFunctions.add.length == 2) {
|
30337 | var me = this;
|
30338 | this.triggerFunctions.add(defaultData, function(finalizedData) {
|
30339 | me.nodesData.add(finalizedData);
|
30340 | me._createManipulatorBar();
|
30341 | me.moving = true;
|
30342 | me.start();
|
30343 | });
|
30344 | }
|
30345 | else {
|
30346 | throw new Error('The function for add does not support two arguments (data,callback)');
|
30347 | this._createManipulatorBar();
|
30348 | this.moving = true;
|
30349 | this.start();
|
30350 | }
|
30351 | }
|
30352 | else {
|
30353 | this.nodesData.add(defaultData);
|
30354 | this._createManipulatorBar();
|
30355 | this.moving = true;
|
30356 | this.start();
|
30357 | }
|
30358 | }
|
30359 | };
|
30360 |
|
30361 |
|
30362 | |
30363 |
|
30364 |
|
30365 |
|
30366 |
|
30367 | exports._createEdge = function(sourceNodeId,targetNodeId) {
|
30368 | if (this.editMode == true) {
|
30369 | var defaultData = {from:sourceNodeId, to:targetNodeId};
|
30370 | if (this.triggerFunctions.connect) {
|
30371 | if (this.triggerFunctions.connect.length == 2) {
|
30372 | var me = this;
|
30373 | this.triggerFunctions.connect(defaultData, function(finalizedData) {
|
30374 | me.edgesData.add(finalizedData);
|
30375 | me.moving = true;
|
30376 | me.start();
|
30377 | });
|
30378 | }
|
30379 | else {
|
30380 | throw new Error('The function for connect does not support two arguments (data,callback)');
|
30381 | this.moving = true;
|
30382 | this.start();
|
30383 | }
|
30384 | }
|
30385 | else {
|
30386 | this.edgesData.add(defaultData);
|
30387 | this.moving = true;
|
30388 | this.start();
|
30389 | }
|
30390 | }
|
30391 | };
|
30392 |
|
30393 | |
30394 |
|
30395 |
|
30396 |
|
30397 |
|
30398 | exports._editEdge = function(sourceNodeId,targetNodeId) {
|
30399 | if (this.editMode == true) {
|
30400 | var defaultData = {id: this.edgeBeingEdited.id, from:sourceNodeId, to:targetNodeId};
|
30401 | if (this.triggerFunctions.editEdge) {
|
30402 | if (this.triggerFunctions.editEdge.length == 2) {
|
30403 | var me = this;
|
30404 | this.triggerFunctions.editEdge(defaultData, function(finalizedData) {
|
30405 | me.edgesData.update(finalizedData);
|
30406 | me.moving = true;
|
30407 | me.start();
|
30408 | });
|
30409 | }
|
30410 | else {
|
30411 | throw new Error('The function for edit does not support two arguments (data, callback)');
|
30412 | this.moving = true;
|
30413 | this.start();
|
30414 | }
|
30415 | }
|
30416 | else {
|
30417 | this.edgesData.update(defaultData);
|
30418 | this.moving = true;
|
30419 | this.start();
|
30420 | }
|
30421 | }
|
30422 | };
|
30423 |
|
30424 | |
30425 |
|
30426 |
|
30427 |
|
30428 |
|
30429 | exports._editNode = function() {
|
30430 | if (this.triggerFunctions.edit && this.editMode == true) {
|
30431 | var node = this._getSelectedNode();
|
30432 | var data = {id:node.id,
|
30433 | label: node.label,
|
30434 | group: node.options.group,
|
30435 | shape: node.options.shape,
|
30436 | color: {
|
30437 | background:node.options.color.background,
|
30438 | border:node.options.color.border,
|
30439 | highlight: {
|
30440 | background:node.options.color.highlight.background,
|
30441 | border:node.options.color.highlight.border
|
30442 | }
|
30443 | }};
|
30444 | if (this.triggerFunctions.edit.length == 2) {
|
30445 | var me = this;
|
30446 | this.triggerFunctions.edit(data, function (finalizedData) {
|
30447 | me.nodesData.update(finalizedData);
|
30448 | me._createManipulatorBar();
|
30449 | me.moving = true;
|
30450 | me.start();
|
30451 | });
|
30452 | }
|
30453 | else {
|
30454 | throw new Error('The function for edit does not support two arguments (data, callback)');
|
30455 | }
|
30456 | }
|
30457 | else {
|
30458 | throw new Error('No edit function has been bound to this button');
|
30459 | }
|
30460 | };
|
30461 |
|
30462 |
|
30463 |
|
30464 |
|
30465 | |
30466 |
|
30467 |
|
30468 |
|
30469 |
|
30470 | exports._deleteSelected = function() {
|
30471 | if (!this._selectionIsEmpty() && this.editMode == true) {
|
30472 | if (!this._clusterInSelection()) {
|
30473 | var selectedNodes = this.getSelectedNodes();
|
30474 | var selectedEdges = this.getSelectedEdges();
|
30475 | if (this.triggerFunctions.del) {
|
30476 | var me = this;
|
30477 | var data = {nodes: selectedNodes, edges: selectedEdges};
|
30478 | if (this.triggerFunctions.del.length = 2) {
|
30479 | this.triggerFunctions.del(data, function (finalizedData) {
|
30480 | me.edgesData.remove(finalizedData.edges);
|
30481 | me.nodesData.remove(finalizedData.nodes);
|
30482 | me._unselectAll();
|
30483 | me.moving = true;
|
30484 | me.start();
|
30485 | });
|
30486 | }
|
30487 | else {
|
30488 | throw new Error('The function for delete does not support two arguments (data, callback)')
|
30489 | }
|
30490 | }
|
30491 | else {
|
30492 | this.edgesData.remove(selectedEdges);
|
30493 | this.nodesData.remove(selectedNodes);
|
30494 | this._unselectAll();
|
30495 | this.moving = true;
|
30496 | this.start();
|
30497 | }
|
30498 | }
|
30499 | else {
|
30500 | alert(this.constants.locales[this.constants.locale]["deleteClusterError"]);
|
30501 | }
|
30502 | }
|
30503 | };
|
30504 |
|
30505 |
|
30506 | },
|
30507 |
|
30508 | function(module, exports, __webpack_require__) {
|
30509 |
|
30510 | var util = __webpack_require__(1);
|
30511 | var Hammer = __webpack_require__(42);
|
30512 |
|
30513 | exports._cleanNavigation = function() {
|
30514 |
|
30515 | if (this.navigationHammers.existing.length != 0) {
|
30516 | for (var i = 0; i < this.navigationHammers.existing.length; i++) {
|
30517 | this.navigationHammers.existing[i].dispose();
|
30518 | }
|
30519 | this.navigationHammers.existing = [];
|
30520 | }
|
30521 |
|
30522 |
|
30523 | var wrapper = document.getElementById('network-navigation_wrapper');
|
30524 | if (wrapper && wrapper.parentNode) {
|
30525 | wrapper.parentNode.removeChild(wrapper);
|
30526 | }
|
30527 | };
|
30528 |
|
30529 | |
30530 |
|
30531 |
|
30532 |
|
30533 |
|
30534 |
|
30535 |
|
30536 |
|
30537 | exports._loadNavigationElements = function() {
|
30538 | this._cleanNavigation();
|
30539 |
|
30540 | this.navigationDivs = {};
|
30541 | var navigationDivs = ['up','down','left','right','zoomIn','zoomOut','zoomExtends'];
|
30542 | var navigationDivActions = ['_moveUp','_moveDown','_moveLeft','_moveRight','_zoomIn','_zoomOut','_zoomExtent'];
|
30543 |
|
30544 | this.navigationDivs['wrapper'] = document.createElement('div');
|
30545 | this.navigationDivs['wrapper'].id = 'network-navigation_wrapper';
|
30546 | this.frame.appendChild(this.navigationDivs['wrapper']);
|
30547 |
|
30548 | for (var i = 0; i < navigationDivs.length; i++) {
|
30549 | this.navigationDivs[navigationDivs[i]] = document.createElement('div');
|
30550 | this.navigationDivs[navigationDivs[i]].id = 'network-navigation_' + navigationDivs[i];
|
30551 | this.navigationDivs[navigationDivs[i]].className = 'network-navigation ' + navigationDivs[i];
|
30552 | this.navigationDivs['wrapper'].appendChild(this.navigationDivs[navigationDivs[i]]);
|
30553 |
|
30554 | var hammer = Hammer(this.navigationDivs[navigationDivs[i]], {prevent_default: true});
|
30555 | hammer.on('touch', this[navigationDivActions[i]].bind(this));
|
30556 | this.navigationHammers.new.push(hammer);
|
30557 | }
|
30558 |
|
30559 | var hammerDoc = Hammer(document, {prevent_default: false});
|
30560 | hammerDoc.on('release', this._stopMovement.bind(this));
|
30561 | this.navigationHammers.new.push(hammerDoc);
|
30562 |
|
30563 | this.navigationHammers.existing = this.navigationHammers.new;
|
30564 | };
|
30565 |
|
30566 |
|
30567 | |
30568 |
|
30569 |
|
30570 |
|
30571 |
|
30572 | exports._zoomExtent = function(event) {
|
30573 |
|
30574 | if (this._zoomExtentLastTime === undefined || new Date() - this._zoomExtentLastTime > 200) {
|
30575 | this._zoomExtentLastTime = new Date();
|
30576 | this.zoomExtent({duration:800});
|
30577 | event.stopPropagation();
|
30578 | }
|
30579 | };
|
30580 |
|
30581 | |
30582 |
|
30583 |
|
30584 |
|
30585 |
|
30586 | exports._stopMovement = function() {
|
30587 | this._xStopMoving();
|
30588 | this._yStopMoving();
|
30589 | this._stopZoom();
|
30590 | };
|
30591 |
|
30592 |
|
30593 | |
30594 |
|
30595 |
|
30596 |
|
30597 |
|
30598 |
|
30599 |
|
30600 |
|
30601 | exports._moveUp = function(event) {
|
30602 | this.yIncrement = this.constants.keyboard.speed.y;
|
30603 | this.start();
|
30604 | event.preventDefault();
|
30605 | };
|
30606 |
|
30607 |
|
30608 | |
30609 |
|
30610 |
|
30611 |
|
30612 | exports._moveDown = function(event) {
|
30613 | this.yIncrement = -this.constants.keyboard.speed.y;
|
30614 | this.start();
|
30615 | event.preventDefault();
|
30616 | };
|
30617 |
|
30618 |
|
30619 | |
30620 |
|
30621 |
|
30622 |
|
30623 | exports._moveLeft = function(event) {
|
30624 | this.xIncrement = this.constants.keyboard.speed.x;
|
30625 | this.start();
|
30626 | event.preventDefault();
|
30627 | };
|
30628 |
|
30629 |
|
30630 | |
30631 |
|
30632 |
|
30633 |
|
30634 | exports._moveRight = function(event) {
|
30635 | this.xIncrement = -this.constants.keyboard.speed.y;
|
30636 | this.start();
|
30637 | event.preventDefault();
|
30638 | };
|
30639 |
|
30640 |
|
30641 | |
30642 |
|
30643 |
|
30644 |
|
30645 | exports._zoomIn = function(event) {
|
30646 | this.zoomIncrement = this.constants.keyboard.speed.zoom;
|
30647 | this.start();
|
30648 | event.preventDefault();
|
30649 | };
|
30650 |
|
30651 |
|
30652 | |
30653 |
|
30654 |
|
30655 |
|
30656 | exports._zoomOut = function(event) {
|
30657 | this.zoomIncrement = -this.constants.keyboard.speed.zoom;
|
30658 | this.start();
|
30659 | event.preventDefault();
|
30660 | };
|
30661 |
|
30662 |
|
30663 | |
30664 |
|
30665 |
|
30666 |
|
30667 | exports._stopZoom = function(event) {
|
30668 | this.zoomIncrement = 0;
|
30669 | event && event.preventDefault();
|
30670 | };
|
30671 |
|
30672 |
|
30673 | |
30674 |
|
30675 |
|
30676 |
|
30677 | exports._yStopMoving = function(event) {
|
30678 | this.yIncrement = 0;
|
30679 | event && event.preventDefault();
|
30680 | };
|
30681 |
|
30682 |
|
30683 | |
30684 |
|
30685 |
|
30686 |
|
30687 | exports._xStopMoving = function(event) {
|
30688 | this.xIncrement = 0;
|
30689 | event && event.preventDefault();
|
30690 | };
|
30691 |
|
30692 |
|
30693 | },
|
30694 |
|
30695 | function(module, exports, __webpack_require__) {
|
30696 |
|
30697 | exports._resetLevels = function() {
|
30698 | for (var nodeId in this.nodes) {
|
30699 | if (this.nodes.hasOwnProperty(nodeId)) {
|
30700 | var node = this.nodes[nodeId];
|
30701 | if (node.preassignedLevel == false) {
|
30702 | node.level = -1;
|
30703 | node.hierarchyEnumerated = false;
|
30704 | }
|
30705 | }
|
30706 | }
|
30707 | };
|
30708 |
|
30709 | |
30710 |
|
30711 |
|
30712 |
|
30713 |
|
30714 |
|
30715 | exports._setupHierarchicalLayout = function() {
|
30716 | if (this.constants.hierarchicalLayout.enabled == true && this.nodeIndices.length > 0) {
|
30717 | if (this.constants.hierarchicalLayout.direction == "RL" || this.constants.hierarchicalLayout.direction == "DU") {
|
30718 | this.constants.hierarchicalLayout.levelSeparation *= -1;
|
30719 | }
|
30720 | else {
|
30721 | this.constants.hierarchicalLayout.levelSeparation = Math.abs(this.constants.hierarchicalLayout.levelSeparation);
|
30722 | }
|
30723 |
|
30724 | if (this.constants.hierarchicalLayout.direction == "RL" || this.constants.hierarchicalLayout.direction == "LR") {
|
30725 | if (this.constants.smoothCurves.enabled == true) {
|
30726 | this.constants.smoothCurves.type = "vertical";
|
30727 | }
|
30728 | }
|
30729 | else {
|
30730 | if (this.constants.smoothCurves.enabled == true) {
|
30731 | this.constants.smoothCurves.type = "horizontal";
|
30732 | }
|
30733 | }
|
30734 |
|
30735 | var hubsize = 0;
|
30736 | var node, nodeId;
|
30737 | var definedLevel = false;
|
30738 | var undefinedLevel = false;
|
30739 |
|
30740 | for (nodeId in this.nodes) {
|
30741 | if (this.nodes.hasOwnProperty(nodeId)) {
|
30742 | node = this.nodes[nodeId];
|
30743 | if (node.level != -1) {
|
30744 | definedLevel = true;
|
30745 | }
|
30746 | else {
|
30747 | undefinedLevel = true;
|
30748 | }
|
30749 | if (hubsize < node.edges.length) {
|
30750 | hubsize = node.edges.length;
|
30751 | }
|
30752 | }
|
30753 | }
|
30754 |
|
30755 |
|
30756 | if (undefinedLevel == true && definedLevel == true) {
|
30757 | throw new Error("To use the hierarchical layout, nodes require either no predefined levels or levels have to be defined for all nodes.");
|
30758 | this.zoomExtent(undefined,true,this.constants.clustering.enabled);
|
30759 | if (!this.constants.clustering.enabled) {
|
30760 | this.start();
|
30761 | }
|
30762 | }
|
30763 | else {
|
30764 |
|
30765 | this._changeConstants();
|
30766 |
|
30767 |
|
30768 | if (undefinedLevel == true) {
|
30769 | if (this.constants.hierarchicalLayout.layout == "hubsize") {
|
30770 | this._determineLevels(hubsize);
|
30771 | }
|
30772 | else {
|
30773 | this._determineLevelsDirected();
|
30774 | }
|
30775 |
|
30776 | }
|
30777 |
|
30778 | var distribution = this._getDistribution();
|
30779 |
|
30780 |
|
30781 | this._placeNodesByHierarchy(distribution);
|
30782 |
|
30783 |
|
30784 | this.start();
|
30785 | }
|
30786 | }
|
30787 | };
|
30788 |
|
30789 |
|
30790 | |
30791 |
|
30792 |
|
30793 |
|
30794 |
|
30795 |
|
30796 | exports._placeNodesByHierarchy = function(distribution) {
|
30797 | var nodeId, node;
|
30798 |
|
30799 |
|
30800 | for (var level in distribution) {
|
30801 | if (distribution.hasOwnProperty(level)) {
|
30802 |
|
30803 | for (nodeId in distribution[level].nodes) {
|
30804 | if (distribution[level].nodes.hasOwnProperty(nodeId)) {
|
30805 | node = distribution[level].nodes[nodeId];
|
30806 | if (this.constants.hierarchicalLayout.direction == "UD" || this.constants.hierarchicalLayout.direction == "DU") {
|
30807 | if (node.xFixed) {
|
30808 | node.x = distribution[level].minPos;
|
30809 | node.xFixed = false;
|
30810 |
|
30811 | distribution[level].minPos += distribution[level].nodeSpacing;
|
30812 | }
|
30813 | }
|
30814 | else {
|
30815 | if (node.yFixed) {
|
30816 | node.y = distribution[level].minPos;
|
30817 | node.yFixed = false;
|
30818 |
|
30819 | distribution[level].minPos += distribution[level].nodeSpacing;
|
30820 | }
|
30821 | }
|
30822 | this._placeBranchNodes(node.edges,node.id,distribution,node.level);
|
30823 | }
|
30824 | }
|
30825 | }
|
30826 | }
|
30827 |
|
30828 |
|
30829 | this._stabilize();
|
30830 | };
|
30831 |
|
30832 |
|
30833 | |
30834 |
|
30835 |
|
30836 |
|
30837 |
|
30838 |
|
30839 | exports._getDistribution = function() {
|
30840 | var distribution = {};
|
30841 | var nodeId, node, level;
|
30842 |
|
30843 |
|
30844 |
|
30845 | for (nodeId in this.nodes) {
|
30846 | if (this.nodes.hasOwnProperty(nodeId)) {
|
30847 | node = this.nodes[nodeId];
|
30848 | node.xFixed = true;
|
30849 | node.yFixed = true;
|
30850 | if (this.constants.hierarchicalLayout.direction == "UD" || this.constants.hierarchicalLayout.direction == "DU") {
|
30851 | node.y = this.constants.hierarchicalLayout.levelSeparation*node.level;
|
30852 | }
|
30853 | else {
|
30854 | node.x = this.constants.hierarchicalLayout.levelSeparation*node.level;
|
30855 | }
|
30856 | if (distribution[node.level] === undefined) {
|
30857 | distribution[node.level] = {amount: 0, nodes: {}, minPos:0, nodeSpacing:0};
|
30858 | }
|
30859 | distribution[node.level].amount += 1;
|
30860 | distribution[node.level].nodes[nodeId] = node;
|
30861 | }
|
30862 | }
|
30863 |
|
30864 |
|
30865 | var maxCount = 0;
|
30866 | for (level in distribution) {
|
30867 | if (distribution.hasOwnProperty(level)) {
|
30868 | if (maxCount < distribution[level].amount) {
|
30869 | maxCount = distribution[level].amount;
|
30870 | }
|
30871 | }
|
30872 | }
|
30873 |
|
30874 |
|
30875 | for (level in distribution) {
|
30876 | if (distribution.hasOwnProperty(level)) {
|
30877 | distribution[level].nodeSpacing = (maxCount + 1) * this.constants.hierarchicalLayout.nodeSpacing;
|
30878 | distribution[level].nodeSpacing /= (distribution[level].amount + 1);
|
30879 | distribution[level].minPos = distribution[level].nodeSpacing - (0.5 * (distribution[level].amount + 1) * distribution[level].nodeSpacing);
|
30880 | }
|
30881 | }
|
30882 |
|
30883 | return distribution;
|
30884 | };
|
30885 |
|
30886 |
|
30887 | |
30888 |
|
30889 |
|
30890 |
|
30891 |
|
30892 |
|
30893 | exports._determineLevels = function(hubsize) {
|
30894 | var nodeId, node;
|
30895 |
|
30896 |
|
30897 | for (nodeId in this.nodes) {
|
30898 | if (this.nodes.hasOwnProperty(nodeId)) {
|
30899 | node = this.nodes[nodeId];
|
30900 | if (node.edges.length == hubsize) {
|
30901 | node.level = 0;
|
30902 | }
|
30903 | }
|
30904 | }
|
30905 |
|
30906 |
|
30907 | for (nodeId in this.nodes) {
|
30908 | if (this.nodes.hasOwnProperty(nodeId)) {
|
30909 | node = this.nodes[nodeId];
|
30910 | if (node.level == 0) {
|
30911 | this._setLevel(1,node.edges,node.id);
|
30912 | }
|
30913 | }
|
30914 | }
|
30915 | };
|
30916 |
|
30917 | |
30918 |
|
30919 |
|
30920 |
|
30921 |
|
30922 |
|
30923 | exports._determineLevelsDirected = function() {
|
30924 | var nodeId, node;
|
30925 |
|
30926 |
|
30927 | for (nodeId in this.nodes) {
|
30928 | if (this.nodes.hasOwnProperty(nodeId)) {
|
30929 | this.nodes[nodeId].level = 10000;
|
30930 | break;
|
30931 | }
|
30932 | }
|
30933 |
|
30934 |
|
30935 | for (nodeId in this.nodes) {
|
30936 | if (this.nodes.hasOwnProperty(nodeId)) {
|
30937 | node = this.nodes[nodeId];
|
30938 | if (node.level == 10000) {
|
30939 | this._setLevelDirected(10000,node.edges,node.id);
|
30940 | }
|
30941 | }
|
30942 | }
|
30943 |
|
30944 |
|
30945 |
|
30946 | var minLevel = 10000;
|
30947 | for (nodeId in this.nodes) {
|
30948 | if (this.nodes.hasOwnProperty(nodeId)) {
|
30949 | node = this.nodes[nodeId];
|
30950 | minLevel = node.level < minLevel ? node.level : minLevel;
|
30951 | }
|
30952 | }
|
30953 |
|
30954 |
|
30955 | for (nodeId in this.nodes) {
|
30956 | if (this.nodes.hasOwnProperty(nodeId)) {
|
30957 | node = this.nodes[nodeId];
|
30958 | node.level -= minLevel;
|
30959 | }
|
30960 | }
|
30961 | };
|
30962 |
|
30963 |
|
30964 | |
30965 |
|
30966 |
|
30967 |
|
30968 |
|
30969 |
|
30970 |
|
30971 |
|
30972 |
|
30973 | exports._changeConstants = function() {
|
30974 | this.constants.clustering.enabled = false;
|
30975 | this.constants.physics.barnesHut.enabled = false;
|
30976 | this.constants.physics.hierarchicalRepulsion.enabled = true;
|
30977 | this._loadSelectedForceSolver();
|
30978 | if (this.constants.smoothCurves.enabled == true) {
|
30979 | this.constants.smoothCurves.dynamic = false;
|
30980 | }
|
30981 | this._configureSmoothCurves();
|
30982 | };
|
30983 |
|
30984 |
|
30985 | |
30986 |
|
30987 |
|
30988 |
|
30989 |
|
30990 |
|
30991 |
|
30992 |
|
30993 |
|
30994 |
|
30995 | exports._placeBranchNodes = function(edges, parentId, distribution, parentLevel) {
|
30996 | for (var i = 0; i < edges.length; i++) {
|
30997 | var childNode = null;
|
30998 | if (edges[i].toId == parentId) {
|
30999 | childNode = edges[i].from;
|
31000 | }
|
31001 | else {
|
31002 | childNode = edges[i].to;
|
31003 | }
|
31004 |
|
31005 |
|
31006 | var nodeMoved = false;
|
31007 | if (this.constants.hierarchicalLayout.direction == "UD" || this.constants.hierarchicalLayout.direction == "DU") {
|
31008 | if (childNode.xFixed && childNode.level > parentLevel) {
|
31009 | childNode.xFixed = false;
|
31010 | childNode.x = distribution[childNode.level].minPos;
|
31011 | nodeMoved = true;
|
31012 | }
|
31013 | }
|
31014 | else {
|
31015 | if (childNode.yFixed && childNode.level > parentLevel) {
|
31016 | childNode.yFixed = false;
|
31017 | childNode.y = distribution[childNode.level].minPos;
|
31018 | nodeMoved = true;
|
31019 | }
|
31020 | }
|
31021 |
|
31022 | if (nodeMoved == true) {
|
31023 | distribution[childNode.level].minPos += distribution[childNode.level].nodeSpacing;
|
31024 | if (childNode.edges.length > 1) {
|
31025 | this._placeBranchNodes(childNode.edges,childNode.id,distribution,childNode.level);
|
31026 | }
|
31027 | }
|
31028 | }
|
31029 | };
|
31030 |
|
31031 |
|
31032 | |
31033 |
|
31034 |
|
31035 |
|
31036 |
|
31037 |
|
31038 |
|
31039 |
|
31040 | exports._setLevel = function(level, edges, parentId) {
|
31041 | for (var i = 0; i < edges.length; i++) {
|
31042 | var childNode = null;
|
31043 | if (edges[i].toId == parentId) {
|
31044 | childNode = edges[i].from;
|
31045 | }
|
31046 | else {
|
31047 | childNode = edges[i].to;
|
31048 | }
|
31049 | if (childNode.level == -1 || childNode.level > level) {
|
31050 | childNode.level = level;
|
31051 | if (childNode.edges.length > 1) {
|
31052 | this._setLevel(level+1, childNode.edges, childNode.id);
|
31053 | }
|
31054 | }
|
31055 | }
|
31056 | };
|
31057 |
|
31058 |
|
31059 | |
31060 |
|
31061 |
|
31062 |
|
31063 |
|
31064 |
|
31065 |
|
31066 |
|
31067 | exports._setLevelDirected = function(level, edges, parentId) {
|
31068 | this.nodes[parentId].hierarchyEnumerated = true;
|
31069 | for (var i = 0; i < edges.length; i++) {
|
31070 | var childNode = null;
|
31071 | var direction = 1;
|
31072 | if (edges[i].toId == parentId) {
|
31073 | childNode = edges[i].from;
|
31074 | direction = -1;
|
31075 | }
|
31076 | else {
|
31077 | childNode = edges[i].to;
|
31078 | }
|
31079 | if (childNode.level == -1) {
|
31080 | childNode.level = level + direction;
|
31081 | }
|
31082 | }
|
31083 |
|
31084 | for (var i = 0; i < edges.length; i++) {
|
31085 | var childNode = null;
|
31086 | if (edges[i].toId == parentId) {childNode = edges[i].from;}
|
31087 | else {childNode = edges[i].to;}
|
31088 | if (childNode.edges.length > 1 && childNode.hierarchyEnumerated === false) {
|
31089 | this._setLevelDirected(childNode.level, childNode.edges, childNode.id);
|
31090 | }
|
31091 | }
|
31092 | };
|
31093 |
|
31094 |
|
31095 | |
31096 |
|
31097 |
|
31098 |
|
31099 |
|
31100 | exports._restoreNodes = function() {
|
31101 | for (var nodeId in this.nodes) {
|
31102 | if (this.nodes.hasOwnProperty(nodeId)) {
|
31103 | this.nodes[nodeId].xFixed = false;
|
31104 | this.nodes[nodeId].yFixed = false;
|
31105 | }
|
31106 | }
|
31107 | };
|
31108 |
|
31109 |
|
31110 | },
|
31111 |
|
31112 | function(module, exports, __webpack_require__) {
|
31113 |
|
31114 | var util = __webpack_require__(1);
|
31115 | var RepulsionMixin = __webpack_require__(62);
|
31116 | var HierarchialRepulsionMixin = __webpack_require__(63);
|
31117 | var BarnesHutMixin = __webpack_require__(64);
|
31118 |
|
31119 | |
31120 |
|
31121 |
|
31122 |
|
31123 |
|
31124 | exports._toggleBarnesHut = function () {
|
31125 | this.constants.physics.barnesHut.enabled = !this.constants.physics.barnesHut.enabled;
|
31126 | this._loadSelectedForceSolver();
|
31127 | this.moving = true;
|
31128 | this.start();
|
31129 | };
|
31130 |
|
31131 |
|
31132 | |
31133 |
|
31134 |
|
31135 |
|
31136 |
|
31137 | exports._loadSelectedForceSolver = function () {
|
31138 |
|
31139 | if (this.constants.physics.barnesHut.enabled == true) {
|
31140 | this._clearMixin(RepulsionMixin);
|
31141 | this._clearMixin(HierarchialRepulsionMixin);
|
31142 |
|
31143 | this.constants.physics.centralGravity = this.constants.physics.barnesHut.centralGravity;
|
31144 | this.constants.physics.springLength = this.constants.physics.barnesHut.springLength;
|
31145 | this.constants.physics.springConstant = this.constants.physics.barnesHut.springConstant;
|
31146 | this.constants.physics.damping = this.constants.physics.barnesHut.damping;
|
31147 |
|
31148 | this._loadMixin(BarnesHutMixin);
|
31149 | }
|
31150 | else if (this.constants.physics.hierarchicalRepulsion.enabled == true) {
|
31151 | this._clearMixin(BarnesHutMixin);
|
31152 | this._clearMixin(RepulsionMixin);
|
31153 |
|
31154 | this.constants.physics.centralGravity = this.constants.physics.hierarchicalRepulsion.centralGravity;
|
31155 | this.constants.physics.springLength = this.constants.physics.hierarchicalRepulsion.springLength;
|
31156 | this.constants.physics.springConstant = this.constants.physics.hierarchicalRepulsion.springConstant;
|
31157 | this.constants.physics.damping = this.constants.physics.hierarchicalRepulsion.damping;
|
31158 |
|
31159 | this._loadMixin(HierarchialRepulsionMixin);
|
31160 | }
|
31161 | else {
|
31162 | this._clearMixin(BarnesHutMixin);
|
31163 | this._clearMixin(HierarchialRepulsionMixin);
|
31164 | this.barnesHutTree = undefined;
|
31165 |
|
31166 | this.constants.physics.centralGravity = this.constants.physics.repulsion.centralGravity;
|
31167 | this.constants.physics.springLength = this.constants.physics.repulsion.springLength;
|
31168 | this.constants.physics.springConstant = this.constants.physics.repulsion.springConstant;
|
31169 | this.constants.physics.damping = this.constants.physics.repulsion.damping;
|
31170 |
|
31171 | this._loadMixin(RepulsionMixin);
|
31172 | }
|
31173 | };
|
31174 |
|
31175 | |
31176 |
|
31177 |
|
31178 |
|
31179 |
|
31180 |
|
31181 | exports._initializeForceCalculation = function () {
|
31182 |
|
31183 | if (this.nodeIndices.length == 1) {
|
31184 | this.nodes[this.nodeIndices[0]]._setForce(0, 0);
|
31185 | }
|
31186 | else {
|
31187 |
|
31188 | if (this.nodeIndices.length > this.constants.clustering.clusterThreshold && this.constants.clustering.enabled == true) {
|
31189 | this.clusterToFit(this.constants.clustering.reduceToNodes, false);
|
31190 | }
|
31191 |
|
31192 |
|
31193 | this._calculateForces();
|
31194 | }
|
31195 | };
|
31196 |
|
31197 |
|
31198 | |
31199 |
|
31200 |
|
31201 |
|
31202 |
|
31203 | exports._calculateForces = function () {
|
31204 |
|
31205 |
|
31206 |
|
31207 |
|
31208 | this._calculateGravitationalForces();
|
31209 | this._calculateNodeForces();
|
31210 |
|
31211 | if (this.constants.physics.springConstant > 0) {
|
31212 | if (this.constants.smoothCurves.enabled == true && this.constants.smoothCurves.dynamic == true) {
|
31213 | this._calculateSpringForcesWithSupport();
|
31214 | }
|
31215 | else {
|
31216 | if (this.constants.physics.hierarchicalRepulsion.enabled == true) {
|
31217 | this._calculateHierarchicalSpringForces();
|
31218 | }
|
31219 | else {
|
31220 | this._calculateSpringForces();
|
31221 | }
|
31222 | }
|
31223 | }
|
31224 | };
|
31225 |
|
31226 |
|
31227 | |
31228 |
|
31229 |
|
31230 |
|
31231 |
|
31232 |
|
31233 |
|
31234 |
|
31235 | exports._updateCalculationNodes = function () {
|
31236 | if (this.constants.smoothCurves.enabled == true && this.constants.smoothCurves.dynamic == true) {
|
31237 | this.calculationNodes = {};
|
31238 | this.calculationNodeIndices = [];
|
31239 |
|
31240 | for (var nodeId in this.nodes) {
|
31241 | if (this.nodes.hasOwnProperty(nodeId)) {
|
31242 | this.calculationNodes[nodeId] = this.nodes[nodeId];
|
31243 | }
|
31244 | }
|
31245 | var supportNodes = this.sectors['support']['nodes'];
|
31246 | for (var supportNodeId in supportNodes) {
|
31247 | if (supportNodes.hasOwnProperty(supportNodeId)) {
|
31248 | if (this.edges.hasOwnProperty(supportNodes[supportNodeId].parentEdgeId)) {
|
31249 | this.calculationNodes[supportNodeId] = supportNodes[supportNodeId];
|
31250 | }
|
31251 | else {
|
31252 | supportNodes[supportNodeId]._setForce(0, 0);
|
31253 | }
|
31254 | }
|
31255 | }
|
31256 |
|
31257 | for (var idx in this.calculationNodes) {
|
31258 | if (this.calculationNodes.hasOwnProperty(idx)) {
|
31259 | this.calculationNodeIndices.push(idx);
|
31260 | }
|
31261 | }
|
31262 | }
|
31263 | else {
|
31264 | this.calculationNodes = this.nodes;
|
31265 | this.calculationNodeIndices = this.nodeIndices;
|
31266 | }
|
31267 | };
|
31268 |
|
31269 |
|
31270 | |
31271 |
|
31272 |
|
31273 |
|
31274 |
|
31275 | exports._calculateGravitationalForces = function () {
|
31276 | var dx, dy, distance, node, i;
|
31277 | var nodes = this.calculationNodes;
|
31278 | var gravity = this.constants.physics.centralGravity;
|
31279 | var gravityForce = 0;
|
31280 |
|
31281 | for (i = 0; i < this.calculationNodeIndices.length; i++) {
|
31282 | node = nodes[this.calculationNodeIndices[i]];
|
31283 | node.damping = this.constants.physics.damping;
|
31284 |
|
31285 | if (this._sector() == "default" && gravity != 0) {
|
31286 | dx = -node.x;
|
31287 | dy = -node.y;
|
31288 | distance = Math.sqrt(dx * dx + dy * dy);
|
31289 |
|
31290 | gravityForce = (distance == 0) ? 0 : (gravity / distance);
|
31291 | node.fx = dx * gravityForce;
|
31292 | node.fy = dy * gravityForce;
|
31293 | }
|
31294 | else {
|
31295 | node.fx = 0;
|
31296 | node.fy = 0;
|
31297 | }
|
31298 | }
|
31299 | };
|
31300 |
|
31301 |
|
31302 |
|
31303 |
|
31304 | |
31305 |
|
31306 |
|
31307 |
|
31308 |
|
31309 | exports._calculateSpringForces = function () {
|
31310 | var edgeLength, edge, edgeId;
|
31311 | var dx, dy, fx, fy, springForce, distance;
|
31312 | var edges = this.edges;
|
31313 |
|
31314 |
|
31315 | for (edgeId in edges) {
|
31316 | if (edges.hasOwnProperty(edgeId)) {
|
31317 | edge = edges[edgeId];
|
31318 | if (edge.connected) {
|
31319 |
|
31320 | if (this.nodes.hasOwnProperty(edge.toId) && this.nodes.hasOwnProperty(edge.fromId)) {
|
31321 | edgeLength = edge.physics.springLength;
|
31322 |
|
31323 | edgeLength += (edge.to.clusterSize + edge.from.clusterSize - 2) * this.constants.clustering.edgeGrowth;
|
31324 |
|
31325 | dx = (edge.from.x - edge.to.x);
|
31326 | dy = (edge.from.y - edge.to.y);
|
31327 | distance = Math.sqrt(dx * dx + dy * dy);
|
31328 |
|
31329 | if (distance == 0) {
|
31330 | distance = 0.01;
|
31331 | }
|
31332 |
|
31333 |
|
31334 | springForce = this.constants.physics.springConstant * (edgeLength - distance) / distance;
|
31335 |
|
31336 | fx = dx * springForce;
|
31337 | fy = dy * springForce;
|
31338 |
|
31339 | edge.from.fx += fx;
|
31340 | edge.from.fy += fy;
|
31341 | edge.to.fx -= fx;
|
31342 | edge.to.fy -= fy;
|
31343 | }
|
31344 | }
|
31345 | }
|
31346 | }
|
31347 | };
|
31348 |
|
31349 |
|
31350 |
|
31351 |
|
31352 | |
31353 |
|
31354 |
|
31355 |
|
31356 |
|
31357 | exports._calculateSpringForcesWithSupport = function () {
|
31358 | var edgeLength, edge, edgeId, combinedClusterSize;
|
31359 | var edges = this.edges;
|
31360 |
|
31361 |
|
31362 | for (edgeId in edges) {
|
31363 | if (edges.hasOwnProperty(edgeId)) {
|
31364 | edge = edges[edgeId];
|
31365 | if (edge.connected) {
|
31366 |
|
31367 | if (this.nodes.hasOwnProperty(edge.toId) && this.nodes.hasOwnProperty(edge.fromId)) {
|
31368 | if (edge.via != null) {
|
31369 | var node1 = edge.to;
|
31370 | var node2 = edge.via;
|
31371 | var node3 = edge.from;
|
31372 |
|
31373 | edgeLength = edge.physics.springLength;
|
31374 |
|
31375 | combinedClusterSize = node1.clusterSize + node3.clusterSize - 2;
|
31376 |
|
31377 |
|
31378 | edgeLength += combinedClusterSize * this.constants.clustering.edgeGrowth;
|
31379 | this._calculateSpringForce(node1, node2, 0.5 * edgeLength);
|
31380 | this._calculateSpringForce(node2, node3, 0.5 * edgeLength);
|
31381 | }
|
31382 | }
|
31383 | }
|
31384 | }
|
31385 | }
|
31386 | };
|
31387 |
|
31388 |
|
31389 | |
31390 |
|
31391 |
|
31392 |
|
31393 |
|
31394 |
|
31395 |
|
31396 |
|
31397 | exports._calculateSpringForce = function (node1, node2, edgeLength) {
|
31398 | var dx, dy, fx, fy, springForce, distance;
|
31399 |
|
31400 | dx = (node1.x - node2.x);
|
31401 | dy = (node1.y - node2.y);
|
31402 | distance = Math.sqrt(dx * dx + dy * dy);
|
31403 |
|
31404 | if (distance == 0) {
|
31405 | distance = 0.01;
|
31406 | }
|
31407 |
|
31408 |
|
31409 | springForce = this.constants.physics.springConstant * (edgeLength - distance) / distance;
|
31410 |
|
31411 | fx = dx * springForce;
|
31412 | fy = dy * springForce;
|
31413 |
|
31414 | node1.fx += fx;
|
31415 | node1.fy += fy;
|
31416 | node2.fx -= fx;
|
31417 | node2.fy -= fy;
|
31418 | };
|
31419 |
|
31420 |
|
31421 | |
31422 |
|
31423 |
|
31424 |
|
31425 | exports._loadPhysicsConfiguration = function () {
|
31426 | if (this.physicsConfiguration === undefined) {
|
31427 | this.backupConstants = {};
|
31428 | util.deepExtend(this.backupConstants,this.constants);
|
31429 |
|
31430 | var hierarchicalLayoutDirections = ["LR", "RL", "UD", "DU"];
|
31431 | this.physicsConfiguration = document.createElement('div');
|
31432 | this.physicsConfiguration.className = "PhysicsConfiguration";
|
31433 | this.physicsConfiguration.innerHTML = '' +
|
31434 | '<table><tr><td><b>Simulation Mode:</b></td></tr>' +
|
31435 | '<tr>' +
|
31436 | '<td width="120px"><input type="radio" name="graph_physicsMethod" id="graph_physicsMethod1" value="BH" checked="checked">Barnes Hut</td>' +
|
31437 | '<td width="120px"><input type="radio" name="graph_physicsMethod" id="graph_physicsMethod2" value="R">Repulsion</td>' +
|
31438 | '<td width="120px"><input type="radio" name="graph_physicsMethod" id="graph_physicsMethod3" value="H">Hierarchical</td>' +
|
31439 | '</tr>' +
|
31440 | '</table>' +
|
31441 | '<table id="graph_BH_table" style="display:none">' +
|
31442 | '<tr><td><b>Barnes Hut</b></td></tr>' +
|
31443 | '<tr>' +
|
31444 | '<td width="150px">gravitationalConstant</td><td>0</td><td><input type="range" min="0" max="20000" value="' + (-1 * this.constants.physics.barnesHut.gravitationalConstant) + '" step="25" style="width:300px" id="graph_BH_gc"></td><td width="50px">-20000</td><td><input value="' + (-1 * this.constants.physics.barnesHut.gravitationalConstant) + '" id="graph_BH_gc_value" style="width:60px"></td>' +
|
31445 | '</tr>' +
|
31446 | '<tr>' +
|
31447 | '<td width="150px">centralGravity</td><td>0</td><td><input type="range" min="0" max="3" value="' + this.constants.physics.barnesHut.centralGravity + '" step="0.05" style="width:300px" id="graph_BH_cg"></td><td>3</td><td><input value="' + this.constants.physics.barnesHut.centralGravity + '" id="graph_BH_cg_value" style="width:60px"></td>' +
|
31448 | '</tr>' +
|
31449 | '<tr>' +
|
31450 | '<td width="150px">springLength</td><td>0</td><td><input type="range" min="0" max="500" value="' + this.constants.physics.barnesHut.springLength + '" step="1" style="width:300px" id="graph_BH_sl"></td><td>500</td><td><input value="' + this.constants.physics.barnesHut.springLength + '" id="graph_BH_sl_value" style="width:60px"></td>' +
|
31451 | '</tr>' +
|
31452 | '<tr>' +
|
31453 | '<td width="150px">springConstant</td><td>0</td><td><input type="range" min="0" max="0.5" value="' + this.constants.physics.barnesHut.springConstant + '" step="0.001" style="width:300px" id="graph_BH_sc"></td><td>0.5</td><td><input value="' + this.constants.physics.barnesHut.springConstant + '" id="graph_BH_sc_value" style="width:60px"></td>' +
|
31454 | '</tr>' +
|
31455 | '<tr>' +
|
31456 | '<td width="150px">damping</td><td>0</td><td><input type="range" min="0" max="0.3" value="' + this.constants.physics.barnesHut.damping + '" step="0.005" style="width:300px" id="graph_BH_damp"></td><td>0.3</td><td><input value="' + this.constants.physics.barnesHut.damping + '" id="graph_BH_damp_value" style="width:60px"></td>' +
|
31457 | '</tr>' +
|
31458 | '</table>' +
|
31459 | '<table id="graph_R_table" style="display:none">' +
|
31460 | '<tr><td><b>Repulsion</b></td></tr>' +
|
31461 | '<tr>' +
|
31462 | '<td width="150px">nodeDistance</td><td>0</td><td><input type="range" min="0" max="300" value="' + this.constants.physics.repulsion.nodeDistance + '" step="1" style="width:300px" id="graph_R_nd"></td><td width="50px">300</td><td><input value="' + this.constants.physics.repulsion.nodeDistance + '" id="graph_R_nd_value" style="width:60px"></td>' +
|
31463 | '</tr>' +
|
31464 | '<tr>' +
|
31465 | '<td width="150px">centralGravity</td><td>0</td><td><input type="range" min="0" max="3" value="' + this.constants.physics.repulsion.centralGravity + '" step="0.05" style="width:300px" id="graph_R_cg"></td><td>3</td><td><input value="' + this.constants.physics.repulsion.centralGravity + '" id="graph_R_cg_value" style="width:60px"></td>' +
|
31466 | '</tr>' +
|
31467 | '<tr>' +
|
31468 | '<td width="150px">springLength</td><td>0</td><td><input type="range" min="0" max="500" value="' + this.constants.physics.repulsion.springLength + '" step="1" style="width:300px" id="graph_R_sl"></td><td>500</td><td><input value="' + this.constants.physics.repulsion.springLength + '" id="graph_R_sl_value" style="width:60px"></td>' +
|
31469 | '</tr>' +
|
31470 | '<tr>' +
|
31471 | '<td width="150px">springConstant</td><td>0</td><td><input type="range" min="0" max="0.5" value="' + this.constants.physics.repulsion.springConstant + '" step="0.001" style="width:300px" id="graph_R_sc"></td><td>0.5</td><td><input value="' + this.constants.physics.repulsion.springConstant + '" id="graph_R_sc_value" style="width:60px"></td>' +
|
31472 | '</tr>' +
|
31473 | '<tr>' +
|
31474 | '<td width="150px">damping</td><td>0</td><td><input type="range" min="0" max="0.3" value="' + this.constants.physics.repulsion.damping + '" step="0.005" style="width:300px" id="graph_R_damp"></td><td>0.3</td><td><input value="' + this.constants.physics.repulsion.damping + '" id="graph_R_damp_value" style="width:60px"></td>' +
|
31475 | '</tr>' +
|
31476 | '</table>' +
|
31477 | '<table id="graph_H_table" style="display:none">' +
|
31478 | '<tr><td width="150"><b>Hierarchical</b></td></tr>' +
|
31479 | '<tr>' +
|
31480 | '<td width="150px">nodeDistance</td><td>0</td><td><input type="range" min="0" max="300" value="' + this.constants.physics.hierarchicalRepulsion.nodeDistance + '" step="1" style="width:300px" id="graph_H_nd"></td><td width="50px">300</td><td><input value="' + this.constants.physics.hierarchicalRepulsion.nodeDistance + '" id="graph_H_nd_value" style="width:60px"></td>' +
|
31481 | '</tr>' +
|
31482 | '<tr>' +
|
31483 | '<td width="150px">centralGravity</td><td>0</td><td><input type="range" min="0" max="3" value="' + this.constants.physics.hierarchicalRepulsion.centralGravity + '" step="0.05" style="width:300px" id="graph_H_cg"></td><td>3</td><td><input value="' + this.constants.physics.hierarchicalRepulsion.centralGravity + '" id="graph_H_cg_value" style="width:60px"></td>' +
|
31484 | '</tr>' +
|
31485 | '<tr>' +
|
31486 | '<td width="150px">springLength</td><td>0</td><td><input type="range" min="0" max="500" value="' + this.constants.physics.hierarchicalRepulsion.springLength + '" step="1" style="width:300px" id="graph_H_sl"></td><td>500</td><td><input value="' + this.constants.physics.hierarchicalRepulsion.springLength + '" id="graph_H_sl_value" style="width:60px"></td>' +
|
31487 | '</tr>' +
|
31488 | '<tr>' +
|
31489 | '<td width="150px">springConstant</td><td>0</td><td><input type="range" min="0" max="0.5" value="' + this.constants.physics.hierarchicalRepulsion.springConstant + '" step="0.001" style="width:300px" id="graph_H_sc"></td><td>0.5</td><td><input value="' + this.constants.physics.hierarchicalRepulsion.springConstant + '" id="graph_H_sc_value" style="width:60px"></td>' +
|
31490 | '</tr>' +
|
31491 | '<tr>' +
|
31492 | '<td width="150px">damping</td><td>0</td><td><input type="range" min="0" max="0.3" value="' + this.constants.physics.hierarchicalRepulsion.damping + '" step="0.005" style="width:300px" id="graph_H_damp"></td><td>0.3</td><td><input value="' + this.constants.physics.hierarchicalRepulsion.damping + '" id="graph_H_damp_value" style="width:60px"></td>' +
|
31493 | '</tr>' +
|
31494 | '<tr>' +
|
31495 | '<td width="150px">direction</td><td>1</td><td><input type="range" min="0" max="3" value="' + hierarchicalLayoutDirections.indexOf(this.constants.hierarchicalLayout.direction) + '" step="1" style="width:300px" id="graph_H_direction"></td><td>4</td><td><input value="' + this.constants.hierarchicalLayout.direction + '" id="graph_H_direction_value" style="width:60px"></td>' +
|
31496 | '</tr>' +
|
31497 | '<tr>' +
|
31498 | '<td width="150px">levelSeparation</td><td>1</td><td><input type="range" min="0" max="500" value="' + this.constants.hierarchicalLayout.levelSeparation + '" step="1" style="width:300px" id="graph_H_levsep"></td><td>500</td><td><input value="' + this.constants.hierarchicalLayout.levelSeparation + '" id="graph_H_levsep_value" style="width:60px"></td>' +
|
31499 | '</tr>' +
|
31500 | '<tr>' +
|
31501 | '<td width="150px">nodeSpacing</td><td>1</td><td><input type="range" min="0" max="500" value="' + this.constants.hierarchicalLayout.nodeSpacing + '" step="1" style="width:300px" id="graph_H_nspac"></td><td>500</td><td><input value="' + this.constants.hierarchicalLayout.nodeSpacing + '" id="graph_H_nspac_value" style="width:60px"></td>' +
|
31502 | '</tr>' +
|
31503 | '</table>' +
|
31504 | '<table><tr><td><b>Options:</b></td></tr>' +
|
31505 | '<tr>' +
|
31506 | '<td width="180px"><input type="button" id="graph_toggleSmooth" value="Toggle smoothCurves" style="width:150px"></td>' +
|
31507 | '<td width="180px"><input type="button" id="graph_repositionNodes" value="Reinitialize" style="width:150px"></td>' +
|
31508 | '<td width="180px"><input type="button" id="graph_generateOptions" value="Generate Options" style="width:150px"></td>' +
|
31509 | '</tr>' +
|
31510 | '</table>'
|
31511 | this.containerElement.parentElement.insertBefore(this.physicsConfiguration, this.containerElement);
|
31512 | this.optionsDiv = document.createElement("div");
|
31513 | this.optionsDiv.style.fontSize = "14px";
|
31514 | this.optionsDiv.style.fontFamily = "verdana";
|
31515 | this.containerElement.parentElement.insertBefore(this.optionsDiv, this.containerElement);
|
31516 |
|
31517 | var rangeElement;
|
31518 | rangeElement = document.getElementById('graph_BH_gc');
|
31519 | rangeElement.onchange = showValueOfRange.bind(this, 'graph_BH_gc', -1, "physics_barnesHut_gravitationalConstant");
|
31520 | rangeElement = document.getElementById('graph_BH_cg');
|
31521 | rangeElement.onchange = showValueOfRange.bind(this, 'graph_BH_cg', 1, "physics_centralGravity");
|
31522 | rangeElement = document.getElementById('graph_BH_sc');
|
31523 | rangeElement.onchange = showValueOfRange.bind(this, 'graph_BH_sc', 1, "physics_springConstant");
|
31524 | rangeElement = document.getElementById('graph_BH_sl');
|
31525 | rangeElement.onchange = showValueOfRange.bind(this, 'graph_BH_sl', 1, "physics_springLength");
|
31526 | rangeElement = document.getElementById('graph_BH_damp');
|
31527 | rangeElement.onchange = showValueOfRange.bind(this, 'graph_BH_damp', 1, "physics_damping");
|
31528 |
|
31529 | rangeElement = document.getElementById('graph_R_nd');
|
31530 | rangeElement.onchange = showValueOfRange.bind(this, 'graph_R_nd', 1, "physics_repulsion_nodeDistance");
|
31531 | rangeElement = document.getElementById('graph_R_cg');
|
31532 | rangeElement.onchange = showValueOfRange.bind(this, 'graph_R_cg', 1, "physics_centralGravity");
|
31533 | rangeElement = document.getElementById('graph_R_sc');
|
31534 | rangeElement.onchange = showValueOfRange.bind(this, 'graph_R_sc', 1, "physics_springConstant");
|
31535 | rangeElement = document.getElementById('graph_R_sl');
|
31536 | rangeElement.onchange = showValueOfRange.bind(this, 'graph_R_sl', 1, "physics_springLength");
|
31537 | rangeElement = document.getElementById('graph_R_damp');
|
31538 | rangeElement.onchange = showValueOfRange.bind(this, 'graph_R_damp', 1, "physics_damping");
|
31539 |
|
31540 | rangeElement = document.getElementById('graph_H_nd');
|
31541 | rangeElement.onchange = showValueOfRange.bind(this, 'graph_H_nd', 1, "physics_hierarchicalRepulsion_nodeDistance");
|
31542 | rangeElement = document.getElementById('graph_H_cg');
|
31543 | rangeElement.onchange = showValueOfRange.bind(this, 'graph_H_cg', 1, "physics_centralGravity");
|
31544 | rangeElement = document.getElementById('graph_H_sc');
|
31545 | rangeElement.onchange = showValueOfRange.bind(this, 'graph_H_sc', 1, "physics_springConstant");
|
31546 | rangeElement = document.getElementById('graph_H_sl');
|
31547 | rangeElement.onchange = showValueOfRange.bind(this, 'graph_H_sl', 1, "physics_springLength");
|
31548 | rangeElement = document.getElementById('graph_H_damp');
|
31549 | rangeElement.onchange = showValueOfRange.bind(this, 'graph_H_damp', 1, "physics_damping");
|
31550 | rangeElement = document.getElementById('graph_H_direction');
|
31551 | rangeElement.onchange = showValueOfRange.bind(this, 'graph_H_direction', hierarchicalLayoutDirections, "hierarchicalLayout_direction");
|
31552 | rangeElement = document.getElementById('graph_H_levsep');
|
31553 | rangeElement.onchange = showValueOfRange.bind(this, 'graph_H_levsep', 1, "hierarchicalLayout_levelSeparation");
|
31554 | rangeElement = document.getElementById('graph_H_nspac');
|
31555 | rangeElement.onchange = showValueOfRange.bind(this, 'graph_H_nspac', 1, "hierarchicalLayout_nodeSpacing");
|
31556 |
|
31557 | var radioButton1 = document.getElementById("graph_physicsMethod1");
|
31558 | var radioButton2 = document.getElementById("graph_physicsMethod2");
|
31559 | var radioButton3 = document.getElementById("graph_physicsMethod3");
|
31560 | radioButton2.checked = true;
|
31561 | if (this.constants.physics.barnesHut.enabled) {
|
31562 | radioButton1.checked = true;
|
31563 | }
|
31564 | if (this.constants.hierarchicalLayout.enabled) {
|
31565 | radioButton3.checked = true;
|
31566 | }
|
31567 |
|
31568 | var graph_toggleSmooth = document.getElementById("graph_toggleSmooth");
|
31569 | var graph_repositionNodes = document.getElementById("graph_repositionNodes");
|
31570 | var graph_generateOptions = document.getElementById("graph_generateOptions");
|
31571 |
|
31572 | graph_toggleSmooth.onclick = graphToggleSmoothCurves.bind(this);
|
31573 | graph_repositionNodes.onclick = graphRepositionNodes.bind(this);
|
31574 | graph_generateOptions.onclick = graphGenerateOptions.bind(this);
|
31575 | if (this.constants.smoothCurves == true && this.constants.dynamicSmoothCurves == false) {
|
31576 | graph_toggleSmooth.style.background = "#A4FF56";
|
31577 | }
|
31578 | else {
|
31579 | graph_toggleSmooth.style.background = "#FF8532";
|
31580 | }
|
31581 |
|
31582 |
|
31583 | switchConfigurations.apply(this);
|
31584 |
|
31585 | radioButton1.onchange = switchConfigurations.bind(this);
|
31586 | radioButton2.onchange = switchConfigurations.bind(this);
|
31587 | radioButton3.onchange = switchConfigurations.bind(this);
|
31588 | }
|
31589 | };
|
31590 |
|
31591 | |
31592 |
|
31593 |
|
31594 |
|
31595 |
|
31596 |
|
31597 |
|
31598 | exports._overWriteGraphConstants = function (constantsVariableName, value) {
|
31599 | var nameArray = constantsVariableName.split("_");
|
31600 | if (nameArray.length == 1) {
|
31601 | this.constants[nameArray[0]] = value;
|
31602 | }
|
31603 | else if (nameArray.length == 2) {
|
31604 | this.constants[nameArray[0]][nameArray[1]] = value;
|
31605 | }
|
31606 | else if (nameArray.length == 3) {
|
31607 | this.constants[nameArray[0]][nameArray[1]][nameArray[2]] = value;
|
31608 | }
|
31609 | };
|
31610 |
|
31611 |
|
31612 | |
31613 |
|
31614 |
|
31615 | function graphToggleSmoothCurves () {
|
31616 | this.constants.smoothCurves.enabled = !this.constants.smoothCurves.enabled;
|
31617 | var graph_toggleSmooth = document.getElementById("graph_toggleSmooth");
|
31618 | if (this.constants.smoothCurves.enabled == true) {graph_toggleSmooth.style.background = "#A4FF56";}
|
31619 | else {graph_toggleSmooth.style.background = "#FF8532";}
|
31620 |
|
31621 | this._configureSmoothCurves(false);
|
31622 | }
|
31623 |
|
31624 | |
31625 |
|
31626 |
|
31627 |
|
31628 | function graphRepositionNodes () {
|
31629 | for (var nodeId in this.calculationNodes) {
|
31630 | if (this.calculationNodes.hasOwnProperty(nodeId)) {
|
31631 | this.calculationNodes[nodeId].vx = 0; this.calculationNodes[nodeId].vy = 0;
|
31632 | this.calculationNodes[nodeId].fx = 0; this.calculationNodes[nodeId].fy = 0;
|
31633 | }
|
31634 | }
|
31635 | if (this.constants.hierarchicalLayout.enabled == true) {
|
31636 | this._setupHierarchicalLayout();
|
31637 | showValueOfRange.call(this, 'graph_H_nd', 1, "physics_hierarchicalRepulsion_nodeDistance");
|
31638 | showValueOfRange.call(this, 'graph_H_cg', 1, "physics_centralGravity");
|
31639 | showValueOfRange.call(this, 'graph_H_sc', 1, "physics_springConstant");
|
31640 | showValueOfRange.call(this, 'graph_H_sl', 1, "physics_springLength");
|
31641 | showValueOfRange.call(this, 'graph_H_damp', 1, "physics_damping");
|
31642 | }
|
31643 | else {
|
31644 | this.repositionNodes();
|
31645 | }
|
31646 | this.moving = true;
|
31647 | this.start();
|
31648 | }
|
31649 |
|
31650 | |
31651 |
|
31652 |
|
31653 | function graphGenerateOptions () {
|
31654 | var options = "No options are required, default values used.";
|
31655 | var optionsSpecific = [];
|
31656 | var radioButton1 = document.getElementById("graph_physicsMethod1");
|
31657 | var radioButton2 = document.getElementById("graph_physicsMethod2");
|
31658 | if (radioButton1.checked == true) {
|
31659 | if (this.constants.physics.barnesHut.gravitationalConstant != this.backupConstants.physics.barnesHut.gravitationalConstant) {optionsSpecific.push("gravitationalConstant: " + this.constants.physics.barnesHut.gravitationalConstant);}
|
31660 | if (this.constants.physics.centralGravity != this.backupConstants.physics.barnesHut.centralGravity) {optionsSpecific.push("centralGravity: " + this.constants.physics.centralGravity);}
|
31661 | if (this.constants.physics.springLength != this.backupConstants.physics.barnesHut.springLength) {optionsSpecific.push("springLength: " + this.constants.physics.springLength);}
|
31662 | if (this.constants.physics.springConstant != this.backupConstants.physics.barnesHut.springConstant) {optionsSpecific.push("springConstant: " + this.constants.physics.springConstant);}
|
31663 | if (this.constants.physics.damping != this.backupConstants.physics.barnesHut.damping) {optionsSpecific.push("damping: " + this.constants.physics.damping);}
|
31664 | if (optionsSpecific.length != 0) {
|
31665 | options = "var options = {";
|
31666 | options += "physics: {barnesHut: {";
|
31667 | for (var i = 0; i < optionsSpecific.length; i++) {
|
31668 | options += optionsSpecific[i];
|
31669 | if (i < optionsSpecific.length - 1) {
|
31670 | options += ", "
|
31671 | }
|
31672 | }
|
31673 | options += '}}'
|
31674 | }
|
31675 | if (this.constants.smoothCurves.enabled != this.backupConstants.smoothCurves.enabled) {
|
31676 | if (optionsSpecific.length == 0) {options = "var options = {";}
|
31677 | else {options += ", "}
|
31678 | options += "smoothCurves: " + this.constants.smoothCurves.enabled;
|
31679 | }
|
31680 | if (options != "No options are required, default values used.") {
|
31681 | options += '};'
|
31682 | }
|
31683 | }
|
31684 | else if (radioButton2.checked == true) {
|
31685 | options = "var options = {";
|
31686 | options += "physics: {barnesHut: {enabled: false}";
|
31687 | if (this.constants.physics.repulsion.nodeDistance != this.backupConstants.physics.repulsion.nodeDistance) {optionsSpecific.push("nodeDistance: " + this.constants.physics.repulsion.nodeDistance);}
|
31688 | if (this.constants.physics.centralGravity != this.backupConstants.physics.repulsion.centralGravity) {optionsSpecific.push("centralGravity: " + this.constants.physics.centralGravity);}
|
31689 | if (this.constants.physics.springLength != this.backupConstants.physics.repulsion.springLength) {optionsSpecific.push("springLength: " + this.constants.physics.springLength);}
|
31690 | if (this.constants.physics.springConstant != this.backupConstants.physics.repulsion.springConstant) {optionsSpecific.push("springConstant: " + this.constants.physics.springConstant);}
|
31691 | if (this.constants.physics.damping != this.backupConstants.physics.repulsion.damping) {optionsSpecific.push("damping: " + this.constants.physics.damping);}
|
31692 | if (optionsSpecific.length != 0) {
|
31693 | options += ", repulsion: {";
|
31694 | for (var i = 0; i < optionsSpecific.length; i++) {
|
31695 | options += optionsSpecific[i];
|
31696 | if (i < optionsSpecific.length - 1) {
|
31697 | options += ", "
|
31698 | }
|
31699 | }
|
31700 | options += '}}'
|
31701 | }
|
31702 | if (optionsSpecific.length == 0) {options += "}"}
|
31703 | if (this.constants.smoothCurves != this.backupConstants.smoothCurves) {
|
31704 | options += ", smoothCurves: " + this.constants.smoothCurves;
|
31705 | }
|
31706 | options += '};'
|
31707 | }
|
31708 | else {
|
31709 | options = "var options = {";
|
31710 | if (this.constants.physics.hierarchicalRepulsion.nodeDistance != this.backupConstants.physics.hierarchicalRepulsion.nodeDistance) {optionsSpecific.push("nodeDistance: " + this.constants.physics.hierarchicalRepulsion.nodeDistance);}
|
31711 | if (this.constants.physics.centralGravity != this.backupConstants.physics.hierarchicalRepulsion.centralGravity) {optionsSpecific.push("centralGravity: " + this.constants.physics.centralGravity);}
|
31712 | if (this.constants.physics.springLength != this.backupConstants.physics.hierarchicalRepulsion.springLength) {optionsSpecific.push("springLength: " + this.constants.physics.springLength);}
|
31713 | if (this.constants.physics.springConstant != this.backupConstants.physics.hierarchicalRepulsion.springConstant) {optionsSpecific.push("springConstant: " + this.constants.physics.springConstant);}
|
31714 | if (this.constants.physics.damping != this.backupConstants.physics.hierarchicalRepulsion.damping) {optionsSpecific.push("damping: " + this.constants.physics.damping);}
|
31715 | if (optionsSpecific.length != 0) {
|
31716 | options += "physics: {hierarchicalRepulsion: {";
|
31717 | for (var i = 0; i < optionsSpecific.length; i++) {
|
31718 | options += optionsSpecific[i];
|
31719 | if (i < optionsSpecific.length - 1) {
|
31720 | options += ", ";
|
31721 | }
|
31722 | }
|
31723 | options += '}},';
|
31724 | }
|
31725 | options += 'hierarchicalLayout: {';
|
31726 | optionsSpecific = [];
|
31727 | if (this.constants.hierarchicalLayout.direction != this.backupConstants.hierarchicalLayout.direction) {optionsSpecific.push("direction: " + this.constants.hierarchicalLayout.direction);}
|
31728 | if (Math.abs(this.constants.hierarchicalLayout.levelSeparation) != this.backupConstants.hierarchicalLayout.levelSeparation) {optionsSpecific.push("levelSeparation: " + this.constants.hierarchicalLayout.levelSeparation);}
|
31729 | if (this.constants.hierarchicalLayout.nodeSpacing != this.backupConstants.hierarchicalLayout.nodeSpacing) {optionsSpecific.push("nodeSpacing: " + this.constants.hierarchicalLayout.nodeSpacing);}
|
31730 | if (optionsSpecific.length != 0) {
|
31731 | for (var i = 0; i < optionsSpecific.length; i++) {
|
31732 | options += optionsSpecific[i];
|
31733 | if (i < optionsSpecific.length - 1) {
|
31734 | options += ", "
|
31735 | }
|
31736 | }
|
31737 | options += '}'
|
31738 | }
|
31739 | else {
|
31740 | options += "enabled:true}";
|
31741 | }
|
31742 | options += '};'
|
31743 | }
|
31744 |
|
31745 |
|
31746 | this.optionsDiv.innerHTML = options;
|
31747 | }
|
31748 |
|
31749 | |
31750 |
|
31751 |
|
31752 |
|
31753 | function switchConfigurations () {
|
31754 | var ids = ["graph_BH_table", "graph_R_table", "graph_H_table"];
|
31755 | var radioButton = document.querySelector('input[name="graph_physicsMethod"]:checked').value;
|
31756 | var tableId = "graph_" + radioButton + "_table";
|
31757 | var table = document.getElementById(tableId);
|
31758 | table.style.display = "block";
|
31759 | for (var i = 0; i < ids.length; i++) {
|
31760 | if (ids[i] != tableId) {
|
31761 | table = document.getElementById(ids[i]);
|
31762 | table.style.display = "none";
|
31763 | }
|
31764 | }
|
31765 | this._restoreNodes();
|
31766 | if (radioButton == "R") {
|
31767 | this.constants.hierarchicalLayout.enabled = false;
|
31768 | this.constants.physics.hierarchicalRepulsion.enabled = false;
|
31769 | this.constants.physics.barnesHut.enabled = false;
|
31770 | }
|
31771 | else if (radioButton == "H") {
|
31772 | if (this.constants.hierarchicalLayout.enabled == false) {
|
31773 | this.constants.hierarchicalLayout.enabled = true;
|
31774 | this.constants.physics.hierarchicalRepulsion.enabled = true;
|
31775 | this.constants.physics.barnesHut.enabled = false;
|
31776 | this.constants.smoothCurves.enabled = false;
|
31777 | this._setupHierarchicalLayout();
|
31778 | }
|
31779 | }
|
31780 | else {
|
31781 | this.constants.hierarchicalLayout.enabled = false;
|
31782 | this.constants.physics.hierarchicalRepulsion.enabled = false;
|
31783 | this.constants.physics.barnesHut.enabled = true;
|
31784 | }
|
31785 | this._loadSelectedForceSolver();
|
31786 | var graph_toggleSmooth = document.getElementById("graph_toggleSmooth");
|
31787 | if (this.constants.smoothCurves.enabled == true) {graph_toggleSmooth.style.background = "#A4FF56";}
|
31788 | else {graph_toggleSmooth.style.background = "#FF8532";}
|
31789 | this.moving = true;
|
31790 | this.start();
|
31791 | }
|
31792 |
|
31793 |
|
31794 | |
31795 |
|
31796 |
|
31797 |
|
31798 |
|
31799 |
|
31800 |
|
31801 | function showValueOfRange (id,map,constantsVariableName) {
|
31802 | var valueId = id + "_value";
|
31803 | var rangeValue = document.getElementById(id).value;
|
31804 |
|
31805 | if (map instanceof Array) {
|
31806 | document.getElementById(valueId).value = map[parseInt(rangeValue)];
|
31807 | this._overWriteGraphConstants(constantsVariableName,map[parseInt(rangeValue)]);
|
31808 | }
|
31809 | else {
|
31810 | document.getElementById(valueId).value = parseInt(map) * parseFloat(rangeValue);
|
31811 | this._overWriteGraphConstants(constantsVariableName, parseInt(map) * parseFloat(rangeValue));
|
31812 | }
|
31813 |
|
31814 | if (constantsVariableName == "hierarchicalLayout_direction" ||
|
31815 | constantsVariableName == "hierarchicalLayout_levelSeparation" ||
|
31816 | constantsVariableName == "hierarchicalLayout_nodeSpacing") {
|
31817 | this._setupHierarchicalLayout();
|
31818 | }
|
31819 | this.moving = true;
|
31820 | this.start();
|
31821 | }
|
31822 |
|
31823 |
|
31824 | },
|
31825 |
|
31826 | function(module, exports, __webpack_require__) {
|
31827 |
|
31828 | function webpackContext(req) {
|
31829 | throw new Error("Cannot find module '" + req + "'.");
|
31830 | }
|
31831 | webpackContext.resolve = webpackContext;
|
31832 | webpackContext.keys = function() { return []; };
|
31833 | module.exports = webpackContext;
|
31834 |
|
31835 |
|
31836 | },
|
31837 |
|
31838 | function(module, exports, __webpack_require__) {
|
31839 |
|
31840 | |
31841 |
|
31842 |
|
31843 |
|
31844 |
|
31845 |
|
31846 | exports._calculateNodeForces = function () {
|
31847 | var dx, dy, angle, distance, fx, fy, combinedClusterSize,
|
31848 | repulsingForce, node1, node2, i, j;
|
31849 |
|
31850 | var nodes = this.calculationNodes;
|
31851 | var nodeIndices = this.calculationNodeIndices;
|
31852 |
|
31853 |
|
31854 | var a_base = -2 / 3;
|
31855 | var b = 4 / 3;
|
31856 |
|
31857 |
|
31858 | var nodeDistance = this.constants.physics.repulsion.nodeDistance;
|
31859 | var minimumDistance = nodeDistance;
|
31860 |
|
31861 |
|
31862 |
|
31863 | for (i = 0; i < nodeIndices.length - 1; i++) {
|
31864 | node1 = nodes[nodeIndices[i]];
|
31865 | for (j = i + 1; j < nodeIndices.length; j++) {
|
31866 | node2 = nodes[nodeIndices[j]];
|
31867 | combinedClusterSize = node1.clusterSize + node2.clusterSize - 2;
|
31868 |
|
31869 | dx = node2.x - node1.x;
|
31870 | dy = node2.y - node1.y;
|
31871 | distance = Math.sqrt(dx * dx + dy * dy);
|
31872 |
|
31873 | minimumDistance = (combinedClusterSize == 0) ? nodeDistance : (nodeDistance * (1 + combinedClusterSize * this.constants.clustering.distanceAmplification));
|
31874 | var a = a_base / minimumDistance;
|
31875 | if (distance < 2 * minimumDistance) {
|
31876 | if (distance < 0.5 * minimumDistance) {
|
31877 | repulsingForce = 1.0;
|
31878 | }
|
31879 | else {
|
31880 | repulsingForce = a * distance + b;
|
31881 | }
|
31882 |
|
31883 |
|
31884 | repulsingForce *= (combinedClusterSize == 0) ? 1 : 1 + combinedClusterSize * this.constants.clustering.forceAmplification;
|
31885 | repulsingForce = repulsingForce / distance;
|
31886 |
|
31887 | fx = dx * repulsingForce;
|
31888 | fy = dy * repulsingForce;
|
31889 |
|
31890 | node1.fx -= fx;
|
31891 | node1.fy -= fy;
|
31892 | node2.fx += fx;
|
31893 | node2.fy += fy;
|
31894 | }
|
31895 | }
|
31896 | }
|
31897 | };
|
31898 |
|
31899 |
|
31900 | },
|
31901 |
|
31902 | function(module, exports, __webpack_require__) {
|
31903 |
|
31904 | |
31905 |
|
31906 |
|
31907 |
|
31908 |
|
31909 |
|
31910 | exports._calculateNodeForces = function () {
|
31911 | var dx, dy, distance, fx, fy,
|
31912 | repulsingForce, node1, node2, i, j;
|
31913 |
|
31914 | var nodes = this.calculationNodes;
|
31915 | var nodeIndices = this.calculationNodeIndices;
|
31916 |
|
31917 |
|
31918 | var nodeDistance = this.constants.physics.hierarchicalRepulsion.nodeDistance;
|
31919 |
|
31920 |
|
31921 |
|
31922 | for (i = 0; i < nodeIndices.length - 1; i++) {
|
31923 | node1 = nodes[nodeIndices[i]];
|
31924 | for (j = i + 1; j < nodeIndices.length; j++) {
|
31925 | node2 = nodes[nodeIndices[j]];
|
31926 |
|
31927 |
|
31928 | if (node1.level == node2.level) {
|
31929 |
|
31930 | dx = node2.x - node1.x;
|
31931 | dy = node2.y - node1.y;
|
31932 | distance = Math.sqrt(dx * dx + dy * dy);
|
31933 |
|
31934 |
|
31935 | var steepness = 0.05;
|
31936 | if (distance < nodeDistance) {
|
31937 | repulsingForce = -Math.pow(steepness*distance,2) + Math.pow(steepness*nodeDistance,2);
|
31938 | }
|
31939 | else {
|
31940 | repulsingForce = 0;
|
31941 | }
|
31942 |
|
31943 | if (distance == 0) {
|
31944 | distance = 0.01;
|
31945 | }
|
31946 | else {
|
31947 | repulsingForce = repulsingForce / distance;
|
31948 | }
|
31949 | fx = dx * repulsingForce;
|
31950 | fy = dy * repulsingForce;
|
31951 |
|
31952 | node1.fx -= fx;
|
31953 | node1.fy -= fy;
|
31954 | node2.fx += fx;
|
31955 | node2.fy += fy;
|
31956 | }
|
31957 | }
|
31958 | }
|
31959 | };
|
31960 |
|
31961 |
|
31962 | |
31963 |
|
31964 |
|
31965 |
|
31966 |
|
31967 | exports._calculateHierarchicalSpringForces = function () {
|
31968 | var edgeLength, edge, edgeId;
|
31969 | var dx, dy, fx, fy, springForce, distance;
|
31970 | var edges = this.edges;
|
31971 |
|
31972 | var nodes = this.calculationNodes;
|
31973 | var nodeIndices = this.calculationNodeIndices;
|
31974 |
|
31975 |
|
31976 | for (var i = 0; i < nodeIndices.length; i++) {
|
31977 | var node1 = nodes[nodeIndices[i]];
|
31978 | node1.springFx = 0;
|
31979 | node1.springFy = 0;
|
31980 | }
|
31981 |
|
31982 |
|
31983 |
|
31984 | for (edgeId in edges) {
|
31985 | if (edges.hasOwnProperty(edgeId)) {
|
31986 | edge = edges[edgeId];
|
31987 | if (edge.connected) {
|
31988 |
|
31989 | if (this.nodes.hasOwnProperty(edge.toId) && this.nodes.hasOwnProperty(edge.fromId)) {
|
31990 | edgeLength = edge.physics.springLength;
|
31991 |
|
31992 | edgeLength += (edge.to.clusterSize + edge.from.clusterSize - 2) * this.constants.clustering.edgeGrowth;
|
31993 |
|
31994 | dx = (edge.from.x - edge.to.x);
|
31995 | dy = (edge.from.y - edge.to.y);
|
31996 | distance = Math.sqrt(dx * dx + dy * dy);
|
31997 |
|
31998 | if (distance == 0) {
|
31999 | distance = 0.01;
|
32000 | }
|
32001 |
|
32002 |
|
32003 | springForce = this.constants.physics.springConstant * (edgeLength - distance) / distance;
|
32004 |
|
32005 | fx = dx * springForce;
|
32006 | fy = dy * springForce;
|
32007 |
|
32008 |
|
32009 |
|
32010 | if (edge.to.level != edge.from.level) {
|
32011 | edge.to.springFx -= fx;
|
32012 | edge.to.springFy -= fy;
|
32013 | edge.from.springFx += fx;
|
32014 | edge.from.springFy += fy;
|
32015 | }
|
32016 | else {
|
32017 | var factor = 0.5;
|
32018 | edge.to.fx -= factor*fx;
|
32019 | edge.to.fy -= factor*fy;
|
32020 | edge.from.fx += factor*fx;
|
32021 | edge.from.fy += factor*fy;
|
32022 | }
|
32023 | }
|
32024 | }
|
32025 | }
|
32026 | }
|
32027 |
|
32028 |
|
32029 | var springForce = 1;
|
32030 | var springFx, springFy;
|
32031 | for (i = 0; i < nodeIndices.length; i++) {
|
32032 | var node = nodes[nodeIndices[i]];
|
32033 | springFx = Math.min(springForce,Math.max(-springForce,node.springFx));
|
32034 | springFy = Math.min(springForce,Math.max(-springForce,node.springFy));
|
32035 |
|
32036 | node.fx += springFx;
|
32037 | node.fy += springFy;
|
32038 | }
|
32039 |
|
32040 |
|
32041 | var totalFx = 0;
|
32042 | var totalFy = 0;
|
32043 | for (i = 0; i < nodeIndices.length; i++) {
|
32044 | var node = nodes[nodeIndices[i]];
|
32045 | totalFx += node.fx;
|
32046 | totalFy += node.fy;
|
32047 | }
|
32048 | var correctionFx = totalFx / nodeIndices.length;
|
32049 | var correctionFy = totalFy / nodeIndices.length;
|
32050 |
|
32051 | for (i = 0; i < nodeIndices.length; i++) {
|
32052 | var node = nodes[nodeIndices[i]];
|
32053 | node.fx -= correctionFx;
|
32054 | node.fy -= correctionFy;
|
32055 | }
|
32056 |
|
32057 | };
|
32058 |
|
32059 | },
|
32060 |
|
32061 | function(module, exports, __webpack_require__) {
|
32062 |
|
32063 | |
32064 |
|
32065 |
|
32066 |
|
32067 |
|
32068 |
|
32069 | exports._calculateNodeForces = function() {
|
32070 | if (this.constants.physics.barnesHut.gravitationalConstant != 0) {
|
32071 | var node;
|
32072 | var nodes = this.calculationNodes;
|
32073 | var nodeIndices = this.calculationNodeIndices;
|
32074 | var nodeCount = nodeIndices.length;
|
32075 |
|
32076 | this._formBarnesHutTree(nodes,nodeIndices);
|
32077 |
|
32078 | var barnesHutTree = this.barnesHutTree;
|
32079 |
|
32080 |
|
32081 | for (var i = 0; i < nodeCount; i++) {
|
32082 | node = nodes[nodeIndices[i]];
|
32083 | if (node.options.mass > 0) {
|
32084 |
|
32085 | this._getForceContribution(barnesHutTree.root.children.NW,node);
|
32086 | this._getForceContribution(barnesHutTree.root.children.NE,node);
|
32087 | this._getForceContribution(barnesHutTree.root.children.SW,node);
|
32088 | this._getForceContribution(barnesHutTree.root.children.SE,node);
|
32089 | }
|
32090 | }
|
32091 | }
|
32092 | };
|
32093 |
|
32094 |
|
32095 | |
32096 |
|
32097 |
|
32098 |
|
32099 |
|
32100 |
|
32101 |
|
32102 |
|
32103 | exports._getForceContribution = function(parentBranch,node) {
|
32104 |
|
32105 | if (parentBranch.childrenCount > 0) {
|
32106 | var dx,dy,distance;
|
32107 |
|
32108 |
|
32109 | dx = parentBranch.centerOfMass.x - node.x;
|
32110 | dy = parentBranch.centerOfMass.y - node.y;
|
32111 | distance = Math.sqrt(dx * dx + dy * dy);
|
32112 |
|
32113 |
|
32114 |
|
32115 |
|
32116 | if (distance * parentBranch.calcSize > this.constants.physics.barnesHut.theta) {
|
32117 |
|
32118 | if (distance == 0) {
|
32119 | distance = 0.1*Math.random();
|
32120 | dx = distance;
|
32121 | }
|
32122 | var gravityForce = this.constants.physics.barnesHut.gravitationalConstant * parentBranch.mass * node.options.mass / (distance * distance * distance);
|
32123 | var fx = dx * gravityForce;
|
32124 | var fy = dy * gravityForce;
|
32125 | node.fx += fx;
|
32126 | node.fy += fy;
|
32127 | }
|
32128 | else {
|
32129 |
|
32130 | if (parentBranch.childrenCount == 4) {
|
32131 | this._getForceContribution(parentBranch.children.NW,node);
|
32132 | this._getForceContribution(parentBranch.children.NE,node);
|
32133 | this._getForceContribution(parentBranch.children.SW,node);
|
32134 | this._getForceContribution(parentBranch.children.SE,node);
|
32135 | }
|
32136 | else {
|
32137 | if (parentBranch.children.data.id != node.id) {
|
32138 |
|
32139 | if (distance == 0) {
|
32140 | distance = 0.5*Math.random();
|
32141 | dx = distance;
|
32142 | }
|
32143 | var gravityForce = this.constants.physics.barnesHut.gravitationalConstant * parentBranch.mass * node.options.mass / (distance * distance * distance);
|
32144 | var fx = dx * gravityForce;
|
32145 | var fy = dy * gravityForce;
|
32146 | node.fx += fx;
|
32147 | node.fy += fy;
|
32148 | }
|
32149 | }
|
32150 | }
|
32151 | }
|
32152 | };
|
32153 |
|
32154 | |
32155 |
|
32156 |
|
32157 |
|
32158 |
|
32159 |
|
32160 |
|
32161 | exports._formBarnesHutTree = function(nodes,nodeIndices) {
|
32162 | var node;
|
32163 | var nodeCount = nodeIndices.length;
|
32164 |
|
32165 | var minX = Number.MAX_VALUE,
|
32166 | minY = Number.MAX_VALUE,
|
32167 | maxX =-Number.MAX_VALUE,
|
32168 | maxY =-Number.MAX_VALUE;
|
32169 |
|
32170 |
|
32171 | for (var i = 0; i < nodeCount; i++) {
|
32172 | var x = nodes[nodeIndices[i]].x;
|
32173 | var y = nodes[nodeIndices[i]].y;
|
32174 | if (nodes[nodeIndices[i]].options.mass > 0) {
|
32175 | if (x < minX) { minX = x; }
|
32176 | if (x > maxX) { maxX = x; }
|
32177 | if (y < minY) { minY = y; }
|
32178 | if (y > maxY) { maxY = y; }
|
32179 | }
|
32180 | }
|
32181 |
|
32182 | var sizeDiff = Math.abs(maxX - minX) - Math.abs(maxY - minY);
|
32183 | if (sizeDiff > 0) {minY -= 0.5 * sizeDiff; maxY += 0.5 * sizeDiff;}
|
32184 | else {minX += 0.5 * sizeDiff; maxX -= 0.5 * sizeDiff;}
|
32185 |
|
32186 |
|
32187 | var minimumTreeSize = 1e-5;
|
32188 | var rootSize = Math.max(minimumTreeSize,Math.abs(maxX - minX));
|
32189 | var halfRootSize = 0.5 * rootSize;
|
32190 | var centerX = 0.5 * (minX + maxX), centerY = 0.5 * (minY + maxY);
|
32191 |
|
32192 |
|
32193 | var barnesHutTree = {
|
32194 | root:{
|
32195 | centerOfMass: {x:0, y:0},
|
32196 | mass:0,
|
32197 | range: {
|
32198 | minX: centerX-halfRootSize,maxX:centerX+halfRootSize,
|
32199 | minY: centerY-halfRootSize,maxY:centerY+halfRootSize
|
32200 | },
|
32201 | size: rootSize,
|
32202 | calcSize: 1 / rootSize,
|
32203 | children: { data:null},
|
32204 | maxWidth: 0,
|
32205 | level: 0,
|
32206 | childrenCount: 4
|
32207 | }
|
32208 | };
|
32209 | this._splitBranch(barnesHutTree.root);
|
32210 |
|
32211 |
|
32212 | for (i = 0; i < nodeCount; i++) {
|
32213 | node = nodes[nodeIndices[i]];
|
32214 | if (node.options.mass > 0) {
|
32215 | this._placeInTree(barnesHutTree.root,node);
|
32216 | }
|
32217 | }
|
32218 |
|
32219 |
|
32220 | this.barnesHutTree = barnesHutTree
|
32221 | };
|
32222 |
|
32223 |
|
32224 | |
32225 |
|
32226 |
|
32227 |
|
32228 |
|
32229 |
|
32230 |
|
32231 | exports._updateBranchMass = function(parentBranch, node) {
|
32232 | var totalMass = parentBranch.mass + node.options.mass;
|
32233 | var totalMassInv = 1/totalMass;
|
32234 |
|
32235 | parentBranch.centerOfMass.x = parentBranch.centerOfMass.x * parentBranch.mass + node.x * node.options.mass;
|
32236 | parentBranch.centerOfMass.x *= totalMassInv;
|
32237 |
|
32238 | parentBranch.centerOfMass.y = parentBranch.centerOfMass.y * parentBranch.mass + node.y * node.options.mass;
|
32239 | parentBranch.centerOfMass.y *= totalMassInv;
|
32240 |
|
32241 | parentBranch.mass = totalMass;
|
32242 | var biggestSize = Math.max(Math.max(node.height,node.radius),node.width);
|
32243 | parentBranch.maxWidth = (parentBranch.maxWidth < biggestSize) ? biggestSize : parentBranch.maxWidth;
|
32244 |
|
32245 | };
|
32246 |
|
32247 |
|
32248 | |
32249 |
|
32250 |
|
32251 |
|
32252 |
|
32253 |
|
32254 |
|
32255 |
|
32256 | exports._placeInTree = function(parentBranch,node,skipMassUpdate) {
|
32257 | if (skipMassUpdate != true || skipMassUpdate === undefined) {
|
32258 |
|
32259 | this._updateBranchMass(parentBranch,node);
|
32260 | }
|
32261 |
|
32262 | if (parentBranch.children.NW.range.maxX > node.x) {
|
32263 | if (parentBranch.children.NW.range.maxY > node.y) {
|
32264 | this._placeInRegion(parentBranch,node,"NW");
|
32265 | }
|
32266 | else {
|
32267 | this._placeInRegion(parentBranch,node,"SW");
|
32268 | }
|
32269 | }
|
32270 | else {
|
32271 | if (parentBranch.children.NW.range.maxY > node.y) {
|
32272 | this._placeInRegion(parentBranch,node,"NE");
|
32273 | }
|
32274 | else {
|
32275 | this._placeInRegion(parentBranch,node,"SE");
|
32276 | }
|
32277 | }
|
32278 | };
|
32279 |
|
32280 |
|
32281 | |
32282 |
|
32283 |
|
32284 |
|
32285 |
|
32286 |
|
32287 |
|
32288 |
|
32289 | exports._placeInRegion = function(parentBranch,node,region) {
|
32290 | switch (parentBranch.children[region].childrenCount) {
|
32291 | case 0:
|
32292 | parentBranch.children[region].children.data = node;
|
32293 | parentBranch.children[region].childrenCount = 1;
|
32294 | this._updateBranchMass(parentBranch.children[region],node);
|
32295 | break;
|
32296 | case 1:
|
32297 |
|
32298 |
|
32299 | if (parentBranch.children[region].children.data.x == node.x &&
|
32300 | parentBranch.children[region].children.data.y == node.y) {
|
32301 | node.x += Math.random();
|
32302 | node.y += Math.random();
|
32303 | }
|
32304 | else {
|
32305 | this._splitBranch(parentBranch.children[region]);
|
32306 | this._placeInTree(parentBranch.children[region],node);
|
32307 | }
|
32308 | break;
|
32309 | case 4:
|
32310 | this._placeInTree(parentBranch.children[region],node);
|
32311 | break;
|
32312 | }
|
32313 | };
|
32314 |
|
32315 |
|
32316 | |
32317 |
|
32318 |
|
32319 |
|
32320 |
|
32321 |
|
32322 |
|
32323 | exports._splitBranch = function(parentBranch) {
|
32324 |
|
32325 | var containedNode = null;
|
32326 | if (parentBranch.childrenCount == 1) {
|
32327 | containedNode = parentBranch.children.data;
|
32328 | parentBranch.mass = 0; parentBranch.centerOfMass.x = 0; parentBranch.centerOfMass.y = 0;
|
32329 | }
|
32330 | parentBranch.childrenCount = 4;
|
32331 | parentBranch.children.data = null;
|
32332 | this._insertRegion(parentBranch,"NW");
|
32333 | this._insertRegion(parentBranch,"NE");
|
32334 | this._insertRegion(parentBranch,"SW");
|
32335 | this._insertRegion(parentBranch,"SE");
|
32336 |
|
32337 | if (containedNode != null) {
|
32338 | this._placeInTree(parentBranch,containedNode);
|
32339 | }
|
32340 | };
|
32341 |
|
32342 |
|
32343 | |
32344 |
|
32345 |
|
32346 |
|
32347 |
|
32348 |
|
32349 |
|
32350 |
|
32351 |
|
32352 |
|
32353 | exports._insertRegion = function(parentBranch, region) {
|
32354 | var minX,maxX,minY,maxY;
|
32355 | var childSize = 0.5 * parentBranch.size;
|
32356 | switch (region) {
|
32357 | case "NW":
|
32358 | minX = parentBranch.range.minX;
|
32359 | maxX = parentBranch.range.minX + childSize;
|
32360 | minY = parentBranch.range.minY;
|
32361 | maxY = parentBranch.range.minY + childSize;
|
32362 | break;
|
32363 | case "NE":
|
32364 | minX = parentBranch.range.minX + childSize;
|
32365 | maxX = parentBranch.range.maxX;
|
32366 | minY = parentBranch.range.minY;
|
32367 | maxY = parentBranch.range.minY + childSize;
|
32368 | break;
|
32369 | case "SW":
|
32370 | minX = parentBranch.range.minX;
|
32371 | maxX = parentBranch.range.minX + childSize;
|
32372 | minY = parentBranch.range.minY + childSize;
|
32373 | maxY = parentBranch.range.maxY;
|
32374 | break;
|
32375 | case "SE":
|
32376 | minX = parentBranch.range.minX + childSize;
|
32377 | maxX = parentBranch.range.maxX;
|
32378 | minY = parentBranch.range.minY + childSize;
|
32379 | maxY = parentBranch.range.maxY;
|
32380 | break;
|
32381 | }
|
32382 |
|
32383 |
|
32384 | parentBranch.children[region] = {
|
32385 | centerOfMass:{x:0,y:0},
|
32386 | mass:0,
|
32387 | range:{minX:minX,maxX:maxX,minY:minY,maxY:maxY},
|
32388 | size: 0.5 * parentBranch.size,
|
32389 | calcSize: 2 * parentBranch.calcSize,
|
32390 | children: {data:null},
|
32391 | maxWidth: 0,
|
32392 | level: parentBranch.level+1,
|
32393 | childrenCount: 0
|
32394 | };
|
32395 | };
|
32396 |
|
32397 |
|
32398 | |
32399 |
|
32400 |
|
32401 |
|
32402 |
|
32403 |
|
32404 |
|
32405 | exports._drawTree = function(ctx,color) {
|
32406 | if (this.barnesHutTree !== undefined) {
|
32407 |
|
32408 | ctx.lineWidth = 1;
|
32409 |
|
32410 | this._drawBranch(this.barnesHutTree.root,ctx,color);
|
32411 | }
|
32412 | };
|
32413 |
|
32414 |
|
32415 | |
32416 |
|
32417 |
|
32418 |
|
32419 |
|
32420 |
|
32421 |
|
32422 |
|
32423 | exports._drawBranch = function(branch,ctx,color) {
|
32424 | if (color === undefined) {
|
32425 | color = "#FF0000";
|
32426 | }
|
32427 |
|
32428 | if (branch.childrenCount == 4) {
|
32429 | this._drawBranch(branch.children.NW,ctx);
|
32430 | this._drawBranch(branch.children.NE,ctx);
|
32431 | this._drawBranch(branch.children.SE,ctx);
|
32432 | this._drawBranch(branch.children.SW,ctx);
|
32433 | }
|
32434 | ctx.strokeStyle = color;
|
32435 | ctx.beginPath();
|
32436 | ctx.moveTo(branch.range.minX,branch.range.minY);
|
32437 | ctx.lineTo(branch.range.maxX,branch.range.minY);
|
32438 | ctx.stroke();
|
32439 |
|
32440 | ctx.beginPath();
|
32441 | ctx.moveTo(branch.range.maxX,branch.range.minY);
|
32442 | ctx.lineTo(branch.range.maxX,branch.range.maxY);
|
32443 | ctx.stroke();
|
32444 |
|
32445 | ctx.beginPath();
|
32446 | ctx.moveTo(branch.range.maxX,branch.range.maxY);
|
32447 | ctx.lineTo(branch.range.minX,branch.range.maxY);
|
32448 | ctx.stroke();
|
32449 |
|
32450 | ctx.beginPath();
|
32451 | ctx.moveTo(branch.range.minX,branch.range.maxY);
|
32452 | ctx.lineTo(branch.range.minX,branch.range.minY);
|
32453 | ctx.stroke();
|
32454 |
|
32455 | |
32456 |
|
32457 |
|
32458 |
|
32459 |
|
32460 |
|
32461 | };
|
32462 |
|
32463 |
|
32464 | },
|
32465 |
|
32466 | function(module, exports, __webpack_require__) {
|
32467 |
|
32468 | module.exports = function(module) {
|
32469 | if(!module.webpackPolyfill) {
|
32470 | module.deprecate = function() {};
|
32471 | module.paths = [];
|
32472 |
|
32473 | module.children = [];
|
32474 | module.webpackPolyfill = 1;
|
32475 | }
|
32476 | return module;
|
32477 | }
|
32478 |
|
32479 |
|
32480 | }
|
32481 | ])
|
32482 | });
|