datamodel
Relational algebra compliant in-memory tabular data store
Last updated 8 months ago by charts.com .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install datamodel 
SYNC missed versions from official npm registry.

Build Status codecov Maintainability NPM version NPM total downloads Contributors License PRs Welcome

What is DataModel?

DataModel is a minimalistic, in-browser representation of tabular data. It supports Relational Algebra operators which enable you to run filter, group, bin, join (and many more) operations on the data.

DataModel can be used if you need an in-browser tabular data store for data analysis, visualization or just general use of data. Since DataModel is immutable and enables all relational algebra operations, it can work seamlessly with any JavaScript library.

Features

  • ???? Supports Relational Algebra operators e.g. selection, projection, union, difference, join etc out-of-the-box.
  • ???? Provides additional operators like bin, groupBy, calculateVariable to harness additional power of data transformation.
  • ???? Compose and store data operations, with support for chaining or multiple levels of nesting.
  • ???? Every operation creates Immutable DataModel instance and builds a Directed Acyclic Graph (DAG) which establishes auto interactivity.

Installation

CDN

Insert the DataModel build into the <head>:

<script src="https://cdn.muzejs.org/lib/datamodel/latest/datamodel.js" type="text/javascript"></script>

NPM

Install DataModel from NPM:

$ npm install --save datamodel

Getting started

  1. Prepare the data and the corresponding schema:
// Prepare the schema for data
const schema = [
  {
    name: 'Name',
    type: 'dimension'
  },
  {
    name: 'Maker',
    type: 'dimension'
  },
  {
    name: 'Horsepower',
    type: 'measure',
    defAggFn: 'avg'
  },
  {
    name: 'Origin',
    type: 'dimension'
  }
]

// Prepare the data
const data = [
   {
    "Name": "chevrolet chevelle malibu",
    "Maker": "chevrolet",
    "Horsepower": 130,
    "Origin": "USA"
  },
  {
    "Name": "buick skylark 320",
    "Maker": "buick",
    "Horsepower": 165,
    "Origin": "USA"
  },
  {
    "Name": "datsun pl510",
    "Maker": "datsun",
    "Horsepower": 88,
    "Origin": "Japan"
  }
]
  1. Pass the data and schema to DataModel constructor and create a new DataModel instance:
import DataModel from 'datamodel';

// Create a new DataModel instance
const dm = new DataModel(data, schema);
console.log(dm.getData().data);
// Output:
//  [
//     ["chevrolet chevelle malibu", "chevrolet", 130, "USA"],
//     ["buick skylark 320", "buick", 165, "USA"],
//     ["datsun pl510", "datsun", 88, "Japan"]
//  ]


// Perform the selection operation
const selectDm = dm.select((fields) => fields.Origin.value === "USA");
console.log(selectDm.getData().data);
// Output:
//  [
//     ["chevrolet chevelle malibu", "chevrolet", 130, "USA],
//     ["buick skylark 320", "buick", 165, "USA]
//  ]

// Perform the projection operation
const projectDm = dm.project(["Origin", "Maker"]);
console.log(projectDm.getData().data);
// Output:
//  [
//     ["USA", "chevrolet"],
//     ["USA", "buick"],
//     ["Japan", "datsun"]
//  ]
console.log(projectDm.getData().schema);
// Output:
//  [
//     {"name": "Origin","type": "dimension"},
//     {"name": "Maker","type": "dimension"}
//  ]

Documentation

Find detailed documentation and API reference from here.

Contributing

Your PRs and stars are always welcome.

Checkout the CONTRIBUTING guides.

License

MIT

Current Tags

  • 2.3.1                                ...           latest (8 months ago)

26 Versions

  • 2.3.1                                ...           8 months ago
  • 2.3.0                                ...           10 months ago
  • 2.2.3                                ...           a year ago
  • 2.2.2                                ...           a year ago
  • 2.2.1                                ...           a year ago
  • 2.2.0                                ...           a year ago
  • 2.1.0                                ...           2 years ago
  • 2.0.2                                ...           2 years ago
  • 2.0.1                                ...           2 years ago
  • 2.0.0                                ...           2 years ago
  • 1.5.1                                ...           4 years ago
  • 1.5.0                                ...           5 years ago
  • 1.4.0                                ...           5 years ago
  • 1.3.0                                ...           5 years ago
  • 1.2.0                                ...           5 years ago
  • 1.1.2                                ...           5 years ago
  • 1.1.1                                ...           6 years ago
  • 1.1.0                                ...           6 years ago
  • 1.0.7                                ...           6 years ago
  • 1.0.6                                ...           6 years ago
  • 1.0.5                                ...           6 years ago
  • 1.0.4                                ...           6 years ago
  • 1.0.3                                ...           6 years ago
  • 1.0.2                                ...           6 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dependents (3)

Copyright 2014 - 2016 © taobao.org |