-
+ constructor(widgetData) {
+
+ var widgetHtml = `
+
-
-
- `)
+ `
- _canvas_base.apply(this, arguments)
+ super(...arguments, widgetHtml)
- this.wrapper = this.widget.find('.wrapper')
- this.input = this.widget.find('.input').fakeInput({align:'center'})
- this.value = undefined
- this.percent = 0
+ this.wrapper = this.widget.find('.wrapper')
+ this.input = this.widget.find('.input').fakeInput({align:'center'})
+ this.value = undefined
+ this.percent = 0
- this.unit = this.widgetData.unit ? ' ' + this.widgetData.unit : ''
+ this.unit = widgetData.unit ? ' ' + widgetData.unit : ''
- this.rangeKeys = []
- this.rangeVals = []
- this.rangeLabels = []
+ this.rangeKeys = []
+ this.rangeVals = []
+ this.rangeLabels = []
- for (k in this.widgetData.range) {
- var key = k=='min'?0:k=='max'?100:parseInt(k),
- val = typeof this.widgetData.range[k] == 'object'?
- this.widgetData.range[k][Object.keys(this.widgetData.range[k])[0]]:
- this.widgetData.range[k],
- label = typeof this.widgetData.range[k] == 'object'?
- Object.keys(this.widgetData.range[k])[0]:
- val
+ for (var k in widgetData.range) {
+ var key = k=='min'?0:k=='max'?100:parseInt(k),
+ val = typeof widgetData.range[k] == 'object'?
+ widgetData.range[k][Object.keys(widgetData.range[k])[0]]:
+ widgetData.range[k],
+ label = typeof widgetData.range[k] == 'object'?
+ Object.keys(widgetData.range[k])[0]:
+ val
- this.rangeKeys.push(key)
- this.rangeVals.push(val)
- this.rangeLabels.push(label)
- }
- this.rangeValsMax = Math.max.apply(Math, this.rangeVals),
- this.rangeValsMin = Math.min.apply(Math, this.rangeVals)
-
- this.originValue = this.widgetData.origin=='auto'?
- this.rangeValsMin:
- clip(this.widgetData.origin,[this.rangeValsMin,this.rangeValsMax])
- this.springValue = this.widgetData.value != '' ? this.widgetData.value : this.originValue
-
- this.widget.on('fake-right-click',function(e){
- if (!EDITING) {
- e.stopPropagation()
- e.preventDefault()
- this.input.focus()
+ this.rangeKeys.push(key)
+ this.rangeVals.push(val)
+ this.rangeLabels.push(label)
}
- }.bind(this))
+ this.rangeValsMax = Math.max(...this.rangeVals),
+ this.rangeValsMin = Math.min(...this.rangeVals)
- this.widget.on('mousewheel',this.mousewheelHandleProxy.bind(this))
- this.canvas.on('draginit',this.draginitHandleProxy.bind(this))
- this.canvas.on('drag',this.dragHandleProxy.bind(this))
+ this.originValue = widgetData.origin=='auto'?
+ this.rangeValsMin:
+ clip(widgetData.origin,[this.rangeValsMin,this.rangeValsMax])
+ this.springValue = widgetData.value != '' ? widgetData.value : this.originValue
+
+ this.widget.on('fake-right-click',function(e){
+ if (!EDITING) {
+ e.stopPropagation()
+ e.preventDefault()
+ this.input.focus()
+ }
+ }.bind(this))
+
+ this.widget.on('mousewheel',this.mousewheelHandleProxy.bind(this))
+ this.canvas.on('draginit',this.draginitHandleProxy.bind(this))
+ this.canvas.on('drag',this.dragHandleProxy.bind(this))
+
+ if (widgetData.spring) {
+ this.canvas.on('dragend', ()=>{
+ this.setValue(this.springValue,{sync:true,send:true,fromLocal:true})
+ })
+ }
+
+ this.input.change(()=>{
+
+ this.setValue(parseFloat(this.input.val()),{sync:true,send:true})
- if (this.widgetData.spring) {
- this.canvas.on('dragend', ()=>{
- this.setValue(this.springValue,{sync:true,send:true,fromLocal:true})
})
+
+ this.setValue(this.originValue)
+
}
- this.input.change(function(){
- this.setValue(parseFloat(this.input.val()),{sync:true,send:true})
- }.bind(this))
+ mousewheelHandleProxy() {
+
+ this.mousewheelHandle(...arguments)
+
+ }
+
+ draginitHandleProxy() {
+
+ this.draginitHandle(...arguments)
+
+ }
+
+ dragHandleProxy() {
+
+ this.dragHandle(...arguments)
+
+ }
- this.setValue(this.originValue)
+ mousewheelHandle(e, data, traversing) {
-}
+ if (e.originalEvent.wheelDeltaX) return
-_sliders_base.prototype = Object.create(_canvas_base.prototype)
+ e.preventDefault()
+ e.stopPropagation()
-_sliders_base.prototype.constructor = _sliders_base
-
-
-_sliders_base.prototype.mousewheelHandleProxy = function() {
- this.mousewheelHandle.apply(this,arguments)
-}
-
-_sliders_base.prototype.draginitHandleProxy = function() {
- this.draginitHandle.apply(this,arguments)
-}
-
-_sliders_base.prototype.dragHandleProxy = function() {
- this.dragHandle.apply(this,arguments)
-}
-
-
-_sliders_base.prototype.mousewheelHandle = function(e, data, traversing) {
- if (e.originalEvent.wheelDeltaX) return
-
- e.preventDefault()
- e.stopPropagation()
-
- var direction = e.originalEvent.wheelDelta / Math.abs(e.originalEvent.wheelDelta),
+ var direction = e.originalEvent.wheelDelta / Math.abs(e.originalEvent.wheelDelta),
increment = e.ctrlKey?0.25:1
- this.percent = clip(this.percent + Math.max(increment,10/Math.pow(10,this.widgetData.precision)) * direction ,[0,100])
+ this.percent = clip(this.percent + Math.max(increment,10/Math.pow(10,this.widgetData.precision)) * direction ,[0,100])
- this.setValue(this.percentToValue(this.percent), {sync:true,send:true,dragged:true})
+ this.setValue(this.percentToValue(this.percent), {sync:true,send:true,dragged:true})
-
-}
-
-_sliders_base.prototype.draginitHandle = function(e, data, traversing) {
-
-}
-
-_sliders_base.prototype.dragHandle = function(e, data, traversing) {
-
-}
-
-
-_sliders_base.prototype.resizeHandle = function(e, width, height, checkColors) {
- if (!this.visible || checkColors) {
- var style = getComputedStyle(this.widget[0])
- this.colors.track = style.getPropertyValue('--color-track')
- this.colors.gauge = style.getPropertyValue('--color-gauge')
- this.colors.knob = style.getPropertyValue('--color-knob')
}
- _canvas_base.prototype.resizeHandle.apply(this, arguments)
-}
+ draginitHandle(e, data, traversing) {
-_sliders_base.prototype.percentToValue = function(percent) {
- var h = clip(percent,[0,100])
- for (var i=0;i${piptext}
+ this.widget.addClass('fader')
+ this.margin = 20
+
+
+ if (widgetData.horizontal) {
+ this.widget.add(container).addClass('horizontal')
+ if (widgetData.width == 'auto' && widgetData.left != 'auto') {
+ this.container.css({'width':'auto', 'right':'0'})
+ }
+ } else {
+ if (widgetData.height == 'auto' && widgetData.top != 'auto') {
+ this.container.css({'height':'auto', 'bottom':'0'})
+ }
+ }
+
+ if (widgetData.compact) {
+ this.widget.addClass('compact')
+ this.margin = 0
+ }
+
+ if (widgetData.alignRight && !widgetData.horizontal) {
+ this.widget.addClass('align-right')
+ }
+
+ if (!widgetData.noPip&&!widgetData.compact) {
+
+ this.widget.addClass('has-pips')
+
+ var pips = $('').appendTo(this.widget.find('.wrapper'))
+ var pipTexts = {}
+ for (var k in this.rangeKeys) {
+ pipTexts[this.rangeKeys[k]]=this.rangeLabels[k]
+ }
+
+ var pipsInner = ''
+ for (var i=0;i<=100;i++) {
+ if (pipTexts[i]==undefined) continue
+
+ var pos = widgetData.horizontal?'left':'bottom';
+
+ var piptext = `${Math.abs(pipTexts[i])>=1000?pipTexts[i]/1000+'k':pipTexts[i]}`
+
+ var add = `
+ ${piptext}
`
- pipsInner = pipsInner + add
+ pipsInner = pipsInner + add
+ }
+ pips[0].innerHTML = pipsInner
}
- pips[0].innerHTML = pipsInner
+
+
+ if (widgetData.meter) {
+ var parsewidgets = require('../../parser').widgets
+ var data = {
+ type:'meter',
+ id: widgetData.id + '/meter',
+ label:false,
+ horizontal:widgetData.horizontal,
+ range:widgetData.range,
+ logScale:widgetData.logScale,
+ address:widgetData.address + '/meter',
+ preArgs:widgetData.preArgs,
+ color:widgetData.color
+ }
+ var element = parsewidgets([data],this.widget.find('.wrapper'))
+ element[0].classList.add('not-editable')
+ this.widget[0].classList.add('has-meter')
+ }
+
}
+ draginitHandle(e, data, traversing) {
- if (widgetData.meter) {
- var parsewidgets = require('../../parser').widgets
- var data = {
- type:'meter',
- id: widgetData.id + '/meter',
- label:false,
- horizontal:widgetData.horizontal,
- range:widgetData.range,
- logScale:widgetData.logScale,
- address:widgetData.address + '/meter',
- preArgs:widgetData.preArgs,
- color:widgetData.color
- }
- var element = parsewidgets([data],this.widget.find('.wrapper'))
- element[0].classList.add('not-editable')
- this.widget[0].classList.add('has-meter')
- }
+ this.percent = clip(this.percent,[0,100])
+ if (!(traversing || this.widgetData.snap)) return
-
-}
-
-Fader.prototype = Object.create(_sliders_base.prototype)
-
-Fader.prototype.constructor = Fader
-
-Fader.prototype.draginitHandle = function(e, data, traversing){
-
- this.percent = clip(this.percent,[0,100])
-
- if (!(traversing || this.widgetData.snap)) return
-
- this.percent = this.widgetData.horizontal?
+ this.percent = this.widgetData.horizontal?
(data.offsetX - this.margin * PXSCALE) / (this.width - (this.margin * PXSCALE * 2)) * 100:
(this.height - data.offsetY - this.margin * PXSCALE) / (this.height - (this.margin * PXSCALE * 2)) * 100
// this.percent = clip(this.percent,[0,100])
- this.setValue(this.percentToValue(this.percent), {send:true,sync:true,dragged:true})
+ this.setValue(this.percentToValue(this.percent), {send:true,sync:true,dragged:true})
-}
+ }
-Fader.prototype.dragHandle = function(e, data) {
+ dragHandle(e, data) {
- this.percent = this.widgetData.horizontal?
+ this.percent = this.widgetData.horizontal?
this.percent + ( data.speedX/(this.width - this.margin * PXSCALE * 2)) * 100:
this.percent + (-data.speedY/(this.height - this.margin * PXSCALE * 2)) * 100
- this.setValue(this.percentToValue(this.percent), {send:true,sync:true,dragged:true})
-
-}
-
-Fader.prototype.percentToCoord = function(percent) {
- if (this.widgetData.horizontal) {
- return clip(percent / 100,[0,1]) * (this.width - 2 * PXSCALE * this.margin)
- } else {
- return (this.height - this.margin * PXSCALE) - clip(percent / 100, [0,1]) * (this.height - 2 * PXSCALE * this.margin)
+ this.setValue(this.percentToValue(this.percent), {send:true,sync:true,dragged:true})
+
+ }
+
+ percentToCoord(percent) {
+
+ if (this.widgetData.horizontal) {
+ return clip(percent / 100,[0,1]) * (this.width - 2 * PXSCALE * this.margin)
+ } else {
+ return (this.height - this.margin * PXSCALE) - clip(percent / 100, [0,1]) * (this.height - 2 * PXSCALE * this.margin)
+ }
}
-}
-Fader.prototype.draw = function(){
+ draw() {
- var d = Math.round(this.percentToCoord(this.percent)),
+ var d = Math.round(this.percentToCoord(this.percent)),
o = Math.round(this.percentToCoord(this.valueToPercent(this.originValue))),
m = Math.round(this.widgetData.horizontal ? this.height / 2 : this.width / 2)
- this.ctx.clearRect(0,0,this.width,this.height)
+ this.ctx.clearRect(0,0,this.width,this.height)
- if (this.widgetData.horizontal) {
- if (this.widgetData.compact) {
+ if (this.widgetData.horizontal) {
+ if (this.widgetData.compact) {
- this.ctx.globalAlpha = 0.2 + 0.2 * Math.abs(d-o) / (d${this.rangeLabels[0]}
${this.rangeLabels[this.rangeLabels.length-1]}
-