// // Diagramme "radar" montrant les notes d'un étudiant // // ScoDoc, (c) E. Viennet 2012 // // Ce code utilise d3.js 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; 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; } var r = g.append("rect") .attr('class','radartip') .attr("x", x + 5) .attr("y", d["y_v"] + 5 ); var txt = g.append("text").text("Note: " + d.note + "/20, moyenne promo: " + d.moy + "/20") .attr('class','radartip') .attr("x", x + 5 + 5) .attr("y", d["y_v"] + 5 + 16 ); 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 poyennes */ 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); }