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: external tooltip legend extra value sync #993

Merged
merged 2 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 13 additions & 2 deletions integration/tests/interactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,27 @@ describe('Interactions', () => {
it('show synced tooltips', async () => {
await common.expectChartWithMouseAtUrlToMatchScreenshot(
'http://localhost:9001/?path=/story/interactions--cursor-update-action&knob-local%20tooltip%20type_Top%20Chart=vertical&knob-local%20tooltip%20type_Bottom%20Chart=vertical&knob-enable%20external%20tooltip_Top%20Chart=true&knob-enable%20external%20tooltip_Bottom%20Chart=true&knob-external%20tooltip%20placement_Top%20Chart=left&knob-external%20tooltip%20placement_Bottom%20Chart=left',
{ right: 120, top: 80 },
{ right: 200, top: 80 },
{
screenshotSelector: '#story-root',
},
);
});

it('show synced crosshairs', async () => {
await common.expectChartWithMouseAtUrlToMatchScreenshot(
'http://localhost:9001/?path=/story/interactions--cursor-update-action&knob-local%20tooltip%20type_Top%20Chart=vertical&knob-local%20tooltip%20type_Bottom%20Chart=vertical&knob-enable%20external%20tooltip_Top%20Chart=true&knob-enable%20external%20tooltip_Bottom%20Chart=false&knob-external%20tooltip%20placement_Top%20Chart=left&knob-external%20tooltip%20placement_Bottom%20Chart=left',
{ right: 120, top: 80 },
{ right: 200, top: 80 },
{
screenshotSelector: '#story-root',
},
);
});

it('show synced extra values in legend', async () => {
await common.expectChartWithMouseAtUrlToMatchScreenshot(
'http://localhost:9001/?path=/story/interactions--cursor-update-action&knob-Series type_Top Chart=line&knob-enable external tooltip_Top Chart=true&knob-Series type_Bottom Chart=line&knob-enable external tooltip_Bottom Chart=false',
{ right: 200, top: 80 },
{
screenshotSelector: '#story-root',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function getTooltipAndHighlightFromValue(
return EMPTY_VALUES;
}

if (tooltipType === TooltipType.None) {
if (tooltipType === TooltipType.None && !externalPointerEvent) {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I love when it's just a one-line change, the hard part is knowing what line to change 🧐

return EMPTY_VALUES;
}

Expand Down
4 changes: 1 addition & 3 deletions src/components/tooltip/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,7 @@ const TooltipComponent = ({
boundary: boundary === 'chart' && chartRef.current ? chartRef.current : undefined,
};
}, [settings, chartRef, rotation]);
if (!visible) {
return null;
}

nickofthyme marked this conversation as resolved.
Show resolved Hide resolved
return (
<TooltipPortal
scope="MainTooltip"
Expand Down
40 changes: 35 additions & 5 deletions stories/interactions/16_cursor_update_action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { action } from '@storybook/addon-actions';
import { boolean } from '@storybook/addon-knobs';
import { boolean, select } from '@storybook/addon-knobs';
import React from 'react';

import {
Expand All @@ -32,12 +32,35 @@ import {
Placement,
niceTimeFormatter,
TooltipType,
LineSeries,
AreaSeries,
} from '../../src';
import { KIBANA_METRICS } from '../../src/utils/data_samples/test_dataset_kibana';
import { palettes } from '../../src/utils/themes/colors';
import { getTooltipTypeKnob, getPlacementKnob } from '../utils/knobs';
import { SB_SOURCE_PANEL } from '../utils/storybook';

const chartTypes: Record<string, any> = {
bar: BarSeries,
line: LineSeries,
area: AreaSeries,
};

const getSeriesKnob = (group?: string) => {
const type =
select<string>(
'Series type',
{
Bar: 'bar',
Line: 'line',
Area: 'area',
},
'bar',
group,
) ?? 'bar';
return chartTypes[type] ?? BarSeries;
};

export const Example = () => {
const ref1 = React.createRef<Chart>();
const ref2 = React.createRef<Chart>();
Expand All @@ -57,6 +80,8 @@ export const Example = () => {
const group1 = 'Top Chart';
const group2 = 'Bottom Chart';

const TopSeries = getSeriesKnob(group1);
const BottomSeries = getSeriesKnob(group2);
const topType = getTooltipTypeKnob('local tooltip type', TooltipType.VerticalCursor, group1);
const bottomType = getTooltipTypeKnob('local tooltip type', TooltipType.VerticalCursor, group2);
const topVisible = boolean('enable external tooltip', true, group1);
Expand All @@ -68,6 +93,8 @@ export const Example = () => {
<>
<Chart className="story-chart" ref={ref1} size={{ height: '50%' }} id="chart1">
<Settings
showLegend
showLegendExtra
onPointerUpdate={pointerUpdate}
externalPointerEvents={{
tooltip: { visible: topVisible, placement: topPlacement },
Expand All @@ -82,8 +109,8 @@ export const Example = () => {
/>
<Axis id="left2" position={Position.Left} tickFormat={(d: any) => Number(d).toFixed(2)} />

<BarSeries
id="bars"
<TopSeries
id="Top"
xScaleType={ScaleType.Time}
yScaleType={ScaleType.Linear}
xAccessor={0}
Expand All @@ -93,6 +120,8 @@ export const Example = () => {
</Chart>
<Chart className="story-chart" ref={ref2} size={{ height: '50%' }} id="chart2">
<Settings
showLegend
showLegendExtra
onPointerUpdate={pointerUpdate}
tooltip={{
type: bottomType,
Expand All @@ -114,8 +143,8 @@ export const Example = () => {
domain={{ min: 5, max: 20 }}
/>

<BarSeries
id="bars"
<BottomSeries
id="Bottom"
xScaleType={ScaleType.Time}
yScaleType={ScaleType.Sqrt}
xAccessor={0}
Expand All @@ -127,6 +156,7 @@ export const Example = () => {
</>
);
};

Example.story = {
parameters: {
info: {
Expand Down