123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393 |
- (function($) {
-
-
-
-
-
-
- function bestFormatString (interval)
- {
- var fstr;
- interval = Math.abs(interval);
- if (interval >= 10) {
- fstr = '%d';
- }
- else if (interval > 1) {
- if (interval === parseInt(interval, 10)) {
- fstr = '%d';
- }
- else {
- fstr = '%.1f';
- }
- }
- else {
- var expv = -Math.floor(Math.log(interval)/Math.LN10);
- fstr = '%.' + expv + 'f';
- }
-
- return fstr;
- }
- var _factors = [0.1, 0.2, 0.3, 0.4, 0.5, 0.8, 1, 2, 3, 4, 5];
- var _getLowerFactor = function(f) {
- var i = _factors.indexOf(f);
- if (i > 0) {
- return _factors[i-1];
- }
- else {
- return _factors[_factors.length - 1] / 100;
- }
- };
- var _getHigherFactor = function(f) {
- var i = _factors.indexOf(f);
- if (i < _factors.length-1) {
- return _factors[i+1];
- }
- else {
- return _factors[0] * 100;
- }
- };
-
-
-
- function bestConstrainedInterval(min, max, nttarget) {
-
- var low = Math.floor(nttarget/2);
- var hi = Math.ceil(nttarget*1.5);
- var badness = Number.MAX_VALUE;
- var r = (max - min);
- var temp;
- var sd;
- var bestNT;
- var gsf = $.jqplot.getSignificantFigures;
- var fsd;
- var fs;
- var currentNT;
- var bestPrec;
- for (var i=0, l=hi-low+1; i<l; i++) {
- currentNT = low + i;
- temp = r/(currentNT-1);
- sd = gsf(temp);
- temp = Math.abs(nttarget - currentNT) + sd.digitsRight;
- if (temp < badness) {
- badness = temp;
- bestNT = currentNT;
- bestPrec = sd.digitsRight;
- }
- else if (temp === badness) {
-
- if (sd.digitsRight < bestPrec) {
- bestNT = currentNT;
- bestPrec = sd.digitsRight;
- }
- }
- }
- fsd = Math.max(bestPrec, Math.max(gsf(min).digitsRight, gsf(max).digitsRight));
- if (fsd === 0) {
- fs = '%d';
- }
- else {
- fs = '%.' + fsd + 'f';
- }
- temp = r / (bestNT - 1);
-
- return [min, max, bestNT, fs, temp];
- }
-
-
-
- function bestInterval(range, numberTicks) {
- numberTicks = numberTicks || 7;
- var minimum = range / (numberTicks - 1);
- var magnitude = Math.pow(10, Math.floor(Math.log(minimum) / Math.LN10));
- var residual = minimum / magnitude;
- var interval;
-
-
- if (magnitude < 1) {
- if (residual > 5) {
- interval = 10 * magnitude;
- }
- else if (residual > 2) {
- interval = 5 * magnitude;
- }
- else if (residual > 1) {
- interval = 2 * magnitude;
- }
- else {
- interval = magnitude;
- }
- }
-
-
- else {
- if (residual > 5) {
- interval = 10 * magnitude;
- }
- else if (residual > 4) {
- interval = 5 * magnitude;
- }
- else if (residual > 3) {
- interval = 4 * magnitude;
- }
- else if (residual > 2) {
- interval = 3 * magnitude;
- }
- else if (residual > 1) {
- interval = 2 * magnitude;
- }
- else {
- interval = magnitude;
- }
- }
- return interval;
- }
-
-
- function bestLinearInterval(range, scalefact) {
- scalefact = scalefact || 1;
- var expv = Math.floor(Math.log(range)/Math.LN10);
- var magnitude = Math.pow(10, expv);
-
- var f = range / magnitude;
- var fact;
-
-
- f = f/scalefact;
-
- if (f<=0.38) {
- fact = 0.1;
- }
- else if (f<=1.6) {
- fact = 0.2;
- }
- else if (f<=4.0) {
- fact = 0.5;
- }
- else if (f<=8.0) {
- fact = 1.0;
- }
-
- else if (f<=16.0) {
- fact = 2;
- }
- else {
- fact = 5;
- }
- return fact*magnitude;
- }
- function bestLinearComponents(range, scalefact) {
- var expv = Math.floor(Math.log(range)/Math.LN10);
- var magnitude = Math.pow(10, expv);
-
- var f = range / magnitude;
- var interval;
- var fact;
-
-
- f = f/scalefact;
-
- if (f<=0.38) {
- fact = 0.1;
- }
- else if (f<=1.6) {
- fact = 0.2;
- }
- else if (f<=4.0) {
- fact = 0.5;
- }
- else if (f<=8.0) {
- fact = 1.0;
- }
-
- else if (f<=16.0) {
- fact = 2;
- }
-
-
-
-
-
-
- else {
- fact = 5;
- }
- interval = fact * magnitude;
- return [interval, fact, magnitude];
- }
-
-
-
-
- $.jqplot.LinearTickGenerator = function(axis_min, axis_max, scalefact, numberTicks, keepMin, keepMax) {
-
-
- keepMin = (keepMin === null) ? false : keepMin;
- keepMax = (keepMax === null || keepMin) ? false : keepMax;
-
- if (axis_min === axis_max) {
- axis_max = (axis_max) ? 0 : 1;
- }
- scalefact = scalefact || 1.0;
-
- if (axis_max < axis_min) {
- var a = axis_max;
- axis_max = axis_min;
- axis_min = a;
- }
- var r = [];
- var ss = bestLinearInterval(axis_max - axis_min, scalefact);
- var gsf = $.jqplot.getSignificantFigures;
-
- if (numberTicks == null) {
-
-
-
-
- if (!keepMin && !keepMax) {
- r[0] = Math.floor(axis_min / ss) * ss;
- r[1] = Math.ceil(axis_max / ss) * ss;
- r[2] = Math.round((r[1]-r[0])/ss+1.0);
- r[3] = bestFormatString(ss);
- r[4] = ss;
- }
- else if (keepMin) {
- r[0] = axis_min;
- r[2] = Math.ceil((axis_max - axis_min) / ss + 1.0);
- r[1] = axis_min + (r[2] - 1) * ss;
- var digitsMin = gsf(axis_min).digitsRight;
- var digitsSS = gsf(ss).digitsRight;
- if (digitsMin < digitsSS) {
- r[3] = bestFormatString(ss);
- }
- else {
- r[3] = '%.' + digitsMin + 'f';
- }
- r[4] = ss;
- }
- else if (keepMax) {
- r[1] = axis_max;
- r[2] = Math.ceil((axis_max - axis_min) / ss + 1.0);
- r[0] = axis_max - (r[2] - 1) * ss;
- var digitsMax = gsf(axis_max).digitsRight;
- var digitsSS = gsf(ss).digitsRight;
- if (digitsMax < digitsSS) {
- r[3] = bestFormatString(ss);
- }
- else {
- r[3] = '%.' + digitsMax + 'f';
- }
- r[4] = ss;
- }
- }
- else {
- var tempr = [];
-
-
-
-
- tempr[0] = Math.floor(axis_min / ss) * ss;
- tempr[1] = Math.ceil(axis_max / ss) * ss;
- tempr[2] = Math.round((tempr[1]-tempr[0])/ss+1.0);
- tempr[3] = bestFormatString(ss);
- tempr[4] = ss;
-
- if (tempr[2] === numberTicks) {
- r = tempr;
- }
- else {
- var newti = bestInterval(tempr[1] - tempr[0], numberTicks);
- r[0] = tempr[0];
- r[2] = numberTicks;
- r[4] = newti;
- r[3] = bestFormatString(newti);
- r[1] = r[0] + (r[2] - 1) * r[4];
- }
- }
- return r;
- };
- $.jqplot.LinearTickGenerator.bestLinearInterval = bestLinearInterval;
- $.jqplot.LinearTickGenerator.bestInterval = bestInterval;
- $.jqplot.LinearTickGenerator.bestLinearComponents = bestLinearComponents;
- $.jqplot.LinearTickGenerator.bestConstrainedInterval = bestConstrainedInterval;
- })(jQuery);
|