// Convertir une coordonnée sur le graphique en position relative à l'affichage (ou à l'écran si ecran = true) function coordToPosX(x, ecran){ if(ecran){ return coordToPosX(x, false)+affichage.offsetLeft; } else{ return (x - affichage.xGauche) * affichage.multX; } } function coordToPosY(y, ecran){ if(ecran){ return coordToPosY(y, false)+affichage.offsetTop; } else{ return affichage.hauteur - (y - affichage.yBas) * affichage.multY; } } var affichage = { // Options id : "affichage", largeur : 640, // Set by init hauteur : 430, // Set by init couleurFond : "rgba(0,0,0,0)", // Bornes (zone d'affichage) xGauche : -5.5, // Set by init xDroite : 5.5, // Set by init yBas : -3.7, yHaut : 3.7, multX : 1, multY : 1, // Axes axes : true, couleurAxes : "rgba(0,0,0,0.5)", widthAxes : 2, // Grille grille : true, couleurGrille : "rgba(255,255,255,0.1)", widthGrille : 2, // Echelle echelle : true, couleurEchelle : "rgba(255,255,255,1)", // Précision precision : 100, precisionAmelioree : true, // false = fonction plus jolie lorsqu'on dé-zoom, true = affichage plus rapide lors du dé-zoom. // Méthode et style methode : "canvas", style : "continu", // Variable définies lors de l'initialisation canvas : null, ctx : null, object : null, offsetTop : null, // Position de l'affichage par rapport à la page offsetLeft : null, init : function(element, width, height){ this.setBornes(); // Supprimer le contenu de l'affichage if(!element){ element = document.getElementById(this.id); } if(element.hasChildNodes()){ while(element.childNodes.length >= 1 ){ element.removeChild(element.firstChild); } } // Définir la taille this.largeur = width || element.clientWidth; this.hauteur = height || element.clientHeight; // Set left and right proportionally to width, height, top and bottom var centerX = this.xGauche + (this.xDroite - this.xGauche)/2; var centerY = this.yBas + (this.yHaut - this.yBas)/2; var dx = ((this.yHaut - this.yBas) / 2) * this.largeur / this.hauteur; this.xGauche = Math.round((centerX - dx)*100)/100; this.xDroite= Math.round((centerX + dx)*100)/100; this.setBornes(); // Récupérer la position var boundingClientRect = element.getBoundingClientRect(); this.offsetTop = boundingClientRect.top; this.offsetLeft = boundingClientRect.left; // Sélectionner la méthode d'affichage if(this.methode == "svg"){ // this.object = document.createElement("embed"); // this.object.type = "image/svg+xml"; // this.object.src = "AffichageSVG.svg"; this.object = document.getElementById("embedSVG"); this.object.width = this.largeur; this.object.height = this.hauteur; this.object.style.top = this.offsetTop +1 +"px"; this.object.style.left = this.offsetLeft +1 +"px"; this.object.style.display = "block"; // element.appendChild(this.object); // affichage.ctx = svg; // affichage.dessiner(); // // Exécuter this.dessiner() maintenant ne va pas car svg n'est pas // // encore défini dans cette fonction, il faut en lancer un nouvelle... setTimeout("affichage.ctx = svg", 50); setTimeout("affichage.dessiner()", 100); } else if(this.methode == "uniboard"){ if(window.uniboard || window.sankore){ try{ initUniboard(); this.ctx = uniboard; this.dessiner(); } catch(err){ alert(err.message); } } else{ this.methode = "canvas"; this.setOptions(); this.init(); } } else{ document.getElementById("embedSVG").style.display = "none"; this.canvas = document.createElement("canvas"); this.canvas.width = this.largeur; this.canvas.height = this.hauteur; element.appendChild(this.canvas); this.ctx = this.canvas.getContext("2d"); this.dessiner(); } // Événements if(window.addEventListener){ element = document.getElementById("eventAffichage"); element.addEventListener('DOMMouseScroll', souris.wheel, false); element.onmousewheel = souris.wheel; element.oncontextmenu = ctxMenu.ouvrir; } }, calculer : function(){ this.getBornes(); this.getOptions(); if(fonction3D){ display3D.draw() } else{ this.dessiner(); } saveOptions(); }, dessiner : function(){ try{ // var ti = new Date().getTime(); var precision; if(this.precisionAmelioree){ precision = 10/this.precision; } else{ precision = Math.abs(this.xDroite - this.xGauche)/this.precision; } this.multX = this.largeur/Math.abs(this.xDroite - this.xGauche); this.multY = this.hauteur/Math.abs(this.yHaut - this.yBas); var ctx = new Object(); ctx = this.ctx; ctx.clearRect(0,0,this.largeur,this.hauteur); ctx.fillStyle = this.couleurFond; ctx.fillRect(0,0,this.largeur,this.hauteur); ctx.strokeOpacity = 1; // svg // Couleur pour l'aire sous la fonction ctx.fillStyle = "rgba(0,180,255,0.3)"; // Fonctions for(var i=0; i x : ajouter = 0.5") } this.xGauche -= ajouter; this.xDroite += ajouter; // Vertical diffBornes = Math.abs(this.yHaut - this.yBas); ajouter = Math.round(diffBornes * (facteur-1)*2)/4; if(ajouter == 0){ ajouter = 0.25; // log("affichage.zoom -> y : ajouter = 0.5") } this.yBas -= ajouter; this.yHaut += ajouter; this.dessiner(); this.setBornes(); saveOptions(); } };