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.

76 lines
2.6 KiB

  1. 'use strict';
  2. import NodeBase from '../util/NodeBase'
  3. class Database extends NodeBase {
  4. constructor (options, body, labelModule) {
  5. super(options, body, labelModule);
  6. this._setMargins();
  7. }
  8. resize(ctx, selected) {
  9. if (this.width === undefined) {
  10. this.textSize = this.labelModule.getTextSize(ctx, selected);
  11. var size = this.textSize.width + this.margin.right + this.margin.left;
  12. this.width = size;
  13. this.height = size;
  14. this.radius = this.width / 2;
  15. }
  16. }
  17. draw(ctx, x, y, selected, hover) {
  18. this.resize(ctx, selected);
  19. this.left = x - this.width / 2;
  20. this.top = y - this.height / 2;
  21. var neutralborderWidth = this.options.borderWidth;
  22. var selectionLineWidth = this.options.borderWidthSelected || 2 * this.options.borderWidth;
  23. var borderWidth = (selected ? selectionLineWidth : neutralborderWidth) / this.body.view.scale;
  24. ctx.lineWidth = Math.min(this.width, borderWidth);
  25. ctx.strokeStyle = selected ? this.options.color.highlight.border : hover ? this.options.color.hover.border : this.options.color.border;
  26. ctx.fillStyle = selected ? this.options.color.highlight.background : hover ? this.options.color.hover.background : this.options.color.background;
  27. ctx.database(x - this.width / 2, y - this.height / 2, this.width, this.height);
  28. // draw shadow if enabled
  29. this.enableShadow(ctx);
  30. // draw the background
  31. ctx.fill();
  32. // disable shadows for other elements.
  33. this.disableShadow(ctx);
  34. //draw dashed border if enabled, save and restore is required for firefox not to crash on unix.
  35. ctx.save();
  36. // if borders are zero width, they will be drawn with width 1 by default. This prevents that
  37. if (borderWidth > 0) {
  38. this.enableBorderDashes(ctx);
  39. //draw the border
  40. ctx.stroke();
  41. //disable dashed border for other elements
  42. this.disableBorderDashes(ctx);
  43. }
  44. ctx.restore();
  45. this.updateBoundingBox(x,y,ctx,selected);
  46. this.labelModule.draw(ctx, this.left + this.textSize.width / 2 + this.margin.left,
  47. this.top + this.textSize.height / 2 + this.margin.top, selected);
  48. }
  49. updateBoundingBox(x,y,ctx, selected) {
  50. this.resize(ctx, selected);
  51. this.left = x - this.width * 0.5;
  52. this.top = y - this.height * 0.5;
  53. this.boundingBox.left = this.left;
  54. this.boundingBox.top = this.top;
  55. this.boundingBox.bottom = this.top + this.height;
  56. this.boundingBox.right = this.left + this.width;
  57. }
  58. distanceToBorder(ctx, angle) {
  59. return this._distanceToBorder(ctx,angle);
  60. }
  61. }
  62. export default Database;