Skip to content

Commit

Permalink
feat: 计算时禁用表单
Browse files Browse the repository at this point in the history
  • Loading branch information
LeafYeeXYZ committed Oct 8, 2024
1 parent 11b0dd9 commit be75423
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/components/PaintView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export function PaintView() {
defaultValue={CASCADER_DEFAULT_VALUE}
options={CASCADER_OPTIONS}
onChange={(value) => CASCADER_ONCHANGE(value, setPage)}
expandTrigger='hover'
/>
</div>
{/* 画图界面 */}
Expand Down
1 change: 1 addition & 0 deletions src/components/StatisticsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export function StatisticsView() {
defaultValue={CASCADER_DEFAULT_VALUE}
options={CASCADER_OPTIONS}
onChange={(value) => CASCADER_ONCHANGE(value, setPage)}
expandTrigger='hover'
/>
</div>
{/* 统计界面 */}
Expand Down
22 changes: 13 additions & 9 deletions src/plots/BasicBoxPlot.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Box } from '@ant-design/plots'
import { Select, Button, Form } from 'antd'
import { Select, Button, Form, Radio } from 'antd'
import { useZustand } from '../lib/useZustand'
import { useState } from 'react'
import { flushSync } from 'react-dom'

type Option = {
/** 分组变量 */
Expand All @@ -26,6 +27,7 @@ export function BasicBoxPlot() {

const { dataCols, dataRows } = useZustand()
const [config, setConfig] = useState<Config | null>(null)
const [disabled, setDisabled] = useState<boolean>(false)
const handleFinish = (values: Option) => {
try {
const data = dataRows
Expand Down Expand Up @@ -53,11 +55,16 @@ export function BasicBoxPlot() {
<Form<Option>
className='w-full'
layout='vertical'
onFinish={handleFinish}
onFinish={(values) => {
flushSync(() => setDisabled(true))
handleFinish(values)
flushSync(() => setDisabled(false))
}}
autoComplete='off'
initialValues={{
showOutliers: true,
}}
disabled={disabled}
>
<Form.Item
label='选择分组变量'
Expand Down Expand Up @@ -96,13 +103,10 @@ export function BasicBoxPlot() {
name='showOutliers'
rules={[{ required: true, message: '请选择是否显示异常点' }]}
>
<Select
className='w-full'
placeholder='请选择是否显示异常点'
>
<Select.Option value={true}></Select.Option>
<Select.Option value={false}></Select.Option>
</Select>
<Radio.Group block>
<Radio.Button value={true}>标注并排除异常点</Radio.Button>
<Radio.Button value={false}>不特殊处理异常点</Radio.Button>
</Radio.Group>
</Form.Item>
<div
className='flex flex-row flex-nowrap justify-center items-center gap-4'
Expand Down
9 changes: 8 additions & 1 deletion src/statistics/OneSampleTTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useZustand } from '../lib/useZustand'
import { Select, Input, Button, Form } from 'antd'
import { useState } from 'react'
import { ttest } from '@stdlib/stats'
import { flushSync } from 'react-dom'

type Option = {
/** 变量名 */
Expand All @@ -21,6 +22,7 @@ export function OneSampleTTest() {

const { dataCols, dataRows } = useZustand()
const [result, setResult] = useState<Result | null>(null)
const [disabled, setDisabled] = useState<boolean>(false)
const handleCalculate = (values: Option) => {
try {
const data = dataRows.map((row) => +row[values.variable] as number)
Expand All @@ -39,13 +41,18 @@ export function OneSampleTTest() {
<Form<Option>
className='w-full'
layout='vertical'
onFinish={handleCalculate}
onFinish={(values) => {
flushSync(() => setDisabled(true))
handleCalculate(values)
flushSync(() => setDisabled(false))
}}
autoComplete='off'
initialValues={{
expect: 0,
alpha: 0.05,
alternative: 'two-sided',
}}
disabled={disabled}
>
<Form.Item
label='选择变量'
Expand Down
9 changes: 8 additions & 1 deletion src/statistics/PeerSampleTTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useZustand } from '../lib/useZustand'
import { Select, Input, Button, Form } from 'antd'
import { useState } from 'react'
import { ttest } from '@stdlib/stats'
import { flushSync } from 'react-dom'

type Option = {
/** 变量名1 */
Expand All @@ -23,6 +24,7 @@ export function PeerSampleTTest() {

const { dataCols, dataRows } = useZustand()
const [result, setResult] = useState<Result | null>(null)
const [disabled, setDisabled] = useState<boolean>(false)
const handleCalculate = (values: Option) => {
try {
const data1 = dataRows.map((row) => +row[values.variable1] as number)
Expand All @@ -42,13 +44,18 @@ export function PeerSampleTTest() {
<Form<Option>
className='w-full'
layout='vertical'
onFinish={handleCalculate}
onFinish={(values) => {
flushSync(() => setDisabled(true))
handleCalculate(values)
flushSync(() => setDisabled(false))
}}
autoComplete='off'
initialValues={{
expect: 0,
alpha: 0.05,
alternative: 'two-sided',
}}
disabled={disabled}
>
<Form.Item
label='选择配对变量'
Expand Down

0 comments on commit be75423

Please sign in to comment.