// // Diagramme "radar" montrant les notes d'un étudiant // // ScoDoc, (c) E. Viennet 2012 // // Ce code utilise d3.js $().ready(function(){ var etudid = $("#etudid")[0].value; var formsemestre_id = $("#formsemestre_id")[0].value; get_notes_and_draw(formsemestre_id, etudid); }); var WIDTH = 460; // taille du canvas SVG var HEIGHT = WIDTH; var CX = WIDTH/2; // coordonnees centre du cercle var CY = HEIGHT/2; var RR = 0.4*WIDTH; // Rayon du cercle exterieur /* Emplacements des marques (polygones et axe gradué) */ var R_TICS = [ 8, 10, 20 ]; /* [6, 8, 10, 12, 14, 16, 18, 20]; */ var R_AXIS_TICS = [4, 6, 8, 10, 12, 14, 16, 18, 20]; var NB_TICS = R_TICS.length; function get_notes_and_draw(formsemestre_id, etudid) { console.log("get_notes(" + formsemestre_id + ", " + etudid + " )"); /* Recupère le bulletin de note et extrait tableau de notes */ /* var notes = [ { 'module' : 'E1', 'note' : 13, 'moy' : 16 }, ]; */ var query = "formsemestre_bulletinetud?formsemestre_id=" + formsemestre_id + "&etudid=" + etudid + "&format=json&version=selectedevals&force_publishing=1" $.get( query, '', function(bul){ var notes = []; bul.ue.forEach( function(ue, i, ues) { ue['module'].forEach( function(m, i) { notes.push( { 'code': m['code'], 'titre' : m['titre'], 'note':m['note']['value'], 'moy':m['note']['moy'] } ); }); } ); draw_radar(notes); }); } function draw_radar(notes) { /* Calcul coordonnées des éléments */ var nmod = notes.length; var angle = 2*Math.PI/nmod; for (var i=0; i WIDTH) { x = WIDTH - rwidth - 12; } } else { if ((x - CX) > 0) { x = x - rwidth - 5; if (x < 12) { x = 12; } } else { x = CX - rwidth/2; } } var yrect = d["y_v"]; var ytext = d["y_v"]; if ((yrect - CY) > 0) { yrect = yrect - 5 - 20; ytext = ytext - 5 - 20 + 16; } else { yrect = yrect + 5; ytext = ytext + 5 + 16; } var r = g.append("rect") .attr('class','radartip') .attr("x", x) .attr("y", yrect ); var txt = g.append("text").text("Note: " + d.note + "/20, moyenne promo: " + d.moy + "/20") .attr('class','radartip') .attr("x", x + 5) .attr("y", ytext); r.attr("width", rwidth).attr("height", 20); }) .on("mouseout", function(d){ d3.selectAll(".radartip").remove() }); /* Valeurs des notes */ g.selectAll("notes_labels") .data(notes_valid) .enter().append("text") .text(function(d) { return d["note"]; }) .attr("x", function(d) { return d["x_v"]; }) .attr("y", function(d) { if (d["y_v"] > CY) return d["y_v"] + 16; else return d["y_v"] - 8; }) .attr("class", "note_label"); /* Petits points sur les moyennes */ g.selectAll("circle2") .data(notes_valid) .enter().append("circle") .attr("cx", function(d) { return d["x_moy"]; }) .attr("cy", function(d) { return d["y_moy"]; }) .attr("r", function(x, i) { return 2; } ) .style("stroke-width", 0) .style("stroke", "black") .style("fill", "rgb(20,90,50)"); /* Valeurs sur axe */ g.selectAll("textaxis") .data( R_AXIS_TICS ) .enter().append("text") .text(String) .attr("x", CX - 10) .attr("y", function(x, i) { return CY - x*RR/20 + 6; }) .attr("class", "textaxis"); /* Noms des modules */ g.selectAll("text_modules") .data(notes) .enter().append("text") .text( function(d) { return d['code']; } ) .attr("x", function(d) { return d['x_label']; } ) .attr("y", function(d) { return d['y_label']; }) .attr("dx", 0) .attr("dy", 0) .on("mouseover", function(d) { var x = d["x_label"]; var yrect = d["y_label"]; var ytext = d["y_label"]; var titre = d['titre'].replace("'", "'").substring(0,64); var rwidth = titre.length * 9; // rough estimate of string width in pixels if ((x - CX) < 0) { x = x + 5; if (x + rwidth + 12 > WIDTH) { x = WIDTH - rwidth - 12; } } else { if ((x - CX) > 0) { x = x - rwidth - 5; if (x < 12) { x = 12; } } else { x = CX - rwidth/2; } } if ((yrect - CY) > 0) { yrect = yrect - 5 - 20; ytext = ytext - 5 - 20 + 16; } else { yrect = yrect + 5; ytext = ytext + 5 + 16; } var r = g.append("rect") .attr('class','radartip') .attr("x", x) .attr("y", yrect) .attr("height", 20) .attr("width", rwidth); var txt = g.append("text").text( titre ) .attr('class','radartip') .attr("x", x + 5) .attr("y", ytext); }) .on("mouseout", function(d){ d3.selectAll(".radartip").remove() }); }