Create a gist now

Instantly share code, notes, and snippets.

labels
<!DOCTYPE>
<html>
<head>
<title>Labels demo</title>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
<script src="http://cytoscape.github.io/cytoscape.js/api/cytoscape.js-latest/cytoscape.min.js"></script>
<!-- for testing with local version of cytoscape.js -->
<!--<script src="../cytoscape.js/build/cytoscape.js"></script>-->
<style>
body {
font-family: helvetica, sans-serif;
font-size: 14px;
}
#cy {
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
z-index: 999;
}
h1 {
opacity: 0.5;
font-size: 1em;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', function(){
var cy = window.cy = cytoscape({
container: document.getElementById('cy'),
boxSelectionEnabled: false,
autounselectify: true,
layout: {
name: 'grid',
cols: 3
},
style: [
{
selector: 'node',
style: {
'height': 40,
'width': 40,
'background-color': '#ccc',
'label': 'data(label)'
}
},
{
selector: 'edge',
style: {
'label': 'data(label)',
'width': 3,
'line-color': '#ccc'
}
},
{
selector: '.top-left',
style: {
'text-valign': 'top',
'text-halign': 'left'
}
},
{
selector: '.top-center',
style: {
'text-valign': 'top',
'text-halign': 'center'
}
},
{
selector: '.top-right',
style: {
'text-valign': 'top',
'text-halign': 'right'
}
},
{
selector: '.center-left',
style: {
'text-valign': 'center',
'text-halign': 'left'
}
},
{
selector: '.center-center',
style: {
'text-valign': 'center',
'text-halign': 'center'
}
},
{
selector: '.center-right',
style: {
'text-valign': 'center',
'text-halign': 'right'
}
},
{
selector: '.bottom-left',
style: {
'text-valign': 'bottom',
'text-halign': 'left'
}
},
{
selector: '.bottom-center',
style: {
'text-valign': 'bottom',
'text-halign': 'center'
}
},
{
selector: '.bottom-right',
style: {
'text-valign': 'bottom',
'text-halign': 'right'
}
},
{
selector: '.multiline-manual',
style: {
'text-wrap': 'wrap'
}
},
{
selector: '.multiline-auto',
style: {
'text-wrap': 'wrap',
'text-max-width': 80
}
},
{
selector: '.autorotate',
style: {
'edge-text-rotation': 'autorotate'
}
},
{
selector: '.background',
style: {
'text-background-opacity': 1,
'text-background-color': '#ccc',
'text-background-shape': 'roundrectangle',
'text-border-color': '#000',
'text-border-width': 1,
'text-border-opacity': 1
}
},
{
selector: '.outline',
style: {
'text-outline-color': '#ccc',
'text-outline-width': 3
}
}
],
elements: [
{ data: { label: 'top left' }, classes: 'top-left' },
{ data: { label: 'top center' }, classes: 'top-center' },
{ data: { label: 'top right' }, classes: 'top-right' },
{ data: { label: 'center left' }, classes: 'center-left' },
{ data: { label: 'center center' }, classes: 'center-center' },
{ data: { label: 'center right' }, classes: 'center-right' },
{ data: { label: 'bottom left' }, classes: 'bottom-left' },
{ data: { label: 'bottom center' }, classes: 'bottom-center' },
{ data: { label: 'bottom right' }, classes: 'bottom-right' },
{ data: { label: 'multiline manual\nfoo\nbar\nbaz' }, classes: 'multiline-manual' },
{ data: { label: 'multiline auto foo bar baz' }, classes: 'multiline-auto' },
{ data: { label: 'outline' }, classes: 'outline' },
{ data: { id: 'ar-src' } },
{ data: { id: 'ar-tgt' } },
{ data: { source: 'ar-src', target: 'ar-tgt', label: 'autorotate (move my nodes)' }, classes: 'autorotate' },
{ data: { label: 'background' }, classes: 'background' }
]
});
});
</script>
</head>
<body>
<h1>Labels demo</h1>
<div id="cy"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment