Ero sivun ”Widget:XJwCharts” versioiden välillä
Järvi-meriwikistä
(Yhtä välissä olevaa versiota samalta käyttäjältä ei näytetä) | |||
Rivi 207: | Rivi 207: | ||
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 | ||
+ | if ( i18n[memo.obscode]['type'] == 'cat' ) { | ||
+ | memo.options.vAxis.ticks = []; | ||
+ | for (var c in i18n[memo.obscode]['catNamesShort']) { | ||
+ | memo.options.vAxis.ticks.push({v: parseInt(c), f: i18n[memo.obscode]['catNamesShort'][c][memo.lang] }); | ||
+ | memo.options.vAxis.ticks.push({v: parseInt(c)+0.5, f: '' }); | ||
+ | } | ||
+ | memo.options.vAxis.ticks.sort( function(a, b) { return a.v-b.v } ); | ||
+ | memo.options.vAxis.viewWindow = { min: -0.5, max: parseInt(memo.options.vAxis.ticks[memo.options.vAxis.ticks.length-1].v)+0.5 }; | ||
+ | memo.options.vAxis.gridlines.color = '#fff'; | ||
+ | memo.options.vAxis.baselineColor = 'none'; | ||
+ | } else if ( typeof i18n[memo.obscode]['min'] != 'undefined' ) { | ||
+ | memo.options.vAxis.viewWindow = { min: i18n[memo.obscode]['min'] }; | ||
+ | } else if ( memo.obsMinValue >= 0) { | ||
+ | memo.options.vAxis.viewWindow = { min: 0 }; | ||
+ | } | ||
+ | |||
+ | if (memo.graphType == 'trend') { | ||
+ | |||
+ | //addDataToTrendChart(memo); | ||
+ | |||
+ | } else if (memo.graphType == 'season') { | ||
+ | |||
+ | //addDataToSeasonChart(memo); | ||
+ | |||
+ | } else if (memo.graphType == 'dateofyear') { | ||
+ | |||
+ | //addDataToDateOfYearChart(memo); | ||
+ | |||
+ | } | ||
data = {}; | data = {}; | ||
Rivi 337: | Rivi 372: | ||
} // ObsesReady | } // ObsesReady | ||
+ | |||
+ | function addDataToDateOfYearChart( memo ) { | ||
+ | |||
+ | // do X axis min and max for this chart type | ||
+ | memo.options.hAxis.minValue = new Date( memo.obsMinDateMs ); | ||
+ | memo.options.hAxis.minValue.setMonth(0); | ||
+ | memo.options.hAxis.minValue.setDate(1); | ||
+ | memo.options.hAxis.viewWindow.min = memo.options.hAxis.minValue; | ||
+ | |||
+ | memo.options.hAxis.maxValue = new Date( memo.obsMaxDateMs ); | ||
+ | memo.options.hAxis.maxValue.setMonth(11); | ||
+ | memo.options.hAxis.maxValue.setDate(31); | ||
+ | memo.options.hAxis.viewWindow.max = memo.options.hAxis.maxValue; | ||
+ | |||
+ | memo.options.vAxis.ticks = []; | ||
+ | |||
+ | //memo.options.hAxis.gridlines.units = { years: { format: [ 'yyyy' ] } }; | ||
+ | //memo.options.hAxis.ticks = []; | ||
+ | |||
+ | // 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.gridlines = { 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 = maxD.getFullYear(); mx = mx - 12; } | ||
+ | |||
+ | 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 | ||
+ | memo.vAxisGridlines = []; | ||
+ | if (mi > 0) { | ||
+ | memo.vAxisGridlines.push( new Date( startOfMonth.getTime() ) ); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // data columns | ||
+ | memo.data.addColumn( 'date', memo.obsMinYear + '-' + memo.obsMaxYear ); | ||
+ | memo.data.addColumn( {'type': 'string', 'role': 'style' } ); | ||
+ | memo.data.addColumn( { type: 'string', role: 'annotation' } ); | ||
+ | memo.data.addColumn( { type: 'string', role: 'tooltip', 'p': { 'html': true } } ); | ||
+ | |||
+ | // scatter series | ||
+ | memo.options.series[0] = { type: 'scatter', pointType: 'circle', pointSize: 9, color: '#3366cc' }; | ||
+ | |||
+ | // linear 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' }; | ||
+ | |||
+ | // data columns for vAxis gridlines | ||
+ | for (g=0; g < memo.vAxisGridlines.length; g++) { | ||
+ | memo.data.addColumn( 'date', 'vAxis gridline_' + g ); | ||
+ | memo.options.series[g+1] = { type: 'line', pointSize: 0, lineWidth: 1, color: '#fff', XlineDashStyle: [3, 3], visibleInLegend: false }; | ||
+ | } | ||
+ | |||
+ | // add data | ||
+ | noc = memo.data.getNumberOfColumns(); | ||
+ | |||
+ | // add obses | ||
+ | for (var o in memo.obsesA) { | ||
+ | dataRow = []; | ||
+ | |||
+ | // fill row with nulls | ||
+ | for (var i=0; i<noc; i++) { dataRow.push( null ); } | ||
+ | |||
+ | centerOfYear = new Date( memo.obsesA[o].datetime.getTime() ); | ||
+ | centerOfYear.setMonth(6); | ||
+ | centerOfYear.setDate(1); | ||
+ | |||
+ | dataRow[0] = centerOfYear; | ||
+ | dataRow[1] = memo.obsesA[o].compareDate; | ||
+ | dataRow[2] = memo.obsesA[o].style; | ||
+ | // annotation | ||
+ | dataRow[4] = memo.obsesA[o].popup; | ||
+ | |||
+ | memo.dataA.push( dataRow ); | ||
+ | } | ||
+ | |||
+ | // add gridlines | ||
+ | for (g=0; g < memo.vAxisGridlines.length; g++) { | ||
+ | |||
+ | dataRow1 = []; | ||
+ | dataRow2 = []; | ||
+ | |||
+ | // fill rows with nulls | ||
+ | for (var i=0; i<noc; i++) { dataRow1.push( null ); dataRow2.push( null ); } | ||
+ | |||
+ | dataRow1[0] = memo.options.hAxis.minValue; | ||
+ | dataRow2[0] = memo.options.hAxis.maxValue; | ||
+ | |||
+ | dataRow1[5+g] = memo.vAxisGridlines[g]; | ||
+ | dataRow2[5+g] = memo.vAxisGridlines[g]; | ||
+ | |||
+ | memo.dataA.push( dataRow1 ); | ||
+ | memo.dataA.push( dataRow2 ); | ||
+ | } | ||
+ | |||
+ | drawChart(memo); | ||
+ | |||
+ | } | ||
memo.fullscreenEl.on( 'click', function() { | memo.fullscreenEl.on( 'click', function() { |