JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 16718
  • Score
    100M100P100Q145296F
  • License MIT

Provides functions for time series data downsampling for visual representation

Package Exports

  • downsample

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (downsample) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

downsample

Collection of several downsampling methods for time series visualisation purposes.

Build Status

Installation

downsample is an NPM module. Install using

  npm install downsample

Usage

Two downsampling methods are currently supported, description of both can be found here:

  • Largest triangle three buckets (LTTB)
  • Largest triangle one bucket (LTOB)

Downsampling a series of data points using either of these looks like this:

// ES6
import { LTOB, LTTB } from "downsample";

// Or old school
var LTOB = require("downsample").LTOB;
var LTTB = require("downsample").LTTB;

// The number of target data points, 100 for example
const numPointsInDownsampledData: number = 100;

// See the API docs for supported input data formats
const data: DataPoint[] = [ ... ];
const downsampledDataLTOB: DataPoint[] = LTOB(data, numPointsInDownsampledData);

// downsampledDataLTOB now contains data downsampled to contain 
// no more than numPointsInDownsampledData data points.
//
// the output data format matches the input one and data points are copied
// shallowly to the resulting array

API

DataPoint type

Represents a data point in the input data array. Two formats are currently supported:

TupleDataPoint is an array tuple of a number or a Date representing the independent variable (e.g. time) and a number representing the value:

const numericTupleDataPoint: TupleDataPoint = [1, 152.2];

const dateTupleDataPoint: TupleDataPoint = [new Date(), 45.1];

XYDataPoint is an object hash with x property representing the independent variable (e.g. time) and an y property the value:

const numericXYDataPoint: XYDataPoint = { x: 1, y: 152.2 };

const dateXYDataPoint: XYDataPoint = { x: new Date(), y: 152.2 };

downsample.LTOB<T extends DataPoint>(data: T[], desiredLength: number): T[]

Implementation of Largest triangle one bucket downsampling method.

data: DataPoint[] is the input array. This array should be sorted by the independent variable otherwise the results will be unpredictable.

desiredLength: number is the length of the downsampled array.

This function will throw an error if the desiredLength is negative.

downsample.LTTB<T extends DataPoint>(data: T[], desiredLength: number): T[]

Implementation of Largest triangle three buckets downsampling method.

data: DataPoint[] is the input array. This array should be sorted by the independent variable otherwise the results will be unpredictable.

desiredLength: number is the length of the downsampled array.

This function will throw an error if the desiredLength is negative.