forked from vergnet/site-accueil-insa
191 lines
No EOL
6.4 KiB
JavaScript
191 lines
No EOL
6.4 KiB
JavaScript
/**
|
|
* jqPlot
|
|
* Pure JavaScript plotting plugin using jQuery
|
|
*
|
|
* Version: @VERSION
|
|
* Revision: @REVISION
|
|
*
|
|
* Copyright (c) 2009-2013 Chris Leonello
|
|
* jqPlot is currently available for use in all personal or commercial projects
|
|
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
|
|
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) 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 at jqplot 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 .
|
|
*
|
|
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
|
|
*
|
|
* version 2007.04.27
|
|
* author Ash Searle
|
|
* http://hexmen.com/blog/2007/03/printf-sprintf/
|
|
* http://hexmen.com/js/sprintf.js
|
|
* The author (Ash Searle) has placed this code in the public domain:
|
|
* "This code is unrestricted: you are free to use it however you like."
|
|
*
|
|
*/
|
|
(function($) {
|
|
// class: $.jqplot.AxisTickRenderer
|
|
// A "tick" object showing the value of a tick/gridline on the plot.
|
|
$.jqplot.AxisTickRenderer = function(options) {
|
|
// Group: Properties
|
|
$.jqplot.ElemContainer.call(this);
|
|
// prop: mark
|
|
// tick mark on the axis. One of 'inside', 'outside', 'cross', '' or null.
|
|
this.mark = 'outside';
|
|
// name of the axis associated with this tick
|
|
this.axis;
|
|
// prop: showMark
|
|
// whether or not to show the mark on the axis.
|
|
this.showMark = true;
|
|
// prop: showGridline
|
|
// whether 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: size
|
|
// Length of the tick beyond the grid in pixels.
|
|
// DEPRECATED: This has been superceeded by markSize
|
|
this.size = 4;
|
|
// 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 = 6;
|
|
// prop: show
|
|
// whether or not to show the tick (mark and label).
|
|
// Setting this to false requires more testing. It is recommended
|
|
// to set showLabel and showMark to false instead.
|
|
this.show = true;
|
|
// prop: showLabel
|
|
// whether or not to show the label.
|
|
this.showLabel = true;
|
|
this.label = null;
|
|
this.value = null;
|
|
this._styles = {};
|
|
// prop: formatter
|
|
// A class of a formatter for the tick text. sprintf by default.
|
|
this.formatter = $.jqplot.DefaultTickFormatter;
|
|
// prop: prefix
|
|
// String to prepend to the tick label.
|
|
// Prefix is prepended to the formatted tick label.
|
|
this.prefix = '';
|
|
// prop: suffix
|
|
// String to append to the tick label.
|
|
// Suffix is appended to the formatted tick label.
|
|
this.suffix = '';
|
|
// prop: formatString
|
|
// string passed to the formatter.
|
|
this.formatString = '';
|
|
// prop: fontFamily
|
|
// css spec for the font-family css attribute.
|
|
this.fontFamily;
|
|
// prop: fontSize
|
|
// css spec for the font-size css attribute.
|
|
this.fontSize;
|
|
// prop: textColor
|
|
// css spec for the color attribute.
|
|
this.textColor;
|
|
// prop: escapeHTML
|
|
// true to escape HTML entities in the label.
|
|
this.escapeHTML = false;
|
|
this._elem;
|
|
this._breakTick = false;
|
|
|
|
$.extend(true, this, options);
|
|
};
|
|
|
|
$.jqplot.AxisTickRenderer.prototype.init = function(options) {
|
|
$.extend(true, this, options);
|
|
};
|
|
|
|
$.jqplot.AxisTickRenderer.prototype = new $.jqplot.ElemContainer();
|
|
$.jqplot.AxisTickRenderer.prototype.constructor = $.jqplot.AxisTickRenderer;
|
|
|
|
$.jqplot.AxisTickRenderer.prototype.setTick = function(value, axisName, isMinor) {
|
|
this.value = value;
|
|
this.axis = axisName;
|
|
if (isMinor) {
|
|
this.isMinorTick = true;
|
|
}
|
|
return this;
|
|
};
|
|
|
|
$.jqplot.AxisTickRenderer.prototype.draw = function() {
|
|
if (this.label === null) {
|
|
this.label = this.prefix + this.formatter(this.formatString, this.value) + this.suffix;
|
|
}
|
|
var style = {position: 'absolute'};
|
|
if (Number(this.label)) {
|
|
style['whitSpace'] = 'nowrap';
|
|
}
|
|
|
|
// Memory Leaks patch
|
|
if (this._elem) {
|
|
this._elem.emptyForce();
|
|
this._elem = null;
|
|
}
|
|
|
|
this._elem = $(document.createElement('div'));
|
|
this._elem.addClass("jqplot-"+this.axis+"-tick");
|
|
|
|
if (!this.escapeHTML) {
|
|
this._elem.html(this.label);
|
|
}
|
|
else {
|
|
this._elem.text(this.label);
|
|
}
|
|
|
|
this._elem.css(style);
|
|
|
|
for (var s in this._styles) {
|
|
this._elem.css(s, this._styles[s]);
|
|
}
|
|
if (this.fontFamily) {
|
|
this._elem.css('font-family', this.fontFamily);
|
|
}
|
|
if (this.fontSize) {
|
|
this._elem.css('font-size', this.fontSize);
|
|
}
|
|
if (this.textColor) {
|
|
this._elem.css('color', this.textColor);
|
|
}
|
|
if (this._breakTick) {
|
|
this._elem.addClass('jqplot-breakTick');
|
|
}
|
|
|
|
return this._elem;
|
|
};
|
|
|
|
$.jqplot.DefaultTickFormatter = function (format, val) {
|
|
if (typeof val == 'number') {
|
|
if (!format) {
|
|
format = $.jqplot.config.defaultTickFormatString;
|
|
}
|
|
return $.jqplot.sprintf(format, val);
|
|
}
|
|
else {
|
|
return String(val);
|
|
}
|
|
};
|
|
|
|
$.jqplot.PercentTickFormatter = function (format, val) {
|
|
if (typeof val == 'number') {
|
|
val = 100 * val;
|
|
if (!format) {
|
|
format = $.jqplot.config.defaultTickFormatString;
|
|
}
|
|
return $.jqplot.sprintf(format, val);
|
|
}
|
|
else {
|
|
return String(val);
|
|
}
|
|
};
|
|
|
|
$.jqplot.AxisTickRenderer.prototype.pack = function() {
|
|
};
|
|
})(jQuery); |