node package manager

olap-cube

is an hypercube of data

OLAP-cube

is an hypercube of data

NPM version Build Status Dependency Status

js-standard-style

Description | Installation | API | License

Description

An OLAP cube is a multidimensional array of data you can explore and analyze. Here you will find an engine and a graphic viewer.

Installation

With npm do

npm install olap-cube

API

All code in this section is run and tested in this single file. Note also that

  1. Everything is immutable, all attributes are static.
  2. Operators are chainable but they always return a brand new instance.

new Table({ dimensions, fields, points, data })

var Table = require('olap-cube').model.Table
 
var table = new Table({
  dimensions: ['year', 'month'],
  fields: ['revenue'],
  points: [[2016, 'Gen']],
  data: [[100]]
})
 
console.log(table) // Table {
                   //   dimensions: ['year', 'month'],
                   //   fields: ['revenue']
                   // }

table.structure

Holds necessary information to clone a table excluding its data.

Create an empty table

const emptyTable = new Table(table.structure)

table.dimensions

They are the cube dimensions. One common dimension in Business Intelligence is time: it can have different granularities, like year, month, day, etc.

console.log(table.dimensions) // [ 'year', 'month' ]

table.fields

They are the name of the data fields.

console.log(table.fields) // [ 'revenue' ]

table.addRows({ header: [key1, key2, ...], rows: [row1, row2, ...]})

Add a set of rows to the table. Every row is an object which attributes are either a dimension or a field.

const table2 = emptyTable.addRows({
  header: [ 'year', 'month', 'revenue' ],
  rows: [
    [ 2015, 'Nov', 80 ],
    [ 2015, 'Dec', 90 ],
    [ 2016, 'Jan', 100 ],
    [ 2016, 'Feb', 170 ],
    [ 2016, 'Mar', 280 ]
  ]
})

table.data

Attribute data holds the rows of the table.

console.log(table2.data) // [[ 80 ],
                         //  [ 90 ],
                         //  [ 100 ],
                         //  [ 170 ],
                         //  [ 280 ]]

table.points

The points are an ordered set of coordinates. In this case you can see 5 points with coordinates:

  1. year
  2. month
console.log(table2.points) // [[ 2015, 'Nov' ],
                           //  [ 2015, 'Dec' ],
                           //  [ 2016, 'Jan' ],
                           //  [ 2016, 'Feb' ],
                           //  [ 2016, 'Mar' ]]

table.slice(dimension, table)

Slice operator picks a rectangular subset of a cube by choosing a single value of its dimensions.

Consider the following example, where a slice with 2016 year is created.

var table3 = table2.slice('year', 2016)
 
console.log(table3.points) // [[ 2016, 'Jan' ],
                           //  [ 2016, 'Feb' ],
                           //  [ 2016, 'Mar' ]]
 
console.log(table3.data) // [[ 100 ],
                         //  [ 170 ],
                         //  [ 280 ]]

License

MIT