Le repo des sources pour le site web des JM2L
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 

242 Zeilen
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.endDate - b.endDate;
  112. });
  113. timeDomainEnd = Set_of_Task[Set_of_Task.length - 1].endDate;
  114. Set_of_Task.sort(function(a, b) {
  115. return a.startDate - b.startDate;
  116. });
  117. timeDomainStart = Set_of_Task[0].startDate;
  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", "fill:url(/img/shadow.svg#BoxGradient)")
  177. .attr("class", function(d){
  178. if(taskStatus[d.status] == null)
  179. { return "bar";}
  180. return taskStatus[d.status];
  181. })
  182. .transition()
  183. .duration(750)
  184. rect.transition()
  185. .duration(750)
  186. .attr("x", function(d){
  187. return xScale(d.placeName || "unk");
  188. })
  189. .attr("y", function(d){
  190. return yScale( d.startDate )+1;
  191. })
  192. .attr("width", function(d) {
  193. return xScale.rangeBand();
  194. })
  195. .attr("height", function(d) {
  196. return (yScale( d.endDate ) - yScale( d.startDate )-2);
  197. });
  198. rect.exit()
  199. .transition()
  200. .duration(300)
  201. .style("opacity", 1e-6)
  202. .remove();
  203. svg.select(".yAxis")
  204. .attr("transform", "translate("+ margin.left +","+ margin.top +")")
  205. .transition()
  206. .call(yAxis);
  207. svg.select(".xAxis")
  208. .attr("transform", "translate("+ margin.left +","+ margin.top +")")
  209. .transition()
  210. .call(xAxis);
  211. chart.attr("transform", "translate("+ margin.left +","+ margin.top +")");
  212. }