@@ -30,18 +30,14 @@ import { onMounted, onUnmounted, ref, watch, WatchHandle } from "vue";
3030import { throttle } from " lodash-es" ;
3131import type { FunctionPlotDatum } from " function-plot" ;
3232import { getFnType } from " ../consts" ;
33- const { width, height } = defineProps <{
34- width: number ;
35- height: number ;
36- }>();
3733
3834import { useProfile } from " @/states" ;
3935const profile = useProfile ();
4036
4137import emitter from " @/mitt" ;
4238const fullUpdateState = defineModel <boolean >();
4339
44- const plotRef = ref <HTMLDivElement | null >( null );
40+ const plotRef = ref <HTMLDivElement >( );
4541const errorMsg = ref <string | undefined >(undefined );
4642
4743function findError(graphData : FunctionPlotDatum []) {
@@ -54,6 +50,9 @@ function findError(graphData: FunctionPlotDatum[]) {
5450 return 0 ;
5551}
5652
53+ import { useElementSize } from " @vueuse/core" ;
54+ const { width, height } = useElementSize (plotRef );
55+
5756let unwatchHandler: WatchHandle | null = null ;
5857const emit = defineEmits ([" require-post-update" ]);
5958import functionPlot from " function-plot" ;
@@ -71,8 +70,8 @@ onMounted(() => {
7170 functionPlot ({
7271 target: plotRef .value ,
7372 data: graphData ,
74- width: width - 20 ,
75- height: height - 20 ,
73+ width: width . value ,
74+ height: height . value ,
7675 annotations: profile .getOriginalAnnotaion (),
7776 ... profile .getOriginalOptions (),
7877 });
@@ -85,8 +84,8 @@ onMounted(() => {
8584 if (! fullUpdateState .value ) emitter .emit (" require-full-update" , " error" );
8685 errorMsg .value = (e as Error ).message ;
8786 }
88- }, 200 );
89- unwatchHandler = watch ([() => width , () => height , profile ], handleUpdate , {
87+ }, 250 );
88+ unwatchHandler = watch ([width , height , profile ], handleUpdate , {
9089 immediate: true ,
9190 });
9291});
@@ -99,12 +98,10 @@ onUnmounted(() => {
9998<style >
10099#graphRender {
101100 position : absolute ;
102- top : 0 ;
103- right : 0 ;
104- left : 0 ;
105- bottom : 0 ;
106- width : fit-content ;
107- height : fit-content ;
101+ top : 10px ;
102+ right : 10px ;
103+ left : 10px ;
104+ bottom : 10px ;
108105 margin : auto ;
109106 color : black ;
110107 user-select : none ;
0 commit comments