gridviz 2.0.33 → 2.0.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/gridviz.js +49 -26
- package/dist/gridviz.min.js +1 -1
- package/package.json +2 -2
- package/src/App.js +9 -2
- package/src/Tooltip.js +39 -23
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gridviz",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.35",
|
|
4
4
|
"description": "Visualization tool for gridded statistics",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"statistics",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"start-dev": "webpack --config webpack.config.dev.cjs",
|
|
40
40
|
"server": "webpack serve -c webpack.config.dev.js --static ./",
|
|
41
41
|
"doc": "./node_modules/.bin/jsdoc src/ src/dataset src/legend src/style -d docs/jsdoc",
|
|
42
|
-
"build": "webpack --config webpack.config.prod.cjs",
|
|
42
|
+
"build-prod": "webpack --config webpack.config.prod.cjs",
|
|
43
43
|
"test": "jest"
|
|
44
44
|
},
|
|
45
45
|
"files": [
|
package/src/App.js
CHANGED
|
@@ -186,7 +186,7 @@ export class App {
|
|
|
186
186
|
this.legendDivId = opts.legendDivId || 'gvizLegend'
|
|
187
187
|
this.legend = select('#' + this.legendDivId)
|
|
188
188
|
if (this.legend.empty()) {
|
|
189
|
-
this.legend = select('
|
|
189
|
+
this.legend = select('#' + container.id)
|
|
190
190
|
.append('div')
|
|
191
191
|
.attr('id', this.legendDivId)
|
|
192
192
|
.style('position', 'absolute')
|
|
@@ -206,6 +206,10 @@ export class App {
|
|
|
206
206
|
|
|
207
207
|
//tooltip
|
|
208
208
|
|
|
209
|
+
// set App container as default parent element for tooltip
|
|
210
|
+
if (!opts.tooltip) opts.tooltip = {}
|
|
211
|
+
if (!opts.tooltip.parentElement) opts.tooltip.parentElement = container
|
|
212
|
+
|
|
209
213
|
/**
|
|
210
214
|
* @private
|
|
211
215
|
* @type {Tooltip} */
|
|
@@ -283,7 +287,10 @@ export class App {
|
|
|
283
287
|
container.addEventListener('mouseout', () => {
|
|
284
288
|
this.tooltip.hide()
|
|
285
289
|
})
|
|
286
|
-
|
|
290
|
+
|
|
291
|
+
// add extra logic to onZoomStartFun
|
|
292
|
+
this.cg.onZoomStartFun = (e) => {
|
|
293
|
+
if (opts.onZoomStartFun) opts.onZoomStartFun(e)
|
|
287
294
|
this.tooltip.hide()
|
|
288
295
|
}
|
|
289
296
|
|
package/src/Tooltip.js
CHANGED
|
@@ -44,12 +44,17 @@ export class Tooltip {
|
|
|
44
44
|
this.yMouseOffset = opts.yMouseOffset || 0
|
|
45
45
|
/** @type {number} */
|
|
46
46
|
this.xMouseOffset = opts.xMouseOffset || 0
|
|
47
|
+
/** @type {HTMLElement} */
|
|
48
|
+
this.parentElement = opts.parentElement || document.body
|
|
47
49
|
|
|
48
50
|
/**
|
|
49
51
|
* @private
|
|
50
52
|
* @type {import("d3-selection").Selection} */
|
|
51
53
|
this.tooltip = select('#' + this.div)
|
|
52
|
-
if (this.tooltip.empty())
|
|
54
|
+
if (this.tooltip.empty())
|
|
55
|
+
this.tooltip = select('#' + this.parentElement.id)
|
|
56
|
+
.append('div')
|
|
57
|
+
.attr('id', this.div)
|
|
53
58
|
|
|
54
59
|
//initialise
|
|
55
60
|
this.tooltip.style('max-width', this.maxWidth)
|
|
@@ -64,6 +69,9 @@ export class Tooltip {
|
|
|
64
69
|
this.tooltip.style('position', 'absolute')
|
|
65
70
|
this.tooltip.style('pointer-events', 'none')
|
|
66
71
|
this.tooltip.style('opacity', '0')
|
|
72
|
+
|
|
73
|
+
// aria-labels (thanks to wahlatlas)
|
|
74
|
+
this.tooltip.attr('role', 'tooltip').attr('aria-live', 'polite')
|
|
67
75
|
}
|
|
68
76
|
|
|
69
77
|
/** Show the tooltip */
|
|
@@ -94,6 +102,8 @@ export class Tooltip {
|
|
|
94
102
|
this.tooltip
|
|
95
103
|
.style('left', event.pageX + this.xOffset + 'px')
|
|
96
104
|
.style('top', event.pageY - this.yOffset + 'px')
|
|
105
|
+
|
|
106
|
+
this.ensureTooltipInsideContainer(event)
|
|
97
107
|
}
|
|
98
108
|
|
|
99
109
|
/*
|
|
@@ -101,12 +111,12 @@ export class Tooltip {
|
|
|
101
111
|
if (html) my.html(html);
|
|
102
112
|
my.setPosition(event);
|
|
103
113
|
my.show()
|
|
104
|
-
//this.
|
|
114
|
+
//this.ensureTooltipInsideContainer();
|
|
105
115
|
};
|
|
106
116
|
|
|
107
117
|
my.mousemove = function (event) {
|
|
108
118
|
my.setPosition(event);
|
|
109
|
-
//this.
|
|
119
|
+
//this.ensureTooltipInsideContainer();
|
|
110
120
|
};
|
|
111
121
|
|
|
112
122
|
my.mouseout = function () {
|
|
@@ -126,25 +136,31 @@ export class Tooltip {
|
|
|
126
136
|
}
|
|
127
137
|
|
|
128
138
|
/**
|
|
129
|
-
* @function
|
|
130
|
-
* @description Prevents the tooltip from overflowing
|
|
139
|
+
* @function ensureTooltipInsideContainer
|
|
140
|
+
* @description Prevents the tooltip from overflowing out of the App container (ensures that the tooltip is inside the gridviz container)
|
|
141
|
+
* @param {MouseEvent} event
|
|
131
142
|
*/
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
143
|
+
ensureTooltipInsideContainer = function (event) {
|
|
144
|
+
let node = this.tooltip.node()
|
|
145
|
+
let rect = this.parentElement.getBoundingClientRect()
|
|
146
|
+
let parentWidth = rect.width
|
|
147
|
+
let parentHeight = rect.height
|
|
148
|
+
|
|
149
|
+
//too far right
|
|
150
|
+
if (node.offsetLeft > rect.left + parentWidth - node.clientWidth) {
|
|
151
|
+
let left = event.x - node.clientWidth - this.xOffset
|
|
152
|
+
node.style.left = left + 'px'
|
|
153
|
+
// check if mouse covers tooltip
|
|
154
|
+
if (node.offsetLeft + node.clientWidth > event.x) {
|
|
155
|
+
//move tooltip left so it doesnt cover mouse
|
|
156
|
+
let left2 = event.x - (node.clientWidth + this.xOffset)
|
|
157
|
+
node.style.left = left2 + 'px'
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
//too far down
|
|
162
|
+
if (node.offsetTop + node.clientHeight > rect.top + parentHeight) {
|
|
163
|
+
node.style.top = node.offsetTop - node.clientHeight + 'px'
|
|
164
|
+
}
|
|
165
|
+
}
|
|
150
166
|
}
|