diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ad972d9..e73b9e52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ - switch: added `showValues` to display both values and labels in the buttons; array values can now be selected via osc - rgb: **removed** `touchAddress` option - labels/texts: multiple white spaces are no longer merged - - plot: can receive stringified arrays of coordinates; added `bars` option for drawing barcharts + - plot: can receive stringified arrays of coordinates or stringified objects for merging coordinates sets; added `bars` option for drawing barcharts; - widgets' `precision` option allows setting a specific data type for numbers (sliders can send doubles !) - misc - event system rewritten diff --git a/resources/docs/widgets/plots.md b/resources/docs/widgets/plots.md index e35f55a4..6aeceb8c 100644 --- a/resources/docs/widgets/plots.md +++ b/resources/docs/widgets/plots.md @@ -43,7 +43,7 @@ The plot receives an array of coordinates and draws them on a chart. Coordinates - `[x, y]` coordinates arrays !!! info - Coordinates also can be sent as a stringified array + Coordinates also can be sent as a stringified array (`[]`). A stringified object can also be sent to change specific points' coordinates (e.g. `{0:1, 4:0}` will change the 1st and 5th points' coordinates) . ```js { diff --git a/src/browser/js/app/widgets/plots/_plots_base.js b/src/browser/js/app/widgets/plots/_plots_base.js index 1b6eec32..7c84b5f4 100644 --- a/src/browser/js/app/widgets/plots/_plots_base.js +++ b/src/browser/js/app/widgets/plots/_plots_base.js @@ -171,13 +171,24 @@ module.exports = class _plots_base extends _canvas_base { setValue(v, options={}) { - if (typeof v == 'string' && v.indexOf('[') == 0) { + if (typeof v == 'string' && (v[0] == '[' || v[0] == '{' )) { v = JSON.parseFlex(v) } - if (Array.isArray(v)) { + if (typeof v == 'object') { + + if (Array.isArray(v)) { + + this.data = v + + } else { + + for (var i in v) { + if (!isNaN(i)) this.data[i] = v[i] + } + + } - this.data = v this.batchDraw() if (options.sync) this.changed(options)