Skip to content

Commit d7abd18

Browse files
committed
more fx constants
1 parent 2a970fc commit d7abd18

File tree

2 files changed

+52
-39
lines changed

2 files changed

+52
-39
lines changed

src/plots/cartesian/constants.js

+24-9
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,31 @@
88

99

1010
module.exports = {
11-
// ms between first mousedown and 2nd mouseup to constitute dblclick...
12-
// we don't seem to have access to the system setting
13-
DBLCLICKDELAY: 600,
11+
// ms between first mousedown and 2nd mouseup to constitute dblclick...
12+
// we don't seem to have access to the system setting
13+
DBLCLICKDELAY: 600,
1414

15-
// pixels to move mouse before you stop clamping to starting point
16-
MINDRAG: 8,
15+
// pixels to move mouse before you stop clamping to starting point
16+
MINDRAG: 8,
1717

18-
// smallest dimension allowed for a zoombox
19-
MINZOOM: 20,
18+
// smallest dimension allowed for a zoombox
19+
MINZOOM: 20,
2020

21-
// width of axis drag regions
22-
DRAGGERSIZE: 20
21+
// width of axis drag regions
22+
DRAGGERSIZE: 20,
23+
24+
// max pixels away from mouse to allow a point to highlight
25+
MAXDIST: 20,
26+
27+
// hover labels for multiple horizontal bars get tilted by this angle
28+
YANGLE: 60,
29+
30+
// size and display constants for hover text
31+
HOVERARROWSIZE: 6, // pixel size of hover arrows
32+
HOVERTEXTPAD: 3, // pixels padding around text
33+
HOVERFONTSIZE: 13,
34+
HOVERFONT: 'Arial, sans-serif',
35+
36+
// minimum time (msec) between hover calls
37+
HOVERMINTIME: 100
2338
};

src/plots/cartesian/graph_interact.js

+28-30
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ fx.init = function(gd) {
195195

196196
// hover labels for multiple horizontal bars get tilted by some angle,
197197
// then need to be offset differently if they overlap
198-
var YANGLE = 60,
198+
var YANGLE = constants.YANGLE,
199199
YA_RADIANS = Math.PI*YANGLE/180,
200200

201201
// expansion of projected height
@@ -228,13 +228,10 @@ function quadrature(dx, dy) {
228228
}
229229

230230
// size and display constants for hover text
231-
var HOVERARROWSIZE = 6, // pixel size of hover arrows
232-
HOVERTEXTPAD = 3, // pixels padding around text
233-
HOVERFONTSIZE = 13,
234-
HOVERFONT = 'Arial, sans-serif';
235-
236-
// max pixels away from mouse to allow a point to highlight
237-
fx.MAXDIST = 20;
231+
var HOVERARROWSIZE = constants.HOVERARROWSIZE,
232+
HOVERTEXTPAD = constants.HOVERTEXTPAD,
233+
HOVERFONTSIZE = constants.HOVERFONTSIZE,
234+
HOVERFONT = constants.HOVERFONT;
238235

239236
// fx.hover: highlight data on hover
240237
// evt can be a mousemove event, or an object with data about what points
@@ -262,8 +259,6 @@ fx.MAXDIST = 20;
262259
// The actual rendering is done by private functions
263260
// hover() and unhover().
264261

265-
var HOVERMINTIME = 100; // minimum time between hover calls
266-
267262
fx.hover = function (gd, evt, subplot) {
268263
if(typeof gd === 'string') gd = document.getElementById(gd);
269264
if(gd._lastHoverTime === undefined) gd._lastHoverTime = 0;
@@ -275,7 +270,7 @@ fx.hover = function (gd, evt, subplot) {
275270
}
276271
// Is it more than 100ms since the last update? If so, force
277272
// an update now (synchronously) and exit
278-
if (Date.now() > gd._lastHoverTime + HOVERMINTIME) {
273+
if (Date.now() > gd._lastHoverTime + constants.HOVERMINTIME) {
279274
hover(gd,evt,subplot);
280275
gd._lastHoverTime = Date.now();
281276
return;
@@ -285,7 +280,7 @@ fx.hover = function (gd, evt, subplot) {
285280
hover(gd,evt,subplot);
286281
gd._lastHoverTime = Date.now();
287282
gd._hoverTimer = undefined;
288-
}, HOVERMINTIME);
283+
}, constants.HOVERMINTIME);
289284
};
290285

