visualizer: use super.draw_data, plots: don't skip out-of-range points

This commit is contained in:
jean-emmanuel 2017-10-11 09:36:56 +02:00
parent 721a0997ac
commit fae27a171f
2 changed files with 9 additions and 39 deletions

View file

@ -19,6 +19,8 @@ module.exports = class _plots_base extends _canvas_base {
this.linkedWidgets = []
this.rangeX = this.getProp('rangeX') || {min:0,max:1}
this.rangeY = this.getProp('rangeY') || {min:0,max:1}
this.logScaleX = this.getProp('logScaleX')
this.logScaleY = this.getProp('logScaleY')
this.pips = {
x : {
min: Math.abs(this.rangeX.min)>=1000?this.rangeY.min/1000+'k':this.rangeX.min,
@ -134,25 +136,18 @@ module.exports = class _plots_base extends _canvas_base {
var points = []
for (let i in this.data) {
if (this.data[i][1]>this.rangeY.max || this.data[i][1]<this.rangeY.min ||
this.data[i][0]>this.rangeX.max || this.data[i][0]<this.rangeX.min) continue
if (this.data[i].length) {
points.push(mapToScale(this.data[i][0],[this.rangeX.min,this.rangeX.max],[0,this.width],0,this.getProp('logScaleX'),true))
points.push(mapToScale(this.data[i][1],[this.rangeY.min,this.rangeY.max],[this.height-2*PXSCALE,2*PXSCALE],0,this.getProp('logScaleY'),true))
points.push(mapToScale(this.data[i][0],[this.rangeX.min,this.rangeX.max],[0,this.width],0,this.logScaleX,true))
points.push(mapToScale(this.data[i][1],[this.rangeY.min,this.rangeY.max],[this.height-2*PXSCALE,2*PXSCALE],0,this.logScaleY,true))
} else {
points.push(mapToScale(i,[0,this.data.length-1],[0,this.width],0,this.getProp('logScaleX'),true))
points.push(mapToScale(this.data[i],[this.rangeY.min,this.rangeY.max],[this.height-2*PXSCALE,2*PXSCALE],0,this.getProp('logScaleY'),true))
points.push(mapToScale(i,[0,this.data.length-1],[0,this.width],0,this.logScaleX,true))
points.push(mapToScale(this.data[i],[this.rangeY.min,this.rangeY.max],[this.height-2*PXSCALE,2*PXSCALE],0,this.logScaleY,true))
}
}
this.ctx.curve(points, this.smooth, Math.round(this.width/(points.length/2 - 1)))
}
setValue(v) {

View file

@ -50,8 +50,10 @@ module.exports = class Visualizer extends _plots_base {
this.pips.y.min = Math.abs(this.getProp('range').min) >= 1000? this.getProp('range').min/1000+'k' : this.getProp('range').min
this.pips.y.max = Math.abs(this.getProp('range').max) >= 1000? this.getProp('range').max/1000+'k' : this.getProp('range').max
this.pips.x = false
this.rangeY = this.getProp('range') || {min:0,max:1}
this.logScaleY = this.getProp('logScale')
this.length = Math.round(clip(this.fps * this.getProp('duration'), [8, 4096]))
this.data = new Array(this.length)
this.data = new Array(this.length).fill(this.rangeY.min)
this.value = this.getProp('range').min
this.cancel = false
this.looping = false
@ -106,33 +108,6 @@ module.exports = class Visualizer extends _plots_base {
}
draw_data() {
var first = true
var point = []
for (var i=0;i<this.length;i++) {
var newpoint = [
mapToScale(i,[0,this.length-1],[0,this.width],1),
mapToScale(this.data[i],[this.getProp('range').min,this.getProp('range').max],[this.height-PXSCALE,PXSCALE],1,this.getProp('logScale'),true),
]
if (first) {
this.ctx.moveTo(newpoint[0],newpoint[1])
first = false
} else {
if (this.getProp('logScale')) {
this.ctx.quadraticCurveTo(newpoint[0], point[1], newpoint[0], newpoint[1])
} else {
this.ctx.lineTo(newpoint[0],newpoint[1])
}
}
point = newpoint
}
}
shiftData(n) {
for (var i=0; i<n; i++) {