Giter VIP home page Giter VIP logo

melt.js's Introduction

Build Status

Melt.js

Javascript library inspired by the R reshape package by Hadley Wickham.

Melt provides two functions melt and cast. How do they work?

First, they presume you have your data in the form of a list of objects. That looks like this:

var data = [
  {key1: 1, key2: 2},
  {key1: 2, key2: 3},
  {key1: 3, key2: 5},
];

But if you need the keys to be represented as a value, then melt can come to the rescue. Let's take a look at some examples:

Examples

Melt: jsfiddle

Cast: jsfiddle

API

melt(data, keep, varName, valName, noAddId)

  • data list of objects - data to melt
  • keep array of strings - names of object keys to keep
  • varName string - name of the key to use in the molten objects for the former keys (those not in keep)
  • valName string - name of the key to use in the molten objects for the former values
  • noAddId bool - if truthy, don't add the _id value to the resulting object

cast(data, keep, fun, funArgs ...)

  • data list of objects - data to cast
  • keep array of strings - names of object keys to keep (the "GROUP BY" keys)
  • fun function - a function used to aggregate values accross grouped objects
  • funArgs mixed - arguments to passed to fun

cast.sum(name, cols) - convience function to summarize data with cast

  • name string name of resulting object key with sum results
  • cols string or array - names of keys to totaled in the sum. Key values should respond to +.

cast.sum(name) - convience function to sum data with cast

  • name string - special case of cast.sum(name, cols) name is treated as both name and cols.

cast.count(name) - convience function to count data with cast

  • name string - name of resulting object key with which to count objects with common keep values

License

Apache 2

githalytics.com alpha

melt.js's People

Contributors

jrideout avatar

Stargazers

Roman Sîrbu avatar Wayne S. avatar  avatar  avatar Dalci de Jesus Bagolin avatar  avatar Michael Keller avatar #rektbyrebs avatar Ichsan Haryadi avatar charly avatar Fabio Dias Rollo avatar Charles Wei avatar Panagiotis H.M. Issaris avatar Geoff Holden avatar A M avatar  avatar Felipe Lopes avatar  avatar  avatar Dewang Mistry avatar Drew Synan avatar Angus H. avatar Liam Clancy avatar federico lopez avatar Vieko Franetovic avatar Dale Dude avatar Zach Sim avatar Useff Chase avatar Patrick Hall avatar Luis Capelo avatar Roger Howell avatar Lauren Ancona avatar Anna Bansaghi avatar  avatar Ben Hunter avatar Christian Malek avatar Jasmine Hegman avatar Stijn Debrouwere avatar Nissan Pow avatar Nikhil S avatar PB avatar Utensil avatar Michael Bortnick avatar David Ko avatar Ramnath Vaidyanathan avatar timelyportfolio avatar Jonathan Barratt avatar Ritchie avatar xavier dutoit avatar  avatar Lorcan Coyle avatar Nick Zhu avatar

Watchers

Jasmine Hegman avatar timelyportfolio avatar James Cloos avatar

melt.js's Issues

Using melt with dc.js

I've got a setup with 2 dc charts which work together. I'm able to melt the data and create a new crossfilter. Is there a way to use melt use the same crossfilter and have it integrate with the other charts? An example fiddle is here: http://jsfiddle.net/tvinci/g8L3s/4/

You can see that the status chart does not update the other charts because it uses a different filter instance. Is there any way around this? If so, is it possible to have melt remove the date, Year and total entries? As a work around, I'm reformatting the entire data which duplicates the date, Year and total entries. I just wanted to make sure I've exhausted all other options.

Cast does not auto-generate column names

First of all, thanks for the awesome library. However, I can't get "cast" to work as it does in the Reshape package for R, namely, I can't figure out how to name columns based on the values of the fields of the input data.

As you can see at the bottom of this R Reshape example:
http://www.statmethods.net/management/reshape.html

"x1" and "x2" were values of field "variable" before casting and after casting "x1" and "x2" become column names. Is it possible to do this with "cast" in melt.js? If so, how? Thank you very much.

Interactive UI to melt.js?

Hi

I was wondering if you know of anyone who had done an interactive UI to melt.js, perhaps along the lines of the UI used to front https://github.com/nicolaskruchten/pivottable ?

I'm thinking of something that allows a user to upload a tabular dataset, for example, preview the column names, then drag the ones they want into id and measure columns (for melt) for example?

thanks
tony

Convert string to number

Hi,
First of all thanks for this amazing library.There was an issue I was facing when using string values with cast.sum method.The problem was that my string values were not converted to numbers before summing them. So I found a method to do that. I modified the cast.sum method.I added a + sign infront of row[k] on line no. 92 in melt.js file.So now it looked like return a + (+row[k]); .Now , even with string values it worked fine. Please suggest some other way if its not appropriate.

Using melt.js on nested json data

I tried melt.js on a complex json structure like this:
https://gist.github.com/jefffriesen/7325451

I got this error:
Uncaught TypeError: Object # has no method 'forEach' (line 43).

My guess is it doesn't work on nested data structures like this. If that is true, would that be something you would consider adding?

For more context, here is the stackoverflow question I am trying to solve to visualize an XML file with d3.js:
http://stackoverflow.com/questions/18425019/converting-xml-to-json-with-generic-keys-instead-of-element-names-as-keys

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.