Skip to content

Commit a8f5bfd

Browse files
authored
[APM] Service map center button (#56434) (#56467)
Add center button for service map. The fullscreen button is still there until #56351 is merged. Add fit and padding to the layout animation. Make the node labels wider so they aren't cut off.
1 parent 59ea076 commit a8f5bfd

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

x-pack/legacy/plugins/apm/public/components/app/ServiceMap/Controls.tsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import React, { useContext, useState, useEffect } from 'react';
87
import { EuiButtonIcon, EuiPanel } from '@elastic/eui';
98
import theme from '@elastic/eui/dist/eui_theme_light.json';
10-
import styled from 'styled-components';
119
import { i18n } from '@kbn/i18n';
10+
import React, { useContext, useEffect, useState } from 'react';
11+
import styled from 'styled-components';
1212
import { CytoscapeContext } from './Cytoscape';
13+
import { animationOptions, nodeHeight } from './cytoscapeOptions';
1314
import { FullscreenPanel } from './FullscreenPanel';
1415

1516
const ControlsContainer = styled('div')`
@@ -58,6 +59,17 @@ export function Controls() {
5859
}
5960
}, [cy]);
6061

62+
function center() {
63+
if (cy) {
64+
const eles = cy.nodes();
65+
cy.animate({
66+
...animationOptions,
67+
center: { eles },
68+
fit: { eles, padding: nodeHeight }
69+
});
70+
}
71+
}
72+
6173
function zoomIn() {
6274
doZoom(cy, increment);
6375
}
@@ -82,6 +94,9 @@ export function Controls() {
8294
const zoomOutLabel = i18n.translate('xpack.apm.serviceMap.zoomOut', {
8395
defaultMessage: 'Zoom out'
8496
});
97+
const centerLabel = i18n.translate('xpack.apm.serviceMap.center', {
98+
defaultMessage: 'Center'
99+
});
85100

86101
return (
87102
<ControlsContainer>
@@ -103,6 +118,15 @@ export function Controls() {
103118
title={zoomOutLabel}
104119
/>
105120
</ZoomPanel>
121+
<EuiPanel hasShadow={true} paddingSize="none">
122+
<Button
123+
aria-label={centerLabel}
124+
color="text"
125+
iconType="crosshairs"
126+
onClick={center}
127+
title={centerLabel}
128+
/>
129+
</EuiPanel>
106130
<FullscreenPanel element={mapDomElement} />
107131
</ControlsContainer>
108132
);

x-pack/legacy/plugins/apm/public/components/app/ServiceMap/cytoscapeOptions.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,23 @@ import theme from '@elastic/eui/dist/eui_theme_light.json';
77
import cytoscape from 'cytoscape';
88
import { defaultIcon, iconForNode } from './icons';
99

10+
export const animationOptions: cytoscape.AnimationOptions = {
11+
duration: parseInt(theme.euiAnimSpeedNormal, 10),
12+
// @ts-ignore The cubic-bezier options here are not recognized by the cytoscape types
13+
easing: theme.euiAnimSlightBounce
14+
};
15+
16+
export const nodeHeight = parseInt(theme.avatarSizing.l.size, 10);
17+
1018
const layout = {
1119
name: 'dagre',
1220
nodeDimensionsIncludeLabels: true,
1321
rankDir: 'LR',
1422
animate: true,
15-
animationEasing: theme.euiAnimSlightBounce,
16-
animationDuration: parseInt(theme.euiAnimSpeedNormal, 10)
23+
animationEasing: animationOptions.easing,
24+
animationDuration: animationOptions.duration,
25+
fit: true,
26+
padding: nodeHeight
1727
};
1828

1929
function isService(el: cytoscape.NodeSingular) {
@@ -45,7 +55,7 @@ const style: cytoscape.Stylesheet[] = [
4555
// specifying a subset of the fonts for the label text.
4656
'font-family': 'Inter UI, Segoe UI, Helvetica, Arial, sans-serif',
4757
'font-size': theme.euiFontSizeXS,
48-
height: theme.avatarSizing.l.size,
58+
height: nodeHeight,
4959
label: 'data(label)',
5060
'min-zoomed-font-size': theme.euiSizeL,
5161
'overlay-opacity': 0,
@@ -56,7 +66,7 @@ const style: cytoscape.Stylesheet[] = [
5666
'text-background-padding': theme.paddingSizes.xs,
5767
'text-background-shape': 'roundrectangle',
5868
'text-margin-y': theme.paddingSizes.s,
59-
'text-max-width': '85px',
69+
'text-max-width': '200px',
6070
'text-valign': 'bottom',
6171
'text-wrap': 'ellipsis',
6272
width: theme.avatarSizing.l.size

0 commit comments

Comments
 (0)