Gathering detailed insights and metrics for downsample
Gathering detailed insights and metrics for downsample
Gathering detailed insights and metrics for downsample
Gathering detailed insights and metrics for downsample
npm install downsample
95.1
Supply Chain
100
Quality
75.7
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
90 Stars
107 Commits
9 Forks
4 Watching
38 Branches
1 Contributors
Updated on 03 Nov 2024
Minified
Minified + Gzipped
TypeScript (92.95%)
JavaScript (4.98%)
Shell (2.07%)
Cumulative downloads
Total Downloads
Last day
-26.2%
2,446
Compared to previous day
Last week
-11.5%
15,357
Compared to previous week
Last month
9.4%
72,262
Compared to previous month
Last year
20.1%
629,984
Compared to previous year
30
Downsampling methods for time series visualisation.
Installation | Usage | API | Demo | Acknowledgement
downsample
is useful when, not extremely surprisingly, you need to downsample a numeric time series before visualizing it without losing the visual characteristics of the data.
downsample is an NPM module. You can easily download it by typing something like the following in your project:
1# for all the npm people out there 2npm install downsample 3 4# or if you are a fan of yarn 5yarn add downsample
The package exports several methods for data downsampling:
You can read more about the details of these in the API section below.
ASAP
:boom: new in 1.2.0 :boom:Automatic Smoothing for Attention Prioritization (read more here) is a smoothing rather than downsampling method - it will remove the short-term noise and reveal the large-scale deviations.
ASAP
accepts an array of data points (see DataPoint) or a TypedArray
(see TypedArray support) and a target resolution (number of output data points) as arguments. It will always return the points in XYDataPoint
format. See advanced API if you need to work with a custom data type.
1function ASAP(data: DataPoint[], targetResolution: number): XYDataPoint[]
1import { ASAP } from 'downsample'; 2 3// Or if your codebase does not supprot tree-shaking 4import { ASAP } from 'downsample/methods/ASAP'; 5 6const chartWidth = 1000; 7const smooth = ASAP([ 8 [0, 1000], 9 [1, 1243], 10 // ... 11], chartWidth);
SMA
:boom: new in 1.2.0 :boom:Simple moving average with variable slide (read more here).
SMA
accepts an array of data points (see DataPoint) or a TypedArray
(see TypedArray support), size of a window over which to calculate average and a slide - an amount by which the window is shifted. It will always return the points in XYDataPoint
format. See advanced API if you need to work with a custom data type.
1function SMA(data: DataPoint[], windowSize: number, slide?: number = 1): XYDataPoint[]
1import { SMA } from 'downsample'; 2 3// Or if your codebase does not supprot tree-shaking 4import { SMA } from 'downsample/methods/SMA'; 5 6const chartWidth = 1000; 7const smooth = SMA([ 8 [0, 1000], 9 [1, 1243], 10 // ... 11], chartWidth);
LTTB
Largest triangle three buckets (read more here). If you are looking for the best performing downsampling method then look no more!
1function LTTB(data: DataPoint[], targetResolution: number): DataPoint[]
LTTB
accepts an array of data points (see DataPoint) or a TypedArray
(see TypedArray support) and a target resolution (number of output data points) as arguments. See advanced API if you need to work with a custom data type.
The format of the data will be preserved, i.e. if passing an array of [number, number]
data points as data
, you will get an array of [number, number]
on the output.
1import { LTTB } from 'downsample'; 2 3// Or if your codebase does not supprot tree-shaking 4import { LTTB } from 'downsample/methods/LTTB'; 5 6const chartWidth = 1000; 7const downsampled = LTTB([ 8 [0, 1000], 9 [1, 1243], 10 // ... 11], chartWidth);
LTOB
Largest triangle one bucket (read more here). Performs only slightly worse than LTTB.
1function LTOB(data: DataPoint[], targetResolution: number): DataPoint[]
LTOB
accepts an array of data points (see DataPoint) or a TypedArray
(see TypedArray support) and a target resolution (number of output data points) as arguments. See advanced API if you need to work with a custom data type.
The format of the data will be preserved, i.e. if passing an array of [number, number]
data points as data
, you will get an array of [number, number]
on the output.
1import { LTOB } from 'downsample'; 2 3// Or if your codebase does not supprot tree-shaking 4import { LTOB } from 'downsample/methods/LTOB'; 5 6const chartWidth = 1000; 7const downsampled = LTOB([ 8 [0, 1000], 9 [1, 1243], 10 // ... 11], chartWidth);
LTD
Largest triangle dynamic (read more here). The simplest downsampling method.
1function LTD(data: DataPoint[], targetResolution: number): DataPoint[]
LTD
accepts an array of data points (see DataPoint) or a TypedArray
(see TypedArray support) and a target resolution (number of output data points) as arguments. See advanced API if you need to work with a custom data type.
The format of the data will be preserved, i.e. if passing an array of [number, number]
data points as data
, you will get an array of [number, number]
on the output.
1import { LTD } from 'downsample'; 2 3// Or if your codebase does not supprot tree-shaking 4import { LTD } from 'downsample/methods/LTD'; 5 6const chartWidth = 1000; 7const downsampled = LTD([ 8 [0, 1000], 9 [1, 1243], 10 // ... 11], chartWidth);
DataPoint
typeRepresents a data point in the input data array. These formats are currently supported:
1type DataPoint = 2 [number, number] | 3 [Date, number] | 4 { x: number; y: number } | 5 { x: Date; y: number } |
TypedArray
supportIt is now possible to pass TypedArray
data to downsampling functions. The returned type will then match the input type, e.g. if Int16Array
is passed in, the result will be a Int16Array
:
1const input: Int16Array = new Int16Array(...); 2const result: Int16Array = LTD(input, 1000);
All the functions above work with DataPoint
objects as a reasonable default. If however this does not fit your needs you can create your own version of a function using a downsampling function factory.
createASAP
Creates an ASAP smoothing function for a specific point data type P
.
1function createASAP({ 2 x: string | number | (point: P) => number, 3 y: string | number | (point: P) => number, 4 toPoint: (x: number, y: number) => P 5}): ASAP;
createSMA
Creates a SMA smoothing function for a specific point data type P
.
1function createSMA({ 2 x: string | number | (point: P) => number, 3 y: string | number | (point: P) => number, 4 toPoint: (x: number, y: number) => P 5}): SMA;
createLTD
Creates an LTD downsampling function for a specific point data type P
.
1function createLTD({ 2 x: string | number | (point: P) => number, 3 y: string | number | (point: P) => number 4}): LTD;
createLTOB
Creates an LTOB downsampling function for a specific point data type P
.
1function createLTOB({ 2 x: string | number | (point: P) => number, 3 y: string | number | (point: P) => number 4}): LTOB;
createLTTB
Creates an LTTB downsampling function for a specific point data type P
.
1function createLTTB({ 2 x: string | number | (point: P) => number, 3 y: string | number | (point: P) => number 4}): LTTB;
There is a very minimal interactive demo app available if you want to play around with the results of downsampling. Check it out here.
The implementation of LTD
, LTOB
and LTTB
is based on Sveinn Steinarsson's 2013 paper Downsampling Time Series for
Visual Representation that can be found here.
The implementation of ASAP
is based on Kexin Rong's and Peter Bailis's 2017 paper. ASAP: Prioritizing Attention via Time Series Smoothing that can be found here. The original code can be found here
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/19 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
115 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More