1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
|
Series = function(sNom,sJrFonc,rDebut,rFin,nIndVeh,nIndCond)
{
this.m_sNom = sNom;
this.m_sJrFonc = sJrFonc;
this.m_rDebut = rDebut;
this.m_rFin = rFin;
this.m_nIndVeh = nIndVeh;
this.m_nIndCond = nIndCond;
}
GraphGannt = function (ChampsCanevas)
{
var m_sChampCanvas = ChampsCanevas;
var m_nIdCanvas;
var m_nContext;
//Titre
var m_sNomTitre;
var m_sFontSizeTitre;
//Series
var m_tabCouleurSeries = new Array;
var m_tabSeries = new Array;
//Fond du graph
var m_nLargeur;
var m_nHauteur;
var m_sCouleurFondGraph;
//Axe Horizontal
var m_rMinAxeHor;
var m_rMaxAxeHor;
var m_sFontSizeAxeHor;
//Axe Vertical
var m_rMinAxeVert;
var m_rMaxAxeVert;
var m_sFontSizeAxeVert;
var m_tabLabelVert = new Array();
this.InitGraph = function()
{
m_nIdCanvas = document.getElementById(m_sChampCanvas);
m_nContext = m_nIdCanvas.getContext("2d");
//add events
m_nIdCanvas.addEventListener('mousemove', this.MoveCanvas, false);
m_sCouleurFondGraph = 'black';
//Titre
m_sNomTitre = 'Graphique';
m_sFontSizeTitre = '30px Angsana New'
//Init axe horizontal
m_rMinAxeHor = 0;
m_rMaxAxeHor = 24;
m_sFontSizeAxeHor = '15px Angsana New';
//Init axe Vertical
m_rMinAxeVert = 0;
m_rMaxAxeVert = 30;
m_sFontSizeAxeVert = '20px Angsana New';
m_tabLabelVert.push(0);
m_tabLabelVert.push(1);
//Cadre du fond du graph
m_nLargeur = m_nIdCanvas.width;
m_nHauteur = m_nIdCanvas.height;
}
this.InitSeries = function()
{
m_tabCouleurSeries[0] = "Black";
m_tabCouleurSeries[1] = "Blue";
m_tabCouleurSeries[2] = "Red";
m_tabCouleurSeries[3] = "Yellow";
m_tabCouleurSeries[4] = "Green";
m_tabCouleurSeries[5] = "Pink";
var Serie0 = new Series("s1","lmmjv--",8.25,10,2,1)
var Serie1 = new Series("s2","lm-jv--",13,15.75,3,1)
m_tabSeries[0] = Serie0
m_tabSeries[1] = Serie1
}
this.DrawGraph = function()
{
m_nContext.beginPath();
m_nContext.strokeStyle = m_sCouleurFondGraph;
m_nContext.lineWidth = '1';
m_nContext.rect(0,0,m_nLargeur,m_nHauteur);
m_nContext.stroke();
//Titre
m_nContext.beginPath();
m_nContext.font = m_sFontSizeTitre;
m_nContext.fillText(m_sNomTitre,100,25);
m_nContext.stroke();
//Axe Horizontal
m_nContext.beginPath();
m_nContext.lineWidth = '2';
m_nContext.moveTo(100,m_nHauteur - 30);
m_nContext.lineTo(m_nLargeur - 20,m_nHauteur - 30);
m_nContext.stroke();
var m_nLargeurAxeHor = m_nLargeur - 120;
var m_nNbInterHor = m_rMaxAxeHor - m_rMinAxeHor;
var m_nIntervalleHor = m_nLargeurAxeHor / m_nNbInterHor;
var i = 0;
var m_rNumLabelAxeHor = m_rMinAxeHor;
var m_sAffLabelAxeHor = "";
for(i=0;i<=m_nNbInterHor;i++)
{
m_nContext.beginPath();
m_nContext.lineWidth = '2';
m_nContext.moveTo(100 + (i * m_nIntervalleHor),m_nHauteur - 30);
m_nContext.lineTo(100 + (i * m_nIntervalleHor),m_nHauteur - 25);
m_nContext.stroke();
m_nContext.beginPath();
m_nContext.lineWidth = '0.2';
m_nContext.moveTo(100 + (i * m_nIntervalleHor),40);
m_nContext.lineTo(100 + (i * m_nIntervalleHor),m_nHauteur - 25);
m_nContext.font = m_sFontSizeAxeHor;
if(m_rNumLabelAxeHor < 10)
m_sAffLabelAxeHor = '0' + m_rNumLabelAxeHor
else
m_sAffLabelAxeHor = m_rNumLabelAxeHor
m_nContext.fillText(m_sAffLabelAxeHor + ':00', 88 + (i * m_nIntervalleHor), m_nHauteur - 15);
m_nContext.stroke();
m_rNumLabelAxeHor++;
}
//Axe Vertical
m_nContext.beginPath();
m_nContext.lineWidth = '2';
m_nContext.moveTo(100,40);
m_nContext.lineTo(100,m_nHauteur - 30);
m_nContext.stroke();
var m_nHauteurAxeVert = m_nHauteur - 70;
var m_nNbInterVert = m_rMaxAxeVert - m_rMinAxeVert;
var m_nIntervalleVert = m_nHauteurAxeVert / m_nNbInterVert;
i = 0;
var m_rNumLabelAxeVert = m_rMinAxeVert;
var m_sAffLabelAxeVert = "";
for(i=0;i<=m_nNbInterVert;i++)
{
m_nContext.beginPath();
m_nContext.lineWidth = '2';
m_nContext.moveTo(100,m_nHauteur - 30 - (i * m_nIntervalleVert));
m_nContext.lineTo(105,m_nHauteur - 30 - (i * m_nIntervalleVert));
m_nContext.stroke();
m_nContext.beginPath();
m_nContext.lineWidth = '0.6';
m_nContext.moveTo(100,m_nHauteur - 30 - (i * m_nIntervalleVert));
m_nContext.lineTo(m_nLargeur - 20,m_nHauteur - 30 - (i * m_nIntervalleVert));
m_nContext.stroke();
m_nContext.font = m_sFontSizeAxeVert;
m_nContext.fillText(m_tabLabelVert[i], 10 , m_nHauteur - 30 - (i * m_nIntervalleVert));
m_nContext.stroke();
m_rNumLabelAxeVert++;
}
this.DrawSeries();
}
this.DrawSeries = function()
{
var m_nHauteurAxeVert = m_nHauteur - 70;
var m_nNbInterVert = m_rMaxAxeVert - m_rMinAxeVert;
var m_nIntervalleVert = m_nHauteurAxeVert / m_nNbInterVert;
var m_nLargeurAxeHor = m_nLargeur - 120;
var m_nNbInterHor = m_rMaxAxeHor - m_rMinAxeHor;
var m_nIntervalleHor = m_nLargeurAxeHor / m_nNbInterHor;
var i = 0;
for(i=0;i<m_tabSeries.length;i++)
{
this.DrawRect(100 + m_tabSeries[i].m_rDebut * m_nIntervalleHor,m_nHauteur-35-(m_tabSeries[i].m_nIndVeh - 1)*m_nIntervalleVert,(100 + m_tabSeries[i].m_rFin * m_nIntervalleHor) - (100 + m_tabSeries[i].m_rDebut * m_nIntervalleHor),10,m_tabSeries[i].m_nIndVeh - 1,0);
}
}
this.DrawRect = function(x,y,x1,y1,VehCond,Mode)
{
alert(x + ' ' + y +' ' + x1 +' '+y1)
m_nContext.beginPath();
m_nContext.lineWidth = '1';
if(Mode == 0)
m_nContext.strokeStyle = 'black';
else
m_nContext.strokeStyle = '#01B0F0';
m_nContext.rect(x,y,x1,y1);
m_nContext.fillStyle = m_tabCouleurSeries[VehCond];
m_nContext.fill();
m_nContext.stroke();
}
this.SetFondGraph = function(x,y,Couleur)
{
m_nLargeur = x;
m_nHauteur = y;
m_sCouleurFondGraph = Couleur;
}
//functions events
this.MoveCanvas = function(Evt)
{
var PosX = Evt.clientX - 8;
var PosY = Evt.clientY - 8;
if (PosX >= 100 && PosX <= (m_nLargeur - 20) && PosY >= 40 && PosY <= (m_nHauteur - 30))
{
var m_nHauteurAxeVert = m_nHauteur - 70;
var m_nNbInterVert = m_rMaxAxeVert - m_rMinAxeVert;
var m_nIntervalleVert = m_nHauteurAxeVert / m_nNbInterVert;
var m_nLargeurAxeHor = m_nLargeur - 120;
var m_nNbInterHor = m_rMaxAxeHor - m_rMinAxeHor;
var m_nIntervalleHor = m_nLargeurAxeHor / m_nNbInterHor;
var PosXDebTemp = 0;
var PosXFinTemp = 0;
var PosYDebTemp = 0;
var PosYFinTemp = 0;
var i = 0;
for(i=0;i<=m_tabSeries.length;i++)
{
PosXDebTemp = 100 + m_tabSeries[i].m_rDebut * m_nIntervalleHor;
PosYDebTemp = m_nHauteur-35-(m_tabSeries[i].m_nIndVeh - 1)*m_nIntervalleVert;
PosXFinTemp = 100 + m_tabSeries[i].m_rFin * m_nIntervalleHor;
PosYFinTemp = PosYDebTemp + 10;
if(PosX >= PosXDebTemp && PosX <= PosXFinTemp && PosY >= PosYDebTemp && PosY <= PosYFinTemp)
{
alert('t1');
this.test();
/*m_nContext.beginPath();
m_nContext.lineWidth = '1';
m_nContext.strokeStyle = '#01B0F0';
m_nContext.rect(PosXDebTemp,PosYDebTemp,PosXFinTemp - PosXDebTemp,PosYFinTemp - PosYDebTemp);
m_nContext.fillStyle = m_tabCouleurSeries[2];
m_nContext.fill();
m_nContext.stroke();*/
//this.DrawRect(PosXDebTemp,PosYDebTemp,PosXFinTemp - PosXDebTemp,PosYFinTemp - PosYDebTemp,m_tabSeries[i].m_nIndVeh-1,1);
}
}
}
}
this.test = function()
{
alert('t2');
}
}
function init()
{
var MonGraph = new GraphGannt('canvas');
MonGraph.InitGraph();
MonGraph.InitSeries();
MonGraph.DrawGraph();
} |
Partager