Skip to content

Commit

Permalink
[APM] Disable map layout animation (#66763)
Browse files Browse the repository at this point in the history
* [APM] Disable map layout animation

Don't animate the layout. Keep animation for centering/zoom.

`preventDefault` when centering an already focused node so it doesn't do an unnecessary navigation.

Fixes #66695
  • Loading branch information
smith authored May 15, 2020
1 parent ae663eb commit 7f7585d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ function getLayoutOptions(
fit: true,
padding: nodeHeight,
spacingFactor: 0.85,
animate: true,
animationEasing: animationOptions.easing,
animationDuration: animationOptions.duration,
// @ts-ignore
// Rotate nodes counter-clockwise to transform layout from top→bottom to left→right.
// The extra 5° achieves the effect of separating overlapping taxi-styled edges.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import theme from '@elastic/eui/dist/eui_theme_light.json';
import { i18n } from '@kbn/i18n';
import cytoscape from 'cytoscape';
import React from 'react';
import React, { MouseEvent } from 'react';
import styled from 'styled-components';
import { fontSize, px } from '../../../../style/variables';
import { Buttons } from './Buttons';
Expand All @@ -31,7 +31,7 @@ const popoverMinWidth = 280;
interface ContentsProps {
isService: boolean;
label: string;
onFocusClick: () => void;
onFocusClick: (event: MouseEvent<HTMLAnchorElement>) => void;
selectedNodeData: cytoscape.NodeDataDefinition;
selectedNodeServiceName: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { EuiPopover } from '@elastic/eui';
import cytoscape from 'cytoscape';
import React, {
CSSProperties,
MouseEvent,
useCallback,
useContext,
useEffect,
Expand All @@ -16,8 +17,8 @@ import React, {
} from 'react';
import { SERVICE_NAME } from '../../../../../common/elasticsearch_fieldnames';
import { CytoscapeContext } from '../Cytoscape';
import { Contents } from './Contents';
import { animationOptions } from '../cytoscapeOptions';
import { Contents } from './Contents';

interface PopoverProps {
focusedServiceName?: string;
Expand Down Expand Up @@ -87,14 +88,18 @@ export function Popover({ focusedServiceName }: PopoverProps) {
}
}, [popoverRef, x, y]);

const centerSelectedNode = useCallback(() => {
if (cy) {
cy.animate({
...animationOptions,
center: { eles: cy.getElementById(selectedNodeServiceName) }
});
}
}, [cy, selectedNodeServiceName]);
const centerSelectedNode = useCallback(
(event: MouseEvent<HTMLAnchorElement>) => {
event.preventDefault();
if (cy) {
cy.animate({
...animationOptions,
center: { eles: cy.getElementById(selectedNodeServiceName) }
});
}
},
[cy, selectedNodeServiceName]
);

const isAlreadyFocused = focusedServiceName === selectedNodeServiceName;

Expand All @@ -110,7 +115,9 @@ export function Popover({ focusedServiceName }: PopoverProps) {
<Contents
isService={isService}
label={label}
onFocusClick={isAlreadyFocused ? centerSelectedNode : deselect}
onFocusClick={
isAlreadyFocused ? centerSelectedNode : _event => deselect()
}
selectedNodeData={selectedNodeData}
selectedNodeServiceName={selectedNodeServiceName}
/>
Expand Down

0 comments on commit 7f7585d

Please sign in to comment.