( function ( $ ) { function log10 ( value ) { return Math . log ( value ) / Math . LN10 ; } function floorAsLog10 ( value ) { return Math . floor ( log10 ( value ) ) ; } function ceilAsLog10 ( value ) { return Math . ceil ( log10 ( value ) ) ; } function floorInBase ( n , base ) { return base * Math . floor ( n / base ) ; } function getUnicodePower ( power ) { var superscripts = [ "⁰" , "¹" , "²" , "³" , "⁴" , "⁵" , "⁶" , "⁷" , "⁸" , "⁹" ] , result = "" , str_power = "" + power ; for ( var i = 0 ; i < str_power . length ; i ++ ) { if ( str_power [ i ] === "+" ) { } else if ( str_power [ i ] === "-" ) { result += "⁻" ; } else { result += superscripts [ str_power [ i ] ] ; } } return result ; } function init ( plot ) { plot . hooks . processOptions . push ( function ( plot ) { $ . each ( plot . getAxes ( ) , function ( axisName , axis ) { var opts = axis . options ; if ( opts . mode === "log" ) { axis . tickGenerator = function ( axis ) { var ticks = [ ] , end = ceilAsLog10 ( axis . max ) , start = floorAsLog10 ( axis . min ) , tick = Number . NaN , i = 0 ; if ( axis . min === null || axis . min <= 0 ) { start = 0 ; axis . min = 0.6 ; } if ( end <= start ) { ticks = [ 1e-6 , 1e-5 , 1e-4 , 1e-3 , 1e-2 , 1e-1 , 1e0 , 1e1 , 1e2 , 1e3 , 1e4 , 1e5 , 1e6 , 1e7 , 1e8 , 1e9 ] ; } else if ( log10 ( axis . max ) - log10 ( axis . datamin ) < 1 ) { var prev ; start = floorInBase ( axis . min , axis . tickSize ) ; do { prev = tick ; tick = start + i * axis . tickSize ; ticks . push ( tick ) ; ++ i ; } while ( tick < axis . max && tick !== prev ) ; } else { for ( ; i <= ( end - start ) ; i ++ ) { tick = Math . pow ( 10 , start + i ) ; ticks . push ( tick ) ; } var length = ticks . length ; if ( end - start < 6 ) { for ( var j = 1 ; j < length * 2 - 1 ; j += 2 ) { tick = ticks [ j - 1 ] * 5 ; ticks . splice ( j , 0 , tick ) ; } } } return ticks ; } ; axis . tickFormatter = function ( value , axis ) { var formatted ; if ( log10 ( axis . max ) - log10 ( axis . datamin ) < 1 ) { var factor = axis . tickDecimals ? Math . pow ( 10 , axis . tickDecimals ) : 1 ; formatted = "" + Math . round ( value * factor ) / factor ; if ( axis . tickDecimals !== null ) { var decimal = formatted . indexOf ( "." ) ; var precision = decimal === - 1 ? 0 : formatted . length - decimal - 1 ; if ( precision < axis . tickDecimals ) { return ( precision ? formatted : formatted + "." ) + ( "" + factor ) . substr ( 1 , axis . tickDecimals - precision ) ; } } } else { var multiplier = "" , exponential = parseFloat ( value ) . toExponential ( 0 ) , power = getUnicodePower ( exponential . slice ( 2 ) ) ; if ( exponential [ 0 ] !== "1" ) { multiplier = exponential [ 0 ] + "x" ; } formatted = multiplier + "10" + power ; } return formatted ; } ; } } ) ; } ) ; } $ . plot . plugins . push ( { init : init , name : "log" , version : "0.9" } ) ; } ) ( jQuery ) ;