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.

94 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, values) {
  42. if (values.shadow) {
  43. ctx.shadowColor = values.shadowColor;
  44. ctx.shadowBlur = values.shadowSize;
  45. ctx.shadowOffsetX = values.shadowX;
  46. ctx.shadowOffsetY = values.shadowY;
  47. }
  48. }
  49. disableShadow(ctx, values) {
  50. if (values.shadow) {
  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, values) {
  58. if (values.borderDashes !== false) {
  59. if (ctx.setLineDash !== undefined) {
  60. let dashes = values.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. values.borderDashes = false;
  70. }
  71. }
  72. }
  73. disableBorderDashes(ctx, values) {
  74. if (values.borderDashes !== false) {
  75. if (ctx.setLineDash !== undefined) {
  76. ctx.setLineDash([0]);
  77. }
  78. else {
  79. console.warn("setLineDash is not supported in this browser. The dashed borders cannot be used.");
  80. this.options.shapeProperties.borderDashes = false;
  81. values.borderDashes = false;
  82. }
  83. }
  84. }
  85. }
  86. export default NodeBase;