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

  1. 'use strict';
  2. import NodeBase from '../util/NodeBase'
  3. /**
  4. * Am Ellipse Node/Cluster shape.
  5. *
  6. * @class Ellipse
  7. * @extends NodeBase
  8. */
  9. class Ellipse extends NodeBase {
  10. /**
  11. * @param {Object} options
  12. * @param {Object} body
  13. * @param {Label} labelModule
  14. * @constructor Ellipse
  15. */
  16. constructor(options, body, labelModule) {
  17. super(options, body, labelModule);
  18. }
  19. /**
  20. *
  21. * @param {CanvasRenderingContext2D} ctx - Unused.
  22. * @param {Boolean} [selected]
  23. * @param {Boolean} [hover]
  24. */
  25. resize(ctx, selected = this.selected, hover = this.hover) {
  26. if (this.needsRefresh(selected, hover)) {
  27. var textSize = this.labelModule.getTextSize(ctx, selected, hover);
  28. this.height = textSize.height * 2;
  29. this.width = textSize.width + this.height;
  30. this.radius = 0.5*this.width;
  31. }
  32. }
  33. /**
  34. *
  35. * @param {CanvasRenderingContext2D} ctx
  36. * @param {number} x width
  37. * @param {number} y height
  38. * @param {boolean} selected
  39. * @param {boolean} hover
  40. * @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
  41. */
  42. draw(ctx, x, y, selected, hover, values) {
  43. this.resize(ctx, selected, hover);
  44. this.left = x - this.width * 0.5;
  45. this.top = y - this.height * 0.5;
  46. this.initContextForDraw(ctx, values);
  47. ctx.ellipse_vis(this.left, this.top, this.width, this.height);
  48. this.performFill(ctx, values);
  49. this.updateBoundingBox(x, y, ctx, selected, hover);
  50. this.labelModule.draw(ctx, x, y, selected, hover);
  51. }
  52. /**
  53. *
  54. * @param {CanvasRenderingContext2D} ctx
  55. * @param {Number} angle
  56. * @returns {Number}
  57. */
  58. distanceToBorder(ctx, angle) {
  59. this.resize(ctx);
  60. var a = this.width * 0.5;
  61. var b = this.height * 0.5;
  62. var w = (Math.sin(angle) * a);
  63. var h = (Math.cos(angle) * b);
  64. return a * b / Math.sqrt(w * w + h * h);
  65. }
  66. }
  67. export default Ellipse;