Skip to content

Commit

Permalink
perf: 优化按键热力图样式 and more
Browse files Browse the repository at this point in the history
  • Loading branch information
nopdan committed Mar 14, 2024
1 parent b6ba7a8 commit 11d71c8
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 298 deletions.
2 changes: 1 addition & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>赛码器 Go</title>
<title>昙花赛码器</title>
</head>

<body>
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import Main from "./components/Main.vue";
</div>
</n-message-provider>
</template>
<style>
<style scoped>
.content {
margin: auto;
max-width: 700px;
min-height: 90vh;
display: flex;
flex-direction: column;
align-items: center;
Expand All @@ -29,9 +28,9 @@ import Main from "./components/Main.vue";
background-image: linear-gradient(to right, orange, rgb(197, 4, 245));
background-clip: text;
color: transparent;
font-size: xx-large;
font-size: 2rem;
font-weight: bold;
padding: 12px;
padding: 12px 0;
font-family: Baskerville, Georgia, "Liberation Serif", "Kaiti SC", STKaiti, "AR PL UKai CN", "AR PL UKai HK",
"AR PL UKai TW", "AR PL UKai TW MBE", "AR PL KaitiM GB", KaiTi, KaiTi_GB2312, DFKai-SB, "TW\-Kai", serif;
}
Expand Down
21 changes: 11 additions & 10 deletions frontend/src/components/FingerHeatMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@ import { Data } from "./Data";
const props = defineProps<{
data: Data;
colspan: number;
name: string;
num: number;
}>();
</script>

