code: remove useless semicolons and use 4-spaces instead of tabs

This commit is contained in:
jean-emmanuel 2017-01-06 08:39:54 +01:00
parent 3fdd586f51
commit b85893d872
18 changed files with 464 additions and 463 deletions

View file

@ -20,10 +20,10 @@ module.exports = {
stateSave: function() {
state = JSON.stringify(module.exports.stateGet(),null,' ')
var down = $('<a download="'+new Date().toJSON().slice(0,10)+'_'+new Date().toJSON().slice(11,16)+'.preset"></a>')
var blob = new Blob([state],{type : 'application/x-javascript'});
var blob = new Blob([state],{type : 'application/x-javascript'})
down.attr('href', window.URL.createObjectURL(blob))
var event = new MouseEvent("click");
down[0].dispatchEvent(event);
var event = new MouseEvent("click")
down[0].dispatchEvent(event)
},
stateGet: function (){
@ -45,13 +45,13 @@ module.exports = {
var prompt = $('<input type="file" accept=".preset"/>')
prompt.click()
prompt.on('change',function(e){
var reader = new FileReader();
var reader = new FileReader()
reader.onloadend = function(e) {
var preset = e.target.result
module.exports.stateSet(JSON.parse(preset),true)
STATE = preset
}
reader.readAsText(e.target.files[0],'utf-8');
reader.readAsText(e.target.files[0],'utf-8')
})
},
@ -102,7 +102,7 @@ module.exports = {
var session = e.target.result
ipc.send('sessionOpen',{file:session,path:file.path})
}
reader.readAsText(file, 'utf-8');
reader.readAsText(file, 'utf-8')
})
},
@ -110,13 +110,13 @@ module.exports = {
sessionSave: function() {
var sessionfile = JSON.stringify(SESSION,null,' ')
var down = $('<a download="'+new Date().toJSON().slice(0,10)+'_'+new Date().toJSON().slice(11,16)+'.js"></a>')
var blob = new Blob([sessionfile],{type : 'application/x-javascript'});
var blob = new Blob([sessionfile],{type : 'application/x-javascript'})
down.attr('href', window.URL.createObjectURL(blob))
var event = new MouseEvent("click");
down[0].dispatchEvent(event);
var event = new MouseEvent("click")
down[0].dispatchEvent(event)
},
editorEnable: function(){
editorEnable: function(){
GRIDWIDTH = getComputedStyle(document.documentElement).getPropertyValue("--grid-width")
$('.editor-root').attr('data-tab','#container').removeClass('disabled')
$('.enable-editor').addClass('on')
@ -143,7 +143,7 @@ module.exports = {
})
$('.editor').append(f)
},
editorDisable: function(){
editorDisable: function(){
$('.widget.ui-resizable').resizable('destroy')
$('.widget.ui-draggable').draggable('destroy').find('.ui-draggable-handle').remove()
$('.editing').removeClass('editing')

View file

@ -104,19 +104,19 @@ var callbacks = module.exports = {
},
applyStyle: function(data){
var style = document.createElement('style');
style.innerHTML = data.join('');
document.body.appendChild(style);
var style = document.createElement('style')
style.innerHTML = data.join('')
document.body.appendChild(style)
GRIDWIDTH = getComputedStyle(document.documentElement).getPropertyValue("--grid-width")
PXSCALE = getComputedStyle(document.documentElement).getPropertyValue("--pixel-scale")
INITIALZOOM = PXSCALE
},
reloadCss: function(){
var queryString = '?reload=' + new Date().getTime();
var queryString = '?reload=' + new Date().getTime()
$('link[rel="stylesheet"][hot-reload]').each(function () {
this.href = this.href.replace(/\?.*|$/, queryString);
});
this.href = this.href.replace(/\?.*|$/, queryString)
})
setTimeout(()=>{
$('canvas').trigger('resize',[0,0,true])
},100)

View file

@ -16,7 +16,7 @@ module.exports = function(purgetabs) {
}
// remove deleted tabs that are not referenced (have no navigation link pointing to them)
var $f = $(formerBuffuredTabs)
var $f = $(formerBuffuredTabs)
for (i in TABS) {
if (!($f.find(`[data-tab="${i}"]`).length || i== '#container')) {
delete TABS[i]
@ -38,12 +38,12 @@ module.exports = function(purgetabs) {
// prune widget stores
// if widgets cannot be found in buffered tabs, it must be unreferenced
var $b = $(bufferedTabs)
var $b = $(bufferedTabs)
for (hash in widgetManager.widgets) {
if (!$b.find(widgetManager.widgets[hash].widget).length) {
widgetManager.removeWidget(hash)
}
}
widgetManager.purge()
}

View file

@ -19,7 +19,7 @@ var iterators = {
}
var hashCode = function(s){
return s.split("").reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a},0);
return s.split("").reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a},0)
}
var $body

