@@ -43,20 +43,43 @@ export default function ScatterPlot(props) {
4343 wordObj . heScore - wordObj . sheScore >= - 5
4444 ) ;
4545
46- //add a small offset to the points in case they are overlapping
47- const seenValues = { } ;
48- selected . forEach ( ( wordObj ) => {
49- const val = `${ wordObj . heScore } -${ wordObj . sheScore } ` ;
50- if ( seenValues [ val ] ) {
51- wordObj . sheScore += 5 ;
52- const val2 = `${ wordObj . heScore } -${ wordObj . sheScore } ` ;
53- if ( seenValues [ val2 ] ) {
54- wordObj . sheScore += 5 ;
55- }
56- } else {
57- seenValues [ val ] = true ;
46+ // use tooltip to collapse words on top off each other into 1 pop-up
47+ const CustomTooltip = ( { active, payload } ) => {
48+ if ( active && payload && payload . length ) {
49+ // Find all words that match the current heScore and sheScore
50+ const { heScore, sheScore } = payload [ 0 ] . payload ;
51+ const matchingWords = selected . filter (
52+ ( wordObj ) =>
53+ wordObj . heScore === heScore && wordObj . sheScore === sheScore
54+ ) ;
55+
56+ return (
57+ < div
58+ style = { {
59+ background : "white" ,
60+ padding : "10px" ,
61+ border : "1px solid #ccc" ,
62+ } }
63+ >
64+ < p >
65+ < strong > He Similarity:</ strong > { heScore } %
66+ </ p >
67+ < p >
68+ < strong > She Similarity:</ strong > { sheScore } %
69+ </ p >
70+ < p >
71+ < strong > Words:</ strong >
72+ </ p >
73+ < ul >
74+ { matchingWords . map ( ( wordObj , index ) => (
75+ < li key = { index } > { wordObj . word } </ li >
76+ ) ) }
77+ </ ul >
78+ </ div >
79+ ) ;
5880 }
59- } ) ;
81+ return null ;
82+ } ;
6083
6184 const listOfScatters = [ ] ;
6285 //append heLeaning words
@@ -113,7 +136,10 @@ export default function ScatterPlot(props) {
113136 </ YAxis >
114137 < ZAxis dataKey = "word" name = "Word" />
115138 < CartesianGrid strokeDasharray = "3 3" />
116- < Tooltip cursor = { { strokeDasharray : "3 3" } } />
139+ < Tooltip
140+ content = { < CustomTooltip /> }
141+ cursor = { { strokeDasharray : "3 3" } }
142+ />
117143 < Scatter
118144 data = { [
119145 { heScore : 0 , sheScore : 0 } ,
0 commit comments