jqplot.categoryAxisRenderer.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. /**
  2. * jqPlot
  3. * Pure JavaScript plotting plugin using jQuery
  4. *
  5. * Version: 1.0.4
  6. * Revision: 1121
  7. *
  8. * Copyright (c) 2009-2012 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. labels.sort(function(a,b) { return a - b; });
  203. }
  204. // keep a reference to these tick labels to use for redrawing plot (see bug #57)
  205. this.ticks = labels;
  206. // now bin the data values to the right lables.
  207. for (var i=0; i<this._series.length; i++) {
  208. var s = this._series[i];
  209. for (var j=0; j<s.data.length; j++) {
  210. if (this.name == 'xaxis' || this.name == 'x2axis') {
  211. val = s.data[j][0];
  212. }
  213. else {
  214. val = s.data[j][1];
  215. }
  216. // for category axis, force the values into category bins.
  217. // we should have the value in the label array now.
  218. var idx = $.inArray(val, labels)+1;
  219. if (this.name == 'xaxis' || this.name == 'x2axis') {
  220. s.data[j][0] = idx;
  221. }
  222. else {
  223. s.data[j][1] = idx;
  224. }
  225. }
  226. }
  227. // adjust with blanks if we have groups
  228. if (this.groups > 1 && !this._grouped) {
  229. var l = labels.length;
  230. var skip = parseInt(l/this.groups, 10);
  231. var count = 0;
  232. for (var i=skip; i<l; i+=skip+1) {
  233. labels[i] = ' ';
  234. }
  235. this._grouped = true;
  236. }
  237. max = numcats + 0.5;
  238. if (this.numberTicks == null) {
  239. this.numberTicks = 2*numcats + 1;
  240. }
  241. var range = max - min;
  242. this.min = min;
  243. this.max = max;
  244. var track = 0;
  245. // todo: adjust this so more ticks displayed.
  246. var maxVisibleTicks = parseInt(3+dim/10, 10);
  247. var skip = parseInt(numcats/maxVisibleTicks, 10);
  248. if (this.tickInterval == null) {
  249. this.tickInterval = range / (this.numberTicks-1);
  250. }
  251. // if tickInterval is specified, we will ignore any computed maximum.
  252. for (var i=0; i<this.numberTicks; i++){
  253. tt = this.min + i * this.tickInterval;
  254. var t = new this.tickRenderer(this.tickOptions);
  255. // if even tick, it isn't a category, it's a divider
  256. if (i/2 == parseInt(i/2, 10)) {
  257. t.showLabel = false;
  258. t.showMark = true;
  259. }
  260. else {
  261. if (skip>0 && track<skip) {
  262. t.showLabel = false;
  263. track += 1;
  264. }
  265. else {
  266. t.showLabel = true;
  267. track = 0;
  268. }
  269. t.label = t.formatter(t.formatString, labels[(i-1)/2]);
  270. t.showMark = false;
  271. t.showGridline = false;
  272. }
  273. t.setTick(tt, this.name);
  274. this._ticks.push(t);
  275. }
  276. }
  277. };
  278. // called with scope of axis
  279. $.jqplot.CategoryAxisRenderer.prototype.draw = function(ctx, plot) {
  280. if (this.show) {
  281. // populate the axis label and value properties.
  282. // createTicks is a method on the renderer, but
  283. // call it within the scope of the axis.
  284. this.renderer.createTicks.call(this);
  285. // fill a div with axes labels in the right direction.
  286. // Need to pregenerate each axis to get it's bounds and
  287. // position it and the labels correctly on the plot.
  288. var dim=0;
  289. var temp;
  290. // Added for theming.
  291. if (this._elem) {
  292. // this._elem.empty();
  293. // Memory Leaks patch
  294. this._elem.emptyForce();
  295. }
  296. this._elem = this._elem || $('<div class="jqplot-axis jqplot-'+this.name+'" style="position:absolute;"></div>');
  297. if (this.name == 'xaxis' || this.name == 'x2axis') {
  298. this._elem.width(this._plotDimensions.width);
  299. }
  300. else {
  301. this._elem.height(this._plotDimensions.height);
  302. }
  303. // create a _label object.
  304. this.labelOptions.axis = this.name;
  305. this._label = new this.labelRenderer(this.labelOptions);
  306. if (this._label.show) {
  307. var elem = this._label.draw(ctx, plot);
  308. elem.appendTo(this._elem);
  309. }
  310. var t = this._ticks;
  311. for (var i=0; i<t.length; i++) {
  312. var tick = t[i];
  313. if (tick.showLabel && (!tick.isMinorTick || this.showMinorTicks)) {
  314. var elem = tick.draw(ctx, plot);
  315. elem.appendTo(this._elem);
  316. }
  317. }
  318. this._groupLabels = [];
  319. // now make group labels
  320. for (var i=0; i<this.groupLabels.length; i++)
  321. {
  322. var elem = $('<div style="position:absolute;" class="jqplot-'+this.name+'-groupLabel"></div>');
  323. elem.html(this.groupLabels[i]);
  324. this._groupLabels.push(elem);
  325. elem.appendTo(this._elem);
  326. }
  327. }
  328. return this._elem;
  329. };
  330. // called with scope of axis
  331. $.jqplot.CategoryAxisRenderer.prototype.set = function() {
  332. var dim = 0;
  333. var temp;
  334. var w = 0;
  335. var h = 0;
  336. var lshow = (this._label == null) ? false : this._label.show;
  337. if (this.show) {
  338. var t = this._ticks;
  339. for (var i=0; i<t.length; i++) {
  340. var tick = t[i];
  341. if (tick.showLabel && (!tick.isMinorTick || this.showMinorTicks)) {
  342. if (this.name == 'xaxis' || this.name == 'x2axis') {
  343. temp = tick._elem.outerHeight(true);
  344. }
  345. else {
  346. temp = tick._elem.outerWidth(true);
  347. }
  348. if (temp > dim) {
  349. dim = temp;
  350. }
  351. }
  352. }
  353. var dim2 = 0;
  354. for (var i=0; i<this._groupLabels.length; i++) {
  355. var l = this._groupLabels[i];
  356. if (this.name == 'xaxis' || this.name == 'x2axis') {
  357. temp = l.outerHeight(true);
  358. }
  359. else {
  360. temp = l.outerWidth(true);
  361. }
  362. if (temp > dim2) {
  363. dim2 = temp;
  364. }
  365. }
  366. if (lshow) {
  367. w = this._label._elem.outerWidth(true);
  368. h = this._label._elem.outerHeight(true);
  369. }
  370. if (this.name == 'xaxis') {
  371. dim += dim2 + h;
  372. this._elem.css({'height':dim+'px', left:'0px', bottom:'0px'});
  373. }
  374. else if (this.name == 'x2axis') {
  375. dim += dim2 + h;
  376. this._elem.css({'height':dim+'px', left:'0px', top:'0px'});
  377. }
  378. else if (this.name == 'yaxis') {
  379. dim += dim2 + w;
  380. this._elem.css({'width':dim+'px', left:'0px', top:'0px'});
  381. if (lshow && this._label.constructor == $.jqplot.AxisLabelRenderer) {
  382. this._label._elem.css('width', w+'px');
  383. }
  384. }
  385. else {
  386. dim += dim2 + w;
  387. this._elem.css({'width':dim+'px', right:'0px', top:'0px'});
  388. if (lshow && this._label.constructor == $.jqplot.AxisLabelRenderer) {
  389. this._label._elem.css('width', w+'px');
  390. }
  391. }
  392. }
  393. };
  394. // called with scope of axis
  395. $.jqplot.CategoryAxisRenderer.prototype.pack = function(pos, offsets) {
  396. var ticks = this._ticks;
  397. var max = this.max;
  398. var min = this.min;
  399. var offmax = offsets.max;
  400. var offmin = offsets.min;
  401. var lshow = (this._label == null) ? false : this._label.show;
  402. var i;
  403. for (var p in pos) {
  404. this._elem.css(p, pos[p]);
  405. }
  406. this._offsets = offsets;
  407. // pixellength will be + for x axes and - for y axes becasue pixels always measured from top left.
  408. var pixellength = offmax - offmin;
  409. var unitlength = max - min;
  410. if (!this.reverse) {
  411. // point to unit and unit to point conversions references to Plot DOM element top left corner.
  412. this.u2p = function(u){
  413. return (u - min) * pixellength / unitlength + offmin;
  414. };
  415. this.p2u = function(p){
  416. return (p - offmin) * unitlength / pixellength + min;
  417. };
  418. if (this.name == 'xaxis' || this.name == 'x2axis'){
  419. this.series_u2p = function(u){
  420. return (u - min) * pixellength / unitlength;
  421. };
  422. this.series_p2u = function(p){
  423. return p * unitlength / pixellength + min;
  424. };
  425. }
  426. else {
  427. this.series_u2p = function(u){
  428. return (u - max) * pixellength / unitlength;
  429. };
  430. this.series_p2u = function(p){
  431. return p * unitlength / pixellength + max;
  432. };
  433. }
  434. }
  435. else {
  436. // point to unit and unit to point conversions references to Plot DOM element top left corner.
  437. this.u2p = function(u){
  438. return offmin + (max - u) * pixellength / unitlength;
  439. };
  440. this.p2u = function(p){
  441. return min + (p - offmin) * unitlength / pixellength;
  442. };
  443. if (this.name == 'xaxis' || this.name == 'x2axis'){
  444. this.series_u2p = function(u){
  445. return (max - u) * pixellength / unitlength;
  446. };
  447. this.series_p2u = function(p){
  448. return p * unitlength / pixellength + max;
  449. };
  450. }
  451. else {
  452. this.series_u2p = function(u){
  453. return (min - u) * pixellength / unitlength;
  454. };
  455. this.series_p2u = function(p){
  456. return p * unitlength / pixellength + min;
  457. };
  458. }
  459. }
  460. if (this.show) {
  461. if (this.name == 'xaxis' || this.name == 'x2axis') {
  462. for (i=0; i<ticks.length; i++) {
  463. var t = ticks[i];
  464. if (t.show && t.showLabel) {
  465. var shim;
  466. if (t.constructor == $.jqplot.CanvasAxisTickRenderer && t.angle) {
  467. // will need to adjust auto positioning based on which axis this is.
  468. var temp = (this.name == 'xaxis') ? 1 : -1;
  469. switch (t.labelPosition) {
  470. case 'auto':
  471. // position at end
  472. if (temp * t.angle < 0) {
  473. shim = -t.getWidth() + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
  474. }
  475. // position at start
  476. else {
  477. shim = -t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
  478. }
  479. break;
  480. case 'end':
  481. shim = -t.getWidth() + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
  482. break;
  483. case 'start':
  484. shim = -t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
  485. break;
  486. case 'middle':
  487. shim = -t.getWidth()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
  488. break;
  489. default:
  490. shim = -t.getWidth()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
  491. break;
  492. }
  493. }
  494. else {
  495. shim = -t.getWidth()/2;
  496. }
  497. var val = this.u2p(t.value) + shim + 'px';
  498. t._elem.css('left', val);
  499. t.pack();
  500. }
  501. }
  502. var labeledge=['bottom', 0];
  503. if (lshow) {
  504. var w = this._label._elem.outerWidth(true);
  505. this._label._elem.css('left', offmin + pixellength/2 - w/2 + 'px');
  506. if (this.name == 'xaxis') {
  507. this._label._elem.css('bottom', '0px');
  508. labeledge = ['bottom', this._label._elem.outerHeight(true)];
  509. }
  510. else {
  511. this._label._elem.css('top', '0px');
  512. labeledge = ['top', this._label._elem.outerHeight(true)];
  513. }
  514. this._label.pack();
  515. }
  516. // draw the group labels
  517. var step = parseInt(this._ticks.length/this.groups, 10);
  518. for (i=0; i<this._groupLabels.length; i++) {
  519. var mid = 0;
  520. var count = 0;
  521. for (var j=i*step; j<=(i+1)*step; j++) {
  522. if (this._ticks[j]._elem && this._ticks[j].label != " ") {
  523. var t = this._ticks[j]._elem;
  524. var p = t.position();
  525. mid += p.left + t.outerWidth(true)/2;
  526. count++;
  527. }
  528. }
  529. mid = mid/count;
  530. this._groupLabels[i].css({'left':(mid - this._groupLabels[i].outerWidth(true)/2)});
  531. this._groupLabels[i].css(labeledge[0], labeledge[1]);
  532. }
  533. }
  534. else {
  535. for (i=0; i<ticks.length; i++) {
  536. var t = ticks[i];
  537. if (t.show && t.showLabel) {
  538. var shim;
  539. if (t.constructor == $.jqplot.CanvasAxisTickRenderer && t.angle) {
  540. // will need to adjust auto positioning based on which axis this is.
  541. var temp = (this.name == 'yaxis') ? 1 : -1;
  542. switch (t.labelPosition) {
  543. case 'auto':
  544. // position at end
  545. case 'end':
  546. if (temp * t.angle < 0) {
  547. shim = -t._textRenderer.height * Math.cos(-t._textRenderer.angle) / 2;
  548. }
  549. else {
  550. shim = -t.getHeight() + t._textRenderer.height * Math.cos(t._textRenderer.angle) / 2;
  551. }
  552. break;
  553. case 'start':
  554. if (t.angle > 0) {
  555. shim = -t._textRenderer.height * Math.cos(-t._textRenderer.angle) / 2;
  556. }
  557. else {
  558. shim = -t.getHeight() + t._textRenderer.height * Math.cos(t._textRenderer.angle) / 2;
  559. }
  560. break;
  561. case 'middle':
  562. // if (t.angle > 0) {
  563. // shim = -t.getHeight()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
  564. // }
  565. // else {
  566. // shim = -t.getHeight()/2 - t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
  567. // }
  568. shim = -t.getHeight()/2;
  569. break;
  570. default:
  571. shim = -t.getHeight()/2;
  572. break;
  573. }
  574. }
  575. else {
  576. shim = -t.getHeight()/2;
  577. }
  578. var val = this.u2p(t.value) + shim + 'px';
  579. t._elem.css('top', val);
  580. t.pack();
  581. }
  582. }
  583. var labeledge=['left', 0];
  584. if (lshow) {
  585. var h = this._label._elem.outerHeight(true);
  586. this._label._elem.css('top', offmax - pixellength/2 - h/2 + 'px');
  587. if (this.name == 'yaxis') {
  588. this._label._elem.css('left', '0px');
  589. labeledge = ['left', this._label._elem.outerWidth(true)];
  590. }
  591. else {
  592. this._label._elem.css('right', '0px');
  593. labeledge = ['right', this._label._elem.outerWidth(true)];
  594. }
  595. this._label.pack();
  596. }
  597. // draw the group labels, position top here, do left after label position.
  598. var step = parseInt(this._ticks.length/this.groups, 10);
  599. for (i=0; i<this._groupLabels.length; i++) {
  600. var mid = 0;
  601. var count = 0;
  602. for (var j=i*step; j<=(i+1)*step; j++) {
  603. if (this._ticks[j]._elem && this._ticks[j].label != " ") {
  604. var t = this._ticks[j]._elem;
  605. var p = t.position();
  606. mid += p.top + t.outerHeight()/2;
  607. count++;
  608. }
  609. }
  610. mid = mid/count;
  611. this._groupLabels[i].css({'top':mid - this._groupLabels[i].outerHeight()/2});
  612. this._groupLabels[i].css(labeledge[0], labeledge[1]);
  613. }
  614. }
  615. }
  616. };
  617. })(jQuery);