How to use the d3-dsv.tsvParseRows function in d3-dsv

To help you get started, we’ve selected a few d3-dsv examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / d3-dsv / d3-dsv-tests.ts View on Github external
num = parseMappedArray[0].length;


// tsvParseRows(...) ============================================================================

// without row mapper -----------------------------------------------------------------------

parseRowsArray = d3Dsv.tsvParseRows(tsvTestString);


str = parseRowsArray[0][0]; // 'Year' of first row
// date = parseRowsArray[0][0]; // fails, return value is string

// with row mapper ---------------------------------------------------------------------------

parseRowsMappedArray = d3Dsv.tsvParseRows(tsvTestString, (rawRow, index) => {
    let rr: string[] = rawRow;
    let i: number = index;
    let pr: ParsedTestObject;

    pr = {
        year: new Date(+rr[0], 0, 1),
        make: rr[1],
        model: rr[2],
        length: +rr[3]
    };

    return pr;

});

date = parseRowsMappedArray[0].year;
github DefinitelyTyped / DefinitelyTyped / d3-dsv / d3-dsv-tests.ts View on Github external
});

columns = parseMappedArray.columns;

date = parseMappedArray[0].year;
str = parseMappedArray[0].make;
str = parseMappedArray[0].model;
num = parseMappedArray[0].length;


// tsvParseRows(...) ============================================================================

// without row mapper -----------------------------------------------------------------------

parseRowsArray = d3Dsv.tsvParseRows(tsvTestString);


str = parseRowsArray[0][0]; // 'Year' of first row
// date = parseRowsArray[0][0]; // fails, return value is string

// with row mapper ---------------------------------------------------------------------------

parseRowsMappedArray = d3Dsv.tsvParseRows(tsvTestString, (rawRow, index) => {
    let rr: string[] = rawRow;
    let i: number = index;
    let pr: ParsedTestObject;

    pr = {
        year: new Date(+rr[0], 0, 1),
        make: rr[1],
        model: rr[2],
github higlass / higlass / app / scripts / data-fetchers / bam-fetcher-worker.js View on Github external
return text(filepath, (error, chrInfoText) => {
    if (error) {
      // console.warn('Chromosome info not found at:', filepath);
      if (success) success(null);
    } else {
      const data = tsvParseRows(chrInfoText);
      const chromInfo = parseChromsizesRows(data);

      Object.keys(chromInfo).forEach((key) => {
        ret[key] = chromInfo[key];
      });
      if (success) success(ret);
    }
  });
}
github higlass / higlass / app / scripts / ChromosomeInfo.js View on Github external
return tileProxy.text(filepath, (error, chrInfoText) => {
    if (error) {
      // console.warn('Chromosome info not found at:', filepath);
      if (success) success(null);
    } else {
      const data = tsvParseRows(chrInfoText);
      const chromInfo = parseChromsizesRows(data);

      Object.keys(chromInfo).forEach((key) => {
        ret[key] = chromInfo[key];
      });
      if (success) success(ret);
    }
  }, pubSub).then(() => ret);
}
github alibaba / kiwi / kiwi-cli / src / import.ts View on Github external
function getMessagesToImport(file) {
  const content = readFileSync(file).toString();
  const messages = tsvParseRows(content, ([key, value]) => {
    try {
      // value 的形式和 JSON 中的字符串值一致,其中的特殊字符是以转义形式存在的,
      // 如换行符 \n,在 value 中占两个字符,需要转成真正的换行符。
      value = JSON.parse(`"${value}"`);
    } catch (e) {
      throw new Error(`Illegal message: ${value}`);
    }
    return [key, value];
  });
  const rst = {};
  const duplicateKeys = new Set();
  messages.forEach(([key, value]) => {
    if (rst.hasOwnProperty(key)) {
      duplicateKeys.add(key);
    }
    rst[key] = value;
github palerdot / exceljson / js / app.js View on Github external
processTSVFile: function (content) {

        var is_column_header = this.uploadPane.isColumnHeader,
            parsed = false;

        if (is_column_header) {
            parsed = tsvParse(content, function (d) {
                return d;
            });
        } else {
            parsed = tsvParseRows(content, function (d) {
                return d;
            });
        }

        console.log("file content ", parsed, this.uploadPane.getFileType() );
        return parsed;
    },
github higlass / higlass / app / scripts / services / chrom-info.js View on Github external
const parseChromInfo = (text) => {
  if (text.length == 0)
    return null;

  const tsv = tsvParseRows(text);
  const cumValues = [];
  const chromLengths = {};
  const chrPositions = {};

  let totalLength = 0;

  for (let i = 0; i < tsv.length; i++) {
    const length = Number(tsv[i][1]);
    totalLength += length;

    const newValue = {
      id: i,
      chr: tsv[i][0],
      pos: totalLength - length,
    };
github twitter / SentenTree / demo / src / DataService.js View on Github external
d3Text(file, (error, data) => {
      if (error) callback(error);

      const rows = tsvParseRows(data)
        .map(([id, text, count]) => ({
          id,
          text: cleanUrl(text),
          count: +count
        }));

      callback(error, rows);
    });
  }