flot.init.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. /******/ (function() { // webpackBootstrap
  2. var __webpack_exports__ = {};
  3. /*!*****************************************!*\
  4. !*** ./resources/js/pages/flot.init.js ***!
  5. \*****************************************/
  6. /*
  7. Template Name: Skote - Admin & Dashboard Template
  8. Author: Themesbrand
  9. Website: https://themesbrand.com/
  10. Contact: themesbrand@gmail.com
  11. File: Flot chart init Js File
  12. */
  13. // get colors array from the string
  14. function getChartColorsArray(chartId) {
  15. if (document.getElementById(chartId) !== null) {
  16. var colors = document.getElementById(chartId).getAttribute("data-colors");
  17. if (colors) {
  18. colors = JSON.parse(colors);
  19. return colors.map(function (value) {
  20. var newValue = value.replace(" ", "");
  21. if (newValue.indexOf(",") === -1) {
  22. var color = getComputedStyle(document.documentElement).getPropertyValue(newValue);
  23. if (color){
  24. color = color.replace(" ", "");
  25. return color;
  26. }
  27. else return newValue;;
  28. } else {
  29. var val = value.split(',');
  30. if (val.length == 2) {
  31. var rgbaColor = getComputedStyle(document.documentElement).getPropertyValue(val[0]);
  32. rgbaColor = "rgba(" + rgbaColor + "," + val[1] + ")";
  33. return rgbaColor;
  34. } else {
  35. return newValue;
  36. }
  37. }
  38. });
  39. }
  40. }
  41. }
  42. !function ($) {
  43. "use strict";
  44. var FlotChart = function FlotChart() {
  45. this.$body = $("body");
  46. this.$realData = [];
  47. }; //creates plot graph
  48. FlotChart.prototype.createPlotGraph = function (selector, data1, data2, data3, labels, colors, borderColor, bgColor) {
  49. //shows tooltip
  50. function showTooltip(x, y, contents) {
  51. $('<div id="tooltip" class="tooltipflot">' + contents + '</div>').css({
  52. position: 'absolute',
  53. top: y + 5,
  54. left: x + 5
  55. }).appendTo("body").fadeIn(200);
  56. }
  57. $.plot($(selector), [{
  58. data: data1,
  59. label: labels[0],
  60. color: colors[0]
  61. }, {
  62. data: data2,
  63. label: labels[1],
  64. color: colors[1]
  65. }, {
  66. data: data3,
  67. label: labels[2],
  68. color: colors[2]
  69. }], {
  70. series: {
  71. lines: {
  72. show: true,
  73. fill: true,
  74. lineWidth: 2,
  75. fillColor: {
  76. colors: [{
  77. opacity: 0.5
  78. }, {
  79. opacity: 0.5
  80. }]
  81. }
  82. },
  83. points: {
  84. show: false
  85. },
  86. shadowSize: 0
  87. },
  88. legend: {
  89. position: 'nw',
  90. backgroundColor: "transparent"
  91. },
  92. grid: {
  93. hoverable: true,
  94. clickable: true,
  95. borderColor: borderColor,
  96. borderWidth: 1,
  97. labelMargin: 10,
  98. backgroundColor: bgColor
  99. },
  100. yaxis: {
  101. min: 0,
  102. max: 300,
  103. tickColor: 'rgba(166, 176, 207, 0.1)',
  104. font: {
  105. color: '#8791af'
  106. }
  107. },
  108. xaxis: {
  109. tickColor: 'rgba(166, 176, 207, 0.1)',
  110. font: {
  111. color: '#8791af'
  112. }
  113. },
  114. tooltip: true,
  115. tooltipOpts: {
  116. content: '%s: Value of %x is %y',
  117. shifts: {
  118. x: -60,
  119. y: 25
  120. },
  121. defaultTheme: false
  122. }
  123. });
  124. }, //end plot graph
  125. //creates Pie Chart
  126. FlotChart.prototype.createPieGraph = function (selector, labels, datas, colors) {
  127. var data = [{
  128. label: labels[0],
  129. data: datas[0]
  130. }, {
  131. label: labels[1],
  132. data: datas[1]
  133. }, {
  134. label: labels[2],
  135. data: datas[2]
  136. }];
  137. var options = {
  138. series: {
  139. pie: {
  140. show: true
  141. }
  142. },
  143. legend: {
  144. show: true,
  145. backgroundColor: "transparent"
  146. },
  147. grid: {
  148. hoverable: true,
  149. clickable: true
  150. },
  151. colors: colors,
  152. tooltip: true,
  153. tooltipOpts: {
  154. content: "%s, %p.0%"
  155. }
  156. };
  157. $.plot($(selector), data, options);
  158. }, //returns some random data
  159. FlotChart.prototype.randomData = function () {
  160. var totalPoints = 300;
  161. if (this.$realData.length > 0) this.$realData = this.$realData.slice(1); // Do a random walk
  162. while (this.$realData.length < totalPoints) {
  163. var prev = this.$realData.length > 0 ? this.$realData[this.$realData.length - 1] : 50,
  164. y = prev + Math.random() * 10 - 5;
  165. if (y < 0) {
  166. y = 0;
  167. } else if (y > 100) {
  168. y = 100;
  169. }
  170. this.$realData.push(y);
  171. } // Zip the generated y values with the x values
  172. var res = [];
  173. for (var i = 0; i < this.$realData.length; ++i) {
  174. res.push([i, this.$realData[i]]);
  175. }
  176. return res;
  177. }, FlotChart.prototype.createRealTimeGraph = function (selector, data, colors) {
  178. var plot = $.plot(selector, [data], {
  179. colors: colors,
  180. series: {
  181. lines: {
  182. show: true,
  183. fill: true,
  184. lineWidth: 2,
  185. fillColor: {
  186. colors: [{
  187. opacity: 0.45
  188. }, {
  189. opacity: 0.45
  190. }]
  191. }
  192. },
  193. points: {
  194. show: false
  195. },
  196. shadowSize: 0
  197. },
  198. grid: {
  199. show: true,
  200. aboveData: false,
  201. color: '#dcdcdc',
  202. labelMargin: 15,
  203. axisMargin: 0,
  204. borderWidth: 0,
  205. borderColor: null,
  206. minBorderMargin: 5,
  207. clickable: true,
  208. hoverable: true,
  209. autoHighlight: false,
  210. mouseActiveRadius: 20
  211. },
  212. tooltip: true,
  213. //activate tooltip
  214. tooltipOpts: {
  215. content: "Value is : %y.0" + "%",
  216. shifts: {
  217. x: -30,
  218. y: -50
  219. }
  220. },
  221. yaxis: {
  222. min: 0,
  223. max: 100,
  224. tickColor: 'rgba(166, 176, 207, 0.1)',
  225. font: {
  226. color: '#8791af'
  227. }
  228. },
  229. xaxis: {
  230. show: false
  231. }
  232. });
  233. return plot;
  234. }, //creates Pie Chart
  235. FlotChart.prototype.createDonutGraph = function (selector, labels, datas, colors) {
  236. var data = [{
  237. label: labels[0],
  238. data: datas[0]
  239. }, {
  240. label: labels[1],
  241. data: datas[1]
  242. }, {
  243. label: labels[2],
  244. data: datas[2]
  245. }, {
  246. label: labels[3],
  247. data: datas[3]
  248. }, {
  249. label: labels[4],
  250. data: datas[4]
  251. }];
  252. var options = {
  253. series: {
  254. pie: {
  255. show: true,
  256. innerRadius: 0.7
  257. }
  258. },
  259. legend: {
  260. show: true,
  261. backgroundColor: "transparent",
  262. labelFormatter: function labelFormatter(label, series) {
  263. return '<div style="font-size:12px;">&nbsp;' + label + '</div>';
  264. },
  265. labelBoxBorderColor: null,
  266. margin: 50,
  267. width: 20,
  268. padding: 1
  269. },
  270. grid: {
  271. hoverable: true,
  272. clickable: true
  273. },
  274. colors: colors,
  275. tooltip: true,
  276. tooltipOpts: {
  277. content: "%s, %p.0%"
  278. }
  279. };
  280. $.plot($(selector), data, options);
  281. }, //initializing various charts and components
  282. FlotChart.prototype.init = function () {
  283. var areaChartColors = getChartColorsArray("website-stats");
  284. if (areaChartColors) {
  285. //plot graph data
  286. var desktops = [[0, 50], [1, 130], [2, 80], [3, 70], [4, 180], [5, 105], [6, 250]];
  287. var laptops = [[0, 80], [1, 100], [2, 60], [3, 120], [4, 140], [5, 100], [6, 105]];
  288. var tablets = [[0, 20], [1, 80], [2, 70], [3, 140], [4, 250], [5, 80], [6, 200]];
  289. var plabels = ["Desktops", "Laptops", "Tablets"];
  290. var pcolors = areaChartColors;
  291. var borderColor = 'rgba(166, 176, 207, 0.1)';
  292. var bgColor = 'transparent';
  293. this.createPlotGraph("#website-stats", desktops, laptops, tablets, plabels, pcolors, borderColor, bgColor);
  294. } //Pie graph data
  295. var pieChartColors = getChartColorsArray("pie-chart-container");
  296. if (pieChartColors) {
  297. var pielabels = ["Desktops", "Laptops", "Tablets"];
  298. var datas = [20, 30, 15];
  299. var colors = pieChartColors;
  300. this.createPieGraph("#pie-chart #pie-chart-container", pielabels, datas, colors);
  301. } //real time data representation
  302. var realTimeChartColors = getChartColorsArray("flotRealTime");
  303. if (realTimeChartColors) {
  304. var plot = this.createRealTimeGraph('#flotRealTime', this.randomData(), realTimeChartColors);
  305. plot.draw();
  306. var $this = this;
  307. }
  308. function updatePlot() {
  309. plot.setData([$this.randomData()]); // Since the axes don't change, we don't need to call plot.setupGrid()
  310. plot.draw();
  311. setTimeout(updatePlot, $('html').hasClass('mobile-device') ? 1000 : 1000);
  312. }
  313. updatePlot(); //Donut pie graph data
  314. var donutChartColors = getChartColorsArray("donut-chart-container");
  315. if (donutChartColors) {
  316. var donutlabels = ["Desktops", "Laptops", "Tablets"];
  317. var donutdatas = [29, 20, 18];
  318. var donutcolors = ['#f0f1f4', '#556ee6', '#34c38f'];
  319. this.createDonutGraph("#donut-chart #donut-chart-container", donutlabels, donutdatas, donutcolors);
  320. }
  321. }, //init flotchart
  322. $.FlotChart = new FlotChart(), $.FlotChart.Constructor = FlotChart;
  323. }(window.jQuery), //initializing flotchart
  324. function ($) {
  325. "use strict";
  326. $.FlotChart.init();
  327. }(window.jQuery);
  328. /******/ })()
  329. ;