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.

50 lines
1.2 KiB

  1. 'use strict';
  2. import NodeBase from '../util/NodeBase'
  3. class Text extends NodeBase {
  4. constructor(options, body, labelModule) {
  5. super(options, body, labelModule);
  6. }
  7. resize(ctx, selected) {
  8. if (this.width === undefined) {
  9. var margin = 5;
  10. var textSize = this.labelModule.getTextSize(ctx,selected);
  11. this.width = textSize.width + 2 * margin;
  12. this.height = textSize.height + 2 * margin;
  13. this.radius = 0.5*this.width;
  14. }
  15. }
  16. draw(ctx, x, y, selected, hover) {
  17. this.resize(ctx, selected || hover);
  18. this.left = x - this.width / 2;
  19. this.top = y - this.height / 2;
  20. // draw shadow if enabled
  21. this.enableShadow(ctx);
  22. this.labelModule.draw(ctx, x, y, selected || hover);
  23. // disable shadows for other elements.
  24. this.disableShadow(ctx);
  25. this.updateBoundingBox(x,y);
  26. }
  27. updateBoundingBox(x,y) {
  28. this.left = x - this.width / 2;
  29. this.top = y - this.height / 2;
  30. this.boundingBox.top = this.top;
  31. this.boundingBox.left = this.left;
  32. this.boundingBox.right = this.left + this.width;
  33. this.boundingBox.bottom = this.top + this.height;
  34. }
  35. distanceToBorder(ctx, angle) {
  36. this.resize(ctx);
  37. return this._distanceToBorder(angle);
  38. }
  39. }
  40. export default Text;