Coder Social home page Coder Social logo

Comments (5)

petebacondarwin avatar petebacondarwin commented on June 17, 2024 2

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?

from covid19_scenarios.

petebacondarwin avatar petebacondarwin commented on June 17, 2024 1

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])

from covid19_scenarios.

petebacondarwin avatar petebacondarwin commented on June 17, 2024

I am not that up with React but I had a little play and it seems to me that this component only needs to re-render the graph if the time series changes, which is defined by the data property, or when the size of the graph changes, which is defined by the width and height properties. Yes?

So I changed

useEffect(() => draw({ data, onDataChange, width, height, d3ref }))
to be:

  useEffect(() => draw({ data, onDataChange, width, height, d3ref }), [data, width, height])

and that seems to solve the problem. Now the graph only re-renders if the start and end dates change, or the number of points changes (this triggers a recalculation of data) or the window is resized (this updates width and height).

Also previous to this the graph is re-rendering on just about every event, not only focus events but all other kinds of events that are not related to this graph.

Happy to create a PR for this if it is agreed that this is the correct solution...

from covid19_scenarios.

petebacondarwin avatar petebacondarwin commented on June 17, 2024

Oops! Of course now the graph is not rendered correctly at application start up... :-(

from covid19_scenarios.

ivan-aksamentov avatar ivan-aksamentov commented on June 17, 2024

Regarding source maps: #94 (comment)

from covid19_scenarios.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.