graphology-operators
Advanced tools
Comparing version 0.2.0 to 1.0.0
export {default as reverse} from './reverse.js'; | ||
export {default as toSimple} from './to-simple.js'; | ||
export {default as toUndirected} from './to-undirected.js'; | ||
export {default as union} from './union.js'; |
@@ -9,2 +9,3 @@ /** | ||
exports.toSimple = require('./to-simple.js'); | ||
exports.toUndirected = require('./to-undirected.js'); | ||
exports.union = require('./union.js'); |
{ | ||
"name": "graphology-operators", | ||
"version": "0.2.0", | ||
"version": "1.0.0", | ||
"description": "Miscellaneous operators for graphology.", | ||
@@ -10,2 +10,3 @@ "main": "index.js", | ||
"reverse.js", | ||
"to-undirected.js", | ||
"to-simple.js", | ||
@@ -41,4 +42,4 @@ "union.js" | ||
"eslint": "^6.8.0", | ||
"graphology": "^0.15.0", | ||
"mocha": "^7.0.1" | ||
"graphology": "^0.16.0", | ||
"mocha": "^7.1.0" | ||
}, | ||
@@ -49,5 +50,5 @@ "eslintConfig": { | ||
"dependencies": { | ||
"graphology-types": "^0.15.0", | ||
"graphology-utils": "^1.1.1" | ||
"graphology-types": "^0.16.0", | ||
"graphology-utils": "^1.7.0" | ||
} | ||
} |
@@ -26,2 +26,3 @@ [![Build Status](https://travis-ci.org/graphology/graphology-operators.svg)](https://travis-ci.org/graphology/graphology-operators) | ||
* [toSimple](#tosimple) | ||
* [toUndirected](#toundirected) | ||
@@ -65,3 +66,3 @@ ### reverse | ||
If a simple graph is passed, the function will only return a copy of it. | ||
If an already simple graph is passed, the function will only return a copy of it. | ||
@@ -75,1 +76,31 @@ ```js | ||
``` | ||
### toUndirected | ||
Returns the undirected version of the given graph where any directed edge will be considered as now undirected. | ||
Note that you can pass a function to merge edge attributes in case of mutual edges or mixed edges conflicts. This can be useful to sum weights and so on... | ||
If an already undirected graph is passed, the function will only return a copy of it. | ||
```js | ||
import {toUndirected} from 'graphology-operators'; | ||
// Alternatively, to load only the relevant code: | ||
import toUndirected from 'graphology-operators/to-undirected'; | ||
const undirectedGraph = toUndirected(graph); | ||
// Using a merging function | ||
const undirectedGraph = toUndirected(graph, (currentAttr, nextAttr) => { | ||
return { | ||
...currentAttr, | ||
weight: currentAttr.weight + nextAttr.weight | ||
}; | ||
}); | ||
``` | ||
*Arguments* | ||
* **graph** *Graph*: target graph. | ||
* **mergeOrOptions** *?function|object*: either a merging function or an options object: | ||
* **mergeEdge** *?function*: merging function to use. |
@@ -19,7 +19,2 @@ /** | ||
// Importing the nodes | ||
graph.forEachNode(function(n, a) { | ||
reversed.addNode(n, a); | ||
}); | ||
// Importing undirected edges | ||
@@ -26,0 +21,0 @@ graph.forEachUndirectedEdge(function(e) { |
@@ -11,3 +11,3 @@ /** | ||
if (!isGraph(multiGraph)) | ||
throw new Error('graphology-operators/cast/toSimple: expecting a valid graphology instance.'); | ||
throw new Error('graphology-operators/to-simple: expecting a valid graphology instance.'); | ||
@@ -21,7 +21,2 @@ // The graph is not multi. We just return a plain copy | ||
// First we need to add nodes | ||
multiGraph.forEachNode(function(node, attr) { | ||
graph.addNode(node, attr); | ||
}); | ||
// Then we need to process edges | ||
@@ -28,0 +23,0 @@ multiGraph.forEachDirectedEdge(function(edge, attr, source, target) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
9905
13
151
1
104
+ Addedgraphology-types@0.16.0(transitive)
- Removedgraphology-types@0.15.5(transitive)
Updatedgraphology-types@^0.16.0
Updatedgraphology-utils@^1.7.0