chart-smoother

chart-smoother

A package for smoothing datasets of linear charts

Installation
npm install chart-smoother
Usage

The chart-smoother module exports a single function, chartSmoother(points, iterations), which takes an array of points and the number of smoothing iterations to perform. The function uses the Chaikin's algorithm to smooth the points.

Chaikin's Algorithm

Chaikin's algorithm is an iterative procedure for curve smoothing. Given a set of points, the algorithm successively replaces each straight line segment connecting consecutive points with two new points, offset from the original line by a fraction of the line's length. The result is a smooth curve that approximates the original set of points.

Here's an example of how to use the chart-smoother module:


const chartSmoother = require("chart-smoother");

// [x,y] array
const points = [
  [0, 0],
  [2, 2],
  [3, 3],
  [4, 1],
  [5, 0],
  [6, 0],
];
const iterations = 2;

const smoothedPoints = chartSmoother(points, iterations);

console.log(smoothedPoints);