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

[Vega] user should be able to toggle "textTruncate" option for tooltips #80524

Merged
merged 4 commits into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/user/dashboard/vega-reference.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ a configuration option for changing the tooltip position and padding:
kibana: {
tooltips: {
position: 'top',
padding: 15
padding: 15,
textTruncate: true,
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/plugins/vis_type_vega/public/_vega_vis.scss
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,19 @@
margin-bottom: $euiSizeS;
}

&--textTruncate {
td {
@include euiTextTruncate;
}
}

td {
@include euiTextTruncate;
padding-top: $euiSizeXS;
padding-bottom: $euiSizeXS;

&.key {
color: $euiColorMediumShade;
max-width: $euiSize * 10;
color: $euiColorMediumShade;
text-align: right;
padding-right: $euiSizeXS;
}
Expand All @@ -131,7 +136,6 @@
}
}


@media only screen and (max-width: map-get($euiBreakpoints, 'm')) {
td {
&.key {
Expand Down
1 change: 1 addition & 0 deletions src/plugins/vis_type_vega/public/data_model/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export interface TooltipConfig {
position?: ToolTipPositions;
padding?: number | Padding;
centerOnMark?: boolean | number;
textTruncate?: boolean;
}

export interface DstObj {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ describe('VegaParser.parseSchema', () => {
});

describe('VegaParser._parseTooltips', () => {
function check(tooltips, position, padding, centerOnMark) {
function check(tooltips, position, padding, centerOnMark, textTruncate = false) {
return () => {
const vp = new VegaParser(tooltips !== undefined ? { config: { kibana: { tooltips } } } : {});
vp._config = vp._parseConfig();
Expand All @@ -253,7 +253,7 @@ describe('VegaParser._parseTooltips', () => {
} else if (position === false) {
expect(vp._parseTooltips()).toEqual(false);
} else {
expect(vp._parseTooltips()).toEqual({ position, padding, centerOnMark });
expect(vp._parseTooltips()).toEqual({ position, padding, centerOnMark, textTruncate });
}
};
}
Expand All @@ -267,6 +267,7 @@ describe('VegaParser._parseTooltips', () => {
test('centerOnMark=10', check({ centerOnMark: 10 }, 'top', 16, 10));
test('centerOnMark=true', check({ centerOnMark: true }, 'top', 16, Number.MAX_VALUE));
test('centerOnMark=false', check({ centerOnMark: false }, 'top', 16, -1));
test('textTruncate=false', check({ textTruncate: true }, 'top', 16, 50, true));

test('false', check(false, false));

Expand Down
11 changes: 11 additions & 0 deletions src/plugins/vis_type_vega/public/data_model/vega_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,17 @@ The URL is an identifier only. Kibana and your browser will never access this UR
);
}

if (result.textTruncate === undefined) {
result.textTruncate = false;
} else if (typeof result.textTruncate !== 'boolean') {
throw new Error(
i18n.translate('visTypeVega.vegaParser.textTruncateConfigValueTypeErrorMessage', {
defaultMessage: '{configName} is expected to be a boolean',
values: { configName: 'textTruncate' },
})
);
}

if (result.centerOnMark === undefined) {
// if mark's width & height is less than this value, center on it
result.centerOnMark = 50;
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/vis_type_vega/public/vega_view/vega_tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class TooltipHandler {
this.position = opts.position;
this.padding = opts.padding;
this.centerOnMark = opts.centerOnMark;
this.textTruncate = opts.textTruncate;

view.tooltip(this.handler.bind(this));
}
Expand All @@ -73,6 +74,10 @@ export class TooltipHandler {
}
);

if (this.textTruncate) {
el.classList.add('vgaVis__tooltip--textTruncate');
}

// Sanitized HTML is created by the tooltip library,
// with a large number of tests, hence suppressing eslint here.
// eslint-disable-next-line no-unsanitized/property
Expand Down