Skip to content

Commit 42172ed

Browse files
committed
discard nan points from input
1 parent 25b2e2d commit 42172ed

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

line.js

+20-6
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ proto.update = function(options) {
279279

280280
var gl = this.plot.gl
281281

282+
var connectGaps = !!options.connectGaps
283+
282284
this.color = (options.color || [0,0,1,1]).slice()
283285
this.width = +(options.width || 1)
284286

@@ -327,6 +329,11 @@ proto.update = function(options) {
327329
for(var i=0; i<numPoints; ++i) {
328330
var ax = data[2*i]
329331
var ay = data[2*i+1]
332+
333+
if (isNaN(ax) || isNaN(ay)) {
334+
continue
335+
}
336+
330337
bounds[0] = Math.min(bounds[0], ax)
331338
bounds[1] = Math.min(bounds[1], ay)
332339
bounds[2] = Math.max(bounds[2], ax)
@@ -347,20 +354,26 @@ proto.update = function(options) {
347354
var pickDataPtr = pickData.length
348355
var ptr = numPoints
349356

350-
this.vertCount = 6 * (numPoints - 1)
357+
var count = 0
351358

352359
while(ptr > 1) {
353360
var id = --ptr
354361
var ax = data[2*ptr]
355362
var ay = data[2*ptr+1]
356363

357-
ax = (ax - bounds[0]) / (bounds[2] - bounds[0])
358-
ay = (ay - bounds[1]) / (bounds[3] - bounds[1])
359-
360364
var next = id-1
361365
var bx = data[2*next]
362366
var by = data[2*next+1]
363367

368+
if (isNaN(ax) || isNaN(ay) || isNaN(bx) || isNaN(by)) {
369+
continue
370+
}
371+
372+
count += 1
373+
374+
ax = (ax - bounds[0]) / (bounds[2] - bounds[0])
375+
ay = (ay - bounds[1]) / (bounds[3] - bounds[1])
376+
364377
bx = (bx - bounds[0]) / (bounds[2] - bounds[0])
365378
by = (by - bounds[1]) / (bounds[3] - bounds[1])
366379

@@ -415,8 +428,9 @@ proto.update = function(options) {
415428
pickData[--pickDataPtr] = akey1
416429
}
417430

418-
this.lineBuffer.update(lineData)
419-
this.pickBuffer.update(pickData)
431+
this.vertCount = 6 * count
432+
this.lineBuffer.update(lineData.subarray(lineDataPtr))
433+
this.pickBuffer.update(pickData.subarray(pickDataPtr))
420434

421435
pool.free(lineData)
422436
pool.free(pickData)

0 commit comments

Comments
 (0)