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.

70 lines
2.7 KiB

  1. 'use strict';
  2. import NodeBase from '../util/NodeBase'
  3. /**
  4. * A Database Node/Cluster shape.
  5. *
  6. * @extends NodeBase
  7. */
  8. class Database extends NodeBase {
  9. /**
  10. * @param {Object} options
  11. * @param {Object} body
  12. * @param {Label} labelModule
  13. */
  14. constructor (options, body, labelModule) {
  15. super(options, body, labelModule);
  16. this._setMargins(labelModule);
  17. }
  18. /**
  19. *
  20. * @param {CanvasRenderingContext2D} ctx
  21. * @param {boolean} selected
  22. * @param {boolean} hover
  23. */
  24. resize(ctx, selected, hover) {
  25. if (this.needsRefresh(selected, hover)) {
  26. this.textSize = this.labelModule.getTextSize(ctx, selected, hover);
  27. var size = this.textSize.width + this.margin.right + this.margin.left;
  28. this.width = size;
  29. this.height = size;
  30. this.radius = this.width / 2;
  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 / 2;
  45. this.top = y - this.height / 2;
  46. this.initContextForDraw(ctx, values);
  47. ctx.database(x - this.width / 2, y - this.height / 2, this.width, this.height);
  48. this.performFill(ctx, values);
  49. this.updateBoundingBox(x, y, ctx, selected, hover);
  50. this.labelModule.draw(ctx, this.left + this.textSize.width / 2 + this.margin.left,
  51. this.top + this.textSize.height / 2 + this.margin.top, selected, hover);
  52. }
  53. /**
  54. *
  55. * @param {CanvasRenderingContext2D} ctx
  56. * @param {number} angle
  57. * @returns {number}
  58. */
  59. distanceToBorder(ctx, angle) {
  60. return this._distanceToBorder(ctx, angle);
  61. }
  62. }
  63. export default Database;