Comparing version 0.2.1 to 0.3.0
154
index.js
@@ -1,8 +0,6 @@ | ||
#!/usr/bin/env node | ||
// Deps imports: | ||
const yargs = require("yargs"); | ||
const seedrandom = require("seedrandom"); | ||
// Local imports: | ||
const DEFAULTS = require("./defaults"); | ||
const layoutFn = require("./layout"); | ||
@@ -15,100 +13,72 @@ const colorizeFn = require("./colorize"); | ||
const defaultColorizeKey = colorizeFn.DEFAULT_ATTRIBUTE_KEY; | ||
const defaultMapSizesKey = mapSizesFn.DEFAULT_ATTRIBUTE_KEY; | ||
function validateParams(params) { | ||
if (!params.sourcePath) | ||
throw new Error("net-to-img: expecting a `sourcePath`!"); | ||
const argv = yargs | ||
// Main parameters: | ||
.usage("Usage: $0 [OPTIONS] SOURCE DEST") | ||
.demandCommand(2, 2) | ||
.describe( | ||
"SOURCE", | ||
"Path of the input graph file (accepts .GEXF, .GRAPHML and .JSON files only)" | ||
) | ||
.describe("DEST", "Path of the output file (only .PNG supported yet)") | ||
// Options: | ||
.options({ | ||
layout: { | ||
alias: "l", | ||
description: "Randomizes layout and applies ForceAtlas 2", | ||
default: true | ||
}, | ||
steps: { | ||
alias: "s", | ||
description: "Number of ForceAtlas 2 iterations to perform", | ||
default: 100 | ||
}, | ||
colorize: { | ||
alias: "c", | ||
description: | ||
"Maps an attribute values to node colors. Uses Louvain communities by default. Use --no-colorize or --no-c to preserve node colors.", | ||
default: defaultColorizeKey | ||
}, | ||
"map-sizes": { | ||
alias: "m", | ||
description: | ||
"Maps an attribute values to node sizes. Uses betweenness centrality by default. Use --no-map-sizes or --no-m to preserve node sizes.", | ||
default: defaultMapSizesKey | ||
}, | ||
seed: { | ||
description: 'A seed for RNG (set it to "" or use --no-seed to unset it)', | ||
default: "net-to-img" | ||
}, | ||
width: { | ||
alias: "w", | ||
description: "Width of the output image", | ||
default: 2048 | ||
}, | ||
height: { | ||
alias: "h", | ||
description: "height of the output image", | ||
default: 2048 | ||
} | ||
}).argv; | ||
if (!params.destPath) throw new Error("net-to-img: expecting a `destPath`!"); | ||
} | ||
// Arguments and options: | ||
const [sourcePath, destPath] = argv._; | ||
const { steps, width, height, colorize, layout } = argv; | ||
const mapSizes = argv["map-sizes"]; | ||
const seed = argv.seed || undefined; | ||
module.exports = function netToImg(params, callback) { | ||
let options = params.options || {}; | ||
options = Object.assign({}, DEFAULTS, options); | ||
// Actual program: | ||
loadGraphFn({ sourcePath }, function(err, graph) { | ||
if (err) throw new Error(err); | ||
validateParams(params); | ||
// Randomness and seeds: | ||
if (seed) { | ||
seedrandom(seed, { global: true }); | ||
} | ||
// Extracting options | ||
const { sourcePath, destPath } = params; | ||
const { | ||
steps, | ||
width, | ||
height, | ||
colorize, | ||
mapSizes, | ||
layout, | ||
seed = undefined, | ||
} = options; | ||
// Graph treatments: | ||
if (colorize !== false) { | ||
graph = colorizeFn(graph, { attributeKey: colorize, seed }); | ||
} | ||
// Actual program: | ||
loadGraphFn({ sourcePath }, function (err, graph) { | ||
if (err) throw new Error(err); | ||
if (mapSizes !== false) { | ||
graph = mapSizesFn(graph, { attributeKey: mapSizes }); | ||
} | ||
// Randomness and seeds: | ||
if (seed) { | ||
seedrandom(seed, { global: true }); | ||
} | ||
if (layout !== false) { | ||
graph = layoutFn(graph, { | ||
steps, | ||
seed, | ||
groupByAttributeKey: colorize === defaultColorizeKey && colorize | ||
}); | ||
} | ||
// Graph treatments: | ||
if (colorize !== false) { | ||
graph = colorizeFn(graph, { attributeKey: colorize, seed }); | ||
} | ||
graph = normalizeFn(graph); | ||
if (mapSizes !== false) { | ||
graph = mapSizesFn(graph, { attributeKey: mapSizes }); | ||
} | ||
// Render and save img file: | ||
saveImageFn( | ||
graph, | ||
destPath, | ||
{ | ||
width, | ||
height | ||
}, | ||
() => { | ||
// Process ended (callback is mandatory...) | ||
if (layout !== false) { | ||
graph = layoutFn(graph, { | ||
steps, | ||
seed, | ||
groupByAttributeKey: colorize === DEFAULTS.colorize && colorize, | ||
}); | ||
} | ||
); | ||
}); | ||
graph = normalizeFn(graph); | ||
// Render and save img file: | ||
saveImageFn( | ||
graph, | ||
destPath, | ||
{ | ||
width, | ||
height, | ||
}, | ||
(err) => { | ||
if (typeof callback !== "function") return; | ||
if (err) return callback(err); | ||
return callback(); | ||
} | ||
); | ||
}); | ||
}; |
@@ -29,3 +29,3 @@ const forceAtlas2 = require("graphology-layout-forceatlas2"); | ||
const group = groups[key]; | ||
group.forEach(node => { | ||
group.forEach((node) => { | ||
graph.setNodeAttribute( | ||
@@ -45,3 +45,3 @@ node, | ||
} else { | ||
graph.forEachNode(node => { | ||
graph.forEachNode((node) => { | ||
graph.setNodeAttribute(node, "x", Math.random() * INITIAL_LAYOUT_SIZE); | ||
@@ -54,3 +54,3 @@ graph.setNodeAttribute(node, "y", Math.random() * INITIAL_LAYOUT_SIZE); | ||
iterations: steps, | ||
settings: forceAtlas2.inferSettings(graph) | ||
settings: forceAtlas2.inferSettings(graph), | ||
}); | ||
@@ -57,0 +57,0 @@ |
@@ -32,3 +32,3 @@ const fs = require("fs"); | ||
graphml: _loadGraphMLFile, | ||
gexf: _loadGEXFFile | ||
gexf: _loadGEXFFile, | ||
}; | ||
@@ -35,0 +35,0 @@ |
@@ -13,3 +13,3 @@ const betweennessCentrality = require("graphology-metrics/centrality/betweenness"); | ||
betweennessCentrality.assign(graph, { | ||
attributes: { centrality: attributeKey } | ||
attributes: { centrality: attributeKey }, | ||
}); | ||
@@ -16,0 +16,0 @@ } |
{ | ||
"name": "net-to-img", | ||
"version": "0.2.1", | ||
"description": "A CLI tool to quickly render a network's topology as an image", | ||
"version": "0.3.0", | ||
"description": "A CLI tool and library to quickly render a network's topology as an image", | ||
"main": "index.js", | ||
"bin": { | ||
"net-to-img": "./index.js" | ||
"net-to-img": "./cli.js" | ||
}, | ||
"scripts": { | ||
"ftest": "./ftest/ftest.sh", | ||
"prettier": "prettier --write \"**\"" | ||
}, | ||
"keywords": [ | ||
@@ -17,15 +21,18 @@ "graph", | ||
"dependencies": { | ||
"graphology": "^0.15.1", | ||
"graphology": "^0.16.1", | ||
"graphology-canvas": "^0.1.1", | ||
"graphology-communities-louvain": "^0.1.1", | ||
"graphology-communities-louvain": "^0.2.0", | ||
"graphology-gexf": "^0.5.1", | ||
"graphology-graphml": "^0.2.0", | ||
"graphology-layout-forceatlas2": "^0.3.1", | ||
"graphology-metrics": "^1.6.1", | ||
"graphology-operators": "^0.2.0", | ||
"graphology-layout-forceatlas2": "^0.4.2", | ||
"graphology-metrics": "^1.10.1", | ||
"graphology-operators": "^1.0.0", | ||
"graphology-svg": "^0.1.0", | ||
"iwanthue": "^1.3.0", | ||
"iwanthue": "^1.4.0", | ||
"seedrandom": "^3.0.5", | ||
"yargs": "^15.1.0" | ||
"yargs": "^15.3.1" | ||
}, | ||
"devDependencies": { | ||
"prettier": "^2.0.2" | ||
} | ||
} |
# net-to-img | ||
A CLI tool to quickly render a network's topology as an image. Its goal is to make it easy to visually detect some graph patterns ([stars](<https://en.wikipedia.org/wiki/Star_(graph_theory)>) for instance). | ||
A CLI tool and library to quickly render a network's topology as an image. Its goal is to make it easy to visually detect some graph patterns ([stars](<https://en.wikipedia.org/wiki/Star_(graph_theory)>) for instance). | ||
@@ -25,2 +25,21 @@ ## Installation | ||
## Library usage | ||
You can also use `net-to-img` programmatically if you need to: | ||
```js | ||
const netToImg = require('net-to-img'); | ||
netToImg({ | ||
sourcePath: 'path/to/graph/file', | ||
destPath: 'path/to/output/image', | ||
options: { | ||
layout: false | ||
} | ||
}, err => { | ||
if (!err) | ||
console.log('Everything went well!'); | ||
}); | ||
``` | ||
## Disclaimer | ||
@@ -40,2 +59,6 @@ | ||
### v0.3.0 | ||
- `net-to-img` can now be used as a library | ||
### v0.2.1 | ||
@@ -42,0 +65,0 @@ |
@@ -19,3 +19,3 @@ const path = require("path"); | ||
png: _savePNG, | ||
svg: _saveSVG | ||
svg: _saveSVG, | ||
}; | ||
@@ -22,0 +22,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
115712750
114
766
78
1
1
+ Addedevents@3.3.0(transitive)
+ Addedgraphology@0.16.1(transitive)
+ Addedgraphology-communities-louvain@0.2.0(transitive)
+ Addedgraphology-layout-forceatlas2@0.4.4(transitive)
+ Addedgraphology-operators@1.6.1(transitive)
+ Addedgraphology-types@0.16.0(transitive)
+ Addedmnemonist@0.32.0(transitive)
+ Addedobliterator@1.6.1(transitive)
- Removedevents@3.1.0(transitive)
- Removedgraphology@0.15.2(transitive)
- Removedgraphology-communities-louvain@0.1.1(transitive)
- Removedgraphology-layout-forceatlas2@0.3.1(transitive)
- Removedgraphology-operators@0.2.0(transitive)
- Removedgraphology-types@0.15.5(transitive)
- Removedobliterator@1.5.0(transitive)
Updatedgraphology@^0.16.1
Updatedgraphology-metrics@^1.10.1
Updatedgraphology-operators@^1.0.0
Updatediwanthue@^1.4.0
Updatedyargs@^15.3.1