@ -7,26 +7,23 @@ class CircularImage extends CircleImageBase {
super ( options , body , labelModule ) ;
super ( options , body , labelModule ) ;
this . setImages ( imageObj , imageObjAlt ) ;
this . setImages ( imageObj , imageObjAlt ) ;
this . _swapToImageResizeWhenImageLoaded = true ;
}
}
resize ( ctx , selected = this . selected , hover = this . hover ) {
resize ( ctx , selected = this . selected , hover = this . hover ) {
if ( ( this . imageObj . src === undefined ) ||
var imageAbsent = ( this . imageObj . src === undefined ) ||
( this . imageObj . width === undefined ) ||
( this . imageObj . width === undefined ) ||
( this . imageObj . height === undefined ) ||
( this . labelModule . differentState ( selected , hover ) ) ) {
( this . imageObj . height === undefined ) ;
if ( imageAbsent ) {
var diameter = this . options . size * 2 ;
var diameter = this . options . size * 2 ;
this . width = diameter ;
this . width = diameter ;
this . height = diameter ;
this . height = diameter ;
this . _swapToImageResizeWhenImageLoaded = true ;
this . radius = 0.5 * this . width ;
this . radius = 0.5 * this . width ;
} else {
if ( this . _swapToImageResizeWhenImageLoaded ) {
this . width = undefined ;
this . height = undefined ;
this . _swapToImageResizeWhenImageLoaded = false ;
}
return ;
}
// At this point, an image is present, i.e. this.imageObj is valid.
if ( this . needsRefresh ( selected , hover ) ) {
this . _resizeImage ( ) ;
this . _resizeImage ( ) ;
}
}
}
}
@ -37,15 +34,14 @@ class CircularImage extends CircleImageBase {
this . switchImages ( selected ) ;
this . switchImages ( selected ) ;
}
}
this . resize ( ) ;
this . selected = selected ;
this . resize ( ctx , selected , hover ) ;
this . left = x - this . width / 2 ;
this . left = x - this . width / 2 ;
this . top = y - this . height / 2 ;
this . top = y - this . height / 2 ;
let size = Math . min ( 0.5 * this . height , 0.5 * this . width ) ;
// draw the background circle. IMPORTANT: the stroke in this method is used by the clip method below.
// draw the background circle. IMPORTANT: the stroke in this method is used by the clip method below.
this . _drawRawCircle ( ctx , x , y , selected , hover , values ) ;
this . _drawRawCircle ( ctx , x , y , values ) ;
// now we draw in the circle, we save so we can revert the clip operation after drawing.
// now we draw in the circle, we save so we can revert the clip operation after drawing.
ctx . save ( ) ;
ctx . save ( ) ;
@ -61,11 +57,14 @@ class CircularImage extends CircleImageBase {
this . updateBoundingBox ( x , y ) ;
this . updateBoundingBox ( x , y ) ;
}
}
// TODO: compare with Circle.updateBoundingBox(), consolidate? More stuff is happening here
updateBoundingBox ( x , y ) {
updateBoundingBox ( x , y ) {
this . boundingBox . top = y - this . options . size ;
this . boundingBox . top = y - this . options . size ;
this . boundingBox . left = x - this . options . size ;
this . boundingBox . left = x - this . options . size ;
this . boundingBox . right = x + this . options . size ;
this . boundingBox . right = x + this . options . size ;
this . boundingBox . bottom = y + this . options . size ;
this . boundingBox . bottom = y + this . options . size ;
// TODO: compare with Image.updateBoundingBox(), consolidate?
this . boundingBox . left = Math . min ( this . boundingBox . left , this . labelModule . size . left ) ;
this . boundingBox . left = Math . min ( this . boundingBox . left , this . labelModule . size . left ) ;
this . boundingBox . right = Math . max ( this . boundingBox . right , this . labelModule . size . left + this . labelModule . size . width ) ;
this . boundingBox . right = Math . max ( this . boundingBox . right , this . labelModule . size . left + this . labelModule . size . width ) ;
this . boundingBox . bottom = Math . max ( this . boundingBox . bottom , this . boundingBox . bottom + this . labelOffset ) ;
this . boundingBox . bottom = Math . max ( this . boundingBox . bottom , this . boundingBox . bottom + this . labelOffset ) ;