From 2262bda87329798f99c3a9cdec9a282465f6abe8 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Mon, 14 Mar 2016 19:36:54 +0100 Subject: [PATCH] - generic collection support for plot - traversing gestures don't break editor's inputs - better editor input eval --- browser/js/app/actions.js | 4 +- browser/js/app/editor/edit-objects.js | 12 +++- browser/js/app/widgets/plot.js | 84 ++++++++++++++++----------- examples/plot.js | 53 ++++++++++++++--- 4 files changed, 106 insertions(+), 47 deletions(-) diff --git a/browser/js/app/actions.js b/browser/js/app/actions.js index 942f89fd..592bdad2 100644 --- a/browser/js/app/actions.js +++ b/browser/js/app/actions.js @@ -181,12 +181,12 @@ module.exports = { }, traversingDisable: function(){ - $('body').delegateDrag('disable') + $('#container').delegateDrag('disable') $('.traversingEnable, .traversingDisable').toggleClass('on') TRAVERSING = false }, traversingEnable: function(){ - $('body').delegateDrag() + $('#container').delegateDrag() $('.traversingEnable, .traversingDisable').toggleClass('on') TRAVERSING = true } diff --git a/browser/js/app/editor/edit-objects.js b/browser/js/app/editor/edit-objects.js index fff6c094..e121a60b 100644 --- a/browser/js/app/editor/edit-objects.js +++ b/browser/js/app/editor/edit-objects.js @@ -69,8 +69,16 @@ var editObject = function(container, data, refresh){ input.on('change',function(){ - var v = $(this).val()!= '' && $(this).data('type') == 'object'?JSON.parse($(this).val()):$(this).val() - data[$(this).attr('title')]= v=='true'||v=='false'?eval(v):v + // var v = $(this).val()!= '' && $(this).data('type') == 'object'?JSON.parse($(this).val()):$(this).val() + var v + try { + eval(`v=${$(this).val()}`) + } catch(err) { + v = $(this).val() + } + console.log(v) + + data[$(this).attr('title')] = v if (v=='') delete data[$(this).attr('title')] updateDom(container,data) }) diff --git a/browser/js/app/widgets/plot.js b/browser/js/app/widgets/plot.js index d38aeb24..9606fad4 100644 --- a/browser/js/app/widgets/plot.js +++ b/browser/js/app/widgets/plot.js @@ -51,10 +51,18 @@ module.exports.create = function(widgetData,container) { } } - for (i in widgetData.points) { - for (j in widgetData.points[i]) { - if (typeof widgetData.points[i][j] == 'string') { - widget.linkedWidgets.push(widgetData.points[i][j]) + + if (typeof widgetData.points=='string') { + + widget.linkedWidgets.push(widgetData.points) + + } else if (typeof widgetData.points=='object') { + + for (i in widgetData.points) { + for (j in widgetData.points[i]) { + if (typeof widgetData.points[i][j] == 'string') { + widget.linkedWidgets.push(widgetData.points[i][j]) + } } } } @@ -99,10 +107,19 @@ module.exports.create = function(widgetData,container) { var point = [] for (i in widget.data) { - var newpoint = [ - mapToScale(widget.data[i][0],[widgetData.rangeX.min,widgetData.rangeX.max],[15,widget.width-15],0,widgetData.logScaleX,true), - mapToScale(widget.data[i][1],[widgetData.rangeY.min,widgetData.rangeY.max],[widget.height-15,15],0,widgetData.logScaleY,true), - ] + var newpoint = widget.data[i].length? + [ + mapToScale(widget.data[i][0],[widgetData.rangeX.min,widgetData.rangeX.max],[15,widget.width-15],0,widgetData.logScaleX,true), + mapToScale(widget.data[i][1],[widgetData.rangeY.min,widgetData.rangeY.max],[widget.height-15,15],0,widgetData.logScaleY,true), + ] + : + [ + mapToScale(i,[0,widget.data.length-1],[15,widget.width-15],0,widgetData.logScaleX,true), + mapToScale(widget.data[i],[widgetData.rangeY.min,widgetData.rangeY.max],[widget.height-15,15],0,widgetData.logScaleY,true), + ] + + + if (first) { ctx.moveTo(newpoint[0],newpoint[1]) first = false @@ -152,34 +169,31 @@ module.exports.create = function(widgetData,container) { widget.fetchValues = function(){ - var data = [] - for (i in widgetData.points) { - data[i] = [] - var point = widgetData.points[i] - if (point.length==2) { - for (k in [0,1]) { - if (typeof point[k] == 'string') { - if (WIDGETS[point[k]] && WIDGETS[point[k]].length) - data[i][k] = WIDGETS[point[k]][WIDGETS[point[k]].length-1].getValue() - } else { - data[i][k] = point[k] - } - } - } else if (point.length==1){ - if (typeof point[0] == 'string') { - if (WIDGETS[point[0]] && WIDGETS[point[0]].length) { - var v = WIDGETS[point[0]][WIDGETS[point[0]].length-1].getValue() - data[i][0] = v[0] - data[i][1] = v[1] - } - } else { - data[i][0] = point[0] - data[i][1] = point[0] - } - } - } + var data = [], + points = widgetData.points + + if (typeof points=='string' && WIDGETS[points]) { + + data = WIDGETS[points][WIDGETS[points].length-1].getValue() + + } else if (typeof points=='object') { + + for (i in points) { + + data[i] = [] + for (k in [0,1]) { + if (typeof points[i][k] == 'string' && WIDGETS[points[i][k]]) { + data[i][k] = WIDGETS[points[i][k]][WIDGETS[points[i][k]].length-1].getValue() + } else { + data[i][k] = points[i][k] + } + } + + } + + } + - if (!datawidget.data) return widget.data = data } diff --git a/examples/plot.js b/examples/plot.js index 46a51d92..0ec96d59 100644 --- a/examples/plot.js +++ b/examples/plot.js @@ -11,7 +11,7 @@ "left": "auto", "top": "auto", "width": "auto", - "height": "auto", + "height": 254, "horizontal": false, "css": "", "absolute": false, @@ -33,7 +33,7 @@ "left": "auto", "top": "auto", "width": "auto", - "height": "auto", + "height": 253, "horizontal": false, "css": "", "absolute": false, @@ -55,7 +55,7 @@ "left": "auto", "top": "auto", "width": "auto", - "height": "auto", + "height": 253, "horizontal": false, "css": "", "absolute": false, @@ -77,7 +77,7 @@ "left": "auto", "top": "auto", "width": "auto", - "height": "auto", + "height": 256, "horizontal": false, "css": "", "absolute": false, @@ -93,11 +93,11 @@ { "type": "plot", "id": "plot_1", - "label": "plot_1", + "label": "plot (faders)", "left": 406, - "top": 215, + "top": 129, "width": "auto", - "height": "auto", + "height": 124, "css": "", "points": [ [ @@ -133,7 +133,7 @@ "left": 406, "top": 7, "width": "auto", - "height": "auto", + "height": 122, "css": "", "id": "visualizer_(fader_1)", "curve": "fader_1", @@ -144,6 +144,43 @@ }, "logScale": false, "label": "visualizer (fader1)" + }, + { + "type": "rgb", + "id": "rgb_1", + "linkId": "", + "label": "rgb_1", + "left": 6, + "top": 261, + "width": "auto", + "height": "auto", + "css": "", + "absolute": false, + "precision": 0, + "path": "/rgb_1", + "split": false, + "target": [] + }, + { + "type": "plot", + "left": 213, + "top": 263, + "width": 191, + "height": 248, + "css": "", + "points": "rgb_1", + "rangeX": { + "min": 0, + "max": 1 + }, + "rangeY": { + "min": 0, + "max": 255 + }, + "logScaleX": false, + "logScaleY": false, + "id": "plot_2", + "label": "plot_2 (rgb)" } ] }