UNPKG

@zhsz/cool-design-dv

Version:

90 lines (89 loc) 3.23 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); const vue = require("vue"); const index$2 = require("../dv-loading/index.js"); const lodashEs = require("lodash-es"); const index = require("../../symbols/index.js"); const useChart = require("../../hooks/useChart.js"); const resizeEvent = require("../../utils/resize-event.js"); const index$1 = require("../dv-box/index.js"); const index$3 = require("../chart/chart-my/index.js"); require("../chart/chart-bar/index.js"); require("../chart/chart-line/index.js"); const extend = require("../chart/utils/extend.js"); const __default__ = vue.defineComponent({ name: "DvBar", inheritAttrs: false }); const _sfc_main = /* @__PURE__ */ vue.defineComponent({ ...__default__, props: { debug: Boolean, options: [Object, Function], extend: { type: [Object, Function] } }, emits: ["resize"], setup(__props, { emit: __emit }) { var _a; const props = __props; const page = vue.inject(index.dvPageSymbols, null); const instance = (_a = vue.getCurrentInstance()) == null ? void 0 : _a.proxy; const currentOptions = vue.ref(); const emits = __emit; const { resize, width, height, loading, theme, chartData } = useChart.useChart( emits, props, page ); function mergeOptions(data) { const opts = typeof props.options === "function" ? props.options(data) : props.options || {}; extend.default(opts, props.extend || {}); currentOptions.value = Object.freeze(lodashEs.merge({}, currentOptions.value, opts)); } vue.watch( () => chartData.value, (val) => { mergeOptions(val); }, { immediate: true } ); vue.watch( () => props.options, () => { mergeOptions(chartData.value); } ); vue.onMounted(() => { resize(instance == null ? void 0 : instance.$el); resizeEvent.addResizeListener(instance == null ? void 0 : instance.$el, () => resize(instance == null ? void 0 : instance.$el)); }); vue.onBeforeUnmount(() => { resizeEvent.removeResizeListener(instance == null ? void 0 : instance.$el, () => resize(instance == null ? void 0 : instance.$el)); }); return (_ctx, _cache) => { return vue.openBlock(), vue.createBlock(vue.unref(index$1.default), vue.mergeProps({ class: "my-dv-chart", "default-width": "400px", "default-height": "400px" }, _ctx.$attrs), { default: vue.withCtx(() => [ vue.unref(loading) ? (vue.openBlock(), vue.createBlock(vue.unref(index$2.default), { key: 0, zoom: 0.6 })) : (vue.openBlock(), vue.createBlock(vue.unref(index$3.default), vue.mergeProps({ key: 1 }, vue.toHandlers(_ctx.$attrs), { debug: __props.debug, theme: vue.unref(theme), options: currentOptions.value, extend: __props.extend, width: `${vue.unref(width)}px`, height: `${vue.unref(height)}px` }), null, 16, ["debug", "theme", "options", "extend", "width", "height"])) ]), _: 1 }, 16); }; } }); exports.default = _sfc_main;