Ero sivun ”Widget:JwObsCharts” versioiden välillä
Järvi-meriwikistä
(49 välissä olevaa versiota samalta käyttäjältä ei näytetä) | |||
Rivi 68: | Rivi 68: | ||
window.jwobschart[id] = {}; | window.jwobschart[id] = {}; | ||
− | + | ||
− | var memo = {}; window.jwobschart[id].memo = memo; | + | var memo = { "distF": 0 }; window.jwobschart[id].memo = memo; |
memo.widgetEl = jQuery( this ); | memo.widgetEl = jQuery( this ); | ||
Rivi 78: | Rivi 78: | ||
memo.waterbody = jQuery( this ).attr( 'data-jw-waterbody' ); if ( typeof memo.waterbody == 'undefined' ) { memo.waterbody = '-'; } | memo.waterbody = jQuery( this ).attr( 'data-jw-waterbody' ); if ( typeof memo.waterbody == 'undefined' ) { memo.waterbody = '-'; } | ||
memo.obscode = jQuery( this ).attr( 'data-jw-obscode' ); if ( typeof memo.obscode == 'undefined' ) { memo.obscode = '-'; } | memo.obscode = jQuery( this ).attr( 'data-jw-obscode' ); if ( typeof memo.obscode == 'undefined' ) { memo.obscode = '-'; } | ||
+ | if ( typeof i18n[ memo.obscode ] == 'undefined' ) { i18n[ memo.obscode ] = i18n.obs; } | ||
memo.refcode = jQuery( this ).attr( 'data-jw-refcode' ); if ( typeof memo.refcode == 'undefined' ) { memo.refcode = '-'; } | memo.refcode = jQuery( this ).attr( 'data-jw-refcode' ); if ( typeof memo.refcode == 'undefined' ) { memo.refcode = '-'; } | ||
memo.reffilter = jQuery( this ).attr( 'data-jw-reffilter' ); if ( typeof memo.reffilter == 'undefined' ) { memo.reffilter = ''; } | memo.reffilter = jQuery( this ).attr( 'data-jw-reffilter' ); if ( typeof memo.reffilter == 'undefined' ) { memo.reffilter = ''; } | ||
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.axistitlev = jQuery( this ).attr( 'data-axistitlev' ); if ( typeof memo.axistitlev == 'undefined' ) { memo.axistitlev = i18n[ memo.obscode ][ 'axisTitleV' ][ memo.lang ]; } | ||
+ | memo.tooltiptitle = jQuery( this ).attr( 'data-tooltiptitle' ); if ( typeof memo.tooltiptitle == 'undefined' ) { memo.tooltiptitle = i18n[ memo.obscode ][ 'title' ][ memo.lang ]; } | ||
memo.info = jQuery( this ).attr( 'data-info' ); if ( typeof memo.info == 'undefined' ) { memo.info = jQuery( this ).attr( 'data-info' ); } | memo.info = jQuery( this ).attr( 'data-info' ); if ( typeof memo.info == 'undefined' ) { memo.info = jQuery( this ).attr( 'data-info' ); } | ||
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-unit' ) != 'undefined' ) { i18n[memo.obscode]['unit'] = parseInt( jQuery( this ).attr( 'data-unit' ) ); } | ||
if ( typeof jQuery( this ).attr( 'data-start-date' ) != 'undefined' ) { | if ( typeof jQuery( this ).attr( 'data-start-date' ) != 'undefined' ) { | ||
Rivi 188: | Rivi 192: | ||
if ( i18n[memo.obscode].type == 'num' ) { | if ( i18n[memo.obscode].type == 'num' ) { | ||
− | + | ||
− | + | headerCols.push( i18n[ 'Date' ][ memo.lang ] ); | |
− | + | headerCols.push( i18n[ 'Time' ][ memo.lang ] ); | |
− | headerCols.push( '"' + | + | headerCols.push( '"' + memo.axistitlev + '"' ); |
headerCols.push( 'Lisätiedot' ); | headerCols.push( 'Lisätiedot' ); | ||
headerCols.push( 'Valokuva' ); | headerCols.push( 'Valokuva' ); | ||
Rivi 211: | Rivi 215: | ||
csvCols.push( '"' + memo.obses[o].value.toString().replace( '.', i18n['dec'][memo.lang] ) + '"' ); | csvCols.push( '"' + memo.obses[o].value.toString().replace( '.', i18n['dec'][memo.lang] ) + '"' ); | ||
− | csvCols.push( memo.obses[o].addInfo ); | + | csvCols.push( memo.obses[o].addInfo.replace( '<p>', '' ).replace( '</p>', '' ) ); |
csvCols.push( '' ); | csvCols.push( '' ); | ||
csvCols.push( memo.obses[o].maintainer ); | csvCols.push( memo.obses[o].maintainer ); | ||
Rivi 329: | Rivi 333: | ||
memo.trendType = jQuery( this ).attr( 'data-trend-type' ); if (typeof memo.trendType == 'undefined') { memo.trendType = i18n[memo.obscode]['trend']['type']; } | memo.trendType = jQuery( this ).attr( 'data-trend-type' ); if (typeof memo.trendType == 'undefined') { memo.trendType = i18n[memo.obscode]['trend']['type']; } | ||
− | memo.jw = new jwApi(); | + | memo.jw = new jwApi(); |
− | memo.jwR = new jwApi(); | + | memo.jwR = new jwApi(); |
var custom = ''; | var custom = ''; | ||
Rivi 347: | Rivi 351: | ||
} | } | ||
+ | // if testsite | ||
+ | if ( memo.siteid == 170072 ) { so.test = true; } | ||
+ | |||
memo.jw.loadObses( so, function( o ) { | memo.jw.loadObses( so, function( o ) { | ||
− | memo.obses = memo.jw.obs; | + | memo.obses = memo.jw.obs; |
if ( memo.refcode != '-' ) { | if ( memo.refcode != '-' ) { | ||
memo.jwR.loadObses( { "obscode": memo.refcode, "siteid": memo.siteid, "sort": "SiteID", "custom": memo.reffilter }, function( r ) { | memo.jwR.loadObses( { "obscode": memo.refcode, "siteid": memo.siteid, "sort": "SiteID", "custom": memo.reffilter }, function( r ) { | ||
Rivi 356: | Rivi 363: | ||
} else { | } else { | ||
drawVisualization(memo); | drawVisualization(memo); | ||
− | } | + | } |
}); | }); | ||
} else { | } else { | ||
Rivi 373: | Rivi 380: | ||
function drawVisualization( memo ) { | function drawVisualization( memo ) { | ||
− | if ( typeof i18n[ memo.obscode ].direction != 'undefined' ) { memo.vaxisdir = i18n[ memo.obscode ].direction; } else { memo.vaxisdir = 1; } | + | if ( typeof i18n[memo.obscode].valfield == 'undefined' ) { i18n[memo.obscode].valfield = 'val'; } |
+ | if ( typeof i18n[ memo.obscode ].direction != 'undefined' ) { memo.vaxisdir = i18n[ memo.obscode ].direction; } else { memo.vaxisdir = 1; } | ||
memo.options = { | memo.options = { | ||
Rivi 384: | Rivi 392: | ||
interpolateNulls: true, | interpolateNulls: true, | ||
vAxis: { | vAxis: { | ||
− | title: | + | title: memo.axistitlev, |
titleTextStyle: { bold: true, italic: false }, | titleTextStyle: { bold: true, italic: false }, | ||
slantedText: false, | slantedText: false, | ||
Rivi 439: | Rivi 447: | ||
obs = memo.obses[o]; | obs = memo.obses[o]; | ||
− | + | ||
memo.obsesTotal++; | memo.obsesTotal++; | ||
// create data | // create data | ||
obs.data = JSON.parse( obs.printouts.DataJSON ); | obs.data = JSON.parse( obs.printouts.DataJSON ); | ||
+ | obs.data.num = obs.data[ i18n[memo.obscode].valfield ]; | ||
if ( obs.data.unit == 'cm' && i18n[memo.obscode]['unit'] == 'm' ) { | if ( obs.data.unit == 'cm' && i18n[memo.obscode]['unit'] == 'm' ) { | ||
− | obs.data. | + | obs.data.num = obs.data.num/100; |
obs.value = obs.value/100; | obs.value = obs.value/100; | ||
} | } | ||
+ | |||
+ | if ( i18n[ memo.obscode ].valfield != 'val' ) { | ||
+ | obs.value = obs.data[ i18n[memo.obscode].valfield ]; | ||
+ | } | ||
// add season | // add season | ||
Rivi 505: | Rivi 518: | ||
if ( i18n[memo.obscode]['type'] == 'cat') { | if ( i18n[memo.obscode]['type'] == 'cat') { | ||
− | obs.popup +='<b>' + | + | obs.popup +='<b>' + memo.tooltiptitle + ': ' + i18n[memo.obscode]['catNames'][obs.value][memo.lang] + '</b> '; |
} else if ( i18n[memo.obscode]['type'] == 'date') { | } else if ( i18n[memo.obscode]['type'] == 'date') { | ||
− | obs.popup +='<b>' + | + | obs.popup +='<b>' + memo.tooltiptitle + '</b> '; |
} else { | } else { | ||
− | obs.popup +='<b>' + | + | memo.decimals = 1; |
+ | if ( memo.obscode == 'level' ) { memo.decimals = 2; } | ||
+ | obs.popup +='<b>' + memo.tooltiptitle + ': ' + (Math.round(obs.value * (memo.decimals*10))/(memo.decimals*10)).toString().replace( '.', i18n['dec'][memo.lang] ) + ' ' + i18n[memo.obscode]['unit'] + '</b> '; | ||
} | } | ||
Rivi 521: | Rivi 536: | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
memo.obsMinDate = new Date( memo.obsMinDateMs ); | memo.obsMinDate = new Date( memo.obsMinDateMs ); | ||
Rivi 1 087: | Rivi 1 086: | ||
// 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' }; | ||
− | + | ||
for (var o in memo.obsesA) { | for (var o in memo.obsesA) { | ||
dateStr = memo.obsesA[o].popup.match( /\([^)]*\)/g ); | dateStr = memo.obsesA[o].popup.match( /\([^)]*\)/g ); | ||
Rivi 1 245: | Rivi 1 244: | ||
// create cols for each series | // create cols for each series | ||
var sc = 0; | var sc = 0; | ||
− | for (var s in memo.seasonsA) { | + | |
+ | |||
+ | for (var s in memo.seasonsA) { | ||
// data | // data | ||
Rivi 1 317: | Rivi 1 318: | ||
// make week averages | // make week averages | ||
− | memo.avgW = {}; | + | memo.avgW = {}; |
for (var o in memo.obsesA) { | for (var o in memo.obsesA) { | ||
Rivi 1 374: | Rivi 1 375: | ||
memo.avgWlist.sort( function(a, b) { return (a.y*100+a.w) - (b.y*100+b.w); }); | memo.avgWlist.sort( function(a, b) { return (a.y*100+a.w) - (b.y*100+b.w); }); | ||
− | |||
firstY = memo.avgWlist[0].y; | firstY = memo.avgWlist[0].y; | ||
firstW = memo.avgWlist[0].w; | firstW = memo.avgWlist[0].w; | ||
Rivi 1 525: | Rivi 1 525: | ||
for (var s in memo.seasonsA) { | for (var s in memo.seasonsA) { | ||
+ | |||
+ | //console.log( s ); | ||
for (var o in memo.seasonsO[memo.seasonsA[s]].obses) { | for (var o in memo.seasonsO[memo.seasonsA[s]].obses) { | ||
Rivi 1 540: | Rivi 1 542: | ||
// data for series cols | // data for series cols | ||
if ( memo.seasonsA[s] == memo.curSeason ) { | if ( memo.seasonsA[s] == memo.curSeason ) { | ||
− | dataRow[s*4+1] = obs.value; | + | dataRow[s*4+1] = obs.value; |
} else { | } else { | ||
+ | //console.log( memo.distF ); | ||
dataRow[s*4+1] = obs.value + memo.distF*Math.random() - memo.distF*Math.random(); | dataRow[s*4+1] = obs.value + memo.distF*Math.random() - memo.distF*Math.random(); | ||
} | } | ||
Rivi 1 563: | Rivi 1 566: | ||
} | } | ||
− | } | + | } |
// make ticks for x axis | // make ticks for x axis | ||
Rivi 1 798: | Rivi 1 801: | ||
'season': { 'winter': { 'fi': 'Talvi', 'en': 'Winter', 'sv': 'Vintern' } }, | 'season': { 'winter': { 'fi': 'Talvi', 'en': 'Winter', 'sv': 'Vintern' } }, | ||
'dec': { 'fi': ',', 'en': '.', 'sv': ',' }, | 'dec': { 'fi': ',', 'en': '.', 'sv': ',' }, | ||
− | 'sep': { 'fi': ' | + | 'sep': { 'fi': ';', 'en': ';', 'sv': ';' }, |
+ | 'obs': { | ||
+ | 'type': 'num', | ||
+ | 'season': 'summer', | ||
+ | 'trend': { 'type': 'gaussian', 'layout': 'line' }, | ||
+ | 'title': { 'fi': '', 'en': '', 'sv': '', 'ru': '' }, | ||
+ | 'unit': '', | ||
+ | 'axisTitleV': { 'fi': '', 'en': '', 'sv': '', 'ru': '' } | ||
+ | }, | ||
'alg': { | 'alg': { | ||
'type': 'cat', | 'type': 'cat', | ||
Rivi 1 813: | Rivi 1 824: | ||
'type': 'num', | 'type': 'num', | ||
'season': 'summer', | 'season': 'summer', | ||
− | + | 'min': 0, | |
'trend': { 'type': 'gaussian', 'layout': 'line' }, | 'trend': { 'type': 'gaussian', 'layout': 'line' }, | ||
'title': { 'fi': 'Pintaveden lämpötila', 'en': 'Surface water termperature', 'sv': 'Ytvattentemperatur', 'ru': '???' }, | 'title': { 'fi': 'Pintaveden lämpötila', 'en': 'Surface water termperature', 'sv': 'Ytvattentemperatur', 'ru': '???' }, | ||
Rivi 1 853: | Rivi 1 864: | ||
'snow_load': { | 'snow_load': { | ||
'catName': 'Lumikuorma', | 'catName': 'Lumikuorma', | ||
+ | 'valfield': 'load', | ||
'type': 'num', | 'type': 'num', | ||
'season': 'winter', | 'season': 'winter', | ||
'min': 0, | 'min': 0, | ||
− | 'trend': { 'type': ' | + | 'trend': { 'type': 'gaussian', 'layout': 'line' }, |
'title': { 'fi': 'Lumikuorma', 'en': 'Snow load', 'sv': 'Snöbelastning', 'ru': '???' }, | 'title': { 'fi': 'Lumikuorma', 'en': 'Snow load', 'sv': 'Snöbelastning', 'ru': '???' }, | ||
'unit': 'kg/m²', | 'unit': 'kg/m²', | ||
Rivi 1 866: | Rivi 1 878: | ||
'season': 'winter', | 'season': 'winter', | ||
'min': 0, | 'min': 0, | ||
− | 'trend': { 'type': ' | + | 'trend': { 'type': 'gaussian', 'layout': 'line' }, |
'title': { 'fi': 'Lumipeitteen paksuus', 'en': 'Snow cover depth', 'sv': 'Snötäckets tjockhet', 'ru': '???' }, | 'title': { 'fi': 'Lumipeitteen paksuus', 'en': 'Snow cover depth', 'sv': 'Snötäckets tjockhet', 'ru': '???' }, | ||
'unit': 'cm', | 'unit': 'cm', | ||
Rivi 1 962: | Rivi 1 974: | ||
'ValueUnit': { 'fi': 'Arvon tyyppi', 'en': 'Value type', 'sv': 'Värdes typ', 'ru': '???' }, | 'ValueUnit': { 'fi': 'Arvon tyyppi', 'en': 'Value type', 'sv': 'Värdes typ', 'ru': '???' }, | ||
'Date': { 'fi': 'Päivämäärä', 'en': 'Date', 'sv': 'Datum', 'ru': '???' }, | 'Date': { 'fi': 'Päivämäärä', 'en': 'Date', 'sv': 'Datum', 'ru': '???' }, | ||
+ | 'Time': { 'fi': 'Kellonaika', 'en': 'Time', 'sv': 'Tid', 'ru': '???' }, | ||
'Additionalinfo': { 'fi': 'Lisätiedot', 'en': 'Additional info', 'sv': 'Tillägsinformation', 'ru': '???' }, | 'Additionalinfo': { 'fi': 'Lisätiedot', 'en': 'Additional info', 'sv': 'Tillägsinformation', 'ru': '???' }, | ||
'Image': { 'fi': 'Valokuva', 'en': 'Image', 'sv': 'Bild', 'ru': '???' }, | 'Image': { 'fi': 'Valokuva', 'en': 'Image', 'sv': 'Bild', 'ru': '???' }, |