forked from Linho1219/function-plot-GUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.vue
More file actions
221 lines (202 loc) · 5.28 KB
/
data.vue
File metadata and controls
221 lines (202 loc) · 5.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<template>
<div class="plot-data" :class="{ hidden: props.self.hidden }">
<div class="selectors">
<!-- fnType Picker -->
<s-picker
:label="t('data.main.fnType')"
v-model.lazy="fnType"
:key="selectKey"
>
<s-picker-item v-for="type in fnTypeArr" :value="type.value">
{{ t("data.fnType." + type.value) }}
</s-picker-item>
</s-picker>
<!-- graphType Picker -->
<s-picker
:label="t('data.main.graphType')"
v-model.lazy="props.self.graphType"
v-show="props.self.graphType !== 'text'"
:key="selectKey"
>
<s-picker-item v-for="type in allowedGraphType" :value="type.value">
{{ t("data.graphType." + type.value) }}
</s-picker-item>
</s-picker>
<div style="flex-grow: 1"></div>
<!-- Buttons -->
<div class="dataBlockBtns">
<!-- Delete -->
<s-tooltip>
<s-icon-button
slot="trigger"
@click="deleteDatum"
style="color: var(--s-color-error)"
>
<SIconDelete />
</s-icon-button>
{{ t("data.topButton.delete") }}
</s-tooltip>
<!-- Hide -->
<s-tooltip>
<s-icon-button
slot="trigger"
@click="props.self.hidden = !props.self.hidden"
:type="props.self.hidden ? 'filled-tonal' : 'standard'"
>
<SIconHide />
</s-icon-button>
{{ t("data.topButton.hide") }}
</s-tooltip>
<!-- Fold -->
<s-tooltip>
<s-icon-button slot="trigger" @click="folded = !folded">
<s-icon :name="folded ? 'chevron_down' : 'chevron_up'"> </s-icon>
</s-icon-button>
{{ t(`data.topButton.${folded ? "more" : "less"}`) }}
</s-tooltip>
<!-- Drag -->
<span class="datablock-drag drag-icon">
<SIconDrag />
</span>
</div>
</div>
<div class="relative">
<component
:is="components[props.self.fnType]"
:self="<PrivateDataTypes.Full>props.self"
:index="props.index"
:folded="folded"
/>
</div>
</div>
</template>
<script setup lang="ts">
import { useI18n } from "vue-i18n";
import { I18nSchema } from "@/i18n";
const { locale, t } = useI18n<{ message: I18nSchema }>();
import { fnTypeArr, getAllowedGraphType } from "../consts";
import { ref, computed, toRef } from "vue";
import linear from "./inputs/linear.vue";
import implicit from "./inputs/implicit.vue";
import parametric from "./inputs/parametric.vue";
import polar from "./inputs/polar.vue";
import points from "./inputs/points.vue";
import vector from "./inputs/vector.vue";
import text from "./inputs/text.vue";
const components = {
linear,
implicit,
parametric,
polar,
points,
vector,
text,
} as const;
import SIconDelete from "@/ui/icons/delete.vue";
import SIconHide from "@/ui/icons/hide.vue";
import SIconDrag from "@/ui/icons/drag.vue";
const props = defineProps<{ index: number; self: PrivateData }>();
const folded = ref(true);
import { Snackbar } from "sober";
import { useProfile } from "@/states";
const profile = useProfile();
function deleteDatum() {
const backup = props.self;
profile.datum.splice(props.index, 1);
Snackbar.builder({
text: t("editor.delete.success"),
action: {
text: t("editor.delete.undo"),
click: () => {
profile.datum.splice(props.index, 0, backup);
},
},
});
}
const allowedGraphType = computed(() => getAllowedGraphType(props.self.fnType));
import { watch } from "vue";
import { PrivateData, PrivateDataTypes, toPrivateData } from "@/types/data";
const selectKey = ref(0);
watch(locale, () => selectKey.value++);
const self = toRef(profile.datum, props.index);
const fnType = ref(props.self.fnType);
watch(fnType, (newFnType) => {
const newGraphType = (<readonly string[]>(
PrivateDataTypes.allowedGraphTypes[newFnType]
)).includes(props.self.graphType)
? props.self.graphType
: PrivateDataTypes.allowedGraphTypes[newFnType][0];
self.value = toPrivateData({
key: self.value.key,
fnType: newFnType,
graphType: newGraphType,
});
});
watch(
() => props.self.graphType,
(newGraphType) => {
if (newGraphType === "scatter" && "closed" in self.value)
self.value.closed = false;
}
);
</script>
<style>
.inputs {
display: flex;
flex-direction: column;
gap: 10px;
}
.inputs.optional {
margin-top: 10px;
margin-bottom: 5px;
}
.inputs .input-box {
position: relative;
display: flex;
}
.plot-data {
position: relative;
padding: 20px 15px;
overflow: hidden;
transition:
opacity 0.15s,
filter 0.15s;
}
.plot-data.hidden {
opacity: 0.6;
filter: saturate(0.8);
}
.datumFolder {
border-bottom: var(--s-color-outline-variant) 1px solid;
}
.selectors {
margin-bottom: 10px;
position: relative;
display: flex;
gap: 10px;
align-items: center;
flex-wrap: wrap-reverse;
justify-content: flex-end;
}
.selectors s-picker {
width: 8em;
}
.dataBlockBtns {
display: flex;
}
.drag-icon {
width: 40px;
height: 40px;
text-align: center;
border-radius: 50%;
cursor: grab;
display: inline-flex;
justify-content: center;
}
.sortable-chosen .drag-icon {
background: var(--s-color-outline-variant);
}
.sortable-chosen {
z-index: 999;
}
</style>