0.0.4 • Published 8 years ago

csv2gexf v0.0.4

Weekly downloads
3
License
-
Repository
github
Last release
8 years ago

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, 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(<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, 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:

$ 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

ParamTypeDescription
configconfigThe configuration object.

csv2gexf~config : Object

The options object for the convert method.

Kind: inner typedef of csv2gexf
See: convert
Properties

NameTypeDescription
graphParamsgraphParamsThe parameters object that is passed to the gexf.create method.
nodesnodesConfigThe options for processing the nodes CSV document.
edgesedgesConfigThe options for processing the edges CSV document.
saveAsstringOptional. 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

NameTypeDescription
defaultEdgeTypestringThe type for all edges when there is no type in the edge schema. The type must be either directed, undirected or mutual.
metametadataProvides 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

NameTypeDescription
lastmodifieddatestringA 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

NameTypeDescription
filestringThe path to the nodes CSV file.
nodeSchemanodeSchemaSpecifies the column types.
parseOptionsparseOptionsThe options passed to the csv.parse function.

csv2gexf~edgesConfig : Object

The options for processing the edges CSV document.

Kind: inner typedef of csv2gexf
Properties

NameTypeDescription
filestringThe path to the nodes CSV file.
edgeSchemaedgeSchemaSpecifies the column types.
parseOptionsparseOptionsThe 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

NameTypeDescription
targetstringThe 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.
idstringOptional. 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.
titlestringOptional. The title of the attribute. When the title is not given, then the id is used.
typestringThe 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

NameTypeDescription
targetstringThe 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.
idstringOptional. 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.
titlestringOptional. The title of the attribute. When the title is not given, then the id is used.
typestringThe 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

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago