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

[Lens][Heatmap] Enables cursor syncronization #142821

Merged
merged 8 commits into from
Oct 12, 2022
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ export const heatmapFunction = (): HeatmapExpressionFunctionDefinition => ({
(handlers.variables?.embeddableTitle as string) ??
handlers.getExecutionContext?.()?.description,
},
syncTooltips: handlers?.isSyncTooltipsEnabled?.() ?? false,
},
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export type HeatmapInput = Datatable;
export interface HeatmapExpressionProps {
data: Datatable;
args: HeatmapArguments;
syncTooltips: boolean;
}

export interface HeatmapRender {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import type { PaletteRegistry } from '@kbn/coloring';
import type { ChartsPluginSetup } from '@kbn/charts-plugin/public';
import type { ChartsPluginSetup, ChartsPluginStart } from '@kbn/charts-plugin/public';
import type { DatatableUtilitiesService } from '@kbn/data-plugin/common';
import type { IFieldFormat, SerializedFieldFormat } from '@kbn/field-formats-plugin/common';
import type { RangeSelectContext, ValueClickContext } from '@kbn/embeddable-plugin/public';
Expand All @@ -31,11 +31,13 @@ export type HeatmapRenderProps = HeatmapExpressionProps & {
timeZone?: string;
formatFactory: FormatFactory;
chartsThemeService: ChartsPluginSetup['theme'];
chartsActiveCursorService: ChartsPluginStart['activeCursor'];
datatableUtilities: DatatableUtilitiesService;
onClickValue: (data: FilterEvent['data']) => void;
onSelectRange: (data: BrushEvent['data']) => void;
paletteService: PaletteRegistry;
uiState: PersistedState;
interactive: boolean;
syncTooltips: boolean;
renderComplete: IInterpreterRenderHandlers['done'];
};
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ const actWithTimeout = (action: Function, timer: number = 1) =>
}, timer)
)
);

const chartStartContract = chartPluginMock.createStartContract();
const chartsThemeService = chartPluginMock.createSetupContract().theme;
const chartsActiveCursorService = chartStartContract.activeCursor;
const palettesRegistry = chartPluginMock.createPaletteRegistry();
const formatService = fieldFormatsServiceMock.createStartContract();
const args: HeatmapArguments = {
Expand Down Expand Up @@ -114,6 +115,7 @@ describe('HeatmapComponent', function () {
wrapperProps = {
data,
chartsThemeService,
chartsActiveCursorService,
args,
uiState,
onClickValue: jest.fn(),
Expand All @@ -122,6 +124,7 @@ describe('HeatmapComponent', function () {
paletteService: palettesRegistry,
formatFactory: formatService.deserialize,
interactive: true,
syncTooltips: false,
renderComplete: jest.fn(),
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import React, { memo, FC, useMemo, useState, useCallback } from 'react';
import React, { memo, FC, useMemo, useState, useCallback, useRef } from 'react';
import {
Chart,
ElementClickListener,
Expand All @@ -25,7 +25,7 @@ import {
} from '@elastic/charts';
import type { CustomPaletteState } from '@kbn/charts-plugin/public';
import { search } from '@kbn/data-plugin/public';
import { LegendToggle, EmptyPlaceholder } from '@kbn/charts-plugin/public';
import { LegendToggle, EmptyPlaceholder, useActiveCursor } from '@kbn/charts-plugin/public';
import {
getAccessorByDimension,
getFormatByAccessor,
Expand Down Expand Up @@ -138,14 +138,17 @@ export const HeatmapComponent: FC<HeatmapRenderProps> = memo(
timeZone,
formatFactory,
chartsThemeService,
chartsActiveCursorService,
datatableUtilities,
onClickValue,
onSelectRange,
paletteService,
uiState,
interactive,
syncTooltips,
renderComplete,
}) => {
const chartRef = useRef<Chart>(null);
const chartTheme = chartsThemeService.useChartsTheme();
const isDarkTheme = chartsThemeService.useDarkMode();
// legacy heatmap legend is handled by the uiState
Expand Down Expand Up @@ -436,6 +439,9 @@ export const HeatmapComponent: FC<HeatmapRenderProps> = memo(
}
return `${metricFormatter.convert(value) ?? ''}`;
};
const handleCursorUpdate = useActiveCursor(chartsActiveCursorService, chartRef, {
datatables: [formattedTable.table],
});

const { colors, ranges } = computeColorRanges(
paletteService,
Expand Down Expand Up @@ -564,12 +570,16 @@ export const HeatmapComponent: FC<HeatmapRenderProps> = memo(
legendPosition: args.legend.position,
}}
>
<Chart>
<Chart ref={chartRef}>
<Settings
onRenderChange={onRenderChange}
noResults={
<EmptyPlaceholder icon={IconChartHeatmap} renderComplete={onRenderChange} />
}
onPointerUpdate={handleCursorUpdate}
externalPointerEvents={{
tooltip: { visible: syncTooltips },
}}
onElementClick={interactive ? (onElementClick as ElementClickListener) : undefined}
showLegend={showLegend ?? args.legend.isVisible}
legendPosition={args.legend.position}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export const heatmapRenderer: (
renderComplete={renderComplete}
uiState={handlers.uiState as PersistedState}
interactive={isInteractive()}
chartsActiveCursorService={plugins.charts.activeCursor}
syncTooltips={config.syncTooltips}
/>
</div>
</KibanaThemeProvider>,
Expand Down