ecommerce_customers.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /* ------------------------------------------------------------------------------
  2. *
  3. * # ECommerce - Customers
  4. *
  5. * Demo JS code for ecommerce_customers.html page
  6. *
  7. * ---------------------------------------------------------------------------- */
  8. // Setup module
  9. // ------------------------------
  10. var EcommerceCustomers = function() {
  11. //
  12. // Setup module components
  13. //
  14. // Chart
  15. var _componentEcharts = function() {
  16. if (typeof echarts == 'undefined') {
  17. console.warn('Warning - echarts.min.js is not loaded.');
  18. return;
  19. }
  20. // Define elements
  21. var customers_chart_element = document.getElementById('customers_chart');
  22. // Weekly statistics chart config
  23. if (customers_chart_element) {
  24. // Initialize chart
  25. var customers_chart = echarts.init(customers_chart_element);
  26. //
  27. // Chart config
  28. //
  29. // Options
  30. customers_chart.setOption({
  31. // Define colors
  32. color: ['#EF5350', '#03A9F4','#4CAF50'],
  33. // Global text styles
  34. textStyle: {
  35. fontFamily: 'Roboto, Arial, Verdana, sans-serif',
  36. fontSize: 13
  37. },
  38. // Chart animation duration
  39. animationDuration: 750,
  40. // Setup grid
  41. grid: {
  42. left: 0,
  43. right: 10,
  44. top: 35,
  45. bottom: 0,
  46. containLabel: true
  47. },
  48. // Add legend
  49. legend: {
  50. data: ['New customers','Returned customers','Orders'],
  51. itemHeight: 8,
  52. itemGap: 20,
  53. textStyle: {
  54. padding: [0, 5]
  55. }
  56. },
  57. // Add tooltip
  58. tooltip: {
  59. trigger: 'axis',
  60. backgroundColor: 'rgba(0,0,0,0.75)',
  61. padding: [10, 15],
  62. textStyle: {
  63. fontSize: 13,
  64. fontFamily: 'Roboto, sans-serif'
  65. },
  66. axisPointer: {
  67. type: 'shadow',
  68. shadowStyle: {
  69. color: 'rgba(0,0,0,0.025)'
  70. }
  71. }
  72. },
  73. // Horizontal axis
  74. xAxis: [{
  75. type: 'category',
  76. data: ['January','February','March','April','May','June','July','August','September','October','November','December'],
  77. axisLabel: {
  78. color: '#333'
  79. },
  80. axisLine: {
  81. lineStyle: {
  82. color: '#999'
  83. }
  84. },
  85. splitLine: {
  86. show: true,
  87. lineStyle: {
  88. color: '#eee',
  89. type: 'dashed'
  90. }
  91. }
  92. }],
  93. // Vertical axis
  94. yAxis: [
  95. {
  96. type: 'value',
  97. name: 'Visitors',
  98. axisTick: {
  99. show: false
  100. },
  101. axisLabel: {
  102. color: '#333',
  103. formatter: '{value}k'
  104. },
  105. axisLine: {
  106. lineStyle: {
  107. color: '#999'
  108. }
  109. },
  110. splitLine: {
  111. show: true,
  112. lineStyle: {
  113. color: ['#eee']
  114. }
  115. },
  116. splitArea: {
  117. show: true,
  118. areaStyle: {
  119. color: ['rgba(250,250,250,0.1)', 'rgba(0,0,0,0.015)']
  120. }
  121. }
  122. },
  123. {
  124. type: 'value',
  125. name: 'Orders',
  126. axisTick: {
  127. show: false
  128. },
  129. axisLabel: {
  130. color: '#333',
  131. formatter: '{value}k'
  132. },
  133. axisLine: {
  134. lineStyle: {
  135. color: '#999'
  136. }
  137. },
  138. splitLine: {
  139. show: true,
  140. lineStyle: {
  141. color: ['#eee']
  142. }
  143. },
  144. splitArea: {
  145. show: true,
  146. areaStyle: {
  147. color: ['rgba(250,250,250,0.1)', 'rgba(0,0,0,0.015)']
  148. }
  149. }
  150. }
  151. ],
  152. // Add series
  153. series: [
  154. {
  155. name: 'New customers',
  156. type: 'bar',
  157. data: [20, 49, 70, 232, 256, 767, 1356, 1622, 326, 200, 64, 33]
  158. },
  159. {
  160. name: 'Returned customers',
  161. type: 'bar',
  162. data: [26, 59, 90, 264, 287, 707, 1756, 1822, 487, 188, 60, 23]
  163. },
  164. {
  165. name: 'Orders',
  166. type: 'line',
  167. smooth: true,
  168. symbolSize: 7,
  169. yAxisIndex: 1,
  170. data: [20, 22, 33, 45, 63, 102, 203, 234, 230, 165, 120, 62],
  171. itemStyle: {
  172. normal: {
  173. borderWidth: 2
  174. }
  175. }
  176. }
  177. ]
  178. });
  179. }
  180. //
  181. // Resize charts
  182. //
  183. // Resize function
  184. var triggerChartResize = function() {
  185. customers_chart_element && customers_chart.resize();
  186. };
  187. // On sidebar width change
  188. $(document).on('click', '.sidebar-control', function() {
  189. setTimeout(function () {
  190. triggerChartResize();
  191. }, 0);
  192. });
  193. // On window resize
  194. var resizeCharts;
  195. window.onresize = function () {
  196. clearTimeout(resizeCharts);
  197. resizeCharts = setTimeout(function () {
  198. triggerChartResize();
  199. }, 200);
  200. };
  201. };
  202. // Datatable
  203. var _componentDatatable = function() {
  204. if (!$().DataTable) {
  205. console.warn('Warning - datatables.min.js is not loaded.');
  206. return;
  207. }
  208. // Initialize
  209. $('.table-customers').DataTable({
  210. autoWidth: false,
  211. columnDefs: [
  212. {
  213. targets: 0,
  214. width: 400
  215. },
  216. {
  217. orderable: false,
  218. width: 16,
  219. targets: 6
  220. },
  221. {
  222. className: 'control',
  223. orderable: false,
  224. targets: -1
  225. },
  226. ],
  227. order: [[ 0, 'asc' ]],
  228. dom: '<"datatable-header datatable-header-accent"fBl><"datatable-scroll-wrap"t><"datatable-footer"ip>',
  229. language: {
  230. search: '<span>Search people:</span> _INPUT_',
  231. searchPlaceholder: 'Type to filter...',
  232. lengthMenu: '<span>Show:</span> _MENU_',
  233. paginate: { 'first': 'First', 'last': 'Last', 'next': $('html').attr('dir') == 'rtl' ? '&larr;' : '&rarr;', 'previous': $('html').attr('dir') == 'rtl' ? '&rarr;' : '&larr;' }
  234. },
  235. lengthMenu: [ 25, 50, 75, 100 ],
  236. displayLength: 50,
  237. responsive: {
  238. details: {
  239. type: 'column',
  240. target: -1
  241. }
  242. },
  243. buttons: [
  244. {
  245. extend: 'pdfHtml5',
  246. text: 'Export list <i class="icon-file-pdf ml-2"></i>',
  247. className: 'btn bg-blue',
  248. orientation: 'landscape',
  249. exportOptions: {
  250. columns: [ 0, 1, 2, 3, 4, 5 ],
  251. stripHtml: true
  252. },
  253. customize: function (doc) {
  254. doc.content[1].table.widths = Array(doc.content[1].table.body[0].length + 1).join('*').split('');
  255. }
  256. }
  257. ]
  258. });
  259. };
  260. // Select2
  261. var _componentSelect2 = function() {
  262. if (!$().select2) {
  263. console.warn('Warning - select2.min.js is not loaded.');
  264. return;
  265. }
  266. // Initialize
  267. $('.dataTables_length select').select2({
  268. minimumResultsForSearch: Infinity,
  269. dropdownAutoWidth: true,
  270. width: 'auto'
  271. });
  272. };
  273. //
  274. // Return objects assigned to module
  275. //
  276. return {
  277. init: function() {
  278. _componentEcharts();
  279. _componentDatatable();
  280. _componentSelect2();
  281. }
  282. }
  283. }();
  284. // Initialize module
  285. // ------------------------------
  286. document.addEventListener('DOMContentLoaded', function() {
  287. EcommerceCustomers.init();
  288. });