// csv_to_bubblechart.js // RJM Programming // July, 2018 // Help out csv_to_bubblechart.html var rawcsv=''; var csvlines=[]; var seltemplate=''; var bcfields=[]; var always1=false, always2=false; function justn(injdt,istime) { var retdis=''; var jdt=injdt.toUpperCase().replace(/\,\ /g,' ').replace(/\,/g,' ').replace(/JANUARY/g,'01').replace(/FEBRUARY/g,'02').replace(/MARCH/g,'03').replace(/APRIL/g,'04').replace(/MAY/g,'05').replace(/JUNE/g,'06').replace(/JULY/g,'07').replace(/AUGUST/g,'08').replace(/SEPTEMBER/g,'09').replace(/OCTOBER/g,'10').replace(/NOVEMBER/g,'11').replace(/DECEMBER/g,'12').replace(/JAN/g,'01').replace(/FEB/g,'02').replace(/MAR/g,'03').replace(/APR/g,'04').replace(/MAY/g,'05').replace(/JUN/g,'06').replace(/JUL/g,'07').replace(/AUG/g,'08').replace(/SEP/g,'09').replace(/OCT/g,'10').replace(/NOV/g,'11').replace(/DEC/g,'12').replace(/ST\ /g,' ').replace(/ND\ /g,' ').replace(/RD\ /g,' ').replace(/TH\ /g,' ').replace(/ST/g,'').replace(/ND/g,'').replace(/RD/g,'').replace(/TH/g,''); for (var iou=0; iou= '0' && jdt.substring(iou, eval(1 + iou)) <= '9') { retdis+=jdt.substring(iou, eval(1 + iou)); } } if (istime) { if (retdis.length == 6) { retdis=',' + retdis.substring(0,2) + ',' + retdis.substring(2,4) + ',' + retdis.substring(4,6); } else if (retdis == 4) { retdis=',' + retdis.substring(0,2) + ',' + retdis.substring(2,4) + ',00'; } else if (retdis == 2) { retdis=',' + retdis.substring(0,2) + ',00,00'; } else { retdis=''; } } else if (retdis.length == 6) { var xtoday = new Date(); var xyyyy = xtoday.getFullYear(); if (eval(retdis.substring(4,6)) > 31) { return ('' + xyyyy).substring(0,2) + retdis.substring(4,6) + retdis.substring(2,4) + retdis.substring(0,2); } else { return ('' + xyyyy).substring(0,2) + retdis.substring(0,2) + retdis.substring(2,4) + retdis.substring(4,6); } } return retdis; } function asdate(indt) { var retd=indt, iyear='-1', imonth='-1', iday='-1', tsuffix='', ispare=0; var today = new Date(); var dd = today.getDate(); var mm = today.getMonth()+1; //January is 0! var yyyy = today.getFullYear(); var hh = today.getHours(); var minm = today.getMinutes(); var ss = today.getSeconds(); if (indt.indexOf(' ') >= 6) { if (indt.split(' ')[0].indexOf('/') != -1) { if (indt.split(' ')[0].split('/').length >= 3) { iyear=indt.split(' ')[0].split('/')[0]; imonth=indt.split(' ')[0].split('/')[1]; iday=indt.split(' ')[0].split('/')[2].split('T')[0].split(' ')[0]; tsuffix=justn(indt.replace(iyear + '/' + imonth + '/' + iday,''), true); } } else if (indt.split(' ')[0].indexOf('-') != -1) { if (indt.split(' ')[0].split('-').length >= 3) { iyear=indt.split(' ')[0].split('-')[0]; imonth=indt.split(' ')[0].split('-')[1]; iday=indt.split(' ')[0].split('-')[2].split('T')[0].split(' ')[0]; tsuffix=justn(indt.replace(iyear + '-' + imonth + '-' + iday,''), true); } } else if (indt.split(' ').length >= 3) { iyear=indt.split(' ')[0]; imonth=indt.split(' ')[1]; iday=indt.split(' ')[2].split('T')[0]; tsuffix=justn(indt.replace(iyear + ' ' + imonth + ' ' + iday,''), true); } } else if (indt.indexOf(':') != -1) { if (indt.split(':')[0].indexOf('/') != -1) { if (indt.split(':')[0].split('/').length >= 3) { iyear=indt.split(':')[0].split('/')[0]; imonth=indt.split(':')[0].split('/')[1]; iday=indt.split(':')[0].split('/')[2].split('T')[0].split(' ')[0]; tsuffix=justn(indt.replace(iyear + '/' + imonth + '/' + iday,''), true); } } else if (indt.split(':')[0].indexOf('-') != -1) { if (indt.split(':')[0].split('-').length >= 3) { iyear=indt.split(':')[0].split('-')[0]; imonth=indt.split(':')[0].split('-')[1]; iday=indt.split(':')[0].split('-')[2].split('T')[0].split(' ')[0]; tsuffix=justn(indt.replace(iyear + '-' + imonth + '-' + iday,''), true); } } else if (indt.split(':').length >= 3) { iyear=indt.split(':')[0]; imonth=indt.split(':')[1]; iday=indt.split(':')[2].split('T')[0].split(' ')[0]; tsuffix=justn(indt.replace(iyear + ':' + imonth + ':' + iday,''), true); } } else if (indt.indexOf('-') != -1) { if (indt.split('-').length >= 3) { iyear=indt.split('-')[0]; imonth=indt.split('-')[1]; iday=indt.split('-')[2].split('T')[0].split(' ')[0]; tsuffix=justn(indt.replace(iyear + '-' + imonth + '-' + iday,''), true); } } else if (indt.indexOf('/') != -1) { if (indt.split('/').length >= 3) { iyear=indt.split('/')[0]; imonth=indt.split('/')[1]; iday=indt.split('/')[2].split('T')[0].split(' ')[0]; tsuffix=justn(indt.replace(iyear + '/' + imonth + '/' + iday,''), true); } } if (iyear == '-1') { iyear=justn(indt,false); if (iyear.length >= 8) { imonth=iyear.substring(4,6); iday=iyear.substring(6,8); if (iyear.length > 8) { tsuffix=',' + iyear.substring(8,10) + ',' + iyear.substring(10,12) + ',' + iyear.substring(12,14); } iyear=iyear.substring(0,4); } } // 'newDate(' + iyear + ',' + eval(-1 + imonth) + ',' + iday + ',' + hh2 + ',' + minm2 + ',' + eval(1 + ss2) + ')]'; if (iyear.length > 0 && imonth.length > 0 && iday.length > 0) { if (iyear.indexOf('-') == -1 && imonth.indexOf('-') == -1 && iday.indexOf('-') == -1) { if (iyear.substring(0,1) >= '0' && imonth.substring(0,1) >= '0' && iday.substring(0,1) >= '0') { if (iyear.substring(0,1) <= '9' && imonth.substring(0,1) <= '9' && iday.substring(0,1) <= '9') { //alert(indt + '=' + iyear + ' ... ' + imonth + ' ... ' + iday); if (eval(iyear) > 31) { if (always1 || (imonth > 12 && iday <= 12)) { ispare=imonth; imonth=iday; iday=ispare; always1=true; } if (eval(iyear) >= 1000) { retd='newDate(' + iyear + ',' + eval(-1 + eval(imonth)) + ',' + iday + tsuffix + ')'; } else if (eval(iyear) >= 100) { retd='newDate(0' + iyear + ',' + eval(-1 + eval(imonth)) + ',' + iday + tsuffix + ')'; } else { yyyy=eval(eval(yyyy - eval(yyyy % 100)) + eval(iyear)); retd='newDate(' + yyyy + ',' + eval(-1 + eval(imonth)) + ',' + iday + tsuffix + ')'; } } else if (eval(iday) > 31) { if (always2 || (imonth > 12 && iyear <= 12)) { ispare=imonth; imonth=iyear; iyear=ispare; always2=true; } if (eval(iday) >= 1000) { retd='newDate(' + iday + ',' + eval(-1 + eval(imonth)) + ',' + iyear + tsuffix + ')'; } else if (eval(iday) >= 100) { retd='newDate(0' + iday + ',' + eval(-1 + eval(imonth)) + ',' + iyear + tsuffix + ')'; } else { yyyy=eval(eval(yyyy - eval(yyyy % 100)) + eval(iday)); retd='newDate(' + yyyy + ',' + eval(-1 + eval(imonth)) + ',' + iyear + tsuffix + ')'; } } else if (eval(iyear) < 100) { if (always1 || (imonth > 12 && iday <= 12)) { ispare=imonth; imonth=iday; iday=ispare; always1=true; } yyyy=eval(eval(yyyy - eval(yyyy % 100)) + eval(iyear)); retd='newDate(' + yyyy + ',' + eval(-1 + eval(imonth)) + ',' + iday + tsuffix + ')'; } else { if (eval(iyear) >= 1000) { if (always1 || (imonth > 12 && iday <= 12)) { ispare=imonth; imonth=iday; iday=ispare; always1=true; } retd='newDate(' + iyear + ',' + eval(-1 + eval(imonth)) + ',' + iday + tsuffix + ')'; } else if (eval(iyear) >= 100) { if (always1 || (imonth > 12 && iday <= 12)) { ispare=imonth; imonth=iday; iday=ispare; always1=true; } retd='newDate(0' + iyear + ',' + eval(-1 + eval(imonth)) + ',' + iday + tsuffix + ')'; } else { if (always1 || (imonth > 12 && iday <= 12)) { ispare=imonth; imonth=iday; iday=ispare; always1=true; } yyyy=eval(eval(yyyy - eval(yyyy % 100)) + eval(iyear)); retd='newDate(' + yyyy + ',' + eval(-1 + eval(imonth)) + ',' + iday + tsuffix + ')'; } } } } } } return retd; } function getfld(ihow,cwhat) { var thisi=-1, ip=0; var thisv=''; while (thisi < Math.abs(eval('' + ihow))) { if (cwhat.substring(ip,eval(1 + eval('' + ip))) == '"') { thisv=cwhat.substring(eval(1 + eval('' + ip))).split('"')[0]; ip+=eval('' + ('"' + thisv + '",').length); } else if (cwhat.substring(ip,eval(1 + eval('' + ip))) == "'") { thisv=cwhat.substring(eval(1 + eval('' + ip))).split("'")[0]; ip+=eval('' + ('"' + thisv + '",').length); } else { thisv=cwhat.substring(ip).split(',')[0]; ip+=eval('' + (thisv + ',').length); } thisi++; } if (('' + ihow).indexOf('-') != -1) { return asdate(thisv.replace(/\'/g,'`')); } return thisv.replace(/\'/g,'`'); } function retchart() { var outd='//www.rjmprogramming.com.au/PHP/BubbleChart/bubble_chart.php'; if (document.getElementById('myform')) { outd=document.getElementById('myform').action; } if (outd.indexOf('/') == -1) { if (outd.toLowerCase().indexOf('annotatedtimeline') != -1) { return '//www.rjmprogramming.com.au/PHP/AnnotatedTimelineChart/annotatedtimeline_chart.php'; } else if (outd.toLowerCase().indexOf('timeline') != -1) { return '//www.rjmprogramming.com.au/PHP/TimelineChart/timeline_chart.php'; } else if (outd.toLowerCase().indexOf('map') != -1) { return '//www.rjmprogramming.com.au/PHP/Map/map.php'; } else if (outd.toLowerCase().indexOf('bubble') != -1) { return '//www.rjmprogramming.com.au/PHP/BubbleChart/bubble_chart.php'; } else if (outd.toLowerCase().indexOf('line') != -1) { return '//www.rjmprogramming.com.au/PHP/LineChart/line_chart.php'; } else if (outd.toLowerCase().indexOf('area') != -1) { return '//www.rjmprogramming.com.au/PHP/AreaChart/area_chart.php'; } else if (outd.toLowerCase().indexOf('column') != -1) { return '//www.rjmprogramming.com.au/PHP/ColumnChart/column_chart.php'; } else if (outd.toLowerCase().indexOf('bar') != -1) { return '//www.rjmprogramming.com.au/PHP/BarChart/bar_chart.php'; } else if (outd.toLowerCase().indexOf('pie') != -1) { return '//www.rjmprogramming.com.au/PHP/PieChart/pie_chart.php'; } else if (outd.toLowerCase().indexOf('histogram') != -1) { return '//www.rjmprogramming.com.au/PHP/HistogramChart/histogram_chart.php'; } else if (outd.toLowerCase().indexOf('geo') != -1) { return '//www.rjmprogramming.com.au/PHP/GeoChart/geo_chart.php'; } else if (outd.toLowerCase().indexOf('intensity') != -1) { return '//www.rjmprogramming.com.au/PHP/IntensityChart/intensity_chart.php'; } } return outd; } function extractcsv(how) { // &data=,%20[~ID1~,1,2,%27three%27,4] var xdata='', cmore=''; var dfs=[]; var fs=how.split(','), jgh=0; for (var ifs=0; ifs 1) { fs[ifs]=('' + fs[ifs]).substring(1); dfs.push('-'); } else { dfs.push(''); } } for (var irows=1; irows 3) { for (jgh=3; jgh 3) { for (jgh=3; jgh 3) { for (jgh=3; jgh 3) { for (jgh=3; jgh') != -1) { rawcsv=aconto.body.innerHTML.replace(ciois.split('>')[0] + '>','').replace('',''); } else { rawcsv=ciois; } if (rawcsv.indexOf('
') != -1) { csvlines=rawcsv.split('
'); } else { csvlines=rawcsv.split(String.fromCharCode(10)); } if (seltemplate == '') { if (document.getElementById('th1')) { seltemplate = document.getElementById('th1').innerHTML; } } if (csvlines.length > 0) { if (csvlines[0].indexOf('",') != -1) { bcfields=csvlines[0].split('",'); } else if (csvlines[0].indexOf(',') != -1) { bcfields=csvlines[0].split(','); } } if (document.getElementById('trhead')) { for (itd=1; itd<=bcfields.length; itd++) { trstuff+="" + bcfields[eval(-1 + itd)] + " eg. " + getfld(eval(-1 + itd),csvlines[1]) + " " + seltemplate.replace('none','block').replace('1','' + itd) + ""; } document.getElementById('trhead').innerHTML=trstuff; } } else if (iois != null && csvlines.length < 2) { var aconto = (iois.contentWindow || iois.contentDocument); if (aconto != null) { if (aconto.document) { aconto = aconto.document; } if (aconto.body != null) { if (aconto.body.innerHTML.indexOf('') != -1) { rawcsv=aconto.body.innerHTML.replace(aconto.body.innerHTML.split('>')[0] + '>','').replace('',''); } else { rawcsv=aconto.body.innerHTML; } if (rawcsv.indexOf('
') != -1) { csvlines=rawcsv.split('
'); } else { csvlines=rawcsv.split(String.fromCharCode(10)); } if (seltemplate == '') { if (document.getElementById('th1')) { seltemplate = document.getElementById('th1').innerHTML; } } if (csvlines.length > 0) { if (csvlines[0].indexOf('",') != -1) { bcfields=csvlines[0].split('",'); } else if (csvlines[0].indexOf(',') != -1) { bcfields=csvlines[0].split(','); } } if (document.getElementById('trhead')) { for (itd=1; itd<=bcfields.length; itd++) { trstuff+="" + bcfields[eval(-1 + itd)] + " eg. " + getfld(eval(-1 + itd),csvlines[1]) + " " + seltemplate.replace('none','block').replace('1','' + itd) + ""; } document.getElementById('trhead').innerHTML=trstuff; } } } } }