Skip to content
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
5 changes: 5 additions & 0 deletions packages/charts/api/charts.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,8 @@ export interface ControlReceiverCallbacks {
focusOnNode: (control: FlameNodeControl) => void;
// (undocumented)
resetFocus: (control: FlameGlobalControl) => void;
// (undocumented)
search: (control: FlameSearchControl) => void;
}

// @public (undocumented)
Expand Down Expand Up @@ -1078,6 +1080,9 @@ export interface FlameLayerValue {
// @public
export type FlameNodeControl = (nodeIndex: number) => void;

// @public
export type FlameSearchControl = (text: string) => void;

// @public
export interface FlameSpec<D extends BaseDatum = Datum> extends Spec, LegacyAnimationConfig {
// (undocumented)
Expand Down
7 changes: 7 additions & 0 deletions packages/charts/src/chart_types/flame_chart/flame_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ export type FlameGlobalControl = () => void; // takes no argument
*/
export type FlameNodeControl = (nodeIndex: number) => void; // takes no arguments

/**
* Control function for setting chart focus on a specific node
* @public
*/
export type FlameSearchControl = (text: string) => void; // takes no arguments

/**
* Provides direct controls for the Flame component user.
* The call site supplied callback function is invoked on the chart component initialization as well as on component update,
Expand All @@ -34,6 +40,7 @@ export type FlameNodeControl = (nodeIndex: number) => void; // takes no argument
export interface ControlReceiverCallbacks {
resetFocus: (control: FlameGlobalControl) => void; // call site responsibility to store and use the `control` function
focusOnNode: (control: FlameNodeControl) => void; // same but the control function passed to the call site uses one arg
search: (control: FlameSearchControl) => void;
}

/**
Expand Down
7 changes: 7 additions & 0 deletions packages/charts/src/chart_types/flame_chart/flame_chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,13 @@ class FlameComponent extends React.Component<FlameProps> {
this.focusOnNode(nodeIndex);
});
}
if (controlProviderCallback.search) {
controlProviderCallback.search((text: string) => {
if (!this.searchInputRef.current) return;
this.searchInputRef.current.value = text;
this.searchForText(false);
});
}
}

private resetFocus() {
Expand Down
9 changes: 8 additions & 1 deletion storybook/stories/icicle/04_cpu_profile_gl_flame.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

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

import {
Expand All @@ -18,6 +18,7 @@ import {
FlameGlobalControl,
FlameNodeControl,
ColumnarViewModel,
FlameSearchControl,
} from '@elastic/charts';
import columnarMock from '@elastic/charts/src/mocks/hierarchical/cpu_profile_tree_mock_columnar.json';
import { getRandomNumberGenerator } from '@elastic/charts/src/mocks/utils';
Expand Down Expand Up @@ -62,6 +63,7 @@ const noop = () => {};
export const Example = () => {
let resetFocusControl: FlameGlobalControl = noop; // initial value
let focusOnNodeControl: FlameNodeControl = noop; // initial value
let searchText: FlameSearchControl = noop; // initial value

const onElementListeners = {
onElementClick: action('onElementClick'),
Expand All @@ -74,6 +76,10 @@ export const Example = () => {
button('Set focus on random node', () => {
focusOnNodeControl(rng(0, 19));
});
const textSearch = text('Text to search', 'github');
button('Search', () => {
searchText(textSearch);
});
const debug = boolean('Debug history', false);
return (
<Chart>
Expand All @@ -87,6 +93,7 @@ export const Example = () => {
controlProviderCallback={{
resetFocus: (control) => (resetFocusControl = control),
focusOnNode: (control) => (focusOnNodeControl = control),
search: (control) => (searchText = control),
}}
/>
</Chart>
Expand Down