@zhsz/cool-design-dv
Version:
68 lines (67 loc) • 1.81 kB
JavaScript
;
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const vue = require("vue");
const theme = require("../packages/chart/utils/theme.js");
function useChart($emit, props, page) {
const width = vue.ref(0);
const height = vue.ref(0);
const chartData = vue.ref();
const loading = vue.ref(true);
const theme$1 = vue.computed(() => {
const config = (page == null ? void 0 : page.settings) || {};
return Object.freeze(theme.default(config.value));
});
function resize($el) {
var _a, _b;
const rect = $el == null ? void 0 : $el.getBoundingClientRect();
if (!rect) {
return;
}
width.value = rect.width / (((_a = page == null ? void 0 : page.widthScale) == null ? void 0 : _a.value) ?? 1);
height.value = rect.height / (((_b = page == null ? void 0 : page.heightScale) == null ? void 0 : _b.value) ?? 1);
$emit("resize", [width.value, height.value]);
}
function load() {
if (props.loader) {
const loader = props.loader;
loading.value = true;
loader().then((data) => {
chartData.value = Object.freeze(data || {});
}).finally(() => {
loading.value = false;
});
} else {
if (props.columns && props.rows) {
chartData.value = Object.freeze({
columns: props.columns,
rows: props.rows,
type: props.type || "map"
});
}
loading.value = false;
}
}
vue.watch(
() => props.loader,
() => {
load();
},
{
immediate: true
}
);
vue.watch(
() => props.rows,
() => {
load();
}
);
vue.watch(
() => props.columns,
() => {
load();
}
);
return { resize, width, height, loading, theme: theme$1, chartData };
}
exports.useChart = useChart;