vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

76 lines
2.7 KiB

'use strict';
import NodeBase from '../util/NodeBase'
/**
* Am Ellipse Node/Cluster shape.
*
* @class Ellipse
* @extends NodeBase
*/
class Ellipse extends NodeBase {
/**
* @param {Object} options
* @param {Object} body
* @param {Label} labelModule
* @constructor Ellipse
*/
constructor(options, body, labelModule) {
super(options, body, labelModule);
}
/**
*
* @param {CanvasRenderingContext2D} ctx - Unused.
* @param {Boolean} [selected]
* @param {Boolean} [hover]
*/
resize(ctx, selected = this.selected, hover = this.hover) {
if (this.needsRefresh(selected, hover)) {
var textSize = this.labelModule.getTextSize(ctx, selected, hover);
this.height = textSize.height * 2;
this.width = textSize.width + this.height;
this.radius = 0.5*this.width;
}
}
/**
*
* @param {CanvasRenderingContext2D} ctx
* @param {number} x width
* @param {number} y height
* @param {boolean} selected
* @param {boolean} hover
* @param {{toArrow: boolean, toArrowScale: (allOptions.edges.arrows.to.scaleFactor|{number}|allOptions.edges.arrows.middle.scaleFactor|allOptions.edges.arrows.from.scaleFactor|Array|number), toArrowType: *, middleArrow: boolean, middleArrowScale: (number|allOptions.edges.arrows.middle.scaleFactor|{number}|Array), middleArrowType: (allOptions.edges.arrows.middle.type|{string}|string|*), fromArrow: boolean, fromArrowScale: (allOptions.edges.arrows.to.scaleFactor|{number}|allOptions.edges.arrows.middle.scaleFactor|allOptions.edges.arrows.from.scaleFactor|Array|number), fromArrowType: *, arrowStrikethrough: (*|boolean|allOptions.edges.arrowStrikethrough|{boolean}), color: undefined, inheritsColor: (string|string|string|allOptions.edges.color.inherit|{string, boolean}|Array|*), opacity: *, hidden: *, length: *, shadow: *, shadowColor: *, shadowSize: *, shadowX: *, shadowY: *, dashes: (*|boolean|Array|allOptions.edges.dashes|{boolean, array}), width: *}} values
*/
draw(ctx, x, y, selected, hover, values) {
this.resize(ctx, selected, hover);
this.left = x - this.width * 0.5;
this.top = y - this.height * 0.5;
this.initContextForDraw(ctx, values);
ctx.ellipse_vis(this.left, this.top, this.width, this.height);
this.performFill(ctx, values);
this.updateBoundingBox(x, y, ctx, selected, hover);
this.labelModule.draw(ctx, x, y, selected, hover);
}
/**
*
* @param {CanvasRenderingContext2D} ctx
* @param {Number} angle
* @returns {Number}
*/
distanceToBorder(ctx, angle) {
this.resize(ctx);
var a = this.width * 0.5;
var b = this.height * 0.5;
var w = (Math.sin(angle) * a);
var h = (Math.cos(angle) * b);
return a * b / Math.sqrt(w * w + h * h);
}
}
export default Ellipse;