11<template >
22 <Navbar />
3- <div id =" content" >
4- <div id =" editor" >
3+ <div id =" content" :class = " { onresize: onResize } " >
4+ <div id =" editor" :style = " { width: sideRatio + 'vw' } " >
55 <div class =" editor-inner" >
6- <DataBlock
7- v-for =" (_dataItem, i) in graphData"
8- v-model =" graphData[i]"
9- @delete =" graphData.splice(i, 1)"
10- />
11- <div class =" plot-data add-data" @click =" graphData.push({})" >+ 添加</div >
6+ <VueDraggable v-model =" graphData" :animation =" 150" handle =" .datablock-drag" >
7+ <DataBlock
8+ v-for =" (dataItem, i) in graphData"
9+ v-model =" graphData[i]"
10+ @delete =" graphData.splice(i, 1)"
11+ :key =" dataItem.key"
12+ />
13+ </VueDraggable >
14+ <div
15+ class =" plot-data add-data"
16+ @click =" graphData.push({ key: Math.random() })"
17+ >
18+ + 添加
19+ </div >
1220 </div >
1321 <CodeDisplay :dataArr =" cloneDeep(graphData)" />
1422 </div >
15- <Graph :key =" graphKey" :graphData =" cloneDeep(graphData)" ref =" graphRef" />
23+ <div id =" divider" @mousedown =" handleDrag" ></div >
24+ <div id =" graph" ref =" shellRef" >
25+ <Graph
26+ :graphData =" cloneDeep(graphData)"
27+ :width =" graphWidth"
28+ :height =" graphHeight"
29+ />
30+ </div >
1631 </div >
1732</template >
1833
@@ -21,13 +36,40 @@ import Navbar from "./components/nav.vue";
2136import Graph from " ./components/graph.vue" ;
2237import DataBlock from " ./components/dataBlock.vue" ;
2338import CodeDisplay from " ./components/codeDisplay.vue" ;
39+ import { VueDraggable } from " vue-draggable-plus" ;
2440import type { FunctionPlotDatum } from " function-plot" ;
25- import { reactive , ref } from " vue" ;
41+ import { onMounted , ref } from " vue" ;
2642import { cloneDeep } from " lodash-es" ;
27-
28- const graphRef = ref <InstanceType <typeof Graph >>();
29- const graphData = reactive <FunctionPlotDatum []>([{ fn: " x^2" }]);
30- const graphKey = ref (0 );
43+ const graphData = ref <(FunctionPlotDatum & { key: number })[]>([
44+ { fn: " x^2" , key: 1 },
45+ ]);
46+ const graphWidth = ref (0 ),
47+ graphHeight = ref (0 );
48+ const sideRatio = ref (33 );
49+ const onResize = ref (false );
50+ const shellRef = ref <HTMLDivElement >();
51+ function handleResize() {
52+ if (shellRef .value ) {
53+ graphWidth .value = shellRef .value .clientWidth ;
54+ graphHeight .value = shellRef .value .clientHeight ;
55+ }
56+ }
57+ onMounted (() => {
58+ window .addEventListener (" resize" , handleResize );
59+ handleResize ();
60+ });
61+ function handleDrag() {
62+ onResize .value = true ;
63+ const xfull = outerWidth ;
64+ const mousemove = (event : MouseEvent ) =>
65+ (sideRatio .value = (event .clientX / xfull ) * 100 );
66+ document .addEventListener (" mousemove" , mousemove );
67+ document .addEventListener (" mouseup" , () => {
68+ document .removeEventListener (" mousemove" , mousemove );
69+ onResize .value = false ;
70+ handleResize ();
71+ });
72+ }
3173 </script >
3274
3375<style >
@@ -59,7 +101,6 @@ const graphKey = ref(0);
59101 flex-shrink : 0 ;
60102}
61103#editor {
62- width : 33vw ;
63104 border-right : var (--c-border ) 1px solid ;
64105 position : relative ;
65106}
@@ -74,6 +115,7 @@ const graphKey = ref(0);
74115#graph {
75116 flex-grow : 1 ;
76117 position : relative ;
118+ overflow : hidden ;
77119}
78120.add-data {
79121 padding-top : 10px ;
@@ -87,30 +129,26 @@ const graphKey = ref(0);
87129.add-data :active {
88130 background : var (--c-bk1 );
89131}
90- .plot-data.output {
91- position : absolute ;
92- left : 0 ;
93- right : 0 ;
94- bottom : 0 ;
95- border-top : var (--c-border ) 1px solid ;
96- padding : 20px 15px ;
97- height : 260px ;
132+
133+ #divider {
134+ width : 6px ;
135+ background : var (--c-accent );
136+ margin-left : -3px ;
137+ margin-right : -3px ;
138+ z-index : 999 ;
139+ opacity : 0 ;
140+ transition : opacity 0.1s ;
141+ cursor : w-resize ;
98142}
99- .plot-data.output .output-title {
100- font-size : 20px ;
101- font-weight : bold ;
102- display : block ;
103- margin-bottom : 10px ;
143+ #divider :hover {
144+ opacity : 0.8 ;
104145}
105- .plot-data.output pre {
106- position : absolute ;
107- top : 60px ;
108- bottom : 15px ;
109- left : 15px ;
110- right : 15px ;
111- margin : 0 ;
112- overflow : scroll ;
113- user-select : all ;
146+ .onresize #divider {
147+ opacity : 0.3 ;
148+ transition : none ;
149+ }
150+ .onresize {
151+ cursor : w-resize ;
152+ user-select : none ;
114153}
115-
116154 </style >
0 commit comments