mirror of
https://github.com/apache/skywalking-booster-ui.git
synced 2025-05-02 17:04:48 +00:00
feat: resize events to rerender charts
This commit is contained in:
parent
4a6ac51b7a
commit
d4dedecd1b
@ -76,7 +76,8 @@
|
|||||||
"ecmaVersion": 2020
|
"ecmaVersion": 2020
|
||||||
},
|
},
|
||||||
"rules": {
|
"rules": {
|
||||||
"@typescript-eslint/no-explicit-any": "off"
|
"@typescript-eslint/no-explicit-any": "off",
|
||||||
|
"@typescript-eslint/explicit-module-boundary-types": "off"
|
||||||
},
|
},
|
||||||
"overrides": [
|
"overrides": [
|
||||||
{
|
{
|
||||||
|
@ -16,9 +16,18 @@ limitations under the License. -->
|
|||||||
<div ref="chartRef" :style="`height:${height};width:${width};`"></div>
|
<div ref="chartRef" :style="`height:${height};width:${width};`"></div>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { watch, ref, defineProps, Ref, onMounted, onBeforeUnmount } from "vue";
|
import {
|
||||||
|
watch,
|
||||||
|
ref,
|
||||||
|
defineProps,
|
||||||
|
Ref,
|
||||||
|
onMounted,
|
||||||
|
onBeforeUnmount,
|
||||||
|
unref,
|
||||||
|
} from "vue";
|
||||||
import type { PropType } from "vue";
|
import type { PropType } from "vue";
|
||||||
import { useECharts } from "@/hooks/useEcharts";
|
import { useECharts } from "@/hooks/useEcharts";
|
||||||
|
import { addResizeListener, removeResizeListener } from "@/utils/event";
|
||||||
/*global Nullable*/
|
/*global Nullable*/
|
||||||
const chartRef = ref<Nullable<HTMLDivElement>>(null);
|
const chartRef = ref<Nullable<HTMLDivElement>>(null);
|
||||||
const { setOptions, resize } = useECharts(chartRef as Ref<HTMLDivElement>);
|
const { setOptions, resize } = useECharts(chartRef as Ref<HTMLDivElement>);
|
||||||
@ -37,6 +46,7 @@ onMounted(() => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
window.addEventListener("resize", resize);
|
window.addEventListener("resize", resize);
|
||||||
|
addResizeListener(unref(chartRef), resize);
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
@ -51,5 +61,6 @@ onBeforeUnmount(() => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
window.removeEventListener("resize", resize);
|
window.removeEventListener("resize", resize);
|
||||||
|
removeResizeListener(unref(chartRef), resize);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
40
src/utils/event.ts
Normal file
40
src/utils/event.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
const isServer = typeof window === "undefined";
|
||||||
|
|
||||||
|
function resizeHandler(entries: any[]): void {
|
||||||
|
for (const entry of entries) {
|
||||||
|
const listeners = entry.target.__resizeListeners__ || [];
|
||||||
|
if (listeners.length) {
|
||||||
|
listeners.forEach((fn: () => any) => {
|
||||||
|
fn();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function addResizeListener(element: any, fn: () => unknown): void {
|
||||||
|
if (isServer) return;
|
||||||
|
if (!element.__resizeListeners__) {
|
||||||
|
element.__resizeListeners__ = [];
|
||||||
|
element.__ro__ = new ResizeObserver(resizeHandler);
|
||||||
|
element.__ro__.observe(element);
|
||||||
|
}
|
||||||
|
element.__resizeListeners__.push(fn);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function removeResizeListener(element: any, fn: () => unknown): void {
|
||||||
|
if (!element || !element.__resizeListeners__) return;
|
||||||
|
element.__resizeListeners__.splice(
|
||||||
|
element.__resizeListeners__.indexOf(fn),
|
||||||
|
1
|
||||||
|
);
|
||||||
|
if (!element.__resizeListeners__.length) {
|
||||||
|
element.__ro__.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function triggerWindowResize(): void {
|
||||||
|
const event = document.createEvent("HTMLEvents");
|
||||||
|
event.initEvent("resize", true, true);
|
||||||
|
(event as any).eventType = "message";
|
||||||
|
window.dispatchEvent(event);
|
||||||
|
}
|
@ -32,7 +32,7 @@ limitations under the License. -->
|
|||||||
</div>
|
</div>
|
||||||
</el-popover>
|
</el-popover>
|
||||||
</div>
|
</div>
|
||||||
<div class="body" :style="{ height: '200px', width: '400px' }">
|
<div class="body">
|
||||||
<component
|
<component
|
||||||
:is="data.graph.type"
|
:is="data.graph.type"
|
||||||
:intervalTime="appStoreWithOut.intervalTime"
|
:intervalTime="appStoreWithOut.intervalTime"
|
||||||
@ -48,10 +48,9 @@ import { LayoutConfig } from "@/types/dashboard";
|
|||||||
import { useDashboardStore } from "@/store/modules/dashboard";
|
import { useDashboardStore } from "@/store/modules/dashboard";
|
||||||
import { useAppStoreWithOut } from "@/store/modules/app";
|
import { useAppStoreWithOut } from "@/store/modules/app";
|
||||||
import graphs from "../graphs";
|
import graphs from "../graphs";
|
||||||
import { ElMessage } from "element-plus";
|
import { ElMessage, ElPopover } from "element-plus";
|
||||||
import Loading from "@/utils/loading";
|
import Loading from "@/utils/loading";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import { ElPopover } from "element-plus";
|
|
||||||
|
|
||||||
const props = {
|
const props = {
|
||||||
data: {
|
data: {
|
||||||
@ -121,6 +120,7 @@ export default defineComponent({
|
|||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.widget {
|
.widget {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.header {
|
.header {
|
||||||
@ -149,8 +149,8 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
.body {
|
.body {
|
||||||
padding: 5px;
|
padding: 5px 10px;
|
||||||
height: 200px;
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
height: calc(100% - 30px);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -30,6 +30,7 @@ limitations under the License. -->
|
|||||||
:i="item.i"
|
:i="item.i"
|
||||||
:key="item.i"
|
:key="item.i"
|
||||||
@click="clickGrid(item)"
|
@click="clickGrid(item)"
|
||||||
|
@resized="resizedEvent"
|
||||||
:class="{ active: dashboardStore.activedGridItem === item.i }"
|
:class="{ active: dashboardStore.activedGridItem === item.i }"
|
||||||
>
|
>
|
||||||
<component
|
<component
|
||||||
@ -57,10 +58,14 @@ export default defineComponent({
|
|||||||
function clickGrid(item: LayoutConfig) {
|
function clickGrid(item: LayoutConfig) {
|
||||||
dashboardStore.activeGridItem(item.i);
|
dashboardStore.activeGridItem(item.i);
|
||||||
}
|
}
|
||||||
|
function resizedEvent() {
|
||||||
|
console.log("test");
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
dashboardStore,
|
dashboardStore,
|
||||||
layoutUpdatedEvent,
|
layoutUpdatedEvent,
|
||||||
clickGrid,
|
clickGrid,
|
||||||
|
resizedEvent,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user