Skip to content
  1. Examples

Multiline

This example shows how to display multiline texts on nodes and edges.

ts
import Ogma from '@linkurious/ogma';

const content =
  'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.';

const ogma = new Ogma({
  container: 'graph-container'
});

// Disable text hover effect and text overlap detection for the example:
ogma.setOptions({
  detect: { nodeTexts: false },
  texts: { preventOverlap: true }
});

ogma.styles.addNodeRule({
  text: {
    content,
    backgroundColor: '#eee',
    size: 12,
    minVisibleSize: 0,
    maxLineLength: 40
  }
});

ogma.generate
  .random({ nodes: 5, edges: 0 })
  .then(g => ogma.setGraph(g))
  .then(() => ogma.layouts.force({ charge: 500, locate: true }));
html
<!doctype html>
<html>
  <head>
    <meta charset="utf-8" />

    <link type="text/css" rel="stylesheet" href="styles.css" />
  </head>

  <body>
    <div id="graph-container"></div>
    <script type="module" src="index.ts"></script>
  </body>
</html>
css
#graph-container {
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  position: absolute;
  margin: 0;
  overflow: hidden;
}