-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathd3scription.js
More file actions
142 lines (125 loc) · 5.22 KB
/
d3scription.js
File metadata and controls
142 lines (125 loc) · 5.22 KB
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
var d3scription = d3scription || {}; d3scription["d3scription"] =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(1);
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/// <reference path="d/d3.d.ts" />
!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__, exports], __WEBPACK_AMD_DEFINE_RESULT__ = function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var windowDimensions = {
width: window.innerWidth,
height: window.innerHeight
};
function setWindowDimmensions() {
windowDimensions = {
width: window.innerWidth,
height: window.innerHeight
};
}
var windowResize = window.addEventListener('resize', setWindowDimmensions);
function getOffset(event, bounds, offset) {
var collideVertically = (windowDimensions.height + window.scrollY) - event.pageY - offset.top - bounds.height < 0;
var collideHorizontally = (windowDimensions.width + window.scrollX) - event.pageX - offset.left - bounds.width < 0;
return {
top: collideVertically ? event.pageY - bounds.height - offset.top : offset.top + event.pageY,
left: collideHorizontally ? event.pageX - bounds.width - offset.left : event.pageX + offset.left
};
}
var defaultOffset = { top: 10, left: 10 };
function getOffsetSettings(offset) {
if (!offset)
return defaultOffset;
return {
top: offset.top === undefined ? defaultOffset.top : offset.top,
left: offset.left === undefined ? defaultOffset.left : offset.left
};
}
function d3scription(contentGetter, options) {
if (options === void 0) { options = {}; }
var offsetSettings = getOffsetSettings(options.offset);
return function () {
var tip = d3.select('body')
.append('div')
.attr('class', options.class || 'd3scription-tip')
.style('position', 'absolute')
.style('z-index', options.zIndex || 100)
.style('visibility', 'hidden');
function updateTipPosition() {
var bounds = tip.node().getBoundingClientRect();
var position = getOffset(d3.event, bounds, offsetSettings);
tip
.style("top", position.top + "px")
.style("left", position.left + "px");
}
function setupTracking(element) {
element.on('mousemove', updateTipPosition);
}
var publicMethods = {
element: function (element) {
setupTracking(element);
return publicMethods;
},
show: function (data) {
updateTipPosition();
tip.html(contentGetter(data));
tip.style('visibility', 'visible');
return publicMethods;
},
update: function (data) {
tip.html(contentGetter(data));
return publicMethods;
},
hide: function () {
tip.style('visibility', 'hidden');
return publicMethods;
},
remove: function () {
tip.remove();
}
};
return publicMethods;
};
}
exports.default = d3scription;
// export as Global Object
if (typeof window === 'object') {
window['d3scription'] = d3scription;
}
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
/***/ })
/******/ ]);