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.

92 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(labelModule) {
  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. labelModule.adjustSizes(this.margin)
  33. }
  34. _distanceToBorder(ctx,angle) {
  35. var borderWidth = this.options.borderWidth;
  36. this.resize(ctx);
  37. return Math.min(
  38. Math.abs(this.width / 2 / Math.cos(angle)),
  39. Math.abs(this.height / 2 / Math.sin(angle))) + borderWidth;
  40. }
  41. enableShadow(ctx) {
  42. if (this.options.shadow.enabled === true) {
  43. ctx.shadowColor = this.options.shadow.color;
  44. ctx.shadowBlur = this.options.shadow.size;
  45. ctx.shadowOffsetX = this.options.shadow.x;
  46. ctx.shadowOffsetY = this.options.shadow.y;
  47. }
  48. }
  49. disableShadow(ctx) {
  50. if (this.options.shadow.enabled === true) {
  51. ctx.shadowColor = 'rgba(0,0,0,0)';
  52. ctx.shadowBlur = 0;
  53. ctx.shadowOffsetX = 0;
  54. ctx.shadowOffsetY = 0;
  55. }
  56. }
  57. enableBorderDashes(ctx) {
  58. if (this.options.shapeProperties.borderDashes !== false) {
  59. if (ctx.setLineDash !== undefined) {
  60. let dashes = this.options.shapeProperties.borderDashes;
  61. if (dashes === true) {
  62. dashes = [5,15]
  63. }
  64. ctx.setLineDash(dashes);
  65. }
  66. else {
  67. console.warn("setLineDash is not supported in this browser. The dashed borders cannot be used.");
  68. this.options.shapeProperties.borderDashes = false;
  69. }
  70. }
  71. }
  72. disableBorderDashes(ctx) {
  73. if (this.options.shapeProperties.borderDashes !== false) {
  74. if (ctx.setLineDash !== undefined) {
  75. ctx.setLineDash([0]);
  76. }
  77. else {
  78. console.warn("setLineDash is not supported in this browser. The dashed borders cannot be used.");
  79. this.options.shapeProperties.borderDashes = false;
  80. }
  81. }
  82. }
  83. }
  84. export default NodeBase;