Fix black dots dragging behavior on the mitigation plot (React hooks + D3.js guru needed)
See original GitHub issueSteps To Reproduce
- Refresh the main page
- Mouse-focus into one of the form fields, for example increment “Imports per day” number.
- Without blurring (moving the cursor out of the form field), try to drag a black dot on the “Mitigation” plot
The current behavior
The “Mitigation” plot dot being dragged is not moving until mouse button is up
The expected behavior
The “Mitigation” plot dot being dragged is not moving as the cursor moves
Hypotheses
The blur event out of the field coincides with the initial click on the plot’s dot. After the blur, the form rerenders and also causes the plot to rerenders.
Currently there is a hack. This .html(null)
on every render clears the entire plot:
This also causes the destruction of the black dot we are dragging. The new dot will be rendered only on mouse up. Meanwhile we are dragging nothing.
Potential solution
We need to remove the hack shown above and to figure out proper dependencies for the `useEffect hook here:
such that the plot is properly cleared when it is needed, that it is responsive (to screen size) and not causing unnecessary rerenders at the same time
D3-React interop in this component should be properly audited for additional bugs and performance problems.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (5 by maintainers)
By the way, as I said I am not that hot on React development but I found that I needed to change the
webpack.SourceMapDevToolPlugin
to setnoSources
to false when debugging in order to get half-decent debugging experience. Is there a better way to manage this?Ahah! So it seems that the first time
draw()
is called we haved3ref.current
isnull
, which causes an error and so the effect is not run again. Adding a guard against this and addingd3ref.current
as a dependency for the effect seems to solve the problem: