OWL ITS + 탐지시스템(인터넷 진흥원)
이민희
2022-01-13 4545664bbece1b1b185945376b344b1660669a53
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
(function(root, factory) {
    if (typeof module === 'object' && module.exports) {
        var d3 = require('d3');
        module.exports = factory(d3);
    } else if(typeof define === 'function' && define.amd) {
        try {
            var d3 = require('d3');
        } catch (e) {
            d3 = root.d3;
        }
 
        d3.contextMenu = factory(d3);
        define([], function() {
            return d3.contextMenu;
        });
    } else if(root.d3) {
        root.d3.contextMenu = factory(root.d3);
    }
}(this,
    function (d3) {
        var utils = {
            noop: function () {},
            
            /**
             * @param {*} value
             * @returns {Boolean}
             */
            isFn: function (value) {
                return typeof value === 'function';
            },
 
            /**
             * @param {*} value
             * @returns {Function}
             */
            const: function (value) {
                return function () { return value; };
            },
 
            /**
             * @param {Function|*} value
             * @param {*} [fallback]
             * @returns {Function}
             */
            toFactory: function (value, fallback) {
                value = (value === undefined) ? fallback : value;
                return utils.isFn(value) ? value : utils.const(value);
            }
        };
 
        // global state for d3-context-menu
        var d3ContextMenu = null;
 
        var closeMenu = function () {
            // global state is populated if a menu is currently opened
            if (d3ContextMenu) {
                d3.select('.d3-context-menu').remove();
                d3.select('body').on('mousedown.d3-context-menu', null);
                d3ContextMenu.boundCloseCallback();
                d3ContextMenu = null;
            }
        };
 
        /**
         * Calls API method (e.g. `close`) or
         * returns handler function for the `contextmenu` event
         * @param {Function|Array|String} menuItems
         * @param {Function|Object} config
         * @returns {?Function}
         */
        return function (menuItems, config) {
            // allow for `d3.contextMenu('close');` calls
            // to programatically close the menu
            if (menuItems === 'close') {
                return closeMenu();
            }
 
            // for convenience, make `menuItems` a factory
            // and `config` an object
            menuItems = utils.toFactory(menuItems);
 
            if (utils.isFn(config)) {
                config = { onOpen: config };
            }
            else {
                config = config || {};
            }
 
            // resolve config
            var openCallback = config.onOpen || utils.noop;
            var closeCallback = config.onClose || utils.noop;
            var positionFactory = utils.toFactory(config.position);
            var themeFactory = utils.toFactory(config.theme, 'd3-context-menu-theme');
 
            /**
             * Context menu event handler
             * @param {*} data
             * @param {Number} index
             */
            return function (data, index) {
                var element = this;
 
                // close any menu that's already opened
                closeMenu();
 
                // store close callback already bound to the correct args and scope
                d3ContextMenu = {
                    boundCloseCallback: closeCallback.bind(element, data, index)
                };
 
                // create the div element that will hold the context menu
                d3.selectAll('.d3-context-menu').data([1])
                    .enter()
                    .append('div')
                    .attr('class', 'd3-context-menu ' + themeFactory.bind(element)(data, index));
 
                // close menu on mousedown outside
                d3.select('body').on('mousedown.d3-context-menu', closeMenu);
 
                var list = d3.selectAll('.d3-context-menu')
                    .on('contextmenu', function() {
                        closeMenu();
                        d3.event.preventDefault();
                        d3.event.stopPropagation();
                    })
                    .append('ul');
                
                list.selectAll('li').data(menuItems.bind(element)(data, index)).enter()
                    .append('li')
                    .attr('class', function(d) {
                        var ret = '';
                        if (utils.toFactory(d.divider).bind(element)(data, index)) {
                            ret += ' is-divider';
                        }
                        if (utils.toFactory(d.disabled).bind(element)(data, index)) {
                            ret += ' is-disabled';
                        }
                        if (!d.action) {
                            ret += ' is-header';
                        }
                        return ret;
                    })
                    .html(function(d) {
                        if (utils.toFactory(d.divider).bind(element)(data, index)) {
                            return '<hr>';
                        }
                        if (!d.title) {
                            console.error('No title attribute set. Check the spelling of your options.');
                        }
                        return utils.toFactory(d.title).bind(element)(data, index);
                    })
                    .on('click', function(d, i) {
                        if (utils.toFactory(d.disabled).bind(element)(data, index)) return; // do nothing if disabled
                        if (!d.action) return; // headers have no "action"
                        d.action.bind(element)(data, index);
                        closeMenu();
                    });
 
                // the openCallback allows an action to fire before the menu is displayed
                // an example usage would be closing a tooltip
                if (openCallback.bind(element)(data, index) === false) {
                    return;
                }
 
                // get position
                var position = positionFactory.bind(element)(data, index);
 
                // display context menu
                d3.select('.d3-context-menu')
                    .style('left', (position ? position.left : d3.event.pageX - 2) + 'px')
                    .style('top', (position ? position.top : d3.event.pageY - 2) + 'px')
                    .style('display', 'block');
 
                d3.event.preventDefault();
                d3.event.stopPropagation();
            };
        };
    }
));