Comments (8)
@pierpo Thanks, works like a charm!
Really appreciate the quick response 💯
from react-archer.
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.
@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.
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.
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.
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.
I hadn't realized this before but wouldn't this solve your issue as well @Rambatino?
from react-archer.
@pierpo seems to!
Thanks!!
from react-archer.
Related Issues (20)
- Ability to set negative offset; HOT 1
- Suggest: Render order of paths HOT 1
- Problem in Creating Dynamic Archer Elements HOT 1
- `endShape` prop does not work properly `ArcherContainer`
- Arrows are disappearing when I click a button HOT 10
- Minified React error #321 in v4.0.0 HOT 13
- throttle on refreshScreen
- Not working with translate property HOT 3
- Is there any other way to add onClick event for each ArcherElement? HOT 2
- Cant access refs inside <ArcherElement> component HOT 2
- In a Next.js app when you go to a page via a <Link /> click the lines don't load, but when you refresh the page the lines work HOT 6
- Remix: react-archer seems to not be compatible with SSR HOT 4
- arrows don't re-render correctly HOT 4
- Feature request: Allow anchors to be placed absolutely or a percentage of total width/height HOT 1
- Support rotating boxes HOT 1
- ArcherContainer content container fixed height '100%' don't work on dynamic content HOT 2
- curved path between short distances HOT 4
- data.map => multiple ArcherElements cause the forwardRef error HOT 1
- Possibly a duplicate regarding flexDirection: row HOT 2
- Is this library support to draw from one box to multiple boxes?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-archer.