function drawAnnualProgressionCharts() { jQuery('.chart-progression').each(function(index, container) { var data = new google.visualization.DataTable(); data.addColumn('date', 'Year'); data.addColumn('number', 'Mark'); //data.addColumn('timeofday', markText); data.addColumn({'type': 'string', 'role': 'tooltip', 'p': { 'html': true } }); data.addColumn({'type': 'string', 'role':'style'}); disciplineGroup = jQuery(container).attr('data-discipline-group'); var dataPHP = jQuery.parseJSON(jQuery(container).attr('data-json')); rows = new Array(); jQuery.each(dataPHP, function(index, value) { dateSplitted = value.date.split('-'); pointColor = (value.windy)? '#ff9933' : '#de142c'; rows[index] = new Array(new Date(dateSplitted[0], dateSplitted[1]-1, dateSplitted[2]), parseFloat(value.result), createCustomHTMLContent(dateSplitted[2]+'.'+dateSplitted[1]+'.'+dateSplitted[0], value.location, value.resultFormatted), pointColor); }); vAxisTicks = calculateTicksFromResults(rows, disciplineGroup); vAxisDirection = getVAxisDirection(disciplineGroup); data.addRows(rows); var options = { width: jQuery('table.rankings').eq(0).width(), // Must set width because chart loaded in hidden tabs pointSize: 10, hAxis: { title: 'Year', format: 'yyyy', showTextEvery: 5 }, vAxis: { title: 'Mark', ticks: vAxisTicks, direction: vAxisDirection }, tooltip: { isHtml: true } }; // Show the chart before drawing it, otherwise width and height will be wrong var chart = new google.visualization.LineChart(container); google.visualization.events.addListener(chart, 'ready', function () { }); chart.draw(data, options); }); } function drawYearlyProgressionCharts() { jQuery('.chart-yearly-progression').each(function(index, container) { var data = new google.visualization.DataTable(); data.addColumn('date', 'Month'); data.addColumn('number', 'Mark'); data.addColumn({ 'type': 'string', 'role': 'tooltip', 'p': { 'html': true } }); data.addColumn({'type': 'string', 'role':'style'}); disciplineGroup = jQuery(container).attr('data-discipline-group'); var dataPHP = jQuery.parseJSON(jQuery(container).attr('data-json')); rows = new Array(); jQuery.each(dataPHP, function(index, value) { dateSplitted = value.date.split('-'); pointColor = (value.windy)? '#ff9933' : '#de142c'; rows[index] = new Array(new Date(dateSplitted[0], dateSplitted[1]-1, dateSplitted[2]), parseFloat(value.result), createCustomHTMLContent(dateSplitted[2]+'.'+dateSplitted[1]+'.'+dateSplitted[0], value.location, value.resultFormatted), pointColor); }); vAxisTicks = calculateTicksFromResults(rows, disciplineGroup); vAxisDirection = getVAxisDirection(disciplineGroup); data.addRows(rows); var options = { pointSize: 10, hAxis: { title: 'Month', format: 'M', showTextEvery: 2 }, vAxis: { title: 'Mark', ticks: vAxisTicks, direction: vAxisDirection }, tooltip: { isHtml: true } }; // Show the chart before drawing it, otherwise width and height will be wrong //container.style.display = 'block'; var chart = new google.visualization.LineChart(container); google.visualization.events.addListener(chart, 'ready', function () { //jQuery(container).parent().hide(); //style.display = 'none'; }); chart.draw(data, options); }); } function drawRecordEvolutionChart() { jQuery('.chart-record-evolution').each(function(index, container) { var data = new google.visualization.DataTable(); data.addColumn('date', 'Year'); data.addColumn('number', 'Mark'); //data.addColumn('timeofday', markText); data.addColumn({'type': 'string', 'role': 'tooltip', 'p': { 'html': true } }); data.addColumn({'type': 'string', 'role':'style'}); pointColor = '#de142c'; var dataPHP = jQuery.parseJSON(jQuery(container).attr('data-json')); rows = new Array(); jQuery.each(dataPHP, function(index, value) { dateSplitted = value.date.split('-'); rows[index] = new Array(new Date(dateSplitted[0], dateSplitted[1]-1, dateSplitted[2]), parseFloat(value.result), createCustomHTMLContent(dateSplitted[2]+'.'+dateSplitted[1]+'.'+dateSplitted[0], value.athlete, value.resultFormatted), pointColor); }); //vAxisTicks = calculateTicksFromResults(rows, disciplineGroup); data.addRows(rows); var options = { width: jQuery('table.rankings').eq(0).width(), // Must set width because chart loaded in hidden tabs pointSize: 10, hAxis: { title: 'Year', format: 'yyyy' }, vAxis: { title: 'Mark' }, tooltip: { isHtml: true } }; // Show the chart before drawing it, otherwise width and height will be wrong var chart = new google.visualization.LineChart(container); google.visualization.events.addListener(chart, 'ready', function () { }); chart.draw(data, options); }); } function drawHeadToHeadDonut() { nbWins = parseInt(jQuery('#head-to-head').attr('data-wins')); nbLosses = parseInt(jQuery('#head-to-head').attr('data-losses')); percentageWins = (100 / (nbWins+nbLosses)) * nbWins; var doughnutData = [ {value:percentageWins,color:"#DD142C"}, {value:100-percentageWins,color:"#c2c2c2"} ]; $("#head-to-head").doughnutit({ dnData: doughnutData, dnSize: 150, dnInnerCutout: 70, dnAnimation: true, dnAnimationSteps: 60, dnAnimationEasing: 'linear', dnStroke: false, dnShowText: true, dnFontSize: '50px', dnFontColor: "#ccc", dnText: 'VS', dnStartAngle: 0, dnCounterClockwise: false, });// End Doughnut } function loadDisciplinesPerSeason(season) { firstSelected = false; if(season == 'indoor') { jQuery.each(jQuery('#results_per_year_discipline option'), function(key, val){ if(jQuery(this).text().indexOf('indoor') >-1) { if(!firstSelected) {jQuery(this).prop('selected', true); firstSelected = true;} jQuery(this).show(); } else { jQuery(this).hide(); } }); } else { jQuery.each(jQuery('#results_per_year_discipline option'), function(key, val){ if(jQuery(this).text().indexOf('indoor') == -1) { if(!firstSelected) {jQuery(this).prop('selected', true); firstSelected = true;} jQuery(this).show(); } else { jQuery(this).hide(); } }); } // Select first one //jQuery('#results_per_year_discipline option').not(':hidden').eq(0).prop('selected', true); } /*jQuery('.block-link').click(function(e) { e.preventDefault(); // Get index in page index = jQuery('.block-link').index(this); jQuery('.chart-container').eq(index).toggle(); return false; });*/ function createCustomHTMLContent(date, location, mark) { return '
' + '' + date + '' + '' + location + '' + '' + mark + '' + '
'; } function calculateTicksFromResults(resultRows, disciplineGroup) { nbTicks = 5; results = new Array(); resultRows.forEach(function(element) { results.push(element[1]); }); minValue = Math.min.apply(null, results); maxValue = Math.max.apply(null, results); minValueTick = minValue * 0.99; // Min value - 1% maxValueTick = maxValue * 1.01; // Max value + 1% difference = maxValueTick - minValueTick; tickAmount = difference / (nbTicks-1); //values = { "1:21.0" : 81, "1:21.5" : 81.5, "1:22:0": 82, "1:22.5": 82.5, "1:23.0": 83, "1:23.5": 83.5}; jsonObj = []; //jsonObj.push({v:minValueTick, f:minValueTick.toString()}); for(var i=0;i 3600) { hour = Math.floor(vValue / 3600); //seconds = vValue / 60 ; min = Math.floor(vValue / 60 % 60).toString(); if(min.length<2) min = '0'+min; seconds = Math.floor(vValue % 60).toString(); if(seconds.length<2) seconds = '0'+seconds; return hour+':'+min+':'+seconds; } timeSplitted = vValue.toString().split('.'); millisecs = (timeSplitted.length > 1)? timeSplitted[1] : '00'; secs = parseFloat(timeSplitted[0]); minutes = Math.floor(((secs/60)%60)); seconds = (secs % 60).toString(); if(seconds.length<2) seconds = '0'+seconds; if(millisecs.length<2) millisecs = millisecs + '0'; return minutes + ':' + seconds + '.' + millisecs; } else { return vValue.toString(); } } function getVAxisDirection(disciplineGroup) { if(disciplineGroup == 'race' || disciplineGroup == 'sprint') { return -1; } else return 1; }