jqplot.pyramidAxisRenderer.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  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. $.jqplot.PyramidAxisRenderer = function() {
  33. $.jqplot.LinearAxisRenderer.call(this);
  34. };
  35. $.jqplot.PyramidAxisRenderer.prototype = new $.jqplot.LinearAxisRenderer();
  36. $.jqplot.PyramidAxisRenderer.prototype.constructor = $.jqplot.PyramidAxisRenderer;
  37. // called with scope of axis
  38. $.jqplot.PyramidAxisRenderer.prototype.init = function(options){
  39. // Group: Properties
  40. //
  41. // prop: position
  42. // Position of axis. Values are: top, bottom , left, center, right.
  43. // By default, x and x2 axes are bottom, y axis is center.
  44. this.position = null;
  45. // prop: drawBaseline
  46. // True to draw the axis baseline.
  47. this.drawBaseline = true;
  48. // prop: baselineWidth
  49. // width of the baseline in pixels.
  50. this.baselineWidth = null;
  51. // prop: baselineColor
  52. // CSS color spec for the baseline.
  53. this.baselineColor = null;
  54. this.tickSpacingFactor = 25;
  55. this._type = 'pyramid';
  56. this._splitAxis = false;
  57. this._splitLength = null;
  58. this.category = false;
  59. this._autoFormatString = '';
  60. this._overrideFormatString = false;
  61. $.extend(true, this, options);
  62. this.renderer.options = options;
  63. this.resetDataBounds = this.renderer.resetDataBounds;
  64. this.resetDataBounds();
  65. };
  66. $.jqplot.PyramidAxisRenderer.prototype.resetDataBounds = function() {
  67. // Go through all the series attached to this axis and find
  68. // the min/max bounds for this axis.
  69. var db = this._dataBounds;
  70. db.min = null;
  71. db.max = null;
  72. var temp;
  73. for (var i=0; i<this._series.length; i++) {
  74. var s = this._series[i];
  75. var d = s._plotData;
  76. for (var j=0, l=d.length; j<l; j++) {
  77. if (this.name.charAt(0) === 'x') {
  78. temp = d[j][1];
  79. if ((temp !== null && temp < db.min) || db.min === null) {
  80. db.min = temp;
  81. }
  82. if ((temp !== null && temp > db.max) || db.max === null) {
  83. db.max = temp;
  84. }
  85. }
  86. else {
  87. temp = d[j][0];
  88. if ((temp !== null && temp < db.min) || db.min === null) {
  89. db.min = temp;
  90. }
  91. if ((temp !== null && temp > db.max) || db.max === null) {
  92. db.max = temp;
  93. }
  94. }
  95. }
  96. }
  97. };
  98. // called with scope of axis
  99. $.jqplot.PyramidAxisRenderer.prototype.draw = function(ctx, plot) {
  100. if (this.show) {
  101. // populate the axis label and value properties.
  102. // createTicks is a method on the renderer, but
  103. // call it within the scope of the axis.
  104. this.renderer.createTicks.call(this, plot);
  105. // fill a div with axes labels in the right direction.
  106. // Need to pregenerate each axis to get its bounds and
  107. // position it and the labels correctly on the plot.
  108. var dim=0;
  109. var temp;
  110. // Added for theming.
  111. if (this._elem) {
  112. // Memory Leaks patch
  113. //this._elem.empty();
  114. this._elem.emptyForce();
  115. this._elem = null;
  116. }
  117. this._elem = $(document.createElement('div'));
  118. this._elem.addClass('jqplot-axis jqplot-'+this.name);
  119. this._elem.css('position', 'absolute');
  120. if (this.name == 'xaxis' || this.name == 'x2axis') {
  121. this._elem.width(this._plotDimensions.width);
  122. }
  123. else {
  124. this._elem.height(this._plotDimensions.height);
  125. }
  126. // create a _label object.
  127. this.labelOptions.axis = this.name;
  128. this._label = new this.labelRenderer(this.labelOptions);
  129. if (this._label.show) {
  130. var elem = this._label.draw(ctx, plot);
  131. elem.appendTo(this._elem);
  132. elem = null;
  133. }
  134. var t = this._ticks;
  135. var tick;
  136. for (var i=0; i<t.length; i++) {
  137. tick = t[i];
  138. if (tick.show && tick.showLabel && (!tick.isMinorTick)) {
  139. this._elem.append(tick.draw(ctx, plot));
  140. }
  141. }
  142. tick = null;
  143. t = null;
  144. }
  145. return this._elem;
  146. };
  147. // Note, primes can be found on http://primes.utm.edu/
  148. var _primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997];
  149. var _primesHash = {};
  150. for (var i =0, l = _primes.length; i < l; i++) {
  151. _primesHash[_primes[i]] = _primes[i];
  152. }
  153. // called with scope of axis
  154. $.jqplot.PyramidAxisRenderer.prototype.createTicks = function(plot) {
  155. // we're are operating on an axis here
  156. var userTicks = this.ticks;
  157. // databounds were set on axis initialization.
  158. var db = this._dataBounds;
  159. var dim;
  160. var interval;
  161. var min;
  162. var max;
  163. var range;
  164. var pos1;
  165. var pos2;
  166. var tt;
  167. var i;
  168. var l;
  169. var s;
  170. // get a copy of user's settings for min/max.
  171. var userMin = this.min;
  172. var userMax = this.max;
  173. var ut;
  174. var t;
  175. var threshold;
  176. var tdim;
  177. var scalefact;
  178. var ret;
  179. var tumin;
  180. var tumax;
  181. var maxVisibleTicks;
  182. var val;
  183. var skip = null;
  184. var temp;
  185. // if we already have ticks, use them.
  186. // ticks must be in order of increasing value.
  187. if (userTicks.length) {
  188. // ticks could be 1D or 2D array of [val, val, ,,,] or [[val, label], [val, label], ...] or mixed
  189. for (i=0, l=userTicks.length; i<l; i++){
  190. ut = userTicks[i];
  191. t = new this.tickRenderer(this.tickOptions);
  192. if ($.isArray(ut)) {
  193. t.value = ut[0];
  194. t.label = ut[1];
  195. t.setTick(ut[0], this.name);
  196. this._ticks.push(t);
  197. }
  198. else if ($.isPlainObject(ut)) {
  199. $.extend(true, t, ut);
  200. t.axis = this.name;
  201. this._ticks.push(t);
  202. }
  203. else {
  204. if (typeof ut === 'string') {
  205. val = i + plot.defaultAxisStart;
  206. }
  207. else {
  208. val = ut;
  209. }
  210. t.value = val;
  211. t.label = ut;
  212. t.axis = this.name;
  213. this._ticks.push(t);
  214. }
  215. }
  216. this.numberTicks = userTicks.length;
  217. this.min = this._ticks[0].value;
  218. this.max = this._ticks[this.numberTicks-1].value;
  219. this.tickInterval = (this.max - this.min) / (this.numberTicks - 1);
  220. // use user specified tickInterval if there is one
  221. if (this._options.tickInterval) {
  222. // hide every tick except for ticks on interval
  223. var ti = this._options.tickInterval;
  224. for (i=0; i<this.numberTicks; i++) {
  225. if (i%ti !== 0) {
  226. // this._ticks[i].show = false;
  227. this._ticks[i].isMinorTick = true;
  228. }
  229. }
  230. }
  231. else {
  232. // check if we have too many ticks
  233. dim = (this.name.charAt(0) === 'x') ? this._plotDimensions.width : this._plotDimensions.height;
  234. maxVisibleTicks = Math.round(2.0 + dim/this.tickSpacingFactor);
  235. if (this.numberTicks > maxVisibleTicks) {
  236. // check for number of ticks we can skip
  237. temp = this.numberTicks - 1;
  238. for (i=2; i<temp; i++) {
  239. if (temp % i === 0 && temp/i < maxVisibleTicks) {
  240. skip = i-1;
  241. break;
  242. }
  243. }
  244. if (skip !== null) {
  245. var count = 1;
  246. for (i=1, l=this._ticks.length; i<l; i++) {
  247. if (count <= skip) {
  248. this._ticks[i].show = false;
  249. count += 1;
  250. }
  251. else {
  252. count = 1;
  253. }
  254. }
  255. }
  256. }
  257. }
  258. // if category style, add minor ticks in between
  259. temp = [];
  260. if (this.category) {
  261. // turn off gridline and mark on first tick
  262. this._ticks[0].showGridline = false;
  263. this._ticks[0].showMark = false;
  264. for (i=this._ticks.length-1; i>0; i--) {
  265. t = new this.tickRenderer(this.tickOptions);
  266. t.value = this._ticks[i-1].value + this.tickInterval/2.0;
  267. t.label = '';
  268. t.showLabel = false;
  269. t.axis = this.name;
  270. this._ticks[i].showGridline = false;
  271. this._ticks[i].showMark = false;
  272. this._ticks.splice(i, 0, t);
  273. // temp.push(t);
  274. }
  275. // merge in the new ticks
  276. // for (i=1, l=temp.length; i<l; i++) {
  277. // this._ticks.splice(i, 0, temp[i]);
  278. // }
  279. // now add a tick at beginning and end
  280. t = new this.tickRenderer(this.tickOptions);
  281. t.value = this._ticks[0].value - this.tickInterval/2.0;
  282. t.label = '';
  283. t.showLabel = false;
  284. t.axis = this.name;
  285. this._ticks.unshift(t);
  286. t = new this.tickRenderer(this.tickOptions);
  287. t.value = this._ticks[this._ticks.length-1].value + this.tickInterval/2.0;
  288. t.label = '';
  289. t.showLabel = false;
  290. t.axis = this.name;
  291. this._ticks.push(t);
  292. this.tickInterval = this.tickInterval / 2.0;
  293. this.numberTicks = this._ticks.length;
  294. this.min = this._ticks[0].value;
  295. this.max = this._ticks[this._ticks.length-1].value;
  296. }
  297. }
  298. // we don't have any ticks yet, let's make some!
  299. else {
  300. if (this.name.charAt(0) === 'x') {
  301. dim = this._plotDimensions.width;
  302. // make sure x axis is symetric about 0.
  303. var tempmax = Math.max(db.max, Math.abs(db.min));
  304. var tempmin = Math.min(db.min, -tempmax);
  305. // min = ((this.min != null) ? this.min : tempmin);
  306. // max = ((this.max != null) ? this.max : tempmax);
  307. min = tempmin;
  308. max = tempmax;
  309. range = max - min;
  310. if (this.tickOptions == null || !this.tickOptions.formatString) {
  311. this._overrideFormatString = true;
  312. }
  313. threshold = 30;
  314. tdim = Math.max(dim, threshold+1);
  315. scalefact = (tdim-threshold)/300.0;
  316. ret = $.jqplot.LinearTickGenerator(min, max, scalefact);
  317. // calculate a padded max and min, points should be less than these
  318. // so that they aren't too close to the edges of the plot.
  319. // User can adjust how much padding is allowed with pad, padMin and PadMax options.
  320. tumin = min + range*(this.padMin - 1);
  321. tumax = max - range*(this.padMax - 1);
  322. if (min < tumin || max > tumax) {
  323. tumin = min - range*(this.padMin - 1);
  324. tumax = max + range*(this.padMax - 1);
  325. ret = $.jqplot.LinearTickGenerator(tumin, tumax, scalefact);
  326. }
  327. this.min = ret[0];
  328. this.max = ret[1];
  329. this.numberTicks = ret[2];
  330. this._autoFormatString = ret[3];
  331. this.tickInterval = ret[4];
  332. }
  333. else {
  334. dim = this._plotDimensions.height;
  335. // ticks will be on whole integers like 1, 2, 3, ... or 1, 4, 7, ...
  336. min = db.min;
  337. max = db.max;
  338. s = this._series[0];
  339. this._ticks = [];
  340. range = max - min;
  341. // if range is a prime, will get only 2 ticks, expand range in that case.
  342. if (_primesHash[range]) {
  343. range += 1;
  344. max += 1;
  345. }
  346. this.max = max;
  347. this.min = min;
  348. maxVisibleTicks = Math.round(2.0 + dim/this.tickSpacingFactor);
  349. if (range + 1 <= maxVisibleTicks) {
  350. this.numberTicks = range + 1;
  351. this.tickInterval = 1.0;
  352. }
  353. else {
  354. // figure out a round number of ticks to skip in every interval
  355. // range / ti + 1 = nt
  356. // ti = range / (nt - 1)
  357. for (var i=maxVisibleTicks; i>1; i--) {
  358. if (range/(i - 1) === Math.round(range/(i - 1))) {
  359. this.numberTicks = i;
  360. this.tickInterval = range/(i - 1);
  361. break;
  362. }
  363. }
  364. }
  365. }
  366. if (this._overrideFormatString && this._autoFormatString != '') {
  367. this.tickOptions = this.tickOptions || {};
  368. this.tickOptions.formatString = this._autoFormatString;
  369. }
  370. var labelval;
  371. for (i=0; i<this.numberTicks; i++) {
  372. this.tickOptions.axis = this.name;
  373. labelval = this.min + this.tickInterval * i;
  374. if (this.name.charAt(0) === 'x') {
  375. labelval = Math.abs(labelval);
  376. }
  377. // this.tickOptions.label = String (labelval);
  378. this.tickOptions.value = this.min + this.tickInterval * i;
  379. t = new this.tickRenderer(this.tickOptions);
  380. t.label = t.prefix + t.formatter(t.formatString, labelval);
  381. this._ticks.push(t);
  382. // for x axis, if y axis is in middle, add a symetrical 0 tick
  383. if (this.name.charAt(0) === 'x' && plot.axes.yMidAxis.show && this.tickOptions.value === 0) {
  384. this._splitAxis = true;
  385. this._splitLength = plot.axes.yMidAxis.getWidth();
  386. // t.value = -this.max/2000.0;
  387. t = new this.tickRenderer(this.tickOptions);
  388. this._ticks.push(t);
  389. t.value = this.max/2000.0;
  390. }
  391. }
  392. t = null;
  393. }
  394. };
  395. // called with scope of axis
  396. $.jqplot.PyramidAxisRenderer.prototype.set = function() {
  397. var dim = 0;
  398. var temp;
  399. var w = 0;
  400. var h = 0;
  401. var i;
  402. var t;
  403. var tick;
  404. var lshow = (this._label == null) ? false : this._label.show;
  405. if (this.show) {
  406. t = this._ticks;
  407. l = t.length;
  408. for (i=0; i<l; i++) {
  409. tick = t[i];
  410. if (!tick._breakTick && tick.show && tick.showLabel && !tick.isMinorTick) {
  411. if (this.name.charAt(0) === 'x') {
  412. temp = tick._elem.outerHeight(true);
  413. }
  414. else {
  415. temp = tick._elem.outerWidth(true);
  416. }
  417. if (temp > dim) {
  418. dim = temp;
  419. }
  420. }
  421. }
  422. if (this.name === 'yMidAxis') {
  423. for (i=0; i<l; i++) {
  424. tick = t[i];
  425. if (tick._elem) {
  426. temp = (dim - tick._elem.outerWidth(true))/2.0;
  427. tick._elem.css('left', temp);
  428. }
  429. }
  430. }
  431. tick = null;
  432. t = null;
  433. if (lshow) {
  434. w = this._label._elem.outerWidth(true);
  435. h = this._label._elem.outerHeight(true);
  436. }
  437. if (this.name === 'xaxis') {
  438. dim = dim + h;
  439. this._elem.css({'height':dim+'px', left:'0px', bottom:'0px'});
  440. }
  441. else if (this.name === 'x2axis') {
  442. dim = dim + h;
  443. this._elem.css({'height':dim+'px', left:'0px', top:'0px'});
  444. }
  445. else if (this.name === 'yaxis') {
  446. dim = dim + w;
  447. this._elem.css({'width':dim+'px', left:'0px', top:'0px'});
  448. if (lshow && this._label.constructor == $.jqplot.AxisLabelRenderer) {
  449. this._label._elem.css('width', w+'px');
  450. }
  451. }
  452. else if (this.name === 'yMidAxis') {
  453. // don't include width of label at all in width of axis?
  454. // dim = (dim > w) ? dim : w;
  455. var temp = dim/2.0 - w/2.0;
  456. this._elem.css({'width':dim+'px', top:'0px'});
  457. if (lshow && this._label.constructor == $.jqplot.AxisLabelRenderer) {
  458. this._label._elem.css({width: w, left: temp, top: 0});
  459. }
  460. }
  461. else {
  462. dim = dim + w;
  463. this._elem.css({'width':dim+'px', right:'0px', top:'0px'});
  464. if (lshow && this._label.constructor == $.jqplot.AxisLabelRenderer) {
  465. this._label._elem.css('width', w+'px');
  466. }
  467. }
  468. }
  469. };
  470. $.jqplot.PyramidAxisRenderer.prototype.pack = function(pos, offsets) {
  471. // Add defaults for repacking from resetTickValues function.
  472. pos = pos || {};
  473. offsets = offsets || this._offsets;
  474. var ticks = this._ticks;
  475. var max = this.max;
  476. var min = this.min;
  477. var offmax = offsets.max;
  478. var offmin = offsets.min;
  479. var lshow = (this._label == null) ? false : this._label.show;
  480. for (var p in pos) {
  481. this._elem.css(p, pos[p]);
  482. }
  483. this._offsets = offsets;
  484. // pixellength will be + for x axes and - for y axes becasue pixels always measured from top left.
  485. var pixellength = offmax - offmin;
  486. var unitlength = max - min;
  487. var sl = this._splitLength;
  488. // point to unit and unit to point conversions references to Plot DOM element top left corner.
  489. if (this._splitAxis) {
  490. pixellength -= this._splitLength;
  491. // don't know that this one is correct.
  492. this.p2u = function(p){
  493. return (p - offmin) * unitlength / pixellength + min;
  494. };
  495. this.u2p = function(u){
  496. if (u <= 0) {
  497. return (u - min) * pixellength / unitlength + offmin;
  498. }
  499. else {
  500. return (u - min) * pixellength / unitlength + offmin + sl;
  501. }
  502. };
  503. this.series_u2p = function(u){
  504. if (u <= 0) {
  505. return (u - min) * pixellength / unitlength;
  506. }
  507. else {
  508. return (u - min) * pixellength / unitlength + sl;
  509. }
  510. };
  511. // don't know that this one is correct.
  512. this.series_p2u = function(p){
  513. return p * unitlength / pixellength + min;
  514. };
  515. }
  516. else {
  517. this.p2u = function(p){
  518. return (p - offmin) * unitlength / pixellength + min;
  519. };
  520. this.u2p = function(u){
  521. return (u - min) * pixellength / unitlength + offmin;
  522. };
  523. if (this.name.charAt(0) === 'x'){
  524. this.series_u2p = function(u){
  525. return (u - min) * pixellength / unitlength;
  526. };
  527. this.series_p2u = function(p){
  528. return p * unitlength / pixellength + min;
  529. };
  530. }
  531. else {
  532. this.series_u2p = function(u){
  533. return (u - max) * pixellength / unitlength;
  534. };
  535. this.series_p2u = function(p){
  536. return p * unitlength / pixellength + max;
  537. };
  538. }
  539. }
  540. if (this.show) {
  541. if (this.name.charAt(0) === 'x') {
  542. for (var i=0; i<ticks.length; i++) {
  543. var t = ticks[i];
  544. if (t.show && t.showLabel) {
  545. var shim;
  546. if (t.constructor == $.jqplot.CanvasAxisTickRenderer && t.angle) {
  547. // will need to adjust auto positioning based on which axis this is.
  548. var temp = (this.name == 'xaxis') ? 1 : -1;
  549. switch (t.labelPosition) {
  550. case 'auto':
  551. // position at end
  552. if (temp * t.angle < 0) {
  553. shim = -t.getWidth() + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
  554. }
  555. // position at start
  556. else {
  557. shim = -t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
  558. }
  559. break;
  560. case 'end':
  561. shim = -t.getWidth() + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
  562. break;
  563. case 'start':
  564. shim = -t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
  565. break;
  566. case 'middle':
  567. shim = -t.getWidth()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
  568. break;
  569. default:
  570. shim = -t.getWidth()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
  571. break;
  572. }
  573. }
  574. else {
  575. shim = -t.getWidth()/2;
  576. }
  577. var val = this.u2p(t.value) + shim + 'px';
  578. t._elem.css('left', val);
  579. t.pack();
  580. }
  581. }
  582. if (lshow) {
  583. var w = this._label._elem.outerWidth(true);
  584. this._label._elem.css('left', offmin + pixellength/2 - w/2 + 'px');
  585. if (this.name == 'xaxis') {
  586. this._label._elem.css('bottom', '0px');
  587. }
  588. else {
  589. this._label._elem.css('top', '0px');
  590. }
  591. this._label.pack();
  592. }
  593. }
  594. else {
  595. for (var i=0; i<ticks.length; i++) {
  596. var t = ticks[i];
  597. if (t.show && t.showLabel && !t.isMinorTick) {
  598. var shim;
  599. if (t.constructor == $.jqplot.CanvasAxisTickRenderer && t.angle) {
  600. // will need to adjust auto positioning based on which axis this is.
  601. var temp = (this.name == 'yaxis') ? 1 : -1;
  602. switch (t.labelPosition) {
  603. case 'auto':
  604. // position at end
  605. case 'end':
  606. if (temp * t.angle < 0) {
  607. shim = -t._textRenderer.height * Math.cos(-t._textRenderer.angle) / 2;
  608. }
  609. else {
  610. shim = -t.getHeight() + t._textRenderer.height * Math.cos(t._textRenderer.angle) / 2;
  611. }
  612. break;
  613. case 'start':
  614. if (t.angle > 0) {
  615. shim = -t._textRenderer.height * Math.cos(-t._textRenderer.angle) / 2;
  616. }
  617. else {
  618. shim = -t.getHeight() + t._textRenderer.height * Math.cos(t._textRenderer.angle) / 2;
  619. }
  620. break;
  621. case 'middle':
  622. // if (t.angle > 0) {
  623. // shim = -t.getHeight()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
  624. // }
  625. // else {
  626. // shim = -t.getHeight()/2 - t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
  627. // }
  628. shim = -t.getHeight()/2;
  629. break;
  630. default:
  631. shim = -t.getHeight()/2;
  632. break;
  633. }
  634. }
  635. else {
  636. shim = -t.getHeight()/2;
  637. }
  638. var val = this.u2p(t.value) + shim + 'px';
  639. t._elem.css('top', val);
  640. t.pack();
  641. }
  642. }
  643. if (lshow) {
  644. var h = this._label._elem.outerHeight(true);
  645. if (this.name !== 'yMidAxis') {
  646. this._label._elem.css('top', offmax - pixellength/2 - h/2 + 'px');
  647. }
  648. if (this.name == 'yaxis') {
  649. this._label._elem.css('left', '0px');
  650. }
  651. else if (this.name !== 'yMidAxis') {
  652. this._label._elem.css('right', '0px');
  653. }
  654. this._label.pack();
  655. }
  656. }
  657. }
  658. ticks = null;
  659. };
  660. })(jQuery);