Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tooltip text overflow #41703

Merged
merged 11 commits into from
Aug 13, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@
</thead>
<tbody>
<tr class="visTooltip__value" ng-repeat="row in rows track by $index">
<td><span ng-bind-html="row.spacer"></span>{{row.field}}</td>
<td>{{row.bucket}}</td>
<td>
nickofthyme marked this conversation as resolved.
Show resolved Hide resolved
<div class="visTooltip__labelContainer"><span ng-bind-html="row.spacer"></span>{{row.field}}</div>
</td>
<td>
<div class="visTooltip__labelContainer">{{row.bucket}}
</td>
<td>{{row.metric}}</td>
</tr>
</tbody>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<table>
<tbody>
<tr ng-repeat="detail in details" >
<td class="visTooltip__label">{{detail.label}}</td>
<td class="visTooltip__label">
<div class="visTooltip__labelContainer">{{detail.label}}</div>
cchaos marked this conversation as resolved.
Show resolved Hide resolved
</td>
<td class="visTooltip__value">
{{detail.value}}
<span ng-if="detail.percent"> ({{detail.percent}})</span>
<div class="visTooltip__valueContainer">{{detail.value}}<span ng-if="detail.percent"> ({{detail.percent}})</span></div>
</td>
</tr>
</tbody>
Expand Down
5 changes: 5 additions & 0 deletions src/legacy/ui/public/vis/components/tooltip/_tooltip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
td,
th {
padding: $euiSizeXS;
@include euiTextOverflowWrap;
}
}
}
Expand All @@ -41,6 +42,10 @@
margin-top: $euiSizeS;
}
}
.visTooltip__labelContainer,
.visTooltip__valueContainer {
@include euiTextOverflowWrap;
}

.visTooltip__headerIcon {
flex: 0 0 auto;
Expand Down
41 changes: 41 additions & 0 deletions src/legacy/ui/public/vis/components/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ import _ from 'lodash';
import { Binder } from '../../../binder';
import { positionTooltip } from './position_tooltip';
import $ from 'jquery';
import theme from '@elastic/eui/dist/eui_theme_light.json';

let allContents = [];

const tooltipColumnPadding = parseInt(theme.euiSizeXS || 0, 10) * 2;
const tooltipTableMargin = parseInt(theme.euiSizeS || 0, 10) * 2;
const tooltipMaxWidth = parseInt(theme.euiSizeXL || 0, 10) * 10;

/**
* Add tooltip and listeners to visualization elements
*
Expand Down Expand Up @@ -97,6 +102,42 @@ Tooltip.prototype.show = function () {
left: placement.left,
top: placement.top
});
const tooltipColumns = $tooltip.find('tbody > tr:nth-of-type(1) > td').length;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a lot of match and element targeting. I'd suggest highly commenting on what is going on so others can follow in case anything needs to be adjusted.

if (tooltipColumns === 2) {
// on pointseries tooltip
const tooltipWidth = $tooltip.outerWidth();
const valueColumn = $tooltip.find('tr:nth-of-type(1) > td:nth-child(2)');
if (valueColumn.length !== 1) {
return;
}
const valueColumnSize = valueColumn.outerWidth();
const isGratherThanHalf = valueColumnSize > tooltipWidth / 2;
const containerMaxWidth = isGratherThanHalf
? tooltipWidth / 2 - tooltipTableMargin - tooltipColumnPadding * 2
: tooltipWidth - valueColumnSize - tooltipTableMargin - tooltipColumnPadding;

$tooltip.find('.visTooltip__labelContainer').css({
'max-width': containerMaxWidth,
});
if (isGratherThanHalf && tooltipWidth === tooltipMaxWidth) {
$tooltip.find('.visTooltip__valueContainer').css({
'max-width': containerMaxWidth,
});
}
} else if(tooltipColumns === 3) {
// on hierarchical tooltip
const tooltipWidth = $tooltip.outerWidth();
const valueColumn = $tooltip.find('tr:nth-of-type(1) > td:nth-child(3)');
if (valueColumn.length !== 1) {
return;
}
const valueColumnSize = valueColumn.outerWidth();
const containerMaxWidth = (tooltipWidth - valueColumnSize - tooltipTableMargin) / 2 - tooltipColumnPadding;

$tooltip.find('.visTooltip__labelContainer').css({
'max-width': containerMaxWidth
});
}
};

/**
Expand Down