Skip to content

Commit 6b041c2

Browse files
committed
Limit length of text in hover info on plots
In many instances this will prevent overflow. Plotly doesn't support sensible overflow or wrapping, so this is an alternative.
1 parent cc268ba commit 6b041c2

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

histomicsui/web_client/panels/MetadataPlot.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,31 @@ var MetadataPlot = Panel.extend({
357357
parts.push(plotData.series[series]);
358358
}
359359
});
360-
parts = parts.map((col) => `${col.title}: ${col.type === 'number' ? this._formatNumber(d[col.index]) : d[col.index]}`);
360+
const maximized = this.$el.closest('.h-panel-maximized').length > 0;
361+
const maxtotallen = 50;
362+
const maxlen = 32;
363+
parts = parts.map((col) => {
364+
let title = '' + col.title;
365+
let val = d[col.index];
366+
if (val === undefined || val === null) {
367+
val = '';
368+
} else if (col.type === 'number') {
369+
val = this._formatNumber(val);
370+
} else {
371+
val = '' + val;
372+
}
373+
const result = title + ': ' + val;
374+
if (maximized || result.length <= maxtotallen) {
375+
return result;
376+
}
377+
if (val.length > maxlen + 3) {
378+
val = val.substring(0, maxlen).replace(/\.+$/, '') + '...';
379+
}
380+
if (title.length + val.length + 2 > maxtotallen + 3) {
381+
title = title.substring(0, maxtotallen - val.length - 2).replace(/\.+$/, '') + '...';
382+
}
383+
return title + ': ' + val;
384+
});
361385

362386
const imageDict = {
363387
id: 'item.id',

0 commit comments

Comments
 (0)