lotivis-csv v1.0.2
lotivis-csv
This module provides functions for reading and writing CSV files with lotivis using d3-dsv.
var text = `
label,location,date,value,group
label-1,paris,1999-01-01,1,group-1
label-1,berlin,1999-01-02,2,group-1
`;
var data = lotivis.csvParse(text);
Installing
If you use npm, npm install lotivis-csv
. You can also download the latest realease on GitHub. For using in browsers, you can load the UMD bundle from an npm-based CDN such as jsDelivr.
<script src="https://cdn.jsdelivr.net/..."></script>
<script>
// ...
</script>
API Reference
lotivis.csvParse(string)
To read csv data use the csvParse
function.
var text = `
label,location,date,value,group
label-1,paris,1999-01-01,1,group-1
label-1,berlin,1999-01-02,2,group-1
`;
var data = lotivis.csvParse(text);
Using the correct names the order of the headlines is variable.
var text = `
value,label,location,group,date
1,label-1,paris,group-1,1999-01-01
2,label-1,berlin,group-1,1999-01-02
`;
var data = lotivis.csvParse(text);
lotivis.csvParseRow(string , row)
To read csv data without headlines use the csvParseRows
function. If the csv data is in the default order (label,location,data,value[,group]).
var text = `
label-1,paris,1999-01-01,1,group-1
label-1,berlin,1999-01-02,2,group-1
`;
var data = lotivis.csvParseRows(text);
When reading csv data in custom order without headlines specify a parse function as second parameter which handles each row.
var text = `
1,label-1,paris,group-1,1999-01-01
2,label-1,berlin,group-1,1999-01-02
`;
let data = csvParseRows(text, (row, index) => {
return {
value: row[0],
label: row[1],
location: row[2],
group: row[3],
date: row[4],
};
});
lotivis.csvRender(data , columns)
Creates a csv string from the specified data
. Optionally specifiy the order of the columns with columns
. The default order is ["label", "location", "date", "value", "group"].
lotivis.csvRenderRows(data , columns)
Creates a csv string without headlines from the specified data
. Optionally specifiy the order of the columns with columns
.
lotivis.fetchCSV(path)
Fetches and parses the data from the csv files specified through the given path
.
lotivis.fetchCSV("path/to/data.csv")
.then((data) => {
// do something with data ...
})
.catch((error) => { /* */});
lotivis.fetchCSVRows(path , row)
Fetches and parses the data from the csv files specified through the given path
. The row
argument works in a simular manner as in csvParseRow.
Development
# build module
yarn build
# develop module
yarn build:watch