question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fix black dots dragging behavior on the mitigation plot (React hooks + D3.js guru needed)

See original GitHub issue

Steps To Reproduce

  1. Refresh the main page
  2. Mouse-focus into one of the form fields, for example increment “Imports per day” number.
  3. 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:

https://github.com/neherlab/covid19_scenarios/blob/b07eeaedd82dd3f54067e241cb62e5e2ac879504/src/components/Main/Containment/ContainmentGraph.tsx#L44-L49

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:

https://github.com/neherlab/covid19_scenarios/blob/b07eeaedd82dd3f54067e241cb62e5e2ac879504/src/components/Main/Containment/ContainmentGraph.tsx#L225-L230

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:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
petebacondarwincommented, Mar 21, 2020

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 set noSources to false when debugging in order to get half-decent debugging experience. Is there a better way to manage this?

1reaction
petebacondarwincommented, Mar 21, 2020

Ahah! So it seems that the first time draw() is called we have d3ref.current is null, which causes an error and so the effect is not run again. Adding a guard against this and adding d3ref.current as a dependency for the effect seems to solve the problem:

function draw({ data, width, height, onDataChange, d3ref }: DrawParams) {
  if (d3ref.current === null) {
    return
  }
  ...
 useEffect(() => draw({ data, onDataChange, width, height, d3ref }), [data, width, height, d3ref.current])
Read more comments on GitHub >

github_iconTop Results From Across the Web

Using D3.js Inside a React App
In this guide, you will learn how to integrate these two libraries. You will learn how to encapsulate your D3.js logic in a...
Read more >
Writing Custom React Hooks for D3 Visualizations
The useDragDrop hook returns triggerRef , which the component can set to a reference of the element dedicated to triggering the drag event, ......
Read more >
HnD - River Thames Conditions
Gotcha video clip, Tinyurl science, Table mountain casino drawings, Coblation turbinate reduction post op, Ss lazio 1900 calciomercato, Voyage pays baltes ...
Read more >
Available CRAN Packages By Name
automagic, Automagically Document and Install Packages Necessary to Run R Code ... DataViz, Data Visualisation Using an HTML Page and 'D3.js'.
Read more >
D3 and React.js crash course using react hooks - YouTube
This is a D3. js and React.js tutorial that takes you through the steps to build a responsive Line chart using react hooks....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found