Installations
npm install downsample
Score
95.1
Supply Chain
100
Quality
75.7
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Developer
janjakubnanista
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
Yes
Node Version
14.15.0
NPM Version
6.14.8
Statistics
90 Stars
107 Commits
9 Forks
4 Watching
38 Branches
1 Contributors
Updated on 03 Nov 2024
Bundle Size
8.76 kB
Minified
3.73 kB
Minified + Gzipped
Languages
TypeScript (92.95%)
JavaScript (4.98%)
Shell (2.07%)
Total Downloads
Cumulative downloads
Total Downloads
1,816,764
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
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
30
downsample
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.
Installation
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
Usage
The package exports several methods for data downsampling:
- ASAP Automatic Smoothing for Attention Prioritization read more here
- SMA Simple moving average read more here
- LTTB Largest triangle three buckets read more here
- LTOB Largest triangle one bucket read more here
- LTD Largest triangle dynamic read more here
You can read more about the details of these in the API section below.
API
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
type
Represents 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
support
It 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);
Advanced API
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;
Demo
There is a very minimal interactive demo app available if you want to play around with the results of downsampling. Check it out here.
Acknowledgement
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
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
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
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: npmCommand not pinned by hash: scripts/release.sh:42
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 14 are checked with a SAST tool
Reason
115 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-whgm-jr23-g3j9
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25
- Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-x9w5-v3q2-3rhw
- Warn: Project is vulnerable to: GHSA-w8qv-6jwh-64r5
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-36jr-mh4h-2g58
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-ff7x-qrg7-qggm
- Warn: Project is vulnerable to: GHSA-phwq-j96m-2c2q
- Warn: Project is vulnerable to: GHSA-ghr5-ch3p-vcr6
- Warn: Project is vulnerable to: GHSA-vh7m-p724-62c2
- Warn: Project is vulnerable to: GHSA-r9p9-mrjm-926w
- Warn: Project is vulnerable to: GHSA-434g-2637-qmqr
- Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m
- Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw
- Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p
- Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747
- Warn: Project is vulnerable to: GHSA-6h5x-7c5m-7cr7
- Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc
- Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx
- Warn: Project is vulnerable to: GHSA-8mmm-9v2q-x3f9
- Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
- Warn: Project is vulnerable to: GHSA-vfrc-7r7c-w9mx
- Warn: Project is vulnerable to: GHSA-7wwv-vh3v-89cq
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-76p3-8jx3-jpfq
- Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488
- Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-4wx3-54gh-9fr9
- Warn: Project is vulnerable to: GHSA-4xcv-9jjx-gfj3
- Warn: Project is vulnerable to: GHSA-r6rj-9ch6-g264
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-w7rc-rwvf-8q5r
- Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g
- Warn: Project is vulnerable to: GHSA-px4h-xg32-q955
- Warn: Project is vulnerable to: GHSA-jmqm-f2gx-4fjv
- Warn: Project is vulnerable to: GHSA-rp65-9cf3-cjxr
- Warn: Project is vulnerable to: GHSA-3j8f-xvm3-ffx4
- Warn: Project is vulnerable to: GHSA-4p35-cfcx-8653
- Warn: Project is vulnerable to: GHSA-7f3x-x4pr-wqhj
- Warn: Project is vulnerable to: GHSA-jpp7-7chh-cf67
- Warn: Project is vulnerable to: GHSA-q6wq-5p59-983w
- Warn: Project is vulnerable to: GHSA-j9fq-vwqv-2fm2
- Warn: Project is vulnerable to: GHSA-pqw5-jmp5-px4v
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-566m-qj78-rww5
- Warn: Project is vulnerable to: GHSA-hwj9-h5mp-3pm3
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-wvhm-4hhf-97x9
- Warn: Project is vulnerable to: GHSA-h4hr-7fg3-h35w
- Warn: Project is vulnerable to: GHSA-gj77-59wh-66hg
- Warn: Project is vulnerable to: GHSA-hqhp-5p83-hx96
- Warn: Project is vulnerable to: GHSA-3949-f494-cm99
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-5q6m-3h65-w53x
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-g4rg-993r-mgx7
- Warn: Project is vulnerable to: GHSA-4rq4-32rv-6wp6
- Warn: Project is vulnerable to: GHSA-64g7-mvw6-v9qj
- Warn: Project is vulnerable to: GHSA-vx3p-948g-6vhq
- Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9
- Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw
- Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-4wf5-vphf-c2xc
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-w5p7-h5w8-2hfq
- Warn: Project is vulnerable to: GHSA-9m6j-fcg5-2442
- Warn: Project is vulnerable to: GHSA-hh27-ffr2-f2jc
- Warn: Project is vulnerable to: GHSA-rqff-837h-mm52
- Warn: Project is vulnerable to: GHSA-8v38-pw62-9cw2
- Warn: Project is vulnerable to: GHSA-hgjh-723h-mx2j
- Warn: Project is vulnerable to: GHSA-jf5r-8hm2-f872
- Warn: Project is vulnerable to: GHSA-wr3j-pwj9-hqq6
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
- Warn: Project is vulnerable to: GHSA-v39p-96qg-c8rf
- Warn: Project is vulnerable to: GHSA-8v63-cqqc-6r2c
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-44c6-4v22-4mhx
- Warn: Project is vulnerable to: GHSA-4x5v-gmq8-25ch
- Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v
- Warn: Project is vulnerable to: GHSA-fhg7-m89q-25r3
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p
- Warn: Project is vulnerable to: GHSA-662x-fhqg-9p8v
- Warn: Project is vulnerable to: GHSA-394c-5j6w-4xmx
- Warn: Project is vulnerable to: GHSA-78cj-fxph-m83p
Score
1.6
/10
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