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.

46 lines
1.1 KiB

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