Skip to content

Commit fb9ca96

Browse files
committedDec 8, 2024
fix bug with normalizing distances from axis labels
1 parent 2387501 commit fb9ca96

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed
 

‎app/src/app/components/visualizations/interactive-embedding-graph.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ const InteractiveEmbeddingGraph = ({
166166
sortedPointsWords.slice(sortedPointsWords.length / 2 - 1).reverse()
167167
);
168168

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+
169173
// Draw points
170174
svg
171175
.append("g")
@@ -181,10 +185,8 @@ const InteractiveEmbeddingGraph = ({
181185
.attr("fill", (d) => colorScale(x_val(d)))
182186
.on("mouseover", (event, d) => {
183187
// 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)
188190
tooltip
189191
.style("opacity", 1)
190192
.html(

0 commit comments

Comments
 (0)