All versions of this documentation
X

Camera

Zoom in and out by scrolling or double-click. Pan the view by dragging with the left button of the mouse. Rotate the view by dragging with the right button of the mouse.

Open in a new window.
          <!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <link href="fonts/font-awesome/css/font-awesome.min.css" rel="stylesheet">
  <script src="../build/ogma.min.js"></script>
  <style>
    #graph-container { top: 0; bottom: 0; left: 0; right: 0; position: absolute; margin: 0; overflow: hidden; }

    .btn {
      display: inline-block;
      padding: 6px 12px;
      margin-bottom: 0;
      font-size: 14px;
      font-weight: 400;
      line-height: 1.42857143;
      text-align: center;
      white-space: nowrap;
      vertical-align: middle;
      cursor: pointer;
      -webkit-user-select: none;
      -moz-user-select: none;
      -ms-user-select: none;
      user-select: none;
      border: 1px solid transparent;
      border-radius: 4px;
    }
    .btn.focus, .btn:focus, .btn:hover {
      color: #333;
      text-decoration: none;
    }

    .btn-default {
      color: #333;
      background-color: #fff;
      border-color: #ccc;
    }
    .btn-default:hover {
      color: #333;
      background-color: #e6e6e6;
      border-color: #adadad;
    }

    .btn-group-vertical {
      position: relative;
      display: inline-block;
      vertical-align: middle;
    }

    .btn-group-vertical > .btn {
      border: 0;
      padding: 6px 10px;
      position: relative;
      display: block;
      float: none;
      width: 100%;
      max-width: 100%;
    }
    .btn-group-vertical >.btn:not(:first-child):not(:last-child) {
      border-radius: 0;
    }
    .btn-group-vertical > .btn:focus {
      background-color: #ffffff;
      outline: none;
    }
    .btn-group-vertical > .btn.active {
      background-color: #cccccc;
    }

    #viewController {
      position: absolute;
      bottom: 10px;
      right: 10px;
      border-radius: 4px;
      background-color: #ffffff;
      box-shadow: 0 1px 6px rgba(0, 0, 0, 0.16), 0 1px 6px rgba(0, 0, 0, 0.23);
    }

  </style>
</head>
<body>
  <div id="graph-container"></div>

  <div id="viewController" class="btn-group-vertical">
    <button type="button" class="btn btn-default" onclick="zoomReset();" title="Zoom In">
      <i class="fa fa-home"></i>
    </button>
    <button type="button" class="btn btn-default" onclick="locateRandomNode();" title="Locate random node">
      <i class="fa fa-location-arrow"></i>
    </button>
    <button type="button" class="btn btn-default" onclick="zoomIn();" title="Zoom In">
      <i class="fa fa-plus"></i>
    </button>
    <button type="button" class="btn btn-default" onclick="zoomOut();" title="Zoom Out">
      <i class="fa fa-minus"></i>
    </button>
    <button type="button" class="btn btn-default" onclick="rotateLeft();" title="Rotate Left">
      <i class="fa fa-rotate-left"></i>
    </button>
    <button type="button" class="btn btn-default" onclick="rotateRight();" title="Rotate Right">
      <i class="fa fa-rotate-right"></i>
    </button>
  </div>
<script>
'use strict';

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

ogma.generate.erdosRenyi({
  nodes : 50,
  p: 0.1
}).then(function(g) {
  ogma.setGraph(g);
  ogma.view.locateGraph();
});

ogma.setOptions({
  interactions: { zoom: { onDoubleClick: true } }
});

function zoomReset() {
  ogma.view.locateGraph({
    easing: 'linear',
    duration: 300,
    // padding: { right: 100 }
  });
}

function zoomIn() {
  ogma.view.zoomIn({ duration: 200 }).then(function() { console.log('zoom done') });
}

function zoomOut() {
  ogma.view.zoomOut({ duration: 200 }).then(function() { console.log('zoom done') });
}

function locateRandomNode() {
  ogma.getNode('0').locate({ duration: 600 });
}

function locateRandomEdge() {
  ogma.getEdge('0').locate({ duration: 600 });
}

function rotateLeft() {
  // angle in radian
  ogma.view.rotate(Math.PI/2, { duration:600 }).then(function() { console.log('rotation done') });
}

function rotateRight() {
  // angle in radian
  ogma.view.rotate(-Math.PI/2, { duration:600 }).then(function() { console.log('rotation done') });
}

</script>
</body>
</html>