ecommerce.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. (function (global, factory) {
  2. if (typeof define === "function" && define.amd) {
  3. define("/dashboard/ecommerce", ["jquery", "Site"], factory);
  4. } else if (typeof exports !== "undefined") {
  5. factory(require("jquery"), require("Site"));
  6. } else {
  7. var mod = {
  8. exports: {}
  9. };
  10. factory(global.jQuery, global.Site);
  11. global.dashboardEcommerce = mod.exports;
  12. }
  13. })(this, function (_jquery, _Site) {
  14. "use strict";
  15. _jquery = babelHelpers.interopRequireDefault(_jquery);
  16. (0, _jquery.default)(document).ready(function ($$$1) {
  17. (0, _Site.run)();
  18. }); // ScoreChart
  19. // ------------------------------
  20. (function () {
  21. var scoreChart = function scoreChart(id, labelList, series1List, series2List) {
  22. var scoreChart = new Chartist.Line('#' + id, {
  23. labels: labelList,
  24. series: [series1List, series2List]
  25. }, {
  26. lineSmooth: Chartist.Interpolation.simple({
  27. divisor: 2
  28. }),
  29. fullWidth: true,
  30. chartPadding: {
  31. right: 25
  32. },
  33. series: {
  34. "series-1": {
  35. showArea: true
  36. },
  37. "series-2": {
  38. showArea: true
  39. }
  40. },
  41. axisX: {
  42. showGrid: false
  43. },
  44. axisY: {
  45. labelInterpolationFnc: function labelInterpolationFnc(value) {
  46. return value / 1000 + 'K';
  47. },
  48. scaleMinSpace: 40
  49. },
  50. plugins: [Chartist.plugins.tooltip()],
  51. low: 0,
  52. height: 300
  53. });
  54. scoreChart.on('created', function (data) {
  55. var defs = data.svg.querySelector('defs') || data.svg.elem('defs');
  56. var width = data.svg.width();
  57. var height = data.svg.height();
  58. var filter = defs.elem('filter', {
  59. x: 0,
  60. y: "-10%",
  61. id: 'shadow' + id
  62. }, '', true);
  63. filter.elem('feGaussianBlur', {
  64. in: "SourceAlpha",
  65. stdDeviation: "8",
  66. result: 'offsetBlur'
  67. });
  68. filter.elem('feOffset', {
  69. dx: "0",
  70. dy: "10"
  71. });
  72. filter.elem('feBlend', {
  73. in: "SourceGraphic",
  74. mode: "multiply"
  75. });
  76. return defs;
  77. }).on('draw', function (data) {
  78. if (data.type === 'line') {
  79. data.element.attr({
  80. filter: 'url(#shadow' + id + ')'
  81. });
  82. } else if (data.type === 'point') {
  83. var parent = new Chartist.Svg(data.element._node.parentNode);
  84. parent.elem('line', {
  85. x1: data.x,
  86. y1: data.y,
  87. x2: data.x + 0.01,
  88. y2: data.y,
  89. "class": 'ct-point-content'
  90. });
  91. }
  92. if (data.type === 'line' || data.type === 'area') {
  93. data.element.animate({
  94. d: {
  95. begin: 1000 * data.index,
  96. dur: 1000,
  97. from: data.path.clone().scale(1, 0).translate(0, data.chartRect.height()).stringify(),
  98. to: data.path.clone().stringify(),
  99. easing: Chartist.Svg.Easing.easeOutQuint
  100. }
  101. });
  102. }
  103. });
  104. };
  105. var DayLabelList = ["1st", "2nd", "3rd", "4th", "5th", "6th", "7th"];
  106. var DaySeries1List = {
  107. name: "series-1",
  108. data: [2400, 4500, 5000, 6100, 7700, 5000, 1700]
  109. };
  110. var DaySeries2List = {
  111. name: "series-2",
  112. data: [1300, 4100, 8000, 4000, 6600, 5600, 3800]
  113. };
  114. var WeekLabelList = ["W1", "W2", "W4", "W5", "W6", "W7", "W8"];
  115. var WeekSeries1List = {
  116. name: "series-1",
  117. data: [18000, 37000, 41000, 29000, 58000, 75000, 43000]
  118. };
  119. var WeekSeries2List = {
  120. name: "series-2",
  121. data: [30000, 20000, 43000, 68000, 72000, 53000, 66000]
  122. };
  123. var MonthLabelList = ["AUG", "SEP", "OTC", "NOV", "DEC", "JAN", "FEB"];
  124. var MonthSeries1List = {
  125. name: "series-1",
  126. data: [100000, 500000, 300000, 700000, 100000, 200000, 700000]
  127. };
  128. var MonthSeries2List = {
  129. name: "series-2",
  130. data: [300000, 400000, 200000, 600000, 800000, 600000, 300000]
  131. };
  132. var createChart = function createChart(button) {
  133. var btn = button || (0, _jquery.default)("#ecommerceChartView .chart-action").find(".active");
  134. var chartId = btn.attr("href");
  135. switch (chartId) {
  136. case "#scoreLineToDay":
  137. scoreChart("scoreLineToDay", DayLabelList, DaySeries1List, DaySeries2List);
  138. break;
  139. case "#scoreLineToWeek":
  140. scoreChart("scoreLineToWeek", WeekLabelList, WeekSeries1List, WeekSeries2List);
  141. break;
  142. case "#scoreLineToMonth":
  143. scoreChart("scoreLineToMonth", MonthLabelList, MonthSeries1List, MonthSeries2List);
  144. break;
  145. }
  146. };
  147. createChart();
  148. (0, _jquery.default)(".chart-action li a").on("click", function () {
  149. createChart((0, _jquery.default)(this));
  150. });
  151. })(); // barChart
  152. // ------------------------------
  153. (function () {
  154. var barChart = new Chartist.Bar('.barChart', {
  155. labels: ['JAN', 'FEB', 'MAR', 'APR', 'MAY'],
  156. series: [[630, 700, 500, 400, 780], [400, 800, 700, 500, 700]]
  157. }, {
  158. axisX: {
  159. showGrid: false
  160. },
  161. axisY: {
  162. showGrid: false,
  163. scaleMinSpace: 30
  164. },
  165. height: 220,
  166. seriesBarDistance: 24
  167. });
  168. barChart.on('draw', function (data) {
  169. if (data.type === 'bar') {
  170. // $("#ecommerceRevenue .ct-labels").attr('transform', 'translate(0 15)');
  171. var parent = new Chartist.Svg(data.element._node.parentNode);
  172. parent.elem('line', {
  173. x1: data.x1,
  174. x2: data.x2,
  175. y1: data.y2,
  176. y2: 0,
  177. "class": 'ct-bar-fill'
  178. });
  179. }
  180. });
  181. })();
  182. });