All versions of this documentation
X

Filter edges

Filters can be applied to filter edges from the graph. Filters use a function selector that returns a boolean indicating whether the edge should be visible (true) or filtered out (false). In the following example, we use the function ogma.transformation.createEdgeFilter to filter edges having a "properties.raised_amount_usd" data property with a value over 50000000. It returns an object that is can be used later to remove the filter by doing `filter.destroy()`.

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; }
  </style>
</head>
<body>
  <div id="graph-container"></div>
  <!-- we force the loading of the font awesome -->
  <i class="fa fa-camera-retro fa-1x" style="color: rgba(0,0,0,0);"></i>
<script>
'use strict';

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

ogma.parse.jsonFromUrl('files/solarCity.json').then(function(g) {
  ogma.setGraph(g);
  ogma.view.locateGraph();

  var filter;

  // Show edges with raised amount >= $50 millions
  // and hide all other edges, including
  // those which have not the raised_amount_usd property.
  setTimeout(function() {
    filter = ogma.transformations.addEdgeFilter(function (e) {
      return e.getData('properties.raised_amount_usd') > 50000000
    });

    filter.whenApplied(function () {
      console.log('Filter done!');
    });
  }, 1500);

  // Remove the previously created filter
  // filter.destroy();
});

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