plots: emit change event to allow synchronization with other widgets
This commit is contained in:
parent
43d6f2df0b
commit
d2d3faf43d
8 changed files with 33 additions and 11 deletions
|
|
@ -150,11 +150,13 @@ module.exports = class _plots_base extends _canvas_base {
|
|||
|
||||
}
|
||||
|
||||
setValue(v) {
|
||||
setValue(v, options={}) {
|
||||
|
||||
this.data = v
|
||||
this.draw()
|
||||
|
||||
if (options.sync) this.widget.trigger({type:'change',id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options:options})
|
||||
|
||||
}
|
||||
|
||||
getValue() {
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ module.exports = class Led extends _widgets_base {
|
|||
|
||||
}
|
||||
|
||||
setValue(v) {
|
||||
setValue(v, options={}) {
|
||||
|
||||
var s = v==null ? '' : '' + v,
|
||||
cache_query = ''
|
||||
|
|
@ -81,6 +81,8 @@ module.exports = class Led extends _widgets_base {
|
|||
|
||||
this.widget[0].style.setProperty('background-image', `url(${this.value}${cache_query})`)
|
||||
|
||||
if (options.sync) this.widget.trigger({type:'change',id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options:options})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,18 +68,20 @@ module.exports = class Led extends _widgets_base {
|
|||
value
|
||||
for (var i=widget.length-1; i>=0; i--) {
|
||||
if (widget[i].getValue) {
|
||||
this.setValue(widget[i].getValue())
|
||||
this.setValue(widget[i].getValue(), {sync: e.options.sync})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
setValue(v) {
|
||||
setValue(v, options={}) {
|
||||
|
||||
if (typeof v != 'number') return
|
||||
this.value = v
|
||||
this.widget[0].style.setProperty('--opacity', mapToScale(v,[this.getProp('range').min,this.getProp('range').max],[0,1],false,this.getProp('logScale'),true))
|
||||
|
||||
if (options.sync) this.widget.trigger({type:'change',id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options:options})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ module.exports = class Meter extends Fader {
|
|||
value
|
||||
for (var i=widget.length-1; i>=0; i--) {
|
||||
if (widget[i].getValue) {
|
||||
this.setValue(widget[i].getValue())
|
||||
this.setValue(widget[i].getValue(), {sync: e.options.sync})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,13 +68,13 @@ module.exports = class Rbgled extends _widgets_base {
|
|||
|
||||
for (var i=widget.length-1; i>=0; i--) {
|
||||
if (widget[i].getValue) {
|
||||
this.setValue(widget[i].getValue())
|
||||
this.setValue(widget[i].getValue(), {sync: e.options.sync})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
setValue(v) {
|
||||
setValue(v, options={}) {
|
||||
|
||||
var c = ''
|
||||
|
||||
|
|
@ -103,6 +103,8 @@ module.exports = class Rbgled extends _widgets_base {
|
|||
|
||||
this.widget[0].style.setProperty('--color-led', c)
|
||||
|
||||
if (options.sync) this.widget.trigger({type:'change',id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options:options})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,18 +71,20 @@ module.exports = class Text extends _widgets_base {
|
|||
value
|
||||
for (var i=widget.length-1; i>=0; i--) {
|
||||
if (widget[i].getValue) {
|
||||
this.setValue(widget[i].getValue())
|
||||
this.setValue(widget[i].getValue(), {sync: e.options.sync})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
setValue(v) {
|
||||
setValue(v, options={}) {
|
||||
|
||||
this.value = v==null ? this.defaultValue : v
|
||||
this.widget.html(iconify(String(this.value).replace(/\n/g,'<br/>')))
|
||||
|
||||
if (options.sync) this.widget.trigger({type:'change',id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options:options})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ module.exports = class Visualizer extends _plots_base {
|
|||
syncHandle(e) {
|
||||
|
||||
if (this.getProp('widgetId')!=e.id || !widgetManager.getWidgetById(e.id).length || !e.widget) return
|
||||
this.setValue(e.widget.getValue())
|
||||
this.setValue(e.widget.getValue(), {sync: e.options.sync})
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -117,7 +117,7 @@ module.exports = class Visualizer extends _plots_base {
|
|||
|
||||
}
|
||||
|
||||
setValue(v) {
|
||||
setValue(v, options={}) {
|
||||
|
||||
if (Array.isArray(v) && v.length == this.length) {
|
||||
|
||||
|
|
@ -125,11 +125,17 @@ module.exports = class Visualizer extends _plots_base {
|
|||
this.value = v[v.length - 1]
|
||||
this.startLoop()
|
||||
|
||||
if (options.sync) this.widget.trigger({type:'change',id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options:options})
|
||||
|
||||
|
||||
} else if (typeof(v) == 'number'){
|
||||
|
||||
this.value = v
|
||||
this.startLoop()
|
||||
|
||||
if (options.sync) this.widget.trigger({type:'change',id:this.getProp('id'),widget:this, linkId:this.getProp('linkId'), options:options})
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue