Narrow screens

On a narrow screen Pele turns a left-to-right flowchart to run top to bottom instead of shrinking it. Drag the handle and watch the “smallest text” size above each frame.

Live demo: the same diagram on a narrowing screen

Drag the yellow handle to resize both phones, or focus it and use the arrow keys.

Pele smallest text –
Mermaid.js smallest text –

Screen width 390 px

What happens

The flowchart runs left to right, which suits a laptop and not a phone. Mermaid.js keeps the same drawing and scales it down to fit, so the text shrinks with it. Pele gets the width of the screen and, when the flowchart doesn't fit a narrow screen, turns the flow to run top to bottom instead, so the text stays at full size and you scroll down, the way you read a phone.

How to get this in your app

mount() does it for you: it watches the element's width and redraws when it changes. With render(), pass the width yourself:

render(text, { maxWidth: el.clientWidth })       // turn below 640 px (the default)
render(text, { maxWidth: el.clientWidth, directionBreakpoint: 360 }) // turn only below 360 px
render(text, { autoDirection: false })           // never turn

By default Pele turns the flow below 640 pixels. This demo sets directionBreakpoint: 360 so you can see both layouts with two phones side by side. The options are in the official API docs; responsive layouts on this site walks through them.

Loading the live demo…