Skip to content

devgru/ffp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Farthest feasible point algorithm implementation

Algorithm is used to filter timeseries points to speed up rendering by defining maximum error on ordinate axis and skipping all points that fit in resulting corridor.

FFP Demo

FFP algorithm is described in this paper, authored by Guilin Xinyu and Zhe Cheng.

The library is distributed as ES module.

Check spec/ffp.spec.js to see usage example.

Built in collaboration with Erohina Elena, original version of FFP implementation can be found here.

Installation

$ yarn add ffp
# or
$ npm install --save ffp

Usage

FFP is instantiated and used like this:

import FFP from "ffp";
const ffp = FFP()
  .maxDeltaY(0.5) // define maximum delta
  .x(({ x }) => x) // define x accessor
  .y(({ y }) => y) // define y accessor
  .result(({ value }) => value); // consume filtered points

const array = [
  { x: 0, y: 3 },
  { x: 1, y: 4 },
  { x: 2, y: 5 },
  // ...
  { x: 5, y: 0 },
];

ffp(array);

FFP library exports a function.

FFP()

Creates FFP utility.

ffp(array)

FFP utility is a function, invoke it on array of elements to filter them out.

ffp.maxDeltaY([delta])

If delta is specified, sets the maximum delta to the specified number. If delta is not specified, returns the current maximum delta value, which defaults to 1.

Maximum delta determines maximum variation between resulting trend and point position on ordinate axis.

ffp.epsilon([epsilon])

If epsilon is specified, sets the epsilon to the specified number. If epsilon is not specified, returns the current epsilon value, which defaults to 1/2³².

epsilon determines the maximum margin of error.

ffp.x([xAccessor])

If xAccessor is specified, sets the x accessor to the specified function. If xAccessor is not specified, returns the current x accessor, which defaults to (value, index) => index.

x accessor is invoked for each point.

ffp.y([yAccessor])

If yAccessor is specified, sets the y accessor to the specified function. If yAccessor is not specified, returns the current y accessor, which defaults to (value) => value.

x accessor is invoked for each point.

ffp.result([resultMapper])

If resultMapper is specified, sets the result mapper to the specified function. If resultMapper is not specified, returns the current result mapper, which defaults to ({ value }) => value.

result mapper is invoked for each point. By default, ffp(array) returns an array of objects with value and index keys. Define custom result mapper to modify this behavior.

Development

  • Run tests: yarn test;

License

MIT © Dmitriy Semyushkin

About

FFP algorithm implementation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published