File tree 1 file changed +6
-4
lines changed
app/src/app/components/visualizations
1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -166,6 +166,10 @@ const InteractiveEmbeddingGraph = ({
166
166
sortedPointsWords . slice ( sortedPointsWords . length / 2 - 1 ) . reverse ( )
167
167
) ;
168
168
169
+ const normalizedDist = ( w1 , w2 ) => {
170
+ return Math . abs ( xScale ( x_val ( w1 ) ) - xScale ( x_val ( w2 ) ) ) / ( xScale ( x_val ( axis0 ) ) - xScale ( x_val ( axis1 ) ) ) ;
171
+ }
172
+
169
173
// Draw points
170
174
svg
171
175
. append ( "g" )
@@ -181,10 +185,8 @@ const InteractiveEmbeddingGraph = ({
181
185
. attr ( "fill" , ( d ) => colorScale ( x_val ( d ) ) )
182
186
. on ( "mouseover" , ( event , d ) => {
183
187
// Show the tooltip with word details
184
- const distanceToAxis0 =
185
- Math . abs ( x_val ( d ) - x_val ( axis0 ) ) / ( x_val ( axis0 ) - x_val ( axis1 ) ) ;
186
- const distanceToAxis1 =
187
- Math . abs ( x_val ( d ) - x_val ( axis1 ) ) / ( x_val ( axis0 ) - x_val ( axis1 ) ) ;
188
+ const distanceToAxis0 = normalizedDist ( d , axis0 )
189
+ const distanceToAxis1 = normalizedDist ( d , axis1 )
188
190
tooltip
189
191
. style ( "opacity" , 1 )
190
192
. html (
You can’t perform that action at this time.
0 commit comments