Skip to content

Instantly share code, notes, and snippets.

@hnakamur hnakamur/index.html
Last active May 27, 2019

Embed
What would you like to do?
cytoscape network weathermap experiment
<!DOCTYPE>
<html>
<head>
<title>network weathermap demo using cytoscape.js</title>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
<script src="https://unpkg.com/cytoscape/dist/cytoscape.min.js"></script>
<script src="https://unpkg.com/cytoscape-automove@1.10.1/cytoscape-automove.js"></script>
<style>
#cy {
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 0;
z-index: 1;
}
</style>
</head>
<body>
<div id="cy"></div>
<script>
// document.addEventListener('DOMContentLoaded', function () {
var cy = cytoscape({
container: document.getElementById('cy'), // container to render in
elements: { // list of graph elements to start with
nodes: [
{ data: { id: 'a', label: 'コアルータ\n(core router)' }, position: { x: 50, y: 250 } },
{ data: { id: 'a2' }, classes: 'empty-joint' },
{ data: { id: 'b', label: 'ルータ\n(router)' }, position: { x: 550, y: 250 } },
{ data: { id: 'b2' }, classes: 'empty-joint' },
{ data: { id: 'c', label: 'スイッチ\n(switch)' }, position: { x: 300, y: 50 } },
{ data: { id: 'c2' }, classes: 'empty-joint' }
],
edges: [
{ data: { id: 'ab', source: 'a', target: 'a2', label: '139.14K', width: '13px', lineColor: '#B3EAD9' } },
{ data: { id: 'ab2', source: 'b', target: 'a2', label: '200.13K', width: '20px', lineColor: '#D1EAF8' } },
{ data: { id: 'bc', source: 'b', target: 'b2', label: '139.14K', width: '13px', lineColor: '#B3EAD9' } },
{ data: { id: 'bc2', source: 'c', target: 'b2', label: '200.13K', width: '20px', lineColor: '#D1EAF8' } },
{ data: { id: 'ca', source: 'c', target: 'c2', label: '139.14K', width: '13px', lineColor: '#B3EAD9' } },
{ data: { id: 'ca2', source: 'a', target: 'c2', label: '200.13K', width: '20px', lineColor: '#D1EAF8' } }
]
},
style: [ // the stylesheet for the graph
{
selector: 'node',
style: {
'background-color': '#666',
'content': 'data(id)'
}
},
{
selector: '.empty-joint',
style: {
'content': '',
'background-opacity': 0,
'width': '1px',
'height': '1px',
'border-width': 0
}
},
{
selector: 'edge',
style: {
'curve-style': 'bezier',
'width': 'data(width)',
'line-color': 'data(lineColor)',
'target-arrow-color': 'data(lineColor)',
'target-arrow-shape': 'triangle'
}
},
{
selector: 'node[label]',
style: {
'text-wrap': 'wrap',
'label': 'data(label)'
}
},
{
selector: 'edge[label]',
style: {
'label': 'data(label)',
'text-border-opacity': 1,
'text-border-color': '#000',
'text-border-width': '1px',
'text-background-padding': '4px',
'text-background-opacity': 1,
'text-background-color': '#FFF',
'text-background-shape': 'rectangle'
}
},
{
selector: '#a',
style: {
'shape': 'rectangle',
'background-opacity': 0,
'width': '72px',
'height': '69px',
'background-fit': 'cover cover',
'background-image': 'data:image/gif;base64,R0lGODlhSABFAPcAAAAMEAAUHBAUGBAYHCAUGAAkNDAUHCQcIBwgJAAsQAA4UABAWQBAXQBEZWkcKABMbXEgLDw8PABVeRBQbQBZgQRdhQBhjVBMTIE4SFBQUFlMUDxZZaEsQIk4TABxoVVVVRBtkRRtkV1VWVVZXa4wRAB5rrY4TGFhYQCFukxteWVlaSh9oWlpaQCNyn1hZc48Vb5EWcpAWTx9mTCBpRCNvgCV1jSFqnFxcRCRzt5AWRyRwuJAWXF1deJAXQiZ1jiJrt5EXeZAXTyJpXF5feZEYTyNsnl5eRCd1hCd2kCNsuZIYVWJnX19feZMZUSRtkiRrjyVuuJQaRyh2nGFkepQaUiVuoWFhepZcQC2/1WZtgS2/wi2/yyq3rZ1gUydzlmdvo2NjVWhwoGRpdptfRS6/zyu3lmlxuppgRi+/12lxkiu2iC+/+Zxhe5xhSjC/32ltp2dnaGdnVW64jTG/+59jbqVnYWuum220qWlpZ2qruaJmWW+5p2usu6JmZ2yvq6urp22vnHG5n3C3nHG6mXK9q6ytm3K7p26xp2+yra2tvKZqnHO8n3K6t6lrp3C0vKdrualsoXO6q7CxonO7o3O5oHS8o3O6onS8o3S6oXW9pHS7n3a/5HW8sbGxpnW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0BqFEF8ylqiqfMLbmqggk1CrsrGPEpuuuhx6HQgEIQpYCBMNGC8mxj22gZLKKeYAANoNE1oIB0UZLhBeawfELY6siWoMFEcT2xw3wxivvDRlwEG60esyrL7zLnTscr5o28IGMBDPxwr3DtkHwwnqmi5kKC8uoAcLDNhExwZIBDCcNF2PnAsXDdoxdJBljixjHImMTRw8g03pFyrF5iZjDiuEQWyyD5KzzzoN8EUPLs9LhCc9ED7IcLovRXDO3mXUAdBCgIJEZH8Cgq7G6iR0B4GgXRNHyGdholqLSoj0AWx0gExFbLruRvZnZvzXSxL1U9PKbv8h61+v+27Bhx0a0fRiIN2duR7ZA38wx4oMYqCjSxiOz2BKIDoK3gOnVTTb2moGM1Ekk5dj9YvlmhTumgBUGypGYnTXYHDoOpGP+mAWIKeAbdqqvbmXrMsJOO4h6a1rhL7anXiV7i7mO3QRMaAL8hHv/SHDuZu6OmPJJWm1yhTJSXz3yjB0RjIEyXxs8q9Jbrzv4jf2SfdKyE4idGo+xzpgC7/+7/f15nqg+YhbIA3Y656bzYY0xRNvakNiHQAUayoCZO439nlO603hAAgnAjgx+R50KiqYFhSBYs4QTnSSkInrC2YXxtkOcKriiIBE8jSSY4z0KSigNtTBIDE/DKWzU0IZaU7mDLg6yw9Ps4Yc2rIAghIGQIpanbTagRDIS4sQntoYTpNCGQlaRiS568YtgDKMYx0jGMnpRFdBYyDXWyMY2uvGNcIyjHOfYRi025I54zKMe98jHPvoRHAEBADs='
}
},
{
selector: '#a[label]',
style: {
'text-valign': 'bottom'
}
},
{
selector: '#b',
style: {
'shape': 'rectangle',
'background-opacity': 0,
'width': '60px',
'height': '35px',
'background-fit': 'cover cover',
'background-image': 'data:image/gif;base64,R0lGODlhPAAjAPcAAAAAAAAtPwUuPxA+UxBFWgBGYwBdgwBljwBtmwB3qAB4qgt+rwV7rQZ8rgB4qx+PvgCAtRWGtRuJtxCDsgCU0QCJwxCa0xCRxwCe4Au3/wC0/xu8/xC5/wCp7xW6/xC4/wW1/zx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NIceumkqC2YqUWZalxIASbBzqj2oRQIIDVq1cFvNhiKhQ3ld5OiSrCAcMISOzSsrslhYJUnUYwGVNLN23NGltGHROHsBsyRjNu2sBVN22uEm9vdijwpLDaSjY9cOmUzaA5VEek3nHMDg7UAwOaWLoJIUQkx3hu5El75eYGO8mMpvKQWMNgzmr1aFjcxrEyGzmH5OwSW6Aq2rVrIojDeZkGCpJQJ7/phZlAOskpoHijC/cHm3vU/v6ejlMGJ4FCyKtfH9WTQD7saxpwUu6WnAo3SUDZz59/FCpf1CaDe/f0gdx0GAwwSWGZ1EQAbs7gIVxtYBAYgR8H1tQBBDklIMIuhT0zYQIgchYHfrUhgQOBCkjQRxI48VIOHCZgUEBvhTXynYZurDNPIzfA8EthvSAW1QZ84KAAiwoskMMfSoBQkwW4sSOiTsDh9MEljsVxgWthAJKCAksKRCaZEogRyBIbaDAFZ5ScgCJ5Y6hTGDAgzMAHIDqcWeY9fpK5wA6ACBKGL7hBM0cM693GTjSLkLFKGWMGymSgZEagQxmO/GGGTDTFV9MGMzDBxyOAVMECpmdeyuqZ+hK0wMMgjnjyBx9neKQRRx6hwQcfq3gCSBk9pLDAq366iiymEqTggg/Q+lDFINSWEa0PP6SQAgPLvqpst+CGKy6Z345r7rmtmonuuusS2IAD8MYr77z01mvvvfg6AIRAhLDrr7gssCJQK5X+azCmDBSCjUDduKLCwRCTyUAa0hj1ihXHRuwvC4ZUbNA0mgQxgcbnsnAIK+YkVA81sKjhAsndRhDEJqzYUxQ3sXiCyA8SwCyxC1hsIgs1KRVFUDbVzOIJIWsUu8K6CzjrAyKb0BJLMEUbnZA31lzTyiueLJ1IIohcGy0WYydSiye2tBLLSVlrLffcdAsUEAAAOw=='
}
},
{
selector: '#b[label]',
style: {
'text-valign': 'bottom'
}
},
{
selector: '#c',
style: {
'shape': 'rectangle',
'background-opacity': 0,
'width': '78px',
'height': '33px',
'background-fit': 'cover cover',
'background-image': 'data:image/gif;base64,R0lGODlhTgAhAPcAAAAAAAASGQA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yY5oWHjyBDihxJsqRIDUZiUUrRweQHNVDWbNSYxoVJDxla3gTZoUCpn0CDCpW1rOgsMxNGfmCjwobMmQRrlnQwoESlNjs/9qRVtKvXr2CX1doEAqQLphBsQCXoxmbIDQoCHDFFdFXWjxtY2drLt+/eW1y91sL1CEZIF29UQEj7FKqbDyAjGDBhKZdXXUgya96s2UmIuxsOBN7VKgtJxBQWM14LB/LHGnTDygbr6q6IBrwIGy4ZI05q1U6hyhkhck6vr778Kt/7C9TdlrtvxqBTQfXi4BuHl4TBCdiyYHct/ogfT778AiOXTugsKYO69euNC9YhvhPIjKwEygjdD/RUV2FLYEBSEHZU995qBmlBQkkYMIDAE/fhV8psFBYVSybReRDEHQcCF59ACoqUgQICJFHKMMu8cpcHM7zi4oswvohKLGAR08oWZX0kBIcdXmcQFwviRKISmMziVSoJJKnkkko6sOIDZXRVDCxtfCbSEHn06CFBXYAkQhPGVFjhMVbuxAQyVJY50hBeaLmlQF2KNIMqyYgZFpkr3vVFm24udoMeAhFhEgh8KLNMKGAkquiijKqZZ0lhRNHnYiv0IZAYNGSq6aaaFsHpp6CGKmqoYUgxKQQt/CGQJIC06uqr1bDGKuustNba6iRXnNpCIAONwcGvwAYr7LDEFmvssb+SocOkOAxCkK/IRivttMMq2ycOhBQELbXcdkustVrmkK223pZrLrgd7lCIRtua66606L7HgyEbtfvuvcXGq9oUh8xkL74AA6svBFMgAtW/AQMcrwRUGHxwwhAnu+xiElTxIbsRQwzuBVUkspZACGd87rIXKOLxxwCELLK3ypaMcq8rK2zFIp+8LBAjPeSs88489+zzz0AHnXMjjthM0CgAIK100kwv7XTTUD8tddRUI+2J0QIFBAA7'
}
}
],
layout: {
name: 'preset'
}
});
cy.automove({
nodesMatching: cy.$('.empty-joint'),
reposition: 'mean',
meanOnSelfPosition: function( node ){ return false; }
});
// });
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.