Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 68a19ac

Browse filesBrowse files
committed
compute bar centroid in Bar.select
... instead of during Bar.plot, so that "main" and "rangePlot" values don't conflict
1 parent 4529fe9 commit 68a19ac
Copy full SHA for 68a19ac

File tree

Expand file treeCollapse file tree

3 files changed

+32
-17
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+32
-17
lines changed

‎src/traces/bar/plot.js

Copy file name to clipboardExpand all lines: src/traces/bar/plot.js
-6Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,11 @@ module.exports = function plot(gd, plotinfo, cdModule, traceLayer) {
7070
y1 = ya.c2p(di.p1, true);
7171
x0 = xa.c2p(di.s0, true);
7272
x1 = xa.c2p(di.s1, true);
73-
74-
// for selections
75-
di.ct = [x1, (y0 + y1) / 2];
7673
} else {
7774
x0 = xa.c2p(di.p0, true);
7875
x1 = xa.c2p(di.p1, true);
7976
y0 = ya.c2p(di.s0, true);
8077
y1 = ya.c2p(di.s1, true);
81-
82-
// for selections
83-
di.ct = [(x0 + x1) / 2, y1];
8478
}
8579

8680
var isBlank = di.isBlank = (

‎src/traces/bar/select.js

Copy file name to clipboardExpand all lines: src/traces/bar/select.js
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = function selectPoints(searchInfo, selectionTester) {
1212
var cd = searchInfo.cd;
1313
var xa = searchInfo.xaxis;
1414
var ya = searchInfo.yaxis;
15+
var trace = cd[0].trace;
1516
var selection = [];
1617
var i;
1718

@@ -21,10 +22,15 @@ module.exports = function selectPoints(searchInfo, selectionTester) {
2122
cd[i].selected = 0;
2223
}
2324
} else {
25+
var getCentroid = trace.orientation === 'h' ?
26+
function(d) { return [xa.c2p(d.s1, true), (ya.c2p(d.p0, true) + ya.c2p(d.p1, true)) / 2]; } :
27+
function(d) { return [(xa.c2p(d.p0, true) + xa.c2p(d.p1, true)) / 2, ya.c2p(d.s1, true)]; };
28+
2429
for(i = 0; i < cd.length; i++) {
2530
var di = cd[i];
31+
var ct = 'ct' in di ? di.ct : getCentroid(di);
2632

27-
if(selectionTester.contains(di.ct, false, i, searchInfo)) {
33+
if(selectionTester.contains(ct, false, i, searchInfo)) {
2834
selection.push({
2935
pointNumber: i,
3036
x: xa.c2d(di.x),

‎test/jasmine/tests/select_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/select_test.js
+25-10Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,16 +2232,7 @@ describe('Test select box and lasso per trace:', function() {
22322232
.then(function() {
22332233
return Plotly.relayout(gd, 'dragmode', 'select');
22342234
})
2235-
.then(function() {
2236-
// For some reason we need this to make the following tests pass
2237-
// on CI consistently. It appears that a double-click action
2238-
// is being confused with a mere click. See
2239-
// https://github.com/plotly/plotly.js/pull/2135#discussion_r148897529
2240-
// for more info.
2241-
return new Promise(function(resolve) {
2242-
setTimeout(resolve, 100);
2243-
});
2244-
})
2235+
.then(delay(100))
22452236
.then(function() {
22462237
return _run(
22472238
[[350, 200], [370, 220]],
@@ -2261,6 +2252,30 @@ describe('Test select box and lasso per trace:', function() {
22612252
null, BOXEVENTS, 'bar select'
22622253
);
22632254
})
2255+
.then(function() {
2256+
// mimic https://github.com/plotly/plotly.js/issues/3795
2257+
return Plotly.relayout(gd, {
2258+
'xaxis.rangeslider.visible': true,
2259+
'xaxis.range': [0, 6]
2260+
});
2261+
})
2262+
.then(function() {
2263+
return _run(
2264+
[[350, 200], [360, 200]],
2265+
function() {
2266+
assertPoints([
2267+
[0, 2.5, -0.429], [1, 2.5, -1.015], [2, 2.5, -1.172],
2268+
]);
2269+
assertSelectedPoints({
2270+
0: [25],
2271+
1: [25],
2272+
2: [25]
2273+
});
2274+
assertRanges([[2.434, 2.521], [-1.4355, 2.0555]]);
2275+
},
2276+
null, BOXEVENTS, 'bar select (after xaxis.range relayout)'
2277+
);
2278+
})
22642279
.catch(failTest)
22652280
.then(done);
22662281
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.