Last active
June 13, 2018 17:02
-
-
Save xeviknal/62705b8a89f8d6135d69798804c7fa7c to your computer and use it in GitHub Desktop.
Adding a icon into cytoscape graph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetch('cy-style.json', {mode: 'no-cors'}) | |
.then(function(res) { | |
return res.json() | |
}) | |
.then(function(style) { | |
var cy = window.cy = cytoscape({ | |
container: document.getElementById('cy'), | |
boxSelectionEnabled: false, | |
autounselectify: true, | |
layout: { | |
name: 'grid', | |
cols: 3 | |
}, | |
style: style, | |
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: '\uf2bb' }, classes: 'autorotate' }, | |
{ data: { label: 'background' }, classes: 'background' } | |
] | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"selector": "node", | |
"style": { | |
"height": 40, | |
"width": 40, | |
"background-color": "#ccc", | |
"label": "data(label)" | |
} | |
}, | |
{ | |
"selector": "edge", | |
"style": { | |
"label": "data(label)", | |
"width": 3, | |
"text-wrap": "wrap", | |
"font-family": "font-awesome, helvetica", | |
"line-color": "#000" | |
} | |
}, | |
{ | |
"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 | |
} | |
} | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE> | |
<!-- This code is for demonstration purposes only. You should not hotlink to Github, Rawgit, or files from the Cytoscape.js documentation in your production apps. --> | |
<html> | |
<head> | |
<title>Labels demo</title> | |
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1"> | |
<link href="style.css" rel="stylesheet" /> | |
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous"> | |
<!-- For loading external data files --> | |
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=Promise,fetch"></script> | |
<script src="http://js.cytoscape.org/js/cytoscape.min.js"></script> | |
<!-- for testing with local version of cytoscape.js --> | |
<!--<script src="../cytoscape.js/build/cytoscape.js"></script>--> | |
</head> | |
<body> | |
<h1>Labels demo</h1> | |
<div id="cy"></div> | |
<!-- Load application code at the end to ensure DOM is loaded --> | |
<script src="code.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment