@@ -3,9 +3,11 @@ import { PropTypes } from "prop-types";
33import * as d3 from "d3" ;
44import { connect } from "react-redux" ;
55import { withTranslation } from "react-i18next" ;
6+ import { throttle } from "lodash" ;
67import { filterGenesByOverlap , measureText } from "../../helpers/utility" ;
78import Wrapper from "./index.style" ;
89import settingsActions from "../../redux/settings/actions" ;
10+ import { store } from "../../redux/store" ;
911
1012const { updateDomains, updateHoveredLocation } = settingsActions ;
1113
@@ -38,12 +40,9 @@ class GenesPlot extends Component {
3840 shouldComponentUpdate ( nextProps , nextState ) {
3941 return (
4042 nextProps . domains . toString ( ) !== this . props . domains . toString ( ) ||
41- nextProps . genesList . toString ( ) !== this . props . genesList . toString ( ) ||
43+ nextProps . genesList !== this . props . genesList ||
4244 nextProps . width !== this . props . width ||
43- nextProps . height !== this . props . height ||
44- nextProps . hoveredLocation !== this . props . hoveredLocation ||
45- nextProps . hoveredLocationPanelIndex !==
46- this . props . hoveredLocationPanelIndex
45+ nextProps . height !== this . props . height
4746 ) ;
4847 }
4948
@@ -74,42 +73,51 @@ class GenesPlot extends Component {
7473 . translate ( - s [ 0 ] , 0 )
7574 ) ;
7675 } ) ;
76+
77+ // Subscribe to Redux store for hover updates (bypassing React)
78+ this . unsubscribeHover = store . subscribe ( ( ) => {
79+ const state = store . getState ( ) ;
80+ const { hoveredLocation, hoveredLocationPanelIndex } = state . Settings ;
81+ this . updateHoverLine ( hoveredLocation , hoveredLocationPanelIndex ) ;
82+ } ) ;
7783 }
7884
7985 componentDidUpdate ( prevProps , prevState ) {
80- const {
81- domains,
82- hoveredLocationPanelIndex,
83- hoveredLocation,
84- chromoBins,
85- zoomedByCmd,
86- } = this . props ;
86+ const { domains, zoomedByCmd } = this . props ;
8787
88- this . panels . forEach ( ( panel , index ) => {
89- let domain = domains [ index ] ;
90- var s = [
91- panel . panelGenomeScale ( domain [ 0 ] ) ,
92- panel . panelGenomeScale ( domain [ 1 ] ) ,
93- ] ;
94- d3 . select ( this . plotContainer )
95- . select ( `#panel-rect-${ index } ` )
96- . attr ( "preserveAspectRatio" , "xMinYMin meet" )
97- . call (
98- panel . zoom . filter (
99- ( event ) => ! zoomedByCmd || ( ! event . button && event . metaKey )
100- )
101- ) ;
102- d3 . select ( this . plotContainer )
103- . select ( `#panel-rect-${ index } ` )
104- . call (
105- panel . zoom . filter (
106- ( event ) => ! zoomedByCmd || ( ! event . button && event . metaKey )
107- ) . transform ,
108- d3 . zoomIdentity
109- . scale ( panel . panelWidth / ( s [ 1 ] - s [ 0 ] ) )
110- . translate ( - s [ 0 ] , 0 )
111- ) ;
112- } ) ;
88+ // Only run expensive zoom transforms if domains changed
89+ const domainsChanged = prevProps . domains . toString ( ) !== domains . toString ( ) ;
90+ if ( domainsChanged ) {
91+ this . panels . forEach ( ( panel , index ) => {
92+ let domain = domains [ index ] ;
93+ var s = [
94+ panel . panelGenomeScale ( domain [ 0 ] ) ,
95+ panel . panelGenomeScale ( domain [ 1 ] ) ,
96+ ] ;
97+ d3 . select ( this . plotContainer )
98+ . select ( `#panel-rect-${ index } ` )
99+ . attr ( "preserveAspectRatio" , "xMinYMin meet" )
100+ . call (
101+ panel . zoom . filter (
102+ ( event ) => ! zoomedByCmd || ( ! event . button && event . metaKey )
103+ )
104+ ) ;
105+ d3 . select ( this . plotContainer )
106+ . select ( `#panel-rect-${ index } ` )
107+ . call (
108+ panel . zoom . filter (
109+ ( event ) => ! zoomedByCmd || ( ! event . button && event . metaKey )
110+ ) . transform ,
111+ d3 . zoomIdentity
112+ . scale ( panel . panelWidth / ( s [ 1 ] - s [ 0 ] ) )
113+ . translate ( - s [ 0 ] , 0 )
114+ ) ;
115+ } ) ;
116+ }
117+ }
118+
119+ updateHoverLine ( hoveredLocation , hoveredLocationPanelIndex ) {
120+ const { chromoBins } = this . props ;
113121
114122 if ( this . panels [ hoveredLocationPanelIndex ] ) {
115123 d3 . select ( this . plotContainer )
@@ -146,6 +154,13 @@ class GenesPlot extends Component {
146154 }
147155 }
148156
157+ componentWillUnmount ( ) {
158+ // Unsubscribe from hover updates
159+ if ( this . unsubscribeHover ) {
160+ this . unsubscribeHover ( ) ;
161+ }
162+ }
163+
149164 zooming ( event , index ) {
150165 let panel = this . panels [ index ] ;
151166 let newDomain = event . transform
@@ -198,12 +213,12 @@ class GenesPlot extends Component {
198213 this . zooming ( event , index ) ;
199214 }
200215
201- handleMouseMove = ( e , panelIndex ) => {
216+ handleMouseMove = throttle ( ( e , panelIndex ) => {
202217 this . props . updateHoveredLocation (
203218 this . panels [ panelIndex ] . xScale . invert ( d3 . pointer ( e ) [ 0 ] ) ,
204219 panelIndex
205220 ) ;
206- } ;
221+ } , 16 , { leading : true , trailing : false } ) ;
207222
208223 handleMouseOut = ( e , panelIndex ) => {
209224 this . props . updateHoveredLocation ( null , panelIndex ) ;
0 commit comments