jqplot.divTitleRenderer.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /**
  2. * jqPlot
  3. * Pure JavaScript plotting plugin using jQuery
  4. *
  5. * Version: @VERSION
  6. * Revision: @REVISION
  7. *
  8. * Copyright (c) 2009-2013 Chris Leonello
  9. * jqPlot is currently available for use in all personal or commercial projects
  10. * under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
  11. * version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
  12. * choose the license that best suits your project and use it accordingly.
  13. *
  14. * Although not required, the author would appreciate an email letting him
  15. * know of any substantial use of jqPlot. You can reach the author at:
  16. * chris at jqplot dot com or see http://www.jqplot.com/info.php .
  17. *
  18. * If you are feeling kind and generous, consider supporting the project by
  19. * making a donation at: http://www.jqplot.com/donate.php .
  20. *
  21. * sprintf functions contained in jqplot.sprintf.js by Ash Searle:
  22. *
  23. * version 2007.04.27
  24. * author Ash Searle
  25. * http://hexmen.com/blog/2007/03/printf-sprintf/
  26. * http://hexmen.com/js/sprintf.js
  27. * The author (Ash Searle) has placed this code in the public domain:
  28. * "This code is unrestricted: you are free to use it however you like."
  29. *
  30. */
  31. (function($) {
  32. // Class: $.jqplot.DivTitleRenderer
  33. // The default title renderer for jqPlot. This class has no options beyond the <Title> class.
  34. $.jqplot.DivTitleRenderer = function() {
  35. };
  36. $.jqplot.DivTitleRenderer.prototype.init = function(options) {
  37. $.extend(true, this, options);
  38. };
  39. $.jqplot.DivTitleRenderer.prototype.draw = function() {
  40. // Memory Leaks patch
  41. if (this._elem) {
  42. this._elem.emptyForce();
  43. this._elem = null;
  44. }
  45. var r = this.renderer;
  46. var elem = document.createElement('div');
  47. this._elem = $(elem);
  48. this._elem.addClass('jqplot-title');
  49. if (!this.text) {
  50. this.show = false;
  51. this._elem.height(0);
  52. this._elem.width(0);
  53. }
  54. else if (this.text) {
  55. var color;
  56. if (this.color) {
  57. color = this.color;
  58. }
  59. else if (this.textColor) {
  60. color = this.textColor;
  61. }
  62. // don't trust that a stylesheet is present, set the position.
  63. var styles = {position:'absolute', top:'0px', left:'0px'};
  64. if (this._plotWidth) {
  65. styles['width'] = this._plotWidth+'px';
  66. }
  67. if (this.fontSize) {
  68. styles['fontSize'] = this.fontSize;
  69. }
  70. if (typeof this.textAlign === 'string') {
  71. styles['textAlign'] = this.textAlign;
  72. }
  73. else {
  74. styles['textAlign'] = 'center';
  75. }
  76. if (color) {
  77. styles['color'] = color;
  78. }
  79. if (this.paddingBottom) {
  80. styles['paddingBottom'] = this.paddingBottom;
  81. }
  82. if (this.fontFamily) {
  83. styles['fontFamily'] = this.fontFamily;
  84. }
  85. this._elem.css(styles);
  86. if (this.escapeHtml) {
  87. this._elem.text(this.text);
  88. }
  89. else {
  90. this._elem.html(this.text);
  91. }
  92. // styletext += (this._plotWidth) ? 'width:'+this._plotWidth+'px;' : '';
  93. // styletext += (this.fontSize) ? 'font-size:'+this.fontSize+';' : '';
  94. // styletext += (this.textAlign) ? 'text-align:'+this.textAlign+';' : 'text-align:center;';
  95. // styletext += (color) ? 'color:'+color+';' : '';
  96. // styletext += (this.paddingBottom) ? 'padding-bottom:'+this.paddingBottom+';' : '';
  97. // this._elem = $('<div class="jqplot-title" style="'+styletext+'">'+this.text+'</div>');
  98. // if (this.fontFamily) {
  99. // this._elem.css('font-family', this.fontFamily);
  100. // }
  101. }
  102. elem = null;
  103. return this._elem;
  104. };
  105. $.jqplot.DivTitleRenderer.prototype.pack = function() {
  106. // nothing to do here
  107. };
  108. })(jQuery);