Le repo des sources pour le site web des JM2L
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

244 lignes
8.0 KiB

  1. var taskStatus = {'Stand':'Stand',
  2. 'Table ronde':'Table-ronde',
  3. 'Atelier':'Atelier',
  4. 'Concert':'Concert',
  5. 'Conference':'Conference',
  6. 'Repas':'Repas'};
  7. var tickFormat = "%H:%M";
  8. var margin = {
  9. top : 15,
  10. right : 0,
  11. bottom : 0,
  12. left : 50
  13. };
  14. var height = 500;
  15. var width = 730;
  16. var Keys = Array();
  17. var Salles = Array();
  18. var Areas = Array();
  19. var Tasks = Array();
  20. d3.json("le-prog-json",
  21. function(error, json) {
  22. if (error) return console.warn(error);
  23. var Keys = Object.keys(json["all"])
  24. // Build set of data in memory
  25. for (var k = 0; k < Keys.length; k++) {
  26. Salles[Keys[k]] = Array();
  27. Areas[Keys[k]] = Array();
  28. Tasks[Keys[k]] = json["all"][Keys[k]]
  29. // Fix Json to make date objects
  30. Tasks[Keys[k]].forEach(function(d) {
  31. d.startDate = new Date(d.startDate);
  32. d.endDate = new Date(d.endDate);
  33. })
  34. // Build the list of Salles and Areas
  35. Tasks[Keys[k]].forEach(function(d) {
  36. Salles[Keys[k]].push( d.placeName );
  37. Areas[Keys[k]].push( d.status );
  38. } )
  39. Salles[Keys[k]] = d3.set(Salles[Keys[k]]).values();
  40. Areas[Keys[k]] = d3.set(Areas[Keys[k]]).values();
  41. // Create Controls to Handle user selection
  42. Areas[Keys[k]].forEach(function(TypeArea) {
  43. d3.select("#Schedule_SVG_"+Keys[k])
  44. .append("input")
  45. .attr("type", "checkbox")
  46. .attr("name", "OptTimetable-"+Keys[k])
  47. .attr("id", TypeArea+"-"+Keys[k])
  48. .attr("area", TypeArea)
  49. .style("float", "left")
  50. .style("margin-left", "5px")
  51. .property("checked",true);
  52. d3.select("#Schedule_SVG_"+Keys[k])
  53. .append("label")
  54. .attr("for", TypeArea+"-"+Keys[k])
  55. .style("float", "left")
  56. .style("margin-left", "5px")
  57. .text(TypeArea);
  58. });
  59. // Create a dedicated SVG for it
  60. svg = d3.select("#Schedule_SVG_"+Keys[k])
  61. .append("svg")
  62. .attr("id", "TimeTable-"+Keys[k])
  63. .attr("width", width + margin.right + margin.left)
  64. .attr("height", height + margin.top + margin.bottom)
  65. //.attr("viewBox", "0 0 " + width + " " + height )
  66. //.attr("preserveAspectRatio", "xMidYMid");
  67. svg.append("g")
  68. .attr("class", "xAxis axis");
  69. svg.append("g")
  70. .attr("class", "yAxis axis");
  71. var chart = svg.append("g")
  72. .attr("class", "timetable");
  73. HandleEvents(Keys[k])
  74. displayit(json["all"][Keys[k]], Salles[Keys[k]], Keys[k]);
  75. }
  76. });
  77. var keyFunction = function(d) {
  78. return d.startDate + d.placeName + d.endDate;
  79. };
  80. function HandleEvents(Ctrl) {
  81. d3.selectAll("input[name=OptTimetable-"+Ctrl+"]")
  82. .data(Areas[Ctrl])
  83. .on("change", function(TypeData) {
  84. ArrayChoice = Array()
  85. checked = d3.selectAll("input[name=OptTimetable-"+Ctrl+"]")[0]
  86. .forEach( function(v)
  87. {
  88. if (d3.select(v).node().checked)
  89. ArrayChoice.push(v.attributes['area'].value)
  90. }
  91. )
  92. area_select = Array()
  93. selection = Tasks[Ctrl].filter(function(v) {
  94. return ArrayChoice.indexOf(v.status)>=0;
  95. });
  96. if (selection.length) {
  97. selection.forEach(function(d)
  98. { area_select.push( d.placeName ); }
  99. );
  100. area_select = d3.set(area_select).values();
  101. displayit(selection, area_select, Ctrl);
  102. d3.select("#TimeTable-"+Ctrl)[0][0].style.opacity = 1;
  103. } else {
  104. d3.select("#TimeTable-"+Ctrl)[0][0].style.opacity = 0;
  105. }
  106. });
  107. }
  108. function displayit(Set_of_Task, Set_of_Area, key) {
  109. // Try to compute time range
  110. Set_of_Task.sort(function(a, b) {
  111. return a.startDate - b.startDate;
  112. });
  113. timeDomainStart = Set_of_Task[0].startDate;
  114. Set_of_Task.sort(function(a, b) {
  115. return a.endDate - b.endDate;
  116. });
  117. timeDomainEnd = Set_of_Task[Set_of_Task.length - 1].endDate;
  118. // Prepare scales
  119. xScale = d3.scale.ordinal()
  120. .domain(Set_of_Area)
  121. .rangeRoundBands([ 0, width ], .1);
  122. yScale = d3.time.scale()
  123. .domain([ timeDomainStart, timeDomainEnd ])
  124. .range([ 0, height - margin.top - margin.bottom ])
  125. .clamp(true);
  126. xAxis = d3.svg.axis()
  127. .scale(xScale)
  128. .orient("top")
  129. .tickSize(1);
  130. yAxis = d3.svg.axis()
  131. .scale(yScale)
  132. .orient("left")
  133. .tickFormat(d3.time.format(tickFormat))
  134. .tickSubdivide(true)
  135. .tickSize(8)
  136. .tickPadding(8);
  137. var svg = d3.select("#TimeTable-"+key);
  138. var chart = svg.select(".timetable")
  139. var content = chart.selectAll("foreignObject")
  140. .data(Set_of_Task, keyFunction);
  141. content.enter()
  142. .insert("foreignObject",":first-child")
  143. .append("xhtml:div")
  144. .html(function(d) {
  145. return '<div style="padding:5px;height:100%"><a href="/event/'+ d.uid +
  146. '">' + d.desc + '</a></div>'
  147. })
  148. .transition()
  149. .duration(750);
  150. content.transition()
  151. .duration(750)
  152. .attr("x", function(d){
  153. return xScale(d.placeName || "unk");
  154. })
  155. .attr("y", function(d){
  156. return yScale( d.startDate );
  157. })
  158. .attr("width", function(d) {
  159. return xScale.rangeBand();
  160. })
  161. .attr("height", function(d) {
  162. return (yScale( d.endDate ) - yScale( d.startDate ));
  163. });
  164. content.exit()
  165. .transition()
  166. .duration(300)
  167. .style("opacity", 1e-6)
  168. .remove();
  169. var rect = chart.selectAll("rect")
  170. .data(Set_of_Task, keyFunction);
  171. rect.enter()
  172. .insert("rect",":first-child")
  173. .attr("rx", 5)
  174. .attr("ry", 5)
  175. .attr("filter", "url(/img/shadow.svg#dropshadow)")
  176. .attr("style", function(d){
  177. return "fill:url(/img/shadow.svg#BoxGradient-"+ taskStatus[d.status] +")"
  178. })
  179. .attr("class", function(d){
  180. if(taskStatus[d.status] == null)
  181. { return "bar";}
  182. return taskStatus[d.status];
  183. })
  184. .transition()
  185. .duration(750)
  186. rect.transition()
  187. .duration(750)
  188. .attr("x", function(d){
  189. return xScale(d.placeName || "unk");
  190. })
  191. .attr("y", function(d){
  192. return yScale( d.startDate )+1;
  193. })
  194. .attr("width", function(d) {
  195. return xScale.rangeBand();
  196. })
  197. .attr("height", function(d) {
  198. return (yScale( d.endDate ) - yScale( d.startDate )-2);
  199. });
  200. rect.exit()
  201. .transition()
  202. .duration(300)
  203. .style("opacity", 1e-6)
  204. .remove();
  205. svg.select(".yAxis")
  206. .attr("transform", "translate("+ margin.left +","+ margin.top +")")
  207. .transition()
  208. .call(yAxis);
  209. svg.select(".xAxis")
  210. .attr("transform", "translate("+ margin.left +","+ margin.top +")")
  211. .transition()
  212. .call(xAxis);
  213. chart.attr("transform", "translate("+ margin.left +","+ margin.top +")");
  214. }