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.

40 lines
994 B

  1. /**
  2. * Created by Alex on 3/18/2015.
  3. */
  4. 'use strict';
  5. import BaseNode from '../util/baseNode'
  6. class Text extends BaseNode {
  7. constructor(options, body, labelModule) {
  8. super(options, body, labelModule);
  9. }
  10. resize(ctx, selected) {
  11. if (this.width === undefined) {
  12. var margin = 5;
  13. var textSize = this.labelModule.getTextSize(ctx,selected);
  14. this.width = textSize.width + 2 * margin;
  15. this.height = textSize.height + 2 * margin;
  16. }
  17. }
  18. draw(ctx, x, y, selected, hover) {
  19. this.resize(ctx, selected || hover);
  20. this.left = x - this.width / 2;
  21. this.top = y - this.height / 2;
  22. this.labelModule.draw(ctx, x, y, selected || hover);
  23. this.boundingBox.top = this.top;
  24. this.boundingBox.left = this.left;
  25. this.boundingBox.right = this.left + this.width;
  26. this.boundingBox.bottom = this.top + this.height;
  27. }
  28. distanceToBorder(ctx, angle) {
  29. this.resize(ctx);
  30. return this._distanceToBorder(angle);
  31. }
  32. }
  33. export default Text;