Git Product home page Git Product logo

react-ngl's Introduction

react-ngl

Jobs npm Contributors Forks Stargazers Issues MIT License


React NGL

React wrapper for NGL
Explore the docs »

View Demo · Report Bug · Request Feature

About The Project

React NGL Screen Shot

react-ngl is a React wrapper for NGL.

Built With

  • ngl >= v2.0.0-dev.37
  • node >= 12.16.0
  • react ^16.13.1

Getting Started

To get a local copy up and running follow these simple steps.

Prerequisites

This is an example of how to list things you need to use the software and how to install them.

  • npm
npm install react-ngl

Installation

  1. Clone the repo
git clone https://github.com/gky360/react-ngl.git
  1. Install NPM packages
npm install

Usage

A minimal example of using react-ngl is as follows.

import React from 'react';
import { Stage, Component } from 'react-ngl';

ReactDOM.render(
  <Stage width="600px" height="400px">
    <Component path="rcsb://4hhb" reprList={reprList} />
  </Stage>,
  document.getElementById('app')
);

For more examples, please refer to the Demo

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Project Link: https://github.com/gky360/react-ngl

Acknowledgements

react-ngl's People

Contributors

cmdcolin avatar dahyorr avatar dependabot[bot] avatar gky360 avatar mirimcz avatar szabatek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-ngl's Issues

React testing library render() fails when rendering NGL stage

When attempting to test an app that contains React NGL <Stage/> using React testing library, render() operation fails with error TypeError: Cannot read property 'setParameters' of undefined

See minimal reproduction based on create-react-app and the basic NGL React example here

`
TypeError: Cannot read property 'setParameters' of undefined

  3 |
  4 | test('renders react ngl app', () => {
> 5 |   render(<App />);
    |   ^
  6 |   expect(screen.getByRole('app')).toBeTruthy();
  7 | });
  8 |

  at E_.setParameters (node_modules/ngl/dist/ngl.js:1:1012424)
  at node_modules/react-ngl/src/components/Stage/Stage.tsx:78:13
  at invokePassiveEffectCreate (node_modules/react-dom/cjs/react-dom.development.js:23487:20)
  at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:3945:14)
  at HTMLUnknownElement.callTheUserObjectsOperation (node_modules/jsdom/lib/jsdom/living/generated/EventListener.js:26:30)
  at innerInvokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:338:25)
  at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:274:3)
  at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:221:9)
  at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:94:17)
  at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:231:34)
  at Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:3994:16)
  at invokeGuardedCallback (node_modules/react-dom/cjs/react-dom.development.js:4056:31)
  at flushPassiveEffectsImpl (node_modules/react-dom/cjs/react-dom.development.js:23574:9)
  at unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:468:12)
  at runWithPriority$1 (node_modules/react-dom/cjs/react-dom.development.js:11276:10)
  at flushPassiveEffects (node_modules/react-dom/cjs/react-dom.development.js:23447:14)
  at Object.<anonymous>.flushWork (node_modules/react-dom/cjs/react-dom-test-utils.development.js:992:10)
  at act (node_modules/react-dom/cjs/react-dom-test-utils.development.js:1107:9)
  at render (node_modules/@testing-library/react/dist/pure.js:97:26)
  at Object.<anonymous> (src/App.test.js:5:3)
  at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13)
  at runJest (node_modules/@jest/core/build/runJest.js:404:19)

`

can't toggle between structures

Hi, this is maybe more of a question than an issue, but I'm not sure how to resolve this.

Basically, my use case is this: I would like to toggle between the known structure of a protein (which exists as a PDB file), and a predicted structure (another PDB file).

