plots: remove margin and add origin option
This commit is contained in:
parent
580d2c747b
commit
758f18cbb0
5 changed files with 65 additions and 26 deletions
|
|
@ -61,6 +61,10 @@ The plot receives an array of [x,y] coordinates and draws them on a chart with
|
|||
- default: `false`
|
||||
- usage: set to `true` to use logarithmic scale for the `y` axis (log10)
|
||||
|
||||
#### `origin`
|
||||
- type: `number`
|
||||
- default: `auto`
|
||||
- usage: defines the y-axis origin. Set to `false` to disable it.
|
||||
|
||||
## Eq
|
||||
|
||||
|
|
@ -106,7 +110,10 @@ The Eq receives an array of filter objects and draws their frequency response be
|
|||
- default: `false`
|
||||
- usage: set to `true` to use logarithmic scale for the `x` axis (log10)
|
||||
|
||||
|
||||
#### `origin`
|
||||
- type: `number`
|
||||
- default: `auto`
|
||||
- usage: defines the y-axis origin. Set to `false` to disable it.
|
||||
|
||||
## Visualizer
|
||||
|
||||
|
|
@ -139,6 +146,10 @@ The visualizer displays the evolution in time of a received value (through osc)
|
|||
- default: `false`
|
||||
- usage: set to `true` use logarithmic scaling (log10)
|
||||
|
||||
#### `origin`
|
||||
- type: `number`
|
||||
- default: `auto`
|
||||
- usage: defines the y-axis origin. Set to `false` to disable it.
|
||||
|
||||
## Text
|
||||
|
||||
|
|
|
|||
|
|
@ -61,27 +61,52 @@ _plots_base.prototype.draw = function() {
|
|||
this.ctx.strokeStyle = this.colors.custom
|
||||
this.ctx.stroke()
|
||||
|
||||
|
||||
|
||||
if (this.widgetData.origin !== false) {
|
||||
|
||||
var origin = mapToScale(this.widgetData.origin||this.rangeY.min,[this.rangeY.min,this.rangeY.max],[this.height,0],0,this.widgetData.logScaleY,true)
|
||||
|
||||
this.ctx.save()
|
||||
this.ctx.globalAlpha = 0.1
|
||||
this.ctx.fillStyle = this.colors.custom
|
||||
this.ctx.lineTo(this.width,origin)
|
||||
this.ctx.lineTo(0,origin)
|
||||
this.ctx.closePath()
|
||||
this.ctx.fill()
|
||||
this.ctx.restore()
|
||||
|
||||
}
|
||||
|
||||
|
||||
this.ctx.font = PXSCALE * 10 + 'px sans-serif'
|
||||
this.ctx.fillStyle = this.colors.text
|
||||
|
||||
if (this.pips.x) {
|
||||
|
||||
this.ctx.textBaseline = "bottom"
|
||||
this.ctx.textAlign = 'left'
|
||||
this.ctx.fillText(this.pips.x.min,12*PXSCALE,this.height)
|
||||
this.ctx.textAlign = 'right'
|
||||
this.ctx.fillText(this.pips.x.max,this.width-10,this.height)
|
||||
this.ctx.textBaseline = "bottom"
|
||||
this.ctx.textAlign = 'left'
|
||||
this.ctx.fillText(this.pips.x.min,(this.pips.y?12:2)*PXSCALE,this.height)
|
||||
this.ctx.textAlign = 'right'
|
||||
this.ctx.fillText(this.pips.x.max,this.width-2*PXSCALE,this.height)
|
||||
|
||||
this.ctx.save()
|
||||
this.ctx.translate(0, this.height)
|
||||
this.ctx.rotate(-Math.PI/2)
|
||||
}
|
||||
|
||||
this.ctx.textBaseline = "top"
|
||||
this.ctx.textAlign = 'left'
|
||||
this.ctx.fillText(this.pips.y.min,12*PXSCALE,2*PXSCALE)
|
||||
this.ctx.textAlign = 'right'
|
||||
this.ctx.fillText(this.pips.y.max,this.height-10*PXSCALE,2*PXSCALE)
|
||||
this.ctx.rotate(Math.PI/2)
|
||||
this.ctx.restore()
|
||||
if (this.pips.y) {
|
||||
|
||||
this.ctx.save()
|
||||
this.ctx.translate(0, this.height)
|
||||
this.ctx.rotate(-Math.PI/2)
|
||||
|
||||
this.ctx.textBaseline = "top"
|
||||
this.ctx.textAlign = 'left'
|
||||
this.ctx.fillText(this.pips.y.min,(this.pips.x?12:2)*PXSCALE,2*PXSCALE)
|
||||
this.ctx.textAlign = 'right'
|
||||
this.ctx.fillText(this.pips.y.max,this.height-2*PXSCALE,2*PXSCALE)
|
||||
this.ctx.rotate(Math.PI/2)
|
||||
this.ctx.restore()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -95,21 +120,22 @@ _plots_base.prototype.draw_data = function() {
|
|||
|
||||
var newpoint = this.data[i].length?
|
||||
[
|
||||
mapToScale(this.data[i][0],[this.rangeX.min,this.rangeX.max],[15*PXSCALE,this.width-15*PXSCALE],0,this.widgetData.logScaleX,true),
|
||||
mapToScale(this.data[i][1],[this.rangeY.min,this.rangeY.max],[this.height-15*PXSCALE,15*PXSCALE],0,this.widgetData.logScaleY,true),
|
||||
mapToScale(this.data[i][0],[this.rangeX.min,this.rangeX.max],[0,this.width],0,this.widgetData.logScaleX,true),
|
||||
mapToScale(this.data[i][1],[this.rangeY.min,this.rangeY.max],[this.height-PXSCALE,PXSCALE],0,this.widgetData.logScaleY,true),
|
||||
]
|
||||
:
|
||||
[
|
||||
mapToScale(i,[0,this.data.length-1],[15*PXSCALE,this.width-15*PXSCALE],0,this.widgetData.logScaleX,true),
|
||||
mapToScale(this.data[i],[this.rangeY.min,this.rangeY.max],[this.height-15*PXSCALE,15*PXSCALE],0,this.widgetData.logScaleY,true),
|
||||
mapToScale(i,[0,this.data.length-1],[0,this.width],0,this.widgetData.logScaleX,true),
|
||||
mapToScale(this.data[i],[this.rangeY.min,this.rangeY.max],[this.height-PXSCALE,PXSCALE],0,this.widgetData.logScaleY,true),
|
||||
]
|
||||
|
||||
|
||||
if (first) {
|
||||
this.ctx.moveTo(newpoint[0],newpoint[1])
|
||||
this.ctx.lineTo(newpoint[0],newpoint[1])
|
||||
first = false
|
||||
} else {
|
||||
this.ctx.moveTo(point[0],point[1])
|
||||
// this.ctx.moveTo(point[0],point[1])
|
||||
this.ctx.lineTo(newpoint[0],newpoint[1])
|
||||
}
|
||||
point = newpoint
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ module.exports.options = {
|
|||
filters:[],
|
||||
resolution:128,
|
||||
rangeY: {min:-20,max:20},
|
||||
origin: 'auto',
|
||||
logScaleX: false,
|
||||
|
||||
separator3:'osc',
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ module.exports.options = {
|
|||
points:[],
|
||||
rangeX: {min:0,max:1},
|
||||
rangeY: {min:0,max:1},
|
||||
origin: 'auto',
|
||||
logScaleX: false,
|
||||
logScaleY: false,
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ module.exports.options = {
|
|||
widgetId:'',
|
||||
duration:1,
|
||||
range: {min:0,max:1},
|
||||
origin: 'auto',
|
||||
logScale: false,
|
||||
|
||||
separator3:'osc',
|
||||
|
|
@ -34,8 +35,7 @@ var Visualizer = function(widgetData) {
|
|||
|
||||
this.pips.y.min = Math.abs(widgetData.range.min)>=1000?widgetData.range.min/1000+'k':widgetData.range.min
|
||||
this.pips.y.max = Math.abs(widgetData.range.max)>=1000?widgetData.range.max/1000+'k':widgetData.range.max
|
||||
this.pips.x.min = ''
|
||||
this.pips.x.max = ''
|
||||
this.pips.x = false
|
||||
this.length = Math.round(clip(60*widgetData.duration,[8,4096]))
|
||||
this.data = new Array(this.length)
|
||||
this.value = widgetData.range.min
|
||||
|
|
@ -77,10 +77,10 @@ Visualizer.prototype.draw_data = function(){
|
|||
var first = true
|
||||
var point = []
|
||||
|
||||
for (var i=this.length-1;i>=0;i=i-1) {
|
||||
for (var i=0;i<this.length;i++) {
|
||||
var newpoint = [
|
||||
mapToScale(i,[0,this.length-1],[15*PXSCALE,this.width-15*PXSCALE],1),
|
||||
mapToScale(this.data[i],[this.widgetData.range.min,this.widgetData.range.max],[this.height-15*PXSCALE,15*PXSCALE],1,this.widgetData.logScale,true),
|
||||
mapToScale(i,[0,this.length-1],[0,this.width],1),
|
||||
mapToScale(this.data[i],[this.widgetData.range.min,this.widgetData.range.max],[this.height-PXSCALE,PXSCALE],1,this.widgetData.logScale,true),
|
||||
]
|
||||
if (first) {
|
||||
this.ctx.moveTo(newpoint[0],newpoint[1])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue