1313 v-model =" graphData[i]"
1414 @delete =" graphData.splice(i, 1)"
1515 :key =" dataItem.key"
16+ @require-full-update =" fullUpdate"
1617 />
1718 </VueDraggable >
1819 <div class =" plot-data add-data" >
2526 <div @click =" handleImport()" class =" add-data-opt import" >↓ 导入</div >
2627 </div >
2728 </div >
28- <CodeDisplay :dataArr =" cloneDeep (graphData)" />
29+ <CodeDisplay :dataArr =" cloneArr (graphData)" />
2930 </div >
3031 <div id =" divider" @mousedown =" handleDrag" ></div >
3132 <div id =" graph" ref =" shellRef" >
3233 <Graph
33- :graphData = " cloneDeep (graphData)"
34+ :data = " cloneArr (graphData)"
3435 :width =" graphWidth"
3536 :height =" graphHeight"
3637 :key =" key"
38+ @requireFullUpdate =" fullUpdate"
39+ @requirePostUpdate =" key++"
40+ v-model =" fullUpdateState"
3741 />
3842 </div >
3943 </div >
@@ -46,17 +50,19 @@ import DataBlock from "./components/dataBlock.vue";
4650import CodeDisplay from " ./components/codeDisplay.vue" ;
4751import { VueDraggable } from " vue-draggable-plus" ;
4852import type { FunctionPlotDatum , FunctionPlotOptions } from " function-plot" ;
49- import { onMounted , ref , watch } from " vue" ;
53+ import { onMounted , ref } from " vue" ;
5054import { cloneDeep } from " lodash-es" ;
5155import JSON5 from " json5" ;
5256import base64 from " base-64" ;
5357import utf8 from " utf8" ;
5458import { Datum } from " ./consts" ;
5559
5660const graphData = ref <Datum []>([{ fn: " x^2" , key: 1 }]);
61+
5762const graphWidth = ref (0 ),
5863 graphHeight = ref (0 );
5964const key = ref (0 );
65+ const fullUpdateState = ref (false );
6066const sideRatio = ref (33 );
6167const onResize = ref (false );
6268const shellRef = ref <HTMLDivElement >();
@@ -67,6 +73,24 @@ function handleResize() {
6773 }
6874}
6975
76+ function cloneArr<T extends Object []>(obj : T ) {
77+ const cloned = cloneDeep (obj );
78+ function removeUndefined(obj : Record <string , any >) {
79+ for (const key in obj ) {
80+ console .log (1 );
81+ if (obj [key ] === undefined ) delete obj [key ];
82+ if (
83+ typeof obj [key ] === " object" &&
84+ obj [key ] !== null &&
85+ ! Array .isArray (obj [key ])
86+ )
87+ removeUndefined (obj [key ]);
88+ }
89+ }
90+ cloned .forEach ((item ) => removeUndefined (item ));
91+ return cloned as T ;
92+ }
93+
7094function importMapper(item : FunctionPlotDatum ): Datum {
7195 if (item .graphType === " text" )
7296 return {
@@ -81,6 +105,11 @@ function importMapper(item: FunctionPlotDatum): Datum {
81105 };
82106}
83107
108+ function fullUpdate() {
109+ fullUpdateState .value = true ;
110+ key .value ++ ;
111+ }
112+
84113onMounted (() => {
85114 const rawCode = window .location .search .match (/ \? code=(. + )$ / )?.[1 ];
86115 if (rawCode )
@@ -96,11 +125,11 @@ onMounted(() => {
96125
97126 window .addEventListener (" resize" , handleResize );
98127 handleResize ();
99- watch (graphData , () => key .value ++ , { deep: true });
100128});
129+
101130function handleDrag() {
102131 onResize .value = true ;
103- const xfull = outerWidth ;
132+ const xfull = window . innerWidth ;
104133 const mousemove = (event : MouseEvent ) =>
105134 (sideRatio .value = (event .clientX / xfull ) * 100 );
106135 document .addEventListener (" mousemove" , mousemove );
@@ -110,6 +139,7 @@ function handleDrag() {
110139 handleResize ();
111140 });
112141}
142+
113143function handleImport() {
114144 const raw = prompt (" 源数据:" );
115145 if (! raw ) return ;
0 commit comments