Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Drip
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
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
backup
Drip
Commits
36ae949f
Commit
36ae949f
authored
5 years ago
by
mashazyu
Browse files
Options
Downloads
Patches
Plain Diff
Move auxiliary functions from day-column.js component file to helpers file
parent
796d995a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
components/chart/day-column.js
+8
-99
8 additions, 99 deletions
components/chart/day-column.js
components/helpers/chart.js
+97
-0
97 additions, 0 deletions
components/helpers/chart.js
with
105 additions
and
99 deletions
components/chart/day-column.js
+
8
−
99
View file @
36ae949f
...
@@ -4,14 +4,17 @@ import { connect } from 'react-redux'
...
@@ -4,14 +4,17 @@ import { connect } from 'react-redux'
import
{
setDate
}
from
'
../../slices/date
'
import
{
setDate
}
from
'
../../slices/date
'
import
{
LocalDate
}
from
'
js-joda
'
import
{
getCycleDay
}
from
'
../../db
'
import
{
getCycleDay
}
from
'
../../db
'
import
SymptomCell
from
'
./symptom-cell
'
import
SymptomCell
from
'
./symptom-cell
'
import
TemperatureColumn
from
'
./temperature-column
'
import
TemperatureColumn
from
'
./temperature-column
'
import
CycleDayLabel
from
'
./cycle-day-label
'
import
CycleDayLabel
from
'
./cycle-day-label
'
import
{
normalizeToScale
}
from
'
../helpers/chart
'
import
{
symptomColorMethods
,
getTemperatureProps
,
isSymptomDataComplete
}
from
'
../helpers/chart
'
class
DayColumn
extends
Component
{
class
DayColumn
extends
Component
{
constructor
(
props
)
{
constructor
(
props
)
{
...
@@ -27,14 +30,13 @@ class DayColumn extends Component {
...
@@ -27,14 +30,13 @@ class DayColumn extends Component {
if
(
symptomData
&&
symptom
===
'
temperature
'
)
{
if
(
symptomData
&&
symptom
===
'
temperature
'
)
{
symptomDataToDisplay
[
symptom
]
=
symptomDataToDisplay
[
symptom
]
=
this
.
getTemperatureProps
(
symptomData
,
columnHeight
,
dateString
)
getTemperatureProps
(
symptomData
,
columnHeight
,
dateString
)
}
else
{
}
else
{
if
(
symptomData
&&
!
symptomData
.
exclude
)
{
if
(
symptomData
&&
!
symptomData
.
exclude
)
{
// if symptomColorMethods entry doesn't exist for given symptom,
// if symptomColorMethods entry doesn't exist for given symptom,
// use 'default'
// use 'default'
const
getSymptomColorIndex
=
const
getSymptomColorIndex
=
this
.
symptomColorMethods
[
symptom
]
||
symptomColorMethods
[
symptom
]
||
symptomColorMethods
[
'
default
'
]
this
.
symptomColorMethods
[
'
default
'
]
symptomDataToDisplay
[
symptom
]
=
getSymptomColorIndex
(
symptomData
)
symptomDataToDisplay
[
symptom
]
=
getSymptomColorIndex
(
symptomData
)
}
}
...
@@ -51,75 +53,6 @@ class DayColumn extends Component {
...
@@ -51,75 +53,6 @@ class DayColumn extends Component {
)
)
}
}
getTemperatureProps
=
(
symptomData
,
columnHeight
,
dateString
)
=>
{
const
extractedData
=
{}
const
{
value
,
exclude
}
=
symptomData
const
neighborTemperatureGraphPoints
=
getInfoForNeighborColumns
(
dateString
,
columnHeight
)
for
(
const
key
in
neighborTemperatureGraphPoints
)
{
extractedData
[
key
]
=
neighborTemperatureGraphPoints
[
key
]
}
return
Object
.
assign
({
value
,
y
:
normalizeToScale
(
value
,
columnHeight
),
temperatureExclude
:
exclude
,
},
extractedData
)
}
symptomColorMethods
=
{
'
mucus
'
:
(
symptomData
)
=>
{
const
{
feeling
,
texture
}
=
symptomData
const
colorIndex
=
feeling
+
texture
return
colorIndex
},
'
cervix
'
:
(
symptomData
)
=>
{
const
{
opening
,
firmness
}
=
symptomData
const
isDataComplete
=
opening
!==
null
&&
firmness
!==
null
const
isClosedAndHard
=
isDataComplete
&&
(
opening
===
0
&&
firmness
===
0
)
const
colorIndex
=
isClosedAndHard
?
0
:
2
return
colorIndex
},
'
sex
'
:
(
symptomData
)
=>
{
const
{
solo
,
partner
}
=
symptomData
const
colorIndex
=
(
solo
!==
null
&&
partner
!==
null
)
?
(
solo
+
2
*
partner
-
1
)
:
0
return
colorIndex
},
'
bleeding
'
:
(
symptomData
)
=>
{
const
{
value
}
=
symptomData
const
colorIndex
=
value
return
colorIndex
},
'
default
'
:
()
=>
{
// desire, pain, mood, note
const
colorIndex
=
0
return
colorIndex
}
}
isSymptomDataComplete
=
(
symptom
)
=>
{
const
{
dateString
}
=
this
.
props
const
cycleDayData
=
getCycleDay
(
dateString
)
const
symptomData
=
cycleDayData
[
symptom
]
const
dataCompletenessCheck
=
{
'
cervix
'
:
()
=>
{
const
{
opening
,
firmness
}
=
symptomData
return
(
opening
!==
null
)
&&
(
firmness
!==
null
)
},
'
mucus
'
:
()
=>
{
const
{
feeling
,
texture
}
=
symptomData
return
(
feeling
!==
null
)
&&
(
texture
!==
null
)
},
'
default
'
:
()
=>
{
return
true
}
}
return
(
dataCompletenessCheck
[
symptom
]
||
dataCompletenessCheck
[
'
default
'
])()
}
onDaySelect
=
(
date
)
=>
{
onDaySelect
=
(
date
)
=>
{
this
.
props
.
setDate
(
date
)
this
.
props
.
setDate
(
date
)
this
.
props
.
navigate
(
'
CycleDay
'
)
this
.
props
.
navigate
(
'
CycleDay
'
)
...
@@ -149,7 +82,7 @@ class DayColumn extends Component {
...
@@ -149,7 +82,7 @@ class DayColumn extends Component {
symptom
=
{
symptom
}
symptom
=
{
symptom
}
symptomValue
=
{
hasSymptomData
&&
this
.
data
[
symptom
]}
symptomValue
=
{
hasSymptomData
&&
this
.
data
[
symptom
]}
isSymptomDataComplete
=
{
isSymptomDataComplete
=
{
hasSymptomData
&&
this
.
isSymptomDataComplete
(
symptom
)
hasSymptomData
&&
isSymptomDataComplete
(
symptom
,
dateString
)
}
}
height
=
{
this
.
props
.
symptomHeight
}
height
=
{
this
.
props
.
symptomHeight
}
/>
)
/>
)
...
@@ -183,27 +116,3 @@ export default connect(
...
@@ -183,27 +116,3 @@ export default connect(
null
,
null
,
mapDispatchToProps
,
mapDispatchToProps
,
)(
DayColumn
)
)(
DayColumn
)
function
getInfoForNeighborColumns
(
dateString
,
columnHeight
)
{
const
ret
=
{
rightY
:
null
,
rightTemperatureExclude
:
null
,
leftY
:
null
,
leftTemperatureExclude
:
null
}
const
target
=
LocalDate
.
parse
(
dateString
)
const
dayBefore
=
target
.
minusDays
(
1
).
toString
()
const
dayAfter
=
target
.
plusDays
(
1
).
toString
()
const
cycleDayBefore
=
getCycleDay
(
dayBefore
)
const
cycleDayAfter
=
getCycleDay
(
dayAfter
)
if
(
cycleDayAfter
&&
cycleDayAfter
.
temperature
)
{
ret
.
rightY
=
normalizeToScale
(
cycleDayAfter
.
temperature
.
value
,
columnHeight
)
ret
.
rightTemperatureExclude
=
cycleDayAfter
.
temperature
.
exclude
}
if
(
cycleDayBefore
&&
cycleDayBefore
.
temperature
)
{
ret
.
leftY
=
normalizeToScale
(
cycleDayBefore
.
temperature
.
value
,
columnHeight
)
ret
.
leftTemperatureExclude
=
cycleDayBefore
.
temperature
.
exclude
}
return
ret
}
This diff is collapsed.
Click to expand it.
components/helpers/chart.js
+
97
−
0
View file @
36ae949f
import
{
LocalDate
}
from
'
js-joda
'
import
{
scaleObservable
,
unitObservable
}
from
'
../../local-storage
'
import
{
scaleObservable
,
unitObservable
}
from
'
../../local-storage
'
import
{
getCycleDay
}
from
'
../../db
'
import
config
from
'
../../config
'
import
config
from
'
../../config
'
export
function
normalizeToScale
(
temp
,
columnHeight
)
{
export
function
normalizeToScale
(
temp
,
columnHeight
)
{
...
@@ -65,3 +69,96 @@ export function getTickList(columnHeight) {
...
@@ -65,3 +69,96 @@ export function getTickList(columnHeight) {
}
}
})
})
}
}
export
function
isSymptomDataComplete
(
symptom
,
dateString
)
{
const
cycleDayData
=
getCycleDay
(
dateString
)
const
symptomData
=
cycleDayData
[
symptom
]
const
dataCompletenessCheck
=
{
'
cervix
'
:
()
=>
{
const
{
opening
,
firmness
}
=
symptomData
return
(
opening
!==
null
)
&&
(
firmness
!==
null
)
},
'
mucus
'
:
()
=>
{
const
{
feeling
,
texture
}
=
symptomData
return
(
feeling
!==
null
)
&&
(
texture
!==
null
)
},
'
default
'
:
()
=>
{
return
true
}
}
return
(
dataCompletenessCheck
[
symptom
]
||
dataCompletenessCheck
[
'
default
'
])()
}
function
getInfoForNeighborColumns
(
dateString
,
columnHeight
)
{
const
ret
=
{
rightY
:
null
,
rightTemperatureExclude
:
null
,
leftY
:
null
,
leftTemperatureExclude
:
null
}
const
target
=
LocalDate
.
parse
(
dateString
)
const
dayBefore
=
target
.
minusDays
(
1
).
toString
()
const
dayAfter
=
target
.
plusDays
(
1
).
toString
()
const
cycleDayBefore
=
getCycleDay
(
dayBefore
)
const
cycleDayAfter
=
getCycleDay
(
dayAfter
)
if
(
cycleDayAfter
&&
cycleDayAfter
.
temperature
)
{
ret
.
rightY
=
normalizeToScale
(
cycleDayAfter
.
temperature
.
value
,
columnHeight
)
ret
.
rightTemperatureExclude
=
cycleDayAfter
.
temperature
.
exclude
}
if
(
cycleDayBefore
&&
cycleDayBefore
.
temperature
)
{
ret
.
leftY
=
normalizeToScale
(
cycleDayBefore
.
temperature
.
value
,
columnHeight
)
ret
.
leftTemperatureExclude
=
cycleDayBefore
.
temperature
.
exclude
}
return
ret
}
export
function
getTemperatureProps
(
symptomData
,
columnHeight
,
dateString
)
{
const
extractedData
=
{}
const
{
value
,
exclude
}
=
symptomData
const
neighborTemperatureGraphPoints
=
getInfoForNeighborColumns
(
dateString
,
columnHeight
)
for
(
const
key
in
neighborTemperatureGraphPoints
)
{
extractedData
[
key
]
=
neighborTemperatureGraphPoints
[
key
]
}
return
Object
.
assign
({
value
,
y
:
normalizeToScale
(
value
,
columnHeight
),
temperatureExclude
:
exclude
,
},
extractedData
)
}
export
const
symptomColorMethods
=
{
'
mucus
'
:
(
symptomData
)
=>
{
const
{
feeling
,
texture
}
=
symptomData
const
colorIndex
=
feeling
+
texture
return
colorIndex
},
'
cervix
'
:
(
symptomData
)
=>
{
const
{
opening
,
firmness
}
=
symptomData
const
isDataComplete
=
opening
!==
null
&&
firmness
!==
null
const
isClosedAndHard
=
isDataComplete
&&
(
opening
===
0
&&
firmness
===
0
)
const
colorIndex
=
isClosedAndHard
?
0
:
2
return
colorIndex
},
'
sex
'
:
(
symptomData
)
=>
{
const
{
solo
,
partner
}
=
symptomData
const
colorIndex
=
(
solo
!==
null
&&
partner
!==
null
)
?
(
solo
+
2
*
partner
-
1
)
:
0
return
colorIndex
},
'
bleeding
'
:
(
symptomData
)
=>
{
const
{
value
}
=
symptomData
const
colorIndex
=
value
return
colorIndex
},
'
default
'
:
()
=>
{
// desire, pain, mood, note
const
colorIndex
=
0
return
colorIndex
}
}
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