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.
 
 
 

167 line
4.3 KiB

  1. import { defineComponent as Z, ref as b, onBeforeMount as _, onMounted as q, getCurrentInstance as K, onBeforeUnmount as $, toRefs as F, watch as c, h as G, nextTick as H } from "vue";
  2. import w from "apexcharts";
  3. const A = [
  4. "animationEnd",
  5. "beforeMount",
  6. "mounted",
  7. "updated",
  8. "click",
  9. "mouseMove",
  10. "mouseLeave",
  11. "legendClick",
  12. "markerClick",
  13. "selection",
  14. "dataPointSelection",
  15. "dataPointMouseEnter",
  16. "dataPointMouseLeave",
  17. "beforeZoom",
  18. "beforeResetZoom",
  19. "zoomed",
  20. "scrolled",
  21. "brushScrolled"
  22. ], m = Z({
  23. name: "apexchart",
  24. props: {
  25. options: {
  26. type: Object
  27. },
  28. type: {
  29. type: String
  30. },
  31. series: {
  32. type: Array,
  33. required: !0
  34. },
  35. width: {
  36. default: "100%"
  37. },
  38. height: {
  39. default: "auto"
  40. }
  41. },
  42. // events emitted by this component
  43. emits: A,
  44. setup(a, { emit: x }) {
  45. const g = b(null), n = b(null), f = (e) => e && typeof e == "object" && !Array.isArray(e) && e != null, S = (e, t) => {
  46. typeof Object.assign != "function" && function() {
  47. Object.assign = function(o) {
  48. if (o == null)
  49. throw new TypeError("Cannot convert undefined or null to object");
  50. let v = Object(o);
  51. for (let i = 1; i < arguments.length; i++) {
  52. let l = arguments[i];
  53. if (l != null)
  54. for (let p in l)
  55. l.hasOwnProperty(p) && (v[p] = l[p]);
  56. }
  57. return v;
  58. };
  59. }();
  60. let s = Object.assign({}, e);
  61. return f(e) && f(t) && Object.keys(t).forEach((o) => {
  62. f(t[o]) ? o in e ? s[o] = S(e[o], t[o]) : Object.assign(s, {
  63. [o]: t[o]
  64. }) : Object.assign(s, {
  65. [o]: t[o]
  66. });
  67. }), s;
  68. }, r = async () => {
  69. if (await H(), n.value)
  70. return;
  71. const e = {
  72. chart: {
  73. type: a.type || a.options.chart.type || "line",
  74. height: a.height,
  75. width: a.width,
  76. events: {}
  77. },
  78. series: a.series
  79. }, t = a.options.chart ? a.options.chart.events : null;
  80. A.forEach((o) => {
  81. let v = (...i) => x(o, ...i);
  82. e.chart.events[o] = (...i) => {
  83. v(...i), t && t.hasOwnProperty(o) && t[o](...i);
  84. };
  85. });
  86. const s = S(a.options, e);
  87. return n.value = new w(g.value, s), n.value.render();
  88. }, d = () => (h(), r()), h = () => {
  89. n.value.destroy();
  90. }, O = (e, t) => n.value.updateSeries(e, t), y = (e, t, s, o) => n.value.updateOptions(e, t, s, o), j = (e) => n.value.toggleSeries(e), P = (e) => {
  91. n.value.showSeries(e);
  92. }, C = (e) => {
  93. n.value.hideSeries(e);
  94. }, E = (e, t) => n.value.appendSeries(e, t), M = () => {
  95. n.value.resetSeries();
  96. }, D = (e, t) => {
  97. n.value.toggleDataPointSelection(e, t);
  98. }, L = (e) => n.value.appendData(e), R = (e, t) => n.value.zoomX(e, t), X = (e) => n.value.dataURI(e), z = (e) => n.value.setLocale(e), I = (e, t) => {
  99. n.value.addXaxisAnnotation(e, t);
  100. }, U = (e, t) => {
  101. n.value.addYaxisAnnotation(e, t);
  102. }, B = (e, t) => {
  103. n.value.addPointAnnotation(e, t);
  104. }, T = (e, t) => {
  105. n.value.removeAnnotation(e, t);
  106. }, Y = () => {
  107. n.value.clearAnnotations();
  108. };
  109. _(() => {
  110. window.ApexCharts = w;
  111. }), q(() => {
  112. g.value = K().proxy.$el, r();
  113. }), $(() => {
  114. n.value && h();
  115. });
  116. const u = F(a);
  117. return c(u.options, () => {
  118. !n.value && a.options ? r() : n.value.updateOptions(a.options);
  119. }), c(
  120. u.series,
  121. () => {
  122. !n.value && a.series ? r() : n.value.updateSeries(a.series);
  123. },
  124. { deep: !0 }
  125. ), c(u.type, () => {
  126. d();
  127. }), c(u.width, () => {
  128. d();
  129. }), c(u.height, () => {
  130. d();
  131. }), {
  132. chart: n,
  133. init: r,
  134. refresh: d,
  135. destroy: h,
  136. updateOptions: y,
  137. updateSeries: O,
  138. toggleSeries: j,
  139. showSeries: P,
  140. hideSeries: C,
  141. resetSeries: M,
  142. zoomX: R,
  143. toggleDataPointSelection: D,
  144. appendData: L,
  145. appendSeries: E,
  146. addXaxisAnnotation: I,
  147. addYaxisAnnotation: U,
  148. addPointAnnotation: B,
  149. removeAnnotation: T,
  150. clearAnnotations: Y,
  151. setLocale: z,
  152. dataURI: X
  153. };
  154. },
  155. render() {
  156. return G("div", {
  157. class: "vue-apexcharts"
  158. });
  159. }
  160. }), J = (a) => {
  161. a.component(m.name, m);
  162. };
  163. m.install = J;
  164. export {
  165. m as default
  166. };