Skip to content

Commit 69d9c8c

Browse files
committed
add lasso/select box for histogram traces
- by reusing Bar.selectPoints 🎉
1 parent 6e6bb32 commit 69d9c8c

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/traces/histogram/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Histogram.plot = require('../bar/plot');
3535
Histogram.style = require('../bar/style');
3636
Histogram.colorbar = require('../scatter/colorbar');
3737
Histogram.hoverPoints = require('../bar/hover');
38+
Histogram.selectPoints = require('../bar/select');
3839

3940
Histogram.moduleType = 'trace';
4041
Histogram.name = 'histogram';

test/jasmine/tests/select_test.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,4 +773,49 @@ describe('Test select box and lasso per trace:', function() {
773773
.catch(fail)
774774
.then(done);
775775
});
776+
777+
it('should work for histogram traces', function(done) {
778+
var assertPoints = makeAssertPoints(['curveNumber', 'x', 'y']);
779+
var assertRanges = makeAssertRanges();
780+
var assertLassoPoints = makeAssertLassoPoints();
781+
782+
var fig = Lib.extendDeep({}, require('@mocks/hist_grouped'));
783+
fig.layout.dragmode = 'lasso';
784+
fig.layout.width = 600;
785+
fig.layout.height = 500;
786+
787+
Plotly.plot(gd, fig)
788+
.then(function() {
789+
return _run(
790+
[[200, 200], [400, 200], [400, 350], [200, 350], [200, 200]],
791+
function() {
792+
assertPoints([
793+
[0, 1.8, 2], [1, 2.2, 1], [1, 3.2, 1]
794+
]);
795+
assertLassoPoints([
796+
[1.66, 3.59, 3.59, 1.66, 1.66],
797+
[2.17, 2.17, 0.69, 0.69, 2.17]
798+
]);
799+
},
800+
null, LASSOEVENTS, 'histogram lasso'
801+
);
802+
})
803+
.then(function() {
804+
return Plotly.relayout(gd, 'dragmode', 'select');
805+
})
806+
.then(function() {
807+
return _run(
808+
[[200, 200], [400, 350]],
809+
function() {
810+
assertPoints([
811+
[0, 1.8, 2], [1, 2.2, 1], [1, 3.2, 1]
812+
]);
813+
assertRanges([[1.66, 3.59], [0.69, 2.17]]);
814+
},
815+
null, BOXEVENTS, 'bar select'
816+
);
817+
})
818+
.catch(fail)
819+
.then(done);
820+
});
776821
});

0 commit comments

Comments
 (0)