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.

72 lines
2.8 KiB

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