View file

@ -1,5 +1,5 @@
var actions = require('./actions'),
icon = require('./utils').icon
icon = require('./utils').icon
var data = [
{
@ -11,137 +11,137 @@ var data = [
]
},
{
title: icon('sliders') + '&nbsp; State',
actions: [
{
title:'Store',
action:actions.stateQuickSave
},
{
title:'Recall',
action:actions.stateQuickLoad,
class:'disabled quickload'
},
{
title:'Send All',
action:actions.stateSend
},
{
title:'Import',
action:actions.stateLoad
},
{
title:'Export',
action:actions.stateSave
}
]
},
{
title: icon('magic') + '&nbsp; Traversing gestures',
actions: [
{
title:'On',
action:actions.traversingEnable,
class:'traversingEnable'
},
{
title:'Off',
action:actions.traversingDisable,
class:'traversingDisable on'
}
]
},
{
title: icon('edit') + '&nbsp; Editor',
class:'editor',
actions: [
{
title:'On',
action:actions.editorEnable,
class:'enable-editor'
},
{
title:'Off',
action:actions.editorDisable,
class:'on disable-editor'
},
{
title:'Root',
class:'editor-root disabled'
},
{
title:'Load',
action:actions.sessionBrowse
},
{
title:'Save',
action:actions.sessionSave
}
]
},
{
title: icon('sliders') + '&nbsp; State',
actions: [
{
title:'Store',
action:actions.stateQuickSave
},
{
title:'Recall',
action:actions.stateQuickLoad,
class:'disabled quickload'
},
{
title:'Send All',
action:actions.stateSend
},
{
title:'Import',
action:actions.stateLoad
},
{
title:'Export',
action:actions.stateSave
}
]
},
{
title: icon('magic') + '&nbsp; Traversing gestures',
actions: [
{
title:'On',
action:actions.traversingEnable,
class:'traversingEnable'
},
{
title:'Off',
action:actions.traversingDisable,
class:'traversingDisable on'
}
]
},
{
title: icon('edit') + '&nbsp; Editor',
class:'editor',
actions: [
{
title:'On',
action:actions.editorEnable,
class:'enable-editor'
},
{
title:'Off',
action:actions.editorDisable,
class:'on disable-editor'
},
{
title:'Root',
class:'editor-root disabled'
},
{
title:'Load',
action:actions.sessionBrowse
},
{
title:'Save',
action:actions.sessionSave
}
]
},
]
var sidepanel = function(data){
var bindAction = function(el,callback) {
el.click(function(){callback()})
}
var bindAction = function(el,callback) {
el.click(function(){callback()})
}
var html = $('<ul id="options"></ul>')
var html = $('<ul id="options"></ul>')
for (i in data) {
var itemData = data[i]
for (i in data) {
var itemData = data[i]
var item = $('<li></li>'),
inner = $('<div></div>').appendTo(item),
wrapper = $('<div class="actions"></div>').appendTo(inner)
var item = $('<li></li>'),
inner = $('<div></div>').appendTo(item),
wrapper = $('<div class="actions"></div>').appendTo(inner)
if (itemData.title) $('<div class="title">'+itemData.title+'</div>').prependTo(wrapper)
if (itemData.class) inner.attr('class',itemData.class)
if (itemData.title) $('<div class="title">'+itemData.title+'</div>').prependTo(wrapper)
if (itemData.class) inner.attr('class',itemData.class)
for (j in itemData.actions) {
var actionData = itemData.actions[j]
var el = $('<a class="btn">'+actionData.title+'</a>').appendTo(wrapper)
if (actionData.action) bindAction(el, actionData.action)
for (j in itemData.actions) {
var actionData = itemData.actions[j]
var el = $('<a class="btn">'+actionData.title+'</a>').appendTo(wrapper)
if (actionData.action) bindAction(el, actionData.action)
if (actionData.class) el.addClass(actionData.class)
if (actionData.class) el.addClass(actionData.class)
}
item.appendTo(html)
}
item.appendTo(html)
}
}
return html
return html
}(data)
var toggle = function(){
var t = $(`<li><a id="open-toggle">${icon('navicon')}</a></li>`).appendTo('.navigation.main ul').click(function(e){
var t = 0
if (!$('#sidepanel').hasClass('sidepanel-open')) t = 250
var t = $(`<li><a id="open-toggle">${icon('navicon')}</a></li>`).appendTo('.navigation.main ul').click(function(e){
var t = 0
if (!$('#sidepanel').hasClass('sidepanel-open')) t = 250
$('#open-toggle, #sidepanel').toggleClass('sidepanel-open')
setTimeout(function(){
$('#container').toggleClass('sidepanel-open')
$(window).resize()
},t)
}).on('mousedown touchstart',function(e){e.stopPropagation()})
$('#open-toggle, #sidepanel').toggleClass('sidepanel-open')
setTimeout(function(){
$('#container').toggleClass('sidepanel-open')
$(window).resize()
},t)
}).on('mousedown touchstart',function(e){e.stopPropagation()})
// in case where are hot loading a session
if ($('#sidepanel').hasClass('sidepanel-open')) {
$('#open-toggle, #container').addClass('sidepanel-open')
}
// in case where are hot loading a session
if ($('#sidepanel').hasClass('sidepanel-open')) {
$('#open-toggle, #container').addClass('sidepanel-open')
}
$(document).on('keydown.sidepanel', function(e){
if (e.keyCode==121) t.click()
})
$(document).on('keydown.sidepanel', function(e){
if (e.keyCode==121) t.click()
})
}
module.exports = {
init:function(){
$('#sidepanel').append(sidepanel)
toggle()
},
createToggle:toggle
init:function(){
$('#sidepanel').append(sidepanel)
toggle()
},
createToggle:toggle
}

