Skip to content
Group consecutive segments.
JavaScript HTML
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
config
dist
src
test
.gitignore
.jshintrc
.travis.yml
LICENSE Initial commit
README.md
bower.json v1.0.0
gulpfile.js
package.json

README.md

consecutive-segments.js

Travis build status Code Climate Test Coverage Dependency Status devDependency Status

time-segments.js outputs segments. This library will group consecutive segments.

Motivation

Not all visualizations show a single block for each segment. Sometimes you will want to aggregate consecutive blocks into a single block. This library prepares segments into a state suitable to be aggregated.

API

This library exposes a single method.

group( segments, scale )

Takes in an array of segments and a scale, returns an array. Each item in the array is an array of consecutive segments.

scale can be any of the resolutions supported by moment.js. A short list of examples include days, years, weeks. Moment's abbrevations are also supported, as in w for weeks. The default scale is weeks.

This library transforms segments from this form:

{
  1000: [eventOne, eventTwo]
}

to be of this form:

{
  timestamp: 1000,
  segments: [eventOne, eventTwo]
}
Something went wrong with that request. Please try again.