Giter Club home page Giter Club logo

Comments (8)

dimapx avatar dimapx commented on May 30, 2024 1

@pierpo Thanks, works like a charm!
Really appreciate the quick response 💯

from react-archer.

pierpo avatar pierpo commented on May 30, 2024

Hi! Thank you for the issue.
I'll have a look at this in the coming days 😊

I'm not sure I understand it all, though. Is it only a TS definition problem or is the scrolling mechanism also an issue?

Could you give me the ideal code you would like to write to achieve this?

In any case, feel free to have a look at the TS definitions and make suggestions 😊

from react-archer.

Rambatino avatar Rambatino commented on May 30, 2024

@pierpo thanks for the quick reply!

It's more of a "how best do I go about doing this" issue. I feel like I've just hacked some code around - forceUpdate() I think is generally discouraged in react.

Also the ref issue is surprising as I would have assumed that ref would have been inherited from the react base component. But maybe not, but I'm no expert in react

I can get a simple demo in a couple of days for you if that would help.

Maybe an update method would be useful on the component itself?

from react-archer.

pierpo avatar pierpo commented on May 30, 2024

Indeed, I see what you mean 🤔
I'll think this through in the coming days. Maybe the update method would be a good option indeed.

Ideally this kind of updates should be handled by the library itself. I would appreciate the simple demo example so that I could experiment on the library's side 😊

from react-archer.

dimapx avatar dimapx commented on May 30, 2024

Hi @pierpo, I've just started out with react-archer and have a use case where I have multiple divs in a scrollable container pointing at a static div (which in turn would point to multiple other divs). While scrolling each of the two containers, the arrows remain static. I was wondering whether I was missing something, or is there a proper way to force the re-render of the arrows while scrolling?

Consider the following as an example -

import { ArcherContainer, ArcherElement } from 'react-archer';

const rowStyle = {
  display: 'flex',
  justifyContent: 'space-between',
}
const columnStyle = { 
  display: 'flex',
  flexDirection: 'column',
  justifyContent: 'flex-start',
  alignItems: 'center',
  width: '250px',
  padding: '15px',
  overflowY: 'auto',
  height: '300px'
}
const boxStyle = { 
  padding: '10px',
  marginTop: '15px',
  marginBottom: '15px',
  border: '1px solid black',
  display: 'flex',
  flexDirection: 'column',
  justifyContent: 'center',
  alignItems: 'center'
};

const strokeStyle = { strokeColor: 'gray', strokeWidth: 1 };

const App = () => {
  return (
    <div>
      <ArcherContainer>
        <div style={rowStyle}>
          <div style={columnStyle}>
            {Array(6).fill().map((val, i) => {
              return (<ArcherElement
                id={`source${(i)}`}
                relations={[{
                  targetId: 'centerElement',
                  targetAnchor: 'left',
                  sourceAnchor: 'right',
                  style: strokeStyle,
                }]}
              >
                <div style={boxStyle}>Source {i+1}</div>
              </ArcherElement>
            )
          })}
          </div>
            
          <div style={columnStyle}>
            <ArcherElement 
              id="centerElement"
              relations={
                Array(6).fill().map((val, i) => {
                  return ({
                    targetId: `target${i}`,
                    targetAnchor: 'left',
                    sourceAnchor: 'right',
                    style: strokeStyle,
                  })
                })                
              }
            >
              <div style={boxStyle}>Central Entity</div>
            </ArcherElement>
          </div>
          
          <div style={columnStyle}>
            {Array(6).fill().map((val, i) => {
                return (<ArcherElement id={`target${i}`}>
                  <div style={boxStyle}>Target {i+1}</div>
                </ArcherElement>
              );
            })}
          </div>

        </div>
      </ArcherContainer>
    </div>
  );
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

Thanks for the help.

from react-archer.

pierpo avatar pierpo commented on May 30, 2024

Hi @dimapx!

I just had a look and made it work. You can use the refreshScreen instance method of the ArcherContainer component 😊

(it is not documented because I wasn't expecting people to use it but this feels valid!)

Add <ArcherContainer ref={containerRef => { this.containerRef = containerRef }} />.
Then add an onScroll props to your scrolling divs, and in the callback function you may call this.containerRef.refreshScreen()!

<div onScroll={() => this.containerRef.refreshScreen()} />

Here's the working code:

import React from 'react';
import ReactDOM from 'react-dom';
import { ArcherContainer, ArcherElement } from 'react-archer';

const rowStyle = {
  display: 'flex',
  justifyContent: 'space-between',
};
const columnStyle = {
  display: 'flex',
  flexDirection: 'column',
  justifyContent: 'flex-start',
  alignItems: 'center',
  width: '250px',
  padding: '15px',
  overflowY: 'auto',
  height: '300px',
};
const boxStyle = {
  padding: '10px',
  marginTop: '15px',
  marginBottom: '15px',
  border: '1px solid black',
  display: 'flex',
  flexDirection: 'column',
  justifyContent: 'center',
  alignItems: 'center',
};

const strokeStyle = { strokeColor: 'gray', strokeWidth: 1 };

class App extends React.Component {
  handleScroll = () => {
    this.myRef.refreshScreen();
  };

  render() {
    return (
      <div>
        <ArcherContainer
          ref={myRef => {
            this.myRef = myRef;
          }}
        >
          <div style={rowStyle} onScroll={this.handleScroll}>
            <div style={columnStyle}>
              {Array(6)
                .fill()
                .map((val, i) => {
                  return (
                    <ArcherElement
                      id={`source${i}`}
                      relations={[
                        {
                          targetId: 'centerElement',
                          targetAnchor: 'left',
                          sourceAnchor: 'right',
                          style: strokeStyle,
                        },
                      ]}
                    >
                      <div style={boxStyle}>Source {i + 1}</div>
                    </ArcherElement>
                  );
                })}
            </div>

            <div style={columnStyle}>
              <ArcherElement
                id="centerElement"
                relations={Array(6)
                  .fill()
                  .map((val, i) => {
                    return {
                      targetId: `target${i}`,
                      targetAnchor: 'left',
                      sourceAnchor: 'right',
                      style: strokeStyle,
                    };
                  })}
              >
                <div style={boxStyle}>Central Entity</div>
              </ArcherElement>
            </div>

            <div style={columnStyle}>
              {Array(6)
                .fill()
                .map((val, i) => {
                  return (
                    <ArcherElement id={`target${i}`}>
                      <div style={boxStyle}>Target {i + 1}</div>
                    </ArcherElement>
                  );
                })}
            </div>
          </div>
        </ArcherContainer>
      </div>
    );
  }
}

const rootElement = document.getElementById('root');

ReactDOM.render(<App />, rootElement);

from react-archer.

pierpo avatar pierpo commented on May 30, 2024

I hadn't realized this before but wouldn't this solve your issue as well @Rambatino?

from react-archer.

Rambatino avatar Rambatino commented on May 30, 2024

@pierpo seems to!

Thanks!!

from react-archer.

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.