Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Responsive diagram in React (Read 242 times)
Kamil
YaBB Newbies
*
Offline



Posts: 12
Joined: Aug 22nd, 2024
Responsive diagram in React
Aug 22nd, 2024 at 10:55am
Print Post  
Hello,
I have 2 questions:

1. Could you advise me on how configure a diagarm in React so that it always fits its container. I'm working on a responsive design, so I can't provide fixed values like this:

Code (Javascript)
Select All
        <DiagramView style={{
            width: someFixedValue,
            height: someFixedValue,
        }} diagram={diagram} /> 



2. I've prepared a simple live demo of a diagram in react: stackblitz.com/edit/react-enmzzg

After I resize the panel with the rendered result, the diagram increases its height automatically (which is a bit unexpected for me). Is this some kind of bug?
Attached images shows how the diagram changes on my PC.

  

before-resize.png ( 11 KB | 21 Downloads )
before-resize.png
after-resize.png ( 13 KB | 21 Downloads )
after-resize.png
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Online


tech.support

Posts: 3248
Joined: Oct 19th, 2005
Re: Responsive diagram in React
Reply #1 - Aug 22nd, 2024 at 1:33pm
Print Post  
Hi,

DiagramView default values if you don't set width and height are 100%, so the view just fills whatever size its container has. The 100% value requires a fixed size somewhere up in the DOM tree, and this website's preview pane seems growing to fit contents, modifying the view's height along. You could use vh units to fix either the container's or view's own height to stop them from growing, while keeping them anchored to browser's size. E.g. this modification of your snippet seems to work:

Code
Select All
  const divStyle = {
    width: '100%',
    height: '98vh',
  };
  return (
    <div className="container" style={divStyle}>
      <DiagramView diagram={diagram} behavior={mfDiagram.Behavior.LinkShapes} />
    </div>
  ); 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Kamil
YaBB Newbies
*
Offline



Posts: 12
Joined: Aug 22nd, 2024
Re: Responsive diagram in React
Reply #2 - Aug 27th, 2024 at 7:44am
Print Post  
Thank you for your answer. It helped me a lot.

My application has a responsive layout and there are multiple elements that resize along with the window (sidebar, navbar, footer). The only solution that I've come up with is keeping a references to all this elements in the state of the application and updating the diagram like this whenever they are being rerendered:


Code (CSS)
Select All
/* Diagram container */
/* 300px is a width of the sidebar (in my application I compute it dynamically instead of passing a fixed value in px */
.container {
  background-color: pink;
  width: calc(100% - 300px);
  height: 98vh;
} 



Live demo with sidebar: https://stackblitz.com/edit/react-akyaxw?file=package.json,src%2FApp.js,src%2Fst
yle.css

It seems like quite a hack for a very simple use case. Maybe it looks quite simple in the demo, but it gets more complex when there are multiple elements that are responsive on the page.

Is there any chance of making the mindfusion diagram component responsive by default in the future?
« Last Edit: Aug 27th, 2024 at 9:54am by Kamil »  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Online


tech.support

Posts: 3248
Joined: Oct 19th, 2005
Re: Responsive diagram in React
Reply #3 - Aug 27th, 2024 at 12:32pm
Print Post  
Hi,

Maybe a CSS grid with 1fr unit for the diagram view would work better for you (fr designates a fraction of remaining space in the grid). Please check attached layout example. It sets outer grid div to fill the window via 0 bottom and right absolute positions, has sidebar in auto column to fit content width, header in auto row to fit height, and the diagram view fills all remaining space of the browser's viewport.

Quote:
Is there any chance of making the mindfusion diagram component responsive by default in the future?


We aren't sure how a reusable component with no intrinsic size could become more responsive than filling its container div/panel, but will review it for next release.

Regards,
Slavcho
Mindfusion
  

Grid.zip ( 495 KB | 14 Downloads )
Back to top
 
IP Logged
 
Kamil
YaBB Newbies
*
Offline



Posts: 12
Joined: Aug 22nd, 2024
Re: Responsive diagram in React
Reply #4 - Aug 28th, 2024 at 8:46am
Print Post  
Thanks! Your approach looks way easier than mine Smiley
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint