Code Monkey home page Code Monkey logo

Comments (3)

flekschas avatar flekschas commented on August 15, 2024

The following code does not work because canvasRef is not a valid property.

createScatterplot({
  canvasRef,
  width: 20,
  height: 20,
  pointSize: 5,
});

See https://github.com/flekschas/regl-scatterplot#basic-example, you need to pass the actual canvas element to regl-scatterplot as the canvas property. Not a React ref object.

The following should work, however, make sure that canvasRef.current is truly a canvas element and not null!

createScatterplot({
  canvas: canvasRef.current,
  width: 20,
  height: 20,
  pointSize: 5,
});

Personally, I would probably implement the React component like this (be aware, I haven't tested the code below!):

const Component = ({ points }) => {
  const scatterplotRef = useRef();
  const refHandler = (canvas) => {
    if (!canvas) return;
    const scatterplot = createScatterplot({
      canvas,
      width: 20,
      height: 20,
      pointSize: 5,
    });
    scatterplot.draw(points);
    scatterplotRef.current = scatterplot;
    return () => {
       scatterplot.destroy();
       scatterplotRef.current = undefined;
    }
  }

  useEffect(() => {
    if (!scatterplotRef.current) return;
    scatterplotRef.current.draw(points);
  }, [points]);

  return <canvas ref={refHandler} />;
}

from regl-scatterplot.

armsp avatar armsp commented on August 15, 2024

Thank you so very much!

EDIT:
@flekschas It works when the data is hardcoded...as in making from let's say something like Math.Random.
When I load an array from a file...basically anything that returns a promise, then it fails to work. I do not get any error, just a blank screen. I have normalized my data like you said one other issue.

Any idea how to make it work so that works even with a promise?

from regl-scatterplot.

flekschas avatar flekschas commented on August 15, 2024

Please open a new ticket with a detailed description. The original issue seems to have been fixed.

My hunch is that you're passing a promise to regl-scatterplot instead of the real data. That's not supported. Simply wait until the promise is resolved first before attempting to call scatterplot.draw(). But I am just guessing here.

from regl-scatterplot.

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.