Converts graph-data in two CSV documents in a GEXF document.
npm install csv2gexf> Convert graph data in CSV documents to a GEXF document.
The current version (0.0.2) does not support dynamic nor hierarchical graphs.
First install NodeJS (version 5.6.0 or higher).
Then install the dependencies for this package:
``shell`
$ npm install
The graph data is loaded from two CSV documents. The first should contain the nodes data, the second the edges data. The data must respect the following requirements.
Both CSV files should contain headers.
, where , and are integer values in the range [0–255].
- A size expressed as a decimal scale. The default is 1.0.
- A shape, which must be either disc, square, triangle, or diamond.#### Edges CSV file
- One column should contain the source node ids.
- One column should contain the target node ids.
- One column may contain unique edge ids.
- One column may contain the edge labels.
- One column may contain the edge types, which must be either
directed, undirected or mutual.
- One column may contain the edge weights, which must be (decimal) numbers.
- All other columns are either edge attributes or visualizaton settings.
- Attributes may be arbitrary values of type string, int, float or boolean.
- Visualization settings must be either:
- A color expressed as RGB components in the form rgb(, where , and are integer values in the range [0–255].
- A thickness expressed as a (decimal) number. The default is 1.0.
- A shape, which must be either solid, dotted, dashed, or double.
Configuration and schemas
To convert the CSV data to a GEXF document you will need to call the
csv2gexf.convert function in this package.
This function takes a configuration object as sole argument. This object contains settings such as where to save the resulting GEXF file. It also contains schema that specify the nature of the columns in the CSV tables. These schema are arrays which contain one item for each column in the order of the columns. Each item is either a string or an object. The strings are used to mark the columns that contain primary node or edges properties such as id, label, source, target, type and weight. Some of these are required, others are optional. The objects are used for columns that contain arbitrary attributes or visualization settings. The format of the configuration object is documented in the API Reference.
Example
See
./example/start.js for an example of how to use the convertor. This example loads the CSV files in ./example/csv/ and writes the resulting Gexf document as result.gexf in the ./example directory.Run this examples:
`shell
$ npm run example
`Dependencies
- csv for NodeJS
- Gexf library for JavaScript
- jsdoc-to-markdown
API Reference
Author: Wouter Van den Broeck
Copyright: 2016
$3
Returns a promise that converts the data in the given CSV documents to a GEXF document. When
config.saveAs is provided then this promise resolves to the path of the resulting GEXF file,
else it resolves to the resulting Gexf object.Kind: static method of csv2gexf
Access: public
| Param | Type | Description |
| --- | --- | --- |
| config | config | The configuration object. |
$3
The options object for the convert method.Kind: inner typedef of csv2gexf
See: convert
Properties
| Name | Type | Description |
| --- | --- | --- |
| graphParams | graphParams | The parameters object that is passed to the
gexf.create method. |
| nodes | nodesConfig | The options for processing the nodes CSV document. |
| edges | edgesConfig | The options for processing the edges CSV document. |
| saveAs | string | Optional. The path of the GEXF file to save the result in. |$3
The parameters object that is passed to the gexf.create method.
Some of these parameters are specified below. Consult the
Gexf documentation for the
other potential parameters. Note that you should not provide a _model_ as this is
derived from the _nodeSchema_ and _edgeSchema_ objects.Kind: inner typedef of csv2gexf
Properties
| Name | Type | Description |
| --- | --- | --- |
| defaultEdgeType | string | The type for all edges when there is no _type_ in the edge schema. The type must be either
directed, undirected or mutual. |
| meta | metadata | Provides additional information about the graph. |$3
Provides additional information about the graph. It can specify
the _lastmodifieddate_ or any additional arbitrary property. The values must be
strings. Each arbitrary property is added as an child element in the meta
element in the _gexf_ document. The property's name is used as element name and
the value as the element's innerHtml.Kind: inner typedef of csv2gexf
Properties
| Name | Type | Description |
| --- | --- | --- |
| lastmodifieddate | string | A date formatted as an international standard date (yyyy-mm-dd), e.g.
'2009−03−20'. Sets the value of the lastmodifieddate attribute of the meta element in the _gexf_ document. |$3
The options for processing the nodes CSV document.Kind: inner typedef of csv2gexf
Properties
| Name | Type | Description |
| --- | --- | --- |
| file | string | The path to the nodes CSV file. |
| nodeSchema | nodeSchema | Specifies the column types. |
| parseOptions | parseOptions | The options passed to the
csv.parse function. |$3
The options for processing the edges CSV document.Kind: inner typedef of csv2gexf
Properties
| Name | Type | Description |
| --- | --- | --- |
| file | string | The path to the nodes CSV file. |
| edgeSchema | edgeSchema | Specifies the column types. |
| parseOptions | parseOptions | The options passed to the
csv.parse function. |$3
An array of type specifications. There should be one type
specifications string for each column.Kind: inner typedef of csv2gexf
$3
Must either be one of the following strings or a
schema element object.
The valid type strings are:
id - There must be one _id_ column that contains string values used as
node id.
label - Optional. There may be one _label_ column. The corresponding
column must contain string values. These values are used as the label of the respective node.
If the schema does not specify a label, then the node ids are also used as the node
labels.
Kind: inner typedef of csv2gexf
$3
Specifies an attribute or viz element in the node schemas.Kind: inner typedef of csv2gexf
Properties
| Name | Type | Description |
| --- | --- | --- |
| target | string | The target is either
attributes or viz. The _target_ determines which _id_ and _type_ values you may provide.
When the _target_ is
attributes then the _id_ and _title_ can be any string and the _type_ must be one of:
string - An attribute of type string. integer - The values in the corresponding column are parsed using parseInt. float - The values in the corresponding column are parsed using parseFloat. boolean - True when the value is either true (case-insensitive) or 1, and false for all other values. When the _target_ is
viz then the _id_ must be either color, size or shape. The type is implied by the _id_ and is thus ignored. The values are to be given as follows:
color: The RGB values expressed like rgb(255,204,0). size: A number that determines the scale. Default is 1.0. shape: Either disc, square, triangle, or diamond. |
| id | string | Optional. The id of the attribute or viz setting. When the id is not given for an attribute, then the header of the corresponding column in the CSV file is used. |
| title | string | Optional. The title of the attribute. When the title is not given, then the _id_ is used. |
| type | string | The type of the value. |$3
An array of type specifications. There should be one type
specifications string for each column.Kind: inner typedef of csv2gexf
$3
Must either be one of the following strings or a
schema element object.
The valid type strings are:
id - Optional. There may be one _id_ column that contains string values used as node id.
If the schema does not specify an _id_, then the ids of the nodes are automatically
generated.
type - Optional. There may be one _type_ column.
The values in the corresponding column must be either 'directed', 'undirected' or 'mutual'.
If the schema does not specify a _type_, then the edge type is the value for
parseOptions.defaultEdgeType.
label - Optional. There may be one _label_ column. The corresponding column must contain
string values. These values are used as the label of the respective edge. If the
schema does not specify a label, then the edge ids are also used as the edge labels.
source - There must be one _source_ column that contains the ids of the edges' source nodes.
target - There must be one _target_ column that contains the ids of the edges' target nodes.
weight - Optional. There may be one _weight_ column which contains numerical values which are
set as weight on the edges.
Kind: inner typedef of csv2gexf
$3
Specifies an attribute or viz element in the edge schemas.Kind: inner typedef of csv2gexf
Properties
| Name | Type | Description |
| --- | --- | --- |
| target | string | The target is either
attributes or viz. The _target_ determines which _id_ and _type_ values you may provide.
When the _target_ is
attributes then the _id_ and _title_ can be any string and the _type_ must be one of:
string - An attribute of type string. integer - The values in the corresponding column are parsed using parseInt. float - The values in the corresponding column are parsed using parseFloat. boolean - True when the value is either true (case-insensitive) or 1, and false for all other values. When the _target_ is
viz then the _id_ must be either color, thickness or shape. The type is implied by the _id_ and is thus ignored. The values are to be given as follows:
color: The RGB values expressed like rgb(255,204,0). thickness: A number. The default is 1.0. shape: Either solid, dotted, dashed, or double. |
| id | string | Optional. The id of the attribute or viz setting. When the id is not given for an attribute, then the header of the corresponding column in the CSV file is used. |
| title | string | Optional. The title of the attribute. When the title is not given, then the _id_ is used. |
| type | string | The type of the value. |$3
The options passed to the csv.parse` function.Kind: inner typedef of csv2gexf
See: http://csv.adaltas.com/parse/.
*
© 2016, Wouter Van den Broeck