Skip to content

Commit d8eb9ce

Browse files
committed
Update plotly and how selections are handled.
Ugly because plotly.js v2 doesn't expose unselect in any meaningful way.
1 parent 5a1287e commit d8eb9ce

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

histomicsui/web_client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"bootstrap-submenu": "^2.0.4",
3939
"copy-webpack-plugin": "^4.5.2",
4040
"petite-vue": "^0.4.1",
41-
"plotly.js": "^1.58.5",
41+
"plotly.js": "^2.34.0",
4242
"sinon": "^2.1.0",
4343
"tinycolor2": "~1.4.1",
4444
"url-search-params-polyfill": "^8.1.1",

histomicsui/web_client/panels/MetadataPlot.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,18 @@ var MetadataPlot = Panel.extend({
236236
},
237237

238238
onSelect: function (evt, plotData) {
239+
if (this._elementSelect) {
240+
this._elementSelect -= 1;
241+
if (this._afterSelect && !this._elementSelect) {
242+
this._afterSelect();
243+
this._afterSelect = null;
244+
}
245+
return;
246+
}
239247
if (plotData.colDict['_3_annotation.id'] === undefined || plotData.colDict['_5_annotationelement.id'] === undefined) {
240248
return;
241249
}
242-
// evt is undefined when selection is cleared
250+
// evt is undefined when the selection is cleared
243251
if (evt === undefined) {
244252
this.parentView._resetSelection();
245253
return;
@@ -284,7 +292,27 @@ var MetadataPlot = Panel.extend({
284292
if (!points.length) {
285293
return;
286294
}
287-
window.Plotly.restyle(this._plotlyNode[0], {selectedpoints: [points]});
295+
/* Deselect any selection on plotly. There is no exposed function to
296+
* do this, so we synthesize several actions: (a) switch to box select
297+
* mode, (b) double click on the plot, (c) ignore the first selection
298+
* event (first click), (d) on the second selection event, the plot no
299+
* longer has a selection, so we can specify the selected points (in
300+
* the _afterSelect callback), (e) switch back to whatever tool the
301+
* user had selected on the plot. */
302+
this._elementSelect = 2;
303+
const curactive = this._plotlyNode.find('.modebar-btn.active');
304+
this._afterSelect = () => {
305+
window.Plotly.restyle(this._plotlyNode[0], {selectedpoints: [points]});
306+
if (curactive.length) {
307+
curactive[0].dispatchEvent(new MouseEvent('click'));
308+
}
309+
};
310+
const plot = this._plotlyNode.find('.drag').first()[0];
311+
for (let i = 0; i <= 2; i += 1) {
312+
this._plotlyNode.find('.modebar-btn[data-val="select"]')[0].dispatchEvent(new MouseEvent('click'));
313+
plot.dispatchEvent(new MouseEvent('mousedown', {bubbles: true, cancelable: true, view: window, clientX: 10, clientY: 10}));
314+
plot.dispatchEvent(new MouseEvent('mouseup', {bubbles: true, cancelable: true, view: window, clientX: 10, clientY: 10}));
315+
}
288316
},
289317

290318
_formatNumber: function (val, significant) {

histomicsui/web_client/webpack.helper.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ module.exports = function (config) {
1212
to: config.output.path,
1313
toType: 'dir'
1414
}, {
15-
from: require.resolve('plotly.js/dist/plotly.min.js'),
15+
// the minified version fails in our test environment because
16+
// plotly.min.js uses some modern javascript (plotly.js doesn't)
17+
from: require.resolve(process.env.TOX_ENV_NAME ? 'plotly.js/dist/plotly.js' : 'plotly.js/dist/plotly.min.js'),
1618
to: path.join(config.output.path, 'extra', 'plotly.js'),
1719
toType: 'file'
1820
}, {

0 commit comments

Comments
 (0)