Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
FitUrRing
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wss9
FitUrRing
Commits
e0e95304
Commit
e0e95304
authored
6 months ago
by
Park Tae hyeon
Browse files
Options
Downloads
Patches
Plain Diff
Fix: WeightChart
parent
a178d2ef
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
front/src/pages/diet/WeightChart.jsx
+34
-10
34 additions, 10 deletions
front/src/pages/diet/WeightChart.jsx
with
34 additions
and
10 deletions
front/src/pages/diet/WeightChart.jsx
+
34
−
10
View file @
e0e95304
...
@@ -38,6 +38,7 @@ const options = {
...
@@ -38,6 +38,7 @@ const options = {
},
},
grid
:
{
grid
:
{
display
:
false
,
display
:
false
,
},
},
ticks
:
{
ticks
:
{
font
:
{
font
:
{
...
@@ -91,6 +92,21 @@ function WeightChart() {
...
@@ -91,6 +92,21 @@ function WeightChart() {
useEffect
(()
=>
{
useEffect
(()
=>
{
const
fetchWeightHistory
=
async
()
=>
{
const
fetchWeightHistory
=
async
()
=>
{
try
{
try
{
/*
const data = [
{ date: '2024-11-29', weight: 50 },
{ date: '2024-11-30', weight: null },
{ date: '2024-12-01', weight: null },
{ date: '2024-12-02', weight: null },
{ date: '2024-12-03', weight: null },
{ date: '2024-12-04', weight: 60 },
{ date: '2024-12-05', weight: null },
{ date: '2024-12-06', weight: null },
{ date: '2024-12-07', weight: null },
{ date: '2024-12-08', weight: 50 }
];
*/
const
data
=
await
getWeightHistory
();
const
data
=
await
getWeightHistory
();
if
(
!
data
||
data
.
length
===
0
)
{
if
(
!
data
||
data
.
length
===
0
)
{
...
@@ -98,12 +114,12 @@ function WeightChart() {
...
@@ -98,12 +114,12 @@ function WeightChart() {
return
;
return
;
}
}
cons
t
weights
=
data
.
map
(
item
=>
item
.
weight
);
le
t
weights
=
data
.
map
(
item
=>
item
.
weight
);
// null 값 처리 후 최대/최소값 계산
// null 값 처리 후 최대/최소값 계산
const
validWeights
=
weights
.
filter
(
w
=>
w
!==
null
);
const
validWeights
=
weights
.
filter
(
w
=>
w
!==
null
);
const
minWeight
=
Math
.
min
(...
validWeights
);
const
minWeight
=
Math
.
min
(...
validWeights
)
*
0.8
;
const
maxWeight
=
Math
.
max
(...
validWeights
);
const
maxWeight
=
Math
.
max
(...
validWeights
)
*
1.2
;
// 범위의 10% 계산
// 범위의 10% 계산
const
range
=
maxWeight
-
minWeight
;
const
range
=
maxWeight
-
minWeight
;
...
@@ -123,23 +139,31 @@ function WeightChart() {
...
@@ -123,23 +139,31 @@ function WeightChart() {
}));
}));
// 기존의 차트 데이터 설정 로직
// 기존의 차트 데이터 설정 로직
cons
t
labels
=
data
.
map
(
item
=>
{
le
t
labels
=
data
.
map
(
item
=>
{
const
date
=
new
Date
(
item
.
date
);
const
date
=
new
Date
(
item
.
date
);
return
`
${
date
.
getFullYear
()}
/
${
String
(
date
.
getMonth
()
+
1
).
padStart
(
2
,
'
0
'
)}
/
${
String
(
date
.
getDate
()).
padStart
(
2
,
'
0
'
)}
`
;
return
`
${
date
.
getFullYear
()}
/
${
String
(
date
.
getMonth
()
+
1
).
padStart
(
2
,
'
0
'
)}
/
${
String
(
date
.
getDate
()).
padStart
(
2
,
'
0
'
)}
`
;
});
});
let
check
=
-
1
;
// null 값을 이후 날짜의 가장 가까운 weight 값으로 채우기
// null 값을 이후 날짜의 가장 가까운 weight 값으로 채우기
for
(
let
i
=
0
;
i
<
weights
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
weights
.
length
;
i
++
)
{
if
(
weights
[
i
]
===
null
)
{
if
(
weights
[
i
]
===
null
)
{
let
nextValue
=
null
;
let
nextValue
=
null
;
for
(
let
j
=
i
+
1
;
j
<
weights
.
length
;
j
++
)
{
for
(
let
j
=
i
-
1
;
j
>=
0
;
j
--
)
{
if
(
weights
[
j
]
!==
null
)
{
if
(
weights
[
j
]
!==
null
)
{
nextValue
=
weights
[
j
];
nextValue
=
weights
[
j
];
break
;
break
;
}
}
}
}
weights
[
i
]
=
nextValue
;
if
(
nextValue
===
null
)
check
=
i
+
1
;
else
weights
[
i
]
=
nextValue
;
}
}
}
// null로 기록된 이전 기록 제거
if
(
check
!=
-
1
)
{
labels
=
labels
.
slice
(
check
);
weights
=
weights
.
slice
(
check
);
}
}
// 차트 데이터 설정
// 차트 데이터 설정
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment