Click
Open in a new window.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!--<script src="../build/ogma.min.js"></script>-->
<script src="../build/ogma.min.js"></script>
<style>
#graph-container { top: 0; bottom: 0; left: 0; right: 0; position: absolute; margin: 0; overflow: hidden; }
.info {
position: absolute;
color: #fff;
background: #141229;
font-size: 12px;
font-family: monospace;
padding: 5px;
}
</style>
</head>
<body>
<div id="graph-container"></div>
<div id="info" class="info"></div>
<script>
'use strict';
var ogma = new Ogma({
container: 'graph-container'
});
ogma.events.onClick(function (evt) {
var target = evt.target,
button = evt.button, // can be "left", "middle" or "right"
x = evt.x,
y = evt.y;
var clickTarget;
if (!target) {
clickTarget = 'background';
} else {
clickTarget = (target.isNode ? 'node' : 'edge') + ' ' + target.getId();
}
document.getElementById('info').textContent =
clickTarget + ' clicked ' + button + ' at (' + x + ',' + y + ')';
});
ogma.generate.random({ nodes: 5, edges:10 }).then(function(g) {
ogma.setGraph(g);
ogma.view.locateGraph();
});
ogma.styles.addNodeRule({
text: {
content: function (n) { return 'Node ' + n.getId(); }
}
});
ogma.styles.addEdgeRule({
text: {
content: function (e) { return 'Edge ' + e.getId(); }
}
});
</script>
</body>
</html>