plots: add widgetId option to text, meter and led
This commit is contained in:
parent
0899f5bc5e
commit
d6e801e0ee
5 changed files with 97 additions and 3 deletions
|
|
@ -1,5 +1,6 @@
|
|||
var {mapToScale} = require('../utils'),
|
||||
_widgets_base = require('../common/_widgets_base')
|
||||
_widgets_base = require('../common/_widgets_base'),
|
||||
{widgetManager} = require('../../managers')
|
||||
|
||||
module.exports = class Led extends _widgets_base {
|
||||
|
||||
|
|
@ -19,6 +20,10 @@ module.exports = class Led extends _widgets_base {
|
|||
color:'auto',
|
||||
css:'',
|
||||
|
||||
_plot:'plot',
|
||||
|
||||
widgetId:'',
|
||||
|
||||
_osc:'osc',
|
||||
|
||||
range:{min:0,max:1},
|
||||
|
|
@ -43,10 +48,31 @@ module.exports = class Led extends _widgets_base {
|
|||
|
||||
this.led = this.widget.find('span')
|
||||
|
||||
if (widgetData.widgetId.length) $('body').on(`sync.${this.hash}`,this.syncHandle.bind(this))
|
||||
|
||||
this.setValue(widgetData.range.min)
|
||||
|
||||
}
|
||||
|
||||
onRemove() {
|
||||
|
||||
$('body').off(`sync.${this.hash}`)
|
||||
|
||||
}
|
||||
|
||||
syncHandle(e) {
|
||||
|
||||
if (this.widgetData.widgetId!=e.id || !widgetManager.getWidgetById(e.id).length) return
|
||||
var widget = widgetManager.getWidgetById(e.id),
|
||||
value
|
||||
for (var i=widget.length-1; i>=0; i--) {
|
||||
if (widget[i].getValue) {
|
||||
this.setValue(widget[i].getValue())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
setValue(v) {
|
||||
|
||||
if (typeof v != 'number') return
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
var Fader = require('../sliders/fader')
|
||||
var Fader = require('../sliders/fader'),
|
||||
{widgetManager} = require('../../managers')
|
||||
|
||||
|
||||
module.exports = class Meter extends Fader {
|
||||
|
||||
|
|
@ -20,6 +22,11 @@ module.exports = class Meter extends Fader {
|
|||
color:'auto',
|
||||
css:'',
|
||||
|
||||
|
||||
_plot:'plot',
|
||||
|
||||
widgetId:'',
|
||||
|
||||
_osc:'osc',
|
||||
|
||||
range:{min:0,max:1},
|
||||
|
|
@ -45,6 +52,29 @@ module.exports = class Meter extends Fader {
|
|||
|
||||
this.canvas.off('draginit drag')
|
||||
|
||||
if (widgetData.widgetId.length) $('body').on(`sync.${this.hash}`,this.syncHandle.bind(this))
|
||||
|
||||
|
||||
}
|
||||
|
||||
onRemove() {
|
||||
|
||||
$('body').off(`sync.${this.hash}`)
|
||||
|
||||
}
|
||||
|
||||
syncHandle(e) {
|
||||
|
||||
if (this.widgetData.widgetId!=e.id || !widgetManager.getWidgetById(e.id).length) return
|
||||
var widget = widgetManager.getWidgetById(e.id),
|
||||
value
|
||||
for (var i=widget.length-1; i>=0; i--) {
|
||||
if (widget[i].getValue) {
|
||||
this.setValue(widget[i].getValue())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sendValue() {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
var {iconify} = require('../../utils'),
|
||||
_widgets_base = require('../common/_widgets_base')
|
||||
_widgets_base = require('../common/_widgets_base'),
|
||||
{widgetManager} = require('../../managers')
|
||||
|
||||
module.exports = class Text extends _widgets_base {
|
||||
|
||||
|
|
@ -20,6 +21,10 @@ module.exports = class Text extends _widgets_base {
|
|||
color:'auto',
|
||||
css:'',
|
||||
|
||||
_plot:'plot',
|
||||
|
||||
widgetId:'',
|
||||
|
||||
_osc:'osc',
|
||||
|
||||
value:'',
|
||||
|
|
@ -46,10 +51,32 @@ module.exports = class Text extends _widgets_base {
|
|||
|
||||
this.value = this.defaultValue
|
||||
|
||||
if (widgetData.widgetId.length) $('body').on(`sync.${this.hash}`,this.syncHandle.bind(this))
|
||||
|
||||
this.setValue(this.value)
|
||||
|
||||
}
|
||||
|
||||
onRemove() {
|
||||
|
||||
$('body').off(`sync.${this.hash}`)
|
||||
|
||||
}
|
||||
|
||||
syncHandle(e) {
|
||||
|
||||
if (this.widgetData.widgetId!=e.id || !widgetManager.getWidgetById(e.id).length) return
|
||||
var widget = widgetManager.getWidgetById(e.id),
|
||||
value
|
||||
for (var i=widget.length-1; i>=0; i--) {
|
||||
if (widget[i].getValue) {
|
||||
this.setValue(widget[i].getValue())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
setValue(v) {
|
||||
|
||||
this.value = typeof v=='object' && !v.length ? this.defaultValue : v
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue