UNPKG

@zhsz/cool-design-dv

Version:

126 lines (125 loc) 3.24 kB
import { defineComponent, getCurrentInstance, useAttrs, onMounted, onBeforeUnmount, openBlock, createElementBlock, normalizeClass, unref, normalizeStyle } from "vue"; import useMyChart from "../hooks/useMyChart.mjs"; import cartesian2d from "../utils/cartesian2d.mjs"; import { DEFAULT_THEME } from "../utils/constant.mjs"; import { pickBy, isFunction } from "lodash-es"; const __default__ = defineComponent({ name: "MyChartBar" }); const _sfc_main = /* @__PURE__ */ defineComponent({ ...__default__, props: { // 宽度 width: { type: String, default: "auto" }, // 高度 height: { type: String, default: "400px" }, // 适应父容器 fit: Boolean, // ECharts 配置选项 options: { type: Object }, // 扩展 options extend: [Object, Function], // 主题 theme: { type: [String, Object], default() { return DEFAULT_THEME; } }, // 显示加载动画 loading: Boolean, // 打印 options debug: { type: Boolean }, // 图表私有设置 settings: { type: Object, default() { return {}; } }, // 图表数据 echarts dataset data: { type: [Object, Array], default() { return {}; } }, // 地图名称 map: String, // 地图geojson对象或构建函数,函数必须返回Promise register: [Object, Function], // 地图注册成功回调 onRegister: Function, // 坐标集合 如:{'广州': [120.3234, 33.4329]}, 或 [{label:'广州',value: [120.3234, 33.4329]}] coords: { type: [Object, Array], default() { return {}; } }, // 排列方向,即类别在哪个轴上 direction: { type: String, default: "x", validator(val) { return ["x", "y"].includes(val); } }, // 数据项的标签设置,字符类型设置position, 对象与原生series.label设置一致 label: [String, Object, Array], // 值类型轴配置 valueAxis: [String, Object, Array], // 堆叠柱,如 ['name1', 'name2'] 或 {'name': ['name1', 'name2']} stack: [Object, Array], // 改成柱状图显示的系列 bars: [String, Array], // 线条平滑,只对折线图有效 smooth: { type: [Boolean, Number], default: 0.5 } }, emits: ["register"], setup(__props, { emit: __emit }) { var _a; const props = __props; const instance = (_a = getCurrentInstance()) == null ? void 0 : _a.proxy; const $listeners = pickBy(useAttrs(), isFunction); const emits = __emit; const adapter = (vm) => { return cartesian2d(vm, "line", props); }; const { registerMap, init, dispose, classes, styles } = useMyChart( props, instance, $listeners, emits, adapter ); onMounted(() => { registerMap().then(init); }); onBeforeUnmount(() => { dispose(); }); return (_ctx, _cache) => { return openBlock(), createElementBlock("div", { class: normalizeClass(unref(classes)), style: normalizeStyle(unref(styles)) }, null, 6); }; } }); export { _sfc_main as default };