View file

@ -1,65 +1,65 @@
var Panel = require('./panel'),
_widgets_base = require('../common/_widgets_base')
_widgets_base = require('../common/_widgets_base')
module.exports = class Modal extends Panel {
static options() {
static options() {
return {
type:'modal',
id:'auto',
return {
type:'modal',
id:'auto',
_style:'style',
_style:'style',
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
_osc:'osc',
_osc:'osc',
address:'auto',
address:'auto',
_chidlren:'chilren',
_chidlren:'chilren',
widgets:[],
tabs:[]
}
widgets:[],
tabs:[]
}
}
}
constructor(widgetData, container) {
constructor(widgetData, container) {
super(...arguments)
super(...arguments)
this.widget.removeClass('noscroll')
this.container = container
this.widget.removeClass('noscroll')
this.container = container
container.append('<div class="light"></div>')
this.light = container.find('.light').first()
container.append('<div class="light"></div>')
this.light = container.find('.light').first()
this.modal = this.widget.detach()
this.modal = this.widget.detach()
this.value = false
this.value = false
this.light.on('fake-click',()=>{
this.setValue(!this.value)
})
this.light.on('fake-click',()=>{
this.setValue(!this.value)
})
}
}
setValue(v) {
setValue(v) {
this.value = v ? true : false
this.container.toggleClass('on', this.value)
this.widget.toggleClass('on', this.value)
this.light.toggleClass('on', this.value)
this.value = v ? true : false
this.container.toggleClass('on', this.value)
this.widget.toggleClass('on', this.value)
this.light.toggleClass('on', this.value)
}
}
}

View file

@ -2,54 +2,54 @@ var _widgets_base = require('../common/_widgets_base')
module.exports = class Panel extends _widgets_base {
static options() {
static options() {
return {
type:'panel',
id:'auto',
return {
type:'panel',
id:'auto',
_style:'style',
_style:'style',
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
scroll:true,
color:'auto',
css:'',
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
scroll:true,
color:'auto',
css:'',
_children:'chilren',
_children:'chilren',
widgets:[],
tabs:[]
}
widgets:[],
tabs:[]
}
}
}
constructor(widgetData) {
constructor(widgetData) {
var widgetHtml = `
<div class="panel
${!widgetData.scroll?'noscroll':''}
${widgetData.tabs.length?'has-tabs':''}
">
</div>
`
var widgetHtml = `
<div class="panel
${!widgetData.scroll?'noscroll':''}
${widgetData.tabs.length?'has-tabs':''}
">
</div>
`
super(...arguments, widgetHtml)
super(...arguments, widgetHtml)
var parsers = require('../../parser'),
parsewidgets = parsers.widgets,
parsetabs = parsers.tabs
var parsers = require('../../parser'),
parsewidgets = parsers.widgets,
parsetabs = parsers.tabs
if (widgetData.tabs.length) {
parsetabs(widgetData.tabs,this.widget)
} else {
parsewidgets(widgetData.widgets,this.widget)
}
if (widgetData.tabs.length) {
parsetabs(widgetData.tabs,this.widget)
} else {
parsewidgets(widgetData.widgets,this.widget)
}
}
}
}

