graph.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. module.exports = {
  19. drawJobTimeLine:function (map, shuffle, reduce, w, h, element, legend_id, timeline_id) {
  20. map = $.parseJSON(map);
  21. shuffle = $.parseJSON(shuffle);
  22. reduce = $.parseJSON(reduce);
  23. if (!map || !shuffle || !reduce) {
  24. console.warn('drawJobTimeLine');
  25. return;
  26. }
  27. var graph = new Rickshaw.Graph({
  28. width:w,
  29. height:h,
  30. element:document.querySelector(element),
  31. renderer:'area',
  32. stroke:true,
  33. series:[
  34. {
  35. data:map,
  36. color:'green',
  37. name:'maps'
  38. },
  39. {
  40. data:shuffle,
  41. color:'lightblue',
  42. name:'shuffles'
  43. },
  44. {
  45. data:reduce,
  46. color:'steelblue',
  47. name:'reduces'
  48. }
  49. ]
  50. }
  51. );
  52. graph.render();
  53. var legend = new Rickshaw.Graph.Legend({
  54. graph:graph,
  55. element:document.getElementById(legend_id)
  56. });
  57. var shelving = new Rickshaw.Graph.Behavior.Series.Toggle({
  58. graph:graph,
  59. legend:legend
  60. });
  61. var order = new Rickshaw.Graph.Behavior.Series.Order({
  62. graph:graph,
  63. legend:legend
  64. });
  65. var highlight = new Rickshaw.Graph.Behavior.Series.Highlight({
  66. graph:graph,
  67. legend:legend
  68. });
  69. var xAxis = new Rickshaw.Graph.Axis.Time({
  70. graph:graph
  71. });
  72. xAxis.render();
  73. var yAxis = new Rickshaw.Graph.Axis.Y({
  74. graph:graph
  75. });
  76. yAxis.render();
  77. var hoverDetail = new Rickshaw.Graph.HoverDetail({
  78. graph:graph,
  79. yFormatter:function (y) {
  80. return Math.floor(y) + " tasks"
  81. }
  82. });
  83. var annotator = new Rickshaw.Graph.Annotate({
  84. graph:graph,
  85. element:document.getElementById(timeline_id)
  86. });
  87. },
  88. drawJobTasks:function (mapNodeLocal, mapRackLocal, mapOffSwitch, reduceOffSwitch, submitTime, w, h, element, legend_id, timeline_id) {
  89. mapNodeLocal = $.parseJSON(mapNodeLocal);
  90. mapRackLocal = $.parseJSON(mapRackLocal);
  91. mapOffSwitch = $.parseJSON(mapOffSwitch);
  92. reduceOffSwitch = $.parseJSON(reduceOffSwitch);
  93. if (!mapNodeLocal || !mapRackLocal || !mapOffSwitch || !reduceOffSwitch) {
  94. console.warn('drawJobTasks');
  95. return;
  96. }
  97. var graph = new Rickshaw.Graph({
  98. width:w,
  99. height:h,
  100. element:document.querySelector(element),
  101. renderer:'scatterplot',
  102. stroke:true,
  103. series:[
  104. {
  105. data:mapNodeLocal,
  106. color:'green',
  107. name:'node_local_map'
  108. },
  109. {
  110. data:mapRackLocal,
  111. color:'lightblue',
  112. name:'rack_local_map'
  113. },
  114. {
  115. data:mapOffSwitch,
  116. color:'brown',
  117. name:'off_switch_map'
  118. },
  119. {
  120. data:reduceOffSwitch,
  121. color:'red',
  122. name:'reduce'
  123. }
  124. ]
  125. });
  126. graph.render();
  127. var legend = new Rickshaw.Graph.Legend({
  128. graph:graph,
  129. element:document.getElementById(legend_id)
  130. });
  131. var shelving = new Rickshaw.Graph.Behavior.Series.Toggle({
  132. graph:graph,
  133. legend:legend
  134. });
  135. var order = new Rickshaw.Graph.Behavior.Series.Order({
  136. graph:graph,
  137. legend:legend
  138. });
  139. var highlight = new Rickshaw.Graph.Behavior.Series.Highlight({
  140. graph:graph,
  141. legend:legend
  142. });
  143. var ticksTreatment = 'glow';
  144. var xAxis = new Rickshaw.Graph.Axis.Time({
  145. graph:graph,
  146. ticksTreatment:ticksTreatment
  147. });
  148. xAxis.render();
  149. var yAxis = new Rickshaw.Graph.Axis.Y({
  150. graph:graph,
  151. ticksTreatment:ticksTreatment
  152. });
  153. yAxis.render();
  154. var hoverDetail = new Rickshaw.Graph.HoverDetail({
  155. graph:graph,
  156. xFormatter:function (x) {
  157. return (x - submitTime) + 's'
  158. },
  159. yFormatter:function (y) {
  160. return y / 1000 + 's'
  161. },
  162. formatter:function (series, x, y, formattedX, formattedY, d) {
  163. var swatch = '<span class="detail_swatch" style="background-color: ' + series.color + '"></span>';
  164. return swatch + (d.label? d.label: d.name) +
  165. '<br>Run-time: ' + formattedY + '<br>Wait-time: ' + formattedX;
  166. }
  167. });
  168. var annotator = new Rickshaw.Graph.Annotate({
  169. graph:graph,
  170. element:document.getElementById(timeline_id)
  171. });
  172. graph.update();
  173. }
  174. }