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.

91 lines
2.6 KiB

  1. class NodeBase {
  2. constructor(options, body, labelModule) {
  3. this.body = body;
  4. this.labelModule = labelModule;
  5. this.setOptions(options);
  6. this.top = undefined;
  7. this.left = undefined;
  8. this.height = undefined;
  9. this.width = undefined;
  10. this.radius = undefined;
  11. this.margin = undefined;
  12. this.boundingBox = {top: 0, left: 0, right: 0, bottom: 0};
  13. }
  14. setOptions(options) {
  15. this.options = options;
  16. }
  17. _setMargins() {
  18. this.margin = {};
  19. if (this.options.margin) {
  20. if (typeof this.options.margin == 'object') {
  21. this.margin.top = this.options.margin.top;
  22. this.margin.right = this.options.margin.right;
  23. this.margin.bottom = this.options.margin.bottom;
  24. this.margin.left = this.options.margin.left;
  25. } else {
  26. this.margin.top = this.options.margin;
  27. this.margin.right = this.options.margin;
  28. this.margin.bottom = this.options.margin;
  29. this.margin.left = this.options.margin;
  30. }
  31. }
  32. }
  33. _distanceToBorder(ctx,angle) {
  34. var borderWidth = this.options.borderWidth;
  35. this.resize(ctx);
  36. return Math.min(
  37. Math.abs(this.width / 2 / Math.cos(angle)),
  38. Math.abs(this.height / 2 / Math.sin(angle))) + borderWidth;
  39. }
  40. enableShadow(ctx) {
  41. if (this.options.shadow.enabled === true) {
  42. ctx.shadowColor = this.options.shadow.color;
  43. ctx.shadowBlur = this.options.shadow.size;
  44. ctx.shadowOffsetX = this.options.shadow.x;
  45. ctx.shadowOffsetY = this.options.shadow.y;
  46. }
  47. }
  48. disableShadow(ctx) {
  49. if (this.options.shadow.enabled === true) {
  50. ctx.shadowColor = 'rgba(0,0,0,0)';
  51. ctx.shadowBlur = 0;
  52. ctx.shadowOffsetX = 0;
  53. ctx.shadowOffsetY = 0;
  54. }
  55. }
  56. enableBorderDashes(ctx) {
  57. if (this.options.shapeProperties.borderDashes !== false) {
  58. if (ctx.setLineDash !== undefined) {
  59. let dashes = this.options.shapeProperties.borderDashes;
  60. if (dashes === true) {
  61. dashes = [5,15]
  62. }
  63. ctx.setLineDash(dashes);
  64. }
  65. else {
  66. console.warn("setLineDash is not supported in this browser. The dashed borders cannot be used.");
  67. this.options.shapeProperties.borderDashes = false;
  68. }
  69. }
  70. }
  71. disableBorderDashes(ctx) {
  72. if (this.options.shapeProperties.borderDashes !== false) {
  73. if (ctx.setLineDash !== undefined) {
  74. ctx.setLineDash([0]);
  75. }
  76. else {
  77. console.warn("setLineDash is not supported in this browser. The dashed borders cannot be used.");
  78. this.options.shapeProperties.borderDashes = false;
  79. }
  80. }
  81. }
  82. }
  83. export default NodeBase;