|
|
@ -1,10 +1,22 @@ |
|
|
|
import NodeBase from '../util/NodeBase' |
|
|
|
|
|
|
|
/** |
|
|
|
* NOTE: This is a bad base class |
|
|
|
* |
|
|
|
* Child classes are: |
|
|
|
* |
|
|
|
* Image - uses *only* image methods |
|
|
|
* Circle - uses *only* _drawRawCircle |
|
|
|
* CircleImage - uses all |
|
|
|
* |
|
|
|
* TODO: Refactor, move _drawRawCircle to different module, derive Circle from NodeBase |
|
|
|
* Rename this to ImageBase |
|
|
|
* Consolidate common code in Image and CircleImage to base class |
|
|
|
*/ |
|
|
|
class CircleImageBase extends NodeBase { |
|
|
|
constructor(options, body, labelModule) { |
|
|
|
super(options, body, labelModule); |
|
|
|
this.labelOffset = 0; |
|
|
|
this.imageLoaded = false; |
|
|
|
this.selected = false; |
|
|
|
} |
|
|
|
|
|
|
@ -38,57 +50,43 @@ class CircleImageBase extends NodeBase { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* This function resizes the image by the options size when the image has not yet loaded. If the image has loaded, we |
|
|
|
* force the update of the size again. |
|
|
|
* Adjust the node dimensions for a loaded image. |
|
|
|
* |
|
|
|
* @private |
|
|
|
* Pre: this.imageObj is valid |
|
|
|
*/ |
|
|
|
_resizeImage() { |
|
|
|
let force = false; |
|
|
|
if (!this.imageObj.width || !this.imageObj.height) { // undefined or 0
|
|
|
|
this.imageLoaded = false; |
|
|
|
} |
|
|
|
else if (this.imageLoaded === false) { |
|
|
|
this.imageLoaded = true; |
|
|
|
force = true; |
|
|
|
} |
|
|
|
var width, height; |
|
|
|
|
|
|
|
if (!this.width || !this.height || force === true) { // undefined or 0
|
|
|
|
var width, height, ratio; |
|
|
|
if (this.imageObj.width && this.imageObj.height) { // not undefined or 0
|
|
|
|
width = 0; |
|
|
|
height = 0; |
|
|
|
} |
|
|
|
if (this.options.shapeProperties.useImageSize === false) { |
|
|
|
if (this.imageObj.width > this.imageObj.height) { |
|
|
|
ratio = this.imageObj.width / this.imageObj.height; |
|
|
|
width = this.options.size * 2 * ratio || this.imageObj.width; |
|
|
|
height = this.options.size * 2 || this.imageObj.height; |
|
|
|
if (this.options.shapeProperties.useImageSize === false) { |
|
|
|
// Use the size property
|
|
|
|
var ratio_width = 1; |
|
|
|
var ratio_height = 1; |
|
|
|
|
|
|
|
// Only calculate the proper ratio if both width and height not zero
|
|
|
|
if (this.imageObj.width && this.imageObj.height) { |
|
|
|
if (this.imageObj.width > this.imageObj.height) { |
|
|
|
ratio_width = this.imageObj.width / this.imageObj.height; |
|
|
|
} |
|
|
|
else { |
|
|
|
if (this.imageObj.width && this.imageObj.height) { // not undefined or 0
|
|
|
|
ratio = this.imageObj.height / this.imageObj.width; |
|
|
|
} |
|
|
|
else { |
|
|
|
ratio = 1; |
|
|
|
} |
|
|
|
width = this.options.size * 2; |
|
|
|
height = this.options.size * 2 * ratio; |
|
|
|
ratio_height = this.imageObj.height / this.imageObj.width; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
// when not using the size property, we use the image size
|
|
|
|
width = this.imageObj.width; |
|
|
|
height = this.imageObj.height; |
|
|
|
} |
|
|
|
this.width = width; |
|
|
|
this.height = height; |
|
|
|
this.radius = 0.5 * this.width; |
|
|
|
|
|
|
|
width = this.options.size * 2 * ratio_width; |
|
|
|
height = this.options.size * 2 * ratio_height; |
|
|
|
} |
|
|
|
else { |
|
|
|
// Use the image size
|
|
|
|
width = this.imageObj.width; |
|
|
|
height = this.imageObj.height; |
|
|
|
} |
|
|
|
|
|
|
|
this.width = width; |
|
|
|
this.height = height; |
|
|
|
this.radius = 0.5 * this.width; |
|
|
|
} |
|
|
|
|
|
|
|
_drawRawCircle(ctx, x, y, selected, hover, values) { |
|
|
|
_drawRawCircle(ctx, x, y, values) { |
|
|
|
var borderWidth = values.borderWidth / this.body.view.scale; |
|
|
|
ctx.lineWidth = Math.min(this.width, borderWidth); |
|
|
|
|
|
|
|