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.

58 lines
1.8 KiB

  1. /**
  2. * Created by Alex on 3/18/2015.
  3. */
  4. 'use strict';
  5. import NodeBase from '../util/NodeBase'
  6. class Database extends NodeBase {
  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. var size = textSize.width + 2 * margin;
  15. this.width = size;
  16. this.height = size;
  17. }
  18. }
  19. draw(ctx, x, y, selected, hover) {
  20. this.resize(ctx, selected);
  21. this.left = x - this.width / 2;
  22. this.top = y - this.height / 2;
  23. var borderWidth = this.options.borderWidth;
  24. var selectionLineWidth = this.options.borderWidthSelected || 2 * this.options.borderWidth;
  25. ctx.strokeStyle = selected ? this.options.color.highlight.border : hover ? this.options.color.hover.border : this.options.color.border;
  26. ctx.lineWidth = (this.selected ? selectionLineWidth : borderWidth);
  27. ctx.lineWidth *= this.networkScaleInv;
  28. ctx.lineWidth = Math.min(this.width, ctx.lineWidth);
  29. ctx.fillStyle = selected ? this.options.color.highlight.background : hover ? this.options.color.hover.background : this.options.color.background;
  30. ctx.database(x - this.width / 2, y - this.height * 0.5, this.width, this.height);
  31. ctx.fill();
  32. ctx.stroke();
  33. this.boundingBox.top = this.top;
  34. this.boundingBox.left = this.left;
  35. this.boundingBox.right = this.left + this.width;
  36. this.boundingBox.bottom = this.top + this.height;
  37. this.labelModule.draw(ctx, x, y, selected);
  38. }
  39. distanceToBorder(ctx, angle) {
  40. this.resize(ctx);
  41. var a = this.width / 2;
  42. var b = this.height / 2;
  43. var w = (Math.sin(angle) * a);
  44. var h = (Math.cos(angle) * b);
  45. return a * b / Math.sqrt(w * w + h * h);
  46. }
  47. }
  48. export default Database;