How to use the d3-dsv.csvFormatRows 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
});

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

// csvFormat(...) ============================================================================

str = d3Dsv.csvFormat(parseRowsMappedArray);
str = d3Dsv.csvFormat(parseRowsMappedArray, columns);

// csvFormatRows(...) ========================================================================

str = d3Dsv.csvFormatRows(parseRowsMappedArray.map((d, i) => [
    d.year.getFullYear().toString(),
    d.make,
    d.model,
    d.length.toString()
]));

// ------------------------------------------------------------------------------------------
// Test TSV
// ------------------------------------------------------------------------------------------

// tsvParse(...) ============================================================================

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

parseArray = d3Dsv.tsvParse(tsvTestStringWithHeader);
github palerdot / exceljson / js / app.js View on Github external
// now we need to find which module to use for the conversion
                    var parsed = "",
                        parse_error = false,
                        parse_error_msg = "";

                    if (this.isColumnHeader) {
                        try {
                            parsed = csvFormat( this.getJSON() );
                            parse_error = false;    
                        } catch (e) {
                            parse_error = true;
                            parse_error_msg = "CSV conversion Failed. Please check if JSON is array of objects.";
                        }
                    } else {
                        try {
                            parsed = csvFormatRows( this.getJSON() );    
                            parse_error = false;    
                        } catch (e) {
                            parse_error = true;
                            parse_error_msg = "CSV conversion Failed. Please check if JSON is array of arrays.";
                        }
                    }

                    if (parse_error) {
                        // show the error message
                        Materialize.toast( parse_error_msg, 4000 );
                        // do not proceed
                        return;
                    }

                    console.log("All success! proceed to download");
                    this.downloadFile( parsed, "csv" );
github keplergl / kepler.gl / src / processors / data-processor.js View on Github external
export function formatCsv(data, fields) {
  const columns = fields.map(f => f.name);
  const formattedData = [columns];

  // parse geojson object as string
  data.forEach(row => {
    formattedData.push(row.map((d, i) => parseFieldValue(d, fields[i].type)));
  });

  return csvFormatRows(formattedData);
}
github medialab / ricardo_data / importApp / src / utils / fileExporter.js View on Github external
export function downloadFlow (array, fileName, ext) {
  let file;
  const header = array[0]
  switch(ext) {
    case 'csv':
    default: {
      const csvString = csvFormatRows(array)
      file = new File(
        [csvString],
        `${fileName}.${ext}`,
        { type: 'text/csv;charset=utf-8' }
      )
      FileSaver.saveAs(file)
      break
    }
    case 'xlsx': {
      const sheet = XLSX.utils.aoa_to_sheet(array, {header});
      const wb = XLSX.utils.book_new();
      XLSX.utils.book_append_sheet(wb, sheet, 'SheetJS');
      XLSX.writeFile(wb, `${fileName}.${ext}`);
      break
    }
  }