This is an implementation of the Largest-Triangle-Three-Buckets (LTTB) downsampling algorithm in Ruby.
The code has been translated from the work of Sveinn Steinarsson in his plugin for Flot charts. More information is available on his page, and you can find the thesis describing the algorithm here.
Add this line to your application's Gemfile:
gem 'lttb'
And then execute:
$ bundle
Or install it yourself as:
$ gem install lttb
Data passed should be in the format [[x1,y1],[x2,y2]].
data = [[1, 1], [2, 4], [3, 9], [4, 16], [5, 25]]
threshold = 3
Lttb.process(data, threshold)
# => [1, 1], [3, 9], [5, 25]]
Pass :dates => true
to process DateTime objects correctly.
Lttb.process(data, threshold, dates: true)
Does not support gaps (null values) in the data array. X-values must be in a strictly increasing order.
Bug reports and pull requests are welcome on GitHub at https://github.com/Jubke/lttb.
The gem is available as open source under the terms of the MIT License.