# chart-smoother

2.0.1 • Public • Published

# chart-smoother

A Node.js module that provides a function to smooth a set of points on a chart, using the Chaikin's algorithm

## Installation

To install the chart-smoother module, run the following command:

`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);
// Output:
// [
//   [0, 0],
//   [0.125, 0.125],
//   [0.375, 0.375],
//   [0.75, 0.75],
//   [1.25, 1.25],
//   [1.6875, 1.6875],
//   [2.0625, 2.0625],
//   [2.375, 2.375],
//   [2.625, 2.625],
//   [2.875, 2.6875],
//   [3.125, 2.5625],
//   [3.375, 2.25],
//   [3.625, 1.75],
//   [3.875, 1.3125],
//   [4.125, 0.9375],
//   [4.375, 0.625],
//   [4.625, 0.375],
//   [4.875, 0.1875],
//   [5.125, 0.0625],
//   [5.375, 0],
//   [5.625, 0],
//   [5.8125, 0],
//   [5.9375, 0],
//   [6, 0],
// ]```

#### Visual representation

Initial dataset:

Final dataset after `chartSmoother` with two iterations:

## Contributing

Contributions to `chart-smoother` are always welcome! If you find a bug or have a feature request, please create an issue on GitHub. If you'd like to contribute code, please fork the repository and submit a pull request.

`chart-smoother` is licensed under the MIT License.

## Package Sidebar

### Install

`npm i chart-smoother`

### Repository

github.com/Murilo-Luciano/chart-smoother

0

2.0.1

ISC

6.68 kB

5