Closed KennethKinLum closed 4 years ago
You can make your own using d3.dsvFormat(" ")
.
You can make your own using
d3.dsvFormat(" ")
.
thank you. Can it do the fetch as well? Would it be:
d3.text("data.txt")
.then(txt => ssv.parse(txt))
.then(data => {
});
?
Seems like it can't. Seems like it needs to be:
ssv = d3.dsvFormat("\t ");
d3.text("multiple.tsv")
.then(txt => {
data = ssv.parse(txt)
console.log(data);
but it seems d3.dsvFormat("\t ");
needs to be d3.dsvFormat(" ");
-- if there is
3 \t 4
(some space and a tab) it is not possible to work this way? But if it is:
ssv = d3.dsvFormat(" ");
d3.text("multiple.tsv")
.then(txt => {
txt = txt.replace(/[\t ]+/g, " ");
data = ssv.parse(txt);
console.log(data);
then it can work.
d3.dsvFormat only allows characters as delimiters; it doesn’t support multiple characters or regular expressions as delimiters. You can use space as a delimiter, or tab, but not both.
To fetch and parse a file:
d3.text(url).then(text => ssv.parse(text))
Added examples here:
d3.dsvFormat only allows characters as delimiters; it doesn’t support multiple characters or regular expressions as delimiters. You can use space as a delimiter, or tab, but not both.
To fetch and parse a file:
d3.text(url).then(text => ssv.parse(text))
Added examples here:
I appreciate it.
I was trying to replicate the case with spaces in front of the first value and this seems to work ok:
ssv = d3.dsvFormat(" ")
d3.text("multiple.ssv")
.then(txt => {
txt = txt.replace(/[\t ]+/g, " ").replace(/^[ ]/gm, "").replace(/[ ]$/gm, "");
data = ssv.parse(txt);
console.log(data);
Besides fetching data by
tsv()
andcsv()
, could we supportssv()
orwssv()
for whitespace separated values?For example, if the data is
the data is quite well formatted and readable by human, and it also can be considered ok to be proper data and processed by a program. For files such as
it the data is not nicely formatted, but if a human can understand it, can it be also be allowed to be processed by the program as well.
The following can preprocess the second form: