Skip to content

Instantly share code, notes, and snippets.

@wasimaftab
Last active December 2, 2020 13:43
Show Gist options
  • Save wasimaftab/b76d3142c84c3a0839777cd0dc680409 to your computer and use it in GitHub Desktop.
Save wasimaftab/b76d3142c84c3a0839777cd0dc680409 to your computer and use it in GitHub Desktop.
Electron Fiddle Gist
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, minimal-ui">
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
<title>Test Cytoscape.js</title>
<!-- <script src="../jquery-3.5.1.min.js"></script> -->
<!-- <link rel="stylesheet" href="../bootstrap-4.0.0-dist/css/bootstrap.min.css"> -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<!-- <script src="https://unpkg.com/cytoscape@3.16.1/dist/cytoscape.min.js"></script>
<script src="https://unpkg.com/cytoscape-cola/cytoscape-cola.js"></script>
<script src="https://unpkg.com/file-saver@2.0.4/dist/FileSaver.js"></script> -->
</head>
<style>
#cy {
width: 100%;
height: 100%;
position: absolute;
/* position: relative; */
top: 0px;
left: 0px;
float: left;
}
#right {
position: relative;
}
#save_plot {
position: absolute;
right: 0;
bottom: 0;
}
</style>
<body>
<!-- Create a button, clicking which will show plots and tables -->
<div class="row pl-5 py-5 mt-10">
<button type="button" id="show_plot" class="btn btn-primary">Show</button>
</div>
<!-- Cytoscape graph -->
<div class="row">
<div class="col-lg-6">
<div class="card pl-2 py-2 mb-2" style="height: 50rem;">
<div class="card-body">
<div id="cy"></div>
</div>
<div id="right"></div>
</div>
</div>
</div>
<script src='./renderer.js'></script>
</body>
</html>
const {
app,
BrowserWindow
} = require('electron');
const path = require('path');
/* Reload app on changes */
// try {
// require('electron-reloader')(module)
// } catch (_) { }
function createWindow() {
// Create the browser window.
const win = new BrowserWindow({
// icon: path.join(__dirname, 'Images/cytoscape_cropped.png'),
width: 1000,
height: 800,
webPreferences: {
enableRemoteModule: true,
nodeIntegration: true,
webSecurity: false
}
})
// Load the index.html of the app.
// win.loadFile(path.join(__dirname, 'src/index.html'));
// win.loadFile(path.join(__dirname, 'src/index_jsbin.html'));
win.loadFile('index.html');
// Open the DevTools.
win.webContents.openDevTools()
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
// This method is equivalent to 'app.on('ready', function())'
app.whenReady().then(createWindow)
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// To stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
// On macOS it's common to re-create a window in the
// app when the dock icon is clicked and there are no
// other windows open.
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
// In this file, you can include the rest of your
// app's specific main process code. You can also
// put them in separate files and require them here.
/* Data for edges */
var source = [
"Itgb2",
"C2",
"Vav1",
"Mbl1",
"Mbl2",
"Syk",
"Sh3bp1",
"Ncf4",
"Sirpa",
"Adipoq",
"Gas6",
"Rab34",
"Ano6",
"Pld4",
"Arhgap25",
"Dock2",
"Nckap1l",
"Colec12",
"Myo18a",
"Flot1",
"Npc1",
"Egf",
"Itgb2",
"Dnm1",
"Cd63",
"Syk",
"Sh3bp1",
"Rock1",
"Sirpa",
"Apoc2",
"Esyt2",
"Heatr5a",
"Pla2r1",
"Siglec1",
"Rab34",
"Ehbp1",
"Inppl1",
"Ano6",
"Syne1",
"Wasf2",
"Rufy1",
"Snx17",
"Arhgap25",
"Dock2",
"Scyl2",
"Nckap1l",
"Colec12",
"Smap1",
"Ifitm3",
"Gtf2h2",
"Rabgef1",
"Prkcd",
"Map2k1",
"Syk",
"Hcls1",
"Apod",
"Rac2",
"Cd84",
"Prkaa1",
"Rbm27",
"Adipoq",
"Gas6",
"Rbm22",
"Ogt",
"Bag4",
"Reep2",
"Gripap1",
"Stx18",
"Vps11",
"Camk1",
"Rufy3",
"Borcs5",
"Xpo4",
"Sphk2",
"Bag3",
"Rabgef1",
"Pakap",
"Icam1",
"Prkcd",
"Hcls1",
"Sh3bp1",
"Pdlim4",
"Nrp1",
"Sirpa",
"Rac2",
"Arhgap17",
"Fscn1",
"Rhoc",
"Inppl1",
"Ppp1r9b",
"Wasf2",
"Arhgap25",
"Ppm1f",
"Bag4",
"Arhgap18",
"Nckap1l",
"Washc1",
"Brk1",
"Triobp",
"Rufy3",
"Gmfg",
"Plek",
"Col5a2",
"P3h1",
"Cyp1b1",
"Colgalt1",
"Emilin1",
"Dpt",
"Plod2",
"Plod3",
"Plod1",
"Sigmar1",
"Cd74",
"Mbl1",
"Adipoq",
"Ogt",
"Pnpt1",
"Brk1",
"Steap4",
"Emilin1",
"C2",
"Mbl1",
"Mbl2",
"Syk",
"Sirpa",
"Adipoq",
"Gas6",
"Ano6",
"Dock2",
"Nckap1l",
"Myo18a",
"Adam10",
"Stk10",
"Cd74",
"Itgb2",
"Icam1",
"Vav1",
"C5ar1",
"S100a9",
"Syk",
"Apod",
"Mpp1",
"Rock1",
"Sirpa",
"Rac2",
"Pla2g7",
"Fadd",
"Gas6",
"Ano6",
"Nckap1l",
"Emilin1",
"Mospd2",
"Rabgef1",
"Cd74",
"Itgb2",
"Apcs",
"Icam1",
"C1qb",
"Crp",
"C2",
"Vav1",
"Prkcd",
"Ptpn6",
"Mbl1",
"Mbl2",
"Msh2",
"Syk",
"Ctsh",
"Ctsc",
"Rac2",
"Cd84",
"Fadd",
"Inpp5d",
"Sphk2",
"Rabgef1",
"Adam10",
"Stk10",
"Cd74",
"Icam1",
"C5ar1",
"Apod",
"Mpp1",
"Rac2",
"Pla2g7",
"Fadd",
"Gas6",
"Ano6",
"Nckap1l",
"Emilin1",
"Mospd2",
"Rabgef1"
];
var target = [
"phagocytosis",
"phagocytosis",
"phagocytosis",
"phagocytosis",
"phagocytosis",
"phagocytosis",
"phagocytosis",
"phagocytosis",
"phagocytosis",
"phagocytosis",
"phagocytosis",
"phagocytosis",
"phagocytosis",
"phagocytosis",
"phagocytosis",
"phagocytosis",
"phagocytosis",
"phagocytosis",
"phagocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"endocytosis",
"regulation of intracellular transport",
"regulation of intracellular transport",
"regulation of intracellular transport",
"regulation of intracellular transport",
"regulation of intracellular transport",
"regulation of intracellular transport",
"regulation of intracellular transport",
"regulation of intracellular transport",
"regulation of intracellular transport",
"regulation of intracellular transport",
"regulation of intracellular transport",
"regulation of intracellular transport",
"regulation of intracellular transport",
"regulation of intracellular transport",
"regulation of intracellular transport",
"regulation of intracellular transport",
"regulation of intracellular transport",
"regulation of intracellular transport",
"regulation of intracellular transport",
"regulation of intracellular transport",
"regulation of intracellular transport",
"regulation of intracellular transport",
"regulation of intracellular transport",
"regulation of intracellular transport",
"regulation of intracellular transport",
"actin filament organization",
"actin filament organization",
"actin filament organization",
"actin filament organization",
"actin filament organization",
"actin filament organization",
"actin filament organization",
"actin filament organization",
"actin filament organization",
"actin filament organization",
"actin filament organization",
"actin filament organization",
"actin filament organization",
"actin filament organization",
"actin filament organization",
"actin filament organization",
"actin filament organization",
"actin filament organization",
"actin filament organization",
"actin filament organization",
"actin filament organization",
"actin filament organization",
"actin filament organization",
"actin filament organization",
"actin filament organization",
"actin filament organization",
"collagen fibril organization",
"collagen fibril organization",
"collagen fibril organization",
"collagen fibril organization",
"collagen fibril organization",
"collagen fibril organization",
"collagen fibril organization",
"collagen fibril organization",
"collagen fibril organization",
"protein trimerization",
"protein trimerization",
"protein trimerization",
"protein trimerization",
"protein trimerization",
"protein trimerization",
"protein trimerization",
"protein trimerization",
"protein trimerization",
"regulation of phagocytosis",
"regulation of phagocytosis",
"regulation of phagocytosis",
"regulation of phagocytosis",
"regulation of phagocytosis",
"regulation of phagocytosis",
"regulation of phagocytosis",
"regulation of phagocytosis",
"regulation of phagocytosis",
"regulation of phagocytosis",
"regulation of phagocytosis",
"leukocyte migration",
"leukocyte migration",
"leukocyte migration",
"leukocyte migration",
"leukocyte migration",
"leukocyte migration",
"leukocyte migration",
"leukocyte migration",
"leukocyte migration",
"leukocyte migration",
"leukocyte migration",
"leukocyte migration",
"leukocyte migration",
"leukocyte migration",
"leukocyte migration",
"leukocyte migration",
"leukocyte migration",
"leukocyte migration",
"leukocyte migration",
"leukocyte migration",
"leukocyte migration",
"leukocyte migration",
"leukocyte mediated immunity",
"leukocyte mediated immunity",
"leukocyte mediated immunity",
"leukocyte mediated immunity",
"leukocyte mediated immunity",
"leukocyte mediated immunity",
"leukocyte mediated immunity",
"leukocyte mediated immunity",
"leukocyte mediated immunity",
"leukocyte mediated immunity",
"leukocyte mediated immunity",
"leukocyte mediated immunity",
"leukocyte mediated immunity",
"leukocyte mediated immunity",
"leukocyte mediated immunity",
"leukocyte mediated immunity",
"leukocyte mediated immunity",
"leukocyte mediated immunity",
"leukocyte mediated immunity",
"leukocyte mediated immunity",
"leukocyte mediated immunity",
"leukocyte mediated immunity",
"regulation of leukocyte migration",
"regulation of leukocyte migration",
"regulation of leukocyte migration",
"regulation of leukocyte migration",
"regulation of leukocyte migration",
"regulation of leukocyte migration",
"regulation of leukocyte migration",
"regulation of leukocyte migration",
"regulation of leukocyte migration",
"regulation of leukocyte migration",
"regulation of leukocyte migration",
"regulation of leukocyte migration",
"regulation of leukocyte migration",
"regulation of leukocyte migration",
"regulation of leukocyte migration",
"regulation of leukocyte migration"
];
var weight = [
0.59375,
0.59375,
0.59375,
0.59375,
0.59375,
0.59375,
0.59375,
0.59375,
0.59375,
0.59375,
0.59375,
0.59375,
0.59375,
0.59375,
0.59375,
0.59375,
0.59375,
0.59375,
0.59375,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0.78125,
0.78125,
0.78125,
0.78125,
0.78125,
0.78125,
0.78125,
0.78125,
0.78125,
0.78125,
0.78125,
0.78125,
0.78125,
0.78125,
0.78125,
0.78125,
0.78125,
0.78125,
0.78125,
0.78125,
0.78125,
0.78125,
0.78125,
0.78125,
0.78125,
0.8125,
0.8125,
0.8125,
0.8125,
0.8125,
0.8125,
0.8125,
0.8125,
0.8125,
0.8125,
0.8125,
0.8125,
0.8125,
0.8125,
0.8125,
0.8125,
0.8125,
0.8125,
0.8125,
0.8125,
0.8125,
0.8125,
0.8125,
0.8125,
0.8125,
0.8125,
0.28125,
0.28125,
0.28125,
0.28125,
0.28125,
0.28125,
0.28125,
0.28125,
0.28125,
0.28125,
0.28125,
0.28125,
0.28125,
0.28125,
0.28125,
0.28125,
0.28125,
0.28125,
0.34375,
0.34375,
0.34375,
0.34375,
0.34375,
0.34375,
0.34375,
0.34375,
0.34375,
0.34375,
0.34375,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.6875,
0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
0.5
];
/* Data for nodes */
var mapped_count = [
19.3478260869565,
25,
21.9565217391304,
22.3913043478261,
15,
15,
15.8695652173913,
20.6521739130435,
20.6521739130435,
18.0434782608696
];
/* Data for legends */
var legend_label = [
9,
11,
32
];
var size = [
15,
15.8695652173913,
25
];
const cytoscape = require("cytoscape");
const cola = require('cytoscape-cola');
cytoscape.use(cola);
var FileSaver = require('file-saver');
document.getElementById('show_plot').addEventListener('click', function (e) {
var uniq_source = Array.from(new Set(source));
var uniq_target = Array.from(new Set(target));
/* Create node json for source*/
var arr_elems = [];
var gene_nodes_col = '#927E61';
var len = uniq_source.length;
for (var i = 0; i <= len - 1; i++) {
arr_elems.push({
group: 'nodes',
data: {
id: uniq_source[i],
label: uniq_source[i],
size: 8,
col: gene_nodes_col,
font_size: 10,
font_family: 'Arial, Helvetica, sans-serif',
font_wt: 'bold',
font_style: 'italic'
// border_col: '#E5C494'
// col: '#787878'
}
}
);
}
/* Create node json for target*/
len = uniq_target.length;
for (var i = 0; i <= len - 1; i++) {
arr_elems.push({
group: 'nodes',
data: {
id: uniq_target[i],
label: uniq_target[i],
size: mapped_count[i],
col: '#E5C494',
font_size: 14,
font_family: 'Arial, Helvetica, sans-serif',
font_wt: 'normal',
font_style: 'normal'
// border_col: gene_nodes_col
}
}
);
}
/* Create edges */
var ll = source.length;
for (var i = 0; i <= ll - 1; i++) {
// var my_source = source[i];
arr_elems.push({
group: 'edges',
data: {
source: source[i],
target: target[i],
weight: weight[i]
}
});
}
/* Create graph object */
var cy = window.cy = cytoscape({
container: document.getElementById('cy'),
boxSelectionEnabled: false,
autounselectify: true,
style: [
{
selector: 'node',
style: {
'label': 'data(label)',
'width': 'data(size)',
'height': 'data(size)',
// 'color': '#26221C',
'color': 'black',
'font-size': 'data(font_size)',
'font-family': 'data(font_family)',
'font-weight': 'data(font_wt)',
'font-style': 'data(font_style)',
'background-color': 'data(col)',
// 'border-color': '#26221C',
'border-color': 'black',
// 'border-color': 'data(border_col)',
'border-width': 1.5,
'background-fit': 'contain',
'background-clip': 'none'
}
},
{
selector: 'edge',
style: {
'curve-style': 'unbundled-bezier',
// 'curve-style': 'straight',
'width': 1.5,
'line-color': '#c4beb6',
// 'line-color': '#927e61',
}
},
{
selector: '#txt_node',
style: {
'label': 'data(label)',
"text-rotation": "autorotate",
"text-margin-x": "0px",
"text-margin-y": "25px",
'shape': 'rectangle',
'background-color': 'white',
'border-color': 'white',
// 'border-width': 1,
'font-size': 16,
"font-style": 'normal',
'font-family': 'Arial, Helvetica, sans-serif',
'font-weight': 'bold'
}
}
]
});
/* add the array of nodes and edges to the graph */
cy.add(arr_elems);
/* create layout and run */
cy.layout({
name: 'cola',
fit: true,
padding: 10,
animate: true,
nodeDimensionsIncludeLabels: true
}).run();
/* Resize and center graph with browser window resizing */
document.addEventListener('resize', function (event) {
cy.center();
cy.fit();
});
/* create a button to save the graph */
var save_button = document.createElement('button');
save_button.id = "save_plot";
save_button.type = "submit";
save_button.value = "Save";
var text = document.createTextNode("Save");
save_button.appendChild(text);
save_button.className = "btn btn-primary btn-sm";
save_button.onclick = function () {
// window.alert('save button was clicked');
FileSaver.saveAs(cy.png());
// return false;
};
document.getElementById("right").appendChild(save_button);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment