Ero sivun ”Widget:JwObsCharts2” versioiden välillä
Järvi-meriwikistä
(22 välissä olevaa versiota samalta käyttäjältä ei näytetä) | |||
Rivi 84: | Rivi 84: | ||
memo.info = jQuery( this ).attr( 'data-info' ); if ( typeof memo.info == 'undefined' ) { memo.info = ""; } | 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 = ""; } | memo.caption = jQuery( this ).attr( 'data-caption' ); if ( typeof memo.caption == 'undefined' ) { memo.caption = ""; } | ||
− | if ( typeof jQuery( this ).attr( 'data-showlink' ) == 'undefined' ) { memo.showlink = false; | + | |
− | else { memo.showlink = ( jQuery( this ).attr( 'data-showlink' ).toLowerCase() == 'true' ); } | + | if ( typeof jQuery( this ).attr( 'data-showlink' ) == 'undefined' ) { |
+ | 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' ) ); } | ||
Rivi 131: | Rivi 135: | ||
// add or hide footer | // add or hide footer | ||
− | if ( memo.caption == '' | + | if ( memo.caption == '' ) { |
memo.footerEl.hide(); | memo.footerEl.hide(); | ||
} else { | } else { | ||
− | + | memo.footerEl.append( memo.caption ); | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
Rivi 332: | Rivi 329: | ||
}); | }); | ||
+ | } | ||
+ | |||
+ | // 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 501: | Rivi 508: | ||
// add compare date to obses | // add compare date to obses | ||
if ( memo.season == 'summer' || obs.obsdatetime.getMonth() > 7 ) { | if ( memo.season == 'summer' || obs.obsdatetime.getMonth() > 7 ) { | ||
− | obs.compareDate = new Date( memo.curSeason, obs.obsdatetime.getMonth(), obs.obsdatetime.getDate() ); | + | obs.compareDate = new Date( memo.curSeason, obs.obsdatetime.getMonth(), obs.obsdatetime.getDate() ); |
} else { | } else { | ||
obs.compareDate = new Date( memo.curSeason+1, obs.obsdatetime.getMonth(), obs.obsdatetime.getDate() ); | obs.compareDate = new Date( memo.curSeason+1, obs.obsdatetime.getMonth(), obs.obsdatetime.getDate() ); | ||
} | } | ||
+ | obs.compareDate.setHours( 12 ); | ||
ms = obs.compareDate.getTime(); | ms = obs.compareDate.getTime(); | ||
memo.obsMinCompDateMs = Math.min(ms, memo.obsMinCompDateMs); | memo.obsMinCompDateMs = Math.min(ms, memo.obsMinCompDateMs); | ||
Rivi 873: | Rivi 881: | ||
memo.obsesA[o].compareDate = getDateOfISOWeek( memo.obsesA[o].data.week, memo.curSeason ) | memo.obsesA[o].compareDate = getDateOfISOWeek( memo.obsesA[o].data.week, memo.curSeason ) | ||
memo.obsesA[o].compareDate.setDate( memo.obsesA[o].compareDate.getDate() + 3 ); | memo.obsesA[o].compareDate.setDate( memo.obsesA[o].compareDate.getDate() + 3 ); | ||
+ | memo.obsesA[o].compareDate.setHours( 12 ); | ||
} | } | ||
} | } | ||
Rivi 915: | Rivi 924: | ||
//m = i+1; | //m = i+1; | ||
middleOfMonth = new Date( memo.curSeason, i, 16 ); | middleOfMonth = new Date( memo.curSeason, i, 16 ); | ||
− | |||
memo.options.hAxis.ticks.push({v: middleOfMonth, f: i18n.months[i]['roman'] }); | memo.options.hAxis.ticks.push({v: middleOfMonth, f: i18n.months[i]['roman'] }); | ||
} | } | ||
Rivi 934: | Rivi 942: | ||
function addDataToTrendWithHighLowChart (memo) { | function addDataToTrendWithHighLowChart (memo) { | ||
− | |||
− | |||
// do axis min and max | // do axis min and max | ||
Rivi 953: | Rivi 959: | ||
// 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) { | ||
Rivi 1 051: | Rivi 1 055: | ||
memo.seasonsO[s].obses.push( memo.obsesA[o] ); | memo.seasonsO[s].obses.push( memo.obsesA[o] ); | ||
} | } | ||
− | |||
for (var o in memo.seasonsO) { memo.seasonsA.push(o); } memo.seasonsA.sort( function(a,b) { return b-a; } ); | for (var o in memo.seasonsO) { memo.seasonsA.push(o); } memo.seasonsA.sort( function(a,b) { return b-a; } ); | ||
Rivi 1 077: | Rivi 1 080: | ||
} else { | } else { | ||
if ( memo.obscode == 'secchi' ) { | if ( memo.obscode == 'secchi' ) { | ||
− | |||
memo.options.series[sc++] = { type: 'area', curveType: 'function', color: colors['curObses'], pointSize: 3, lineWidth: 4, visibleInLegend: true, hideThis: false, origSize: 10 }; | memo.options.series[sc++] = { type: 'area', curveType: 'function', color: colors['curObses'], pointSize: 3, lineWidth: 4, visibleInLegend: true, hideThis: false, origSize: 10 }; | ||
} else { | } else { | ||
Rivi 1 129: | Rivi 1 131: | ||
// make week averages | // make week averages | ||
memo.avgW = {}; | memo.avgW = {}; | ||
− | 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() ); |
+ | //mwDate.setHours( 12 ); | ||
+ | mwDate = new Date( memo.obsesA[o].compareDate.getTime() ); | ||
+ | mwDate.setDate( mwDate.getDate() - mwDate.getDay() + 3 ); | ||
+ | memo.obsesA[o].mwDate = mwDate; | ||
y = mwDate.getFullYear(); | y = mwDate.getFullYear(); | ||
w = mwDate.getWeek(); | w = mwDate.getWeek(); | ||
Rivi 1 139: | Rivi 1 145: | ||
if ( typeof memo.avgW[y][w] == 'undefined' ) { | if ( typeof memo.avgW[y][w] == 'undefined' ) { | ||
− | mwDate.setDate( mwDate.getDate() - mwDate.getDay() + 3 ) | + | //mwDate.setDate( mwDate.getDate() - mwDate.getDay() + 3 ); |
memo.avgW[y][w] = { cDate: mwDate, values: [ v ], sum: v, count: 1, avg: v }; | memo.avgW[y][w] = { cDate: mwDate, values: [ v ], sum: v, count: 1, avg: v }; | ||
} else { | } else { | ||
Rivi 1 204: | Rivi 1 210: | ||
for ( var w=w1; w<=w2; w++) { | for ( var w=w1; w<=w2; w++) { | ||
− | |||
− | |||
if ( typeof(memo.avgW[y][w]) == 'undefined' ) { | if ( typeof(memo.avgW[y][w]) == 'undefined' ) { | ||
Rivi 1 235: | Rivi 1 239: | ||
} | } | ||
} | } | ||
− | |||
− | |||
for ( var i=0; i<memo.avgMlist.length; i++ ) { | for ( var i=0; i<memo.avgMlist.length; i++ ) { | ||
Rivi 1 265: | Rivi 1 267: | ||
memo.avgLlist = memo.avgLlist.slice( memo.avgLlist.length - memo.gSmoothing/2 - 2 ).concat( memo.avgLlist ).concat( memo.avgLlist.slice( 0, memo.gSmoothing/2 + 2 ) ); | memo.avgLlist = memo.avgLlist.slice( memo.avgLlist.length - memo.gSmoothing/2 - 2 ).concat( memo.avgLlist ).concat( memo.avgLlist.slice( 0, memo.gSmoothing/2 + 2 ) ); | ||
memo.avgHlist = memo.avgHlist.slice( memo.avgHlist.length - memo.gSmoothing/2 - 2 ).concat( memo.avgHlist ).concat( memo.avgHlist.slice( 0, memo.gSmoothing/2 + 2 ) ); | memo.avgHlist = memo.avgHlist.slice( memo.avgHlist.length - memo.gSmoothing/2 - 2 ).concat( memo.avgHlist ).concat( memo.avgHlist.slice( 0, memo.gSmoothing/2 + 2 ) ); | ||
− | |||
− | |||
} else { | } else { | ||
Rivi 1 357: | Rivi 1 357: | ||
dataRow[s*4+2] = obs.style; | dataRow[s*4+2] = obs.style; | ||
dataRow[s*4+3] = obs.popup; | dataRow[s*4+3] = obs.popup; | ||
− | |||
if ( ( today.getTime() - obs.compareDate.getTime() < 10*24*60*60*1000 ) && s == 0 && o == ( memo.seasonsO[memo.seasonsA[s]].obses.length - 1 ) ) { | if ( ( today.getTime() - obs.compareDate.getTime() < 10*24*60*60*1000 ) && s == 0 && o == ( memo.seasonsO[memo.seasonsA[s]].obses.length - 1 ) ) { | ||
− | + | var diff = obs.value - memo.avgW[ obs.mwDate.getFullYear() ][ obs.mwDate.getWeek() ].avg; | |
− | var diff = obs.value - memo.avgW[ obs. | ||
var diff = Math.round( diff*100 ); | var diff = Math.round( diff*100 ); | ||
var diffStr = diff.toString() + ' cm'; | var diffStr = diff.toString() + ' cm'; | ||
Rivi 1 433: | Rivi 1 431: | ||
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 495: | Rivi 1 494: | ||
function wait() { | function wait() { | ||
− | |||
− | |||
var w = memo.chartEl.width(); | var w = memo.chartEl.width(); | ||
var h = memo.chartEl.height(); | var h = memo.chartEl.height(); | ||
− | |||
− | |||
if ( typeof memo.oldW == 'undefined' ) { memo.oldW = 1; } | if ( typeof memo.oldW == 'undefined' ) { memo.oldW = 1; } | ||
Rivi 1 541: | Rivi 1 536: | ||
// 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' ); | ||
− | |||
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 ); | ||
Rivi 1 621: | Rivi 1 615: | ||
'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' } }, |