2018-02-16 13:41:31 +01:00
/ * J a v a s c r i p t p l o t t i n g l i b r a r y f o r j Q u e r y , v e r s i o n 0 . 8 . 3 .
Copyright ( c ) 2007 - 2014 IOLA and Ole Laursen .
Licensed under the MIT license .
* /
2021-04-09 11:29:26 +02:00
( function ( $ ) { $ . color = { } ; $ . color . make = function ( r , g , b , a ) { var o = { } ; o . r = r || 0 ; o . g = g || 0 ; o . b = b || 0 ; o . a = a != null ? a : 1 ; o . add = function ( c , d ) { for ( var i = 0 ; i < c . length ; ++ i ) o [ c . charAt ( i ) ] += d ; return o . normalize ( ) } ; o . scale = function ( c , f ) { for ( var i = 0 ; i < c . length ; ++ i ) o [ c . charAt ( i ) ] *= f ; return o . normalize ( ) } ; o . toString = function ( ) { if ( o . a >= 1 ) { return "rgb(" + [ o . r , o . g , o . b ] . join ( "," ) + ")" } else { return "rgba(" + [ o . r , o . g , o . b , o . a ] . join ( "," ) + ")" } } ; o . normalize = function ( ) { function clamp ( min , value , max ) { return value < min ? min : value > max ? max : value } o . r = clamp ( 0 , parseInt ( o . r ) , 255 ) ; o . g = clamp ( 0 , parseInt ( o . g ) , 255 ) ; o . b = clamp ( 0 , parseInt ( o . b ) , 255 ) ; o . a = clamp ( 0 , o . a , 1 ) ; return o } ; o . clone = function ( ) { return $ . color . make ( o . r , o . b , o . g , o . a ) } ; return o . normalize ( ) } ; $ . color . extract = function ( elem , css ) { var c ; do { c = elem . css ( css ) . toLowerCase ( ) ; if ( c != "" && c != "transparent" ) break ; elem = elem . parent ( ) } while ( elem . length && ! $ . nodeName ( elem . get ( 0 ) , "body" ) ) ; if ( c == "rgba(0, 0, 0, 0)" ) c = "transparent" ; return $ . color . parse ( c ) } ; $ . color . parse = function ( str ) { var res , m = $ . color . make ; if ( res = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/ . exec ( str ) ) return m ( parseInt ( res [ 1 ] , 10 ) , parseInt ( res [ 2 ] , 10 ) , parseInt ( res [ 3 ] , 10 ) ) ; if ( res = /rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/ . exec ( str ) ) return m ( parseInt ( res [ 1 ] , 10 ) , parseInt ( res [ 2 ] , 10 ) , parseInt ( res [ 3 ] , 10 ) , parseFloat ( res [ 4 ] ) ) ; if ( res = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/ . exec ( str ) ) return m ( parseFloat ( res [ 1 ] ) * 2.55 , parseFloat ( res [ 2 ] ) * 2.55 , parseFloat ( res [ 3 ] ) * 2.55 ) ; if ( res = /rgba\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/ . exec ( str ) ) return m ( parseFloat ( res [ 1 ] ) * 2.55 , parseFloat ( res [ 2 ] ) * 2.55 , parseFloat ( res [ 3 ] ) * 2.55 , parseFloat ( res [ 4 ] ) ) ; if ( res = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/ . exec ( str ) ) return m ( parseInt ( res [ 1 ] , 16 ) , parseInt ( res [ 2 ] , 16 ) , parseInt ( res [ 3 ] , 16 ) ) ; if ( res = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/ . exec ( str ) ) return m ( parseInt ( res [ 1 ] + res [ 1 ] , 16 ) , parseInt ( res [ 2 ] + res [ 2 ] , 16 ) , parseInt ( res [ 3 ] + res [ 3 ] , 16 ) ) ; var name = $ . trim ( str ) . toLowerCase ( ) ; if ( name == "transparent" ) return m ( 255 , 255 , 255 , 0 ) ; else { res = lookupColors [ name ] || [ 0 , 0 , 0 ] ; return m ( res [ 0 ] , res [ 1 ] , res [ 2 ] ) } } ; var lookupColors = { aqua : [ 0 , 255 , 255 ] , azure : [ 240 , 255 , 255 ] , beige : [ 245 , 245 , 220 ] , black : [ 0 , 0 , 0 ] , blue : [ 0 , 0 , 255 ] , brown : [ 165 , 42 , 42 ] , cyan : [ 0 , 255 , 255 ] , darkblue : [ 0 , 0 , 139 ] , darkcyan : [ 0 , 139 , 139 ] , darkgrey : [ 169 , 169 , 169 ] , darkgreen : [ 0 , 100 , 0 ] , darkkhaki : [ 189 , 183 , 107 ] , darkmagenta : [ 139 , 0 , 139 ] , darkolivegreen : [ 85 , 107 , 47 ] , darkorange : [ 255 , 140 , 0 ] , darkorchid : [ 153 , 50 , 204 ] , darkred : [ 139 , 0 , 0 ] , darksalmon : [ 233 , 150 , 122 ] , darkviolet : [ 148 , 0 , 211 ] , fuchsia : [ 255 , 0 , 255 ] , gold : [ 255 , 215 , 0 ] , green : [ 0 , 128 , 0 ] , indigo : [ 75 , 0 , 130 ] , khaki : [ 240 , 230 , 140 ] , lightblue : [ 173 , 216 , 230 ] , lightcyan : [ 224 , 255 , 255 ] , lightgreen : [ 144 , 238 , 144 ] , lightgrey : [ 211 , 211 , 211 ] , lightpink : [ 255 , 182 , 193 ] , lightyellow : [ 255 , 255 , 224 ] , lime : [ 0 , 255 , 0 ] , magenta : [ 255 , 0 , 255 ] , maroon : [ 128 , 0 , 0 ] , navy : [ 0 , 0 , 128 ] , olive : [ 128 , 128 , 0 ] , orange : [ 255 , 165 , 0 ] , pink : [ 255 , 192 , 203 ] , purple : [ 128 , 0 , 128 ] , violet : [ 128 , 0 , 128 ] , red : [ 255 , 0 , 0 ] , silver : [ 192 , 192 , 192 ] , white : [ 255 , 255 , 255 ] , yellow : [ 255 , 255 , 0 ] } } ) ( jQuery ) ; ( function ( $ ) {
2021-06-29 12:03:49 +02:00
var hasOwnProperty = Object . prototype . hasOwnProperty ; if ( ! $ . fn . detach ) { $ . fn . detach = function ( ) { return this . each ( function ( ) { if ( this . parentNode ) { this . parentNode . removeChild ( this ) } } ) } } function Canvas ( cls , container ) { var element = container . children ( "." + cls ) [ 0 ] ; if ( element == null ) { element = document . createElement ( "canvas" ) ; element . className = cls ; $ ( element ) . css ( { direction : "ltr" , position : "absolute" , left : 0 , top : 0 } ) . appendTo ( container ) ; if ( ! element . getContext ) { if ( window . G _vmlCanvasManager ) { element = window . G _vmlCanvasManager . initElement ( element ) } else { throw new Error ( "Canvas is not available. If you're using IE with a fall-back such as Excanvas, then there's either a mistake in your conditional include, or the page has no DOCTYPE and is rendering in Quirks Mode." ) } } } this . element = element ; var context = this . context = element . getContext ( "2d" ) ; var devicePixelRatio = window . devicePixelRatio || 1 , backingStoreRatio = context . webkitBackingStorePixelRatio || context . mozBackingStorePixelRatio || context . msBackingStorePixelRatio || context . oBackingStorePixelRatio || context . backingStorePixelRatio || 1 ; this . pixelRatio = devicePixelRatio / backingStoreRatio ; this . resize ( container . width ( ) , container . height ( ) ) ; this . textContainer = null ; this . text = { } ; this . _textCache = { } } Canvas . prototype . resize = function ( width , height ) { if ( width <= 0 || height <= 0 ) { throw new Error ( "Invalid dimensions for plot, width = " + width + ", height = " + height ) } var element = this . element , context = this . context , pixelRatio = this . pixelRatio ; if ( this . width != width ) { element . width = width * pixelRatio ; element . style . width = width + "px" ; this . width = width } if ( this . height != height ) { element . height = height * pixelRatio ; element . style . height = height + "px" ; this . height = height } context . restore ( ) ; context . save ( ) ; context . scale ( pixelRatio , pixelRatio ) } ; Canvas . prototype . clear = function ( ) { this . context . clearRect ( 0 , 0 , this . width , this . height ) } ; Canvas . prototype . render = function ( ) { var cache = this . _textCache ; for ( var layerKey in cache ) { if ( hasOwnProperty . call ( cache , layerKey ) ) { var layer = this . getTextLayer ( layerKey ) , layerCache = cache [ layerKey ] ; layer . hide ( ) ; for ( var styleKey in layerCache ) { if ( hasOwnProperty . call ( layerCache , styleKey ) ) { var styleCache = layerCache [ styleKey ] ; for ( var key in styleCache ) { if ( hasOwnProperty . call ( styleCache , key ) ) { var positions = styleCache [ key ] . positions ; for ( var i = 0 , position ; position = positions [ i ] ; i ++ ) { if ( position . active ) { if ( ! position . rendered ) { layer . append ( position . element ) ; position . rendered = true } } else { positions . splice ( i -- , 1 ) ; if ( position . rendered ) { position . element . detach ( ) } } } if ( positions . length == 0 ) { delete styleCache [ key ] } } } } } layer . show ( ) } } } ; Canvas . prototype . getTextLayer = function ( classes ) { var layer = this . text [ classes ] ; if ( layer == null ) { if ( this . textContainer == null ) { this . textContainer = $ ( "<div class='flot-text'></div>" ) . css ( { position : "absolute" , top : 0 , left : 0 , bottom : 0 , right : 0 , "font-size" : "smaller" } ) . insertAfter ( this . element ) } layer = this . text [ classes ] = $ ( "<div></div>" ) . addClass ( classes ) . css ( { position : "absolute" , top : 0 , left : 0 , bottom : 0 , right : 0 } ) . appendTo ( this . textContainer ) } return layer } ; Canvas . prototype . getTextInfo = function ( layer , text , font , angle , width ) { var textStyle , layerCache , styleCache , info ; text = "" + text ; if ( typeof font === "object" ) { textStyle = font . style + " " + font . variant + " " + font . weight + " " + font . size + "px/" + font . lineHeight + "px " + font . family } else { textStyle = font } layerCache = this . _textCache [ layer ] ; if ( layerCache == null ) { layerCache = this . _textCache [ layer ] = { } } styleCache = layerCache [ textStyle ] ; if ( styleCache == null ) { styleCache = layerCache [ textStyle ] = { } } info = styleCache [ text ] ; if ( info == null ) { var element = $ ( "<div></div>" ) . html ( text ) . css ( { position : "absolute" , "max-width" : width , top : - 9999 } ) . appendTo ( this . getTextLayer ( layer ) ) ; if ( typeof font === "object" ) { element . css ( { font : tex
2021-04-09 11:29:26 +02:00
var series = [ ] , options = { colors : [ "#edc240" , "#afd8f8" , "#cb4b4b" , "#4da74d" , "#9440ed" ] , legend : { show : true , noColumns : 1 , labelFormatter : null , labelBoxBorderColor : "#ccc" , container : null , position : "ne" , margin : 5 , backgroundColor : null , backgroundOpacity : . 85 , sorted : null } , xaxis : { show : null , position : "bottom" , mode : null , font : null , color : null , tickColor : null , transform : null , inverseTransform : null , min : null , max : null , autoscaleMargin : null , ticks : null , tickFormatter : null , labelWidth : null , labelHeight : null , reserveSpace : null , tickLength : null , alignTicksWithAxis : null , tickDecimals : null , tickSize : null , minTickSize : null } , yaxis : { autoscaleMargin : . 02 , position : "left" } , xaxes : [ ] , yaxes : [ ] , series : { points : { show : false , radius : 3 , lineWidth : 2 , fill : true , fillColor : "#ffffff" , symbol : "circle" } , lines : { lineWidth : 2 , fill : false , fillColor : null , steps : false } , bars : { show : false , lineWidth : 2 , barWidth : 1 , fill : true , fillColor : null , align : "left" , horizontal : false , zero : true } , shadowSize : 3 , highlightColor : null } , grid : { show : true , aboveData : false , color : "#545454" , backgroundColor : null , borderColor : null , tickColor : null , margin : 0 , labelMargin : 5 , axisMargin : 8 , borderWidth : 2 , minBorderMargin : null , markings : null , markingsColor : "#f4f4f4" , markingsLineWidth : 2 , clickable : false , hoverable : false , autoHighlight : true , mouseActiveRadius : 10 } , interaction : { redrawOverlayInterval : 1e3 / 60 } , hooks : { } } , surface = null , overlay = null , eventHolder = null , ctx = null , octx = null , xaxes = [ ] , yaxes = [ ] , plotOffset = { left : 0 , right : 0 , top : 0 , bottom : 0 } , plotWidth = 0 , plotHeight = 0 , hooks = { processOptions : [ ] , processRawData : [ ] , processDatapoints : [ ] , processOffset : [ ] , drawBackground : [ ] , drawSeries : [ ] , draw : [ ] , bindEvents : [ ] , drawOverlay : [ ] , shutdown : [ ] } , plot = this ; plot . setData = setData ; plot . setupGrid = setupGrid ; plot . draw = draw ; plot . getPlaceholder = function ( ) { return placeholder } ; plot . getCanvas = function ( ) { return surface . element } ; plot . getPlotOffset = function ( ) { return plotOffset } ; plot . width = function ( ) { return plotWidth } ; plot . height = function ( ) { return plotHeight } ; plot . offset = function ( ) { var o = eventHolder . offset ( ) ; o . left += plotOffset . left ; o . top += plotOffset . top ; return o } ; plot . getData = function ( ) { return series } ; plot . getAxes = function ( ) { var res = { } , i ; $ . each ( xaxes . concat ( yaxes ) , function ( _ , axis ) { if ( axis ) res [ axis . direction + ( axis . n != 1 ? axis . n : "" ) + "axis" ] = axis } ) ; return res } ; plot . getXAxes = function ( ) { return xaxes } ; plot . getYAxes = function ( ) { return yaxes } ; plot . c2p = canvasToAxisCoords ; plot . p2c = axisToCanvasCoords ; plot . getOptions = function ( ) { return options } ; plot . highlight = highlight ; plot . unhighlight = unhighlight ; plot . triggerRedrawOverlay = triggerRedrawOverlay ; plot . pointOffset = function ( point ) { return { left : parseInt ( xaxes [ axisNumber ( point , "x" ) - 1 ] . p2c ( + point . x ) + plotOffset . left , 10 ) , top : parseInt ( yaxes [ axisNumber ( point , "y" ) - 1 ] . p2c ( + point . y ) + plotOffset . top , 10 ) } } ; plot . shutdown = shutdown ; plot . destroy = function ( ) { shutdown ( ) ; placeholder . removeData ( "plot" ) . empty ( ) ; series = [ ] ; options = null ; surface = null ; overlay = null ; eventHolder = null ; ctx = null ; octx = null ; xaxes = [ ] ; yaxes = [ ] ; hooks = null ; highlights = [ ] ; plot = null } ; plot . resize = function ( ) { var width = placeholder . width ( ) , height = placeholder . height ( ) ; surface . resize ( width , height ) ; overlay . resize ( width , height ) } ; plot . hooks = hooks ; initPlugins ( plot ) ; parseOptions ( options _ ) ; setupCanvases ( ) ; setData ( data _ ) ; setupGrid ( ) ; draw ( ) ; bindEvents ( ) ; function executeHooks ( hook , args ) { args = [ plot ] . concat ( args ) ; for ( var i = 0 ; i < hook . length ; ++ i ) hook [ i ] . apply ( this , args ) } function initPlugins ( ) { var classes = { Canvas : Canvas } ; for ( var i = 0 ; i < plugins . length ; ++ i ) { var p = plugins [ i ] ; p . init ( plot , classes ) ; if ( p . options ) $ . extend ( true , options , p . options ) } } function parseOptions ( opts ) { $ . extend ( true , options , opts ) ; if ( opts && opts . colors ) {
var i , axes , bw , bc ; ctx . save ( ) ; ctx . translate ( plotOffset . left , plotOffset . top ) ; var markings = options . grid . markings ; if ( markings ) {
if ( $ . isFunction ( markings ) ) { axes = plot . getAxes ( ) ; axes . xmin = axes . xaxis . min ; axes . xmax = axes . xaxis . max ; axes . ymin = axes . yaxis . min ; axes . ymax = axes . yaxis . max ; markings = markings ( axes ) } for ( i = 0 ; i < markings . length ; ++ i ) {
var m = markings [ i ] , xrange = extractRange ( m , "x" ) , yrange = extractRange ( m , "y" ) ; if ( xrange . from == null ) xrange . from = xrange . axis . min ; if ( xrange . to == null ) xrange . to = xrange . axis . max ;
if ( yrange . from == null ) yrange . from = yrange . axis . min ; if ( yrange . to == null ) yrange . to = yrange . axis . max ; if ( xrange . to < xrange . axis . min || xrange . from > xrange . axis . max || yrange . to < yrange . axis . min || yrange . from > yrange . axis . max ) continue ; xrange . from = Math . max ( xrange . from , xrange . axis . min ) ; xrange . to = Math . min ( xrange . to , xrange . axis . max ) ; yrange . from = Math . max ( yrange . from , yrange . axis . min ) ; yrange . to = Math . min ( yrange . to , yrange . axis . max ) ; var xequal = xrange . from === xrange . to , yequal = yrange . from === yrange . to ; if ( xequal && yequal ) { continue } xrange . from = Math . floor ( xrange . axis . p2c ( xrange . from ) ) ; xrange . to = Math . floor ( xrange . axis . p2c ( xrange . to ) ) ; yrange . from = Math . floor ( yrange . axis . p2c ( yrange . from ) ) ; yrange . to = Math . floor ( yrange . axis . p2c ( yrange . to ) ) ; if ( xequal || yequal ) { var lineWidth = m . lineWidth || options . grid . markingsLineWidth , subPixel = lineWidth % 2 ? . 5 : 0 ; ctx . beginPath ( ) ; ctx . strokeStyle = m . color || options . grid . markingsColor ; ctx . lineWidth = lineWidth ; if ( xequal ) { ctx . moveTo ( xrange . to + subPixel , yrange . from ) ; ctx . lineTo ( xrange . to + subPixel , yrange . to ) } else { ctx . moveTo ( xrange . from , yrange . to + subPixel ) ; ctx . lineTo ( xrange . to , yrange . to + subPixel ) } ctx . stroke ( ) } else { ctx . fillStyle = m . color || options . grid . markingsColor ; ctx . fillRect ( xrange . from , yrange . to , xrange . to - xrange . from , yrange . from - yrange . to ) }
}
} axes = allAxes ( ) ; bw = options . grid . borderWidth ; for ( var j = 0 ; j < axes . length ; ++ j ) { var axis = axes [ j ] , box = axis . box , t = axis . tickLength , x , y , xoff , yoff ; if ( ! axis . show || axis . ticks . length == 0 ) continue ; ctx . lineWidth = 1 ; if ( axis . direction == "x" ) { x = 0 ; if ( t == "full" ) y = axis . position == "top" ? 0 : plotHeight ; else y = box . top - plotOffset . top + ( axis . position == "top" ? box . height : 0 ) } else { y = 0 ; if ( t == "full" ) x = axis . position == "left" ? 0 : plotWidth ; else x = box . left - plotOffset . left + ( axis . position == "left" ? box . width : 0 ) } if ( ! axis . innermost ) { ctx . strokeStyle = axis . options . color ; ctx . beginPath ( ) ; xoff = yoff = 0 ; if ( axis . direction == "x" ) xoff = plotWidth + 1 ; else yoff = plotHeight + 1 ; if ( ctx . lineWidth == 1 ) { if ( axis . direction == "x" ) { y = Math . floor ( y ) + . 5 } else { x = Math . floor ( x ) + . 5 } } ctx . moveTo ( x , y ) ; ctx . lineTo ( x + xoff , y + yoff ) ; ctx . stroke ( ) } ctx . strokeStyle = axis . options . tickColor ; ctx . beginPath ( ) ; for ( i = 0 ; i < axis . ticks . length ; ++ i ) { var v = axis . ticks [ i ] . v ; xoff = yoff = 0 ; if ( isNaN ( v ) || v < axis . min || v > axis . max || t == "full" && ( typeof bw == "object" && bw [ axis . position ] > 0 || bw > 0 ) && ( v == axis . min || v == axis . max ) ) continue ; if ( axis . direction == "x" ) { x = axis . p2c ( v ) ; yoff = t == "full" ? - plotHeight : t ; if ( axis . position == "top" ) yoff = - yoff } else { y = axis . p2c ( v ) ; xoff = t == "full" ? - plotWidth : t ; if ( axis . position == "left" ) xoff = - xoff } if ( ctx . lineWidth == 1 ) { if ( axis . direction == "x" ) x = Math . floor ( x ) + . 5 ; else y = Math . floor ( y ) + . 5 } ctx . moveTo ( x , y ) ; ctx . lineTo ( x + xoff , y + yoff ) } ctx . stroke ( ) } if ( bw ) { bc = options . grid . borderColor ; if ( typeof bw == "object" || typeof bc == "object" ) { if ( typeof bw !== "object" ) { bw = { top : bw , right : bw , bottom : bw , left : bw } } if ( typeof bc !== "object" ) { bc = { top : bc , right : bc , bottom : bc , left : bc } } if ( bw . top > 0 ) { ctx . strokeStyle = bc . top ; ctx . lineWidth = bw . top ; ctx . beginPath ( ) ; ctx . moveTo ( 0 - bw . left , 0 - bw . top / 2 ) ; ctx . lineTo ( plotWidth , 0 - bw . top / 2 ) ; ctx . stroke ( ) } if ( bw . right > 0 ) { ctx . strokeStyle = bc . right ; ctx . lineWidth = bw . right ; ctx . beginPath ( ) ; ctx . moveTo ( plotWidth + bw . right / 2 , 0 - bw . top ) ; ctx . lineTo ( plotWidth + bw . right / 2 , plotHeight ) ; ctx . stroke ( ) } if ( bw . bottom > 0 ) { ctx . strokeStyle = bc . bottom ; ctx . lineWidth = bw . bottom ; ctx . beginPath ( ) ; ctx . moveTo ( plotWidth + bw . right , plotHeight + bw . bottom / 2 ) ; ctx . lineTo ( 0 , plotHeight + bw . bottom / 2 ) ; ctx . stroke ( ) } if ( bw . left > 0 ) { ctx . strokeStyle = bc . left ; ctx . lineWidth = bw . left ; ctx . beginPath ( ) ; ctx . moveTo ( 0 - bw . left / 2 , plotHeight + bw . bottom ) ; ctx . lineTo ( 0 - bw . left / 2 , 0 ) ; ctx . stroke ( ) } } else { ctx . lineWidth = bw ; ctx . strokeStyle = options . grid . borderColor ; ctx . strokeRect ( - bw / 2 , - bw / 2 , plotWidth + bw , plotHeight + bw ) } } ctx . restore ( )
2021-04-14 12:07:38 +02:00
} function drawAxisLabels ( ) { $ . each ( allAxes ( ) , function ( _ , axis ) { var box = axis . box , legacyStyles = axis . direction + "Axis " + axis . direction + axis . n + "Axis" , layer = "flot-" + axis . direction + "-axis flot-" + axis . direction + axis . n + "-axis " + legacyStyles , font = axis . options . font || "flot-tick-label tickLabel" , tick , x , y , halign , valign ; surface . removeText ( layer ) ; if ( ! axis . show || axis . ticks . length == 0 ) return ; for ( var i = 0 ; i < axis . ticks . length ; ++ i ) { tick = axis . ticks [ i ] ; if ( ! tick . label || tick . v < axis . min || tick . v > axis . max ) continue ; if ( axis . direction == "x" ) { halign = "center" ; x = plotOffset . left + axis . p2c ( tick . v ) ; if ( axis . position == "bottom" ) { y = box . top + box . padding } else { y = box . top + box . height - box . padding ; valign = "bottom" } } else { valign = "middle" ; y = plotOffset . top + axis . p2c ( tick . v ) ; if ( axis . position == "left" ) { x = box . left + box . width - box . padding ; halign = "right" } else { x = box . left + box . padding } } surface . addText ( layer , x , y , tick . label , font , null , null , halign , valign ) } } ) } function drawSeries ( series ) { if ( series . lines . show ) drawSeriesLines ( series ) ; if ( series . bars . show ) drawSeriesBars ( series ) ; if ( series . points . show ) drawSeriesPoints ( series ) } function drawSeriesLines ( series ) { function plotLine ( datapoints , xoffset , yoffset , axisx , axisy ) { var points = datapoints . points , ps = datapoints . pointsize , prevx = null , prevy = null ; ctx . beginPath ( ) ; for ( var i = ps ; i < points . length ; i += ps ) { var x1 = points [ i - ps ] , y1 = points [ i - ps + 1 ] , x2 = points [ i ] , y2 = points [ i + 1 ] ; if ( x1 == null || x2 == null ) continue ; if ( y1 <= y2 && y1 < axisy . min ) { if ( y2 < axisy . min ) continue ; x1 = ( axisy . min - y1 ) / ( y2 - y1 ) * ( x2 - x1 ) + x1 ; y1 = axisy . min } else if ( y2 <= y1 && y2 < axisy . min ) { if ( y1 < axisy . min ) continue ; x2 = ( axisy . min - y1 ) / ( y2 - y1 ) * ( x2 - x1 ) + x1 ; y2 = axisy . min } if ( y1 >= y2 && y1 > axisy . max ) { if ( y2 > axisy . max ) continue ; x1 = ( axisy . max - y1 ) / ( y2 - y1 ) * ( x2 - x1 ) + x1 ; y1 = axisy . max } else if ( y2 >= y1 && y2 > axisy . max ) { if ( y1 > axisy . max ) continue ; x2 = ( axisy . max - y1 ) / ( y2 - y1 ) * ( x2 - x1 ) + x1 ; y2 = axisy . max } if ( x1 <= x2 && x1 < axisx . min ) { if ( x2 < axisx . min ) continue ; y1 = ( axisx . min - x1 ) / ( x2 - x1 ) * ( y2 - y1 ) + y1 ; x1 = axisx . min } else if ( x2 <= x1 && x2 < axisx . min ) { if ( x1 < axisx . min ) continue ; y2 = ( axisx . min - x1 ) / ( x2 - x1 ) * ( y2 - y1 ) + y1 ; x2 = axisx . min } if ( x1 >= x2 && x1 > axisx . max ) { if ( x2 > axisx . max ) continue ; y1 = ( axisx . max - x1 ) / ( x2 - x1 ) * ( y2 - y1 ) + y1 ; x1 = axisx . max } else if ( x2 >= x1 && x2 > axisx . max ) { if ( x1 > axisx . max ) continue ; y2 = ( axisx . max - x1 ) / ( x2 - x1 ) * ( y2 - y1 ) + y1 ; x2 = axisx . max } if ( x1 != prevx || y1 != prevy ) ctx . moveTo ( axisx . p2c ( x1 ) + xoffset , axisy . p2c ( y1 ) + yoffset ) ; prevx = x2 ; prevy = y2 ; ctx . lineTo ( axisx . p2c ( x2 ) + xoffset , axisy . p2c ( y2 ) + yoffset ) } ctx . stroke ( ) } function plotLineArea ( datapoints , axisx , axisy ) { var points = datapoints . points , ps = datapoints . pointsize , bottom = Math . min ( Math . max ( 0 , axisy . min ) , axisy . max ) , i = 0 , top , areaOpen = false , ypos = 1 , segmentStart = 0 , segmentEnd = 0 ; while ( true ) { if ( ps > 0 && i > points . length + ps ) break ; i += ps ; var x1 = points [ i - ps ] , y1 = points [ i - ps + ypos ] , x2 = points [ i ] , y2 = points [ i + ypos ] ; if ( areaOpen ) { if ( ps > 0 && x1 != null && x2 == null ) { segmentEnd = i ; ps = - ps ; ypos = 2 ; continue } if ( ps < 0 && i == segmentStart + ps ) { ctx . fill ( ) ; areaOpen = false ; ps = - ps ; ypos = 1 ; i = segmentStart = segmentEnd + ps ; continue } } if ( x1 == null || x2 == null ) continue ; if ( x1 <= x2 && x1 < axisx . min ) { if ( x2 < axisx . min ) continue ; y1 = ( axisx . min - x1 ) / ( x2 - x1 ) * ( y2 - y1 ) + y1 ; x1 = axisx . min } else if ( x2 <= x1 && x2 < axisx . min ) { if ( x1 < axisx . min ) continue ; y2 = ( axisx . min - x1 ) / ( x2 - x1 ) * ( y2 - y1 ) + y1 ; x2 = axisx . min } if ( x1 >= x2 && x1 > axisx . max ) { if ( x2 > axisx . max ) continue ; y1 = ( axisx . max - x1 ) / ( x2 - x1 ) * ( y2 - y1 ) + y1 ; x1 = axisx . max } else if ( x2 >= x1 && x2 > axisx . max ) { if ( x1 > axisx . max ) continue ; y2 = ( axisx . max - x1 ) / ( x2 - x1 ) * ( y2 -
2021-04-09 11:29:26 +02:00
} $ . plot = function ( placeholder , data , options ) { var plot = new Plot ( $ ( placeholder ) , data , options , $ . plot . plugins ) ; return plot } ; $ . plot . version = "0.8.3" ; $ . plot . plugins = [ ] ; $ . fn . plot = function ( data , options ) { return this . each ( function ( ) { $ . plot ( this , data , options ) } ) } ; function floorInBase ( n , base ) { return base * Math . floor ( n / base ) }
} ) ( jQuery ) ;