Coder Social home page Coder Social logo

Comments (5)

mbostock avatar mbostock commented on May 1, 2024

This is why there’s a dsv.formatRows method. I’ve added some examples to the API reference. Hope this helps!

from d3-dsv.

mariocasciaro avatar mariocasciaro commented on May 1, 2024

Thanks for the answer, it's all clear now!

from d3-dsv.

mbostock avatar mbostock commented on May 1, 2024

Even though you can do this with dsv.formatRows, I think it would be easy to support this, so I’m reopening this issue. As you suggested, the dsv.format method could take an optional array of column names. Then, instead of this:

var string = csv.formatRows([[
    "year",
    "make",
    "model",
    "length"
  ]].concat(data.map(function(d, i) {
  return [
    d.year,
    d.make,
    d.model,
    d.length
  ];
})));

You could say this:

var string = csv.format(data, ["year", "make", "model", "length"]);

Which is obviously much nicer. 😁

Another possibility is that we could check if the passed-in rows array exposes a columns array, now that dsv.parse supports this feature. But I think this is probably too magical, since you might forget about the existence of the columns property after transforming the array. So, better to make it an explicit argument.

from d3-dsv.

mbostock avatar mbostock commented on May 1, 2024

Fixed in 0.1.11.

from d3-dsv.

mariocasciaro avatar mariocasciaro commented on May 1, 2024

Thanks for the feature! It's definitely a much neater approach

from d3-dsv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.