module Webglimpse { export interface TimeGridPainterOptions { tickSpacing ? : number ; gridColor ? : Color ; referenceDate ? : string ; } export function newTimeGridPainter ( timeAxis , isVerticalAxis , timeZone , options ? ) { var tickSpacing = ( hasval ( options ) && hasval ( options . tickSpacing ) ? options . tickSpacing : 60 ) ; var gridColor = ( hasval ( options ) && hasval ( options . gridColor ) ? options . gridColor : black ) ; var referenceDate_PMILLIS = ( hasval ( options ) && hasval ( options . referenceDate ) ? parseTime_PMILLIS ( options . referenceDate ) : undefined ) ; var program = new Program ( xyFrac_VERTSHADER , solid_FRAGSHADER ) ; var u_Color = new UniformColor ( program , 'u_Color' ) ; var a_XyFrac = new Attribute ( program , 'a_XyFrac' ) ; var xyFrac = new Float32Array ( 0 ) ; var xyFracBuffer = newDynamicBuffer ( ) ; return function ( gl , viewport ) { var tickTimes_PMILLIS = getTickTimes_PMILLIS ( timeAxis , ( isVerticalAxis ? viewport . h : viewport . w ) , tickSpacing , timeZone , referenceDate_PMILLIS ) ; var tickCount = tickTimes_PMILLIS . length ; program . use ( gl ) ; u_Color . setData ( gl , gridColor ) ; xyFrac = ensureCapacityFloat32 ( xyFrac , 4 * tickCount ) ; for ( var n = 0 ; n < tickCount ; n ++ ) { var tFrac = timeAxis . tFrac ( tickTimes_PMILLIS [ n ] ) ; if ( isVerticalAxis ) { tFrac = ( Math . floor ( tFrac * viewport . h ) + 0.5 ) / viewport . h ; xyFrac [ ( 4 * n + 0 ) ] = 0 ; xyFrac [ ( 4 * n + 1 ) ] = tFrac ; xyFrac [ ( 4 * n + 2 ) ] = 1 ; xyFrac [ ( 4 * n + 3 ) ] = tFrac ; } else { tFrac = ( Math . floor ( tFrac * viewport . w + 1e-4 ) + 0.5 ) / viewport . w ; xyFrac [ ( 4 * n + 0 ) ] = tFrac ; xyFrac [ ( 4 * n + 1 ) ] = 0 ; xyFrac [ ( 4 * n + 2 ) ] = tFrac ; xyFrac [ ( 4 * n + 3 ) ] = 1 ; } } xyFracBuffer . setData ( xyFrac . subarray ( 0 , 4 * tickCount ) ) ; a_XyFrac . setDataAndEnable ( gl , xyFracBuffer , 2 , GL . FLOAT ) ; gl . lineWidth ( 1 ) ; gl . drawArrays ( GL . LINES , 0 , 2 * tickCount ) ; a_XyFrac . disable ( gl ) ; program . endUse ( gl ) ; } ; } }