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:
$ 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.
- One column should contain unique node ids.
- One column may contain the node labels.
- All other columns are either node 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(<r>,<g>,<b>)
, where<r>
,<g>
and<b>
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
, ordiamond
.
- A color expressed as RGB components in the form
- 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
ormutual
. - 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(<r>,<g>,<b>)
, where<r>
,<g>
and<b>
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
, ordouble
.
- A color expressed as RGB components in the form
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.
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:
$ npm run example
Author: Wouter Van den Broeck
Copyright: 2016
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. |
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. |
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. |
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. |
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. |
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. |
An array of type specifications. There should be one type specifications string for each column.
Kind: inner typedef of csv2gexf
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
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
|
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. |
An array of type specifications. There should be one type specifications string for each column.
Kind: inner typedef of csv2gexf
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
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
|
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. |
The options passed to the csv.parse
function.
Kind: inner typedef of csv2gexf
See: http://csv.adaltas.com/parse/.
© 2016, Wouter Van den Broeck