119119
120120<script lang="ts" setup>
121121import { PrivateDataTypes } from " @/types/data" ;
122- import { computed , reactive , ref , toRef } from " vue" ;
122+ import { computed , reactive , ref , toRef , watchEffect } from " vue" ;
123123import FunctionField from " ./function.vue" ;
124124
125125import AnimatedList from " @/ui/animated/animatedList.vue" ;
@@ -133,30 +133,87 @@ const props = defineProps<{
133133const tab = ref (" derivate" );
134134const self = toRef (props , " self" );
135135
136- const derivateEnabled = ref (false );
137- const derivateFn = ref (" " );
138- const derivFollowMouseStr = ref (" followMouse" );
136+ const initDerivate = self .value .derivative ?? {
137+ fn: " " ,
138+ updateOnMouseMove: true ,
139+ x0: " " as number | " " ,
140+ };
141+
142+ const derivateEnabled = ref (self .value .derivative !== undefined );
143+ const derivateFn = ref (initDerivate .fn );
144+ const derivFollowMouseStr = ref (
145+ initDerivate .updateOnMouseMove ? " followMouse" : " manual"
146+ );
139147const derivFollowMouse = computed (
140148 () => derivFollowMouseStr .value === " followMouse"
141149);
142- const derivateX = ref (0 );
150+ const derivateX = ref <number | " " >(initDerivate .x0 ?? " " );
151+ const derivateReady = computed (
152+ (): undefined | PrivateDataTypes .LinearPart .Derivative => {
153+ if (! derivateEnabled .value ) return undefined ;
154+ if (derivFollowMouse .value )
155+ return {
156+ fn: derivateFn .value ,
157+ updateOnMouseMove: true ,
158+ };
159+ return {
160+ fn: derivateFn .value ,
161+ updateOnMouseMove: false ,
162+ x0: derivateX .value || 0 ,
163+ };
164+ }
165+ );
166+ watchEffect (() => {
167+ self .value .derivative = derivateReady .value ;
168+ });
143169
144- const secantEnabled = ref (false );
170+ const initSecant = self .value .secants ;
171+ const secantEnabled = ref (initSecant .length > 0 );
145172const secantArr = reactive <
146173 {
147174 key : number ;
148175 followMouse : boolean ;
149176 x1 : number | " " ;
150177 x2 : number | " " ;
151178 }[]
152- > ([]);
179+ > (
180+ initSecant .map ((item ) => ({
181+ key: Math .random (),
182+ followMouse: item .updateOnMouseMove ,
183+ x1: item .x0 ,
184+ x2: item .x1 || " " ,
185+ }))
186+ );
187+ const secantReady = computed ((): PrivateDataTypes .LinearPart .Secant [] => {
188+ if (! secantEnabled .value ) return [];
189+ return secantArr .flatMap ((item ) => {
190+ if (item .x1 === " " ) return [];
191+ if (item .followMouse )
192+ return {
193+ x0: item .x1 ,
194+ updateOnMouseMove: true ,
195+ };
196+ if (item .x2 === " " ) return [];
197+ return {
198+ x0: item .x1 ,
199+ x1: item .x2 ,
200+ updateOnMouseMove: false ,
201+ };
202+ });
203+ });
204+ watchEffect (() => {
205+ self .value .secants = secantReady .value ;
206+ });
153207 </script >
154208
155209<style lang="scss">
156210.derivate-pane {
157211 width : 25em ;
158212 s-tab {
159213 background-color : var (--s-color-surface-container-low );
214+ border-top-left-radius : 3px ;
215+ border-top-right-radius : 3px ;
216+ overflow : hidden ;
160217 }
161218 .tab-text {
162219 display : flex ;
@@ -172,7 +229,7 @@ const secantArr = reactive<
172229 & -leave-active {
173230 transition :
174231 opacity 0.1s ,
175- margin-left 0.5s cubic-bezier (0 , 1 , 0 , 1 );
232+ margin-left 0.5s cubic-bezier (0.075 , 0.82 , 0.165 , 1 );
176233 }
177234 & -leave-to ,
178235 & -enter-from {
0 commit comments