I want to allow the user to select which version of the structure to view in the same component (as there may be many predictions, and I don't want to have too many structure viewers on the page).

What I have tried is something similar to the following:

export default function StructureViewer(props) {

  const [selectedStructure, setSelectedStructure] = useState('');
  const [path, setPath] = useState(null);
  const structureBlobs = {'known': new Blob(), 'predicted': new Blob()}; // in the actual code these are real blobs
  const availableStructures = ['known', 'predicted'];

  useEffect(() => {
    setPath(structureBlobs[selectedStructure]);
  }, [selectedStructure])


  const handleStructureInputChange = (event) => {
    setSelectedStructure(event.target.value);
  }

...

  return (
      <AutoSizer disableHeight>
          <Stage
            height={'300px'}
            width={width}
            params={{
              backgroundColor: '#f5f5f5',
              quality: 'low',
              ...stageParams,
            }}
            cameraState={{}}
          >
            <Component
              path={path}
              reprList={reprList}
              transform={viewerControls}
              loadFileParams={loadFileParams}
            />
          </Stage>
      </AutoSizer>

      <label>Select which structure to view:</label>
      <br/>
      <select name='structure' onChange={handleStructureInputChange}>
        {
          availableStructures.map( (structureName) =>
            <option
              key={structureName.toLowerCase()}
              value={structureName.toLowerCase()}
            >
              {structureName}
            </option>
          )
        }
      </select>
  )
}

This works just fine for viewing the structure at first, but when I select a new structure and change the value of structureName (which changes path), instead of clearing the previous structure and displaying the new one, it superimposes them!

This may be an interesting feature in the future, but for now it's not the desired behavior. Looking at the Component class, it looks like when path updates, it should trigger a re-render here:

  useAsyncEffect(
    function* loadFile(setCancelHandler, c) {
      const abortController = new AbortController();
      setCancelHandler(() => abortController.abort());
      let nextComponent: NGL.Component | undefined;
      try {
        nextComponent = (yield* c(stage.loadFile(path, loadFileParams))) as
          | NGL.Component
          | undefined;
      } catch (error) {
        if (onLoadFailure) {
          onLoadFailure(error);
        }
      }
      if (nextComponent) {
        setComponent(nextComponent);
      }
    },
    [loadFileParams, onLoadFailure, path, stage]
  );

does setComponent(nextComponent) not clear the current component? or is there an easy workaround?

would love any help, and thank you in advance!

Can't use defaultRepresentation

Hi! Thank you for making this wrapper, it's super useful!

I'm not sure about this, but I think there's an issue with how representations are handled when

{ defaultRepresentation: true }

is passed into loadFileParams for Component. The behavior is that the structure briefly flashes on screen (with the expected colorful defaultRepresentation) before disappearing, leaving just an empty Stage.

From briefly browsing around, I think what happens is that when the Component instance is created and this runs:

  useEffect(() => {
    if (component) {
      component.removeAllRepresentations();
      reprList.forEach((repr) =>
        component.addRepresentation(repr.type, repr.params)
      );
    }
  }, [component, reprList]);

whatever representation was created from the first flag passed into loadFileParams is cleared out and it causes an empty Stage. I don't know if that's how it works under the hood, but I suspect that that may be the case.

I haven't tested this, but I think that changing the above to:

  useEffect(() => {
    if (component && reprList.length > 0) {
      component.removeAllRepresentations();
      reprList.forEach((repr) =>
        component.addRepresentation(repr.type, repr.params)
      );
    }
  }, [component, reprList]);

would allow for the defaultRepresentation flag to work as long as a reprList prop weren't passed in to Component.

Let me know what you think!

Typescript error in `nglTypes.d.ts` when using `typescript@latest`

I'm trying to include react-ngl in a React Typescript project and I'm getting this:

Declaration or statement expected.  TS1128

    1 | export * from 'ngl';
    2 | export { Matrix3, Matrix4, Vector2, Vector3, Box3, Quaternion, Euler, Plane, Color, } from 'three';
  > 3 | export type { StageParameters } from 'ngl/declarations/stage/stage';
      | ^
    4 | export type { ComponentParameters } from 'ngl/declarations/component/component';
    5 | export type { StructureRepresentationType } from 'ngl/declarations/component/structure-component';
    6 | export type { SurfaceRepresentationType } from 'ngl/declarations/component/surface-component';

If I set my typsecript version to 3.8, then the problem goes away.

How to use a hover signal?

Hi there

I was interested in using ngl with react and this looked like a great library. I wasn't sure how I could add a custom hover signal though.

Something similar to interactive/hover-tooltip https://nglviewer.org/ngl/gallery/index.html

The aim is not necessarily to do a custom tooltip but just make a custom listener for what atom is being moused over

Typescript error with Components inside Stage

i get error "Type '{ children: Element; width: string; height: string; params: { backgroundColor: string; }; }' is not assignable to type 'IntrinsicAttributes & StageProps'.
Property 'children' does not exist on type 'IntrinsicAttributes & StageProps'.ts(2322)
(alias) const Stage: React.FC

It means, that in props of scene we don't have field children

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.