bvs/static/fonctions_analyse.js

290 lines
12 KiB
JavaScript
Raw Normal View History

2023-03-03 10:56:59 +01:00
// nuemro init de l'analyse
2023-03-31 09:31:23 +02:00
num_analyse = 1
2023-03-10 17:37:58 +01:00
idx_tache = 0 // ATTENTION ça commence à 1
2023-03-18 20:26:13 +01:00
h_bouton_analyse = 0.1*window.innerHeight
2023-03-03 10:56:59 +01:00
// Variable
function init_variable_analyse(){
2023-03-18 20:26:13 +01:00
// liste des checkbox clické pour chaque recap
2023-03-22 15:56:46 +01:00
//checkbox_clicked_courant = {}
// for (let p=0; p<nb_choix_demande; p++){
// checkbox_clicked_courant["Viewpoint_"+(p+1)] = {idx_checkbox:[], mots:[]}
// }
checkbox_clicked_courant = {idx_checkbox:[], mots:[]}
// Analayse des choix avec les checkboxs
2023-04-01 15:00:45 +02:00
keywords_init = ["Side view", "Front view", "Global view", "Eyes contact", "Pleasant", "Recognizable", "3/4 view"]
2023-03-22 16:54:11 +01:00
keywords = shuffle(keywords_init).concat(["Other:"])
2023-03-10 17:37:58 +01:00
2023-04-01 15:00:45 +02:00
l_keyword_max = 0
for (let p = 0; p<=keywords.length; p++){
if (l_keyword_max < ctx.measureText(keywords[p])) {l_keyword_max = ctx.measureText(keywords[p])}
}
l_keyword_max = l_keyword_max +10
2023-03-18 20:26:13 +01:00
y_recap = 0.2*window.innerHeight
taille_texte_explication = 0.01*window.innerWidth
x_recap_init = (window.innerWidth - nb_choix_demande*(H_3D/2))/(nb_choix_demande+1)
// checkbox
2023-04-01 15:00:45 +02:00
w_checkbox = 2*taille_texte_explication
h_checkbox = 2*taille_texte_explication
2023-03-18 20:26:13 +01:00
y_checkbox_init = y_recap + H_3D/2 + h_checkbox
2023-03-03 10:56:59 +01:00
}
function affichage_legende(pos){
2023-03-18 20:26:13 +01:00
x_image = (pos+1)*x_recap_init + pos*(H_3D/2)
2023-03-03 10:56:59 +01:00
ctx.strokeStyle = "rgb(255, 255, 255)"; ctx.fillStyle = "rgb(255, 255, 255)"
2023-03-18 20:26:13 +01:00
if (pos==0){print_text(handle_text("Best viewpoint:", x_image, y_recap-10, taille_texte_explication+"pt Courier", longueur_max_recap))}
if (pos==1){print_text(handle_text("2nd viewpoint:", x_image, y_recap-10, taille_texte_explication+"pt Courier", longueur_max_recap))}
if (pos==2){print_text(handle_text("3rd viewpoint:", x_image, y_recap-10, taille_texte_explication+"pt Courier", longueur_max_recap))}
2023-03-03 10:56:59 +01:00
}
function affichage_texte(){
// Texte
2023-03-22 15:56:46 +01:00
//draw_rectangle(0,0,canvas.width, canvas.height, "rgb(3, 26, 33)", 1) // ou + clair 4, 38, 48
2023-04-01 15:00:45 +02:00
affichage_titre("Analysis your selections:", (0.015*window.innerWidth)+"pt Courier", "#EF476F", yt = 0.05*window.innerHeight)
affichage_titre("Select the characteristics that have allowed to select these viewpoints, from the most important to the least.", (0.01*window.innerWidth)+"pt Courier", "#EF476F", yt = 0.1*window.innerHeight)
2023-03-03 10:56:59 +01:00
}
// idx_tache est la num de la tache à aller chercher dans all_ctxMins
function affichage_analyse(idx_tache){
2023-03-31 09:31:23 +02:00
canvasMins = all_canvasMins['tache_N'+list_idx_tache[idx_tache]][1]
2023-03-18 20:26:13 +01:00
for (let i=0; i<nb_choix_demande; i++){
2023-03-03 10:56:59 +01:00
affichage_legende(i)
2023-03-18 20:26:13 +01:00
x_recap = (i+1)*x_recap_init + i*(H_3D/2)
2023-03-22 16:54:11 +01:00
ctx.drawImage(canvasMins[i], x_recap, y_recap, H_3D/2, H_3D/2)
//draw_contour( x_recap, y_recap, H_3D/2, H_3D/2, "rgb(255,0,0)")
2023-03-03 10:56:59 +01:00
}
}
function progress_bar_analyse(N_analyse, N_analyse_total){
if (N_analyse<=N_analyse_total){
// background
draw_rectangle(x_progress_bar, y_progress_bar, w_progress_bar, h_progress_bar, "rgb(255,255,255)", 1)
// bar
w_bar = ((N_analyse)/N_analyse_total)*w_progress_bar
draw_rectangle(x_progress_bar, y_progress_bar, w_bar, h_progress_bar, "rgb(17, 138, 178)", 1)
// numero de tache
2023-03-10 08:57:25 +01:00
ctx.strokeStyle = "rgb(255, 255, 255)" // Pour que le contour soit rouge
ctx.fillStyle = "rgb(255, 255, 255)" // Pour que l'intérieur soit bleu
ctx.font = "18pt Courier";
ctx.fillText((N_analyse)+"/"+(N_analyse_total), x_progress_bar+w_progress_bar+10, h_progress_bar)
2023-03-03 10:56:59 +01:00
}
}
///////////////////////////////////////////////////////////////
///////////////////// Bouton
2023-03-18 20:26:13 +01:00
function affichage_bouton_valider_analyse(m){
ratio_bouton_analyse = h_bouton_analyse/boutons["valider"].height
w_bouton_analyse = ratio_bouton_analyse*boutons["valider"].width
h_bouton_analyse = h_bouton_analyse
x_bouton_analyse = (window.innerWidth/2) - w_bouton_analyse/2
y_bouton_analyse = window.innerHeight - h_bouton_analyse - 20
2023-03-03 10:56:59 +01:00
// si au moins un mot est coché
2023-03-18 20:26:13 +01:00
if (condition_valider()){
2023-03-03 10:56:59 +01:00
// affichage bouton valider
2023-03-18 20:26:13 +01:00
if (m == "en_cours")
{ctx.drawImage(boutons["valider"], x_bouton_analyse, y_bouton_analyse, w_bouton_analyse, h_bouton_analyse)}
2023-04-01 15:00:45 +02:00
else{ctx.drawImage(boutons["suivant_grand"], x_bouton_analyse, y_bouton_analyse, w_bouton_analyse, h_bouton_analyse)}
2023-03-03 10:56:59 +01:00
// survol
2023-03-18 20:26:13 +01:00
if(is_inside(xyMouseMove, x_bouton_analyse, y_bouton_analyse, w_bouton_analyse, h_bouton_analyse)){
draw_rectangle(x_bouton_analyse, y_bouton_analyse, w_bouton_analyse, h_bouton_analyse, "rgb(200, 200, 200)", 0.6)
2023-03-03 10:56:59 +01:00
}
}
}
2023-03-18 20:26:13 +01:00
function condition_valider(){
2023-03-22 15:56:46 +01:00
//S'il n'y a pas de checkbox cochée
if (checkbox_clicked_courant.idx_checkbox.length == 0){
return false
}
//il y a Other: other --> texte non vide
if (checkbox_clicked_courant.idx_checkbox.indexOf(keywords.length-1)!=-1){
if(document.getElementById('texte_area').value.length == 0){
2023-03-18 20:26:13 +01:00
return false
2023-03-22 15:56:46 +01:00
}
2023-03-18 20:26:13 +01:00
}
return true
}
2023-03-03 10:56:59 +01:00
function action_bouton_valider_analyse(){
2023-03-31 09:31:23 +02:00
interactions.push({"time": new Date().getTime(), "type": get_message("bouton_valider_analyse", [num_analyse]) })
2023-03-03 10:56:59 +01:00
// si au moins un mot est coché et qu'il reste des analyse à faire
2023-03-18 20:26:13 +01:00
if (condition_valider()){
2023-03-03 10:56:59 +01:00
// sauvegarde des checkbox clikée et les mesh
2023-03-22 15:56:46 +01:00
if (checkbox_clicked_courant.idx_checkbox.indexOf(keywords.length-1)!=-1){
texte_toto = lecture_zone_texte()
2023-03-31 09:31:23 +02:00
checkbox_clicked['Analyse_N'+(num_analyse)] = {"mesh" : choix["tache_N"+list_idx_tache[idx_tache]].mesh ,"Checkbox" : checkbox_clicked_courant, "Texte_other":texte_toto}
2023-03-22 15:56:46 +01:00
} else {
2023-03-31 09:31:23 +02:00
checkbox_clicked['Analyse_N'+(num_analyse)] = {"mesh" : choix["tache_N"+list_idx_tache[idx_tache]].mesh ,"Checkbox" : checkbox_clicked_courant}
2023-03-18 20:26:13 +01:00
}
2023-03-22 15:56:46 +01:00
//RAZ pour la prochaine analyse
checkbox_clicked_courant = {idx_checkbox:[], mots:[]}
2023-03-22 16:54:11 +01:00
keywords = shuffle(keywords_init).concat(["Other:"])
2023-03-22 15:56:46 +01:00
toto = document.getElementById('texte_area')
if (toto!= null){toto.parentElement.removeChild(toto)}
2023-03-03 10:56:59 +01:00
// analyse suivant
num_analyse = num_analyse + 1
// indice mesh da l'analyse suivante
idx_tache = idx_tache + 1
2023-03-31 09:31:23 +02:00
if (num_analyse<=nb_analyse_demande){
interactions.push({"time": new Date().getTime(), "type": get_message("fin_analyse_i", [num_analyse-1]) })
interactions.push({"time": new Date().getTime(), "type": get_message("debut_analyse_i", [num_analyse, choix["tache_N"+list_idx_tache[idx_tache]].mesh,]) })}
2023-03-03 10:56:59 +01:00
}
}
///////////////////////////////////////////////////////////////
///////////////////// Checkbox
2023-04-01 15:00:45 +02:00
function measure_largeur(debut, pos){
2023-03-22 15:56:46 +01:00
if (pos>=0){
l = 0
2023-04-01 15:00:45 +02:00
for (let p = debut; p<=debut+pos; p++){
l = l + ctx.measureText(keywords[p]).width + 0.05*window.innerWidth
2023-03-22 15:56:46 +01:00
}
return l
}
2023-04-01 15:00:45 +02:00
else{return 15}
2023-03-22 15:56:46 +01:00
}
2023-03-03 10:56:59 +01:00
2023-03-18 20:26:13 +01:00
function traitement_empty_checkbox(){
2023-03-22 15:56:46 +01:00
//for(let p=0; p<nb_choix_demande; p++){
2023-03-18 20:26:13 +01:00
for (let i = 0 ; i < keywords.length; i++){
// checkbox vide
2023-03-22 15:56:46 +01:00
//i*((window.innerWidth * 8/10)/6)
2023-04-01 15:00:45 +02:00
if(i<=5){x_checkbox = window.innerWidth*1/10 + measure_largeur(0, i-1);
y_checkbox = y_checkbox_init}
else {p = (i%5)-1;
x_checkbox = window.innerWidth*1/10 + measure_largeur(6, p-1);
y_checkbox = y_checkbox_init + 2*h_checkbox}
2023-03-18 20:26:13 +01:00
ctx.drawImage(imgs["checkbox"], x_checkbox , y_checkbox, w_checkbox, h_checkbox)
// Texte
2023-04-01 15:00:45 +02:00
print_text(handle_text(keywords[i], x_checkbox + w_checkbox + 10, y_checkbox + h_checkbox*0.75, taille_texte_explication+"pt Courier", longueur_max_error))
2023-03-18 20:26:13 +01:00
// survol
if (is_inside(xyMouseMove, x_checkbox, y_checkbox, w_checkbox, h_checkbox)){
draw_rectangle(x_checkbox, y_checkbox, w_checkbox, h_checkbox, "rgb(0, 255, 0)", alpha_survol)
}
// clicked
if (clicked && is_inside(xyMouseMove, x_checkbox, y_checkbox, w_checkbox, h_checkbox)){
2023-03-22 15:56:46 +01:00
check_ou_decheck(i)
2023-03-18 20:26:13 +01:00
}
2023-03-03 10:56:59 +01:00
}
2023-03-22 15:56:46 +01:00
2023-03-03 10:56:59 +01:00
}
2023-03-22 15:56:46 +01:00
//}
2023-03-03 10:56:59 +01:00
2023-03-22 15:56:46 +01:00
function check_ou_decheck(i_mot){
//s'il n'y a pas deja un check dessus
if (checkbox_clicked_courant.idx_checkbox.indexOf(i_mot) == -1){
checkbox_clicked_courant.idx_checkbox.push(i_mot)
checkbox_clicked_courant.mots.push(keywords[i_mot])
2023-03-29 18:10:51 +02:00
interactions.push({"time": new Date().getTime(), "type": get_message("ajout_check", [num_analyse, keywords[i_mot]])})
2023-03-22 15:56:46 +01:00
console.log("ajout "+keywords[i_mot])
// checkbox Other
if (i_mot == keywords.length-1){
zone_texte()
}
2023-03-03 10:56:59 +01:00
}
else{
2023-03-22 15:56:46 +01:00
position_i = checkbox_clicked_courant.idx_checkbox.indexOf(i_mot)
checkbox_clicked_courant.idx_checkbox.splice(position_i,1)
checkbox_clicked_courant.mots.splice(position_i,1)
console.log("retrait "+keywords[i_mot])
2023-03-29 18:10:51 +02:00
interactions.push({"time": new Date().getTime(), "type": get_message("retrait_check", [num_analyse, keywords[i_mot]])})
2023-03-22 15:56:46 +01:00
if (i_mot == keywords.length-1){
toto = document.getElementById('texte_area')
if (toto!= null){toto.parentElement.removeChild(toto)}
}
2023-03-03 10:56:59 +01:00
}
}
2023-03-22 15:56:46 +01:00
function draw_check(){
idx_check = checkbox_clicked_courant.idx_checkbox
2023-03-03 10:56:59 +01:00
// pour chacune de ces checkbox cliquée on affiche un check
for (let i = 0 ; i < idx_check.length; i++){
pos = idx_check[i]
2023-04-01 15:00:45 +02:00
if (pos > 5){p = (pos%5)-1; x_checkbox = window.innerWidth*1/10 + measure_largeur(6, p-1); y_checkbox = y_checkbox_init + 2*h_checkbox}
2023-03-22 15:56:46 +01:00
else{
2023-04-01 15:00:45 +02:00
x_checkbox = window.innerWidth*1/10 + measure_largeur(0, pos-1)
2023-03-22 15:56:46 +01:00
y_checkbox = y_checkbox_init
}
2023-04-01 15:00:45 +02:00
//ctx.drawImage(imgs["check"], x_checkbox-5 , y_checkbox-5, w_checkbox+10, h_checkbox+10)
print_text(handle_text(""+(i+1), x_checkbox + 0.2*w_checkbox, y_checkbox + h_checkbox*0.75, taille_texte_explication+"pt Courier", longueur_max_error, '#EF476F'))
2023-03-03 10:56:59 +01:00
}
}
2023-03-22 15:56:46 +01:00
function zone_texte(){
inscription_finie = false
h_text_zone = 0.15*window.innerHeight
nb_caract_min = 1
nb_caract_max = 250
2023-04-01 15:00:45 +02:00
x_texte_zone = (window.innerWidth/3)
y_texte_zone = y_checkbox_init + 2*h_checkbox
2023-03-22 15:56:46 +01:00
ecart_texte_zone = 0.2*window.innerHeight
// Zone de texte : Name
input2 = document.createElement('textarea');
input2.type = 'text';
input2.id = 'texte_area';
input2.maxLength = nb_caract_max
input2.cols = 0.02*window.innerWidth
// style
input2.style.position = 'fixed';
input2.style.left = x_texte_zone+'px';
input2.style.top = y_texte_zone+'px';//ecart_texte_zone+y_texte_zone+'px';
input2.style.textAlign = 'left'
input2.style.height = h_text_zone
input2.style.display = true
input2.style.font = taille_texte_inscription+"pt Courier"
document.body.appendChild(input2);
//input2.focus();
}
function lecture_zone_texte(){
toto = document.getElementById('texte_area')
if(toto.value != null){
return toto.value
}
}
2023-03-03 10:56:59 +01:00
///////////////////////////////////////////////////////////////
///////////////////// MAIN
2023-03-22 15:56:46 +01:00
function traitement_analyse(){
2023-03-31 09:31:23 +02:00
if ((num_analyse <= nb_analyse_demande)){
2023-03-03 10:56:59 +01:00
// affiche les textes de la page sauf les ceheckbox
affichage_texte()
// afficher les checkbox et gerer les click ou declick
2023-03-18 20:26:13 +01:00
traitement_empty_checkbox()
2023-03-03 10:56:59 +01:00
// affiche les check vert en fonction de ce qu'il y a dans checkbox_clicked_courant
2023-03-18 20:26:13 +01:00
for (let p =0; p<nb_choix_demande;p++){draw_check(p)}
2023-03-03 10:56:59 +01:00
// affiche les nb_demande_choix images recap
affichage_analyse(idx_tache)
// affiche progress bar
2023-03-22 15:56:46 +01:00
//progress_bar_analyse(num_analyse, nb_analyse_demande)
2023-03-31 09:31:23 +02:00
if (num_analyse <= nb_analyse_demande-1){
2023-03-18 20:26:13 +01:00
// bouton valider
affichage_bouton_valider_analyse("en_cours")}
else{
affichage_bouton_valider_analyse("fin")
}
2023-03-03 10:56:59 +01:00
// action si bouton valider
2023-03-18 20:26:13 +01:00
if (clicked && is_inside(xyMouseMove, x_bouton_analyse, y_bouton_analyse, w_bouton_analyse, h_bouton_analyse)){
2023-03-03 10:56:59 +01:00
action_bouton_valider_analyse()
}
}
else{
page_analyse = false
2023-03-31 09:31:23 +02:00
interactions.push({"time": new Date().getTime(), "type": get_message("fin_analyse_i", [num_analyse-1]) })
2023-03-29 18:10:51 +02:00
interactions.push({"time": new Date().getTime(), "type": get_message("fin_etude", [])})
2023-03-03 10:56:59 +01:00
}
}