plot: receive stringified arrays (issue #130)

This commit is contained in:
jean-emmanuel 2018-01-28 14:00:51 +01:00
parent c119c6074e
commit c3f361f110
3 changed files with 25 additions and 9 deletions

View file

@ -16,6 +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
- widgets' `precision` option allows setting a specific data type for numbers (sliders can send doubles !)
- misc
- event system rewritten

View file

@ -38,7 +38,12 @@ This one is like the `led` except it takes either three arguments (red, green an
## Plot
The plot receives an array of [x,y] coordinates and draws them on a chart with linear or logarithmic interpolation.
The plot receives an array of coordinates and draws them on a chart. Coordinates can be :
- `y` values evenly spaced on the `x` axis
- `[x, y]` coordinates arrays
!!! info
Coordinates also can be sent as a stringified array
```js
{
@ -51,10 +56,11 @@ The plot receives an array of [x,y] coordinates and draws them on a chart with
- type: `array|string`
- default: `[]`
- usage:
- as a `string`: a widget's `id` whose multiple values will be displayed on the `y` axis, evenly spaced on the `x` axis (only *[matrices](matrices.md)* and *[pads](pads.md)* will work)
- as an `array`: each element must be an `array` of `[x,y]` coordinates, where `x` and `y` can either be a:
- `number`: constant values
- `string`: a widget's `id` whose value will be used
- as a `string`: a widget's `id` whose values will be used
- as an `array`: where items can be
- `number`
- `string` (widget's `id`)
- `[x, y]`: array of `number` or `string`
### `range`
- type: `object`
@ -78,7 +84,7 @@ The plot receives an array of [x,y] coordinates and draws them on a chart with
### `smooth`
- type: `boolean`
- default: `false`
- usage: set to true to make the line smooth. Float values are also acceptable (works fine between 0 and 0.5)
- usage: set to `true` to make the line smooth. Float values are also acceptable (works fine between 0 and 0.5)
### `origin`
- type: `number`

View file

@ -145,10 +145,19 @@ module.exports = class _plots_base extends _canvas_base {
setValue(v, options={}) {
this.data = v
this.batchDraw()
if (typeof v == 'string' && v.indexOf('[') == 0) {
v = JSON.parseFlex(v)
}
if (Array.isArray(v)) {
this.data = v
this.batchDraw()
if (options.sync) this.changed(options)
}
if (options.sync) this.changed(options)
}