| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
(function($) { |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
$.jqplot.BarRenderer = function(){ |
| 38 |
$.jqplot.LineRenderer.call(this); |
| 39 |
}; |
| 40 |
|
| 41 |
$.jqplot.BarRenderer.prototype = new $.jqplot.LineRenderer(); |
| 42 |
$.jqplot.BarRenderer.prototype.constructor = $.jqplot.BarRenderer; |
| 43 |
|
| 44 |
|
| 45 |
$.jqplot.BarRenderer.prototype.init = function(options, plot) { |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
this.barPadding = 8; |
| 51 |
|
| 52 |
|
| 53 |
this.barMargin = 10; |
| 54 |
|
| 55 |
|
| 56 |
this.barDirection = 'vertical'; |
| 57 |
|
| 58 |
|
| 59 |
this.barWidth = null; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
this.shadowOffset = 2; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
this.shadowDepth = 5; |
| 68 |
|
| 69 |
|
| 70 |
this.shadowAlpha = 0.08; |
| 71 |
|
| 72 |
|
| 73 |
this.waterfall = false; |
| 74 |
|
| 75 |
|
| 76 |
this.groups = 1; |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
this.varyBarColor = false; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
this.highlightMouseOver = true; |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
this.highlightMouseDown = false; |
| 93 |
|
| 94 |
|
| 95 |
this.highlightColors = []; |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
this.transposedData = true; |
| 103 |
this.renderer.animation = { |
| 104 |
show: false, |
| 105 |
direction: 'down', |
| 106 |
speed: 3000, |
| 107 |
_supported: true |
| 108 |
}; |
| 109 |
this._type = 'bar'; |
| 110 |
|
| 111 |
|
| 112 |
if (options.highlightMouseDown && options.highlightMouseOver == null) { |
| 113 |
options.highlightMouseOver = false; |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
$.extend(true, this, options); |
| 124 |
|
| 125 |
|
| 126 |
$.extend(true, this.renderer, options); |
| 127 |
|
| 128 |
|
| 129 |
this.fill = true; |
| 130 |
|
| 131 |
|
| 132 |
if (this.barDirection === 'horizontal' && this.rendererOptions.animation && this.rendererOptions.animation.direction == null) { |
| 133 |
this.renderer.animation.direction = 'left'; |
| 134 |
} |
| 135 |
|
| 136 |
if (this.waterfall) { |
| 137 |
this.fillToZero = false; |
| 138 |
this.disableStack = true; |
| 139 |
} |
| 140 |
|
| 141 |
if (this.barDirection == 'vertical' ) { |
| 142 |
this._primaryAxis = '_xaxis'; |
| 143 |
this._stackAxis = 'y'; |
| 144 |
this.fillAxis = 'y'; |
| 145 |
} |
| 146 |
else { |
| 147 |
this._primaryAxis = '_yaxis'; |
| 148 |
this._stackAxis = 'x'; |
| 149 |
this.fillAxis = 'x'; |
| 150 |
} |
| 151 |
|
| 152 |
this._highlightedPoint = null; |
| 153 |
|
| 154 |
this._plotSeriesInfo = null; |
| 155 |
|
| 156 |
this._dataColors = []; |
| 157 |
this._barPoints = []; |
| 158 |
|
| 159 |
|
| 160 |
var opts = {lineJoin:'miter', lineCap:'round', fill:true, isarc:false, strokeStyle:this.color, fillStyle:this.color, closePath:this.fill}; |
| 161 |
this.renderer.shapeRenderer.init(opts); |
| 162 |
|
| 163 |
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}; |
| 164 |
this.renderer.shadowRenderer.init(sopts); |
| 165 |
|
| 166 |
plot.postInitHooks.addOnce(postInit); |
| 167 |
plot.postDrawHooks.addOnce(postPlotDraw); |
| 168 |
plot.eventListenerHooks.addOnce('jqplotMouseMove', handleMove); |
| 169 |
plot.eventListenerHooks.addOnce('jqplotMouseDown', handleMouseDown); |
| 170 |
plot.eventListenerHooks.addOnce('jqplotMouseUp', handleMouseUp); |
| 171 |
plot.eventListenerHooks.addOnce('jqplotClick', handleClick); |
| 172 |
plot.eventListenerHooks.addOnce('jqplotRightClick', handleRightClick); |
| 173 |
}; |
| 174 |
|
| 175 |
|
| 176 |
function barPreInit(target, data, seriesDefaults, options) { |
| 177 |
if (this.rendererOptions.barDirection == 'horizontal') { |
| 178 |
this._stackAxis = 'x'; |
| 179 |
this._primaryAxis = '_yaxis'; |
| 180 |
} |
| 181 |
if (this.rendererOptions.waterfall == true) { |
| 182 |
this._data = $.extend(true, [], this.data); |
| 183 |
var sum = 0; |
| 184 |
var pos = (!this.rendererOptions.barDirection || this.rendererOptions.barDirection === 'vertical' || this.transposedData === false) ? 1 : 0; |
| 185 |
for(var i=0; i<this.data.length; i++) { |
| 186 |
sum += this.data[i][pos]; |
| 187 |
if (i>0) { |
| 188 |
this.data[i][pos] += this.data[i-1][pos]; |
| 189 |
} |
| 190 |
} |
| 191 |
this.data[this.data.length] = (pos == 1) ? [this.data.length+1, sum] : [sum, this.data.length+1]; |
| 192 |
this._data[this._data.length] = (pos == 1) ? [this._data.length+1, sum] : [sum, this._data.length+1]; |
| 193 |
} |
| 194 |
if (this.rendererOptions.groups > 1) { |
| 195 |
this.breakOnNull = true; |
| 196 |
var l = this.data.length; |
| 197 |
var skip = parseInt(l/this.rendererOptions.groups, 10); |
| 198 |
var count = 0; |
| 199 |
for (var i=skip; i<l; i+=skip) { |
| 200 |
this.data.splice(i+count, 0, [null, null]); |
| 201 |
this._plotData.splice(i+count, 0, [null, null]); |
| 202 |
this._stackData.splice(i+count, 0, [null, null]); |
| 203 |
count++; |
| 204 |
} |
| 205 |
for (i=0; i<this.data.length; i++) { |
| 206 |
if (this._primaryAxis == '_xaxis') { |
| 207 |
this.data[i][0] = i+1; |
| 208 |
this._plotData[i][0] = i+1; |
| 209 |
this._stackData[i][0] = i+1; |
| 210 |
} |
| 211 |
else { |
| 212 |
this.data[i][1] = i+1; |
| 213 |
this._plotData[i][1] = i+1; |
| 214 |
this._stackData[i][1] = i+1; |
| 215 |
} |
| 216 |
} |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
$.jqplot.preSeriesInitHooks.push(barPreInit); |
| 221 |
|
| 222 |
|
| 223 |
$.jqplot.BarRenderer.prototype.calcSeriesNumbers = function() { |
| 224 |
var nvals = 0; |
| 225 |
var nseries = 0; |
| 226 |
var paxis = this[this._primaryAxis]; |
| 227 |
var s, series, pos; |
| 228 |
|
| 229 |
for (var i=0; i < paxis._series.length; i++) { |
| 230 |
series = paxis._series[i]; |
| 231 |
if (series === this) { |
| 232 |
pos = i; |
| 233 |
} |
| 234 |
|
| 235 |
if (series.renderer.constructor == $.jqplot.BarRenderer) { |
| 236 |
|
| 237 |
nvals += series.data.length; |
| 238 |
nseries += 1; |
| 239 |
} |
| 240 |
} |
| 241 |
|
| 242 |
return [nvals, nseries, pos]; |
| 243 |
}; |
| 244 |
|
| 245 |
$.jqplot.BarRenderer.prototype.setBarWidth = function() { |
| 246 |
|
| 247 |
var i; |
| 248 |
var nvals = 0; |
| 249 |
var nseries = 0; |
| 250 |
var paxis = this[this._primaryAxis]; |
| 251 |
var s, series, pos; |
| 252 |
var temp = this._plotSeriesInfo = this.renderer.calcSeriesNumbers.call(this); |
| 253 |
nvals = temp[0]; |
| 254 |
nseries = temp[1]; |
| 255 |
var nticks = paxis.numberTicks; |
| 256 |
var nbins = (nticks-1)/2; |
| 257 |
|
| 258 |
if (paxis.name == 'xaxis' || paxis.name == 'x2axis') { |
| 259 |
if (this._stack) { |
| 260 |
this.barWidth = (paxis._offsets.max - paxis._offsets.min) / nvals * nseries - this.barMargin; |
| 261 |
} |
| 262 |
else { |
| 263 |
this.barWidth = ((paxis._offsets.max - paxis._offsets.min)/nbins - this.barPadding * (nseries-1) - this.barMargin*2)/nseries; |
| 264 |
|
| 265 |
} |
| 266 |
} |
| 267 |
else { |
| 268 |
if (this._stack) { |
| 269 |
this.barWidth = (paxis._offsets.min - paxis._offsets.max) / nvals * nseries - this.barMargin; |
| 270 |
} |
| 271 |
else { |
| 272 |
this.barWidth = ((paxis._offsets.min - paxis._offsets.max)/nbins - this.barPadding * (nseries-1) - this.barMargin*2)/nseries; |
| 273 |
|
| 274 |
} |
| 275 |
} |
| 276 |
return [nvals, nseries]; |
| 277 |
}; |
| 278 |
|
| 279 |
function computeHighlightColors (colors) { |
| 280 |
var ret = []; |
| 281 |
for (var i=0; i<colors.length; i++){ |
| 282 |
var rgba = $.jqplot.getColorComponents(colors[i]); |
| 283 |
var newrgb = [rgba[0], rgba[1], rgba[2]]; |
| 284 |
var sum = newrgb[0] + newrgb[1] + newrgb[2]; |
| 285 |
for (var j=0; j<3; j++) { |
| 286 |
|
| 287 |
newrgb[j] = (sum > 570) ? newrgb[j] * 0.8 : newrgb[j] + 0.3 * (255 - newrgb[j]); |
| 288 |
newrgb[j] = parseInt(newrgb[j], 10); |
| 289 |
} |
| 290 |
ret.push('rgb('+newrgb[0]+','+newrgb[1]+','+newrgb[2]+')'); |
| 291 |
} |
| 292 |
return ret; |
| 293 |
} |
| 294 |
|
| 295 |
function getStart(sidx, didx, comp, plot, axis) { |
| 296 |
|
| 297 |
var seriesIndex = sidx, |
| 298 |
prevSeriesIndex = sidx - 1, |
| 299 |
start, |
| 300 |
prevVal, |
| 301 |
aidx = (axis === 'x') ? 0 : 1; |
| 302 |
|
| 303 |
|
| 304 |
if (seriesIndex > 0) { |
| 305 |
prevVal = plot.series[prevSeriesIndex]._plotData[didx][aidx]; |
| 306 |
|
| 307 |
|
| 308 |
if ((comp * prevVal) < 0) { |
| 309 |
start = getStart(prevSeriesIndex, didx, comp, plot, axis); |
| 310 |
} |
| 311 |
|
| 312 |
|
| 313 |
else { |
| 314 |
start = plot.series[prevSeriesIndex].gridData[didx][aidx]; |
| 315 |
} |
| 316 |
|
| 317 |
} |
| 318 |
|
| 319 |
|
| 320 |
else { |
| 321 |
|
| 322 |
start = (aidx === 0) ? plot.series[seriesIndex]._xaxis.series_u2p(0) : plot.series[seriesIndex]._yaxis.series_u2p(0); |
| 323 |
} |
| 324 |
|
| 325 |
return start; |
| 326 |
} |
| 327 |
|
| 328 |
|
| 329 |
$.jqplot.BarRenderer.prototype.draw = function(ctx, gridData, options, plot) { |
| 330 |
var i; |
| 331 |
|
| 332 |
var opts = $.extend({}, options); |
| 333 |
var shadow = (opts.shadow != undefined) ? opts.shadow : this.shadow; |
| 334 |
var showLine = (opts.showLine != undefined) ? opts.showLine : this.showLine; |
| 335 |
var fill = (opts.fill != undefined) ? opts.fill : this.fill; |
| 336 |
var xaxis = this.xaxis; |
| 337 |
var yaxis = this.yaxis; |
| 338 |
var xp = this._xaxis.series_u2p; |
| 339 |
var yp = this._yaxis.series_u2p; |
| 340 |
var pointx, pointy; |
| 341 |
|
| 342 |
this._dataColors = []; |
| 343 |
this._barPoints = []; |
| 344 |
|
| 345 |
if (this.barWidth == null) { |
| 346 |
this.renderer.setBarWidth.call(this); |
| 347 |
} |
| 348 |
|
| 349 |
var temp = this._plotSeriesInfo = this.renderer.calcSeriesNumbers.call(this); |
| 350 |
var nvals = temp[0]; |
| 351 |
var nseries = temp[1]; |
| 352 |
var pos = temp[2]; |
| 353 |
var points = []; |
| 354 |
|
| 355 |
if (this._stack) { |
| 356 |
this._barNudge = 0; |
| 357 |
} |
| 358 |
else { |
| 359 |
this._barNudge = (-Math.abs(nseries/2 - 0.5) + pos) * (this.barWidth + this.barPadding); |
| 360 |
} |
| 361 |
if (showLine) { |
| 362 |
var negativeColors = new $.jqplot.ColorGenerator(this.negativeSeriesColors); |
| 363 |
var positiveColors = new $.jqplot.ColorGenerator(this.seriesColors); |
| 364 |
var negativeColor = negativeColors.get(this.index); |
| 365 |
if (! this.useNegativeColors) { |
| 366 |
negativeColor = opts.fillStyle; |
| 367 |
} |
| 368 |
var positiveColor = opts.fillStyle; |
| 369 |
var base; |
| 370 |
var xstart; |
| 371 |
var ystart; |
| 372 |
|
| 373 |
if (this.barDirection == 'vertical') { |
| 374 |
for (var i=0; i<gridData.length; i++) { |
| 375 |
if (!this._stack && this.data[i][1] == null) { |
| 376 |
continue; |
| 377 |
} |
| 378 |
points = []; |
| 379 |
base = gridData[i][0] + this._barNudge; |
| 380 |
|
| 381 |
|
| 382 |
if (this._stack && this._prevGridData.length) { |
| 383 |
ystart = getStart(this.index, i, this._plotData[i][1], plot, 'y'); |
| 384 |
} |
| 385 |
|
| 386 |
|
| 387 |
else { |
| 388 |
if (this.fillToZero) { |
| 389 |
ystart = this._yaxis.series_u2p(0); |
| 390 |
} |
| 391 |
else if (this.waterfall && i > 0 && i < this.gridData.length-1) { |
| 392 |
ystart = this.gridData[i-1][1]; |
| 393 |
} |
| 394 |
else if (this.waterfall && i == 0 && i < this.gridData.length-1) { |
| 395 |
if (this._yaxis.min <= 0 && this._yaxis.max >= 0) { |
| 396 |
ystart = this._yaxis.series_u2p(0); |
| 397 |
} |
| 398 |
else if (this._yaxis.min > 0) { |
| 399 |
ystart = ctx.canvas.height; |
| 400 |
} |
| 401 |
else { |
| 402 |
ystart = 0; |
| 403 |
} |
| 404 |
} |
| 405 |
else if (this.waterfall && i == this.gridData.length - 1) { |
| 406 |
if (this._yaxis.min <= 0 && this._yaxis.max >= 0) { |
| 407 |
ystart = this._yaxis.series_u2p(0); |
| 408 |
} |
| 409 |
else if (this._yaxis.min > 0) { |
| 410 |
ystart = ctx.canvas.height; |
| 411 |
} |
| 412 |
else { |
| 413 |
ystart = 0; |
| 414 |
} |
| 415 |
} |
| 416 |
else { |
| 417 |
ystart = ctx.canvas.height; |
| 418 |
} |
| 419 |
} |
| 420 |
if ((this.fillToZero && this._plotData[i][1] < 0) || (this.waterfall && this._data[i][1] < 0)) { |
| 421 |
if (this.varyBarColor && !this._stack) { |
| 422 |
if (this.useNegativeColors) { |
| 423 |
opts.fillStyle = negativeColors.next(); |
| 424 |
} |
| 425 |
else { |
| 426 |
opts.fillStyle = positiveColors.next(); |
| 427 |
} |
| 428 |
} |
| 429 |
else { |
| 430 |
opts.fillStyle = negativeColor; |
| 431 |
} |
| 432 |
} |
| 433 |
else { |
| 434 |
if (this.varyBarColor && !this._stack) { |
| 435 |
opts.fillStyle = positiveColors.next(); |
| 436 |
} |
| 437 |
else { |
| 438 |
opts.fillStyle = positiveColor; |
| 439 |
} |
| 440 |
} |
| 441 |
|
| 442 |
if (!this.fillToZero || this._plotData[i][1] >= 0) { |
| 443 |
points.push([base-this.barWidth/2, ystart]); |
| 444 |
points.push([base-this.barWidth/2, gridData[i][1]]); |
| 445 |
points.push([base+this.barWidth/2, gridData[i][1]]); |
| 446 |
points.push([base+this.barWidth/2, ystart]); |
| 447 |
} |
| 448 |
|
| 449 |
else { |
| 450 |
points.push([base-this.barWidth/2, gridData[i][1]]); |
| 451 |
points.push([base-this.barWidth/2, ystart]); |
| 452 |
points.push([base+this.barWidth/2, ystart]); |
| 453 |
points.push([base+this.barWidth/2, gridData[i][1]]); |
| 454 |
} |
| 455 |
this._barPoints.push(points); |
| 456 |
|
| 457 |
|
| 458 |
if (shadow && !this._stack) { |
| 459 |
var sopts = $.extend(true, {}, opts); |
| 460 |
|
| 461 |
delete sopts.fillStyle; |
| 462 |
this.renderer.shadowRenderer.draw(ctx, points, sopts); |
| 463 |
} |
| 464 |
var clr = opts.fillStyle || this.color; |
| 465 |
this._dataColors.push(clr); |
| 466 |
this.renderer.shapeRenderer.draw(ctx, points, opts); |
| 467 |
} |
| 468 |
} |
| 469 |
|
| 470 |
else if (this.barDirection == 'horizontal'){ |
| 471 |
for (var i=0; i<gridData.length; i++) { |
| 472 |
if (!this._stack && this.data[i][0] == null) { |
| 473 |
continue; |
| 474 |
} |
| 475 |
points = []; |
| 476 |
base = gridData[i][1] - this._barNudge; |
| 477 |
xstart; |
| 478 |
|
| 479 |
if (this._stack && this._prevGridData.length) { |
| 480 |
xstart = getStart(this.index, i, this._plotData[i][0], plot, 'x'); |
| 481 |
} |
| 482 |
|
| 483 |
else { |
| 484 |
if (this.fillToZero) { |
| 485 |
xstart = this._xaxis.series_u2p(0); |
| 486 |
} |
| 487 |
else if (this.waterfall && i > 0 && i < this.gridData.length-1) { |
| 488 |
xstart = this.gridData[i-1][0]; |
| 489 |
} |
| 490 |
else if (this.waterfall && i == 0 && i < this.gridData.length-1) { |
| 491 |
if (this._xaxis.min <= 0 && this._xaxis.max >= 0) { |
| 492 |
xstart = this._xaxis.series_u2p(0); |
| 493 |
} |
| 494 |
else if (this._xaxis.min > 0) { |
| 495 |
xstart = 0; |
| 496 |
} |
| 497 |
else { |
| 498 |
xstart = 0; |
| 499 |
} |
| 500 |
} |
| 501 |
else if (this.waterfall && i == this.gridData.length - 1) { |
| 502 |
if (this._xaxis.min <= 0 && this._xaxis.max >= 0) { |
| 503 |
xstart = this._xaxis.series_u2p(0); |
| 504 |
} |
| 505 |
else if (this._xaxis.min > 0) { |
| 506 |
xstart = 0; |
| 507 |
} |
| 508 |
else { |
| 509 |
xstart = ctx.canvas.width; |
| 510 |
} |
| 511 |
} |
| 512 |
else { |
| 513 |
xstart = 0; |
| 514 |
} |
| 515 |
} |
| 516 |
if ((this.fillToZero && this._plotData[i][0] < 0) || (this.waterfall && this._data[i][0] < 0)) { |
| 517 |
if (this.varyBarColor && !this._stack) { |
| 518 |
if (this.useNegativeColors) { |
| 519 |
opts.fillStyle = negativeColors.next(); |
| 520 |
} |
| 521 |
else { |
| 522 |
opts.fillStyle = positiveColors.next(); |
| 523 |
} |
| 524 |
} |
| 525 |
else { |
| 526 |
opts.fillStyle = negativeColor; |
| 527 |
} |
| 528 |
} |
| 529 |
else { |
| 530 |
if (this.varyBarColor && !this._stack) { |
| 531 |
opts.fillStyle = positiveColors.next(); |
| 532 |
} |
| 533 |
else { |
| 534 |
opts.fillStyle = positiveColor; |
| 535 |
} |
| 536 |
} |
| 537 |
|
| 538 |
|
| 539 |
if (!this.fillToZero || this._plotData[i][0] >= 0) { |
| 540 |
points.push([xstart, base + this.barWidth / 2]); |
| 541 |
points.push([xstart, base - this.barWidth / 2]); |
| 542 |
points.push([gridData[i][0], base - this.barWidth / 2]); |
| 543 |
points.push([gridData[i][0], base + this.barWidth / 2]); |
| 544 |
} |
| 545 |
else { |
| 546 |
points.push([gridData[i][0], base + this.barWidth / 2]); |
| 547 |
points.push([gridData[i][0], base - this.barWidth / 2]); |
| 548 |
points.push([xstart, base - this.barWidth / 2]); |
| 549 |
points.push([xstart, base + this.barWidth / 2]); |
| 550 |
} |
| 551 |
|
| 552 |
this._barPoints.push(points); |
| 553 |
|
| 554 |
|
| 555 |
if (shadow && !this._stack) { |
| 556 |
var sopts = $.extend(true, {}, opts); |
| 557 |
delete sopts.fillStyle; |
| 558 |
this.renderer.shadowRenderer.draw(ctx, points, sopts); |
| 559 |
} |
| 560 |
var clr = opts.fillStyle || this.color; |
| 561 |
this._dataColors.push(clr); |
| 562 |
this.renderer.shapeRenderer.draw(ctx, points, opts); |
| 563 |
} |
| 564 |
} |
| 565 |
} |
| 566 |
|
| 567 |
if (this.highlightColors.length == 0) { |
| 568 |
this.highlightColors = $.jqplot.computeHighlightColors(this._dataColors); |
| 569 |
} |
| 570 |
|
| 571 |
else if (typeof(this.highlightColors) == 'string') { |
| 572 |
var temp = this.highlightColors; |
| 573 |
this.highlightColors = []; |
| 574 |
for (var i=0; i<this._dataColors.length; i++) { |
| 575 |
this.highlightColors.push(temp); |
| 576 |
} |
| 577 |
} |
| 578 |
|
| 579 |
}; |
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
$.jqplot.BarRenderer.prototype.drawShadow = function(ctx, gridData, options, plot) { |
| 584 |
var i; |
| 585 |
var opts = (options != undefined) ? options : {}; |
| 586 |
var shadow = (opts.shadow != undefined) ? opts.shadow : this.shadow; |
| 587 |
var showLine = (opts.showLine != undefined) ? opts.showLine : this.showLine; |
| 588 |
var fill = (opts.fill != undefined) ? opts.fill : this.fill; |
| 589 |
var xaxis = this.xaxis; |
| 590 |
var yaxis = this.yaxis; |
| 591 |
var xp = this._xaxis.series_u2p; |
| 592 |
var yp = this._yaxis.series_u2p; |
| 593 |
var pointx, points, pointy, nvals, nseries, pos; |
| 594 |
|
| 595 |
if (this._stack && this.shadow) { |
| 596 |
if (this.barWidth == null) { |
| 597 |
this.renderer.setBarWidth.call(this); |
| 598 |
} |
| 599 |
|
| 600 |
var temp = this._plotSeriesInfo = this.renderer.calcSeriesNumbers.call(this); |
| 601 |
nvals = temp[0]; |
| 602 |
nseries = temp[1]; |
| 603 |
pos = temp[2]; |
| 604 |
|
| 605 |
if (this._stack) { |
| 606 |
this._barNudge = 0; |
| 607 |
} |
| 608 |
else { |
| 609 |
this._barNudge = (-Math.abs(nseries/2 - 0.5) + pos) * (this.barWidth + this.barPadding); |
| 610 |
} |
| 611 |
if (showLine) { |
| 612 |
|
| 613 |
if (this.barDirection == 'vertical') { |
| 614 |
for (var i=0; i<gridData.length; i++) { |
| 615 |
if (this.data[i][1] == null) { |
| 616 |
continue; |
| 617 |
} |
| 618 |
points = []; |
| 619 |
var base = gridData[i][0] + this._barNudge; |
| 620 |
var ystart; |
| 621 |
|
| 622 |
if (this._stack && this._prevGridData.length) { |
| 623 |
ystart = getStart(this.index, i, this._plotData[i][1], plot, 'y'); |
| 624 |
} |
| 625 |
else { |
| 626 |
if (this.fillToZero) { |
| 627 |
ystart = this._yaxis.series_u2p(0); |
| 628 |
} |
| 629 |
else { |
| 630 |
ystart = ctx.canvas.height; |
| 631 |
} |
| 632 |
} |
| 633 |
|
| 634 |
points.push([base-this.barWidth/2, ystart]); |
| 635 |
points.push([base-this.barWidth/2, gridData[i][1]]); |
| 636 |
points.push([base+this.barWidth/2, gridData[i][1]]); |
| 637 |
points.push([base+this.barWidth/2, ystart]); |
| 638 |
this.renderer.shadowRenderer.draw(ctx, points, opts); |
| 639 |
} |
| 640 |
} |
| 641 |
|
| 642 |
else if (this.barDirection == 'horizontal'){ |
| 643 |
for (var i=0; i<gridData.length; i++) { |
| 644 |
if (this.data[i][0] == null) { |
| 645 |
continue; |
| 646 |
} |
| 647 |
points = []; |
| 648 |
var base = gridData[i][1] - this._barNudge; |
| 649 |
var xstart; |
| 650 |
|
| 651 |
if (this._stack && this._prevGridData.length) { |
| 652 |
xstart = getStart(this.index, i, this._plotData[i][0], plot, 'x'); |
| 653 |
} |
| 654 |
else { |
| 655 |
if (this.fillToZero) { |
| 656 |
xstart = this._xaxis.series_u2p(0); |
| 657 |
} |
| 658 |
else { |
| 659 |
xstart = 0; |
| 660 |
} |
| 661 |
} |
| 662 |
|
| 663 |
points.push([xstart, base+this.barWidth/2]); |
| 664 |
points.push([gridData[i][0], base+this.barWidth/2]); |
| 665 |
points.push([gridData[i][0], base-this.barWidth/2]); |
| 666 |
points.push([xstart, base-this.barWidth/2]); |
| 667 |
this.renderer.shadowRenderer.draw(ctx, points, opts); |
| 668 |
} |
| 669 |
} |
| 670 |
} |
| 671 |
|
| 672 |
} |
| 673 |
}; |
| 674 |
|
| 675 |
function postInit(target, data, options) { |
| 676 |
for (var i=0; i<this.series.length; i++) { |
| 677 |
if (this.series[i].renderer.constructor == $.jqplot.BarRenderer) { |
| 678 |
|
| 679 |
if (this.series[i].highlightMouseOver) { |
| 680 |
this.series[i].highlightMouseDown = false; |
| 681 |
} |
| 682 |
} |
| 683 |
} |
| 684 |
} |
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
function postPlotDraw() { |
| 690 |
|
| 691 |
if (this.plugins.barRenderer && this.plugins.barRenderer.highlightCanvas) { |
| 692 |
|
| 693 |
this.plugins.barRenderer.highlightCanvas.resetCanvas(); |
| 694 |
this.plugins.barRenderer.highlightCanvas = null; |
| 695 |
} |
| 696 |
|
| 697 |
this.plugins.barRenderer = {highlightedSeriesIndex:null}; |
| 698 |
this.plugins.barRenderer.highlightCanvas = new $.jqplot.GenericCanvas(); |
| 699 |
|
| 700 |
this.eventCanvas._elem.before(this.plugins.barRenderer.highlightCanvas.createElement(this._gridPadding, 'jqplot-barRenderer-highlight-canvas', this._plotDimensions, this)); |
| 701 |
this.plugins.barRenderer.highlightCanvas.setContext(); |
| 702 |
this.eventCanvas._elem.bind('mouseleave', {plot:this}, function (ev) { unhighlight(ev.data.plot); }); |
| 703 |
} |
| 704 |
|
| 705 |
function highlight (plot, sidx, pidx, points) { |
| 706 |
var s = plot.series[sidx]; |
| 707 |
var canvas = plot.plugins.barRenderer.highlightCanvas; |
| 708 |
canvas._ctx.clearRect(0,0,canvas._ctx.canvas.width, canvas._ctx.canvas.height); |
| 709 |
s._highlightedPoint = pidx; |
| 710 |
plot.plugins.barRenderer.highlightedSeriesIndex = sidx; |
| 711 |
var opts = {fillStyle: s.highlightColors[pidx]}; |
| 712 |
s.renderer.shapeRenderer.draw(canvas._ctx, points, opts); |
| 713 |
canvas = null; |
| 714 |
} |
| 715 |
|
| 716 |
function unhighlight (plot) { |
| 717 |
var canvas = plot.plugins.barRenderer.highlightCanvas; |
| 718 |
canvas._ctx.clearRect(0,0, canvas._ctx.canvas.width, canvas._ctx.canvas.height); |
| 719 |
for (var i=0; i<plot.series.length; i++) { |
| 720 |
plot.series[i]._highlightedPoint = null; |
| 721 |
} |
| 722 |
plot.plugins.barRenderer.highlightedSeriesIndex = null; |
| 723 |
plot.target.trigger('jqplotDataUnhighlight'); |
| 724 |
canvas = null; |
| 725 |
} |
| 726 |
|
| 727 |
|
| 728 |
function handleMove(ev, gridpos, datapos, neighbor, plot) { |
| 729 |
if (neighbor) { |
| 730 |
var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data]; |
| 731 |
var evt1 = jQuery.Event('jqplotDataMouseOver'); |
| 732 |
evt1.pageX = ev.pageX; |
| 733 |
evt1.pageY = ev.pageY; |
| 734 |
plot.target.trigger(evt1, ins); |
| 735 |
if (plot.series[ins[0]].show && plot.series[ins[0]].highlightMouseOver && |
| 736 |
!(ins[0] == plot.plugins.barRenderer.highlightedSeriesIndex && ins[1] == plot.series[ins[0]]._highlightedPoint)) { |
| 737 |
var evt = jQuery.Event('jqplotDataHighlight'); |
| 738 |
evt.which = ev.which; |
| 739 |
evt.pageX = ev.pageX; |
| 740 |
evt.pageY = ev.pageY; |
| 741 |
plot.target.trigger(evt, ins); |
| 742 |
highlight (plot, neighbor.seriesIndex, neighbor.pointIndex, neighbor.points); |
| 743 |
} |
| 744 |
} |
| 745 |
else if (neighbor == null) { |
| 746 |
unhighlight (plot); |
| 747 |
} |
| 748 |
} |
| 749 |
|
| 750 |
function handleMouseDown(ev, gridpos, datapos, neighbor, plot) { |
| 751 |
if (neighbor) { |
| 752 |
var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data]; |
| 753 |
if (plot.series[ins[0]].highlightMouseDown && !(ins[0] == plot.plugins.barRenderer.highlightedSeriesIndex && ins[1] == plot.series[ins[0]]._highlightedPoint)) { |
| 754 |
var evt = jQuery.Event('jqplotDataHighlight'); |
| 755 |
evt.which = ev.which; |
| 756 |
evt.pageX = ev.pageX; |
| 757 |
evt.pageY = ev.pageY; |
| 758 |
plot.target.trigger(evt, ins); |
| 759 |
highlight (plot, neighbor.seriesIndex, neighbor.pointIndex, neighbor.points); |
| 760 |
} |
| 761 |
} |
| 762 |
else if (neighbor == null) { |
| 763 |
unhighlight (plot); |
| 764 |
} |
| 765 |
} |
| 766 |
|
| 767 |
function handleMouseUp(ev, gridpos, datapos, neighbor, plot) { |
| 768 |
var idx = plot.plugins.barRenderer.highlightedSeriesIndex; |
| 769 |
if (idx != null && plot.series[idx].highlightMouseDown) { |
| 770 |
unhighlight(plot); |
| 771 |
} |
| 772 |
} |
| 773 |
|
| 774 |
function handleClick(ev, gridpos, datapos, neighbor, plot) { |
| 775 |
if (neighbor) { |
| 776 |
var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data]; |
| 777 |
var evt = jQuery.Event('jqplotDataClick'); |
| 778 |
evt.which = ev.which; |
| 779 |
evt.pageX = ev.pageX; |
| 780 |
evt.pageY = ev.pageY; |
| 781 |
plot.target.trigger(evt, ins); |
| 782 |
} |
| 783 |
} |
| 784 |
|
| 785 |
function handleRightClick(ev, gridpos, datapos, neighbor, plot) { |
| 786 |
if (neighbor) { |
| 787 |
var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data]; |
| 788 |
var idx = plot.plugins.barRenderer.highlightedSeriesIndex; |
| 789 |
if (idx != null && plot.series[idx].highlightMouseDown) { |
| 790 |
unhighlight(plot); |
| 791 |
} |
| 792 |
var evt = jQuery.Event('jqplotDataRightClick'); |
| 793 |
evt.which = ev.which; |
| 794 |
evt.pageX = ev.pageX; |
| 795 |
evt.pageY = ev.pageY; |
| 796 |
plot.target.trigger(evt, ins); |
| 797 |
} |
| 798 |
} |
| 799 |
|
| 800 |
|
| 801 |
})(jQuery); |