mirror of
https://github.com/ecomfe/vue-echarts.git
synced 2025-11-06 21:18:32 +08:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0edfb3936c | |||
| ed4bd392ff | |||
| 58e7b13652 | |||
| 0a4601bc1a | |||
| 3b2f2b547b |
13
CHANGELOG.md
13
CHANGELOG.md
@ -1,3 +1,16 @@
|
|||||||
|
## 6.5.0
|
||||||
|
|
||||||
|
* Use more precise typings for all event params.
|
||||||
|
* Updated peer deps for `echarts` to `^5.4.1`.
|
||||||
|
|
||||||
|
## 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.5.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.5.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.5.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.5.0"></script>
|
||||||
```
|
```
|
||||||
<!-- vue2Scripts:end -->
|
<!-- vue2Scripts:end -->
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "vue-echarts",
|
"name": "vue-echarts",
|
||||||
"version": "6.3.3",
|
"version": "6.5.0",
|
||||||
"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": {
|
||||||
@ -40,7 +40,7 @@
|
|||||||
"@vue/eslint-config-typescript": "^10.0.0",
|
"@vue/eslint-config-typescript": "^10.0.0",
|
||||||
"comment-mark": "^1.0.0",
|
"comment-mark": "^1.0.0",
|
||||||
"core-js": "^3.23.0",
|
"core-js": "^3.23.0",
|
||||||
"echarts": "^5.3.2",
|
"echarts": "^5.4.1",
|
||||||
"echarts-liquidfill": "^3.1.0",
|
"echarts-liquidfill": "^3.1.0",
|
||||||
"eslint": "^7.20.0",
|
"eslint": "^7.20.0",
|
||||||
"eslint-plugin-prettier": "^3.3.1",
|
"eslint-plugin-prettier": "^3.3.1",
|
||||||
@ -67,7 +67,7 @@
|
|||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@vue/composition-api": "^1.0.5",
|
"@vue/composition-api": "^1.0.5",
|
||||||
"echarts": "^5.1.2",
|
"echarts": "^5.4.1",
|
||||||
"vue": "^2.6.12 || ^3.1.1"
|
"vue": "^2.6.12 || ^3.1.1"
|
||||||
},
|
},
|
||||||
"jsdelivr": "dist/index.umd.min.js",
|
"jsdelivr": "dist/index.umd.min.js",
|
||||||
|
|||||||
20
pnpm-lock.yaml
generated
20
pnpm-lock.yaml
generated
@ -15,7 +15,7 @@ specifiers:
|
|||||||
'@vue/eslint-config-typescript': ^10.0.0
|
'@vue/eslint-config-typescript': ^10.0.0
|
||||||
comment-mark: ^1.0.0
|
comment-mark: ^1.0.0
|
||||||
core-js: ^3.23.0
|
core-js: ^3.23.0
|
||||||
echarts: ^5.3.2
|
echarts: ^5.4.1
|
||||||
echarts-liquidfill: ^3.1.0
|
echarts-liquidfill: ^3.1.0
|
||||||
eslint: ^7.20.0
|
eslint: ^7.20.0
|
||||||
eslint-plugin-prettier: ^3.3.1
|
eslint-plugin-prettier: ^3.3.1
|
||||||
@ -60,8 +60,8 @@ devDependencies:
|
|||||||
'@vue/eslint-config-typescript': 10.0.0_yzev4ryi2uowr3tzgilgj3i2em
|
'@vue/eslint-config-typescript': 10.0.0_yzev4ryi2uowr3tzgilgj3i2em
|
||||||
comment-mark: 1.1.1
|
comment-mark: 1.1.1
|
||||||
core-js: 3.23.3
|
core-js: 3.23.3
|
||||||
echarts: 5.3.3
|
echarts: 5.4.1
|
||||||
echarts-liquidfill: 3.1.0_echarts@5.3.3
|
echarts-liquidfill: 3.1.0_echarts@5.4.1
|
||||||
eslint: 7.32.0
|
eslint: 7.32.0
|
||||||
eslint-plugin-prettier: 3.4.1_fqyzhpusvewbsl54pqqbxqaegm
|
eslint-plugin-prettier: 3.4.1_fqyzhpusvewbsl54pqqbxqaegm
|
||||||
eslint-plugin-vue: 8.7.1_eslint@7.32.0
|
eslint-plugin-vue: 8.7.1_eslint@7.32.0
|
||||||
@ -3925,19 +3925,19 @@ packages:
|
|||||||
engines: {node: '>=6.0.0'}
|
engines: {node: '>=6.0.0'}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/echarts-liquidfill/3.1.0_echarts@5.3.3:
|
/echarts-liquidfill/3.1.0_echarts@5.4.1:
|
||||||
resolution: {integrity: sha512-5Dlqs/jTsdTUAsd+K5LPLLTgrbbNORUSBQyk8PSy1Mg2zgHDWm83FmvA4s0ooNepCJojFYRITTQ4GU1UUSKYLw==}
|
resolution: {integrity: sha512-5Dlqs/jTsdTUAsd+K5LPLLTgrbbNORUSBQyk8PSy1Mg2zgHDWm83FmvA4s0ooNepCJojFYRITTQ4GU1UUSKYLw==}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
echarts: ^5.0.1
|
echarts: ^5.0.1
|
||||||
dependencies:
|
dependencies:
|
||||||
echarts: 5.3.3
|
echarts: 5.4.1
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/echarts/5.3.3:
|
/echarts/5.4.1:
|
||||||
resolution: {integrity: sha512-BRw2serInRwO5SIwRviZ6Xgm5Lb7irgz+sLiFMmy/HOaf4SQ+7oYqxKzRHAKp4xHQ05AuHw1xvoQWJjDQq/FGw==}
|
resolution: {integrity: sha512-9ltS3M2JB0w2EhcYjCdmtrJ+6haZcW6acBolMGIuf01Hql1yrIV01L1aRj7jsaaIULJslEP9Z3vKlEmnJaWJVQ==}
|
||||||
dependencies:
|
dependencies:
|
||||||
tslib: 2.3.0
|
tslib: 2.3.0
|
||||||
zrender: 5.3.2
|
zrender: 5.4.1
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/ee-first/1.1.1:
|
/ee-first/1.1.1:
|
||||||
@ -7831,8 +7831,8 @@ packages:
|
|||||||
strip-indent: 2.0.0
|
strip-indent: 2.0.0
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/zrender/5.3.2:
|
/zrender/5.4.1:
|
||||||
resolution: {integrity: sha512-8IiYdfwHj2rx0UeIGZGGU4WEVSDEdeVCaIg/fomejg1Xu6OifAL1GVzIPHg2D+MyUkbNgPWji90t0a8IDk+39w==}
|
resolution: {integrity: sha512-M4Z05BHWtajY2241EmMPHglDQAJ1UyHQcYsxDNzD9XLSkPDqMq4bB28v9Pb4mvHnVQ0GxyTklZ/69xCFP6RXBA==}
|
||||||
dependencies:
|
dependencies:
|
||||||
tslib: 2.3.0
|
tslib: 2.3.0
|
||||||
dev: true
|
dev: true
|
||||||
|
|||||||
@ -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,
|
||||||
|
|||||||
71
src/types.ts
71
src/types.ts
@ -1,4 +1,9 @@
|
|||||||
import { init, type SetOptionOpts } from "echarts/core";
|
import {
|
||||||
|
init,
|
||||||
|
type SetOptionOpts,
|
||||||
|
type ECElementEvent,
|
||||||
|
type ElementEvent
|
||||||
|
} from "echarts/core";
|
||||||
import type { Ref } from "vue";
|
import type { Ref } from "vue";
|
||||||
|
|
||||||
export type Injection<T> = T | null | Ref<T | null> | { value: T | null };
|
export type Injection<T> = T | null | Ref<T | null> | { value: T | null };
|
||||||
@ -20,16 +25,28 @@ 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 ElementEventName =
|
||||||
| "click"
|
| "click"
|
||||||
| "dblclick"
|
| "dblclick"
|
||||||
|
| "mousewheel"
|
||||||
|
| "mouseout"
|
||||||
|
| "mouseover"
|
||||||
|
| "mouseup"
|
||||||
| "mousedown"
|
| "mousedown"
|
||||||
| "mousemove"
|
| "mousemove"
|
||||||
| "mouseup"
|
|
||||||
| "mouseover"
|
|
||||||
| "mouseout"
|
|
||||||
| "globalout"
|
|
||||||
| "contextmenu"
|
| "contextmenu"
|
||||||
|
| "drag"
|
||||||
|
| "dragstart"
|
||||||
|
| "dragend"
|
||||||
|
| "dragenter"
|
||||||
|
| "dragleave"
|
||||||
|
| "dragover"
|
||||||
|
| "drop"
|
||||||
|
| "globalout";
|
||||||
|
|
||||||
|
type ZRenderEventName = `zr:${ElementEventName}`;
|
||||||
|
|
||||||
|
type OtherEventName =
|
||||||
| "highlight"
|
| "highlight"
|
||||||
| "downplay"
|
| "downplay"
|
||||||
| "selectchanged"
|
| "selectchanged"
|
||||||
@ -56,28 +73,22 @@ type EChartsEventName =
|
|||||||
| "brush"
|
| "brush"
|
||||||
| "brushEnd"
|
| "brushEnd"
|
||||||
| "brushselected"
|
| "brushselected"
|
||||||
| "globalcursortaken"
|
| "globalcursortaken";
|
||||||
| "rendered"
|
|
||||||
| "finished";
|
type ElementEmits = {
|
||||||
type ZRenderEventName =
|
[key in ElementEventName]: (params: ECElementEvent) => boolean;
|
||||||
| "click"
|
|
||||||
| "dblclick"
|
|
||||||
| "mousewheel"
|
|
||||||
| "mouseout"
|
|
||||||
| "mouseover"
|
|
||||||
| "mouseup"
|
|
||||||
| "mousedown"
|
|
||||||
| "mousemove"
|
|
||||||
| "contextmenu"
|
|
||||||
| "drag"
|
|
||||||
| "dragstart"
|
|
||||||
| "dragend"
|
|
||||||
| "dragenter"
|
|
||||||
| "dragleave"
|
|
||||||
| "dragover"
|
|
||||||
| "drop"
|
|
||||||
| "globalout";
|
|
||||||
type EventName = EChartsEventName | `zr:${ZRenderEventName}`;
|
|
||||||
export type Emits = {
|
|
||||||
[key in EventName]: null;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type ZRenderEmits = {
|
||||||
|
[key in ZRenderEventName]: (params: ElementEvent) => boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
type OtherEmits = {
|
||||||
|
[key in OtherEventName]: null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type Emits = ElementEmits &
|
||||||
|
OtherEmits & {
|
||||||
|
rendered: (params: { elapsedTime: number }) => boolean;
|
||||||
|
finished: () => boolean;
|
||||||
|
} & ZRenderEmits;
|
||||||
|
|||||||
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