|
1 | 1 | <template> |
2 | 2 | <Navbar /> |
3 | 3 | <div id="content"> |
4 | | - <div id="editor" @click="graphData.push({ fn: 'sin(x)' })">{{ graphData }}</div> |
| 4 | + <div id="editor"> |
| 5 | + <div v-for="dataItem in graphData" class="plot-data"> |
| 6 | + <select |
| 7 | + v-model="dataItem.fnType" |
| 8 | + @change=" |
| 9 | + getFnType(dataItem.fnType).notAllowedInIntervel && |
| 10 | + !dataItem.graphType && |
| 11 | + (dataItem.graphType = 'polyline') |
| 12 | + " |
| 13 | + > |
| 14 | + <option :value="undefined">{{ fnTypeArr[0].label }}</option> |
| 15 | + <option v-for="type in fnTypeArr.slice(1)" :value="type.value"> |
| 16 | + {{ type.label }} |
| 17 | + </option> |
| 18 | + </select> |
| 19 | + |
| 20 | + <select v-model="dataItem.graphType"> |
| 21 | + <option |
| 22 | + v-if="!getFnType(dataItem.fnType).notAllowedInIntervel" |
| 23 | + :value="undefined" |
| 24 | + > |
| 25 | + {{ graphTypeArr[0].label }} |
| 26 | + </option> |
| 27 | + <option v-for="type in graphTypeArr.slice(1)" :value="type.value"> |
| 28 | + {{ type.label }} |
| 29 | + </option> |
| 30 | + </select> |
| 31 | + <div class="input-wrapper"> |
| 32 | + <input |
| 33 | + v-for="input in inputArr.filter(({ value }) => { |
| 34 | + const inputs = getFnType(dataItem.fnType).inputs; |
| 35 | + if (inputs.includes(value)) return true; |
| 36 | + else delete dataItem[value]; |
| 37 | + })" |
| 38 | + type="text" |
| 39 | + v-model="dataItem[input.value]" |
| 40 | + /> |
| 41 | + </div> |
| 42 | + </div> |
| 43 | + <div class="add-data" @click="graphData.push({})">+ 添加</div> |
| 44 | + {{ graphData }} |
| 45 | + </div> |
5 | 46 | <Graph :graphData="graphData" /> |
6 | 47 | </div> |
7 | 48 | </template> |
|
10 | 51 | import Navbar from "./components/nav.vue"; |
11 | 52 | import Graph from "./components/graph.vue"; |
12 | 53 | import type { FunctionPlotDatum } from "function-plot"; |
13 | | -
|
14 | | -import { reactive, ref, watch } from "vue"; |
15 | | -const graphData = ref([{ fn: 'x^2' }]); |
16 | | -const cnt = ref(0); |
17 | | -watch(graphData, () => cnt.value++,{deep:true}); |
| 54 | +import { reactive } from "vue"; |
| 55 | +import { fnTypeArr, graphTypeArr, inputArr } from "./consts"; |
| 56 | +import type { FnType, ValueLabel } from "./consts"; |
| 57 | +const graphData = reactive<FunctionPlotDatum[]>([{ fn: "x^2" }]); |
| 58 | +const getFnType = (fnType?: string) => |
| 59 | + <FnType>fnTypeArr.find(({ value }) => value === (fnType || "linear")); |
18 | 60 | </script> |
19 | 61 |
|
20 | 62 | <style> |
|
0 commit comments