Skip to content

Commit 2bd0698

Browse files
committed
悬浮十字线选项
1 parent e39dfce commit 2bd0698

File tree

2 files changed

+86
-30
lines changed

2 files changed

+86
-30
lines changed

src/editor/options.vue

Lines changed: 75 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,75 +2,94 @@
22
<s-scroll-view>
33
<div id="options">
44
<!-- global -->
5-
<s-divider>{{ t("options.global") }}</s-divider>
6-
<div class="option">
5+
<s-divider class="options-divider">{{ t("options.global") }}</s-divider>
6+
<div class="fields">
77
<span class="label">{{ t("options.grid") }}</span>
88
<s-switch
99
v-model.lazy="profile.options.grid"
1010
type="checkbox"
11+
class="input"
1112
></s-switch>
12-
</div>
13-
<div class="option">
13+
14+
<span class="label">悬浮十字线</span>
15+
<div class="input checkboxes">
16+
<s-checkbox v-model.lazy="profile.options.tip.yLine" type="checkbox">
17+
横线
18+
</s-checkbox>
19+
<s-checkbox v-model.lazy="profile.options.tip.xLine" type="checkbox">
20+
竖线
21+
</s-checkbox>
22+
</div>
23+
1424
<span class="label">{{ t("options.title") }}</span>
1525
<s-text-field
1626
:label="t('options.title')"
1727
v-model="profile.options.title"
28+
class="input"
1829
></s-text-field>
1930
</div>
2031

2132
<!-- xAxis -->
22-
<s-divider>{{ t("options.horizontal") }}</s-divider>
23-
<div class="option">
33+
<s-divider class="options-divider">{{
34+
t("options.horizontal")
35+
}}</s-divider>
36+
<div class="fields">
2437
<span class="label">{{ t("options.axis.reverse") }}</span>
2538
<s-switch
2639
v-model.lazy="profile.options.xAxis.invert"
2740
type="checkbox"
41+
class="input"
2842
></s-switch>
29-
</div>
30-
<div class="option">
43+
3144
<span class="label">{{ t("options.axis.grow") }}</span>
32-
<s-segmented-button v-model.lazy="profile.options.xAxis.type">
45+
<s-segmented-button
46+
v-model.lazy="profile.options.xAxis.type"
47+
class="input"
48+
>
3349
<s-segmented-button-item value="linear">{{
3450
t("options.axis.linear")
3551
}}</s-segmented-button-item>
3652
<s-segmented-button-item value="log">
3753
{{ t("options.axis.log") }}
3854
</s-segmented-button-item>
3955
</s-segmented-button>
40-
</div>
41-
<div class="option">
56+
4257
<span class="label">{{ t("options.axis.caption") }}</span>
4358
<s-text-field
4459
:label="t('options.axis.caption')"
60+
class="input"
4561
v-model="profile.options.xAxis.label"
4662
></s-text-field>
4763
</div>
4864

4965
<!-- yAxis -->
50-
<s-divider>{{ t("options.vertical") }}</s-divider>
51-
<div class="option">
66+
<s-divider class="options-divider">{{ t("options.vertical") }}</s-divider>
67+
<div class="fields">
5268
<span class="label">{{ t("options.axis.reverse") }}</span>
5369
<s-switch
5470
v-model.lazy="profile.options.yAxis.invert"
5571
type="checkbox"
72+
class="input"
5673
></s-switch>
57-
</div>
58-
<div class="option">
74+
5975
<span class="label">{{ t("options.axis.grow") }}</span>
60-
<s-segmented-button v-model.lazy="profile.options.yAxis.type">
76+
<s-segmented-button
77+
v-model.lazy="profile.options.yAxis.type"
78+
class="input"
79+
>
6180
<s-segmented-button-item value="linear">{{
6281
t("options.axis.linear")
6382
}}</s-segmented-button-item>
6483
<s-segmented-button-item value="log">
6584
{{ t("options.axis.log") }}
6685
</s-segmented-button-item>
6786
</s-segmented-button>
68-
</div>
69-
<div class="option">
87+
7088
<span class="label">{{ t("options.axis.caption") }}</span>
7189
<s-text-field
7290
:label="t('options.axis.caption')"
7391
v-model="profile.options.yAxis.label"
92+
class="input"
7493
></s-text-field>
7594
</div>
7695
</div>
@@ -100,28 +119,55 @@ watch(
100119
);
101120
</script>
102121

103-
<style>
122+
<style lang="scss">
104123
#options {
105124
display: flex;
106125
flex-direction: column;
107126
gap: 10px;
108127
padding-top: 5px;
109-
}
110-
#options s-divider {
111-
font-size: 0.8em;
112-
margin: 5px 15px;
128+
font-size: 16px;
129+
130+
.options-divider {
131+
font-size: 0.8em;
132+
margin: 5px 15px;
133+
}
134+
135+
.fields {
136+
display: grid;
137+
grid-template-columns: max-content minmax(auto, 16em);
138+
justify-content: space-between;
139+
align-items: center;
140+
row-gap: 0.5em;
141+
column-gap: 1.5em;
142+
margin: 0 30px;
143+
144+
.label {
145+
justify-self: start;
146+
display: flex;
147+
}
148+
.input {
149+
justify-self: end;
150+
}
151+
.checkboxes {
152+
display: flex;
153+
gap: 1em;
154+
}
155+
s-text-field.input {
156+
width: 100%;
157+
}
158+
}
113159
}
114160
.option {
115161
display: flex;
116162
flex-wrap: wrap;
117163
align-items: center;
118164
justify-content: space-between;
119165
margin: 0 30px;
120-
}
121-
.option span {
122-
line-height: 2em;
123-
}
124-
.option s-text-field {
125-
max-width: 100%;
166+
span {
167+
line-height: 2em;
168+
}
169+
s-text-field {
170+
max-width: 100%;
171+
}
126172
}
127173
</style>

src/types/options.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export type PrivateOptions = {
1212
yAxis: PrivateAxis;
1313
grid: boolean;
1414
title: string;
15+
tip: {
16+
xLine: boolean;
17+
yLine: boolean;
18+
};
1519
};
1620

1721
const defaultAxis = {
@@ -23,12 +27,16 @@ const defaultAxis = {
2327
export function toPrivateOptions(
2428
original: Partial<FunctionPlotOptions>
2529
): PrivateOptions {
26-
const { xAxis, yAxis, title, grid } = original;
30+
const { xAxis, yAxis, title, grid, tip = {} } = original;
2731
return amendAttr<PrivateOptions>(
2832
{ xAxis, yAxis, title, grid },
2933
{
3034
xAxis: () => amendAttr<PrivateAxis>(xAxis ?? {}, defaultAxis),
3135
yAxis: () => amendAttr<PrivateAxis>(yAxis ?? {}, defaultAxis),
36+
tip: () => ({
37+
xLine: tip?.xLine ?? false,
38+
yLine: tip?.yLine ?? false,
39+
}),
3240
title: "",
3341
grid: false,
3442
}
@@ -45,11 +53,13 @@ export const toPublicOptions = (
4553
...options,
4654
xAxis: omitAttr(options.xAxis, defaultAxis),
4755
yAxis: omitAttr(options.yAxis, defaultAxis),
56+
tip: omitAttr(options.tip, { xLine: false, yLine: false }),
4857
},
4958
{
5059
title: "",
5160
grid: false,
5261
xAxis: checkObjEmpty,
5362
yAxis: checkObjEmpty,
63+
tip: checkObjEmpty,
5464
}
5565
);

0 commit comments

Comments
 (0)