resize: compute size only once the handler; make sure css color vars are only retreived at first resize / when css changes

This commit is contained in:
jean-emmanuel 2016-12-12 15:46:53 +01:00
parent 3f61d34722
commit d9711e27a6
6 changed files with 14 additions and 13 deletions

View file

@ -118,7 +118,7 @@ var callbacks = module.exports = {
this.href = this.href.replace(/\?.*|$/, queryString);
});
setTimeout(()=>{
$('canvas').trigger('resize')
$('canvas').trigger('resize',[0,0,true])
},100)
GRIDWIDTH = getComputedStyle(document.documentElement).getPropertyValue("--grid-width")
PXSCALE = getComputedStyle(document.documentElement).getPropertyValue("--pixel-scale")

View file

@ -16,7 +16,7 @@ var _canvas_base = module.exports = function() {
this.textColor = getComputedStyle(document.documentElement).getPropertyValue('--color-text-fade')
this.canvas.resize(this.resizeHandleProxy.bind(this))
this.canvas.on('resize',this.resizeHandleProxy.bind(this))
this.ctx.arc = (x, y, r, s, e, c)=>{
@ -35,10 +35,10 @@ _canvas_base.prototype.resizeHandleProxy = function() {
this.resizeHandle.apply(this,arguments)
}
_canvas_base.prototype.resizeHandle = function(){
_canvas_base.prototype.resizeHandle = function(e, width, height, checkColors){
var width = this.canvas.width(),
height = this.canvas.height()
var width = width || this.canvas.width(),
height = height || this.canvas.height()
if (height==100 && width==100) return
@ -49,7 +49,7 @@ _canvas_base.prototype.resizeHandle = function(){
this.canvas[0].setAttribute('width',width)
this.canvas[0].setAttribute('height',height)
if (!self.visible) {
if (!this.visible || checkColors) {
this.visible = true
this.colors.custom = getComputedStyle(this.widget[0]).getPropertyValue('--color-custom')
this.colors.text = getComputedStyle(this.widget[0]).getPropertyValue('--color-text')

View file

@ -48,7 +48,7 @@ _plots_base.prototype.syncHandle = function(e) {
_plots_base.prototype.resizeHandle = function(){
this.updateData()
_canvas_base.prototype.resizeHandle.call(this)
_canvas_base.prototype.resizeHandle.apply(this, arguments)
}
_plots_base.prototype.draw = function() {

View file

@ -117,13 +117,13 @@ _sliders_base.prototype.dragHandle = function(e, data, traversing) {
}
_sliders_base.prototype.resizeHandle = function() {
if (!self.visible) {
_sliders_base.prototype.resizeHandle = function(e, width, height, checkColors) {
if (!this.visible || checkColors) {
this.colors.track = getComputedStyle(this.widget[0]).getPropertyValue('--color-track')
this.colors.gauge = getComputedStyle(this.widget[0]).getPropertyValue('--color-gauge')
this.colors.knob = getComputedStyle(this.widget[0]).getPropertyValue('--color-knob')
}
_canvas_base.prototype.resizeHandle.call(this)
_canvas_base.prototype.resizeHandle.apply(this, arguments)
}

View file

@ -134,7 +134,7 @@ Knob.prototype.percentToAngle = function(percent) {
}
Knob.prototype.resizeHandle = function() {
_sliders_base.prototype.resizeHandle.call(this)
_sliders_base.prototype.resizeHandle.apply(this, arguments)
this.minDimension = Math.min(this.width, this.height)
this.gaugeWidth = this.minDimension / 8
if (this.widgetData.compact) {

View file

@ -56,8 +56,9 @@
if (!document.contains(elem)) continue
var width = elem.offsetWidth,
height = elem.offsetHeight
var style = window.getComputedStyle(elem),
width = parseInt(style['width']) - parseInt(style['padding-left']) - parseInt(style['padding-right']),
height = parseInt(style['height']) - parseInt(style['padding-top']) - parseInt(style['padding-bottom'])
if (!width) continue