Skip to content

Commit 37e7c74

Browse files
committed
定义域设置
1 parent 274a631 commit 37e7c74

File tree

4 files changed

+86
-18
lines changed

4 files changed

+86
-18
lines changed

src/editor/inputs/inputs.scss

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,14 @@
3434
padding: 0 15px;
3535
.fields {
3636
display: grid;
37-
grid-template-columns: max-content minmax(auto, 20em);
37+
grid-template-columns: max-content minmax(auto, 18em);
3838
justify-content: space-between;
3939
align-items: center;
4040
gap: var(--input-inner-gap);
4141
}
4242
s-text-field {
4343
width: 100%;
4444
font-size: inherit;
45-
&.styled {
46-
font-size: 1.1em;
47-
}
4845
}
4946
.label {
5047
justify-self: start;

src/editor/inputs/linear.vue

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
<s-divider>{{ t("title.moreOptions") }}</s-divider>
99
<div class="input-inner-optional">
1010
<div class="fields">
11+
<span class="label">定义域</span>
12+
<Domain :self="self" />
1113
<span class="label">
12-
颜色 <HelpIcon> 支持颜色名称 / RGB(A) / HEX </HelpIcon>
14+
颜色 <HelpIcon> 支持颜色名称 / RGB(A) / HEX,留空将自动着色 </HelpIcon>
1315
</span>
1416
<ColorPicker v-model="self.color" />
15-
<span class="label">采样数</span>
17+
<span class="label"
18+
>采样数 <HelpIcon> 留空则根据图像宽度动态调整 </HelpIcon>
19+
</span>
1620
<s-text-field
1721
class="input monospace"
1822
type="number"
@@ -27,8 +31,8 @@
2731
闭合并填充
2832
</s-checkbox>
2933
<s-checkbox type="checkbox" v-model.lazy="self.skipTip">
30-
不显示指示条
31-
<HelpIcon> 鼠标经过时标出的点及其坐标 </HelpIcon>
34+
隐藏悬浮指示条
35+
<HelpIcon> 隐藏鼠标经过时标出的点与坐标信息 </HelpIcon>
3236
</s-checkbox>
3337
</div>
3438
</div>
@@ -52,5 +56,6 @@ const self = toRef(props, "self");
5256
import FilledTextfield from "./subblocks/function.vue";
5357
import HelpIcon from "./subblocks/helpIcon.vue";
5458
import ColorPicker from "./subblocks/colorPicker.vue";
59+
import Domain from "./subblocks/domain.vue";
5560
import "./inputs.scss";
5661
</script>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<template>
2+
<div class="input domain">
3+
<s-text-field
4+
class="domain-input styled-inner"
5+
type="number"
6+
v-model="value1"
7+
label="最小值"
8+
></s-text-field>
9+
<s-text-field
10+
class="domain-input styled-inner"
11+
type="number"
12+
v-model="value2"
13+
label="最大值"
14+
></s-text-field>
15+
</div>
16+
</template>
17+
18+
<script setup lang="ts">
19+
import { PrivateDataTypes } from "@/types/data";
20+
import { ref, watch } from "vue";
21+
const props = defineProps<{ self: PrivateDataTypes.Functions }>();
22+
const infToUndefined = (value: number) =>
23+
value === Infinity || value === -Infinity ? "" : value;
24+
const undefinedToInf = (value: number | "" | undefined, sign: number) =>
25+
value === "" || value === undefined ? sign * Infinity : value;
26+
const value1 = ref<number | "">(infToUndefined(props.self.range[0]));
27+
const value2 = ref<number | "">(infToUndefined(props.self.range[1]));
28+
29+
watch(value1, (newVal) => {
30+
props.self.range[0] = undefinedToInf(newVal, -1);
31+
});
32+
watch(value2, (newVal) => {
33+
props.self.range[1] = undefinedToInf(newVal, 1);
34+
});
35+
</script>
36+
37+
<style lang="scss">
38+
.input-inner .input.domain {
39+
display: flex;
40+
width: 100%;
41+
gap: 6px;
42+
.domain-input {
43+
width: 0;
44+
flex-grow: 1;
45+
&::part(input) {
46+
font-size: 1.25em;
47+
}
48+
}
49+
}
50+
</style>

src/types/data.ts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export namespace PrivateDataTypes {
1313
skipTip: boolean;
1414
nSamples: number | undefined;
1515
closed: boolean;
16+
range: [number, number];
1617
};
1718

1819
export const allowedGraphTypes = {
@@ -81,6 +82,8 @@ export namespace PrivateDataTypes {
8182
| Vector
8283
| Text;
8384

85+
export type Functions = Linear | Implicit | Parametric | Polar;
86+
8487
export type Full = Linear &
8588
Implicit &
8689
Parametric &
@@ -105,16 +108,28 @@ export function toPublicData(data: PrivateData): FunctionPlotDatum {
105108
color: "",
106109
}
107110
);
108-
return omitAttr(cloneDeep(data), {
109-
key: () => true,
110-
fnType: "linear",
111-
graphType: "interval",
112-
skipTip: false,
113-
closed: false,
114-
hidden: false,
115-
color: "",
116-
nSamples: undefined,
117-
});
111+
return omitAttr(
112+
cloneDeep({
113+
...data,
114+
range: ((): [number, number] | undefined => {
115+
if (!("range" in data)) return undefined;
116+
let [v1, v2] = data.range;
117+
if (v1 === -Infinity && v2 === Infinity) return undefined;
118+
return data.range;
119+
})(),
120+
}),
121+
{
122+
key: () => true,
123+
fnType: "linear",
124+
graphType: "interval",
125+
skipTip: false,
126+
closed: false,
127+
hidden: false,
128+
color: "",
129+
nSamples: undefined,
130+
range: (range) => range === undefined,
131+
}
132+
);
118133
}
119134

120135
export function toPrivateData(input: Object) {
@@ -129,6 +144,7 @@ export function toPrivateData(input: Object) {
129144
skipTip: false,
130145
closed: false,
131146
nSamples: undefined,
147+
range: () => [-Infinity, Infinity] as [number, number],
132148
});
133149
switch (data.fnType) {
134150
case "linear":

0 commit comments

Comments
 (0)