View file

@ -50,7 +50,7 @@ module.exports = class Keyboard extends _matrices_base {
pattern = 'wbwbwwbwbwbw',
wCount = 0
var parsers = require('../../parser'),
var parsers = require('../../parser'),
parsewidgets = parsers.widgets
for (var i=widgetData.start;i<widgetData.keys+widgetData.start&&i<108;i++) {

View file

@ -60,7 +60,7 @@ module.exports = class Multifader extends _matrices_base {
var strData = JSON.stringify(widgetData)
var parsers = require('../../parser'),
var parsers = require('../../parser'),
parsewidgets = parsers.widgets
for (var i=widgetData.start; i<widgetData.strips+widgetData.start;i++) {

View file

@ -48,7 +48,7 @@ module.exports = class Multipush extends _matrices_base {
var strData = JSON.stringify(widgetData)
var parsers = require('../../parser'),
var parsers = require('../../parser'),
parsewidgets = parsers.widgets
for (var i=widgetData.start;i<widgetData.matrix[0]*widgetData.matrix[1]+widgetData.start;i++) {

View file

@ -8,9 +8,9 @@ module.exports = class Multitoggle extends _matrices_base {
type:'multitoggle',
id:'auto',
_matrix: 'Matrix',
_matrix: 'Matrix',
matrix: [2,2],
matrix: [2,2],
start:0,
_style:'style',
@ -47,7 +47,7 @@ module.exports = class Multitoggle extends _matrices_base {
var strData = JSON.stringify(widgetData)
var parsers = require('../../parser'),
var parsers = require('../../parser'),
parsewidgets = parsers.widgets
for (var i=widgetData.start;i<widgetData.matrix[0]*widgetData.matrix[1]+widgetData.start;i++) {

View file

@ -5,133 +5,133 @@
// original @ Nigel Redmon
module.exports = function(options,linear,resolution) {
var {type, freq, q, gain} = options,
Fs = 44100,
a0,a1,a2,b1,b2,norm,
ymin, ymax, minVal, maxVal,
len = resolution
var {type, freq, q, gain} = options,
Fs = 44100,
a0,a1,a2,b1,b2,norm,
ymin, ymax, minVal, maxVal,
len = resolution
var V = Math.pow(10, Math.abs(gain) / 20)
var K = Math.tan(Math.PI * freq / Fs)
switch (type) {
case "lowpass":
norm = 1 / (1 + K / q + K * K)
a0 = K * K * norm
a1 = 2 * a0
a2 = a0
b1 = 2 * (K * K - 1) * norm
b2 = (1 - K / q + K * K) * norm
break
var V = Math.pow(10, Math.abs(gain) / 20)
var K = Math.tan(Math.PI * freq / Fs)
switch (type) {
case "lowpass":
norm = 1 / (1 + K / q + K * K)
a0 = K * K * norm
a1 = 2 * a0
a2 = a0
b1 = 2 * (K * K - 1) * norm
b2 = (1 - K / q + K * K) * norm
break
case "highpass":
norm = 1 / (1 + K / q + K * K)
a0 = 1 * norm
a1 = -2 * a0
a2 = a0
b1 = 2 * (K * K - 1) * norm
b2 = (1 - K / q + K * K) * norm
break
case "highpass":
norm = 1 / (1 + K / q + K * K)
a0 = 1 * norm
a1 = -2 * a0
a2 = a0
b1 = 2 * (K * K - 1) * norm
b2 = (1 - K / q + K * K) * norm
break
case "bandpass":
norm = 1 / (1 + K / q + K * K)
a0 = K / q * norm
a1 = 0
a2 = -a0
b1 = 2 * (K * K - 1) * norm
b2 = (1 - K / q + K * K) * norm
break
case "bandpass":
norm = 1 / (1 + K / q + K * K)
a0 = K / q * norm
a1 = 0
a2 = -a0
b1 = 2 * (K * K - 1) * norm
b2 = (1 - K / q + K * K) * norm
break
case "notch":
norm = 1 / (1 + K / q + K * K)
a0 = (1 + K * K) * norm
a1 = 2 * (K * K - 1) * norm
a2 = a0
b1 = a1
b2 = (1 - K / q + K * K) * norm
break
case "notch":
norm = 1 / (1 + K / q + K * K)
a0 = (1 + K * K) * norm
a1 = 2 * (K * K - 1) * norm
a2 = a0
b1 = a1
b2 = (1 - K / q + K * K) * norm
break
case "peak":
if (gain >= 0) {
norm = 1 / (1 + 1/q * K + K * K)
a0 = (1 + V/q * K + K * K) * norm
a1 = 2 * (K * K - 1) * norm
a2 = (1 - V/q * K + K * K) * norm
b1 = a1
b2 = (1 - 1/q * K + K * K) * norm
}
else {
norm = 1 / (1 + V/q * K + K * K)
a0 = (1 + 1/q * K + K * K) * norm
a1 = 2 * (K * K - 1) * norm
a2 = (1 - 1/q * K + K * K) * norm
b1 = a1
b2 = (1 - V/q * K + K * K) * norm
}
break
case "lowshelf":
if (gain >= 0) {
norm = 1 / (1 + Math.SQRT2 * K + K * K)
a0 = (1 + Math.sqrt(2*V) * K + V * K * K) * norm
a1 = 2 * (V * K * K - 1) * norm
a2 = (1 - Math.sqrt(2*V) * K + V * K * K) * norm
b1 = 2 * (K * K - 1) * norm
b2 = (1 - Math.SQRT2 * K + K * K) * norm
}
else {
norm = 1 / (1 + Math.sqrt(2*V) * K + V * K * K)
a0 = (1 + Math.SQRT2 * K + K * K) * norm
a1 = 2 * (K * K - 1) * norm
a2 = (1 - Math.SQRT2 * K + K * K) * norm
b1 = 2 * (V * K * K - 1) * norm
b2 = (1 - Math.sqrt(2*V) * K + V * K * K) * norm
}
break
case "highshelf":
if (gain >= 0) {
norm = 1 / (1 + Math.SQRT2 * K + K * K)
a0 = (V + Math.sqrt(2*V) * K + K * K) * norm
a1 = 2 * (K * K - V) * norm
a2 = (V - Math.sqrt(2*V) * K + K * K) * norm
b1 = 2 * (K * K - 1) * norm
b2 = (1 - Math.SQRT2 * K + K * K) * norm
}
else {
norm = 1 / (V + Math.sqrt(2*V) * K + K * K)
a0 = (1 + Math.SQRT2 * K + K * K) * norm
a1 = 2 * (K * K - 1) * norm
a2 = (1 - Math.SQRT2 * K + K * K) * norm
b1 = 2 * (K * K - V) * norm
b2 = (V - Math.sqrt(2*V) * K + K * K) * norm
}
break
}
case "peak":
if (gain >= 0) {
norm = 1 / (1 + 1/q * K + K * K)
a0 = (1 + V/q * K + K * K) * norm
a1 = 2 * (K * K - 1) * norm
a2 = (1 - V/q * K + K * K) * norm
b1 = a1
b2 = (1 - 1/q * K + K * K) * norm
}
else {
norm = 1 / (1 + V/q * K + K * K)
a0 = (1 + 1/q * K + K * K) * norm
a1 = 2 * (K * K - 1) * norm
a2 = (1 - 1/q * K + K * K) * norm
b1 = a1
b2 = (1 - V/q * K + K * K) * norm
}
break
case "lowshelf":
if (gain >= 0) {
norm = 1 / (1 + Math.SQRT2 * K + K * K)
a0 = (1 + Math.sqrt(2*V) * K + V * K * K) * norm
a1 = 2 * (V * K * K - 1) * norm
a2 = (1 - Math.sqrt(2*V) * K + V * K * K) * norm
b1 = 2 * (K * K - 1) * norm
b2 = (1 - Math.SQRT2 * K + K * K) * norm
}
else {
norm = 1 / (1 + Math.sqrt(2*V) * K + V * K * K)
a0 = (1 + Math.SQRT2 * K + K * K) * norm
a1 = 2 * (K * K - 1) * norm
a2 = (1 - Math.SQRT2 * K + K * K) * norm
b1 = 2 * (V * K * K - 1) * norm
b2 = (1 - Math.sqrt(2*V) * K + V * K * K) * norm
}
break
case "highshelf":
if (gain >= 0) {
norm = 1 / (1 + Math.SQRT2 * K + K * K)
a0 = (V + Math.sqrt(2*V) * K + K * K) * norm
a1 = 2 * (K * K - V) * norm
a2 = (V - Math.sqrt(2*V) * K + K * K) * norm
b1 = 2 * (K * K - 1) * norm
b2 = (1 - Math.SQRT2 * K + K * K) * norm
}
else {
norm = 1 / (V + Math.sqrt(2*V) * K + K * K)
a0 = (1 + Math.SQRT2 * K + K * K) * norm
a1 = 2 * (K * K - 1) * norm
a2 = (1 - Math.SQRT2 * K + K * K) * norm
b1 = 2 * (K * K - V) * norm
b2 = (V - Math.sqrt(2*V) * K + K * K) * norm
}
break
}
var magPlot = []
for (var i = 0; i < len; i++) {
var w, phi, y
if (linear)
w = i / (len - 1) * Math.PI; // 0 to pi, linear scale
else
w = Math.exp(Math.log(1 / 0.001) * i / (len - 1)) * 0.001 * Math.PI; // 0.001 to 1, times pi, log scale
var magPlot = []
for (var i = 0; i < len; i++) {
var w, phi, y
if (linear)
w = i / (len - 1) * Math.PI; // 0 to pi, linear scale
else
w = Math.exp(Math.log(1 / 0.001) * i / (len - 1)) * 0.001 * Math.PI; // 0.001 to 1, times pi, log scale
phi = Math.pow(Math.sin(w/2), 2)
phi = Math.pow(Math.sin(w/2), 2)
y = Math.log(Math.pow(a0+a1+a2, 2) - 4*(a0*a1 + 4*a0*a2 + a1*a2)*phi + 16*a0*a2*phi*phi) - Math.log(Math.pow(1+b1+b2, 2) - 4*(b1 + 4*b2 + b1*b2)*phi + 16*b2*phi*phi)
y = y * 10 / Math.LN10
if (y == -Infinity) y = -200
y = Math.log(Math.pow(a0+a1+a2, 2) - 4*(a0*a1 + 4*a0*a2 + a1*a2)*phi + 16*a0*a2*phi*phi) - Math.log(Math.pow(1+b1+b2, 2) - 4*(b1 + 4*b2 + b1*b2)*phi + 16*b2*phi*phi)
y = y * 10 / Math.LN10
if (y == -Infinity) y = -200
if (linear)
magPlot.push([i / (len - 1) * Fs / 2, y])
else
magPlot.push([i / (len - 1) * Fs / 2, y])
if (linear)
magPlot.push([i / (len - 1) * Fs / 2, y])
else
magPlot.push([i / (len - 1) * Fs / 2, y])
if (i == 0)
minVal = maxVal = y
else if (y < minVal)
minVal = y
else if (y > maxVal)
maxVal = y
}
if (i == 0)
minVal = maxVal = y
else if (y < minVal)
minVal = y
else if (y > maxVal)
maxVal = y
}
return magPlot
return magPlot
}

View file

@ -8,24 +8,24 @@ module.exports = class Eq extends _plots_base {
static options() {
return {
type:'eq',
id:'auto',
type:'eq',
id:'auto',
_style:'style',
_style:'style',
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
css:'',
_plot:'plot',
_plot:'plot',
filters:[],
filters:[],
resolution:128,
rangeY: {min:-20,max:20},
rangeY: {min:-20,max:20},
origin: 'auto',
logScaleX: false,

View file

@ -7,24 +7,24 @@ module.exports = class Plot extends _plots_base {
static options() {
return {
type:'plot',
id:'auto',
type:'plot',
id:'auto',
_style:'style',
_style:'style',
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
css:'',
_plot:'plot',
_plot:'plot',
points:[],
rangeX: {min:0,max:1},
rangeY: {min:0,max:1},
points:[],
rangeX: {min:0,max:1},
rangeY: {min:0,max:1},
origin: 'auto',
logScaleX: false,
logScaleY: false,

View file

@ -38,7 +38,7 @@ module.exports = class Text extends _widgets_base {
super(...arguments, widgetHtml)
this.defaultValue = widgetData.label===false?
this.defaultValue = widgetData.label===false?
widgetData.id:
widgetData.label=='auto'?
widgetData.id:

View file

@ -7,24 +7,24 @@ module.exports = class Visualizer extends _plots_base {
static options() {
return {
type:'visualizer',
id:'auto',
type:'visualizer',
id:'auto',
_style:'style',
_style:'style',
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
css:'',
_plot:'plot',
_plot:'plot',
widgetId:'',
widgetId:'',
duration:1,
range: {min:0,max:1},
range: {min:0,max:1},
origin: 'auto',
logScale: false,

View file

@ -1,72 +1,72 @@
module.exports = {
clip: function(value,range) {
var value = parseFloat(value)
clip: function(value,range) {
var value = parseFloat(value)
if (isNaN(value)) value = range[0]
return Math.max(Math.min(range[0],range[1]),Math.min(value,Math.max(range[0],range[1])))
if (isNaN(value)) value = range[0]
return Math.max(Math.min(range[0],range[1]),Math.min(value,Math.max(range[0],range[1])))
},
},
// map a value from a scale to another input and output must be range arrays
mapToScale: function(value,rangeIn,rangeOut,precision,log,revertlog) {
// map a value from a scale to another input and output must be range arrays
mapToScale: function(value,rangeIn,rangeOut,precision,log,revertlog) {
var value = module.exports.clip(value,[rangeIn[0],rangeIn[1]])
var value = module.exports.clip(value,[rangeIn[0],rangeIn[1]])
value = log?
value = log?
revertlog?
(Math.pow(10,((value-rangeIn[0])/(rangeIn[1]-rangeIn[0])))/9-1/9) * (rangeOut[1]-rangeOut[0]) + rangeOut[0]
:Math.log10(((value-rangeIn[0])/(rangeIn[1]-rangeIn[0]))*9+1) * (rangeOut[1]-rangeOut[0]) + rangeOut[0]
:((value-rangeIn[0])/(rangeIn[1]-rangeIn[0])) * (rangeOut[1]-rangeOut[0]) + rangeOut[0]
value = Math.max(Math.min(rangeOut[0],rangeOut[1]),Math.min(value,Math.max(rangeOut[0],rangeOut[1])))
value = Math.max(Math.min(rangeOut[0],rangeOut[1]),Math.min(value,Math.max(rangeOut[0],rangeOut[1])))
if (precision!==false) value = parseFloat(value.toFixed(precision))
if (precision!==false) value = parseFloat(value.toFixed(precision))
return value
return value
},
},
hsbToRgb: function (hsb) {
var rgb = {}
var h = hsb.h
var s = hsb.s*255/100
var v = hsb.b*255/100
if(s == 0) {
rgb.r = rgb.g = rgb.b = v
} else {
var t1 = v
var t2 = (255-s)*v/255
var t3 = (t1-t2)*(h%60)/60
if(h==360) h = 0
if(h<60) {rgb.r=t1; rgb.b=t2; rgb.g=t2+t3}
else if(h<120) {rgb.g=t1; rgb.b=t2; rgb.r=t1-t3}
else if(h<180) {rgb.g=t1; rgb.r=t2; rgb.b=t2+t3}
else if(h<240) {rgb.b=t1; rgb.r=t2; rgb.g=t1-t3}
else if(h<300) {rgb.b=t1; rgb.g=t2; rgb.r=t2+t3}
else if(h<360) {rgb.r=t1; rgb.g=t2; rgb.b=t1-t3}
else {rgb.r=0; rgb.g=0; rgb.b=0}
}
return rgb
},
hsbToRgb: function (hsb) {
var rgb = {}
var h = hsb.h
var s = hsb.s*255/100
var v = hsb.b*255/100
if(s == 0) {
rgb.r = rgb.g = rgb.b = v
} else {
var t1 = v
var t2 = (255-s)*v/255
var t3 = (t1-t2)*(h%60)/60
if(h==360) h = 0
if(h<60) {rgb.r=t1; rgb.b=t2; rgb.g=t2+t3}
else if(h<120) {rgb.g=t1; rgb.b=t2; rgb.r=t1-t3}
else if(h<180) {rgb.g=t1; rgb.r=t2; rgb.b=t2+t3}
else if(h<240) {rgb.b=t1; rgb.r=t2; rgb.g=t1-t3}
else if(h<300) {rgb.b=t1; rgb.g=t2; rgb.r=t2+t3}
else if(h<360) {rgb.r=t1; rgb.g=t2; rgb.b=t1-t3}
else {rgb.r=0; rgb.g=0; rgb.b=0}
}
return rgb
},
rgbToHsb: function (rgb) {
var hsb = {h: 0, s: 0, b: 0}
var min = Math.min(rgb.r, rgb.g, rgb.b)
var max = Math.max(rgb.r, rgb.g, rgb.b)
var delta = max - min
hsb.b = max
hsb.s = max != 0 ? 255 * delta / max : 0
if (hsb.s != 0) {
if (rgb.r == max) hsb.h = (rgb.g - rgb.b) / delta
else if (rgb.g == max) hsb.h = 2 + (rgb.b - rgb.r) / delta
else hsb.h = 4 + (rgb.r - rgb.g) / delta
} else hsb.h = 0
hsb.h *= 60
if (hsb.h < 0) hsb.h += 360
hsb.s *= 100/255
hsb.b *= 100/255
return hsb
}
rgbToHsb: function (rgb) {
var hsb = {h: 0, s: 0, b: 0}
var min = Math.min(rgb.r, rgb.g, rgb.b)
var max = Math.max(rgb.r, rgb.g, rgb.b)
var delta = max - min
hsb.b = max
hsb.s = max != 0 ? 255 * delta / max : 0
if (hsb.s != 0) {
if (rgb.r == max) hsb.h = (rgb.g - rgb.b) / delta
else if (rgb.g == max) hsb.h = 2 + (rgb.b - rgb.r) / delta
else hsb.h = 4 + (rgb.r - rgb.g) / delta
} else hsb.h = 0
hsb.h *= 60
if (hsb.h < 0) hsb.h += 360
hsb.s *= 100/255
hsb.b *= 100/255
return hsb
}
}

View file

@ -3,27 +3,27 @@
var settings = $.extend({
align:'left'
}, options );
}, options )
var self= this,
canvas = $('<canvas></canvas>').appendTo(self),
ctx = canvas[0].getContext('2d')
var self= this,
canvas = $('<canvas></canvas>').appendTo(self),
ctx = canvas[0].getContext('2d')
self.value = undefined
self.height = undefined
self.width = undefined
self.color = undefined
self.value = undefined
self.height = undefined
self.width = undefined
self.color = undefined
self.center = settings.align == 'center'
self.visible = false
self.attr('tabindex',"0")
self.attr('tabindex',"0")
canvas.resize(function(e,width,height,checkColors){
canvas.resize(function(e,width,height,checkColors){
var width = width*2,
height = height*2
var width = width*2,
height = height*2
if (width && height) {
if (width && height) {
self.height=height
self.width=width
@ -36,20 +36,22 @@
self.fontSize = parseFloat(getComputedStyle(canvas[0]).getPropertyValue("font-size"))
}
self.val(self.value)
})
self.val(self.value)
self.val = function(newVal) {
if (newVal==undefined) return self.value
})
self.value = newVal
self.val = function(newVal) {
if (!self.height || !self.width || (self.height==100 && self.width==100)) return
if (newVal==undefined) return self.value
ctx.clearRect(0,0,self.width,self.height)
ctx.font = 2 * self.fontSize + 'px Droid Sans'
ctx.textBaseline = "middle"
ctx.fillStyle = self.color
self.value = newVal
if (!self.height || !self.width || (self.height==100 && self.width==100)) return
ctx.clearRect(0,0,self.width,self.height)
ctx.font = 2 * self.fontSize + 'px Droid Sans'
ctx.textBaseline = "middle"
ctx.fillStyle = self.color
if (self.center) {
ctx.textAlign = settings.align
@ -58,36 +60,35 @@
ctx.fillText(newVal,0,this.height/2)
}
}
}
self.on('focus',function(){
self.attr('tabindex','-1')
var i = $('<input></input>')
.prependTo(self)
.val(self.value)
.focus()
.change(function(){
self.val($(this).val())
self.on('focus',function(){
self.attr('tabindex','-1')
var i = $('<input></input>')
.prependTo(self)
.val(self.value)
.focus()
.change(function(){
self.val($(this).val())
i.blur()
})
i.blur(function(){
self.attr('tabindex','0')
i.remove()
})
i.blur(function(){
self.attr('tabindex','0')
i.remove()
$(document).off('.fakeInput')
})
$(document).on('touchstart.fakeInput mousedown.fakeInput',function(e){
})
$(document).on('touchstart.fakeInput mousedown.fakeInput',function(e){
if (e.originalEvent.target!=i[0]) {
i.blur()
}
}).on('keydown.fakeInput', function(e){
}).on('keydown.fakeInput', function(e){
if (e.keyCode==13) i.change()
if (e.keyCode==27) i.off('change').blur()
})
})
})
return self
return self
}
})(jQuery)