Bez popisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

argon.js 21KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  1. /*!
  2. =========================================================
  3. * Argon Dashboard - v1.0.0
  4. =========================================================
  5. * Product Page: https://www.creative-tim.com/product/argon-dashboard
  6. * Copyright 2018 Creative Tim (https://www.creative-tim.com) & UPDIVISION (https://www.updivision.com)
  7. * Licensed under MIT (https://github.com/creativetimofficial/argon-dashboard/blob/master/LICENSE.md)
  8. * Coded by www.creative-tim.com & www.updivision.com
  9. =========================================================
  10. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  11. */
  12. //
  13. // Bootstrap Datepicker
  14. //
  15. 'use strict';
  16. var Datepicker = (function() {
  17. // Variables
  18. var $datepicker = $('.datepicker');
  19. // Methods
  20. function init($this) {
  21. var options = {
  22. disableTouchKeyboard: true,
  23. autoclose: false
  24. };
  25. $this.datepicker(options);
  26. }
  27. // Events
  28. if ($datepicker.length) {
  29. $datepicker.each(function() {
  30. init($(this));
  31. });
  32. }
  33. })();
  34. //
  35. // Icon code copy/paste
  36. //
  37. 'use strict';
  38. var CopyIcon = (function() {
  39. // Variables
  40. var $element = '.btn-icon-clipboard',
  41. $btn = $($element);
  42. // Methods
  43. function init($this) {
  44. $this.tooltip().on('mouseleave', function() {
  45. // Explicitly hide tooltip, since after clicking it remains
  46. // focused (as it's a button), so tooltip would otherwise
  47. // remain visible until focus is moved away
  48. $this.tooltip('hide');
  49. });
  50. var clipboard = new ClipboardJS($element);
  51. clipboard.on('success', function(e) {
  52. $(e.trigger)
  53. .attr('title', 'Copied!')
  54. .tooltip('_fixTitle')
  55. .tooltip('show')
  56. .attr('title', 'Copy to clipboard')
  57. .tooltip('_fixTitle')
  58. e.clearSelection()
  59. });
  60. }
  61. // Events
  62. if ($btn.length) {
  63. init($btn);
  64. }
  65. })();
  66. //
  67. // Form control
  68. //
  69. 'use strict';
  70. var FormControl = (function() {
  71. // Variables
  72. var $input = $('.form-control');
  73. // Methods
  74. function init($this) {
  75. $this.on('focus blur', function(e) {
  76. $(this).parents('.form-group').toggleClass('focused', (e.type === 'focus' || this.value.length > 0));
  77. }).trigger('blur');
  78. }
  79. // Events
  80. if ($input.length) {
  81. init($input);
  82. }
  83. })();
  84. //
  85. // Google maps
  86. //
  87. var $map = $('#map-canvas'),
  88. map,
  89. lat,
  90. lng,
  91. color = "#5e72e4";
  92. function initMap() {
  93. map = document.getElementById('map-canvas');
  94. lat = map.getAttribute('data-lat');
  95. lng = map.getAttribute('data-lng');
  96. var myLatlng = new google.maps.LatLng(lat, lng);
  97. var mapOptions = {
  98. zoom: 12,
  99. scrollwheel: false,
  100. center: myLatlng,
  101. mapTypeId: google.maps.MapTypeId.ROADMAP,
  102. styles: [{"featureType":"administrative","elementType":"labels.text.fill","stylers":[{"color":"#444444"}]},{"featureType":"landscape","elementType":"all","stylers":[{"color":"#f2f2f2"}]},{"featureType":"poi","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"road","elementType":"all","stylers":[{"saturation":-100},{"lightness":45}]},{"featureType":"road.highway","elementType":"all","stylers":[{"visibility":"simplified"}]},{"featureType":"road.arterial","elementType":"labels.icon","stylers":[{"visibility":"off"}]},{"featureType":"transit","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"water","elementType":"all","stylers":[{"color":color},{"visibility":"on"}]}]
  103. }
  104. map = new google.maps.Map(map, mapOptions);
  105. var marker = new google.maps.Marker({
  106. position: myLatlng,
  107. map: map,
  108. animation: google.maps.Animation.DROP,
  109. title: 'Hello World!'
  110. });
  111. var contentString = '<div class="info-window-content"><h2>Argon Dashboard</h2>' +
  112. '<p>A beautiful Dashboard for Bootstrap 4. It is Free and Open Source.</p></div>';
  113. var infowindow = new google.maps.InfoWindow({
  114. content: contentString
  115. });
  116. google.maps.event.addListener(marker, 'click', function() {
  117. infowindow.open(map, marker);
  118. });
  119. }
  120. if($map.length) {
  121. google.maps.event.addDomListener(window, 'load', initMap);
  122. }
  123. // //
  124. // // Headroom - show/hide navbar on scroll
  125. // //
  126. //
  127. // 'use strict';
  128. //
  129. // var Headroom = (function() {
  130. //
  131. // // Variables
  132. //
  133. // var $headroom = $('#navbar-main');
  134. //
  135. //
  136. // // Methods
  137. //
  138. // function init($this) {
  139. //
  140. // var headroom = new Headroom(document.querySelector("#navbar-main"), {
  141. // offset: 300,
  142. // tolerance: {
  143. // up: 30,
  144. // down: 30
  145. // },
  146. // });
  147. //
  148. //
  149. //
  150. // // Events
  151. //
  152. // if ($headroom.length) {
  153. // headroom.init();
  154. // }
  155. //
  156. // })();
  157. //
  158. // Navbar
  159. //
  160. 'use strict';
  161. var Navbar = (function() {
  162. // Variables
  163. var $nav = $('.navbar-nav, .navbar-nav .nav');
  164. var $collapse = $('.navbar .collapse');
  165. var $dropdown = $('.navbar .dropdown');
  166. // Methods
  167. function accordion($this) {
  168. $this.closest($nav).find($collapse).not($this).collapse('hide');
  169. }
  170. function closeDropdown($this) {
  171. var $dropdownMenu = $this.find('.dropdown-menu');
  172. $dropdownMenu.addClass('close');
  173. setTimeout(function() {
  174. $dropdownMenu.removeClass('close');
  175. }, 200);
  176. }
  177. // Events
  178. $collapse.on({
  179. 'show.bs.collapse': function() {
  180. accordion($(this));
  181. }
  182. })
  183. $dropdown.on({
  184. 'hide.bs.dropdown': function() {
  185. closeDropdown($(this));
  186. }
  187. })
  188. })();
  189. //
  190. // Navbar collapse
  191. //
  192. var NavbarCollapse = (function() {
  193. // Variables
  194. var $nav = $('.navbar-nav'),
  195. $collapse = $('.navbar .collapse');
  196. // Methods
  197. function hideNavbarCollapse($this) {
  198. $this.addClass('collapsing-out');
  199. }
  200. function hiddenNavbarCollapse($this) {
  201. $this.removeClass('collapsing-out');
  202. }
  203. // Events
  204. if ($collapse.length) {
  205. $collapse.on({
  206. 'hide.bs.collapse': function() {
  207. hideNavbarCollapse($collapse);
  208. }
  209. })
  210. $collapse.on({
  211. 'hidden.bs.collapse': function() {
  212. hiddenNavbarCollapse($collapse);
  213. }
  214. })
  215. }
  216. })();
  217. //
  218. // Form control
  219. //
  220. 'use strict';
  221. var noUiSlider = (function() {
  222. // Variables
  223. // var $sliderContainer = $('.input-slider-container'),
  224. // $slider = $('.input-slider'),
  225. // $sliderId = $slider.attr('id'),
  226. // $sliderMinValue = $slider.data('range-value-min');
  227. // $sliderMaxValue = $slider.data('range-value-max');;
  228. // // Methods
  229. //
  230. // function init($this) {
  231. // $this.on('focus blur', function(e) {
  232. // $this.parents('.form-group').toggleClass('focused', (e.type === 'focus' || this.value.length > 0));
  233. // }).trigger('blur');
  234. // }
  235. //
  236. //
  237. // // Events
  238. //
  239. // if ($input.length) {
  240. // init($input);
  241. // }
  242. if ($(".input-slider-container")[0]) {
  243. $('.input-slider-container').each(function() {
  244. var slider = $(this).find('.input-slider');
  245. var sliderId = slider.attr('id');
  246. var minValue = slider.data('range-value-min');
  247. var maxValue = slider.data('range-value-max');
  248. var sliderValue = $(this).find('.range-slider-value');
  249. var sliderValueId = sliderValue.attr('id');
  250. var startValue = sliderValue.data('range-value-low');
  251. var c = document.getElementById(sliderId),
  252. d = document.getElementById(sliderValueId);
  253. noUiSlider.create(c, {
  254. start: [parseInt(startValue)],
  255. connect: [true, false],
  256. //step: 1000,
  257. range: {
  258. 'min': [parseInt(minValue)],
  259. 'max': [parseInt(maxValue)]
  260. }
  261. });
  262. c.noUiSlider.on('update', function(a, b) {
  263. d.textContent = a[b];
  264. });
  265. })
  266. }
  267. if ($("#input-slider-range")[0]) {
  268. var c = document.getElementById("input-slider-range"),
  269. d = document.getElementById("input-slider-range-value-low"),
  270. e = document.getElementById("input-slider-range-value-high"),
  271. f = [d, e];
  272. noUiSlider.create(c, {
  273. start: [parseInt(d.getAttribute('data-range-value-low')), parseInt(e.getAttribute('data-range-value-high'))],
  274. connect: !0,
  275. range: {
  276. min: parseInt(c.getAttribute('data-range-value-min')),
  277. max: parseInt(c.getAttribute('data-range-value-max'))
  278. }
  279. }), c.noUiSlider.on("update", function(a, b) {
  280. f[b].textContent = a[b]
  281. })
  282. }
  283. })();
  284. //
  285. // Popover
  286. //
  287. 'use strict';
  288. var Popover = (function() {
  289. // Variables
  290. var $popover = $('[data-toggle="popover"]'),
  291. $popoverClass = '';
  292. // Methods
  293. function init($this) {
  294. if ($this.data('color')) {
  295. $popoverClass = 'popover-' + $this.data('color');
  296. }
  297. var options = {
  298. trigger: 'focus',
  299. template: '<div class="popover ' + $popoverClass + '" role="tooltip"><div class="arrow"></div><h3 class="popover-header"></h3><div class="popover-body"></div></div>'
  300. };
  301. $this.popover(options);
  302. }
  303. // Events
  304. if ($popover.length) {
  305. $popover.each(function() {
  306. init($(this));
  307. });
  308. }
  309. })();
  310. //
  311. // Scroll to (anchor links)
  312. //
  313. 'use strict';
  314. var ScrollTo = (function() {
  315. //
  316. // Variables
  317. //
  318. var $scrollTo = $('.scroll-me, [data-scroll-to], .toc-entry a');
  319. //
  320. // Methods
  321. //
  322. function scrollTo($this) {
  323. var $el = $this.attr('href');
  324. var offset = $this.data('scroll-to-offset') ? $this.data('scroll-to-offset') : 0;
  325. var options = {
  326. scrollTop: $($el).offset().top - offset
  327. };
  328. // Animate scroll to the selected section
  329. $('html, body').stop(true, true).animate(options, 600);
  330. event.preventDefault();
  331. }
  332. //
  333. // Events
  334. //
  335. if ($scrollTo.length) {
  336. $scrollTo.on('click', function(event) {
  337. scrollTo($(this));
  338. });
  339. }
  340. })();
  341. //
  342. // Tooltip
  343. //
  344. 'use strict';
  345. var Tooltip = (function() {
  346. // Variables
  347. var $tooltip = $('[data-toggle="tooltip"]');
  348. // Methods
  349. function init() {
  350. $tooltip.tooltip();
  351. }
  352. // Events
  353. if ($tooltip.length) {
  354. init();
  355. }
  356. })();
  357. //
  358. // Charts
  359. //
  360. 'use strict';
  361. var Charts = (function() {
  362. // Variable
  363. var $toggle = $('[data-toggle="chart"]');
  364. var mode = 'light';//(themeMode) ? themeMode : 'light';
  365. var fonts = {
  366. base: 'Open Sans'
  367. }
  368. // Colors
  369. var colors = {
  370. gray: {
  371. 100: '#f6f9fc',
  372. 200: '#e9ecef',
  373. 300: '#dee2e6',
  374. 400: '#ced4da',
  375. 500: '#adb5bd',
  376. 600: '#8898aa',
  377. 700: '#525f7f',
  378. 800: '#32325d',
  379. 900: '#212529'
  380. },
  381. theme: {
  382. 'default': '#172b4d',
  383. 'primary': '#5e72e4',
  384. 'secondary': '#f4f5f7',
  385. 'info': '#11cdef',
  386. 'success': '#2dce89',
  387. 'danger': '#f5365c',
  388. 'warning': '#fb6340'
  389. },
  390. black: '#12263F',
  391. white: '#FFFFFF',
  392. transparent: 'transparent',
  393. };
  394. // Methods
  395. // Chart.js global options
  396. function chartOptions() {
  397. // Options
  398. var options = {
  399. defaults: {
  400. global: {
  401. responsive: true,
  402. maintainAspectRatio: false,
  403. defaultColor: (mode == 'dark') ? colors.gray[700] : colors.gray[600],
  404. defaultFontColor: (mode == 'dark') ? colors.gray[700] : colors.gray[600],
  405. defaultFontFamily: fonts.base,
  406. defaultFontSize: 13,
  407. layout: {
  408. padding: 0
  409. },
  410. legend: {
  411. display: false,
  412. position: 'bottom',
  413. labels: {
  414. usePointStyle: true,
  415. padding: 16
  416. }
  417. },
  418. elements: {
  419. point: {
  420. radius: 0,
  421. backgroundColor: colors.theme['primary']
  422. },
  423. line: {
  424. tension: .4,
  425. borderWidth: 4,
  426. borderColor: colors.theme['primary'],
  427. backgroundColor: colors.transparent,
  428. borderCapStyle: 'rounded'
  429. },
  430. rectangle: {
  431. backgroundColor: colors.theme['warning']
  432. },
  433. arc: {
  434. backgroundColor: colors.theme['primary'],
  435. borderColor: (mode == 'dark') ? colors.gray[800] : colors.white,
  436. borderWidth: 4
  437. }
  438. },
  439. tooltips: {
  440. enabled: false,
  441. mode: 'index',
  442. intersect: false,
  443. custom: function(model) {
  444. // Get tooltip
  445. var $tooltip = $('#chart-tooltip');
  446. // Create tooltip on first render
  447. if (!$tooltip.length) {
  448. $tooltip = $('<div id="chart-tooltip" class="popover bs-popover-top" role="tooltip"></div>');
  449. // Append to body
  450. $('body').append($tooltip);
  451. }
  452. // Hide if no tooltip
  453. if (model.opacity === 0) {
  454. $tooltip.css('display', 'none');
  455. return;
  456. }
  457. function getBody(bodyItem) {
  458. return bodyItem.lines;
  459. }
  460. // Fill with content
  461. if (model.body) {
  462. var titleLines = model.title || [];
  463. var bodyLines = model.body.map(getBody);
  464. var html = '';
  465. // Add arrow
  466. html += '<div class="arrow"></div>';
  467. // Add header
  468. titleLines.forEach(function(title) {
  469. html += '<h3 class="popover-header text-center">' + title + '</h3>';
  470. });
  471. // Add body
  472. bodyLines.forEach(function(body, i) {
  473. var colors = model.labelColors[i];
  474. var styles = 'background-color: ' + colors.backgroundColor;
  475. var indicator = '<span class="badge badge-dot"><i class="bg-primary"></i></span>';
  476. var align = (bodyLines.length > 1) ? 'justify-content-left' : 'justify-content-center';
  477. html += '<div class="popover-body d-flex align-items-center ' + align + '">' + indicator + body + '</div>';
  478. });
  479. $tooltip.html(html);
  480. }
  481. // Get tooltip position
  482. var $canvas = $(this._chart.canvas);
  483. var canvasWidth = $canvas.outerWidth();
  484. var canvasHeight = $canvas.outerHeight();
  485. var canvasTop = $canvas.offset().top;
  486. var canvasLeft = $canvas.offset().left;
  487. var tooltipWidth = $tooltip.outerWidth();
  488. var tooltipHeight = $tooltip.outerHeight();
  489. var top = canvasTop + model.caretY - tooltipHeight - 16;
  490. var left = canvasLeft + model.caretX - tooltipWidth / 2;
  491. // Display tooltip
  492. $tooltip.css({
  493. 'top': top + 'px',
  494. 'left': left + 'px',
  495. 'display': 'block',
  496. 'z-index': '100'
  497. });
  498. },
  499. callbacks: {
  500. label: function(item, data) {
  501. var label = data.datasets[item.datasetIndex].label || '';
  502. var yLabel = item.yLabel;
  503. var content = '';
  504. if (data.datasets.length > 1) {
  505. content += '<span class="badge badge-primary mr-auto">' + label + '</span>';
  506. }
  507. content += '<span class="popover-body-value">' + yLabel + '</span>' ;
  508. return content;
  509. }
  510. }
  511. }
  512. },
  513. doughnut: {
  514. cutoutPercentage: 83,
  515. tooltips: {
  516. callbacks: {
  517. title: function(item, data) {
  518. var title = data.labels[item[0].index];
  519. return title;
  520. },
  521. label: function(item, data) {
  522. var value = data.datasets[0].data[item.index];
  523. var content = '';
  524. content += '<span class="popover-body-value">' + value + '</span>';
  525. return content;
  526. }
  527. }
  528. },
  529. legendCallback: function(chart) {
  530. var data = chart.data;
  531. var content = '';
  532. data.labels.forEach(function(label, index) {
  533. var bgColor = data.datasets[0].backgroundColor[index];
  534. content += '<span class="chart-legend-item">';
  535. content += '<i class="chart-legend-indicator" style="background-color: ' + bgColor + '"></i>';
  536. content += label;
  537. content += '</span>';
  538. });
  539. return content;
  540. }
  541. }
  542. }
  543. }
  544. // yAxes
  545. Chart.scaleService.updateScaleDefaults('linear', {
  546. gridLines: {
  547. borderDash: [2],
  548. borderDashOffset: [2],
  549. color: (mode == 'dark') ? colors.gray[900] : colors.gray[300],
  550. drawBorder: false,
  551. drawTicks: false,
  552. lineWidth: 0,
  553. zeroLineWidth: 0,
  554. zeroLineColor: (mode == 'dark') ? colors.gray[900] : colors.gray[300],
  555. zeroLineBorderDash: [2],
  556. zeroLineBorderDashOffset: [2]
  557. },
  558. ticks: {
  559. beginAtZero: true,
  560. padding: 10,
  561. callback: function(value) {
  562. if (!(value % 10)) {
  563. return value
  564. }
  565. }
  566. }
  567. });
  568. // xAxes
  569. Chart.scaleService.updateScaleDefaults('category', {
  570. gridLines: {
  571. drawBorder: false,
  572. drawOnChartArea: false,
  573. drawTicks: false
  574. },
  575. ticks: {
  576. padding: 20
  577. },
  578. maxBarThickness: 10
  579. });
  580. return options;
  581. }
  582. // Parse global options
  583. function parseOptions(parent, options) {
  584. for (var item in options) {
  585. if (typeof options[item] !== 'object') {
  586. parent[item] = options[item];
  587. } else {
  588. parseOptions(parent[item], options[item]);
  589. }
  590. }
  591. }
  592. // Push options
  593. function pushOptions(parent, options) {
  594. for (var item in options) {
  595. if (Array.isArray(options[item])) {
  596. options[item].forEach(function(data) {
  597. parent[item].push(data);
  598. });
  599. } else {
  600. pushOptions(parent[item], options[item]);
  601. }
  602. }
  603. }
  604. // Pop options
  605. function popOptions(parent, options) {
  606. for (var item in options) {
  607. if (Array.isArray(options[item])) {
  608. options[item].forEach(function(data) {
  609. parent[item].pop();
  610. });
  611. } else {
  612. popOptions(parent[item], options[item]);
  613. }
  614. }
  615. }
  616. // Toggle options
  617. function toggleOptions(elem) {
  618. var options = elem.data('add');
  619. var $target = $(elem.data('target'));
  620. var $chart = $target.data('chart');
  621. if (elem.is(':checked')) {
  622. // Add options
  623. pushOptions($chart, options);
  624. // Update chart
  625. $chart.update();
  626. } else {
  627. // Remove options
  628. popOptions($chart, options);
  629. // Update chart
  630. $chart.update();
  631. }
  632. }
  633. // Update options
  634. function updateOptions(elem) {
  635. var options = elem.data('update');
  636. var $target = $(elem.data('target'));
  637. var $chart = $target.data('chart');
  638. // Parse options
  639. parseOptions($chart, options);
  640. // Toggle ticks
  641. toggleTicks(elem, $chart);
  642. // Update chart
  643. $chart.update();
  644. }
  645. // Toggle ticks
  646. function toggleTicks(elem, $chart) {
  647. if (elem.data('prefix') !== undefined || elem.data('prefix') !== undefined) {
  648. var prefix = elem.data('prefix') ? elem.data('prefix') : '';
  649. var suffix = elem.data('suffix') ? elem.data('suffix') : '';
  650. // Update ticks
  651. $chart.options.scales.yAxes[0].ticks.callback = function(value) {
  652. if (!(value % 10)) {
  653. return prefix + value + suffix;
  654. }
  655. }
  656. // Update tooltips
  657. $chart.options.tooltips.callbacks.label = function(item, data) {
  658. var label = data.datasets[item.datasetIndex].label || '';
  659. var yLabel = item.yLabel;
  660. var content = '';
  661. if (data.datasets.length > 1) {
  662. content += '<span class="popover-body-label mr-auto">' + label + '</span>';
  663. }
  664. content += '<span class="popover-body-value">' + prefix + yLabel + suffix + '</span>';
  665. return content;
  666. }
  667. }
  668. }
  669. // Events
  670. // Parse global options
  671. if (window.Chart) {
  672. parseOptions(Chart, chartOptions());
  673. }
  674. // Toggle options
  675. $toggle.on({
  676. 'change': function() {
  677. var $this = $(this);
  678. if ($this.is('[data-add]')) {
  679. toggleOptions($this);
  680. }
  681. },
  682. 'click': function() {
  683. var $this = $(this);
  684. if ($this.is('[data-update]')) {
  685. updateOptions($this);
  686. }
  687. }
  688. });
  689. // Return
  690. return {
  691. colors: colors,
  692. fonts: fonts,
  693. mode: mode
  694. };
  695. })();
  696. //
  697. // Orders chart
  698. //
  699. var OrdersChart = (function() {
  700. //
  701. // Variables
  702. //
  703. var $chart = $('#chart-orders');
  704. var $ordersSelect = $('[name="ordersSelect"]');
  705. //
  706. // Methods
  707. //
  708. // Init chart
  709. function initChart($chart) {
  710. // Create chart
  711. var ordersChart = new Chart($chart, {
  712. type: 'bar',
  713. options: {
  714. scales: {
  715. yAxes: [{
  716. ticks: {
  717. callback: function(value) {
  718. if (!(value % 10)) {
  719. //return '$' + value + 'k'
  720. return value
  721. }
  722. }
  723. }
  724. }]
  725. },
  726. tooltips: {
  727. callbacks: {
  728. label: function(item, data) {
  729. var label = data.datasets[item.datasetIndex].label || '';
  730. var yLabel = item.yLabel;
  731. var content = '';
  732. if (data.datasets.length > 1) {
  733. content += '<span class="popover-body-label mr-auto">' + label + '</span>';
  734. }
  735. content += '<span class="popover-body-value">' + yLabel + '</span>';
  736. return content;
  737. }
  738. }
  739. }
  740. },
  741. data: {
  742. labels: ['Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  743. datasets: [{
  744. label: 'Sales',
  745. data: [25, 20, 30, 22, 17, 29]
  746. }]
  747. }
  748. });
  749. // Save to jQuery object
  750. $chart.data('chart', ordersChart);
  751. }
  752. // Init chart
  753. if ($chart.length) {
  754. initChart($chart);
  755. }
  756. })();
  757. //
  758. // Charts
  759. //
  760. 'use strict';
  761. //
  762. // Sales chart
  763. //
  764. var SalesChart = (function() {
  765. // Variables
  766. var $chart = $('#chart-sales');
  767. // Methods
  768. function init($chart) {
  769. var salesChart = new Chart($chart, {
  770. type: 'line',
  771. options: {
  772. scales: {
  773. yAxes: [{
  774. gridLines: {
  775. color: Charts.colors.gray[900],
  776. zeroLineColor: Charts.colors.gray[900]
  777. },
  778. ticks: {
  779. callback: function(value) {
  780. if (!(value % 10)) {
  781. return '$' + value + 'k';
  782. }
  783. }
  784. }
  785. }]
  786. },
  787. tooltips: {
  788. callbacks: {
  789. label: function(item, data) {
  790. var label = data.datasets[item.datasetIndex].label || '';
  791. var yLabel = item.yLabel;
  792. var content = '';
  793. if (data.datasets.length > 1) {
  794. content += '<span class="popover-body-label mr-auto">' + label + '</span>';
  795. }
  796. content += '<span class="popover-body-value">$' + yLabel + 'k</span>';
  797. return content;
  798. }
  799. }
  800. }
  801. },
  802. data: {
  803. labels: ['May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  804. datasets: [{
  805. label: 'Performance',
  806. data: [0, 20, 10, 30, 15, 40, 20, 60, 60]
  807. }]
  808. }
  809. });
  810. // Save to jQuery object
  811. $chart.data('chart', salesChart);
  812. };
  813. // Events
  814. if ($chart.length) {
  815. init($chart);
  816. }
  817. })();