X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=public%2Ffacet_graph.js;h=21b8dd97a70afa8762f807c005e3187492f820cc;hb=c054774aaeaf735809d65a7558aae1405538d670;hp=70ab79d58cfd3f9061d0d1ca52ea8b1a3ab28e30;hpb=c40b99f7d53d05af30ba20384116cc04e3094c78;p=MojoFacets.git diff --git a/public/facet_graph.js b/public/facet_graph.js index 70ab79d..21b8dd9 100644 --- a/public/facet_graph.js +++ b/public/facet_graph.js @@ -1,3 +1,12 @@ +$(document).ready( function() { + +var count = parseInt( $('#facet-count').text() ); +if ( count > 5000 ) { + console.debug( 'skip graph', count ); + return; +} +console.debug( 'drawing graph', count ); + var data = { x: { min: Number.MAX_VALUE, @@ -75,7 +84,13 @@ ctx.fillStyle = '#ffcc88'; ctx.moveTo( 0, 0 ); ctx.beginPath(); -for( var i in data.x.data ) { +var elements = data.x.data.length; +var step = elements / data.width; +console.debug( elements, step ); +if ( step < 1 ) step = 1; +var i_float = 0; +while( i_float < elements ) { + var i = i_float.toFixed(); var x = data.x.data[i]; if ( data.numeric ) x = Math.ceil( ( x - data.x.min ) / data.x.range * data.width ); var y = Math.ceil( ( data.y.data[i] - data.y.min ) / data.y.range * data.height ); @@ -84,10 +99,11 @@ for( var i in data.x.data ) { data.x.px.push( x ); } else { var x_px = i * data.x.inc_bar; - console.debug( x_px, y ); +// console.debug( x_px, y ); ctx.fillRect( x_px, 0, data.x.inc_bar, -y ); ctx.strokeRect( x_px, 0, data.x.inc_bar, -y ); } + i_float += step; } ctx.stroke(); @@ -122,3 +138,4 @@ draw_labels( 'labels-y', data.y, data.height, 'bottom', 'bottom:'+data.height+'p console.debug( 'data', data ); +}); // document.ready