-
Notifications
You must be signed in to change notification settings - Fork 1
/
Columns.js
115 lines (101 loc) · 3.32 KB
/
Columns.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import PropTypes from 'prop-types'
import React, { Component } from 'react'
import { iterateTimes } from '../utility/calendar'
import { TimelineStateConsumer } from '../timeline/TimelineStateContext'
const passThroughPropTypes = {
canvasTimeStart: PropTypes.number.isRequired,
canvasTimeEnd: PropTypes.number.isRequired,
canvasWidth: PropTypes.number.isRequired,
lineCount: PropTypes.number.isRequired,
minUnit: PropTypes.string.isRequired,
timeSteps: PropTypes.object.isRequired,
height: PropTypes.number.isRequired,
verticalLineClassNamesForTime: PropTypes.func
}
class Columns extends Component {
static propTypes = {
...passThroughPropTypes,
getLeftOffsetFromDate: PropTypes.func.isRequired
}
shouldComponentUpdate(nextProps) {
return !(
nextProps.canvasTimeStart === this.props.canvasTimeStart &&
nextProps.canvasTimeEnd === this.props.canvasTimeEnd &&
nextProps.canvasWidth === this.props.canvasWidth &&
nextProps.lineCount === this.props.lineCount &&
nextProps.minUnit === this.props.minUnit &&
nextProps.timeSteps === this.props.timeSteps &&
nextProps.height === this.props.height &&
nextProps.verticalLineClassNamesForTime ===
this.props.verticalLineClassNamesForTime
)
}
render() {
const {
canvasTimeStart,
canvasTimeEnd,
canvasWidth,
minUnit,
timeSteps,
height,
verticalLineClassNamesForTime,
getLeftOffsetFromDate
} = this.props
const ratio = canvasWidth / (canvasTimeEnd - canvasTimeStart)
let lines = []
iterateTimes(
canvasTimeStart,
canvasTimeEnd,
minUnit,
timeSteps,
(time, nextTime) => {
const minUnitValue = time.get(minUnit === 'day' ? 'date' : minUnit)
const firstOfType = minUnitValue === (minUnit === 'day' ? 1 : 0)
let classNamesForTime = []
if (verticalLineClassNamesForTime) {
classNamesForTime = verticalLineClassNamesForTime(
time.unix() * 1000, // turn into ms, which is what verticalLineClassNamesForTime expects
nextTime.unix() * 1000 - 1
)
}
// TODO: rename or remove class that has reference to vertical-line
const classNames =
'rct-vl' +
(firstOfType ? ' rct-vl-first' : '') +
(minUnit === 'day' || minUnit === 'hour' || minUnit === 'minute'
? ` rct-day-${time.day()} `
: ' ') +
classNamesForTime.join(' ')
const left = getLeftOffsetFromDate(time.valueOf())
const right = getLeftOffsetFromDate(nextTime.valueOf())
lines.push(
<div
key={`line-${time.valueOf()}`}
className={classNames}
style={{
pointerEvents: 'none',
top: '0px',
left: `${left}px`,
width: `${right - left}px`,
height: `${height}px`
}}
/>
)
}
)
return <div className="rct-vertical-lines">{lines}</div>
}
}
const ColumnsWrapper = ({ ...props }) => {
return (
<TimelineStateConsumer>
{({ getLeftOffsetFromDate }) => (
<Columns getLeftOffsetFromDate={getLeftOffsetFromDate} {...props} />
)}
</TimelineStateConsumer>
)
}
ColumnsWrapper.defaultProps = {
...passThroughPropTypes
}
export default ColumnsWrapper