refactor: pull up method
This commit is contained in:
parent
50d87e029d
commit
e2abf88705
1 changed files with 9 additions and 15 deletions
|
|
@ -62,6 +62,11 @@ const Graph = ({ data, timeFrame, timezone }) => {
|
||||||
[]
|
[]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const filterDay = useMemo(
|
||||||
|
x => (timeFrame === 'day' ? x.getUTCHours() === 0 : x.getUTCDate() === 1),
|
||||||
|
[timeFrame]
|
||||||
|
)
|
||||||
|
|
||||||
const getPastAndCurrentDayLabels = useCallback(d => {
|
const getPastAndCurrentDayLabels = useCallback(d => {
|
||||||
const currentDate = new Date(d)
|
const currentDate = new Date(d)
|
||||||
const currentDateDay = currentDate.getUTCDate()
|
const currentDateDay = currentDate.getUTCDate()
|
||||||
|
|
@ -213,12 +218,7 @@ const Graph = ({ data, timeFrame, timezone }) => {
|
||||||
g
|
g
|
||||||
.append('g')
|
.append('g')
|
||||||
.selectAll('line')
|
.selectAll('line')
|
||||||
.data(
|
.data(buildTicks(x.domain()).filter(filterDay))
|
||||||
buildTicks(x.domain()).filter(x => {
|
|
||||||
if (timeFrame === 'day') return x.getUTCHours() === 0
|
|
||||||
return x.getUTCDate() === 1
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.join('line')
|
.join('line')
|
||||||
.attr('class', 'dateSeparator')
|
.attr('class', 'dateSeparator')
|
||||||
.attr('x1', d => 0.5 + x(d))
|
.attr('x1', d => 0.5 + x(d))
|
||||||
|
|
@ -237,10 +237,7 @@ const Graph = ({ data, timeFrame, timezone }) => {
|
||||||
|
|
||||||
if (!separator) return
|
if (!separator) return
|
||||||
|
|
||||||
const breakpoint = buildTicks(x.domain()).filter(x => {
|
const breakpoint = buildTicks(x.domain()).filter(filterDay)
|
||||||
if (timeFrame === 'day') return x.getUTCHours() === 0
|
|
||||||
return x.getUTCDate() === 1
|
|
||||||
})
|
|
||||||
|
|
||||||
const labels = getPastAndCurrentDayLabels(breakpoint)
|
const labels = getPastAndCurrentDayLabels(breakpoint)
|
||||||
|
|
||||||
|
|
@ -261,10 +258,7 @@ const Graph = ({ data, timeFrame, timezone }) => {
|
||||||
|
|
||||||
if (!separator) return
|
if (!separator) return
|
||||||
|
|
||||||
const breakpoint = buildTicks(x.domain()).filter(x => {
|
const breakpoint = buildTicks(x.domain()).filter(filterDay)
|
||||||
if (timeFrame === 'day') return x.getUTCHours() === 0
|
|
||||||
return x.getUTCDate() === 1
|
|
||||||
})
|
|
||||||
|
|
||||||
const labels = getPastAndCurrentDayLabels(breakpoint)
|
const labels = getPastAndCurrentDayLabels(breakpoint)
|
||||||
|
|
||||||
|
|
@ -277,7 +271,7 @@ const Graph = ({ data, timeFrame, timezone }) => {
|
||||||
.text(labels.current)
|
.text(labels.current)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
[GRAPH_MARGIN, buildTicks, getPastAndCurrentDayLabels, x, y, timeFrame]
|
[GRAPH_MARGIN, buildTicks, getPastAndCurrentDayLabels, x, y, filterDay]
|
||||||
)
|
)
|
||||||
|
|
||||||
const formatTicksText = useCallback(
|
const formatTicksText = useCallback(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue