// # (gH) -_- paysUE_tableau.js ; TimeStamp (unix) : 29 Décembre 2015 vers 22:45
function paysUE( htmlFile ) {
// initialisation des variables
// var url = "http://www.touteleurope.eu/les-pays-de-l-union-europeenne.html" ;
var url = "paysUE.html" ;
var xhr ;
var allHtml ;
var nbc = -1 ;
var nbPays = -1 ;
var tabNoms = [] ;
var tabSurf = [] ;
var tabPops = [] ;
var nomsCol = [] ;
var aligne = [] ;
var tabCols = ["Pays","Population","Superficie"] ;
var nbCol = tabCols.length ;
// création du titre de niveau 2
d3.select("#hautDePage")
.append("h2").text("Tableau des populations et des superficies")
var posWtmp = htmlFile.indexOf("wtmp") ;
var htmlFile = "../" + htmlFile.substring(posWtmp) ;
allHtml = file_get_contents(htmlFile) ;
var regExp = /eltContenu(.*?)p class/g ;
var tabRes = allHtml.match(regExp) ;
var nbPays = tabRes.length ;
for (numPays=0;numPays<nbPays;numPays=numPays+1) {
pays = tabRes[numPays] ;
regExp = /id="(.*?)"/ ;
resNom = pays.match(regExp) ;
tabNoms[numPays] = resNom[1] ;
resPop = pays.match(/Population : <\/strong><\/span><span>(.*?)million/) ;
popPays = resPop[1].replace(",","") ;
tabPops[numPays] = popPays ;
resSurf = pays.match(/Superficie : <\/strong><\/span><span>(.*?)[Kk]m/) ;
surfPays = resSurf[1].replace(" ","") ;
tabSurf[numPays] = surfPays ;
} // # fin pour nump
// un peu de décalage ne fait pas de mal
d3.select("#hautDePage")
.append("blockquote")
.attr("id","avantTabUE")
// création du tableau...
d3.select("#avantTabUE")
.append("table")
.attr("id","tabUE")
.attr("border",1)
.attr("cellpadding",15)
.style("border-collapse","collapse")
// de la partie entete
d3.select("#tabUE")
.append("thead")
.append("tr")
.attr("id","headerUE")
// et du corps du tableau
d3.select("#tabUE")
.append("tbody")
.attr("id","bodyTabUE")
// remplissage des entetes de colonne
d3.select("#headerUE")
.append("th")
.text("Numéro") ;
for (numCol=0;numCol<nbCol;numCol=numCol+1) {
d3.select("#headerUE")
.append("th")
.text(tabCols[numCol]) ;
if (numCol<=0) {
aligne[numCol] = "left" ;
} else {
aligne[numCol] = "right" ;
} ; // fin si
} // # fin pour numCol
// remplissage du tableau
for (numPays=0;numPays<nbPays;numPays=numPays+1) {
d3.select("#bodyTabUE")
.append("tr")
.attr("id","ligneInd"+numPays)
.append("td")
.text(numPays+1)
.style("text-align","right") ;
for (numCol=0;numCol<nbCol;numCol=numCol+1) {
if (numCol==0) { info = tabNoms[numPays] ; } ;
if (numCol==1) { info = tabPops[numPays] ; } ;
if (numCol==2) { info = tabSurf[numPays] ; } ;
d3.select("#ligneInd"+numPays)
.append("td")
.text(info)
.style("text-align",aligne[numCol]) ;
} ; // fin pour numCol
} ; // fin pour numPays
// pour finir, on rend les colonnes triables
d3.select("#tabUE").attr("class","sortable") ;
} // fin de fonction paysUE
|