csv2gexf
v0.0.4
Published
Converts graph-data in two CSV documents in a GEXF document.
Downloads
11
Readme
csv2gexf
Convert graph data in CSV documents to a GEXF document.
The current version (0.0.2) does not support dynamic nor hierarchical graphs.
Getting started
First install NodeJS (version 5.6.0 or higher).
Then install the dependencies for this package:
$ npm install
CSV Documents
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.
Nodes CSV file
- 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
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
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
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:
$ npm run example
Dependencies
API Reference
Author: Wouter Van den Broeck
Copyright: 2016
csv2gexf.convert(config) ⇒ Promise
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. |
csv2gexf~config : 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. |
csv2gexf~graphParams : Object
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. |
csv2gexf~metadata : Object
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. |
csv2gexf~nodesConfig : Object
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. |
csv2gexf~edgesConfig : Object
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. |
csv2gexf~nodeSchema : Array.<nodeSchemaEl>
An array of type specifications. There should be one type specifications string for each column.
Kind: inner typedef of csv2gexf
csv2gexf~nodeSchemaEl : string | nodeSchemaObj
Must either be one of the following strings or a schema element object. The valid type strings are:
Kind: inner typedef of csv2gexf
csv2gexf~nodeSchemaObj : Object
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. |
csv2gexf~edgeSchema : Array.<edgeSchemaEl>
An array of type specifications. There should be one type specifications string for each column.
Kind: inner typedef of csv2gexf
csv2gexf~edgeSchemaEl : string | edgeSchemaObj
Must either be one of the following strings or a schema element object. The valid type strings are:
Kind: inner typedef of csv2gexf
csv2gexf~edgeSchemaObj : Object
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. |
csv2gexf~parseOptions : Object
The options passed to the csv.parse
function.
Kind: inner typedef of csv2gexf
See: http://csv.adaltas.com/parse/.
© 2016, Wouter Van den Broeck