plots: normalize a few things and fix visualizer's value sync (#352)
This commit is contained in:
parent
0501ed2a06
commit
f66a011ec1
3 changed files with 45 additions and 39 deletions
|
|
@ -14,7 +14,7 @@ module.exports = class _plots_base extends Canvas {
|
|||
|
||||
super({...options, html: html})
|
||||
|
||||
this.data = []
|
||||
this.value = []
|
||||
this.rangeX = this.getProp('rangeX') || {min:0,max:1}
|
||||
this.rangeY = this.getProp('rangeY') || {min:0,max:1}
|
||||
this.logScaleX = this.getProp('logScaleX')
|
||||
|
|
@ -94,14 +94,14 @@ module.exports = class _plots_base extends Canvas {
|
|||
|
||||
var points = []
|
||||
|
||||
for (let i in this.data) {
|
||||
for (let i in this.value) {
|
||||
|
||||
if (this.data[i].length) {
|
||||
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))
|
||||
if (this.value[i].length) {
|
||||
points.push(mapToScale(this.value[i][0],[this.rangeX.min,this.rangeX.max],[0,this.width],0,this.logScaleX,true))
|
||||
points.push(mapToScale(this.value[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.logScaleX,true))
|
||||
points.push(mapToScale(this.data[i],[this.rangeY.min,this.rangeY.max],[this.height-2*PXSCALE,2*PXSCALE],0,this.logScaleY,true))
|
||||
points.push(mapToScale(i,[0,this.value.length-1],[0,this.width],0,this.logScaleX,true))
|
||||
points.push(mapToScale(this.value[i],[this.rangeY.min,this.rangeY.max],[this.height-2*PXSCALE,2*PXSCALE],0,this.logScaleY,true))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -151,15 +151,15 @@ module.exports = class _plots_base extends Canvas {
|
|||
|
||||
draw_bars() {
|
||||
|
||||
var barWidth = Math.round(this.width / this.data.length),
|
||||
offset = Math.round((this.width - barWidth * this.data.length) / 2)
|
||||
var barWidth = Math.round(this.width / this.value.length),
|
||||
offset = Math.round((this.width - barWidth * this.value.length) / 2)
|
||||
|
||||
var origin = mapToScale(this.getProp('origin') || this.rangeY.min,[this.rangeY.min,this.rangeY.max],[this.height,0],0,this.getProp('logScaleY'),true)
|
||||
|
||||
this.ctx.beginPath()
|
||||
|
||||
for (let i in this.data) {
|
||||
var y = mapToScale(this.data[i].length ? this.data[i][1] : this.data[i],[this.rangeY.min,this.rangeY.max],[this.height-2*PXSCALE,2*PXSCALE],0,this.logScaleY,true)
|
||||
for (let i in this.value) {
|
||||
var y = mapToScale(this.value[i].length ? this.value[i][1] : this.value[i],[this.rangeY.min,this.rangeY.max],[this.height-2*PXSCALE,2*PXSCALE],0,this.logScaleY,true)
|
||||
this.ctx.rect(offset + i * barWidth, Math.min(y, origin), barWidth - PXSCALE, Math.abs(Math.min(y - origin)))
|
||||
|
||||
}
|
||||
|
|
@ -182,12 +182,12 @@ module.exports = class _plots_base extends Canvas {
|
|||
|
||||
if (Array.isArray(v)) {
|
||||
|
||||
this.data = v
|
||||
this.value = v
|
||||
|
||||
} else {
|
||||
|
||||
for (var i in v) {
|
||||
if (!isNaN(i)) this.data[i] = v[i]
|
||||
if (!isNaN(i)) this.value[i] = v[i]
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -201,12 +201,6 @@ module.exports = class _plots_base extends Canvas {
|
|||
|
||||
}
|
||||
|
||||
getValue() {
|
||||
|
||||
return deepCopy(this.data)
|
||||
|
||||
}
|
||||
|
||||
updateData() {
|
||||
|
||||
// update the coordinates to draw
|
||||
|
|
|
|||
|
|
@ -72,29 +72,37 @@ module.exports = class Eq extends _plots_base {
|
|||
} catch(err) {}
|
||||
}
|
||||
|
||||
if (typeof v == 'object' && v !== null) {
|
||||
if (Array.isArray(v)) {
|
||||
|
||||
var filters = v,
|
||||
eqResponse = []
|
||||
|
||||
for (let i in filters) {
|
||||
if (v.length === this.resolution) {
|
||||
|
||||
var filterResponse
|
||||
eqResponse = v
|
||||
|
||||
if (!filters[i].type) filters[i].type = 'peak'
|
||||
} else {
|
||||
|
||||
if (!filters[i].on) {
|
||||
filterResponse = _biquad_response({type:'peak',freq:1,gain:0,q:1},!this.getProp('logScaleX'), this.resolution)
|
||||
} else {
|
||||
filterResponse = _biquad_response(filters[i],!this.getProp('logScaleX'), this.resolution)
|
||||
}
|
||||
for (let i in filters) {
|
||||
|
||||
for (var k in filterResponse) {
|
||||
if (eqResponse[k]===undefined) {
|
||||
eqResponse[k]=[0,0]
|
||||
var filterResponse
|
||||
|
||||
if (!filters[i].type) filters[i].type = 'peak'
|
||||
|
||||
if (!filters[i].on) {
|
||||
filterResponse = _biquad_response({type:'peak',freq:1,gain:0,q:1},!this.getProp('logScaleX'), this.resolution)
|
||||
} else {
|
||||
filterResponse = _biquad_response(filters[i],!this.getProp('logScaleX'), this.resolution)
|
||||
}
|
||||
|
||||
for (var k in filterResponse) {
|
||||
if (eqResponse[k]===undefined) {
|
||||
eqResponse[k]=[0,0]
|
||||
}
|
||||
|
||||
eqResponse[k] = [filterResponse[k][0], eqResponse[k][1]+filterResponse[k][1]]
|
||||
}
|
||||
|
||||
eqResponse[k] = [filterResponse[k][0], eqResponse[k][1]+filterResponse[k][1]]
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,8 +61,7 @@ module.exports = class Visualizer extends _plots_base {
|
|||
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).fill(this.rangeY.min)
|
||||
this.value = this.getProp('range').min
|
||||
this.value = new Array(this.length).fill(this.rangeY.min)
|
||||
this.cancel = false
|
||||
this.looping = false
|
||||
this.clock = 0
|
||||
|
|
@ -112,18 +111,23 @@ module.exports = class Visualizer extends _plots_base {
|
|||
shiftData(n) {
|
||||
|
||||
for (var i=0; i<n; i++) {
|
||||
this.data.push(this.value)
|
||||
this.data.splice(0,1)
|
||||
this.value.push(this.value[this.length - 1])
|
||||
this.value.splice(0,1)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
getValue() {
|
||||
|
||||
return this.value[this.length - 1]
|
||||
|
||||
}
|
||||
|
||||
setValue(v, options={}) {
|
||||
|
||||
if (Array.isArray(v) && v.length == this.length) {
|
||||
|
||||
this.data = v
|
||||
this.value = v[v.length - 1]
|
||||
this.value = v
|
||||
this.startLoop()
|
||||
|
||||
if (options.sync) this.changed(options)
|
||||
|
|
@ -131,7 +135,7 @@ module.exports = class Visualizer extends _plots_base {
|
|||
|
||||
} else if (typeof(v) == 'number'){
|
||||
|
||||
this.value = v
|
||||
this.value[this.length - 1] = v
|
||||
this.startLoop()
|
||||
|
||||
if (options.sync) this.changed(options)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue