|
|
Rivi 564: |
Rivi 564: |
| // sort | | // sort |
| memo.obsesA.sort( function(a, b) { return a.obsdatetime - b.obsdatetime; }); | | memo.obsesA.sort( function(a, b) { return a.obsdatetime - b.obsdatetime; }); |
|
| |
| // create DataTable
| |
| memo.data = new google.visualization.DataTable();
| |
|
| |
| // col for xAxis values
| |
| memo.data.addColumn( 'date', 'time' );
| |
|
| |
|
| // make ticks for y axis on cat types | | // make ticks for y axis on cat types |
Rivi 878: |
Rivi 872: |
| } | | } |
| | | |
| var doResize = function( memo ) {
| |
|
| |
| function wait() {
| |
|
| |
| //console.log( memo );
| |
|
| |
| var w = memo.chartEl.width();
| |
| var h = memo.chartEl.height();
| |
|
| |
| //console.log( w );
| |
|
| |
| if ( typeof memo.oldW == 'undefined' ) { memo.oldW = 1; }
| |
| if ( typeof memo.oldH == 'undefined' ) { memo.oldH = 1; }
| |
|
| |
| if ( ( w != memo.oldW || h != memo.oldH ) && w*h != 0 ) {
| |
|
| |
| memo.oldW = w; memo.oldH = h;
| |
|
| |
| memo.margins = { top: 10, right: 10, bottom: 80, left: 80 };
| |
|
| |
| var w = memo.chartEl.width();
| |
| var h = memo.chartEl.height();
| |
|
| |
| var l = Math.max( memo.margins.left, 0.1*w );
| |
| var r = Math.max( memo.margins.right, 0.02*w );
| |
| var t = Math.max( memo.margins.top, 0.02*h );
| |
| var b = Math.max( memo.margins.bottom, 0.15*h );
| |
|
| |
| memo.options.chartArea = { top: t, left: l, width: (w - l - r), height: (h - t - b), backgroundColor: { fill: '#fff', stroke: '#eee', strokeWidth: 4 }};
| |
|
| |
| memo.chart.draw( memo.data, memo.options );
| |
|
| |
| // hide every second vaxis gridline on cat charts
| |
| if ( i18n[memo.obscode]['type'] == 'cat') {
| |
| var glc = 0;
| |
| jQuery( document.getElementById(memo.id) ).find( 'rect[height="1"]' ).each( function() {
| |
| if ( ( glc++ % 2 ) == 0 ) {
| |
| jQuery( this ).attr( 'fill', 'none' );
| |
| }
| |
| });
| |
| }
| |
|
| |
| // add dash to trendlines
| |
| jQuery( document.getElementById(memo.id) ).find( 'path[stroke-width="2.33"]' ).each( function() {
| |
| jQuery( this ).attr('stroke-dasharray', '5, 5');
| |
| });
| |
|
| |
| // move current observations to top
| |
| gEl = jQuery( document.getElementById(memo.id) ).find( 'svg' ).append( 'g' );
| |
| jQuery( document.getElementById(memo.id) ).find( 'path[stroke="#3366cc"]' ).detach().appendTo( gEl );
| |
| jQuery( document.getElementById(memo.id) ).find( 'circle[fill="#3366cc"]' ).detach().appendTo( gEl );
| |
| jQuery( document.getElementById(memo.id) ).find( 'circle[stroke-width="3"]' ).each( function() { jQuery( this ).parent().append( jQuery( this ) ); });
| |
|
| |
| }
| |
| }
| |
| //wait();
| |
| if ( typeof memo.chartEl != 'undefined' ) {
| |
| setTimeout( wait, 500 );
| |
| }
| |
|
| |
| }
| |
| window.jwcurrentchartresize = doResize;
| |
|
| |
| function smooth( list, degree ) {
| |
| var win = degree*2-1;
| |
| weight = _.range(0, win).map(function (x) { return 1.0; });
| |
| weightGauss = [];
| |
| for (i in _.range(0, win)) {
| |
| i = i-degree+1;
| |
| frac = i/win;
| |
| gauss = 1 / Math.exp((4*(frac))*(4*(frac)));
| |
| weightGauss.push(gauss);
| |
| }
| |
| weight = _(weightGauss).zip(weight).map(function (x) { return x[0]*x[1]; });
| |
| smoothed = _.range(0, (list.length+1)-win).map(function (x) { return 0.0; });
| |
| for (i=0; i < smoothed.length; i++) {
| |
| smoothed[i] = _(list.slice(i, i+win)).zip(weight).map(function (x) { return x[0]*x[1]; }).reduce(function (memo, num){ return memo + num; }, 0) / _(weight).reduce(function (memo, num){ return memo + num; }, 0);
| |
| }
| |
| return smoothed;
| |
| }
| |
|
| |
| function dec2hex( dec, padding ) { | | function dec2hex( dec, padding ) { |
| return parseInt( dec, 10 ).toString( 16 ).padStart( padding, '0' ); | | return parseInt( dec, 10 ).toString( 16 ).padStart( padding, '0' ); |