Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling of Canvas time #928

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions demo/app/demo-controlled-scrolling/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import Timeline, {
import generateFakeData from '../generate-fake-data'

var minTime = moment()
.add(-6, 'months')
.add(-1, 'day')
.valueOf()
var maxTime = moment()
.add(6, 'months')
.add(1, 'day')
.valueOf()

var keys = {
Expand Down Expand Up @@ -202,6 +202,8 @@ export default class App extends Component {
onItemDoubleClick={this.handleItemDoubleClick}
buffer={1}
onTimeChange={this.handleTimeChange}
canvasTimeStart={minTime}
canvasTimeEnd={maxTime}
// moveResizeValidator={this.moveResizeValidator}
>
<TimelineMarkers>
Expand Down
2 changes: 2 additions & 0 deletions demo/app/demo-controlled-select/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ export default class App extends Component {
moveResizeValidator={this.moveResizeValidator}
selected={this.state.selected}
onItemDeselect={this.handleItemDeselect}
canvasTimeStart={minTime}
canvasTimeEnd={maxTime}
>
<TimelineMarkers>
<TodayMarker />
Expand Down
9 changes: 9 additions & 0 deletions demo/app/demo-custom-info-label/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ var keys = {
groupLabelKey: 'title'
}

var minTime = moment()
.add(-6, 'months')
.valueOf()
var maxTime = moment()
.add(6, 'months')
.valueOf()

export default class App extends Component {
constructor(props) {
super(props)
Expand Down Expand Up @@ -148,6 +155,8 @@ export default class App extends Component {
onItemMove={this.handleItemMove}
onItemResize={this.handleItemResize}
onItemDrag={this.handleItemDrag}
canvasTimeStart={minTime}
canvasTimeEnd={maxTime}
/>
</div>
)
Expand Down
2 changes: 2 additions & 0 deletions demo/app/demo-custom-items/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ export default class App extends Component {
onItemDoubleClick={this.handleItemDoubleClick}
onTimeChange={this.handleTimeChange}
moveResizeValidator={this.moveResizeValidator}
canvasTimeStart={minTime}
canvasTimeEnd={maxTime}
/>
)
}
Expand Down
9 changes: 9 additions & 0 deletions demo/app/demo-element-resize/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ var keys = {
itemTimeEndKey: 'end'
}

var minTime = moment()
.add(-6, 'months')
.valueOf()
var maxTime = moment()
.add(6, 'months')
.valueOf()

export default class App extends Component {
constructor(props) {
super(props)
Expand Down Expand Up @@ -74,6 +81,8 @@ export default class App extends Component {
resizeDetector={containerResizeDetector}
defaultTimeStart={defaultTimeStart}
defaultTimeEnd={defaultTimeEnd}
canvasTimeStart={minTime}
canvasTimeEnd={maxTime}
/>
</div>
<div style={{ width: `${100 - width}%`, float: 'left' }}>
Expand Down
6 changes: 4 additions & 2 deletions demo/app/demo-headers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ export default class App extends Component {
// moveResizeValidator={this.moveResizeValidator}
rightSidebarWidth={150}
rightSidebarContent={<div>Above The Right</div>}
canvasTimeStart={minTime}
canvasTimeEnd={maxTime}
>
<TimelineHeaders className="header-background">
<SidebarHeader/>
Expand All @@ -209,7 +211,7 @@ export default class App extends Component {
showPeriod,
data,
},

) => {
console.log('props', data)
return (
Expand Down Expand Up @@ -322,7 +324,7 @@ export default class App extends Component {
headerData={{ hey: 'date header' }}
intervalRenderer={(
{ getIntervalProps, intervalContext, data },

) => {
console.log('intervalRenderer props', data)
return (
Expand Down
9 changes: 9 additions & 0 deletions demo/app/demo-linked-timelines/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ var keys = {
itemTimeEndKey: 'end'
}

var minTime = moment()
.add(-6, 'months')
.valueOf()
var maxTime = moment()
.add(6, 'months')
.valueOf()

export default class App extends Component {
constructor(props) {
super(props)
Expand Down Expand Up @@ -98,6 +105,8 @@ export default class App extends Component {
itemHeightRatio={0.75}
visibleTimeStart={visibleTimeStart}
visibleTimeEnd={visibleTimeEnd}
canvasTimeStart={minTime}
canvasTimeEnd={maxTime}
onTimeChange={this.handleTimeChangeSecond}
/>
)
Expand Down
29 changes: 15 additions & 14 deletions demo/app/demo-main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import Timeline, {
import generateFakeData from '../generate-fake-data'

var minTime = moment()
.add(-6, 'months')
.add(-3, 'day')
.valueOf()
var maxTime = moment()
.add(6, 'months')
.add(3, 'day')
.valueOf()

var keys = {
Expand Down Expand Up @@ -119,17 +119,17 @@ export default class App extends Component {
}

// this limits the timeline to -6 months ... +6 months
handleTimeChange = (visibleTimeStart, visibleTimeEnd, updateScrollCanvas) => {
if (visibleTimeStart < minTime && visibleTimeEnd > maxTime) {
updateScrollCanvas(minTime, maxTime)
} else if (visibleTimeStart < minTime) {
updateScrollCanvas(minTime, minTime + (visibleTimeEnd - visibleTimeStart))
} else if (visibleTimeEnd > maxTime) {
updateScrollCanvas(maxTime - (visibleTimeEnd - visibleTimeStart), maxTime)
} else {
updateScrollCanvas(visibleTimeStart, visibleTimeEnd)
}
}
// handleTimeChange = (visibleTimeStart, visibleTimeEnd, updateScrollCanvas) => {
// if (visibleTimeStart < minTime && visibleTimeEnd > maxTime) {
// updateScrollCanvas(minTime, maxTime)
// } else if (visibleTimeStart < minTime) {
// updateScrollCanvas(minTime, minTime + (visibleTimeEnd - visibleTimeStart))
// } else if (visibleTimeEnd > maxTime) {
// updateScrollCanvas(maxTime - (visibleTimeEnd - visibleTimeStart), maxTime)
// } else {
// updateScrollCanvas(visibleTimeStart, visibleTimeEnd)
// }
// }

handleZoom = (timelineContext, unit) => {
console.log('Zoomed', timelineContext, unit)
Expand Down Expand Up @@ -164,6 +164,8 @@ export default class App extends Component {
itemHeightRatio={0.75}
defaultTimeStart={defaultTimeStart}
defaultTimeEnd={defaultTimeEnd}
canvasTimeStart={minTime}
canvasTimeEnd={maxTime}
onCanvasClick={this.handleCanvasClick}
onCanvasDoubleClick={this.handleCanvasDoubleClick}
onCanvasContextMenu={this.handleCanvasContextMenu}
Expand All @@ -173,7 +175,6 @@ export default class App extends Component {
onItemMove={this.handleItemMove}
onItemResize={this.handleItemResize}
onItemDoubleClick={this.handleItemDoubleClick}
onTimeChange={this.handleTimeChange}
onZoom={this.handleZoom}
moveResizeValidator={this.moveResizeValidator}
buffer={3}
Expand Down
3 changes: 2 additions & 1 deletion demo/app/demo-performance/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ export default class App extends Component {
defaultTimeEnd={defaultTimeEnd}
// itemRenderer={this.itemRenderer}
// groupRenderer={this.groupRenderer}

canvasTimeStart={minTime}
canvasTimeEnd={maxTime}
onCanvasClick={this.handleCanvasClick}
onCanvasContextMenu={this.handleCanvasContextMenu}
onItemClick={this.handleItemClick}
Expand Down
3 changes: 2 additions & 1 deletion demo/app/demo-renderers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ export default class App extends Component {
visibleTimeEnd={visibleTimeEnd}
// itemRenderer={this.itemRenderer}
groupRenderer={this.groupRenderer}

canvasTimeStart={minTime}
canvasTimeEnd={maxTime}
onCanvasClick={this.handleCanvasClick}
onCanvasContextMenu={this.handleCanvasContextMenu}
onItemClick={this.handleItemClick}
Expand Down
9 changes: 9 additions & 0 deletions demo/app/demo-tree-groups/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ var keys = {
itemTimeEndKey: 'end'
}

var minTime = moment()
.add(-6, 'months')
.valueOf()
var maxTime = moment()
.add(6, 'months')
.valueOf()

export default class App extends Component {
constructor(props) {
super(props)
Expand Down Expand Up @@ -115,6 +122,8 @@ export default class App extends Component {
itemHeightRatio={0.75}
defaultTimeStart={defaultTimeStart}
defaultTimeEnd={defaultTimeEnd}
canvasTimeStart={minTime}
canvasTimeEnd={maxTime}
horizontalLineClassNamesForGroup={(group) => group.root ? ["row-root"] : []}
/>
)
Expand Down
9 changes: 9 additions & 0 deletions demo/app/demo-vertical-classes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ const keys = {
itemTimeEndKey: 'end'
}

var minTime = moment()
.add(-6, 'months')
.valueOf()
var maxTime = moment()
.add(6, 'months')
.valueOf()

export default class App extends Component {

constructor(props) {
Expand Down Expand Up @@ -97,6 +104,8 @@ export default class App extends Component {
itemHeightRatio={0.75}
defaultTimeStart={defaultTimeStart}
defaultTimeEnd={defaultTimeEnd}
canvasTimeStart={minTime}
canvasTimeEnd={maxTime}
verticalLineClassNamesForTime={this.verticalLineClassNamesForTime}
/>
</div>
Expand Down
12 changes: 10 additions & 2 deletions src/lib/Timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ export default class ReactCalendarTimeline extends Component {

defaultTimeStart: PropTypes.object,
defaultTimeEnd: PropTypes.object,
canvasTimeStart: PropTypes.number,
canvasTimeEnd: PropTypes.number,

visibleTimeStart: PropTypes.number,
visibleTimeEnd: PropTypes.number,
Expand Down Expand Up @@ -265,9 +267,15 @@ export default class ReactCalendarTimeline extends Component {
)
}

if(!this.props.canvasTimeStart || !this.props.canvasTimeEnd) {
throw new Error(
'You must provide either "canvasTimeStart" and "canvasTimeEnd" to initialize the Timeline'
)
}

const [canvasTimeStart, canvasTimeEnd] = getCanvasBoundariesFromVisibleTime(
visibleTimeStart,
visibleTimeEnd,
props.canvasTimeStart,
props.canvasTimeEnd,
props.buffer,
)

Expand Down
23 changes: 12 additions & 11 deletions src/lib/utility/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ export function stackAll(itemsDimensions, groupOrders, lineHeight, stackItems) {
groupHeights.push(Math.max(groupHeight, lineHeight))
}
}

return {
height: sum(groupHeights),
groupHeights,
Expand All @@ -411,11 +411,11 @@ export function stackAll(itemsDimensions, groupOrders, lineHeight, stackItems) {
}

/**
*
* @param {*} itemsDimensions
* @param {*} isGroupStacked
* @param {*} lineHeight
* @param {*} groupTop
*
* @param {*} itemsDimensions
* @param {*} isGroupStacked
* @param {*} lineHeight
* @param {*} groupTop
*/
export function stackGroup(itemsDimensions, isGroupStacked, lineHeight, groupTop) {
var groupHeight = 0
Expand Down Expand Up @@ -643,8 +643,8 @@ export function getCanvasBoundariesFromVisibleTime(
) {
const zoom = visibleTimeEnd - visibleTimeStart
// buffer - 1 (1 is visible area) divided by 2 (2 is the buffer split on the right and left of the timeline)
const canvasTimeStart = visibleTimeStart - (zoom * (buffer - 1 )/2)
const canvasTimeEnd = canvasTimeStart + zoom * buffer
const canvasTimeStart = visibleTimeStart
const canvasTimeEnd = visibleTimeEnd
return [canvasTimeStart, canvasTimeEnd]
}

Expand All @@ -667,7 +667,8 @@ export function calculateScrollCanvas(
items,
groups,
props,
state
state,

) {
const buffer = props.buffer;
const oldCanvasTimeStart = state.canvasTimeStart
Expand All @@ -686,8 +687,8 @@ export function calculateScrollCanvas(

if (!canKeepCanvas || forceUpdateDimensions) {
const [canvasTimeStart, canvasTimeEnd] = getCanvasBoundariesFromVisibleTime(
visibleTimeStart,
visibleTimeEnd,
state.canvasTimeStart,
state.canvasTimeEnd,
buffer
)
newState.canvasTimeStart = canvasTimeStart
Expand Down