Skip to content

Commit

Permalink
[APM] Adding stickTo on charts and adjusting search bar breakpoints (#…
Browse files Browse the repository at this point in the history
…107433) (#107596)

* adding stickTo prop to tooltip

* adjusting search bar breakpoints

* adjusting breakpoints

* addressing pr comments

* fixing ts issue

* fixing comparison size

Co-authored-by: Cauê Marcondes <[email protected]>
  • Loading branch information
kibanamachine and cauemarcondes authored Aug 3, 2021
1 parent 7fef282 commit 53e92a1
Show file tree
Hide file tree
Showing 10 changed files with 192 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export function ErrorDistribution({ distribution, title }: Props) {
);

const tooltipProps: SettingsSpec['tooltip'] = {
stickTo: 'top',
headerFormatter: (tooltip: TooltipValue) => {
const serie = buckets.find((bucket) => bucket.x0 === tooltip.value);
if (serie) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export function TransactionDistribution({
const bucketsMap = keyBy(buckets, 'x0');

const tooltip: SettingsSpec['tooltip'] = {
stickTo: 'top',
customTooltip: (props: TooltipInfo) => {
const datum = props.header?.datum as IChartPoint;
const selectedDistribution = distributionMap[datum?.x0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export function InstancesLatencyDistributionChart({
const latencyFormatter = getDurationFormatter(maxLatency);

const tooltip: TooltipProps = {
stickTo: 'center',
type: TooltipType.Follow,
snap: false,
customTooltip: (props: TooltipInfo) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
LineAnnotation,
LineSeries,
niceTimeFormatter,
Placement,
Position,
RectAnnotation,
ScaleType,
Expand All @@ -36,17 +35,17 @@ import {
RectCoordinate,
TimeSeries,
} from '../../../../typings/timeseries';
import { FETCH_STATUS } from '../../../hooks/use_fetcher';
import { useTheme } from '../../../hooks/use_theme';
import { useAnnotationsContext } from '../../../context/annotations/use_annotations_context';
import { useApmPluginContext } from '../../../context/apm_plugin/use_apm_plugin_context';
import { APMServiceAlert } from '../../../context/apm_service/apm_service_context';
import { useChartPointerEventContext } from '../../../context/chart_pointer_event/use_chart_pointer_event_context';
import { FETCH_STATUS } from '../../../hooks/use_fetcher';
import { useTheme } from '../../../hooks/use_theme';
import { getLatencyChartSelector } from '../../../selectors/latency_chart_selectors';
import { unit } from '../../../utils/style';
import { ChartContainer } from './chart_container';
import { onBrushEnd, isTimeseriesEmpty } from './helper/helper';
import { getLatencyChartSelector } from '../../../selectors/latency_chart_selectors';
import { APMServiceAlert } from '../../../context/apm_service/apm_service_context';
import { getAlertAnnotations } from './helper/get_alert_annotations';
import { useApmPluginContext } from '../../../context/apm_plugin/use_apm_plugin_context';
import { isTimeseriesEmpty, onBrushEnd } from './helper/helper';

interface Props {
id: string;
Expand Down Expand Up @@ -115,6 +114,7 @@ export function TimeseriesChart({
>
<Chart ref={chartRef} id={id}>
<Settings
tooltip={{ stickTo: 'top' }}
onBrushEnd={({ x }) => onBrushEnd({ x, history })}
theme={{
...chartTheme,
Expand All @@ -125,7 +125,7 @@ export function TimeseriesChart({
}}
onPointerUpdate={setPointerEvent}
externalPointerEvents={{
tooltip: { visible: true, placement: Placement.Right },
tooltip: { visible: true },
}}
showLegend
showLegendExtra
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
CurveType,
LineAnnotation,
niceTimeFormatter,
Placement,
Position,
ScaleType,
Settings,
Expand All @@ -29,11 +28,11 @@ import {
asPercent,
} from '../../../../../common/utils/formatters';
import { Coordinate, TimeSeries } from '../../../../../typings/timeseries';
import { FETCH_STATUS } from '../../../../hooks/use_fetcher';
import { useTheme } from '../../../../hooks/use_theme';
import { useUrlParams } from '../../../../context/url_params_context/use_url_params';
import { useAnnotationsContext } from '../../../../context/annotations/use_annotations_context';
import { useChartPointerEventContext } from '../../../../context/chart_pointer_event/use_chart_pointer_event_context';
import { useUrlParams } from '../../../../context/url_params_context/use_url_params';
import { FETCH_STATUS } from '../../../../hooks/use_fetcher';
import { useTheme } from '../../../../hooks/use_theme';
import { unit } from '../../../../utils/style';
import { ChartContainer } from '../../charts/chart_container';
import { isTimeseriesEmpty, onBrushEnd } from '../../charts/helper/helper';
Expand Down Expand Up @@ -73,6 +72,7 @@ export function TransactionBreakdownChartContents({
<ChartContainer height={height} hasData={!isEmpty} status={fetchStatus}>
<Chart ref={chartRef}>
<Settings
tooltip={{ stickTo: 'top' }}
onBrushEnd={({ x }) => onBrushEnd({ x, history })}
showLegend
showLegendExtra
Expand All @@ -82,7 +82,9 @@ export function TransactionBreakdownChartContents({
flatLegend
onPointerUpdate={setPointerEvent}
externalPointerEvents={{
tooltip: { visible: true, placement: Placement.Bottom },
tooltip: {
visible: true,
},
}}
/>
<Axis
Expand Down
16 changes: 10 additions & 6 deletions x-pack/plugins/apm/public/components/shared/search_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
EuiFlexItem,
EuiLink,
EuiSpacer,
EuiFlexGroupProps,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
Expand Down Expand Up @@ -83,23 +84,26 @@ export function SearchBar({
showTimeComparison = false,
showTransactionTypeSelector = false,
}: Props) {
const { isSmall, isMedium, isLarge, isXl, isXXL } = useBreakPoints();
const { isSmall, isMedium, isLarge, isXl, isXXL, isXXXL } = useBreakPoints();

if (hidden) {
return null;
}

const searchBarDirection: EuiFlexGroupProps['direction'] =
isXXXL || (!isXl && !showTimeComparison) ? 'row' : 'column';

return (
<>
<DebugQueryCallout />
<EuiFlexGroup
gutterSize="s"
responsive={false}
direction={isXXL ? 'row' : 'column'}
direction={searchBarDirection}
>
<EuiFlexItem>
<EuiFlexGroup
direction={isSmall ? 'columnReverse' : 'row'}
direction={isLarge ? 'columnReverse' : 'row'}
gutterSize="s"
responsive={false}
>
Expand All @@ -116,15 +120,15 @@ export function SearchBar({
)}
</EuiFlexGroup>
</EuiFlexItem>
<EuiFlexItem grow={showTimeComparison && !isXXL}>
<EuiFlexItem grow={showTimeComparison && !isXXXL}>
<EuiFlexGroup
direction={isSmall || isMedium || isLarge ? 'columnReverse' : 'row'}
justifyContent={isXl ? 'flexEnd' : undefined}
justifyContent={isXXL ? 'flexEnd' : undefined}
gutterSize="s"
responsive={false}
>
{showTimeComparison && (
<EuiFlexItem grow={isXXL} style={{ minWidth: 300 }}>
<EuiFlexItem grow={isXXXL} style={{ minWidth: 300 }}>
<TimeComparison />
</EuiFlexItem>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export function getSelectOptions({
export function TimeComparison() {
const trackApmEvent = useUiTracker({ app: 'apm' });
const history = useHistory();
const { isMedium, isLarge } = useBreakPoints();
const { isSmall } = useBreakPoints();
const {
urlParams: { comparisonEnabled, comparisonType, exactStart, exactEnd },
} = useUrlParams();
Expand Down Expand Up @@ -191,7 +191,7 @@ export function TimeComparison() {

return (
<EuiSelect
fullWidth={!isMedium && isLarge}
fullWidth={isSmall}
data-test-subj="comparisonSelect"
disabled={!comparisonEnabled}
options={selectOptions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import React, { FormEvent, useCallback } from 'react';
import { useHistory } from 'react-router-dom';
import styled from 'styled-components';
import { useApmServiceContext } from '../../context/apm_service/use_apm_service_context';
import { useBreakPoints } from '../../hooks/use_break_points';
import * as urlHelpers from './Links/url_helpers';

// The default transaction type (for non-RUM services) is "request". Set the
Expand All @@ -20,6 +21,7 @@ const EuiSelectWithWidth = styled(EuiSelect)`
`;

export function TransactionTypeSelect() {
const { isSmall } = useBreakPoints();
const { transactionTypes, transactionType } = useApmServiceContext();
const history = useHistory();

Expand All @@ -38,6 +40,7 @@ export function TransactionTypeSelect() {
return (
<>
<EuiSelectWithWidth
fullWidth={isSmall}
data-test-subj="headerFilterTransactionType"
onChange={handleChange}
options={options}
Expand Down
153 changes: 153 additions & 0 deletions x-pack/plugins/apm/public/hooks/use_break_points.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { getScreenSizes } from './use_break_points';

describe('use_break_points', () => {
describe('getScreenSizes', () => {
it('return xs when within 0px - 5740x', () => {
expect(getScreenSizes(0)).toEqual({
isXSmall: true,
isSmall: true,
isMedium: true,
isLarge: true,
isXl: true,
isXXL: true,
isXXXL: false,
});
expect(getScreenSizes(574)).toEqual({
isXSmall: true,
isSmall: true,
isMedium: true,
isLarge: true,
isXl: true,
isXXL: true,
isXXXL: false,
});
});
it('return s when within 575px - 767px', () => {
expect(getScreenSizes(575)).toEqual({
isXSmall: false,
isSmall: true,
isMedium: true,
isLarge: true,
isXl: true,
isXXL: true,
isXXXL: false,
});
expect(getScreenSizes(767)).toEqual({
isXSmall: false,
isSmall: true,
isMedium: true,
isLarge: true,
isXl: true,
isXXL: true,
isXXXL: false,
});
});
it('return m when within 768px - 991', () => {
expect(getScreenSizes(768)).toEqual({
isXSmall: false,
isSmall: false,
isMedium: true,
isLarge: true,
isXl: true,
isXXL: true,
isXXXL: false,
});
expect(getScreenSizes(991)).toEqual({
isXSmall: false,
isSmall: false,
isMedium: true,
isLarge: true,
isXl: true,
isXXL: true,
isXXXL: false,
});
});
it('return l when within 992px - 1199px', () => {
expect(getScreenSizes(992)).toEqual({
isXSmall: false,
isSmall: false,
isMedium: false,
isLarge: true,
isXl: true,
isXXL: true,
isXXXL: false,
});
expect(getScreenSizes(1199)).toEqual({
isXSmall: false,
isSmall: false,
isMedium: false,
isLarge: true,
isXl: true,
isXXL: true,
isXXXL: false,
});
});
it('return xl when within 1200px - 1599px', () => {
expect(getScreenSizes(1200)).toEqual({
isXSmall: false,
isSmall: false,
isMedium: false,
isLarge: false,
isXl: true,
isXXL: true,
isXXXL: false,
});
expect(getScreenSizes(1599)).toEqual({
isXSmall: false,
isSmall: false,
isMedium: false,
isLarge: false,
isXl: true,
isXXL: true,
isXXXL: false,
});
});
it('return xxl when within 1600px - 1999px', () => {
expect(getScreenSizes(1600)).toEqual({
isXSmall: false,
isSmall: false,
isMedium: false,
isLarge: false,
isXl: false,
isXXL: true,
isXXXL: false,
});
expect(getScreenSizes(1999)).toEqual({
isXSmall: false,
isSmall: false,
isMedium: false,
isLarge: false,
isXl: false,
isXXL: true,
isXXXL: false,
});
});
it('return xxxl when greater than or equals to 2000px', () => {
expect(getScreenSizes(2000)).toEqual({
isXSmall: false,
isSmall: false,
isMedium: false,
isLarge: false,
isXl: false,
isXXL: false,
isXXXL: true,
});
expect(getScreenSizes(3000)).toEqual({
isXSmall: false,
isSmall: false,
isMedium: false,
isLarge: false,
isXl: false,
isXXL: false,
isXXXL: true,
});
});
});
});
15 changes: 6 additions & 9 deletions x-pack/plugins/apm/public/hooks/use_break_points.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,17 @@
import { useState } from 'react';
import useWindowSize from 'react-use/lib/useWindowSize';
import useDebounce from 'react-use/lib/useDebounce';
import { isWithinMaxBreakpoint } from '@elastic/eui';
import { isWithinMaxBreakpoint, isWithinMinBreakpoint } from '@elastic/eui';

function isMinXXL(windowWidth: number) {
return windowWidth >= 1600;
}

function getScreenSizes(windowWidth: number) {
const isXXL = isMinXXL(windowWidth);
export function getScreenSizes(windowWidth: number) {
return {
isXSmall: isWithinMaxBreakpoint(windowWidth, 'xs'),
isSmall: isWithinMaxBreakpoint(windowWidth, 's'),
isMedium: isWithinMaxBreakpoint(windowWidth, 'm'),
isLarge: isWithinMaxBreakpoint(windowWidth, 'l'),
isXl: isWithinMaxBreakpoint(windowWidth, 'xl') && !isXXL,
isXXL,
isXl: isWithinMaxBreakpoint(windowWidth, 1599),
isXXL: isWithinMaxBreakpoint(windowWidth, 1999),
isXXXL: isWithinMinBreakpoint(windowWidth, 2000),
};
}

Expand Down

0 comments on commit 53e92a1

Please sign in to comment.