jqplot.barRenderer.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. /**
  2. * jqPlot
  3. * Pure JavaScript plotting plugin using jQuery
  4. *
  5. * Version: 1.0.0a_r701
  6. *
  7. * Copyright (c) 2009-2011 Chris Leonello
  8. * jqPlot is currently available for use in all personal or commercial projects
  9. * under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
  10. * version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
  11. * choose the license that best suits your project and use it accordingly.
  12. *
  13. * Although not required, the author would appreciate an email letting him
  14. * know of any substantial use of jqPlot. You can reach the author at:
  15. * chris at jqplot dot com or see http://www.jqplot.com/info.php .
  16. *
  17. * If you are feeling kind and generous, consider supporting the project by
  18. * making a donation at: http://www.jqplot.com/donate.php .
  19. *
  20. * sprintf functions contained in jqplot.sprintf.js by Ash Searle:
  21. *
  22. * version 2007.04.27
  23. * author Ash Searle
  24. * http://hexmen.com/blog/2007/03/printf-sprintf/
  25. * http://hexmen.com/js/sprintf.js
  26. * The author (Ash Searle) has placed this code in the public domain:
  27. * "This code is unrestricted: you are free to use it however you like."
  28. *
  29. */
  30. (function($) {
  31. // Class: $.jqplot.BarRenderer
  32. // A plugin renderer for jqPlot to draw a bar plot.
  33. // Draws series as a line.
  34. $.jqplot.BarRenderer = function(){
  35. $.jqplot.LineRenderer.call(this);
  36. };
  37. $.jqplot.BarRenderer.prototype = new $.jqplot.LineRenderer();
  38. $.jqplot.BarRenderer.prototype.constructor = $.jqplot.BarRenderer;
  39. // called with scope of series.
  40. $.jqplot.BarRenderer.prototype.init = function(options, plot) {
  41. // Group: Properties
  42. //
  43. // prop: barPadding
  44. // Number of pixels between adjacent bars at the same axis value.
  45. this.barPadding = 8;
  46. // prop: barMargin
  47. // Number of pixels between groups of bars at adjacent axis values.
  48. this.barMargin = 10;
  49. // prop: barDirection
  50. // 'vertical' = up and down bars, 'horizontal' = side to side bars
  51. this.barDirection = 'vertical';
  52. // prop: barWidth
  53. // Width of the bar in pixels (auto by devaul). null = calculated automatically.
  54. this.barWidth = null;
  55. // prop: shadowOffset
  56. // offset of the shadow from the slice and offset of
  57. // each succesive stroke of the shadow from the last.
  58. this.shadowOffset = 2;
  59. // prop: shadowDepth
  60. // number of strokes to apply to the shadow,
  61. // each stroke offset shadowOffset from the last.
  62. this.shadowDepth = 5;
  63. // prop: shadowAlpha
  64. // transparency of the shadow (0 = transparent, 1 = opaque)
  65. this.shadowAlpha = 0.08;
  66. // prop: waterfall
  67. // true to enable waterfall plot.
  68. this.waterfall = false;
  69. // prop: groups
  70. // group bars into this many groups
  71. this.groups = 1;
  72. // prop: varyBarColor
  73. // true to color each bar of a series separately rather than
  74. // have every bar of a given series the same color.
  75. // If used for non-stacked multiple series bar plots, user should
  76. // specify a separate 'seriesColors' array for each series.
  77. // Otherwise, each series will set their bars to the same color array.
  78. // This option has no Effect for stacked bar charts and is disabled.
  79. this.varyBarColor = false;
  80. // prop: highlightMouseOver
  81. // True to highlight slice when moused over.
  82. // This must be false to enable highlightMouseDown to highlight when clicking on a slice.
  83. this.highlightMouseOver = true;
  84. // prop: highlightMouseDown
  85. // True to highlight when a mouse button is pressed over a slice.
  86. // This will be disabled if highlightMouseOver is true.
  87. this.highlightMouseDown = false;
  88. // prop: highlightColors
  89. // an array of colors to use when highlighting a bar.
  90. this.highlightColors = [];
  91. // if user has passed in highlightMouseDown option and not set highlightMouseOver, disable highlightMouseOver
  92. if (options.highlightMouseDown && options.highlightMouseOver == null) {
  93. options.highlightMouseOver = false;
  94. }
  95. $.extend(true, this, options);
  96. // fill is still needed to properly draw the legend.
  97. // bars have to be filled.
  98. this.fill = true;
  99. if (this.waterfall) {
  100. this.fillToZero = false;
  101. this.disableStack = true;
  102. }
  103. if (this.barDirection == 'vertical' ) {
  104. this._primaryAxis = '_xaxis';
  105. this._stackAxis = 'y';
  106. this.fillAxis = 'y';
  107. }
  108. else {
  109. this._primaryAxis = '_yaxis';
  110. this._stackAxis = 'x';
  111. this.fillAxis = 'x';
  112. }
  113. // index of the currenty highlighted point, if any
  114. this._highlightedPoint = null;
  115. // total number of values for all bar series, total number of bar series, and position of this series
  116. this._plotSeriesInfo = null;
  117. // Array of actual data colors used for each data point.
  118. this._dataColors = [];
  119. this._barPoints = [];
  120. // set the shape renderer options
  121. var opts = {lineJoin:'miter', lineCap:'round', fill:true, isarc:false, strokeStyle:this.color, fillStyle:this.color, closePath:this.fill};
  122. this.renderer.shapeRenderer.init(opts);
  123. // set the shadow renderer options
  124. var sopts = {lineJoin:'miter', lineCap:'round', fill:true, isarc:false, angle:this.shadowAngle, offset:this.shadowOffset, alpha:this.shadowAlpha, depth:this.shadowDepth, closePath:this.fill};
  125. this.renderer.shadowRenderer.init(sopts);
  126. plot.postInitHooks.addOnce(postInit);
  127. plot.postDrawHooks.addOnce(postPlotDraw);
  128. plot.eventListenerHooks.addOnce('jqplotMouseMove', handleMove);
  129. plot.eventListenerHooks.addOnce('jqplotMouseDown', handleMouseDown);
  130. plot.eventListenerHooks.addOnce('jqplotMouseUp', handleMouseUp);
  131. plot.eventListenerHooks.addOnce('jqplotClick', handleClick);
  132. plot.eventListenerHooks.addOnce('jqplotRightClick', handleRightClick);
  133. };
  134. // called with scope of series
  135. function barPreInit(target, data, seriesDefaults, options) {
  136. if (this.rendererOptions.barDirection == 'horizontal') {
  137. this._stackAxis = 'x';
  138. this._primaryAxis = '_yaxis';
  139. }
  140. if (this.rendererOptions.waterfall == true) {
  141. this._data = $.extend(true, [], this.data);
  142. var sum = 0;
  143. var pos = (!this.rendererOptions.barDirection || this.rendererOptions.barDirection == 'vertical') ? 1 : 0;
  144. for(var i=0; i<this.data.length; i++) {
  145. sum += this.data[i][pos];
  146. if (i>0) {
  147. this.data[i][pos] += this.data[i-1][pos];
  148. }
  149. }
  150. this.data[this.data.length] = (pos == 1) ? [this.data.length+1, sum] : [sum, this.data.length+1];
  151. this._data[this._data.length] = (pos == 1) ? [this._data.length+1, sum] : [sum, this._data.length+1];
  152. }
  153. if (this.rendererOptions.groups > 1) {
  154. this.breakOnNull = true;
  155. var l = this.data.length;
  156. var skip = parseInt(l/this.rendererOptions.groups, 10);
  157. var count = 0;
  158. for (var i=skip; i<l; i+=skip) {
  159. this.data.splice(i+count, 0, [null, null]);
  160. count++;
  161. }
  162. for (i=0; i<this.data.length; i++) {
  163. if (this._primaryAxis == '_xaxis') {
  164. this.data[i][0] = i+1;
  165. }
  166. else {
  167. this.data[i][1] = i+1;
  168. }
  169. }
  170. }
  171. }
  172. $.jqplot.preSeriesInitHooks.push(barPreInit);
  173. // needs to be called with scope of series, not renderer.
  174. $.jqplot.BarRenderer.prototype.calcSeriesNumbers = function() {
  175. var nvals = 0;
  176. var nseries = 0;
  177. var paxis = this[this._primaryAxis];
  178. var s, series, pos;
  179. // loop through all series on this axis
  180. for (var i=0; i < paxis._series.length; i++) {
  181. series = paxis._series[i];
  182. if (series === this) {
  183. pos = i;
  184. }
  185. // is the series rendered as a bar?
  186. if (series.renderer.constructor == $.jqplot.BarRenderer) {
  187. // gridData may not be computed yet, use data length insted
  188. nvals += series.data.length;
  189. nseries += 1;
  190. }
  191. }
  192. // return total number of values for all bar series, total number of bar series, and position of this series
  193. return [nvals, nseries, pos];
  194. };
  195. $.jqplot.BarRenderer.prototype.setBarWidth = function() {
  196. // need to know how many data values we have on the approprate axis and figure it out.
  197. var i;
  198. var nvals = 0;
  199. var nseries = 0;
  200. var paxis = this[this._primaryAxis];
  201. var s, series, pos;
  202. var temp = this._plotSeriesInfo = this.renderer.calcSeriesNumbers.call(this);
  203. nvals = temp[0];
  204. nseries = temp[1];
  205. var nticks = paxis.numberTicks;
  206. var nbins = (nticks-1)/2;
  207. // so, now we have total number of axis values.
  208. if (paxis.name == 'xaxis' || paxis.name == 'x2axis') {
  209. if (this._stack) {
  210. this.barWidth = (paxis._offsets.max - paxis._offsets.min) / nvals * nseries - this.barMargin;
  211. }
  212. else {
  213. this.barWidth = ((paxis._offsets.max - paxis._offsets.min)/nbins - this.barPadding * (nseries-1) - this.barMargin*2)/nseries;
  214. // this.barWidth = (paxis._offsets.max - paxis._offsets.min) / nvals - this.barPadding - this.barMargin/nseries;
  215. }
  216. }
  217. else {
  218. if (this._stack) {
  219. this.barWidth = (paxis._offsets.min - paxis._offsets.max) / nvals * nseries - this.barMargin;
  220. }
  221. else {
  222. this.barWidth = ((paxis._offsets.min - paxis._offsets.max)/nbins - this.barPadding * (nseries-1) - this.barMargin*2)/nseries;
  223. // this.barWidth = (paxis._offsets.min - paxis._offsets.max) / nvals - this.barPadding - this.barMargin/nseries;
  224. }
  225. }
  226. return [nvals, nseries];
  227. };
  228. function computeHighlightColors (colors) {
  229. var ret = [];
  230. for (var i=0; i<colors.length; i++){
  231. var rgba = $.jqplot.getColorComponents(colors[i]);
  232. var newrgb = [rgba[0], rgba[1], rgba[2]];
  233. var sum = newrgb[0] + newrgb[1] + newrgb[2];
  234. for (var j=0; j<3; j++) {
  235. // when darkening, lowest color component can be is 60.
  236. newrgb[j] = (sum > 570) ? newrgb[j] * 0.8 : newrgb[j] + 0.3 * (255 - newrgb[j]);
  237. newrgb[j] = parseInt(newrgb[j], 10);
  238. }
  239. ret.push('rgb('+newrgb[0]+','+newrgb[1]+','+newrgb[2]+')');
  240. }
  241. return ret;
  242. }
  243. $.jqplot.BarRenderer.prototype.draw = function(ctx, gridData, options) {
  244. var i;
  245. var opts = (options != undefined) ? options : {};
  246. var shadow = (opts.shadow != undefined) ? opts.shadow : this.shadow;
  247. var showLine = (opts.showLine != undefined) ? opts.showLine : this.showLine;
  248. var fill = (opts.fill != undefined) ? opts.fill : this.fill;
  249. var xaxis = this.xaxis;
  250. var yaxis = this.yaxis;
  251. var xp = this._xaxis.series_u2p;
  252. var yp = this._yaxis.series_u2p;
  253. var pointx, pointy, nvals, nseries, pos;
  254. // clear out data colors.
  255. this._dataColors = [];
  256. this._barPoints = [];
  257. if (this.barWidth == null) {
  258. this.renderer.setBarWidth.call(this);
  259. }
  260. var temp = this._plotSeriesInfo = this.renderer.calcSeriesNumbers.call(this);
  261. nvals = temp[0];
  262. nseries = temp[1];
  263. pos = temp[2];
  264. if (this._stack) {
  265. this._barNudge = 0;
  266. }
  267. else {
  268. this._barNudge = (-Math.abs(nseries/2 - 0.5) + pos) * (this.barWidth + this.barPadding);
  269. }
  270. if (showLine) {
  271. var negativeColors = new $.jqplot.ColorGenerator(this.negativeSeriesColors);
  272. var positiveColors = new $.jqplot.ColorGenerator(this.seriesColors);
  273. var negativeColor = negativeColors.get(this.index);
  274. if (! this.useNegativeColors) {
  275. negativeColor = opts.fillStyle;
  276. }
  277. var positiveColor = opts.fillStyle;
  278. if (this.barDirection == 'vertical') {
  279. for (var i=0; i<gridData.length; i++) {
  280. if (this.data[i][1] == null) {
  281. continue;
  282. }
  283. points = [];
  284. var base = gridData[i][0] + this._barNudge;
  285. var ystart;
  286. // stacked
  287. if (this._stack && this._prevGridData.length) {
  288. ystart = this._prevGridData[i][1];
  289. }
  290. // not stacked and first series in stack
  291. else {
  292. if (this.fillToZero) {
  293. ystart = this._yaxis.series_u2p(0);
  294. }
  295. else if (this.waterfall && i > 0 && i < this.gridData.length-1) {
  296. ystart = this.gridData[i-1][1];
  297. }
  298. else {
  299. ystart = ctx.canvas.height;
  300. }
  301. }
  302. if ((this.fillToZero && this._plotData[i][1] < 0) || (this.waterfall && this._data[i][1] < 0)) {
  303. if (this.varyBarColor && !this._stack) {
  304. if (this.useNegativeColors) {
  305. opts.fillStyle = negativeColors.next();
  306. }
  307. else {
  308. opts.fillStyle = positiveColors.next();
  309. }
  310. }
  311. else {
  312. opts.fillStyle = negativeColor;
  313. }
  314. }
  315. else {
  316. if (this.varyBarColor && !this._stack) {
  317. opts.fillStyle = positiveColors.next();
  318. }
  319. else {
  320. opts.fillStyle = positiveColor;
  321. }
  322. }
  323. points.push([base-this.barWidth/2, ystart]);
  324. points.push([base-this.barWidth/2, gridData[i][1]]);
  325. points.push([base+this.barWidth/2, gridData[i][1]]);
  326. points.push([base+this.barWidth/2, ystart]);
  327. this._barPoints.push(points);
  328. // now draw the shadows if not stacked.
  329. // for stacked plots, they are predrawn by drawShadow
  330. if (shadow && !this._stack) {
  331. var sopts = $.extend(true, {}, opts);
  332. // need to get rid of fillStyle on shadow.
  333. delete sopts.fillStyle;
  334. this.renderer.shadowRenderer.draw(ctx, points, sopts);
  335. }
  336. var clr = opts.fillStyle || this.color;
  337. this._dataColors.push(clr);
  338. this.renderer.shapeRenderer.draw(ctx, points, opts);
  339. }
  340. }
  341. else if (this.barDirection == 'horizontal'){
  342. for (var i=0; i<gridData.length; i++) {
  343. if (this.data[i][0] == null) {
  344. continue;
  345. }
  346. points = [];
  347. var base = gridData[i][1] - this._barNudge;
  348. var xstart;
  349. if (this._stack && this._prevGridData.length) {
  350. xstart = this._prevGridData[i][0];
  351. }
  352. // not stacked and first series in stack
  353. else {
  354. if (this.fillToZero) {
  355. xstart = this._xaxis.series_u2p(0);
  356. }
  357. else if (this.waterfall && i > 0 && i < this.gridData.length-1) {
  358. xstart = this.gridData[i-1][1];
  359. }
  360. else {
  361. xstart = 0;
  362. }
  363. }
  364. if ((this.fillToZero && this._plotData[i][1] < 0) || (this.waterfall && this._data[i][1] < 0)) {
  365. if (this.varyBarColor && !this._stack) {
  366. if (this.useNegativeColors) {
  367. opts.fillStyle = negativeColors.next();
  368. }
  369. else {
  370. opts.fillStyle = positiveColors.next();
  371. }
  372. }
  373. }
  374. else {
  375. if (this.varyBarColor && !this._stack) {
  376. opts.fillStyle = positiveColors.next();
  377. }
  378. else {
  379. opts.fillStyle = positiveColor;
  380. }
  381. }
  382. points.push([xstart, base+this.barWidth/2]);
  383. points.push([xstart, base-this.barWidth/2]);
  384. points.push([gridData[i][0], base-this.barWidth/2]);
  385. points.push([gridData[i][0], base+this.barWidth/2]);
  386. this._barPoints.push(points);
  387. // now draw the shadows if not stacked.
  388. // for stacked plots, they are predrawn by drawShadow
  389. if (shadow && !this._stack) {
  390. var sopts = $.extend(true, {}, opts);
  391. delete sopts.fillStyle;
  392. this.renderer.shadowRenderer.draw(ctx, points, sopts);
  393. }
  394. var clr = opts.fillStyle || this.color;
  395. this._dataColors.push(clr);
  396. this.renderer.shapeRenderer.draw(ctx, points, opts);
  397. }
  398. }
  399. }
  400. if (this.highlightColors.length == 0) {
  401. this.highlightColors = computeHighlightColors(this._dataColors);
  402. }
  403. else if (typeof(this.highlightColors) == 'string') {
  404. var temp = this.highlightColors;
  405. this.highlightColors = [];
  406. for (var i=0; i<this._dataColors.length; i++) {
  407. this.highlightColors.push(temp);
  408. }
  409. }
  410. };
  411. // for stacked plots, shadows will be pre drawn by drawShadow.
  412. $.jqplot.BarRenderer.prototype.drawShadow = function(ctx, gridData, options) {
  413. var i;
  414. var opts = (options != undefined) ? options : {};
  415. var shadow = (opts.shadow != undefined) ? opts.shadow : this.shadow;
  416. var showLine = (opts.showLine != undefined) ? opts.showLine : this.showLine;
  417. var fill = (opts.fill != undefined) ? opts.fill : this.fill;
  418. var xaxis = this.xaxis;
  419. var yaxis = this.yaxis;
  420. var xp = this._xaxis.series_u2p;
  421. var yp = this._yaxis.series_u2p;
  422. var pointx, pointy, nvals, nseries, pos;
  423. if (this._stack && this.shadow) {
  424. if (this.barWidth == null) {
  425. this.renderer.setBarWidth.call(this);
  426. }
  427. var temp = this._plotSeriesInfo = this.renderer.calcSeriesNumbers.call(this);
  428. nvals = temp[0];
  429. nseries = temp[1];
  430. pos = temp[2];
  431. if (this._stack) {
  432. this._barNudge = 0;
  433. }
  434. else {
  435. this._barNudge = (-Math.abs(nseries/2 - 0.5) + pos) * (this.barWidth + this.barPadding);
  436. }
  437. if (showLine) {
  438. if (this.barDirection == 'vertical') {
  439. for (var i=0; i<gridData.length; i++) {
  440. if (this.data[i][1] == null) {
  441. continue;
  442. }
  443. points = [];
  444. var base = gridData[i][0] + this._barNudge;
  445. var ystart;
  446. if (this._stack && this._prevGridData.length) {
  447. ystart = this._prevGridData[i][1];
  448. }
  449. else {
  450. if (this.fillToZero) {
  451. ystart = this._yaxis.series_u2p(0);
  452. }
  453. else {
  454. ystart = ctx.canvas.height;
  455. }
  456. }
  457. points.push([base-this.barWidth/2, ystart]);
  458. points.push([base-this.barWidth/2, gridData[i][1]]);
  459. points.push([base+this.barWidth/2, gridData[i][1]]);
  460. points.push([base+this.barWidth/2, ystart]);
  461. this.renderer.shadowRenderer.draw(ctx, points, opts);
  462. }
  463. }
  464. else if (this.barDirection == 'horizontal'){
  465. for (var i=0; i<gridData.length; i++) {
  466. if (this.data[i][0] == null) {
  467. continue;
  468. }
  469. points = [];
  470. var base = gridData[i][1] - this._barNudge;
  471. var xstart;
  472. if (this._stack && this._prevGridData.length) {
  473. xstart = this._prevGridData[i][0];
  474. }
  475. else {
  476. xstart = 0;
  477. }
  478. points.push([xstart, base+this.barWidth/2]);
  479. points.push([gridData[i][0], base+this.barWidth/2]);
  480. points.push([gridData[i][0], base-this.barWidth/2]);
  481. points.push([xstart, base-this.barWidth/2]);
  482. this.renderer.shadowRenderer.draw(ctx, points, opts);
  483. }
  484. }
  485. }
  486. }
  487. };
  488. function postInit(target, data, options) {
  489. for (i=0; i<this.series.length; i++) {
  490. if (this.series[i].renderer.constructor == $.jqplot.BarRenderer) {
  491. // don't allow mouseover and mousedown at same time.
  492. if (this.series[i].highlightMouseOver) {
  493. this.series[i].highlightMouseDown = false;
  494. }
  495. }
  496. }
  497. this.target.bind('mouseout', {plot:this}, function (ev) { unhighlight(ev.data.plot); });
  498. }
  499. // called within context of plot
  500. // create a canvas which we can draw on.
  501. // insert it before the eventCanvas, so eventCanvas will still capture events.
  502. function postPlotDraw() {
  503. this.plugins.barRenderer = {highlightedSeriesIndex:null};
  504. this.plugins.barRenderer.highlightCanvas = new $.jqplot.GenericCanvas();
  505. this.eventCanvas._elem.before(this.plugins.barRenderer.highlightCanvas.createElement(this._gridPadding, 'jqplot-barRenderer-highlight-canvas', this._plotDimensions));
  506. this.plugins.barRenderer.highlightCanvas.setContext();
  507. }
  508. function highlight (plot, sidx, pidx, points) {
  509. var s = plot.series[sidx];
  510. var canvas = plot.plugins.barRenderer.highlightCanvas;
  511. canvas._ctx.clearRect(0,0,canvas._ctx.canvas.width, canvas._ctx.canvas.height);
  512. s._highlightedPoint = pidx;
  513. plot.plugins.barRenderer.highlightedSeriesIndex = sidx;
  514. var opts = {fillStyle: s.highlightColors[pidx]};
  515. s.renderer.shapeRenderer.draw(canvas._ctx, points, opts);
  516. canvas = null;
  517. }
  518. function unhighlight (plot) {
  519. var canvas = plot.plugins.barRenderer.highlightCanvas;
  520. canvas._ctx.clearRect(0,0, canvas._ctx.canvas.width, canvas._ctx.canvas.height);
  521. for (var i=0; i<plot.series.length; i++) {
  522. plot.series[i]._highlightedPoint = null;
  523. }
  524. plot.plugins.barRenderer.highlightedSeriesIndex = null;
  525. plot.target.trigger('jqplotDataUnhighlight');
  526. canvas = null;
  527. }
  528. function handleMove(ev, gridpos, datapos, neighbor, plot) {
  529. if (neighbor) {
  530. var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
  531. var evt1 = jQuery.Event('jqplotDataMouseOver');
  532. evt1.pageX = ev.pageX;
  533. evt1.pageY = ev.pageY;
  534. plot.target.trigger(evt1, ins);
  535. if (plot.series[ins[0]].highlightMouseOver && !(ins[0] == plot.plugins.barRenderer.highlightedSeriesIndex && ins[1] == plot.series[ins[0]]._highlightedPoint)) {
  536. var evt = jQuery.Event('jqplotDataHighlight');
  537. evt.pageX = ev.pageX;
  538. evt.pageY = ev.pageY;
  539. plot.target.trigger(evt, ins);
  540. highlight (plot, neighbor.seriesIndex, neighbor.pointIndex, neighbor.points);
  541. }
  542. }
  543. else if (neighbor == null) {
  544. unhighlight (plot);
  545. }
  546. }
  547. function handleMouseDown(ev, gridpos, datapos, neighbor, plot) {
  548. if (neighbor) {
  549. var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
  550. if (plot.series[ins[0]].highlightMouseDown && !(ins[0] == plot.plugins.barRenderer.highlightedSeriesIndex && ins[1] == plot.series[ins[0]]._highlightedPoint)) {
  551. var evt = jQuery.Event('jqplotDataHighlight');
  552. evt.pageX = ev.pageX;
  553. evt.pageY = ev.pageY;
  554. plot.target.trigger(evt, ins);
  555. highlight (plot, neighbor.seriesIndex, neighbor.pointIndex, neighbor.points);
  556. }
  557. }
  558. else if (neighbor == null) {
  559. unhighlight (plot);
  560. }
  561. }
  562. function handleMouseUp(ev, gridpos, datapos, neighbor, plot) {
  563. var idx = plot.plugins.barRenderer.highlightedSeriesIndex;
  564. if (idx != null && plot.series[idx].highlightMouseDown) {
  565. unhighlight(plot);
  566. }
  567. }
  568. function handleClick(ev, gridpos, datapos, neighbor, plot) {
  569. if (neighbor) {
  570. var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
  571. var evt = jQuery.Event('jqplotDataClick');
  572. evt.pageX = ev.pageX;
  573. evt.pageY = ev.pageY;
  574. plot.target.trigger(evt, ins);
  575. }
  576. }
  577. function handleRightClick(ev, gridpos, datapos, neighbor, plot) {
  578. if (neighbor) {
  579. var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
  580. var idx = plot.plugins.barRenderer.highlightedSeriesIndex;
  581. if (idx != null && plot.series[idx].highlightMouseDown) {
  582. unhighlight(plot);
  583. }
  584. var evt = jQuery.Event('jqplotDataRightClick');
  585. evt.pageX = ev.pageX;
  586. evt.pageY = ev.pageY;
  587. plot.target.trigger(evt, ins);
  588. }
  589. }
  590. })(jQuery);