mirror of
https://github.com/ecomfe/vue-echarts.git
synced 2025-11-06 21:18:32 +08:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 58e7b13652 | |||
| 0a4601bc1a | |||
| 3b2f2b547b |
@ -1,3 +1,11 @@
|
|||||||
|
## 6.4.1
|
||||||
|
|
||||||
|
* Improve typings for mouse event params.
|
||||||
|
|
||||||
|
## 6.4.0
|
||||||
|
|
||||||
|
* Delay the disposal of the ECharts instance to the moment the element is disconnected from the DOM if possible (#433).
|
||||||
|
|
||||||
## 6.3.3
|
## 6.3.3
|
||||||
|
|
||||||
* Make autoresize work for grid layout by default (#675).
|
* Make autoresize work for grid layout by default (#675).
|
||||||
|
|||||||
@ -227,7 +227,7 @@ Drop `<script>` inside your HTML file and access the component via `window.VueEC
|
|||||||
```html
|
```html
|
||||||
<script src="https://cdn.jsdelivr.net/npm/vue@3.2.37"></script>
|
<script src="https://cdn.jsdelivr.net/npm/vue@3.2.37"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/echarts@5.3.3"></script>
|
<script src="https://cdn.jsdelivr.net/npm/echarts@5.3.3"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/vue-echarts@6.3.2"></script>
|
<script src="https://cdn.jsdelivr.net/npm/vue-echarts@6.4.0"></script>
|
||||||
```
|
```
|
||||||
<!-- vue3Scripts:end -->
|
<!-- vue3Scripts:end -->
|
||||||
|
|
||||||
@ -247,7 +247,7 @@ app.component('v-chart', VueECharts)
|
|||||||
```html
|
```html
|
||||||
<script src="https://cdn.jsdelivr.net/npm/vue@2.7.5"></script>
|
<script src="https://cdn.jsdelivr.net/npm/vue@2.7.5"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/echarts@5.3.3"></script>
|
<script src="https://cdn.jsdelivr.net/npm/echarts@5.3.3"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/vue-echarts@6.3.2"></script>
|
<script src="https://cdn.jsdelivr.net/npm/vue-echarts@6.4.0"></script>
|
||||||
```
|
```
|
||||||
<!-- vue2Scripts:end -->
|
<!-- vue2Scripts:end -->
|
||||||
|
|
||||||
|
|||||||
@ -225,7 +225,7 @@ import "echarts";
|
|||||||
```html
|
```html
|
||||||
<script src="https://cdn.jsdelivr.net/npm/vue@3.2.37"></script>
|
<script src="https://cdn.jsdelivr.net/npm/vue@3.2.37"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/echarts@5.3.3"></script>
|
<script src="https://cdn.jsdelivr.net/npm/echarts@5.3.3"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/vue-echarts@6.3.2"></script>
|
<script src="https://cdn.jsdelivr.net/npm/vue-echarts@6.4.0"></script>
|
||||||
```
|
```
|
||||||
<!-- vue3Scripts:end -->
|
<!-- vue3Scripts:end -->
|
||||||
|
|
||||||
@ -245,7 +245,7 @@ app.component('v-chart', VueECharts)
|
|||||||
```html
|
```html
|
||||||
<script src="https://cdn.jsdelivr.net/npm/vue@2.7.5"></script>
|
<script src="https://cdn.jsdelivr.net/npm/vue@2.7.5"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/echarts@5.3.3"></script>
|
<script src="https://cdn.jsdelivr.net/npm/echarts@5.3.3"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/vue-echarts@6.3.2"></script>
|
<script src="https://cdn.jsdelivr.net/npm/vue-echarts@6.4.0"></script>
|
||||||
```
|
```
|
||||||
<!-- vue2Scripts:end -->
|
<!-- vue2Scripts:end -->
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "vue-echarts",
|
"name": "vue-echarts",
|
||||||
"version": "6.3.3",
|
"version": "6.4.1",
|
||||||
"description": "Vue.js component for Apache ECharts.",
|
"description": "Vue.js component for Apache ECharts.",
|
||||||
"author": "GU Yiling <justice360@gmail.com>",
|
"author": "GU Yiling <justice360@gmail.com>",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import {
|
|||||||
computed,
|
computed,
|
||||||
inject,
|
inject,
|
||||||
onMounted,
|
onMounted,
|
||||||
onUnmounted,
|
onBeforeUnmount,
|
||||||
h,
|
h,
|
||||||
nextTick,
|
nextTick,
|
||||||
watchEffect,
|
watchEffect,
|
||||||
@ -38,9 +38,10 @@ import {
|
|||||||
loadingProps
|
loadingProps
|
||||||
} from "./composables";
|
} from "./composables";
|
||||||
import { omitOn, unwrapInjected } from "./utils";
|
import { omitOn, unwrapInjected } from "./utils";
|
||||||
|
import { register, TAG_NAME, type EChartsElement } from "./wc";
|
||||||
import "./style.css";
|
import "./style.css";
|
||||||
|
|
||||||
const TAG_NAME = "x-vue-echarts";
|
const wcRegistered = register();
|
||||||
|
|
||||||
if (Vue2) {
|
if (Vue2) {
|
||||||
Vue2.config.ignoredElements.push(TAG_NAME);
|
Vue2.config.ignoredElements.push(TAG_NAME);
|
||||||
@ -70,7 +71,7 @@ export default defineComponent({
|
|||||||
emits: [] as unknown as Emits,
|
emits: [] as unknown as Emits,
|
||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
setup(props, { attrs }) {
|
setup(props, { attrs }) {
|
||||||
const root = shallowRef<HTMLElement>();
|
const root = shallowRef<EChartsElement>();
|
||||||
const chart = shallowRef<EChartsType>();
|
const chart = shallowRef<EChartsType>();
|
||||||
const manualOption = shallowRef<Option>();
|
const manualOption = shallowRef<Option>();
|
||||||
const defaultTheme = inject(THEME_KEY, null);
|
const defaultTheme = inject(THEME_KEY, null);
|
||||||
@ -273,7 +274,17 @@ export default defineComponent({
|
|||||||
init();
|
init();
|
||||||
});
|
});
|
||||||
|
|
||||||
onUnmounted(cleanup);
|
onBeforeUnmount(() => {
|
||||||
|
if (wcRegistered && root.value) {
|
||||||
|
// For registered web component, we can leverage the
|
||||||
|
// `disconnectedCallback` to dispose the chart instance
|
||||||
|
// so that we can delay the cleanup after exsiting leaving
|
||||||
|
// transition.
|
||||||
|
root.value.__dispose = cleanup;
|
||||||
|
} else {
|
||||||
|
cleanup();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
chart,
|
chart,
|
||||||
|
|||||||
29
src/types.ts
29
src/types.ts
@ -20,7 +20,7 @@ export type EventTarget = EChartsType | ZRenderType;
|
|||||||
type SetOptionType = EChartsType["setOption"];
|
type SetOptionType = EChartsType["setOption"];
|
||||||
export type Option = Parameters<SetOptionType>[0];
|
export type Option = Parameters<SetOptionType>[0];
|
||||||
|
|
||||||
type EChartsEventName =
|
type EChartsMouseEventName =
|
||||||
| "click"
|
| "click"
|
||||||
| "dblclick"
|
| "dblclick"
|
||||||
| "mousedown"
|
| "mousedown"
|
||||||
@ -29,7 +29,8 @@ type EChartsEventName =
|
|||||||
| "mouseover"
|
| "mouseover"
|
||||||
| "mouseout"
|
| "mouseout"
|
||||||
| "globalout"
|
| "globalout"
|
||||||
| "contextmenu"
|
| "contextmenu";
|
||||||
|
type EChartsOtherEventName =
|
||||||
| "highlight"
|
| "highlight"
|
||||||
| "downplay"
|
| "downplay"
|
||||||
| "selectchanged"
|
| "selectchanged"
|
||||||
@ -77,7 +78,25 @@ type ZRenderEventName =
|
|||||||
| "dragover"
|
| "dragover"
|
||||||
| "drop"
|
| "drop"
|
||||||
| "globalout";
|
| "globalout";
|
||||||
type EventName = EChartsEventName | `zr:${ZRenderEventName}`;
|
type OtherEventName = EChartsOtherEventName | `zr:${ZRenderEventName}`;
|
||||||
export type Emits = {
|
|
||||||
[key in EventName]: null;
|
// See https://echarts.apache.org/en/api.html#events.Mouse%20events
|
||||||
|
interface MouseEventParams {
|
||||||
|
componentType: string;
|
||||||
|
seriesType: string;
|
||||||
|
seriesIndex: number;
|
||||||
|
seriesName: string;
|
||||||
|
name: string;
|
||||||
|
dataIndex: number;
|
||||||
|
color: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
type MouseEmits = {
|
||||||
|
[k in EChartsMouseEventName]: (params: MouseEventParams) => boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type OtherEmits = {
|
||||||
|
[key in OtherEventName]: null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type Emits = MouseEmits & OtherEmits;
|
||||||
|
|||||||
51
src/wc.ts
Normal file
51
src/wc.ts
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
let registered: boolean | null = null;
|
||||||
|
|
||||||
|
export const TAG_NAME = "x-vue-echarts";
|
||||||
|
|
||||||
|
export interface EChartsElement extends HTMLElement {
|
||||||
|
__dispose: (() => void) | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function register(): boolean {
|
||||||
|
if (registered != null) {
|
||||||
|
return registered;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
typeof HTMLElement === "undefined" ||
|
||||||
|
typeof customElements === "undefined"
|
||||||
|
) {
|
||||||
|
return (registered = false);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Class definitions cannot be transpiled to ES5
|
||||||
|
// so we are doing a little trick here to ensure
|
||||||
|
// we are using native classes. As we use this as
|
||||||
|
// a progressive enhancement, it will be fine even
|
||||||
|
// if the browser doesn't support native classes.
|
||||||
|
const reg = new Function(
|
||||||
|
"tag",
|
||||||
|
`class EChartsElement extends HTMLElement {
|
||||||
|
__dispose = null;
|
||||||
|
|
||||||
|
disconnectedCallback() {
|
||||||
|
if (this.__dispose) {
|
||||||
|
this.__dispose();
|
||||||
|
this.__dispose = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (customElements.get(tag) == null) {
|
||||||
|
customElements.define(tag, EChartsElement);
|
||||||
|
}
|
||||||
|
`
|
||||||
|
);
|
||||||
|
reg(TAG_NAME);
|
||||||
|
} catch (e) {
|
||||||
|
return (registered = false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (registered = true);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user