forked from extern/egroupware
jqplot version update to 1.0.8
This commit is contained in:
@ -2,9 +2,10 @@
|
||||
* jqPlot
|
||||
* Pure JavaScript plotting plugin using jQuery
|
||||
*
|
||||
* Version: 1.0.0b2_r947
|
||||
* Version: 1.0.8
|
||||
* Revision: 1250
|
||||
*
|
||||
* Copyright (c) 2009-2011 Chris Leonello
|
||||
* 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
|
||||
@ -48,13 +49,12 @@
|
||||
//
|
||||
// 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.
|
||||
// base - the logarithmic base, commonly 2, 10 or Math.E
|
||||
// tickDistribution - Deprecated. "power" distribution of ticks
|
||||
// always used. Option has no effect.
|
||||
this.axisDefaults = {
|
||||
base : 10,
|
||||
tickDistribution :'even'
|
||||
tickDistribution :'power'
|
||||
};
|
||||
};
|
||||
|
||||
@ -65,51 +65,43 @@
|
||||
// prop: drawBaseline
|
||||
// True to draw the axis baseline.
|
||||
this.drawBaseline = true;
|
||||
$.extend(true, this.renderer, options);
|
||||
// prop: minorTicks
|
||||
// Number of ticks to add between "major" ticks.
|
||||
// Major ticks are ticks supplied by user or auto computed.
|
||||
// Minor ticks cannot be created by user.
|
||||
this.minorTicks = 'auto';
|
||||
this._scalefact = 1.0;
|
||||
|
||||
$.extend(true, this, options);
|
||||
|
||||
this._autoFormatString = '%d';
|
||||
this._overrideFormatString = false;
|
||||
|
||||
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] != null && d[j][0] < db.min) || db.min == null) {
|
||||
db.min = d[j][0];
|
||||
}
|
||||
if ((d[j][0] != null && d[j][0] > db.max) || db.max == null) {
|
||||
db.max = d[j][0];
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ((d[j][1] != null && d[j][1] < db.min) || db.min == null) {
|
||||
db.min = d[j][1];
|
||||
}
|
||||
if ((d[j][1] != null && d[j][1] > db.max) || db.max == null) {
|
||||
db.max = d[j][1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.resetDataBounds();
|
||||
};
|
||||
|
||||
$.jqplot.LogAxisRenderer.prototype.createTicks = function() {
|
||||
$.jqplot.LogAxisRenderer.prototype.createTicks = function(plot) {
|
||||
// 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 dim = (this.name.charAt(0) === 'x') ? this._plotDimensions.width : this._plotDimensions.height;
|
||||
var interval;
|
||||
var min, max;
|
||||
var pos1, pos2;
|
||||
var tt, i;
|
||||
|
||||
var threshold = 30;
|
||||
// For some reason scalefactor is screwing up ticks.
|
||||
this._scalefact = (Math.max(dim, threshold+1) - threshold)/300;
|
||||
|
||||
// if we already have ticks, use them.
|
||||
// ticks must be in order of increasing value.
|
||||
if (userTicks.length) {
|
||||
@ -156,16 +148,9 @@
|
||||
}
|
||||
|
||||
// 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);
|
||||
else if (this.min == null && this.max == null) {
|
||||
min = db.min * (2 - this.padMin);
|
||||
max = db.max * this.padMax;
|
||||
|
||||
// if min and max are same, space them out a bit
|
||||
if (min == max) {
|
||||
@ -176,81 +161,179 @@
|
||||
|
||||
// perform some checks
|
||||
if (this.min != null && this.min <= 0) {
|
||||
throw('log axis minimum must be greater than 0');
|
||||
throw new Error("Log axis minimum must be greater than 0");
|
||||
}
|
||||
if (this.max != null && this.max <= 0) {
|
||||
throw('log axis maximum must be greater than 0');
|
||||
throw new Error("Log axis maximum must be greater than 0");
|
||||
}
|
||||
// if (this.pad >1.99) this.pad = 1.99;
|
||||
var range = max - min;
|
||||
|
||||
function findCeil (val) {
|
||||
var order = Math.pow(10, Math.floor(Math.log(val)/Math.LN10));
|
||||
return Math.ceil(val/order) * order;
|
||||
}
|
||||
|
||||
function findFloor(val) {
|
||||
var order = Math.pow(10, Math.floor(Math.log(val)/Math.LN10));
|
||||
return Math.floor(val/order) * order;
|
||||
}
|
||||
|
||||
// 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);
|
||||
// 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.floor(Math.log(min)/Math.log(this.base)));
|
||||
rmax = Math.pow(this.base, Math.ceil(Math.log(max)/Math.log(this.base)));
|
||||
|
||||
// // if min and max are same, space them out a bit
|
||||
// if (rmin === rmax) {
|
||||
// var adj = 0.05;
|
||||
// rmin = rmin*(1-adj);
|
||||
// rmax = rmax*(1+adj);
|
||||
// }
|
||||
|
||||
// Handle case where a data value was zero
|
||||
if (rmin === 0) {
|
||||
rmin = 1;
|
||||
}
|
||||
|
||||
var order = Math.round(Math.log(rmin)/Math.LN10);
|
||||
|
||||
if (this.tickOptions == null || !this.tickOptions.formatString) {
|
||||
this._overrideFormatString = true;
|
||||
}
|
||||
|
||||
this.min = rmin;
|
||||
this.max = rmax;
|
||||
var range = this.max - this.min;
|
||||
|
||||
var minorTicks = (this.minorTicks === 'auto') ? 0 : this.minorTicks;
|
||||
var numberTicks;
|
||||
if (this.numberTicks == null){
|
||||
if (dim > 140) {
|
||||
numberTicks = Math.round(Math.log(this.max/this.min)/Math.log(this.base) + 1);
|
||||
if (numberTicks < 2) {
|
||||
numberTicks = 2;
|
||||
}
|
||||
else {
|
||||
this.numberTicks = 2;
|
||||
if (minorTicks === 0) {
|
||||
var temp = dim/(numberTicks - 1);
|
||||
if (temp < 100) {
|
||||
minorTicks = 0;
|
||||
}
|
||||
else if (temp < 190) {
|
||||
minorTicks = 1;
|
||||
}
|
||||
else if (temp < 250) {
|
||||
minorTicks = 3;
|
||||
}
|
||||
else if (temp < 600) {
|
||||
minorTicks = 4;
|
||||
}
|
||||
else {
|
||||
minorTicks = 9;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
numberTicks = 2;
|
||||
if (minorTicks === 0) {
|
||||
minorTicks = 1;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
t.setTick(tt, this.name);
|
||||
this._ticks.push(t);
|
||||
minorTicks = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
numberTicks = this.numberTicks;
|
||||
}
|
||||
|
||||
if (order >= 0 && minorTicks !== 3) {
|
||||
this._autoFormatString = '%d';
|
||||
}
|
||||
// Adjust format string for case with 3 ticks where we'll have like 1, 2.5, 5, 7.5, 10
|
||||
else if (order <= 0 && minorTicks === 3) {
|
||||
var temp = -(order - 1);
|
||||
this._autoFormatString = '%.'+ Math.abs(order-1) + 'f';
|
||||
}
|
||||
|
||||
// Adjust format string for values less than 1.
|
||||
else if (order < 0) {
|
||||
var temp = -order;
|
||||
this._autoFormatString = '%.'+ Math.abs(order) + 'f';
|
||||
}
|
||||
|
||||
else {
|
||||
this._autoFormatString = '%d';
|
||||
}
|
||||
|
||||
var to, t, val, tt1, spread, interval;
|
||||
for (var i=0; i<numberTicks; i++){
|
||||
tt = Math.pow(this.base, i - numberTicks + 1) * this.max;
|
||||
|
||||
t = new this.tickRenderer(this.tickOptions);
|
||||
|
||||
if (this._overrideFormatString) {
|
||||
t.formatString = this._autoFormatString;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
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 (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 (minorTicks && i<numberTicks-1) {
|
||||
tt1 = Math.pow(this.base, i - numberTicks + 2) * this.max;
|
||||
spread = tt1 - tt;
|
||||
interval = tt1 / (minorTicks+1);
|
||||
for (var j=minorTicks-1; j>=0; j--) {
|
||||
val = tt1-interval*(j+1);
|
||||
t = new this.tickRenderer(this.tickOptions);
|
||||
|
||||
if (this._overrideFormatString && this._autoFormatString != '') {
|
||||
t.formatString = this._autoFormatString;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// min and max are set as would be the case with zooming
|
||||
else if (this.min != null && this.max != null) {
|
||||
var opts = $.extend(true, {}, this.tickOptions, {name: this.name, value: null});
|
||||
var nt, ti;
|
||||
// don't have an interval yet, pick one that gives the most
|
||||
// "round" ticks we can get.
|
||||
if (this.numberTicks == null && this.tickInterval == null) {
|
||||
// var threshold = 30;
|
||||
var tdim = Math.max(dim, threshold+1);
|
||||
var nttarget = Math.ceil((tdim-threshold)/35 + 1);
|
||||
|
||||
var ret = $.jqplot.LinearTickGenerator.bestConstrainedInterval(this.min, this.max, nttarget);
|
||||
|
||||
this._autoFormatString = ret[3];
|
||||
nt = ret[2];
|
||||
ti = ret[4];
|
||||
|
||||
for (var i=0; i<nt; i++) {
|
||||
opts.value = this.min + i * ti;
|
||||
t = new this.tickRenderer(opts);
|
||||
|
||||
if (this._overrideFormatString && this._autoFormatString != '') {
|
||||
t.formatString = this._autoFormatString;
|
||||
}
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
@ -258,29 +341,30 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// for loose zoom, number ticks and interval are also set.
|
||||
else if (this.numberTicks != null && this.tickInterval != null) {
|
||||
nt = this.numberTicks;
|
||||
for (var i=0; i<nt; i++) {
|
||||
opts.value = this.min + i * this.tickInterval;
|
||||
t = new this.tickRenderer(opts);
|
||||
|
||||
if (this._overrideFormatString && this._autoFormatString != '') {
|
||||
t.formatString = this._autoFormatString;
|
||||
}
|
||||
if (!this.showTicks) {
|
||||
t.showLabel = false;
|
||||
t.showMark = false;
|
||||
}
|
||||
else if (!this.showTickMarks) {
|
||||
t.showMark = false;
|
||||
}
|
||||
this._ticks.push(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user