|
| 1 | +require.config({ |
| 2 | + paths: { |
| 3 | + angular: 'node_modules/angular/angular', |
| 4 | + 'angular-visjs': 'angular-vis', |
| 5 | + vis: 'node_modules/vis/dist/vis', |
| 6 | + moment: 'node_modules/moment/moment' |
| 7 | + }, |
| 8 | + shim: { |
| 9 | + angular: {exports: 'angular'} |
| 10 | + } |
| 11 | +}); |
| 12 | + |
| 13 | +require(['angular', 'angular-visjs', 'moment'], (angular, ngVis, moment) => { |
| 14 | + |
| 15 | +'use strict'; |
| 16 | + |
| 17 | + |
| 18 | +var ngVisApp = angular.module('ngVisApp', [ngVis]); |
| 19 | + |
| 20 | +ngVisApp.controller('appController', function ($scope, $location, $timeout, VisDataSet) { |
| 21 | + |
| 22 | + $scope.logs = {}; |
| 23 | + |
| 24 | + $scope.defaults = { |
| 25 | + orientation: ['top', 'bottom'], |
| 26 | + autoResize: [true, false], |
| 27 | + showCurrentTime: [true, false], |
| 28 | + // showCustomTime: [true, false], |
| 29 | + showMajorLabels: [true, false], |
| 30 | + showMinorLabels: [true, false], |
| 31 | + align: ['left', 'center', 'right'], |
| 32 | + stack: [true, false], |
| 33 | + |
| 34 | + moveable: [true, false], |
| 35 | + zoomable: [true, false], |
| 36 | + selectable: [true, false], |
| 37 | + editable: [true, false] |
| 38 | + }; |
| 39 | + |
| 40 | + var options = { |
| 41 | + align: 'center', // left | right (String) |
| 42 | + autoResize: true, // false (Boolean) |
| 43 | + editable: true, |
| 44 | + selectable: true, |
| 45 | + // start: null, |
| 46 | + // end: null, |
| 47 | + // height: null, |
| 48 | + // width: '100%', |
| 49 | + // margin: { |
| 50 | + // axis: 20, |
| 51 | + // item: 10 |
| 52 | + // }, |
| 53 | + // min: null, |
| 54 | + // max: null, |
| 55 | + // maxHeight: null, |
| 56 | + orientation: 'bottom', |
| 57 | + // padding: 5, |
| 58 | + showCurrentTime: true, |
| 59 | + // showCustomTime: true, |
| 60 | + showMajorLabels: true, |
| 61 | + showMinorLabels: true |
| 62 | + // type: 'box', // dot | point |
| 63 | + // zoomMin: 1000, |
| 64 | + // zoomMax: 1000 * 60 * 60 * 24 * 30 * 12 * 10, |
| 65 | + // groupOrder: 'content' |
| 66 | + }; |
| 67 | + |
| 68 | + var now = moment().minutes(0).seconds(0).milliseconds(0); |
| 69 | + |
| 70 | + var sampleData = function () { |
| 71 | + return VisDataSet([ |
| 72 | + { |
| 73 | + id: 1, |
| 74 | + content: '<i class="fi-flag"></i> item 1', |
| 75 | + start: moment().add('days', 1), |
| 76 | + className: 'magenta' |
| 77 | + }, |
| 78 | + { |
| 79 | + id: 2, |
| 80 | + content: '<a href="http://visjs.org" target="_blank">visjs.org</a>', |
| 81 | + start: moment().add('days', 2) |
| 82 | + }, |
| 83 | + { |
| 84 | + id: 3, |
| 85 | + content: 'item 3', |
| 86 | + start: moment().add('days', -2) |
| 87 | + }, |
| 88 | + { |
| 89 | + id: 4, |
| 90 | + content: 'item 4', |
| 91 | + start: moment().add('days', 1), |
| 92 | + end: moment().add('days', 3), |
| 93 | + type: 'range' |
| 94 | + }, |
| 95 | + { |
| 96 | + id: 7, |
| 97 | + content: '<i class="fi-anchor"></i> item 7', |
| 98 | + start: moment().add('days', -3), |
| 99 | + end: moment().add('days', -2), |
| 100 | + type: 'range', |
| 101 | + className: 'orange' |
| 102 | + }, |
| 103 | + { |
| 104 | + id: 5, |
| 105 | + content: 'item 5', |
| 106 | + start: moment().add('days', -1), |
| 107 | + type: 'point' |
| 108 | + }, |
| 109 | + { |
| 110 | + id: 6, |
| 111 | + content: 'item 6', |
| 112 | + start: moment().add('days', 4), |
| 113 | + type: 'point' |
| 114 | + } |
| 115 | + ]); |
| 116 | + }; |
| 117 | + |
| 118 | + var groups = VisDataSet([ |
| 119 | + {id: 0, content: 'First', value: 1}, |
| 120 | + {id: 1, content: 'Third', value: 3}, |
| 121 | + {id: 2, content: 'Second', value: 2} |
| 122 | + ]); |
| 123 | + var items = VisDataSet([ |
| 124 | + {id: 0, group: 0, content: 'item 0', start: new Date(2014, 3, 17), end: new Date(2014, 3, 21)}, |
| 125 | + {id: 1, group: 0, content: 'item 1', start: new Date(2014, 3, 19), end: new Date(2014, 3, 20)}, |
| 126 | + {id: 2, group: 1, content: 'item 2', start: new Date(2014, 3, 16), end: new Date(2014, 3, 24)}, |
| 127 | + {id: 3, group: 1, content: 'item 3', start: new Date(2014, 3, 23), end: new Date(2014, 3, 24)}, |
| 128 | + {id: 4, group: 1, content: 'item 4', start: new Date(2014, 3, 22), end: new Date(2014, 3, 26)}, |
| 129 | + {id: 5, group: 2, content: 'item 5', start: new Date(2014, 3, 24), end: new Date(2014, 3, 27)} |
| 130 | + ]); |
| 131 | + |
| 132 | + $scope.data = {groups: groups, items: items}; |
| 133 | + var orderedContent = 'content'; |
| 134 | + var orderedSorting = function (a, b) { |
| 135 | + // option groupOrder can be a property name or a sort function |
| 136 | + // the sort function must compare two groups and return a value |
| 137 | + // > 0 when a > b |
| 138 | + // < 0 when a < b |
| 139 | + // 0 when a == b |
| 140 | + return a.value - b.value; |
| 141 | + }; |
| 142 | + |
| 143 | + $scope.options = angular.extend(options, { |
| 144 | + groupOrder: orderedContent, |
| 145 | + editable: true |
| 146 | + }); |
| 147 | + |
| 148 | + $scope.onSelect = function (items) { |
| 149 | + // debugger; |
| 150 | + alert('select'); |
| 151 | + }; |
| 152 | + |
| 153 | + $scope.onClick = function (props) { |
| 154 | + //debugger; |
| 155 | + alert('Click'); |
| 156 | + }; |
| 157 | + |
| 158 | + $scope.onDoubleClick = function (props) { |
| 159 | + // debugger; |
| 160 | + alert('DoubleClick'); |
| 161 | + }; |
| 162 | + |
| 163 | + $scope.rightClick = function (props) { |
| 164 | + alert('Right click!'); |
| 165 | + props.event.preventDefault(); |
| 166 | + }; |
| 167 | + |
| 168 | + $scope.events = { |
| 169 | + // rangechange: $scope.onRangeChange, |
| 170 | + // rangechanged: $scope.onRangeChanged, |
| 171 | + onload: $scope.onLoaded, |
| 172 | + select: $scope.onSelect, |
| 173 | + click: $scope.onClick, |
| 174 | + doubleClick: $scope.onDoubleClick, |
| 175 | + contextmenu: $scope.rightClick |
| 176 | + }; |
| 177 | + |
| 178 | +}); |
| 179 | + |
| 180 | +angular.bootstrap(document, [ngVisApp.name]); |
| 181 | + |
| 182 | +}); |
0 commit comments