@@ -8,10 +8,13 @@ import TrafficStopsStyled, {
88 PieWrapper ,
99 StopGroupsContainer ,
1010 SwitchContainer ,
11+ Tooltip ,
1112} from './TrafficStops.styled' ;
1213import * as S from '../ChartSections/ChartsCommon.styled' ;
1314import { useTheme } from 'styled-components' ;
1415import cloneDeep from 'lodash.clonedeep' ;
16+ import { usePopper } from 'react-popper' ;
17+ import tooltipLanguage from '../../../util/tooltipLanguage' ;
1518
1619// Util
1720import {
@@ -678,6 +681,31 @@ function TrafficStops(props) {
678681 return `Traffic Stops by Percentage for ${ subject } since ${ stopsByPercentageData . labels [ 0 ] } ` ;
679682 } ;
680683
684+ const [ tooltipText , setTooltipText ] = useState ( '' ) ;
685+ const [ tooltipReferenceElement , setTooltipReferenceElement ] = useState ( null ) ;
686+ const [ popperElement , setPopperElement ] = useState ( null ) ;
687+ const { styles, attributes } = usePopper ( tooltipReferenceElement , popperElement , {
688+ placement : 'top-start' ,
689+ modifiers : [
690+ {
691+ name : 'offset' ,
692+ options : {
693+ offset : [ 0 , 5 ] ,
694+ } ,
695+ } ,
696+ ] ,
697+ } ) ;
698+
699+ const showTooltip = ( key ) => {
700+ setTooltipText ( tooltipLanguage ( key === 'Regulatory/Equipment' ? 'Regulatory Equipment' : key ) ) ;
701+ popperElement . setAttribute ( 'data-show' , true ) ;
702+ } ;
703+
704+ const hideTooltip = ( ) => {
705+ setTooltipText ( '' ) ;
706+ popperElement . removeAttribute ( 'data-show' ) ;
707+ } ;
708+
681709 return (
682710 < TrafficStopsStyled >
683711 { /* Traffic Stops by Percentage */ }
@@ -838,6 +866,13 @@ function TrafficStops(props) {
838866 </ LineChartWithPieContainer >
839867 </ S . ChartSection >
840868 < S . ChartSection marginTop = { 5 } id = "stops_by_purpose_and_count" >
869+ < Tooltip
870+ ref = { setPopperElement }
871+ style = { { ...styles . popper , width : '300px' } }
872+ { ...attributes . popper }
873+ >
874+ { tooltipText }
875+ </ Tooltip >
841876 < ChartHeader
842877 chartTitle = "Traffic Stops By Stop Purpose and Race Count"
843878 handleViewData = { showGroupedStopPurposeModal }
@@ -873,17 +908,22 @@ function TrafficStops(props) {
873908 </ SwitchContainer >
874909 < div style = { { marginTop : '1em' } } >
875910 < P weight = { WEIGHTS [ 1 ] } > Toggle graphs:</ P >
876- < div style = { { display : 'flex' , gap : '10px' , flexDirection : 'row' , flexWrap : 'wrap' } } >
911+ < div
912+ style = { { display : 'flex' , gap : '10px' , flexDirection : 'row' , flexWrap : 'wrap' } }
913+ ref = { setTooltipReferenceElement }
914+ >
877915 { visibleStopsGroupedByPurpose . map ( ( vg , i ) => (
878- < Checkbox
879- height = { 25 }
880- width = { 25 }
881- label = { vg . title }
882- value = { vg . key }
883- key = { i }
884- checked = { vg . visible }
885- onChange = { toggleGroupedPurposeGraphs }
886- />
916+ < div onMouseEnter = { ( ) => showTooltip ( vg . title ) } onMouseLeave = { hideTooltip } >
917+ < Checkbox
918+ height = { 25 }
919+ width = { 25 }
920+ label = { vg . title }
921+ value = { vg . key }
922+ key = { i }
923+ checked = { vg . visible }
924+ onChange = { toggleGroupedPurposeGraphs }
925+ />
926+ </ div >
887927 ) ) }
888928 </ div >
889929 </ div >
0 commit comments