11<template >
22 <div id =" graphRender" ref =" plotRef" ></div >
3-
4- <s-tooltip id =" refresh" align =" bottom" >
5- <s-icon-button slot =" trigger" @click =" emit('requireFullUpdate')" >
6- <s-icon >
7- <svg viewBox =" 0 -960 960 960" >
8- <path
9- d =" M480-160q-134 0-227-93t-93-227q0-134 93-227t227-93q69 0 132 28.5T720-690v-110h80v280H520v-80h168q-32-56-87.5-88T480-720q-100 0-170 70t-70 170q0 100 70 170t170 70q77 0 139-44t87-116h84q-28 106-114 173t-196 67Z"
10- ></path >
11- </svg >
12- </s-icon >
13- </s-icon-button >
14- {{ t("buttons.reset") }}
15- </s-tooltip >
3+ <div class =" buttons" id =" topright" >
4+ <s-tooltip align =" right" >
5+ <s-icon-button slot =" trigger" @click =" emit('requireFullUpdate')" >
6+ <s-icon >
7+ <svg viewBox =" 0 -960 960 960" >
8+ <path
9+ d =" M480-160q-134 0-227-93t-93-227q0-134 93-227t227-93q69 0 132 28.5T720-690v-110h80v280H520v-80h168q-32-56-87.5-88T480-720q-100 0-170 70t-70 170q0 100 70 170t170 70q77 0 139-44t87-116h84q-28 106-114 173t-196 67Z"
10+ ></path >
11+ </svg >
12+ </s-icon >
13+ </s-icon-button >
14+ {{ t("buttons.reset") }}
15+ </s-tooltip >
16+ <s-tooltip align =" right" v-if =" errorMsg !== undefined" >
17+ <s-icon-button slot =" trigger" >
18+ <s-icon id =" warningIcon" >
19+ <svg viewBox =" 0 -960 960 960" >
20+ <path
21+ d =" m40-120 440-760 440 760H40Zm138-80h604L480-720 178-200Zm302-40q17 0 28.5-11.5T520-280q0-17-11.5-28.5T480-320q-17 0-28.5 11.5T440-280q0 17 11.5 28.5T480-240Zm-40-120h80v-200h-80v200Zm40-100Z"
22+ ></path >
23+ </svg >
24+ </s-icon >
25+ </s-icon-button >
26+ <pre class =" tooltipMsgPre" >{{ errorMsg }}</pre >
27+ </s-tooltip >
28+ </div >
1629</template >
1730
1831<script setup lang="ts">
@@ -22,7 +35,7 @@ const { t } = useI18n();
2235import { onMounted , ref , watch } from " vue" ;
2336import { cloneDeep , throttle } from " lodash-es" ;
2437import type { FunctionPlotDatum } from " function-plot" ;
25- import { findError } from " ../consts" ;
38+ import { getFnType } from " ../consts" ;
2639const { data, width, height } = defineProps <{
2740 data: FunctionPlotDatum [];
2841 width: number ;
@@ -32,14 +45,29 @@ const emit = defineEmits(["requireFullUpdate", "requirePostUpdate"]);
3245const fullUpdateState = defineModel <boolean >();
3346
3447const plotRef = ref <HTMLDivElement | null >(null );
48+ const errorMsg = ref <string | undefined >(undefined );
49+
50+ function findError(graphData : FunctionPlotDatum []) {
51+ for (const [index, dataItem] of graphData .entries ()) {
52+ const fnType = getFnType (dataItem .fnType );
53+ for (const input of fnType .inputs ) if (! dataItem [input .value ]) return index ;
54+ for (const coord of fnType .coord ?? [])
55+ if (! dataItem [coord .value ] && ! coord .optional ) return index ;
56+ }
57+ return 0 ;
58+ }
59+
3560onMounted (async () => {
3661 const functionPlot = (await import (" function-plot" )).default ;
3762 watch (
3863 [() => width , () => height , () => data ],
3964 throttle (() => {
4065 const graphData = cloneDeep (data );
4166 const flag = findError (graphData );
42- if (flag ) return ;
67+ if (flag ) {
68+ errorMsg .value = ` Invalid input in function ${flag + 1 } ` ;
69+ return ;
70+ }
4371 try {
4472 plotRef .value &&
4573 functionPlot ({
@@ -54,10 +82,11 @@ onMounted(async () => {
5482 if (fullUpdateState .value ) {
5583 fullUpdateState .value = false ;
5684 emit (" requirePostUpdate" );
57- }
85+ } else errorMsg . value = undefined ;
5886 } catch (e ) {
5987 // console.log(e);
6088 if (! fullUpdateState .value ) emit (" requireFullUpdate" );
89+ errorMsg .value = (e as Error ).message ;
6190 }
6291 }, 200 ),
6392 { immediate: true }
@@ -90,9 +119,21 @@ onMounted(async () => {
90119 display : none ;
91120}
92121
93- #refresh {
122+ #topright {
94123 position : absolute ;
95124 top : 25px ;
96125 right : 25px ;
126+ display : flex ;
127+ flex-direction : column ;
128+ }
129+
130+ #warningIcon {
131+ color : var (--s-color-warning );
132+ }
133+
134+ .tooltipMsgPre {
135+ margin : 0 ;
136+ padding : 0 ;
137+ font-size : 14px ;
97138}
98139 </style >
0 commit comments