removed jqplot
This commit is contained in:
parent
d11a96a34d
commit
4039c6056b
35 changed files with 0 additions and 6209 deletions
1
frontend/javascripts/jqplot/excanvas.min.js
vendored
1
frontend/javascripts/jqplot/excanvas.min.js
vendored
File diff suppressed because one or more lines are too long
14
frontend/javascripts/jqplot/jquery.jqplot.min.js
vendored
14
frontend/javascripts/jqplot/jquery.jqplot.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -1,404 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2009 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* The author would appreciate an email letting him know of any substantial
|
||||
* use of jqPlot. You can reach the author at: chris dot leonello at gmail
|
||||
* dot com or see http://www.jqplot.com/info.php . This is, of course,
|
||||
* not required.
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* Thanks for using jqPlot!
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
|
||||
// Class: $.jqplot.BarRenderer
|
||||
// A plugin renderer for jqPlot to draw a bar plot.
|
||||
// Draws series as a line.
|
||||
|
||||
$.jqplot.BarRenderer = function(){
|
||||
$.jqplot.LineRenderer.call(this);
|
||||
};
|
||||
|
||||
$.jqplot.BarRenderer.prototype = new $.jqplot.LineRenderer();
|
||||
$.jqplot.BarRenderer.prototype.constructor = $.jqplot.BarRenderer;
|
||||
|
||||
// called with scope of series.
|
||||
$.jqplot.BarRenderer.prototype.init = function(options) {
|
||||
// Group: Properties
|
||||
//
|
||||
// prop: barPadding
|
||||
// Number of pixels between adjacent bars at the same axis value.
|
||||
this.barPadding = 8;
|
||||
// prop: barMargin
|
||||
// Number of pixels between groups of bars at adjacent axis values.
|
||||
this.barMargin = 10;
|
||||
// prop: barDirection
|
||||
// 'vertical' = up and down bars, 'horizontal' = side to side bars
|
||||
this.barDirection = 'vertical';
|
||||
// prop: barWidth
|
||||
// Width of the bar in pixels (auto by devaul). null = calculated automatically.
|
||||
this.barWidth = null;
|
||||
// prop: shadowOffset
|
||||
// offset of the shadow from the slice and offset of
|
||||
// each succesive stroke of the shadow from the last.
|
||||
this.shadowOffset = 2;
|
||||
// prop: shadowDepth
|
||||
// number of strokes to apply to the shadow,
|
||||
// each stroke offset shadowOffset from the last.
|
||||
this.shadowDepth = 5;
|
||||
// prop: shadowAlpha
|
||||
// transparency of the shadow (0 = transparent, 1 = opaque)
|
||||
this.shadowAlpha = 0.08;
|
||||
// prop: waterfall
|
||||
// true to enable waterfall plot.
|
||||
this.waterfall = false;
|
||||
// prop: varyBarColor
|
||||
// true to color each bar separately.
|
||||
this.varyBarColor = false;
|
||||
$.extend(true, this, options);
|
||||
// fill is still needed to properly draw the legend.
|
||||
// bars have to be filled.
|
||||
this.fill = true;
|
||||
|
||||
if (this.waterfall) {
|
||||
this.fillToZero = false;
|
||||
this.disableStack = true;
|
||||
}
|
||||
|
||||
if (this.barDirection == 'vertical' ) {
|
||||
this._primaryAxis = '_xaxis';
|
||||
this._stackAxis = 'y';
|
||||
this.fillAxis = 'y';
|
||||
}
|
||||
else {
|
||||
this._primaryAxis = '_yaxis';
|
||||
this._stackAxis = 'x';
|
||||
this.fillAxis = 'x';
|
||||
}
|
||||
// set the shape renderer options
|
||||
var opts = {lineJoin:'miter', lineCap:'round', fill:true, isarc:false, strokeStyle:this.color, fillStyle:this.color, closePath:this.fill};
|
||||
this.renderer.shapeRenderer.init(opts);
|
||||
// set the shadow renderer options
|
||||
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};
|
||||
this.renderer.shadowRenderer.init(sopts);
|
||||
};
|
||||
|
||||
// called with scope of series
|
||||
function barPreInit(target, data, seriesDefaults, options) {
|
||||
if (this.rendererOptions.barDirection == 'horizontal') {
|
||||
this._stackAxis = 'x';
|
||||
this._primaryAxis = '_yaxis';
|
||||
}
|
||||
if (this.rendererOptions.waterfall == true) {
|
||||
this._data = $.extend(true, [], this.data);
|
||||
var sum = 0;
|
||||
var pos = (!this.rendererOptions.barDirection || this.rendererOptions.barDirection == 'vertical') ? 1 : 0;
|
||||
for(var i=0; i<this.data.length; i++) {
|
||||
sum += this.data[i][pos];
|
||||
if (i>0) {
|
||||
this.data[i][pos] += this.data[i-1][pos];
|
||||
}
|
||||
}
|
||||
this.data[this.data.length] = (pos == 1) ? [this.data.length+1, sum] : [sum, this.data.length+1];
|
||||
this._data[this._data.length] = (pos == 1) ? [this._data.length+1, sum] : [sum, this._data.length+1];
|
||||
}
|
||||
}
|
||||
|
||||
$.jqplot.preSeriesInitHooks.push(barPreInit);
|
||||
|
||||
// needs to be called with scope of series, not renderer.
|
||||
$.jqplot.BarRenderer.prototype.calcSeriesNumbers = function() {
|
||||
var nvals = 0;
|
||||
var nseries = 0;
|
||||
var paxis = this[this._primaryAxis];
|
||||
var s, series, pos;
|
||||
// loop through all series on this axis
|
||||
for (var i=0; i < paxis._series.length; i++) {
|
||||
series = paxis._series[i];
|
||||
if (series === this) {
|
||||
pos = i;
|
||||
}
|
||||
// is the series rendered as a bar?
|
||||
if (series.renderer.constructor == $.jqplot.BarRenderer) {
|
||||
// gridData may not be computed yet, use data length insted
|
||||
nvals += series.data.length;
|
||||
nseries += 1;
|
||||
}
|
||||
}
|
||||
return [nvals, nseries, pos];
|
||||
};
|
||||
|
||||
$.jqplot.BarRenderer.prototype.setBarWidth = function() {
|
||||
// need to know how many data values we have on the approprate axis and figure it out.
|
||||
var i;
|
||||
var nvals = 0;
|
||||
var nseries = 0;
|
||||
var paxis = this[this._primaryAxis];
|
||||
var s, series, pos;
|
||||
var temp = this.renderer.calcSeriesNumbers.call(this);
|
||||
nvals = temp[0];
|
||||
nseries = temp[1];
|
||||
var nticks = paxis.numberTicks;
|
||||
var nbins = (nticks-1)/2;
|
||||
// so, now we have total number of axis values.
|
||||
if (paxis.name == 'xaxis' || paxis.name == 'x2axis') {
|
||||
if (this._stack) {
|
||||
this.barWidth = (paxis._offsets.max - paxis._offsets.min) / nvals * nseries - this.barMargin;
|
||||
}
|
||||
else {
|
||||
this.barWidth = ((paxis._offsets.max - paxis._offsets.min)/nbins - this.barPadding * (nseries-1) - this.barMargin*2)/nseries;
|
||||
// this.barWidth = (paxis._offsets.max - paxis._offsets.min) / nvals - this.barPadding - this.barMargin/nseries;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (this._stack) {
|
||||
this.barWidth = (paxis._offsets.min - paxis._offsets.max) / nvals * nseries - this.barMargin;
|
||||
}
|
||||
else {
|
||||
this.barWidth = ((paxis._offsets.min - paxis._offsets.max)/nbins - this.barPadding * (nseries-1) - this.barMargin*2)/nseries;
|
||||
// this.barWidth = (paxis._offsets.min - paxis._offsets.max) / nvals - this.barPadding - this.barMargin/nseries;
|
||||
}
|
||||
}
|
||||
return [nvals, nseries];
|
||||
};
|
||||
|
||||
$.jqplot.BarRenderer.prototype.draw = function(ctx, gridData, options) {
|
||||
var i;
|
||||
var opts = (options != undefined) ? options : {};
|
||||
var shadow = (opts.shadow != undefined) ? opts.shadow : this.shadow;
|
||||
var showLine = (opts.showLine != undefined) ? opts.showLine : this.showLine;
|
||||
var fill = (opts.fill != undefined) ? opts.fill : this.fill;
|
||||
var xaxis = this.xaxis;
|
||||
var yaxis = this.yaxis;
|
||||
var xp = this._xaxis.series_u2p;
|
||||
var yp = this._yaxis.series_u2p;
|
||||
var pointx, pointy, nvals, nseries, pos;
|
||||
|
||||
if (this.barWidth == null) {
|
||||
this.renderer.setBarWidth.call(this);
|
||||
}
|
||||
|
||||
var temp = this.renderer.calcSeriesNumbers.call(this);
|
||||
nvals = temp[0];
|
||||
nseries = temp[1];
|
||||
pos = temp[2];
|
||||
|
||||
if (this._stack) {
|
||||
this._barNudge = 0;
|
||||
}
|
||||
else {
|
||||
this._barNudge = (-Math.abs(nseries/2 - 0.5) + pos) * (this.barWidth + this.barPadding);
|
||||
}
|
||||
if (showLine) {
|
||||
var negativeColors = new $.jqplot.ColorGenerator(this.negativeSeriesColors);
|
||||
var positiveColors = new $.jqplot.ColorGenerator(this.seriesColors);
|
||||
var negativeColor = negativeColors.get(this.index);
|
||||
if (! this.useNegativeColors) {
|
||||
negativeColor = opts.fillStyle;
|
||||
}
|
||||
var positiveColor = opts.fillStyle;
|
||||
|
||||
if (this.barDirection == 'vertical') {
|
||||
for (var i=0; i<gridData.length; i++) {
|
||||
points = [];
|
||||
var base = gridData[i][0] + this._barNudge;
|
||||
var ystart;
|
||||
|
||||
// stacked
|
||||
if (this._stack && this._prevGridData.length) {
|
||||
ystart = this._prevGridData[i][1];
|
||||
}
|
||||
// not stacked and first series in stack
|
||||
else {
|
||||
if (this.fillToZero) {
|
||||
ystart = this._yaxis.series_u2p(0);
|
||||
}
|
||||
else if (this.waterfall && i > 0 && i < this.gridData.length-1) {
|
||||
ystart = this.gridData[i-1][1];
|
||||
}
|
||||
else {
|
||||
ystart = ctx.canvas.height;
|
||||
}
|
||||
}
|
||||
if ((this.fillToZero && this._plotData[i][1] < 0) || (this.waterfall && this._data[i][1] < 0)) {
|
||||
if (this.varyBarColor) {
|
||||
if (this.useNegativeColors) {
|
||||
opts.fillStyle = negativeColors.next();
|
||||
}
|
||||
else {
|
||||
opts.fillStyle = positiveColors.next();
|
||||
}
|
||||
}
|
||||
else {
|
||||
opts.fillStyle = negativeColor;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (this.varyBarColor) {
|
||||
opts.fillStyle = positiveColors.next();
|
||||
}
|
||||
else {
|
||||
opts.fillStyle = positiveColor;
|
||||
}
|
||||
}
|
||||
|
||||
points.push([base-this.barWidth/2, ystart]);
|
||||
points.push([base-this.barWidth/2, gridData[i][1]]);
|
||||
points.push([base+this.barWidth/2, gridData[i][1]]);
|
||||
points.push([base+this.barWidth/2, ystart]);
|
||||
// now draw the shadows if not stacked.
|
||||
// for stacked plots, they are predrawn by drawShadow
|
||||
if (shadow && !this._stack) {
|
||||
this.renderer.shadowRenderer.draw(ctx, points, opts);
|
||||
}
|
||||
this.renderer.shapeRenderer.draw(ctx, points, opts);
|
||||
}
|
||||
}
|
||||
|
||||
else if (this.barDirection == 'horizontal'){
|
||||
for (var i=0; i<gridData.length; i++) {
|
||||
points = [];
|
||||
var base = gridData[i][1] - this._barNudge;
|
||||
var xstart;
|
||||
|
||||
if (this._stack && this._prevGridData.length) {
|
||||
xstart = this._prevGridData[i][0];
|
||||
}
|
||||
// not stacked and first series in stack
|
||||
else {
|
||||
if (this.fillToZero) {
|
||||
xstart = this._xaxis.series_u2p(0);
|
||||
}
|
||||
else if (this.waterfall && i > 0 && i < this.gridData.length-1) {
|
||||
xstart = this.gridData[i-1][1];
|
||||
}
|
||||
else {
|
||||
xstart = 0;
|
||||
}
|
||||
}
|
||||
if ((this.fillToZero && this._plotData[i][1] < 0) || (this.waterfall && this._data[i][1] < 0)) {
|
||||
if (this.varyBarColor) {
|
||||
if (this.useNegativeColors) {
|
||||
opts.fillStyle = negativeColors.next();
|
||||
}
|
||||
else {
|
||||
opts.fillStyle = positiveColors.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (this.varyBarColor) {
|
||||
opts.fillStyle = positiveColors.next();
|
||||
}
|
||||
else {
|
||||
opts.fillStyle = positiveColor;
|
||||
}
|
||||
}
|
||||
|
||||
points.push([xstart, base+this.barWidth/2]);
|
||||
points.push([gridData[i][0], base+this.barWidth/2]);
|
||||
points.push([gridData[i][0], base-this.barWidth/2]);
|
||||
points.push([xstart, base-this.barWidth/2]);
|
||||
// now draw the shadows if not stacked.
|
||||
// for stacked plots, they are predrawn by drawShadow
|
||||
if (shadow && !this._stack) {
|
||||
this.renderer.shadowRenderer.draw(ctx, points, opts);
|
||||
}
|
||||
this.renderer.shapeRenderer.draw(ctx, points, opts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
// for stacked plots, shadows will be pre drawn by drawShadow.
|
||||
$.jqplot.BarRenderer.prototype.drawShadow = function(ctx, gridData, options) {
|
||||
var i;
|
||||
var opts = (options != undefined) ? options : {};
|
||||
var shadow = (opts.shadow != undefined) ? opts.shadow : this.shadow;
|
||||
var showLine = (opts.showLine != undefined) ? opts.showLine : this.showLine;
|
||||
var fill = (opts.fill != undefined) ? opts.fill : this.fill;
|
||||
var xaxis = this.xaxis;
|
||||
var yaxis = this.yaxis;
|
||||
var xp = this._xaxis.series_u2p;
|
||||
var yp = this._yaxis.series_u2p;
|
||||
var pointx, pointy, nvals, nseries, pos;
|
||||
|
||||
if (this._stack && this.shadow) {
|
||||
if (this.barWidth == null) {
|
||||
this.renderer.setBarWidth.call(this);
|
||||
}
|
||||
|
||||
var temp = this.renderer.calcSeriesNumbers.call(this);
|
||||
nvals = temp[0];
|
||||
nseries = temp[1];
|
||||
pos = temp[2];
|
||||
|
||||
if (this._stack) {
|
||||
this._barNudge = 0;
|
||||
}
|
||||
else {
|
||||
this._barNudge = (-Math.abs(nseries/2 - 0.5) + pos) * (this.barWidth + this.barPadding);
|
||||
}
|
||||
if (showLine) {
|
||||
|
||||
if (this.barDirection == 'vertical') {
|
||||
for (var i=0; i<gridData.length; i++) {
|
||||
points = [];
|
||||
var base = gridData[i][0] + this._barNudge;
|
||||
var ystart;
|
||||
|
||||
if (this._stack && this._prevGridData.length) {
|
||||
ystart = this._prevGridData[i][1];
|
||||
}
|
||||
else {
|
||||
if (this.fillToZero) {
|
||||
ystart = this._yaxis.series_u2p(0);
|
||||
}
|
||||
else {
|
||||
ystart = ctx.canvas.height;
|
||||
}
|
||||
}
|
||||
|
||||
points.push([base-this.barWidth/2, ystart]);
|
||||
points.push([base-this.barWidth/2, gridData[i][1]]);
|
||||
points.push([base+this.barWidth/2, gridData[i][1]]);
|
||||
points.push([base+this.barWidth/2, ystart]);
|
||||
this.renderer.shadowRenderer.draw(ctx, points, opts);
|
||||
}
|
||||
}
|
||||
|
||||
else if (this.barDirection == 'horizontal'){
|
||||
for (var i=0; i<gridData.length; i++) {
|
||||
points = [];
|
||||
var base = gridData[i][1] - this._barNudge;
|
||||
var xstart;
|
||||
|
||||
if (this._stack && this._prevGridData.length) {
|
||||
xstart = this._prevGridData[i][0];
|
||||
}
|
||||
else {
|
||||
xstart = 0;
|
||||
}
|
||||
|
||||
points.push([xstart, base+this.barWidth/2]);
|
||||
points.push([gridData[i][0], base+this.barWidth/2]);
|
||||
points.push([gridData[i][0], base-this.barWidth/2]);
|
||||
points.push([xstart, base-this.barWidth/2]);
|
||||
this.renderer.shadowRenderer.draw(ctx, points, opts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
})(jQuery);
|
File diff suppressed because one or more lines are too long
|
@ -1,200 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2009 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* The author would appreciate an email letting him know of any substantial
|
||||
* use of jqPlot. You can reach the author at: chris dot leonello at gmail
|
||||
* dot com or see http://www.jqplot.com/info.php . This is, of course,
|
||||
* not required.
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* Thanks for using jqPlot!
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
/**
|
||||
* Class: $.jqplot.CanvasAxisLabelRenderer
|
||||
* Renderer to draw axis labels with a canvas element to support advanced
|
||||
* featrues such as rotated text. This renderer uses a separate rendering engine
|
||||
* to draw the text on the canvas. Two modes of rendering the text are available.
|
||||
* If the browser has native font support for canvas fonts (currently Mozila 3.5
|
||||
* and Safari 4), you can enable text rendering with the canvas fillText method.
|
||||
* You do so by setting the "enableFontSupport" option to true.
|
||||
*
|
||||
* Browsers lacking native font support will have the text drawn on the canvas
|
||||
* using the Hershey font metrics. Even if the "enableFontSupport" option is true
|
||||
* non-supporting browsers will still render with the Hershey font.
|
||||
*
|
||||
*/
|
||||
$.jqplot.CanvasAxisLabelRenderer = function(options) {
|
||||
// Group: Properties
|
||||
|
||||
// prop: angle
|
||||
// angle of text, measured clockwise from x axis.
|
||||
this.angle = 0;
|
||||
// name of the axis associated with this tick
|
||||
this.axis;
|
||||
// prop: show
|
||||
// wether or not to show the tick (mark and label).
|
||||
this.show = true;
|
||||
// prop: showLabel
|
||||
// wether or not to show the label.
|
||||
this.showLabel = true;
|
||||
// prop: label
|
||||
// label for the axis.
|
||||
this.label = '';
|
||||
// prop: fontFamily
|
||||
// CSS spec for the font-family css attribute.
|
||||
// Applies only to browsers supporting native font rendering in the
|
||||
// canvas tag. Currently Mozilla 3.5 and Safari 4.
|
||||
this.fontFamily = '"Trebuchet MS", Arial, Helvetica, sans-serif';
|
||||
// prop: fontSize
|
||||
// CSS spec for font size.
|
||||
this.fontSize = '11pt';
|
||||
// prop: fontWeight
|
||||
// CSS spec for fontWeight: normal, bold, bolder, lighter or a number 100 - 900
|
||||
this.fontWeight = 'normal';
|
||||
// prop: fontStretch
|
||||
// Multiplier to condense or expand font width.
|
||||
// Applies only to browsers which don't support canvas native font rendering.
|
||||
this.fontStretch = 1.0;
|
||||
// prop: textColor
|
||||
// css spec for the color attribute.
|
||||
this.textColor = '#666666';
|
||||
// prop: enableFontSupport
|
||||
// true to turn on native canvas font support in Mozilla 3.5+ and Safari 4+.
|
||||
// If true, label will be drawn with canvas tag native support for fonts.
|
||||
// If false, label will be drawn with Hershey font metrics.
|
||||
this.enableFontSupport = false;
|
||||
// prop: pt2px
|
||||
// Point to pixel scaling factor, used for computing height of bounding box
|
||||
// around a label. The labels text renderer has a default setting of 1.4, which
|
||||
// should be suitable for most fonts. Leave as null to use default. If tops of
|
||||
// letters appear clipped, increase this. If bounding box seems too big, decrease.
|
||||
// This is an issue only with the native font renderering capabilities of Mozilla
|
||||
// 3.5 and Safari 4 since they do not provide a method to determine the font height.
|
||||
this.pt2px = null;
|
||||
|
||||
this._elem;
|
||||
this._ctx;
|
||||
this._plotWidth;
|
||||
this._plotHeight;
|
||||
this._plotDimensions = {height:null, width:null};
|
||||
|
||||
$.extend(true, this, options);
|
||||
|
||||
if (options.angle == null && this.axis != 'xaxis' && this.axis != 'x2axis') {
|
||||
this.angle = -90;
|
||||
}
|
||||
|
||||
var ropts = {fontSize:this.fontSize, fontWeight:this.fontWeight, fontStretch:this.fontStretch, fillStyle:this.textColor, angle:this.getAngleRad(), fontFamily:this.fontFamily};
|
||||
if (this.pt2px) {
|
||||
ropts.pt2px = this.pt2px;
|
||||
}
|
||||
|
||||
if (this.enableFontSupport) {
|
||||
if ($.browser.safari) {
|
||||
var p = $.browser.version.split('.');
|
||||
for (var i=0; i<p.length; i++) { p[i] = Number(p[i]); }
|
||||
if (p[0] > 528 || (p[0] == 528 && p[1] >= 16)) {
|
||||
this._textRenderer = new $.jqplot.CanvasFontRenderer(ropts);
|
||||
}
|
||||
}
|
||||
else if ($.browser.mozilla) {
|
||||
var p = $.browser.version.split(".");
|
||||
if (p[0] > 1 || (p[0] == 1 && p[1] >= 9 && p[2] > 0) ) {
|
||||
this._textRenderer = new $.jqplot.CanvasFontRenderer(ropts);
|
||||
}
|
||||
else {
|
||||
this._textRenderer = new $.jqplot.CanvasTextRenderer(ropts);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: test and enable this
|
||||
// else if ($.browser.msie) {
|
||||
// this._textRenderer = new $.jqplot.CanvasFontRenderer(ropts);
|
||||
// }
|
||||
|
||||
else {
|
||||
this._textRenderer = new $.jqplot.CanvasTextRenderer(ropts);
|
||||
}
|
||||
}
|
||||
else {
|
||||
this._textRenderer = new $.jqplot.CanvasTextRenderer(ropts);
|
||||
}
|
||||
};
|
||||
|
||||
$.jqplot.CanvasAxisLabelRenderer.prototype.init = function(options) {
|
||||
$.extend(true, this, options);
|
||||
this._textRenderer.init({fontSize:this.fontSize, fontWeight:this.fontWeight, fontStretch:this.fontStretch, fillStyle:this.textColor, angle:this.getAngleRad(), fontFamily:this.fontFamily});
|
||||
};
|
||||
|
||||
// return width along the x axis
|
||||
// will check first to see if an element exists.
|
||||
// if not, will return the computed text box width.
|
||||
$.jqplot.CanvasAxisLabelRenderer.prototype.getWidth = function(ctx) {
|
||||
if (this._elem) {
|
||||
return this._elem.outerWidth(true);
|
||||
}
|
||||
else {
|
||||
var tr = this._textRenderer;
|
||||
var l = tr.getWidth(ctx);
|
||||
var h = tr.getHeight(ctx);
|
||||
var w = Math.abs(Math.sin(tr.angle)*h) + Math.abs(Math.cos(tr.angle)*l);
|
||||
return w;
|
||||
}
|
||||
};
|
||||
|
||||
// return height along the y axis.
|
||||
$.jqplot.CanvasAxisLabelRenderer.prototype.getHeight = function(ctx) {
|
||||
if (this._elem) {
|
||||
return this._elem.outerHeight(true);
|
||||
}
|
||||
else {
|
||||
var tr = this._textRenderer;
|
||||
var l = tr.getWidth(ctx);
|
||||
var h = tr.getHeight(ctx);
|
||||
var w = Math.abs(Math.cos(tr.angle)*h) + Math.abs(Math.sin(tr.angle)*l);
|
||||
return w;
|
||||
}
|
||||
};
|
||||
|
||||
$.jqplot.CanvasAxisLabelRenderer.prototype.getAngleRad = function() {
|
||||
var a = this.angle * Math.PI/180;
|
||||
return a;
|
||||
};
|
||||
|
||||
$.jqplot.CanvasAxisLabelRenderer.prototype.draw = function(ctx) {
|
||||
// create a canvas here, but can't draw on it untill it is appended
|
||||
// to dom for IE compatability.
|
||||
var domelem = document.createElement('canvas');
|
||||
this._textRenderer.setText(this.label, ctx);
|
||||
var w = this.getWidth(ctx);
|
||||
var h = this.getHeight(ctx);
|
||||
domelem.width = w;
|
||||
domelem.height = h;
|
||||
domelem.style.width = w;
|
||||
domelem.style.height = h;
|
||||
// domelem.style.textAlign = 'center';
|
||||
domelem.style.position = 'absolute';
|
||||
this._domelem = domelem;
|
||||
this._elem = $(domelem);
|
||||
this._elem.addClass('jqplot-'+this.axis+'-label');
|
||||
|
||||
return this._elem;
|
||||
};
|
||||
|
||||
$.jqplot.CanvasAxisLabelRenderer.prototype.pack = function() {
|
||||
if ($.browser.msie) {
|
||||
window.G_vmlCanvasManager.init_(document);
|
||||
this._domelem = window.G_vmlCanvasManager.initElement(this._domelem);
|
||||
}
|
||||
var ctx = this._elem.get(0).getContext("2d");
|
||||
this._textRenderer.draw(ctx, this.label);
|
||||
};
|
||||
|
||||
})(jQuery);
|
|
@ -1,14 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2009 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris dot leonello at gmail dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*/
|
||||
(function(a){a.jqplot.CanvasAxisLabelRenderer=function(b){this.angle=0;this.axis;this.show=true;this.showLabel=true;this.label="";this.fontFamily='"Trebuchet MS", Arial, Helvetica, sans-serif';this.fontSize="11pt";this.fontWeight="normal";this.fontStretch=1;this.textColor="#666666";this.enableFontSupport=false;this.pt2px=null;this._elem;this._ctx;this._plotWidth;this._plotHeight;this._plotDimensions={height:null,width:null};a.extend(true,this,b);if(b.angle==null&&this.axis!="xaxis"&&this.axis!="x2axis"){this.angle=-90}var e={fontSize:this.fontSize,fontWeight:this.fontWeight,fontStretch:this.fontStretch,fillStyle:this.textColor,angle:this.getAngleRad(),fontFamily:this.fontFamily};if(this.pt2px){e.pt2px=this.pt2px}if(this.enableFontSupport){if(a.browser.safari){var d=a.browser.version.split(".");for(var c=0;c<d.length;c++){d[c]=Number(d[c])}if(d[0]>528||(d[0]==528&&d[1]>=16)){this._textRenderer=new a.jqplot.CanvasFontRenderer(e)}}else{if(a.browser.mozilla){var d=a.browser.version.split(".");if(d[0]>1||(d[0]==1&&d[1]>=9&&d[2]>0)){this._textRenderer=new a.jqplot.CanvasFontRenderer(e)}else{this._textRenderer=new a.jqplot.CanvasTextRenderer(e)}}else{this._textRenderer=new a.jqplot.CanvasTextRenderer(e)}}}else{this._textRenderer=new a.jqplot.CanvasTextRenderer(e)}};a.jqplot.CanvasAxisLabelRenderer.prototype.init=function(b){a.extend(true,this,b);this._textRenderer.init({fontSize:this.fontSize,fontWeight:this.fontWeight,fontStretch:this.fontStretch,fillStyle:this.textColor,angle:this.getAngleRad(),fontFamily:this.fontFamily})};a.jqplot.CanvasAxisLabelRenderer.prototype.getWidth=function(d){if(this._elem){return this._elem.outerWidth(true)}else{var f=this._textRenderer;var c=f.getWidth(d);var e=f.getHeight(d);var b=Math.abs(Math.sin(f.angle)*e)+Math.abs(Math.cos(f.angle)*c);return b}};a.jqplot.CanvasAxisLabelRenderer.prototype.getHeight=function(d){if(this._elem){return this._elem.outerHeight(true)}else{var f=this._textRenderer;var c=f.getWidth(d);var e=f.getHeight(d);var b=Math.abs(Math.cos(f.angle)*e)+Math.abs(Math.sin(f.angle)*c);return b}};a.jqplot.CanvasAxisLabelRenderer.prototype.getAngleRad=function(){var b=this.angle*Math.PI/180;return b};a.jqplot.CanvasAxisLabelRenderer.prototype.draw=function(c){var e=document.createElement("canvas");this._textRenderer.setText(this.label,c);var b=this.getWidth(c);var d=this.getHeight(c);e.width=b;e.height=d;e.style.width=b;e.style.height=d;e.style.position="absolute";this._domelem=e;this._elem=a(e);this._elem.addClass("jqplot-"+this.axis+"-label");return this._elem};a.jqplot.CanvasAxisLabelRenderer.prototype.pack=function(){if(a.browser.msie){window.G_vmlCanvasManager.init_(document);this._domelem=window.G_vmlCanvasManager.initElement(this._domelem)}var b=this._elem.get(0).getContext("2d");this._textRenderer.draw(b,this.label)}})(jQuery);
|
|
@ -1,232 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2009 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* The author would appreciate an email letting him know of any substantial
|
||||
* use of jqPlot. You can reach the author at: chris dot leonello at gmail
|
||||
* dot com or see http://www.jqplot.com/info.php . This is, of course,
|
||||
* not required.
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* Thanks for using jqPlot!
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
/**
|
||||
* Class: $.jqplot.CanvasAxisTickRenderer
|
||||
* Renderer to draw axis ticks with a canvas element to support advanced
|
||||
* featrues such as rotated text. This renderer uses a separate rendering engine
|
||||
* to draw the text on the canvas. Two modes of rendering the text are available.
|
||||
* If the browser has native font support for canvas fonts (currently Mozila 3.5
|
||||
* and Safari 4), you can enable text rendering with the canvas fillText method.
|
||||
* You do so by setting the "enableFontSupport" option to true.
|
||||
*
|
||||
* Browsers lacking native font support will have the text drawn on the canvas
|
||||
* using the Hershey font metrics. Even if the "enableFontSupport" option is true
|
||||
* non-supporting browsers will still render with the Hershey font.
|
||||
*/
|
||||
$.jqplot.CanvasAxisTickRenderer = function(options) {
|
||||
// Group: Properties
|
||||
|
||||
// prop: mark
|
||||
// tick mark on the axis. One of 'inside', 'outside', 'cross', '' or null.
|
||||
this.mark = 'outside';
|
||||
// prop: showMark
|
||||
// wether or not to show the mark on the axis.
|
||||
this.showMark = true;
|
||||
// prop: showGridline
|
||||
// wether or not to draw the gridline on the grid at this tick.
|
||||
this.showGridline = true;
|
||||
// prop: isMinorTick
|
||||
// if this is a minor tick.
|
||||
this.isMinorTick = false;
|
||||
// prop: angle
|
||||
// angle of text, measured clockwise from x axis.
|
||||
this.angle = 0;
|
||||
// prop: markSize
|
||||
// Length of the tick marks in pixels. For 'cross' style, length
|
||||
// will be stoked above and below axis, so total length will be twice this.
|
||||
this.markSize = 4;
|
||||
// prop: show
|
||||
// wether or not to show the tick (mark and label).
|
||||
this.show = true;
|
||||
// prop: showLabel
|
||||
// wether or not to show the label.
|
||||
this.showLabel = true;
|
||||
// prop: labelPosition
|
||||
// 'auto', 'start', 'middle' or 'end'.
|
||||
// Whether tick label should be positioned so the start, middle, or end
|
||||
// of the tick mark.
|
||||
this.labelPosition = 'auto';
|
||||
this.label = '';
|
||||
this.value = null;
|
||||
this._styles = {};
|
||||
// prop: formatter
|
||||
// A class of a formatter for the tick text.
|
||||
// The default $.jqplot.DefaultTickFormatter uses sprintf.
|
||||
this.formatter = $.jqplot.DefaultTickFormatter;
|
||||
// prop: formatString
|
||||
// string passed to the formatter.
|
||||
this.formatString = '';
|
||||
// prop: fontFamily
|
||||
// css spec for the font-family css attribute.
|
||||
this.fontFamily = '"Trebuchet MS", Arial, Helvetica, sans-serif';
|
||||
// prop: fontSize
|
||||
// CSS spec for font size.
|
||||
this.fontSize = '11px';
|
||||
// prop: fontWeight
|
||||
// CSS spec for fontWeight
|
||||
this.fontWeight = 'normal';
|
||||
// prop: fontStretch
|
||||
// Multiplier to condense or expand font width.
|
||||
// Applies only to browsers which don't support canvas native font rendering.
|
||||
this.fontStretch = 1.0;
|
||||
// prop: textColor
|
||||
// css spec for the color attribute.
|
||||
this.textColor = '#666666';
|
||||
// prop: enableFontSupport
|
||||
// true to turn on native canvas font support in Mozilla 3.5+ and Safari 4+.
|
||||
// If true, tick label will be drawn with canvas tag native support for fonts.
|
||||
// If false, tick label will be drawn with Hershey font metrics.
|
||||
this.enableFontSupport = false;
|
||||
// prop: pt2px
|
||||
// Point to pixel scaling factor, used for computing height of bounding box
|
||||
// around a label. The labels text renderer has a default setting of 1.4, which
|
||||
// should be suitable for most fonts. Leave as null to use default. If tops of
|
||||
// letters appear clipped, increase this. If bounding box seems too big, decrease.
|
||||
// This is an issue only with the native font renderering capabilities of Mozilla
|
||||
// 3.5 and Safari 4 since they do not provide a method to determine the font height.
|
||||
this.pt2px = null;
|
||||
|
||||
this._elem;
|
||||
this._ctx;
|
||||
this._plotWidth;
|
||||
this._plotHeight;
|
||||
this._plotDimensions = {height:null, width:null};
|
||||
|
||||
$.extend(true, this, options);
|
||||
|
||||
var ropts = {fontSize:this.fontSize, fontWeight:this.fontWeight, fontStretch:this.fontStretch, fillStyle:this.textColor, angle:this.getAngleRad(), fontFamily:this.fontFamily};
|
||||
if (this.pt2px) {
|
||||
ropts.pt2px = this.pt2px;
|
||||
}
|
||||
|
||||
if (this.enableFontSupport) {
|
||||
if ($.browser.safari) {
|
||||
var p = $.browser.version.split('.');
|
||||
for (var i=0; i<p.length; i++) { p[i] = Number(p[i]); }
|
||||
if (p[0] > 528 || (p[0] == 528 && p[1] >= 16)) {
|
||||
this._textRenderer = new $.jqplot.CanvasFontRenderer(ropts);
|
||||
}
|
||||
}
|
||||
else if ($.browser.mozilla) {
|
||||
var p = $.browser.version.split(".");
|
||||
if (p[0] > 1 || (p[0] == 1 && p[1] >= 9 && p[2] > 0) ) {
|
||||
this._textRenderer = new $.jqplot.CanvasFontRenderer(ropts);
|
||||
}
|
||||
else {
|
||||
this._textRenderer = new $.jqplot.CanvasTextRenderer(ropts);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: test and enable this
|
||||
// else if ($.browser.msie) {
|
||||
// this._textRenderer = new $.jqplot.CanvasFontRenderer(ropts);
|
||||
// }
|
||||
|
||||
else {
|
||||
this._textRenderer = new $.jqplot.CanvasTextRenderer(ropts);
|
||||
}
|
||||
}
|
||||
else {
|
||||
this._textRenderer = new $.jqplot.CanvasTextRenderer(ropts);
|
||||
}
|
||||
};
|
||||
|
||||
$.jqplot.CanvasAxisTickRenderer.prototype.init = function(options) {
|
||||
$.extend(true, this, options);
|
||||
this._textRenderer.init({fontSize:this.fontSize, fontWeight:this.fontWeight, fontStretch:this.fontStretch, fillStyle:this.textColor, angle:this.getAngleRad(), fontFamily:this.fontFamily});
|
||||
};
|
||||
|
||||
// return width along the x axis
|
||||
// will check first to see if an element exists.
|
||||
// if not, will return the computed text box width.
|
||||
$.jqplot.CanvasAxisTickRenderer.prototype.getWidth = function(ctx) {
|
||||
if (this._elem) {
|
||||
return this._elem.outerWidth(true);
|
||||
}
|
||||
else {
|
||||
var tr = this._textRenderer;
|
||||
var l = tr.getWidth(ctx);
|
||||
var h = tr.getHeight(ctx);
|
||||
var w = Math.abs(Math.sin(tr.angle)*h) + Math.abs(Math.cos(tr.angle)*l);
|
||||
return w;
|
||||
}
|
||||
};
|
||||
|
||||
// return height along the y axis.
|
||||
$.jqplot.CanvasAxisTickRenderer.prototype.getHeight = function(ctx) {
|
||||
if (this._elem) {
|
||||
return this._elem.outerHeight(true);
|
||||
}
|
||||
else {
|
||||
var tr = this._textRenderer;
|
||||
var l = tr.getWidth(ctx);
|
||||
var h = tr.getHeight(ctx);
|
||||
var w = Math.abs(Math.cos(tr.angle)*h) + Math.abs(Math.sin(tr.angle)*l);
|
||||
return w;
|
||||
}
|
||||
};
|
||||
|
||||
$.jqplot.CanvasAxisTickRenderer.prototype.getAngleRad = function() {
|
||||
var a = this.angle * Math.PI/180;
|
||||
return a;
|
||||
};
|
||||
|
||||
|
||||
$.jqplot.CanvasAxisTickRenderer.prototype.setTick = function(value, axisName, isMinor) {
|
||||
this.value = value;
|
||||
if (isMinor) {
|
||||
this.isMinorTick = true;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
$.jqplot.CanvasAxisTickRenderer.prototype.draw = function(ctx) {
|
||||
if (!this.label) {
|
||||
this.label = this.formatter(this.formatString, this.value);
|
||||
}
|
||||
// create a canvas here, but can't draw on it untill it is appended
|
||||
// to dom for IE compatability.
|
||||
var domelem = document.createElement('canvas');
|
||||
this._textRenderer.setText(this.label, ctx);
|
||||
var w = this.getWidth(ctx);
|
||||
var h = this.getHeight(ctx);
|
||||
domelem.width = w;
|
||||
domelem.height = h;
|
||||
domelem.style.width = w;
|
||||
domelem.style.height = h;
|
||||
domelem.style.textAlign = 'left';
|
||||
domelem.style.position = 'absolute';
|
||||
this._domelem = domelem;
|
||||
this._elem = $(domelem);
|
||||
this._elem.css(this._styles);
|
||||
this._elem.addClass('jqplot-'+this.axis+'-tick');
|
||||
|
||||
return this._elem;
|
||||
};
|
||||
|
||||
$.jqplot.CanvasAxisTickRenderer.prototype.pack = function() {
|
||||
if ($.browser.msie) {
|
||||
window.G_vmlCanvasManager.init_(document);
|
||||
this._domelem = window.G_vmlCanvasManager.initElement(this._domelem);
|
||||
}
|
||||
var ctx = this._elem.get(0).getContext("2d");
|
||||
this._textRenderer.draw(ctx, this.label);
|
||||
};
|
||||
|
||||
})(jQuery);
|
|
@ -1,14 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2009 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris dot leonello at gmail dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*/
|
||||
(function(a){a.jqplot.CanvasAxisTickRenderer=function(b){this.mark="outside";this.showMark=true;this.showGridline=true;this.isMinorTick=false;this.angle=0;this.markSize=4;this.show=true;this.showLabel=true;this.labelPosition="auto";this.label="";this.value=null;this._styles={};this.formatter=a.jqplot.DefaultTickFormatter;this.formatString="";this.fontFamily='"Trebuchet MS", Arial, Helvetica, sans-serif';this.fontSize="11px";this.fontWeight="normal";this.fontStretch=1;this.textColor="#666666";this.enableFontSupport=false;this.pt2px=null;this._elem;this._ctx;this._plotWidth;this._plotHeight;this._plotDimensions={height:null,width:null};a.extend(true,this,b);var e={fontSize:this.fontSize,fontWeight:this.fontWeight,fontStretch:this.fontStretch,fillStyle:this.textColor,angle:this.getAngleRad(),fontFamily:this.fontFamily};if(this.pt2px){e.pt2px=this.pt2px}if(this.enableFontSupport){if(a.browser.safari){var d=a.browser.version.split(".");for(var c=0;c<d.length;c++){d[c]=Number(d[c])}if(d[0]>528||(d[0]==528&&d[1]>=16)){this._textRenderer=new a.jqplot.CanvasFontRenderer(e)}}else{if(a.browser.mozilla){var d=a.browser.version.split(".");if(d[0]>1||(d[0]==1&&d[1]>=9&&d[2]>0)){this._textRenderer=new a.jqplot.CanvasFontRenderer(e)}else{this._textRenderer=new a.jqplot.CanvasTextRenderer(e)}}else{this._textRenderer=new a.jqplot.CanvasTextRenderer(e)}}}else{this._textRenderer=new a.jqplot.CanvasTextRenderer(e)}};a.jqplot.CanvasAxisTickRenderer.prototype.init=function(b){a.extend(true,this,b);this._textRenderer.init({fontSize:this.fontSize,fontWeight:this.fontWeight,fontStretch:this.fontStretch,fillStyle:this.textColor,angle:this.getAngleRad(),fontFamily:this.fontFamily})};a.jqplot.CanvasAxisTickRenderer.prototype.getWidth=function(d){if(this._elem){return this._elem.outerWidth(true)}else{var f=this._textRenderer;var c=f.getWidth(d);var e=f.getHeight(d);var b=Math.abs(Math.sin(f.angle)*e)+Math.abs(Math.cos(f.angle)*c);return b}};a.jqplot.CanvasAxisTickRenderer.prototype.getHeight=function(d){if(this._elem){return this._elem.outerHeight(true)}else{var f=this._textRenderer;var c=f.getWidth(d);var e=f.getHeight(d);var b=Math.abs(Math.cos(f.angle)*e)+Math.abs(Math.sin(f.angle)*c);return b}};a.jqplot.CanvasAxisTickRenderer.prototype.getAngleRad=function(){var b=this.angle*Math.PI/180;return b};a.jqplot.CanvasAxisTickRenderer.prototype.setTick=function(b,d,c){this.value=b;if(c){this.isMinorTick=true}return this};a.jqplot.CanvasAxisTickRenderer.prototype.draw=function(c){if(!this.label){this.label=this.formatter(this.formatString,this.value)}var e=document.createElement("canvas");this._textRenderer.setText(this.label,c);var b=this.getWidth(c);var d=this.getHeight(c);e.width=b;e.height=d;e.style.width=b;e.style.height=d;e.style.textAlign="left";e.style.position="absolute";this._domelem=e;this._elem=a(e);this._elem.css(this._styles);this._elem.addClass("jqplot-"+this.axis+"-tick");return this._elem};a.jqplot.CanvasAxisTickRenderer.prototype.pack=function(){if(a.browser.msie){window.G_vmlCanvasManager.init_(document);this._domelem=window.G_vmlCanvasManager.initElement(this._domelem)}var b=this._elem.get(0).getContext("2d");this._textRenderer.draw(b,this.label)}})(jQuery);
|
|
@ -1,408 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2009 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* The author would appreciate an email letting him know of any substantial
|
||||
* use of jqPlot. You can reach the author at: chris dot leonello at gmail
|
||||
* dot com or see http://www.jqplot.com/info.php . This is, of course,
|
||||
* not required.
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* Thanks for using jqPlot!
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
// This code is a modified version of the canvastext.js code, copyright below:
|
||||
//
|
||||
// This code is released to the public domain by Jim Studt, 2007.
|
||||
// He may keep some sort of up to date copy at http://www.federated.com/~jim/canvastext/
|
||||
//
|
||||
$.jqplot.CanvasTextRenderer = function(options){
|
||||
this.fontStyle = 'normal'; // normal, italic, oblique [not implemented]
|
||||
this.fontVariant = 'normal'; // normal, small caps [not implemented]
|
||||
this.fontWeight = 'normal'; // normal, bold, bolder, lighter, 100 - 900
|
||||
this.fontSize = '10px';
|
||||
this.fontFamily = 'sans-serif';
|
||||
this.fontStretch = 1.0;
|
||||
this.fillStyle = '#666666';
|
||||
this.angle = 0;
|
||||
this.textAlign = 'start';
|
||||
this.textBaseline = 'alphabetic';
|
||||
this.text;
|
||||
this.width;
|
||||
this.height;
|
||||
this.pt2px = 1.28;
|
||||
|
||||
$.extend(true, this, options);
|
||||
this.normalizedFontSize = this.normalizeFontSize(this.fontSize);
|
||||
this.setHeight();
|
||||
};
|
||||
|
||||
$.jqplot.CanvasTextRenderer.prototype.init = function(options) {
|
||||
$.extend(true, this, options);
|
||||
this.normalizedFontSize = this.normalizeFontSize(this.fontSize);
|
||||
this.setHeight();
|
||||
};
|
||||
|
||||
// convert css spec into point size
|
||||
// returns float
|
||||
$.jqplot.CanvasTextRenderer.prototype.normalizeFontSize = function(sz) {
|
||||
sz = String(sz);
|
||||
n = parseFloat(sz);
|
||||
if (sz.indexOf('px') > -1) {
|
||||
return n/this.pt2px;
|
||||
}
|
||||
else if (sz.indexOf('pt') > -1) {
|
||||
return n;
|
||||
}
|
||||
else if (sz.indexOf('em') > -1) {
|
||||
return n*12;
|
||||
}
|
||||
else if (sz.indexOf('%') > -1) {
|
||||
return n*12/100;
|
||||
}
|
||||
// default to pixels;
|
||||
else {
|
||||
return n/this.pt2px;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
$.jqplot.CanvasTextRenderer.prototype.fontWeight2Float = function(w) {
|
||||
// w = normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
|
||||
// return values adjusted for Hershey font.
|
||||
if (Number(w)) {
|
||||
return w/400;
|
||||
}
|
||||
else {
|
||||
switch (w) {
|
||||
case 'normal':
|
||||
return 1;
|
||||
break;
|
||||
case 'bold':
|
||||
return 1.75;
|
||||
break;
|
||||
case 'bolder':
|
||||
return 2.25;
|
||||
break;
|
||||
case 'lighter':
|
||||
return 0.75;
|
||||
break;
|
||||
default:
|
||||
return 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$.jqplot.CanvasTextRenderer.prototype.getText = function() {
|
||||
return this.text;
|
||||
};
|
||||
|
||||
$.jqplot.CanvasTextRenderer.prototype.setText = function(t, ctx) {
|
||||
this.text = t;
|
||||
this.setWidth(ctx);
|
||||
return this;
|
||||
};
|
||||
|
||||
$.jqplot.CanvasTextRenderer.prototype.getWidth = function(ctx) {
|
||||
return this.width;
|
||||
};
|
||||
|
||||
$.jqplot.CanvasTextRenderer.prototype.setWidth = function(ctx, w) {
|
||||
if (!w) {
|
||||
this.width = this.measure(ctx, this.text);
|
||||
}
|
||||
else {
|
||||
this.width = w;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
// return height in pixels.
|
||||
$.jqplot.CanvasTextRenderer.prototype.getHeight = function(ctx) {
|
||||
return this.height;
|
||||
};
|
||||
|
||||
// w - height in pt
|
||||
// set heigh in px
|
||||
$.jqplot.CanvasTextRenderer.prototype.setHeight = function(w) {
|
||||
if (!w) {
|
||||
//height = this.fontSize /0.75;
|
||||
this.height = this.normalizedFontSize * this.pt2px;
|
||||
}
|
||||
else {
|
||||
this.height = w;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
$.jqplot.CanvasTextRenderer.prototype.letter = function (ch)
|
||||
{
|
||||
return this.letters[ch];
|
||||
};
|
||||
|
||||
$.jqplot.CanvasTextRenderer.prototype.ascent = function()
|
||||
{
|
||||
return this.normalizedFontSize;
|
||||
};
|
||||
|
||||
$.jqplot.CanvasTextRenderer.prototype.descent = function()
|
||||
{
|
||||
return 7.0*this.normalizedFontSize/25.0;
|
||||
};
|
||||
|
||||
$.jqplot.CanvasTextRenderer.prototype.measure = function(ctx, str)
|
||||
{
|
||||
var total = 0;
|
||||
var len = str.length;
|
||||
|
||||
for ( i = 0; i < len; i++) {
|
||||
var c = this.letter(str.charAt(i));
|
||||
if (c) {
|
||||
total += c.width * this.normalizedFontSize / 25.0 * this.fontStretch;
|
||||
}
|
||||
}
|
||||
return total;
|
||||
};
|
||||
|
||||
$.jqplot.CanvasTextRenderer.prototype.draw = function(ctx,str)
|
||||
{
|
||||
var x = 0;
|
||||
// leave room at bottom for descenders.
|
||||
var y = this.height*0.72;
|
||||
var total = 0;
|
||||
var len = str.length;
|
||||
var mag = this.normalizedFontSize / 25.0;
|
||||
|
||||
ctx.save();
|
||||
var tx, ty;
|
||||
|
||||
// 1st quadrant
|
||||
if ((-Math.PI/2 <= this.angle && this.angle <= 0) || (Math.PI*3/2 <= this.angle && this.angle <= Math.PI*2)) {
|
||||
tx = 0;
|
||||
ty = -Math.sin(this.angle) * this.width;
|
||||
}
|
||||
// 4th quadrant
|
||||
else if ((0 < this.angle && this.angle <= Math.PI/2) || (-Math.PI*2 <= this.angle && this.angle <= -Math.PI*3/2)) {
|
||||
tx = Math.sin(this.angle) * this.height;
|
||||
ty = 0;
|
||||
}
|
||||
// 2nd quadrant
|
||||
else if ((-Math.PI < this.angle && this.angle < -Math.PI/2) || (Math.PI <= this.angle && this.angle <= Math.PI*3/2)) {
|
||||
tx = -Math.cos(this.angle) * this.width;
|
||||
ty = -Math.sin(this.angle) * this.width - Math.cos(this.angle) * this.height;
|
||||
}
|
||||
// 3rd quadrant
|
||||
else if ((-Math.PI*3/2 < this.angle && this.angle < Math.PI) || (Math.PI/2 < this.angle && this.angle < Math.PI)) {
|
||||
tx = Math.sin(this.angle) * this.height - Math.cos(this.angle)*this.width;
|
||||
ty = -Math.cos(this.angle) * this.height;
|
||||
}
|
||||
|
||||
ctx.strokeStyle = this.fillStyle;
|
||||
ctx.fillStyle = this.fillStyle;
|
||||
ctx.translate(tx, ty);
|
||||
ctx.rotate(this.angle);
|
||||
ctx.lineCap = "round";
|
||||
// multiplier was 2.0
|
||||
var fact = (this.normalizedFontSize > 30) ? 2.0 : 2 + (30 - this.normalizedFontSize)/20;
|
||||
ctx.lineWidth = fact * mag * this.fontWeight2Float(this.fontWeight);
|
||||
|
||||
for ( var i = 0; i < len; i++) {
|
||||
var c = this.letter( str.charAt(i));
|
||||
if ( !c) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ctx.beginPath();
|
||||
|
||||
var penUp = 1;
|
||||
var needStroke = 0;
|
||||
for ( var j = 0; j < c.points.length; j++) {
|
||||
var a = c.points[j];
|
||||
if ( a[0] == -1 && a[1] == -1) {
|
||||
penUp = 1;
|
||||
continue;
|
||||
}
|
||||
if ( penUp) {
|
||||
ctx.moveTo( x + a[0]*mag*this.fontStretch, y - a[1]*mag);
|
||||
penUp = false;
|
||||
} else {
|
||||
ctx.lineTo( x + a[0]*mag*this.fontStretch, y - a[1]*mag);
|
||||
}
|
||||
}
|
||||
ctx.stroke();
|
||||
x += c.width*mag*this.fontStretch;
|
||||
}
|
||||
ctx.restore();
|
||||
return total;
|
||||
};
|
||||
|
||||
$.jqplot.CanvasTextRenderer.prototype.letters = {
|
||||
' ': { width: 16, points: [] },
|
||||
'!': { width: 10, points: [[5,21],[5,7],[-1,-1],[5,2],[4,1],[5,0],[6,1],[5,2]] },
|
||||
'"': { width: 16, points: [[4,21],[4,14],[-1,-1],[12,21],[12,14]] },
|
||||
'#': { width: 21, points: [[11,25],[4,-7],[-1,-1],[17,25],[10,-7],[-1,-1],[4,12],[18,12],[-1,-1],[3,6],[17,6]] },
|
||||
'$': { width: 20, points: [[8,25],[8,-4],[-1,-1],[12,25],[12,-4],[-1,-1],[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]] },
|
||||
'%': { width: 24, points: [[21,21],[3,0],[-1,-1],[8,21],[10,19],[10,17],[9,15],[7,14],[5,14],[3,16],[3,18],[4,20],[6,21],[8,21],[10,20],[13,19],[16,19],[19,20],[21,21],[-1,-1],[17,7],[15,6],[14,4],[14,2],[16,0],[18,0],[20,1],[21,3],[21,5],[19,7],[17,7]] },
|
||||
'&': { width: 26, points: [[23,12],[23,13],[22,14],[21,14],[20,13],[19,11],[17,6],[15,3],[13,1],[11,0],[7,0],[5,1],[4,2],[3,4],[3,6],[4,8],[5,9],[12,13],[13,14],[14,16],[14,18],[13,20],[11,21],[9,20],[8,18],[8,16],[9,13],[11,10],[16,3],[18,1],[20,0],[22,0],[23,1],[23,2]] },
|
||||
'\'': { width: 10, points: [[5,19],[4,20],[5,21],[6,20],[6,18],[5,16],[4,15]] },
|
||||
'(': { width: 14, points: [[11,25],[9,23],[7,20],[5,16],[4,11],[4,7],[5,2],[7,-2],[9,-5],[11,-7]] },
|
||||
')': { width: 14, points: [[3,25],[5,23],[7,20],[9,16],[10,11],[10,7],[9,2],[7,-2],[5,-5],[3,-7]] },
|
||||
'*': { width: 16, points: [[8,21],[8,9],[-1,-1],[3,18],[13,12],[-1,-1],[13,18],[3,12]] },
|
||||
'+': { width: 26, points: [[13,18],[13,0],[-1,-1],[4,9],[22,9]] },
|
||||
',': { width: 10, points: [[6,1],[5,0],[4,1],[5,2],[6,1],[6,-1],[5,-3],[4,-4]] },
|
||||
'-': { width: 18, points: [[6,9],[12,9]] },
|
||||
'.': { width: 10, points: [[5,2],[4,1],[5,0],[6,1],[5,2]] },
|
||||
'/': { width: 22, points: [[20,25],[2,-7]] },
|
||||
'0': { width: 20, points: [[9,21],[6,20],[4,17],[3,12],[3,9],[4,4],[6,1],[9,0],[11,0],[14,1],[16,4],[17,9],[17,12],[16,17],[14,20],[11,21],[9,21]] },
|
||||
'1': { width: 20, points: [[6,17],[8,18],[11,21],[11,0]] },
|
||||
'2': { width: 20, points: [[4,16],[4,17],[5,19],[6,20],[8,21],[12,21],[14,20],[15,19],[16,17],[16,15],[15,13],[13,10],[3,0],[17,0]] },
|
||||
'3': { width: 20, points: [[5,21],[16,21],[10,13],[13,13],[15,12],[16,11],[17,8],[17,6],[16,3],[14,1],[11,0],[8,0],[5,1],[4,2],[3,4]] },
|
||||
'4': { width: 20, points: [[13,21],[3,7],[18,7],[-1,-1],[13,21],[13,0]] },
|
||||
'5': { width: 20, points: [[15,21],[5,21],[4,12],[5,13],[8,14],[11,14],[14,13],[16,11],[17,8],[17,6],[16,3],[14,1],[11,0],[8,0],[5,1],[4,2],[3,4]] },
|
||||
'6': { width: 20, points: [[16,18],[15,20],[12,21],[10,21],[7,20],[5,17],[4,12],[4,7],[5,3],[7,1],[10,0],[11,0],[14,1],[16,3],[17,6],[17,7],[16,10],[14,12],[11,13],[10,13],[7,12],[5,10],[4,7]] },
|
||||
'7': { width: 20, points: [[17,21],[7,0],[-1,-1],[3,21],[17,21]] },
|
||||
'8': { width: 20, points: [[8,21],[5,20],[4,18],[4,16],[5,14],[7,13],[11,12],[14,11],[16,9],[17,7],[17,4],[16,2],[15,1],[12,0],[8,0],[5,1],[4,2],[3,4],[3,7],[4,9],[6,11],[9,12],[13,13],[15,14],[16,16],[16,18],[15,20],[12,21],[8,21]] },
|
||||
'9': { width: 20, points: [[16,14],[15,11],[13,9],[10,8],[9,8],[6,9],[4,11],[3,14],[3,15],[4,18],[6,20],[9,21],[10,21],[13,20],[15,18],[16,14],[16,9],[15,4],[13,1],[10,0],[8,0],[5,1],[4,3]] },
|
||||
':': { width: 10, points: [[5,14],[4,13],[5,12],[6,13],[5,14],[-1,-1],[5,2],[4,1],[5,0],[6,1],[5,2]] },
|
||||
';': { width: 10, points: [[5,14],[4,13],[5,12],[6,13],[5,14],[-1,-1],[6,1],[5,0],[4,1],[5,2],[6,1],[6,-1],[5,-3],[4,-4]] },
|
||||
'<': { width: 24, points: [[20,18],[4,9],[20,0]] },
|
||||
'=': { width: 26, points: [[4,12],[22,12],[-1,-1],[4,6],[22,6]] },
|
||||
'>': { width: 24, points: [[4,18],[20,9],[4,0]] },
|
||||
'?': { width: 18, points: [[3,16],[3,17],[4,19],[5,20],[7,21],[11,21],[13,20],[14,19],[15,17],[15,15],[14,13],[13,12],[9,10],[9,7],[-1,-1],[9,2],[8,1],[9,0],[10,1],[9,2]] },
|
||||
'@': { width: 27, points: [[18,13],[17,15],[15,16],[12,16],[10,15],[9,14],[8,11],[8,8],[9,6],[11,5],[14,5],[16,6],[17,8],[-1,-1],[12,16],[10,14],[9,11],[9,8],[10,6],[11,5],[-1,-1],[18,16],[17,8],[17,6],[19,5],[21,5],[23,7],[24,10],[24,12],[23,15],[22,17],[20,19],[18,20],[15,21],[12,21],[9,20],[7,19],[5,17],[4,15],[3,12],[3,9],[4,6],[5,4],[7,2],[9,1],[12,0],[15,0],[18,1],[20,2],[21,3],[-1,-1],[19,16],[18,8],[18,6],[19,5]] },
|
||||
'A': { width: 18, points: [[9,21],[1,0],[-1,-1],[9,21],[17,0],[-1,-1],[4,7],[14,7]] },
|
||||
'B': { width: 21, points: [[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[-1,-1],[4,11],[13,11],[16,10],[17,9],[18,7],[18,4],[17,2],[16,1],[13,0],[4,0]] },
|
||||
'C': { width: 21, points: [[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5]] },
|
||||
'D': { width: 21, points: [[4,21],[4,0],[-1,-1],[4,21],[11,21],[14,20],[16,18],[17,16],[18,13],[18,8],[17,5],[16,3],[14,1],[11,0],[4,0]] },
|
||||
'E': { width: 19, points: [[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11],[-1,-1],[4,0],[17,0]] },
|
||||
'F': { width: 18, points: [[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11]] },
|
||||
'G': { width: 21, points: [[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[18,8],[-1,-1],[13,8],[18,8]] },
|
||||
'H': { width: 22, points: [[4,21],[4,0],[-1,-1],[18,21],[18,0],[-1,-1],[4,11],[18,11]] },
|
||||
'I': { width: 8, points: [[4,21],[4,0]] },
|
||||
'J': { width: 16, points: [[12,21],[12,5],[11,2],[10,1],[8,0],[6,0],[4,1],[3,2],[2,5],[2,7]] },
|
||||
'K': { width: 21, points: [[4,21],[4,0],[-1,-1],[18,21],[4,7],[-1,-1],[9,12],[18,0]] },
|
||||
'L': { width: 17, points: [[4,21],[4,0],[-1,-1],[4,0],[16,0]] },
|
||||
'M': { width: 24, points: [[4,21],[4,0],[-1,-1],[4,21],[12,0],[-1,-1],[20,21],[12,0],[-1,-1],[20,21],[20,0]] },
|
||||
'N': { width: 22, points: [[4,21],[4,0],[-1,-1],[4,21],[18,0],[-1,-1],[18,21],[18,0]] },
|
||||
'O': { width: 22, points: [[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21]] },
|
||||
'P': { width: 21, points: [[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,14],[17,12],[16,11],[13,10],[4,10]] },
|
||||
'Q': { width: 22, points: [[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21],[-1,-1],[12,4],[18,-2]] },
|
||||
'R': { width: 21, points: [[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[4,11],[-1,-1],[11,11],[18,0]] },
|
||||
'S': { width: 20, points: [[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]] },
|
||||
'T': { width: 16, points: [[8,21],[8,0],[-1,-1],[1,21],[15,21]] },
|
||||
'U': { width: 22, points: [[4,21],[4,6],[5,3],[7,1],[10,0],[12,0],[15,1],[17,3],[18,6],[18,21]] },
|
||||
'V': { width: 18, points: [[1,21],[9,0],[-1,-1],[17,21],[9,0]] },
|
||||
'W': { width: 24, points: [[2,21],[7,0],[-1,-1],[12,21],[7,0],[-1,-1],[12,21],[17,0],[-1,-1],[22,21],[17,0]] },
|
||||
'X': { width: 20, points: [[3,21],[17,0],[-1,-1],[17,21],[3,0]] },
|
||||
'Y': { width: 18, points: [[1,21],[9,11],[9,0],[-1,-1],[17,21],[9,11]] },
|
||||
'Z': { width: 20, points: [[17,21],[3,0],[-1,-1],[3,21],[17,21],[-1,-1],[3,0],[17,0]] },
|
||||
'[': { width: 14, points: [[4,25],[4,-7],[-1,-1],[5,25],[5,-7],[-1,-1],[4,25],[11,25],[-1,-1],[4,-7],[11,-7]] },
|
||||
'\\': { width: 14, points: [[0,21],[14,-3]] },
|
||||
']': { width: 14, points: [[9,25],[9,-7],[-1,-1],[10,25],[10,-7],[-1,-1],[3,25],[10,25],[-1,-1],[3,-7],[10,-7]] },
|
||||
'^': { width: 16, points: [[6,15],[8,18],[10,15],[-1,-1],[3,12],[8,17],[13,12],[-1,-1],[8,17],[8,0]] },
|
||||
'_': { width: 16, points: [[0,-2],[16,-2]] },
|
||||
'`': { width: 10, points: [[6,21],[5,20],[4,18],[4,16],[5,15],[6,16],[5,17]] },
|
||||
'a': { width: 19, points: [[15,14],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]] },
|
||||
'b': { width: 19, points: [[4,21],[4,0],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]] },
|
||||
'c': { width: 18, points: [[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]] },
|
||||
'd': { width: 19, points: [[15,21],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]] },
|
||||
'e': { width: 18, points: [[3,8],[15,8],[15,10],[14,12],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]] },
|
||||
'f': { width: 12, points: [[10,21],[8,21],[6,20],[5,17],[5,0],[-1,-1],[2,14],[9,14]] },
|
||||
'g': { width: 19, points: [[15,14],[15,-2],[14,-5],[13,-6],[11,-7],[8,-7],[6,-6],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]] },
|
||||
'h': { width: 19, points: [[4,21],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]] },
|
||||
'i': { width: 8, points: [[3,21],[4,20],[5,21],[4,22],[3,21],[-1,-1],[4,14],[4,0]] },
|
||||
'j': { width: 10, points: [[5,21],[6,20],[7,21],[6,22],[5,21],[-1,-1],[6,14],[6,-3],[5,-6],[3,-7],[1,-7]] },
|
||||
'k': { width: 17, points: [[4,21],[4,0],[-1,-1],[14,14],[4,4],[-1,-1],[8,8],[15,0]] },
|
||||
'l': { width: 8, points: [[4,21],[4,0]] },
|
||||
'm': { width: 30, points: [[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0],[-1,-1],[15,10],[18,13],[20,14],[23,14],[25,13],[26,10],[26,0]] },
|
||||
'n': { width: 19, points: [[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]] },
|
||||
'o': { width: 19, points: [[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3],[16,6],[16,8],[15,11],[13,13],[11,14],[8,14]] },
|
||||
'p': { width: 19, points: [[4,14],[4,-7],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]] },
|
||||
'q': { width: 19, points: [[15,14],[15,-7],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]] },
|
||||
'r': { width: 13, points: [[4,14],[4,0],[-1,-1],[4,8],[5,11],[7,13],[9,14],[12,14]] },
|
||||
's': { width: 17, points: [[14,11],[13,13],[10,14],[7,14],[4,13],[3,11],[4,9],[6,8],[11,7],[13,6],[14,4],[14,3],[13,1],[10,0],[7,0],[4,1],[3,3]] },
|
||||
't': { width: 12, points: [[5,21],[5,4],[6,1],[8,0],[10,0],[-1,-1],[2,14],[9,14]] },
|
||||
'u': { width: 19, points: [[4,14],[4,4],[5,1],[7,0],[10,0],[12,1],[15,4],[-1,-1],[15,14],[15,0]] },
|
||||
'v': { width: 16, points: [[2,14],[8,0],[-1,-1],[14,14],[8,0]] },
|
||||
'w': { width: 22, points: [[3,14],[7,0],[-1,-1],[11,14],[7,0],[-1,-1],[11,14],[15,0],[-1,-1],[19,14],[15,0]] },
|
||||
'x': { width: 17, points: [[3,14],[14,0],[-1,-1],[14,14],[3,0]] },
|
||||
'y': { width: 16, points: [[2,14],[8,0],[-1,-1],[14,14],[8,0],[6,-4],[4,-6],[2,-7],[1,-7]] },
|
||||
'z': { width: 17, points: [[14,14],[3,0],[-1,-1],[3,14],[14,14],[-1,-1],[3,0],[14,0]] },
|
||||
'{': { width: 14, points: [[9,25],[7,24],[6,23],[5,21],[5,19],[6,17],[7,16],[8,14],[8,12],[6,10],[-1,-1],[7,24],[6,22],[6,20],[7,18],[8,17],[9,15],[9,13],[8,11],[4,9],[8,7],[9,5],[9,3],[8,1],[7,0],[6,-2],[6,-4],[7,-6],[-1,-1],[6,8],[8,6],[8,4],[7,2],[6,1],[5,-1],[5,-3],[6,-5],[7,-6],[9,-7]] },
|
||||
'|': { width: 8, points: [[4,25],[4,-7]] },
|
||||
'}': { width: 14, points: [[5,25],[7,24],[8,23],[9,21],[9,19],[8,17],[7,16],[6,14],[6,12],[8,10],[-1,-1],[7,24],[8,22],[8,20],[7,18],[6,17],[5,15],[5,13],[6,11],[10,9],[6,7],[5,5],[5,3],[6,1],[7,0],[8,-2],[8,-4],[7,-6],[-1,-1],[8,8],[6,6],[6,4],[7,2],[8,1],[9,-1],[9,-3],[8,-5],[7,-6],[5,-7]] },
|
||||
'~': { width: 24, points: [[3,6],[3,8],[4,11],[6,12],[8,12],[10,11],[14,8],[16,7],[18,7],[20,8],[21,10],[-1,-1],[3,8],[4,10],[6,11],[8,11],[10,10],[14,7],[16,6],[18,6],[20,7],[21,10],[21,12]] }
|
||||
};
|
||||
|
||||
$.jqplot.CanvasFontRenderer = function(options) {
|
||||
options = options || {};
|
||||
if (!options.pt2px) {
|
||||
options.pt2px = 1.5;
|
||||
}
|
||||
$.jqplot.CanvasTextRenderer.call(this, options);
|
||||
};
|
||||
|
||||
$.jqplot.CanvasFontRenderer.prototype = new $.jqplot.CanvasTextRenderer({});
|
||||
$.jqplot.CanvasFontRenderer.prototype.constructor = $.jqplot.CanvasFontRenderer;
|
||||
|
||||
$.jqplot.CanvasFontRenderer.prototype.measure = function(ctx, str)
|
||||
{
|
||||
// var fstyle = this.fontStyle+' '+this.fontVariant+' '+this.fontWeight+' '+this.fontSize+' '+this.fontFamily;
|
||||
var fstyle = this.fontSize+' '+this.fontFamily;
|
||||
ctx.save();
|
||||
ctx.font = fstyle;
|
||||
var w = ctx.measureText(str).width;
|
||||
ctx.restore();
|
||||
return w;
|
||||
};
|
||||
|
||||
$.jqplot.CanvasFontRenderer.prototype.draw = function(ctx, str)
|
||||
{
|
||||
var x = 0;
|
||||
// leave room at bottom for descenders.
|
||||
var y = this.height*0.72;
|
||||
//var y = 12;
|
||||
|
||||
ctx.save();
|
||||
var tx, ty;
|
||||
|
||||
// 1st quadrant
|
||||
if ((-Math.PI/2 <= this.angle && this.angle <= 0) || (Math.PI*3/2 <= this.angle && this.angle <= Math.PI*2)) {
|
||||
tx = 0;
|
||||
ty = -Math.sin(this.angle) * this.width;
|
||||
}
|
||||
// 4th quadrant
|
||||
else if ((0 < this.angle && this.angle <= Math.PI/2) || (-Math.PI*2 <= this.angle && this.angle <= -Math.PI*3/2)) {
|
||||
tx = Math.sin(this.angle) * this.height;
|
||||
ty = 0;
|
||||
}
|
||||
// 2nd quadrant
|
||||
else if ((-Math.PI < this.angle && this.angle < -Math.PI/2) || (Math.PI <= this.angle && this.angle <= Math.PI*3/2)) {
|
||||
tx = -Math.cos(this.angle) * this.width;
|
||||
ty = -Math.sin(this.angle) * this.width - Math.cos(this.angle) * this.height;
|
||||
}
|
||||
// 3rd quadrant
|
||||
else if ((-Math.PI*3/2 < this.angle && this.angle < Math.PI) || (Math.PI/2 < this.angle && this.angle < Math.PI)) {
|
||||
tx = Math.sin(this.angle) * this.height - Math.cos(this.angle)*this.width;
|
||||
ty = -Math.cos(this.angle) * this.height;
|
||||
}
|
||||
ctx.strokeStyle = this.fillStyle;
|
||||
ctx.fillStyle = this.fillStyle;
|
||||
// var fstyle = this.fontStyle+' '+this.fontVariant+' '+this.fontWeight+' '+this.fontSize+' '+this.fontFamily;
|
||||
var fstyle = this.fontSize+' '+this.fontFamily;
|
||||
ctx.font = fstyle;
|
||||
ctx.translate(tx, ty);
|
||||
ctx.rotate(this.angle);
|
||||
ctx.fillText(str, x, y);
|
||||
// ctx.strokeText(str, x, y);
|
||||
|
||||
ctx.restore();
|
||||
};
|
||||
|
||||
})(jQuery);
|
File diff suppressed because one or more lines are too long
|
@ -1,238 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2009 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* The author would appreciate an email letting him know of any substantial
|
||||
* use of jqPlot. You can reach the author at: chris dot leonello at gmail
|
||||
* dot com or see http://www.jqplot.com/info.php . This is, of course,
|
||||
* not required.
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* Thanks for using jqPlot!
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
/**
|
||||
* class: $.jqplot.CategoryAxisRenderer
|
||||
* A plugin for jqPlot to render a category style axis, with equal pixel spacing between y data values of a series.
|
||||
* This renderer has no options beyond those supplied by the <Axis> class.
|
||||
*
|
||||
* To use this renderer, include the plugin in your source
|
||||
* > <script type="text/javascript" language="javascript" src="plugins/jqplot.categoryAxisRenderer.js"></script>
|
||||
*
|
||||
* and supply the appropriate options to your plot
|
||||
*
|
||||
* > {axes:{xaxis:{renderer:$.jqplot.CategoryAxisRenderer}}}
|
||||
**/
|
||||
$.jqplot.CategoryAxisRenderer = function() {
|
||||
$.jqplot.LinearAxisRenderer.call(this);
|
||||
};
|
||||
|
||||
$.jqplot.CategoryAxisRenderer.prototype = new $.jqplot.LinearAxisRenderer();
|
||||
$.jqplot.CategoryAxisRenderer.prototype.constructor = $.jqplot.CategoryAxisRenderer;
|
||||
|
||||
$.jqplot.CategoryAxisRenderer.prototype.init = function(options){
|
||||
// prop: tickRenderer
|
||||
// A class of a rendering engine for creating the ticks labels displayed on the plot,
|
||||
// See <$.jqplot.AxisTickRenderer>.
|
||||
// this.tickRenderer = $.jqplot.AxisTickRenderer;
|
||||
// this.labelRenderer = $.jqplot.AxisLabelRenderer;
|
||||
$.extend(true, this, {tickOptions:{formatString:'%d'}}, options);
|
||||
var db = this._dataBounds;
|
||||
// Go through all the series attached to this axis and find
|
||||
// the min/max bounds for this axis.
|
||||
for (var i=0; i<this._series.length; i++) {
|
||||
var s = this._series[i];
|
||||
var d = s.data;
|
||||
|
||||
for (var j=0; j<d.length; j++) {
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis') {
|
||||
if (d[j][0] < db.min || db.min == null) {
|
||||
db.min = d[j][0];
|
||||
}
|
||||
if (d[j][0] > db.max || db.max == null) {
|
||||
db.max = d[j][0];
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (d[j][1] < db.min || db.min == null) {
|
||||
db.min = d[j][1];
|
||||
}
|
||||
if (d[j][1] > db.max || db.max == null) {
|
||||
db.max = d[j][1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
$.jqplot.CategoryAxisRenderer.prototype.createTicks = function() {
|
||||
// we're are operating on an axis here
|
||||
var ticks = this._ticks;
|
||||
var userTicks = this.ticks;
|
||||
var name = this.name;
|
||||
// databounds were set on axis initialization.
|
||||
var db = this._dataBounds;
|
||||
var dim, interval;
|
||||
var min, max;
|
||||
var pos1, pos2;
|
||||
var tt, i;
|
||||
|
||||
// if we already have ticks, use them.
|
||||
if (userTicks.length) {
|
||||
this.min = 0.5;
|
||||
this.max = userTicks.length + 0.5;
|
||||
var range = this.max - this.min;
|
||||
this.numberTicks = 2*userTicks.length + 1;
|
||||
for (i=0; i<userTicks.length; i++){
|
||||
tt = this.min + 2 * i * range / (this.numberTicks-1);
|
||||
// need a marker before and after the tick
|
||||
var t = new this.tickRenderer(this.tickOptions);
|
||||
t.showLabel = false;
|
||||
t.showMark = true;
|
||||
t.setTick(tt, this.name);
|
||||
this._ticks.push(t);
|
||||
var t = new this.tickRenderer(this.tickOptions);
|
||||
t.label = userTicks[i];
|
||||
t.showLabel = true;
|
||||
t.showMark = false;
|
||||
t.showGridline = false;
|
||||
t.setTick(tt+0.5, this.name);
|
||||
this._ticks.push(t);
|
||||
}
|
||||
// now add the last tick at the end
|
||||
var t = new this.tickRenderer(this.tickOptions);
|
||||
t.showLabel = false;
|
||||
t.showMark = true;
|
||||
t.setTick(tt+1, this.name);
|
||||
this._ticks.push(t);
|
||||
}
|
||||
|
||||
// we don't have any ticks yet, let's make some!
|
||||
else {
|
||||
if (name == 'xaxis' || name == 'x2axis') {
|
||||
dim = this._plotDimensions.width;
|
||||
}
|
||||
else {
|
||||
dim = this._plotDimensions.height;
|
||||
}
|
||||
|
||||
// if min, max and number of ticks specified, user can't specify interval.
|
||||
if (this.min != null && this.max != null && this.numberTicks != null) {
|
||||
this.tickInterval = null;
|
||||
}
|
||||
|
||||
// if max, min, and interval specified and interval won't fit, ignore interval.
|
||||
if (this.min != null && this.max != null && this.tickInterval != null) {
|
||||
if (parseInt((this.max-this.min)/this.tickInterval, 10) != (this.max-this.min)/this.tickInterval) {
|
||||
this.tickInterval = null;
|
||||
}
|
||||
}
|
||||
|
||||
// find out how many categories are in the lines and collect labels
|
||||
var labels = [];
|
||||
var numcats = 0;
|
||||
var min = 0.5;
|
||||
var max, val;
|
||||
for (var i=0; i<this._series.length; i++) {
|
||||
var s = this._series[i];
|
||||
for (var j=0; j<s.data.length; j++) {
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis') {
|
||||
val = s.data[j][0];
|
||||
}
|
||||
else {
|
||||
val = s.data[j][1];
|
||||
}
|
||||
if ($.inArray(val, labels) == -1) {
|
||||
numcats += 1;
|
||||
labels.push(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// keep a reference to these tick labels to use for redrawing plot (see bug #57)
|
||||
this.ticks = labels;
|
||||
|
||||
// now bin the data values to the right lables.
|
||||
for (var i=0; i<this._series.length; i++) {
|
||||
var s = this._series[i];
|
||||
for (var j=0; j<s.data.length; j++) {
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis') {
|
||||
val = s.data[j][0];
|
||||
}
|
||||
else {
|
||||
val = s.data[j][1];
|
||||
}
|
||||
// for category axis, force the values into category bins.
|
||||
// we should have the value in the label array now.
|
||||
var idx = $.inArray(val, labels)+1;
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis') {
|
||||
s.data[j][0] = idx;
|
||||
}
|
||||
else {
|
||||
s.data[j][1] = idx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
max = numcats + 0.5;
|
||||
if (this.numberTicks == null) {
|
||||
this.numberTicks = 2*numcats + 1;
|
||||
}
|
||||
|
||||
var range = max - min;
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
var track = 0;
|
||||
|
||||
// todo: adjust this so more ticks displayed.
|
||||
var maxVisibleTicks = parseInt(3+dim/20, 10);
|
||||
var skip = parseInt(numcats/maxVisibleTicks, 10);
|
||||
|
||||
if (this.tickInterval == null) {
|
||||
|
||||
this.tickInterval = range / (this.numberTicks-1);
|
||||
|
||||
}
|
||||
// if tickInterval is specified, we will ignore any computed maximum.
|
||||
for (var i=0; i<this.numberTicks; i++){
|
||||
tt = this.min + i * this.tickInterval;
|
||||
var t = new this.tickRenderer(this.tickOptions);
|
||||
// if even tick, it isn't a category, it's a divider
|
||||
if (i/2 == parseInt(i/2, 10)) {
|
||||
t.showLabel = false;
|
||||
t.showMark = true;
|
||||
}
|
||||
else {
|
||||
if (skip>0 && track<skip) {
|
||||
t.showLabel = false;
|
||||
track += 1;
|
||||
}
|
||||
else {
|
||||
t.showLabel = true;
|
||||
track = 0;
|
||||
}
|
||||
t.label = t.formatter(t.formatString, labels[(i-1)/2]);
|
||||
t.showMark = false;
|
||||
t.showGridline = false;
|
||||
}
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(tt, this.name);
|
||||
this._ticks.push(t);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
})(jQuery);
|
|
@ -1,14 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2009 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris dot leonello at gmail dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*/
|
||||
(function(a){a.jqplot.CategoryAxisRenderer=function(){a.jqplot.LinearAxisRenderer.call(this)};a.jqplot.CategoryAxisRenderer.prototype=new a.jqplot.LinearAxisRenderer();a.jqplot.CategoryAxisRenderer.prototype.constructor=a.jqplot.CategoryAxisRenderer;a.jqplot.CategoryAxisRenderer.prototype.init=function(e){a.extend(true,this,{tickOptions:{formatString:"%d"}},e);var b=this._dataBounds;for(var f=0;f<this._series.length;f++){var g=this._series[f];var h=g.data;for(var c=0;c<h.length;c++){if(this.name=="xaxis"||this.name=="x2axis"){if(h[c][0]<b.min||b.min==null){b.min=h[c][0]}if(h[c][0]>b.max||b.max==null){b.max=h[c][0]}}else{if(h[c][1]<b.min||b.min==null){b.min=h[c][1]}if(h[c][1]>b.max||b.max==null){b.max=h[c][1]}}}}};a.jqplot.CategoryAxisRenderer.prototype.createTicks=function(){var y=this._ticks;var v=this.ticks;var B=this.name;var x=this._dataBounds;var p,w;var n,q;var d,c;var b,r;if(v.length){this.min=0.5;this.max=v.length+0.5;var h=this.max-this.min;this.numberTicks=2*v.length+1;for(r=0;r<v.length;r++){b=this.min+2*r*h/(this.numberTicks-1);var f=new this.tickRenderer(this.tickOptions);f.showLabel=false;f.showMark=true;f.setTick(b,this.name);this._ticks.push(f);var f=new this.tickRenderer(this.tickOptions);f.label=v[r];f.showLabel=true;f.showMark=false;f.showGridline=false;f.setTick(b+0.5,this.name);this._ticks.push(f)}var f=new this.tickRenderer(this.tickOptions);f.showLabel=false;f.showMark=true;f.setTick(b+1,this.name);this._ticks.push(f)}else{if(B=="xaxis"||B=="x2axis"){p=this._plotDimensions.width}else{p=this._plotDimensions.height}if(this.min!=null&&this.max!=null&&this.numberTicks!=null){this.tickInterval=null}if(this.min!=null&&this.max!=null&&this.tickInterval!=null){if(parseInt((this.max-this.min)/this.tickInterval,10)!=(this.max-this.min)/this.tickInterval){this.tickInterval=null}}var u=[];var z=0;var n=0.5;var q,A;for(var r=0;r<this._series.length;r++){var g=this._series[r];for(var o=0;o<g.data.length;o++){if(this.name=="xaxis"||this.name=="x2axis"){A=g.data[o][0]}else{A=g.data[o][1]}if(a.inArray(A,u)==-1){z+=1;u.push(A)}}}this.ticks=u;for(var r=0;r<this._series.length;r++){var g=this._series[r];for(var o=0;o<g.data.length;o++){if(this.name=="xaxis"||this.name=="x2axis"){A=g.data[o][0]}else{A=g.data[o][1]}var k=a.inArray(A,u)+1;if(this.name=="xaxis"||this.name=="x2axis"){g.data[o][0]=k}else{g.data[o][1]=k}}}q=z+0.5;if(this.numberTicks==null){this.numberTicks=2*z+1}var h=q-n;this.min=n;this.max=q;var l=0;var e=parseInt(3+p/20,10);var m=parseInt(z/e,10);if(this.tickInterval==null){this.tickInterval=h/(this.numberTicks-1)}for(var r=0;r<this.numberTicks;r++){b=this.min+r*this.tickInterval;var f=new this.tickRenderer(this.tickOptions);if(r/2==parseInt(r/2,10)){f.showLabel=false;f.showMark=true}else{if(m>0&&l<m){f.showLabel=false;l+=1}else{f.showLabel=true;l=0}f.label=f.formatter(f.formatString,u[(r-1)/2]);f.showMark=false;f.showGridline=false}if(!this.showTicks){f.showLabel=false;f.showMark=false}else{if(!this.showTickMarks){f.showMark=false}}f.setTick(b,this.name);this._ticks.push(f)}}}})(jQuery);
|
|
@ -1,812 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2009 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* The author would appreciate an email letting him know of any substantial
|
||||
* use of jqPlot. You can reach the author at: chris dot leonello at gmail
|
||||
* dot com or see http://www.jqplot.com/info.php . This is, of course,
|
||||
* not required.
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* Thanks for using jqPlot!
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
|
||||
/**
|
||||
* Class: $.jqplot.Cursor
|
||||
* Plugin class representing the cursor as displayed on the plot.
|
||||
*/
|
||||
$.jqplot.Cursor = function(options) {
|
||||
// Group: Properties
|
||||
//
|
||||
// prop: style
|
||||
// CSS spec for cursor style
|
||||
this.style = 'crosshair';
|
||||
this.previousCursor = 'auto';
|
||||
// prop: show
|
||||
// wether to show the cursor or not.
|
||||
this.show = $.jqplot.config.enablePlugins;
|
||||
// prop: showTooltip
|
||||
// show a cursor position tooltip near the cursor
|
||||
this.showTooltip = true;
|
||||
// prop: followMouse
|
||||
// Tooltip follows the mouse, it is not at a fixed location.
|
||||
// Tooltip will show on the grid at the location given by
|
||||
// tooltipLocation, offset from the grid edge by tooltipOffset.
|
||||
this.followMouse = false;
|
||||
// prop: tooltipLocation
|
||||
// Where to position tooltip. If followMouse is true, this is
|
||||
// relative to the cursor, otherwise, it is relative to the grid.
|
||||
// One of 'n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw'
|
||||
this.tooltipLocation = 'se';
|
||||
// prop: tooltipOffset
|
||||
// Pixel offset of tooltip from the grid boudaries or cursor center.
|
||||
this.tooltipOffset = 6;
|
||||
// prop: showTooltipGridPosition
|
||||
// show the grid pixel coordinates of the mouse.
|
||||
this.showTooltipGridPosition = false;
|
||||
// prop: showTooltipUnitPosition
|
||||
// show the unit (data) coordinates of the mouse.
|
||||
this.showTooltipUnitPosition = true;
|
||||
// prop: showTooltipDataPosition
|
||||
// Used with showVerticalLine to show intersecting data points in the tooltip.
|
||||
this.showTooltipDataPosition = false;
|
||||
// prop: tooltipFormatString
|
||||
// sprintf format string for the tooltip.
|
||||
// Uses Ash Searle's javascript sprintf implementation
|
||||
// found here: http://hexmen.com/blog/2007/03/printf-sprintf/
|
||||
// See http://perldoc.perl.org/functions/sprintf.html for reference
|
||||
// Note, if showTooltipDataPosition is true, the default tooltipFormatString
|
||||
// will be set to the cursorLegendFormatString, not the default given here.
|
||||
this.tooltipFormatString = '%.4P, %.4P';
|
||||
// prop: useAxesFormatters
|
||||
// Use the x and y axes formatters to format the text in the tooltip.
|
||||
this.useAxesFormatters = true;
|
||||
// prop: tooltipAxisGroups
|
||||
// Show position for the specified axes.
|
||||
// This is an array like [['xaxis', 'yaxis'], ['xaxis', 'y2axis']]
|
||||
// Default is to compute automatically for all visible axes.
|
||||
this.tooltipAxisGroups = [];
|
||||
// prop: zoom
|
||||
// Enable plot zooming.
|
||||
this.zoom = false;
|
||||
// zoomProxy and zoomTarget properties are not directly set by user.
|
||||
// They Will be set through call to zoomProxy method.
|
||||
this.zoomProxy = false;
|
||||
this.zoomTarget = false;
|
||||
// prop: clickReset
|
||||
// Will reset plot zoom if single click on plot without drag.
|
||||
this.clickReset = false;
|
||||
// prop: dblClickReset
|
||||
// Will reset plot zoom if double click on plot without drag.
|
||||
this.dblClickReset = true;
|
||||
// prop: showVerticalLine
|
||||
// draw a vertical line across the plot which follows the cursor.
|
||||
// When the line is near a data point, a special legend and/or tooltip can
|
||||
// be updated with the data values.
|
||||
this.showVerticalLine = false;
|
||||
// prop: showHorizontalLine
|
||||
// draw a horizontal line across the plot which follows the cursor.
|
||||
this.showHorizontalLine = false;
|
||||
// prop: constrainZoomTo
|
||||
// 'none', 'x' or 'y'
|
||||
this.constrainZoomTo = 'none';
|
||||
// // prop: autoscaleConstraint
|
||||
// // when a constrained axis is specified, true will
|
||||
// // auatoscale the adjacent axis.
|
||||
// this.autoscaleConstraint = true;
|
||||
this.shapeRenderer = new $.jqplot.ShapeRenderer();
|
||||
this._zoom = {start:[], end:[], started: false, zooming:false, isZoomed:false, axes:{start:{}, end:{}}};
|
||||
this._tooltipElem;
|
||||
this.zoomCanvas;
|
||||
this.cursorCanvas;
|
||||
// prop: intersectionThreshold
|
||||
// pixel distance from data point or marker to consider cursor lines intersecting with point.
|
||||
// If data point markers are not shown, this should be >= 1 or will often miss point intersections.
|
||||
this.intersectionThreshold = 2;
|
||||
// prop: showCursorLegend
|
||||
// Replace the plot legend with an enhanced legend displaying intersection information.
|
||||
this.showCursorLegend = false;
|
||||
// prop: cursorLegendFormatString
|
||||
// Format string used in the cursor legend. If showTooltipDataPosition is true,
|
||||
// this will also be the default format string used by tooltipFormatString.
|
||||
this.cursorLegendFormatString = $.jqplot.Cursor.cursorLegendFormatString;
|
||||
$.extend(true, this, options);
|
||||
};
|
||||
|
||||
$.jqplot.Cursor.cursorLegendFormatString = '%s x:%s, y:%s';
|
||||
|
||||
// called with scope of plot
|
||||
$.jqplot.Cursor.init = function (target, data, opts){
|
||||
// add a cursor attribute to the plot
|
||||
var options = opts || {};
|
||||
this.plugins.cursor = new $.jqplot.Cursor(options.cursor);
|
||||
var c = this.plugins.cursor;
|
||||
|
||||
if (c.show) {
|
||||
$.jqplot.eventListenerHooks.push(['jqplotMouseEnter', handleMouseEnter]);
|
||||
$.jqplot.eventListenerHooks.push(['jqplotMouseLeave', handleMouseLeave]);
|
||||
$.jqplot.eventListenerHooks.push(['jqplotMouseMove', handleMouseMove]);
|
||||
|
||||
if (c.showCursorLegend) {
|
||||
opts.legend = opts.legend || {};
|
||||
opts.legend.renderer = $.jqplot.CursorLegendRenderer;
|
||||
opts.legend.formatString = this.plugins.cursor.cursorLegendFormatString;
|
||||
opts.legend.show = true;
|
||||
}
|
||||
|
||||
if (c.zoom) {
|
||||
$.jqplot.eventListenerHooks.push(['jqplotMouseDown', handleMouseDown]);
|
||||
$.jqplot.eventListenerHooks.push(['jqplotMouseUp', handleMouseUp]);
|
||||
|
||||
if (c.clickReset) {
|
||||
$.jqplot.eventListenerHooks.push(['jqplotClick', handleClick]);
|
||||
}
|
||||
|
||||
if (c.dblClickReset) {
|
||||
$.jqplot.eventListenerHooks.push(['jqplotDblClick', handleDblClick]);
|
||||
}
|
||||
}
|
||||
|
||||
this.resetZoom = function() {
|
||||
var axes = this.axes;
|
||||
if (!c.zoomProxy) {
|
||||
for (var ax in axes) {
|
||||
axes[ax].reset();
|
||||
}
|
||||
this.redraw();
|
||||
}
|
||||
else {
|
||||
var ctx = this.plugins.cursor.zoomCanvas._ctx;
|
||||
ctx.clearRect(0,0,ctx.canvas.width, ctx.canvas.height);
|
||||
}
|
||||
this.plugins.cursor._zoom.isZoomed = false;
|
||||
this.target.trigger('jqplotResetZoom', [this, this.plugins.cursor]);
|
||||
};
|
||||
|
||||
|
||||
if (c.showTooltipDataPosition) {
|
||||
c.showTooltipUnitPosition = false;
|
||||
c.showTooltipGridPosition = false;
|
||||
if (options.cursor.tooltipFormatString == undefined) {
|
||||
c.tooltipFormatString = $.jqplot.Cursor.cursorLegendFormatString;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// called with context of plot
|
||||
$.jqplot.Cursor.postDraw = function() {
|
||||
var c = this.plugins.cursor;
|
||||
// if (c.zoom) {
|
||||
c.zoomCanvas = new $.jqplot.GenericCanvas();
|
||||
this.eventCanvas._elem.before(c.zoomCanvas.createElement(this._gridPadding, 'jqplot-zoom-canvas', this._plotDimensions));
|
||||
var zctx = c.zoomCanvas.setContext();
|
||||
// }
|
||||
c._tooltipElem = $('<div class="jqplot-cursor-tooltip" style="position:absolute;display:none"></div>');
|
||||
c.zoomCanvas._elem.before(c._tooltipElem);
|
||||
if (c.showVerticalLine || c.showHorizontalLine) {
|
||||
c.cursorCanvas = new $.jqplot.GenericCanvas();
|
||||
this.eventCanvas._elem.before(c.cursorCanvas.createElement(this._gridPadding, 'jqplot-cursor-canvas', this._plotDimensions));
|
||||
var zctx = c.cursorCanvas.setContext();
|
||||
}
|
||||
|
||||
// if we are showing the positions in unit coordinates, and no axes groups
|
||||
// were specified, create a default set.
|
||||
if (c.showTooltipUnitPosition){
|
||||
if (c.tooltipAxisGroups.length === 0) {
|
||||
var series = this.series;
|
||||
var s;
|
||||
var temp = [];
|
||||
for (var i=0; i<series.length; i++) {
|
||||
s = series[i];
|
||||
var ax = s.xaxis+','+s.yaxis;
|
||||
if ($.inArray(ax, temp) == -1) {
|
||||
temp.push(ax);
|
||||
}
|
||||
}
|
||||
for (var i=0; i<temp.length; i++) {
|
||||
c.tooltipAxisGroups.push(temp[i].split(','));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Group: methods
|
||||
//
|
||||
// method: $.jqplot.Cursor.zoomProxy
|
||||
// links targetPlot to controllerPlot so that plot zooming of
|
||||
// targetPlot will be controlled by zooming on the controllerPlot.
|
||||
// controllerPlot will not actually zoom, but acts as an
|
||||
// overview plot. Note, the zoom options must be set to true for
|
||||
// zoomProxy to work.
|
||||
$.jqplot.Cursor.zoomProxy = function(targetPlot, controllerPlot) {
|
||||
var tc = targetPlot.plugins.cursor;
|
||||
var cc = controllerPlot.plugins.cursor;
|
||||
tc.zoomTarget = true;
|
||||
tc.zoom = true;
|
||||
tc.style = 'auto';
|
||||
tc.dblClickReset = false;
|
||||
cc.zoom = true;
|
||||
cc.zoomProxy = true;
|
||||
|
||||
controllerPlot.target.bind('jqplotZoom', plotZoom);
|
||||
controllerPlot.target.bind('jqplotResetZoom', plotReset);
|
||||
|
||||
function plotZoom(ev, gridpos, datapos, plot, cursor) {
|
||||
tc.doZoom(gridpos, datapos, targetPlot, cursor);
|
||||
}
|
||||
|
||||
function plotReset(ev, plot, cursor) {
|
||||
targetPlot.resetZoom();
|
||||
}
|
||||
};
|
||||
|
||||
$.jqplot.Cursor.prototype.resetZoom = function(plot, cursor) {
|
||||
var axes = plot.axes;
|
||||
var cax = cursor._zoom.axes;
|
||||
if (!plot.plugins.cursor.zoomProxy && cursor._zoom.isZoomed) {
|
||||
for (var ax in axes) {
|
||||
axes[ax]._ticks = [];
|
||||
axes[ax].min = cax[ax].min;
|
||||
axes[ax].max = cax[ax].max;
|
||||
axes[ax].numberTicks = cax[ax].numberTicks;
|
||||
axes[ax].tickInterval = cax[ax].tickInterval;
|
||||
// for date axes
|
||||
axes[ax].daTickInterval = cax[ax].daTickInterval;
|
||||
}
|
||||
plot.redraw();
|
||||
cursor._zoom.isZoomed = false;
|
||||
}
|
||||
else {
|
||||
var ctx = cursor.zoomCanvas._ctx;
|
||||
ctx.clearRect(0,0,ctx.canvas.width, ctx.canvas.height);
|
||||
}
|
||||
plot.target.trigger('jqplotResetZoom', [plot, cursor]);
|
||||
};
|
||||
|
||||
$.jqplot.Cursor.resetZoom = function(plot) {
|
||||
plot.resetZoom();
|
||||
};
|
||||
|
||||
$.jqplot.Cursor.prototype.doZoom = function (gridpos, datapos, plot, cursor) {
|
||||
var c = cursor;
|
||||
var axes = plot.axes;
|
||||
var zaxes = c._zoom.axes;
|
||||
var start = zaxes.start;
|
||||
var end = zaxes.end;
|
||||
var min, max;
|
||||
var ctx = plot.plugins.cursor.zoomCanvas._ctx;
|
||||
// don't zoom is zoom area is too small (in pixels)
|
||||
if ((c.constrainZoomTo == 'none' && Math.abs(gridpos.x - c._zoom.start[0]) > 6 && Math.abs(gridpos.y - c._zoom.start[1]) > 6) || (c.constrainZoomTo == 'x' && Math.abs(gridpos.x - c._zoom.start[0]) > 6) || (c.constrainZoomTo == 'y' && Math.abs(gridpos.y - c._zoom.start[1]) > 6)) {
|
||||
if (!plot.plugins.cursor.zoomProxy) {
|
||||
for (var ax in datapos) {
|
||||
// make a copy of the original axes to revert back.
|
||||
if (c._zoom.axes[ax] == undefined) {
|
||||
c._zoom.axes[ax] = {};
|
||||
c._zoom.axes[ax].numberTicks = axes[ax].numberTicks;
|
||||
c._zoom.axes[ax].tickInterval = axes[ax].tickInterval;
|
||||
// for date axes...
|
||||
c._zoom.axes[ax].daTickInterval = axes[ax].daTickInterval;
|
||||
c._zoom.axes[ax].min = axes[ax].min;
|
||||
c._zoom.axes[ax].max = axes[ax].max;
|
||||
}
|
||||
if ((c.constrainZoomTo == 'none') || (c.constrainZoomTo == 'x' && ax.charAt(0) == 'x') || (c.constrainZoomTo == 'y' && ax.charAt(0) == 'y')) {
|
||||
dp = datapos[ax];
|
||||
if (dp != null) {
|
||||
if (dp > start[ax]) {
|
||||
axes[ax].min = start[ax];
|
||||
axes[ax].max = dp;
|
||||
}
|
||||
else {
|
||||
span = start[ax] - dp;
|
||||
axes[ax].max = start[ax];
|
||||
axes[ax].min = dp;
|
||||
}
|
||||
axes[ax].tickInterval = null;
|
||||
// for date axes...
|
||||
axes[ax].daTickInterval = null;
|
||||
axes[ax]._ticks = [];
|
||||
}
|
||||
}
|
||||
|
||||
// if ((c.constrainZoomTo == 'x' && ax.charAt(0) == 'y' && c.autoscaleConstraint) || (c.constrainZoomTo == 'y' && ax.charAt(0) == 'x' && c.autoscaleConstraint)) {
|
||||
// dp = datapos[ax];
|
||||
// if (dp != null) {
|
||||
// axes[ax].max == null;
|
||||
// axes[ax].min = null;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
ctx.clearRect(0,0,ctx.canvas.width, ctx.canvas.height);
|
||||
plot.redraw();
|
||||
c._zoom.isZoomed = true;
|
||||
}
|
||||
plot.target.trigger('jqplotZoom', [gridpos, datapos, plot, cursor]);
|
||||
}
|
||||
};
|
||||
|
||||
$.jqplot.preInitHooks.push($.jqplot.Cursor.init);
|
||||
$.jqplot.postDrawHooks.push($.jqplot.Cursor.postDraw);
|
||||
|
||||
function updateTooltip(gridpos, datapos, plot) {
|
||||
var c = plot.plugins.cursor;
|
||||
var s = '';
|
||||
var addbr = false;
|
||||
if (c.showTooltipGridPosition) {
|
||||
s = gridpos.x+', '+gridpos.y;
|
||||
addbr = true;
|
||||
}
|
||||
if (c.showTooltipUnitPosition) {
|
||||
var g;
|
||||
for (var i=0; i<c.tooltipAxisGroups.length; i++) {
|
||||
g = c.tooltipAxisGroups[i];
|
||||
if (addbr) {
|
||||
s += '<br />';
|
||||
}
|
||||
if (c.useAxesFormatters) {
|
||||
var xf = plot.axes[g[0]]._ticks[0].formatter;
|
||||
var yf = plot.axes[g[1]]._ticks[0].formatter;
|
||||
var xfstr = plot.axes[g[0]]._ticks[0].formatString;
|
||||
var yfstr = plot.axes[g[1]]._ticks[0].formatString;
|
||||
s += xf(xfstr, datapos[g[0]]) + ', '+ yf(yfstr, datapos[g[1]]);
|
||||
}
|
||||
else {
|
||||
s += $.jqplot.sprintf(c.tooltipFormatString, datapos[g[0]], datapos[g[1]]);
|
||||
}
|
||||
addbr = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (c.showTooltipDataPosition) {
|
||||
var series = plot.series;
|
||||
var ret = getIntersectingPoints(plot, gridpos.x, gridpos.y);
|
||||
var addbr = false;
|
||||
|
||||
for (var i = 0; i< series.length; i++) {
|
||||
if (series[i].show) {
|
||||
var idx = series[i].index;
|
||||
var label = series[i].label.toString();
|
||||
var cellid = $.inArray(idx, ret.indices);
|
||||
var sx = undefined;
|
||||
var sy = undefined;
|
||||
if (cellid != -1) {
|
||||
var data = ret.data[cellid].data;
|
||||
if (c.useAxesFormatters) {
|
||||
var xf = series[i]._xaxis._ticks[0].formatter;
|
||||
var yf = series[i]._yaxis._ticks[0].formatter;
|
||||
var xfstr = series[i]._xaxis._ticks[0].formatString;
|
||||
var yfstr = series[i]._yaxis._ticks[0].formatString;
|
||||
sx = xf(xfstr, data[0]);
|
||||
sy = yf(yfstr, data[1]);
|
||||
}
|
||||
else {
|
||||
sx = data[0];
|
||||
sy = data[1];
|
||||
}
|
||||
if (addbr) {
|
||||
s += '<br />';
|
||||
}
|
||||
s += $.jqplot.sprintf(c.tooltipFormatString, label, sx, sy);
|
||||
addbr = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
c._tooltipElem.html(s);
|
||||
}
|
||||
|
||||
function moveLine(gridpos, plot) {
|
||||
var c = plot.plugins.cursor;
|
||||
var ctx = c.cursorCanvas._ctx;
|
||||
ctx.clearRect(0,0,ctx.canvas.width, ctx.canvas.height);
|
||||
if (c.showVerticalLine) {
|
||||
c.shapeRenderer.draw(ctx, [[gridpos.x, 0], [gridpos.x, ctx.canvas.height]]);
|
||||
}
|
||||
if (c.showHorizontalLine) {
|
||||
c.shapeRenderer.draw(ctx, [[0, gridpos.y], [ctx.canvas.width, gridpos.y]]);
|
||||
}
|
||||
var ret = getIntersectingPoints(plot, gridpos.x, gridpos.y);
|
||||
if (c.showCursorLegend) {
|
||||
var cells = $(plot.targetId + ' td.jqplot-cursor-legend-label');
|
||||
for (var i=0; i<cells.length; i++) {
|
||||
var idx = $(cells[i]).data('seriesIndex');
|
||||
var series = plot.series[idx];
|
||||
var label = series.label.toString();
|
||||
var cellid = $.inArray(idx, ret.indices);
|
||||
var sx = undefined;
|
||||
var sy = undefined;
|
||||
if (cellid != -1) {
|
||||
var data = ret.data[cellid].data;
|
||||
if (c.useAxesFormatters) {
|
||||
var xf = series._xaxis._ticks[0].formatter;
|
||||
var yf = series._yaxis._ticks[0].formatter;
|
||||
var xfstr = series._xaxis._ticks[0].formatString;
|
||||
var yfstr = series._yaxis._ticks[0].formatString;
|
||||
sx = xf(xfstr, data[0]);
|
||||
sy = yf(yfstr, data[1]);
|
||||
}
|
||||
else {
|
||||
sx = data[0];
|
||||
sy = data[1];
|
||||
}
|
||||
}
|
||||
if (plot.legend.escapeHtml) {
|
||||
$(cells[i]).text($.jqplot.sprintf(c.cursorLegendFormatString, label, sx, sy));
|
||||
}
|
||||
else {
|
||||
$(cells[i]).html($.jqplot.sprintf(c.cursorLegendFormatString, label, sx, sy));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getIntersectingPoints(plot, x, y) {
|
||||
var ret = {indices:[], data:[]};
|
||||
var s, i, d0, d, j, r;
|
||||
var threshold;
|
||||
var c = plot.plugins.cursor;
|
||||
for (var i=0; i<plot.series.length; i++) {
|
||||
s = plot.series[i];
|
||||
r = s.renderer;
|
||||
if (s.show) {
|
||||
threshold = c.intersectionThreshold;
|
||||
if (s.showMarker) {
|
||||
threshold += s.markerRenderer.size/2;
|
||||
}
|
||||
for (var j=0; j<s.gridData.length; j++) {
|
||||
p = s.gridData[j];
|
||||
// check vertical line
|
||||
if (c.showVerticalLine) {
|
||||
if (Math.abs(x-p[0]) <= threshold) {
|
||||
ret.indices.push(i);
|
||||
ret.data.push({seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
function moveTooltip(gridpos, plot) {
|
||||
var c = plot.plugins.cursor;
|
||||
var elem = c._tooltipElem;
|
||||
switch (c.tooltipLocation) {
|
||||
case 'nw':
|
||||
var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true) - c.tooltipOffset;
|
||||
var y = gridpos.y + plot._gridPadding.top - c.tooltipOffset - elem.outerHeight(true);
|
||||
break;
|
||||
case 'n':
|
||||
var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true)/2;
|
||||
var y = gridpos.y + plot._gridPadding.top - c.tooltipOffset - elem.outerHeight(true);
|
||||
break;
|
||||
case 'ne':
|
||||
var x = gridpos.x + plot._gridPadding.left + c.tooltipOffset;
|
||||
var y = gridpos.y + plot._gridPadding.top - c.tooltipOffset - elem.outerHeight(true);
|
||||
break;
|
||||
case 'e':
|
||||
var x = gridpos.x + plot._gridPadding.left + c.tooltipOffset;
|
||||
var y = gridpos.y + plot._gridPadding.top - elem.outerHeight(true)/2;
|
||||
break;
|
||||
case 'se':
|
||||
var x = gridpos.x + plot._gridPadding.left + c.tooltipOffset;
|
||||
var y = gridpos.y + plot._gridPadding.top + c.tooltipOffset;
|
||||
break;
|
||||
case 's':
|
||||
var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true)/2;
|
||||
var y = gridpos.y + plot._gridPadding.top + c.tooltipOffset;
|
||||
break;
|
||||
case 'sw':
|
||||
var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true) - c.tooltipOffset;
|
||||
var y = gridpos.y + plot._gridPadding.top + c.tooltipOffset;
|
||||
break;
|
||||
case 'w':
|
||||
var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true) - c.tooltipOffset;
|
||||
var y = gridpos.y + plot._gridPadding.top - elem.outerHeight(true)/2;
|
||||
break;
|
||||
default:
|
||||
var x = gridpos.x + plot._gridPadding.left + c.tooltipOffset;
|
||||
var y = gridpos.y + plot._gridPadding.top + c.tooltipOffset;
|
||||
break;
|
||||
}
|
||||
|
||||
c._tooltipElem.css('left', x);
|
||||
c._tooltipElem.css('top', y);
|
||||
}
|
||||
|
||||
function positionTooltip(plot) {
|
||||
// fake a grid for positioning
|
||||
var grid = plot._gridPadding;
|
||||
var c = plot.plugins.cursor;
|
||||
var elem = c._tooltipElem;
|
||||
switch (c.tooltipLocation) {
|
||||
case 'nw':
|
||||
var a = grid.left + c.tooltipOffset;
|
||||
var b = grid.top + c.tooltipOffset;
|
||||
elem.css('left', a);
|
||||
elem.css('top', b);
|
||||
break;
|
||||
case 'n':
|
||||
var a = (grid.left + (plot._plotDimensions.width - grid.right))/2 - elem.outerWidth(true)/2;
|
||||
var b = grid.top + c.tooltipOffset;
|
||||
elem.css('left', a);
|
||||
elem.css('top', b);
|
||||
break;
|
||||
case 'ne':
|
||||
var a = grid.right + c.tooltipOffset;
|
||||
var b = grid.top + c.tooltipOffset;
|
||||
elem.css({right:a, top:b});
|
||||
break;
|
||||
case 'e':
|
||||
var a = grid.right + c.tooltipOffset;
|
||||
var b = (grid.top + (plot._plotDimensions.height - grid.bottom))/2 - elem.outerHeight(true)/2;
|
||||
elem.css({right:a, top:b});
|
||||
break;
|
||||
case 'se':
|
||||
var a = grid.right + c.tooltipOffset;
|
||||
var b = grid.bottom + c.tooltipOffset;
|
||||
elem.css({right:a, bottom:b});
|
||||
break;
|
||||
case 's':
|
||||
var a = (grid.left + (plot._plotDimensions.width - grid.right))/2 - elem.outerWidth(true)/2;
|
||||
var b = grid.bottom + c.tooltipOffset;
|
||||
elem.css({left:a, bottom:b});
|
||||
break;
|
||||
case 'sw':
|
||||
var a = grid.left + c.tooltipOffset;
|
||||
var b = grid.bottom + c.tooltipOffset;
|
||||
elem.css({left:a, bottom:b});
|
||||
break;
|
||||
case 'w':
|
||||
var a = grid.left + c.tooltipOffset;
|
||||
var b = (grid.top + (plot._plotDimensions.height - grid.bottom))/2 - elem.outerHeight(true)/2;
|
||||
elem.css({left:a, top:b});
|
||||
break;
|
||||
default: // same as 'se'
|
||||
var a = grid.right - c.tooltipOffset;
|
||||
var b = grid.bottom + c.tooltipOffset;
|
||||
elem.css({right:a, bottom:b});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function handleClick (ev, gridpos, datapos, neighbor, plot) {
|
||||
ev.stopPropagation();
|
||||
ev.preventDefault();
|
||||
var c = plot.plugins.cursor;
|
||||
if (c.clickReset) {
|
||||
c.resetZoom(plot, c);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function handleDblClick (ev, gridpos, datapos, neighbor, plot) {
|
||||
ev.stopPropagation();
|
||||
ev.preventDefault();
|
||||
var c = plot.plugins.cursor;
|
||||
if (c.dblClickReset) {
|
||||
c.resetZoom(plot, c);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function handleMouseLeave(ev, gridpos, datapos, neighbor, plot) {
|
||||
var c = plot.plugins.cursor;
|
||||
if (c.show) {
|
||||
$(ev.target).css('cursor', c.previousCursor);
|
||||
if (c.showTooltip) {
|
||||
c._tooltipElem.hide();
|
||||
}
|
||||
if (c.zoom) {
|
||||
c._zoom.started = false;
|
||||
c._zoom.zooming = false;
|
||||
if (!c.zoomProxy) {
|
||||
var ctx = c.zoomCanvas._ctx;
|
||||
ctx.clearRect(0,0,ctx.canvas.width, ctx.canvas.height);
|
||||
}
|
||||
}
|
||||
if (c.showVerticalLine || c.showHorizontalLine) {
|
||||
var ctx = c.cursorCanvas._ctx;
|
||||
ctx.clearRect(0,0,ctx.canvas.width, ctx.canvas.height);
|
||||
} if (c.showCursorLegend) {
|
||||
var cells = $(plot.targetId + ' td.jqplot-cursor-legend-label');
|
||||
for (var i=0; i<cells.length; i++) {
|
||||
var idx = $(cells[i]).data('seriesIndex');
|
||||
var series = plot.series[idx];
|
||||
var label = series.label.toString();
|
||||
if (plot.legend.escapeHtml) {
|
||||
$(cells[i]).text($.jqplot.sprintf(c.cursorLegendFormatString, label, undefined, undefined));
|
||||
}
|
||||
else {
|
||||
$(cells[i]).html($.jqplot.sprintf(c.cursorLegendFormatString, label, undefined, undefined));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handleMouseEnter(ev, gridpos, datapos, neighbor, plot) {
|
||||
var c = plot.plugins.cursor;
|
||||
if (c.show) {
|
||||
c.previousCursor = ev.target.style.cursor;
|
||||
ev.target.style.cursor = c.style;
|
||||
if (c.showTooltip) {
|
||||
updateTooltip(gridpos, datapos, plot);
|
||||
if (c.followMouse) {
|
||||
moveTooltip(gridpos, plot);
|
||||
}
|
||||
else {
|
||||
positionTooltip(plot);
|
||||
}
|
||||
c._tooltipElem.show();
|
||||
}
|
||||
if (c.showVerticalLine || c.showHorizontalLine) {
|
||||
moveLine(gridpos, plot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handleMouseMove(ev, gridpos, datapos, neighbor, plot) {
|
||||
var c = plot.plugins.cursor;
|
||||
var ctx = c.zoomCanvas._ctx;
|
||||
if (c.show) {
|
||||
if (c.showTooltip) {
|
||||
updateTooltip(gridpos, datapos, plot);
|
||||
if (c.followMouse) {
|
||||
moveTooltip(gridpos, plot);
|
||||
}
|
||||
}
|
||||
if (c.zoom && c._zoom.started && !c.zoomTarget) {
|
||||
c._zoom.zooming = true;
|
||||
if (c.constrainZoomTo == 'x') {
|
||||
c._zoom.end = [gridpos.x, ctx.canvas.height];
|
||||
}
|
||||
else if (c.constrainZoomTo == 'y') {
|
||||
c._zoom.end = [ctx.canvas.width, gridpos.y];
|
||||
}
|
||||
else {
|
||||
c._zoom.end = [gridpos.x, gridpos.y];
|
||||
}
|
||||
drawZoomBox.call(c);
|
||||
}
|
||||
if (c.showVerticalLine || c.showHorizontalLine) {
|
||||
moveLine(gridpos, plot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handleMouseDown(ev, gridpos, datapos, neighbor, plot) {
|
||||
var c = plot.plugins.cursor;
|
||||
var axes = plot.axes;
|
||||
if (c.zoom) {
|
||||
if (!c.zoomProxy) {
|
||||
var ctx = c.zoomCanvas._ctx;
|
||||
ctx.clearRect(0,0,ctx.canvas.width, ctx.canvas.height);
|
||||
}
|
||||
if (c.constrainZoomTo == 'x') {
|
||||
c._zoom.start = [gridpos.x, 0];
|
||||
}
|
||||
else if (c.constrainZoomTo == 'y') {
|
||||
c._zoom.start = [0, gridpos.y];
|
||||
}
|
||||
else {
|
||||
c._zoom.start = [gridpos.x, gridpos.y];
|
||||
}
|
||||
c._zoom.started = true;
|
||||
for (var ax in datapos) {
|
||||
// get zoom starting position.
|
||||
c._zoom.axes.start[ax] = datapos[ax];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handleMouseUp(ev, gridpos, datapos, neighbor, plot) {
|
||||
var c = plot.plugins.cursor;
|
||||
if (c.zoom && c._zoom.zooming && !c.zoomTarget) {
|
||||
c.doZoom(gridpos, datapos, plot, c);
|
||||
}
|
||||
c._zoom.started = false;
|
||||
c._zoom.zooming = false;
|
||||
}
|
||||
|
||||
function drawZoomBox() {
|
||||
var start = this._zoom.start;
|
||||
var end = this._zoom.end;
|
||||
var ctx = this.zoomCanvas._ctx;
|
||||
var l, t, h, w;
|
||||
if (end[0] > start[0]) {
|
||||
l = start[0];
|
||||
w = end[0] - start[0];
|
||||
}
|
||||
else {
|
||||
l = end[0];
|
||||
w = start[0] - end[0];
|
||||
}
|
||||
if (end[1] > start[1]) {
|
||||
t = start[1];
|
||||
h = end[1] - start[1];
|
||||
}
|
||||
else {
|
||||
t = end[1];
|
||||
h = start[1] - end[1];
|
||||
}
|
||||
ctx.fillStyle = 'rgba(0,0,0,0.2)';
|
||||
ctx.strokeStyle = '#999999';
|
||||
ctx.lineWidth = 1.0;
|
||||
ctx.clearRect(0,0,ctx.canvas.width, ctx.canvas.height);
|
||||
ctx.fillRect(0,0,ctx.canvas.width, ctx.canvas.height);
|
||||
ctx.clearRect(l, t, w, h);
|
||||
// IE won't show transparent fill rect, so stroke a rect also.
|
||||
ctx.strokeRect(l,t,w,h);
|
||||
}
|
||||
|
||||
$.jqplot.CursorLegendRenderer = function(options) {
|
||||
$.jqplot.TableLegendRenderer.call(this, options);
|
||||
this.formatString = '%s';
|
||||
};
|
||||
|
||||
$.jqplot.CursorLegendRenderer.prototype = new $.jqplot.TableLegendRenderer();
|
||||
$.jqplot.CursorLegendRenderer.prototype.constructor = $.jqplot.CursorLegendRenderer;
|
||||
|
||||
// called in context of a Legend
|
||||
$.jqplot.CursorLegendRenderer.prototype.draw = function() {
|
||||
if (this.show) {
|
||||
var series = this._series;
|
||||
// make a table. one line label per row.
|
||||
this._elem = $('<table class="jqplot-legend jqplot-cursor-legend" style="position:absolute"></table>');
|
||||
|
||||
var pad = false;
|
||||
for (var i = 0; i< series.length; i++) {
|
||||
s = series[i];
|
||||
if (s.show) {
|
||||
var lt = $.jqplot.sprintf(this.formatString, s.label.toString());
|
||||
if (lt) {
|
||||
var color = s.color;
|
||||
if (s._stack && !s.fill) {
|
||||
color = '';
|
||||
}
|
||||
addrow.call(this, lt, color, pad, i);
|
||||
pad = true;
|
||||
}
|
||||
// let plugins add more rows to legend. Used by trend line plugin.
|
||||
for (var j=0; j<$.jqplot.addLegendRowHooks.length; j++) {
|
||||
var item = $.jqplot.addLegendRowHooks[j].call(this, s);
|
||||
if (item) {
|
||||
addrow.call(this, item.label, item.color, pad);
|
||||
pad = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addrow(label, color, pad, idx) {
|
||||
var rs = (pad) ? this.rowSpacing : '0';
|
||||
var tr = $('<tr class="jqplot-legend jqplot-cursor-legend"></tr>').appendTo(this._elem);
|
||||
tr.data('seriesIndex', idx);
|
||||
$('<td class="jqplot-legend jqplot-cursor-legend-swatch" style="padding-top:'+rs+';">'+
|
||||
'<div style="border:1px solid #cccccc;padding:0.2em;">'+
|
||||
'<div class="jqplot-cursor-legend-swatch" style="background-color:'+color+';"></div>'+
|
||||
'</div></td>').appendTo(tr);
|
||||
var td = $('<td class="jqplot-legend jqplot-cursor-legend-label" style="vertical-align:middle;padding-top:'+rs+';"></td>');
|
||||
td.appendTo(tr);
|
||||
td.data('seriesIndex', idx);
|
||||
if (this.escapeHtml) {
|
||||
td.text(label);
|
||||
}
|
||||
else {
|
||||
td.html(label);
|
||||
}
|
||||
}
|
||||
return this._elem;
|
||||
};
|
||||
|
||||
})(jQuery);
|
File diff suppressed because one or more lines are too long
|
@ -1,313 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2009 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* The author would appreciate an email letting him know of any substantial
|
||||
* use of jqPlot. You can reach the author at: chris dot leonello at gmail
|
||||
* dot com or see http://www.jqplot.com/info.php . This is, of course,
|
||||
* not required.
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* Thanks for using jqPlot!
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
/**
|
||||
* Class: $.jqplot.DateAxisRenderer
|
||||
* A plugin for a jqPlot to render an axis as a series of date values.
|
||||
* This renderer has no options beyond those supplied by the <Axis> class.
|
||||
* It supplies it's own tick formatter, so the tickOptions.formatter option
|
||||
* should not be overridden.
|
||||
*
|
||||
* Thanks to Ken Synder for his enhanced Date instance methods which are
|
||||
* included with this code <http://kendsnyder.com/sandbox/date/>.
|
||||
*
|
||||
* To use this renderer, include the plugin in your source
|
||||
* > <script type="text/javascript" language="javascript" src="plugins/jqplot.dateAxisRenderer.js"></script>
|
||||
*
|
||||
* and supply the appropriate options to your plot
|
||||
*
|
||||
* > {axes:{xaxis:{renderer:$.jqplot.DateAxisRenderer}}}
|
||||
*
|
||||
* Dates can be passed into the axis in almost any recognizable value and
|
||||
* will be parsed. They will be rendered on the axis in the format
|
||||
* specified by tickOptions.formatString. e.g. tickOptions.formatString = '%Y-%m-%d'.
|
||||
*
|
||||
* Accecptable format codes
|
||||
* are:
|
||||
*
|
||||
* > Code Result Description
|
||||
* > == Years ==
|
||||
* > %Y 2008 Four-digit year
|
||||
* > %y 08 Two-digit year
|
||||
* > == Months ==
|
||||
* > %m 09 Two-digit month
|
||||
* > %#m 9 One or two-digit month
|
||||
* > %B September Full month name
|
||||
* > %b Sep Abbreviated month name
|
||||
* > == Days ==
|
||||
* > %d 05 Two-digit day of month
|
||||
* > %#d 5 One or two-digit day of month
|
||||
* > %e 5 One or two-digit day of month
|
||||
* > %A Sunday Full name of the day of the week
|
||||
* > %a Sun Abbreviated name of the day of the week
|
||||
* > %w 0 Number of the day of the week (0 = Sunday, 6 = Saturday)
|
||||
* > %o th The ordinal suffix string following the day of the month
|
||||
* > == Hours ==
|
||||
* > %H 23 Hours in 24-hour format (two digits)
|
||||
* > %#H 3 Hours in 24-hour integer format (one or two digits)
|
||||
* > %I 11 Hours in 12-hour format (two digits)
|
||||
* > %#I 3 Hours in 12-hour integer format (one or two digits)
|
||||
* > %p PM AM or PM
|
||||
* > == Minutes ==
|
||||
* > %M 09 Minutes (two digits)
|
||||
* > %#M 9 Minutes (one or two digits)
|
||||
* > == Seconds ==
|
||||
* > %S 02 Seconds (two digits)
|
||||
* > %#S 2 Seconds (one or two digits)
|
||||
* > %s 1206567625723 Unix timestamp (Seconds past 1970-01-01 00:00:00)
|
||||
* > == Milliseconds ==
|
||||
* > %N 008 Milliseconds (three digits)
|
||||
* > %#N 8 Milliseconds (one to three digits)
|
||||
* > == Timezone ==
|
||||
* > %O 360 difference in minutes between local time and GMT
|
||||
* > %Z Mountain Standard Time Name of timezone as reported by browser
|
||||
* > %G -06:00 Hours and minutes between GMT
|
||||
* > == Shortcuts ==
|
||||
* > %F 2008-03-26 %Y-%m-%d
|
||||
* > %T 05:06:30 %H:%M:%S
|
||||
* > %X 05:06:30 %H:%M:%S
|
||||
* > %x 03/26/08 %m/%d/%y
|
||||
* > %D 03/26/08 %m/%d/%y
|
||||
* > %#c Wed Mar 26 15:31:00 2008 %a %b %e %H:%M:%S %Y
|
||||
* > %v 3-Sep-2008 %e-%b-%Y
|
||||
* > %R 15:31 %H:%M
|
||||
* > %r 3:31:00 PM %I:%M:%S %p
|
||||
* > == Characters ==
|
||||
* > %n \n Newline
|
||||
* > %t \t Tab
|
||||
* > %% % Percent Symbol
|
||||
*/
|
||||
$.jqplot.DateAxisRenderer = function() {
|
||||
$.jqplot.LinearAxisRenderer.call(this);
|
||||
};
|
||||
|
||||
$.jqplot.DateAxisRenderer.prototype = new $.jqplot.LinearAxisRenderer();
|
||||
$.jqplot.DateAxisRenderer.prototype.constructor = $.jqplot.DateAxisRenderer;
|
||||
|
||||
$.jqplot.DateTickFormatter = function(format, val) {
|
||||
if (!format) {
|
||||
format = '%Y/%m/%d';
|
||||
}
|
||||
return Date.create(val).strftime(format);
|
||||
};
|
||||
|
||||
$.jqplot.DateAxisRenderer.prototype.init = function(options){
|
||||
// prop: tickRenderer
|
||||
// A class of a rendering engine for creating the ticks labels displayed on the plot,
|
||||
// See <$.jqplot.AxisTickRenderer>.
|
||||
// this.tickRenderer = $.jqplot.AxisTickRenderer;
|
||||
// this.labelRenderer = $.jqplot.AxisLabelRenderer;
|
||||
this.tickOptions.formatter = $.jqplot.DateTickFormatter;
|
||||
this.daTickInterval = null;
|
||||
this._daTickInterval = null;
|
||||
$.extend(true, this, options);
|
||||
var db = this._dataBounds;
|
||||
// Go through all the series attached to this axis and find
|
||||
// the min/max bounds for this axis.
|
||||
for (var i=0; i<this._series.length; i++) {
|
||||
var s = this._series[i];
|
||||
var d = s.data;
|
||||
var pd = s._plotData;
|
||||
var sd = s._stackData;
|
||||
|
||||
for (var j=0; j<d.length; j++) {
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis') {
|
||||
d[j][0] = Date.create(d[j][0]).getTime();
|
||||
pd[j][0] = Date.create(d[j][0]).getTime();
|
||||
sd[j][0] = Date.create(d[j][0]).getTime();
|
||||
if (d[j][0] < db.min || db.min == null) {
|
||||
db.min = d[j][0];
|
||||
}
|
||||
if (d[j][0] > db.max || db.max == null) {
|
||||
db.max = d[j][0];
|
||||
}
|
||||
}
|
||||
else {
|
||||
d[j][1] = Date.create(d[j][1]).getTime();
|
||||
pd[j][1] = Date.create(d[j][1]).getTime();
|
||||
sd[j][1] = Date.create(d[j][1]).getTime();
|
||||
if (d[j][1] < db.min || db.min == null) {
|
||||
db.min = d[j][1];
|
||||
}
|
||||
if (d[j][1] > db.max || db.max == null) {
|
||||
db.max = d[j][1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// called with scope of an axis
|
||||
$.jqplot.DateAxisRenderer.prototype.reset = function() {
|
||||
this.min = this._min;
|
||||
this.max = this._max;
|
||||
this.tickInterval = this._tickInterval;
|
||||
this.numberTicks = this._numberTicks;
|
||||
this.daTickInterval = this._daTickInterval;
|
||||
// this._ticks = this.__ticks;
|
||||
};
|
||||
|
||||
$.jqplot.DateAxisRenderer.prototype.createTicks = function() {
|
||||
// we're are operating on an axis here
|
||||
var ticks = this._ticks;
|
||||
var userTicks = this.ticks;
|
||||
var name = this.name;
|
||||
// databounds were set on axis initialization.
|
||||
var db = this._dataBounds;
|
||||
var dim, interval;
|
||||
var min, max;
|
||||
var pos1, pos2;
|
||||
var tt, i;
|
||||
|
||||
// if we already have ticks, use them.
|
||||
// ticks must be in order of increasing value.
|
||||
|
||||
if (userTicks.length) {
|
||||
// ticks could be 1D or 2D array of [val, val, ,,,] or [[val, label], [val, label], ...] or mixed
|
||||
for (i=0; i<userTicks.length; i++){
|
||||
var ut = userTicks[i];
|
||||
var t = new this.tickRenderer(this.tickOptions);
|
||||
if (ut.constructor == Array) {
|
||||
t.value = Date.create(ut[0]).getTime();
|
||||
t.label = ut[1];
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(t.value, this.name);
|
||||
this._ticks.push(t);
|
||||
}
|
||||
|
||||
else {
|
||||
t.value = Date.create(ut).getTime();
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(t.value, this.name);
|
||||
this._ticks.push(t);
|
||||
}
|
||||
}
|
||||
this.numberTicks = userTicks.length;
|
||||
this.min = this._ticks[0].value;
|
||||
this.max = this._ticks[this.numberTicks-1].value;
|
||||
this.daTickInterval = [(this.max - this.min) / (this.numberTicks - 1)/1000, 'seconds'];
|
||||
}
|
||||
|
||||
// we don't have any ticks yet, let's make some!
|
||||
else {
|
||||
if (name == 'xaxis' || name == 'x2axis') {
|
||||
dim = this._plotDimensions.width;
|
||||
}
|
||||
else {
|
||||
dim = this._plotDimensions.height;
|
||||
}
|
||||
|
||||
// if min, max and number of ticks specified, user can't specify interval.
|
||||
if (this.min != null && this.max != null && this.numberTicks != null) {
|
||||
this.tickInterval = null;
|
||||
}
|
||||
|
||||
// if user specified a tick interval, convert to usable.
|
||||
if (this.tickInterval != null)
|
||||
{
|
||||
// if interval is a number or can be converted to one, use it.
|
||||
// Assume it is in SECONDS!!!
|
||||
if (Number(this.tickInterval)) {
|
||||
this.daTickInterval = [Number(this.tickInterval), 'seconds'];
|
||||
}
|
||||
// else, parse out something we can build from.
|
||||
else if (typeof this.tickInterval == "string") {
|
||||
var parts = this.tickInterval.split(' ');
|
||||
if (parts.length == 1) {
|
||||
this.daTickInterval = [1, parts[0]];
|
||||
}
|
||||
else if (parts.length == 2) {
|
||||
this.daTickInterval = [parts[0], parts[1]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
min = ((this.min != null) ? Date.create(this.min).getTime() : db.min);
|
||||
max = ((this.max != null) ? Date.create(this.max).getTime() : db.max);
|
||||
|
||||
// if min and max are same, space them out a bit
|
||||
if (min == max) {
|
||||
var adj = 24*60*60*500; // 1/2 day
|
||||
min -= adj;
|
||||
max += adj;
|
||||
}
|
||||
|
||||
var range = max - min;
|
||||
var rmin, rmax;
|
||||
|
||||
rmin = (this.min != null) ? Date.create(this.min).getTime() : min - range/2*(this.padMin - 1);
|
||||
rmax = (this.max != null) ? Date.create(this.max).getTime() : max + range/2*(this.padMax - 1);
|
||||
this.min = rmin;
|
||||
this.max = rmax;
|
||||
range = this.max - this.min;
|
||||
|
||||
if (this.numberTicks == null){
|
||||
// if tickInterval is specified by user, we will ignore computed maximum.
|
||||
// max will be equal or greater to fit even # of ticks.
|
||||
if (this.daTickInterval != null) {
|
||||
var nc = Date.create(this.max).diff(this.min, this.daTickInterval[1], true);
|
||||
this.numberTicks = Math.ceil(nc/this.daTickInterval[0]) +1;
|
||||
// this.max = Date.create(this.min).add(this.numberTicks-1, this.daTickInterval[1]).getTime();
|
||||
this.max = Date.create(this.min).add((this.numberTicks-1) * this.daTickInterval[0], this.daTickInterval[1]).getTime();
|
||||
}
|
||||
else if (dim > 200) {
|
||||
this.numberTicks = parseInt(3+(dim-200)/100, 10);
|
||||
}
|
||||
else {
|
||||
this.numberTicks = 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.daTickInterval == null) {
|
||||
this.daTickInterval = [range / (this.numberTicks-1)/1000, 'seconds'];
|
||||
}
|
||||
for (var i=0; i<this.numberTicks; i++){
|
||||
var min = Date.create(this.min);
|
||||
tt = min.add(i*this.daTickInterval[0], this.daTickInterval[1]).getTime();
|
||||
var t = new this.tickRenderer(this.tickOptions);
|
||||
// var t = new $.jqplot.AxisTickRenderer(this.tickOptions);
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(tt, this.name);
|
||||
this._ticks.push(t);
|
||||
}
|
||||
}
|
||||
if (this._daTickInterval == null) {
|
||||
this._daTickInterval = this.daTickInterval;
|
||||
}
|
||||
};
|
||||
|
||||
})(jQuery);
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2009 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris dot leonello at gmail dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*/
|
||||
(function(a){a.jqplot.DateAxisRenderer=function(){a.jqplot.LinearAxisRenderer.call(this)};a.jqplot.DateAxisRenderer.prototype=new a.jqplot.LinearAxisRenderer();a.jqplot.DateAxisRenderer.prototype.constructor=a.jqplot.DateAxisRenderer;a.jqplot.DateTickFormatter=function(b,c){if(!b){b="%Y/%m/%d"}return Date.create(c).strftime(b)};a.jqplot.DateAxisRenderer.prototype.init=function(f){this.tickOptions.formatter=a.jqplot.DateTickFormatter;this.daTickInterval=null;this._daTickInterval=null;a.extend(true,this,f);var c=this._dataBounds;for(var g=0;g<this._series.length;g++){var h=this._series[g];var l=h.data;var b=h._plotData;var k=h._stackData;for(var e=0;e<l.length;e++){if(this.name=="xaxis"||this.name=="x2axis"){l[e][0]=Date.create(l[e][0]).getTime();b[e][0]=Date.create(l[e][0]).getTime();k[e][0]=Date.create(l[e][0]).getTime();if(l[e][0]<c.min||c.min==null){c.min=l[e][0]}if(l[e][0]>c.max||c.max==null){c.max=l[e][0]}}else{l[e][1]=Date.create(l[e][1]).getTime();b[e][1]=Date.create(l[e][1]).getTime();k[e][1]=Date.create(l[e][1]).getTime();if(l[e][1]<c.min||c.min==null){c.min=l[e][1]}if(l[e][1]>c.max||c.max==null){c.max=l[e][1]}}}}};a.jqplot.DateAxisRenderer.prototype.reset=function(){this.min=this._min;this.max=this._max;this.tickInterval=this._tickInterval;this.numberTicks=this._numberTicks;this.daTickInterval=this._daTickInterval};a.jqplot.DateAxisRenderer.prototype.createTicks=function(){var v=this._ticks;var r=this.ticks;var w=this.name;var u=this._dataBounds;var o,s;var m,p;var d,c;var b,q;if(r.length){for(q=0;q<r.length;q++){var f=r[q];var h=new this.tickRenderer(this.tickOptions);if(f.constructor==Array){h.value=Date.create(f[0]).getTime();h.label=f[1];if(!this.showTicks){h.showLabel=false;h.showMark=false}else{if(!this.showTickMarks){h.showMark=false}}h.setTick(h.value,this.name);this._ticks.push(h)}else{h.value=Date.create(f).getTime();if(!this.showTicks){h.showLabel=false;h.showMark=false}else{if(!this.showTickMarks){h.showMark=false}}h.setTick(h.value,this.name);this._ticks.push(h)}}this.numberTicks=r.length;this.min=this._ticks[0].value;this.max=this._ticks[this.numberTicks-1].value;this.daTickInterval=[(this.max-this.min)/(this.numberTicks-1)/1000,"seconds"]}else{if(w=="xaxis"||w=="x2axis"){o=this._plotDimensions.width}else{o=this._plotDimensions.height}if(this.min!=null&&this.max!=null&&this.numberTicks!=null){this.tickInterval=null}if(this.tickInterval!=null){if(Number(this.tickInterval)){this.daTickInterval=[Number(this.tickInterval),"seconds"]}else{if(typeof this.tickInterval=="string"){var k=this.tickInterval.split(" ");if(k.length==1){this.daTickInterval=[1,k[0]]}else{if(k.length==2){this.daTickInterval=[k[0],k[1]]}}}}}m=((this.min!=null)?Date.create(this.min).getTime():u.min);p=((this.max!=null)?Date.create(this.max).getTime():u.max);if(m==p){var g=24*60*60*500;m-=g;p+=g}var j=p-m;var l,n;l=(this.min!=null)?Date.create(this.min).getTime():m-j/2*(this.padMin-1);n=(this.max!=null)?Date.create(this.max).getTime():p+j/2*(this.padMax-1);this.min=l;this.max=n;j=this.max-this.min;if(this.numberTicks==null){if(this.daTickInterval!=null){var e=Date.create(this.max).diff(this.min,this.daTickInterval[1],true);this.numberTicks=Math.ceil(e/this.daTickInterval[0])+1;this.max=Date.create(this.min).add((this.numberTicks-1)*this.daTickInterval[0],this.daTickInterval[1]).getTime()}else{if(o>200){this.numberTicks=parseInt(3+(o-200)/100,10)}else{this.numberTicks=2}}}if(this.daTickInterval==null){this.daTickInterval=[j/(this.numberTicks-1)/1000,"seconds"]}for(var q=0;q<this.numberTicks;q++){var m=Date.create(this.min);b=m.add(q*this.daTickInterval[0],this.daTickInterval[1]).getTime();var h=new this.tickRenderer(this.tickOptions);if(!this.showTicks){h.showLabel=false;h.showMark=false}else{if(!this.showTickMarks){h.showMark=false}}h.setTick(b,this.name);this._ticks.push(h)}}if(this._daTickInterval==null){this._daTickInterval=this.daTickInterval}}})(jQuery);
|
|
@ -1,203 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2009 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* The author would appreciate an email letting him know of any substantial
|
||||
* use of jqPlot. You can reach the author at: chris dot leonello at gmail
|
||||
* dot com or see http://www.jqplot.com/info.php . This is, of course,
|
||||
* not required.
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* Thanks for using jqPlot!
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
|
||||
/**
|
||||
* Class: $.jqplot.Dragable
|
||||
* Plugin to make plotted points dragable by the user.
|
||||
*/
|
||||
$.jqplot.Dragable = function(options) {
|
||||
// Group: Properties
|
||||
this.markerRenderer = new $.jqplot.MarkerRenderer({shadow:false});
|
||||
this.shapeRenderer = new $.jqplot.ShapeRenderer();
|
||||
this.isDragging = false;
|
||||
this.isOver = false;
|
||||
this._ctx;
|
||||
this._elem;
|
||||
this._point;
|
||||
this._gridData;
|
||||
// prop: color
|
||||
// CSS color spec for the dragged point (and adjacent line segment or bar).
|
||||
this.color;
|
||||
// prop: constrainTo
|
||||
// Constrain dragging motion to an axis or to none.
|
||||
// Allowable values are 'none', 'x', 'y'
|
||||
this.constrainTo = 'none'; // 'x', 'y', or 'none';
|
||||
$.extend(true, this, options);
|
||||
};
|
||||
|
||||
function DragCanvas() {
|
||||
$.jqplot.GenericCanvas.call(this);
|
||||
this.isDragging = false;
|
||||
this.isOver = false;
|
||||
this._neighbor;
|
||||
this._cursors = [];
|
||||
}
|
||||
|
||||
DragCanvas.prototype = new $.jqplot.GenericCanvas();
|
||||
DragCanvas.prototype.constructor = DragCanvas;
|
||||
|
||||
|
||||
// called within scope of series
|
||||
$.jqplot.Dragable.parseOptions = function (defaults, opts) {
|
||||
var options = opts || {};
|
||||
this.plugins.dragable = new $.jqplot.Dragable(options.dragable);
|
||||
// since this function is called before series options are parsed,
|
||||
// we can set this here and it will be overridden if needed.
|
||||
this.isDragable = $.jqplot.config.enablePlugins;
|
||||
};
|
||||
|
||||
// called within context of plot
|
||||
// create a canvas which we can draw on.
|
||||
// insert it before the eventCanvas, so eventCanvas will still capture events.
|
||||
// add a new DragCanvas object to the plot plugins to handle drawing on this new canvas.
|
||||
$.jqplot.Dragable.postPlotDraw = function() {
|
||||
this.plugins.dragable = {previousCursor:'auto', isOver:false};
|
||||
this.plugins.dragable.dragCanvas = new DragCanvas();
|
||||
|
||||
this.eventCanvas._elem.before(this.plugins.dragable.dragCanvas.createElement(this._gridPadding, 'jqplot-dragable-canvas', this._plotDimensions));
|
||||
var dctx = this.plugins.dragable.dragCanvas.setContext();
|
||||
};
|
||||
|
||||
//$.jqplot.preInitHooks.push($.jqplot.Dragable.init);
|
||||
$.jqplot.preParseSeriesOptionsHooks.push($.jqplot.Dragable.parseOptions);
|
||||
$.jqplot.postDrawHooks.push($.jqplot.Dragable.postPlotDraw);
|
||||
$.jqplot.eventListenerHooks.push(['jqplotMouseMove', handleMove]);
|
||||
$.jqplot.eventListenerHooks.push(['jqplotMouseDown', handleDown]);
|
||||
$.jqplot.eventListenerHooks.push(['jqplotMouseUp', handleUp]);
|
||||
|
||||
|
||||
function initDragPoint(plot, neighbor) {
|
||||
var s = plot.series[neighbor.seriesIndex];
|
||||
var drag = s.plugins.dragable;
|
||||
|
||||
// first, init the mark renderer for the dragged point
|
||||
var smr = s.markerRenderer;
|
||||
var mr = drag.markerRenderer;
|
||||
mr.style = smr.style;
|
||||
mr.lineWidth = smr.lineWidth + 2.5;
|
||||
mr.size = smr.size + 5;
|
||||
if (!drag.color) {
|
||||
var rgba = $.jqplot.getColorComponents(smr.color);
|
||||
var newrgb = [rgba[0], rgba[1], rgba[2]];
|
||||
var alpha = (rgba[3] >= 0.6) ? rgba[3]*0.6 : rgba[3]*(2-rgba[3]);
|
||||
drag.color = 'rgba('+newrgb[0]+','+newrgb[1]+','+newrgb[2]+','+alpha+')';
|
||||
}
|
||||
mr.color = drag.color;
|
||||
mr.init();
|
||||
|
||||
var start = (neighbor.pointIndex > 0) ? neighbor.pointIndex - 1 : 0;
|
||||
var end = neighbor.pointIndex+2;
|
||||
drag._gridData = s.gridData.slice(start, end);
|
||||
}
|
||||
|
||||
function handleMove(ev, gridpos, datapos, neighbor, plot) {
|
||||
if (plot.plugins.dragable.dragCanvas.isDragging) {
|
||||
var dc = plot.plugins.dragable.dragCanvas;
|
||||
var dp = dc._neighbor;
|
||||
var s = plot.series[dp.seriesIndex];
|
||||
var drag = s.plugins.dragable;
|
||||
var gd = s.gridData;
|
||||
|
||||
// compute the new grid position with any constraints.
|
||||
var x = (drag.constrainTo == 'y') ? dp.gridData[0] : gridpos.x;
|
||||
var y = (drag.constrainTo == 'x') ? dp.gridData[1] : gridpos.y;
|
||||
|
||||
// compute data values for any listeners.
|
||||
var xu = s._xaxis.series_p2u(x);
|
||||
var yu = s._yaxis.series_p2u(y);
|
||||
|
||||
// clear the canvas then redraw effect at new position.
|
||||
var ctx = dc._ctx;
|
||||
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
||||
|
||||
// adjust our gridData for the new mouse position
|
||||
if (dp.pointIndex > 0) {
|
||||
drag._gridData[1] = [x, y];
|
||||
}
|
||||
else {
|
||||
drag._gridData[0] = [x, y];
|
||||
}
|
||||
plot.series[dp.seriesIndex].draw(dc._ctx, {gridData:drag._gridData, shadow:false, preventJqPlotSeriesDrawTrigger:true, color:drag.color, markerOptions:{color:drag.color, shadow:false}, trendline:{show:false}});
|
||||
plot.target.trigger('jqplotSeriesPointChange', [dp.seriesIndex, dp.pointIndex, [xu,yu], [x,y]]);
|
||||
}
|
||||
else if (neighbor != null) {
|
||||
var series = plot.series[neighbor.seriesIndex];
|
||||
if (series.isDragable) {
|
||||
var dc = plot.plugins.dragable.dragCanvas;
|
||||
if (!dc.isOver) {
|
||||
dc._cursors.push(ev.target.style.cursor);
|
||||
ev.target.style.cursor = "pointer";
|
||||
}
|
||||
dc.isOver = true;
|
||||
}
|
||||
}
|
||||
else if (neighbor == null) {
|
||||
var dc = plot.plugins.dragable.dragCanvas;
|
||||
if (dc.isOver) {
|
||||
ev.target.style.cursor = dc._cursors.pop();
|
||||
dc.isOver = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handleDown(ev, gridpos, datapos, neighbor, plot) {
|
||||
var dc = plot.plugins.dragable.dragCanvas;
|
||||
dc._cursors.push(ev.target.style.cursor);
|
||||
if (neighbor != null) {
|
||||
var s = plot.series[neighbor.seriesIndex];
|
||||
var drag = s.plugins.dragable;
|
||||
if (s.isDragable && !dc.isDragging) {
|
||||
dc._neighbor = neighbor;
|
||||
dc.isDragging = true;
|
||||
initDragPoint(plot, neighbor);
|
||||
drag.markerRenderer.draw(s.gridData[neighbor.pointIndex][0], s.gridData[neighbor.pointIndex][1], dc._ctx);
|
||||
ev.target.style.cursor = "move";
|
||||
}
|
||||
}
|
||||
// Just in case of a hickup, we'll clear the drag canvas and reset.
|
||||
else {
|
||||
var ctx = dc._ctx;
|
||||
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
||||
dc.isDragging = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleUp(ev, gridpos, datapos, neighbor, plot) {
|
||||
if (plot.plugins.dragable.dragCanvas.isDragging) {
|
||||
var dc = plot.plugins.dragable.dragCanvas;
|
||||
// clear the canvas
|
||||
var ctx = dc._ctx;
|
||||
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
||||
dc.isDragging = false;
|
||||
// redraw the series canvas at the new point.
|
||||
var dp = dc._neighbor;
|
||||
var s = plot.series[dp.seriesIndex];
|
||||
var drag = s.plugins.dragable;
|
||||
// compute the new grid position with any constraints.
|
||||
var x = (drag.constrainTo == 'y') ? dp.data[0] : datapos[s.xaxis];
|
||||
var y = (drag.constrainTo == 'x') ? dp.data[1] : datapos[s.yaxis];
|
||||
// var x = datapos[s.xaxis];
|
||||
// var y = datapos[s.yaxis];
|
||||
s.data[dp.pointIndex] = [x,y];
|
||||
plot.drawSeries({preventJqPlotSeriesDrawTrigger:true}, dp.seriesIndex);
|
||||
dc._neighbor = null;
|
||||
ev.target.style.cursor = dc._cursors.pop();
|
||||
}
|
||||
}
|
||||
})(jQuery);
|
|
@ -1,14 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2009 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris dot leonello at gmail dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*/
|
||||
(function(d){d.jqplot.Dragable=function(g){this.markerRenderer=new d.jqplot.MarkerRenderer({shadow:false});this.shapeRenderer=new d.jqplot.ShapeRenderer();this.isDragging=false;this.isOver=false;this._ctx;this._elem;this._point;this._gridData;this.color;this.constrainTo="none";d.extend(true,this,g)};function b(){d.jqplot.GenericCanvas.call(this);this.isDragging=false;this.isOver=false;this._neighbor;this._cursors=[]}b.prototype=new d.jqplot.GenericCanvas();b.prototype.constructor=b;d.jqplot.Dragable.parseOptions=function(i,h){var g=h||{};this.plugins.dragable=new d.jqplot.Dragable(g.dragable);this.isDragable=d.jqplot.config.enablePlugins};d.jqplot.Dragable.postPlotDraw=function(){this.plugins.dragable={previousCursor:"auto",isOver:false};this.plugins.dragable.dragCanvas=new b();this.eventCanvas._elem.before(this.plugins.dragable.dragCanvas.createElement(this._gridPadding,"jqplot-dragable-canvas",this._plotDimensions));var g=this.plugins.dragable.dragCanvas.setContext()};d.jqplot.preParseSeriesOptionsHooks.push(d.jqplot.Dragable.parseOptions);d.jqplot.postDrawHooks.push(d.jqplot.Dragable.postPlotDraw);d.jqplot.eventListenerHooks.push(["jqplotMouseMove",e]);d.jqplot.eventListenerHooks.push(["jqplotMouseDown",c]);d.jqplot.eventListenerHooks.push(["jqplotMouseUp",a]);function f(n,p){var q=n.series[p.seriesIndex];var m=q.plugins.dragable;var h=q.markerRenderer;var i=m.markerRenderer;i.style=h.style;i.lineWidth=h.lineWidth+2.5;i.size=h.size+5;if(!m.color){var l=d.jqplot.getColorComponents(h.color);var o=[l[0],l[1],l[2]];var k=(l[3]>=0.6)?l[3]*0.6:l[3]*(2-l[3]);m.color="rgba("+o[0]+","+o[1]+","+o[2]+","+k+")"}i.color=m.color;i.init();var g=(p.pointIndex>0)?p.pointIndex-1:0;var j=p.pointIndex+2;m._gridData=q.gridData.slice(g,j)}function e(o,l,h,t,m){if(m.plugins.dragable.dragCanvas.isDragging){var u=m.plugins.dragable.dragCanvas;var i=u._neighbor;var w=m.series[i.seriesIndex];var k=w.plugins.dragable;var r=w.gridData;var p=(k.constrainTo=="y")?i.gridData[0]:l.x;var n=(k.constrainTo=="x")?i.gridData[1]:l.y;var g=w._xaxis.series_p2u(p);var q=w._yaxis.series_p2u(n);var v=u._ctx;v.clearRect(0,0,v.canvas.width,v.canvas.height);if(i.pointIndex>0){k._gridData[1]=[p,n]}else{k._gridData[0]=[p,n]}m.series[i.seriesIndex].draw(u._ctx,{gridData:k._gridData,shadow:false,preventJqPlotSeriesDrawTrigger:true,color:k.color,markerOptions:{color:k.color,shadow:false},trendline:{show:false}});m.target.trigger("jqplotSeriesPointChange",[i.seriesIndex,i.pointIndex,[g,q],[p,n]])}else{if(t!=null){var j=m.series[t.seriesIndex];if(j.isDragable){var u=m.plugins.dragable.dragCanvas;if(!u.isOver){u._cursors.push(o.target.style.cursor);o.target.style.cursor="pointer"}u.isOver=true}}else{if(t==null){var u=m.plugins.dragable.dragCanvas;if(u.isOver){o.target.style.cursor=u._cursors.pop();u.isOver=false}}}}}function c(k,i,g,l,j){var m=j.plugins.dragable.dragCanvas;m._cursors.push(k.target.style.cursor);if(l!=null){var o=j.series[l.seriesIndex];var h=o.plugins.dragable;if(o.isDragable&&!m.isDragging){m._neighbor=l;m.isDragging=true;f(j,l);h.markerRenderer.draw(o.gridData[l.pointIndex][0],o.gridData[l.pointIndex][1],m._ctx);k.target.style.cursor="move"}}else{var n=m._ctx;n.clearRect(0,0,n.canvas.width,n.canvas.height);m.isDragging=false}}function a(m,j,g,o,k){if(k.plugins.dragable.dragCanvas.isDragging){var p=k.plugins.dragable.dragCanvas;var q=p._ctx;q.clearRect(0,0,q.canvas.width,q.canvas.height);p.isDragging=false;var h=p._neighbor;var r=k.series[h.seriesIndex];var i=r.plugins.dragable;var n=(i.constrainTo=="y")?h.data[0]:g[r.xaxis];var l=(i.constrainTo=="x")?h.data[1]:g[r.yaxis];r.data[h.pointIndex]=[n,l];k.drawSeries({preventJqPlotSeriesDrawTrigger:true},h.seriesIndex);p._neighbor=null;m.target.style.cursor=p._cursors.pop()}}})(jQuery);
|
|
@ -1,359 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2009 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* The author would appreciate an email letting him know of any substantial
|
||||
* use of jqPlot. You can reach the author at: chris dot leonello at gmail
|
||||
* dot com or see http://www.jqplot.com/info.php . This is, of course,
|
||||
* not required.
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* Thanks for using jqPlot!
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
$.jqplot.eventListenerHooks.push(['jqplotMouseMove', handleMove]);
|
||||
|
||||
/**
|
||||
* Class: $.jqplot.Highlighter
|
||||
* Plugin which will highlight data points when they are moused over.
|
||||
*
|
||||
* To use this plugin, include the js
|
||||
* file in your source:
|
||||
*
|
||||
* > <script type="text/javascript" src="plugins/jqplot.highlighter.js"></script>
|
||||
*
|
||||
* A tooltip providing information about the data point is enabled by default.
|
||||
* To disable the tooltip, set "showTooltip" to false.
|
||||
*
|
||||
* You can control what data is displayed in the tooltip with various
|
||||
* options. The "tooltipAxes" option controls wether the x, y or both
|
||||
* data values are displayed.
|
||||
*
|
||||
* Some chart types (e.g. hi-low-close) have more than one y value per
|
||||
* data point. To display the additional values in the tooltip, set the
|
||||
* "yvalues" option to the desired number of y values present (3 for a hlc chart).
|
||||
*
|
||||
* By default, data values will be formatted with the same formatting
|
||||
* specifiers as used to format the axis ticks. A custom format code
|
||||
* can be supplied with the tooltipFormatString option. This will apply
|
||||
* to all values in the tooltip.
|
||||
*
|
||||
* For more complete control, the "formatString" option can be set. This
|
||||
* Allows conplete control over tooltip formatting. Values are passed to
|
||||
* the format string in an order determined by the "tooltipAxes" and "yvalues"
|
||||
* options. So, if you have a hi-low-close chart and you just want to display
|
||||
* the hi-low-close values in the tooltip, you could set a formatString like:
|
||||
*
|
||||
* > highlighter: {
|
||||
* > tooltipAxes: 'y',
|
||||
* > yvalues: 3,
|
||||
* > formatString:'<table class="jqplot-highlighter">
|
||||
* > <tr><td>hi:</td><td>%s</td></tr>
|
||||
* > <tr><td>low:</td><td>%s</td></tr>
|
||||
* > <tr><td>close:</td><td>%s</td></tr></table>'
|
||||
* > }
|
||||
*
|
||||
*/
|
||||
$.jqplot.Highlighter = function(options) {
|
||||
// Group: Properties
|
||||
//
|
||||
//prop: show
|
||||
// true to show the highlight.
|
||||
this.show = $.jqplot.config.enablePlugins;
|
||||
// prop: markerRenderer
|
||||
// Renderer used to draw the marker of the highlighted point.
|
||||
// Renderer will assimilate attributes from the data point being highlighted,
|
||||
// so no attributes need set on the renderer directly.
|
||||
// Default is to turn off shadow drawing on the highlighted point.
|
||||
this.markerRenderer = new $.jqplot.MarkerRenderer({shadow:false});
|
||||
// prop: showMarker
|
||||
// true to show the marker
|
||||
this.showMarker = true;
|
||||
// prop: lineWidthAdjust
|
||||
// Pixels to add to the lineWidth of the highlight.
|
||||
this.lineWidthAdjust = 2.5;
|
||||
// prop: sizeAdjust
|
||||
// Pixels to add to the overall size of the highlight.
|
||||
this.sizeAdjust = 5;
|
||||
// prop: showTooltip
|
||||
// Show a tooltip with data point values.
|
||||
this.showTooltip = true;
|
||||
// prop: tooltipLocation
|
||||
// Where to position tooltip, 'n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw'
|
||||
this.tooltipLocation = 'nw';
|
||||
// prop: tooltipFade
|
||||
// true = fade in/out tooltip, flase = show/hide tooltip
|
||||
this.fadeTooltip = true;
|
||||
// prop: tooltipFadeSpeed
|
||||
// 'slow', 'def', 'fast', or number of milliseconds.
|
||||
this.tooltipFadeSpeed = "fast";
|
||||
// prop: tooltipOffset
|
||||
// Pixel offset of tooltip from the highlight.
|
||||
this.tooltipOffset = 2;
|
||||
// prop: tooltipAxes
|
||||
// Which axes to display in tooltip, 'x', 'y' or 'both', 'xy' or 'yx'
|
||||
// 'both' and 'xy' are equivalent, 'yx' reverses order of labels.
|
||||
this.tooltipAxes = 'both';
|
||||
// prop; tooltipSeparator
|
||||
// String to use to separate x and y axes in tooltip.
|
||||
this.tooltipSeparator = ', ';
|
||||
// prop: useAxesFormatters
|
||||
// Use the x and y axes formatters to format the text in the tooltip.
|
||||
this.useAxesFormatters = true;
|
||||
// prop: tooltipFormatString
|
||||
// sprintf format string for the tooltip.
|
||||
// Uses Ash Searle's javascript sprintf implementation
|
||||
// found here: http://hexmen.com/blog/2007/03/printf-sprintf/
|
||||
// See http://perldoc.perl.org/functions/sprintf.html for reference.
|
||||
// Additional "p" and "P" format specifiers added by Chris Leonello.
|
||||
this.tooltipFormatString = '%.5P';
|
||||
// prop: formatString
|
||||
// alternative to tooltipFormatString
|
||||
// will format the whole tooltip text, populating with x, y values as
|
||||
// indicated by tooltipAxes option. So, you could have a tooltip like:
|
||||
// 'Date: %s, number of cats: %d' to format the whole tooltip at one go.
|
||||
// If useAxesFormatters is true, values will be formatted according to
|
||||
// Axes formatters and you can populate your tooltip string with
|
||||
// %s placeholders.
|
||||
this.formatString = null;
|
||||
// prop: yvalues
|
||||
// Number of y values to expect in the data point array.
|
||||
// Typically this is 1. Certain plots, like OHLC, will
|
||||
// have more y values in each data point array.
|
||||
this.yvalues = 1;
|
||||
this._tooltipElem;
|
||||
this.isHighlighting = false;
|
||||
|
||||
$.extend(true, this, options);
|
||||
};
|
||||
|
||||
// axis.renderer.tickrenderer.formatter
|
||||
|
||||
// called with scope of plot
|
||||
$.jqplot.Highlighter.init = function (target, data, opts){
|
||||
var options = opts || {};
|
||||
// add a highlighter attribute to the plot
|
||||
this.plugins.highlighter = new $.jqplot.Highlighter(options.highlighter);
|
||||
};
|
||||
|
||||
// called within scope of series
|
||||
$.jqplot.Highlighter.parseOptions = function (defaults, options) {
|
||||
this.showHighlight = true;
|
||||
};
|
||||
|
||||
// called within context of plot
|
||||
// create a canvas which we can draw on.
|
||||
// insert it before the eventCanvas, so eventCanvas will still capture events.
|
||||
$.jqplot.Highlighter.postPlotDraw = function() {
|
||||
this.plugins.highlighter.highlightCanvas = new $.jqplot.GenericCanvas();
|
||||
|
||||
this.eventCanvas._elem.before(this.plugins.highlighter.highlightCanvas.createElement(this._gridPadding, 'jqplot-highlight-canvas', this._plotDimensions));
|
||||
var hctx = this.plugins.highlighter.highlightCanvas.setContext();
|
||||
|
||||
var p = this.plugins.highlighter;
|
||||
p._tooltipElem = $('<div class="jqplot-highlighter-tooltip" style="position:absolute;display:none"></div>');
|
||||
this.target.append(p._tooltipElem);
|
||||
};
|
||||
|
||||
$.jqplot.preInitHooks.push($.jqplot.Highlighter.init);
|
||||
$.jqplot.preParseSeriesOptionsHooks.push($.jqplot.Highlighter.parseOptions);
|
||||
$.jqplot.postDrawHooks.push($.jqplot.Highlighter.postPlotDraw);
|
||||
|
||||
function draw(plot, neighbor) {
|
||||
var hl = plot.plugins.highlighter;
|
||||
var s = plot.series[neighbor.seriesIndex];
|
||||
var smr = s.markerRenderer;
|
||||
var mr = hl.markerRenderer;
|
||||
mr.style = smr.style;
|
||||
mr.lineWidth = smr.lineWidth + hl.lineWidthAdjust;
|
||||
mr.size = smr.size + hl.sizeAdjust;
|
||||
var rgba = $.jqplot.getColorComponents(smr.color);
|
||||
var newrgb = [rgba[0], rgba[1], rgba[2]];
|
||||
var alpha = (rgba[3] >= 0.6) ? rgba[3]*0.6 : rgba[3]*(2-rgba[3]);
|
||||
mr.color = 'rgba('+newrgb[0]+','+newrgb[1]+','+newrgb[2]+','+alpha+')';
|
||||
mr.init();
|
||||
mr.draw(s.gridData[neighbor.pointIndex][0], s.gridData[neighbor.pointIndex][1], hl.highlightCanvas._ctx);
|
||||
}
|
||||
|
||||
function showTooltip(plot, series, neighbor) {
|
||||
// neighbor looks like: {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]}
|
||||
// gridData should be x,y pixel coords on the grid.
|
||||
// add the plot._gridPadding to that to get x,y in the target.
|
||||
var hl = plot.plugins.highlighter;
|
||||
var elem = hl._tooltipElem;
|
||||
if (hl.useAxesFormatters) {
|
||||
var xf = series._xaxis._ticks[0].formatter;
|
||||
var yf = series._yaxis._ticks[0].formatter;
|
||||
var xfstr = series._xaxis._ticks[0].formatString;
|
||||
var yfstr = series._yaxis._ticks[0].formatString;
|
||||
var str;
|
||||
var xstr = xf(xfstr, neighbor.data[0]);
|
||||
var ystrs = [];
|
||||
for (var i=1; i<hl.yvalues+1; i++) {
|
||||
ystrs.push(yf(yfstr, neighbor.data[i]));
|
||||
}
|
||||
if (hl.formatString) {
|
||||
switch (hl.tooltipAxes) {
|
||||
case 'both':
|
||||
case 'xy':
|
||||
ystrs.unshift(xstr);
|
||||
ystrs.unshift(hl.formatString);
|
||||
str = $.jqplot.sprintf.apply($.jqplot.sprintf, ystrs);
|
||||
break;
|
||||
case 'yx':
|
||||
ystrs.push(xstr);
|
||||
ystrs.unshift(hl.formatString);
|
||||
str = $.jqplot.sprintf.apply($.jqplot.sprintf, ystrs);
|
||||
break;
|
||||
case 'x':
|
||||
str = $.jqplot.sprintf.apply($.jqplot.sprintf, [hl.formatString, xstr]);
|
||||
break;
|
||||
case 'y':
|
||||
ystrs.unshift(hl.formatString);
|
||||
str = $.jqplot.sprintf.apply($.jqplot.sprintf, ystrs);
|
||||
break;
|
||||
default: // same as xy
|
||||
ystrs.unshift(xstr);
|
||||
ystrs.unshift(hl.formatString);
|
||||
str = $.jqplot.sprintf.apply($.jqplot.sprintf, ystrs);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch (hl.tooltipAxes) {
|
||||
case 'both':
|
||||
case 'xy':
|
||||
str = xstr;
|
||||
for (var i=0; i<ystrs.length; i++) {
|
||||
str += hl.tooltipSeparator + ystrs[i];
|
||||
}
|
||||
break;
|
||||
case 'yx':
|
||||
str = '';
|
||||
for (var i=0; i<ystrs.length; i++) {
|
||||
str += ystrs[i] + hl.tooltipSeparator;
|
||||
}
|
||||
str += xstr;
|
||||
break;
|
||||
case 'x':
|
||||
str = xstr;
|
||||
break;
|
||||
case 'y':
|
||||
str = '';
|
||||
for (var i=0; i<ystrs.length; i++) {
|
||||
str += ystrs[i] + hl.tooltipSeparator;
|
||||
}
|
||||
break;
|
||||
default: // same as 'xy'
|
||||
str = xstr;
|
||||
for (var i=0; i<ystrs.length; i++) {
|
||||
str += hl.tooltipSeparator + ystrs[i];
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
var str;
|
||||
if (hl.tooltipAxes == 'both' || hl.tooltipAxes == 'xy') {
|
||||
str = $.jqplot.sprintf(hl.tooltipFormatString, neighbor.data[0]) + hl.tooltipSeparator + $.jqplot.sprintf(hl.tooltipFormatString, neighbor.data[1]);
|
||||
}
|
||||
else if (hl.tooltipAxes == 'yx') {
|
||||
str = $.jqplot.sprintf(hl.tooltipFormatString, neighbor.data[1]) + hl.tooltipSeparator + $.jqplot.sprintf(hl.tooltipFormatString, neighbor.data[0]);
|
||||
}
|
||||
else if (hl.tooltipAxes == 'x') {
|
||||
str = $.jqplot.sprintf(hl.tooltipFormatString, neighbor.data[0]);
|
||||
}
|
||||
else if (hl.tooltipAxes == 'y') {
|
||||
str = $.jqplot.sprintf(hl.tooltipFormatString, neighbor.data[1]);
|
||||
}
|
||||
}
|
||||
elem.html(str);
|
||||
var gridpos = {x:neighbor.gridData[0], y:neighbor.gridData[1]};
|
||||
var ms = 0;
|
||||
var fact = 0.707;
|
||||
if (series.markerRenderer.show == true) {
|
||||
ms = (series.markerRenderer.size + hl.sizeAdjust)/2;
|
||||
}
|
||||
switch (hl.tooltipLocation) {
|
||||
case 'nw':
|
||||
var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true) - hl.tooltipOffset - fact * ms;
|
||||
var y = gridpos.y + plot._gridPadding.top - hl.tooltipOffset - elem.outerHeight(true) - fact * ms;
|
||||
break;
|
||||
case 'n':
|
||||
var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true)/2;
|
||||
var y = gridpos.y + plot._gridPadding.top - hl.tooltipOffset - elem.outerHeight(true) - ms;
|
||||
break;
|
||||
case 'ne':
|
||||
var x = gridpos.x + plot._gridPadding.left + hl.tooltipOffset + fact * ms;
|
||||
var y = gridpos.y + plot._gridPadding.top - hl.tooltipOffset - elem.outerHeight(true) - fact * ms;
|
||||
break;
|
||||
case 'e':
|
||||
var x = gridpos.x + plot._gridPadding.left + hl.tooltipOffset + ms;
|
||||
var y = gridpos.y + plot._gridPadding.top - elem.outerHeight(true)/2;
|
||||
break;
|
||||
case 'se':
|
||||
var x = gridpos.x + plot._gridPadding.left + hl.tooltipOffset + fact * ms;
|
||||
var y = gridpos.y + plot._gridPadding.top + hl.tooltipOffset + fact * ms;
|
||||
break;
|
||||
case 's':
|
||||
var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true)/2;
|
||||
var y = gridpos.y + plot._gridPadding.top + hl.tooltipOffset + ms;
|
||||
break;
|
||||
case 'sw':
|
||||
var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true) - hl.tooltipOffset - fact * ms;
|
||||
var y = gridpos.y + plot._gridPadding.top + hl.tooltipOffset + fact * ms;
|
||||
break;
|
||||
case 'w':
|
||||
var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true) - hl.tooltipOffset - ms;
|
||||
var y = gridpos.y + plot._gridPadding.top - elem.outerHeight(true)/2;
|
||||
break;
|
||||
default: // same as 'nw'
|
||||
var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true) - hl.tooltipOffset - fact * ms;
|
||||
var y = gridpos.y + plot._gridPadding.top - hl.tooltipOffset - elem.outerHeight(true) - fact * ms;
|
||||
break;
|
||||
}
|
||||
elem.css('left', x);
|
||||
elem.css('top', y);
|
||||
if (hl.fadeTooltip) {
|
||||
elem.fadeIn(hl.tooltipFadeSpeed);
|
||||
}
|
||||
else {
|
||||
elem.show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function handleMove(ev, gridpos, datapos, neighbor, plot) {
|
||||
var hl = plot.plugins.highlighter;
|
||||
if (hl.show) {
|
||||
if (neighbor == null && hl.isHighlighting) {
|
||||
var ctx = hl.highlightCanvas._ctx;
|
||||
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
||||
if (hl.fadeTooltip) {
|
||||
hl._tooltipElem.fadeOut(hl.tooltipFadeSpeed);
|
||||
}
|
||||
else {
|
||||
hl._tooltipElem.hide();
|
||||
}
|
||||
hl.isHighlighting = false;
|
||||
|
||||
}
|
||||
if (neighbor != null && plot.series[neighbor.seriesIndex].showHighlight && !hl.isHighlighting) {
|
||||
hl.isHighlighting = true;
|
||||
if (hl.showMarker) {
|
||||
draw(plot, neighbor);
|
||||
}
|
||||
if (hl.showTooltip) {
|
||||
showTooltip(plot, plot.series[neighbor.seriesIndex], neighbor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})(jQuery);
|
File diff suppressed because one or more lines are too long
|
@ -1,434 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2009 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* The author would appreciate an email letting him know of any substantial
|
||||
* use of jqPlot. You can reach the author at: chris dot leonello at gmail
|
||||
* dot com or see http://www.jqplot.com/info.php . This is, of course,
|
||||
* not required.
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* Thanks for using jqPlot!
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
/**
|
||||
* class: $.jqplot.LogAxisRenderer
|
||||
* A plugin for a jqPlot to render a logarithmic axis.
|
||||
*
|
||||
* To use this renderer, include the plugin in your source
|
||||
* > <script type="text/javascript" language="javascript" src="plugins/jqplot.logAxisRenderer.js"></script>
|
||||
*
|
||||
* and supply the appropriate options to your plot
|
||||
*
|
||||
* > {axes:{xaxis:{renderer:$.jqplot.LogAxisRenderer}}}
|
||||
**/
|
||||
$.jqplot.LogAxisRenderer = function() {
|
||||
$.jqplot.LinearAxisRenderer.call(this);
|
||||
// prop: axisDefaults
|
||||
// Default properties which will be applied directly to the series.
|
||||
//
|
||||
// Group: Properties
|
||||
//
|
||||
// Properties
|
||||
//
|
||||
/// base - the logarithmic base, commonly 2, 10 or Math.E
|
||||
// tickDistribution - 'even' or 'power'. 'even' gives equal pixel
|
||||
// spacing of the ticks on the plot. 'power' gives ticks in powers
|
||||
// of 10.
|
||||
this.axisDefaults = {
|
||||
base : 10,
|
||||
tickDistribution :'even'
|
||||
};
|
||||
};
|
||||
|
||||
$.jqplot.LogAxisRenderer.prototype = new $.jqplot.LinearAxisRenderer();
|
||||
$.jqplot.LogAxisRenderer.prototype.constructor = $.jqplot.LogAxisRenderer;
|
||||
|
||||
$.jqplot.LogAxisRenderer.prototype.init = function(options) {
|
||||
// prop: tickRenderer
|
||||
// A class of a rendering engine for creating the ticks labels displayed on the plot,
|
||||
// See <$.jqplot.AxisTickRenderer>.
|
||||
// this.tickRenderer = $.jqplot.AxisTickRenderer;
|
||||
// this.labelRenderer = $.jqplot.AxisLabelRenderer;
|
||||
$.extend(true, this.renderer, options);
|
||||
for (var d in this.renderer.axisDefaults) {
|
||||
if (this[d] == null) {
|
||||
this[d] = this.renderer.axisDefaults[d];
|
||||
}
|
||||
}
|
||||
var db = this._dataBounds;
|
||||
// Go through all the series attached to this axis and find
|
||||
// the min/max bounds for this axis.
|
||||
for (var i=0; i<this._series.length; i++) {
|
||||
var s = this._series[i];
|
||||
var d = s.data;
|
||||
|
||||
for (var j=0; j<d.length; j++) {
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis') {
|
||||
if (d[j][0] > db.max || db.max == null) {
|
||||
db.max = d[j][0];
|
||||
}
|
||||
if (d[j][0] > db.max || db.max == null) {
|
||||
db.max = d[j][0];
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (d[j][1] < db.min || db.min == null) {
|
||||
db.min = d[j][1];
|
||||
}
|
||||
if (d[j][1] > db.max || db.max == null) {
|
||||
db.max = d[j][1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$.jqplot.LogAxisRenderer.prototype.createTicks = function() {
|
||||
// we're are operating on an axis here
|
||||
var ticks = this._ticks;
|
||||
var userTicks = this.ticks;
|
||||
var name = this.name;
|
||||
var db = this._dataBounds;
|
||||
var dim, interval;
|
||||
var min, max;
|
||||
var pos1, pos2;
|
||||
var tt, i;
|
||||
|
||||
// if we already have ticks, use them.
|
||||
// ticks must be in order of increasing value.
|
||||
if (userTicks.length) {
|
||||
// ticks could be 1D or 2D array of [val, val, ,,,] or [[val, label], [val, label], ...] or mixed
|
||||
for (i=0; i<userTicks.length; i++){
|
||||
var ut = userTicks[i];
|
||||
var t = new this.tickRenderer(this.tickOptions);
|
||||
if (ut.constructor == Array) {
|
||||
t.value = ut[0];
|
||||
t.label = ut[1];
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(ut[0], this.name);
|
||||
this._ticks.push(t);
|
||||
}
|
||||
|
||||
else {
|
||||
t.value = ut;
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(ut, this.name);
|
||||
this._ticks.push(t);
|
||||
}
|
||||
}
|
||||
this.numberTicks = userTicks.length;
|
||||
this.min = this._ticks[0].value;
|
||||
this.max = this._ticks[this.numberTicks-1].value;
|
||||
}
|
||||
|
||||
// we don't have any ticks yet, let's make some!
|
||||
else {
|
||||
if (name == 'xaxis' || name == 'x2axis') {
|
||||
dim = this._plotDimensions.width;
|
||||
}
|
||||
else {
|
||||
dim = this._plotDimensions.height;
|
||||
}
|
||||
|
||||
min = ((this.min != null) ? this.min : db.min);
|
||||
max = ((this.max != null) ? this.max : db.max);
|
||||
|
||||
// if min and max are same, space them out a bit
|
||||
if (min == max) {
|
||||
var adj = 0.05;
|
||||
min = min*(1-adj);
|
||||
max = max*(1+adj);
|
||||
}
|
||||
|
||||
// perform some checks
|
||||
if (this.min != null && this.min <= 0) {
|
||||
throw('log axis minimum must be greater than 0');
|
||||
}
|
||||
if (this.max != null && this.max <= 0) {
|
||||
throw('log axis maximum must be greater than 0');
|
||||
}
|
||||
// if (this.pad >1.99) this.pad = 1.99;
|
||||
var range = max - min;
|
||||
var rmin, rmax;
|
||||
|
||||
if (this.tickDistribution == 'even') {
|
||||
rmin = (this.min != null) ? this.min : min - min*((this.padMin-1)/2);
|
||||
rmax = (this.max != null) ? this.max : max + max*((this.padMax-1)/2);
|
||||
this.min = rmin;
|
||||
this.max = rmax;
|
||||
range = this.max - this.min;
|
||||
|
||||
if (this.numberTicks == null){
|
||||
if (dim > 100) {
|
||||
this.numberTicks = parseInt(3+(dim-100)/75, 10);
|
||||
}
|
||||
else {
|
||||
this.numberTicks = 2;
|
||||
}
|
||||
}
|
||||
|
||||
var u = Math.pow(this.base, (1/(this.numberTicks-1)*Math.log(this.max/this.min)/Math.log(this.base)));
|
||||
for (var i=0; i<this.numberTicks; i++){
|
||||
tt = this.min * Math.pow(u, i);
|
||||
var t = new this.tickRenderer(this.tickOptions);
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(tt, this.name);
|
||||
this._ticks.push(t);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
else if (this.tickDistribution == 'power'){
|
||||
// for power distribution, open up range to get a nice power of axis.renderer.base.
|
||||
// power distribution won't respect the user's min/max settings.
|
||||
rmin = Math.pow(this.base, Math.ceil(Math.log(min*(2-this.padMin))/Math.log(this.base))-1);
|
||||
rmax = Math.pow(this.base, Math.floor(Math.log(max*this.padMax)/Math.log(this.base))+1);
|
||||
this.min = rmin;
|
||||
this.max = rmax;
|
||||
range = this.max - this.min;
|
||||
|
||||
var fittedTicks = 0;
|
||||
var minorTicks = 0;
|
||||
if (this.numberTicks == null){
|
||||
if (dim > 100) {
|
||||
this.numberTicks = Math.round(Math.log(this.max/this.min)/Math.log(this.base) + 1);
|
||||
if (this.numberTicks < 2) {
|
||||
this.numberTicks = 2;
|
||||
}
|
||||
fittedTicks = parseInt(3+(dim-100)/75, 10);
|
||||
}
|
||||
else {
|
||||
this.numberTicks = 2;
|
||||
fittedTicks = 2;
|
||||
}
|
||||
// if we don't have enough ticks, add some intermediate ticks
|
||||
// how many to have between major ticks.
|
||||
if (this.numberTicks < fittedTicks-1) {
|
||||
minorTicks = Math.floor(fittedTicks/this.numberTicks);
|
||||
}
|
||||
}
|
||||
|
||||
for (var i=0; i<this.numberTicks; i++){
|
||||
tt = Math.pow(this.base, i - this.numberTicks + 1) * this.max;
|
||||
var t = new this.tickRenderer(this.tickOptions);
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(tt, this.name);
|
||||
this._ticks.push(t);
|
||||
|
||||
if (minorTicks && i<this.numberTicks-1) {
|
||||
var tt1 = Math.pow(this.base, i - this.numberTicks + 2) * this.max;
|
||||
var spread = tt1 - tt;
|
||||
var interval = tt1 / (minorTicks+1);
|
||||
for (var j=minorTicks-1; j>=0; j--) {
|
||||
var val = tt1-interval*(j+1);
|
||||
var t = new this.tickRenderer(this.tickOptions);
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(val, this.name);
|
||||
this._ticks.push(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$.jqplot.LogAxisRenderer.prototype.pack = function(pos, offsets) {
|
||||
var lb = parseInt(this.base, 10);
|
||||
var ticks = this._ticks;
|
||||
var trans = function (v) { return Math.log(v)/Math.log(lb); };
|
||||
var invtrans = function (v) { return Math.pow(Math.E, (Math.log(lb)*v)); };
|
||||
max = trans(this.max);
|
||||
min = trans(this.min);
|
||||
var offmax = offsets.max;
|
||||
var offmin = offsets.min;
|
||||
var lshow = (this._label == null) ? false : this._label.show;
|
||||
|
||||
for (var p in pos) {
|
||||
this._elem.css(p, pos[p]);
|
||||
}
|
||||
|
||||
this._offsets = offsets;
|
||||
// pixellength will be + for x axes and - for y axes becasue pixels always measured from top left.
|
||||
var pixellength = offmax - offmin;
|
||||
var unitlength = max - min;
|
||||
|
||||
// point to unit and unit to point conversions references to Plot DOM element top left corner.
|
||||
this.p2u = function(p){
|
||||
return invtrans((p - offmin) * unitlength / pixellength + min);
|
||||
};
|
||||
|
||||
this.u2p = function(u){
|
||||
return (trans(u) - min) * pixellength / unitlength + offmin;
|
||||
};
|
||||
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis'){
|
||||
this.series_u2p = function(u){
|
||||
return (trans(u) - min) * pixellength / unitlength;
|
||||
};
|
||||
this.series_p2u = function(p){
|
||||
return invtrans(p * unitlength / pixellength + min);
|
||||
};
|
||||
}
|
||||
// yaxis is max at top of canvas.
|
||||
else {
|
||||
this.series_u2p = function(u){
|
||||
return (trans(u) - max) * pixellength / unitlength;
|
||||
};
|
||||
this.series_p2u = function(p){
|
||||
return invtrans(p * unitlength / pixellength + max);
|
||||
};
|
||||
}
|
||||
|
||||
if (this.show) {
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis') {
|
||||
for (i=0; i<ticks.length; i++) {
|
||||
var t = ticks[i];
|
||||
if (t.show && t.showLabel) {
|
||||
var shim;
|
||||
|
||||
if (t.constructor == $.jqplot.CanvasAxisTickRenderer && t.angle) {
|
||||
switch (t.labelPosition) {
|
||||
case 'auto':
|
||||
// position at end
|
||||
if (t.angle < 0) {
|
||||
shim = -t.getWidth() + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
|
||||
}
|
||||
// position at start
|
||||
else {
|
||||
shim = -t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
|
||||
}
|
||||
break;
|
||||
case 'end':
|
||||
shim = -t.getWidth() + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
|
||||
break;
|
||||
case 'start':
|
||||
shim = -t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
|
||||
break;
|
||||
case 'middle':
|
||||
shim = -t.getWidth()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
|
||||
break;
|
||||
default:
|
||||
shim = -t.getWidth()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
shim = -t.getWidth()/2;
|
||||
}
|
||||
// var shim = t.getWidth()/2;
|
||||
var val = this.u2p(t.value) + shim + 'px';
|
||||
t._elem.css('left', val);
|
||||
t.pack();
|
||||
}
|
||||
}
|
||||
if (lshow) {
|
||||
var w = this._label._elem.outerWidth(true);
|
||||
this._label._elem.css('left', offmin + pixellength/2 - w/2 + 'px');
|
||||
if (this.name == 'xaxis') {
|
||||
this._label._elem.css('bottom', '0px');
|
||||
}
|
||||
else {
|
||||
this._label._elem.css('top', '0px');
|
||||
}
|
||||
this._label.pack();
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (i=0; i<ticks.length; i++) {
|
||||
var t = ticks[i];
|
||||
if (t.show && t.showLabel) {
|
||||
var shim;
|
||||
if (t.constructor == $.jqplot.CanvasAxisTickRenderer && t.angle) {
|
||||
switch (t.labelPosition) {
|
||||
case 'auto':
|
||||
// position at end
|
||||
case 'end':
|
||||
if (t.angle < 0) {
|
||||
shim = -t._textRenderer.height * Math.cos(-t._textRenderer.angle) / 2;
|
||||
}
|
||||
else {
|
||||
shim = -t.getHeight() + t._textRenderer.height * Math.cos(t._textRenderer.angle) / 2;
|
||||
}
|
||||
break;
|
||||
case 'start':
|
||||
if (t.angle > 0) {
|
||||
shim = -t._textRenderer.height * Math.cos(-t._textRenderer.angle) / 2;
|
||||
}
|
||||
else {
|
||||
shim = -t.getHeight() + t._textRenderer.height * Math.cos(t._textRenderer.angle) / 2;
|
||||
}
|
||||
break;
|
||||
case 'middle':
|
||||
// if (t.angle > 0) {
|
||||
// shim = -t.getHeight()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
|
||||
// }
|
||||
// else {
|
||||
// shim = -t.getHeight()/2 - t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
|
||||
// }
|
||||
shim = -t.getHeight()/2;
|
||||
break;
|
||||
default:
|
||||
shim = -t.getHeight()/2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
shim = -t.getHeight()/2;
|
||||
}
|
||||
|
||||
var val = this.u2p(t.value) + shim + 'px';
|
||||
t._elem.css('top', val);
|
||||
t.pack();
|
||||
}
|
||||
}
|
||||
if (lshow) {
|
||||
var h = this._label._elem.outerHeight(true);
|
||||
this._label._elem.css('top', offmax - pixellength/2 - h/2 + 'px');
|
||||
if (this.name == 'yaxis') {
|
||||
this._label._elem.css('left', '0px');
|
||||
}
|
||||
else {
|
||||
this._label._elem.css('right', '0px');
|
||||
}
|
||||
this._label.pack();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
})(jQuery);
|
File diff suppressed because one or more lines are too long
|
@ -1,595 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2009 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* The author would appreciate an email letting him know of any substantial
|
||||
* use of jqPlot. You can reach the author at: chris dot leonello at gmail
|
||||
* dot com or see http://www.jqplot.com/info.php . This is, of course,
|
||||
* not required.
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* Thanks for using jqPlot!
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
// class: $.jqplot.MekkoAxisRenderer
|
||||
// An axis renderer for a Mekko chart.
|
||||
// Should be used with a Mekko chart where the mekkoRenderer is used on the series.
|
||||
// Displays the Y axis as a range from 0 to 1 (0 to 100%) and the x axis with a tick
|
||||
// for each series scaled to the sum of all the y values.
|
||||
$.jqplot.MekkoAxisRenderer = function() {
|
||||
};
|
||||
|
||||
// called with scope of axis object.
|
||||
$.jqplot.MekkoAxisRenderer.prototype.init = function(options){
|
||||
// prop: tickMode
|
||||
// How to space the ticks on the axis.
|
||||
// 'bar' will place a tick at the width of each bar.
|
||||
// This is the default for the x axis.
|
||||
// 'even' will place ticks at even intervals. This is
|
||||
// the default for x2 axis and y axis. y axis cannot be changed.
|
||||
this.tickMode;
|
||||
// prop: barLabelRenderer
|
||||
// renderer to use to draw labels under each bar.
|
||||
this.barLabelRenderer = $.jqplot.AxisLabelRenderer;
|
||||
// prop: barLabels
|
||||
// array of labels to put under each bar.
|
||||
this.barLabels = this.barLabels || [];
|
||||
// prop: barLabelOptions
|
||||
// options object to pass to the bar label renderer.
|
||||
this.barLabelOptions = {};
|
||||
this.tickOptions = $.extend(true, {showGridline:false}, this.tickOptions);
|
||||
this._barLabels = [];
|
||||
$.extend(true, this, options);
|
||||
if (this.name == 'yaxis') {
|
||||
this.tickOptions.formatString = this.tickOptions.formatString || "%d\%";
|
||||
}
|
||||
var db = this._dataBounds;
|
||||
db.min = 0;
|
||||
// for y axes, scale always go from 0 to 1 (0 to 100%)
|
||||
if (this.name == 'yaxis' || this.name == 'y2axis') {
|
||||
db.max = 100;
|
||||
this.tickMode = 'even';
|
||||
}
|
||||
// For x axes, scale goes from 0 to sum of all y values.
|
||||
else if (this.name == 'xaxis'){
|
||||
this.tickMode = (this.tickMode == null) ? 'bar' : this.tickMode;
|
||||
for (var i=0; i<this._series.length; i++) {
|
||||
db.max += this._series[i]._sumy;
|
||||
}
|
||||
}
|
||||
else if (this.name == 'x2axis'){
|
||||
this.tickMode = (this.tickMode == null) ? 'even' : this.tickMode;
|
||||
for (var i=0; i<this._series.length; i++) {
|
||||
db.max += this._series[i]._sumy;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// called with scope of axis
|
||||
$.jqplot.MekkoAxisRenderer.prototype.draw = function(ctx) {
|
||||
if (this.show) {
|
||||
// populate the axis label and value properties.
|
||||
// createTicks is a method on the renderer, but
|
||||
// call it within the scope of the axis.
|
||||
this.renderer.createTicks.call(this);
|
||||
// fill a div with axes labels in the right direction.
|
||||
// Need to pregenerate each axis to get it's bounds and
|
||||
// position it and the labels correctly on the plot.
|
||||
var dim=0;
|
||||
var temp;
|
||||
|
||||
this._elem = $('<div class="jqplot-axis jqplot-'+this.name+'" style="position:absolute;"></div>');
|
||||
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis') {
|
||||
this._elem.width(this._plotDimensions.width);
|
||||
}
|
||||
else {
|
||||
this._elem.height(this._plotDimensions.height);
|
||||
}
|
||||
|
||||
// draw the axis label
|
||||
// create a _label object.
|
||||
this.labelOptions.axis = this.name;
|
||||
this._label = new this.labelRenderer(this.labelOptions);
|
||||
if (this._label.show) {
|
||||
var elem = this._label.draw(ctx);
|
||||
elem.appendTo(this._elem);
|
||||
}
|
||||
|
||||
var t, tick, elem;
|
||||
if (this.showTicks) {
|
||||
t = this._ticks;
|
||||
for (var i=0; i<t.length; i++) {
|
||||
tick = t[i];
|
||||
if (tick.showLabel && (!tick.isMinorTick || this.showMinorTicks)) {
|
||||
elem = tick.draw(ctx);
|
||||
elem.appendTo(this._elem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// draw the series labels
|
||||
for (i=0; i<this.barLabels.length; i++) {
|
||||
this.barLabelOptions.axis = this.name;
|
||||
this.barLabelOptions.label = this.barLabels[i];
|
||||
this._barLabels.push(new this.barLabelRenderer(this.barLabelOptions));
|
||||
if (this.tickMode != 'bar') {
|
||||
this._barLabels[i].show = false;
|
||||
}
|
||||
if (this._barLabels[i].show) {
|
||||
var elem = this._barLabels[i].draw(ctx);
|
||||
elem.removeClass('jqplot-'+this.name+'-label');
|
||||
elem.addClass('jqplot-'+this.name+'-tick');
|
||||
elem.addClass('jqplot-mekko-barLabel');
|
||||
elem.appendTo(this._elem);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return this._elem;
|
||||
};
|
||||
|
||||
// called with scope of an axis
|
||||
$.jqplot.MekkoAxisRenderer.prototype.reset = function() {
|
||||
this.min = this._min;
|
||||
this.max = this._max;
|
||||
this.tickInterval = this._tickInterval;
|
||||
this.numberTicks = this._numberTicks;
|
||||
// this._ticks = this.__ticks;
|
||||
};
|
||||
|
||||
// called with scope of axis
|
||||
$.jqplot.MekkoAxisRenderer.prototype.set = function() {
|
||||
var dim = 0;
|
||||
var temp;
|
||||
var w = 0;
|
||||
var h = 0;
|
||||
var lshow = (this._label == null) ? false : this._label.show;
|
||||
if (this.show && this.showTicks) {
|
||||
var t = this._ticks;
|
||||
for (var i=0; i<t.length; i++) {
|
||||
var tick = t[i];
|
||||
if (tick.showLabel && (!tick.isMinorTick || this.showMinorTicks)) {
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis') {
|
||||
temp = tick._elem.outerHeight(true);
|
||||
}
|
||||
else {
|
||||
temp = tick._elem.outerWidth(true);
|
||||
}
|
||||
if (temp > dim) {
|
||||
dim = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (lshow) {
|
||||
w = this._label._elem.outerWidth(true);
|
||||
h = this._label._elem.outerHeight(true);
|
||||
}
|
||||
if (this.name == 'xaxis') {
|
||||
dim = dim + h;
|
||||
this._elem.css({'height':dim+'px', left:'0px', bottom:'0px'});
|
||||
}
|
||||
else if (this.name == 'x2axis') {
|
||||
dim = dim + h;
|
||||
this._elem.css({'height':dim+'px', left:'0px', top:'0px'});
|
||||
}
|
||||
else if (this.name == 'yaxis') {
|
||||
dim = dim + w;
|
||||
this._elem.css({'width':dim+'px', left:'0px', top:'0px'});
|
||||
if (lshow && this._label.constructor == $.jqplot.AxisLabelRenderer) {
|
||||
this._label._elem.css('width', w+'px');
|
||||
}
|
||||
}
|
||||
else {
|
||||
dim = dim + w;
|
||||
this._elem.css({'width':dim+'px', right:'0px', top:'0px'});
|
||||
if (lshow && this._label.constructor == $.jqplot.AxisLabelRenderer) {
|
||||
this._label._elem.css('width', w+'px');
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// called with scope of axis
|
||||
$.jqplot.MekkoAxisRenderer.prototype.createTicks = function() {
|
||||
// we're are operating on an axis here
|
||||
var ticks = this._ticks;
|
||||
var userTicks = this.ticks;
|
||||
var name = this.name;
|
||||
// databounds were set on axis initialization.
|
||||
var db = this._dataBounds;
|
||||
var dim, interval;
|
||||
var min, max;
|
||||
var pos1, pos2;
|
||||
var t, tt, i, j;
|
||||
|
||||
// if we already have ticks, use them.
|
||||
// ticks must be in order of increasing value.
|
||||
|
||||
if (userTicks.length) {
|
||||
// ticks could be 1D or 2D array of [val, val, ,,,] or [[val, label], [val, label], ...] or mixed
|
||||
for (i=0; i<userTicks.length; i++){
|
||||
var ut = userTicks[i];
|
||||
var t = new this.tickRenderer(this.tickOptions);
|
||||
if (ut.constructor == Array) {
|
||||
t.value = ut[0];
|
||||
t.label = ut[1];
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(ut[0], this.name);
|
||||
this._ticks.push(t);
|
||||
}
|
||||
|
||||
else {
|
||||
t.value = ut;
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(ut, this.name);
|
||||
this._ticks.push(t);
|
||||
}
|
||||
}
|
||||
this.numberTicks = userTicks.length;
|
||||
this.min = this._ticks[0].value;
|
||||
this.max = this._ticks[this.numberTicks-1].value;
|
||||
this.tickInterval = (this.max - this.min) / (this.numberTicks - 1);
|
||||
}
|
||||
|
||||
// we don't have any ticks yet, let's make some!
|
||||
else {
|
||||
if (name == 'xaxis' || name == 'x2axis') {
|
||||
dim = this._plotDimensions.width;
|
||||
}
|
||||
else {
|
||||
dim = this._plotDimensions.height;
|
||||
}
|
||||
|
||||
// if min, max and number of ticks specified, user can't specify interval.
|
||||
if (this.min != null && this.max != null && this.numberTicks != null) {
|
||||
this.tickInterval = null;
|
||||
}
|
||||
|
||||
min = (this.min != null) ? this.min : db.min;
|
||||
max = (this.max != null) ? this.max : db.max;
|
||||
|
||||
// if min and max are same, space them out a bit.+
|
||||
if (min == max) {
|
||||
var adj = 0.05;
|
||||
if (min > 0) {
|
||||
adj = Math.max(Math.log(min)/Math.LN10, 0.05);
|
||||
}
|
||||
min -= adj;
|
||||
max += adj;
|
||||
}
|
||||
|
||||
var range = max - min;
|
||||
var rmin, rmax;
|
||||
var temp, prev, curr;
|
||||
var ynumticks = [3,5,6,11,21];
|
||||
|
||||
// yaxis divide ticks in nice intervals from 0 to 1.
|
||||
if (this.name == 'yaxis' || this.name == 'y2axis') {
|
||||
this.min = 0;
|
||||
this.max = 100;
|
||||
// user didn't specify number of ticks.
|
||||
if (!this.numberTicks){
|
||||
if (this.tickInterval) {
|
||||
this.numberTicks = 3 + Math.ceil(range / this.tickInterval);
|
||||
}
|
||||
else {
|
||||
temp = 2 + Math.ceil((dim-(this.tickSpacing-1))/this.tickSpacing);
|
||||
for (i=0; i<ynumticks.length; i++) {
|
||||
curr = temp/ynumticks[i];
|
||||
if (curr == 1) {
|
||||
this.numberTicks = ynumticks[i];
|
||||
break;
|
||||
}
|
||||
else if (curr > 1) {
|
||||
prev = curr;
|
||||
continue;
|
||||
}
|
||||
else if (curr < 1) {
|
||||
// was prev or is curr closer to one?
|
||||
if (Math.abs(prev - 1) < Math.abs(curr - 1)) {
|
||||
this.numberTicks = ynumticks[i-1];
|
||||
break;
|
||||
}
|
||||
else {
|
||||
this.numberTicks = ynumticks[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (i == ynumticks.length -1) {
|
||||
this.numberTicks = ynumticks[i];
|
||||
}
|
||||
}
|
||||
this.tickInterval = range / (this.numberTicks - 1);
|
||||
}
|
||||
}
|
||||
|
||||
// user did specify number of ticks.
|
||||
else {
|
||||
this.tickInterval = range / (this.numberTicks - 1);
|
||||
}
|
||||
|
||||
for (var i=0; i<this.numberTicks; i++){
|
||||
tt = this.min + i * this.tickInterval;
|
||||
t = new this.tickRenderer(this.tickOptions);
|
||||
// var t = new $.jqplot.AxisTickRenderer(this.tickOptions);
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(tt, this.name);
|
||||
this._ticks.push(t);
|
||||
}
|
||||
}
|
||||
|
||||
// for x axes, have number ot ticks equal to number of series and ticks placed
|
||||
// at sum of y values for each series.
|
||||
else if (this.tickMode == 'bar') {
|
||||
this.min = 0;
|
||||
this.numberTicks = this._series.length + 1;
|
||||
t = new this.tickRenderer(this.tickOptions);
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(0, this.name);
|
||||
this._ticks.push(t);
|
||||
|
||||
temp = 0;
|
||||
|
||||
for (i=1; i<this.numberTicks; i++){
|
||||
temp += this._series[i-1]._sumy;
|
||||
t = new this.tickRenderer(this.tickOptions);
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(temp, this.name);
|
||||
this._ticks.push(t);
|
||||
}
|
||||
this.max = this.max || temp;
|
||||
|
||||
// if user specified a max and it is greater than sum, add a tick
|
||||
if (this.max > temp) {
|
||||
t = new this.tickRenderer(this.tickOptions);
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(this.max, this.name);
|
||||
this._ticks.push(t);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
else if (this.tickMode == 'even') {
|
||||
this.min = 0;
|
||||
this.max = this.max || db.max;
|
||||
// get a desired number of ticks
|
||||
var nt = 2 + Math.ceil((dim-(this.tickSpacing-1))/this.tickSpacing);
|
||||
range = this.max - this.min;
|
||||
this.numberTicks = nt;
|
||||
this.tickInterval = range / (this.numberTicks - 1);
|
||||
|
||||
for (i=0; i<this.numberTicks; i++){
|
||||
tt = this.min + i * this.tickInterval;
|
||||
t = new this.tickRenderer(this.tickOptions);
|
||||
// var t = new $.jqplot.AxisTickRenderer(this.tickOptions);
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(tt, this.name);
|
||||
this._ticks.push(t);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// called with scope of axis
|
||||
$.jqplot.MekkoAxisRenderer.prototype.pack = function(pos, offsets) {
|
||||
var ticks = this._ticks;
|
||||
var max = this.max;
|
||||
var min = this.min;
|
||||
var offmax = offsets.max;
|
||||
var offmin = offsets.min;
|
||||
var lshow = (this._label == null) ? false : this._label.show;
|
||||
|
||||
for (var p in pos) {
|
||||
this._elem.css(p, pos[p]);
|
||||
}
|
||||
|
||||
this._offsets = offsets;
|
||||
// pixellength will be + for x axes and - for y axes becasue pixels always measured from top left.
|
||||
var pixellength = offmax - offmin;
|
||||
var unitlength = max - min;
|
||||
|
||||
// point to unit and unit to point conversions references to Plot DOM element top left corner.
|
||||
this.p2u = function(p){
|
||||
return (p - offmin) * unitlength / pixellength + min;
|
||||
};
|
||||
|
||||
this.u2p = function(u){
|
||||
return (u - min) * pixellength / unitlength + offmin;
|
||||
};
|
||||
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis'){
|
||||
this.series_u2p = function(u){
|
||||
return (u - min) * pixellength / unitlength;
|
||||
};
|
||||
this.series_p2u = function(p){
|
||||
return p * unitlength / pixellength + min;
|
||||
};
|
||||
}
|
||||
|
||||
else {
|
||||
this.series_u2p = function(u){
|
||||
return (u - max) * pixellength / unitlength;
|
||||
};
|
||||
this.series_p2u = function(p){
|
||||
return p * unitlength / pixellength + max;
|
||||
};
|
||||
}
|
||||
|
||||
if (this.show) {
|
||||
if (this.name == 'xaxis' || this.name == 'x2axis') {
|
||||
for (i=0; i<ticks.length; i++) {
|
||||
var t = ticks[i];
|
||||
if (t.show && t.showLabel) {
|
||||
var shim;
|
||||
|
||||
if (t.constructor == $.jqplot.CanvasAxisTickRenderer && t.angle) {
|
||||
// will need to adjust auto positioning based on which axis this is.
|
||||
var temp = (this.name == 'xaxis') ? 1 : -1;
|
||||
switch (t.labelPosition) {
|
||||
case 'auto':
|
||||
// position at end
|
||||
if (temp * t.angle < 0) {
|
||||
shim = -t.getWidth() + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
|
||||
}
|
||||
// position at start
|
||||
else {
|
||||
shim = -t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
|
||||
}
|
||||
break;
|
||||
case 'end':
|
||||
shim = -t.getWidth() + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
|
||||
break;
|
||||
case 'start':
|
||||
shim = -t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
|
||||
break;
|
||||
case 'middle':
|
||||
shim = -t.getWidth()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
|
||||
break;
|
||||
default:
|
||||
shim = -t.getWidth()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
shim = -t.getWidth()/2;
|
||||
}
|
||||
var val = this.u2p(t.value) + shim + 'px';
|
||||
t._elem.css('left', val);
|
||||
t.pack();
|
||||
}
|
||||
}
|
||||
var w;
|
||||
if (lshow) {
|
||||
w = this._label._elem.outerWidth(true);
|
||||
this._label._elem.css('left', offmin + pixellength/2 - w/2 + 'px');
|
||||
if (this.name == 'xaxis') {
|
||||
this._label._elem.css('bottom', '0px');
|
||||
}
|
||||
else {
|
||||
this._label._elem.css('top', '0px');
|
||||
}
|
||||
this._label.pack();
|
||||
}
|
||||
// now show the labels under the bars.
|
||||
var b, l, r;
|
||||
for (i=0; i<this.barLabels.length; i++) {
|
||||
b = this._barLabels[i];
|
||||
if (b.show) {
|
||||
w = b.getWidth();
|
||||
l = this._ticks[i].getLeft() + this._ticks[i].getWidth();
|
||||
r = this._ticks[i+1].getLeft();
|
||||
b._elem.css('left', (r+l-w)/2+'px');
|
||||
b._elem.css('top', this._ticks[i]._elem.css('top'));
|
||||
b.pack();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (i=0; i<ticks.length; i++) {
|
||||
var t = ticks[i];
|
||||
if (t.show && t.showLabel) {
|
||||
var shim;
|
||||
if (t.constructor == $.jqplot.CanvasAxisTickRenderer && t.angle) {
|
||||
// will need to adjust auto positioning based on which axis this is.
|
||||
var temp = (this.name == 'yaxis') ? 1 : -1;
|
||||
switch (t.labelPosition) {
|
||||
case 'auto':
|
||||
// position at end
|
||||
case 'end':
|
||||
if (temp * t.angle < 0) {
|
||||
shim = -t._textRenderer.height * Math.cos(-t._textRenderer.angle) / 2;
|
||||
}
|
||||
else {
|
||||
shim = -t.getHeight() + t._textRenderer.height * Math.cos(t._textRenderer.angle) / 2;
|
||||
}
|
||||
break;
|
||||
case 'start':
|
||||
if (t.angle > 0) {
|
||||
shim = -t._textRenderer.height * Math.cos(-t._textRenderer.angle) / 2;
|
||||
}
|
||||
else {
|
||||
shim = -t.getHeight() + t._textRenderer.height * Math.cos(t._textRenderer.angle) / 2;
|
||||
}
|
||||
break;
|
||||
case 'middle':
|
||||
shim = -t.getHeight()/2;
|
||||
break;
|
||||
default:
|
||||
shim = -t.getHeight()/2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
shim = -t.getHeight()/2;
|
||||
}
|
||||
|
||||
var val = this.u2p(t.value) + shim + 'px';
|
||||
t._elem.css('top', val);
|
||||
t.pack();
|
||||
}
|
||||
}
|
||||
if (lshow) {
|
||||
var h = this._label._elem.outerHeight(true);
|
||||
this._label._elem.css('top', offmax - pixellength/2 - h/2 + 'px');
|
||||
if (this.name == 'yaxis') {
|
||||
this._label._elem.css('left', '0px');
|
||||
}
|
||||
else {
|
||||
this._label._elem.css('right', '0px');
|
||||
}
|
||||
this._label.pack();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
})(jQuery);
|
File diff suppressed because one or more lines are too long
|
@ -1,308 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2009 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* The author would appreciate an email letting him know of any substantial
|
||||
* use of jqPlot. You can reach the author at: chris dot leonello at gmail
|
||||
* dot com or see http://www.jqplot.com/info.php . This is, of course,
|
||||
* not required.
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* Thanks for using jqPlot!
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
// Class: $.jqplot.MekkoRenderer
|
||||
$.jqplot.MekkoRenderer = function(){
|
||||
this.shapeRenderer = new $.jqplot.ShapeRenderer();
|
||||
};
|
||||
|
||||
// called with scope of series.
|
||||
$.jqplot.MekkoRenderer.prototype.init = function(options, plot) {
|
||||
this.fill = false;
|
||||
this.fillRect = true;
|
||||
this.strokeRect = true;
|
||||
this.shadow = false;
|
||||
// width of bar on x axis.
|
||||
this._xwidth = 0;
|
||||
this._xstart = 0;
|
||||
$.extend(true, this.renderer, options);
|
||||
// set the shape renderer options
|
||||
var opts = {lineJoin:'miter', lineCap:'butt', isarc:false, fillRect:this.fillRect, strokeRect:this.strokeRect};
|
||||
this.renderer.shapeRenderer.init(opts);
|
||||
plot.axes.x2axis._series.push(this);
|
||||
};
|
||||
|
||||
// Method: setGridData
|
||||
// converts the user data values to grid coordinates and stores them
|
||||
// in the gridData array. Will convert user data into appropriate
|
||||
// rectangles.
|
||||
// Called with scope of a series.
|
||||
$.jqplot.MekkoRenderer.prototype.setGridData = function(plot) {
|
||||
// recalculate the grid data
|
||||
var xp = this._xaxis.series_u2p;
|
||||
var yp = this._yaxis.series_u2p;
|
||||
var data = this._plotData;
|
||||
this.gridData = [];
|
||||
// figure out width on x axis.
|
||||
// this._xwidth = this._sumy / plot._sumy * this.canvas.getWidth();
|
||||
this._xwidth = xp(this._sumy) - xp(0);
|
||||
if (this.index>0) {
|
||||
this._xstart = plot.series[this.index-1]._xstart + plot.series[this.index-1]._xwidth;
|
||||
}
|
||||
var totheight = this.canvas.getHeight();
|
||||
var sumy = 0;
|
||||
var cury;
|
||||
var curheight;
|
||||
for (var i=0; i<data.length; i++) {
|
||||
if (data[i] != null) {
|
||||
sumy += data[i][1];
|
||||
cury = totheight - (sumy / this._sumy * totheight);
|
||||
curheight = data[i][1] / this._sumy * totheight;
|
||||
this.gridData.push([this._xstart, cury, this._xwidth, curheight]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Method: makeGridData
|
||||
// converts any arbitrary data values to grid coordinates and
|
||||
// returns them. This method exists so that plugins can use a series'
|
||||
// linerenderer to generate grid data points without overwriting the
|
||||
// grid data associated with that series.
|
||||
// Called with scope of a series.
|
||||
$.jqplot.MekkoRenderer.prototype.makeGridData = function(data, plot) {
|
||||
// recalculate the grid data
|
||||
// figure out width on x axis.
|
||||
var xp = this._xaxis.series_u2p;
|
||||
var totheight = this.canvas.getHeight();
|
||||
var sumy = 0;
|
||||
var cury;
|
||||
var curheight;
|
||||
var gd = [];
|
||||
for (var i=0; i<data.length; i++) {
|
||||
if (data[i] != null) {
|
||||
sumy += data[i][1];
|
||||
cury = totheight - (sumy / this._sumy * totheight);
|
||||
curheight = data[i][1] / this._sumy * totheight;
|
||||
gd.push([this._xstart, cury, this._xwidth, curheight]);
|
||||
}
|
||||
}
|
||||
return gd;
|
||||
};
|
||||
|
||||
|
||||
// called within scope of series.
|
||||
$.jqplot.MekkoRenderer.prototype.draw = function(ctx, gd, options) {
|
||||
var i;
|
||||
var opts = (options != undefined) ? options : {};
|
||||
var showLine = (opts.showLine != undefined) ? opts.showLine : this.showLine;
|
||||
var colorGenerator = new $.jqplot.ColorGenerator(this.seriesColors);
|
||||
ctx.save();
|
||||
if (gd.length) {
|
||||
if (showLine) {
|
||||
for (i=0; i<gd.length; i++){
|
||||
opts.fillStyle = colorGenerator.next();
|
||||
this.renderer.shapeRenderer.draw(ctx, gd[i], opts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ctx.restore();
|
||||
};
|
||||
|
||||
$.jqplot.MekkoRenderer.prototype.drawShadow = function(ctx, gd, options) {
|
||||
// This is a no-op, no shadows on mekko charts.
|
||||
};
|
||||
|
||||
// called with scope of legend renderer.
|
||||
$.jqplot.MekkoLegendRenderer = function() {
|
||||
$.jqplot.TableLegendRenderer.call(this);
|
||||
};
|
||||
|
||||
$.jqplot.MekkoLegendRenderer.prototype = new $.jqplot.TableLegendRenderer();
|
||||
$.jqplot.MekkoLegendRenderer.prototype.constructor = $.jqplot.MekkoLegendRenderer;
|
||||
|
||||
// called with scope of legend
|
||||
$.jqplot.MekkoLegendRenderer.prototype.init = function(options) {
|
||||
this.labels = [];
|
||||
this.placement = "outside";
|
||||
$.extend(true, this, options);
|
||||
};
|
||||
|
||||
// called with context of legend
|
||||
$.jqplot.MekkoLegendRenderer.prototype.draw = function() {
|
||||
var legend = this;
|
||||
if (this.show) {
|
||||
var series = this._series;
|
||||
// make a table. one line label per row.
|
||||
var ss = 'position:absolute;';
|
||||
ss += (this.background) ? 'background:'+this.background+';' : '';
|
||||
ss += (this.border) ? 'border:'+this.border+';' : '';
|
||||
ss += (this.fontSize) ? 'font-size:'+this.fontSize+';' : '';
|
||||
ss += (this.fontFamily) ? 'font-family:'+this.fontFamily+';' : '';
|
||||
ss += (this.textColor) ? 'color:'+this.textColor+';' : '';
|
||||
this._elem = $('<table class="jqplot-table-legend jqplot-mekko-legend" style="'+ss+'"></table>');
|
||||
|
||||
var pad = false, i, labels = [], colors = [];
|
||||
var s = series[0];
|
||||
var colorGenerator = new $.jqplot.ColorGenerator(s.seriesColors);
|
||||
if (s.show) {
|
||||
var pd = s.data;
|
||||
for (i=0; i<pd.length; i++){
|
||||
labels.push(this.labels[i] || pd[i][0].toString());
|
||||
colors.push(colorGenerator.next());
|
||||
}
|
||||
for (i=pd.length-1; i>-1; i--) {
|
||||
if (labels[i]) {
|
||||
this.renderer.addrow.call(this, labels[i], colors[i], pad);
|
||||
pad = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return this._elem;
|
||||
};
|
||||
|
||||
$.jqplot.MekkoLegendRenderer.prototype.pack = function(offsets) {
|
||||
if (this.show) {
|
||||
// fake a grid for positioning
|
||||
var grid = {_top:offsets.top, _left:offsets.left, _right:offsets.right, _bottom:this._plotDimensions.height - offsets.bottom};
|
||||
if (this.placement == 'inside') {
|
||||
switch (this.location) {
|
||||
case 'nw':
|
||||
var a = grid._left + this.xoffset;
|
||||
var b = grid._top + this.yoffset;
|
||||
this._elem.css('left', a);
|
||||
this._elem.css('top', b);
|
||||
break;
|
||||
case 'n':
|
||||
var a = (offsets.left + (this._plotDimensions.width - offsets.right))/2 - this.getWidth()/2;
|
||||
var b = grid._top + this.yoffset;
|
||||
this._elem.css('left', a);
|
||||
this._elem.css('top', b);
|
||||
break;
|
||||
case 'ne':
|
||||
var a = offsets.right + this.xoffset;
|
||||
var b = grid._top + this.yoffset;
|
||||
this._elem.css({right:a, top:b});
|
||||
break;
|
||||
case 'e':
|
||||
var a = offsets.right + this.xoffset;
|
||||
var b = (offsets.top + (this._plotDimensions.height - offsets.bottom))/2 - this.getHeight()/2;
|
||||
this._elem.css({right:a, top:b});
|
||||
break;
|
||||
case 'se':
|
||||
var a = offsets.right + this.xoffset;
|
||||
var b = offsets.bottom + this.yoffset;
|
||||
this._elem.css({right:a, bottom:b});
|
||||
break;
|
||||
case 's':
|
||||
var a = (offsets.left + (this._plotDimensions.width - offsets.right))/2 - this.getWidth()/2;
|
||||
var b = offsets.bottom + this.yoffset;
|
||||
this._elem.css({left:a, bottom:b});
|
||||
break;
|
||||
case 'sw':
|
||||
var a = grid._left + this.xoffset;
|
||||
var b = offsets.bottom + this.yoffset;
|
||||
this._elem.css({left:a, bottom:b});
|
||||
break;
|
||||
case 'w':
|
||||
var a = grid._left + this.xoffset;
|
||||
var b = (offsets.top + (this._plotDimensions.height - offsets.bottom))/2 - this.getHeight()/2;
|
||||
this._elem.css({left:a, top:b});
|
||||
break;
|
||||
default: // same as 'se'
|
||||
var a = grid._right - this.xoffset;
|
||||
var b = grid._bottom + this.yoffset;
|
||||
this._elem.css({right:a, bottom:b});
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
switch (this.location) {
|
||||
case 'nw':
|
||||
var a = this._plotDimensions.width - grid._left + this.xoffset;
|
||||
var b = grid._top + this.yoffset;
|
||||
this._elem.css('right', a);
|
||||
this._elem.css('top', b);
|
||||
break;
|
||||
case 'n':
|
||||
var a = (offsets.left + (this._plotDimensions.width - offsets.right))/2 - this.getWidth()/2;
|
||||
var b = this._plotDimensions.height - grid._top + this.yoffset;
|
||||
this._elem.css('left', a);
|
||||
this._elem.css('bottom', b);
|
||||
break;
|
||||
case 'ne':
|
||||
var a = this._plotDimensions.width - offsets.right + this.xoffset;
|
||||
var b = grid._top + this.yoffset;
|
||||
this._elem.css({left:a, top:b});
|
||||
break;
|
||||
case 'e':
|
||||
var a = this._plotDimensions.width - offsets.right + this.xoffset;
|
||||
var b = (offsets.top + (this._plotDimensions.height - offsets.bottom))/2 - this.getHeight()/2;
|
||||
this._elem.css({left:a, top:b});
|
||||
break;
|
||||
case 'se':
|
||||
var a = this._plotDimensions.width - offsets.right + this.xoffset;
|
||||
var b = offsets.bottom + this.yoffset;
|
||||
this._elem.css({left:a, bottom:b});
|
||||
break;
|
||||
case 's':
|
||||
var a = (offsets.left + (this._plotDimensions.width - offsets.right))/2 - this.getWidth()/2;
|
||||
var b = this._plotDimensions.height - offsets.bottom + this.yoffset;
|
||||
this._elem.css({left:a, top:b});
|
||||
break;
|
||||
case 'sw':
|
||||
var a = this._plotDimensions.width - grid._left + this.xoffset;
|
||||
var b = offsets.bottom + this.yoffset;
|
||||
this._elem.css({right:a, bottom:b});
|
||||
break;
|
||||
case 'w':
|
||||
var a = this._plotDimensions.width - grid._left + this.xoffset;
|
||||
var b = (offsets.top + (this._plotDimensions.height - offsets.bottom))/2 - this.getHeight()/2;
|
||||
this._elem.css({right:a, top:b});
|
||||
break;
|
||||
default: // same as 'se'
|
||||
var a = grid._right - this.xoffset;
|
||||
var b = grid._bottom + this.yoffset;
|
||||
this._elem.css({right:a, bottom:b});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// setup default renderers for axes and legend so user doesn't have to
|
||||
// called with scope of plot
|
||||
function preInit(target, data, options) {
|
||||
options = options || {};
|
||||
options.axesDefaults = options.axesDefaults || {};
|
||||
options.legend = options.legend || {};
|
||||
options.seriesDefaults = options.seriesDefaults || {};
|
||||
var setopts = false;
|
||||
if (options.seriesDefaults.renderer == $.jqplot.MekkoRenderer) {
|
||||
setopts = true;
|
||||
}
|
||||
else if (options.series) {
|
||||
for (var i=0; i < options.series.length; i++) {
|
||||
if (options.series[i].renderer == $.jqplot.MekkoRenderer) {
|
||||
setopts = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (setopts) {
|
||||
options.axesDefaults.renderer = $.jqplot.MekkoAxisRenderer;
|
||||
options.legend.renderer = $.jqplot.MekkoLegendRenderer;
|
||||
options.legend.preDraw = true;
|
||||
}
|
||||
}
|
||||
|
||||
$.jqplot.preInitHooks.push(preInit);
|
||||
|
||||
})(jQuery);
|
File diff suppressed because one or more lines are too long
|
@ -1,343 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2009 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* The author would appreciate an email letting him know of any substantial
|
||||
* use of jqPlot. You can reach the author at: chris dot leonello at gmail
|
||||
* dot com or see http://www.jqplot.com/info.php . This is, of course,
|
||||
* not required.
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* Thanks for using jqPlot!
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
/**
|
||||
* Class: $.jqplot.OHLCRenderer
|
||||
* jqPlot Plugin to draw Open Hi Low Close, Candlestick and Hi Low Close charts.
|
||||
*
|
||||
* To use this plugin, include the renderer js file in
|
||||
* your source:
|
||||
*
|
||||
* > <script type="text/javascript" src="plugins/jqplot.ohlcRenderer.js"></script>
|
||||
*
|
||||
* You will most likely want to use a date axis renderer
|
||||
* for the x axis also, so include the date axis render js file also:
|
||||
*
|
||||
* > <script type="text/javascript" src="plugins/jqplot.dateAxisRenderer.js"></script>
|
||||
*
|
||||
* Then you set the renderer in the series options on your plot:
|
||||
*
|
||||
* > series: [{renderer:$.jqplot.OHLCRenderer}]
|
||||
*
|
||||
* For OHLC and candlestick charts, data should be specified
|
||||
* like so:
|
||||
*
|
||||
* > dat = [['07/06/2009',138.7,139.68,135.18,135.4], ['06/29/2009',143.46,144.66,139.79,140.02], ...]
|
||||
*
|
||||
* If the data array has only 4 values per point instead of 5,
|
||||
* the renderer will create a Hi Low Close chart instead. In that case,
|
||||
* data should be supplied like:
|
||||
*
|
||||
* > dat = [['07/06/2009',139.68,135.18,135.4], ['06/29/2009',144.66,139.79,140.02], ...]
|
||||
*
|
||||
* To generate a candlestick chart instead of an OHLC chart,
|
||||
* set the "candlestick" option to true:
|
||||
*
|
||||
* > series: [{renderer:$.jqplot.OHLCRenderer, rendererOptions:{candleStick:true}}],
|
||||
*
|
||||
*/
|
||||
$.jqplot.OHLCRenderer = function(){
|
||||
// subclass line renderer to make use of some of it's methods.
|
||||
$.jqplot.LineRenderer.call(this);
|
||||
// prop: candleStick
|
||||
// true to render chart as candleStick.
|
||||
// Must have an open price, cannot be a hlc chart.
|
||||
this.candleStick = false;
|
||||
// prop: tickLength
|
||||
// length of the line in pixels indicating open and close price.
|
||||
// Default will auto calculate based on plot width and
|
||||
// number of points displayed.
|
||||
this.tickLength = 'auto';
|
||||
// prop: bodyWidth
|
||||
// width of the candlestick body in pixels. Default will auto calculate
|
||||
// based on plot width and number of candlesticks displayed.
|
||||
this.bodyWidth = 'auto';
|
||||
// prop: openColor
|
||||
// color of the open price tick mark. Default is series color.
|
||||
this.openColor = null;
|
||||
// prop: closeColor
|
||||
// color of the close price tick mark. Default is series color.
|
||||
this.closeColor = null;
|
||||
// prop: wickColor
|
||||
// color of the hi-lo line thorugh the candlestick body.
|
||||
// Default is the series color.
|
||||
this.wickColor = null;
|
||||
// prop: fillUpBody
|
||||
// true to render an "up" day (close price greater than open price)
|
||||
// with a filled candlestick body.
|
||||
this.fillUpBody = false;
|
||||
// prop: fillDownBody
|
||||
// true to render a "down" day (close price lower than open price)
|
||||
// with a filled candlestick body.
|
||||
this.fillDownBody = true;
|
||||
// prop: upBodyColor
|
||||
// Color of candlestick body of an "up" day. Default is series color.
|
||||
this.upBodyColor = null;
|
||||
// prop: downBodyColor
|
||||
// Color of candlestick body on a "down" day. Default is series color.
|
||||
this.downBodyColor = null;
|
||||
// prop: hlc
|
||||
// true if is a hi-low-close chart (no open price).
|
||||
// This is determined automatically from the series data.
|
||||
this.hlc = false;
|
||||
this._tickLength;
|
||||
this._bodyWidth;
|
||||
};
|
||||
|
||||
$.jqplot.OHLCRenderer.prototype = new $.jqplot.LineRenderer();
|
||||
$.jqplot.OHLCRenderer.prototype.constructor = $.jqplot.OHLCRenderer;
|
||||
|
||||
// called with scope of series.
|
||||
$.jqplot.OHLCRenderer.prototype.init = function(options) {
|
||||
// prop: lineWidth
|
||||
// Width of the hi-low line and open/close ticks.
|
||||
this.lineWidth = 1.5;
|
||||
$.jqplot.LineRenderer.prototype.init.call(this, options);
|
||||
// set the yaxis data bounds here to account for hi and low values
|
||||
var db = this._yaxis._dataBounds;
|
||||
var d = this._plotData;
|
||||
// if data points have less than 5 values, force a hlc chart.
|
||||
if (d[0].length < 5) {
|
||||
this.renderer.hlc = true;
|
||||
|
||||
for (var j=0; j<d.length; j++) {
|
||||
if (d[j][2] < db.min || db.min == null) {
|
||||
db.min = d[j][2];
|
||||
}
|
||||
if (d[j][1] > db.max || db.max == null) {
|
||||
db.max = d[j][1];
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (var j=0; j<d.length; j++) {
|
||||
if (d[j][3] < db.min || db.min == null) {
|
||||
db.min = d[j][3];
|
||||
}
|
||||
if (d[j][2] > db.max || db.max == null) {
|
||||
db.max = d[j][2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// called within scope of series.
|
||||
$.jqplot.OHLCRenderer.prototype.draw = function(ctx, gd, options) {
|
||||
var d = this.data;
|
||||
var xmin = this._xaxis.min;
|
||||
var xmax = this._xaxis.max;
|
||||
// index of last value below range of plot.
|
||||
var xminidx = 0;
|
||||
// index of first value above range of plot.
|
||||
var xmaxidx = d.length;
|
||||
var xp = this._xaxis.series_u2p;
|
||||
var yp = this._yaxis.series_u2p;
|
||||
var i, prevColor, ops, b, h, w, a, points;
|
||||
var o;
|
||||
var r = this.renderer;
|
||||
var opts = (options != undefined) ? options : {};
|
||||
var shadow = (opts.shadow != undefined) ? opts.shadow : this.shadow;
|
||||
var fill = (opts.fill != undefined) ? opts.fill : this.fill;
|
||||
var fillAndStroke = (opts.fillAndStroke != undefined) ? opts.fillAndStroke : this.fillAndStroke;
|
||||
r.bodyWidth = (opts.bodyWidth != undefined) ? opts.bodyWidth : r.bodyWidth;
|
||||
r.tickLength = (opts.tickLength != undefined) ? opts.tickLength : r.tickLength;
|
||||
ctx.save();
|
||||
if (this.show) {
|
||||
var x, open, hi, low, close;
|
||||
// need to get widths based on number of points shown,
|
||||
// not on total number of points. Use the results
|
||||
// to speed up drawing in next step.
|
||||
for (var i=0; i<d.length; i++) {
|
||||
if (d[i][0] < xmin) {
|
||||
xminidx = i;
|
||||
}
|
||||
else if (d[i][0] < xmax) {
|
||||
xmaxidx = i+1;
|
||||
}
|
||||
}
|
||||
|
||||
if (r.candleStick) {
|
||||
if (typeof(r.bodyWidth) == 'number') {
|
||||
r._bodyWidth = r.bodyWidth;
|
||||
}
|
||||
else {
|
||||
r._bodyWidth = Math.min(20, ctx.canvas.width/(xmaxidx - xminidx)/2);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (typeof(r.tickLength) == 'number') {
|
||||
r._tickLength = r.tickLength;
|
||||
}
|
||||
else {
|
||||
r._tickLength = Math.min(10, ctx.canvas.width/(xmaxidx - xminidx)/4);
|
||||
}
|
||||
}
|
||||
|
||||
for (var i=xminidx; i<xmaxidx; i++) {
|
||||
x = xp(d[i][0]);
|
||||
if (r.hlc) {
|
||||
open = null;
|
||||
hi = yp(d[i][1]);
|
||||
low = yp(d[i][2]);
|
||||
close = yp(d[i][3]);
|
||||
}
|
||||
else {
|
||||
open = yp(d[i][1]);
|
||||
hi = yp(d[i][2]);
|
||||
low = yp(d[i][3]);
|
||||
close = yp(d[i][4]);
|
||||
}
|
||||
o = {};
|
||||
if (r.candleStick && !r.hlc) {
|
||||
w = r._bodyWidth;
|
||||
a = x - w/2;
|
||||
// draw candle
|
||||
// determine if candle up or down
|
||||
// up, remember grid coordinates increase downward
|
||||
if (close < open) {
|
||||
// draw wick
|
||||
if (r.wickColor) {
|
||||
o.color = r.wickColor;
|
||||
}
|
||||
else if (r.downBodyColor) {
|
||||
o.color = r.upBodyColor;
|
||||
}
|
||||
ops = $.extend(true, {}, opts, o);
|
||||
r.shapeRenderer.draw(ctx, [[x, hi], [x, close]], ops);
|
||||
r.shapeRenderer.draw(ctx, [[x, open], [x, low]], ops);
|
||||
o = {};
|
||||
b = close;
|
||||
h = open - close;
|
||||
// if color specified, use it
|
||||
if (r.fillUpBody) {
|
||||
o.fillRect = true;
|
||||
}
|
||||
else {
|
||||
o.strokeRect = true;
|
||||
w = w - this.lineWidth;
|
||||
a = x - w/2;
|
||||
}
|
||||
if (r.upBodyColor) {
|
||||
o.color = r.upBodyColor;
|
||||
o.fillStyle = r.upBodyColor;
|
||||
}
|
||||
points = [a, b, w, h];
|
||||
}
|
||||
// down
|
||||
else if (close > open) {
|
||||
// draw wick
|
||||
if (r.wickColor) {
|
||||
o.color = r.wickColor;
|
||||
}
|
||||
else if (r.downBodyColor) {
|
||||
o.color = r.downBodyColor;
|
||||
}
|
||||
ops = $.extend(true, {}, opts, o);
|
||||
r.shapeRenderer.draw(ctx, [[x, hi], [x, open]], ops);
|
||||
r.shapeRenderer.draw(ctx, [[x, close], [x, low]], ops);
|
||||
|
||||
o = {};
|
||||
|
||||
b = open;
|
||||
h = close - open;
|
||||
// if color specified, use it
|
||||
if (r.fillDownBody) {
|
||||
o.fillRect = true;
|
||||
}
|
||||
else {
|
||||
o.strokeRect = true;
|
||||
w = w - this.lineWidth;
|
||||
a = x - w/2;
|
||||
}
|
||||
if (r.downBodyColor) {
|
||||
o.color = r.downBodyColor;
|
||||
o.fillStyle = r.downBodyColor;
|
||||
}
|
||||
points = [a, b, w, h];
|
||||
}
|
||||
// even, open = close
|
||||
else {
|
||||
// draw wick
|
||||
if (r.wickColor) {
|
||||
o.color = r.wickColor;
|
||||
}
|
||||
ops = $.extend(true, {}, opts, o);
|
||||
r.shapeRenderer.draw(ctx, [[x, hi], [x, low]], ops);
|
||||
o = {};
|
||||
o.fillRect = false;
|
||||
o.strokeRect = false;
|
||||
a = [x - w/2, open];
|
||||
b = [x + w/2, close];
|
||||
w = null;
|
||||
h = null;
|
||||
points = [a, b];
|
||||
}
|
||||
ops = $.extend(true, {}, opts, o);
|
||||
r.shapeRenderer.draw(ctx, points, ops);
|
||||
}
|
||||
else {
|
||||
prevColor = opts.color;
|
||||
if (r.openColor) {
|
||||
opts.color = r.openColor;
|
||||
}
|
||||
// draw open tick
|
||||
if (!r.hlc) {
|
||||
r.shapeRenderer.draw(ctx, [[x-r._tickLength, open], [x, open]], opts);
|
||||
}
|
||||
opts.color = prevColor;
|
||||
// draw wick
|
||||
if (r.wickColor) {
|
||||
opts.color = r.wickColor;
|
||||
}
|
||||
r.shapeRenderer.draw(ctx, [[x, hi], [x, low]], opts);
|
||||
opts.color = prevColor;
|
||||
// draw close tick
|
||||
if (r.closeColor) {
|
||||
opts.color = r.closeColor;
|
||||
}
|
||||
r.shapeRenderer.draw(ctx, [[x, close], [x+r._tickLength, close]], opts);
|
||||
opts.color = prevColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ctx.restore();
|
||||
};
|
||||
|
||||
$.jqplot.OHLCRenderer.prototype.drawShadow = function(ctx, gd, options) {
|
||||
// This is a no-op, shadows drawn with lines.
|
||||
};
|
||||
|
||||
// called with scope of plot.
|
||||
$.jqplot.OHLCRenderer.checkOptions = function(target, data, options) {
|
||||
// provide some sensible highlighter options by default
|
||||
// These aren't good for hlc, only for ohlc or candlestick
|
||||
if (!options.highlighter) {
|
||||
options.highlighter = {
|
||||
showMarker:false,
|
||||
tooltipAxes: 'y',
|
||||
yvalues: 4,
|
||||
formatString:'<table class="jqplot-highlighter"><tr><td>date:</td><td>%s</td></tr><tr><td>open:</td><td>%s</td></tr><tr><td>hi:</td><td>%s</td></tr><tr><td>low:</td><td>%s</td></tr><tr><td>close:</td><td>%s</td></tr></table>'
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
//$.jqplot.preInitHooks.push($.jqplot.OHLCRenderer.checkOptions);
|
||||
|
||||
})(jQuery);
|
|
@ -1,14 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2009 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris dot leonello at gmail dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*/
|
||||
(function(a){a.jqplot.OHLCRenderer=function(){a.jqplot.LineRenderer.call(this);this.candleStick=false;this.tickLength="auto";this.bodyWidth="auto";this.openColor=null;this.closeColor=null;this.wickColor=null;this.fillUpBody=false;this.fillDownBody=true;this.upBodyColor=null;this.downBodyColor=null;this.hlc=false;this._tickLength;this._bodyWidth};a.jqplot.OHLCRenderer.prototype=new a.jqplot.LineRenderer();a.jqplot.OHLCRenderer.prototype.constructor=a.jqplot.OHLCRenderer;a.jqplot.OHLCRenderer.prototype.init=function(e){this.lineWidth=1.5;a.jqplot.LineRenderer.prototype.init.call(this,e);var b=this._yaxis._dataBounds;var f=this._plotData;if(f[0].length<5){this.renderer.hlc=true;for(var c=0;c<f.length;c++){if(f[c][2]<b.min||b.min==null){b.min=f[c][2]}if(f[c][1]>b.max||b.max==null){b.max=f[c][1]}}}else{for(var c=0;c<f.length;c++){if(f[c][3]<b.min||b.min==null){b.min=f[c][3]}if(f[c][2]>b.max||b.max==null){b.max=f[c][2]}}}};a.jqplot.OHLCRenderer.prototype.draw=function(z,J,g){var G=this.data;var u=this._xaxis.min;var y=this._xaxis.max;var k=0;var H=G.length;var n=this._xaxis.series_u2p;var F=this._yaxis.series_u2p;var C,D,e,I,E,m,K,B;var v;var t=this.renderer;var q=(g!=undefined)?g:{};var j=(q.shadow!=undefined)?q.shadow:this.shadow;var A=(q.fill!=undefined)?q.fill:this.fill;var c=(q.fillAndStroke!=undefined)?q.fillAndStroke:this.fillAndStroke;t.bodyWidth=(q.bodyWidth!=undefined)?q.bodyWidth:t.bodyWidth;t.tickLength=(q.tickLength!=undefined)?q.tickLength:t.tickLength;z.save();if(this.show){var l,p,f,L,s;for(var C=0;C<G.length;C++){if(G[C][0]<u){k=C}else{if(G[C][0]<y){H=C+1}}}if(t.candleStick){if(typeof(t.bodyWidth)=="number"){t._bodyWidth=t.bodyWidth}else{t._bodyWidth=Math.min(20,z.canvas.width/(H-k)/2)}}else{if(typeof(t.tickLength)=="number"){t._tickLength=t.tickLength}else{t._tickLength=Math.min(10,z.canvas.width/(H-k)/4)}}for(var C=k;C<H;C++){l=n(G[C][0]);if(t.hlc){p=null;f=F(G[C][1]);L=F(G[C][2]);s=F(G[C][3])}else{p=F(G[C][1]);f=F(G[C][2]);L=F(G[C][3]);s=F(G[C][4])}v={};if(t.candleStick&&!t.hlc){m=t._bodyWidth;K=l-m/2;if(s<p){if(t.wickColor){v.color=t.wickColor}else{if(t.downBodyColor){v.color=t.upBodyColor}}e=a.extend(true,{},q,v);t.shapeRenderer.draw(z,[[l,f],[l,s]],e);t.shapeRenderer.draw(z,[[l,p],[l,L]],e);v={};I=s;E=p-s;if(t.fillUpBody){v.fillRect=true}else{v.strokeRect=true;m=m-this.lineWidth;K=l-m/2}if(t.upBodyColor){v.color=t.upBodyColor;v.fillStyle=t.upBodyColor}B=[K,I,m,E]}else{if(s>p){if(t.wickColor){v.color=t.wickColor}else{if(t.downBodyColor){v.color=t.downBodyColor}}e=a.extend(true,{},q,v);t.shapeRenderer.draw(z,[[l,f],[l,p]],e);t.shapeRenderer.draw(z,[[l,s],[l,L]],e);v={};I=p;E=s-p;if(t.fillDownBody){v.fillRect=true}else{v.strokeRect=true;m=m-this.lineWidth;K=l-m/2}if(t.downBodyColor){v.color=t.downBodyColor;v.fillStyle=t.downBodyColor}B=[K,I,m,E]}else{if(t.wickColor){v.color=t.wickColor}e=a.extend(true,{},q,v);t.shapeRenderer.draw(z,[[l,f],[l,L]],e);v={};v.fillRect=false;v.strokeRect=false;K=[l-m/2,p];I=[l+m/2,s];m=null;E=null;B=[K,I]}}e=a.extend(true,{},q,v);t.shapeRenderer.draw(z,B,e)}else{D=q.color;if(t.openColor){q.color=t.openColor}if(!t.hlc){t.shapeRenderer.draw(z,[[l-t._tickLength,p],[l,p]],q)}q.color=D;if(t.wickColor){q.color=t.wickColor}t.shapeRenderer.draw(z,[[l,f],[l,L]],q);q.color=D;if(t.closeColor){q.color=t.closeColor}t.shapeRenderer.draw(z,[[l,s],[l+t._tickLength,s]],q);q.color=D}}}z.restore()};a.jqplot.OHLCRenderer.prototype.drawShadow=function(b,d,c){};a.jqplot.OHLCRenderer.checkOptions=function(d,c,b){if(!b.highlighter){b.highlighter={showMarker:false,tooltipAxes:"y",yvalues:4,formatString:'<table class="jqplot-highlighter"><tr><td>date:</td><td>%s</td></tr><tr><td>open:</td><td>%s</td></tr><tr><td>hi:</td><td>%s</td></tr><tr><td>low:</td><td>%s</td></tr><tr><td>close:</td><td>%s</td></tr></table>'}}}})(jQuery);
|
|
@ -1,333 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2009 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* The author would appreciate an email letting him know of any substantial
|
||||
* use of jqPlot. You can reach the author at: chris dot leonello at gmail
|
||||
* dot com or see http://www.jqplot.com/info.php . This is, of course,
|
||||
* not required.
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* Thanks for using jqPlot!
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
/**
|
||||
* Class: $.jqplot.PieRenderer
|
||||
* Plugin renderer to draw a pie chart.
|
||||
* Pie charts will draw only the first series. Other series are ignored.
|
||||
* x values, if present, will be used as slice labels.
|
||||
* y values give slice size.
|
||||
*/
|
||||
$.jqplot.PieRenderer = function(){
|
||||
$.jqplot.LineRenderer.call(this);
|
||||
};
|
||||
|
||||
$.jqplot.PieRenderer.prototype = new $.jqplot.LineRenderer();
|
||||
$.jqplot.PieRenderer.prototype.constructor = $.jqplot.PieRenderer;
|
||||
|
||||
// called with scope of a series
|
||||
$.jqplot.PieRenderer.prototype.init = function(options) {
|
||||
// Group: Properties
|
||||
//
|
||||
// prop: diameter
|
||||
// diameter of the pie, auto computed by default
|
||||
this.diameter = null;
|
||||
// prop: padding
|
||||
// padding between the pie and plot edges, legend, etc.
|
||||
this.padding = 20;
|
||||
// prop: sliceMargin
|
||||
// pixels spacing between pie slices.
|
||||
this.sliceMargin = 0;
|
||||
// prop: fill
|
||||
// true or false, wether to fil the slices.
|
||||
this.fill = true;
|
||||
// prop: shadowOffset
|
||||
// offset of the shadow from the slice and offset of
|
||||
// each succesive stroke of the shadow from the last.
|
||||
this.shadowOffset = 2;
|
||||
// prop: shadowAlpha
|
||||
// transparency of the shadow (0 = transparent, 1 = opaque)
|
||||
this.shadowAlpha = 0.07;
|
||||
// prop: shadowDepth
|
||||
// number of strokes to apply to the shadow,
|
||||
// each stroke offset shadowOffset from the last.
|
||||
this.shadowDepth = 5;
|
||||
this.tickRenderer = $.jqplot.PieTickRenderer;
|
||||
$.extend(true, this, options);
|
||||
if (this.diameter != null) {
|
||||
this.diameter = this.diameter - this.sliceMargin;
|
||||
}
|
||||
this._diameter = null;
|
||||
};
|
||||
|
||||
$.jqplot.PieRenderer.prototype.setGridData = function(plot) {
|
||||
// this is a no-op
|
||||
};
|
||||
|
||||
$.jqplot.PieRenderer.prototype.makeGridData = function(data, plot) {
|
||||
var stack = [];
|
||||
var td = [];
|
||||
for (var i=0; i<data.length; i++){
|
||||
stack.push(data[i][1]);
|
||||
td.push([data[i][0]]);
|
||||
if (i>0) {
|
||||
stack[i] += stack[i-1];
|
||||
}
|
||||
}
|
||||
var fact = Math.PI*2/stack[stack.length - 1];
|
||||
|
||||
for (var i=0; i<stack.length; i++) {
|
||||
td[i][1] = stack[i] * fact;
|
||||
}
|
||||
return td;
|
||||
};
|
||||
|
||||
$.jqplot.PieRenderer.prototype.drawSlice = function (ctx, ang1, ang2, color, isShadow) {
|
||||
var r = this._diameter / 2;
|
||||
var fill = this.fill;
|
||||
var lineWidth = this.lineWidth;
|
||||
ctx.save();
|
||||
ctx.translate(this.sliceMargin*Math.cos((ang1+ang2)/2), this.sliceMargin*Math.sin((ang1+ang2)/2));
|
||||
|
||||
if (isShadow) {
|
||||
for (var i=0; i<this.shadowDepth; i++) {
|
||||
ctx.save();
|
||||
ctx.translate(this.shadowOffset*Math.cos(this.shadowAngle/180*Math.PI), this.shadowOffset*Math.sin(this.shadowAngle/180*Math.PI));
|
||||
doDraw();
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
doDraw();
|
||||
}
|
||||
|
||||
function doDraw () {
|
||||
// Fix for IE and Chrome that can't seem to draw circles correctly.
|
||||
// ang2 should always be <= 2 pi since that is the way the data is converted.
|
||||
if (ang2 > 6.282) {
|
||||
ang2 = 6.282;
|
||||
if (ang1 > ang2) {
|
||||
ang1 = 6.281;
|
||||
}
|
||||
}
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(0, 0);
|
||||
ctx.fillStyle = color;
|
||||
ctx.strokeStyle = color;
|
||||
ctx.lineWidth = lineWidth;
|
||||
ctx.arc(0, 0, r, ang1, ang2, false);
|
||||
ctx.closePath();
|
||||
if (fill) {
|
||||
ctx.fill();
|
||||
}
|
||||
else {
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
|
||||
if (isShadow) {
|
||||
for (var i=0; i<this.shadowDepth; i++) {
|
||||
ctx.restore();
|
||||
}
|
||||
}
|
||||
|
||||
ctx.restore();
|
||||
};
|
||||
|
||||
// called with scope of series
|
||||
$.jqplot.PieRenderer.prototype.draw = function (ctx, gd, options) {
|
||||
var i;
|
||||
var opts = (options != undefined) ? options : {};
|
||||
// offset and direction of offset due to legend placement
|
||||
var offx = 0;
|
||||
var offy = 0;
|
||||
var trans = 1;
|
||||
var colorGenerator = new this.colorGenerator(this.seriesColors);
|
||||
if (options.legendInfo) {
|
||||
var li = options.legendInfo;
|
||||
switch (li.location) {
|
||||
case 'nw':
|
||||
offx = li.width + li.xoffset;
|
||||
break;
|
||||
case 'w':
|
||||
offx = li.width + li.xoffset;
|
||||
break;
|
||||
case 'sw':
|
||||
offx = li.width + li.xoffset;
|
||||
break;
|
||||
case 'ne':
|
||||
offx = li.width + li.xoffset;
|
||||
trans = -1;
|
||||
break;
|
||||
case 'e':
|
||||
offx = li.width + li.xoffset;
|
||||
trans = -1;
|
||||
break;
|
||||
case 'se':
|
||||
offx = li.width + li.xoffset;
|
||||
trans = -1;
|
||||
break;
|
||||
case 'n':
|
||||
offy = li.height + li.yoffset;
|
||||
break;
|
||||
case 's':
|
||||
offy = li.height + li.yoffset;
|
||||
trans = -1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var shadow = (opts.shadow != undefined) ? opts.shadow : this.shadow;
|
||||
var showLine = (opts.showLine != undefined) ? opts.showLine : this.showLine;
|
||||
var fill = (opts.fill != undefined) ? opts.fill : this.fill;
|
||||
var cw = ctx.canvas.width;
|
||||
var ch = ctx.canvas.height;
|
||||
var w = cw - offx - 2 * this.padding;
|
||||
var h = ch - offy - 2 * this.padding;
|
||||
var d = Math.min(w,h);
|
||||
this._diameter = this.diameter || d - this.sliceMargin;
|
||||
// this.diameter -= this.sliceMargin;
|
||||
var r = this._diameter/2;
|
||||
ctx.save();
|
||||
ctx.translate((cw - trans * offx)/2 + trans * offx, (ch - trans*offy)/2 + trans * offy);
|
||||
|
||||
if (this.shadow) {
|
||||
var shadowColor = 'rgba(0,0,0,'+this.shadowAlpha+')';
|
||||
for (var i=0; i<gd.length; i++) {
|
||||
var ang1 = (i == 0) ? 0 : gd[i-1][1];
|
||||
this.renderer.drawSlice.call (this, ctx, ang1, gd[i][1], shadowColor, true);
|
||||
}
|
||||
|
||||
}
|
||||
for (var i=0; i<gd.length; i++) {
|
||||
var ang1 = (i == 0) ? 0 : gd[i-1][1];
|
||||
this.renderer.drawSlice.call (this, ctx, ang1, gd[i][1], colorGenerator.next());
|
||||
}
|
||||
|
||||
ctx.restore();
|
||||
};
|
||||
|
||||
$.jqplot.PieAxisRenderer = function() {
|
||||
$.jqplot.LinearAxisRenderer.call(this);
|
||||
};
|
||||
|
||||
$.jqplot.PieAxisRenderer.prototype = new $.jqplot.LinearAxisRenderer();
|
||||
$.jqplot.PieAxisRenderer.prototype.constructor = $.jqplot.PieAxisRenderer;
|
||||
|
||||
|
||||
// There are no traditional axes on a pie chart. We just need to provide
|
||||
// dummy objects with properties so the plot will render.
|
||||
// called with scope of axis object.
|
||||
$.jqplot.PieAxisRenderer.prototype.init = function(options){
|
||||
//
|
||||
this.tickRenderer = $.jqplot.PieTickRenderer;
|
||||
$.extend(true, this, options);
|
||||
// I don't think I'm going to need _dataBounds here.
|
||||
// have to go Axis scaling in a way to fit chart onto plot area
|
||||
// and provide u2p and p2u functionality for mouse cursor, etc.
|
||||
// for convienence set _dataBounds to 0 and 100 and
|
||||
// set min/max to 0 and 100.
|
||||
this._dataBounds = {min:0, max:100};
|
||||
this.min = 0;
|
||||
this.max = 100;
|
||||
this.showTicks = false;
|
||||
this.ticks = [];
|
||||
this.showMark = false;
|
||||
this.show = false;
|
||||
};
|
||||
|
||||
$.jqplot.PieLegendRenderer = function() {
|
||||
$.jqplot.TableLegendRenderer.call(this);
|
||||
};
|
||||
|
||||
$.jqplot.PieLegendRenderer.prototype = new $.jqplot.TableLegendRenderer();
|
||||
$.jqplot.PieLegendRenderer.prototype.constructor = $.jqplot.PieLegendRenderer;
|
||||
|
||||
// called with context of legend
|
||||
$.jqplot.PieLegendRenderer.prototype.draw = function() {
|
||||
var legend = this;
|
||||
if (this.show) {
|
||||
var series = this._series;
|
||||
// make a table. one line label per row.
|
||||
var ss = 'position:absolute;';
|
||||
ss += (this.background) ? 'background:'+this.background+';' : '';
|
||||
ss += (this.border) ? 'border:'+this.border+';' : '';
|
||||
ss += (this.fontSize) ? 'font-size:'+this.fontSize+';' : '';
|
||||
ss += (this.fontFamily) ? 'font-family:'+this.fontFamily+';' : '';
|
||||
ss += (this.textColor) ? 'color:'+this.textColor+';' : '';
|
||||
this._elem = $('<table class="jqplot-table-legend" style="'+ss+'"></table>');
|
||||
|
||||
var pad = false;
|
||||
var s = series[0];
|
||||
var colorGenerator = new s.colorGenerator(s.seriesColors);
|
||||
if (s.show) {
|
||||
var pd = s.data;
|
||||
for (var i=0; i<pd.length; i++){
|
||||
var lt = pd[i][0].toString();
|
||||
if (lt) {
|
||||
this.renderer.addrow.call(this, lt, colorGenerator.next(), pad);
|
||||
pad = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return this._elem;
|
||||
};
|
||||
|
||||
// setup default renderers for axes and legend so user doesn't have to
|
||||
// called with scope of plot
|
||||
function preInit(target, data, options) {
|
||||
options = options || {};
|
||||
options.axesDefaults = options.axesDefaults || {};
|
||||
options.legend = options.legend || {};
|
||||
options.seriesDefaults = options.seriesDefaults || {};
|
||||
// only set these if there is a pie series
|
||||
var setopts = false;
|
||||
if (options.seriesDefaults.renderer == $.jqplot.PieRenderer) {
|
||||
setopts = true;
|
||||
}
|
||||
else if (options.series) {
|
||||
for (var i=0; i < options.series.length; i++) {
|
||||
if (options.series[i].renderer == $.jqplot.PieRenderer) {
|
||||
setopts = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (setopts) {
|
||||
options.axesDefaults.renderer = $.jqplot.PieAxisRenderer;
|
||||
options.legend.renderer = $.jqplot.PieLegendRenderer;
|
||||
options.legend.preDraw = true;
|
||||
// options.seriesDefaults.colorGenerator = this.colorGenerator;
|
||||
// options.seriesDefaults.seriesColors = this.seriesColors;
|
||||
}
|
||||
}
|
||||
|
||||
// called with scope of plot
|
||||
function postParseOptions(options) {
|
||||
for (var i=0; i<this.series.length; i++) {
|
||||
this.series[i].seriesColors = this.seriesColors;
|
||||
this.series[i].colorGenerator = this.colorGenerator;
|
||||
}
|
||||
}
|
||||
|
||||
$.jqplot.preInitHooks.push(preInit);
|
||||
$.jqplot.postParseOptionsHooks.push(postParseOptions);
|
||||
|
||||
$.jqplot.PieTickRenderer = function() {
|
||||
$.jqplot.AxisTickRenderer.call(this);
|
||||
};
|
||||
|
||||
$.jqplot.PieTickRenderer.prototype = new $.jqplot.AxisTickRenderer();
|
||||
$.jqplot.PieTickRenderer.prototype.constructor = $.jqplot.PieTickRenderer;
|
||||
|
||||
})(jQuery);
|
||||
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2009 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris dot leonello at gmail dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*/
|
||||
(function(b){b.jqplot.PieRenderer=function(){b.jqplot.LineRenderer.call(this)};b.jqplot.PieRenderer.prototype=new b.jqplot.LineRenderer();b.jqplot.PieRenderer.prototype.constructor=b.jqplot.PieRenderer;b.jqplot.PieRenderer.prototype.init=function(d){this.diameter=null;this.padding=20;this.sliceMargin=0;this.fill=true;this.shadowOffset=2;this.shadowAlpha=0.07;this.shadowDepth=5;this.tickRenderer=b.jqplot.PieTickRenderer;b.extend(true,this,d);if(this.diameter!=null){this.diameter=this.diameter-this.sliceMargin}this._diameter=null};b.jqplot.PieRenderer.prototype.setGridData=function(d){};b.jqplot.PieRenderer.prototype.makeGridData=function(g,h){var d=[];var j=[];for(var f=0;f<g.length;f++){d.push(g[f][1]);j.push([g[f][0]]);if(f>0){d[f]+=d[f-1]}}var e=Math.PI*2/d[d.length-1];for(var f=0;f<d.length;f++){j[f][1]=d[f]*e}return j};b.jqplot.PieRenderer.prototype.drawSlice=function(n,l,k,f,h){var d=this._diameter/2;var m=this.fill;var j=this.lineWidth;n.save();n.translate(this.sliceMargin*Math.cos((l+k)/2),this.sliceMargin*Math.sin((l+k)/2));if(h){for(var g=0;g<this.shadowDepth;g++){n.save();n.translate(this.shadowOffset*Math.cos(this.shadowAngle/180*Math.PI),this.shadowOffset*Math.sin(this.shadowAngle/180*Math.PI));e()}}else{e()}function e(){if(k>6.282){k=6.282;if(l>k){l=6.281}}n.beginPath();n.moveTo(0,0);n.fillStyle=f;n.strokeStyle=f;n.lineWidth=j;n.arc(0,0,d,l,k,false);n.closePath();if(m){n.fill()}else{n.stroke()}}if(h){for(var g=0;g<this.shadowDepth;g++){n.restore()}}n.restore()};b.jqplot.PieRenderer.prototype.draw=function(v,B,k){var y;var s=(k!=undefined)?k:{};var g=0;var f=0;var l=1;var e=new this.colorGenerator(this.seriesColors);if(k.legendInfo){var q=k.legendInfo;switch(q.location){case"nw":g=q.width+q.xoffset;break;case"w":g=q.width+q.xoffset;break;case"sw":g=q.width+q.xoffset;break;case"ne":g=q.width+q.xoffset;l=-1;break;case"e":g=q.width+q.xoffset;l=-1;break;case"se":g=q.width+q.xoffset;l=-1;break;case"n":f=q.height+q.yoffset;break;case"s":f=q.height+q.yoffset;l=-1;break;default:break}}var n=(s.shadow!=undefined)?s.shadow:this.shadow;var C=(s.showLine!=undefined)?s.showLine:this.showLine;var x=(s.fill!=undefined)?s.fill:this.fill;var j=v.canvas.width;var p=v.canvas.height;var o=j-g-2*this.padding;var z=p-f-2*this.padding;var A=Math.min(o,z);this._diameter=this.diameter||A-this.sliceMargin;var t=this._diameter/2;v.save();v.translate((j-l*g)/2+l*g,(p-l*f)/2+l*f);if(this.shadow){var u="rgba(0,0,0,"+this.shadowAlpha+")";for(var y=0;y<B.length;y++){var m=(y==0)?0:B[y-1][1];this.renderer.drawSlice.call(this,v,m,B[y][1],u,true)}}for(var y=0;y<B.length;y++){var m=(y==0)?0:B[y-1][1];this.renderer.drawSlice.call(this,v,m,B[y][1],e.next())}v.restore()};b.jqplot.PieAxisRenderer=function(){b.jqplot.LinearAxisRenderer.call(this)};b.jqplot.PieAxisRenderer.prototype=new b.jqplot.LinearAxisRenderer();b.jqplot.PieAxisRenderer.prototype.constructor=b.jqplot.PieAxisRenderer;b.jqplot.PieAxisRenderer.prototype.init=function(d){this.tickRenderer=b.jqplot.PieTickRenderer;b.extend(true,this,d);this._dataBounds={min:0,max:100};this.min=0;this.max=100;this.showTicks=false;this.ticks=[];this.showMark=false;this.show=false};b.jqplot.PieLegendRenderer=function(){b.jqplot.TableLegendRenderer.call(this)};b.jqplot.PieLegendRenderer.prototype=new b.jqplot.TableLegendRenderer();b.jqplot.PieLegendRenderer.prototype.constructor=b.jqplot.PieLegendRenderer;b.jqplot.PieLegendRenderer.prototype.draw=function(){var k=this;if(this.show){var f=this._series;var m="position:absolute;";m+=(this.background)?"background:"+this.background+";":"";m+=(this.border)?"border:"+this.border+";":"";m+=(this.fontSize)?"font-size:"+this.fontSize+";":"";m+=(this.fontFamily)?"font-family:"+this.fontFamily+";":"";m+=(this.textColor)?"color:"+this.textColor+";":"";this._elem=b('<table class="jqplot-table-legend" style="'+m+'"></table>');var d=false;var l=f[0];var h=new l.colorGenerator(l.seriesColors);if(l.show){var j=l.data;for(var g=0;g<j.length;g++){var e=j[g][0].toString();if(e){this.renderer.addrow.call(this,e,h.next(),d);d=true}}}}return this._elem};function a(h,g,e){e=e||{};e.axesDefaults=e.axesDefaults||{};e.legend=e.legend||{};e.seriesDefaults=e.seriesDefaults||{};var d=false;if(e.seriesDefaults.renderer==b.jqplot.PieRenderer){d=true}else{if(e.series){for(var f=0;f<e.series.length;f++){if(e.series[f].renderer==b.jqplot.PieRenderer){d=true}}}}if(d){e.axesDefaults.renderer=b.jqplot.PieAxisRenderer;e.legend.renderer=b.jqplot.PieLegendRenderer;e.legend.preDraw=true}}function c(d){for(var e=0;e<this.series.length;e++){this.series[e].seriesColors=this.seriesColors;this.series[e].colorGenerator=this.colorGenerator}}b.jqplot.preInitHooks.push(a);b.jqplot.postParseOptionsHooks.push(c);b.jqplot.PieTickRenderer=function(){b.jqplot.AxisTickRenderer.call(this)};b.jqplot.PieTickRenderer.prototype=new b.jqplot.AxisTickRenderer();b.jqplot.PieTickRenderer.prototype.constructor=b.jqplot.PieTickRenderer})(jQuery);
|
|
@ -1,307 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2009 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* The author would appreciate an email letting him know of any substantial
|
||||
* use of jqPlot. You can reach the author at: chris dot leonello at gmail
|
||||
* dot com or see http://www.jqplot.com/info.php . This is, of course,
|
||||
* not required.
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* Thanks for using jqPlot!
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
|
||||
/**
|
||||
* Class: $.jqplot.PointLabels
|
||||
* Plugin for putting labels at the data points.
|
||||
*
|
||||
* To use this plugin, include the js
|
||||
* file in your source:
|
||||
*
|
||||
* > <script type="text/javascript" src="plugins/jqplot.pointLabels.js"></script>
|
||||
*
|
||||
* By default, the last value in the data ponit array in the data series is used
|
||||
* for the label. For most series renderers, extra data can be added to the
|
||||
* data point arrays and the last value will be used as the label.
|
||||
*
|
||||
* For instance,
|
||||
* this series:
|
||||
*
|
||||
* > [[1,4], [3,5], [7,2]]
|
||||
*
|
||||
* Would, by default, use the y values in the labels.
|
||||
* Extra data can be added to the series like so:
|
||||
*
|
||||
* > [[1,4,'mid'], [3 5,'hi'], [7,2,'low']]
|
||||
*
|
||||
* And now the point labels would be 'mid', 'low', and 'hi'.
|
||||
*
|
||||
* Options to the point labels and a custom labels array can be passed into the
|
||||
* "pointLabels" option on the series option like so:
|
||||
*
|
||||
* > series:[{pointLabels:{
|
||||
* > labels:['mid', 'hi', 'low'],
|
||||
* > location:'se',
|
||||
* > ypadding: 12
|
||||
* > }
|
||||
* > }]
|
||||
*
|
||||
* A custom labels array in the options takes precendence over any labels
|
||||
* in the series data. If you have a custom labels array in the options,
|
||||
* but still want to use values from the series array as labels, set the
|
||||
* "labelsFromSeries" option to true.
|
||||
*
|
||||
* By default, html entities (<, >, etc.) are escaped in point labels.
|
||||
* If you want to include actual html markup in the labels,
|
||||
* set the "escapeHTML" option to false.
|
||||
*
|
||||
*/
|
||||
$.jqplot.PointLabels = function(options) {
|
||||
// Group: Properties
|
||||
//
|
||||
// prop: show
|
||||
// show the labels or not.
|
||||
this.show = $.jqplot.config.enablePlugins;
|
||||
// prop: location
|
||||
// compass location where to position the label around the point.
|
||||
// 'n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw'
|
||||
this.location = 'n';
|
||||
// prop: labelsFromSeries
|
||||
// true to use labels within data point arrays.
|
||||
this.labelsFromSeries = false;
|
||||
// prop: seriesLabelIndex
|
||||
// array index for location of labels within data point arrays.
|
||||
// if null, will use the last element of teh data point array.
|
||||
this.seriesLabelIndex = null;
|
||||
// prop: labels
|
||||
// array of arrays of labels, one array for each series.
|
||||
this.labels = [];
|
||||
// prop: stackedValue
|
||||
// true to display value as stacked in a stacked plot.
|
||||
// no effect if labels is specified.
|
||||
this.stackedValue = false;
|
||||
// prop: ypadding
|
||||
// vertical padding in pixels between point and label
|
||||
this.ypadding = 6;
|
||||
// prop: xpadding
|
||||
// horizontal padding in pixels between point and label
|
||||
this.xpadding = 6;
|
||||
// prop: escapeHTML
|
||||
// true to escape html entities in the labels.
|
||||
// If you want to include markup in the labels, set to false.
|
||||
this.escapeHTML = true;
|
||||
// prop: edgeTolerance
|
||||
// Number of pixels that the label must be away from an axis
|
||||
// boundary in order to be drawn. Negative values will allow overlap
|
||||
// with the grid boundaries.
|
||||
this.edgeTolerance = 0;
|
||||
// prop: hideZeros
|
||||
// true to not show a label for a value which is 0.
|
||||
this.hideZeros = false;
|
||||
|
||||
$.extend(true, this, options);
|
||||
};
|
||||
|
||||
var locations = ['nw', 'n', 'ne', 'e', 'se', 's', 'sw', 'w'];
|
||||
var locationIndicies = {'nw':0, 'n':1, 'ne':2, 'e':3, 'se':4, 's':5, 'sw':6, 'w':7};
|
||||
var oppositeLocations = ['se', 's', 'sw', 'w', 'nw', 'n', 'ne', 'e'];
|
||||
|
||||
// called with scope of a series
|
||||
$.jqplot.PointLabels.init = function (target, data, seriesDefaults, opts){
|
||||
var options = $.extend(true, {}, seriesDefaults, opts);
|
||||
// add a pointLabels attribute to the series plugins
|
||||
this.plugins.pointLabels = new $.jqplot.PointLabels(options.pointLabels);
|
||||
var p = this.plugins.pointLabels;
|
||||
if (p.labels.length == 0 || p.labelsFromSeries) {
|
||||
if (p.stackedValue) {
|
||||
if (this._plotData.length && this._plotData[0].length){
|
||||
var idx = p.seriesLabelIndex || this._plotData[0].length -1;
|
||||
for (var i=0; i<this._plotData.length; i++) {
|
||||
p.labels.push(this._plotData[i][idx]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
var d = this.data;
|
||||
if (this.renderer.constructor == $.jqplot.BarRenderer && this.waterfall) {
|
||||
d = this._data;
|
||||
}
|
||||
if (d.length && d[0].length) {
|
||||
var idx = p.seriesLabelIndex || d[0].length -1;
|
||||
for (var i=0; i<d.length; i++) {
|
||||
p.labels.push(d[i][idx]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$.jqplot.PointLabels.prototype.xOffset = function(elem, location, padding) {
|
||||
location = location || this.location;
|
||||
padding = padding || this.xpadding;
|
||||
var offset;
|
||||
|
||||
switch (location) {
|
||||
case 'nw':
|
||||
offset = -elem.outerWidth(true) - this.xpadding;
|
||||
break;
|
||||
case 'n':
|
||||
offset = -elem.outerWidth(true)/2;
|
||||
break;
|
||||
case 'ne':
|
||||
offset = this.xpadding;
|
||||
break;
|
||||
case 'e':
|
||||
offset = this.xpadding;
|
||||
break;
|
||||
case 'se':
|
||||
offset = this.xpadding;
|
||||
break;
|
||||
case 's':
|
||||
offset = -elem.outerWidth(true)/2;
|
||||
break;
|
||||
case 'sw':
|
||||
offset = -elem.outerWidth(true) - this.xpadding;
|
||||
break;
|
||||
case 'w':
|
||||
offset = -elem.outerWidth(true) - this.xpadding;
|
||||
break;
|
||||
default: // same as 'nw'
|
||||
offset = -elem.outerWidth(true) - this.xpadding;
|
||||
break;
|
||||
}
|
||||
return offset;
|
||||
};
|
||||
|
||||
$.jqplot.PointLabels.prototype.yOffset = function(elem, location, padding) {
|
||||
location = location || this.location;
|
||||
padding = padding || this.xpadding;
|
||||
var offset;
|
||||
|
||||
switch (location) {
|
||||
case 'nw':
|
||||
offset = -elem.outerHeight(true) - this.ypadding;
|
||||
break;
|
||||
case 'n':
|
||||
offset = -elem.outerHeight(true) - this.ypadding;
|
||||
break;
|
||||
case 'ne':
|
||||
offset = -elem.outerHeight(true) - this.ypadding;
|
||||
break;
|
||||
case 'e':
|
||||
offset = -elem.outerHeight(true)/2;
|
||||
break;
|
||||
case 'se':
|
||||
offset = this.ypadding;
|
||||
break;
|
||||
case 's':
|
||||
offset = this.ypadding;
|
||||
break;
|
||||
case 'sw':
|
||||
offset = this.ypadding;
|
||||
break;
|
||||
case 'w':
|
||||
offset = -elem.outerHeight(true)/2;
|
||||
break;
|
||||
default: // same as 'nw'
|
||||
offset = -elem.outerHeight(true) - this.ypadding;
|
||||
break;
|
||||
}
|
||||
return offset;
|
||||
};
|
||||
|
||||
// called with scope of series
|
||||
$.jqplot.PointLabels.draw = function (sctx, options) {
|
||||
var p = this.plugins.pointLabels;
|
||||
if (p.show) {
|
||||
// var xoffset, yoffset;
|
||||
//
|
||||
// switch (p.location) {
|
||||
// case 'nw':
|
||||
// xoffset = function(elem) { return -elem.outerWidth(true) - p.xpadding; };
|
||||
// yoffset = function(elem) { return -elem.outerHeight(true) - p.ypadding; };
|
||||
// break;
|
||||
// case 'n':
|
||||
// xoffset = function(elem) { return -elem.outerWidth(true)/2; };
|
||||
// yoffset = function(elem) { return -elem.outerHeight(true) - p.ypadding; };
|
||||
// break;
|
||||
// case 'ne':
|
||||
// xoffset = function(elem) { return p.xpadding; };
|
||||
// yoffset = function(elem) { return -elem.outerHeight(true) - p.ypadding; };
|
||||
// break;
|
||||
// case 'e':
|
||||
// xoffset = function(elem) { return p.xpadding; };
|
||||
// yoffset = function(elem) { return -elem.outerHeight(true)/2; };
|
||||
// break;
|
||||
// case 'se':
|
||||
// xoffset = function(elem) { return p.xpadding; };
|
||||
// yoffset = function(elem) { return p.ypadding; };
|
||||
// break;
|
||||
// case 's':
|
||||
// xoffset = function(elem) { return -elem.outerWidth(true)/2; };
|
||||
// yoffset = function(elem) { return p.ypadding; };
|
||||
// break;
|
||||
// case 'sw':
|
||||
// xoffset = function(elem) { return -elem.outerWidth(true) - p.xpadding; };
|
||||
// yoffset = function(elem) { return p.ypadding; };
|
||||
// break;
|
||||
// case 'w':
|
||||
// xoffset = function(elem) { return -elem.outerWidth(true) - p.xpadding; };
|
||||
// yoffset = function(elem) { return -elem.outerHeight(true)/2; };
|
||||
// break;
|
||||
// default: // same as 'nw'
|
||||
// xoffset = function(elem) { return -elem.outerWidth(true) - p.xpadding; };
|
||||
// yoffset = function(elem) { return -elem.outerHeight(true) - p.ypadding; };
|
||||
// break;
|
||||
// }
|
||||
|
||||
for (var i=0; i<p.labels.length; i++) {
|
||||
var pd = this._plotData;
|
||||
var xax = this._xaxis;
|
||||
var yax = this._yaxis;
|
||||
var label = p.labels[i];
|
||||
|
||||
if (p.hideZeros && parseInt(p.labels[i], 10) == 0) {
|
||||
label = '';
|
||||
}
|
||||
|
||||
var elem = $('<div class="jqplot-point-label" style="position:absolute"></div>');
|
||||
elem.insertAfter(sctx.canvas);
|
||||
if (p.escapeHTML) {
|
||||
elem.text(label);
|
||||
}
|
||||
else {
|
||||
elem.html(label);
|
||||
}
|
||||
var location = p.location;
|
||||
if (this.waterfall && parseInt(label, 10) < 0) {
|
||||
location = oppositeLocations[locationIndicies[location]];
|
||||
}
|
||||
var ell = xax.u2p(pd[i][0]) + p.xOffset(elem, location);
|
||||
var elt = yax.u2p(pd[i][1]) + p.yOffset(elem, location);
|
||||
elem.css('left', ell);
|
||||
elem.css('top', elt);
|
||||
var elr = ell + $(elem).width();
|
||||
var elb = elt + $(elem).height();
|
||||
var et = p.edgeTolerance;
|
||||
var scl = $(sctx.canvas).position().left;
|
||||
var sct = $(sctx.canvas).position().top;
|
||||
var scr = sctx.canvas.width + scl;
|
||||
var scb = sctx.canvas.height + sct;
|
||||
// if label is outside of allowed area, remove it
|
||||
if (ell - et < scl || elt - et < sct || elr + et > scr || elb + et > scb) {
|
||||
$(elem).remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$.jqplot.postSeriesInitHooks.push($.jqplot.PointLabels.init);
|
||||
$.jqplot.postDrawSeriesHooks.push($.jqplot.PointLabels.draw);
|
||||
})(jQuery);
|
|
@ -1,273 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2009 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* The author would appreciate an email letting him know of any substantial
|
||||
* use of jqPlot. You can reach the author at: chris dot leonello at gmail
|
||||
* dot com or see http://www.jqplot.com/info.php . This is, of course,
|
||||
* not required.
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* Thanks for using jqPlot!
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
|
||||
/**
|
||||
* Class: $.jqplot.PointLabels
|
||||
* Plugin for putting labels at the data points.
|
||||
*
|
||||
* To use this plugin, include the js
|
||||
* file in your source:
|
||||
*
|
||||
* > <script type="text/javascript" src="plugins/jqplot.pointLabels.js"></script>
|
||||
*
|
||||
* By default, the last value in the data ponit array in the data series is used
|
||||
* for the label. For most series renderers, extra data can be added to the
|
||||
* data point arrays and the last value will be used as the label.
|
||||
*
|
||||
* For instance,
|
||||
* this series:
|
||||
*
|
||||
* > [[1,4], [3,5], [7,2]]
|
||||
*
|
||||
* Would, by default, use the y values in the labels.
|
||||
* Extra data can be added to the series like so:
|
||||
*
|
||||
* > [[1,4,'mid'], [3 5,'hi'], [7,2,'low']]
|
||||
*
|
||||
* And now the point labels would be 'mid', 'low', and 'hi'.
|
||||
*
|
||||
* Options to the point labels and a custom labels array can be passed into the
|
||||
* "pointLabels" option on the series option like so:
|
||||
*
|
||||
* > series:[{pointLabels:{
|
||||
* > labels:['mid', 'hi', 'low'],
|
||||
* > location:'se',
|
||||
* > ypadding: 12
|
||||
* > }
|
||||
* > }]
|
||||
*
|
||||
* A custom labels array in the options takes precendence over any labels
|
||||
* in the series data. If you have a custom labels array in the options,
|
||||
* but still want to use values from the series array as labels, set the
|
||||
* "labelsFromSeries" option to true.
|
||||
*
|
||||
* By default, html entities (<, >, etc.) are escaped in point labels.
|
||||
* If you want to include actual html markup in the labels,
|
||||
* set the "escapeHTML" option to false.
|
||||
*
|
||||
*/
|
||||
$.jqplot.PointLabels = function(options) {
|
||||
// Group: Properties
|
||||
//
|
||||
// prop: show
|
||||
// show the labels or not.
|
||||
this.show = $.jqplot.config.enablePlugins;
|
||||
// prop: location
|
||||
// compass location where to position the label around the point.
|
||||
// 'n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw'
|
||||
this.location = 'n';
|
||||
// prop: labelsFromSeries
|
||||
// true to use labels within data point arrays.
|
||||
this.labelsFromSeries = false;
|
||||
// prop: seriesLabelIndex
|
||||
// array index for location of labels within data point arrays.
|
||||
// if null, will use the last element of teh data point array.
|
||||
this.seriesLabelIndex = null;
|
||||
// prop: labels
|
||||
// array of arrays of labels, one array for each series.
|
||||
this.labels = [];
|
||||
// prop: stackedValue
|
||||
// true to display value as stacked in a stacked plot.
|
||||
// no effect if labels is specified.
|
||||
this.stackedValue = false;
|
||||
// prop: ypadding
|
||||
// vertical padding in pixels between point and label
|
||||
this.ypadding = 6;
|
||||
// prop: xpadding
|
||||
// horizontal padding in pixels between point and label
|
||||
this.xpadding = 6;
|
||||
// prop: escapeHTML
|
||||
// true to escape html entities in the labels.
|
||||
// If you want to include markup in the labels, set to false.
|
||||
this.escapeHTML = true;
|
||||
// prop: edgeTolerance
|
||||
// Number of pixels that the label must be away from an axis
|
||||
// boundary in order to be drawn. Negative values will allow overlap
|
||||
// with the grid boundaries.
|
||||
this.edgeTolerance = 0;
|
||||
// prop: hideZeros
|
||||
// true to not show a label for a value which is 0.
|
||||
this.hideZeros = false;
|
||||
// prop: formatString
|
||||
// format string to format label value
|
||||
this.formatString = '';
|
||||
// prop: formatter
|
||||
// formatter function to use with format string.
|
||||
this.formatter = $.jqplot.sprintf;
|
||||
|
||||
$.extend(true, this, options);
|
||||
};
|
||||
|
||||
var locations = ['nw', 'n', 'ne', 'e', 'se', 's', 'sw', 'w'];
|
||||
var locationIndicies = {'nw':0, 'n':1, 'ne':2, 'e':3, 'se':4, 's':5, 'sw':6, 'w':7};
|
||||
var oppositeLocations = ['se', 's', 'sw', 'w', 'nw', 'n', 'ne', 'e'];
|
||||
|
||||
// called with scope of a series
|
||||
$.jqplot.PointLabels.init = function (target, data, seriesDefaults, opts){
|
||||
var options = $.extend(true, {}, seriesDefaults, opts);
|
||||
// add a pointLabels attribute to the series plugins
|
||||
this.plugins.pointLabels = new $.jqplot.PointLabels(options.pointLabels);
|
||||
var p = this.plugins.pointLabels;
|
||||
if (p.labels.length == 0 || p.labelsFromSeries) {
|
||||
if (p.stackedValue) {
|
||||
if (this._plotData.length && this._plotData[0].length){
|
||||
var idx = p.seriesLabelIndex || this._plotData[0].length -1;
|
||||
for (var i=0; i<this._plotData.length; i++) {
|
||||
p.labels.push(this._plotData[i][idx]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
var d = this.data;
|
||||
if (this.renderer.constructor == $.jqplot.BarRenderer && this.waterfall) {
|
||||
d = this._data;
|
||||
}
|
||||
if (d.length && d[0].length) {
|
||||
var idx = p.seriesLabelIndex || d[0].length -1;
|
||||
for (var i=0; i<d.length; i++) {
|
||||
p.labels.push(d[i][idx]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$.jqplot.PointLabels.prototype.xOffset = function(elem, location, padding) {
|
||||
location = location || this.location;
|
||||
padding = padding || this.xpadding;
|
||||
var offset;
|
||||
|
||||
switch (location) {
|
||||
case 'nw':
|
||||
offset = -elem.outerWidth(true) - this.xpadding;
|
||||
break;
|
||||
case 'n':
|
||||
offset = -elem.outerWidth(true)/2;
|
||||
break;
|
||||
case 'ne':
|
||||
offset = this.xpadding;
|
||||
break;
|
||||
case 'e':
|
||||
offset = this.xpadding;
|
||||
break;
|
||||
case 'se':
|
||||
offset = this.xpadding;
|
||||
break;
|
||||
case 's':
|
||||
offset = -elem.outerWidth(true)/2;
|
||||
break;
|
||||
case 'sw':
|
||||
offset = -elem.outerWidth(true) - this.xpadding;
|
||||
break;
|
||||
case 'w':
|
||||
offset = -elem.outerWidth(true) - this.xpadding;
|
||||
break;
|
||||
default: // same as 'nw'
|
||||
offset = -elem.outerWidth(true) - this.xpadding;
|
||||
break;
|
||||
}
|
||||
return offset;
|
||||
};
|
||||
|
||||
$.jqplot.PointLabels.prototype.yOffset = function(elem, location, padding) {
|
||||
location = location || this.location;
|
||||
padding = padding || this.xpadding;
|
||||
var offset;
|
||||
|
||||
switch (location) {
|
||||
case 'nw':
|
||||
offset = -elem.outerHeight(true) - this.ypadding;
|
||||
break;
|
||||
case 'n':
|
||||
offset = -elem.outerHeight(true) - this.ypadding;
|
||||
break;
|
||||
case 'ne':
|
||||
offset = -elem.outerHeight(true) - this.ypadding;
|
||||
break;
|
||||
case 'e':
|
||||
offset = -elem.outerHeight(true)/2;
|
||||
break;
|
||||
case 'se':
|
||||
offset = this.ypadding;
|
||||
break;
|
||||
case 's':
|
||||
offset = this.ypadding;
|
||||
break;
|
||||
case 'sw':
|
||||
offset = this.ypadding;
|
||||
break;
|
||||
case 'w':
|
||||
offset = -elem.outerHeight(true)/2;
|
||||
break;
|
||||
default: // same as 'nw'
|
||||
offset = -elem.outerHeight(true) - this.ypadding;
|
||||
break;
|
||||
}
|
||||
return offset;
|
||||
};
|
||||
|
||||
// called with scope of series
|
||||
$.jqplot.PointLabels.draw = function (sctx, options) {
|
||||
var p = this.plugins.pointLabels;
|
||||
if (p.show) {
|
||||
|
||||
for (var i=0; i<p.labels.length; i++) {
|
||||
var pd = this._plotData;
|
||||
var xax = this._xaxis;
|
||||
var yax = this._yaxis;
|
||||
var label = p.labels[i];
|
||||
|
||||
if (p.hideZeros && parseInt(p.labels[i], 10) == 0) {
|
||||
label = '';
|
||||
}
|
||||
|
||||
var elem = $('<div class="jqplot-point-label" style="position:absolute"></div>');
|
||||
elem.insertAfter(sctx.canvas);
|
||||
if (p.escapeHTML) {
|
||||
elem.text(label);
|
||||
}
|
||||
else {
|
||||
elem.html(label);
|
||||
}
|
||||
var location = p.location;
|
||||
if (this.waterfall && parseInt(label, 10) < 0) {
|
||||
location = oppositeLocations[locationIndicies[location]];
|
||||
}
|
||||
var ell = xax.u2p(pd[i][0]) + p.xOffset(elem, location);
|
||||
var elt = yax.u2p(pd[i][1]) + p.yOffset(elem, location);
|
||||
elem.css('left', ell);
|
||||
elem.css('top', elt);
|
||||
var elr = ell + $(elem).width();
|
||||
var elb = elt + $(elem).height();
|
||||
var et = p.edgeTolerance;
|
||||
var scl = $(sctx.canvas).position().left;
|
||||
var sct = $(sctx.canvas).position().top;
|
||||
var scr = sctx.canvas.width + scl;
|
||||
var scb = sctx.canvas.height + sct;
|
||||
// if label is outside of allowed area, remove it
|
||||
if (ell - et < scl || elt - et < sct || elr + et > scr || elb + et > scb) {
|
||||
$(elem).remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$.jqplot.postSeriesInitHooks.push($.jqplot.PointLabels.init);
|
||||
$.jqplot.postDrawSeriesHooks.push($.jqplot.PointLabels.draw);
|
||||
})(jQuery);
|
|
@ -1,14 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2009 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris dot leonello at gmail dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*/
|
||||
(function(c){c.jqplot.PointLabels=function(e){this.show=c.jqplot.config.enablePlugins;this.location="n";this.labelsFromSeries=false;this.seriesLabelIndex=null;this.labels=[];this.stackedValue=false;this.ypadding=6;this.xpadding=6;this.escapeHTML=true;this.edgeTolerance=0;this.hideZeros=false;c.extend(true,this,e)};var a=["nw","n","ne","e","se","s","sw","w"];var d={nw:0,n:1,ne:2,e:3,se:4,s:5,sw:6,w:7};var b=["se","s","sw","w","nw","n","ne","e"];c.jqplot.PointLabels.init=function(k,h,g,e){var n=c.extend(true,{},g,e);this.plugins.pointLabels=new c.jqplot.PointLabels(n.pointLabels);var f=this.plugins.pointLabels;if(f.labels.length==0||f.labelsFromSeries){if(f.stackedValue){if(this._plotData.length&&this._plotData[0].length){var m=f.seriesLabelIndex||this._plotData[0].length-1;for(var j=0;j<this._plotData.length;j++){f.labels.push(this._plotData[j][m])}}}else{var l=this.data;if(this.renderer.constructor==c.jqplot.BarRenderer&&this.waterfall){l=this._data}if(l.length&&l[0].length){var m=f.seriesLabelIndex||l[0].length-1;for(var j=0;j<l.length;j++){f.labels.push(l[j][m])}}}}};c.jqplot.PointLabels.prototype.xOffset=function(f,e,g){e=e||this.location;g=g||this.xpadding;var h;switch(e){case"nw":h=-f.outerWidth(true)-this.xpadding;break;case"n":h=-f.outerWidth(true)/2;break;case"ne":h=this.xpadding;break;case"e":h=this.xpadding;break;case"se":h=this.xpadding;break;case"s":h=-f.outerWidth(true)/2;break;case"sw":h=-f.outerWidth(true)-this.xpadding;break;case"w":h=-f.outerWidth(true)-this.xpadding;break;default:h=-f.outerWidth(true)-this.xpadding;break}return h};c.jqplot.PointLabels.prototype.yOffset=function(f,e,g){e=e||this.location;g=g||this.xpadding;var h;switch(e){case"nw":h=-f.outerHeight(true)-this.ypadding;break;case"n":h=-f.outerHeight(true)-this.ypadding;break;case"ne":h=-f.outerHeight(true)-this.ypadding;break;case"e":h=-f.outerHeight(true)/2;break;case"se":h=this.ypadding;break;case"s":h=this.ypadding;break;case"sw":h=this.ypadding;break;case"w":h=-f.outerHeight(true)/2;break;default:h=-f.outerHeight(true)-this.ypadding;break}return h};c.jqplot.PointLabels.draw=function(s,h){var q=this.plugins.pointLabels;if(q.show){for(var r=0;r<q.labels.length;r++){var y=this._plotData;var v=this._xaxis;var n=this._yaxis;var m=q.labels[r];if(q.hideZeros&&parseInt(q.labels[r],10)==0){m=""}var u=c('<div class="jqplot-point-label" style="position:absolute"></div>');u.insertAfter(s.canvas);if(q.escapeHTML){u.text(m)}else{u.html(m)}var f=q.location;if(this.waterfall&&parseInt(m,10)<0){f=b[d[f]]}var l=v.u2p(y[r][0])+q.xOffset(u,f);var g=n.u2p(y[r][1])+q.yOffset(u,f);u.css("left",l);u.css("top",g);var j=l+c(u).width();var o=g+c(u).height();var x=q.edgeTolerance;var e=c(s.canvas).position().left;var t=c(s.canvas).position().top;var w=s.canvas.width+e;var k=s.canvas.height+t;if(l-x<e||g-x<t||j+x>w||o+x>k){c(u).remove()}}}};c.jqplot.postSeriesInitHooks.push(c.jqplot.PointLabels.init);c.jqplot.postDrawSeriesHooks.push(c.jqplot.PointLabels.draw)})(jQuery);
|
|
@ -1,208 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2009 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* The author would appreciate an email letting him know of any substantial
|
||||
* use of jqPlot. You can reach the author at: chris dot leonello at gmail
|
||||
* dot com or see http://www.jqplot.com/info.php . This is, of course,
|
||||
* not required.
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*
|
||||
* Thanks for using jqPlot!
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
|
||||
/**
|
||||
* Class: $.jqplot.Trendline
|
||||
* Plugin which will automatically compute and draw trendlines for plotted data.
|
||||
*/
|
||||
$.jqplot.Trendline = function() {
|
||||
// Group: Properties
|
||||
|
||||
// prop: show
|
||||
// Wether or not to show the trend line.
|
||||
this.show = $.jqplot.config.enablePlugins;
|
||||
// prop: color
|
||||
// CSS color spec for the trend line.
|
||||
// By default this wil be the same color as the primary line.
|
||||
this.color = '#666666';
|
||||
// prop: renderer
|
||||
// Renderer to use to draw the trend line.
|
||||
// The data series that is plotted may not be rendered as a line.
|
||||
// Therefore, we use our own line renderer here to draw a trend line.
|
||||
this.renderer = new $.jqplot.LineRenderer();
|
||||
// prop: rendererOptions
|
||||
// Options to pass to the line renderer.
|
||||
// By default, markers are not shown on trend lines.
|
||||
this.rendererOptions = {marker:{show:false}};
|
||||
// prop: label
|
||||
// Label for the trend line to use in the legend.
|
||||
this.label = '';
|
||||
// prop: type
|
||||
// Either 'exponential', 'exp', or 'linear'.
|
||||
this.type = 'linear';
|
||||
// prop: shadow
|
||||
// true or false, wether or not to show the shadow.
|
||||
this.shadow = true;
|
||||
// prop: markerRenderer
|
||||
// Renderer to use to draw markers on the line.
|
||||
// I think this is wrong.
|
||||
this.markerRenderer = {show:false};
|
||||
// prop: lineWidth
|
||||
// Width of the trend line.
|
||||
this.lineWidth = 1.5;
|
||||
// prop: shadowAngle
|
||||
// Angle of the shadow on the trend line.
|
||||
this.shadowAngle = 45;
|
||||
// prop: shadowOffset
|
||||
// pixel offset for each stroke of the shadow.
|
||||
this.shadowOffset = 1.0;
|
||||
// prop: shadowAlpha
|
||||
// Alpha transparency of the shadow.
|
||||
this.shadowAlpha = 0.07;
|
||||
// prop: shadowDepth
|
||||
// number of strokes to make of the shadow.
|
||||
this.shadowDepth = 3;
|
||||
|
||||
};
|
||||
|
||||
$.jqplot.postParseSeriesOptionsHooks.push(parseTrendLineOptions);
|
||||
$.jqplot.postDrawSeriesHooks.push(drawTrendline);
|
||||
$.jqplot.addLegendRowHooks.push(addTrendlineLegend);
|
||||
|
||||
// called witin scope of the legend object
|
||||
// current series passed in
|
||||
// must return null or an object {label:label, color:color}
|
||||
function addTrendlineLegend(series) {
|
||||
var lt = series.trendline.label.toString();
|
||||
var ret = null;
|
||||
if (this.renderer.constructor != $.jqplot.PieRenderer && series.trendline.show && lt) {
|
||||
ret = {label:lt, color:series.trendline.color};
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// called within scope of a series
|
||||
function parseTrendLineOptions (seriesDefaults, options) {
|
||||
if (this.renderer.constructor != $.jqplot.PieRenderer) {
|
||||
this.trendline = new $.jqplot.Trendline();
|
||||
options = options || {};
|
||||
$.extend(true, this.trendline, {color:this.color}, seriesDefaults.trendline, options.trendline);
|
||||
this.trendline.renderer.init.call(this.trendline, null);
|
||||
}
|
||||
}
|
||||
|
||||
// called within scope of series object
|
||||
function drawTrendline(sctx, options) {
|
||||
// if we have options, merge trendline options in with precedence
|
||||
options = $.extend(true, {}, this.trendline, options);
|
||||
|
||||
if (options.show && this.renderer.constructor != $.jqplot.PieRenderer) {
|
||||
var fit;
|
||||
// this.renderer.setGridData.call(this);
|
||||
var data = options.data || this.data;
|
||||
fit = fitData(data, this.trendline.type);
|
||||
var gridData = options.gridData || this.renderer.makeGridData.call(this, fit.data);
|
||||
|
||||
this.trendline.renderer.draw.call(this.trendline, sctx, gridData, {showLine:true, shadow:this.trendline.shadow});
|
||||
}
|
||||
}
|
||||
|
||||
function regression(x, y, typ) {
|
||||
var type = (typ == null) ? 'linear' : typ;
|
||||
var N = x.length;
|
||||
var slope;
|
||||
var intercept;
|
||||
var SX = 0;
|
||||
var SY = 0;
|
||||
var SXX = 0;
|
||||
var SXY = 0;
|
||||
var SYY = 0;
|
||||
var Y = [];
|
||||
var X = [];
|
||||
|
||||
if (type == 'linear') {
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
else if (type == 'exp' || type == 'exponential') {
|
||||
for ( var i=0; i<y.length; i++) {
|
||||
// ignore points <= 0, log undefined.
|
||||
if (y[i] <= 0) {
|
||||
N--;
|
||||
}
|
||||
else {
|
||||
X.push(x[i]);
|
||||
Y.push(Math.log(y[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for ( var i = 0; i < N; i++) {
|
||||
SX = SX + X[i];
|
||||
SY = SY + Y[i];
|
||||
SXY = SXY + X[i]* Y[i];
|
||||
SXX = SXX + X[i]* X[i];
|
||||
SYY = SYY + Y[i]* Y[i];
|
||||
}
|
||||
|
||||
slope = (N*SXY - SX*SY)/(N*SXX - SX*SX);
|
||||
intercept = (SY - slope*SX)/N;
|
||||
|
||||
return [slope, intercept];
|
||||
}
|
||||
|
||||
function linearRegression(X,Y) {
|
||||
var ret;
|
||||
ret = regression(X,Y,'linear');
|
||||
return [ret[0],ret[1]];
|
||||
}
|
||||
|
||||
function expRegression(X,Y) {
|
||||
var ret;
|
||||
var x = X;
|
||||
var y = Y;
|
||||
ret = regression(x, y,'exp');
|
||||
var base = Math.exp(ret[0]);
|
||||
var coeff = Math.exp(ret[1]);
|
||||
return [base, coeff];
|
||||
}
|
||||
|
||||
function fitData(data, typ) {
|
||||
var type = (typ == null) ? 'linear' : typ;
|
||||
var ret;
|
||||
var res;
|
||||
var x = [];
|
||||
var y = [];
|
||||
var ypred = [];
|
||||
|
||||
for (i=0; i<data.length; i++){
|
||||
if (data[i] != null && data[i][0] != null && data[i][1] != null) {
|
||||
x.push(data[i][0]);
|
||||
y.push(data[i][1]);
|
||||
}
|
||||
}
|
||||
|
||||
if (type == 'linear') {
|
||||
ret = linearRegression(x,y);
|
||||
for ( var i=0; i<x.length; i++){
|
||||
res = ret[0]*x[i] + ret[1];
|
||||
ypred.push([x[i], res]);
|
||||
}
|
||||
}
|
||||
else if (type == 'exp' || type == 'exponential') {
|
||||
ret = expRegression(x,y);
|
||||
for ( var i=0; i<x.length; i++){
|
||||
res = ret[1]*Math.pow(ret[0],x[i]);
|
||||
ypred.push([x[i], res]);
|
||||
}
|
||||
}
|
||||
return {data: ypred, slope: ret[0], intercept: ret[1]};
|
||||
}
|
||||
|
||||
})(jQuery);
|
|
@ -1,14 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2009 Chris Leonello
|
||||
* jqPlot is currently available for use in all personal or commercial projects
|
||||
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||||
* choose the license that best suits your project and use it accordingly.
|
||||
*
|
||||
* Although not required, the author would appreciate an email letting him
|
||||
* know of any substantial use of jqPlot. You can reach the author at:
|
||||
* chris dot leonello at gmail dot com or see http://www.jqplot.com/info.php .
|
||||
*
|
||||
* If you are feeling kind and generous, consider supporting the project by
|
||||
* making a donation at: http://www.jqplot.com/donate.php .
|
||||
*/
|
||||
(function(f){f.jqplot.Trendline=function(){this.show=f.jqplot.config.enablePlugins;this.color="#666666";this.renderer=new f.jqplot.LineRenderer();this.rendererOptions={marker:{show:false}};this.label="";this.type="linear";this.shadow=true;this.markerRenderer={show:false};this.lineWidth=1.5;this.shadowAngle=45;this.shadowOffset=1;this.shadowAlpha=0.07;this.shadowDepth=3};f.jqplot.postParseSeriesOptionsHooks.push(e);f.jqplot.postDrawSeriesHooks.push(g);f.jqplot.addLegendRowHooks.push(a);function a(k){var i=k.trendline.label.toString();var j=null;if(this.renderer.constructor!=f.jqplot.PieRenderer&&k.trendline.show&&i){j={label:i,color:k.trendline.color}}return j}function e(j,i){if(this.renderer.constructor!=f.jqplot.PieRenderer){this.trendline=new f.jqplot.Trendline();i=i||{};f.extend(true,this.trendline,{color:this.color},j.trendline,i.trendline);this.trendline.renderer.init.call(this.trendline,null)}}function g(m,i){i=f.extend(true,{},this.trendline,i);if(i.show&&this.renderer.constructor!=f.jqplot.PieRenderer){var k;var l=i.data||this.data;k=c(l,this.trendline.type);var j=i.gridData||this.renderer.makeGridData.call(this,k.data);this.trendline.renderer.draw.call(this.trendline,m,j,{showLine:true,shadow:this.trendline.shadow})}}function b(w,v,n){var u=(n==null)?"linear":n;var s=w.length;var t;var z;var o=0;var m=0;var r=0;var q=0;var l=0;var j=[];var k=[];if(u=="linear"){k=w;j=v}else{if(u=="exp"||u=="exponential"){for(var p=0;p<v.length;p++){if(v[p]<=0){s--}else{k.push(w[p]);j.push(Math.log(v[p]))}}}}for(var p=0;p<s;p++){o=o+k[p];m=m+j[p];q=q+k[p]*j[p];r=r+k[p]*k[p];l=l+j[p]*j[p]}t=(s*q-o*m)/(s*r-o*o);z=(m-t*o)/s;return[t,z]}function h(k,j){var i;i=b(k,j,"linear");return[i[0],i[1]]}function d(o,m){var k;var i=o;var n=m;k=b(i,n,"exp");var l=Math.exp(k[0]);var j=Math.exp(k[1]);return[l,j]}function c(l,j){var p=(j==null)?"linear":j;var n;var o;var r=[];var q=[];var m=[];for(k=0;k<l.length;k++){if(l[k]!=null&&l[k][0]!=null&&l[k][1]!=null){r.push(l[k][0]);q.push(l[k][1])}}if(p=="linear"){n=h(r,q);for(var k=0;k<r.length;k++){o=n[0]*r[k]+n[1];m.push([r[k],o])}}else{if(p=="exp"||p=="exponential"){n=d(r,q);for(var k=0;k<r.length;k++){o=n[1]*Math.pow(n[0],r[k]);m.push([r[k],o])}}}return{data:m,slope:n[0],intercept:n[1]}}})(jQuery);
|
Loading…
Add table
Reference in a new issue