jqplot.categoryAxisRenderer.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  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. /**
  33. * class: $.jqplot.CategoryAxisRenderer
  34. * A plugin for jqPlot to render a category style axis, with equal pixel spacing between y data values of a series.
  35. *
  36. * To use this renderer, include the plugin in your source
  37. * > <script type="text/javascript" language="javascript" src="plugins/jqplot.categoryAxisRenderer.js"></script>
  38. *
  39. * and supply the appropriate options to your plot
  40. *
  41. * > {axes:{xaxis:{renderer:$.jqplot.CategoryAxisRenderer}}}
  42. **/
  43. $.jqplot.CategoryAxisRenderer = function(options) {
  44. $.jqplot.LinearAxisRenderer.call(this);
  45. // prop: sortMergedLabels
  46. // True to sort tick labels when labels are created by merging
  47. // x axis values from multiple series. That is, say you have
  48. // two series like:
  49. // > line1 = [[2006, 4], [2008, 9], [2009, 16]];
  50. // > line2 = [[2006, 3], [2007, 7], [2008, 6]];
  51. // If no label array is specified, tick labels will be collected
  52. // from the x values of the series. With sortMergedLabels
  53. // set to true, tick labels will be:
  54. // > [2006, 2007, 2008, 2009]
  55. // With sortMergedLabels set to false, tick labels will be:
  56. // > [2006, 2008, 2009, 2007]
  57. //
  58. // Note, this property is specified on the renderOptions for the
  59. // axes when creating a plot:
  60. // > axes:{xaxis:{renderer:$.jqplot.CategoryAxisRenderer, rendererOptions:{sortMergedLabels:true}}}
  61. this.sortMergedLabels = false;
  62. };
  63. $.jqplot.CategoryAxisRenderer.prototype = new $.jqplot.LinearAxisRenderer();
  64. $.jqplot.CategoryAxisRenderer.prototype.constructor = $.jqplot.CategoryAxisRenderer;
  65. $.jqplot.CategoryAxisRenderer.prototype.init = function(options){
  66. this.groups = 1;
  67. this.groupLabels = [];
  68. this._groupLabels = [];
  69. this._grouped = false;
  70. this._barsPerGroup = null;
  71. this.reverse = false;
  72. // prop: tickRenderer
  73. // A class of a rendering engine for creating the ticks labels displayed on the plot,
  74. // See <$.jqplot.AxisTickRenderer>.
  75. // this.tickRenderer = $.jqplot.AxisTickRenderer;
  76. // this.labelRenderer = $.jqplot.AxisLabelRenderer;
  77. $.extend(true, this, {tickOptions:{formatString:'%d'}}, options);
  78. var db = this._dataBounds;
  79. // Go through all the series attached to this axis and find
  80. // the min/max bounds for this axis.
  81. for (var i=0; i<this._series.length; i++) {
  82. var s = this._series[i];
  83. if (s.groups) {
  84. this.groups = s.groups;
  85. }
  86. var d = s.data;
  87. for (var j=0; j<d.length; j++) {
  88. if (this.name == 'xaxis' || this.name == 'x2axis') {
  89. if (d[j][0] < db.min || db.min == null) {
  90. db.min = d[j][0];
  91. }
  92. if (d[j][0] > db.max || db.max == null) {
  93. db.max = d[j][0];
  94. }
  95. }
  96. else {
  97. if (d[j][1] < db.min || db.min == null) {
  98. db.min = d[j][1];
  99. }
  100. if (d[j][1] > db.max || db.max == null) {
  101. db.max = d[j][1];
  102. }
  103. }
  104. }
  105. }
  106. if (this.groupLabels.length) {
  107. this.groups = this.groupLabels.length;
  108. }
  109. };
  110. $.jqplot.CategoryAxisRenderer.prototype.createTicks = function() {
  111. // we're are operating on an axis here
  112. var ticks = this._ticks;
  113. var userTicks = this.ticks;
  114. var name = this.name;
  115. // databounds were set on axis initialization.
  116. var db = this._dataBounds;
  117. var dim, interval;
  118. var min, max;
  119. var pos1, pos2;
  120. var tt, i;
  121. // if we already have ticks, use them.
  122. if (userTicks.length) {
  123. // adjust with blanks if we have groups
  124. if (this.groups > 1 && !this._grouped) {
  125. var l = userTicks.length;
  126. var skip = parseInt(l/this.groups, 10);
  127. var count = 0;
  128. for (var i=skip; i<l; i+=skip) {
  129. userTicks.splice(i+count, 0, ' ');
  130. count++;
  131. }
  132. this._grouped = true;
  133. }
  134. this.min = 0.5;
  135. this.max = userTicks.length + 0.5;
  136. var range = this.max - this.min;
  137. this.numberTicks = 2*userTicks.length + 1;
  138. for (i=0; i<userTicks.length; i++){
  139. tt = this.min + 2 * i * range / (this.numberTicks-1);
  140. // need a marker before and after the tick
  141. var t = new this.tickRenderer(this.tickOptions);
  142. t.showLabel = false;
  143. // t.showMark = true;
  144. t.setTick(tt, this.name);
  145. this._ticks.push(t);
  146. var t = new this.tickRenderer(this.tickOptions);
  147. t.label = userTicks[i];
  148. // t.showLabel = true;
  149. t.showMark = false;
  150. t.showGridline = false;
  151. t.setTick(tt+0.5, this.name);
  152. this._ticks.push(t);
  153. }
  154. // now add the last tick at the end
  155. var t = new this.tickRenderer(this.tickOptions);
  156. t.showLabel = false;
  157. // t.showMark = true;
  158. t.setTick(tt+1, this.name);
  159. this._ticks.push(t);
  160. }
  161. // we don't have any ticks yet, let's make some!
  162. else {
  163. if (name == 'xaxis' || name == 'x2axis') {
  164. dim = this._plotDimensions.width;
  165. }
  166. else {
  167. dim = this._plotDimensions.height;
  168. }
  169. // if min, max and number of ticks specified, user can't specify interval.
  170. if (this.min != null && this.max != null && this.numberTicks != null) {
  171. this.tickInterval = null;
  172. }
  173. // if max, min, and interval specified and interval won't fit, ignore interval.
  174. if (this.min != null && this.max != null && this.tickInterval != null) {
  175. if (parseInt((this.max-this.min)/this.tickInterval, 10) != (this.max-this.min)/this.tickInterval) {
  176. this.tickInterval = null;
  177. }
  178. }
  179. // find out how many categories are in the lines and collect labels
  180. var labels = [];
  181. var numcats = 0;
  182. var min = 0.5;
  183. var max, val;
  184. var isMerged = false;
  185. for (var i=0; i<this._series.length; i++) {
  186. var s = this._series[i];
  187. for (var j=0; j<s.data.length; j++) {
  188. if (this.name == 'xaxis' || this.name == 'x2axis') {
  189. val = s.data[j][0];
  190. }
  191. else {
  192. val = s.data[j][1];
  193. }
  194. if ($.inArray(val, labels) == -1) {
  195. isMerged = true;
  196. numcats += 1;
  197. labels.push(val);
  198. }
  199. }
  200. }
  201. if (isMerged && this.sortMergedLabels) {
  202. if (typeof labels[0] == "string") {
  203. labels.sort();
  204. } else {
  205. labels.sort(function(a,b) { return a - b; });
  206. }
  207. }
  208. // keep a reference to these tick labels to use for redrawing plot (see bug #57)
  209. this.ticks = labels;
  210. // now bin the data values to the right lables.
  211. for (var i=0; i<this._series.length; i++) {
  212. var s = this._series[i];
  213. for (var j=0; j<s.data.length; j++) {
  214. if (this.name == 'xaxis' || this.name == 'x2axis') {
  215. val = s.data[j][0];
  216. }
  217. else {
  218. val = s.data[j][1];
  219. }
  220. // for category axis, force the values into category bins.
  221. // we should have the value in the label array now.
  222. var idx = $.inArray(val, labels)+1;
  223. if (this.name == 'xaxis' || this.name == 'x2axis') {
  224. s.data[j][0] = idx;
  225. }
  226. else {
  227. s.data[j][1] = idx;
  228. }
  229. }
  230. }
  231. // adjust with blanks if we have groups
  232. if (this.groups > 1 && !this._grouped) {
  233. var l = labels.length;
  234. var skip = parseInt(l/this.groups, 10);
  235. var count = 0;
  236. for (var i=skip; i<l; i+=skip+1) {
  237. labels[i] = ' ';
  238. }
  239. this._grouped = true;
  240. }
  241. max = numcats + 0.5;
  242. if (this.numberTicks == null) {
  243. this.numberTicks = 2*numcats + 1;
  244. }
  245. var range = max - min;
  246. this.min = min;
  247. this.max = max;
  248. var track = 0;
  249. // todo: adjust this so more ticks displayed.
  250. var maxVisibleTicks = parseInt(3+dim/10, 10);
  251. var skip = parseInt(numcats/maxVisibleTicks, 10);
  252. if (this.tickInterval == null) {
  253. this.tickInterval = range / (this.numberTicks-1);
  254. }
  255. // if tickInterval is specified, we will ignore any computed maximum.
  256. for (var i=0; i<this.numberTicks; i++){
  257. tt = this.min + i * this.tickInterval;
  258. var t = new this.tickRenderer(this.tickOptions);
  259. // if even tick, it isn't a category, it's a divider
  260. if (i/2 == parseInt(i/2, 10)) {
  261. t.showLabel = false;
  262. t.showMark = true;
  263. }
  264. else {
  265. if (skip>0 && track<skip) {
  266. t.showLabel = false;
  267. track += 1;
  268. }
  269. else {
  270. t.showLabel = true;
  271. track = 0;
  272. }
  273. t.label = t.formatter(t.formatString, labels[(i-1)/2]);
  274. t.showMark = false;
  275. t.showGridline = false;
  276. }
  277. t.setTick(tt, this.name);
  278. this._ticks.push(t);
  279. }
  280. }
  281. };
  282. // called with scope of axis
  283. $.jqplot.CategoryAxisRenderer.prototype.draw = function(ctx, plot) {
  284. if (this.show) {
  285. // populate the axis label and value properties.
  286. // createTicks is a method on the renderer, but
  287. // call it within the scope of the axis.
  288. this.renderer.createTicks.call(this);
  289. // fill a div with axes labels in the right direction.
  290. // Need to pregenerate each axis to get its bounds and
  291. // position it and the labels correctly on the plot.
  292. var dim=0;
  293. var temp;
  294. // Added for theming.
  295. if (this._elem) {
  296. // this._elem.empty();
  297. // Memory Leaks patch
  298. this._elem.emptyForce();
  299. }
  300. this._elem = this._elem || $('<div class="jqplot-axis jqplot-'+this.name+'" style="position:absolute;"></div>');
  301. if (this.name == 'xaxis' || this.name == 'x2axis') {
  302. this._elem.width(this._plotDimensions.width);
  303. }
  304. else {
  305. this._elem.height(this._plotDimensions.height);
  306. }
  307. // create a _label object.
  308. this.labelOptions.axis = this.name;
  309. this._label = new this.labelRenderer(this.labelOptions);
  310. if (this._label.show) {
  311. var elem = this._label.draw(ctx, plot);
  312. elem.appendTo(this._elem);
  313. }
  314. var t = this._ticks;
  315. for (var i=0; i<t.length; i++) {
  316. var tick = t[i];
  317. if (tick.showLabel && (!tick.isMinorTick || this.showMinorTicks)) {
  318. var elem = tick.draw(ctx, plot);
  319. elem.appendTo(this._elem);
  320. }
  321. }
  322. this._groupLabels = [];
  323. // now make group labels
  324. for (var i=0; i<this.groupLabels.length; i++)
  325. {
  326. var elem = $('<div style="position:absolute;" class="jqplot-'+this.name+'-groupLabel"></div>');
  327. elem.html(this.groupLabels[i]);
  328. this._groupLabels.push(elem);
  329. elem.appendTo(this._elem);
  330. }
  331. }
  332. return this._elem;
  333. };
  334. // called with scope of axis
  335. $.jqplot.CategoryAxisRenderer.prototype.set = function() {
  336. var dim = 0;
  337. var temp;
  338. var w = 0;
  339. var h = 0;
  340. var lshow = (this._label == null) ? false : this._label.show;
  341. if (this.show) {
  342. var t = this._ticks;
  343. for (var i=0; i<t.length; i++) {
  344. var tick = t[i];
  345. if (tick.showLabel && (!tick.isMinorTick || this.showMinorTicks)) {
  346. if (this.name == 'xaxis' || this.name == 'x2axis') {
  347. temp = tick._elem.outerHeight(true);
  348. }
  349. else {
  350. temp = tick._elem.outerWidth(true);
  351. }
  352. if (temp > dim) {
  353. dim = temp;
  354. }
  355. }
  356. }
  357. var dim2 = 0;
  358. for (var i=0; i<this._groupLabels.length; i++) {
  359. var l = this._groupLabels[i];
  360. if (this.name == 'xaxis' || this.name == 'x2axis') {
  361. temp = l.outerHeight(true);
  362. }
  363. else {
  364. temp = l.outerWidth(true);
  365. }
  366. if (temp > dim2) {
  367. dim2 = temp;
  368. }
  369. }
  370. if (lshow) {
  371. w = this._label._elem.outerWidth(true);
  372. h = this._label._elem.outerHeight(true);
  373. }
  374. if (this.name == 'xaxis') {
  375. dim += dim2 + h;
  376. this._elem.css({'height':dim+'px', left:'0px', bottom:'0px'});
  377. }
  378. else if (this.name == 'x2axis') {
  379. dim += dim2 + h;
  380. this._elem.css({'height':dim+'px', left:'0px', top:'0px'});
  381. }
  382. else if (this.name == 'yaxis') {
  383. dim += dim2 + w;
  384. this._elem.css({'width':dim+'px', left:'0px', top:'0px'});
  385. if (lshow && this._label.constructor == $.jqplot.AxisLabelRenderer) {
  386. this._label._elem.css('width', w+'px');
  387. }
  388. }
  389. else {
  390. dim += dim2 + w;
  391. this._elem.css({'width':dim+'px', right:'0px', top:'0px'});
  392. if (lshow && this._label.constructor == $.jqplot.AxisLabelRenderer) {
  393. this._label._elem.css('width', w+'px');
  394. }
  395. }
  396. }
  397. };
  398. // called with scope of axis
  399. $.jqplot.CategoryAxisRenderer.prototype.pack = function(pos, offsets) {
  400. var ticks = this._ticks;
  401. var max = this.max;
  402. var min = this.min;
  403. var offmax = offsets.max;
  404. var offmin = offsets.min;
  405. var lshow = (this._label == null) ? false : this._label.show;
  406. var i;
  407. for (var p in pos) {
  408. this._elem.css(p, pos[p]);
  409. }
  410. this._offsets = offsets;
  411. // pixellength will be + for x axes and - for y axes becasue pixels always measured from top left.
  412. var pixellength = offmax - offmin;
  413. var unitlength = max - min;
  414. if (!this.reverse) {
  415. // point to unit and unit to point conversions references to Plot DOM element top left corner.
  416. this.u2p = function(u){
  417. return (u - min) * pixellength / unitlength + offmin;
  418. };
  419. this.p2u = function(p){
  420. return (p - offmin) * unitlength / pixellength + min;
  421. };
  422. if (this.name == 'xaxis' || this.name == 'x2axis'){
  423. this.series_u2p = function(u){
  424. return (u - min) * pixellength / unitlength;
  425. };
  426. this.series_p2u = function(p){
  427. return p * unitlength / pixellength + min;
  428. };
  429. }
  430. else {
  431. this.series_u2p = function(u){
  432. return (u - max) * pixellength / unitlength;
  433. };
  434. this.series_p2u = function(p){
  435. return p * unitlength / pixellength + max;
  436. };
  437. }
  438. }
  439. else {
  440. // point to unit and unit to point conversions references to Plot DOM element top left corner.
  441. this.u2p = function(u){
  442. return offmin + (max - u) * pixellength / unitlength;
  443. };
  444. this.p2u = function(p){
  445. return min + (p - offmin) * unitlength / pixellength;
  446. };
  447. if (this.name == 'xaxis' || this.name == 'x2axis'){
  448. this.series_u2p = function(u){
  449. return (max - u) * pixellength / unitlength;
  450. };
  451. this.series_p2u = function(p){
  452. return p * unitlength / pixellength + max;
  453. };
  454. }
  455. else {
  456. this.series_u2p = function(u){
  457. return (min - u) * pixellength / unitlength;
  458. };
  459. this.series_p2u = function(p){
  460. return p * unitlength / pixellength + min;
  461. };
  462. }
  463. }
  464. if (this.show) {
  465. if (this.name == 'xaxis' || this.name == 'x2axis') {
  466. for (i=0; i<ticks.length; i++) {
  467. var t = ticks[i];
  468. if (t.show && t.showLabel) {
  469. var shim;
  470. if (t.constructor == $.jqplot.CanvasAxisTickRenderer && t.angle) {
  471. // will need to adjust auto positioning based on which axis this is.
  472. var temp = (this.name == 'xaxis') ? 1 : -1;
  473. switch (t.labelPosition) {
  474. case 'auto':
  475. // position at end
  476. if (temp * t.angle < 0) {
  477. shim = -t.getWidth() + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
  478. }
  479. // position at start
  480. else {
  481. shim = -t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
  482. }
  483. break;
  484. case 'end':
  485. shim = -t.getWidth() + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
  486. break;
  487. case 'start':
  488. shim = -t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
  489. break;
  490. case 'middle':
  491. shim = -t.getWidth()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
  492. break;
  493. default:
  494. shim = -t.getWidth()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
  495. break;
  496. }
  497. }
  498. else {
  499. shim = -t.getWidth()/2;
  500. }
  501. var val = this.u2p(t.value) + shim + 'px';
  502. t._elem.css('left', val);
  503. t.pack();
  504. }
  505. }
  506. var labeledge=['bottom', 0];
  507. if (lshow) {
  508. var w = this._label._elem.outerWidth(true);
  509. this._label._elem.css('left', offmin + pixellength/2 - w/2 + 'px');
  510. if (this.name == 'xaxis') {
  511. this._label._elem.css('bottom', '0px');
  512. labeledge = ['bottom', this._label._elem.outerHeight(true)];
  513. }
  514. else {
  515. this._label._elem.css('top', '0px');
  516. labeledge = ['top', this._label._elem.outerHeight(true)];
  517. }
  518. this._label.pack();
  519. }
  520. // draw the group labels
  521. var step = parseInt(this._ticks.length/this.groups, 10) + 1;
  522. for (i=0; i<this._groupLabels.length; i++) {
  523. var mid = 0;
  524. var count = 0;
  525. for (var j=i*step; j<(i+1)*step; j++) {
  526. if (j >= this._ticks.length-1) continue; // the last tick does not exist as there is no other group in order to have an empty one.
  527. if (this._ticks[j]._elem && this._ticks[j].label != " ") {
  528. var t = this._ticks[j]._elem;
  529. var p = t.position();
  530. mid += p.left + t.outerWidth(true)/2;
  531. count++;
  532. }
  533. }
  534. mid = mid/count;
  535. this._groupLabels[i].css({'left':(mid - this._groupLabels[i].outerWidth(true)/2)});
  536. this._groupLabels[i].css(labeledge[0], labeledge[1]);
  537. }
  538. }
  539. else {
  540. for (i=0; i<ticks.length; i++) {
  541. var t = ticks[i];
  542. if (t.show && t.showLabel) {
  543. var shim;
  544. if (t.constructor == $.jqplot.CanvasAxisTickRenderer && t.angle) {
  545. // will need to adjust auto positioning based on which axis this is.
  546. var temp = (this.name == 'yaxis') ? 1 : -1;
  547. switch (t.labelPosition) {
  548. case 'auto':
  549. // position at end
  550. case 'end':
  551. if (temp * t.angle < 0) {
  552. shim = -t._textRenderer.height * Math.cos(-t._textRenderer.angle) / 2;
  553. }
  554. else {
  555. shim = -t.getHeight() + t._textRenderer.height * Math.cos(t._textRenderer.angle) / 2;
  556. }
  557. break;
  558. case 'start':
  559. if (t.angle > 0) {
  560. shim = -t._textRenderer.height * Math.cos(-t._textRenderer.angle) / 2;
  561. }
  562. else {
  563. shim = -t.getHeight() + t._textRenderer.height * Math.cos(t._textRenderer.angle) / 2;
  564. }
  565. break;
  566. case 'middle':
  567. // if (t.angle > 0) {
  568. // shim = -t.getHeight()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
  569. // }
  570. // else {
  571. // shim = -t.getHeight()/2 - t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
  572. // }
  573. shim = -t.getHeight()/2;
  574. break;
  575. default:
  576. shim = -t.getHeight()/2;
  577. break;
  578. }
  579. }
  580. else {
  581. shim = -t.getHeight()/2;
  582. }
  583. var val = this.u2p(t.value) + shim + 'px';
  584. t._elem.css('top', val);
  585. t.pack();
  586. }
  587. }
  588. var labeledge=['left', 0];
  589. if (lshow) {
  590. var h = this._label._elem.outerHeight(true);
  591. this._label._elem.css('top', offmax - pixellength/2 - h/2 + 'px');
  592. if (this.name == 'yaxis') {
  593. this._label._elem.css('left', '0px');
  594. labeledge = ['left', this._label._elem.outerWidth(true)];
  595. }
  596. else {
  597. this._label._elem.css('right', '0px');
  598. labeledge = ['right', this._label._elem.outerWidth(true)];
  599. }
  600. this._label.pack();
  601. }
  602. // draw the group labels, position top here, do left after label position.
  603. var step = parseInt(this._ticks.length/this.groups, 10) + 1; // step is one more than before as we don't want to have overlaps in loops
  604. for (i=0; i<this._groupLabels.length; i++) {
  605. var mid = 0;
  606. var count = 0;
  607. for (var j=i*step; j<(i+1)*step; j++) { // j must never reach (i+1)*step as we don't want to have overlap between loops
  608. if (j >= this._ticks.length-1) continue; // the last tick does not exist as there is no other group in order to have an empty one.
  609. if (this._ticks[j]._elem && this._ticks[j].label != " ") {
  610. var t = this._ticks[j]._elem;
  611. var p = t.position();
  612. mid += p.top + t.outerHeight()/2;
  613. count++;
  614. }
  615. }
  616. mid = mid/count;
  617. this._groupLabels[i].css({'top':mid - this._groupLabels[i].outerHeight()/2});
  618. this._groupLabels[i].css(labeledge[0], labeledge[1]);
  619. }
  620. }
  621. }
  622. };
  623. })(jQuery);