dashboard.js 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. jQuery(document).ready(function(){
  2. "use strict";
  3. function showTooltip(x, y, contents) {
  4. jQuery('<div id="tooltip" class="tooltipflot">' + contents + '</div>').css( {
  5. position: 'absolute',
  6. display: 'none',
  7. top: y + 5,
  8. left: x + 5
  9. }).appendTo("body").fadeIn(200);
  10. }
  11. var uploads = [[0, 2], [1, 9], [2,5], [3, 13], [4, 6], [5, 13], [6, 8]];
  12. var downloads = [[0, 0], [1, 6.5], [2,4], [3, 10], [4, 2], [5, 10], [6, 4]];
  13. var plot = jQuery.plot(jQuery("#basicflot"),
  14. [{ data: uploads,
  15. label: "Uploads",
  16. color: "#1CAF9A"
  17. },
  18. { data: downloads,
  19. label: "Downloads",
  20. color: "#428BCA"
  21. }
  22. ],
  23. {
  24. series: {
  25. lines: {
  26. show: false
  27. },
  28. splines: {
  29. show: true,
  30. tension: 0.5,
  31. lineWidth: 1,
  32. fill: 0.45
  33. },
  34. shadowSize: 0
  35. },
  36. points: {
  37. show: true
  38. },
  39. legend: {
  40. position: 'nw'
  41. },
  42. grid: {
  43. hoverable: true,
  44. clickable: true,
  45. borderColor: '#ddd',
  46. borderWidth: 1,
  47. labelMargin: 10,
  48. backgroundColor: '#fff'
  49. },
  50. yaxis: {
  51. min: 0,
  52. max: 15,
  53. color: '#eee'
  54. },
  55. xaxis: {
  56. color: '#eee'
  57. }
  58. });
  59. var previousPoint = null;
  60. jQuery("#basicflot").bind("plothover", function (event, pos, item) {
  61. jQuery("#x").text(pos.x.toFixed(2));
  62. jQuery("#y").text(pos.y.toFixed(2));
  63. if(item) {
  64. if (previousPoint != item.dataIndex) {
  65. previousPoint = item.dataIndex;
  66. jQuery("#tooltip").remove();
  67. var x = item.datapoint[0].toFixed(2),
  68. y = item.datapoint[1].toFixed(2);
  69. showTooltip(item.pageX, item.pageY,
  70. item.series.label + " of " + x + " = " + y);
  71. }
  72. } else {
  73. jQuery("#tooltip").remove();
  74. previousPoint = null;
  75. }
  76. });
  77. jQuery("#basicflot").bind("plotclick", function (event, pos, item) {
  78. if (item) {
  79. plot.highlight(item.series, item.datapoint);
  80. }
  81. });
  82. // Donut Chart
  83. var m1 = new Morris.Donut({
  84. element: 'donut-chart2',
  85. data: [
  86. {label: "Chrome", value: 30},
  87. {label: "Firefox", value: 20},
  88. {label: "Opera", value: 20},
  89. {label: "Safari", value: 20},
  90. {label: "Internet Explorer", value: 10}
  91. ],
  92. colors: ['#D9534F','#1CAF9A','#428BCA','#5BC0DE','#428BCA']
  93. });
  94. var m2 = new Morris.Line({
  95. // ID of the element in which to draw the chart.
  96. element: 'line-chart',
  97. // Chart data records -- each entry in this array corresponds to a point on
  98. // the chart.
  99. data: [
  100. { y: '2006', a: 50, b: 0 },
  101. { y: '2007', a: 60, b: 25 },
  102. { y: '2008', a: 45, b: 30 },
  103. { y: '2009', a: 40, b: 20 },
  104. { y: '2010', a: 50, b: 35 },
  105. { y: '2011', a: 60, b: 50 },
  106. { y: '2012', a: 65, b: 55 }
  107. ],
  108. xkey: 'y',
  109. ykeys: ['a', 'b'],
  110. labels: ['Series A', 'Series B'],
  111. gridTextColor: 'rgba(255,255,255,0.5)',
  112. lineColors: ['#fff', '#fdd2a4'],
  113. lineWidth: '2px',
  114. hideHover: 'always',
  115. smooth: false,
  116. grid: false
  117. });
  118. // Trigger Resize in Morris Chart
  119. var delay = (function() {
  120. var timer = 0;
  121. return function(callback, ms) {
  122. clearTimeout(timer);
  123. timer = setTimeout(callback, ms);
  124. };
  125. })();
  126. jQuery(window).resize(function() {
  127. delay(function() {
  128. m1.redraw();
  129. m2.redraw();
  130. }, 200);
  131. }).trigger('resize');
  132. jQuery('#sparkline').sparkline([4,3,3,1,4,3,2,2,3,10,9,6], {
  133. type: 'bar',
  134. height:'30px',
  135. barColor: '#428BCA'
  136. });
  137. jQuery('#sparkline2').sparkline([9,8,8,6,9,10,6,5,6,3,4,2], {
  138. type: 'bar',
  139. height:'30px',
  140. barColor: '#999'
  141. });
  142. // Chosen Select
  143. jQuery("select").chosen({
  144. 'min-width': '100px',
  145. 'white-space': 'nowrap',
  146. disable_search_threshold: 10
  147. });
  148. // Do not use the code below. It's for demo purposes only
  149. var c = jQuery.cookie('change-skin');
  150. if (jQuery('.panel-stat').length > 0 && c == 'dodgerblue') {
  151. jQuery('.panel-stat').each(function(){
  152. if ($(this).hasClass('panel-danger')) {
  153. $(this).removeClass('panel-danger').addClass('panel-warning');
  154. }
  155. });
  156. }
  157. if (jQuery('#basicflot').length > 0 && c == 'greyjoy') {
  158. plot.setData([{
  159. data: uploads,
  160. color: '#dd5702',
  161. label: 'Uploads',
  162. lines: {
  163. show: true,
  164. fill: true,
  165. lineWidth: 1
  166. },
  167. splines: {
  168. show: false
  169. }
  170. },
  171. {
  172. data: downloads,
  173. color: '#cc0000',
  174. label: 'Downloads',
  175. lines: {
  176. show: true,
  177. fill: true,
  178. lineWidth: 1
  179. },
  180. splines: {
  181. show: false
  182. }
  183. }]);
  184. plot.draw();
  185. }
  186. });