diff --git a/src/components/_container.scss b/src/components/_container.scss index 461dc1e198..a1dd5b6068 100644 --- a/src/components/_container.scss +++ b/src/components/_container.scss @@ -13,3 +13,7 @@ } } } + +.echChart--isBrushEnabled { + cursor: crosshair; +} diff --git a/src/components/react_canvas/reactive_chart.tsx b/src/components/react_canvas/reactive_chart.tsx index 501d1583f6..303aec779f 100644 --- a/src/components/react_canvas/reactive_chart.tsx +++ b/src/components/react_canvas/reactive_chart.tsx @@ -1,3 +1,4 @@ +import classNames from 'classnames'; import { inject, observer } from 'mobx-react'; import React from 'react'; import { Layer, Rect, Stage } from 'react-konva'; @@ -376,6 +377,10 @@ class Chart extends React.Component { clipHeight: chartDimensions.height, }; + const className = classNames({ + 'echChart--isBrushEnabled': this.props.chartStore!.isCrosshairCursorVisible.get(), + }); + return (
{ onClick={() => { this.props.chartStore!.handleChartClick(); }} + className={className} > { expectedTooltipValues.set('seriesKey', 123); expect(store.legendItemTooltipValues.get()).toEqual(expectedTooltipValues); }); + describe('can determine if crosshair cursor is visible', () => { + const brushEndListener = (): void => { + return; + }; + + beforeEach(() => { + store.xScale = new ScaleContinuous(ScaleType.Linear, [0, 100], [0, 100]); + }); + + test('when cursor is outside of chart bounds', () => { + store.cursorPosition.x = -1; + store.cursorPosition.y = -1; + store.onBrushEndListener = brushEndListener; + expect(store.isCrosshairCursorVisible.get()).toBe(false); + }); + + test('when cursor is within chart bounds and brush enabled', () => { + store.cursorPosition.x = 10; + store.cursorPosition.y = 10; + store.onBrushEndListener = brushEndListener; + expect(store.isCrosshairCursorVisible.get()).toBe(true); + }); + + test('when cursor is within chart bounds and brush disabled', () => { + store.cursorPosition.x = 10; + store.cursorPosition.y = 10; + store.onBrushEndListener = undefined; + expect(store.isCrosshairCursorVisible.get()).toBe(false); + }); + }); }); diff --git a/src/state/chart_state.ts b/src/state/chart_state.ts index 8c2e4e1388..55d2d73e86 100644 --- a/src/state/chart_state.ts +++ b/src/state/chart_state.ts @@ -221,6 +221,20 @@ export class ChartStore { this.computeChart(); }); + /** + * determine if crosshair cursor should be visible based on cursor position and brush enablement + */ + isCrosshairCursorVisible = computed(() => { + const xPos = this.cursorPosition.x; + const yPos = this.cursorPosition.y; + + if (yPos < 0 || xPos < 0) { + return false; + } + + return this.isBrushEnabled(); + }); + /** * x and y values are relative to the container. */