timelines.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. /* ------------------------------------------------------------------------------
  2. *
  3. * # Timelines
  4. *
  5. * Demo JS code for Timeline pages set
  6. *
  7. * ---------------------------------------------------------------------------- */
  8. // Setup module
  9. // ------------------------------
  10. var Timelines = function() {
  11. //
  12. // Setup module components
  13. //
  14. // Charts
  15. var _chartsStatistics = function() {
  16. if (typeof echarts == 'undefined') {
  17. console.warn('Warning - echarts.min.js is not loaded.');
  18. return;
  19. }
  20. // Define elements
  21. var daily_statistics_element = document.getElementById('daily_statistics');
  22. var weekly_statistics_element = document.getElementById('weekly_statistics');
  23. // Daily statistics chart config
  24. if (daily_statistics_element) {
  25. // Initialize chart
  26. var daily_statistics = echarts.init(daily_statistics_element);
  27. //
  28. // Chart config
  29. //
  30. // Options
  31. daily_statistics.setOption({
  32. // Define colors
  33. color: ['#2ec7c9','#b6a2de','#5ab1ef','#ffb980','#d87a80'],
  34. // Global text styles
  35. textStyle: {
  36. fontFamily: 'Roboto, Arial, Verdana, sans-serif',
  37. fontSize: 13
  38. },
  39. // Chart animation duration
  40. animationDuration: 750,
  41. // Setup grid
  42. grid: {
  43. left: 0,
  44. right: 10,
  45. top: 35,
  46. bottom: 0,
  47. containLabel: true
  48. },
  49. // Add legend
  50. legend: {
  51. data: ['Clicks','Visits','Sales'],
  52. itemHeight: 8,
  53. itemGap: 20,
  54. textStyle: {
  55. padding: [0, 5]
  56. }
  57. },
  58. // Add tooltip
  59. tooltip: {
  60. trigger: 'axis',
  61. backgroundColor: 'rgba(0,0,0,0.75)',
  62. padding: [10, 15],
  63. textStyle: {
  64. fontSize: 13,
  65. fontFamily: 'Roboto, sans-serif'
  66. },
  67. axisPointer: {
  68. type: 'shadow',
  69. shadowStyle: {
  70. color: 'rgba(0,0,0,0.025)'
  71. }
  72. }
  73. },
  74. // Horizontal axis
  75. xAxis: [{
  76. type: 'category',
  77. data: ['00:00','02:00','04:00','06:00','08:00','10:00','12:00','14:00','16:00','18:00','20:00','22:00'],
  78. axisLabel: {
  79. color: '#333'
  80. },
  81. axisLine: {
  82. lineStyle: {
  83. color: '#999'
  84. }
  85. },
  86. splitLine: {
  87. show: true,
  88. lineStyle: {
  89. color: '#eee',
  90. type: 'dashed'
  91. }
  92. },
  93. axisTick: {
  94. show: false
  95. },
  96. }],
  97. // Vertical axis
  98. yAxis: [{
  99. type: 'value',
  100. name: 'Visits',
  101. axisLabel: {
  102. color: '#333'
  103. },
  104. axisLine: {
  105. lineStyle: {
  106. color: '#999'
  107. }
  108. },
  109. splitLine: {
  110. lineStyle: {
  111. color: ['#eee']
  112. }
  113. },
  114. splitArea: {
  115. show: true,
  116. areaStyle: {
  117. color: ['rgba(250,250,250,0.1)', 'rgba(0,0,0,0.01)']
  118. }
  119. }
  120. },
  121. {
  122. type: 'value',
  123. name: 'Clicks',
  124. axisLabel: {
  125. color: '#333'
  126. },
  127. axisLine: {
  128. lineStyle: {
  129. color: '#999'
  130. }
  131. },
  132. splitLine: {
  133. lineStyle: {
  134. color: ['#eee']
  135. }
  136. },
  137. splitArea: {
  138. show: true,
  139. areaStyle: {
  140. color: ['rgba(250,250,250,0.1)', 'rgba(0,0,0,0.01)']
  141. }
  142. }
  143. }],
  144. // Add series
  145. series: [
  146. {
  147. name: 'Clicks',
  148. type: 'bar',
  149. data: [20, 150, 270, 340, 400, 700, 1000, 750, 500, 380, 220, 120]
  150. },
  151. {
  152. name: 'Visits',
  153. type: 'bar',
  154. data: [130, 160, 330, 380, 480, 1100, 1250, 900, 680, 490, 350, 230]
  155. },
  156. {
  157. name: 'Sales',
  158. type: 'line',
  159. smooth: true,
  160. symbolSize: 7,
  161. yAxisIndex: 1,
  162. data: [10, 50, 70, 100, 110, 130, 150, 180, 160, 140, 120, 60],
  163. itemStyle: {
  164. normal: {
  165. borderWidth: 2
  166. }
  167. }
  168. }
  169. ]
  170. });
  171. }
  172. // Weekly statistics chart config
  173. if (weekly_statistics_element) {
  174. // Initialize chart
  175. var weekly_statistics = echarts.init(weekly_statistics_element);
  176. //
  177. // Chart config
  178. //
  179. // Options
  180. weekly_statistics.setOption({
  181. // Define colors
  182. color: ['#2ec7c9','#5ab1ef','#b6a2de',],
  183. // Global text styles
  184. textStyle: {
  185. fontFamily: 'Roboto, Arial, Verdana, sans-serif',
  186. fontSize: 13
  187. },
  188. // Chart animation duration
  189. animationDuration: 750,
  190. // Setup grid
  191. grid: {
  192. left: 0,
  193. right: 10,
  194. top: 35,
  195. bottom: 0,
  196. containLabel: true
  197. },
  198. // Add legend
  199. legend: {
  200. data: ['Profit', 'Expenses', 'Income'],
  201. itemHeight: 8,
  202. itemGap: 20,
  203. textStyle: {
  204. padding: [0, 5]
  205. }
  206. },
  207. // Add tooltip
  208. tooltip: {
  209. trigger: 'axis',
  210. backgroundColor: 'rgba(0,0,0,0.75)',
  211. padding: [10, 15],
  212. textStyle: {
  213. fontSize: 13,
  214. fontFamily: 'Roboto, sans-serif'
  215. },
  216. axisPointer: {
  217. type: 'shadow',
  218. shadowStyle: {
  219. color: 'rgba(0,0,0,0.025)'
  220. }
  221. }
  222. },
  223. // Horizontal axis
  224. xAxis: [{
  225. type: 'value',
  226. axisLabel: {
  227. color: '#333'
  228. },
  229. axisLine: {
  230. lineStyle: {
  231. color: '#999'
  232. }
  233. },
  234. splitLine: {
  235. show: true,
  236. lineStyle: {
  237. color: '#eee',
  238. type: 'dashed'
  239. }
  240. }
  241. }],
  242. // Vertical axis
  243. yAxis: [{
  244. type: 'category',
  245. data: ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'],
  246. axisTick: {
  247. show: false
  248. },
  249. axisLabel: {
  250. color: '#333'
  251. },
  252. axisLine: {
  253. lineStyle: {
  254. color: '#999'
  255. }
  256. },
  257. splitLine: {
  258. show: true,
  259. lineStyle: {
  260. color: ['#eee']
  261. }
  262. },
  263. splitArea: {
  264. show: true,
  265. areaStyle: {
  266. color: ['rgba(250,250,250,0.1)', 'rgba(0,0,0,0.015)']
  267. }
  268. }
  269. }],
  270. // Add series
  271. series: [
  272. {
  273. name: 'Profit',
  274. type: 'bar',
  275. barWidth: 26,
  276. itemStyle: {
  277. normal: {
  278. label: {
  279. show: true,
  280. position: 'inside',
  281. textStyle: {
  282. fontSize: 12
  283. }
  284. }
  285. }
  286. },
  287. data: [200, 170, 240, 244, 200, 220, 210]
  288. },
  289. {
  290. name: 'Income',
  291. type: 'bar',
  292. stack: 'Total',
  293. barWidth: 5,
  294. itemStyle: {
  295. normal: {
  296. label: {
  297. show: true,
  298. position: 'right',
  299. textStyle: {
  300. fontSize: 12
  301. }
  302. }
  303. }
  304. },
  305. data: [320, 302, 341, 374, 390, 450, 420]
  306. },
  307. {
  308. name: 'Expenses',
  309. type: 'bar',
  310. stack: 'Total',
  311. itemStyle: {
  312. normal: {
  313. label: {
  314. show: true,
  315. position: 'left',
  316. textStyle: {
  317. fontSize: 12
  318. }
  319. }
  320. }
  321. },
  322. data: [-120, -132, -101, -134, -190, -230, -210]
  323. }
  324. ]
  325. });
  326. }
  327. //
  328. // Resize charts
  329. //
  330. // On sidebar width change
  331. $('.sidebar-control').on('click', function() {
  332. daily_statistics.resize();
  333. weekly_statistics.resize();
  334. })
  335. // On window resizw
  336. var resizeCharts;
  337. window.onresize = function () {
  338. clearTimeout(resizeCharts);
  339. resizeCharts = setTimeout(function () {
  340. daily_statistics.resize();
  341. weekly_statistics.resize();
  342. }, 200);
  343. };
  344. };
  345. // Schedule
  346. var _componentFullCalendar = function() {
  347. if (!$().fullCalendar) {
  348. console.warn('Warning - fullcalendar.min.js is not loaded.');
  349. return;
  350. }
  351. // Add events
  352. var eventsColors = [
  353. {
  354. title: 'Day off',
  355. start: '2014-11-01',
  356. color: '#DB7272'
  357. },
  358. {
  359. title: 'University',
  360. start: '2014-11-07',
  361. end: '2014-11-10',
  362. color: '#42A5F5'
  363. },
  364. {
  365. id: 999,
  366. title: 'Shopping',
  367. start: '2014-11-09T13:00:00',
  368. color: '#8D6E63'
  369. },
  370. {
  371. id: 999,
  372. title: 'Shopping',
  373. start: '2014-11-15T16:00:00',
  374. color: '#00BCD4'
  375. },
  376. {
  377. title: 'Conference',
  378. start: '2014-11-11',
  379. end: '2014-11-13',
  380. color: '#26A69A'
  381. },
  382. {
  383. title: 'Meeting',
  384. start: '2014-11-14T08:30:00',
  385. end: '2014-11-14T12:30:00',
  386. color: '#7986CB'
  387. },
  388. {
  389. title: 'Meeting',
  390. start: '2014-11-11T09:30:00',
  391. color: '#78909C'
  392. },
  393. {
  394. title: 'Happy Hour',
  395. start: '2014-11-12T14:30:00',
  396. color: '#26A69A'
  397. },
  398. {
  399. title: 'Dinner',
  400. start: '2014-11-13T19:00:00',
  401. color: '#FF7043'
  402. },
  403. {
  404. title: 'Birthday Party',
  405. start: '2014-11-13T03:00:00',
  406. color: '#4CAF50'
  407. }
  408. ];
  409. // Container
  410. var $element = $('.my-schedule');
  411. // Initialize with options
  412. $element.fullCalendar({
  413. header: {
  414. left: 'prev,next today',
  415. center: 'title',
  416. right: 'month,agendaWeek,agendaDay'
  417. },
  418. defaultView: 'agendaWeek',
  419. defaultDate: '2014-11-15',
  420. editable: true,
  421. events: eventsColors,
  422. isRTL: $('html').attr('dir') == 'rtl' ? 'rtl' : 'ltr'
  423. });
  424. // Render if inside hidden element
  425. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  426. $element.fullCalendar('render');
  427. });
  428. };
  429. //
  430. // Return objects assigned to module
  431. //
  432. return {
  433. init: function() {
  434. _chartsStatistics();
  435. _componentFullCalendar();
  436. }
  437. }
  438. }();
  439. // Initialize module
  440. // ------------------------------
  441. document.addEventListener('DOMContentLoaded', function() {
  442. Timelines.init();
  443. });