Ero sivun ”Widget:XJwCharts” versioiden välillä
Järvi-meriwikistä
Rivi 372: | 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() { |