291286
fx.unhover = function (gd, evt, subplot) {
@@ -442,7 +437,7 @@ function hover(gd, evt, subplot){
442437
name: (gd.data.length>1 || trace.hoverinfo.indexOf('name')!==-1) ? trace.name : undefined,
443438
// point properties - override all of these
444439
index: false, // point index in trace - only used by plotly.js hoverdata consumers
445-
distance: Math.min(distance, fx.MAXDIST), // pixel distance or pseudo-distance
440+
distance: Math.min(distance, constants.MAXDIST), // pixel distance or pseudo-distance
446441
color: Plotly.Color.defaultLine, // trace color
447442
x0: undefined,
448443
x1: undefined,
@@ -762,7 +757,7 @@ function createHoverText(hoverData, opts) {
762757
// show the common label, if any, on the axis
763758
// never show a common label in array mode,
764759
// even if sometimes there could be one
765-
var showCommonLabel = c0.distance<=fx.MAXDIST &&
760+
var showCommonLabel = c0.distance<=constants.MAXDIST &&
766761
(hovermode==='x' || hovermode==='y');
767762

768763
// all hover traces hoverinfo must contain the hovermode
@@ -1312,6 +1307,8 @@ function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
13121307
ya = [plotinfo.y()],
13131308
pw = xa[0]._length,
13141309
ph = ya[0]._length,
1310+
MINDRAG = constants.MINDRAG,
1311+
MINZOOM = constants.MINZOOM,
13151312
i,
13161313
subplotXa,
13171314
subplotYa;
@@ -1449,7 +1446,7 @@ function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
14491446
y1 = Math.max(0, Math.min(ph, dy0 + y0)),
14501447
dx = Math.abs(x1 - x0),
14511448
dy = Math.abs(y1 - y0),
1452-
clen = Math.floor(Math.min(dy, dx, constants.MINZOOM) / 2);
1449+
clen = Math.floor(Math.min(dy, dx, MINZOOM) / 2);
14531450

14541451
box.l = Math.min(x0, x1);
14551452
box.r = Math.max(x0, x1);
@@ -1458,8 +1455,8 @@ function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
14581455

14591456
// look for small drags in one direction or the other,
14601457
// and only drag the other axis
1461-
if(!yActive || dy < Math.min(Math.max(dx * 0.6, constants.MINDRAG), constants.MINZOOM)) {
1462-
if(dx < constants.MINDRAG) {
1458+
if(!yActive || dy < Math.min(Math.max(dx * 0.6, MINDRAG), MINZOOM)) {
1459+
if(dx < MINDRAG) {
14631460
zoomMode = '';
14641461
box.r = box.l;
14651462
box.t = box.b;
@@ -1470,21 +1467,21 @@ function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
14701467
box.b = ph;
14711468
zoomMode = 'x';
14721469
corners.attr('d',
1473-
'M' + (box.l - 0.5) + ',' + (y0 - constants.MINZOOM - 0.5) +
1474-
'h-3v' + (2 * constants.MINZOOM + 1) + 'h3ZM' +
1475-
(box.r + 0.5) + ',' + (y0 - constants.MINZOOM - 0.5) +
1476-
'h3v' + (2 * constants.MINZOOM + 1) + 'h-3Z');
1470+
'M' + (box.l - 0.5) + ',' + (y0 - MINZOOM - 0.5) +
1471+
'h-3v' + (2 * MINZOOM + 1) + 'h3ZM' +
1472+
(box.r + 0.5) + ',' + (y0 - MINZOOM - 0.5) +
1473+
'h3v' + (2 * MINZOOM + 1) + 'h-3Z');
14771474
}
14781475
}
1479-
else if(!xActive || dx < Math.min(dy * 0.6, constants.MINZOOM)) {
1476+
else if(!xActive || dx < Math.min(dy * 0.6, MINZOOM)) {
14801477
box.l = 0;
14811478
box.r = pw;
14821479
zoomMode = 'y';
14831480
corners.attr('d',
1484-
'M' + (x0 - constants.MINZOOM - 0.5) + ',' + (box.t - 0.5) +
1485-
'v-3h' + (2 * constants.MINZOOM + 1) + 'v3ZM' +
1486-
(x0 - constants.MINZOOM - 0.5) + ',' + (box.b + 0.5) +
1487-
'v3h' + (2 * constants.MINZOOM + 1) + 'v-3Z');
1481+
'M' + (x0 - MINZOOM - 0.5) + ',' + (box.t - 0.5) +
1482+
'v-3h' + (2 * MINZOOM + 1) + 'v3ZM' +
1483+
(x0 - MINZOOM - 0.5) + ',' + (box.b + 0.5) +
1484+
'v3h' + (2 * MINZOOM + 1) + 'v-3Z');
14881485
}
14891486
else {
14901487
zoomMode = 'xy';
@@ -1536,7 +1533,7 @@ function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
15361533
}
15371534

15381535
function zoomDone(dragged, numClicks) {
1539-
if(Math.min(box.h, box.w) < constants.MINDRAG * 2) {
1536+
if(Math.min(box.h, box.w) < MINDRAG * 2) {
15401537
if(numClicks === 2) doubleClick();
15411538
else pauseForDrag(gd);
15421539

@@ -1973,6 +1970,7 @@ fx.dragCursors = function(x,y,xanchor,yanchor){
19731970
fx.dragElement = function(options) {
19741971
var gd = Plotly.Lib.getPlotDiv(options.element) || {},
19751972
numClicks = 1,
1973+
DBLCLICKDELAY = constants.DBLCLICKDELAY,
19761974
startX,
19771975
startY,
19781976
newMouseDownTime,
@@ -1996,7 +1994,7 @@ fx.dragElement = function(options) {
19961994
initialTarget = e.target;
19971995

19981996
newMouseDownTime = (new Date()).getTime();
1999-
if(newMouseDownTime - gd._mouseDownTime < constants.DBLCLICKDELAY) {
1997+
if(newMouseDownTime - gd._mouseDownTime < DBLCLICKDELAY) {
20001998
// in a click train
20011999
numClicks += 1;
20022000
}
@@ -2047,7 +2045,7 @@ fx.dragElement = function(options) {
20472045

20482046
// don't count as a dblClick unless the mouseUp is also within
20492047
// the dblclick delay
2050-
if((new Date()).getTime() - gd._mouseDownTime > constants.DBLCLICKDELAY) {
2048+
if((new Date()).getTime() - gd._mouseDownTime > DBLCLICKDELAY) {
20512049
numClicks = Math.max(numClicks - 1, 1);
20522050
}
20532051

@@ -2105,7 +2103,7 @@ fx.setCursor = function(el3,csr) {
21052103
// count one edge as in, so that over continuous ranges you never get a gap
21062104
fx.inbox = function(v0,v1){
21072105
if(v0*v1<0 || v0===0) {
2108-
return fx.MAXDIST*(0.6-0.3/Math.max(3,Math.abs(v0-v1)));
2106+
return constants.MAXDIST*(0.6-0.3/Math.max(3,Math.abs(v0-v1)));
21092107
}
21102108
return Infinity;
21112109
};

0 commit comments

Comments
 (0)