https://github.com/jamesplease/consecutive-segments.js
Group consecutive segments.
https://github.com/jamesplease/consecutive-segments.js
Last synced: 3 months ago
JSON representation
Group consecutive segments.
- Host: GitHub
- URL: https://github.com/jamesplease/consecutive-segments.js
- Owner: jamesplease
- License: mit
- Created: 2015-01-14T17:13:13.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-05-30T22:34:15.000Z (about 10 years ago)
- Last Synced: 2025-03-17T03:47:24.976Z (4 months ago)
- Language: JavaScript
- Size: 324 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# consecutive-segments.js
[](https://travis-ci.org/jmeas/consecutive-segments.js)
[](https://codeclimate.com/github/jmeas/consecutive-segments.js)
[](https://codeclimate.com/github/jmeas/consecutive-segments.js)
[](https://david-dm.org/jmeas/consecutive-segments.js)
[](https://david-dm.org/jmeas/consecutive-segments.js#info=devDependencies)[time-segments.js](https://github.com/jmeas/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](http://momentjs.com/).
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:
```js
{
1000: [eventOne, eventTwo]
}
```to be of this form:
```js
{
timestamp: 1000,
segments: [eventOne, eventTwo]
}
```