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.

54 lines
1.3 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. /**
  2. * Prototype for visual components
  3. * @param {{dom: Object, domProps: Object, emitter: Emitter, range: Range}} [body]
  4. * @param {Object} [options]
  5. */
  6. function Component (body, options) {
  7. this.options = null;
  8. this.props = null;
  9. }
  10. /**
  11. * Set options for the component. The new options will be merged into the
  12. * current options.
  13. * @param {Object} options
  14. */
  15. Component.prototype.setOptions = function(options) {
  16. if (options) {
  17. util.extend(this.options, options);
  18. }
  19. };
  20. /**
  21. * Repaint the component
  22. * @return {boolean} Returns true if the component is resized
  23. */
  24. Component.prototype.redraw = function() {
  25. // should be implemented by the component
  26. return false;
  27. };
  28. /**
  29. * Destroy the component. Cleanup DOM and event listeners
  30. */
  31. Component.prototype.destroy = function() {
  32. // should be implemented by the component
  33. };
  34. /**
  35. * Test whether the component is resized since the last time _isResized() was
  36. * called.
  37. * @return {Boolean} Returns true if the component is resized
  38. * @protected
  39. */
  40. Component.prototype._isResized = function() {
  41. var resized = (this.props._previousWidth !== this.props.width ||
  42. this.props._previousHeight !== this.props.height);
  43. this.props._previousWidth = this.props.width;
  44. this.props._previousHeight = this.props.height;
  45. return resized;
  46. };
  47. module.exports = Component;