mirror of
https://github.com/apache/skywalking-booster-ui.git
synced 2025-07-04 21:35:24 +00:00
feat: create Graph Component with echarts
This commit is contained in:
parent
3f392c64f3
commit
1f4299291e
15
package-lock.json
generated
15
package-lock.json
generated
@ -2139,6 +2139,15 @@
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/echarts": {
|
||||
"version": "4.9.12",
|
||||
"resolved": "https://registry.npmjs.org/@types/echarts/-/echarts-4.9.12.tgz",
|
||||
"integrity": "sha512-yi5yzCRQCZDXeMcTD0W1sRENILJ98PjwG0UH/gZwADU2wsGt523RmocXakbpUOch6FHJqWwwJijsoSGNhGp4kA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/zrender": "*"
|
||||
}
|
||||
},
|
||||
"@types/express": {
|
||||
"version": "4.17.13",
|
||||
"resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.13.tgz",
|
||||
@ -2403,6 +2412,12 @@
|
||||
"integrity": "sha512-7tFImggNeNBVMsn0vLrpn1H1uPrUBdnARPTpZoitY37ZrdJREzf7I16tMrlK3hen349gr1NYh8CmZQa7CTG6Aw==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/zrender": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/zrender/-/zrender-4.0.1.tgz",
|
||||
"integrity": "sha512-IyTRf30jPOXK1+1RChI/78U6aV9hyWYf/vhL96Vt66oDz9es/BDjeKpvbNZSOHVA7zAReOwJcmdZS5AGAqhygw==",
|
||||
"dev": true
|
||||
},
|
||||
"@typescript-eslint/eslint-plugin": {
|
||||
"version": "4.33.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.33.0.tgz",
|
||||
|
@ -24,6 +24,7 @@
|
||||
"vuex": "^4.0.0-0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/echarts": "^4.9.12",
|
||||
"@types/jest": "^24.0.19",
|
||||
"@types/three": "^0.131.0",
|
||||
"@typescript-eslint/eslint-plugin": "^4.18.0",
|
||||
|
73
src/components/Graph.vue
Normal file
73
src/components/Graph.vue
Normal file
@ -0,0 +1,73 @@
|
||||
<!-- Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License. -->
|
||||
<template>
|
||||
<div
|
||||
class="echarts"
|
||||
ref="chart"
|
||||
:style="`height:${height};width:${width};`"
|
||||
></div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import {
|
||||
onMounted,
|
||||
watch,
|
||||
reactive,
|
||||
ref,
|
||||
defineProps,
|
||||
onBeforeUnmount,
|
||||
} from "vue";
|
||||
import type { PropType } from "vue";
|
||||
import * as echarts from "echarts";
|
||||
const dom = ref<any>(null);
|
||||
const state = reactive<any>({
|
||||
instanceChart: null,
|
||||
});
|
||||
const props = defineProps({
|
||||
clickEvent: { type: Function as PropType<(param: unknown) => void> },
|
||||
height: { type: Number, default: 100 },
|
||||
width: { type: Number, default: 300 },
|
||||
option: { type: Object as PropType<any>, default: () => ({}) },
|
||||
});
|
||||
onMounted(() => {
|
||||
drawEcharts();
|
||||
window.addEventListener("resize", state.instanceChart.resize);
|
||||
});
|
||||
function drawEcharts(): void {
|
||||
state.instanceChart = echarts.init(dom.value, "");
|
||||
state.instanceChart.setOption(state.option);
|
||||
state.instanceChart.on("click", (params: any) => {
|
||||
if (!props.clickEvent) {
|
||||
return;
|
||||
}
|
||||
props.clickEvent(params);
|
||||
});
|
||||
}
|
||||
watch(
|
||||
() => props.option,
|
||||
(opt) => {
|
||||
if (state.instanceChart) {
|
||||
state.instanceChart.setOption(opt, true);
|
||||
} else {
|
||||
drawEcharts();
|
||||
}
|
||||
}
|
||||
);
|
||||
onBeforeUnmount(() => {
|
||||
if (state.instanceChart.dispose) {
|
||||
state.instanceChart.dispose();
|
||||
}
|
||||
window.removeEventListener("resize", state.instanceChart.resize);
|
||||
});
|
||||
</script>
|
17
src/types/echarts.d.ts
vendored
Normal file
17
src/types/echarts.d.ts
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
declare module "echarts";
|
Loading…
Reference in New Issue
Block a user