Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
* under the License.
*/

// TODO: Remove bus when action/triggers are available with LegacyPluginApi or metric is converted to Embeddable
import $ from 'jquery';
import { Subject } from 'rxjs';

export const ACTIVE_CURSOR = 'ACTIVE_CURSOR';

export const eventBus = $({});
interface ActiveCursor {
cursor: any;
}

export const activeCursor$ = new Subject<ActiveCursor>();
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
} from '@elastic/charts';
import { EuiIcon } from '@elastic/eui';
import { getTimezone } from '../../../lib/get_timezone';
import { eventBus, ACTIVE_CURSOR } from '../../lib/active_cursor';
import { activeCursor$ } from '../../lib/active_cursor';
import { getUISettings, getChartsSetup } from '../../../../services';
import { GRID_LINE_CONFIG, ICON_TYPES_MAP, STACKED_OPTIONS } from '../../constants';
import { AreaSeriesDecorator } from './decorators/area_decorator';
Expand All @@ -54,7 +54,7 @@ const generateAnnotationData = (values, formatter) =>
const decorateFormatter = (formatter) => ({ value }) => formatter(value);

const handleCursorUpdate = (cursor) => {
eventBus.trigger(ACTIVE_CURSOR, cursor);
activeCursor$.next({ cursor });
};

export const TimeSeries = ({
Expand All @@ -73,16 +73,20 @@ export const TimeSeries = ({
const chartRef = useRef();

useEffect(() => {
const updateCursor = (_, cursor) => {
if (chartRef.current) {
const updateCursor = ({ cursor }) => {
if (
chartRef.current &&
cursor &&
chartRef.current.chartStore.getState().chartId !== cursor.chartId
) {
chartRef.current.dispatchExternalPointerEvent(cursor);
}
};

eventBus.on(ACTIVE_CURSOR, updateCursor);
const subscription = activeCursor$.subscribe(updateCursor);

return () => {
eventBus.off(ACTIVE_CURSOR, undefined, updateCursor);
subscription.unsubscribe();
};
}, []);

Expand Down