<template>
<div
class="heat-key"
:style="{
'background-color': `rgb(80, 80, 255, ${(data.Dist.Finger[num] || 0) / data.Keys.Count / 0.3})`,
}"
>
<div style="font-size: 0.8em; color: #000; white-space: nowrap">{{ name }}</div>
<div style="font-size: 0.3em; color: #333; white-space: nowrap">
{{ ((data.Dist.Finger[num] / data.Keys.Count) * 100 || 0).toFixed(2) }}
<div class="heat-key-container">
<div
class="heat-key"
:style="{
'background-color': `rgb(80, 80, 255, ${(data.Dist.Finger[num] || 0) / data.Keys.Count / 0.3})`,
}"
>
<div class="key-label">{{ name }}</div>
<div class="key-rate">
{{ ((data.Dist.Finger[num] / data.Keys.Count) * 100 || 0).toFixed(2) }}
</div>
</div>
</div>
</template>
Expand Down
37 changes: 27 additions & 10 deletions frontend/src/components/HeatMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,42 @@ const props = defineProps<{
</script>

<template>
<div
class="heat-key"
:style="{
'background-color': `rgb(255, 0, 0, ${(data.Dist.Key[_key] || 0) / data.Keys.Count / 0.13})`,
}"
>
<div style="font-size: 0.8em; color: #000; white-space: nowrap">{{ _key.toUpperCase() }}</div>
<div style="font-size: 0.3em; color: #555; white-space: nowrap">
{{ ((data.Dist.Key[_key] / data.Keys.Count) * 100 || 0).toFixed(2) }}
<div class="heat-key-container">
<div
class="heat-key"
:style="{
'background-color': `rgb(255, 0, 0, ${(data.Dist.Key[_key] || 0) / data.Keys.Count / 0.13})`,
}"
>
<div class="key-label">{{ _key.toUpperCase() }}</div>
<div class="key-rate">
{{ ((data.Dist.Key[_key] / data.Keys.Count) * 100 || 0).toFixed(2) }}
</div>
</div>
</div>
</template>
<style>
div.heat-key-container {
--my-wh: calc(33rem / 12);
width: var(--my-wh);
height: var(--my-wh);
}
div.heat-key {
display: flex;
flex-direction: column;
align-items: center;
border-radius: 5px;
border: 1px solid #e0e0e0;
margin: 2px;
margin: 0.125rem;
& > .key-label {
font-size: 0.9rem;
color: #000;
white-space: nowrap;
}
& > .key-rate {
font-size: 0.6rem;
}
}
</style>
4 changes: 2 additions & 2 deletions frontend/src/components/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ async function race() {
<Show :result="result"></Show>
</template>

<style>
<style scoped>
.line {
display: flex;
align-items: center;
Expand All @@ -470,7 +470,7 @@ async function race() {
text-align: right;
padding-right: 30px;
color: #111;
font-size: 125%;
font-size: 1.1rem;
font-weight: bold;
font-family: Baskerville, "Times New Roman", "Liberation Serif", STFangsong, FangSong, FangSong_GB2312, "CWTEX\-F",
serif;
Expand Down
68 changes: 41 additions & 27 deletions frontend/src/components/MultiResult.vue
Original file line number Diff line number Diff line change
Expand Up @@ -197,45 +197,59 @@ function dist(dist: number[]) {
</div>

<n-flex justify="center" style="font-weight: bold; margin-bottom: 8px">按键频率 %</n-flex>
<n-grid :cols="12">
<n-gi v-for="v in '0123456789-='"><heat-map :data="data" :_key="v"></heat-map></n-gi>
<n-gi v-for="v in 'qwertyuiop[]'"><heat-map :data="data" :_key="v"></heat-map></n-gi>
<n-gi v-for="v in 'asdfghjkl;\''"><heat-map :data="data" :_key="v"></heat-map></n-gi>
<n-gi></n-gi>
<n-gi v-for="v in 'zxcvbnm,./'"><heat-map :data="data" :_key="v"></heat-map></n-gi>
<n-gi></n-gi>
<n-gi></n-gi>
<n-gi><finger-heat-map :data="data" :colspan="1" :name="'小指'" :num="2"></finger-heat-map></n-gi>
<n-gi><finger-heat-map :data="data" :colspan="1" :name="'无名'" :num="2"></finger-heat-map></n-gi>
<n-gi><finger-heat-map :data="data" :colspan="1" :name="'中指'" :num="3"></finger-heat-map></n-gi>
<n-gi><finger-heat-map :data="data" :colspan="1" :name="'食指'" :num="4"></finger-heat-map></n-gi>
<n-gi><finger-heat-map :data="data" :colspan="1" :name="'拇指'" :num="5"></finger-heat-map></n-gi>
<n-gi><finger-heat-map :data="data" :colspan="1" :name="'拇指'" :num="6"></finger-heat-map></n-gi>
<n-gi><finger-heat-map :data="data" :colspan="1" :name="'食指'" :num="7"></finger-heat-map></n-gi>
<n-gi><finger-heat-map :data="data" :colspan="1" :name="'中指'" :num="8"></finger-heat-map></n-gi>
<n-gi><finger-heat-map :data="data" :colspan="1" :name="'无名'" :num="9"></finger-heat-map></n-gi>
<n-gi><finger-heat-map :data="data" :colspan="1" :name="'小指'" :num="10"></finger-heat-map></n-gi
></n-grid>
<div class="heat-map">
<div class="heat-line">
<div v-for="v in '0123456789-='"><heat-map :data="data" :_key="v"></heat-map></div>
</div>
<div class="heat-line">
<div v-for="v in 'qwertyuiop[]'"><heat-map :data="data" :_key="v"></heat-map></div>
</div>
<div class="heat-line">
<div v-for="v in 'asdfghjkl;\''"><heat-map :data="data" :_key="v"></heat-map></div>
</div>
<div class="heat-line">
<div v-for="v in 'zxcvbnm,./'"><heat-map :data="data" :_key="v"></heat-map></div>
</div>
<div class="heat-line">
<finger-heat-map :data="data" :colspan="1" :name="'小指'" :num="2"></finger-heat-map>
<finger-heat-map :data="data" :colspan="1" :name="'无名'" :num="2"></finger-heat-map>
<finger-heat-map :data="data" :colspan="1" :name="'中指'" :num="3"></finger-heat-map>
<finger-heat-map :data="data" :colspan="1" :name="'食指'" :num="4"></finger-heat-map>
<finger-heat-map :data="data" :colspan="1" :name="'拇指'" :num="5"></finger-heat-map>
<finger-heat-map :data="data" :colspan="1" :name="'拇指'" :num="6"></finger-heat-map>
<finger-heat-map :data="data" :colspan="1" :name="'食指'" :num="7"></finger-heat-map>
<finger-heat-map :data="data" :colspan="1" :name="'中指'" :num="8"></finger-heat-map>
<finger-heat-map :data="data" :colspan="1" :name="'无名'" :num="9"></finger-heat-map>
<finger-heat-map :data="data" :colspan="1" :name="'小指'" :num="10"></finger-heat-map>
</div>
</div>
</div>
</template>

<style scoped>
div.heat-map {
& .heat-line {
display: flex;
flex-wrap: wrap;
}
}
.card {
font-size: 1rem;
display: flex;
font-size: medium;
flex-direction: column;
margin: 0.5em;
padding: 0.8em 1.5em;
margin: 1rem 0.5rem;
padding: 0.8rem 1.5rem 1.5rem;
background-color: #fefefe;
border: 1px solid #eee;
border-radius: 10px;
width: 550px;
width: 33em;
}
.name {
font-family: Baskerville, "Times New Roman", "Liberation Serif", STFangsong, FangSong, FangSong_GB2312, "CWTEX\-F",
serif;
font-size: 23px;
font-size: 1.3rem;
font-weight: bold;
overflow-x: auto;
white-space: nowrap;
Expand All @@ -247,7 +261,7 @@ div.dist {
margin-top: 5px;
max-width: 550px;
align-items: start;
height: 100px;
height: 105px;
& table {
white-space: nowrap;
Expand Down Expand Up @@ -278,14 +292,14 @@ table.dist-body {
font-size: inherit;
margin: 0;
overflow: visible;
padding: 2px 1em;
padding: 3px 1rem;
white-space: nowrap;
}
}
.pure-table caption {
color: #000;
padding: 1em 0;
padding: 1rem 0;
text-align: center;
}
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/components/Result/Result.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ provide("schema1", d1);
provide("schema2", d2);
</script>
<template>
<n-layout>
<n-layout class="result">
<n-layout-header>
<n-h2>赛码报告</n-h2>
<n-p style="display: flex; align-items: center">
Expand Down Expand Up @@ -191,4 +191,11 @@ provide("schema2", d2);
</n-layout-footer>
</n-layout>
</template>
../DataOld
<style scoped>
.result {
min-width: 60rem;
max-width: 80rem;
margin: 1rem auto 0;
padding: 0.8rem;
}
</style>
70 changes: 50 additions & 20 deletions frontend/src/components/Show.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,64 @@ const multi = ref(true);
</script>
<template>
<n-drawer v-model:show="active" :width="502" placement="bottom" height="100vh">
<n-drawer-content :native-scrollbar="false" header-style="padding: 0; display: flex; margin: auto">
<n-drawer-content :native-scrollbar="false" header-style="padding: 0;" body-content-style="padding: 0;">
<template #header>
<n-flex justify="space-between" style="width: 80vw; align-items: center; padding: 10px">
<n-button @click="multi = !multi">切换风格</n-button>
<span class="title">{{ props.result[0].Info.TextName }}</span>
<n-button type="info" ghost @click="active = false">关闭</n-button>
</n-flex>
</template>
<div>
<div v-if="multi" style="display: flex; justify-content: center">
<div style="display: flex; overflow-x: auto">
<div v-for="data in props.result">
<MultiResult :data="data"></MultiResult>
</div>
<div class="drawer-header">
<div class="button-left">
<n-button @click="multi = !multi">切换风格</n-button>
</div>
<div class="button-right">
<n-button type="info" ghost @click="active = false">关闭</n-button>
</div>
<div class="title">{{ props.result[0].Info.TextName }}</div>
</div>
<div v-else>
<Result :result="props.result" style="min-width: 50em; max-width: 80em; margin: auto" />
</template>
<div v-if="multi" class="multi-res">
<div v-for="data in props.result">
<MultiResult :data="data"></MultiResult>
</div>
</div>
<Result v-else :result="props.result" />
</n-drawer-content>
</n-drawer>
</template>
<style scoped>
.title {
font-size: 30px;
font-weight: bold;
font-family: Baskerville, Georgia, "Liberation Serif", "Kaiti SC", STKaiti, "AR PL UKai CN", "AR PL UKai HK",
"AR PL UKai TW", "AR PL UKai TW MBE", "AR PL KaitiM GB", KaiTi, KaiTi_GB2312, DFKai-SB, "TW\-Kai", serif;
.multi-res {
display: flex;
justify-content: safe center;
margin: 0 auto;
flex-wrap: wrap;
overflow-x: auto;
}
.drawer-header {
width: 100vw;
display: flex;
align-items: center;
justify-content: center;
padding: 0;
height: 2.75em;
& .title {
clear: both;
font-size: 1.75rem;
font-weight: bold;
font-family: Baskerville, Georgia, "Liberation Serif", "Kaiti SC", STKaiti, "AR PL UKai CN", "AR PL UKai HK",
"AR PL UKai TW", "AR PL UKai TW MBE", "AR PL KaitiM GB", KaiTi, KaiTi_GB2312, DFKai-SB, "TW\-Kai", serif;
}
& .button-left {
position: absolute;
float: left;
left: 0;
margin-left: 1rem;
}
& .button-right {
position: absolute;
float: right;
right: 0;
margin-right: 1rem;
}
}
</style>
Loading

0 comments on commit 11d71c8

Please sign in to comment.