-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: decuple brush cursor from chart rendering (#331)
This PR remove the unnecessary style recalculation caused by chancing the cursor style on the document body from the chart_state. This was noticeable on this PR elastic/kibana#36517 (review) where the style reflow calculation tooks up to 75ms. This PR decouple the chart container from the chart renderer, allowing to set correctly the cursor changing the class without re-rendering the chart component, as the actual implementation. The cursor style now depends also on the status of the highlighted geometries. If one geometry is highlighted but no onElementClick or onElementOver listener is available, the cursor will be default if the brush is disabled, or crosshair if the brush is Enabled. The pointer is shown only if we have one between onElementClick or onElementOver enabled and we are over a geometry
- Loading branch information
Showing
7 changed files
with
149 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from 'react'; | ||
import { inject, observer } from 'mobx-react'; | ||
import { ChartStore } from '../../chart_types/xy_chart/store/chart_state'; | ||
import { ReactiveChart } from './reactive_chart'; | ||
interface ReactiveChartProps { | ||
chartStore?: ChartStore; // FIX until we find a better way on ts mobx | ||
} | ||
|
||
class ChartContainerComponent extends React.Component<ReactiveChartProps> { | ||
static displayName = 'ChartContainer'; | ||
|
||
render() { | ||
const { chartInitialized } = this.props.chartStore!; | ||
if (!chartInitialized.get()) { | ||
return null; | ||
} | ||
const { setCursorPosition } = this.props.chartStore!; | ||
return ( | ||
<div | ||
className="echChartCursorContainer" | ||
style={{ | ||
cursor: this.props.chartStore!.chartCursor.get(), | ||
}} | ||
onMouseMove={({ nativeEvent: { offsetX, offsetY } }) => { | ||
setCursorPosition(offsetX, offsetY); | ||
}} | ||
onMouseLeave={() => { | ||
setCursorPosition(-1, -1); | ||
}} | ||
onMouseUp={() => { | ||
if (this.props.chartStore!.isBrushing.get()) { | ||
return; | ||
} | ||
this.props.chartStore!.handleChartClick(); | ||
}} | ||
> | ||
<ReactiveChart /> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export const ChartContainer = inject('chartStore')(observer(ChartContainerComponent)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters