jqplot.axisLabelRenderer.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.AxisLabelRenderer
  33. // Renderer to place labels on the axes.
  34. $.jqplot.AxisLabelRenderer = function(options) {
  35. // Group: Properties
  36. $.jqplot.ElemContainer.call(this);
  37. // name of the axis associated with this tick
  38. this.axis;
  39. // prop: show
  40. // whether or not to show the tick (mark and label).
  41. this.show = true;
  42. // prop: label
  43. // The text or html for the label.
  44. this.label = '';
  45. this.fontFamily = null;
  46. this.fontSize = null;
  47. this.textColor = null;
  48. this._elem;
  49. // prop: escapeHTML
  50. // true to escape HTML entities in the label.
  51. this.escapeHTML = false;
  52. $.extend(true, this, options);
  53. };
  54. $.jqplot.AxisLabelRenderer.prototype = new $.jqplot.ElemContainer();
  55. $.jqplot.AxisLabelRenderer.prototype.constructor = $.jqplot.AxisLabelRenderer;
  56. $.jqplot.AxisLabelRenderer.prototype.init = function(options) {
  57. $.extend(true, this, options);
  58. };
  59. $.jqplot.AxisLabelRenderer.prototype.draw = function(ctx, plot) {
  60. // Memory Leaks patch
  61. if (this._elem) {
  62. this._elem.emptyForce();
  63. this._elem = null;
  64. }
  65. this._elem = $('<div style="position:absolute;" class="jqplot-'+this.axis+'-label"></div>');
  66. if (Number(this.label)) {
  67. this._elem.css('white-space', 'nowrap');
  68. }
  69. if (!this.escapeHTML) {
  70. this._elem.html(this.label);
  71. }
  72. else {
  73. this._elem.text(this.label);
  74. }
  75. if (this.fontFamily) {
  76. this._elem.css('font-family', this.fontFamily);
  77. }
  78. if (this.fontSize) {
  79. this._elem.css('font-size', this.fontSize);
  80. }
  81. if (this.textColor) {
  82. this._elem.css('color', this.textColor);
  83. }
  84. return this._elem;
  85. };
  86. $.jqplot.AxisLabelRenderer.prototype.pack = function() {
  87. };
  88. })(jQuery);