widget-inline-charts.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. //[widget inline charts Javascript]
  2. //Project: Riday Admin - Responsive Admin Template
  3. //Primary use: Used only for the widget inline charts
  4. $(function () {
  5. /* jQueryKnob */
  6. $(".knob").knob({
  7. /*change : function (value) {
  8. //console.log("change : " + value);
  9. },
  10. release : function (value) {
  11. console.log("release : " + value);
  12. },
  13. cancel : function () {
  14. console.log("cancel : " + this.value);
  15. },*/
  16. draw: function () {
  17. // "tron" case
  18. if (this.$.data('skin') == 'tron') {
  19. var a = this.angle(this.cv) // Angle
  20. , sa = this.startAngle // Previous start angle
  21. , sat = this.startAngle // Start angle
  22. , ea // Previous end angle
  23. , eat = sat + a // End angle
  24. , r = true;
  25. this.g.lineWidth = this.lineWidth;
  26. this.o.cursor
  27. && (sat = eat - 0.3)
  28. && (eat = eat + 0.3);
  29. if (this.o.displayPrevious) {
  30. ea = this.startAngle + this.angle(this.value);
  31. this.o.cursor
  32. && (sa = ea - 0.3)
  33. && (ea = ea + 0.3);
  34. this.g.beginPath();
  35. this.g.strokeStyle = this.previousColor;
  36. this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, sa, ea, false);
  37. this.g.stroke();
  38. }
  39. this.g.beginPath();
  40. this.g.strokeStyle = r ? this.o.fgColor : this.fgColor;
  41. this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, sat, eat, false);
  42. this.g.stroke();
  43. this.g.lineWidth = 2;
  44. this.g.beginPath();
  45. this.g.strokeStyle = this.o.fgColor;
  46. this.g.arc(this.xy, this.xy, this.radius - this.lineWidth + 1 + this.lineWidth * 2 / 3, 0, 2 * Math.PI, false);
  47. this.g.stroke();
  48. return false;
  49. }
  50. }
  51. });
  52. /* END JQUERY KNOB */
  53. //SPARKLINE pia CHARTS
  54. $("#sparkline5").sparkline([18, 22, 38, 20], {
  55. type: 'pie',
  56. height: '100',
  57. sliceColors: ['#3aa0dc', '#06d79c', '#745af2', '#ff4c52'],
  58. highlightLighten: 1.1
  59. });
  60. //INITIALIZE SPARKLINE CHARTS
  61. $(".sparkline").each(function () {
  62. var $this = $(this);
  63. $this.sparkline('html', $this.data());
  64. });
  65. /* SPARKLINE DOCUMENTATION EXAMPLES http://omnipotent.net/jquery.sparkline/#s-about */
  66. drawDocSparklines();
  67. drawMouseSpeedDemo();
  68. });
  69. function drawDocSparklines() {
  70. // Bar + line composite charts
  71. $('#compositebar').sparkline('html', {type: 'bar', barColor: '#aaf'});
  72. $('#compositebar').sparkline([7,3,10,5,4,8,6,4,2,4,5,3,4,5],
  73. {composite: true, fillColor: false, lineColor: '#ff4c52'});
  74. // Line charts taking their values from the tag
  75. $('.sparkline-1').sparkline();
  76. // Larger line charts for the docs
  77. $('.largeline').sparkline('html',
  78. {type: 'line', height: '2.5em', width: '4em'});
  79. // Customized line chart
  80. $('#linecustom').sparkline('html',
  81. {
  82. height: '1.5em', width: '8em', lineColor: '#ff4c52', fillColor: '#faa700',
  83. minSpotColor: false, maxSpotColor: false, spotColor: '#745af2', spotRadius: 3
  84. });
  85. // Bar charts using inline values
  86. $('.sparkbar').sparkline('html', {type: 'bar'});
  87. $('.barformat').sparkline([1, 3, 5, 3, 8], {
  88. type: 'bar',
  89. tooltipFormat: '{{value:levels}} - {{value}}',
  90. tooltipValueLookups: {
  91. levels: $.range_map({':2': 'Low', '3:6': 'Medium', '7:': 'High'})
  92. }
  93. });
  94. // Tri-state charts using inline values
  95. $('.sparktristate').sparkline('html', {type: 'tristate'});
  96. $('.sparktristatecols').sparkline('html',
  97. {type: 'tristate', colorMap: {'-2': '#3aa0dc', '2': '#3aa0dc'}});
  98. // Composite line charts, the second using values supplied via javascript
  99. $('#compositeline').sparkline('html', {fillColor: false, changeRangeMin: 0, chartRangeMax: 10});
  100. $('#compositeline').sparkline([7,3,10,5,4,8,6,4,2,4,5,3,4,5],
  101. {composite: true, fillColor: false, lineColor: '#ff4c52', changeRangeMin: 0, chartRangeMax: 10});
  102. // Line charts with normal range marker
  103. $('#normalline').sparkline('html',
  104. {fillColor: false, normalRangeMin: -1, normalRangeMax: 8});
  105. $('#normalExample').sparkline('html',
  106. {fillColor: false, normalRangeMin: 80, normalRangeMax: 95, normalRangeColor: '#4f4'});
  107. // Discrete charts
  108. $('.discrete1').sparkline('html',
  109. {type: 'discrete', lineColor: '#3aa0dc', xwidth: 18});
  110. $('#discrete2').sparkline('html',
  111. {type: 'discrete', lineColor: '#3aa0dc', thresholdColor: '#ff4c52', thresholdValue: 4});
  112. // Bullet charts
  113. $('.sparkbullet').sparkline('html', {type: 'bullet'});
  114. // Pie charts
  115. $('.sparkpie').sparkline('html', {type: 'pie', height: '1.0em'});
  116. // Box plots
  117. $('.sparkboxplot').sparkline('html', {type: 'box'});
  118. $('.sparkboxplotraw').sparkline([1, 3, 5, 8, 10, 15, 18],
  119. {type: 'box', raw: true, showOutliers: true, target: 6});
  120. // Box plot with specific field order
  121. $('.boxfieldorder').sparkline('html', {
  122. type: 'box',
  123. tooltipFormatFieldlist: ['med', 'lq', 'uq'],
  124. tooltipFormatFieldlistKey: 'field'
  125. });
  126. // click event demo sparkline
  127. $('.clickdemo').sparkline();
  128. $('.clickdemo').bind('sparklineClick', function (ev) {
  129. var sparkline = ev.sparklines[0],
  130. region = sparkline.getCurrentRegionFields();
  131. value = region.y;
  132. alert("Clicked on x=" + region.x + " y=" + region.y);
  133. });
  134. // mouseover event demo sparkline
  135. $('.mouseoverdemo').sparkline();
  136. $('.mouseoverdemo').bind('sparklineRegionChange', function (ev) {
  137. var sparkline = ev.sparklines[0],
  138. region = sparkline.getCurrentRegionFields();
  139. value = region.y;
  140. $('.mouseoverregion').text("x=" + region.x + " y=" + region.y);
  141. }).bind('mouseleave', function () {
  142. $('.mouseoverregion').text('');
  143. });
  144. }
  145. /**
  146. ** Draw the little mouse speed animated graph
  147. ** This just attaches a handler to the mousemove event to see
  148. ** (roughly) how far the mouse has moved
  149. ** and then updates the display a couple of times a second via
  150. ** setTimeout()
  151. **/
  152. function drawMouseSpeedDemo() {
  153. var mrefreshinterval = 500; // update display every 500ms
  154. var lastmousex = -1;
  155. var lastmousey = -1;
  156. var lastmousetime;
  157. var mousetravel = 0;
  158. var mpoints = [];
  159. var mpoints_max = 30;
  160. $('html').mousemove(function (e) {
  161. var mousex = e.pageX;
  162. var mousey = e.pageY;
  163. if (lastmousex > -1) {
  164. mousetravel += Math.max(Math.abs(mousex - lastmousex), Math.abs(mousey - lastmousey));
  165. }
  166. lastmousex = mousex;
  167. lastmousey = mousey;
  168. });
  169. var mdraw = function () {
  170. var md = new Date();
  171. var timenow = md.getTime();
  172. if (lastmousetime && lastmousetime != timenow) {
  173. var pps = Math.round(mousetravel / (timenow - lastmousetime) * 1000);
  174. mpoints.push(pps);
  175. if (mpoints.length > mpoints_max)
  176. mpoints.splice(0, 1);
  177. mousetravel = 0;
  178. $('#mousespeed').sparkline(mpoints, {width: mpoints.length * 2, tooltipSuffix: ' pixels per second'});
  179. }
  180. lastmousetime = timenow;
  181. setTimeout(mdraw, mrefreshinterval);
  182. };
  183. // We could use setInterval instead, but I prefer to do it this way
  184. setTimeout(mdraw, mrefreshinterval);
  185. }