Ero sivun ”Widget:JwObsCharts2” versioiden välillä
Järvi-meriwikistä
(46 välissä olevaa versiota samalta käyttäjältä ei näytetä) | |||
Rivi 82: | Rivi 82: | ||
memo.obscodeParts = memo.obscode.split('_'); | memo.obscodeParts = memo.obscode.split('_'); | ||
memo.title = jQuery( this ).attr( 'data-title' ); if ( typeof memo.title == 'undefined' ) { memo.title = i18n[ memo.obscode ][ 'title' ][ memo.lang ]; } | memo.title = jQuery( this ).attr( 'data-title' ); if ( typeof memo.title == 'undefined' ) { memo.title = i18n[ memo.obscode ][ 'title' ][ memo.lang ]; } | ||
− | memo.info = jQuery( this ).attr( 'data-info' ); if ( typeof memo.info == 'undefined' ) { memo.info = jQuery( this ).attr( 'data- | + | memo.info = jQuery( this ).attr( 'data-info' ); if ( typeof memo.info == 'undefined' ) { memo.info = ""; } |
+ | memo.caption = jQuery( this ).attr( 'data-caption' ); if ( typeof memo.caption == 'undefined' ) { memo.caption = ""; } | ||
+ | //console.log( jQuery( this ).attr( 'data-showlink' ) ); | ||
+ | if ( typeof jQuery( this ).attr( 'data-showlink' ) == 'undefined' ) { | ||
+ | //console.log( 'sd' ); | ||
+ | memo.showlink = false; | ||
+ | } else { | ||
+ | memo.showlink = ( jQuery( this ).attr( 'data-showlink' ).toLowerCase() == 'true' ); | ||
+ | } | ||
if ( typeof jQuery( this ).attr( 'data-min' ) != 'undefined' ) { i18n[memo.obscode]['min'] = parseInt( jQuery( this ).attr( 'data-min' ) ); } | if ( typeof jQuery( this ).attr( 'data-min' ) != 'undefined' ) { i18n[memo.obscode]['min'] = parseInt( jQuery( this ).attr( 'data-min' ) ); } | ||
+ | if ( typeof jQuery( this ).attr( 'data-max' ) != 'undefined' ) { i18n[memo.obscode]['max'] = parseInt( jQuery( this ).attr( 'data-max' ) ); } | ||
if ( typeof jQuery( this ).attr( 'data-start-date' ) != 'undefined' ) { | if ( typeof jQuery( this ).attr( 'data-start-date' ) != 'undefined' ) { | ||
Rivi 116: | Rivi 125: | ||
// add chart container | // add chart container | ||
− | memo.widgetEl.append( '<div class="card JwCard mb-2" style="position: relative; width: 100%; height: 100%;"><div class="card-header" style="min-height: 49px;"></div><div class="card-body p-2" style="position: relative; width: 100%; height: 100%;"><div class="chart-container" style="position: relative; z-index: 110; width: 100%; height: 100%;"></div></div></div>' ); | + | memo.widgetEl.append( '<div class="card JwCard mb-2" style="position: relative; width: 100%; height: 100%;"><div class="card-header" style="min-height: 49px;"></div><div class="card-body p-2" style="position: relative; width: 100%; height: 100%;"><div class="chart-container" style="position: relative; z-index: 110; width: 100%; height: 100%;"></div></div><div class="card-footer"></div>' ); |
memo.chartEl = jQuery( this ).find( '.chart-container' ); | memo.chartEl = jQuery( this ).find( '.chart-container' ); | ||
memo.chartEl.css( 'height', memo.height + 'px' ); | memo.chartEl.css( 'height', memo.height + 'px' ); | ||
− | memo.headerEl = jQuery( this ).find( '.card-header' ); | + | memo.headerEl = jQuery( this ).find( '.card-header' ); |
+ | memo.footerEl = jQuery( this ).find( '.card-footer' ); | ||
// add title | // add title | ||
memo.headerEl.append( '<div class="obscharttitle" style="float: left;"></div>' ); | memo.headerEl.append( '<div class="obscharttitle" style="float: left;"></div>' ); | ||
memo.titleEl = jQuery( this ).find( '.obscharttitle' ); | memo.titleEl = jQuery( this ).find( '.obscharttitle' ); | ||
+ | console.log( memo ); | ||
+ | // add or hide footer | ||
+ | if ( memo.caption == '' ) { | ||
+ | memo.footerEl.hide(); | ||
+ | } else { | ||
+ | memo.footerEl.append( memo.caption ); | ||
+ | } | ||
// add fullscreen button | // add fullscreen button | ||
Rivi 313: | Rivi 330: | ||
}); | }); | ||
+ | } | ||
+ | |||
+ | // add show site link button | ||
+ | if ( memo.showlink ) { | ||
+ | memo.headerEl.append( '<div class="obschartbutton sitelink-button" style="display: none; margin-left: 10px; float: right; Xbackground-color: rgba( 255, 255, 255, 1 ); border-radius: 50%; Xborder: 1px solid rgba( 0, 0, 0, 0.5 ); Xpadding: 1px;"><button title="' + i18n['sitelink'][memo.lang] + '" style="width: 24px; height: 24px; padding: 0; margin: 0; color: #1B599B; background: none; border: none; "><i class="fas fa-map-marked"></i></button></div>' ); | ||
+ | memo.sitelinkEl = jQuery( this ).find( '.sitelink-button' ); | ||
+ | memo.sitelinkEl.on( 'click', function() { | ||
+ | var elem = memo.widgetEl[0]; | ||
+ | window.location.href = 'https://www.jarviwiki.fi/w/index.php?curid=' + memo.siteid; | ||
+ | }); | ||
} | } | ||
− | } | + | } |
memo.loadStarts = 0; | memo.loadStarts = 0; | ||
Rivi 354: | Rivi 381: | ||
so.waterbody = memo.waterbody; | so.waterbody = memo.waterbody; | ||
} | } | ||
− | + | ||
− | |||
− | |||
− | |||
memo.jw.loadObses( so, function( o ) { | memo.jw.loadObses( so, function( o ) { | ||
− | |||
memo.obses = memo.jw.obs; | memo.obses = memo.jw.obs; | ||
drawVisualization(memo); | drawVisualization(memo); | ||
Rivi 449: | Rivi 472: | ||
// create data | // create data | ||
obs.data = JSON.parse( obs.printouts.DataJSON ); | obs.data = JSON.parse( obs.printouts.DataJSON ); | ||
− | |||
if ( obs.data.unit == 'cm' && i18n[memo.obscode]['unit'] == 'm' ) { | if ( obs.data.unit == 'cm' && i18n[memo.obscode]['unit'] == 'm' ) { | ||
Rivi 527: | Rivi 549: | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
memo.obsMinDate = new Date( memo.obsMinDateMs ); | memo.obsMinDate = new Date( memo.obsMinDateMs ); | ||
Rivi 594: | Rivi 600: | ||
// make ticks for y axis on cat types | // make ticks for y axis on cat types | ||
if ( memo.obsesA.length > 0 && memo.graphType != 'current' ) { | if ( memo.obsesA.length > 0 && memo.graphType != 'current' ) { | ||
+ | |||
if ( i18n[memo.obscode]['type'] == 'cat') { | if ( i18n[memo.obscode]['type'] == 'cat') { | ||
memo.options.vAxis.ticks = []; | memo.options.vAxis.ticks = []; | ||
Rivi 601: | Rivi 608: | ||
} | } | ||
memo.options.vAxis.ticks.sort( function(a, b) { return a.v-b.v } ); | memo.options.vAxis.ticks.sort( function(a, b) { return a.v-b.v } ); | ||
− | memo.options.vAxis.viewWindow = | + | memo.options.vAxis.viewWindow.min = -0.5; |
+ | memo.options.vAxis.viewWindow.max = parseInt(memo.options.vAxis.ticks[memo.options.vAxis.ticks.length-1].v)+0.5; | ||
memo.options.vAxis.gridlines.color = '#eee'; | memo.options.vAxis.gridlines.color = '#eee'; | ||
memo.options.vAxis.baselineColor = 'none'; | memo.options.vAxis.baselineColor = 'none'; | ||
− | } else if ( typeof i18n[memo.obscode]['min'] != 'undefined' ) { | + | } else { |
− | + | ||
− | + | if ( typeof i18n[memo.obscode]['min'] != 'undefined' ) { | |
+ | if ( i18n[memo.obscode]['min'] != -999 ) { | ||
+ | memo.options.vAxis.viewWindow.min = i18n[memo.obscode]['min']; | ||
+ | } | ||
+ | } else if ( memo.obsMinValue >= 0) { | ||
+ | //memo.options.vAxis.minValue = memo.obsMinValue; | ||
+ | memo.options.vAxis.viewWindow.min = memo.obsMinValue; | ||
} | } | ||
− | + | ||
− | + | if ( typeof i18n[memo.obscode]['max'] != 'undefined' ) { | |
− | + | if ( i18n[memo.obscode]['max'] != -999 ) { | |
+ | memo.options.vAxis.viewWindow.max = i18n[memo.obscode]['max']; | ||
+ | } | ||
+ | } else if ( memo.obsMaxValue >= 0) { | ||
+ | //memo.options.vAxis.minValue = memo.obsMinValue; | ||
+ | //memo.options.vAxis.viewWindow.max = memo.obsMaxValue; | ||
+ | } | ||
} | } | ||
Rivi 624: | Rivi 644: | ||
} | } | ||
− | if ( | + | if ( memo.info != '' ) { |
memo.titleEl.append( ' <button style="padding: 0 0.25em; font-size: 13px; margin-bottom: 3px;" type="button" class="btn btn-secondary btn-info" data-toggle="tooltip" data-placement="top" title="' + memo.info + '"><span class="fontawesome"></span></button>' ); | memo.titleEl.append( ' <button style="padding: 0 0.25em; font-size: 13px; margin-bottom: 3px;" type="button" class="btn btn-secondary btn-info" data-toggle="tooltip" data-placement="top" title="' + memo.info + '"><span class="fontawesome"></span></button>' ); | ||
jQuery( '[data-toggle="tooltip"]' ).tooltip(); | jQuery( '[data-toggle="tooltip"]' ).tooltip(); | ||
Rivi 651: | Rivi 671: | ||
addDataToDateOfYearChart( memo ); | addDataToDateOfYearChart( memo ); | ||
− | + | } | |
− | |||
− | |||
− | |||
− | } | ||
} | } | ||
− | function | + | function addDataToDateOfYearChart( memo ) { |
− | // | + | // do X axis min and max for this chart type |
− | memo. | + | memo.options.hAxis.minValue = new Date( memo.obsMinDateMs ); |
− | + | if ( memo.season = 'winter' && memo.options.hAxis.minValue.getMonth() < 8 ) { memo.options.hAxis.minValue.setFullYear( memo.options.hAxis.minValue.getFullYear()-1 ); } | |
− | if ( | + | memo.options.hAxis.minValue.setMonth(0); |
− | + | memo.options.hAxis.minValue.setDate(1); | |
− | + | memo.options.hAxis.viewWindow.min = memo.options.hAxis.minValue; | |
− | |||
− | |||
− | if ( memo. | + | memo.options.hAxis.maxValue = new Date( memo.obsMaxDateMs ); |
+ | if ( memo.season = 'winter' && memo.options.hAxis.maxValue.getMonth() > 7 ) { memo.options.hAxis.maxValue.setFullYear( memo.options.hAxis.maxValue.getFullYear()+1 ); } | ||
+ | else { memo.options.hAxis.maxValue.setFullYear( memo.options.hAxis.maxValue.getFullYear()+1 ); } | ||
+ | memo.options.hAxis.maxValue.setMonth(11); | ||
+ | memo.options.hAxis.maxValue.setDate(31); | ||
+ | memo.options.hAxis.viewWindow.max = memo.options.hAxis.maxValue; | ||
+ | |||
+ | // do Y axis min and max for this chart type | ||
+ | memo.options.vAxis.minValue = new Date( memo.obsMinCompDate.getTime() ); | ||
+ | memo.options.vAxis.minValue.setDate(1); | ||
+ | memo.options.vAxis.viewWindow.min = memo.options.vAxis.minValue; | ||
− | + | memo.options.vAxis.maxValue = new Date( memo.obsMaxCompDate.getTime() ); | |
− | + | memo.options.vAxis.maxValue.setMonth( memo.options.vAxis.maxValue.getMonth()+1 ); | |
− | + | memo.options.vAxis.maxValue.setDate(0); | |
+ | memo.options.vAxis.viewWindow.max = memo.options.vAxis.maxValue; | ||
− | + | // do Y axis ticks and gridlines | |
− | + | memo.options.vAxis.ticks = []; | |
− | + | memo.vAxisGridlines = []; | |
− | + | memo.options.vAxis.gridlines = { color: 'transparent' }; | |
− | + | memo.options.vAxis.minorGridlines = { color: 'transparent' }; | |
− | + | minM = memo.options.vAxis.minValue.getMonth(); | |
− | + | maxM = memo.options.vAxis.maxValue.getMonth(); | |
− | + | ||
− | + | if ( minM > maxM ) { mc = 13-minM+maxM; } | |
− | + | else { mc = maxM-minM+1; } | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | for ( mi = 0; mi < mc; mi++ ) { | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | mx = minM+mi; | |
− | + | yx = memo.options.vAxis.minValue.getFullYear(); | |
− | + | if ( mx > 11 ) { yx = memo.options.vAxis.maxValue.getFullYear(); mx = mx - 12; } | |
− | if ( | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | startOfMonth = new Date( yx, mx, 1 ); | |
− | + | middleOfMonth = new Date( yx, mx, 15 ); | |
− | + | // ticks | |
− | + | memo.options.vAxis.ticks.push( { v: middleOfMonth, f: i18n['months'][mx]['long'][memo.lang] } ); | |
− | + | // gridlines except for first | |
− | + | if (mi > 0) { | |
− | + | memo.vAxisGridlines.push( new Date( startOfMonth.getTime() ) ); | |
− | if ( | + | } |
− | + | } | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | memo.seriesO = {}; | |
− | |||
− | |||
− | + | for ( var o in memo.obsesA ) { | |
− | memo. | + | obs = memo.obsesA[ o ]; |
− | + | s = obs.seriesId; | |
− | + | if ( typeof memo.seriesO[ s ] == 'undefined' ) { | |
− | + | memo.seriesO[ s ] = { 'id': s, 'order': parseInt( obs.data.cat ), 'title': i18n[ s ].title[ memo.lang ], 'type': 'scatter', 'color': i18n[ s ].color, 'obses': [] }; | |
− | + | } | |
+ | obs.xvalue = obs.seasonmiddle; | ||
+ | obs.yvalue = obs.compareDate; | ||
+ | obs.value = obs.obsdatetime.toLocaleDateString( memo.lang ); | ||
+ | obs.valueUnit = i18n[ 'Date' ][ memo.lang ]; | ||
+ | obs.tooltip = '<p><b>' + i18n[ 'season' ][ 'winter' ][ memo.lang ] + ' ' + obs.season + '–' + (obs.season+1) + '</b></p>'; | ||
+ | obs.tooltip += '<p>' + i18n[ s ].title2[ memo.lang ] + ': ' + obs.obsdatetime.toLocaleDateString( memo.lang ) + '</p>'; | ||
+ | obs.tooltip += obs.addInfo; | ||
+ | memo.seriesO[ s ].obses.push( obs ); | ||
+ | } | ||
− | + | // create ice cover series | |
− | + | if ( memo.obscode == 'ice_cat_2,5' ) { | |
− | + | memo.obsesS = {}; | |
− | + | for ( var o in memo.obsesA ) { | |
− | + | var obs = memo.obsesA[ o ]; | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | for ( var o in memo.obsesA ) { | ||
− | |||
− | |||
− | |||
− | + | if ( typeof memo.obsesS[ obs.season ] == 'undefined' ) { | |
− | + | memo.obsesS[ obs.season ] = { 'maintainer': obs.maintainer }; | |
− | |||
− | |||
− | |||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | if ( obs.data.cat == '2' ) { | ||
+ | memo.obsesS[ obs.season ][ 'low' ] = obs.compareDate; | ||
+ | } else if ( obs.data.cat == '5' ) { | ||
+ | memo.obsesS[ obs.season ][ 'high' ] = obs.compareDate; | ||
+ | } | ||
+ | if ( memo.obsesS[ obs.season ][ 'maintainer' ] != obs.maintainer ) { memo.obsesS[ obs.season ][ 'maintainer' ] = ''; } | ||
− | + | if ( typeof memo.obsesS[ obs.season ][ 'low' ] != 'undefined' && typeof memo.obsesS[ obs.season ][ 'high' ] != 'undefined' ) { | |
− | + | days = Math.round( ( memo.obsesS[ obs.season ][ 'high' ].getTime() - memo.obsesS[ obs.season ][ 'low' ].getTime() ) / ( 1000*60*60*24 ) ); | |
− | + | if ( typeof memo.seriesO[ 'ice_cat_2,5' ] == 'undefined' ) { | |
− | + | memo.seriesO[ 'ice_cat_2,5' ] = { 'id': 'ice_cat_2,5', 'order': 10, 'title': i18n[ 'ice_cat_2,5' ].title[ memo.lang ], 'type': 'candlestick', 'color': i18n[ 'ice_cat_2,5' ].color, obses: [] }; | |
− | + | } | |
− | + | memo.seriesO[ 'ice_cat_2,5' ].obses.push( { 'obsdatetime': obs.obsdatetime, 'season': obs.season, 'value': days, 'valueUnit': i18n[ 'days' ][ memo.lang ], 'addInfo': '', 'maintainer': memo.obsesS[ obs.season ][ 'maintainer' ], 'xvalue': obs.seasonmiddle, 'low': memo.obsesS[ obs.season ][ 'low' ], 'high': memo.obsesS[ obs.season ][ 'high' ], 'tooltip': '<p><b>' + i18n[ 'season' ][ 'winter' ][ memo.lang ] + ' ' + obs.season + '–' + (obs.season+1) + '</b></p><p>' + i18n[ 'ice_cat_2,5' ].title[ memo.lang ] + ': ' + days + ' ' + i18n[ 'days' ][ memo.lang ] + '</p>' } ); | |
− | + | } | |
− | |||
− | + | } | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
+ | memo.seriesA = []; for ( var s in memo.seriesO ) { memo.seriesA.push( memo.seriesO[s] ) }; | ||
+ | memo.seriesA.sort( function( a, b ) { return a.order-b.order; } ); | ||
− | + | for ( var s in memo.seriesA ) { | |
− | |||
− | + | if ( memo.seriesA[ s ].type == 'scatter' ) { | |
− | + | memo.data.addColumn( 'date', memo.seriesA[ s ].title ); // + ' ' + memo.obsMinYear + '-' + memo.obsMaxYear ); | |
+ | memo.data.addColumn( { type: 'string', 'role': 'style' } ); | ||
+ | memo.data.addColumn( { type: 'string', role: 'tooltip', 'p': { 'html': true } } ); | ||
+ | memo.data.addColumn( { type: 'string', role: 'annotation' } ); | ||
− | + | memo.options.series.push( { type: 'scatter', pointType: 'circle', pointSize: 8, color: memo.seriesA[ s ].color, XstrokeWidth: 2, Xstroke: '#000000' } ); | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | if ( memo.seriesA[ s ].obses.length > 1 ) { | |
− | + | memo.options.trendlines[ memo.options.series.length - 1 ] = { type: 'linear', title: i18n.trendline, lineWidth: 2.33, visibleInLegend: false, tooltip: false }; | |
− | + | } else { | |
− | + | memo.options.trendlines[ memo.options.series.length - 1 ] = { type: 'linear', title: i18n.trendline, lineWidth: 0, color: 'transparent', visibleInLegend: false, tooltip: false }; | |
− | + | } | |
− | |||
− | + | } else if ( memo.seriesA[ s ].type == 'candlestick' ) { | |
− | |||
− | |||
− | |||
− | + | memo.data.addColumn( 'date', memo.seriesA[ s ].title ); | |
− | + | memo.data.addColumn( 'date', '' ); | |
− | + | memo.data.addColumn( 'date', '' ); | |
− | + | memo.data.addColumn( 'date', '' ); | |
+ | memo.data.addColumn({ role: 'tooltip', 'p': { 'html': true } }); | ||
− | + | memo.options.series.push( { type: 'candlesticks', color: memo.seriesA[ s ].color, strokeWidth: 2, stroke: '#cccccc' } ); | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | } | |
− | |||
− | + | } | |
− | + | // add data to table | |
− | + | cc = memo.data.getNumberOfColumns(); | |
− | + | var st = 0; | |
+ | for ( var s in memo.seriesA ) { | ||
+ | |||
+ | for ( var o in memo.seriesA[ s ].obses ) { | ||
+ | |||
+ | obs = memo.seriesA[ s ].obses[ o ]; | ||
− | + | dataRow = []; | |
− | |||
− | + | // fill row with nulls | |
− | + | for ( var i=0; i<cc; i++ ) { dataRow.push( null ); } | |
− | + | // x axis value | |
− | + | dataRow[ 0 ] = obs.xvalue; | |
− | |||
− | |||
− | |||
− | + | if ( memo.seriesA[ s ].type == 'candlestick' ) { | |
− | + | dataRow[ st+1 ] = obs.low; | |
− | + | dataRow[ st+2 ] = obs.low; | |
− | + | dataRow[ st+3 ] = obs.high; | |
− | + | dataRow[ st+4 ] = obs.high; | |
− | + | dataRow[ st+5 ] = obs.tooltip; | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | } else if ( memo.seriesA[ s ].type == 'scatter' ) { | |
− | |||
− | |||
− | |||
− | |||
− | + | dataRow[ st+1 ] = obs.yvalue; | |
− | + | dataRow[ st+2 ] = obs.style; | |
+ | dataRow[ st+3 ] = obs.tooltip; | ||
+ | dataRow[ st+4 ] = null; | ||
} | } | ||
− | + | memo.dataA.push( dataRow ); | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | } | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | if ( memo.seriesA[ s ].type == 'candlestick' ) { | ||
+ | st += 5; | ||
+ | } else if ( memo.seriesA[ s ].type == 'scatter' ) { | ||
+ | st += 4; | ||
} | } | ||
+ | |||
} | } | ||
− | + | drawChart(memo); | |
− | |||
− | + | } | |
+ | |||
+ | function addDataToSeasonWithRefsChart(memo) { | ||
− | + | // do axis min and max | |
+ | memo.axisMinDate = new Date( memo.curSeason, 0, 1 ); | ||
+ | memo.axisMaxDate = new Date( memo.curSeason, 11, 31 ); | ||
− | + | memo.data.addColumn( 'number', '1991-2020' ); | |
− | + | memo.data.addColumn( { id:'i0', type:'number', role:'interval' } ); | |
− | + | memo.data.addColumn( { id:'i0', type:'number', role:'interval' } ); | |
− | + | memo.data.addColumn( { type: 'string', role: 'tooltip', 'p': { 'html': true } } ); | |
− | + | memo.data.addColumn( 'number', memo.curSeason ); | |
− | + | memo.data.addColumn( {'type': 'string', 'role': 'style' } ); | |
− | + | memo.data.addColumn( { type: 'string', role: 'annotation' } ); | |
− | + | memo.data.addColumn( { type: 'string', role: 'tooltip', 'p': { 'html': true } } ); | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | // series for trend line | ||
+ | //memo.options.trendlines[0] = { labelInLegend: i18n['trendline'][memo.lang], tooltip: false, color: colors['trend'], lineWidth: 2, opacity: 0.5, type: 'linear', visibleInLegend: memo.trendType!='moving' }; | ||
+ | |||
+ | for (var o in memo.obsesA) { | ||
+ | if ( memo.obsesA[o].printouts.ObsCode == memo.refcode ) { | ||
+ | memo.obsesA[o].compareDate = getDateOfISOWeek( memo.obsesA[o].data.week, memo.curSeason ) | ||
+ | memo.obsesA[o].compareDate.setDate( memo.obsesA[o].compareDate.getDate() + 3 ); | ||
} | } | ||
− | + | } | |
+ | |||
+ | var weekdata = []; | ||
+ | for ( var w=1; w<=53; w++ ) { | ||
+ | weekdata.push( { 'week': w, 'val': null, 'mw': null, 'low': null, 'high': null, 'style': null } ); | ||
+ | } | ||
+ | |||
+ | for (var o in memo.obsesA) { | ||
+ | if ( memo.obsesA[ o ].printouts.ObsCode == memo.obscode ) { | ||
+ | weekdata[ memo.obsesA[ o ].data.week-1 ].val = memo.obsesA[ o ].data.val; | ||
+ | weekdata[ memo.obsesA[ o ].data.week-1 ].style = memo.obsesA[ o ].style; | ||
+ | } else { | ||
+ | weekdata[ memo.obsesA[ o ].data.week-1 ].mw = memo.obsesA[ o ].data.val; | ||
+ | weekdata[ memo.obsesA[ o ].data.week-1 ].low = memo.obsesA[ o ].data.low / 100; | ||
+ | weekdata[ memo.obsesA[ o ].data.week-1 ].high = memo.obsesA[ o ].data.high / 100; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | for ( var w in weekdata ) { | ||
+ | |||
+ | mow = getDateOfISOWeek( weekdata[w].week, memo.curSeason ); | ||
+ | mow.setDate( mow.getDate() + 3 ); | ||
+ | |||
+ | memo.dataA.push( [ | ||
+ | mow, | ||
+ | weekdata[w].mw, | ||
+ | weekdata[w].low, | ||
+ | weekdata[w].high, | ||
+ | '<div style="padding: 5px;"><b>Vertailukauden 1991-2020 havainnot viikolla ' + weekdata[w].week + '</b><br />Suurin arvo (HW): ' + weekdata[w].high + '<br />Keskiarvo (MW): ' + weekdata[w].mw + '<br />Pienin arvo (LW): ' + weekdata[w].low + '</div>', | ||
+ | weekdata[w].val, | ||
+ | weekdata[w].style, | ||
+ | null, | ||
+ | '<div style="padding: 5px;"><b>Kuluvan vuoden vedenkorkeus viikolla ' + weekdata[w].week + '</b><br />Keskiarvo (MW): ' + weekdata[w].val + '</div>', | ||
+ | ] ); | ||
+ | } | ||
+ | |||
+ | // make ticks for x axis | ||
+ | memo.options.hAxis.ticks = []; | ||
+ | for (i=0; i<12; i++) { | ||
+ | //m = i+1; | ||
+ | middleOfMonth = new Date( memo.curSeason, i, 16 ); | ||
+ | //console.log(m); | ||
+ | memo.options.hAxis.ticks.push({v: middleOfMonth, f: i18n.months[i]['roman'] }); | ||
} | } | ||
− | + | memo.options.seriesType = 'line'; | |
− | + | memo.options.series[0] = { type: 'line', pointSize: 0, color: colors.average, lineWidth: 2.33 }; | |
− | + | memo.options.curveType = 'function'; | |
− | + | memo.options.intervals = { 'style': 'area' }; | |
− | + | memo.options.series[1] = { type: 'line', pointSize: 0, color: colors.curObses, lineWidth: 5 }; | |
− | + | ||
− | + | //memo.options.vAxis.viewWindow.min = 80.5; | |
− | + | //memo.options.vAxis.viewWindow.max = 81.7; | |
− | + | ||
− | + | memo.chart = new google.visualization.LineChart( memo.chartEl[0] ); // document.getElementById(memo.id) | |
− | + | ||
− | + | drawChart(memo); | |
− | + | } | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | function addDataToTrendWithHighLowChart (memo) { | |
− | |||
− | |||
− | |||
− | |||
− | + | //console.log( 'high low chart'); | |
− | + | // do axis min and max | |
+ | memo.axisMinDate = new Date(memo.obsMinDate.getTime()); | ||
+ | memo.axisMaxDate = new Date(memo.obsMaxDate.getTime()); | ||
+ | memo.axisMinDate.setMonth(0); | ||
+ | memo.axisMaxDate.setMonth(11); | ||
+ | memo.axisMinDate.setDate(1); | ||
+ | memo.axisMaxDate.setDate(31); | ||
− | + | memo.data.addColumn( 'number', memo.obsMinYear + '-' + memo.obsMaxYear ); | |
− | + | memo.data.addColumn( { id:'i0', type:'number', role:'interval' } ); | |
− | + | memo.data.addColumn( { id:'i0', type:'number', role:'interval' } ); | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | memo.data.addColumn( 'number', ' | ||
− | memo.data.addColumn( { id:'i0', type:'number', role:'interval' } ); | ||
− | memo.data.addColumn( { id:'i0', type:'number', role:'interval' } ); | ||
− | |||
memo.data.addColumn( {'type': 'string', 'role': 'style' } ); | memo.data.addColumn( {'type': 'string', 'role': 'style' } ); | ||
memo.data.addColumn( { type: 'string', role: 'annotation' } ); | memo.data.addColumn( { type: 'string', role: 'annotation' } ); | ||
Rivi 1 094: | Rivi 962: | ||
// series for trend line | // series for trend line | ||
//memo.options.trendlines[0] = { labelInLegend: i18n['trendline'][memo.lang], tooltip: false, color: colors['trend'], lineWidth: 2, opacity: 0.5, type: 'linear', visibleInLegend: memo.trendType!='moving' }; | //memo.options.trendlines[0] = { labelInLegend: i18n['trendline'][memo.lang], tooltip: false, color: colors['trend'], lineWidth: 2, opacity: 0.5, type: 'linear', visibleInLegend: memo.trendType!='moving' }; | ||
+ | |||
+ | //console.log( memo ); | ||
+ | |||
+ | for (var o in memo.obsesA) { | ||
− | + | dateStr = memo.obsesA[o].popup.match( /\([^)]*\)/g ); | |
− | + | yearStr = dateStr[0].match( /[0-9]{4}/g ); | |
− | + | memo.obsesA[o].popup = memo.obsesA[o].popup.replace( dateStr[0], '(' + yearStr[0] + ')' ); | |
− | + | memo.dataA.push( [ memo.obsesA[o].obsdatetime, memo.obsesA[o].value, memo.obsesA[o].data.low/100, memo.obsesA[o].data.high/100, memo.obsesA[o].style, null, memo.obsesA[o].popup ] ); | |
− | |||
− | |||
− | |||
} | } | ||
− | + | ||
− | + | memo.options.hAxis.ticks = []; | |
− | for ( | + | for (i=memo.axisMinDate.getFullYear(); i<=memo.axisMaxDate.getFullYear(); i++) { |
− | + | middleOfYear = new Date( i, 6, 1 ); | |
+ | memo.options.hAxis.ticks.push({v: middleOfYear, f: String(i) }); | ||
} | } | ||
+ | |||
+ | memo.options.seriesType = 'line'; | ||
+ | memo.options.series[0] = { type: 'line', pointSize: 3, color: '#3366cc' }; | ||
+ | memo.options.curveType = 'function'; | ||
+ | memo.options.intervals = { 'style': 'area' }; | ||
− | + | memo.options.vAxis.viewWindow.min = 80; | |
− | + | memo.options.vAxis.viewWindow.max = 82; | |
− | + | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | memo.chart = new google.visualization.LineChart( memo.chartEl[0] ); // document.getElementById(memo.id) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | drawChart(memo); | |
− | + | } | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | function addDataToTrendChart(memo) { | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | function | ||
− | |||
− | |||
// do axis min and max | // do axis min and max | ||
Rivi 1 180: | Rivi 1 005: | ||
memo.data.addColumn( 'number', memo.obsMinYear + '-' + memo.obsMaxYear ); | memo.data.addColumn( 'number', memo.obsMinYear + '-' + memo.obsMaxYear ); | ||
− | |||
− | |||
memo.data.addColumn( {'type': 'string', 'role': 'style' } ); | memo.data.addColumn( {'type': 'string', 'role': 'style' } ); | ||
memo.data.addColumn( { type: 'string', role: 'annotation' } ); | memo.data.addColumn( { type: 'string', role: 'annotation' } ); | ||
Rivi 1 187: | Rivi 1 010: | ||
// series for trend line | // series for trend line | ||
− | + | memo.options.trendlines[0] = { labelInLegend: i18n['trendline'][memo.lang], tooltip: false, color: colors['trend'], lineWidth: 2, opacity: 0.5, type: 'linear', visibleInLegend: memo.trendType!='moving' }; | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | memo.options.trendlines[0] = { labelInLegend: i18n['trendline'][memo.lang], tooltip: false, color: colors['trend'], lineWidth: 2, opacity: 0.5, type: 'linear', visibleInLegend: memo.trendType!='moving' }; | ||
Rivi 1 667: | Rivi 1 441: | ||
memo.fullscreenEl.fadeIn( "slow" ); | memo.fullscreenEl.fadeIn( "slow" ); | ||
if ( memo.download) { memo.downloadEl.fadeIn( "slow" ); } | if ( memo.download) { memo.downloadEl.fadeIn( "slow" ); } | ||
+ | if ( memo.showlink ) { memo.sitelinkEl.fadeIn( "slow" ); } | ||
memo.selectedCol = 0; | memo.selectedCol = 0; | ||
Rivi 1 730: | Rivi 1 505: | ||
function wait() { | function wait() { | ||
− | //console.log( memo ); | + | //console.log( memo.options ); |
var w = memo.chartEl.width(); | var w = memo.chartEl.width(); | ||
Rivi 1 775: | Rivi 1 550: | ||
// move current observations to top | // move current observations to top | ||
gEl = jQuery( document.getElementById(memo.id) ).find( 'svg' ).append( 'g' ); | gEl = jQuery( document.getElementById(memo.id) ).find( 'svg' ).append( 'g' ); | ||
+ | //console.log( jQuery( document.getElementById(memo.id) ).find( 'svg' ) ); | ||
jQuery( document.getElementById(memo.id) ).find( 'path[stroke="#3366cc"]' ).detach().appendTo( gEl ); | 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[fill="#3366cc"]' ).detach().appendTo( gEl ); | ||
jQuery( document.getElementById(memo.id) ).find( 'circle[stroke-width="3"]' ).each( function() { jQuery( this ).parent().append( jQuery( this ) ); }); | jQuery( document.getElementById(memo.id) ).find( 'circle[stroke-width="3"]' ).each( function() { jQuery( this ).parent().append( jQuery( this ) ); }); | ||
− | + | ||
+ | jQuery( 'circle[fill="#3366cc"]' ).each( function() { | ||
+ | //jQuery( this ).detach().appendTo( gEl ); | ||
+ | }); | ||
} | } | ||
} | } | ||
Rivi 1 851: | Rivi 1 630: | ||
'download': { 'fi': 'Lataa csv-muodossa', 'en': 'Download in csv format', 'sv': 'Ladda ner i csv-format' }, | 'download': { 'fi': 'Lataa csv-muodossa', 'en': 'Download in csv format', 'sv': 'Ladda ner i csv-format' }, | ||
'fullscreen': { 'fi': 'Ota käyttöön/poista kokoruututila', 'en': 'Toggle fullscreen mode', 'sv': 'Växla helskärmsläge' }, | 'fullscreen': { 'fi': 'Ota käyttöön/poista kokoruututila', 'en': 'Toggle fullscreen mode', 'sv': 'Växla helskärmsläge' }, | ||
+ | 'sitelink': { 'fi': 'Mene havaintopaikan sivulle', 'en': "Go to the observation site's page", 'sv': 'Gå till observationsplatsen.' }, | ||
'edit': { 'fi': 'Lisää/muokkaa havaintoja', 'en': 'Add/edit observations', 'sv': 'Lägg till/redigera observationer' }, | 'edit': { 'fi': 'Lisää/muokkaa havaintoja', 'en': 'Add/edit observations', 'sv': 'Lägg till/redigera observationer' }, | ||
'season': { 'winter': { 'fi': 'Talvi', 'en': 'Winter', 'sv': 'Vintern' } }, | 'season': { 'winter': { 'fi': 'Talvi', 'en': 'Winter', 'sv': 'Vintern' } }, |