Skip to content

Commit

Permalink
Fix max level conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
dy committed May 1, 2018
1 parent e5a2627 commit f920988
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 6 additions & 3 deletions quad.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,15 @@ module.exports = function cluster (srcPoints, options) {
if (typeof options.d === 'number') d = [options.d, options.d]
else if (options.d.length) d = options.d

maxLevel = Math.max(
Math.ceil(-log2(Math.abs(d[0]) / (bounds[2] - bounds[0]))),
Math.ceil(-log2(Math.abs(d[1]) / (bounds[3] - bounds[1]))),
maxLevel = Math.min(
Math.max(
Math.ceil(-log2(Math.abs(d[0]) / (bounds[2] - bounds[0]))),
Math.ceil(-log2(Math.abs(d[1]) / (bounds[3] - bounds[1])))
),
maxLevel
)
}
maxLevel = Math.min(maxLevel, levels.length)

This comment has been minimized.

Copy link
@dy

dy May 1, 2018

Author Owner

This corrects behaviour caused slow panning in plotly/plotly.js#2593
Sorry @etpinard, the panning is not that slow actually, we just rendered all levels basically.

This comment has been minimized.

Copy link
@etpinard

etpinard May 1, 2018

This makes me so happy. Thanks very much!


// return levels of details
if (options.lod) {
Expand Down
4 changes: 3 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ t('quad: max depth', t => {
t.end()
})

t('quad: lod method', t => {
t.only('quad: lod method', t => {
let points = [0,0, 1,1, 2,2, 3,3, 4,4, 5,5, 6,6, 7,7]

let index = cluster(points)

t.deepEqual(index.range({lod: true, d: 1e-10}), [[0,1], [1,3], [3,6], [6,8]])
t.deepEqual(index.range({lod: true, level: 400}), [[0,1], [1,3], [3,6], [6,8]])
t.deepEqual(index.range({lod: true}), [[0,1], [1,3], [3,6], [6,8]])
t.deepEqual(index.range([1,6], {lod: true}), [[0,1], [1,2], [3,4], [6,7]])

Expand Down

0 comments on commit f920988

Please sign in to comment.