Ero sivun ”Widget:Test4” versioiden välillä
Järvi-meriwikistä
(49 välissä olevaa versiota samalta käyttäjältä ei näytetä) | |||
Rivi 112: | Rivi 112: | ||
drawVisualization(memo); | drawVisualization(memo); | ||
}); | }); | ||
− | |||
− | |||
}); | }); | ||
Rivi 634: | Rivi 632: | ||
var size = 6; | var size = 6; | ||
var line = 0; | var line = 0; | ||
+ | var highlight = true; | ||
if ( memo.seasonsA[ s ].id == memo.curSeason ) { | if ( memo.seasonsA[ s ].id == memo.curSeason ) { | ||
legend = true; color = colors.curObses; | legend = true; color = colors.curObses; | ||
size = 9; | size = 9; | ||
line = 4; | line = 4; | ||
+ | highlight = false; | ||
} | } | ||
− | memo.seriesA.push( { 'type': 'scatter', 'title': memo.seasonsA[ s ].id, 'color': color, 'size': size, 'line': line, 'legend': legend, 'trendline': 'none', obses: [] } ); | + | memo.seriesA.push( { 'type': 'scatter', 'title': memo.seasonsA[ s ].id, 'highlight': highlight, 'color': color, 'size': size, 'line': line, 'legend': legend, 'trendline': 'none', obses: [] } ); |
for ( var o in memo.seasonsA[ s ].obses ) { | for ( var o in memo.seasonsA[ s ].obses ) { | ||
memo.seriesA[ memo.seriesA.length - 1 ].obses.push( { | memo.seriesA[ memo.seriesA.length - 1 ].obses.push( { | ||
Rivi 650: | Rivi 650: | ||
} | } | ||
} | } | ||
− | memo.seriesA.push( { 'type': 'scatter', 'title': memo.obsMinDate.getFullYear() + '-' + memo.obsMaxDate.getFullYear(), 'color': colors.obses, 'size': 6, 'line': 0, 'legend': true, 'trendline': 'none', obses: [] } ); | + | memo.seriesA.push( { 'type': 'scatter', 'title': memo.obsMinDate.getFullYear() + '-' + memo.obsMaxDate.getFullYear(), 'highlight': false, 'color': colors.obses, 'size': 6, 'line': 0, 'legend': true, 'trendline': 'none', obses: [] } ); |
// make week averages | // make week averages | ||
Rivi 656: | Rivi 656: | ||
for (var o in memo.obsesA) { | for (var o in memo.obsesA) { | ||
− | mwDate = new Date( memo.obsesA[o].compareDate.getFullYear(), memo.obsesA[o].compareDate.getMonth(), memo.obsesA[o].compareDate.getDate() ); | + | mwDate = new Date( memo.obsesA[o].compareDate.getFullYear(), memo.obsesA[o].compareDate.getMonth(), memo.obsesA[o].compareDate.getDate(), 12 ); |
+ | mwDate.setDate( mwDate.getDate() - mwDate.getDay() + 3 ); | ||
+ | |||
w = mwDate.getWeek(); | w = mwDate.getWeek(); | ||
v = memo.obsesA[o].value; | v = memo.obsesA[o].value; | ||
− | |||
− | |||
− | |||
− | |||
− | |||
if ( typeof memo.avgW[w] == 'undefined' ) { | if ( typeof memo.avgW[w] == 'undefined' ) { | ||
− | mwDate.setDate( mwDate.getDate() - mwDate.getDay() + 3 ) | + | mwDate.setDate( mwDate.getDate() - mwDate.getDay() + 3 ); |
memo.avgW[w] = { week: w, cDate: new Date( mwDate.getTime() ), values: [ v ], sum: v, count: 1, avg: v }; | memo.avgW[w] = { week: w, cDate: new Date( mwDate.getTime() ), values: [ v ], sum: v, count: 1, avg: v }; | ||
} else { | } else { | ||
Rivi 675: | Rivi 672: | ||
} | } | ||
} | } | ||
− | |||
memo.avgWA = []; | memo.avgWA = []; | ||
if ( memo.season == 'summer' ) { | if ( memo.season == 'summer' ) { | ||
− | for ( var w=1; w<54; | + | for ( var w=1; w<54; w++ ) { |
if ( typeof memo.avgW[ w ] != 'undefined' ) { memo.avgWA.push( memo.avgW[ w ] ); } | if ( typeof memo.avgW[ w ] != 'undefined' ) { memo.avgWA.push( memo.avgW[ w ] ); } | ||
} | } | ||
Rivi 690: | Rivi 686: | ||
} | } | ||
} | } | ||
− | + | ||
+ | for ( var w=0; w<(memo.avgWA.length); w++ ) { | ||
+ | memo.avgWA[ w ].running3 = memo.avgWA[ w ].avg; | ||
+ | memo.avgWA[ w ].running5 = memo.avgWA[ w ].avg; | ||
+ | } | ||
+ | |||
+ | // make running average of 3 week averages | ||
+ | for ( var w=1; w<(memo.avgWA.length-1); w++ ) { | ||
+ | memo.avgWA[ w ].running3 = ( memo.avgWA[ w-1 ].sum + memo.avgWA[ w ].sum + memo.avgWA[ w+1 ].sum ) / ( memo.avgWA[ w-1 ].count + memo.avgWA[ w ].count + memo.avgWA[ w+1 ].count ); | ||
+ | //memo.avgWA[ w ].running3 = ( memo.avgWA[ w-1 ].avg + memo.avgWA[ w ].avg + memo.avgWA[ w+1 ].avg ) / ( 3 ); | ||
+ | } | ||
+ | |||
+ | // make running average of 5 week averages | ||
+ | for ( var w=2; w<(memo.avgWA.length-2); w++ ) { | ||
+ | memo.avgWA[ w ].running = ( memo.avgWA[ w-2 ].sum + memo.avgWA[ w-1 ].sum + memo.avgWA[ w ].sum + memo.avgWA[ w+1 ].sum + memo.avgWA[ w+2 ].sum ) / ( memo.avgWA[ w-2 ].count + memo.avgWA[ w-1 ].count + memo.avgWA[ w ].count + memo.avgWA[ w+1 ].count + memo.avgWA[ w+2 ].count ); | ||
+ | //memo.avgWA[ w ].running = ( memo.avgWA[ w-2 ].avg + memo.avgWA[ w-1 ].avg + memo.avgWA[ w ].avg + memo.avgWA[ w+1 ].avg + memo.avgWA[ w+2 ].avg ) / ( 5 ); | ||
+ | } | ||
+ | |||
+ | // make raw hma | ||
+ | for ( var w=0; w<(memo.avgWA.length); w++ ) { | ||
+ | memo.avgWA[ w ].hma = 2*memo.avgWA[ w ].running3 - memo.avgWA[ w ].running5; | ||
+ | memo.avgWA[ w ].hmas = memo.avgWA[ w ].hma; | ||
+ | } | ||
+ | |||
+ | for ( var w=1; w<(memo.avgWA.length-1); w++ ) { | ||
+ | memo.avgWA[ w ].hmas = ( memo.avgWA[ w-1 ].hma + memo.avgWA[ w ].hma + memo.avgWA[ w+1 ].hma ) / ( 3 ); | ||
+ | } | ||
+ | |||
// make running average of week averages | // make running average of week averages | ||
Rivi 706: | Rivi 729: | ||
} | } | ||
− | } | + | } |
+ | |||
+ | // calculate standard deviation | ||
+ | devSum = 0; | ||
+ | devC = 0; | ||
+ | devMax = 0; | ||
+ | for ( var w=0; w<memo.avgWA.length; w++ ) { | ||
+ | devC++; | ||
+ | devx = 0; | ||
+ | for (var vi in memo.avgWA[w].values ) { | ||
+ | devx += Math.pow( (memo.avgWA[w].values[vi] - memo.avgWA[w].avg), 2 ); | ||
+ | } | ||
+ | memo.avgWA[w].dev = Math.sqrt( devx/memo.avgWA[w].count ); | ||
+ | devSum += memo.avgWA[w].dev; | ||
+ | devMax = Math.max( memo.avgWA[w].dev, devMax ); | ||
+ | } | ||
+ | devAvg = devSum/devC; | ||
//console.log( memo.avgWA ); | //console.log( memo.avgWA ); | ||
− | memo.seriesA.push( { 'type': 'area', 'title': ' | + | memo.seriesA.push( { 'type': 'area', 'title': i18n[ 'average' ][ memo.lang ], 'highlight': false, 'color': colors.average, 'size': 0, 'line': 2.33, 'legend': true, 'trendline': 'none', obses: [] } ); |
+ | for ( var w in memo.avgWA ) { | ||
+ | memo.seriesA[ memo.seriesA.length - 1 ].obses.push( { | ||
+ | 'x': memo.avgWA[ w ].cDate, | ||
+ | 'y': memo.avgWA[ w ].hmas, | ||
+ | 'style': null, | ||
+ | 'tooltip': i18n[ 'moving' ][ memo.lang ], | ||
+ | 'annotation': null | ||
+ | }); | ||
+ | |||
+ | } | ||
+ | |||
+ | /* | ||
+ | memo.seriesA.push( { 'type': 'scatter', 'title': 'Hull', 'highlight': false, 'color': 'green', 'size': 0, 'line': 2.33, 'legend': true, 'trendline': 'none', obses: [] } ); | ||
for ( var w in memo.avgWA ) { | for ( var w in memo.avgWA ) { | ||
memo.seriesA[ memo.seriesA.length - 1 ].obses.push( { | memo.seriesA[ memo.seriesA.length - 1 ].obses.push( { | ||
'x': memo.avgWA[ w ].cDate, | 'x': memo.avgWA[ w ].cDate, | ||
− | 'y': memo.avgWA[ w ].running, | + | //'y': memo.avgWA[ w ].running + Math.max( memo.avgWA[ w ].dev, devAvg ) * 2, |
+ | 'y': memo.avgWA[ w ].hmas, | ||
'style': null, | 'style': null, | ||
− | 'tooltip': | + | 'tooltip': i18n[ 'moving' ][ memo.lang ], |
'annotation': null | 'annotation': null | ||
}); | }); | ||
− | } | + | } |
+ | */ | ||
+ | for ( var w=0; w<memo.avgWA.length; w++ ) { | ||
+ | //Integer( SquareRoot(Period) ) WMA [2 x Integer(Period/2) WMA(Price) - Period WMA(Price)] | ||
+ | } | ||
// add columns | // add columns | ||
Rivi 732: | Rivi 789: | ||
memo.data.addColumn( { type: 'string', role: 'annotation' } ); | memo.data.addColumn( { type: 'string', role: 'annotation' } ); | ||
− | memo.options.series.push( { type: 'line', curveType: 'function', pointType: 'circle', pointSize: memo.seriesA[ s ].size, lineWidth: memo.seriesA[ s ].line, 'color': memo.seriesA[ s ].color, 'visibleInLegend': memo.seriesA[ s ].legend } ); | + | memo.options.series.push( { label: memo.seriesA[ s ].title, type: 'line', curveType: 'function', pointType: 'circle', pointSize: memo.seriesA[ s ].size, lineWidth: memo.seriesA[ s ].line, 'color': memo.seriesA[ s ].color, 'visibleInLegend': memo.seriesA[ s ].legend, highlight: memo.seriesA[ s ].highlight } ); |
if ( memo.seriesA[ s ].trendline != 'none' ) { | if ( memo.seriesA[ s ].trendline != 'none' ) { | ||
Rivi 750: | Rivi 807: | ||
memo.data.addColumn( { type: 'string', role: 'annotation' } ); | memo.data.addColumn( { type: 'string', role: 'annotation' } ); | ||
− | memo.options.series.push( { type: 'area', curveType: 'function', pointType: 'circle', pointSize: memo.seriesA[ s ].size, lineWidth: memo.seriesA[ s ].line, 'color': memo.seriesA[ s ].color, 'visibleInLegend': memo.seriesA[ s ].legend } ); | + | memo.options.series.push( { label: memo.seriesA[ s ].title, type: 'area', curveType: 'function', pointType: 'circle', pointSize: memo.seriesA[ s ].size, lineWidth: memo.seriesA[ s ].line, 'color': memo.seriesA[ s ].color, 'areaOpacity': 0.8, 'visibleInLegend': memo.seriesA[ s ].legend, highlight: memo.seriesA[ s ].highlight } ); |
if ( memo.seriesA[ s ].trendline != 'none' ) { | if ( memo.seriesA[ s ].trendline != 'none' ) { | ||
Rivi 794: | Rivi 851: | ||
} | } | ||
− | } | + | } |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | console.log( memo.dataA ); | ||
− | |||
− | |||
// make ticks for x axis | // make ticks for x axis | ||
Rivi 841: | Rivi 890: | ||
memo.options.hAxis.ticks.push({v: middleOfMonth, f: i18n.months[m]['roman'] }); | memo.options.hAxis.ticks.push({v: middleOfMonth, f: i18n.months[m]['roman'] }); | ||
} | } | ||
− | } | + | } |
− | + | ||
− | |||
− | |||
drawChart(memo); | drawChart(memo); | ||
Rivi 862: | Rivi 909: | ||
memo.downloadEl.fadeIn( "slow" ); | memo.downloadEl.fadeIn( "slow" ); | ||
− | memo.selectedCol = | + | memo.selectedCol = -1; |
google.visualization.events.addListener( memo.chart, 'select', function () { | google.visualization.events.addListener( memo.chart, 'select', function () { | ||
+ | |||
+ | for ( var c in memo.options.series ) { | ||
+ | if ( memo.options.series[c].highlight ) { | ||
+ | memo.options.series[c].lineWidth = 0; | ||
+ | //memo.options.series[c].pointSize = memo.options.series[c].origSize; | ||
+ | memo.options.series[c].color = colors['obses']; | ||
+ | memo.options.series[c].visibleInLegend = false; | ||
+ | } | ||
+ | } | ||
var selection = memo.chart.getSelection(); | var selection = memo.chart.getSelection(); | ||
− | if (selection.length > 0) { | + | if ( selection.length > 0 ) { |
var col = selection[0].column; | var col = selection[0].column; | ||
+ | var sLabel = memo.data.getColumnLabel( selection[0].column ); | ||
+ | var sSeries = ''; | ||
− | for (var c in memo.options.series) { | + | for (var c in memo.options.series) { |
− | if (memo.options.series[c]. | + | if ( memo.options.series[c].label == sLabel ) { |
− | + | sSeries = c; break; | |
− | + | } | |
− | |||
− | |||
− | } | ||
} | } | ||
− | + | ||
− | if (col != memo.selectedCol && memo.options.series[ | + | if ( col != memo.selectedCol && memo.options.series[c].highlight ) { |
memo.selectedCol = col; | memo.selectedCol = col; | ||
− | memo.options.series[ | + | memo.options.series[ sSeries ].lineWidth = 3; |
//memo.options.series[(col-1)/4].pointSize = 12; | //memo.options.series[(col-1)/4].pointSize = 12; | ||
− | memo.options.series[ | + | memo.options.series[ sSeries ].color = colors[ 'selObses' ]; |
− | memo.options.series[ | + | memo.options.series[ sSeries ].visibleInLegend = true; |
} else { | } else { | ||
− | memo.selectedCol = | + | memo.selectedCol = -1; |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
} | } | ||
− | + | doResize(); | |
}); | }); | ||
Rivi 965: | Rivi 1 007: | ||
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( i18n[ 'Observation' ][ memo.lang ] ); | ||
+ | headerCols.push( i18n[ 'Value' ][ memo.lang ] ); | ||
+ | headerCols.push( i18n[ 'ValueUnit' ][ memo.lang ] ); | ||
+ | headerCols.push( i18n[ 'Additionalinfo' ][ memo.lang ] ); | ||
+ | headerCols.push( i18n[ 'Image' ][ memo.lang ] ); | ||
+ | headerCols.push( i18n[ 'ObserverStatus' ][ memo.lang ] ); | ||
− | + | header += headerCols.join( ';' ); | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | header += headerCols.join( | ||
for ( var o in memo.obses ) { | for ( var o in memo.obses ) { | ||
Rivi 979: | Rivi 1 023: | ||
csvCols = []; | csvCols = []; | ||
− | csvCols.push( memo.obses[o].obsdatetime. | + | csvCols.push( memo.obses[o].obsdatetime.toLocaleDateString( memo.lang ) ); |
− | + | csvCols.push( memo.obses[o].obsdatetime.toLocaleTimeString( memo.lang ) ); | |
− | + | ||
− | + | //csvCols.push( memo.obses[o].obsdatetime.getFullYear() + '-' + ( memo.obses[o].obsdatetime.getMonth() + 1 ) + '-' + memo.obses[o].obsdatetime.getDate() ); | |
− | |||
− | |||
− | |||
+ | //if ( memo.obses[o].obsdatetime.getUTCHours() == 0 && memo.obses[o].obsdatetime.getUTCMinutes() == 0 && memo.obses[o].obsdatetime.getUTCSeconds() == 0 ) { | ||
+ | // csvCols.push( '' ); | ||
+ | //} else { | ||
+ | // csvCols.push( ( "0" + memo.obses[o].obsdatetime.getUTCHours() ).slice(-2) + ':' + ( "0" + memo.obses[o].obsdatetime.getUTCMinutes() ).slice(-2) ); | ||
+ | //} | ||
+ | csvCols.push( i18n[ memo ].title[memo.lang ] ); | ||
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 ); | ||
Rivi 1 157: | Rivi 1 204: | ||
} | } | ||
− | + | doResize(); | |
} | } | ||
Rivi 1 193: | Rivi 1 240: | ||
Date.prototype.getWeek = function() { | Date.prototype.getWeek = function() { | ||
var date = new Date(this.getTime()); | var date = new Date(this.getTime()); | ||
− | date.setHours( | + | date.setHours(12, 0, 0, 0); |
// Thursday in current week decides the year. | // Thursday in current week decides the year. | ||
date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7); | date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7); | ||
Rivi 1 207: | Rivi 1 254: | ||
var seriesC = [ 'lightgray', '#3366cc', 'orange' ]; | var seriesC = [ 'lightgray', '#3366cc', 'orange' ]; | ||
− | var colors = { 'average': ' | + | var colors = { 'average': '#c1e7f7', 'trend': '#ff4500', 'obses': 'lightgray', 'curObses': '#3366cc', 'selObses': 'gold', 'noticeObses': 'tan' }; |
var i18n = { | var i18n = { | ||
Rivi 1 233: | Rivi 1 280: | ||
'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': '???' }, | ||
'unit': '°C', | 'unit': '°C', | ||
− | 'axisTitleV': { 'fi': 'Lämpötila, °C', 'en': 'Temperature, °C', 'sv': 'Temperatur, °C', 'ru': '°C' } | + | 'axisTitleV': { 'fi': 'Lämpötila, °C', 'en': 'Temperature, °C', 'sv': 'Temperatur, °C', 'ru': '°C' }, |
+ | 'changes': { | ||
+ | 'fi': 'Pintaveden lämpötilan kuvio on uudistunut.', | ||
+ | 'en': 'The surface water temperature graph has been renewed.', | ||
+ | 'sv': 'Ytvattentemperaturdiagrammet har förnyats.', | ||
+ | 'ru': '' | ||
+ | } | ||
}, | }, | ||
'ice': { | 'ice': { | ||
Rivi 1 246: | Rivi 1 299: | ||
'axisTitleV': { 'fi': 'Jääpeite, cm', 'en': 'Ice cover, cm', 'sv': 'Istäcket, cm', 'ru': 'm' }, | 'axisTitleV': { 'fi': 'Jääpeite, cm', 'en': 'Ice cover, cm', 'sv': 'Istäcket, cm', 'ru': 'm' }, | ||
'changes': { | 'changes': { | ||
− | 'fi': 'Jääpeitteen | + | 'fi': 'Jääpeitteen paksuudesta kertova kuvio on uudistunut. Nyt voit esimerkiksi korostaa kuviosta tietyn vuoden kehityksen valitsemalla yksittäisen havainnon.', |
− | 'en': '', | + | 'en': 'The chart showing the thickness of the ice sheet has been renewed. For example, you can now highlight a particular year in the chart by selecting a single observation.', |
− | 'sv': '', | + | 'sv': 'Diagrammet som visar isens tjocklek har förnyats. Till exempel kan du nu markera ett visst år i diagrammet genom att välja en enskild observation.', |
'ru': '' | 'ru': '' | ||
} | } | ||
Rivi 1 311: | Rivi 1 364: | ||
'ObserverStatus': { 'fi': 'Havainnoijan status', 'en': 'Observer status', 'sv': 'Observatörens status', 'ru': '???' }, | 'ObserverStatus': { 'fi': 'Havainnoijan status', 'en': 'Observer status', 'sv': 'Observatörens status', 'ru': '???' }, | ||
'average': { 'fi': 'Keskimäärin', 'en': 'Average', 'sv': 'Genomsnitt', 'ru': '???' }, | 'average': { 'fi': 'Keskimäärin', 'en': 'Average', 'sv': 'Genomsnitt', 'ru': '???' }, | ||
+ | 'moving': { 'fi': 'Liukuva keskiarvo', 'en': 'Moving average', 'sv': 'Glidande medelvärde', 'ru': '???' }, | ||
'trendline': { 'fi': 'Trendiviiva', 'en': 'Trend line', 'sv': 'Trendlinje', 'ru': '???' }, | 'trendline': { 'fi': 'Trendiviiva', 'en': 'Trend line', 'sv': 'Trendlinje', 'ru': '???' }, | ||
'days': { 'fi': 'päivää', 'en': 'days', 'sv': 'dygn', 'ru': '???' }, | 'days': { 'fi': 'päivää', 'en': 'days', 'sv': 'dygn', 'ru': '???' }, |