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.0 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.boundingBox = {top: 0, left: 0, right: 0, bottom: 0};
  12. }
  13. setOptions(options) {
  14. this.options = options;
  15. }
  16. _distanceToBorder(ctx,angle) {
  17. var borderWidth = 1;
  18. this.resize(ctx);
  19. return Math.min(
  20. Math.abs(this.width / 2 / Math.cos(angle)),
  21. Math.abs(this.height / 2 / Math.sin(angle))) + borderWidth;
  22. }
  23. enableShadow(ctx) {
  24. if (this.options.shadow.enabled === true) {
  25. ctx.shadowColor = 'rgba(0,0,0,0.5)';
  26. ctx.shadowBlur = this.options.shadow.size;
  27. ctx.shadowOffsetX = this.options.shadow.x;
  28. ctx.shadowOffsetY = this.options.shadow.y;
  29. }
  30. }
  31. disableShadow(ctx) {
  32. if (this.options.shadow.enabled === true) {
  33. ctx.shadowColor = 'rgba(0,0,0,0)';
  34. ctx.shadowBlur = 0;
  35. ctx.shadowOffsetX = 0;
  36. ctx.shadowOffsetY = 0;
  37. }
  38. }
  39. enableBorderDashes(ctx) {
  40. if (this.options.shapeProperties.borderDashes !== false) {
  41. if (ctx.setLineDash !== undefined) {
  42. let dashes = this.options.shapeProperties.borderDashes;
  43. if (dashes === true) {
  44. dashes = [5,15]
  45. }
  46. ctx.setLineDash(dashes);
  47. }
  48. else {
  49. console.warn("setLineDash is not supported in this browser. The dashed borders cannot be used.");
  50. this.options.shapeProperties.borderDashes = false;
  51. }
  52. }
  53. }
  54. disableBorderDashes(ctx) {
  55. if (this.options.shapeProperties.borderDashes !== false) {
  56. if (ctx.setLineDash !== undefined) {
  57. ctx.setLineDash([0]);
  58. }
  59. else {
  60. console.warn("setLineDash is not supported in this browser. The dashed borders cannot be used.");
  61. this.options.shapeProperties.borderDashes = false;
  62. }
  63. }
  64. }
  65. }
  66. export default NodeBase;