Skip to content

Commit

Permalink
Fixes #176
Browse files Browse the repository at this point in the history
  • Loading branch information
NeXTs committed Dec 19, 2021
1 parent f5768d8 commit 0cbaebe
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
20 changes: 12 additions & 8 deletions clusterize.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Clusterize.js - v0.18.1 - 2018-01-02
/* Clusterize.js - v0.19.0 - 2021-12-19
http://NeXTs.github.com/Clusterize.js/
Copyright (c) 2015 Denis Lukov; Licensed GPLv3 */

Expand Down Expand Up @@ -87,7 +87,7 @@
pointer_events_set = false;
}, 50);
}
if (last_cluster != (last_cluster = self.getClusterNum()))
if (last_cluster != (last_cluster = self.getClusterNum(rows)))
self.insertToDOM(rows, cache);
if (self.options.callbacks.scrollingProgress)
self.options.callbacks.scrollingProgress(self.getScrollProgress());
Expand Down Expand Up @@ -194,9 +194,13 @@
return prev_item_height != opts.item_height;
},
// get current cluster number
getClusterNum: function () {
this.options.scroll_top = this.scroll_elem.scrollTop;
return Math.floor(this.options.scroll_top / (this.options.cluster_height - this.options.block_height)) || 0;
getClusterNum: function (rows) {
var opts = this.options;
opts.scroll_top = this.scroll_elem.scrollTop;
var cluster_divider = opts.cluster_height - opts.block_height;
var current_cluster = Math.floor(opts.scroll_top / cluster_divider);
var max_cluster = Math.floor((rows.length * opts.item_height) / cluster_divider);
return Math.min(current_cluster, max_cluster);
},
// generate empty row if no data provided
generateEmptyRow: function() {
Expand All @@ -215,7 +219,7 @@
return [empty_row.outerHTML];
},
// generate cluster for current scroll position
generate: function (rows, cluster_num) {
generate: function (rows) {
var opts = this.options,
rows_len = rows.length;
if (rows_len < opts.rows_in_block) {
Expand All @@ -226,7 +230,7 @@
rows: rows_len ? rows : this.generateEmptyRow()
}
}
var items_start = Math.max((opts.rows_in_cluster - opts.rows_in_block) * cluster_num, 0),
var items_start = Math.max((opts.rows_in_cluster - opts.rows_in_block) * this.getClusterNum(rows), 0),
items_end = items_start + opts.rows_in_cluster,
top_offset = Math.max(items_start * opts.item_height, 0),
bottom_offset = Math.max((rows_len - items_end) * opts.item_height, 0),
Expand Down Expand Up @@ -258,7 +262,7 @@
if( ! this.options.cluster_height) {
this.exploreEnvironment(rows, cache);
}
var data = this.generate(rows, this.getClusterNum()),
var data = this.generate(rows),
this_cluster_rows = data.rows.join(''),
this_cluster_content_changed = this.checkChanges('data', this_cluster_rows, cache),
top_offset_changed = this.checkChanges('top', data.top_offset, cache),
Expand Down
28 changes: 14 additions & 14 deletions clusterize.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clusterize.js",
"version": "0.18.1",
"version": "0.19.0",
"description": "Tiny vanilla JS plugin to display large data sets easily",
"main": "clusterize.js",
"style": "clusterize.css",
Expand Down

0 comments on commit 0cbaebe

Please sign in to comment.